Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import gcd, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()
aN = LIST()

aN.sort()
sm = sum(aN)
if sm < X:
    print(N-1)
elif sm == X:
    print(N)
else:
    x = X
    for i in range(N):
        x -= aN[i]
        if x < 0:
            print(i)
            exit()


Fixed submission:
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, initial=1)
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, X = MAP()
aN = LIST()

aN.sort()
sm = sum(aN)
if sm < X:
    print(N-1)
elif sm == X:
    print(N)
else:
    x = X
    for i in range(N):
        x -= aN[i]
        if x < 0:
            print(i)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import itertools

N,K = map(int, input().split())

p = list(itertools.product(range(1,N+1), repeat=3))

ans = 0
for pair in p:
    if (pair[0] + pair[1]) % K == 0 and (pair[1] + pair[2]) % K == 0 and (pair[2] + pair[0]) % K == 0:
        ans += 1

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

# mod Kをうまく使ってaを全検索

N,K = map(int, input().split())

num = [0] * K
# 元のNまでの数がmod Kの世界で何になるかを集計
for i in range(1,N+1):
    num[i%K] += 1

ans = 0
# a mod Kを決め打ちしてb mod Kとc mod Kを出す
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    # つじつまが合ってるか確認
    if (b + c) % K == 0:
        # 予め集計してあるmod Kでの数を合計させる
        ans += num[a] * num[b] * num[c]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import itertools

N,K = map(int, input().split())

p = list(itertools.product(range(1,N+1), repeat=3))

ans = 0
for pair in p:
    if (pair[0] + pair[1]) % K == 0 and (pair[1] + pair[2]) % K == 0 and (pair[2] + pair[0]) % K == 0:
        ans += 1

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

# mod Kをうまく使ってaを全検索

N,K = map(int, input().split())

num = [0] * K
# 元のNまでの数がmod Kの世界で何になるかを集計
for i in range(1,N+1):
    num[i%K] += 1

ans = 0
# a mod Kを決め打ちしてb mod Kとc mod Kを出す
for a in range(K):
    b = (K - a) % K
    c = (K - a) % K
    # つじつまが合ってるか確認
    if (b + c) % K == 0:
        # 予め集計してあるmod Kでの数を合計させる
        ans += num[a] * num[b] * num[c]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K = MAP()
A = LIST()

ans = INF
for i in range(K):
    if i+K > N:
        break
    A2 = A[i:i+K]
    l = A2[0]
    r = A2[-1]
    # 左だけ行く
    if r <= 0:
        ans = min(ans, -l)
    # 右だけ行く
    elif l >= 0:
        ans = min(ans, r)
    # 両方行く
    else:
        # 短い方を先に行って往復
        ans = min(ans, min(-l, r) * 2 + max(-l, r))
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

N,K = map(int, input().split())
xN = list(map(int, input().split()))

ans = float('inf')
for i in range(N-K+1):
    tmp = float('inf')
    # 範囲が0を含む
    if xN[i] <= 0 <= xN[i+K-1]:
        # 距離の短い方を往復する
        if abs(xN[i]) <= abs(xN[i+K-1]):
            tmp = abs(xN[i])*2 + abs(xN[i+K-1])
        else:
            tmp = abs(xN[i]) + abs(xN[i+K-1])*2
    # 範囲が全て0より大きい
    elif xN[i] > 0:
        tmp = abs(xN[i+K-1])
    # 範囲が全て0より小さい
    elif xN[i+K-1] < 0:
        tmp = abs(xN[i])
    ans = min(tmp, ans)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input())

i = 0
while True:
    bins = list(bin(i)[2:])
    ans = 0
    for j in range(len(bins)-1, -1, -1):
        if bins[j] == "1":
            ans += (-2) ** (len(bins)-1-j)
    if ans == N:
        print("".join(bins))
        exit()
    i += 1

Fixed submission:
# -*- coding: utf-8 -*-

N = int(input())

ans = ""
while N != 0:
    # 末尾の桁が偶奇を決めているので、そこが0か1かは判断できる
    if N % 2 == 0:
        ans = "0" + ans
    else:
        # 今の末尾の桁は1だったので、まずはその分を引く
        N -= 1
        ans = "1" + ans
    # -2進数は-2で割れば桁を落とせる(10進数で割る10する感じ)
    N /= -2
