Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.

Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:  on both diagonals of the square paper all letters are the same;  all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. 

Help Valera, write the program that completes the described task for him.


-----Input-----

The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.


-----Output-----

Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.


-----Examples-----
Input
5
xooox
oxoxo
soxoo
oxoxo
xooox

Output
NO

Input
3
wsw
sws
wsw

Output
YES

Input
3
xpx
pxp
xpe

Output
NO

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import sys

def check(grid):
	width = len(grid)
	expected_diag = grid[0][0]
	expected_non_diag = grid[0][1]
	if expected_diag == expected_non_diag:
		return False
	for i in range(width):
		for j in range(width):
			if i == j or j == width - 1 - i:
				if not grid[i][j] == expected_diag:
					return False
			elif not grid[i][j] == expected_non_diag:
				return False
	return True
n = int(sys.stdin.readline())
grid = []
for i in range(n):
	grid.append(sys.stdin.readline().strip())
if check(grid):
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for z in range(n):
	a.append(list(input()))
x = a[0][0]
y = a[0][1]
if x == y:
	print('NO')
	quit()
for i in range(n):
	for j in range(n):
		if (i == j or i + j == n - 1) and a[i][j] != x:
			print('NO')
			quit()
		elif i != j and i + j != n - 1 and (a[i][j] != y):
			print('NO')
			quit()
print('YES')


n = int(input())
l = [[j for j in input().strip()] for i in range(n)]
a = l[0][0]
b = l[0][1]
y = a != b
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if l[i][j] != a:
				y = 0
				break
		elif l[i][j] != b:
			y = 0
			break
if y == 0:
	print('NO')
else:
	print('YES')


def test(sq, n):
	(a, b) = (sq[0][0], sq[0][1])
	if a == b:
		return False
	else:
		for i in range(n):
			if sq[i][i] != a or sq[i][-i - 1] != a:
				return False
		return sum([l.count(b) for l in sq]) == n * n - 2 * n + 1
n = int(input())
sq = []
for i in range(n):
	sq.append(input())
print('YES' if test(sq, n) else 'NO')


from itertools import product
from math import ceil
import string

def binary_table(string_with_all_characters, length_to_make):
	return [''.join(x) for x in product(string_with_all_characters, repeat=length_to_make)]

def all_possible_substrings(string):
	return [int(string[i:j]) for i in range(len(string)) for j in range(i + 1, len(string) + 1)]

def number_of_substrings(length):
	return int(length * (length + 1) / 2)

def is_prime(num):
	for i in range(2, num):
		if num / i == int(num / i) and num != i:
			return False
	return True
num_of_lines = int(input())
build_letter = ''
cond = False
cond_2 = False
position_1 = ''
position_2 = ''
arr = set()
aller = set()
for i in range(num_of_lines):
	inp = input()
	if i == 0:
		if inp[0] == inp[-1]:
			build_letter = inp[0]
			position_1 = 0
			position_2 = len(inp) - 1
			positions = [x for x in range(len(inp)) if inp[x] == build_letter]
			if len(positions) > 2:
				cond = True
				break
		else:
			cond = True
			break
	else:
		if position_1 == position_2:
			cond_2 = True
		if cond_2:
			position_1 -= 1
			position_2 += 1
		else:
			position_1 += 1
			position_2 -= 1
		positions = [x for x in range(len(inp)) if inp[x] == build_letter]
		if len(positions) > 2:
			cond = True
			break
		elif len(positions) == 1:
			if positions[0] != position_1 or positions[0] != position_2:
				cond = True
				break
		elif len(positions) == 0:
			cond = True
			break
		elif position_1 != positions[0] or position_2 != positions[1]:
			cond = True
			break
	arr.add(inp)
if not cond:
	for i in arr:
		for j in i:
			aller.add(j)
	if len(aller) == 2:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
y = []
for i in range(n):
	y.append(list(input()))
(ans1, ans2) = ([], [])
for i in range(n):
	for j in range(n):
		if i == j:
			ans1.append(y[i][j])
for i in range(n):
	for j in range(n):
		if i + j == n - 1:
			ans1.append(y[i][j])
for i in range(n):
	for j in range(n):
		if i != j and j != n - i - 1:
			ans2.append(y[i][j])
if len(set(ans1)) == 1 and len(set(ans2)) == 1 and (ans1[0] != ans2[0]):
	print('YES')
else:
	print('NO')


n = int(input())
first_line = str(input())
sum_letters_diff_from_diag_calculation = int((n - 2) * n + 1)
sum_for_each_line = int(n - 2)
state = ''
for i in range(n - 1):
	from_secLine_and_above = str(input())
	if first_line[0] != from_secLine_and_above[i + 1]:
		state = 'NO'
		break
	if first_line[-1] != from_secLine_and_above[-i - 1 - 1]:
		state = 'NO'
		break
	if n > 3:
		if first_line[1] == first_line[2] and first_line[2] == first_line[3]:
			sum_for_each_line += from_secLine_and_above.count(first_line[1])
		else:
			state = 'NO'
			break
	elif n == 3:
		if first_line[1] != first_line[0]:
			sum_for_each_line += from_secLine_and_above.count(first_line[1])
		else:
			state = 'NO'
			break
	else:
		state = 'NO'
		break
if len(state) == 0:
	if sum_for_each_line == sum_letters_diff_from_diag_calculation:
		print('YES')
	else:
		print('NO')
else:
	print(state)


g = input
n = int(g())
p = [g() for _ in range(n)]
x = p[0][0]
if len(set((c for l in p for c in l))) != 2:
	print('NO')
	return
