Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*n for i in range(n)]
for i in range(m):
    l, r = list(map(lambda x: int(x)-1, input().split()))
    lst[l][r] += 1
newlst = cumsum(lst, axis=1)
for i in range(q):
    a, b = list(map(lambda x: int(x)-1, input().split()))
    ans = sum([newlst[i][b] for i in range(a, b+1)])
    print(ans)

Fixed submission:
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l, r = list(map(int, input().split()))
    lst[l][r] += 1
ans1 = cumsum(lst, axis=1)
ans = cumsum(ans1, axis=0)
for i in range(q):
    a, b = list(map(int, input().split()))
    print(ans[b, b] - ans[a-1, b])

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*n for i in range(n)]
for i in range(m):
    l, r = list(map(lambda x: int(x)-1, input().split()))
    lst[l][r] += 1
newlst = cumsum(lst, axis=1)
pq = list(list(map(lambda x: int(x)-1, input().split())) for i in range(q))
for a, b in pq:
    ans = sum([newlst[i][b] for i in range(a, b+1)])
    print(ans)

Fixed submission:
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l, r = list(map(int, input().split()))
    lst[l][r] += 1
ans1 = cumsum(lst, axis=1)
ans = cumsum(ans1, axis=0)
for i in range(q):
    a, b = list(map(int, input().split()))
    print(ans[b, b] - ans[a-1, b])

Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = list(map(int, input().split()))
lst = [[0]*n for i in range(n)]
for i in range(m):
    l, r = list(map(int, input().split()))
    lst[l-1][r-1] += 1
pq = list(list(map(int, input().split())) for i in range(q))
for a, b in pq:
    ans = sum([sum(lst[i][a-1:b]) for i in range(a-1, b)])
    print(ans)

Fixed submission:
from numpy import cumsum 
n, m, q = list(map(int, input().split()))
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
    l, r = list(map(int, input().split()))
    lst[l][r] += 1
ans1 = cumsum(lst, axis=1)
ans = cumsum(ans1, axis=0)
for i in range(q):
    a, b = list(map(int, input().split()))
    print(ans[b, b] - ans[a-1, b])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
count = 0
a, qa, c, qc = 0, 0, 0, 0
def calc(x, qx, y, qy):
    return ((3*x+qx) * (3*y+qy) * pow(3, qx+qy-2))
#x*y*pow(3,qx+qy)+qx*y*pow(3,qx+qy-1)+x*qy*pow(3,qx+qy-1)+qx*qy*pow(3,qx+qy-2)
for i in range(len(s)):
    if s[i] == 'C':
        c += 1
    elif s[i] == '?':
        qc += 1
    else:
        continue
for i in range(len(s)):
    if s[i] == 'A':
        a += 1
    elif s[i] == 'C':
        c -= 1
    elif s[i] == 'B':
        count += calc(a, qa, c, qc)
    else:
        qc -= 1
        count += calc(a, qa, c, qc)
        qa += 1
print(int(count) % 1000000007)

Fixed submission:
s = input()
count = 0
a, qa, c, qc = 0, 0, 0, 0
def calc(x, qx, y, qy):
    return ((3*x+qx) * (3*y+qy) * pow3q)
#x*y*pow(3,qx+qy)+qx*y*pow(3,qx+qy-1)+x*qy*pow(3,qx+qy-1)+qx*qy*pow(3,qx+qy-2)
for i in range(len(s)):
    if s[i] == 'C':
        c += 1
    elif s[i] == '?':
        qc += 1
    else:
        continue
pow3q = pow(3, qc-3)
for i in range(len(s)):
    if s[i] == 'A':
        a += 1
    elif s[i] == 'C':
        c -= 1
    elif s[i] == 'B':
        count += 3*calc(a, qa, c, qc)
    else:
        qc -= 1
        count += calc(a, qa, c, qc)
        qa += 1
print(int(count) % 1000000007)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
sadlist = []
for h in range(n):
    a[h] = a[h] - (h + 1)
for i in a:
    sad = 0
    for j in range(n):
        sad = sad + abs(a[j] - i)
    sadlist.append(sad)
print(min(sadlist))

Fixed submission:
n = int(input())
if n % 2 == 0:
    print(n)
else:
    print(n * 2)
