Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

dp = [0] * N
prev_i = [-1] * (10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] >= 0:
    if prev_i[a] == i - 1:
      dp[i] = dp[i - 1]
    else:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1])

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

MOD = 10**9 + 7

dp = [0] * N
prev_i = [-1] * (2 * 10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] >= 0:
    if prev_i[a] == i - 1:
      dp[i] = dp[i - 1]
    else:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1] % MOD)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

dp = [0] * N
prev_i = [-1] * (10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] != -1:
    if prev_i[a] != i - 1:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
    else:
      dp[i] = dp[i - 1]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1])

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

MOD = 10**9 + 7

dp = [0] * N
prev_i = [-1] * (2 * 10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] >= 0:
    if prev_i[a] == i - 1:
      dp[i] = dp[i - 1]
    else:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1] % MOD)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for _ in range(N)]

dp = [0] * N
prev_i = [-1] * (N + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] != -1:
    if prev_i[a] != i - 1:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
    else:
      dp[i] = dp[i - 1]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1])

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]

MOD = 10**9 + 7

dp = [0] * N
prev_i = [-1] * (2 * 10**5 + 1)

dp[0] = 1
prev_i[A[0]] = 0

for i in range(1, N):
  a = A[i]
  if prev_i[a] >= 0:
    if prev_i[a] == i - 1:
      dp[i] = dp[i - 1]
    else:
      dp[i] = dp[i - 1] + dp[prev_i[a]]
  else:
    dp[i] = dp[i - 1]
  prev_i[a] = i
  #print(i, dp, prev_i)

print(dp[-1] % MOD)
Buggy python submission (verdict: Runtime Error):
root = [i for i in range(N + 1)]
comp_size = [1] * (N+1)
 
def root_find(x):
  y = root[x]
  if x == y:
    return x
  else:
    z = root_find(y)
    root[x] = z
    return z

def merge(x, y):
  #print(x, y)
  rx = root_find(x)
  ry = root_find(y)
  sx = comp_size[rx]
  sy = comp_size[ry]
  if rx == ry:
    return 0
  else:
    if sx >= sy:
      root[ry] = rx
      comp_size[rx] = sx + sy
    else:
      root[rx] = ry
      comp_size[ry] = sx + sy
    return sx * sy

