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
3
xxo
xox
oxx

Output
YES

Input
4
xxxo
xoxo
oxox
xxxx

Output
NO

Difficulty: interview

Starter code:

Solutions:
n = int(input())
s = []
for i in range(n):
    s.append(input())
new = [[0] * n for i in range(n)]
for i in range(n):
    for j in range(n):
        if s[i][j] == 'o':
            new[i][j] = 1
flag = True
for i in range(n):
    for j in range(n):
        s = 0
        if i > 0 and new[i - 1][j] == 1:
            s += 1
        if i < n - 1 and new[i + 1][j] == 1:
            s += 1
        if j > 0 and new[i][j - 1] == 1:
            s += 1
        if j < n - 1 and new[i][j + 1] == 1:
            s += 1
        if s % 2 == 1:
            flag = False
            break
if flag:
    print("YES")
else:
    print("NO")

N = int(input())
m = [input() for i in range(N)]

dx, dy = [0, 0, 1, -1], [1, -1, 0, 0]

for x in range(N):
    for y in range(N):
        cnt = 0
        for i in range(4):
            tx, ty = x + dx[i], y + dy[i]
            if 0 <= tx < N and 0 <= ty < N and m[ty][tx] == 'o':
                cnt += 1
        if cnt % 2:
            print('NO')
            return
print('YES')


n=int(input())


b=[[0 for i in range(n+2)] for j in range(n+2)]

for i in range(1,n+1):
	s=input()
	for j in range(1, n+1):
		if s[j-1]=='o':
			b[i-1][j]+=1
			b[i+1][j]+=1
			b[i][j+1]+=1
			b[i][j-1]+=1
yes=True
for i in range(1,n+1):
	if not yes:
		break
	for j in range(1, n+1):
		if b[i][j]%2==1:
			print("NO")
			yes=False
			break
if yes:
	print("YES")

import sys

def o_s(i, j):
    ret = 0
    if board[i-1][j] == 'o': ret += 1
    if board[i+1][j] == 'o': ret += 1
    if board[i][j-1] == 'o': ret += 1
    if board[i][j+1] == 'o': ret += 1
    return ret

n = int(sys.stdin.readline())
board = ['x'*(n+2)]
for i in range(n): board.append('x' + sys.stdin.readline().strip() + 'x')
board.append('x'*(n+2))

even = True
for i in range(1, n+1):
    for j in range(1, n+1):
        if o_s(i, j) % 2 == 1: even = False
        if not even: break
    if not even: break
if even: print("YES")
else: print("NO")

n=int(input())
desk=[input() for i in range(n)]
fl=True
for i in range(n):
    for g in range(n):
        a=0
        if g-1>=0:
            if desk[i][g-1]=='o':
                a+=1
        if g+1<n:
            if desk[i][g+1]=='o':
                a+=1
        if i-1>=0:
            if desk[i-1][g]=='o':
                a+=1
        if i+1<n:
            if desk[i+1][g]=='o':
                a+=1
        if a%2!=0:
            fl=False
            break
    if not fl:
        print('NO')
        break
if fl:
    print('YES')

n=int(input())
a=[input() for i in range(n)]
if n==1:
    print("YES")
else:
    ans=True
    c=0
    for i in range(n):
        for j in range(n):
            if i==0 and j==0:
                c+=int(a[i+1][j]=='o')+int(a[i][j+1]=='o')
            elif i==n-1 and j==n-1:
                c+=int(a[i-1][j]=='o')+int(a[i][j-1]=='o')
            elif i==0 and j==n-1:
                c+=int(a[i+1][j]=='o')+int(a[i][j-1]=='o')
            elif i==n-1 and j==0:
                c+=int(a[i-1][j]=='o')+int(a[i][j+1]=='o')
            elif i==0:
                c+=int(a[i+1][j]=='o')+int(a[i][j+1]=='o')+int(a[i][j-1]=='o')
            elif i==n-1:
                c+=int(a[i-1][j]=='o')+int(a[i][j+1]=='o')+int(a[i][j-1]=='o')
            elif j==0:
                c+=int(a[i+1][j]=='o')+int(a[i-1][j]=='o')+int(a[i][j+1]=='o')
            elif j==n-1:
                c+=int(a[i+1][j]=='o')+int(a[i-1][j]=='o')+int(a[i][j-1]=='o')
            else:
                c+=int(a[i+1][j]=='o')+int(a[i][j+1]=='o')+int(a[i][j-1]=='o')+int(a[i-1][j]=='o')
            if c%2!=0:
                ans=False
    print(["NO","YES"][ans])

