Algorithm


A. Appleman and Easy Task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?

Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.

Input

The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.

Output

Print "YES" or "NO" (without the quotes) depending on the answer to the problem.

Examples
input
Copy
3
xxo
xox
oxx
output
Copy
YES
input
Copy
4
xxxo
xoxo
oxox
xxxx
output
Copy
NO

 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 101;
int n;
int di[] = { 1, 0, -1, 0 };
int dj[] = { 0, 1, 0, -1 };
char g[N][N];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < n; ++i)
    scanf("%s", g[i]);
  
  int res = 0;
  for(int i = 0; i < n; ++i)
    for(int j = 0, cnt = 0; j < n; ++j) {
      for(int k = 0, ni, nj; k < 4; ++k) {
        ni = i + di[k];
        nj = j + dj[k];
        if(ni >= 0 && ni < n && nj >= 0 && nj < n && g[ni][nj] == 'o')
          ++cnt;
      }
      if(cnt % 2 == 0)
        ++res;
    }
  if(res == (n * n))
    puts("YES");
  else
    puts("NO");
  
  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
xxo
xox
oxx

Output

x
+
cmd
YES
Advertisements

Demonstration


Codeforces Solution-Appleman and Easy Task-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+