Fixed submission:
A,B,C=map(int,input().split())
print(min(C,B//A))
Buggy python submission (verdict: Runtime Error):
aa

Fixed submission:
K,A,B=map(int,input().split())
if B-A>=2:
  if K+1>=A:
    K=K-A+1
    print(A+(B-A)*(K//2)+K%2)
  else:
    print(1+K)
else:
  print(1+K)
Buggy python submission (verdict: Runtime Error):
10
1 8 10 5 8 12 34 100 11 3

Fixed submission:
N=int(input())
L=list(map(int,input().split()))
s=sum(L)

sw=0
for i in range(N):
  if s-L[i]<=L[i]:
    sw=1
    break
print("Yes" if sw==0 else "No")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
S = input()
T = input()

S_cnt = [0] * 27
T_cnt = [0] * 27

for s in S:
  S_cnt[ord(s) - ord("A")] += 1
for t in T:
  T_cnt[ord(t) - ord("A")] += 1
#print("S_cnt", *S_cnt)
#print("T_cnt", *T_cnt)

answer = 0
for i in range(27):
  if S_cnt[i]:
    if T_cnt[i] == 0:
      print(-1)
      exit()
    else:
      answer = max(answer, -(-S_cnt[i] // T_cnt[i]))
print(answer)

Fixed submission:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

A = []
C = []
for a, b in AB:
  A.append(a)
  C.append(a + b)
#print("C:", C)

C.sort()
C = C[::-1]

print(sum(A) - sum(C[1::2]))
Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
from collections import defaultdict

N, K = map(int, input().split())
TD = [list(map(int, input().split())) for _ in range(N)]

DT = [[d, t] for t, d  in TD]
DT.sort(reverse = True)
#print(DT)

h_in = []
cnt = defaultdict(int)

tmp = []
kiso = 0
for d, t in DT:
    if cnt[t] == 0:
        heappush(h_in, [d, t])
        kiso += d
    else:
        tmp.append([d, t])
    cnt[t] += 1

tmp = tmp[::-1]
len_h_in = len(h_in)
if len_h_in < K:
    d = K - len_h_in
    for i in range(d):
        heappush(h_in, tmp[i])
        kiso += tmp[i][0]

kind = 0
for k, v in list(cnt.items()):
    if v:
        kind += 1
#print(kiso, kind)
#print(h_in)
#print(tmp)

answer = kiso + kind ** 2
tmp = tmp[::-1]
while tmp:
    out_d, out_t = tmp.pop()
    in_d, in_t = heappop(h_in)
    
    kiso += out_d - in_d
    cnt[in_t] -= 1
    if cnt[in_t] == 0: kind -= 1
    cnt[out_t] += 1
    if cnt[out_t] == 1: kind += 1
    
    answer = max(answer, kiso + kind ** 2)

print(answer)

Fixed submission:
from collections import defaultdict

N, K = map(int, input().split())
TD = [list(map(int, input().split())) for _ in range(N)]

TD.sort(key = lambda x: -x[1])
#print(TD)

tmp = [[] for _ in range(N + 1)]
cnt = defaultdict(int)
out_candidate = []
kiso = 0
kind = 0
for i in range(K):
    t, d = TD[i]
    tmp[t].append(d)
    if cnt[t]:
        out_candidate.append([t, d])
    else:
        kind += 1
    kiso += d
    cnt[t] += 1
out_candidate.sort(key = lambda x: -x[1])
#print(tmp)
#print(cnt)
#print(out_candidate)
#print(kiso, kind)

answer = []
answer.append(kiso + kind ** 2)

in_candidate = []
if K < N:
    for i in range(K, N):
        in_candidate.append(TD[i])
in_candidate.sort(key = lambda x: x[1])
#print(in_candidate)

while out_candidate and in_candidate:
    in_t, in_d = in_candidate.pop()
    if cnt[in_t] == 0:
        cnt[in_t] += 1
        out_t, out_d = out_candidate.pop()
        kiso += in_d - out_d
        kind += 1
        answer.append(kiso + kind ** 2)
        
print(max(answer))
Buggy python submission (verdict: Runtime Error):
a=["k","e","y","e","n","c","e"]
s=input()

if a==s[:7] or a==s[-7:]:
  print("YES")
else:
  i=0
  sw=0
  while 1:
    if a[i]==s[i]:
      i+=1
    else:
      break
  while 1:
    if a[i]==s[-7+i]:
      i+=1
    else:
      sw=1
      break
    if i==7:
      break
  print("NO" if sw==1 else "YES")
  

Fixed submission:
a="keyence"
s=input()
#print(s[:7],s[-7:])
if a==s[:7] or a==s[-7:]:
  print("YES")
else:
  i=0
  sw=0
  while 1:
    if a[i]==s[i]:
      i+=1
    else:
      break
  while 1:
    if a[i]==s[-7+i]:
      i+=1
    else:
      sw=1
      break
    if i==7:
      break
  print("NO" if sw==1 else "YES")
Buggy python submission (verdict: Runtime Error):
# 埋める配列
# dp[x] = 足場0からスタートして足場xに着地するときに足場xまでに払うコストの最小値

# 計算方法
# dp[0] = 0
# dp[x] = min(dp[x - 1] + |h[x] - h[x - 1]|, dp[x - 2] + |h[x] - h[x - 2]|, ... ,  dp[x - K] + |h[x] - h[x - K]|)

# 埋める順番
# xが小さい順

N, K = map(int, input().split())
H = list(map(int, input().split()))
INF = 10 ** 18

dp = [0] * (N + 5)

for i in range(1, N):
    dp[i] = INF
    for j in range(1, K + 1):
        if i - j >= 0: # 脳死
            dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))

print(dp[N - 1])

Fixed submission:
N=int(input())
h=list(map(int,input().split()))

c=[0]*N
c[1]=abs(h[1]-h[0])
for i in range(2,N):
  c[i]=min(c[i-2]+abs(h[i]-h[i-2]),c[i-1]+abs(h[i]-h[i-1]))
print(c[-1])
Buggy python submission (verdict: Time Limit Exceeded):
# 埋める配列
# dp[x] = 足場0からスタートして足場xに着地するときに足場xまでに払うコストの最小値

# 計算方法
# dp[0] = 0
# dp[x] = min(dp[x - 1] + |h[x] - h[x - 1]|, dp[x - 2] + |h[x] - h[x - 2]|, ... ,  dp[x - K] + |h[x] - h[x - K]|)

# 埋める順番
# xが小さい順

N, K = map(int, input().split())
H = list(map(int, input().split()))
INF = 10 ** 18

dp = [0] * (N + 5)

for i in range(1, N):
    dp[i] = INF
    for j in range(1, K + 1):
        if i - j >= 0: # 脳死
            dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))

print(dp[N - 1])

Fixed submission:
N, K = map(int, input().split())
H = list(map(int, input().split()))

# 0-indexed
INF = 10 ** 15
dp = [INF] * N
dp[0] = 0

for i in range(N):
  for k in range(1, K+1):
    if i + k < N and dp[i] + abs(H[i+k] - H[i]) < dp[i+k]:
      dp[i+k] = dp[i] + abs(H[i+k] - H[i])
      
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]

dp = [-1 for _ in range(W + 1)] # dp[重量の総和]:= 価値の総和
dp[0] = 0

for i in range(N):
  w, v = wv[i]
  for j in range(W, -1, -1):
    if dp[j] >= 0 and j + w <=  W:
      dp[j+w] = max(dp[j+w], dp[j]+v)
      
print(max(dp))

Fixed submission:
N, W = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(N)]
 
