Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)


Fixed submission:
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K,*X = map(int,open(0).read().split())
S = bin(K)[2:]
L = len(S)
ls = [(a,b) for a,b in zip(*[iter(X)]*2)]
s = '0'
ans = 0
for i,c in enumerate(S):
  if c=='0':
    s += c
    continue
  j = L-i
  m = (1<<(j-1))-1
  n = int(s,2)<<j
  x = m|n
  v = 0
  for a,b in ls:
    if x==x|a:
      v += b
  ans = max(v,ans)
  s += c
v = 0
for a,b in ls:
  if K==K|a:
    v += b
ans = max(ans,v)
print(ans)


Fixed submission:
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K,*X = map(int,open(0).read().split())
S = bin(K)[2:]
L = len(S)
ls = [(a,b) for a,b in zip(*[iter(X)]*2)]
s = '0'
ans = 0
for i,c in enumerate(S):
  if c=='0':
    s += c
    continue
  j = L-i
  m = (1<<(j-1))-1
  n = int(s,2)<<j
  x = m|n
  v = 0
  for a,b in ls:
    if x==x|a:
      v += b
  ans = max(v,ans)
  s += c
v = 0
for a,b in ls:
  if K==K|a:
    v += b
ans = max(ans,v)
print(ans)

Fixed submission:
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)

Buggy python submission (verdict: Runtime Error):
N,K,*X = map(int,open(0).read().split())
S = bin(K)[2:]
L = len(S)
ls = [(a,b) for a,b in zip(*[iter(X)]*2)]
s = '0'
ans = 0
for i,c in enumerate(S):
  if c=='0':
    s += c
    continue
  j = L-i
  m = (1<<(j-1))-1
  n = int(s,2)<<j
  x = m|n
  v = 0
  for a,b in ls:
    if x==x|a:
      v += b
  ans = max(v,ans)
  s += c
v = 0
for a,b in ls:
  if K==K|a:
    v += b
ans = max(ans,v)
print(ans)

Fixed submission:
N,K,*X = map(int, open(0).read().split())
S = bin(K)[2:]
L = len(S)
one = set()
ls = [(a,b) for a,b in zip(*[iter(X)]*2) if a<=K]
kls = [K]
ans = 0
for i in range(L):
  if S[i]=='1':
    m = int(S[:i]+'0'+'1'*(L-i-1),2)
    kls.append(m)
for k in kls:
  m = 0
  for a,b in ls:
    if k==k|a:
      m += b
  ans = max(ans,m)
print(ans)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
N = int(input())
dic = [0]*N
for i in range(N):
  dic[i] = [int(c) for c in input().split()]

d = floyd_warshall(dic)
ans = 0
for i in range(N-1):
  for j in range(i+1,N):
    if d[i][j] < dic[i][j]:
      print(-1)
      break
    elif dic[i][j] == d[i][j]:
      flag = False
      for k in range(N):
        if k==i or k==j:
          continue
        if d[i][j] == d[i][k]+d[k][j]:
          flag = True
          ans = -1
          break
      if flag:
        continue
    ans += dic[i][j]

print(ans)


Fixed submission:
N = int(input())
A = int(input())
print(N*N-A)
Buggy python submission (verdict: Runtime Error):
from itertools import permutations
N, M, R, *L = map(int, open('0').read().split())
city = L[:R]
inf = L[R:]
dist = [[10**10]*N for i in range(N)]
for x,y,c in zip(*[iter(inf)]*3):
  dist[x-1][y-1] = c
  dist[y-1][x-1] = c
for i in range(N):
  dist[i][i] = 0

for k in range(N):
  for i in range(N):
    for j in range(N):
      dist[i][j] = min(dist[i][k]+dist[k][j], dist[i][j])

ans = 10**10
for m in permutations(city):
  n = 0
  for i in range(R-1):
    n += dist[m[i]-1][m[i+1]-1]
  ans = min(ans,n)
  print(n,m)
print(ans)  
  

Fixed submission:
from itertools import permutations
N, M, R = map(int, input().split())
r = [int(c)-1 for c in input().split()]
cost = [[float('inf')]*N for i in range(N)]
for i in range(M):
  a, b, c = map(int, input().split())
  cost[a-1][b-1] = c
  cost[b-1][a-1] = c