n = int(input())
A = []
s = ''
st = ''
for i in range(n + 2):
    st += 'x'
A.append(st)
for i in range(n):
    s = 'x' + input() + 'x'
    A.append(s)
A.append(st)
ans = "YES"
for i in range(1, n + 1):
    for j in range(1, n + 1):
        c = 0
        if A[i + 1][j] == 'o': c += 1
        if A[i - 1][j] == 'o': c += 1
        if A[i][j + 1] == 'o': c += 1
        if A[i][j - 1] == 'o': c += 1
        if c % 2 == 0:
            continue
        else:
            ans = "NO"
            break
print(ans)


n = int(input())
b = []
k = 0
ans = 'YES'
for i in range(n):
    b.append(input())
for i in range(n):
    for j in range(n):
        if j - 1 >= 0:
            if b[i][j-1] == 'o':
                k += 1
        if j + 1 < n:
            if b[i][j+1] == 'o':
                k += 1
        if i - 1 >= 0:
            if b[i-1][j] == 'o':
                k += 1
        if i + 1 < n:
            if b[i+1][j] == 'o':
                k += 1
        if k % 2 == 1:
            ans = 'NO'
print(ans)
                


n = int(input())
count = 0
board = []
fail = False
while count < n:
    x = input()
    for letter in x:
        board.append(letter)
    count += 1
for i in range(n**2):
    total = 0
    if i-n < 0:
        pass
    else:
        if board[i-n] == 'o':
            total += 1
    if i-1 < 0:
        pass
    elif i % n == 0:
        pass
    else:
        if board[i-1] == 'o':
            total += 1
    if i+1 > n**2-1:
        pass
    elif i % n == n-1:
        pass
    else:
        if board[i+1] == 'o':
            total += 1
    if i+n > n**2-1:
        pass
    else:
        if board[i+n] == 'o':
            total += 1
    if total % 2 == 1:
        fail = True
if fail == True:
    print("NO")
else:
    print("YES")

n = int(input())
a = ['#' * (n + 2)]
for i in range(1, n+1):
    a.append('#')
    a[i] += input()
    a[i] += '#'
a.append('#' * (n + 2))
o = True
for i in range(1, n + 1):
    for j in range(1, n + 1):
        cnt = 0
        if a[i-1][j] == 'o':
            cnt += 1
        if a[i][j-1] == 'o':
            cnt += 1
        if a[i+1][j] == 'o':
            cnt += 1
        if a[i][j+1] == 'o':
            cnt += 1
        if cnt % 2 != 0:
            o = False
            break
    if o == False:
        break
if o:
    print('YES')
else:
    print('NO')

__author__ = 'Natik'
n = int(input())
mas = [[100] * n for i in range(n)]
for i in range(0, n):
    mas[i] = input()
ot = 0
for i in range(0, n):
    for j in range(0, n):
        klo = 0
        if j+1 < n:
            if mas[i][j+1] == 'o':
                klo += 1
        if i+1 < n:
            if mas[i+1][j] == 'o':
                klo += 1
        if i-1 >= 0:
            if mas[i-1][j] == 'o':
                klo += 1
        if j-1 >= 0:
            if mas[i][j-1] == 'o':
                klo += 1
        if klo % 2 == 1:
            ot = 1
if ot == 0:
    print('YES')
else:
    print('NO')

table = []

actions = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def go(pos, diff):
  return (pos[0] + diff[0], pos[1] + diff[1])

def check(pos, n):
  return pos[0] >= 0 and pos[0] < n and pos[1] >= 0 and pos[1] < n

