When LaLa laid down on her pet Leo's back to fall asleep, she noticed that the lamp is all messed up, which must have been the act of her sister LiLi.
The lamp can be modeled as a regular triangular grid where each cell contains a bulb which is either on or off.
LaLa wants to turn off the lamp (that is, set the state of all bulbs to off). LaLa can pick any of the three directions parallel to the side of a lamp, pick any row parallel to that direction, and then flip the state of all the bulbs in the row (on to off and off to on) with her magic. LaLa also could just walk over to the lamp and manually turn every bulb off, but she would prefer not to.
Write a program that determines whether LaLa can turn off the lamp with her magic.
The input is given in the following format:
N
S_0
S_1
⋮
S_N−1
where N is the number of bulbs in a side of the lamp, and S_i is the binary string of length i+1 representing the initial states of bulbs in the i-th row, where the j-th character of S_i is '1' if and only if the j-th bulb is on.
The input satisfies the following constraint:
If LaLa can turn off the lamp with magic, print a single string "Yes". Otherwise, print a single string "No". You may print each character in either case (lower or upper).
The following illustrates a sequence of magic LaLa should cast to turn off the lamp given in the sample. Empty circles denote the bulbs that are off, yellow circles denote the bulbs that are on, and red line is the choosen row for magic.
| Step 0 | Step 1 | Step 2 |
|---|---|---|
![]() | ![]() | ![]() |
| Step 3 | Step 4 | Step 5 |
![]() | ![]() | ![]() |
| Step 6 | ||
![]() |