def warshall_floyd(d,n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
dist = warshall_floyd(cost,N)
ls = list(permutations(r))
ans = -1
for l in ls:
  m = 0
  p = l[0]
  flag = False
  for q in l[1:]:
    m += dist[p][q]
    p = q
  if ans==-1 or ans>m:
    ans = m
print(ans)
Buggy python submission (verdict: Runtime Error):
import numpy as np
H, W, N, *A = map(int, open('0').read().split())
ls = []
for i in range(N):
  ls += [str(i+1)]*A[i]
ls = np.array(ls)
ls = ls.reshape((H,W))
ls[1::2] = ls[1::2,::-1]
for a in ls:
  print(' '.join(a))

Fixed submission:
import numpy as np
H, W, N, *A = map(int, open(0).read().split())
ls = []
for i in range(N):
  ls += [str(i+1)]*A[i]
ls = np.array(ls)
ls = ls.reshape((H,W))
ls[1::2] = ls[1::2,::-1]
for a in ls:
  print(' '.join(a))
Buggy python submission (verdict: Time Limit Exceeded):
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = []
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans.append(max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(min(ans))

Fixed submission:
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = []
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans.append(max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(min(ans))

Buggy python submission (verdict: Time Limit Exceeded):
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = N
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans = min(ans,max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(ans)

Fixed submission:
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = []
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans.append(max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(min(ans))

Buggy python submission (verdict: Runtime Error):
N, M, *X = map(int, open('0').read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = N
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans = min(ans,max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(ans)

Fixed submission:
N, M, *X = map(int, open(0).read().split())
A = []
for a in zip(*[iter(X)]*M):
  A.append(a)
log = set(range(1,M+1))
ans = []
while log:
  dic = {}
  for i in range(N):
    for j in range(M):
      if A[i][j] in log:
        dic[A[i][j]] = dic.get(A[i][j],0)+1
        break
  ans.append(max(dic.values()))
  c = max(dic.keys(),key=lambda x:dic[x])
  log.remove(c)
print(min(ans))
Buggy python submission (verdict: Runtime Error):
N, S = open('0').read().split()
N = int(N)
cnt = 0
l = 0
for i in range(N):
  if S[i]=='(':
    cnt += 1
  else:
    if cnt==0:
      l += 1
    else:
      cnt -= 1
cnt = 0
r = 0
for i in range(N-1,-1,-1):
  if S[i]==')':
    cnt += 1
  else:
    if cnt==0:
      r += 1
    else:
      cnt -= 1
print('('*l+S+')'*r)

Fixed submission:
N, S = open(0).read().split()
N = int(N)
cnt = 0
l = 0
for i in range(N):
  if S[i]=='(':
    cnt += 1
  else:
    if cnt==0:
      l += 1
    else:
      cnt -= 1
cnt = 0
r = 0
for i in range(N-1,-1,-1):
  if S[i]==')':
    cnt += 1
  else:
    if cnt==0:
      r += 1
    else:
      cnt -= 1
print('('*l+S+')'*r)
Buggy python submission (verdict: Runtime Error):
N, A, B , *h = map(int, open('0').read().split())
C = A-B
l = -1
r = 10**12
while l+1<r:
  s = (l+r)//2
  M = [c-s*B for c in h]
  cnt = sum((c+C-1)//C if c>0 else 0 for c in M)
  if cnt>s:
    l = s
  else:
    r = s
print(r)

Fixed submission:
from math import ceil
N, A, B = map(int, input().split())
h = []
for i in range(N):
  h += [int(input())]

Th = 2*max(h)//B
Tl = 0
while Tl+1<Th:
  t = (Th+Tl)//2
  d = []
  for i in range(N):
    c = h[i]
    d += [c-B*t]
  for i in range(N):
    c = d[i]
    if c<=0:
      continue
    t -= ceil(c/(A-B))
    if t<0:
      Tl = (Th+Tl)//2
      break
  else:
    Th = (Th+Tl)//2
print(Th)
Buggy python submission (verdict: Runtime Error):
N, W = map(int,input().split())
ls = []
for i in range(N):
  w, v = map(int, input().split())
  ls += [[w,v]]
w1 = ls[0][0]
for i in range(N):
  ls[i][0] -= w1
ans = 0
M = 3*N
dp = [[-1]*(W+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
  w, v = ls[i]
  for h in range(N,0,-1):
    for j in range(W,-1,-1):
      if j-w>=0 and dp[h-1][j-w]!=-1:
        dp[h][j] = max(dp[h][j], dp[h-1][j-w]+v)
for i in range(1,N+1):
  B = i*w1
  m = 0
  for j in range(M,-1,-1):
    if B+j<=W:
      m = max(m,dp[i][j])
  if ans<m:
    ans = m
print(ans)

Fixed submission:
N, W = map(int,input().split())
ls = []
for i in range(N):
  w, v = map(int, input().split())
  ls += [[w,v]]
w1 = ls[0][0]
for i in range(N):
  ls[i][0] -= w1
ans = 0
M = 3*N
dp = [[-1]*(M+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
  w, v = ls[i]
  for h in range(N,0,-1):
    for j in range(M,-1,-1):
      if j-w>=0 and dp[h-1][j-w]!=-1:
        dp[h][j] = max(dp[h][j], dp[h-1][j-w]+v)
for i in range(1,N+1):
  B = i*w1
  m = 0
  for j in range(M+1):
    if B+j<=W:
      m = max(m,dp[i][j])
  if ans<m:
    ans = m
print(ans)

Buggy python submission (verdict: Runtime Error):
N, W = map(int,input().split())
ls = []
for i in range(N):
  w, v = map(int, input().split())
  ls += [[w,v]]
w1 = ls[0][0]
for i in range(N):
  ls[i][0] -= w1
ans = 0
M = 3*N
dp = [[-1]*(W+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
  w, v = ls[i]
  for h in range(N,-1,-1):
    for j in range(W,-1,-1):
      if j-w>=0 and dp[h-1][j-w]!=-1:
        dp[h][j] = max(dp[h][j], dp[h-1][j-w]+v)
for i in range(1,N+1):
  B = i*w1
  m = 0
  for j in range(M,-1,-1):
    if B+j<=W:
      m = max(m,dp[i][j])
  if ans<m:
    ans = m
print(ans)

Fixed submission:
N, W = map(int,input().split())
ls = []
for i in range(N):
  w, v = map(int, input().split())
  ls += [[w,v]]
w1 = ls[0][0]
for i in range(N):
  ls[i][0] -= w1
ans = 0
M = 3*N
dp = [[-1]*(M+1) for i in range(N+1)]
dp[0][0] = 0
for i in range(N):
  w, v = ls[i]
  for h in range(N,0,-1):
    for j in range(M,-1,-1):
      if j-w>=0 and dp[h-1][j-w]!=-1:
        dp[h][j] = max(dp[h][j], dp[h-1][j-w]+v)
for i in range(1,N+1):
  B = i*w1
  m = 0
  for j in range(M+1):
    if B+j<=W:
      m = max(m,dp[i][j])
  if ans<m:
    ans = m
print(ans)
Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)

Fixed submission:
N, *A = map(int, open(0).read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)
Buggy python submission (verdict: Runtime Error):
from functools import lru_cache
N, *A = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for i in range(N-1):
  dic[A[i]] += [i+2]
@lru_cache(None)
def solve(n):
  if len(dic[n])==0:
    return 0
  ls = []
  for e in dic[n]:
    ls += [solve(e)]
  ls.sort(reverse=True)
  return max(ls[i]+i+1 for i in range(len(ls)))

print(solve(1))

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N, *A = map(int, open(0).read().split())
dic = [[] for i in range(N+1)]
for i in range(N-1):
  dic[A[i]] += [i+2]
def solve(n):
  if len(dic[n])==0:
    return 0
  ls = []
  for e in dic[n]:
    ls += [solve(e)]
  ls.sort(reverse=True)
  return max(ls[i]+i+1 for i in range(len(ls)))

print(solve(1))
Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
Els = []
for i in range(M):
  a, b, c = map(int, input().split())
  dic[a-1] += [(b-1,c)]
  dic[b-1] += [(a-1, c)]
  Els += [(a,b,c)]

def dijkstra(s,e):
  dist = [float('inf')]*N
  dist[s] = 0
  q = [(0,s)]
  z = -1
  while q:
    c, v = heappop(q)
    if dist[v]<c:
      continue
    dist[v] = c
    for u, m in dic[v]:
      if dist[u]>dist[v]+m:
        dist[u] = dist[v]+m
        heappush(q,(dist[v],v))
        if u==e:
          z = v
  return z

ans = 0
for a, b, c in Els:
  if dijkstra(a,b)==a:
    ans += 1
print(ans)

Fixed submission:
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
Els = []
for i in range(M):
  a, b, c = map(int, input().split())
  dic[a-1] += [(b-1,c)]
  dic[b-1] += [(a-1, c)]
  Els += [(a-1,b-1,c)]

def dijkstra(s,e):
  dist = [float('inf')]*N
  dist[s] = 0
  q = [(0,s)]
  z = -1
  while q:
    c, v = heappop(q)
    if dist[v]<c:
      continue
    dist[v] = c
    for u, m in dic[v]:
      if dist[u]>dist[v]+m:
        dist[u] = dist[v]+m
        heappush(q,(dist[u],u))
        if u==e:
          z = v
  return z

ans = 0
for a, b, c in Els:
  if dijkstra(a,b)!=a:
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate as acc
N, K, *A = map(int, open('0').read().split())
B = [0]+list(acc(A))
M = list(acc(a if a>0 else 0 for a in A))
ans = -10**30
s = sum(A)
for i in range(N-K+1):
  mi = B[i+K]-B[i]
  c = M[N-1] - M[i+K-1]
  if i>0:
    c += M[i-1]
  ans = max(ans,mi+c,c)
print(ans)

Fixed submission:
from itertools import accumulate as acc
N, K, *A = map(int, open(0).read().split())
B = [0]+list(acc(A))
M = list(acc(a if a>0 else 0 for a in A))
ans = -10**30
s = sum(A)
for i in range(N-K+1):
  mi = B[i+K]-B[i]
  c = M[N-1] - M[i+K-1]
  if i>0:
    c += M[i-1]
  ans = max(ans,mi+c,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
N, *P = map(int, open('0').read().split())
b = list(range(N*N, N-1, -N))
a = [0]*N
for i,p in enumerate(P):
  a[p-1] = N*p+i
print(*a)
print(*b)

Fixed submission:
N, *P = map(int, open(0).read().split())
b = list(range(N*N, N-1, -N))
a = [0]*N
for i,p in enumerate(P):
  a[p-1] = N*p+i
print(*a)
print(*b)
Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Fixed submission:
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1,-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Buggy python submission (verdict: Runtime Error):
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[0]
for i in range(1,N):
  if A[i]>=A[i-1]:
    flag = True
  else:
    if flag:
      ls += [A[i-1]-st]
    flag = False
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Fixed submission:
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1,-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)
Buggy python submission (verdict: Runtime Error):
H, W, N, *L = map(int, open('0').read().split())
dic = {}
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[i*W+j] = dic.get(i*W+j,0)+1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print('\n'.join(map(str,ans)))

Fixed submission:
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')

Buggy python submission (verdict: Runtime Error):
from collections import defaultdict
H, W, N, *L = map(int, open('0').read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')
        

Fixed submission:
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')
Buggy python submission (verdict: Runtime Error):
from itertools import accumulate as acc
N, x, *A = map(int, open(0).read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**10
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)

Fixed submission:
from itertools import accumulate as acc
N, x, *A = map(int, open(0).read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**60
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate as acc
N, x, *A = map(int, open('0').read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**10
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)

Fixed submission:
from itertools import accumulate as acc
N, x, *A = map(int, open(0).read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**60
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)
Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
ans = sum(c//2 for c in A)
A = [c%2 for c in A]
for i in range(N-2):
  if A[i]==A[i+1]==1:
    A[i+1] = 0
    ans += 1
print(ans)

Fixed submission:
N, *A = map(int, open(0).read().split())
ls = []
s = 0
ans = 0
for c in A:
  if c==0:
    ans += s//2
    s = 0
  else:
    s += c
ans += s//2
print(ans)
Buggy python submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
ans = 0
B = sorted(A)
dic = {B[i]:i for i in range(N)}
for i,n in enumerate(A):
  if i%2!=dic[n]%2:
    ans += 1
print(ans//2)

Fixed submission:
N, *A = map(int, open(0).read().split())
ans = 0
B = sorted(A)
dic = {B[i]:i for i in range(N)}
for i,n in enumerate(A):
  if i%2!=dic[n]%2:
    ans += 1
print(ans//2)
Buggy python submission (verdict: Time Limit Exceeded):
def sq(a, b, mod):  # aのb乗を剰余,kは初期値#20191116-D-Knight
    if b == 0:
        return 1
    elif b % 2 == 0:
        return sq(a, b // 2, mod)**2 % mod
    else:
        return sq(a, b - 1, mod) * a % mod


def nCk(n, k, mod=998244353):
    x = max(k, n - k)
    y = min(k, n - k)
    kkai = 1
    for i in range(2, y + 1):
        kkai = (kkai * i) % mod
    nkkai = 1
    for i in range(x + 1, n + 1):
        nkkai = (nkkai * i) % mod
    answer = sq(kkai, mod - 2, mod) * nkkai % mod
    return answer


N, M, K = map(int, input().split())
mod = 998244353
ans = 0
for i in range(K+1):
    ans += pow(M-1, N-1-i, mod) * nCk(N-1, i)
    ans %= mod
ans *= M
print(ans%mod)

Fixed submission:
mod = 998244353
max = (10**5)*2 + 1
facts = [1 for i in range(max)]
invs = [1 for i in range(max)]
 
def inv(x):
    return pow(x,mod-2,mod)
 
for i in range(1,max):
    facts[i] = facts[i-1]*i%mod
    invs[i] = inv(facts[i])
 
def nCk(n,r):
    return facts[n]*invs[r] * invs[n-r] % mod



N, M, K = map(int, input().split())
ans = 0
for i in range(K+1):
    ans += pow(M-1, N-1-i, mod) * nCk(N-1, i)
    ans %= mod
ans *= M
print(ans%mod)
Buggy python submission (verdict: Runtime Error):
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    try:
        for i in range(len(num)):
            a = num[i]
            for j in range(i+1):
                if a - num[j] == X:
                    x, y = i-1, j-1
                    # print(i-1, j-1)
                    assert x**5-y**5 == X
                    return x, y
    except IndexError:
        print(0)
print(*solve(int(input())))


Fixed submission:
num = [i**5 for i in range(-121, 121)]
X = int(input())
for i in range(len(num)):
    a = num[i]
    for j in range(i+1):
        if a - num[j] == X:
            print(i-121, j-121)
            exit()

Buggy python submission (verdict: Runtime Error):
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    try:
        for i in range(len(num)):
            a = num[i]
            for j in range(i+1):
                if a - num[j] == X:
                    x, y = i-1, j-1
                    # print(i-1, j-1)
                    assert x**5-y**5 == X
                    return x, y
    except AssertionError:
        print(0)
print(*solve(int(input())))


Fixed submission:
num = [i**5 for i in range(-121, 121)]
X = int(input())
for i in range(len(num)):
    a = num[i]
    for j in range(i+1):
        if a - num[j] == X:
            print(i-121, j-121)
            exit()

Buggy python submission (verdict: Runtime Error):
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    for i in range(len(num)):
        a = num[i]
        for j in range(i+1):
            if a - num[j] == X:
                x, y = i-1, j-1
                # print(i-1, j-1)
                assert x**5-y**5 == X
                return x, y
print(*solve(int(input())))


Fixed submission:
num = [i**5 for i in range(-121, 121)]
X = int(input())
for i in range(len(num)):
    a = num[i]
    for j in range(i+1):
        if a - num[j] == X:
            print(i-121, j-121)
            exit()
Buggy python submission (verdict: Time Limit Exceeded):
from collections import Counter
N = int(input())
S = input()
Sc = Counter(S)
rgb = Sc["R"] * Sc["G"] * Sc["B"]
for j in range(1, N-1):
    for i in range(j):
        k = j + (j-i)
        assert i < j < k
        if k < N:
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                rgb -= 1
print(rgb)

Fixed submission:
from collections import Counter
N = int(input())
S = input()
Sc = Counter(S)
rgb = Sc["R"] * Sc["G"] * Sc["B"]
for j in range(1, N-1):
    for i in range(j):
        k = j + (j-i)
        assert i < j < k
        if k < N:
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                rgb -= 1
print(rgb)