def pt(pos):
  return pos[1] + pos[0] * n

def is_even(table, pos):
  nonlocal actions
  count = 0
  for action in actions:
    tgt = go(pos, action)
    if check(tgt, n):
      if(table[pt(tgt)] == 'o'):
        count += 1
        #print(tgt)
  #print(count)
  return count % 2 == 0

n = int(input())
for x in range(n):
  table += input()

for i in range(n):
  for j in range(n):
    if not is_even(table, (i, j)):
      #print(i, j)
      print("NO")
      quit()

print("YES")



n=int(input())
m=list()
for i in range (n):
    m.append(input())
    
for i in range(n):
    for j in range(n):
        k=0
        if (i>0) and (m[i-1][j]=='o'):
            k+=1
        if (i<(n-1)) and (m[i+1][j]=='o'):
            k+=1
        if (j>0) and (m[i][j-1]=='o'):
            k+=1
        if (j<n-1) and (m[i][j+1]=='o'):
            k+=1
        if (k%2):
            print("NO")
            return
print("YES")

n = int(input())
board = []
for i in range(n):
    r = input()
    board.append(r)
#print(board)
can = True
for i in range(n):
    row = board[i]
    for j in range(n):
        ele = row[j]
        c = 0
        ind_r = [j + 1, j - 1]
        ind_c = [i + 1, i - 1]
        for k in range(2):
            if ind_r[k] >= n or ind_r[k] < 0 :
                continue
            
            else:
                #print(row[ind_r[k]])
                #print("----------")
                if row[ind_r[k]] == 'o':
                    c += 1
        for k in range(2):
            if ind_c[k] >= n or ind_c[k] < 0:
                continue
            
            else:
                #print(board[ind_c[k]][j])
                #print("----------")
                if board[ind_c[k]][j] == 'o':
                    c += 1
        #print(c)
        if c % 2 != 0:
            can = False
            break
    if can == False:
        break
if can == True:
    print("YES")
else:
    print("NO")
    
            
        
        


import collections
import itertools


n = int(input())
m = collections.defaultdict(lambda: "x")
for y in range(n):

    for x, ch in enumerate(input()):

        m[x, y] = ch

deltas = ((-1, 0), (0, -1), (1, 0), (0, 1))
for p in itertools.product(list(range(n)), repeat=2):

    cps = [tuple(map(sum, list(zip(p, dp)))) for dp in deltas]
    if len(tuple([cp for cp in cps if m[cp] == "o"])) % 2:

        print("NO")
        return

print("YES")


n=int(input())
i=0
thelist=[]
while i<n:
    newline=input()
    j=0
    newlist=[]
    while j<len(newline):
        newlist.append(newline[j])
        j+=1
    thelist.append(newlist)
    i+=1
#print(thelist)
finallist=[]
x=0
y=0
row=[]
while y<len(thelist)+2:
    row.append(0)
    y+=1
#print(row)
finallist.append(row)
for item in thelist:
    item_0=[0]
    for x in item:
        if x=="o":
            item_0.append(1)
        else:
            item_0.append(0)
    item_0.append(0)
    finallist.append(item_0)
finallist.append(row)
#print(finallist)
istrue="YES"
i=1
j=1
#print(len(finallist))
while i<len(finallist)-1:
    while j<len(finallist)-1:
        thecount=finallist[i-1][j]+finallist[i+1][j]+finallist[i][j-1]+finallist[i][j+1]
        #print(thecount)
        if thecount % 2 ==1:
            istrue="NO"
        j+=1
    i+=1
    j=1
print(istrue)


n, l, flag, o = int(input()), [], True, 0
for i in range(n):
    l.append('0')
    l[i] = str(input())
for i in range(n):
    for el in range(n):
        if el - 1 >= 0:
            if l[i][el - 1] == 'o':
                o += 1
        if el + 1 < n:
            if l[i][el + 1] == 'o':
                o += 1
        if i - 1 >= 0:
            if l[i - 1][el] == 'o':
                o += 1
        if i + 1 < n:
            if l[i + 1][el] == 'o':
                o += 1
        flag &= (o % 2 == 0)