# Nが元々0だった場合
if ans == "":
    ans = 0

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
aN = list(map(int, input().split()))

cnt = 0
for i in range(N):
    ans = 0
    for j in range(i, N):
        ans += aN[j]
        if ans % M == 0:
            cnt += 1
print(cnt)


Fixed submission:
# -*- coding: utf-8 -*-

"""
参考：https://img.atcoder.jp/abc105/editorial.pdf
　　　http://drken1215.hatenablog.com/entry/2018/08/13/125300
　　　https://www.hamayanhamayan.com/entry/2018/08/12/010816
・左端固定で右端動かすループの累積和だけ取れば、
　(右端の累積和)-(左端-1の累積和)で、どこでも分かるようになる。
・B-AがMの倍数 → BとAのmod Mが等しい(やってみれば分かる)
・各ループ内で、それまでに集計した累積和mod Mから左端として使える場所を数える。
"""

from collections import defaultdict

N, M = map(int, input().split())
aN = list(map(int, input().split()))

# 累積和を一時的に格納する変数
sm = 0
ans = 0
# 累積和のmod Mを格納するdict
d = defaultdict(int)
# 何もない累積和0の分を足しておく
d[0] = 1
for i in range(N):
    sm += + aN[i]
    # 今回のsm%Mを右端として、mod Mが同値になる左端候補の数を答えに加算
    ans += d[sm%M]
    # 今回のsm%Mはこの後左端候補として使うので+1
    d[sm%M] += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import itertools
 
n, m, d = map(int, input().split())

# 重複順列で全パターン出す
nm = list(itertools.product([i for i in range(1, n+1)], repeat=m))

avg = []
for tmp in nm:
    bty = 0
    for i in range(m-1):
        if abs(tmp[i] - tmp[i+1]) == d:
            bty += 1
    avg.append(bty)

print(sum(avg) / len(nm))

Fixed submission:
# -*- coding: utf-8 -*-
 
n, m, d = map(int, input().split())

if d == 0:
    print(1 / n * (m - 1))

else:
    print((2 * (n - d) / n ** 2) * (m - 1))
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

def check(m):
    sm = 0
    for i, a in enumerate(A):
        sm += abs(a - (m+i+1))
    return sm

# 三分探索
low = -INF
hi = INF
while low+2 < hi:
    m1 = (low*2+hi) // 3
    m2 = (low+hi*2) // 3
    res1 = check(m1)
    res2 = check(m2)
    # 今回は下に凸な関数なので値の小さい方に向かって狭めていく
    if res1 <= res2:
        hi = m2
    else:
        low = m1

ans = INF
for i in range(low, low+2):
    ans = min(ans, check(i))
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

N = int(input())
AN = list(map(int, input().split()))

# Ai - i の各値を用意してソートする
BN = [AN[i] - (i + 1) for i in range(N)]
BN.sort()
# 中央値を取る
b = BN[len(BN) // 2]
# 最適な b で実際の計算をする
ans = 0
for i in range(N):
    ans += abs(AN[i] - (b + i + 1))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

"""
参考：http://drken1215.hatenablog.com/entry/2018/07/22/133200
　　　https://www.hamayanhamayan.com/entry/2018/06/16/091039
・自力ACできたけど、メモをもう一歩深く書けば
　メインのループ1つ落とせるのが分かったのでそっちもやってみる。
"""
 
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
cN = [list(map(int, input().split())) for i in range(N)]

# [mod 3でどれになるか][今度の色] = そうなった時の違和感の総和
memo = [[0] * C for i in range(3)]
for c in range(C):
    for i in range(N):
        for j in range(N):
            memo[(i+j+2)%3][c] += D[cN[i][j]-1][c]

ans = float('inf')
# 変わる色を全組み合わせループ
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i == j or j == k or k == i:
                continue
            # メモで違和感の合計まで出してあるので、ここではループなし
            sm = memo[0][i] + memo[1][j] + memo[2][k]
            ans = min(sm, ans)
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
 
N, C = map(int, input().split())
D = [list(map(int, input().split())) for i in range(C)]
cN = [list(map(int, input().split())) for i in range(N)]

# [mod 3でどれになるか][今の色] = 該当する数
memo = [[0] * C for i in range(3)]
for i in range(N):
    for j in range(N):
        memo[(i+j+2)%3][cN[i][j]-1] += 1

ans = float('inf')
# 変わる色を全組み合わせループ
for i in range(C):
    for j in range(C):
        for k in range(C):
            if i == j or j == k or k == i:
                continue
            sm = 0
            # 元の色ループ
            for l in range(C):
                # メモを元に、各塗り替えでどのくらい違和感が出るか算出
                sm += D[l][i] * memo[0][l]
                sm += D[l][j] * memo[1][l]
                sm += D[l][k] * memo[2][l]
            ans = min(sm, ans)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input())