Buggy python submission (verdict: Time Limit Exceeded):
import  re
s = input().replace("BC", "X")
cnt = 0
while "AX" in s:
  if "AXAX" in s:
    tmp = re.subn("AXAX", "XXAA", s)
    s = tmp[0]
    cnt += tmp[1] * 3

  tmp = re.subn("AX", "XA", s)
  s = tmp[0]
  cnt += tmp[1]
print(cnt)

Fixed submission:
cnt, tmp = 0, 0
for c in input().replace("BC", "X"):
  if c == "A":
    tmp += 1
  elif c == "X":
    cnt += tmp
  else:
    tmp = 0
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import  re
s = input().replace("BC", "X")
cnt = 0
while "AX" in s:
  tmp = re.subn("AX", "XA", s)
  s = tmp[0]
  cnt += tmp[1]
print(cnt)

Fixed submission:
cnt, tmp = 0, 0
for c in input().replace("BC", "X"):
  if c == "A":
    tmp += 1
  elif c == "X":
    cnt += tmp
  else:
    tmp = 0
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s = input().replace("BC", "X")
cnt = 0
while True:
  pos = s.find("AX")
  if pos == -1:
    break
  s = s[:pos] + "XA" + s[pos + 2:]
  cnt += 1
print(cnt)

Fixed submission:
cnt, tmp = 0, 0
for c in input().replace("BC", "X"):
  if c == "A":
    tmp += 1
  elif c == "X":
    cnt += tmp
  else:
    tmp = 0
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
cnt = 0
while True:
  pos = s.find("ABC")
  if pos == -1:
    break
  s = s[:pos] + "BCA" + s[pos + 3:]
  cnt += 1
print(cnt)

Fixed submission:
cnt, tmp = 0, 0
for c in input().replace("BC", "X"):
  if c == "A":
    tmp += 1
  elif c == "X":
    cnt += tmp
  else:
    tmp = 0
print(cnt)
Buggy python submission (verdict: Runtime Error):
b=input()
b=input()

if b=='A':
  print('T')
elif b=='T':
  print('A')
elif b=='C':
  print('G')
elif b=='G':
  pring('C')

Fixed submission:
b=input()

if b=='A':
  print('T')
elif b=='T':
  print('A')
elif b=='C':
  print('G')
elif b=='G':
  print('C')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

global res
global res_print
global flg
res=[0]*len(A)
res_print=[0]*len(A)

def test(X):
    if len(X)==1:
        if X[0]==1:
            res[0]=1
            #res_printに答えを入れる
            #res_print=res
            for s in range(len(res)):
                res_print[s]=res[s]
            return 1
        else:
            return 0
    else:
        flg=[0]*len(X)
        for i in range(len(X)):
            if X[i]==i+1:
                res[len(X)-1]=i+1
                X1=X[:i]
                X1.extend(X[i+1:])
                flg[i]=test(X1)
        return max(flg)

if test(A)== 0:
  print(-1)
else:
  for s in range(len(res)):
    print(res_print[s])


Fixed submission:
import numpy as np

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

A=np.array(A)

global res

res=[0]*N

def test(A):
    if A.shape[0]==1:
        if A[0]==1:
            res[0]=1
            return 1
        else:
            return 0
    else:
        B=np.arange(len(A))+1
        C=max((A==B)*B)
        if C==0:
            return 0
        else:
            res[len(A)-1]=C
            return test(np.delete(A,C-1,0))

if test(A)==1:
  for i in range(N):
    print(res[i])
else:
  print(-1)
Buggy python submission (verdict: Runtime Error):

def computeMinimumNoOfOperations(candies, x):
    noOfOperations = 0
    for i in range(len(candies) - 1):
        if (candies[i] > x):
          candiesTocandiesToEat = candies[i] - x
          candies[i] -= candiesTocandiesToEat
          noOfOperations += candiesToEat
        if (candies[i] + candies[i + 1] > x):
            candiesToEat = candies[i] + candies[i + 1] - x
            candies[i + 1] -= candiesToEat
            noOfOperations += candiesToEat 
    return noOfOperations


def start():
    n, x = list(map(int, input().split()))
    candies = list(map(int, input().split()))
    return computeMinimumNoOfOperations(candies, x)

print(start())


Fixed submission:

