Given a partially hidden scoreboard with known solve counts and a staircase visibility pattern, decide whether the hidden entries can be filled so every contestant solves at least one problem, every problem is solved, and nobody solves all problems.
Medium6GreedyBrute forceImplementationCombinatoricsNo attempts yetTime limit1sMemory limit512 MBRunning a contest means weighing a great many factors. Hyeonjeong is famous for making contests that are bad in every sense. Her problem sets have never once met the standard of a good contest either. The good contest Hyeonjeong wants to make is a contest that meets all three of the following conditions.
After many such experiences, Hyeonjeong gave everything she had to make a good contest this time. She seems to have given too much, because she collapsed before the contest ended. When she woke up, the first thing she wanted was to look at the results and find out whether this contest had been a good one.
She hurried to the contest website and found the scoreboard with the results. But the top right corner of her laptop screen is broken in a triangular shape, so she could not see the whole scoreboard.

On the scoreboard, a contestant who solved more problems ranks higher, and the rows are sorted by rank with first place at the top. Because Hyeonjeong's screen is broken in a ◥ shape, the part of the scoreboard she can see satisfies all of the following rules.
Hyeonjeong knows how many problems each contestant solved, and she has partial information about which problems they solved. She starts daydreaming. She wants to fill in the hidden part of the scoreboard however she likes, so that she can believe the contest was a good one. Each hidden result is filled in as either solved or unsolved. Of course, she cannot change the number of problems each contestant solved or any result she can already see. Given the scoreboard visible on the broken screen, determine whether this contest can be a good contest.
The first line contains the number of contestants N (1≤N≤100) and the number of problems M (1≤M≤10). Each of the next N lines describes one contestant, in order from first place to place N. The line for the contestant in place i contains the number of problems that contestant solved, Ki (0≤Ki≤M), followed by M results for problems 1 to M. A result is 1 if the problem was solved, 0 if it was not solved, and -1 if it is hidden by the broken screen.
The given scoreboard is part of a real contest result. That is, Ki never increases from first place downward, and the visible results satisfy the four rules above and do not contradict Ki.
Print YES if the contest can be a good contest, and NO otherwise.
Below is one of several ways to fill in the hidden results of the first example so that the contest is a good contest.
1 1 0 1 1
1 0 1 0 1
1 0 1 0 0
1 0 0 0 0