S = input()

# 累積和を使う方法
W_ruiseki = []
E_ruiseki = []
# 0地点を含めたN+1パターンを予め用意しておく
for i in range(N+1):
    W_ruiseki.append(S[:i].count("W"))
    E_ruiseki.append(i - W_ruiseki[i])

ans = float("inf")
for i in range(N):
    cnt = 0
    cnt += W_ruiseki[i]
    cnt += E_ruiseki[N] - E_ruiseki[i+1]
    ans = min(ans, cnt)

print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

N = int(input())
S = input()

# 初期値設定
cnt = S[1:].count("E")
ans = cnt
# 結局自分と1個前しか変化しない
for i in range(1, N):
    if S[i] == "E":
        cnt -= 1
    if S[i-1] == "W":
        cnt += 1
    ans = min(ans, cnt)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

N = int(input())
S = input()

ans = float("inf")
for i in range(N):
    cnt = 0
    cnt += S[:i].count("W")
    cnt += S[i+1:].count("E")
    ans = min(ans, cnt)
print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

N = int(input())
S = input()

# 初期値設定
cnt = S[1:].count("E")
ans = cnt
# 結局自分と1個前しか変化しない
for i in range(1, N):
    if S[i] == "E":
        cnt -= 1
    if S[i-1] == "W":
        cnt += 1
    ans = min(ans, cnt)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
 
N = int(input())
aN = list(map(int, input().split()))

ans = 0
for i in range(N):
    sm = xor = 0
    for j in range(i, N):
        sm += aN[j]
        xor ^= aN[j]
        if sm == xor:
            ans += 1
        # 一度合わなくなったら、そこから先で合うことはないはず
        else:
            break
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

"""
しゃくとり法
・前にやったのとか参考にして自力実装
"""
 
N = int(input())
aN = list(map(int, input().split()))

l,r,ans = 0,0,0
sm = xor = 0
# 外ループで左を動かす
while l < N:
    # 内ループは条件を満たす限り右を動かす
    while r < N and sm + aN[r] == xor ^ aN[r]:
        ans += 1
        sm += aN[r]
        xor ^= aN[r]
        r += 1
    # 左右の差分-1
    ans += r - l - 1
    # ※今回はl==rの時whileの条件を確実に満たすので、
    # ここでl==rになることはなく、このif文は本当は必要ない。
    if l == r:
        # 左が右に追いついたら、右も左に合わせて+1する
        r += 1
    else:
        # 左を動かす分の合計を引く
        sm -= aN[l]
        xor ^= aN[l]
    l += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, Q = MAP()
A = LIST()

ans = INF
# 使う要素の最小値とする値xを全探索
for x in A:
    # 数列Aをx未満の値で区切った数列Bを作る
    B = []
    tmp = []
    for i in range(N):
        if A[i] >= x:
            tmp.append(A[i])
        else:
            B.append(tmp)
            tmp = []
    B.append(tmp)
    # 数列B内の各数列から、使える要素を集める
    C =  []
    for li in B:
        m = len(li)
        li.sort()
        C += li[:max(m-K+1, 0)]
    # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y
    C.sort()
    if len(C) < Q:
        continue
    y = C[Q-1]
    ans = min(ans, y - x)
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, K, Q = MAP()
A = LIST()

ans = INF
# 使う要素の最小値とする値xを全探索
for x in A:
    # 数列Aをx未満の値で区切った数列Bを作る
    B = []
    tmp = []
    for i in range(N):
        if A[i] >= x:
            tmp.append(A[i])
        else:
            B.append(tmp)
            tmp = []
    B.append(tmp)
    # 数列B内の各数列から、使える要素を集める
    C =  []
    for li in B:
        m = len(li)
        li.sort()
        C += li[:max(m-K+1, 0)]
    # 集めた要素からQ個をクエリで使うので、小さい方からQ番目が使う要素の最大値y
    C.sort()
    if len(C) < Q:
        continue
    y = C[Q-1]
    ans = min(ans, y - x)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST(N)