def computeMinimumNoOfOperations(candies, x):
    noOfOperations = 0
    for i in range(len(candies) - 1):
        if (candies[i] > x):
            candiesToEat = candies[i] - x
            candies[i] -= candiesToEat
            noOfOperations += candiesToEat
        if (candies[i] + candies[i + 1] > x):
            candiesToEat = candies[i] + candies[i + 1] - x
            candies[i + 1] -= candiesToEat
            noOfOperations += candiesToEat 
    return noOfOperations


def start():
    n, x = list(map(int, input().split()))
    candies = list(map(int, input().split()))
    return computeMinimumNoOfOperations(candies, x)

print(start())

Buggy python submission (verdict: Runtime Error):


def computeMinimumNoOfOperations(candies, x):
  noOfOperations = 0
  for i in range(0, len(candies) - 1):
    if (candies[i] > x):
      eat = candies[i] - x
      candies[i] -= eat
      noOfOperations += eat
    if (candies[i] + candies[i + 1] > x):
      if (candies[i] > candies[i + 1]):
        eat = candies[i] - x
      	candies[i] -= eat
      	noOfOperations += eat 
      else:
        eat = candies[i + 1] - x
      	candies[i + 1] -= eat
      	noOfOperations += eat 
  return noOfOperations


def start():
  n, x = list(map(int, input().split()))
  candies = list(map(int, input().split()))
  return computeMinimumNoOfOperations(candies, x)

print(start())

Fixed submission:

def computeMinimumNoOfOperations(candies, x):
    noOfOperations = 0
    for i in range(len(candies) - 1):
        if (candies[i] > x):
            candiesToEat = candies[i] - x
            candies[i] -= candiesToEat
            noOfOperations += candiesToEat
        if (candies[i] + candies[i + 1] > x):
            candiesToEat = candies[i] + candies[i + 1] - x
            candies[i + 1] -= candiesToEat
            noOfOperations += candiesToEat 
    return noOfOperations


def start():
    n, x = list(map(int, input().split()))
    candies = list(map(int, input().split()))
    return computeMinimumNoOfOperations(candies, x)