if flag:
    print("YES")
else:
    print("NO")

__author__ = 'Глеб'
import sys
n = int(input())
desk = [[0] * (n + 10) for j in range(n + 10)]
for i in range(n):
    str = input()
    for j in range(n):
        if str[j] == 'x':
            desk[i][j] = 0
        else:
            desk[i][j] = 1
for i in range(n):
    for j in range(n):
        if (desk[i][j + 1] + desk[i][j - 1] + desk[i + 1][j] + desk[i - 1][j]) % 2 != 0:
            print('NO')
            return
print('YES')

li=[]
n= int(input())
matrix = [[0 for i in range(n)] for i in range(n)]
for _ in range(n):
	l=input()
	li.append(l)
flag = 0
for i in range(n):
	for j in range(n):
		count = 0
		if(j>=1):
			if(li[i][j-1]=='o'):
				count = count+1
		if(j<n-1):
			if(li[i][j+1]=='o'):
				count = count+1
		if(i<n-1):
			if(li[i+1][j]=='o'):
				count = count+1
		if(i>=1):
			if(li[i-1][j]=='o'):
				count = count+1
		if(count%2!=0):
			flag=1
			break
			break
if(flag==0):
	print("YES")
else:
	print("NO")

p = 1
n = int(input())
grid = []
for i in range(0,n):
    grid.append(input())
difx = (1,-1,0,0)
dify = (0,0,-1,1)
for i in range(0,n):
    for j in range(0,n):
        count = 0
        for c in range(0,4):
            x = i+difx[c]
            y = j+dify[c]
            if x < 0 or x >= n or y < 0 or y >= n:
                continue
            if grid[x][y] == 'o':
                count += 1
        if count%2 != 0:
            p = 0
            


if p == 1:
    print ("YES")
else:
    print("NO")


n = int(input())

b = [input() for _ in range(n)]
ans = True
for i in range(n):
    for j in range(n):
        ans &= len([1 for di, dj in [(1, 0), (-1, 0), (0, 1), (0, -1)] if 0 <= i + di < n and 0 <= j + dj < n and b[i + di][j + dj] == 'o']) % 2 == 0
print('YES' if ans else 'NO')

tcs = int(input())
board = [['.']*(tcs+2)]+[['.']+[x for x in input()]+['.'] for i in range(tcs)]+[['.']*(tcs+2)]

def do(board, size):
    for i in range(1, size+1):
        for j in range(1, size+1):
            listx = [board[i+1][j], board[i-1][j], board[i][j-1], board[i][j+1]]
            if listx.count('o')%2 != 0:
                return False
    return True

if do(board, tcs):
    print("YES")
else:
    print("NO")


def prepare(n):
    table = [[0] * n for _ in range(n)]
    
    for i in range(n):
        line = input()
        for j in range(n):
            if line[j] == 'o':
                if i - 1 >= 0:
                    table[i - 1][j] = (table[i - 1][j] + 1) % 2
                    if table[i - 1][j] != 0:
                        return 'NO'
                if j - 1 >= 0:
                    table[i][j - 1] = (table[i][j - 1] + 1) % 2
                if j + 1 < n:
                    table[i][j + 1] = (table[i][j + 1] + 1) % 2
                if i + 1 < n:
                    table[i + 1][j] = (table[i + 1][j] + 1) % 2
    for j in range(n):
        if table[n - 1][j] != 0:
            return 'NO'
    return 'YES'


def __starting_point():
    n = int(input())
    
    print(prepare(n))


__starting_point()

n = int(input())
a = ["x" * (n + 2)] + ["x" + input() + "x" for i in range(n)] + ["x" * (n + 2)]
def f(i, j):
  c = 0
  if a[i - 1][j] == 'o':
    c += 1
  if a[i][j - 1] == 'o':
    c += 1
  if a[i + 1][j] == 'o':
    c += 1
  if a[i][j + 1] == 'o':
    c += 1
  return c % 2 == 0
print("YES" if all(f(i + 1, j + 1) for i in range(n) for j in range(n)) else "NO")