mx = 0
for i in range(1, N+1):
    cnt = 0
    nxt = i
    for a in A:
        if a == nxt:
            cnt += 1
            nxt += 1
    mx = max(mx, cnt)
print(N - mx)


Fixed submission:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST(N)

B = [0] * N
for i, a in enumerate(A):
    B[a-1] = i

mx = cnt = 1
for i in range(N-1):
    if B[i] < B[i+1]:
        cnt += 1
    else:
        cnt = 1
    mx = max(mx, cnt)
print(N - mx)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

instr = input()
target = int(input())

# 部分文字列の一覧リストを作成
str_list = []
for i in range(len(instr)):

	for j in range(len(instr)+1):
		
		# 開始位置iの方が大きいものはやる必要がないのでjを増やす
		if i >= j:
			j = i + 1
		
		# targetよりも大きい文字数のものは処理しない
		if j-i > target:
			break

		# 候補となる部分文字列の格納
		str_list.append(instr[i:j])
		j += 1
	i += 1

# 重複削除
str_list = list(set(str_list))
# 昇順ソート
str_list.sort()

print(str_list[target-1])

Fixed submission:
# -*- coding: utf-8 -*-

# 入力を各変数に格納
a, b, c, d = map(int, input().split())

# 直接可能
if abs(a - c) <= d:
	print("Yes")
# 間接可能
elif abs(a - b) <= d and abs(b - c) <= d:
	print("Yes")
else:
	print("No")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

N = INT()
grid = build_grid(N, N, '', str, space=0)

def check(i, j):
    for k in range(N):
        for l in range(k+1, N):
            if grid[(k+i)%N][(l+j)%N] != grid[(l+i)%N][(k+j)%N]:
                return False
    return True

# 片側しかやらなくていい
cnt = 0
for i in range(N):
    if check(0, i):
        cnt += 1
print(cnt * N)


Fixed submission:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

N = INT()
grid = build_grid(N, N, '', str, space=0)

def check(i, j):
    for k in range(N):
        for l in range(k+1, N):
            if grid[(k+i)%N][(l+j)%N] != grid[(l+i)%N][(k+j)%N]:
                return False
    return True

# 片側しかやらなくていい
cnt = 0
for i in range(N):
    if check(0, i):
        cnt += 1
print(cnt * N)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

list_size = int(input())
num_list = [int(i) for i in input().split()]

for i in range(0, list_size):

	num_list2 = []
	for idx, num in enumerate(num_list):
		
		if idx != i:
			num_list2.append(num)
	
	# 昇順ソート
	num_list2.sort()
	# 中央値の計算
	ans = num_list2[int((len(num_list2) + 1) / 2) - 1]
	print(ans)

Fixed submission:
# -*- coding: utf-8 -*-

list_size = int(input())
num_list = [int(i) for i in input().split()]
# 昇順ソート
num_list2 = sorted(num_list)
# 中央値候補
center_left = num_list2[int(list_size / 2) - 1]
center_right = num_list2[int(list_size / 2)]

for i in range(list_size):
	# 除く値が左寄り(小さい)なら右、右寄り(大きい)なら左
	if num_list[i] <= center_left:
		print(center_right)
	else:
		print(center_left)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-

# 3つの数字をリストから数値の変数に
input_list = input().split()
start_num = int(input_list[0])
end_num = int(input_list[1])
range_num = int(input_list[2])

for i in range(start_num, end_num + 1):
	# 条件に当てはまるものを抽出
	if i < start_num + range_num or i > end_num - range_num:
		print(i)


Fixed submission:
# -*- coding: utf-8 -*-

# 3つの数字をリストから数値の変数に
input_list = input().split()
start_num = int(input_list[0])
end_num = int(input_list[1])
range_num = int(input_list[2])

result_list = []
for i in range(start_num, end_num + 1):
	# 前半の条件に当てはまるものを抽出
	if i < start_num + range_num:
		result_list.append(i)
	else:
		break

for i in range(end_num, start_num -1, -1):
	# 後半の条件に当てはまるものを抽出
	if i > end_num - range_num:
		result_list.append(i)
	else:
		break

# 重複削除
result_list = list(set(result_list))
# 昇順ソート
result_list.sort()

for num in result_list:
	print(num)