print(start())
Buggy python submission (verdict: Runtime Error):
i = int(input())
degree = 180 * (i - 2)
print(degree

Fixed submission:
i = int(input())
degree = 180 * (i - 2)
print(degree)
Buggy python submission (verdict: Runtime Error):
num_list = [int(input()) for i in range(3)]
result_yen = int(intput())

count = 0

for yen_500 in range(coin_list[0]):
    for yen_100 in range(coin_list[1]):
        for yen_50 in range(coin_list[2]):
            if result_yen == yen_500*500 + yen_100*100 + yen_50 *50:
                count += 1
                
print(count)

Fixed submission:
input_num = [int(input()) for i in range(4)]

coin_list = input_num[0:3]
result_yen = input_num[3]

count = 0

for yen_500 in range(coin_list[0]+1):
    for yen_100 in range(coin_list[1]+1):
        for yen_50 in range(coin_list[2]+1):
            if result_yen == yen_500*500 + yen_100*100 + yen_50 *50:
                count += 1
                
print(count)

Buggy python submission (verdict: Runtime Error):
num_list = [int(input()) for i in range(3)]
result_yen = int(intput())

count = 0

for yen_500 in range(coin_list[0]):
    for yen_100 in range(coin_list[1]):
        for yen_50 in range(coin_list[2]):
            if result_yen == yen_500*500 + yen_100*100 + yen_50 *50:
                count += 1
                
print(count)

Fixed submission:
input_num = [int(input()) for i in range(4)]

coin_list = input_num[0:3]
result_yen = input_num[3]

count = 0

for yen_500 in range(coin_list[0]+1):
    for yen_100 in range(coin_list[1]+1):
        for yen_50 in range(coin_list[2]+1):
            if result_yen == yen_500*500 + yen_100*100 + yen_50 *50:
                count += 1
                
print(count)
Buggy python submission (verdict: Runtime Error):
input_nums = input().split()

product = 1

for num in input_nums:
  product = product * num
  
if(product % 2 == 0):
  print('Even')
else:
  print('Odd')
  



Fixed submission:
input_nums = input().split()

product = 1

for num in input_nums:
  product = product * int(num)
  
if(product % 2 == 0):
  print('Even')
else:
  print('Odd')

Buggy python submission (verdict: Runtime Error):
input_nums = input().split()

product = 1

for num in lnput_nums:
  product = product * num
  
if(product % 2 == 0):
  print('Even')
else:
  print('Odd')
  



Fixed submission:
input_nums = input().split()

product = 1

for num in input_nums:
  product = product * int(num)
  
if(product % 2 == 0):
  print('Even')
else:
  print('Odd')

Buggy python submission (verdict: Runtime Error):
s = input().split()

if s[0] * s[0] % 2 == 0:
  print('Even')
else:
  print('Odd')

Fixed submission:
input_nums = input().split()

product = 1

for num in input_nums:
  product = product * int(num)
  
if(product % 2 == 0):
  print('Even')
else:
  print('Odd')
Buggy python submission (verdict: Runtime Error):
n = int(input())
edges = [[] for _  in range(n)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

height = [None for _ in range(n)]
root = 0
height[root] = 0

def build(node):
    for to in edges[node]:
        if height[to] == None:
            height[to] = height[node] + 1
            build(to)

build(root)

enum = [(-h, i) for i, h in enumerate(height)]
enum.sort()

score = 0
tree = [None] * n
clst = sorted(map(int, input().split()))

for c, hi in zip(clst, enum):
    h, i = hi
    tree[i] = c

print(sum(clst[:-1]))
print(*tree)


Fixed submission:
import sys
sys.setrecursionlimit(100000)

n = int(input())
edges = [[] for _  in range(n)]

for _ in range(n - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

height = [None for _ in range(n)]
root = 0
height[root] = 0

def build(node):
    for to in edges[node]:
        if height[to] == None:
            height[to] = height[node] + 1
            build(to)

build(root)

enum = [(-h, i) for i, h in enumerate(height)]
enum.sort()

tree = [None] * n
clst = sorted(map(int, input().split()))

for c, hi in zip(clst, enum):
    h, i = hi
    tree[i] = c

print(sum(clst[:-1]))
print(*tree)
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
layers = [1]
pats = [1]
cnt = 1
p_cnt = 1
for _ in range(n):
  cnt = cnt * 2 + 3
  p_cnt = p_cnt * 2 + 1
  layers.append(cnt)
  pats.append(p_cnt)
def solve(lev, rest):
  if rest == 0:
    return 0
  if rest - 1 <= (layers[lev] - 3) // 2:
    return solve(lev - 1, rest - 1)
  elif rest - 1 == (layers[lev] - 3) // 2:
    return pats[lev - 1] + 1
  else:
    return pats[lev - 1] + 1 + solve(lev - 1, rest - 1 - layers[lev - 1] - 1)

print(solve(n, x))

Fixed submission:
import sys
sys.setrecursionlimit(1000000)
n, x = map(int, input().split())
layers = [1]
pats = [1]
cnt = 1
p_cnt = 1
for _ in range(n):
  cnt = cnt * 2 + 3
  p_cnt = p_cnt * 2 + 1
  layers.append(cnt)
  pats.append(p_cnt)
def solve(lev, rest):
  if rest == 0:
    return 0
  if lev == 0:
    return 1
  if rest - 1 <= layers[lev - 1]:
    return solve(lev - 1, rest - 1)
  elif rest - 1 == layers[lev - 1]:
    return pats[lev - 1] + 1
  else:
    return pats[lev - 1] + 1 + solve(lev - 1, rest - 1 - layers[lev - 1] - 1)

print(solve(n, x))
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left as bl
from bisect import bisect_right as br
from itertools import combinations as cmb
from itertools import combinations_with_replacement as cmbwr
from itertools import permutations as prm
from itertools import accumulate as acm
from math import gcd
from math import ceil
from math import factorial as fact
from collections import deque
from collections import Counter
from heapq import heappop as hpp
from heapq import heappush as hps
import sys
sys.setrecursionlimit(10 ** 6)
INF = 10 ** 20
direct = ((1, 0), (0, 1), (-1, 0), (0, -1))
def ilinp(): return list(map(int, input().split()))
def slinp(): return input().split()
def iinp(): return int(input())

a, b = ilinp()
if a + b == 15:
  print("+")
elif a* b == 15:
  print("*")
else:
  print("x")

Fixed submission:
def ilinp(): return list(map(int, input().split()))
def slinp(): return input().split()
def iinp(): return int(input())

a, b = ilinp()
if a + b == 15:
  print("+")
elif a* b == 15:
  print("*")
else:
  print("x")
Buggy python submission (verdict: Time Limit Exceeded):
from heapq import heappush, heappop 
INF = 10 ** 100
n, m, s, t = map(int, input().split())
s -= 1
t -= 1
init = 10 ** 15
edges = [[] for _ in range(n * 2)]
for _ in range(m):
  u, v, a, b = map(int, input().split())
  u -= 1
  v -= 1
  edges[u].append((v, a))
  edges[v].append((u, a))
  edges[u + n].append((v + n, b))
  edges[v + n].append((u + n, b))

for i in range(n):
  edges[i].append((i + n, 0))

for i in range(n):
  if i >= 1:
    edges[i - 1].remove((i - 1 + n, 0))

  que = []
  heappush(que, (0, s))
  costs = [INF] * (n * 2)
  costs[s] = 0
  while que:
    total, node = heappop(que)
    for to, dist in edges[node]:
      if costs[to] > total + dist:
        costs[to] = total + dist
        heappush(que, (total + dist, to))
  print(init - costs[t + n])

Fixed submission:
from heapq import heappush, heappop 
def main():
  INF = 10 ** 20
  n, m, s, t = map(int, input().split())
  s -= 1
  t -= 1
  init = 10 ** 15
  edges1 = [[] for _ in range(n)]
  edges2 = [[] for _ in range(n)]
  for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1
    v -= 1
    edges1[u].append((v, a))
    edges1[v].append((u, a))
    edges2[u].append((v, b))
    edges2[v].append((u, b))
  
  from_s = [INF] * n
  from_s[s] = 0
  que = []
  heappush(que, (0, s))
  while que:
    total, node = heappop(que)
    for to, dist in edges1[node]:
      if from_s[to] > total + dist:
        from_s[to] = total + dist
        heappush(que, (total + dist, to))
  
  from_t = [INF] * n
  from_t[t] = 0
  que = []
  heappush(que, (0, t))
  while que:
    total, node = heappop(que)
    for to, dist in edges2[node]:
      if from_t[to] > total + dist:
        from_t[to] = total + dist
        heappush(que, (total + dist, to))

  save = []
  for i in range(n):
    save.append(init - from_s[i] - from_t[i])
  save.reverse()
  acc = 0
  ans = []
  for s in save:
    acc = max(acc, s)
    ans.append(acc)
  ans.reverse() 
  for i in range(n):
    print(ans[i])

main()
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)
h,w = map(int,input().split())
lst = []
for i in range(h):
  lst.append([s for s in input()])
def dfs(x,y):
  if lst[x][y] == '#':
    lst[x][y] = '.'
    if x + 1 <= h - 1:
      dfs(x + 1,y)
    if x - 1 >= 0:
      dfs(x - 1,y)
    if y + 1 <= w - 1:
      dfs(x, y + 1)
    if y - 1 >= 0:
      dfs(x,y - 1)
flag = True
for i in range(h):
  for j in range(w):
    if lst[i][j] == '#':
      if (i - 1 >= 0 and lst[i - 1][j] == "#") or (i + 1 < h and lst[i + 1][j] == "#") or (j - 1 >= 0 and lst[i][j - 1] == "#") or (j + 1 < w and lst[i][j + 1] == "#"):
        dfs(i,j)
      else:
        flag = False
        break
if flag:
  print("Yes")
else:
  print("No")


Fixed submission:
a,b = map(int,input().split())
if b >= a: print(a)
else: print(a - 1)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
lst = []
for i in range(h):
  lst.append([s for s in input()])
def dfs(x,y):
  if lst[x][y] == '#':
    lst[x][y] = '.'
    if x + 1 <= h - 1:
      dfs(x + 1,y)
    if x - 1 >= 0:
      dfs(x - 1,y)
    if y + 1 <= w - 1:
      dfs(x, y + 1)
    if y - 1 >= 0:
      dfs(x,y - 1)
flag = True
for i in range(h):
  for j in range(w):
    if lst[i][j] == '#':
      if (i - 1 >= 0 and lst[i - 1][j] == "#") or (i + 1 < h and lst[i + 1][j] == "#") or (j - 1 >= 0 and lst[i][j - 1] == "#") or (j + 1 < w and lst[i][j + 1] == "#"):
        dfs(i,j)
      else:
        flag = False
        break
if flag:
  print("Yes")
else:
  print("No")


Fixed submission:
import sys
sys.setrecursionlimit(100000)
h,w = map(int,input().split())
lst = []
for i in range(h):
  lst.append([s for s in input()])
def dfs(x,y):
  if lst[x][y] == '#':
    lst[x][y] = '.'
    if x + 1 <= h - 1:
      dfs(x + 1,y)
    if x - 1 >= 0:
      dfs(x - 1,y)
    if y + 1 <= w - 1:
      dfs(x, y + 1)
    if y - 1 >= 0:
      dfs(x,y - 1)
flag = True
for i in range(h):
  for j in range(w):
    if lst[i][j] == '#':
      if (i - 1 >= 0 and lst[i - 1][j] == "#") or (i + 1 < h and lst[i + 1][j] == "#") or (j - 1 >= 0 and lst[i][j - 1] == "#") or (j + 1 < w and lst[i][j + 1] == "#"):
        dfs(i,j)
      else:
        flag = False
        break
if flag:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def main():
  def check(mp):
    for i in range(n):
      for j in range(i, n):
        if mp[i][j] != mp[j][i]: return 0
    return 1
  n = int(input())
  mp = deque([deque(list(input())) for _ in range(n)])
  ans = 0
  for a in range(n):
    mp.rotate()
    for b in range(n):
      for y in range(n):
        mp[y].rotate()
      ans += check(mp)
  print(ans)
  
main()

Fixed submission:
from collections import deque


def main():
  def check(mp):
    for i in range(n):
      for j in range(i, n):
        if mp[i][j] != mp[j][i]: return 0
    return 1
  n = int(input())
  mp = deque([deque(list(input())) for _ in range(n)])
  ans = 0
  for a in range(n):
    mp.rotate()
    ans += check(mp)
  print(ans * n)
  
main()

Buggy python submission (verdict: Time Limit Exceeded):
def check(mp):
  for i in range(n):
    for j in range(i, n):
      if mp[i][j] != mp[j][i]: return 0
  return 1

n = int(input())
mp = [input() for _ in range(n)]
ans = 0
for a in range(n):
  mp.insert(0, mp.pop())
  for b in range(n):
    for y in range(n):
      mp[y] = mp[y][-1] + mp[y][:-1]
    ans += check(mp)
print(ans)


Fixed submission:
from collections import deque


def main():
  def check(mp):
    for i in range(n):
      for j in range(i, n):
        if mp[i][j] != mp[j][i]: return 0
    return 1
  n = int(input())
  mp = deque([deque(list(input())) for _ in range(n)])
  ans = 0
  for a in range(n):
    mp.rotate()
    ans += check(mp)
  print(ans * n)
  
main()
Buggy python submission (verdict: Runtime Error):
print(min(int(input()),int(input())) + min(int(input()) + int(input())))

Fixed submission:
print(min(int(input()),int(input())) + min(int(input()),int(input())))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  h, w, d = map(int, input().split())
  dic = {}
  for i in range(1, h + 1):
    alst = list(map(int, input().split()))
    for j in range(w):
      dic[alst[j]] = (i, j + 1)
  
  q = int(input())
  for _ in range(q):
    l, r = map(int, input().split())
    ans = 0
    tmpx, tmpy = dic[l]
    while r > l:
      ldx, ldy = dic[l + d]
      ans += abs(tmpx - ldx) + abs(tmpy - ldy)
      l += d
      tmpx, tmpy = ldx, ldy
    print(ans)
  
main()

Fixed submission:
def main():
  h, w, d = map(int, input().split())
  dic = {}
  for i in range(1, h + 1):
    alst = list(map(int, input().split()))
    for j in range(w):
      dic[alst[j]] = (i, j + 1)
  
  acc = []
  for i in range(d):
    lst = [0]
    a = 0
    x, y = dic[(i - 1) % d + 1]
    for j in range((i - 1) % d + 1 + d, h * w + 1, d):
      x2, y2 = dic[j]
      a += abs(x - x2) + abs(y - y2)
      x, y = x2, y2
      lst.append(a)
    acc.append(lst)
  q = int(input())
  ans = 0
  for _ in range(q):
    l, r = map(int, input().split())
    ld = l // d
    rd = r // d
    if l % d == 0:
      ld -= 1
      rd -= 1
    ans = acc[l % d][rd] - acc[l % d][ld]
    print(ans)

  
main()