dp = [-1 for _ in range(W + 1)] # dp[重量の総和]:= 価値の総和
dp[0] = 0
 
for i in range(N):
  w, v = wv[i]
  for j in range(W, -1, -1):
    if dp[j] >= 0 and j + w <=  W:
      dp[j+w] = max(dp[j+w], dp[j]+v)
      
print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
S, T = input(), input()

def lcs(S, T):
  LS = len(S)
  LT = len(T)
 
  dps=[["" for _ in range(LT + 1)] for _j in range(LS + 1)]
  dpl=[[0 for _ in range(LT + 1)] for _j in range(LS + 1)]
  # dp[Sのi番目][Tのj番目] := それまでの最大長
 
  for i in range(LS):
    for j in range(LT):
      if S[i] == T[j]:
        dpl[i + 1][j + 1] += dpl[i][j] + 1
        dps[i + 1][j + 1] += dps[i][j] + S[i]
      else:
        if dpl[i + 1][j] >= dpl[i][j + 1]:
          dpl[i + 1][j + 1] = dpl[i + 1][j]
          dps[i + 1][j + 1] = dps[i + 1][j]
        else:
          dpl[i + 1][j + 1] = dpl[i][j + 1]
          dps[i + 1][j + 1] = dps[i][j + 1]
  return dps[-1][-1]

print(lcs(S, T))

Fixed submission:
S = input()
T = input()
 
lenS = len(S)
lenT = len(T)
 
lcs = [[0 for i in range(lenT + 1)] for j in range(lenS + 1)]
 
for i in range(lenS):
  for j in range(lenT):
    if S[i] == T[j]:
      lcs[i + 1][j + 1] = lcs[i][j] + 1
    else:
      lcs[i + 1][j + 1] = max(lcs[i + 1][j], lcs[i][j + 1])
#for i in range(lenS + 1):
#  print(lcs[i])

