atcoder#ABC241C. [ABC241C] Connect 6

[ABC241C] Connect 6

Score : 300300 points

Problem Statement

There is a grid with NN horizontal rows and NN vertical columns, where each square is painted white or black. The state of the grid is represented by NN strings, SiS_i. If the jj-th character of SiS_i is #, the square at the ii-th row from the top and the jj-th column from the left is painted black. If the character is ., then the square is painted white.

Takahashi can choose at most two of these squares that are painted white, and paint them black. Determine if it is possible to make the grid contain 66 or more consecutive squares painted black aligned either vertically, horizontally, or diagonally. Here, the grid is said to be containing 66 or more consecutive squares painted black aligned diagonally if the grid with NN rows and NN columns completely contains a subgrid with 66 rows and 66 columns such that all the squares on at least one of its diagonals are painted black.

Constraints

  • 6N10006 \leq N \leq 1000
  • Si=N\lvert S_i\rvert =N
  • SiS_i consists of # and ..

Input

Input is given from Standard Input in the following format:

NN

S1S_1

S2S_2

\vdots

SNS_N

Output

If it is possible to fulfill the condition by painting at most two squares, then print Yes; otherwise, print No.

8
........
........
.#.##.#.
........
........
........
........
........
Yes

By painting the 33-rd and the 66-th squares from the left in the 33-rd row from the top, there will be 66 squares painted black aligned horizontally.

6
######
######
######
######
######
######
Yes

While Takahashi cannot choose a square to paint black, the grid already satisfies the condition.

10
..........
#..##.....
..........
..........
....#.....
....#.....
.#...#..#.
..........
..........
..........
No