Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
s,ans = s+s,0
for i in range(n):
	flag = True
	for j in range(i,i+n):
		x = ""
		for k in range(i+1,i+n): x+=s[k][j-i]
		if s[j][1:n]!=x:
			flag = False
			break
	if flag: ans += n
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
if all(s[i][j]==s[0][0] for i in range(n) for j in range(n)): print(n**2)
else:
	for i in range(n): s[i] += s[i]
	s,ans = s+s,0
	for k in range(n):
		flag = True
		for k2 in range(k,n+k):
			for j2 in range(n):
				if s[k2][j2]!=s[j2+k][k2-k]:
					flag = False
					break
			if not flag: break
		if flag: ans += n
	print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
if all(s[i][j]==s[0][0] for i in range(n) for j in range(n)): print(n**2)
else:
	for i in range(n): s[i] += s[i]
	s,ans = s+s,0
	for j in range(n):
		for k in range(n):
			flag = True
			for k2 in range(k,n+k):
				for j2 in range(j,n+j):
					if s[k2][j2]!=s[j2-j+k][k2-k+j]:
						flag = False
						break
				if not flag: break
			if flag: ans += 1
	print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
if all(s[i][j]==s[0][0] for i in range(n) for j in range(n)): print(n**2)
else:
	for i in range(n): s[i] += s[i]
	ans = 0
	for i in range(n):
		s2 = []
		for j in s: s2.append(j[i:i+n])
		s2 += s2
		for k in range(n):
			flag = True
			for k2 in range(k,n+k):
				for k3 in range(n):
					if s2[k2][k3]!=s2[k3+k][k2-k]:
						flag = False
						break
				if not flag: break
			if flag: ans += 1
	print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = [input() for i in range(n)]
for i in range(n): s[i] += s[i]
ans = 0
for i in range(n):
	s2 = []
	for j in s: s2.append(j[i:i+n])
	s2 += s2
	for k in range(n):
		flag = True
		for k2 in range(k,n+k):
			if any(s2[k2][k3]!=s2[k3+k][k2-k] for k3 in range(n)):
				flag = False
				break
		if flag: ans += 1
print(ans)

Fixed submission:
n = int(input())
s = [input() for i in range(n)]
s,s2,ans = s+s,[],0
for i in range(n):
	x = ""
	for j in s: x+=j[i]
	s2.append(x)
for i in range(n):
	flag = True
	for j in range(i,i+n):
		if s[j][1:n]!=s2[j-i][1+i:n+i]:
			flag = False
			break
	if flag: ans += n
print(ans)