i, j = lenS, lenT
answer = ""
while i != 0 and j != 0:
  if lcs[i - 1][j] == lcs[i][j] - 1:
    if lcs[i][j - 1] == lcs[i][j] - 1:
      answer += S[i - 1]
      i -= 1
    j -= 1
  else:
    i -= 1
  #print(i, j, lcs[i][j], answer)
print(answer[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
S, T = input(), input()

def lcs(S, T):
  LS = len(S)
  LT = len(T)
 
  dp=[["" for _ in range(LT + 1)] for _j in range(LS + 1)]
  # dp[Sのi番目][Tのj番目] := それまでの最大長
 
  for i in range(LS):
    for j in range(LT):
      if S[i] == T[j]:
        dp[i + 1][j + 1] += dp[i][j] + S[i]
      else:
        if len(dp[i + 1][j]) >= len(dp[i][j + 1]):
          dp[i + 1][j + 1] = dp[i + 1][j]
        else:
          dp[i + 1][j + 1] = dp[i][j + 1]
  return dp[-1][-1]

print(lcs(S, T))

Fixed submission:
S = input()
T = input()
 
lenS = len(S)
lenT = len(T)
 
lcs = [[0 for i in range(lenT + 1)] for j in range(lenS + 1)]
 
for i in range(lenS):
  for j in range(lenT):
    if S[i] == T[j]:
      lcs[i + 1][j + 1] = lcs[i][j] + 1
    else:
      lcs[i + 1][j + 1] = max(lcs[i + 1][j], lcs[i][j + 1])
#for i in range(lenS + 1):
#  print(lcs[i])

i, j = lenS, lenT
answer = ""
while i != 0 and j != 0:
  if lcs[i - 1][j] == lcs[i][j] - 1:
    if lcs[i][j - 1] == lcs[i][j] - 1:
      answer += S[i - 1]
      i -= 1
    j -= 1
  else:
    i -= 1
  #print(i, j, lcs[i][j], answer)
print(answer[::-1])
Buggy python submission (verdict: Runtime Error):
N,P=map(int,input().split())
Q=[0]*(10**6+1)

i=2

while 1:
  if P==1:
    break
  if P%i==0:
    P//=i
    Q[i]+=1
    i=2
  else:
    i+=1
#print(Q[:20])
#print(list(map(lambda x: x//N,Q)))
Q=list(map(lambda x: x//N,Q))

ans=1
for i,q in enumerate(Q):
  if q:
    ans*=i**q
print(ans)

Fixed submission:
N,P=map(int,input().split())
Q=[0]*(10**6+1)

i=2

if N==1:
  print(P)
  exit()

while 1:
  if P==1 or i>=10**6:
    break
  if P%i==0:
    P//=i
    Q[i]+=1
    i=2
  else:
    i+=1
#print(Q[:20])
#print(list(map(lambda x: x//N,Q)))
Q=list(map(lambda x: x//N,Q))

ans=1
for i,q in enumerate(Q):
  if q:
    ans*=i**q
print(ans)
Buggy python submission (verdict: Runtime Error):
from math import log2, ceil
from collections import defaultdict

N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

cnt = defaultdict(int)
for a in A:
  cnt[a] += 1

answer = 0
for a in A:
  if cnt[a]:
    i = (1 << ceil(log2(a))) - a
    if cnt[i]:
      cnt[a] -= 1
      cnt[i] -= 1
      answer += 1
      
print(answer)

Fixed submission:
from math import log2, ceil
from collections import defaultdict

N = int(input())
A = sorted(list(map(int, input().split())))[::-1]

cnt = defaultdict(int)
for a in A:
  cnt[a] += 1

answer = 0
for a in A:
  if cnt[a]:
    if ceil(log2(a)) == log2(a):
      i = (1 << (ceil(log2(a)) + 1)) - a
    else:
      i = (1 << ceil(log2(a))) - a

    if i != a:
      if cnt[i]:
        cnt[a] -= 1
        cnt[i] -= 1
        answer += 1
    else:
      if cnt[i] > 1:
        cnt[a] -= 2
        answer += 1
        
print(answer)
Buggy python submission (verdict: Runtime Error):
N = int(input())
T = int(input())
c_min = -1

for i in range(N):
    c = int(input())
    t = int(input())
    if t <= T:
        if c_min == -1:
            c_min = c
        else:
            if c < c_min:
                c_min = c
if c_min == -1:
    print("TLE")
else:
    print(c)

Fixed submission:
N,T=map(int,input().split())
min_c = 10**10
for i in range(N):
    c,t=map(int,input().split())
    if t<=T:
        min_c=min(min_c,c)
print("TLE" if min_c==10**10 else min_c)

Buggy python submission (verdict: Runtime Error):
N = int(input())
T = int(input())
c_min = -1

for i in range(N):
    c = int(input())
    t = int(input())
    if t <= T:
        if c_min == -1:
            c_min = c
        else:
            if c < c_min:
                c_min = c
if c_min == -1:
    print("TLE")
else:
    print(c)

Fixed submission:
N,T=map(int,input().split())
min_c = 10**10
for i in range(N):
    c,t=map(int,input().split())
    if t<=T:
        min_c=min(min_c,c)
print("TLE" if min_c==10**10 else min_c)
Buggy python submission (verdict: Runtime Error):
print(int(input()/111)*111)

Fixed submission:
print(-(-int(input())//111)*111)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
X = list(map(int, input().split()))

answer = []
for i in range(N):
  if i + K > N:
    break
  Y = X[i:i+K]
  if Y[0] > 0:
    answer.append(Y[-1])
  elif Y[-1] < 0:
    answer.append(-Y[0])
  else:
    answer.append(min(Y[0]*(-2)+Y[-1], Y[-1]*2-Y[0]))

print(min(answer))

Fixed submission:
N,K=map(int,input().split())
x=list(map(int,input().split()))

tmp=10**10
for i in range(N-K+1):
  if x[i]*x[i+K-1]<0:
    tmp=min(tmp,min(abs(x[i]),abs(x[i+K-1]))*2+max(abs(x[i]),abs(x[i+K-1])))
  else:
    tmp=min(tmp,max(abs(x[i]),abs(x[i+K-1])))
print(tmp)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
X = list(map(int, input().split()))

answer = []
for i in range(N):
  if i + K > N:
    break
  Y = X[i:i+K]
  if Y[0] > 0:
    answer.append(Y[-1])
  elif Y[-1] < 0:
    answer.append(-Y[0])
  else:
    answer.append(min(Y[0]*(-2)+Y[-1], Y[-1]*2-Y[0]))

print(min(answer)

Fixed submission:
N,K=map(int,input().split())
x=list(map(int,input().split()))

tmp=10**10
for i in range(N-K+1):
  if x[i]*x[i+K-1]<0:
    tmp=min(tmp,min(abs(x[i]),abs(x[i+K-1]))*2+max(abs(x[i]),abs(x[i+K-1])))
  else:
    tmp=min(tmp,max(abs(x[i]),abs(x[i+K-1])))
print(tmp)
Buggy python submission (verdict: Runtime Error):
# 二次元累積和
# A[i1, j1] から A[i2, j2] までの長方形の積算値は
# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(w + 1)] for _ in range(h + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
#for a in Acum:
#  print(a)

Fixed submission:
A,B=map(int,input().split())
print((A-1)*(B-1))

Buggy python submission (verdict: Runtime Error):
# 二次元累積和
# A[i1, j1] から A[i2, j2] までの長方形の積算値は
# Acum[i2 + 1][j2 + 1] - Acum[i1][j2 + 1] - Acum[i2 + 1][j1] + Acum[i1][j1]
def two_dim_accumulate(a) -> list:
  h, w = len(a), len(a[0])
  acum = [[0 for _ in range(h + 1)] for _ in range(w + 1)]
  for i in range(h):
    for j in range(w):
      acum[i + 1][j + 1] = a[i][j]
  for i in range(1, h + 1):
    for j in range(1, w + 1):
      acum[i][j] += acum[i][j - 1]
  for j in range(1, w + 1):
    for i in range(1, h + 1):
      acum[i][j] += acum[i - 1][j]
  return acum

Acum = two_dim_accumulate(A)
Acum[q][q] - Acum[p - 1][q] - Acum[q][p - 1] + Acum[p - 1][p - 1]


Fixed submission:
A,B=map(int,input().split())
print((A-1)*(B-1))
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
print(max(A,B,C)-min(A,B,C)

Fixed submission:
A,B,C=map(int,input().split())
print(max(A,B,C)-min(A,B,C))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
k=int(input())

print(sum(a,b,c)-max(a,b,c)+max(a,b,c)*(2**k))

Fixed submission:
a=list(map(int,input().split()))
k=int(input())

print(sum(a)-max(a)+max(a)*(2**k))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(map(lambda x: ord(x) - ord("a") + 1, list(input()))) for _ in range(N)]
#print("S:", S)

yoko, tate = [], []
for i in range(N):
  tmp = 0
  for j in range(N):
    tmp += S[i][j] * 2 ** ((N - j - 1) * 5)
  yoko.append(tmp)
for j in range(N):
  tmp = 0
  for i in range(N):
    tmp += S[i][j] * 2 ** ((N - i - 1) * 5)
  tate.append(tmp)
#print("yoko:", yoko)
#print("tate:", tate)

answer = 0
yi, ti = 0, 0
for y in range(N):
  for t in range(N):
    flag = 0
    for i in range(N):
      if yoko[(i + yi) % N] != tate[(i + ti) % N]:
        flag = 1
        break
    if flag == 0:
      answer += 1
    
    # 左にずらす
    for i in range(N):
      tate[i] = (tate[i] << 5 | tate[i] >> (N - 1) * 5) & (2 ** (5 * N) - 1)
    yi += 1
    #print("tate:", tate)

  # 上にずらす
  for i in range(N):
    yoko[i] = (yoko[i] << 5 | yoko[i] >> (N - 1) * 5) & (2 ** (5 * N) - 1)
  ti += 1

print(answer)

Fixed submission:
N = int(input())
S = [list(map(lambda x: ord(x) - ord("a") + 1, list(input()))) for _ in range(N)]
#print("S:", S)

yoko, tate = [], []
for i in range(N):
  tmp = 0
  for j in range(N):
    tmp += S[i][j] * 2 ** ((N - j - 1) * 5)
  yoko.append(tmp)
for j in range(N):
  tmp = 0
  for i in range(N):
    tmp += S[i][j] * 2 ** ((N - i - 1) * 5)
  tate.append(tmp)
#print("yoko:", yoko)
#print("tate:", tate)

answer = 0
yi, ti = 0, 0
for t in range(N):
  flag = 0
  for i in range(N):
    if yoko[(i + yi) % N] != tate[(i + ti) % N]:
      flag = 1
      break
  if flag == 0:
    answer += N
    
  # 左にずらす
  for i in range(N):
    tate[i] = (tate[i] << 5 | tate[i] >> (N - 1) * 5) & (2 ** (5 * N) - 1)
  yi += 1
  #print("tate:", tate)

print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
import math

def comb(a,b):
  return math.factorial(a)//((math.factorial(b)*math.factorial(a-b)))

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

a.sort()
ans=-1
for i in range(N-1):
  if ans<comb(a[-1],a[i]):
    ans=comb(a[-1],a[i])
    max_i=i
print(a[-1],a[max_i])

Fixed submission:
import math

def comb(a,b):
  return math.factorial(a)//((math.factorial(b)*math.factorial(a-b)))

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

a.sort()
a_max=a[-1]
a=a[:-1]
#print(a)

b = [[abs(i+(-a_max//2)),i] for i in a]
b.sort()
print(a_max, b[0][1])
Buggy python submission (verdict: Runtime Error):
S=list(input())
print("YES" if a in S and b in S and c in S else "NO")

Fixed submission:
S="".join(sorted(list(input())))
print("Yes" if S == "abc" else "No")

Buggy python submission (verdict: Runtime Error):
S=input()
print("YES" if a in S and b in S and c in S else "NO")

Fixed submission:
S="".join(sorted(list(input())))
print("Yes" if S == "abc" else "No")
Buggy python submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
printf("Yes" if A+B>=C else "No")

Fixed submission:
A,B,C=map(int,input().split())
print("Yes" if A+B>=C else "No")
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input()))
print(sum(a[::2])-sum(a[1::2]))

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
a.sort()
a=a[::-1]

for i in range(1,N,2):
  a[i] *= -1
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
for i in range(N):
  a[i],b[i]=map(int,input().split())
#print(a)
#print(b)

b.sort(reverse=True)
#print(max(a))
#print(b)

ans=0
for i in range(N):
  if b[i]<max(a):
    break
  if H<=0:
    break
  H-=b[i]
  ans+=1
if H>0:
  ans+=-(-H//max(a))
print(ans)

Fixed submission:
N,H=map(int,input().split())
a=[0]*N
b=[0]*N
for i in range(N):
  a[i],b[i]=map(int,input().split())
#print(a)
#print(b)

b.sort(reverse=True)
maxa=max(a)
#print(max(a))
#print(b)

ans=0
for i in range(N):
  if b[i]<maxa:
    break
  if H<=0:
    break
  H-=b[i]
  ans+=1
if H>0:
  ans+=-(-H//maxa)
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
F=sum(list(str(N)))

ans="Yes"
if N%F:
  ans="No"
print(ans)

Fixed submission:
N=int(input())
F=sum(map(int,list(str(N))))

ans="Yes"
if N%F:
  ans="No"
print(ans)
Buggy python submission (verdict: Runtime Error):
S=input()

T=["AKIHABARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA"]
T+=["AKIHABR","AKIHBAR","KIHABAR","AKIHBRA","KIHABRA","KIHBARA"]
T+=["KIHABR","KIHBAR","KIHBRA","AKIHBR","KIHBR"]
#print(T)

prin("YES" if S in T else "NO")

Fixed submission:
S=input()

T=["AKIHABARA","AKIHABAR","AKIHABRA","AKIHBARA","KIHABARA"]
T+=["AKIHABR","AKIHBAR","KIHABAR","AKIHBRA","KIHABRA","KIHBARA"]
T+=["KIHABR","KIHBAR","KIHBRA","AKIHBR","KIHBR"]
#print(T)

print("YES" if S in T else "NO")
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
c=[]
for i in range(10):
  c.append(list(map(int,input().split())))

for i in range(10):
  for j in range(10):
    for k in range(10):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])
#print(c)

ans=0
for i in range(H):
  A=list(map(int,input()))
  for j in A:
    if A[i][j]!=-1:
      ans+=c[A[i][j]][1]
print(ans)

Fixed submission:
H,W=map(int,input().split())
c=[]
for i in range(10):
  c.append(list(map(int,input().split())))

for k in range(10):
  for i in range(10):
    for j in range(10):
      c[i][j]=min(c[i][j],c[i][k]+c[k][j])
#print(c)

ans=0
for i in range(H):
  A=list(map(int,input().split()))
  for j in A:
    if j>=0:
      ans+=c[j][1]
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

bc=[0]*N
ii=0
for i in range(N):
  while c[ii]<=b[i] and ii<N:
    ii+=1
    if ii==N:
      break
  bc[i]=N-ii
#print(bc)
for i in range(N-2,-1,-1):
  bc[i]+=bc[i+1]
#print(bc)

ab=[0]*N
ii=0
for i in range(N):
  while b[ii]<=a[i] and ii <N:
    ii+=1
    if ii==N:
      break
  ab[i]=bc[ii] if ii<N else 0
print(sum(ab))

Fixed submission:
import bisect as bi

N=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

a.sort()
c.sort()
#print(a)
#print(c)

ans=0
for i in b:
  ans+=bi.bisect_left(a,i)*(N-bi.bisect_right(c,i))
print(ans)