Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=''
for i in range(n):
	s+=raw_input()
s+=s
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if not ok:
			break
		j=0
		while j<n:
			if s[(i+shift)*n+j]!=s[(j+shift)*n+i]:
				ok=False
				break
			j+=1
	if ok:
		result+=n
print result

Fixed submission:
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)
#print s
t=''.join(t)
#print t
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=''
for i in range(n):
	s+=raw_input()
s+=s
result=0
for shift in range(n):
	ok=True
	for i in range(n):
		for j in range(n):
			if s[(i+shift)*n+j]!=s[(j+shift)*n+i]:
				ok=False
				break
	if ok:
		result+=n
print result

Fixed submission:
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)
#print s
t=''.join(t)
#print t
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=[]
for i in range(n):
	s+=[raw_input()]
result=0
for shift in range(n):
	ok=True
	for i in range(n):
		for j in range(n):
			if s[i][j]!=s[j][i]:
				ok=False
				break
	if ok:
		result+=n
	s=s[1:]+s[:1]
print result

Fixed submission:
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)
#print s
t=''.join(t)
#print t
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=[]
for i in range(n):
	s+=[raw_input()]
result=0
for shift in range(n):
	ok=True
	for i in range(n):
		for j in range(n):
			if s[(i+shift)%n][j]!=s[(j+shift)%n][i]:
				ok=False
				break
	if ok:
		result+=n
print result

Fixed submission:
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)
#print s
t=''.join(t)
#print t
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=[]
for i in range(n):
	s+=[raw_input()]
result=0
for shift in range(n):
	ok=True
	for i in range(n):
		for j in range(n):
			if s[i][j]!=s[j][i]:
				ok=False
				break
	if ok:
		result+=n
	for i in range(n):
		s[i]=s[i][1:]+s[i][0:1]
print result

Fixed submission:
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)
#print s
t=''.join(t)
#print t
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=[]
for i in range(n):
	s+=[raw_input()]
result=0
for shift in range(n):
	ok=True
	for i in range(n):
		for j in range(n):
			if s[i][j]!=s[j][i]:
				ok=False
	if ok:
		result+=n
	for i in range(n):
		s[i]=s[i][1:]+s[i][0:1]
print result

Fixed submission:
n=input()
s=[raw_input() for i in range(n)]
t=[]
for i in range(n):
	t+=[s[j][i] for j in xrange(n)]*2
s+=s
s=''.join(s)
#print s
t=''.join(t)
#print t
result=0
for shift in xrange(n):
	ok=True
	for i in xrange(n):
		if s[(i+shift)*n: (i+shift)*n+n]!=t[i*n*2+shift: i*n*2+shift+n]:
			ok=False
			break
	if ok:
		result+=n
print result