print('YNEOS'[any((1 for i in range(n) if x != p[i][i] or x != p[i][-i - 1] or p[i].count(x) != (1 if i == n // 2 else 2)))::2])


n = int(input())
l = []
for _ in range(n):
	l.append(list(input()))
ist = 1
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if l[0][0] != l[i][j]:
				ist = -1
		elif l[0][1] != l[i][j] or l[0][0] == l[i][j]:
			ist = -1
print('YES') if ist == 1 else print('NO')


n = int(input())
a = []
used = [[False] * n for _ in range(n)]
for _ in range(n):
	a.append(input())
let = None
for i in range(n):
	if a[i][i] != a[n - i - 1][i]:
		print('NO')
		exit(0)
	used[i][i] = used[n - i - 1][i] = True
	if let is None:
		let = a[i][i]
	elif a[i][i] != let:
		print('NO')
		exit(0)
let2 = None
for i in range(n):
	for j in range(n):
		if used[i][j]:
			continue
		if a[i][j] == let:
			print('NO')
			exit(0)
		used[i][j] = True
		if let2 is None:
			let2 = a[i][j]
		elif a[i][j] != let2:
			print('NO')
			exit(0)
print('YES')


n = int(input())
s = ''
for i in range(n):
	s += input()
if s == ''.join(list(reversed(s))) and s.count(s[0]) == n * 2 - 1:
	print('YES')
else:
	print('NO')


arr = []
n = int(input())
for i in range(n):
	temp = input()
	arr.append(temp)
dic = []
for i in range(n):
	for j in range(n):
		if arr[i][j] not in dic:
			dic.append(arr[i][j])
if len(dic) != 2:
	print('NO')
else:
	a = arr[0][0]
	dic.remove(a)
	b = dic[0]
	flag = True
	i = 0
	j = n - 1
	while i < j:
		if arr[i] == arr[j]:
			pass
		else:
			flag = False
			print('NO')
			break
		i += 1
		j -= 1
	if flag:
		ideal = ''
		for i in range(n):
			if i == n // 2:
				ideal += a
			else:
				ideal += b
		if arr[n // 2] == ideal:
			pass
		else:
			print('NO')
			flag = False
		if flag:
			print('YES')


n = int(input())
L = []
for i in range(n):
	L.append(list(input()))
(p, q) = (L[0][0], L[0][1])
if p == q:
	print('NO')
	quit()
for i in range(n):
	for j in range(n):
		if i == j or j == n - i - 1:
			if L[i][j] != p:
				print('NO')
				quit()
		elif L[i][j] != q:
			print('NO')
			quit()
print('YES')


n = int(input())
flag = True
diag = None
norm = None
for i in range(n):
	m = input()
	if i == 0:
		diag = m[0]
		norm = m[1]
		if diag == norm:
			flag = False
	for j in range(n):
		if j == i or j == n - i - 1:
			if m[j] != diag:
				flag = False
		elif m[j] != norm:
			flag = False
if flag:
	print('YES')
else:
	print('NO')


diag = []
nond = []
t = int(input())
for a in range(t):
	s = input()
	diag.append(s[0 + a])
	diag.append(s[t - 1 - a])
	for b in s:
		nond.append(b)
	nond.remove(s[0 + a])
	if t - 1 - a != 0 + a:
		nond.remove(s[t - 1 - a])
if len(diag) == diag.count(diag[0]) and len(nond) == nond.count(nond[0]) and (nond[0] != diag[0]):
	print('YES')
else:
	print('NO')


n = int(input())
grid = []
res = ''
pset = set()
for _ in range(n):
	r = input()
	if len(set(r)) != 2 or (pset and pset != set(r)):
		res = 'NO'
		break
	grid.append(r)
	pset = set(r)
diag = []
if not res:
	for i in range(n):
		for j in range(n):
			if i + j == n - 1 or i == j:
				if grid[i][j] != grid[0][0]:
					res = 'NO'
					break
			elif grid[i][j] != grid[0][1]:
				res = 'NO'
				break
	res = 'YES' if not res else 'NO'
print(res)


n = int(input())
out = True
letters = []
for i in range(n):
	x = input()
	a = list(set(list(x)))
	if len(a) == 2:
		if len(letters) == 0:
			letters = [a[0], a[1]]
		if a[0] not in letters or a[1] not in letters:
			out = False
		elif i == n // 2:
			if x.count(a[0]) == 1:
				if x[i] != a[0]:
					out = False
			elif x.count(a[1]) == 1:
				if x[i] != a[1]:
					out = False
			else:
				out = False
		elif x.count(a[0]) == 2:
			if x[i] != a[0] or x[-1 - i] != a[0]:
				out = False
		elif x.count(a[1]) == 2:
			if x[i] != a[1] or x[-1 - i] != a[1]:
				out = False
		else:
			out = False
	if len(a) != 2:
		out = False
if out:
	print('YES')
else:
	print('NO')


def main():
	n = int(input().strip())
	it = iter(enumerate((input().strip() for _ in range(n))))
	(_, s) = next(it)
	(x, o) = (s[0], s[1])
	if x == o or s[-1] != x or any((_ != o for _ in s[1:-1])):
		return False
	for (i, s) in it:
		mask = (i, n - i - 1)
		if any((c != (o, x)[j in mask] for (j, c) in enumerate(s))):
			return False
	return True
print(('NO', 'YES')[main()])


n = int(input())
isX = True
uniqLet = set()
k = 0
for i in range(n):
	l = list(input())
	if l[k] != l[n - k - 1]:
		isX = False
	uniqLet.add(l[k])
	for j in range(n):
		if j == k or j == n - k - 1:
			continue
		if l[k] == l[j]:
			isX = False
		uniqLet.add(l[j])
	if len(uniqLet) != 2:
		isX = False
	k += 1
if isX:
	print('YES')
else:
	print('NO')


n = int(input())
res = 1
for i in range(n):
	s = input()
	if i == 0:
		a = s[0]
		b = s[1]
	for j in range(n):
		if (i + j == n - 1 or i == j) and a != s[j]:
			res = 0
		elif (i + j != n - 1 and i != j) and b != s[j]:
			res = 0
print('YES') if res and a != b else print('NO')


import sys
inp = sys.stdin
x = inp.readline()
n = int(x)
ls = []
for i in range(n):
	ls.append(inp.readline())
a = ls[0][0]
b = ls[0][1]
Answer = True
if a == b:
	Answer = False
for i in range(n):
	for j in range(n):
		if i == j or n - i - 1 == j:
			if ls[i][j] != a:
				Answer = False
		elif ls[i][j] != b:
			Answer = False
if Answer:
	print('YES')
else:
	print('NO')


n = int(input())
L = [input() for i in range(n)]
a = []
b = []
for i in range(n):
	for j in range(n):
		if i == j or i + j + 1 == n:
			a.append(L[i][j])
		else:
			b.append(L[i][j])
if len(set(a)) == 1 and len(set(b)) == 1 and (a[0] != b[0]):
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
ans = 'YES'
s1 = s[0]
s2 = s[1]
if s[n - 1] != s1 or s1 == s2:
	ans = 'NO'
for i in range(1, n - 1):
	if s[i] != s2:
		ans = 'NO'
for i in range(1, n):
	s = input()
	p1 = i
	p2 = n - 1 - i
	if s[p1] != s1 or s[p2] != s1:
		ans = 'NO'
	for j in range(n):
		if j != p1 and j != p2 and (s[j] != s2):
			ans = 'NO'
print(ans)


n = int(input())
li = []
for i in range(n):
	li += [input()]
a = li[0][0]
b = li[0][1]
flag = 1
if a != b:
	for i in range(n):
		for j in range(n):
			if i == j or j == n - i - 1:
				if li[i][j] != a:
					flag = 0
					break
			elif li[i][j] != b:
				flag = 0
				break
	if flag == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
x = []
for i in range(n):
	v = list(input())
	x.append(v)
k = True
if x[0][0] == x[0][1]:
	k = False
for i in range(n):
	v = []
	for j in range(n):
		if i == j or n - i - 1 == j:
			if x[i][j] != x[0][0]:
				k = False
				break
		elif x[i][j] != x[0][1]:
			k = False
			break
	x.append(v)
if k:
	print('YES')
else:
	print('NO')


def Contador(A, l):
	cont = 0
	for i in range(len(A)):
		if A[i] == l:
			cont += 1
	return cont
n = int(input())
a = input()
antX = a[0]
antNX = a[1]
c = 0
if a[0] == a[n - 1] and Contador(a, antNX) == n - 2:
	c += 1
	for i in range(1, n):
		a = input()
		if i == n - 1 - i:
			if antX == a[i] and Contador(a, antNX) == n - 1:
				c += 1
		elif a[i] == a[n - 1 - i] and antX == a[i] and (Contador(a, antNX) == n - 2):
			c += 1
if c == n:
	print('YES')
else:
	print('NO')


n = int(input())
arr = []
state = True
word = input()
left = word[0]
right = word[1]
count = 0
arr.append(word)
if left == right:
	state = False
if word[n - 1] != left:
	state = False
for x in range(n - 2):
	if word[x + 1] != right and word[n - x - 2] != right:
		state = False
for x in range(n - 1):
	word = input()
	if word[x + 1] == left and word[n - 2 - x] == left:
		for y in range(n):
			if word[y] == right or x + 1 == y or n - 2 - x == y:
				arr.append(word)
			else:
				state = False
				break
	else:
		state = False
		break
if state:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
n = int(input().strip())
a = []
b = set()
for i in range(n):
	s = input().strip()
	a.append(s)
	for ch in s:
		b.add(ch)
if len(b) == 2:
	b = set()
	c = set()
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				b.add(a[i][j])
			else:
				c.add(a[i][j])
	if len(b) == len(c) == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
st1 = set()
st2 = set()
for i in range(n):
	s = input()
	for j in range(n):
		if i == j or i + j == n - 1:
			st1.add(s[j])
		else:
			st2.add(s[j])
if len(st1) == 1 and len(st2) == 1 and (st1 != st2):
	print('YES')
	exit()
else:
	print('NO')
	exit()


side = int(input())
formX = True
for i in range(side):
	row = input()
	if i == 0:
		l1 = row[0]
		l2 = row[1]
		if l2 == l1:
			formX = False
			break
	if not l1 == row[i] == row[-1 - i]:
		formX = False
		break
	elif not all([row[j] == l2 for j in range(side) if j != i and j != side - 1 - i]):
		formX = False
		break
print('YES' if formX else 'NO')


inp = int(input())
(rem, mem) = ([], [])
for i in range(inp):
	st = input()
	for q in range(inp):
		if q == inp - i - 1 or q == i:
			mem.append(st[q])
		else:
			rem.append(st[q])
else:
	c = rem[0]
	m = mem[0]
	if c != m:
		if mem.count(m) != inp * 2 - 1 or rem.count(c) != inp ** 2 - inp * 2 + 1:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')


n = int(input())
s = [[j for j in input()] for i in range(n)]
for i in range((n - 1) // 2 + 1):
	if (s[i][i] != s[i][n - 1 - i]) | (s[i][i] != s[0][0]):
		print('NO')
		exit()
for i in range(n - 1, (n - 1) // 2, -1):
	if (s[i][i] != s[i][n - i - 1]) | (s[i][i] != s[0][0]):
		print('NO')
		exit()
if (s[0][0] != s[(n - 1) // 2][(n - 1) // 2]) | (s[0][0] == s[0][1]):
	print('NO')
	exit()
for i in range(1, n):
	if i == (n - 1) // 2:
		continue
	if s[(n - 1) // 2][0] != s[(n - 1) // 2][i]:
		print('NO')
		exit()
for i in range((n - 1) // 2):
	for j in range(n):
		if (i == j) | (n - 1 - i == j):
			continue
		if s[i][j] != s[0][1]:
			print('NO')
			exit()
for i in range(n - 1, (n - 1) // 2, -1):
	for j in range(n):
		if (i == j) | (j == n - 1 - i):
			continue
		if s[i][j] != s[0][1]:
			print('NO')
			exit()
print('YES')


n = int(input())
a = [input() for _ in range(n)]
l = []
l1 = []
for i in range(n):
	for j in range(n):
		if i - j == 0:
			l.append(a[i][j])
		elif i + j == n - 1:
			l.append(a[i][j])
		else:
			l1.append(a[i][j])
set1 = set(l)
set2 = set(l1)
l = list(set1)
l1 = list(set2)
if len(l) == 1 and len(l1) == 1:
	if l[0] != l1[0]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
first = input()
if first[0] != first[-1]:
	print('NO')
elif len(set(first[1:-1])) > 1:
	print('NO')
elif first[0] == first[1]:
	print('NO')
else:
	l = set(first)
	check = first[0]
	err = False
	for x in range(1, n):
		s = input()
		l.update(set(s))
		if len(l) != 2:
			print('NO')
			break
		for (i, c) in enumerate(s):
			if i in (x, n - x - 1) and c != check:
				err = True
				break
			elif i not in (x, n - x - 1) and c == check:
				err = True
				break
		if err:
			print('NO')
			break
	else:
		print('YES')


n = int(input())
s = []
v = 0
for i in range(n):
	s.append(input())
for j in range(n):
	for k in range(n):
		if s[0][0] == s[0][1]:
			print('NO')
			v = 1
			break
		elif j == k and s[j][k] != s[0][0]:
			print('NO')
			v = 1
			break
		elif j + k == n - 1 and s[j][k] != s[0][0]:
			print('NO')
			v = 1
			break
		elif j != k and j + k != n - 1 and (s[j][k] != s[0][1]):
			print('NO')
			v = 1
			break
	if v == 1:
		break
else:
	print('YES')


n = int(input())
choice = ''
other = ''
for i in range(n):
	row = input()
	if not other and (not choice):
		other = row[1]
		choice = row[0]
		if other == choice:
			print('NO')
			exit()
	if row[i] != choice or row[n - i - 1] != choice:
		print('NO')
		exit()
	for (j, v) in enumerate(row):
		if v != other and v != choice:
			print('NO')
			exit()
		if j != i and j != n - i - 1:
			if v != other:
				print('NO')
				exit()
print('YES')


(n, arr1, arr2) = (int(input()), [], [])
for i in range(n):
	s = input()
	for j in range(len(s)):
		if i == j or j == n - 1 - i:
			arr1.append(s[j])
		else:
			arr2.append(s[j])
if len(set(arr1)) == 1 == len(set(arr2)) and set(arr1) != set(arr2):
	print('YES')
else:
	print('NO')


p = []
n = int(input())
for i in range(n):
	p.append(input())
x = p[0][0]
o = p[0][1]
sumx = 0
sumo = 0
(a, b) = (0, -1)
for i in range(n):
	if p[i][a] != x or p[i][b] != x:
		print('NO')
		break
	a += 1
	b -= 1
	sumx += p[i].count(x)
	sumo += p[i].count(o)
else:
	if sumx == 2 * n - 1 and sumo == n ** 2 - (2 * n - 1):
		print('YES')
	else:
		print('NO')


n_val = int(input())
letters = list()
for index in range(n_val):
	letters.append(input())
diagonal_letter = letters[0][0]
off_diag_letter = letters[0][1]
if diagonal_letter == off_diag_letter:
	print('NO')
	exit(0)
for row in range(n_val):
	if letters[row][row] != diagonal_letter:
		print('NO')
		exit(0)
	if letters[row][n_val - 1 - row] != diagonal_letter:
		print('NO')
		exit(0)
for row in range(n_val):
	for col in range(n_val):
		if col != row and col != n_val - 1 - row:
			if letters[row][col] != off_diag_letter:
				print('NO')
				exit(0)
print('YES')


n = int(input())
l = []
while n:
	l.append(list(input()))
	n = n - 1
(l1, l2) = ([], [])

def printPrincipalDiagonal(mat, n):
	for i in range(n):
		l1.append(mat[i][i])
	return l1

def printSecondaryDiagonal(mat, n):
	for i in range(n):
		l2.append(mat[i][n - i - 1])
	return l2
printSecondaryDiagonal(l, len(l))
printPrincipalDiagonal(l, len(l))
l3 = l1 + l2
s1 = list(set(l3))
l4 = []

def printDiagonal(mat, n):
	for i in range(n):
		for j in range(n):
			if i != j and i + j != n - 1:
				l4.append(mat[i][j])
printDiagonal(l, len(l))
s2 = list(set(l4))
if len(s1) == len(s2) == 1 and ord(s1[0]) != ord(s2[0]):
	print('YES')
else:
	print('NO')


n = input()
p1 = ['' for i in range(int(n))]
p2 = ['' for i in range(int(n))]
for i in range(int(n)):
	p1[i] = input()
a = p1[0][0]
b = p1[0][1]
if a == b:
	print('NO')
else:
	for i in range(int(n)):
		for j in range(int(n)):
			if j == i:
				p2[i] += a
			elif j == int(n) - (i + 1):
				p2[i] += a
			else:
				p2[i] += b
	if p1 == p2:
		print('YES')
	else:
		print('NO')


n = int(input())
take = [input() for i in range(n)]
check = []
for i in range(n):
	generate = [take[0][1]] * n
	(generate[i], generate[n - 1 - i]) = (take[0][0], take[0][0])
	check.append(''.join(generate))
print('YES' if take == check and take[0][0] != take[0][1] else 'NO')


n = int(input())
x = []
c = -1
d1 = ''
d2 = ''
others = ''
for i in range(n):
	x.append(list(map(str, input().split())))
	d1 += x[i][0][i]
	d2 += x[i][0][c]
	current = x[i][0]
	if i == (n + 1) // 2 - 1:
		current = current.replace(d1[-1], '', 1)
	else:
		current = current.replace(d1[-1], '', 1)
		current = current.replace(d2[-1], '', 1)
	others += current
	c -= 1
if d1 == d2 and len(set(others)) == 1 and (others[0] != d1[0]) and (len(set(d1)) == 1):
	print('YES')
else:
	print('NO')


n = int(input())
square = [''] * n
for i in range(n):
	square[i] = input()
diagonals = square[0][0]
undiagonals = square[0][1]
ans = True
if diagonals == undiagonals:
	ans = False
else:
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if square[i][j] != diagonals:
					ans = False
			elif square[i][j] != undiagonals:
				ans = False
if ans:
	print('YES')
else:
	print('NO')


n = int(input())
l = []
d = {}
for i in range(n):
	a = input()
	for i in a:
		d[i] = 1
	l.append(a)
if len(d) != 2:
	print('NO')
else:
	p = l[0][0]
	oth = ''
	for i in d:
		if i != p:
			oth = i
			break
	f = 0
	for i in range(n):
		for j in range(n):
			if i == j:
				if l[i][j] != p:
					f = 1
					break
			elif i == n - j - 1:
				if l[i][j] != p:
					f = 1
					break
			elif l[i][j] != oth:
				f = 1
				break
			if f == 1:
				break
		if f == 1:
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = [S() for _ in range(n)]
	m = n // 2
	s = set()
	t = set()
	for i in range(n):
		for j in range(n):
			if abs(i - m) == abs(j - m):
				s.add(a[i][j])
			else:
				t.add(a[i][j])
	if len(s) > 1 or len(t) > 1 or list(s)[0] == list(t)[0]:
		return 'NO'
	return 'YES'
print(main())


n = int(input())
a = []
b = []
for i in range(n):
	x1 = input().strip()
	x = list(x1)
	a.append(x)
	for j in x:
		b.append(j)
k = len(list(set(b)))
kj = 0
for aj in b:
	if aj == a[0][1]:
		kj += 1
if k != 2:
	print('NO')
elif kj != n ** 2 - (2 * n - 1):
	print('NO')
else:
	pp = 0
	p = 0
	p1 = n - 1
	for kk in range(n - 1):
		if a[kk][p] == a[kk + 1][p + 1] and a[kk][p1] == a[kk + 1][p1 - 1]:
			p += 1
			p1 -= 1
		else:
			pp = 1
			break
	if pp == 0:
		print('YES')
	else:
		print('NO')


import sys
n = int(input())
lines = [input() for _ in range(n)]
if len(set((c for l in lines for c in l))) != 2:
	print('NO')
	return
for i in range(n):
	if lines[0][0] != lines[i][i] or lines[0][0] != lines[i][-i - 1]:
		print('NO')
		return
	if lines[i].count(lines[0][0]) != (1 if i == n // 2 else 2):
		print('NO')
		return
print('YES')


arr = []
n = int(input())
for _ in range(n):
	word = input()
	arr.append(word)
total = ''.join(arr)
if len(set(total)) != 2 or arr[::-1] != arr:
	print('NO')
else:
	for item in arr:
		if item != item[::-1] or len(set(item)) != 2:
			print('NO')
			break
	else:
		print('YES')


m = int(input())
list1 = []
for x in range(m):
	list2 = list(input())
	list1.append(list2)
flag = True
for x in range(len(list1)):
	common = list1[0][0]
	second_common = list1[0][1]
	if second_common == common:
		flag = False
		break
	for y in range(len(list1[x])):
		if x == y or x == m - y - 1 or y == m - x - 1:
			if list1[x][y] != common:
				flag = False
				break
		elif list1[x][y] != second_common:
			flag = False
			break
	if not flag:
		break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
l = [input() for _ in range(n)]
s = set()
check = set()
c = 0
for i in range(n):
	s.add(l[i][i])
	s.add(l[i][n - 1 - i])
	c += l[i].count(l[i][i])
	check = check.union(set(l[i]))
if len(s) == 1 and c == 2 * n - 1 and (len(check) == 2):
	print('YES')
else:
	print('NO')


n = int(input())
mat = []
for i in range(n):
	mat.append(list(input()))
valid = True
for k in range(n):
	for j in range(n):
		if k == j or k == n - j - 1:
			if mat[k][j] != mat[0][0]:
				valid = False
				break
		elif mat[k][j] != mat[0][1]:
			valid = False
			break
if valid and mat[0][0] != mat[0][1]:
	print('YES')
else:
	print('NO')


n = int(input())
x = True
for i in range(n):
	line = input()
	if i == 0:
		letter = line[0]
		oldLine = line
	if len(set(line)) != 2:
		x = False
	if line[i] != letter and line[n - 1 - i] != letter:
		x = False
	if i == n // 2:
		if line.count(letter) != 1:
			x = False
	elif line.count(letter) != 2:
		x = False
	if set(line) != set(oldLine):
		x = False
	oldLine = line
print('YES' if x else 'NO')


n = int(input())
matrix = []
for i in range(n):
	matrix.append(list(map(str, input())))
isWrong = False
answerDone = False
i = 0
j = n - 1
while i != j:
	if matrix[i] != matrix[j]:
		isWrong = True
		answerDone = True
		print('NO')
		break
	i += 1
	j -= 1
if isWrong == False:
	middle = matrix[i]
	i = 0
	j = n - 1
	while i != j:
		if middle[i] != middle[j] or middle[i] != matrix[i][n // 2] or middle[j] != matrix[i][n // 2] or (middle[i] == middle[n // 2]) or (middle[i] == middle[n // 2]):
			isWrong = True
			answerDone = True
			print('NO')
			break
		i += 1
		j -= 1
	if isWrong == False and middle[i] == matrix[0][0]:
		answerDone = True
		print('YES')
	if answerDone == False:
		print('NO')


n = int(input())
x = 0
m = list()
for i in range(n):
	s = list(input())
	m.append(set(s))
	if len(set(s)) != 2:
		x = 1
		break
	elif set(s) != m[0]:
		x = 1
		break
	elif i < int(n / 2):
		if s.count(s[i]) != 2:
			x = 1
			break
		else:
			r = s[::-1]
			if s != r:
				x = 1
				break
	elif i == int(n / 2):
		if s.count(s[i]) != 1:
			x = 1
			break
	elif s.count(s[2 * int(n / 2) - i]) != 2:
		x = 1
		break
	else:
		r = s[::-1]
		if s != r:
			x = 1
			break
if x:
	print('NO')
else:
	print('YES')


a = int(input())
y = 0
for i in range(a):
	c = -i - 1
	b = input()
	if i == 0:
		t = b[i]
		u = b[i + 1]
		if t == u:
			y += 1
			break
	for x in range(a):
		if x == i or x == a + c:
			if b[x] != t:
				y += 1
				break
		elif b[x] != u:
			y += 1
			break
	if y > 0:
		break
if y == 0:
	print('YES')
else:
	print('NO')


s = ''

def ch(be, en):
	global x, e
	if s[be] != x or s[en] != x:
		return True
	for i in range(len(s)):
		if i != be and i != en and (s[i] != e):
			return True
	return False
n = int(input())
s = input()
x = s[0]
e = s[1]
if s[0] == s[1] or ch(0, n - 1):
	print('NO')
	exit()
for i in range(1, n):
	s = input()
	if ch(i, n - i - 1):
		print('NO')
		exit()
print('YES')


def solve(arr, n):
	last_d = arr[0][0]
	last = arr[0][1]
	for i in range(n):
		for j in range(n):
			if i == j or i == n - j - 1:
				if last_d != arr[i][j] or last == arr[i][j]:
					return 'NO'
			elif last != arr[i][j] or arr[i][j] == last_d:
				return 'NO'
	return 'YES'

def main():
	n = int(input())
	arr = []
	for _ in range(n):
		i = input()
		arr.append(i)
	print(solve(arr, n))
main()


import sys
import math
n = int(sys.stdin.readline())
a = 0
b = n - 1
line = sys.stdin.readline()
sa = line[0]
sb = line[1]
cc = 0
for j in range(n):
	if line[j] == sa:
		cc += 1
		if not (j == a or j == b):
			print('NO')
			exit()
	elif line[j] != sb:
		print('NO')
		exit()
if cc != 2:
	print('NO')
	exit()
a += 1
b -= 1
for i in range(int(n / 2) - 1):
	cc = 0
	line = sys.stdin.readline()
	for j in range(n):
		if line[j] == sa:
			cc += 1
			if not (j == a or j == b):
				print('NO')
				exit()
		elif line[j] != sb:
			print('NO')
			exit()
	a += 1
	b -= 1
	if cc != 2:
		print('NO1')
		exit()
cc = 0
line = sys.stdin.readline()
for j in range(n):
	if line[j] == sa:
		cc += 1
		if not (j == a or j == b):
			print('NO')
			exit()
	elif line[j] != sb:
		print('NO')
		exit()
if cc == 0:
	print('NO')
	exit()
a -= 1
b += 1
for i in range(int(n / 2)):
	cc = 0
	line = sys.stdin.readline()
	for j in range(n):
		if line[j] == sa:
			cc += 1
			if not (j == a or j == b):
				print('NO')
				exit()
		elif line[j] != sb:
			print('NO')
			exit()
	a -= 1
	b += 1
	if cc != 2:
		print('NO')
		exit()
print('YES')


n = int(input())
a = []
for i in range(n):
	a.append(input())
gh = set([])
ggh = set([])
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			gh.add(a[i][j])
		else:
			ggh.add(a[i][j])
if len(gh) == 1 and len(ggh) == 1 and (gh != ggh):
	print('YES')
else:
	print('NO')


n = int(input())
bl = True
uniq = set()
k = 0
for i in range(n):
	l = list(input())
	if l[k] != l[n - k - 1]:
		bl = False
	uniq.add(l[k])
	for j in range(n):
		if j == k or j == n - k - 1:
			continue
		if l[k] == l[j]:
			bl = False
		uniq.add(l[j])
	if len(uniq) != 2:
		bl = False
	k += 1
if bl is True:
	print('YES')
else:
	print('NO')


n = int(input().strip())
ll = []
for i in range(n):
	ll.append(input().strip())
k0 = ll[0][0]
k1 = ll[0][1]
t = True
if k1 != k0:
	for i in range(n):
		if ll[i][i] != k0:
			t = False
			break
	j = n - 1
	k = 0
	for i in range(n):
		if ll[k][j] != k0:
			t = False
			break
		j -= 1
		k += 1
	for i in range(n):
		for j in range(n):
			if i != j and j != n - 1 - i:
				if ll[i][j] != k1:
					t = False
	print('YES' if t == True else 'NO')
else:
	print('NO')


n = int(input())
mat = []
for i in range(n):
	mat.append(list(map(str, input())))
a = mat[0][0]
b = mat[0][1]
flag = False
if a == b:
	flag = True
for i in range(n):
	for j in range(n):
		if flag == False:
			if i == j or n - i - 1 == j:
				if mat[i][j] == a:
					pass
				else:
					flag = True
					break
			elif mat[i][j] == b:
				pass
			else:
				flag = True
				break
if flag:
	print('NO')
else:
	print('YES')


col = int(input())
for i in range(col):
	line = input()
	if i == 0:
		a = line[0]
		b = line[1]
		if a == b:
			print('NO')
			break
	st = 0
	ed = col - 1
	while st <= ed:
		if st == i or ed == i:
			ch = a
		else:
			ch = b
		if line[st] != ch or line[ed] != ch:
			break
		st += 1
		ed -= 1
	if st <= ed:
		print('NO')
		break
else:
	print('YES')


n = int(input())
for i in range(n):
	line = input()
	if i == 0:
		char = line[0]
		ch_set = set(line[1:-1])
	if line[i] != line[-(i + 1)] or line[i] != char:
		print('NO')
		exit()
	if i == 0 or i == n - 1:
		line = line[1:-1]
	elif i < n - i - 1:
		line = line[:i] + line[i + 1:-(i + 1)] + line[-i:]
	elif i > n - i - 1:
		line = line[:-(i + 1)] + line[-i:i] + line[i + 1:]
	else:
		line = line[:i] + line[i + 1:]
	if len(set(line)) != 1 or set(line) != ch_set or line[0] == char:
		print('NO')
		exit()
print('YES')


n = int(input())
s = [input() for _ in range(n)]
(x, nx) = (s[0][0], s[0][1])
ok = x != nx
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if s[i][j] != x:
				ok = 0
		elif s[i][j] != nx:
			ok = 0
print('YES' if ok else 'NO')


n = int(input())
k = n * 2 - 1
matrix = []
for i in range(n):
	raw = list(input())
	matrix.append(raw)
l1 = matrix[0][0]
for i in range(n):
	if matrix[i][i] != l1 or matrix[i][n - i - 1] != l1:
		print('NO')
		exit()
dict = {}
for i in matrix:
	for j in i:
		if j in dict:
			dict[j] += 1
		else:
			dict[j] = 1
if len(dict) != 2:
	print('NO')
	exit()
if dict[l1] == k:
	print('YES')
else:
	print('NO')


n = int(input())
matrix = []
for i in range(n):
	x = list(input())
	matrix.append(x)
t1 = matrix[0][0]
t2 = matrix[0][1]
true_false = 1
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if matrix[i][j] != t1:
				true_false = 0
				break
		elif matrix[i][j] != t2:
			true_false = 0
			break
if true_false == 1 and t1 != t2:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	s = input()
	a.append(s)
a1 = a[0][0]
a2 = a[0][1]
if a1 == a2:
	print('NO')
else:
	f = 1
	for i in range(n):
		for j in range(n):
			if j == i or j == n - i - 1:
				if a[i][j] != a1:
					f = 0
					break
			elif a[i][j] != a2:
				f = 0
				break
		if f == 0:
			break
	if f == 0:
		print('NO')
	else:
		print('YES')


t = []
n = int(input())
for k in range(n):
	a = list(input())
	t.append(a)
u = []
for j in range(n):
	u.append(t[j][j])
	t[j][j] = '0'
	i = n - 1 - j
	if i != j:
		u.append(t[i][j])
		t[i][j] = '0'
if len(set(u)) == 1:
	h = 0
	f = ''
	for j in t:
		if u[0] not in j:
			pass
		else:
			print('NO')
			h += 1
			break
		f += ''.join(j)
	if h == 0 and len(set(list(f))) == 2:
		print('YES')
	elif h == 0:
		print('NO')
else:
	print('NO')


def tablica(a):
	lst1 = [a[i][i] for i in range(len(a[0]))]
	lst2 = [a[len(a[0]) - 1 - i][i] for i in range(len(a[0]) - 1, -1, -1)]
	flag = 0
	for i in range(len(a[0])):
		for j in range(len(a[0])):
			if i != j and a[i][j] == a[0][1]:
				flag += 1
	if flag == len(a[0]) * len(a[0]) - len(lst1) - len(lst2) + 1 and lst1 == lst2 and all((x == lst1[0] for x in lst1)) and all((x == lst2[0] for x in lst2)):
		return 'YES'
	return 'NO'
n = int(input())
b = list()
for z in range(n):
	s = input()
	b.append(list(s))
print(tablica(b))


n = int(input())
a = []
for i in range(n):
	s = input()
	a.append(s)
x = a[0][0]
y = a[0][1]
l = 0
if x != y:
	for i in range(n):
		for j in range(n):
			if i == j or n - j - 1 == i:
				if x != a[i][j]:
					print('NO')
					l = 1
					break
			elif y != a[i][j]:
				print('NO')
				l = 1
				break
		if l == 1:
			break
	else:
		print('YES')
else:
	print('NO')


n = int(input())
mat = []
for j in range(n):
	mat.append(str(input()))
output = 'YES'
if mat[0][0] == mat[0][1]:
	output = 'NO'
for j in range(n):
	for k in range(n):
		if j == k or k == n - j - 1:
			if mat[j][k] != mat[0][0]:
				output = 'NO'
				break
		elif mat[j][k] != mat[0][1]:
			output = 'NO'
			break
	if output == 'NO':
		break
print(output)


n = int(input())
s = set()
count = 0
l = []
count2 = 0
for i in range(n):
	l.append(input())
for i in range(n):
	s.add(l[i][i])
	s.add(l[n - 1 - i][i])
	count += l[i].count(l[0][0])
	count2 += l[i].count(l[0][1])
if len(s) != 1:
	print('NO')
elif count == 2 * n - 1 and count2 == n * n - 2 * n + 1:
	print('YES')
else:
	print('NO')


n = int(input())
d = None
nd = None
stat = True
depth = 0
for i in range(1, n + 1):
	inns = input()
	ins = []
	for x in inns:
		ins.append(x)
	if i == 1:
		d = ins[0]
		nd = ins[1]
	for j in range(0, n):
		if j + 1 == i or len(ins) - depth - 1 == j:
			if ins[j] != d:
				stat = False
		elif ins[j] != nd:
			stat = False
	depth += 1
print('YES' if stat == True and d != nd else 'NO')


n = int(input())
l = []
for i in range(n):
	l.append(list(input()))
c = ''
for i in l:
	c += ''.join(i)
a = c.count(str(l[0][0]))
b = len(set(list(c)))
p = l[0][0]
if l[0][0] == l[n - 1][n - 1] == l[n - 1][0] == l[0][n - 1] and a == n * 2 - 1 and (b == 2):
	ans = 'YES'
	for j in range(n):
		if l[j][j] != p or l[n - j - 1][j] != p:
			ans = 'NO'
	print(ans)
else:
	print('NO')


n = int(input())
grid = []
for i in range(n):
	grid.append(input())
diag = grid[0][0]
other = grid[0][1]
good = True
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if grid[i][j] != diag:
				good = False
		elif grid[i][j] != other:
			good = False
if diag != other and good:
	print('YES')
else:
	print('NO')


n = int(input())
arr = [list(input()) for i in range(n)]
(i, j) = (0, n - 1)
x = arr[0][0]
o = arr[0][1]
no = False
for row in arr:
	if row[i] != x or row[j] != x:
		no = True
		break
	if row.count(o) != n - 2 and i != j:
		no = True
		break
	elif i == j and row.count(o) != n - 1:
		no = True
		break
	i += 1
	j -= 1
if no:
	print('NO')
else:
	print('YES')


n = int(input())
j = n - 1
f = 0
list1 = []
list2 = []
for i in range(n):
	a = input()
	if i == 0:
		x = a[0]
	d = len(a)
	for k in range(d):
		if k == i or k == j - i:
			list1.append(a[k])
		else:
			list2.append(a[k])
list2 = list(set(list2))
list1 = list(set(list1))
if len(list1) == 1 and len(list2) == 1 and (list1 != list2):
	print('YES')
else:
	print('NO')


n = int(input())
ls = list()
for i in range(n):
	ls.append(input())
for i in range(n):
	for j in range(len(ls[0])):
		if i == j or i + j == n - 1:
			if ls[i][j] != ls[0][0]:
				print('NO')
				quit()
		elif ls[i][j] != ls[0][1] or ls[i][j] == ls[0][0]:
			print('NO')
			quit()
print('YES')


x = int(input())
s = []
for n in range(x):
	er = input()
	s.append(er)
l = 1
for n in range(x):
	for k in range(x):
		if n == k or n + k == x - 1:
			if s[n][k] != s[0][0]:
				l = 0
				break
		elif s[n][k] == s[0][0] or s[n][k] != s[0][1]:
			l = 0
			break
	if l == 0:
		break
if l == 0:
	print('NO')
else:
	print('YES')


from sys import stdin, stdout
from collections import deque
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
from random import randint
mod = 1000000007

def solve():
	x = set()
	n = inp()
	s = set()
	for i in range(n):
		l = st()
		s.add(l[i])
		s.add(l[n - i - 1])
		for j in range(n):
			if j == i or j == n - i - 1:
				continue
			x.add(l[j])
	if len(x) == 1 and len(s) == 1:
		if x != s:
			pr('YES')
		else:
			pr('NO')
	else:
		pr('NO')
for _ in range(1):
	solve()


n = int(input())
h = [''] * n
for i in range(n):
	h[i] = input()
c = h[0][0]
d = h[1][0]
b = True
if c == d:
	b = False
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if c != h[i][j]:
				b = False
				break
		elif d != h[i][j]:
			b = False
			break
if b:
	print('YES')
else:
	print('NO')


n = int(input())
flag = 0
line = input()
line = line.strip()
x = line[0]
o = line[1]
if x == o:
	flag = 1
for j in range(1, n - 1):
	if line[j] != o:
		flag = 1
if line[n - 1] != x:
	flag = 1
i = 1
while i < n and flag == 0:
	line = input()
	line = line.strip()
	for j in range(0, n):
		if j == i or j == n - 1 - i:
			if line[j] != x:
				flag = 1
		elif line[j] != o:
			flag = 1
	i = i + 1
if flag == 0:
	print('YES')
else:
	print('NO')


import sys
n = int(input())
z = list()
for i in range(n):
	z.append(input())
if z[0][0] == z[0][1]:
	print('NO')
	sys.exit()
for i in range(n // 2):
	s = z[0][1] * i + z[0][0] + (n - 2 - 2 * i) * z[0][1] + z[0][0] + z[0][1] * i
	if s != z[i]:
		print('NO')
		break
else:
	s = z[0][1] * (n // 2) + z[0][0] + z[0][1] * (n // 2)
	if s != z[n // 2]:
		print('NO')
	else:
		for i in range(n // 2):
			s = z[0][1] * i + z[0][0] + (n - 2 - 2 * i) * z[0][1] + z[0][0] + z[0][1] * i
			if s != z[n - i - 1]:
				print('NO')
				break
		else:
			print('YES')


l = []
d = ''
for i in range(int(input())):
	s = str(input(''))
	d = d + s
	s = list(s)
	if len(set(s)) != 2:
		print('NO')
		exit()
	else:
		l.append(s)
d = set(list(d))
if len(d) != 2:
	print('NO')
	exit()
j = l[int((len(l) - 1) / 2)]
if j[:] != j[::-1]:
	print('NO')
	exit()
for i in range(int((len(l) - 1) / 2)):
	if l[i] != l[-i - 1]:
		print('NO')
		exit()
print('YES')


n = int(input())
a = []
f = False
for i in range(n):
	a.append(input())
	if a[i][i] != a[i][n - 1 - i]:
		f = True
		break
c = a[0][1]
k = n // 2
if not f:
	if c == a[0][0] or a[k][k] != a[0][0]:
		f = True
	else:
		for i in range(n):
			for j in range(n):
				if i != j and j != n - 1 - i:
					if a[i][j] != c:
						f = True
						break
			if f:
				break
if f:
	print('NO')
else:
	print('YES')


n = int(input())
m = []
for i in range(n):
	l = input()
	m.append(l)
d = m[0][0]
nd = m[0][1]
if d == nd:
	print('NO')
	exit(0)
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if m[i][j] != d:
				print('NO')
				exit(0)
		elif m[i][j] != nd:
			print('NO')
			exit(0)
print('YES')
exit(0)


squares = int(input())

def are_all_same(alphas):
	return len(set(alphas)) == 1
alpha = [input() for i in range(squares)]
diag1 = [alpha[i][j] for i in range(squares) for j in range(squares) if i == j]
diag2 = [alpha[i][j] for i in range(squares) for j in range(squares) if i + j == squares - 1]
non_diagnols = [alpha[i][j] for i in range(squares) for j in range(squares) if i != j and i + j != squares - 1]
if are_all_same(diag1) and are_all_same(diag2) and are_all_same(non_diagnols):
	if non_diagnols[0] != diag1[0] and non_diagnols[0] != diag2[0]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input().strip())
a = []
for i in range(n):
	a.append(input().strip())
ch = a[0][0]
fl = True
for i in range(n):
	if a[i][i] != ch or a[i][n - i - 1] != ch:
		fl = False
		break
ch2 = a[0][1]
if ch == ch2:
	fl = False
for i in range(n):
	for j in range(n):
		if i != j and j != n - i - 1:
			if a[i][j] != ch2:
				fl = False
				break
if fl:
	print('YES')
else:
	print('NO')


n = int(input())
x = []
for i in range(n):
	x.append([])
	c = input()
	for j in range(len(c)):
		x[i].append(c[j])
temp = x[0][0]
temp1 = x[0][1]
flag = 1
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if x[i][j] != temp:
				flag = 0
				break
		elif x[i][j] != temp1:
			flag = 0
			break
	if flag == 0:
		break
if flag == 0 or temp1 == temp:
	print('NO\n')
else:
	print('YES\n')


def solve(page, n):
	diagonal_symbol = set()
	diagonal_index = []
	nonDiagonals = set()
	for (index, i) in enumerate(page):
		diagonal_symbol.add(i[index])
		diagonal_symbol.add(i[n - index - 1])
		diagonal_index.append([index, n - index - 1])
	if len(diagonal_symbol) != 1:
		return 'NO'
	for (index, i) in enumerate(page):
		for j in range(n):
			if j in diagonal_index[index]:
				continue
			else:
				nonDiagonals.add(i[j])
	if len(nonDiagonals) != 1:
		return 'NO'
	if diagonal_symbol == nonDiagonals:
		return 'NO'
	return 'YES'

def main():
	_ = int(input())
	paper = [input() for i in range(_)]
	print(solve(paper, _))
main()


n = int(input())
stack = list()
row_set = set()
for i in range(n):
	row = input()
	if not row_set:
		row_set.update(row)
		if len(row_set) != 2:
			print('NO')
			break
	if set(row) != row_set:
		print('NO')
		break
	if i < n // 2:
		stack.append(row)
	elif i == n // 2:
		if row[:n // 2 + 1] != row[n // 2:][::-1]:
			print('NO')
			break
	elif stack.pop() != row:
		print('NO')
		break
else:
	print('YES')


x = int(input())
z = 0
l = []
h = []
i = 0
while z < x:
	f = input()
	l.append(f[i])
	l.append(f[x - i - 1])
	n = 0
	while n < x:
		if n != i and n != x - i - 1:
			h.append(f[n])
		n += 1
	z += 1
	i += 1
if len(set(l)) != 1 or len(set(h)) != 1 or l[0] == h[0]:
	print('NO')
else:
	print('YES')


n = int(input())
flag = 1
a = []
b = set()
for i in range(n):
	d = input()
	c = set(d)
	b.update(c)
	if len(b) != 2:
		flag = 0
	else:
		a += [d]
if flag == 0:
	print('NO')
else:
	x = a[0][0]
	for i in range(n):
		for j in range(n):
			if j == i or j == n - 1 - i:
				if a[i][j] != x:
					flag = 0
					break
			elif a[i][j] == x:
				flag = 0
				break
	if flag == 0:
		print('NO')
	else:
		print('YES')


n = int(input())
lists = []
z = ''
t = ''
count = 0
newlist = []
for i in range(n):
	z = input()
	t += z
	lists.append(z)
p = 0
k = 0
while k <= n // 2:
	if lists[k][k] == lists[k][-1 - k] == lists[-1 - k][k] == lists[-1 - k][-1 - k] == lists[0][0]:
		count += 1
	k += 1
y = t.count(lists[0][0])
z = t.count(lists[0][1])
for i in t:
	newlist += i
myset = set(newlist)
if count == n // 2 + 1 and len(myset) == 2 and (y == 2 * n - 1):
	print('YES')
else:
	print('NO')


import sys
(mod, MOD) = (1000000007, 998244353)
from math import ceil, floor, log, sqrt, factorial, pi, gcd

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
mat = []
for i in range(n):
	mat.append(list(input()))
alpha = mat[0][0]
for i in range(1, n):
	if mat[i][i] != alpha:
		print('NO')
		exit()
i = 0
j = n - 1
while i < n and j >= 0:
	if mat[i][j] != alpha:
		print('NO')
		exit()
	i += 1
	j -= 1
alpha2 = mat[0][1]
for i in range(n):
	for j in range(n):
		if i + j == n - 1 or i - j == 0:
			continue
		elif mat[i][j] == alpha or mat[i][j] != alpha2:
			print('NO')
			exit()
print('YES')


x = []
n = int(input())
for i in range(n):
	x.append(input())
a = x[0][0]
b = x[0][1]
c = 0
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if x[i][j] == a:
				continue
			else:
				c = 1
				break
		elif x[i][j] == b:
			continue
		else:
			c = 1
			break
	if c == 0:
		continue
	else:
		break
if c == 0 and a != b:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout, exit
import math
from fractions import gcd

def sin():
	return stdin.readline().rstrip()

def listInput():
	return list(map(int, sin().split()))

def printBS(li):
	if not li:
		return
	for i in range(len(li) - 1):
		stdout.write('%d ' % li[i])
	stdout.write('%d\n' % li[-1])
n = int(sin())
mat = []
for _ in range(n):
	mat.append(sin())
cro = mat[0][0]
offdi = mat[0][1]
if cro == offdi:
	print('NO')
	exit(0)
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if cro != mat[i][j]:
				print('NO')
				exit(0)
		elif offdi != mat[i][j]:
			print('NO')
			exit(0)
print('YES')


a = int(input())
l = []
for i in range(a):
	b = input()
	l.append(b)
m = l[0][0]
n = l[0][1]
flag = 0
if m == n:
	print('NO')
else:
	for i in range(a):
		if l[i][i] != m:
			flag = 1
			break
	dia = []
	if flag != 1:
		for i in range(a - 1, -1, -1):
			p = []
			p.append(i)
			p.append(a - 1 - i)
			dia.append(p)
			if l[i][a - 1 - i] != m:
				flag = 1
				break
	if flag != 1:
		for i in range(a):
			for j in range(a):
				m = []
				m.append(i)
				m.append(j)
				if m not in dia and i != j:
					if l[i][j] != n:
						flag = 1
						break
			if flag == 1:
				break
	if flag == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
x = [input() for i in range(n)]
(a, b) = (set(), set())
for i in range(n):
	for j in range(n):
		if i == j or i == n - 1 - j:
			a.add(x[i][j])
		else:
			b.add(x[i][j])
print('YES' if a.pop() != b.pop() and (not a) and (not b) else 'NO')


n = int(input())
s = ''
(x, e) = (set(), set())
for _ in range(n):
	s += input()
for i in range(n):
	for j in range(n):
		if i * n + j == i * n + i or i * n + j == i * n + n - i - 1:
			x.add(s[i * n + j])
		else:
			e.add(s[i * n + j])
if len(x) == 1 and len(e) == 1 and (s[0] != s[1]):
	print('YES')
else:
	print('NO')


n = int(input())
(a, b) = (set(), set())
for i in range(n):
	s = input()
	for j in range(n):
		if i == j or i + j == n - 1:
			a.add(s[j])
		else:
			b.add(s[j])
if len(a) == 1 and len(b) == 1 and (a != b):
	print('YES')
else:
	print('NO')


n = int(input())
a = []
flag = 1
for i in range(n):
	a.append(input())
	for j in range(n):
		if i + j == n - 1 or i - j == 0:
			flag &= a[-1][j] == a[0][0]
		else:
			flag &= (a[-1][j] == a[0][1]) & (a[-1][j] != a[0][0])
if flag:
	print('YES')
else:
	print('NO')


lines = int(input())
grid = []
result = 'YES'
for i in range(lines):
	grid.append(input())
x_char = grid[0][0]
test = ''.join([i for i in grid])
if len(''.join(set(test))) > 2:
	result = 'NO'
else:
	for i in range(lines // 2 + 1):
		if grid[i] != grid[-(i + 1)]:
			result = 'NO'
			break
		if grid[i][i] != grid[i][-(i + 1)]:
			result = 'NO'
			break
		if grid[i][i] != x_char:
			result = 'NO'
			break
		if grid[i].count(x_char) > 2:
			result = 'NO'
			break
if grid[lines // 2].count(x_char) > 1:
	result = 'NO'
print(result)


n = int(input())
lst = []
flag = True
for i in range(n):
	lst.append(str(input()))
for i in range(n):
	for j in range(n):
		if i == j or j == n - 1 - i:
			if lst[i][j] == lst[0][0]:
				continue
			else:
				flag = False
		elif lst[i][j] == lst[0][1]:
			continue
		else:
			flag = False
if lst[0][0] == lst[0][1]:
	flag = False
if flag == True:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for _ in range(n):
	s = input()
	a.append(s)
s = a[0][0]
j = 0
for i in range(n):
	if a[i][j] != s:
		print('NO')
		exit()
	j += 1
j = n - 1
for i in range(n):
	if a[i][j] != s:
		print('NO')
		exit()
	j -= 1
s1 = a[0][1]
if s1 == s:
	print('NO')
	exit()
for i in range(n):
	c = 0
	for j in range(n):
		if a[i][j] == s1:
			c += 1
	if i != n // 2:
		if c != n - 2:
			print('NO')
			exit()
	elif c != n - 1:
		print('NO')
		exit()
print('YES')


n = int(input())
grid = []
c = 0
for i in range(n):
	s = input()
	l = list(s)
	grid.append(l)
start = grid[0][0]
m = grid[0][1]
flag = 0
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if grid[i][j] != start:
				flag = 1
				break
		elif grid[i][j] != m or grid[i][j] == start:
			flag = 1
			break
	if flag == 1:
		break
if flag == 0:
	print('YES')
else:
	print('NO')


(a, b) = (int(input()), [])
for i in range(a):
	b.append(input())
(s1, s2, t) = ('', '', 0)
for i in range(a):
	s1 += b[i][i]
for i in range(a - 1, -1, -1):
	s2 += b[i][a - i - 1]
if s1 == s2 and s1.count(s1[0]) == a:
	for i in b:
		t += i.count(b[0][1])
	if t == a ** 2 - 2 * a + 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
vec = []
for i in range(n):
	vec.append(input())
x = True
r = c1 = 0
c2 = n - 1
letter = vec[0][0]
while r < n:
	if vec[r][c1] != letter or vec[r][c2] != letter:
		x = False
		break
	c1 += 1
	c2 -= 1
	r += 1
if x:
	line = ''.join(vec)
	letters = set([i for i in line])
	if len(letters) != 2 or line.count(letter) != n * 2 - 1:
		x = False
print('YES' if x else 'NO')


n = int(input())
l = []
f = 0
for i in range(n):
	temp = input()
	s = set(temp)
	if len(s) != 2:
		f = 1
	l.append(temp)
if f == 1:
	print('NO')
else:
	flag = 1
	count = 0
	for i in range(0, n // 2 + 1):
		if l[i][i] == l[i][n - i - 1]:
			count += 2
			continue
		else:
			flag = 0
			break
	if flag == 0:
		print('NO')
	else:
		flag = 1
		for i in range(n - 1, n // 2, -1):
			if l[i] == l[n - i - 1]:
				count += 2
				continue
			else:
				flag = 0
				break
		count -= 1
		ac = 0
		for i in range(n):
			for j in range(n):
				if l[i][j] == l[0][0]:
					ac += 1
		if ac != count:
			flag = 0
		if flag == 0:
			print('NO')
		else:
			print('YES')


n = int(input())
s = list(input())
x = s[0]
e = s[1]
if x == e:
	print('NO')
	exit()
for i in range(n):
	if s[i] != x or s[n - 1 - i] != x:
		print('NO')
		exit()
	for j in range(n):
		if j != i and j != n - 1 - i:
			if s[j] != e:
				print('NO')
				exit()
	if i != n - 1:
		s = list(input())
else:
	print('YES')


x = int(input())
s = list((input() for i in range(x)))
(fst, sec) = (s[0][0], s[0][1])
flag = fst != sec
for i in range(x):
	for j in range(x):
		if i == j or i == x - 1 - j:
			if s[i][j] != fst:
				flag = False
		elif s[i][j] != sec:
			flag = False
print('YES' if flag == True else 'NO')


n = int(input())
i = 0
v = 0
h = []
l = []
while i < n:
	a = list(input())
	h.append(a[i])
	if a.count(a[0]) == len(a):
		break
	if a[i] != a[len(a) - i - 1] or h.count(h[0]) != len(h) or a.count(a[i]) > 2:
		break
	if i == n // 2 and a.count(a[i]) != 1:
		break
	k = a[i]
	d = []
	for s in a:
		if s != k:
			l.append(s)
	if l.count(l[0]) != len(l):
		break
	a = 0
	i += 1
if i == n:
	print('YES')
else:
	print('NO')


n = int(input())
L = [input() for k in range(n)]
D = L[0][0]
E = L[0][1]
for k in range(n):
	for j in range(n):
		if k == j:
			if D != L[k][j]:
				print('NO')
				exit()
		elif k == abs(n - 1 - j):
			if D != L[k][j]:
				print('NO')
				exit()
		elif L[k][j] == D:
			print('NO')
			exit()
		elif L[k][j] != E:
			print('NO')
			exit()
print('YES')


n = int(input())
matrix = []
for _ in range(n):
	matrix.append(input())
dia = matrix[0][0]
other = matrix[0][1]
if dia == other:
	print('NO')
	exit()
val = n - 1
for i in range(n):
	for j in range(n):
		if i == j or i + j == val:
			if matrix[i][j] != dia:
				print('NO')
				exit()
		elif matrix[i][j] != other:
			print('NO')
			exit()
print('YES')


n = int(input())
flag = True
line = input()
if line[0] == line[-1]:
	bgn = line[0]
else:
	flag = False
avr = line[1]
for i in range(n - 3):
	if not line[i + 2] == avr:
		flag = False
		break
if not flag or avr == bgn:
	print('NO')
	return
else:
	for j in range(n - 1):
		line = input()
		k = j + 1
		for t in range(n):
			if (t == k or t == n - k - 1) and (not line[t] == bgn):
				flag = False
				break
			if not (t == k or t == n - k - 1) and (not line[t] == avr):
				flag = False
				break
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
c = 0
d = 0
for x in range(n):
	m = input()
	if len(m) == 1:
		print('YES')
		break
	if x == 0:
		a = m[0]
		b = m[1]
	if m[x] != a or m[n - x - 1] != a:
		c = 1
	for y in range(n):
		if y != x and y != n - x - 1:
			if m[y] != b or m[n - y - 1] != b or m[y] == a:
				d = 1
if c == 1 or d == 1:
	print('NO')
else:
	print('YES')


def calculate(n_dim, matrix):
	diag_equal = True
	rem_equal = True
	diag_elem = matrix[0][0]
	for i in range(n_dim):
		if diag_equal:
			for j in range(n_dim):
				if i == j or i + j == n_dim - 1:
					f = matrix[i][j]
					s = matrix[j][i]
					if f != s or f != diag_elem or s != diag_elem:
						diag_equal = False
						break
	for i in range(n_dim):
		if rem_equal:
			for j in range(n_dim):
				if i != j and i + j != n_dim - 1:
					f = matrix[i][j]
					s = matrix[j][i]
					if f != s or (f == diag_elem or s == diag_elem):
						rem_equal = False
						break
	if diag_equal and rem_equal:
		return 'YES'
	else:
		return 'NO'
num = int(input())
matrix = []
for i in range(num):
	row = list(input())
	matrix.append(row)
result = calculate(num, matrix)
print(result)


n = int(input())
s = []
for i in range(n):
	s.append(input())
flag = True
for i in range(n):
	if s[i][i] != s[0][0] or s[i][n - 1 - i] != s[0][0]:
		flag = False
for i in range(n):
	for j in range(n):
		if i != j and i + j != n - 1:
			if s[i][j] != s[0][1] or s[i][j] == s[i][i]:
				flag = False
if flag:
	print('YES')
else:
	print('NO')


n = int(input())
(s1, s2) = (set({}), set({}))
for i in range(n):
	a = input()
	for j in range(n):
		if i == j or i + j == n - 1:
			s1.add(a[j])
		else:
			s2.add(a[j])
print('YES' if len(set(s1)) * len(set(s2)) == 1 and s1.pop() != s2.pop() else 'NO')


n = int(input())
A = [input() for _ in range(n)]
x = A[0][0]
a = A[0][1]
if x != a:
	msg = 'YES'
	for i in range(n):
		for j in range(n):
			if i == j or i == n - j - 1:
				if A[i][j] != x:
					msg = 'NO'
					break
			elif A[i][j] != a:
				msg = 'NO'
				break
else:
	msg = 'NO'
print(msg)


rep = int(input())
arr = []
estado = True
palabra = input()
letra = palabra[0]
extra = palabra[1]
contador = 0
arr.append(palabra)
if letra == extra:
	estado = False
if palabra[rep - 1] != letra:
	estado = False
for x in range(rep - 2):
	if palabra[x + 1] != extra and palabra[rep - x - 2] != extra:
		estado = False
for x in range(rep - 1):
	palabra = input()
	if palabra[x + 1] == letra and palabra[rep - 2 - x] == letra:
		for y in range(rep):
			if palabra[y] == extra or x + 1 == y or rep - 2 - x == y:
				arr.append(palabra)
			else:
				estado = False
				break
	else:
		estado = False
		break
if estado:
	print('YES')
else:
	print('NO')


n = int(input())
strings = []
counter = 0
isDiagonal = True
isOthers = True
while counter < n:
	strings.append(input())
	counter += 1
others = strings[0][1]
diagonal = strings[0][0]
for i in range(n):
	for j in range(n):
		if j == i + 0 or j == n - 1 - i:
			continue
		elif strings[i][j] != others:
			isOthers = False
			break
	if not isOthers:
		break
if isOthers:
	for i in range(n):
		if strings[i][0 + i] != diagonal or strings[i][n - (1 + i)] != diagonal:
			isDiagonal = False
			break
if not isDiagonal or not isOthers or diagonal == others:
	print('NO')
else:
	print('YES')


n = int(input())
l = list()
for i in range(n):
	l.append(list(input()))
diag = l[0][0]
mid = l[0][1]
result = True
for i in range(1, n):
	if l[i][i] != diag:
		result = False
		break
for i in range(n - 1, -1, -1):
	if l[n - 1 - i][i] != diag:
		result = False
		break
if result:
	temp = 0
	for i in range(n):
		temp += l[i].count(mid)
	if n % 2 == 0:
		if temp != n * n - n * 2:
			result = False
	elif temp != n * n - n * 2 + 1:
		result = False
if result:
	print('YES')
else:
	print('NO')


n = int(input())
data = []
for _ in range(n):
	data.append(list(input()))
x = data[0][0]
o = data[1][0]
if x == o:
	print('NO')
	exit(0)
for i in range(n):
	for j in range(n):
		if i == j or j == n - i - 1:
			if data[i][j] != x:
				print('NO')
				exit(0)
		elif data[i][j] != o:
			print('NO')
			exit(0)
print('YES')


n = int(input())
matrix = []
for i in range(n):
	matrix.append(list(map(str, input())))
a = matrix[0][0]
b = matrix[0][1]
if a == b:
	print('NO')
	exit(0)
c = n - 1
for i in range(n):
	for j in range(n):
		if i != j and j != c and (matrix[i][j] != b):
			print('NO')
			exit(0)
		elif i == j and matrix[i][j] != a or matrix[i][c] != a:
			print('NO')
			exit(0)
	c = c - 1
print('YES')


(n, r) = (int(input()), '')
for i in range(n):
	r += input()
if len(set(r)) != 2:
	print('NO')
else:
	for i in range(0, n * n, n):
		s = r[i:i + n]
		o = i // n
		if s[o] != r[0] or s[n - 1 - o] != r[0] or s.count(r[0]) > 1 + int(o != n - o - 1):
			exit(print('NO'))
	print('YES')


n = int(input())
l = []
for i in range(n):
	l.append(input())
letter = l[0][0]
sec = l[0][1]
count = 0
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if l[i][j] == letter:
				count += 1
			else:
				break
		elif l[i][j] == sec and l[i][j] != letter:
			count += 1
		else:
			break
if count == n * n:
	print('YES')
else:
	print('NO')


n = int(input())
x = input()

def dummy(i):
	while i < n:
		x = input()
		i += 1
	print('NO')

def check():
	global x
	a = x[0]
	b = x[1]
	if a == b:
		dummy(1)
		return
	string = a + b * (2 * int(n / 2) - 1) + a
	if x == string:
		for i in range(1, int(n / 2)):
			x = input()
			string = b * i + a + b * (2 * (int(n / 2) - i) - 1) + a + b * i
			if x != string:
				dummy(i + 1)
				return
		x = input()
		string = b * int(n / 2) + a + b * int(n / 2)
		if string != x:
			dummy(int(n / 2) + 1)
			return
		i = int(n / 2) - 1
		while i >= 0:
			x = input()
			string = b * i + a + b * (2 * (int(n / 2) - i) - 1) + a + b * i
			if x != string:
				dummy(n - i)
				return
			i -= 1
	else:
		dummy(1)
		return
	print('YES')
	return
y = set(x)
if len(y) > 2:
	dummy(1)
else:
	check()


n = int(input())
l = []
for i in range(n):
	l.append(input())
(x, y) = ([], [])
for i in range(n):
	for j in range(n):
		if j == i or j == n - 1 - i:
			x.append(l[i][j])
		else:
			y.append(l[i][j])
if len(set(x)) == 1 and len(set(y)) == 1 and (x[0] != y[0]):
	print('YES')
else:
	print('NO')


n = int(input())
m = []
for i in range(n):
	m.append(list(input()))
x = m[0][0]
o = m[0][1]
fail = False
if x == o:
	fail = True
for j in range(n // 2):
	if not m[j][j] == x or not m[n - 1 - j][j] == x:
		fail = True
		break
	else:
		m[j][j] = o
		m[n - 1 - j][j] = o
	if not m[j][n - j - 1] == x or not m[n - 1 - j][n - j - 1] == x:
		fail = True
		break
	else:
		m[j][n - j - 1] = o
		m[n - 1 - j][n - j - 1] = o
if m[n // 2][n // 2] != x:
	fail = True
else:
	m[n // 2][n // 2] = o
for line in m:
	for char in line:
		if char != o:
			fail = True
			break
	if fail:
		break
if fail:
	print('NO')
else:
	print('YES')


n = int(input())
s = []
for i in range(n):
	s.append(input())

def func(s):
	a = s[0][0]
	b = s[0][1]
	if a == b:
		print('NO')
		return 0
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if s[i][j] != a:
					print('NO')
					return 0
			elif s[i][j] != b:
				print('NO')
				return 0
	print('YES')
func(s)


n = int(input())
a = [0] * n
for i in range(n):
	a[i] = input()
x1 = a[0][0]
x2 = a[0][1]
can = None
if all((a[i][i] == x1 and a[i][n - 1 - i] == x1 for i in range(n))) and all((a[i][j] == x2 for i in range(n) for j in range(n) if i != j and i + j != n - 1)) and (x1 != x2):
	print('YES')
else:
	print('NO')


n = int(input())
t = 1
a = 0
b = n - 1
pp = 0
qq = 0
oo = 1
for j in range(0, n):
	s = input()
	if t == 1:
		w = s[1]
		q = s[0]
		if w == q:
			oo = 0
		t = 0
	for k in range(0, len(s)):
		if k == a or k == b:
			if s[k] == q or s[k] == q:
				pp = pp + 1
		elif s[k] == w:
			qq = qq + 1
	a = a + 1
	b = b - 1
if pp == n * 2 - 1 and qq == n * n - n * 2 + 1 and (oo != 0):
	print('YES')
else:
	print('NO')


def solve(mat):
	s = mat[0][0]
	p = mat[0][1]
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if mat[i][j] != s:
					return 'NO'
			elif mat[i][j] != p or mat[i][j] == mat[0][0]:
				return 'NO'
	return 'YES'
n = int(input())
mat = []
for i in range(n):
	a = input()
	mat.append(a)
print(solve(mat))


n = int(input())
matrix = []
for i in range(n):
	row = list(input())
	matrix.append(row)
isDiag = True
diag = matrix[0][0]
nonDiag = matrix[0][1]
if diag == nonDiag:
	isDiag = False
for i in range(n):
	row = matrix[i]
	leftToRightDiag = i
	rightToLeftDiag = n - i - 1
	leftDiag = min(leftToRightDiag, rightToLeftDiag)
	rightDiag = max(leftToRightDiag, rightToLeftDiag)
	nonDiagRow = row[:leftDiag] + row[leftDiag + 1:rightDiag] + row[rightDiag + 1:]
	if row[leftDiag] != diag or row[rightDiag] != diag or len([c for c in nonDiagRow if c != nonDiag]) > 0:
		isDiag = False
print('YES' if isDiag else 'NO')


n = int(input())
r = c = n
grid = []
for i in range(n):
	grid.append(list(input()))
cur = grid[0][0]
notcur = grid[0][1]
f = 0
for i in range(r):
	for j in range(c):
		if i == j or i + j == n - 1:
			if grid[i][j] != cur:
				f = 1
				break
		elif grid[i][j] != notcur:
			f = 1
			break
	if f == 1:
		break
if f == 0 and cur != notcur:
	print('YES')
else:
	print('NO')


n = int(input())
s = input()
x = s[0]
d = s[1]
if x == d:
	print('NO')
	exit()
for i in range(1, n - 1):
	if s[i] != s[1]:
		print('NO')
		exit()
if s[n - 1] != s[0]:
	print('NO')
	exit()
for i in range(1, n):
	s = input()
	for j in range(n):
		if i - j == 0 or j + i == n - 1:
			if s[j] != x:
				print('NO')
				exit()
		elif s[j] != d:
			print('NO')
			exit()
print('YES')


from sys import stdin, stdout
n = int(stdin.readline().strip())
square = []
diagonals = []
x = True
for i in range(n):
	row = list(stdin.readline().strip())
	if i != (n - 1) / 2:
		diagonals.append(row[i])
		row[i] = '0'
		diagonals.append(row[n - 1 - i])
		row[n - 1 - i] = '0'
		for item in row:
			if item.isalpha():
				square.append(item)
	else:
		diagonals.append(row[i])
		row[i] = '0'
		for item in row:
			if item.isalpha():
				square.append(item)
diag_copy = diagonals.copy()
a = diagonals.pop(0)
diagonals.append(a)
sq_copy = square.copy()
b = square.pop(0)
square.append(b)
if sq_copy != square or diag_copy != diagonals or sq_copy[0] == diagonals[0]:
	x = False
if x:
	stdout.write('YES')
else:
	stdout.write('NO')


a = int(input())
s = []
for i in range(a):
	s.append(list(input()))
b = set()
for i in range(0, a):
	b.add(s[i][i])
	b.add(s[i][a - i - 1])
if len(b) != 1:
	print('NO')
else:
	check = s[1][0]
	ans = True
	for i in range(0, a):
		for j in range(0, a):
			if i == j or j == a - i - 1:
				continue
			elif s[i][j] != check or s[i][j] == s[0][0]:
				ans = False
	if ans:
		print('YES')
	else:
		print('NO')


n = int(input())
grid = []
for i in range(n):
	grid.append(input())
x = grid[0][0]
o = grid[0][1]
if x == o:
	print('NO')
else:
	fine = True
	for i in range(n):
		if fine:
			for j in range(n):
				if j == i or j == n - 1 - i:
					if grid[i][j] != x:
						print('NO')
						fine = False
						break
				elif grid[i][j] != o:
					print('NO')
					fine = False
					break
	if fine:
		print('YES')


__copyright__ = ''
__author__ = 'Son-Huy TRAN'
__email__ = 'sonhuytran@gmail.com'
__doc__ = ''
__version__ = '1.0'

def x_me(n: int, inputs: list) -> bool:
	n_minus_1 = n - 1
	first_char = inputs[0][0]
	second_char = inputs[0][1]
	if first_char == second_char:
		return False
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n_minus_1:
				if inputs[i][j] != first_char:
					return False
			elif inputs[i][j] != second_char:
				return False
	return True

def main() -> int:
	n = int(input())
	inputs = []
	for _ in range(n):
		inputs.append(input())
	print('YES' if x_me(n, inputs) else 'NO')
	return 0
exit(main())


n = int(input())
x = []
for i in range(n):
	x.append(input())
sign = x[0][0]
nosign = x[0][1]
l = 0
r = n - 1
good = True
num = True
for i in range(n):
	if x[i][l] != sign and x[i][r] != sign:
		good = False
		break
	else:
		l += 1
		r -= 1
mid = n // 2
for i in range(n):
	csign = x[i].count(sign)
	cnsign = x[i].count(nosign)
	if i != mid:
		if csign == 2 and cnsign == n - 2:
			pass
		else:
			num = False
	elif csign == 1 and cnsign == n - 1:
		pass
	else:
		num = False
if good and num:
	print('YES')
else:
	print('NO')


def solve(l):
	a = l[0][0]
	b = l[0][1]
	if a == b:
		return 'NO'
	length = len(l) - 1
	for (i, line) in enumerate(l):
		for (j, char) in enumerate(line):
			if i == j or length - i == j:
				if char != a:
					return 'NO'
			elif char != b:
				return 'NO'
	return 'YES'
n = int(input())
res = solve([input() for _ in range(n)])
print(res)


n = int(input())
l = []
for i in range(n):
	l.append(list(input()))
x = l[0][0]
y = l[0][1]
if x == y:
	print('NO')
	exit()
else:
	for i in range(n):
		if x == l[i][i] == l[i][-i - 1]:
			l[i][i] = y
			l[i][-i - 1] = y
			if len(set(l[i])) != 1:
				print('NO')
				exit()
		else:
			print('NO')
			exit()
	print('YES')


(n, A, B) = (int(input()), set(), set())
for i in range(n):
	for (j, ch) in enumerate(input()):
		if j in (i, n - i - 1):
			A.add(ch)
		else:
			B.add(ch)
print('YES' if len(A) == len(B) == 1 and A != B else 'NO')


from sys import stdin, stdout
import sys
import math

def get_int():
	return int(stdin.readline().strip())

def get_ints():
	return map(int, stdin.readline().strip().split())

def get_array():
	return list(map(int, stdin.readline().strip().split()))

def get_string():
	return stdin.readline().strip()

def op(c):
	return stdout.write(c)
n = get_int()
ar = []
for i in range(n):
	ar.append(get_string())
x = ar[0][0]
y = ar[0][1]
f = 0
if x == y:
	print('NO')
else:
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if ar[i][j] != x:
					f = 1
					print('NO')
					break
			elif ar[i][j] != y:
				f = 1
				print('NO')
				break
		if f == 1:
			break
	else:
		print('YES')


n = int(input())
k = []
x = 0
w = 0
for i in range(n):
	row = list(str(input()))
	k.append(row)
for i in range(n):
	for j in range(n):
		if i == j and k[i][j] == k[0][0]:
			x += 1
		elif n - 1 == i + j and k[i][j] == k[0][0]:
			x += 1
		if (i != j or n - 1 != i + j) and k[i][j] == k[0][1]:
			w += 1
if x + w == n * n and x == 2 * n - 1:
	print('YES')
else:
	print('NO')


n = int(input())
(s1, s2) = ('', '')
for i in range(n):
	s = input()
	if i == n - i - 1:
		s1 += s[i]
	else:
		s1 += s[i] + s[n - i - 1]
	if i < n - i - 1:
		s2 += s[:i] + s[i + 1:n - i - 1] + s[n - i:]
	else:
		s2 += s[:n - i - 1] + s[n - i:i] + s[i + 1:]
if s1 == s[0] * (n * 2 - 1) and s2 == s[1] * (n * n - n * 2 + 1) and (s[0] != s[1]):
	print('YES')
else:
	print('NO')


n = int(input())
letters = []
for _ in range(n):
	letters.append(input())
diagonalLetter = letters[0][0]
otherLetter = letters[0][1]
result = diagonalLetter != otherLetter
if diagonalLetter != otherLetter:
	for i in range(n):
		for j in range(n):
			expectedLetter = ''
			if j == i or j == n - i - 1:
				expectedLetter = diagonalLetter
			else:
				expectedLetter = otherLetter
			if letters[i][j] != expectedLetter:
				result = False
				break
print('YES' if result else 'NO')


n = int(input())
b = []
for i in range(n):
	a = list(input())
	b.append(a)
(q, w) = (set(), set())
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			q.add(b[i][j])
		else:
			w.add(b[i][j])
if q == w:
	print('NO')
else:
	print(['NO', 'YES'][len(q) == len(w) == 1])


n = int(input())
s = []
for i in range(n):
	s.append(input())
st = s[0][0]
ss = s[0][1]
for i in range(n):
	if s[i][i] != s[i][-1 - i] or (s[i].count(s[i][i]) != 2 and i != n // 2) or (s[i].count(st) != 1 and i == n // 2) or (len(set(list(s[i]))) != 2) or (set(s[i]) != set([st, ss])):
		print('NO')
		exit()
print('YES')


n = int(input(''))
l = []
for i in range(n):
	s1 = input('')
	s1 = list(s1)
	l.append(s1)
count = 0
l1 = []
for i in range(n // 2):
	if l[i] == l[-(i + 1)] and l[0][0] != l[0][1]:
		count += 1
	else:
		print('NO')
		break
if count == n // 2:
	temp = l[0][0]
	temp1 = l[0][1]
	for i in range(len(l[0])):
		if i == n // 2:
			l1.append(temp)
		else:
			l1.append(temp1)
	if l1 == l[n // 2]:
		print('YES')
	else:
		print('NO')


n = int(input())
arr = [str(input()) for i in range(n)]
t = arr[0][0]
u = arr[0][1]
a = 0
b = 0
for j in range(n):
	for k in range(n):
		if arr[j][k] == t and arr[j][n - k - 1] == t:
			a += 1
			break
for j in range(n):
	b += arr[j].count(u)
if a == n and b == n * n - n * 2 + 1:
	print('YES')
else:
	print('NO')


v = []
n = int(input())
for j in range(n):
	v.append(input())
v = ''.join(v)
count1 = v.count(v[0])
count2 = v.count(v[1])
if count1 == n * 2 - 1 and count2 == n ** 2 - (n * 2 - 1):
	if v[:] == v[::-1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


l = []
a = int(input())
for i in range(a):
	l.append(input())
p = l[0][0]
c = 0
u = ''
for i in range(a):
	if l[i][i] == p and l[i][a - i - 1] == p:
		c += 1
	if l[i].count(p) > 2:
		c -= 1
	if l[a // 2].count(p) > 1:
		c -= 1
	u = u + l[i]
if c == a and len(set(u)) < 3:
	print('YES')
else:
	print('NO')


N = int(input())
M = []
for i in range(N):
	M += [input()]
ini = M[0][0]
f = True
for i in range(N):
	if M[i][i] != ini or M[N - i - 1][i] != ini:
		f = False
		break
ini = M[0][1]
if M[0][0] == ini:
	f = False
if f == False:
	print('NO')
else:
	for i in range(N):
		for j in range(N):
			if j != i and j != N - 1 - i and (M[i][j] != ini):
				f = False
				break
	if f == False:
		print('NO')
	else:
		print('YES')


n = int(input())
k = n // 2
s = input().strip()
x = s[0]
o = s[1]
if x == o or s != x + o * (n - 2) + x:
	print('NO')
else:
	for i in range(2, k + 1):
		s = input().strip()
		if s != o * (i - 1) + x + o * (n - 2 * i) + x + o * (i - 1):
			print('NO')
			break
	else:
		s = input().strip()
		if s != o * k + x + o * k:
			print('NO')
		else:
			for i in range(k, 0, -1):
				s = input().strip()
				if s != o * (i - 1) + x + o * (n - 2 * i) + x + o * (i - 1):
					print('NO')
					break
			else:
				print('YES')


n = int(input())
mat = [[None for i in range(n)] for j in range(n)]
for i in range(n):
	temp = input()
	for j in range(n):
		mat[i][j] = temp[j]
diag = True
elem = mat[0][0]
for i in range(n):
	if mat[i][i] != elem:
		diag = False
		break
	if mat[i][n - 1 - i] != elem:
		diag = False
		break
rest = True
elem = mat[0][1]
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		if i == n - 1 - j:
			continue
		if mat[i][j] != elem:
			rest = False
			break
is_cross = diag and rest and (mat[0][1] != mat[0][0])
print('YES' if is_cross else 'NO')


n = int(input())
l = []
for i in range(n):
	a = list(input())
	l.append(a)
nd = l[0][1]
d = l[0][0]
if nd == d:
	print('NO')
	exit()
c = 0
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if l[i][j] != d or l[i][j] == nd:
				c = c + 1
				print('NO')
				break
		elif l[i][j] != nd or l[i][j] == d:
			c = c + 1
			print('NO')
			break
	if c != 0:
		break
if c == 0:
	print('YES')


n = int(input())
from collections import Counter
mt = []
for i in range(n):
	mt.append(input())
symbol = mt[0][0]
us = Counter()
for i in range(n):
	us[i, i] += 1
	if symbol != mt[i][i]:
		print('NO')
		exit()
(x, y) = (0, n - 1)
while y > -1:
	if mt[x][y] != symbol:
		print('NO')
		exit()
	us[x, y] += 1
	y -= 1
	x += 1
if mt[0][1] == symbol:
	print('NO')
	exit()
symbol = mt[0][1]
for i in range(n):
	for j in range(n):
		if not us[i, j] and symbol != mt[i][j]:
			print('NO')
			exit()
print('YES')


n = int(input())
flag = 0
for i in range(n):
	a = input()
	for j in range(n):
		if i == 0 and j == 0:
			u = a[j]
		elif i == 0 and j == 1:
			v = a[j]
		elif i == j:
			if a[j] != u:
				flag = 1
				break
		elif j == n - i - 1:
			if a[j] != u:
				flag = 1
				break
		elif a[j] != v:
			flag = 1
			break
	if flag == 1:
		break
if flag == 0 and a[0] != a[1]:
	print('YES')
else:
	print('NO')


n = int(input())
(diagSet, leftSet) = (set(), set())
(i, j) = (0, n - 1)
for l in range(0, n):
	line = input()
	for c in range(0, n):
		if c == i or c == j:
			diagSet.add(line[c])
		else:
			leftSet.add(line[c])
	(i, j) = (i + 1, j - 1)
print('YES' if len(diagSet) == 1 and len(leftSet) == 1 and (len(leftSet - diagSet) == 1) else 'NO')


n = int(input())
b = [input() for i in range(n)]
l = b[0][0]
c = b[0][1]
flag = True
for i in range(n):
	if i == n // 2:
		if b[i][i] != l or b[i].count(l) != 1 or b[i].count(c) != n - 1:
			flag = False
			break
	elif b[i][i] != l or b[i][n - 1 - i] != l or b[i].count(l) != 2 or (b[i].count(c) != n - 2):
		flag = False
		break
if flag:
	print('YES')
else:
	print('NO')


import math, sys
size = int(input())
matrix = []
for i in range(0, size):
	x = list(map(str, input()))
	matrix.append(x)
buffer = matrix[0][0]
for i in range(0, size):
	if matrix[i][i] == buffer:
		continue
	else:
		print('NO')
		sys.exit()
buffer = matrix[size - 1][0]
shift = 0
for i in range(size - 1, -1, -1):
	if matrix[shift][i] == buffer:
		shift += 1
		continue
	else:
		print('NO')
		sys.exit()
counter = 0
buffer = matrix[0][1]
for i in range(0, size):
	for j in range(0, size):
		if matrix[i][j] == buffer:
			counter += 1
if counter == size ** 2 - (size * 2 - 1):
	print('YES')
else:
	print('NO')


n = int(input())
first = True
res = 'YES'
for i in range(n):
	line = input()
	if first:
		x = line[0]
		y = line[1]
		first = False
	if x == y:
		res = 'NO'
	for j in range(n):
		if i == j or i == n - 1 - j:
			if line[j] != x:
				res = 'NO'
		elif line[j] != y:
			res = 'NO'
print(res)


n = int(input())
diagnonals = set()
others = set()
l = []
for i in range(n):
	l.append(input())
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			diagnonals.add(l[i][j])
		else:
			others.add(l[i][j])
if len(diagnonals) == 1 and len(others) == 1 and (diagnonals != others):
	print('YES')
else:
	print('NO')


n = int(input())
li = [list(input()) for _ in range(n)]
sdg = set()
se = set()
for i in range(n):
	for j in range(n):
		if i == j or i == n - (j + 1):
			sdg.add(li[i][j])
		else:
			se.add(li[i][j])
print('YES') if len(sdg) == len(se) == 1 and sdg.isdisjoint(se) else print('NO')


n = int(input())
non_diag = set()
diag = set()
for i in range(n):
	letter = input()
	for j in range(n):
		if i == j or i == n - 1 - j:
			diag.add(letter[i])
			diag.add(letter[n - 1 - j])
		else:
			non_diag.add(letter[j])
if len(diag) == 1 and len(non_diag) == 1 and (not diag.intersection(non_diag)):
	print('YES')
else:
	print('NO')


n = int(input())
flag = 0
x_prev = input()
clue = x_prev[1]
clue1 = x_prev[0]
if x_prev[0] != x_prev[-1] or len(set(x_prev)) > 2 or x_prev.count(clue1) > 2:
	print('NO')
	flag = 1
if flag == 0:
	for i in range(1, n):
		x = input()
		if i == n // 2 and x[i] != x_prev[i - 1] or x_prev[i - 1] != x[i] or x_prev[i - 1] != x[-(i + 1)] or (len(set(x_prev)) > 2) or (len(set(x_prev)) == 1) or (x.count(clue) == 0) or (i == n // 2 and x.count(x[i]) > 1) or (x.count(clue1) > 2):
			print('NO')
			break
		x_prev = x
		if i == n - 1:
			print('YES')


n = int(input())
t = []
for i in range(n):
	l = input()
	t.append(l)
p = t[0][0]
q = t[0][1]
c = 0
if p == q:
	print('NO')
else:
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if t[i][j] != p:
					c = 1
					print('NO')
					break
			elif t[i][j] != q:
				c = 1
				print('NO')
				break
		if c == 1:
			break
	if c == 0:
		print('YES')


n = int(input())
a = [0] * n
for i in range(n):
	a[i] = input().split()[0]
x = a[0][0]
fon = a[0][1]
if fon == x:
	print('NO')
else:
	flag = True
	for i in range(n):
		for j in range(n):
			if i == j or i == n - 1 - j:
				if a[i][j] != x:
					flag = False
			elif a[i][j] != fon:
				flag = False
	if flag:
		print('YES')
	else:
		print('NO')


n = int(input())
s = ''
a = []
for _ in range(n):
	u = input()
	a.append(u)
	s += u
se = set(s)
if len(se) != 2:
	print('NO')
	exit()
x = a[0][0]
se.remove(x)
o = se.pop()
for i in range(n):
	for j in range(n):
		if i == j or j == n - i - 1:
			if a[i][j] == x:
				continue
			else:
				print('NO')
				exit()
		elif a[i][j] == o:
			continue
		else:
			print('NO')
			exit()
print('YES')


n = int(input())
s = input()
if len(set(s)) != 2:
	print('NO')
	exit()
t = s[0]
cnt = 0
po = []
for i in s:
	po.append(i)
if s[len(s) - 1] != t:
	print('NO')
	exit()
elif s.count(t) > 2:
	print('NO')
	exit()
else:
	for i in range(n - 1):
		p = input()
		for O in p:
			po.append(O)
		if i == n // 2 - 1:
			if p.count(t) > 1:
				cnt = 0
				break
		if p.count(t) > 2:
			cnt = 0
			break
		elif len(set(p)) != 2:
			cnt = 0
			break
		elif p[i + 1] == t and p[n - (i + 2)] == t:
			cnt += 1
	if len(set(po)) != 2:
		print('NO')
		exit()
	elif cnt == n - 1:
		print('YES')
	else:
		print('NO')


n = int(input())
diag = None
last = None
x = 1
for i in range(n):
	l = list(input())
	if l[i] != l[n - 1 - i]:
		x = 0
		break
	elif diag is None:
		diag = l[i]
	elif diag != l[i]:
		x = 0
		break
	if last is None:
		last = l[i + 1]
		if last == diag:
			x = 0
			break
	for t in range(n):
		if t != i and t != n - 1 - i:
			if l[t] != last:
				x = 0
				break
if x == 0:
	print('NO')
else:
	print('YES')


n = int(input())
c = [0] * 26
a = []
for i in range(n):
	a.append(input().strip())
	for k in a[-1]:
		c[ord(k) - ord('a')] += 1
b = True
for i in range(n):
	if a[i][i] != a[0][0] or a[0][0] != a[i][n - i - 1]:
		b = False
		break
if b == False:
	print('NO')
elif a[0][0] == a[0][1]:
	print('NO')
elif c[ord(a[0][1]) - ord('a')] != n * n - 2 * n + 1:
	print('NO')
else:
	print('YES')


def f():
	n = int(input())
	(k, m) = (n // 2, n - 2)
	t = input()
	(a, b) = (t[0], t[1])
	if a == b:
		return 'NO'
	if t != a + b * m + a:
		return 'NO'
	for i in range(1, k):
		if input() != b * i + a + b * (m - 2 * i) + a + b * i:
			return 'NO'
	if input() != b * k + a + b * k:
		return 'NO'
	for i in range(k - 1, -1, -1):
		if input() != b * i + a + b * (m - 2 * i) + a + b * i:
			return 'NO'
	return 'YES'
print(f())


n = int(input())
letters = []
for i in range(n):
	letters.append(tuple(input()))
is_x = True
diagonal_letter = letters[0][0]
not_diagonal_letter = letters[0][1]
if diagonal_letter != not_diagonal_letter:
	diagonal_indices = [(i, i) for i in range(n)]
	for i in range(n):
		j = n - 1 - i
		diagonal_indices.append((i, j))
	for i in range(n):
		for j in range(n):
			if (i, j) in diagonal_indices and letters[i][j] != diagonal_letter or ((i, j) not in diagonal_indices and letters[i][j] != not_diagonal_letter):
				is_x = False
				break
	if is_x:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


bot = True
n = int(input())
s = [input() for i in range(n)]
print('YES' if len(set(''.join(s))) == 2 and all(((i == j or i == n - j - 1) == (s[i][j] == s[0][0]) for i in range(n) for j in range(n))) else 'NO')


n = int(input())
m = n
matrix = []
totalO = 0
totalS = 0
other = 0
same = 0
NOs = 0
while m > 0:
	t = input()
	if n == m:
		other = t[1]
		same = t[0]
	if t[n - m] == t[m - n - 1] == same:
		m = m - 1
		for i in t:
			if i == other:
				totalO = totalO + 1
			if i == same:
				totalS = totalS + 1
		continue
	else:
		NOs = 1
		print('NO')
		break
if NOs == 0:
	if totalO == n * n - (2 * n - 1) and totalS == 2 * n - 1:
		print('YES')
	else:
		print('NO')


n = int(input())
s = [input() for i in range(n)]
res = 'YES'
for i in range(n):
	for j in range(n):
		if s[0][0] == s[0][1]:
			res = 'NO'
		elif i == j:
			if s[i][j] != s[0][0]:
				res = 'NO'
		elif i + j == n - 1:
			if s[i][j] != s[0][0]:
				res = 'NO'
		elif s[i][j] != s[0][1]:
			res = 'NO'
print(res)


n = int(input())
mat = []
for i in range(0, n):
	mat.append(list(str(input())))
(r, c) = (n, n)
(x, y, z) = (set(), set(), set())
for i in range(n):
	for j in range(n):
		if i == j:
			x.add(mat[i][j])
		elif i == n - j - 1:
			y.add(mat[i][j])
		else:
			z.add(mat[i][j])
if x == y and len(z) == 1 and (z != x):
	print('YES')
else:
	print('NO')


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def main():
	s = []
	n = inp()
	for _ in range(n):
		s.append(input())
	l1 = s[0][0]
	l2 = s[0][1]
	res = 'YES'
	if l1 == l2:
		res = 'NO'
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if s[i][j] != l1:
					res = 'NO'
					break
			elif s[i][j] != l2:
				res = 'NO'
				break
		if res == 'NO':
			break
	print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
g = []
for i in range(n):
	g.append(input())
d = g[0][0]
o = '.'
res = True
for i in range(n):
	for j in range(n):
		if i == j or j == n - 1 - i:
			if g[i][j] != d:
				res = False
		elif o == '.':
			o = g[i][j]
			if o == d:
				res = False
		elif g[i][j] != o:
			res = False
if res:
	print('YES')
else:
	print('NO')


r = int(input())
list1 = []
list2 = []
for i in range(r):
	k = list(map(str, input().split()))
	list1.append(k)
for i in range(len(list1)):
	list2.append([])
	for j in list1[i]:
		for k in range(len(j)):
			list2[i].append(j[k])
v = list2[0][0]
z = list2[0][1]
temp = 1
for i in range(r):
	if list2[i][i] != v:
		temp = 0
		break
if temp == 1:
	b = r - 1
	for i in range(r):
		if list2[i][b] != v:
			temp = 0
			break
		else:
			list2[i][b] = 0
			b -= 1
if temp == 1 and v != z:
	for i in range(r):
		for j in range(r):
			if i != j and list2[i][j] != 0:
				if list2[i][j] != z:
					temp = 0
					break
		if temp == 0:
			break
if v == z:
	temp = 0
if temp == 0:
	print('NO')
else:
	print('YES')


def main():
	n = int(input())
	lines = []
	for _ in range(n):
		lines.append(input())
	y = lines[0][1]
	for i in range(n):
		for j in range(n):
			if i == j or i == n - j - 1:
				continue
			if lines[i][j] != y:
				print('NO')
				return
	x = lines[0][0]
	for i in range(n):
		if lines[i][i] != x or lines[i][n - i - 1] != x:
			print('NO')
			return
	if x == y:
		print('NO')
	else:
		print('YES')
main()


def sol():
	n = int(input())
	m = []
	for i in range(n):
		m.append(input())
	a = m[0][0]
	b = m[0][1]
	if a == b:
		return 'NO'
	for i in range(n):
		for j in range(n):
			if i == j:
				if m[i][j] != a:
					return 'NO'
			elif i + j == n - 1:
				if m[i][j] != a:
					return 'NO'
			elif m[i][j] != b:
				return 'NO'
	return 'YES'
print(sol())


n = int(input())
a = [input() for i in range(n)]

def main():
	(x, y) = (a[0][0], a[0][1])
	if x == y:
		return 'NO'
	for i in range(n):
		for j in range(n):
			if i == j and a[i][j] != x or (i + j + 1 == n and a[i][j] != x) or (i != j and i + j + 1 != n and (a[i][j] != y)):
				return 'NO'
	return 'YES'
print(main())


n = int(input())
f = 0
t = ''
sl = []
for i in range(0, n):
	s = input()
	t += s
	sl.append(s)
x = sl[0][0]
y = sl[0][1]
for j in range(0, n):
	if not (sl[j][j] == x and sl[j][n - j - 1] == x):
		f = 1
if f == 0:
	if t.count(x) + t.count(y) == len(t) and t.count(x) == 2 * n - 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
a = []
for i in range(0, n):
	a.append(input())
x = a[0][0]
y = a[0][1]
flag = 0
count = 0
if x != y:
	for i in range(0, n):
		for j in range(0, n):
			if a[i][j] == x:
				if i == j or j == n - 1 - i:
					flag = flag + 1
			elif a[i][j] == y:
				if i != j or j != n - 1 - i:
					count = count + 1
if flag == 2 * n - 1 and count == n * n - 2 * n + 1:
	print('YES')
else:
	print('NO')


def check(a, b, l):
	if a == b:
		return False
	else:
		for i in range(n):
			for j in range(n):
				if j == i or j == n - i - 1:
					if l[i][j] != a:
						return False
				elif l[i][j] != b:
					return False
	return True
n = int(input())
rip = False
l = []
for i in range(n):
	l.append(input().lower())
a = l[0][0]
b = l[0][1]
if check(a, b, l):
	print('YES')
else:
	print('NO')


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
n = N()
(a, b, d, r) = (list(), list(), 2, 0)
for i in range(n):
	s = input()
	if i < int(n / 2) + n % 2:
		r = n - 1 - i
	else:
		r = i - d
		d += 2
	a.extend([s[i], s[r]] if i != r else s[i])
	b.extend([s[j] for j in range(n) if not s[j] in (s[i], s[r])])
(r, d, a, b) = (len(a), len(b), len(Counter(a)), len(Counter(b)))
if (a != 1 or b != 1) or n ** 2 - r != d:
	print('NO')
else:
	print('YES')


hat = int(input())
lst = []
check = ''
for i in range(hat):
	inp = input()
	check += inp
	if len(set(check)) != 2:
		print('NO')
		quit()
	else:
		lst.append(inp)
char = lst[0][0]
length = 0
for i in check:
	if i == char:
		length += 1
if length != 2 * hat - 1:
	print('NO')
	quit()
score = 0
for i in range(hat):
	if lst[i][i] != char or lst[i][hat - i - 1] != char:
		break
	else:
		score += 1
		continue
if score == hat:
	print('YES')
else:
	print('NO')


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
(n,) = I()
x = 0
char = -1
a = []
d = dd(int)
for i in range(n):
	s = input()
	a.append(s)
	if char == -1:
		char = s[0]
	for i in s:
		d[i] += 1
if d[char] != 2 * n - 1 or len(d) > 2:
	print('NO')
	exit()
c = 0
ans = 'YES'
for i in range(n):
	if not a[i][c] == a[i][n - c - 1] == char:
		ans = 'NO'
		break
	c += 1
print(ans)


n = int(input())
main = []
for i in range(n):
	ans = input()
	main.append(ans)
f = 0
p = set()
o = set()
try:
	for i in range(n):
		for j in range(n):
			if i == j:
				p.add(main[i][j])
			elif i + j == n - 1:
				p.add(main[i][j])
			else:
				o.add(main[i][j])
except:
	pass
if len(o) == 1 and len(p) == 1 and (list(p)[0] != list(o)[0]):
	print('YES')
else:
	print('NO')


n = int(input())
s = ''
for _ in range(n):
	s += input()
print('YES' if s == ''.join(list(reversed(s))) and len(set(s)) <= 2 and (s.count(s[0]) == n * 2 - 1) else 'NO')


def check(li):
	letter_a = li[0][0]
	letter_b = li[0][1]
	if letter_a == letter_b:
		return False
	n = len(li)
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if li[i][j] != letter_a:
					return False
			elif li[i][j] != letter_b:
				return False
	return True
n = int(input())
li = []
for i in range(n):
	li.append(input())
if check(li):
	print('YES')
else:
	print('NO')


n = int(input())
mylist = []
myset = set()
isOk = True
for i in range(n):
	mystr = input()
	ts = set(mystr)
	if len(ts) == 2 and mystr[i] == mystr[-(i + 1)] and isOk:
		tlist = list(mystr)
		mylist.append(tlist)
		tlist[i] = ' '
		tlist[-(i + 1)] = ' '
		myset = myset.union(ts)
		ts = set(tlist)
		myset = myset.union(ts)
		if len(ts) != 2 or len(myset) != 3:
			isOk = False
	else:
		isOk = False
if isOk:
	print('YES')
else:
	print('NO')


n = int(input())
a = n - 1
b = 0
c = 1
u = 0
t = ''
ss = ''
for i in range(n):
	d = input()
	t = t + d[i]
	ss = ss + d[1]
	f = d[a]
	g = d[b]
	l = d[c]
	for j in range(n):
		if a == b and f != t[0]:
			u = 1
		elif j == a:
			if f == g and f != l:
				continue
			else:
				u = 1
		elif j == b:
			if f == g and g != l:
				continue
			else:
				u = 1
		elif d[j] == ss[0]:
			continue
		else:
			u = 1
	a = a - 1
	if b == a:
		b = b
	else:
		b = b + 1
	if c == b:
		c = c - 1
	elif c == a:
		c = c + 1
	else:
		c = c + 1
if u == 0:
	print('YES')
else:
	print('NO')


n = int(input())
x = []
answer = 'YES'
for i in range(0, n):
	x.append(input())
if x != 1:
	m = x[0][0]
	k = x[0][1]
	if m != k:
		for i in range(0, n):
			for j in range(0, n):
				if (j == i or n - 1 - i == j) and x[i][j] != m:
					answer = 'NO'
				elif j != i and n - 1 - i != j and (x[i][j] != k):
					answer = 'NO'
	else:
		answer = 'NO'
print(answer)


import sys
import queue
input = lambda : sys.stdin.readline()

def Main():
	n = int(input())
	d = [None] * n
	for i in range(n):
		d[i] = input().strip()
	valx = d[0][0]
	valr = d[0][1]
	work = True
	for i in range(n):
		for j in range(n):
			if i == j or j == n - (i + 1):
				if d[i][j] != valx:
					work = False
			elif d[i][j] != valr:
				work = False
	if valx == valr:
		work = False
	if work == True:
		print('YES')
	else:
		print('NO')
Main()


n = int(input())
ds = set()
os = set()
for i in range(n):
	inp = input()
	for j in range(n):
		if i == j or i == n - j - 1:
			ds.add(inp[j])
		else:
			os.add(inp[j])
if len(ds) == 1 and len(os) == 1 and (next(iter(ds)) != next(iter(os))):
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	a.append([])
	k = input()
	for j in range(n):
		a[i].append(k[j])
c = 0
r = 0
for i in range(1, n):
	if a[0][0] == a[i][i]:
		c += 1
		a[i][i] = 0
if c == n - 1:
	c = 0
	for i in range(n):
		if a[0][0] == a[i][n - i - 1]:
			c += 1
			a[i][n - i - 1] = 0
	k = a[0][0]
	a[0][0] = 0
	m = a[0][1]
	if c == n - 1:
		for i in range(n):
			for j in range(n):
				if a[i][j] != 0 and a[i][j] != k and (a[i][j] == m):
					r += 1
		if r == n - 1 + (n - 2) * (n - 1):
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


x = int(input())
y = []
b = 0
for i in range(x):
	z = input()
	if i == 0:
		a = z[0]
		c = z[1]
	if a == c:
		b = 1
	y.append(z)
	for j in range(x):
		if j == i or j == x - 1 - i:
			if z[x - 1 - i] != z[i] or z[x - 1 - i] != a or z[i] != a:
				b = 1
				break
		elif z[j] != c:
			b = 1
			break
	if b == 1:
		break
if b == 0:
	print('YES')
else:
	print('NO')


n = int(input())
s = set()
s1 = set()
l = []
for i in range(n):
	l.append(list(input()))
for i in range(n):
	for j in range(n):
		if i == j or j == n - i - 1:
			s.add(l[i][j])
		else:
			s1.add(l[i][j])
if len(s) == 1 and len(s1) == 1 and (s != s1):
	print('YES')
else:
	print('NO')


x = int(input())
l = list()
for i in range(x):
	l.append(list(input()))
flag = 'YES'
for i in range(x):
	for j in range(x):
		if i == j:
			if l[i][i] != l[0][0] or l[i][x - i - 1] != l[0][0]:
				flag = 'NO'
		elif i != j and j != x - i - 1:
			if l[i][j] != l[0][1] or l[i][j] == l[0][0]:
				flag = 'NO'
print(flag)


n = int(input())
l = 0
d = None
o = None
for i in range(n):
	s = input()
	for i in range(len(s)):
		if not d:
			d = s[i]
		elif not o:
			o = s[i]
			if o == d:
				print('NO')
				quit()
		elif l == i or n - l - 1 == i:
			if s[i] != d or s[n - l - 1] != d:
				print('NO')
				quit()
		elif s[i] != o:
			print('NO')
			quit()
	l += 1
print('YES')


n = int(input())
row = []
for i in range(n):
	row.append(input())
diagonal = row[0][0]
other = row[1][0]
if diagonal == other:
	print('NO')
else:
	di = True
	ro = True
	for i in range(n):
		if row[i][i] == row[i][n - 1 - i] and row[i][i] == diagonal:
			continue
		else:
			di = False
			break
	if di:
		for i in range(n):
			for j in range(n):
				if i == j or j == n - 1 - i:
					continue
				elif row[i][j] != other:
					ro = False
					break
		if ro:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


n = int(input())
matrix = []
for i in range(n):
	rowstr = input()
	row = []
	for i in rowstr:
		row.append(i)
	matrix.append(row)
diag = matrix[0][0]
non_diag = matrix[1][0]
count = 0
for i in range(n):
	for j in range(n):
		if i != j:
			if i + j != n - 1:
				if matrix[i][j] != non_diag:
					count += 1
		if i == j or i + j == n - 1:
			if matrix[i][j] != diag:
				count += 1
if diag == non_diag:
	count += 1
if count > 0:
	print('NO')
else:
	print('YES')


n = int(input())
m = []
for _ in range(n):
	m.append(input())
i = 0
b = True
ideal_chr = m[0][1]
dig_chr = m[0][0]
base = True
dig_possible = n + n - 1
other_possible = n * n - dig_possible
if ideal_chr == dig_chr:
	b = False
if b:
	for word in m:
		if word[i] != dig_chr or word[-(i + 1)] != dig_chr:
			b = False
			break
		i += 1
if b:
	(dig_ele, reg_ele) = (0, 0)
	for row in range(n):
		if base:
			for col in range(n):
				if m[row][col] == dig_chr:
					dig_ele += 1
				elif m[row][col] == ideal_chr:
					reg_ele += 1
				else:
					base = False
					break
		else:
			base = False
			break
	if dig_ele != dig_possible:
		b = False
	if reg_ele != other_possible:
		b = False
if b:
	if base:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


import math
rep = int(input())
cont = rep - 1
diferentes = False
linea = False
arr = []
letras = []
for x in range(rep):
	arr.append(input())
for x in range(rep):
	palabra = arr[x]
	palabra2 = arr[cont]
	for y in range(rep):
		letras.append(palabra[y])
	if x == cont:
		break
	if arr[x][x] != arr[x][cont] or arr[cont][x] != arr[cont][cont]:
		diferentes = True
		break
	cont = cont - 1
cont = rep - 1
if diferentes:
	print('NO')
else:
	for x in range(rep):
		palabra = arr[x]
		palabra2 = arr[cont]
		if x == cont:
			if palabra[x] != palabra[x + 1]:
				difs = palabra.count(palabra[x + 1])
				if difs == rep - 1:
					diferentes = False
				else:
					diferentes = True
			else:
				diferentes = True
			break
		if palabra[x] != palabra[x + 1] and palabra2[x] != palabra2[x + 1]:
			difs1 = palabra.count(palabra[x + 1])
			difs2 = palabra2.count(palabra2[x + 1])
			if difs2 == difs1 and difs1 == rep - 2:
				diferentes = False
			else:
				diferentes = True
				break
		else:
			diferentes = True
			break
		cont = cont - 1
	if diferentes:
		print('NO')
	else:
		letras = list(dict.fromkeys(letras))
		if len(letras) != 2:
			print('NO')
		else:
			print('YES')


n = int(input())
data = []
ghotr = set()
other = set()
for i in range(n):
	text = input()
	for index in range(len(text)):
		if index == i:
			ghotr.add(text[index])
		elif index == n - i - 1:
			ghotr.add(text[n - 1 - i])
		else:
			other.add(text[index])
if len(ghotr) == len(other) == 1:
	if ghotr.pop() == other.pop():
		print('NO')
	else:
		print('YES')
else:
	print('NO')


n = int(input())
data = [list(input()) for _ in range(n)]
mid = n // 2
if data[mid][mid] == data[1][0]:
	print('NO')
	exit(0)
for i in range(n):
	for j in range(n):
		if abs(i - mid) == abs(j - mid):
			if data[i][j] != data[mid][mid]:
				print('NO')
				exit(0)
		elif data[i][j] != data[1][0]:
			print('NO')
			exit(0)
print('YES')


def change_char(s, p, r):
	return s[:p] + r + s[p + 1:]
n = int(input())
string = input()
x = string[0]
o = string[1]
t = o * (n - 2)
test = string[n - 1] == x and string[1:-1] == t and (not x == o)
i = 1
while test and i < n:
	string = input()
	a = max(i, n - i - 1)
	b = min(i, n - i - 1)
	if not string[i] == string[n - i - 1] or not string[i] == x:
		test = False
		break
	if not i == n // 2:
		string = change_char(string, a, '')
		string = change_char(string, b, '')
		test = string == t
	else:
		string = change_char(string, i, '')
		test = string == t + o
	i += 1
print('YES') if test else print('NO')


n = int(input())
arr = []
for i in range(n):
	x = input()
	l = []
	for i in range(n):
		l.append(x[i])
	arr.append(l)
d = []
rest = []
for i in range(n):
	d.append(arr[i][i])
	d.append(arr[i][n - i - 1])
for i in range(n):
	for j in range(n):
		if i != j and i != n - j - 1:
			rest.append(arr[i][j])
d = set(d)
rest = set(rest)
if len(d) == 1 and len(rest) == 1 and (d != rest):
	print('YES')
else:
	print('NO')


n = int(input())
table = []
for i in range(n):
	table.append(input())
letter1 = table[0][0]
letter2 = table[0][1]
if letter1 == letter2:
	print('NO')
	exit()
flag = True
for i in range(n):
	for j in range(n):
		if i == j or i + j + 1 == n:
			if table[i][j] != letter1:
				flag = False
				break
		elif table[i][j] != letter2:
			flag = False
			break
	if flag == False:
		break
print('NYOE S'[flag::2])


__author__ = 'Adela'

def main():
	n = int(input())
	diag = 'A'
	other = 'A'
	for i in range(n):
		for (j, ch) in enumerate(input()):
			if diag == 'A':
				diag = ch
			elif other == 'A':
				other = ch
			elif i == j or i == n - 1 - j:
				if ch != diag:
					print('NO')
					return
			elif ch != other:
				print('NO')
				return
	if diag == other:
		print('NO')
	else:
		print('YES')
main()


import sys
n = int(input())
arr = [list(input()) for i in range(n)]
c = arr[0][0]
d = arr[0][1]
if c == d:
	print('NO')
	sys.exit(0)
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if c != arr[i][j]:
				print('NO')
				sys.exit(0)
		elif d != arr[i][j]:
			print('NO')
			sys.exit()
print('YES')


def solve(arr, n):
	diagSet = set()
	otherSet = set()
	for i in range(n):
		for j in range(n):
			if j == i or j == n - i - 1:
				diagSet.add(arr[i][j])
			else:
				otherSet.add(arr[i][j])
	if len(diagSet) == 1 and len(otherSet) == 1 and (diagSet != otherSet):
		return 'YES'
	else:
		return 'NO'
n = int(input())
arr = []
for i in range(n):
	arr.append(input())
result = solve(arr, n)
print(result)


n = int(input())
sx = set()
sy = set()
for i in range(n):
	s = input()
	for j in range(n):
		if i == j or j == n - i - 1:
			sx.add(s[j])
		else:
			sy.add(s[j])
if len(sx) == 1 and len(sy) == 1 and (sx != sy):
	print('YES')
else:
	print('NO')


n = int(input())
arr = [input() for i in range(n)]
diagonal = []
other = []
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			diagonal.append(arr[i][j])
		else:
			other.append(arr[i][j])
a = list(set(diagonal))
b = list(set(other))
if len(a) == 1 and len(b) == 1 and (a[0] != b[0]):
	print('YES')
else:
	print('NO')


import math
n = int(input(''))
valid = True
notXLetter = ''
Letter = ''
for i in range(n):
	line = input('')
	ltr = i
	rtl = n - i - 1
	if i == 0:
		Letter = line[0]
		notXLetter = line[1]
		if Letter == notXLetter:
			valid = False
	if line[ltr] != Letter or Letter != line[rtl]:
		valid = False
	if rtl < ltr:
		(rtl, ltr) = (ltr, rtl)
	for j in range(0, ltr):
		if line[j] != notXLetter:
			valid = False
	for j in range(ltr + 1, rtl):
		if line[j] != notXLetter:
			valid = False
	for j in range(rtl + 1, n):
		if line[j] != notXLetter:
			valid = False
	if valid == False:
		break
if valid == False:
	print('NO')
else:
	print('YES')


(paper, dim) = ([], int(input()))
for i in range(dim):
	paper.append(input())
(priDiag, secDiag) = ('', '')
for i in range(dim):
	priDiag += paper[i][i]
	secDiag += paper[i][dim - 1 - i]
(x, y, otherSquares) = (0, dim - 1, '')
for i in range(dim):
	for j in range(dim):
		if i != j and (not (i == x and j == y)):
			otherSquares += paper[i][j]
	x += 1
	y -= 1
(diagSq, offSq) = (paper[0][0], paper[0][1])
t0 = priDiag == secDiag == diagSq * dim
mul = pow(dim, 2) - (2 * dim - 1)
t1 = otherSquares == offSq * mul
print('YES') if t0 and t1 and (diagSq != offSq) else print('NO')


x = input()
l1 = ''
l2 = ''
y = []
for i in range(0, int(x)):
	y.append(list(input()))
l1 = y[0][0]
l2 = y[0][1]
t = True
if l1 == l2:
	t = False
else:
	for i in range(0, int(x)):
		for j in range(0, int(x)):
			if i == j or i + j == int(x) - 1:
				if y[i][j] != l1:
					t = False
					break
			elif y[i][j] != l2:
				t = False
				break
		if not t:
			break
if t:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	s = list(input())
	a.append(s)
one = a[0][0]
two = a[0][1]
flag = 1
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if a[i][j] != one:
				flag = 0
				break
		elif a[i][j] != two:
			flag = 0
			break
	if flag == 0:
		break
if flag == 1 and one != two:
	print('YES')
else:
	print('NO')


n = int(input())
arr = []
for i in range(n):
	arr.append(list(input()))
dia = arr[0][0]
nor = arr[0][1]
flag = 0
if dia == nor:
	print('NO')
else:
	for i in range(len(arr)):
		for j in range(len(arr)):
			if i == j or i + j == n - 1:
				if arr[i][j] != dia:
					flag = 1
					break
			elif arr[i][j] != nor:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


n = int(input())

def check(d, l, x, o):
	ixf = False
	ix = l.find(x)
	if ix != -1:
		if not ixf and ix == d and (l.rfind(x) == n - d - 1) and (l.count(x) <= 2):
			for j in l.replace(x, ''):
				if o != j:
					return False
			return True
	return False
inp = [input() for _ in range(n)]
(x_, o_) = (inp[0][0], inp[0][1])
for i in range(n):
	if i - 1 >= n // 2:
		if inp[i - 2] != inp[n - i + 1]:
			print('NO')
			exit(0)
	elif not check(i, inp[i], x_, o_):
		print('NO')
		exit(0)
print('YES')


n = int(input())
lst = list()
for i in range(n):
	lst1 = [i for i in input()]
	lst.append(lst1)
dal = set()
dar = set()
other = set()
for i in range(n):
	for j in range(n):
		if i == j:
			dal.add(lst[i][j])
		elif j == n - 1 - i:
			dar.add(lst[i][j])
		else:
			other.add(lst[i][j])
if len(dar) == 1 and len(dal) == 1 and (len(other) == 1) and (dar.pop() != other.pop()):
	print('YES')
else:
	print('NO')


a = []
n = int(input())
for _ in range(n):
	a.append(input())
diag = a[0][0]
ndiag = a[0][1]
flag = False
for i in range(n):
	for j in range(n):
		if i == j or i == n - 1 - j:
			if a[i][j] != diag:
				flag = True
				break
		elif a[i][j] != ndiag:
			flag = True
			break
	if flag:
		break
if diag == ndiag:
	flag = True
if flag:
	print('NO')
else:
	print('YES')


n = int(input())
l = []
mid = int((n - 1) / 2)
status_2 = 0
status_1 = 0
diag = 0
ls = []
ll = []
res = 0
c = []
final = []
for i in range(n):
	l.append(input())
d = l[mid][mid]
for i in range(n):
	if l[i][i] == d:
		status_1 = 1
		ls.append(l[i][i])
	else:
		status_1 = 0
		break
for i in range(int((n - 1) / 2)):
	if l[0 + i][n - 1 - i] == d:
		status_2 = 1
		ls.append(l[0 + i][n - 1 - i])
	else:
		status_2 = 0
		break
	if l[n - 1 - i][0 + i] == d:
		status_2 = 1
		ls.append(l[n - 1 - i][0 + i])
	else:
		status_2 = 0
		break
if status_1 and status_2:
	diag = 1
else:
	diag = 0
for i in range(n):
	c.append(l[i].replace(d, ''))
for i in c:
	final += list(set(i))
for i in range(n):
	if i == mid:
		if len(set(l[i])) == 2 and l[i].count(d) == 1 and (len(set(final)) == 1):
			res = 1
		else:
			res = 0
			break
	elif len(set(l[i])) == 2 and l[i].count(d) == 2 and (len(set(final)) == 1):
		res = 1
	else:
		res = 0
		break
if res and diag:
	print('YES')
else:
	print('NO')


import sys
import itertools
from functools import reduce
from math import gcd, log, ceil
from collections import deque

def test(testcase):
	otherChars = set([])
	crossChars = set([])
	n = int(sys.stdin.readline().strip())
	for i in range(0, n):
		xPos1 = i
		xPos2 = n - 1 - i
		line = sys.stdin.readline().strip()
		for (j, c) in enumerate(line):
			if j == xPos1 or j == xPos2:
				crossChars.add(c)
			elif j != xPos1 and j != xPos2:
				otherChars.add(c)
	if len(otherChars) != 1 or len(crossChars) != 1 or list(crossChars)[0] == list(otherChars)[0]:
		print('NO')
	else:
		print('YES')

def main():
	testcases = 1
	for testId in range(0, testcases):
		test(testId + 1)
main()


def main():
	n = int(input())
	i = 0
	j = n - 1
	c = None
	c2 = None
	flipped = False
	for i in range(n):
		l = list(input())
		if c == None:
			c = l[1]
		for k in range(n):
			if k != i and k != j:
				if l[k] != c:
					return False
		if c2 == None:
			c2 = l[i]
		if c2 == c:
			return False
		if l[i] != l[j] or l[i] != c2:
			return False
		i += 1
		j -= 1
	return True
print('YES' if main() else 'NO')


N = int(input())
table = []
for i in range(N):
	table.append(input())
d = {}
for i in range(N):
	for j in range(N):
		s = table[i][j]
		d[s] = d.get(s, 0) + 1
if len(d) != 2:
	print('NO')
	exit()
diag = set([])
nodiag = set([])
for i in range(N):
	for j in range(N):
		s = table[i][j]
		if i == j or i == N - j - 1:
			diag.add(s)
		else:
			nodiag.add(s)
if len(diag) == 1 and len(nodiag) == 1:
	print('YES')
else:
	print('NO')


n = int(input())
q = [[str(x) for x in input()] for i in range(n)]
s = set()
for r in q:
	for e in r:
		s.add(e)
flag = 1
if len(s) != 2:
	flag = 0
else:
	for i in range(n):
		t = q[i][i]
		x = q[i][n - i - 1]
		if x != t:
			flag = 0
			break
	if flag:
		for i in range(n):
			for j in range(n):
				if j != i and j != n - i - 1:
					if q[i][j] == q[i][i]:
						flag = 0
						break
			if not flag:
				break
print('YES' if flag else 'NO')


n = int(input())
first_diag = ''
sec_diag = ''
x = []
new = []
for i in range(n):
	a = list(input())
	x.append(a)
	new.append(a)
for i in range(n):
	first_diag += x[i][i]
	x[i][i] = '.'
for j in range(n):
	if j == n // 2:
		sec_diag += first_diag[n // 2]
	else:
		sec_diag += x[j][n - j - 1]
		x[j][n - j - 1] = '.'
if first_diag == sec_diag:
	if len(set(first_diag)) != 1:
		print('NO')
		exit()
	m = []
	for a in x:
		m.extend(a)
	n = []
	for r in m:
		if r in 'abcdefghijklmnopqrstuvwxyz':
			n.append(r)
	if len(set(n)) == 1 and first_diag[0] not in set(n):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
mas = []
for i in range(n):
	mas += [input()]
x_symb = mas[0][0]
y_symb = mas[0][1]
if x_symb == y_symb:
	print('NO')
	exit()
for i in range(n):
	for j in range(n):
		if i == j or i == n - 1 - j:
			if mas[i][j] != x_symb:
				print('NO')
				exit()
		elif mas[i][j] != y_symb:
			print('NO')
			exit()
print('YES')


n = int(input())
l1 = []
l2 = []
ruined = 0
for x in range(n // 2):
	l1.append(input())
center = input()
for x in range(n // 2):
	l2.append(input())
l2.reverse()
poss = l1[0][0]
notpos = l1[0][1]
if poss == notpos:
	ruined = 1
elif center != notpos * (n // 2) + poss + notpos * (n // 2):
	ruined = 1
else:
	for x in range(len(l1)):
		if l1[x] != notpos * x + poss + notpos * (n - 2 * x - 2) + poss + notpos * x:
			ruined = 1
			break
		if l2[x] != l1[x]:
			ruined = 1
			break
if not ruined:
	print('YES')
else:
	print('NO')


n = int(input())
mat = []
for _ in range(n):
	mat.append(input())
diag = set()
cross = True
j = n - 1
for i in range(n):
	diag.add((i, i))
	diag.add((i, j))
	if mat[i][i] != mat[0][0] or mat[i][j] != mat[0][0]:
		cross = False
		break
	j -= 1
if not cross or mat[0][0] == mat[0][1]:
	print('NO')
else:
	for i in range(n):
		for j in range(n):
			if (i, j) in diag:
				continue
			if mat[i][j] != mat[0][1]:
				cross = False
	print('YES' if cross else 'NO')


from sys import stdin
n = int(input())
b = True
s = set()
(l, r) = (0, n - 1)
for i in range(n):
	k = list(str(input()))
	for j in k:
		s.add(j)
	if len(s) > 2 or k[l] != k[r] or k.count(k[l]) > 2:
		b = False
	if i == n // 2 and k.count(k[i]) > 1:
		b = False
	l += 1
	r -= 1
print('YES') if b and len(s) == 2 else print('NO')


a = b = int(input())
num = -1
key = 1
for i in range(b):
	l = input()
	a -= 1
	num += 1
	if i == 0:
		z = l[0]
		x = l[1]
		if z == x:
			key = 0
	for u in range(b):
		if u == a or u == num:
			if l[u] != z:
				key = 0
		elif l[u] != x:
			key = 0
if key == 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for i in range(n):
	a.append(input())
canFormAnX = True
i = 0
j = 0
x = a[0][0]
while i < n and j < n:
	if a[i][j] != x:
		canFormAnX = False
		break
	i += 1
	j += 1
i = 0
j = n - 1
while i < n and j >= 0:
	if a[i][j] != x:
		canFormAnX = False
		break
	i += 1
	j -= 1
if canFormAnX == False:
	print('NO')
else:
	y = a[0][1]
	for i in range(n):
		for j in range(n):
			if i != j and i + j != n - 1:
				if a[i][j] != y or a[i][j] == x:
					canFormAnX = False
					break
	if canFormAnX == False:
		print('NO')
	else:
		print('YES')


N = int(input())
matrix = []
for i in range(N):
	matrix.append([x for x in input()])
A = matrix[0][0]
B = matrix[0][1]
for i in range(N):
	for j in range(N):
		if i == j:
			if A != matrix[i][j]:
				print('NO')
				exit()
		elif i == N - 1 - j:
			if A != matrix[i][j]:
				print('NO')
				exit()
		elif B != matrix[i][j] or A == matrix[i][j]:
			print('NO')
			exit()
print('YES')


import sys
from math import *
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
ls = lambda : list(input().strip())
from collections import defaultdict as df
import heapq
infinite = float('inf')
n = int(input())
l = [[] for i in range(n)]
for i in range(n):
	l[i] = ls()
i = 0
j = 0
f = 0
ch = l[0][0]
while i != n:
	if l[i][j] != ch:
		f = 1
		break
	i += 1
	j += 1
i = 0
j = n - 1
while i != n:
	if l[i][j] != ch:
		f = 1
		break
	i += 1
	j -= 1
ch = l[0][1]
if ch == l[0][0]:
	f = 1
for i in range(n):
	for j in range(n):
		if i - j == 0 or i + j == n - 1:
			continue
		if l[i][j] != ch:
			f = 1
			break
if f == 0:
	print('YES')
else:
	print('NO')


counter = int(input())
store = []
for i in range(counter):
	inputArray = list(input())
	store.append(inputArray)
diagonalMeasure = set()
otherMeasure = set()
endPoint = len(store[0]) - 1
for i in range(len(store)):
	for j in range(len(store[0])):
		if i == j:
			diagonalMeasure.add(store[i][j])
			diagonalMeasure.add(store[i][endPoint - i])
		elif j != endPoint - i:
			otherMeasure.add(store[i][j])
if len(diagonalMeasure) == 1 and len(otherMeasure) == 1:
	for x in diagonalMeasure:
		diag = x
	for x in otherMeasure:
		other = x
	if diag != other:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


N = int(input())
Alpha = ''
X = input()
Alpha = X[0]
MySet = set(X)
if X[0] != X[-1] or len(set(X)) > 2 or X.count(Alpha) > 2:
	print('NO')
	exit()
for i in range(1, N):
	X = input()
	MySet = MySet.union(set(X))
	if i == N // 2:
		if X[i] != Alpha or len(MySet) > 2 or X.count(Alpha) > 1:
			print('NO')
			exit()
	elif X[i] != X[-(i + 1)] or len(MySet) > 2 or X.count(Alpha) > 2:
		print('NO')
		exit()
print('YES')


global l, n

def abc():
	x = l[0][0]
	nonx = l[0][1]
	if x == nonx:
		return 'NO'
	sn = n - 1
	for i in range(n):
		for j in range(n):
			if i == j or i + j == sn:
				if l[i][j] != x:
					return 'NO'
			elif l[i][j] != nonx:
				return 'NO'
	return 'YES'
n = int(input())
l = []
for i in range(n):
	l.append(input())
print(abc())


n = int(input())
s = input()
diag = s[0]
notdiag = s[1]
result = 'YES'
if s[-1] != diag:
	result = 'NO'
if s[1:-1] != notdiag * len(s[1:-1]):
	result = 'NO'
if diag == notdiag:
	result = 'NO'
if result == 'YES':
	for i in range(1, n):
		s = input()
		if s[i] != diag or s[-i - 1] != diag:
			result = 'NO'
			break
		if i * 2 + 1 == n:
			line = s[:i] + s[i + 1:]
		else:
			i = min(i, n - i - 1)
			if i:
				line = s[:i] + s[i + 1:-i - 1] + s[-i:]
			else:
				line = s[:i] + s[i + 1:-i - 1]
		if line != notdiag * len(line):
			result = 'NO'
print(result)


n = int(input())
l1 = []
import sys
for i in range(n):
	l1.append(list(input()))
c = l1[0][0]
flag = 0
for i in range(n):
	if l1[i][i] != c:
		print('NO')
		sys.exit()
	if l1[i][n - i - 1] != c:
		print('NO')
		sys.exit()
z = 2 * n - 1
c = l1[0][1]
for item in l1:
	z += item.count(c)
if z == n ** 2:
	print('YES')
else:
	print('NO')


x = int(input())
nums = []
for i in range(x):
	nums.append(list(input()))
vetor = []
vetor2 = []
for i in range(x):
	for j in range(x):
		if i == j or i + j == x - 1:
			vetor.append(nums[i][j])
		else:
			vetor2.append(nums[i][j])
if len(set(vetor)) == 1 and len(set(vetor2)) == 1 and (vetor[0] != vetor2[0]):
	print('YES')
else:
	print('NO')


n = int(input().strip())
arr = [[j for j in input().strip()] for i in range(n)]
(diagonal, other) = ([], [])
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if arr[i][j] not in diagonal:
				diagonal.append(arr[i][j])
		elif arr[i][j] not in other:
			other.append(arr[i][j])
if len(diagonal) == 1 and len(other) == 1:
	if ''.join(diagonal) != ''.join(other):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
list1 = []
for i in range(n):
	ll = list(input())
	list1.append(ll)
set1 = set()
set2 = set()
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			set1.add(list1[i][j])
		else:
			set2.add(list1[i][j])
if len(set1) == 1 and len(set2) == 1 and (set1 != set2):
	print('YES')
else:
	print('NO')


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
Y = lambda : list(map(int, input().split()))
P = lambda : map(int, input().split())
N = lambda : int(input())
n = N()
s = [input() for _ in range(n)]
(x, nx) = (s[0][0], s[0][1])
r = x != nx
for i in range(n):
	for j in range(n):
		if j == i or j == n - 1 - i:
			if s[i][j] != x:
				r = 0
		elif s[i][j] != nx:
			r = 0
	if not r:
		break
print('YNEOS'[not r::2])


n = int(input())
l = 0
r = n - 1
s = input()
dCh = s[0]
nCh = s[1]
ans = True
if dCh == nCh:
	ans = False
if dCh != s[n - 1]:
	ans = False
if ans:
	for i in range(1, n - 1):
		if nCh != s[i]:
			ans = False
			break
if ans:
	for i in range(1, n):
		l = l + 1
		r = r - 1
		s = input()
		if s[l] != dCh or s[r] != dCh:
			ans = False
			print('NO')
			exit()
		for j in range(0, n):
			if s[j] != nCh and j != l and (j != r):
				ans = False
				print('NO')
				exit()
	print('YES')
else:
	print('NO')


n = int(input())
mat = []
for i in range(n):
	mat.append(list(input())[:n])
digonals = []
entire = []
for i in range(n):
	for j in range(n):
		if i == j:
			digonals.append(mat[i][j])
		elif i + j == n - 1:
			digonals.append(mat[i][j])
		else:
			entire.append(mat[i][j])
if len(set(digonals)) == 1 and len(set(entire)) == 1 and (set(digonals) != set(entire)):
	print('YES')
else:
	print('NO')


n = int(input())
a = []
for _ in range(n):
	a.append(list(str(input())))
x = a[0][0]
y = a[0][1]
if x == y:
	print('NO')
else:
	k = 0
	for _ in range(len(a)):
		for i in range(len(a[_])):
			if (_ == i or _ + i == n - 1) and a[_][i] != str(x):
				print('NO')
				k = 1
				break
			if (_ != i and _ + i != n - 1) and a[_][i] != str(y):
				k = 1
				print('NO')
				break
		if k == 1:
			break
	if k == 0:
		print('YES')


n = int(input())
arr = []
for i in range(n):
	arr.append(input())
(d, nd) = (arr[0][0], arr[0][1])
if d == nd:
	print('NO')
else:
	check = 0
	index = n // 2
	for i in range(n):
		for j in range(index + 1):
			if i == j or i + j == n - 1:
				if arr[i][j] == arr[i][n - 1 - j] == d:
					continue
				else:
					check = 1
					break
			elif arr[i][j] != nd or arr[i][n - 1 - j] != nd:
				check = 1
				break
		if check == 1:
			break
	if check == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
res = 'YES'
s = list(input())
chk = s[0]
nul = s[1]
if s[0] != chk or s[n - 1] != chk or s[0] == nul or (s[n - 1] == nul):
	res = 'NO'
s[0] = nul
s[n - 1] = nul
if not all(map(lambda x: x == nul, s)):
	res = 'NO'
if res == 'YES':
	for j in range(1, n):
		s = list(input())
		if s[j] != chk or s[n - 1 - j] != chk or s[j] == nul or (s[n - 1 - j] == nul):
			res = 'NO'
		s[j] = nul
		s[n - 1 - j] = nul
		if not all(map(lambda x: x == nul, s)):
			res = 'NO'
print(res)


def valeraX(n, array, array_copy):
	s = array[0][0]
	r = array[0][1]
	if array[0][0] == array[0][n - 1] and array_copy.count(r) == n ** 2 - (2 * n - 1):
		for i in range(1, n):
			if array[i][i] != s:
				return 'NO'
			if array[i][n - i - 1] != s:
				return 'NO'
		else:
			return 'YES'
	else:
		return 'NO'
n = input()
array = list()
array_copy = list()
for i in range(int(n)):
	y = input()
	array.append(y)
	for j in y:
		array_copy.append(j)
a = valeraX(int(n), array, array_copy)
print(a)


length = int(input())
row = []
response = 'YES'
for i in range(length):
	row.append(list(input()))
	xLetter = row[0][0]
	otherLetter = row[0][1]
if xLetter != otherLetter:
	for i in range(length):
		for j in range(length):
			xLetterPos = i == j or i == length - 1 - j
			otherLetterPos = i != j and i != length - 1 - j
			currentPos = row[i][j]
			if xLetterPos and currentPos != xLetter:
				response = 'NO'
				break
			elif otherLetterPos and currentPos != otherLetter:
				response = 'NO'
				break
else:
	response = 'NO'
print(response)


n = int(input())

def str_to_list(a):
	y = []
	for i in range(len(a)):
		y.append(a[i])
	return y
b = []
for i in range(n):
	c = input()
	b.append(str_to_list(c))
check = 1
for i in range(n):
	if check != 1:
		break
	for j in range(n):
		if j == i or j == n - 1 - i:
			if b[i][j] != b[0][0]:
				check -= 1
				break
		elif b[i][j] != b[0][1]:
			check -= 1
			break
if check == 1 and b[0][0] != b[0][1]:
	print('YES')
else:
	print('NO')


n = int(input())
d1 = ''
d2 = ''
l = []
flag = 1
c = []
for i in range(n):
	a = input()
	l.append(a)
	d1 += a[i]
	d2 += a[n - 1 - i]
if len(set(list(d1))) == 1 and len(set(list(d2))) == 1:
	for j in range(n):
		b = l[j]
		b = list(b)
		for k in range(n):
			if k == j or k == n - 1 - j:
				continue
			c.append(b[k])
			if b[k] == d1[0]:
				flag = 0
				print('NO')
				break
		if flag == 0:
			break
	if flag == 1:
		if len(set(c)) == 1:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


n = int(input())
M = []
for i in range(n):
	s = input()
	M.append(s)
d = M[0][0]
nd = M[0][1]
co = True
if d == nd:
	co = False
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if M[i][j] != d:
				co = False
				break
		elif M[i][j] != nd:
			co = False
			break
	if not co:
		break
if co:
	print('YES')
else:
	print('NO')


n = int(input())
s = []
for i in range(n):
	a = input()
	s.append(a)
dic = []
for i in s:
	for j in i:
		dic.append(j)
dic = set(dic)
if len(dic) > 2:
	print('NO')
elif len(dic) < 2:
	print('NO')
else:
	c = 0
	a = s[0][0]
	for i in range(n):
		for j in range(n):
			if i == j and s[i][j] == a:
				c += 1
			if i + j == n - 1 and s[i][j] == a:
				c += 1
	c1 = 0
	for i in range(n):
		for j in range(n):
			if s[i][j] == a:
				c1 += 1
	if c == 2 * n and c1 == 2 * n - 1:
		print('YES')
	else:
		print('NO')


n = int(input())
a = []
b = []
c = []
for i in range(n):
	a.append(list(input()))
for i in range(n):
	b.append(a[i][i])
	a[i][i] = 1
	b.append(a[i][n - i - 1])
	a[i][n - i - 1] = 1
if len(list(set(b))) > 2:
	print('NO')
	exit()
for i in range(n):
	for j in range(n):
		if a[i][j] != 1:
			c.append(a[i][j])
if len(list(set(c))) == 1 and (not c[0] in b):
	print('YES')
else:
	print('NO')


n = int(input())
(x, y) = (set(), set())
for i in range(n):
	line = input()
	for j in range(n):
		if i == j or i == n - j - 1:
			x.add(line[j])
		else:
			y.add(line[j])
if len(x) == 1 and len(y) == 1 and (x != y):
	print('YES')
else:
	print('NO')


n = int(input())
rows = []
for x in range(n):
	string = input()
	rows.append(list(string))
p = rows[0][0]
q = rows[0][1]
results = 'NO'
if p != q:
	results = 'YES'
	for x in range(n):
		for y in range(n):
			a = rows[x][y]
			condition = x == y or n - x - 1 == y
			if condition and a == p:
				pass
			elif condition:
				results = 'NO'
				break
			elif a == q:
				pass
			else:
				results = 'NO'
				break
		if results == 'NO':
			break
print(results)


n = int(input())
face = list()
for i in range(n):
	face.append(list(str(input())))
char_0 = face[0][0]
char_1 = face[0][1]
if char_0 == char_1:
	print('NO')
else:
	flag = True
	for i in range(n):
		line = [char_1] * n
		line[i] = char_0
		line[n - 1 - i] = char_0
		if line != face[i]:
			flag = False
			break
	if flag:
		print('YES')
	else:
		print('NO')


n = int(input())
b = []
for x in range(n):
	a = input()
	b += a
i = 0
j = n - 1
s = b[0]
v = 0
c = []
d = []
e = []
while v < n * n:
	if v == i:
		if v == n * n // 2:
			j += n - 1
		d.append(b[v])
		i += n + 1
	elif v == j:
		e.append(b[v])
		j += n - 1
	else:
		c.append(b[v])
	v += 1
t = list(set(d))
u = list(set(e))
v = list(set(c))
if len(v) == 1:
	if len(t) == 1 and len(u) == 1 and (t[0] == u[0]) and (t[0] != v[0]):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
dc = None
ndc = None
for i in range(n):
	line = input().strip()
	if not dc or not ndc:
		dc = line[0]
		ndc = line[1]
		if dc == ndc:
			print('NO')
			exit()
	for j in range(n):
		if j == i or j == n - i - 1:
			if line[j] != dc:
				print('NO')
				exit()
		elif line[j] != ndc:
			print('NO')
			exit()
print('YES')


n = int(input())
l = []
se = set()
for i in range(n):
	s = input()
	for j in s:
		se.add(j)
	l.append(list(s))
y = len(se) == 2
if y:
	p = l[0][0]
	t = l[1][0]
	pp = set()
	for i in range(n):
		for j in range(n):
			pp.add((i, j))
	tt = set()
	for i in range(n):
		pp.discard((i, i))
		tt.add((i, i))
	for i in range(n):
		pp.discard((i, n - i - 1))
		tt.add((i, n - i - 1))
	ppp = set()
	for i in pp:
		ppp.add(l[i[0]][i[1]])
	y = len(ppp) == 1 and ppp.pop() == t
	if y:
		ttt = set()
		for i in tt:
			ttt.add(l[i[0]][i[1]])
		y = len(ttt) == 1 and ttt.pop() == p
print('YES' if y else 'NO')


import sys
n = int(input())
c = []
count = 0
if n == 1:
	print('YES')
	sys.exit()

def check_diagonals(c, n, g):
	for i in range(n):
		if c[i][i] != g:
			return 0
	index = 0
	for i in range(n - 1, -1, -1):
		if c[index][i] != g:
			return 0
		index += 1
	return 1

def check_rem(c, n, w):
	for i in range(n):
		for j in range(n):
			if i != j and j != n - i - 1:
				if c[i][j] != w:
					return 0
	return 1
for i in range(n):
	d = list(input())
	c.append(d)
g = c[0][0]
w = c[0][1]
if g == w:
	print('NO')
	sys.exit()
elif check_diagonals(c, n, g) and check_rem(c, n, w):
	print('YES')
else:
	print('NO')


(n, count) = (int(input()), 0)
(c1, c2) = ('', '')
for i in range(n):
	s = input()
	num = 2
	if i == 0:
		(c1, c2) = (s[i], s[i + 1])
	if i == n // 2:
		num = 1
	if s[i] == s[n - i - 1] == c1 and s.count(c1) == num:
		s = s.replace(s[i], '')
		if s.count(c2) != len(s):
			print('NO')
			exit()
	else:
		print('NO')
		exit()
print('YES')


n = int(input())
l = [[] for i in range(n)]
for i in range(n):
	s = input()
	for i in range(len(s)):
		l[i].append(s[i])
l1 = l[0][0]
l2 = l[0][1]
if l1 == l2:
	print('NO')
else:
	r = 0
	for i in range(n):
		for j in range(len(l[0])):
			c = 0
			if i == j or i == n - j - 1:
				if l[i][j] != l1:
					c += 1
			elif l[i][j] != l2:
				c += 1
			if c != 0:
				r = 1
				break
		if r == 1:
			break
	if r == 0:
		print('YES')
	else:
		print('NO')


n = int(input())
s = [input() for i in range(n)]
(x, nx) = (s[0][0], s[0][1])
valid = True
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if s[i][j] != x:
				valid = False
		elif s[i][j] != nx:
			valid = False
print('YES' if valid and x != nx else 'NO')


n = int(input())
arr = [input() for _ in range(n)]
a = arr[0][0]
b = arr[0][1]
if a == b:
	print('NO')
	quit()
j = 0
nn = n - 1
arr2 = []
for i in range(0, n):
	c = ''
	for xx in range(0, n):
		if xx == j or xx == nn:
			c += a
		else:
			c += b
	if i >= n // 2:
		j -= 1
		nn += 1
	else:
		j += 1
		nn -= 1
	arr2.append(c)
if arr2 == arr:
	print('YES')
else:
	print('NO')


n = int(input())
matrix = []
diagf = 0
elemf = 0
for _ in range(n):
	matrix.append(input())
diag = matrix[0][0]
elem = matrix[0][1]
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if matrix[i][j] != diag:
				diagf = 1
				break
		elif matrix[i][j] != elem:
			elemf = 1
			break
	if diagf == 1 or elemf == 1:
		break
if diagf == 1 or elemf == 1 or diag == elem:
	print('NO')
else:
	print('YES')


n = k = int(input())
lt = []
while n != 0:
	n -= 1
	s = input()
	lt.append(s)
n = k
c = lt[0][0]
k = 0
D = {}
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if lt[i][j] != c:
				k = 1
				break
		else:
			D[lt[i][j]] = 1
if len(D) != 1:
	k = 1
elif c in D:
	k = 1
if k == 0:
	print('YES')
else:
	print('NO')


import math
from bisect import bisect_right as br
import sys
input = sys.stdin.readline
n = int(input())
l = []
for i in range(n):
	l.append(list(input()))
x = l[0][0]
y = l[0][1]
flag = True
if x == y:
	flag = False
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if l[i][j] != x:
				flag = False
				break
		elif l[i][j] != y:
			flag = False
			break
	if flag == False:
		break
print('YES') if flag else print('NO')


from collections import Counter
n = int(input())
l = []
temp = []
for _ in range(n):
	l.append(list(input()))
for i in range(n):
	for j in range(n):
		temp.append(l[i][j])
s = Counter(temp)
c = 0
f = 0
for i in s.keys():
	c += 1
	if c > 2:
		f = 1
		print('NO')
		break
check = l[0][0]
if f == 0:
	for i in range(n):
		for j in range(n):
			if i == j and l[i][j] == check:
				f = 0
			elif i + j == n - 1 and l[i][j] == check:
				f = 0
			elif i == j and l[i][j] != check:
				f = 1
				break
			elif i + j == n - 1 and l[i][j] != check:
				f = 1
				break
			elif i != j and i + j != n - 1 and (l[i][j] == check):
				f = 1
				break
		if f == 1:
			print('NO')
			break
	if f == 0:
		print('YES')


n = int(input())
x_letter = ''
o_letter = ''
for i in range(n):
	s = input()
	if i == 0:
		x_letter = s[0]
		o_letter = s[1]
	cnt = n - 1 if i == n - i - 1 else n - 2
	if s[i] != x_letter or s[n - i - 1] != x_letter or s.count(o_letter) != cnt:
		print('NO')
		break
else:
	print('YES')


import sys
import math
import bisect

def solve(A):
	n = len(A)
	s1 = set()
	s2 = set()
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				s1.add(A[i][j])
			else:
				s2.add(A[i][j])
	return len(s1) == 1 and len(s2) == 1 and (s1 != s2)

def main():
	n = int(input())
	A = []
	for i in range(n):
		A.append(input())
	if solve(A):
		print('YES')
	else:
		print('NO')
main()


n = int(input())
li = []
for i in range(1, n + 1):
	li.append(input())
if n == 1:
	print('YES')
	exit()
(diagonal, normal) = (li[0][0], li[0][1])
if diagonal == normal:
	print('NO')
	exit()
f = 1
for i in range(n):
	if li[i][i] != diagonal or li[i][n - i - 1] != diagonal:
		f = 0
		break
if not f:
	print('NO')
	exit()
for i in range(n):
	for j in range(n):
		if j != i and j != n - i - 1:
			if li[i][j] != normal:
				f = 0
				break
	if not f:
		break
print('YES') if f else print('NO')


import sys
import bisect
n = int(input())
rows = []
chex = []
for i in range(n):
	rows.append(input())
	ml = []
	for j in range(n):
		ml.append(0)
	chex.append(ml)
check = 1
for i in range(1, n):
	if rows[i][i] != rows[i - 1][i - 1]:
		check = 0
	chex[i][i] = 1
	chex[i - 1][i - 1] = 1
x = 0
i = n - 1
while i >= 1:
	if rows[i][x] != rows[i - 1][x + 1]:
		check = 0
	chex[i][x] = 1
	chex[i - 1][x + 1] = 1
	i -= 1
	x += 1
s = []
for i in rows:
	for j in i:
		s.append(j)
s.sort()
for i in range(n):
	for j in range(n):
		if rows[i][j] == rows[0][0] and chex[i][j] == 0:
			check = 0
cnt = 0
sz = len(s)
for i in range(0, sz):
	if s[i] != s[i - 1]:
		cnt += 1
if cnt != 2 or check == 0:
	print('NO')
else:
	print('YES')


n = int(input())
left = 0
right = n - 1
nope = False
d = ''
o = ''
can = False
for i in range(n):
	x = input()
	if not nope:
		d = str(x[0])
		o = str(x[1])
		if d == o:
			print('NO')
			break
		nope = True
	if x[left] != x[right] or x[left] != d or x[right] != d:
		print('NO')
		break
	for j in range(n):
		if j != left and j != right and (x[j] != o):
			can = True
			break
	if can:
		print('NO')
		break
	left += 1
	right -= 1
else:
	print('YES')


shape = int(input())
x_matrix = []
flag = 0
for i in range(shape):
	row_string = input()
	x_matrix.append([char for char in row_string])
spec_charac = x_matrix[0][1]
dig_charac = x_matrix[0][0]
for i in range(shape):
	for j in range(shape):
		if i == j:
			if x_matrix[i][j] != dig_charac:
				flag = 1
				break
		elif i + j == shape - 1:
			if x_matrix[i][j] != dig_charac:
				flag = 1
				break
		elif x_matrix[i][j] != spec_charac or x_matrix[i][j] == dig_charac:
			flag = 1
			break
if flag == 1:
	print('NO')
else:
	print('YES')


n = int(input())
(d, nd) = ([], [])
for i in range(n):
	s = input()
	for j in range(n):
		if j == i or j == n - 1 - i:
			d.append(s[j])
		else:
			nd.append(s[j])
if len(set(d)) == len(set(nd)) == 1 and set(d) != set(nd):
	print('YES')
else:
	print('NO')


def read_ints():
	return list(map(int, input().strip().split()))
(n,) = read_ints()
t = [input() for _ in range(n)]

def check():
	if t[0][0] == t[0][1]:
		return False
	for x in range(n):
		if t[x][x] != t[0][0]:
			return False
		if t[x][n - x - 1] != t[0][0]:
			return False
		for y in range(n):
			if x == y or x == n - y - 1:
				continue
			if t[x][y] != t[0][1]:
				return False
	return True
print('YES' if check() else 'NO')


n = int(input())
d = 1
k = 0
for i in range(n):
	s = input()
	if d == 1:
		if k == 0:
			k = 1
			if s[1] * (n - 2) == s[1:n - 1] and s[0] == s[n - 1]:
				c = s[1]
				b = s[0]
			else:
				d = 0
		elif c == b:
			d = 0
		else:
			j = i
			if i > n // 2:
				j = n - i - 1
			if i == n // 2:
				if s != c * j + b + c * (n - j - 1):
					d = 0
			elif s != c * j + b + c * (n - 2 * j - 2) + b + c * j:
				d = 0
if d == 1:
	print('YES')
else:
	print('NO')


side = int(input())
sqre = []
for i in range(side):
	sqre.append(input())
y = 0
for j in range(0, side // 2 + 1):
	if sqre[j] != sqre[side - 1 - j] or sqre[side // 2][j] != sqre[side // 2][side - 1 - j]:
		y = 1
		break
if sqre[0][0] != sqre[side // 2][side // 2]:
	y = 1
if sqre[0][0] == sqre[0][1]:
	y = 1
if y == 0:
	print('YES')
else:
	print('NO')


n = int(input())
s = []
flag1 = 1
flag2 = 1
flag3 = 1
for i in range(n):
	s1 = input()
	s.append(s1)
d = s[0][0]
o = s[0][1]
if d == o:
	print('NO')
else:
	for i in range(n):
		for j in range(n):
			if i == j:
				if s[i][j] != d:
					flag1 = 0
					break
				else:
					continue
			elif j == n - 1 - i:
				if s[i][j] != d:
					flag2 = 0
					break
			elif s[i][j] != o:
				flag3 = 0
				break
	if flag1 and flag2 and flag3:
		print('YES')
	else:
		print('NO')


a = int(input())
b = [[] for i in range(a)]
c = 0
for i in range(a):
	d = input()
	for j in d:
		b[i].append(j)
for i in range(a):
	for j in range(a):
		if b[i][j] != b[i][-j - 1] or len(set(b[i])) != 2 or (i != a // 2 and b[i].count(b[0][0]) != 2) or (i == a // 2 and b[i].count(b[0][0]) != 1) or (b[i] != b[-i - 1]):
			print('NO')
			exit()
print('YES')


n = int(input())
m = n
l = []
while m:
	l.append(list(input()))
	m -= 1
x = l[0][0]
o = l[0][1]
if x == o:
	print('NO')
	exit()
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if l[i][j] != x:
				print('NO')
				exit()
		elif l[i][j] != o:
			print('NO')
			exit()
print('YES')


from sys import stdin, stdout
input = stdin.readline
n = int(input())
tbl = [input()[:-1] for _ in range(n)]
p = tbl[0][0]
c = tbl[0][1]
for i in range(n):
	if p != tbl[i][i] or p != tbl[i][n - i - 1]:
		stdout.write('NO')
		exit(0)
	for j in range(n):
		if tbl[i][j] != c:
			if j != i and j != n - i - 1:
				stdout.write('NO')
				exit(0)
if p != c:
	stdout.write('YES')
else:
	stdout.write('NO')


class CodeforcesTask404ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.text = []

	def read_input(self):
		self.n = int(input())
		for x in range(self.n):
			self.text.append(input())

	def process_task(self):
		full = ''.join(self.text)
		if 1 < len(set([ord(c) for c in full])) <= 2:
			x_text = []
			x = 0
			domc = self.text[0][0]
			for y in range(self.n):
				row = list(self.text[0][1] * self.n)
				row[x] = domc
				row[-x - 1] = domc
				row = ''.join(row)
				x_text.append(row)
				x += 1
			if ''.join(x_text) == full:
				self.result = 'YES'
			else:
				self.result = 'NO'
		else:
			self.result = 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask404ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
x_smb = set()
o_smb = set()
flag_yes = True
for i in range(n):
	next_str = list(str(input()))
	x_smb = x_smb | set([next_str[i], next_str[-i - 1]])
	for j in sorted(list(set((i, n - i - 1))), reverse=True):
		next_str.pop(j)
	o_smb = o_smb | set(next_str)
	if len(x_smb) != 1 or len(o_smb) != 1 or len(x_smb | o_smb) == 1:
		print('NO')
		flag_yes = False
		break
if flag_yes:
	print('YES')


n = int(input())
l1 = list()
res = 'YES'
for i in range(n):
	l1.append(input())
temp = l1[0][0]
temp1 = l1[0][1]
for i in range(int(n / 2)):
	if l1[i] != l1[n - 1 - i] or temp == temp1:
		res = 'NO'
for i in range(n):
	if i == int(n / 2):
		if l1[i][i] != temp or temp == temp1:
			res = 'NO'
	elif l1[int(n / 2)][i] != temp1 or temp == temp1:
		res = 'NO'
print(res)


def main():
	n = int(input())
	temp = 0
	flag = True
	arr = set()
	arr2 = set()
	n1 = n
	while n1:
		string = str(input())
		for i in range(len(string)):
			if i != temp and i != n - 1 - temp:
				arr.add(string[i])
		arr2.add(string[temp])
		arr2.add(string[n - 1 - temp])
		if temp == n - 1 // 2:
			flag = False
		if flag:
			temp += 1
		else:
			temp -= 1
		n1 -= 1
	if len(arr) == 1 and len(arr2) == 1 and (arr != arr2):
		print('YES')
	else:
		print('NO')
	return
main()


def main():
	n = int(input())
	r = k = True
	if n > 2:
		for i in range(n):
			s = input()
			if k:
				if i == 0:
					x = s[0]
					e = s[1]
				if s[i] == s[n - 1 - i] == x and x != e:
					for j in range(n):
						if j != i and j != n - 1 - i:
							if s[j] != e:
								k = r = False
								continue
							else:
								pass
						else:
							continue
				else:
					k = r = False
					continue
			else:
				continue
	elif n % 2 == 0:
		(print('Invalid input'), exit())
	else:
		s = input()
	if r:
		print('YES')
	else:
		print('NO')
main()


n = int(input())
l = []
for i in range(n):
	l.append(input())
a = l[0][0]
b = l[0][1]
if a == b:
	print('NO')
	exit(0)
f = int(0)
for i in range(n):
	for j in range(n):
		if i == j or i == n - 1 - j:
			if l[i][j] != a:
				f = 1
				break
		elif l[i][j] != b:
			f = 1
			break
	if f == 1:
		break
print('YES') if f == 0 else print('NO')


n = int(input())
diag = []
nondiag = []
l = []
for i in range(n):
	g = list(input())
	l.append(g)
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			diag.append(l[i][j])
		else:
			nondiag.append(l[i][j])
diag = list(set(diag))
nondiag = list(set(nondiag))
if len(diag) == 1 and len(nondiag) == 1:
	if diag != nondiag:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())

def Valera_and_X(x):
	ans = 'YES'
	(t, b) = (0, -1)
	z = set()
	while t < int(n / 2) + 1:
		z = z.union(set(x[t]))
		if len(z) != 2:
			ans = 'NO'
			break
		if x[t] != x[b]:
			ans = 'NO'
			break
		if len(set(x[t])) != 2:
			ans = 'NO'
			break
		if len(set(x[b])) != 2:
			ans = 'NO'
			break
		t += 1
		b -= 1
	if ans == 'NO':
		return 'NO'
	else:
		return 'YES' if x[int(n / 2)] == ''.join([i[int(n / 2)] for i in x]) else 'NO'
print(Valera_and_X([input() for s in range(n)]))


n = int(input())
L = [str(input()) for _ in range(n)]
a = L[0][0]
b = L[0][1]
ok = 1
for i in range(n // 2):
	for j in range(n):
		if (j == i or j == n - 1 - i) and L[i][j] != a:
			ok = 0
			break
		elif j != i and j != n - 1 - i and (L[i][j] != b):
			ok = 0
			break
	if ok == 0:
		break
for i in range(n // 2 + 1):
	for j in range(n):
		if (j == n // 2 - i or j == n // 2 + i) and L[n // 2 + i][j] != a:
			ok = 0
			break
		elif j != n // 2 - i and j != n // 2 + i and (L[n // 2 + i][j] != b):
			ok = 0
			break
	if ok == 0:
		break
if ok and a != b:
	print('YES')
else:
	print('NO')


n = int(input())
grid = []
res = 'YES'
for _ in range(n):
	grid.append(input())
if grid[0][0] != grid[0][1]:
	for i in range(n):
		for j in range(n):
			if i + j == n - 1 or i == j:
				if grid[i][j] != grid[0][0]:
					res = 'NO'
					break
			elif grid[i][j] != grid[0][1]:
				res = 'NO'
				break
		if res == 'NO':
			break
else:
	res = 'NO'
print(res)


n = int(input())
s_list = []
for i in range(n):
	put = input()
	s_list.append(put)
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if s_list[i][j] != s_list[0][0]:
				print('NO')
				exit()
		elif s_list[i][j] != s_list[0][1] or s_list[i][j] == s_list[0][0]:
			print('NO')
			exit()
print('YES')


def find(a, n):
	de = a[0][0]
	ce = a[0][n // 2]
	if de == ce:
		return False
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if a[i][j] != de:
					return False
			elif a[i][j] != ce:
				return False
	return True
n = int(input())
a = []
for i in range(n):
	s = input()
	a.append(s)
if find(a, n):
	print('YES')
else:
	print('NO')


s = ''
n = int(input())
for i in range(n):
	s = s + str(input())
check = s[-2]
x = s[-1]
co = n - 2
i = 0
j = 0
k = 0
while i < len(s):
	temp = s[i:i + n]
	if temp[j] == temp[n - j - 1] and temp[j] == x:
		if j == n - j - 1:
			if temp.count(check) == co + 1:
				k = 0
			else:
				k = 1
				break
		elif temp.count(check) == co:
			k = 0
		else:
			k = 1
			break
	else:
		k = 1
		break
	j = j + 1
	i = i + n
if k == 0:
	print('YES')
else:
	print('NO')


n = int(input())
bigl = []
y = 0
f = False
for x in range(n):
	bigl.insert(y, input())
	y += 1
if bigl[0][0] == bigl[0][1]:
	print('NO')
	exit()
for x in bigl[:]:
	for i in x:
		if i != bigl[0][0] and i != bigl[0][1]:
			print('NO')
			exit()
y = 0
if bigl[0][0] == bigl[0][-1]:
	for x in bigl:
		for i in x:
			if i == bigl[0][0]:
				y += 1
		if y > 1 and bigl.index(x) + 1 == (n + 1) // 2:
			print('NO')
			exit()
		if y > 2:
			print('NO')
			exit()
		y = 0
else:
	print('NO')
	exit()
y = 0
while y < n - 1:
	if bigl[y][y] != bigl[y + 1][y + 1]:
		print('NO')
		exit()
	y += 1
y = -1
z = 0
while y > -n:
	if bigl[y][z] != bigl[y - 1][z + 1]:
		print('NO')
		exit()
	y -= 1
	z += 1
print('YES')


def is_x(square, diagonals):
	t = square[0][0]
	if all((square[i][j] == t for (i, j) in diagonals)):
		t = square[0][1]
		for i in range(len(square)):
			for j in range(len(square[0])):
				if (i, j) in diagonals:
					continue
				if square[i][j] != t or square[i][j] == square[0][0]:
					return 'NO'
		return 'YES'
	return 'NO'
n = int(input())
square = list()
for i in range(n):
	t = str(input())
	square.append(t)
diagonals = []
for i in range(n):
	diagonals.append((i, i))
j = n - 1
for i in range(n):
	diagonals.append((i, j))
	j -= 1
ans = is_x(square, diagonals)
print(ans)


n = int(input())
field = [input().strip() for x in range(n)]
for i in range(n):
	for j in range(n):
		if j == i and field[i][j] != field[0][0] or (j == n - 1 - i and field[i][j] != field[0][0]) or (n > 2) * (j not in [i, n - i - 1] and (field[i][j] != field[0][1] or field[i][j] == field[0][0])):
			print('NO')
			exit(0)
print('YES')


j = int(input())
m = []
r2 = []
r3 = []
for i in range(0, j):
	m.append(input().strip())
for a in range(0, j):
	for b in range(0, j):
		if a == b or b == j - a - 1:
			r2.append(m[a][b])
		else:
			r3.append(m[a][b])
r2 = list(set(r2))
r3 = list(set(r3))
if len(r2) == 1 and len(r3) == 1 and (r2 != r3):
	print('YES')
else:
	print('NO')


n = int(input())
a = []
z = 0
for i in range(n):
	b = list(input())
	a.append(b)
c = a[0][0]
d = a[0][1]
e = a[0][len(a) - 1]
if c == d:
	print('NO')
elif c != e:
	print('NO')
else:
	for i in range(len(a)):
		for j in range(len(a)):
			if i == j or i + j == n - 1:
				if a[i][j] == c:
					z += 1
			elif a[i][j] == d:
				z += 1
	if z == n * n:
		print('YES')
	else:
		print('NO')


n = int(input())
paper = []
for i in range(n):
	paper.append(list(input()))
check1 = True
check2 = True
char1 = paper[0][0]
char2 = paper[0][1]
if char2 == char1:
	print('NO')
	exit()
for i in range(n):
	if paper[i][i] != char1 or paper[i][n - 1 - i] != char1:
		check1 = False
		break
if check1:
	for i in range(n):
		for j in range(n):
			if i != j and i + j != n - 1:
				if paper[i][j] != char2:
					check2 = False
					break
if check1 and check2:
	print('YES')
else:
	print('NO')


q1 = 0
m = 0
b = []
lst = []
z = int(input())
for x in range(z):
	c = list(map(str, input()))
	lst.append(c)
q2 = len(lst[0]) - 1
for v in lst:
	if v[q1] not in b:
		b.append(v[q1])
	if v[q2] not in b:
		b.append(v[q1])
	a = lst[0][1]
	v[q1] = a
	v[q2] = a
	q1 += 1
	q2 -= 1
if len(b) != 1 or b[0] == lst[0][0]:
	print('NO')
else:
	for n in range(len(lst)):
		if lst[0] != lst[n]:
			print('NO')
			break
		m += 1
if m == len(lst):
	print('YES')


square_l = int(input())
grid = []
for i in range(square_l):
	row = list(input())
	grid.append(row)
target_letter = grid[0][0]
current = grid[0][1]
marker = True
for i in range(0, square_l):
	if grid[i][i] == target_letter:
		continue
	else:
		marker = False
		break
if marker == True:
	for i in range(1, square_l + 1):
		if grid[-i][i - 1] == target_letter:
			continue
		else:
			marker = False
			break
for i in range(0, square_l):
	for j in range(0, square_l):
		if i != j and i + j != square_l - 1:
			if grid[i][j] != current:
				marker = False
				break
if target_letter == current:
	marker = False
if marker == False:
	print('NO')
else:
	print('YES')


n = int(input())
a = [0] * n
for i in range(n):
	a[i] = input()
m = a[0][0]
s = a[0][1]
for i in range(n):
	if a[i][i] != a[i][-i - 1] or (a[i][i] == a[i][-i - 1] and a[i][i] != m):
		ans = False
		break
	elif a[i].count(s) + a[i].count(m) != n or (a[i].count(m) != 2 and i != n // 2 or (a[i].count(m) != 1 and i == n // 2)):
		ans = False
		break
	ans = True
if ans and m != s:
	print('YES')
else:
	print('NO')


s = []
n = int(input())
z = ''
for _ in range(n):
	x = input()
	y = []
	z += x
	for i in x:
		y.append(i)
	s.append(y)
right = [s[i][i] for i in range(n)]
left = [s[i][n - i - 1] for i in range(n)]
if left == right and len(set(left)) == len(set(right)) == 1:
	l2 = s[0][1]
	if z.count(l2) == pow(n, 2) - (2 * n - 1):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


a = int(input())
l = []
l1 = []
for i in range(a):
	b = input()
	l1.append([b])
	for i in b:
		l.append(i)
k1 = l1[0][0][1]
for i in range(a):
	k = -(i + 1)
	if l1[i][0][i] != l1[i][0][k]:
		print('NO')
		exit()
	for j in range(a):
		if j == i or j == a - 1 - i:
			pass
		elif l1[i][0][j] != k1:
			print('NO')
			exit()
l = set(l)
if l1[a // 2][0][a // 2] != l1[0][0][0]:
	print('NO')
	exit()
if len(l) == 2:
	print('YES')
else:
	print('NO')


n = int(input())
X = True
lines = ''
for i in range(n):
	line = input()
	lines += line
	if line[i] != line[n - i - 1] or line[i] != lines[0]:
		X = False
if not X:
	print('NO')
elif len(set([i for i in lines])) != 2:
	print('NO')
else:
	l = lines[0]
	if len([i for i in lines if i != l]) != n * (n - 2) + 1:
		print('NO')
	else:
		print('YES')


n = int(input())
arr = []
for i in range(n):
	string = input()
	arr.append(string)
x = arr[0][0]
o = arr[0][1]
thex = []
for i in range(n):
	st = ''
	for j in range(n):
		if j == i or j == n - 1 - i:
			st += x
		else:
			st += o
	thex.append(st)
if thex == arr:
	if x == o:
		print('NO')
	else:
		print('YES')
else:
	print('NO')


n = int(input())
paper = []
for i in range(n):
	t = input()
	paper.append(t)
for i in range(n):
	for j in range(n):
		if i == j and paper[i][j] != paper[0][0] or (j == n - i - 1 and paper[i][j] != paper[0][0]):
			print('NO')
			exit()
		elif i != j and i != n - j - 1 and (paper[i][j] != paper[0][1]) or paper[0][1] == paper[0][0]:
			print('NO')
			exit()
print('YES')


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import random
import re
import heapq
n = int(input())
s = list(input())
(x, o) = (s[0], s[1])
if x == o:
	print('NO')
	exit(0)
for i in range(n):
	for c in range(n):
		if c == i or c == n - 1 - i:
			if s[c] != x:
				print('NO')
				exit(0)
		elif s[c] != o:
			print('NO')
			exit(0)
	if i < n - 1:
		s = input()
print('YES')


def diagonal_check(my_board):
	s = len(my_board)
	ch = my_board[0][0]
	for z in range(size):
		if my_board[z][z] != ch or my_board[z][-1 - z] != ch:
			return False
	return True

def other_check(my_board):
	s = len(my_board)
	start = 0
	end = s - 1
	check = ''
	for y in range(s):
		for z in range(s):
			if z == start or z == end:
				continue
			check = check + my_board[y][z]
		start += 1
		end -= 1
	for c in check:
		if c != my_board[0][1] or c == my_board[0][0]:
			return False
	return True
size = int(input())
board = [''] * size
for x in range(size):
	board[x] = input()
diag_check = diagonal_check(board)
if diag_check:
	othr_check = other_check(board)
	if othr_check:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input(''))
g = []
f = True
for i in range(n):
	g.append([d for d in input()])
d_l = g[0][0]
flattened = sum(g, [])
if len(set(flattened)) != 2 or flattened.count(d_l) != n * 2 - 1:
	f = False
	print('NO')
if f:
	for i in range(n):
		if g[i][i] != d_l or g[i][n - i - 1] != d_l:
			print('NO')
			f = False
			break
if f:
	print('YES')


n = int(input())
a = []
for i in range(n):
	a.append(input())
a = ' '.join(a)
if a.count(a[1]) == n ** 2 - (n + n - 1) and a.count(a[0]) == n + n - 1:
	if a[:] == a[::-1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


n = int(input())
matrix = ''
matrices = []
cnt = 0
k = 0
cnt2 = 0
for i in range(n):
	matrix = list(input())
	matrices.append(matrix)
for j in matrices:
	if j[k] == j[n - k - 1] == matrices[0][0]:
		cnt += 1
	k += 1
	for l in j:
		if l == matrices[0][1]:
			cnt2 += 1
if cnt == n and cnt2 == n ** 2 - (2 * (n - 1) + 1):
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for _ in range(n):
	l.append(list(input()))
co = 0
k = l[0][0]
m = l[0][1]
if m == k:
	print('NO')
	exit()
for i in range(n):
	if l[i][i] != k:
		print('NO')
		exit()
	if l[i][n - 1 - i] != k:
		print('NO')
		exit()
for i in range(n):
	for j in range(n):
		if j == i or j == n - 1 - i:
			continue
		elif l[i][j] != m:
			print('NO')
			exit()
print('YES')


a = int(input())
mid = a // 2
b = []
c = []
for i in range(a):
	t = list(input())
	b.append(t)
	for j in t:
		c.append(j)
if len(set(c)) != 2:
	print('NO')
elif c.count(c[0]) != 2 * a - 1:
	print('NO')
elif c.count(c[1]) != a ** 2 - (2 * a - 1):
	print('NO')
elif b[mid][mid] != b[0][0] or b[a - 1][a - 1] != b[0][0]:
	print('NO')
elif b[a - 1][0] != b[mid][mid] or b[a - 1][0] != b[0][a - 1]:
	print('NO')
elif b[0][0] != b[1][1]:
	print('NO')
else:
	print('YES')


import math
n = int(input())
mat = []
for _ in range(n):
	tmp = input()
	mat.append(tmp)
diagonal1 = ''
diagonal2 = ''
chars = ''.join(mat)
if len(set(chars)) != 2:
	print('NO')
else:
	j = n - 1
	for i in range(n):
		diagonal1 += mat[i][i]
		diagonal2 += mat[i][j]
		j -= 1
	if diagonal1 != diagonal2:
		print('NO')
	else:
		ans = 'YES'
		for i in mat:
			if len(set(i)) != 2:
				ans = 'NO'
				break
			else:
				pass
		sample = diagonal1[0]
		mid = math.floor(n / 2)
		for i in range(n):
			if i == mid and mat[i].count(sample) != 1:
				ans = 'NO'
				break
			elif i != mid and mat[i].count(sample) != 2:
				ans = 'NO'
				break
			else:
				pass
		print(ans)


n = int(input())
m = []
for i in range(n):
	s = list(input())
	m.append(s)

def ex(m):
	d = m[0][0]
	o = m[0][1]
	if d == o:
		return 'NO'
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if m[i][j] != d:
					return 'NO'
				else:
					pass
			elif m[i][j] != o:
				return 'NO'
	return 'YES'
print(ex(m))


n = int(input())
A = [input() for _ in range(n)]
if len(set([A[i][j] for i in range(n) for j in range(n)])) == 2:
	ok_x = True
	ok_y = True
	for i in range(n):
		for j in range(n):
			if i == j or i == n - 1 - j:
				ok_x &= A[i][j] == A[0][0]
			else:
				ok_y &= A[i][j] == A[0][1]
	ok = ok_x and ok_y
else:
	ok = False
print('YES' if ok else 'NO')


def bool(mat, n):
	diagonals = set()
	others = set()
	i = 0
	j = 0
	while i < n and j < n:
		diagonals.add(mat[i][j])
		diagonals.add(mat[i][n - i - 1])
		i += 1
		j += 1
	for i in range(n):
		for j in range(n):
			if i == j or j == n - i - 1:
				continue
			others.add(mat[i][j])
	if len(diagonals) == 1 and len(others) == 1 and (diagonals != others):
		return 'YES'
	return 'NO'
n = int(input())
res = []
mat = []
l = []
for _ in range(n):
	l = input()
	res.append(l)
for i in range(n):
	l = []
	for j in range(n):
		l += res[i][j]
	mat.append(l)
print(bool(mat, n))


n = int(input())
L = []
for i in range(n):
	L.append(input())
valid = True
x = 0
y = 0
E = []
p = L[0][0]
while x < n and y < n:
	if L[x][y] != p:
		valid = False
	x += 1
	y += 1
x = 0
y = n - 1
while x < n and y >= 0:
	if L[x][y] != p:
		valid = False
	x += 1
	y -= 1
K = {}
for i in range(n):
	for j in range(n):
		if L[i][j] in K:
			K[L[i][j]] += 1
		else:
			K[L[i][j]] = 1
if not valid or K[p] != 2 * n - 1 or len(K) != 2:
	print('NO')
else:
	print('YES')


n = int(input())
square = []
for i in range(n):
	square.append(list(input()))
diag = square[0][0]
side = square[0][1]
if diag == side:
	print('NO')
else:
	valera = True
	for i in range(n):
		if square[i][i] != diag:
			valera = False
			break
		else:
			square[i][i] = 0
	if valera == True:
		for j in range(n - 1, -1, -1):
			a = n - (j + 1)
			if a == j:
				continue
			if square[a][j] != diag:
				valera = False
				break
			else:
				square[a][j] = 0
	if valera == True:
		case = True
		for x in range(n):
			for y in range(n):
				if square[x][y] == side or square[x][y] == 0:
					continue
				else:
					valera = False
					case = False
					break
			if case == False:
				break
	if valera == False:
		print('NO')
	else:
		print('YES')


n = int(input().strip())
grid = [list(input().strip()) for _ in range(n)]

def solve(grid, n):
	s1 = grid[0][0]
	s2 = grid[0][1]
	if s1 == s2:
		return 'NO'
	for i in range(n):
		for j in range(n):
			if i == 0 and j == 0:
				continue
			if (i == j or n - i - 1 == j) and grid[i][j] != s1:
				return 'NO'
			elif (i != j and n - i - 1 != j) and grid[i][j] != s2:
				return 'NO'
	return 'YES'
print(solve(grid, n))


def findX(length, sheet):
	letter = str(sheet[0][0])
	positionL = 0
	positionR = int(length) - 1
	rowIndex = 0
	letter2 = str(sheet[0][1])
	middle = 0
	cIndex = 0
	if letter2 == letter:
		return 'NO'
	for row in sheet:
		cIndex = 0
		for j in row:
			if j == letter and (cIndex == positionL or cIndex == positionR):
				cIndex += 1
				continue
			if letter2 != j:
				return 'NO'
			cIndex += 1
		if str(sheet[rowIndex][positionL]) == letter and str(sheet[rowIndex][positionR]) == letter:
			rowIndex += 1
			if positionL == positionR:
				middle = 1
			if middle == 1:
				positionL -= 1
				positionR += 1
				continue
			else:
				positionL += 1
				positionR -= 1
				continue
		else:
			return 'NO'
	return 'YES'
num = int(input())
matrix = []
for i in range(num):
	row = str(input())
	matrix.append(row)
print(findX(int(num), matrix))


n = int(input())
a = []
for i in range(n):
	temp = list(input())
	a.append(temp)
sampled = a[1][1]
samplen = a[1][2]
res = True
if sampled == samplen:
	res = False
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			if a[i][j] != sampled:
				res = False
				break
		elif a[i][j] != samplen:
			res = False
			break
	if res == False:
		break
if res == True:
	print('YES')
else:
	print('NO')


num_lines = int(input())
chars = []
for i in range(num_lines):
	current = input()
	chars.append(current.lower())
char_cross = chars[0][0]
char_other = chars[0][1]
result = True
if char_cross == char_other:
	result = False
for i in range(num_lines):
	for j in range(num_lines):
		if i + j == num_lines - 1 or i == j:
			if chars[i][j] != char_cross:
				result = False
		elif chars[i][j] != char_other:
			result = False
if result:
	print('YES')
else:
	print('NO')


def solve(arr, n):
	symbol = arr[0][0]
	for i in range(0, n):
		if arr[i][i] != symbol:
			return 'NO'
	j = 0
	for i in range(n - 1, -1, -1):
		if arr[i][j] != symbol:
			return 'NO'
		j += 1
	return 'YES'
n = int(input())
chars = []
while len(chars) < n:
	s = input()
	chars.append(list(s))
L = sum(chars, [])
amount = set(sum(chars, []))
if len(amount) == 2 and L.count(L[0]) == n * 2 - 1:
	print(solve(chars, n))
else:
	print('NO')


n = int(input())
M = [input() for i in range(n)]
r = M[0][1]
v = M[0][0]
d = n // 2
l = 0
c = 1
k = 0
for i in range(d):
	for j in range(n):
		if l == j and M[i][l] == v and (v != r):
			k = 1
		elif j == n - l - 1 and M[i][n - l - 1] == v and (v != r):
			k = 1
		elif j != l and j != n - l - 1 and (M[i][j] == r) and (v != r):
			k = 1
		else:
			c = 0
			break
	l = l + 1
if n % 2 != 0:
	for i in range(n):
		if M[n // 2][i] == r:
			k = 1
		elif i == n // 2 and M[n // 2][i] == v:
			k = 0
		else:
			c = 0
			break
for i in range(d, n):
	for j in range(n):
		if l == j and M[i][l] == v:
			k = 1
		elif j == n - l - 1 and M[i][n - l - 1] == v:
			k = 0
		elif j != l and j != n - l - 1 and (M[i][j] == r):
			k = 1
		else:
			c = 0
			break
	l = l - 1
if c == 1:
	print('YES')
else:
	print('NO')


n = int(input())
a = []
a = [a for j in range(n)]
for i in range(n):
	a[i] = input()
x1 = a[0][0]
x2 = a[0][1]
it = False
for i in range(n):
	for j in range(n):
		if (i == j or i + j + 1 == n) and a[i][j] == x1 or (not (i == j or i + j + 1 == n) and a[i][j] == x2):
			it = True
		else:
			it = False
		if x1 == x2:
			it = False
		if not it:
			break
	if not it:
		break
if it:
	print('YES')
else:
	print('NO')


n = int(input())
words = list()
sets = list()
i = 0
while i < n:
	word = input()
	w = list(word)
	s = set(w)
	if len(s) == 2:
		sets.append(len(s))
		words.append(word)
	i += 1
if len(sets) < n:
	print('NO')
else:
	length = len(words)
	k = int(length / 2)
	l = -1
	j = 0
	for t in words:
		if t[j] != t[l]:
			print('NO')
			break
		elif k == j:
			if t[k] != words[0][0]:
				print('NO')
			elif (words[0:k] == words[-1:-k - 1:-1] or words[0:k] == words[k + 1:]) and words[k][0:int(len(words[k]) / 2)] == words[k][int(len(words[k]) / 2) + 1:]:
				print('YES')
			else:
				print('NO')
				break
		j += 1
		l -= 1


n = int(input())
mat = []
for i in range(n):
	inp = input()
	mat.append(inp)
dc = mat[0][0]
oc = mat[0][1]
if dc == oc:
	print('NO')
	exit()
for i in range(n):
	if i > n // 2:
		d = n - 1 - i
	else:
		d = i
	for j in range(n):
		if j == d or j == n - 1 - d:
			if mat[i][j] != dc:
				print('NO')
				exit()
		elif mat[i][j] != oc:
			print('NO')
			exit()
print('YES')


n = int(input())
s = ''
for i in range(n):
	s += input()
flag = 0
s1 = set(s)
cnt1 = 0
if s[0] != s[-1] or len(s1) > 2 or len(s1) == 1:
	print('NO')
else:
	first = s[0]
	second = s[1]
	h = 1 + n * n // 2
	for i in range(0, h):
		if s[i] == first:
			if s[i] != s[n * n - i - 1]:
				flag = 1
				break
	if flag == 0 and s.count(second) == n * n - (2 * n - 1) and (s[h - 1] == first):
		print('YES')
	else:
		print('NO')


n = int(input())
flag = 1
for i in range(n):
	r = input().strip()
	if i == 0:
		de = r[0]
		ode = r[1]
		if de == ode:
			flag = 0
			print('NO')
			break
	for j in range(n):
		if j == n - 1 - i or j == i:
			if r[j] != de:
				flag = 0
				break
		elif r[j] != ode:
			flag = 0
			break
	if flag == 0:
		print('NO')
		break
if flag == 1:
	print('YES')


letter1 = []
letter2 = []
grid = int(input())
letters = [[char for char in input()] for i in range(grid)]
for a in range(grid):
	for b in range(grid):
		if a + b == grid - 1 or a == b:
			letter1.append(letters[a][b])
		else:
			letter2.append(letters[a][b])
if len(set(letter1)) == 1 and len(set(letter2)) == 1 and (letter1[0] != letter2[0]):
	print('YES')
else:
	print('NO')


from sys import *
n = int(input())
l = [list(input()) for _ in range(n)]
x = l[0][0]
xx = l[0][1]
nn = n // 2
for i in range(n):
	s = set(l[i])
	le = len(s)
	if le > 2 or le == 1:
		print('NO')
		break
	if i == nn:
		if l[i].count(x) > 1:
			print('NO')
			break
	if i != nn:
		if l[i].count(x) > 2:
			print('NO')
			break
	for j in s:
		if j != x and j != xx:
			print('NO')
			exit()
	j = i
	if i > nn:
		j = n - i - 1
	if l[i][j] != x or l[i][-j - 1] != x:
		print('NO')
		break
else:
	print('YES')


def helper(arr, n):
	diag = arr[0][0]
	for i in range(n):
		if arr[i][i] != diag:
			print('NO')
			return
	i = 0
	for j in range(n - 1, -1, -1):
		if arr[i][j] != diag:
			print('NO')
			return
		i += 1
	ndiag = arr[0][1]
	if ndiag == diag:
		print('NO')
		return
	for i in range(n):
		for j in range(n):
			if i == j or j + i == n - 1:
				continue
			if arr[i][j] != ndiag:
				print('NO')
				return
	print('YES')
n = int(input())
arr = [input() for x in range(n)]
helper(arr, n)


n = int(input())
data = []
for _ in range(n):
	data.append(input())
diag = data[0][0]
ofdiag = data[0][1]
if diag == ofdiag:
	print('NO')
	exit()
ok = True
for i in range(n):
	for j in range(n):
		if i == j or j == n - i - 1:
			if data[i][j] != diag:
				ok = False
		elif data[i][j] != ofdiag:
			ok = False
		if not ok:
			print('NO')
			exit()
print('YES')


n = int(input())
(ptrn, etrn) = ('', '')
if n == 1:
	print('NO')
else:
	for i in range(n):
		s = [i for i in input()]
		if i == 0:
			ptrn = s[0]
			extrn = s[1]
			if ptrn == extrn:
				print('NO')
				break
		if s[i] != ptrn or s[0 - 1 - i] != ptrn:
			print('NO')
			break
		(s[i], s[0 - 1 - i]) = (extrn, extrn)
		if s != [extrn] * n:
			print('NO')
			break
	else:
		print('YES')


n = int(input())
a = []
for i in range(n):
	l = input()
	s = []
	for j in l:
		s.append(j)
	a.append(s)
(x, y) = ([], [])
for i in range(n):
	for j in range(n):
		if i == j or i + j + 1 == n:
			x.append(a[i][j])
		else:
			y.append(a[i][j])
(x, y) = (set(x), set(y))
z = x & y
if len(x) == 1 and len(y) == 1 and (z == set()):
	print('YES')
else:
	print('NO')


n = int(input())
matrix = []
for i in range(n):
	a = input()
	matrix.append(a)
diag = matrix[0][0]
non = matrix[0][1]
ans = 'YES'
for i in range(n):
	flag = 0
	for j in range(n):
		if i == j or i == n - j - 1:
			if matrix[i][j] != diag or matrix[i][j] == non:
				flag = 1
				break
		elif matrix[i][j] != non or matrix[i][j] == diag:
			flag = 1
			break
	if flag == 1:
		ans = 'NO'
		break
print(ans)


n = int(input())
l1 = []
l2 = []
flag = 0
ans = []
for i in range(n):
	l = list((x for x in input()))
	l1.append(l)
	if l[i] == l[n - i - 1]:
		ans.append(l[i])
	if l[i] != l[n - i - 1]:
		flag = 1
		break
if len(set(ans)) != 1:
	flag = 1
if flag == 0:
	for i in range(n):
		l2.append(list((x[i] for x in l1)))
	for (x, y) in zip(l1, l2):
		if x != y:
			flag = 1
			break
		if len(set(x)) != 2 and len(set(y)) != 2:
			flag = 1
			break
if flag == 0:
	print('YES')
else:
	print('NO')


N = int(input())
squares = [None] * N
for i in range(N):
	squares[i] = input()
diag_ch = squares[0][0]
another_ch = squares[0][1]
first_diag = [squares[i][i] for i in range(N)]
second_diag = [squares[i][-(i + 1)] for i in range(N)]
if any((e != diag_ch for e in first_diag)) or any((e != diag_ch for e in second_diag)):
	print('NO')
	exit
else:
	flag = 0
	counter = 0
	for i in range(N):
		if all((e == diag_ch for e in squares[i])):
			flag = 1
			break
		counter += squares[i].count(another_ch)
	if flag == 1 or counter < N ** 2 - (len(first_diag) + len(second_diag) - 1):
		print('NO')
	else:
		print('YES')


N = int(input())
L = []
for i in range(N):
	S = input()
	L.append(S)
x = str(L[0][0])
s = str(L[0][1])
sumx = 0
sums = 0
for i in range(len(L)):
	l = L[i]
	l = list(l)
	x_cou = l.count(x)
	s_cou = l.count(s)
	sumx += x_cou
	sums += s_cou
sums_all = sumx + sums
mid_s = N // 2 + 1
if sums_all == N * N:
	lss = 0
	ls = 1
	for i in range(mid_s):
		if L[i] == L[-ls]:
			ls += 1
			lss += 1
	if lss == mid_s:
		if sumx == N * 2 - 1:
			print('YES')
		elif sumx != N * 2 - 1:
			print('NO')
	elif lss != mid_s:
		print('NO')
else:
	print('NO')


n = int(input())
a = []
for i in range(0, n):
	s = str(input())
	a.append(list(s))
temp = a[0][0]
temp2 = a[0][1]
coun = 0
coun2 = 0
for i in range(0, n):
	for j in range(0, n):
		if (i == j or i + j == n - 1) and a[i][j] == temp:
			coun = coun + 1
		elif a[i][j] == temp2 and a[i][j] != temp:
			coun2 = coun2 + 1
if coun == n * 2 - 1 and coun2 == n * n - (n * 2 - 1):
	print('YES')
else:
	print('NO')


matrix_length = int(input())
matrix = []
for i in range(matrix_length):
	matrix_row = list(input())
	matrix.append(matrix_row)
if matrix_length == 1:
	print('YES')
else:
	matrix_map = {}
	for i in range(matrix_length):
		for j in range(matrix_length):
			if matrix[i][j] in matrix_map:
				matrix_map[matrix[i][j]] += 1
			else:
				matrix_map[matrix[i][j]] = 1
	if len(matrix_map) > 2:
		print('NO')
	else:
		main_symbol = matrix[0][0]
		secondary_symbol = matrix[0][1]
		exit = True
		for i in range(matrix_length):
			for j in range(matrix_length):
				if j - i == 0 or j + i + 1 == matrix_length:
					if matrix[i][j] != main_symbol:
						exit = False
						break
				elif matrix[i][j] == main_symbol:
					exit = False
					break
		if not exit:
			print('NO')
		else:
			print('YES')


n = int(input())
l = []
for i in range(n):
	l.append(input())
t = l[0][0]
ans = 'YES'
for i in range(1, n):
	if l[i][i] != t:
		ans = 'NO'
		break
for i in range(n):
	if l[i][n - i - 1] != t:
		ans = 'NO'
		break
a = []
for i in range(n):
	for j in range(n):
		if i != j and i != n - j - 1:
			a.append(l[i][j])
if len(set(a)) != 1 or a[0] == t:
	ans = 'NO'
print(ans)


def valera_x():
	rows = int(input())
	maze = []
	for i in range(rows):
		maze.append(input())
		maze[i] = [maze[i][j] for j in range(len(maze[i]))]
	L = 0
	R = len(maze) - 1
	row = 0
	down_row = -1
	dic = {}
	dic[maze[0][0]] = 1
	while True:
		if maze[row][L] in dic and maze[row][R] in dic and (maze[down_row][L] in dic) and (maze[down_row][R] in dic):
			maze[row].pop(R)
			maze[row].pop(L)
			maze[down_row].pop(R)
			maze[down_row].pop(L)
			L += 1
			R -= 1
			row += 1
			down_row -= 1
			if L == R:
				if maze[row][L] in dic:
					maze[row].pop(L)
					break
		else:
			return 'NO'
	if maze[0][0] in dic:
		return 'NO'
	dic = {}
	dic[maze[0][0]] = 1
	for i in range(len(maze)):
		for j in range(len(maze[i])):
			if maze[i][j] not in dic:
				return 'NO'
	return 'YES'
answer = valera_x()
print(answer)


import sys
n = int(input())
square = sys.stdin.readlines()
square = [x.strip() for x in square]
dia = set([square[i][i] for i in range(n)] + [square[i][-i - 1] for i in range(n)])
other = set([square[i][j] for i in range(n) for j in range(n) if i != j and i + j != n - 1])
if len(dia) != 1 or len(other) != 1:
	print('NO')
elif len(dia | other) != 2:
	print('NO')
else:
	print('YES')


n = int(input())
arr = [input() for _ in range(n)]
x = arr[0][0]
y = arr[0][1]
f = True
if x == y:
	print('NO')
else:
	for i in range(n):
		for j in range(n):
			if i == j or i + j == n - 1:
				if arr[i][j] != x:
					f = False
					break
			elif arr[i][j] != y:
				f = False
				break
	print('YES' if f else 'NO')


def check_diags(matrix):
	l = len(matrix)
	ch = matrix[0][0]
	for i in range(l):
		if matrix[i][i] != ch:
			return False
		if matrix[i][l - i - 1] != ch:
			return False
	return True

def check_field(matrix):
	l = len(matrix)
	ch = matrix[0][1]
	count = 0
	for i in range(l):
		for j in range(l):
			if matrix[i][j] == ch:
				count += 1
	if count == l * l - (l * 2 - 1):
		return True
	else:
		return False
n = int(input())
l = []
for i in range(n):
	l.append(input())
if check_diags(l) and check_field(l):
	print('YES')
else:
	print('NO')


n = int(input())
m = []
for i in range(n):
	r = list(input())
	m.append(r)
v1 = m[0][0]
v2 = m[1][0]
if v1 == v2:
	print('NO')
	exit()
for i in range(n):
	for j in range(n):
		if i == j or i == n - j - 1:
			if m[i][j] != v1:
				print('NO')
				exit()
		elif m[i][j] != v2:
			print('NO')
			exit()
print('YES')


n = int(input())
matrix = [[j for j in input()] for i in range(n)]

def check_diagonal(matrix, n):
	t = 1
	d_element = matrix[0][0]
	for i in range(n):
		if matrix[i][i] != d_element or matrix[i][n - i - 1] != d_element:
			t = 0
	if t != 1:
		return False
	return True

def rest_element(matrix, n):
	r_element = matrix[0][1]
	t = 1
	for i in range(n):
		for j in range(n):
			if [i, j] != [i, i] and [i, j] != [i, n - i - 1]:
				if matrix[i][j] != r_element:
					t = 0
	if t != 1:
		return False
	return True
if check_diagonal(matrix, n) and rest_element(matrix, n) and (matrix[0][1] != matrix[0][0]):
	print('YES')
else:
	print('NO')


n = int(input())
pole = []
for i in range(n):
	pole.append(input())
gd = []
pd = []
other = []
for y in range(n):
	for x in range(n):
		if x == y:
			gd.append(pole[y][x])
		if y == n - 1 - x:
			pd.append(pole[y][x])
		if not x == y and (not y == n - 1 - x):
			other.append(pole[y][x])
if len(set(pd)) == 1 and len(set(gd)) == 1 and (gd[0] == pd[0]) and (len(set(other)) == 1) and (gd[0] != other[0]):
	print('YES')
else:
	print('NO')


def main():
	n = int(input())
	grid = [input() for _ in range(n)]
	diag_set = set()
	other_set = set()
	for r in range(n):
		for c in range(n):
			if r == c or r == n - c - 1:
				diag_set.add(grid[r][c])
			else:
				other_set.add(grid[r][c])
	if len(diag_set) == len(other_set) == 1 and (not diag_set & other_set):
		print('YES')
	else:
		print('NO')
main()


from sys import stdin, stdout
n = int(stdin.readline())
letters = stdin.readline()
char_in_diagonal = letters[0]
char_not_in_diagonal = letters[1]
start = 0
end = n - 1

def compareLetters(string, start, end):
	if string[start] != char_in_diagonal or string[end] != char_in_diagonal:
		stdout.write('NO\n')
		exit()
	for j in range(n):
		if j == start or j == end:
			continue
		if string[j] != char_not_in_diagonal:
			stdout.write('NO\n')
			exit()
if char_in_diagonal == char_not_in_diagonal:
	stdout.write('NO\n')
	exit()
compareLetters(letters, int(start), int(end))
for i in range(n - 1):
	start += 1
	end -= 1
	letters = stdin.readline()
	compareLetters(letters, start, end)
stdout.write('YES\n')


n = int(input())
l = []
s = ''
a = 0
b = n - 1
for i in range(n):
	inp = input()
	l.append(inp)
	inp = list(inp)
a = set()
b = set()
for i in range(n):
	for j in range(n):
		if i == j or i + j == n - 1:
			a.add(l[i][j])
		else:
			b.add(l[i][j])
if len(a) == 1 and len(b) == 1 and (a != b):
	print('YES')
else:
	print('NO')


n = int(input())
l = []
for _ in range(n):
	l.append(list(input()))
s = set()
(i, j) = (0, n - 1)
dig = True
p = l[0][0]
for x in l:
	if x[i] != x[j] or x[i] != p:
		dig = False
		break
	if x.count(p) != 2 and i != j:
		dig = False
		break
	elif x.count(p) != 1 and i == j:
		dig = False
		break
	i += 1
	j -= 1
	for y in x:
		s.add(y)
	if len(s) != 2:
		dig = False
		break
if dig and len(s) == 2:
	print('YES')
else:
	print('NO')


n = int(input())
l = [list(input()) for _ in range(n)]
if len(set(sum(l, []))) != 2:
	print('NO')
else:
	d = {}
	for i in set(sum(l, [])):
		d[i] = sum(l, []).count(i)
	if n == 3:
		if l[0] == l[2] and l[1] == list(l[0][1] + l[0][0] + l[0][1]):
			print('YES')
		else:
			print('NO')
	elif any((d[j] not in [2 * (n - 1) + 1, n ** 2 - 2 * n + 1] for j in set(sum(l, [])))):
		print('NO')
	else:
		m = min(d, key=d.get)
		for x in range(n):
			if l[x][x] != m or l[x][::-1][x] != m:
				print('NO')
				quit()
		if l[n // 2][n // 2] == l[n // 2][0] or l[n // 2][n // 2] == l[n // 2][-1]:
			print('NO')
		else:
			print('YES')


n = int(input())
l = []
for i in range(n):
	s = input()
	p = [char for char in s]
	l.append(p)
d = l[0][0]
nd = l[0][1]
if d == nd:
	print('NO')
else:
	t = True
	k = n
	for i in range(n):
		k -= 1
		if l[i][i] != d:
			t = False
			break
		if l[i][k] != d:
			t = False
			break
		for j in range(n):
			if j != i and j != k:
				if l[i][j] != nd:
					t = False
					break
					break
	if t:
		print('YES')
	else:
		print('NO')