Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03262 (python)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# import math
from functools import reduce
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

N,X = map(int, input().split())
A = list(map(int, input().split()))
A = [ abs(a-X) for a in A]

print( reduce(gcd, A) )

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
import math
from functools import reduce


N,X = map(int, input().split())
A = list(map(int, input().split()))
A = [ abs(a-X) for a in A]

print( reduce(math.gcd, A) )

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
N,X = map(int, input().split())
A = list(map(int, input().split()))
A = [ abs(a-X) for a in A]
import math
from functools import reduce

print( reduce(math.gcd, A) )

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
N,X = map(int, input().split())
A = list(map(int, input().split()))
A = [ abs(a-X) for a in A]
import math
from functools import reduce

print( reduce(math.gcd, A) )
Problem p03393 (python)

Fixed submission:
s=input()
b="abcdefghijklmnopqrstuvwxyz"
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
lst=[]
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      lst.append(s[:i]+mn)
      #print(s[:i]+mn)
      #exit()
if lst:
  print(sorted(lst)[0])
  exit()
print(-1)

Buggy submission (verdict: Runtime Error):
s=input()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn)
      exit()
print(-1)

Buggy submission (verdict: Runtime Error):
s=input() 
b="".join(list(reversed("zyxwvutsrqponmlkjihgfedcba")))
if s=="zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn+s[i:first]+s[first+1])
      exit()
Problem p03452 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5)
N,M = map(int, input().split())
input = sys.stdin.readline
LRD = [ [int(j) for j in input().split()] for _ in range(M)]

data = [x for x in range(N+1)]
rank = [0]  * (N+1)
diff_weight = [0] * (N+1)

def root(x):
    if data[x] == x:
        return x
    else:
        r = root( data[x] )
        diff_weight[x] += diff_weight[ data[x] ]
        data[x] = r
        return r

def weight(x):
    # _ = root(x)
    return diff_weight[x]


def diff(x,y):
    return weight(y) - weight(x)

def merge(x,y,w):
    w  += weight(x); w -= weight(y)
    x = root(x)
    y = root(y)
    if x == y: return False
    if rank[x] < rank[y]: x,y = y,x; w = -w
    if rank[x] == rank[y]: rank[x] += 1
    data[y] = x
    diff_weight[y] = w
    return True

def issame(x,y):
    return root(x) == root(y)

for i in range(M):
    L,R,D = LRD[i]
    # print(L,R,D)
    if not issame(L,R):
        _  = merge(L,R,D)
    else:
        if diff(L,R) != D:
            print("No")
            exit(0)
            
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
N,M = map(int, input().split())
input = sys.stdin.readline()
LRD = [ [int(j) for j in input().split()] for _ in range(M)]

data = [-1] * (N+1)
rank = [0]  * (N+1)
diff_weight = [0] * (N+1)

def root(x):
    if data[x] == x:
        return x
    else:
        r = root(x)
        diff_weight[x] += diff_weight[ data[x] ]
        data[x] = r
        return r

def weight(x):
    _ = root(x)
    return diff_weight[x]


def diff(x,y):
    return weight(y) - weight(x)

def merge(x,y,w):
    w  += weight(x); w -= weight(y)
    x = root(x)
    y = root(y)
    if x == y: return False
    if rank[x] < rank[y]: x,y = y,x; w = -w
    if rank[x] == rank[y]: rank[x] += 1
    data[y] = x
    diff_weight[y] = w
    return True

def issame(x,y):
    return root(x) == root(y)

for i in range(M):
    L,R,D = LRD[i]
    if not issame(L,R):
        merge(L,R,D)
    else:
        if weight(L,R) != D:
            print("No")
            exit(0)
            
print("Yes")

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
N,M = map(int, input().split())
LRD = [ [int(j) for j in input().split()] for _ in range(M)]

data = [-1] * (N+1)
rank = [0]  * (N+1)
diff_weight = [0] * (N+1)

def root(x):
    if data[x] == x:
        return x
    else:
        r = root(x)
        diff_weight[x] += diff_weight[ data[x] ]
        data[x] = r
        return r

def weight(x):
    _ = root(x)
    return diff_weight[x]


def diff(x,y):
    return weight(y) - weight(x)

def merge(x,y,w):
    w  += weight(x); w -= weight(y)
    x = root(x)
    y = root(y)
    if x == y: return False
    if rank[x] < rank[y]: x,y = y,x; w = -w
    if rank[x] == rank[y]: rank[x] += 1
    data[y] = x
    diff_weight[y] = w
    return True

def issame(x,y):
    return root(x) == root(y)

for i in range(M):
    L,R,D = LRD[i]
    if not issame(L,R):
        merge(L,R,D)
    else:
        if weight(L,R) != D:
            print("No")
            exit(0)
            
print("Yes")
Problem p03569 (python)

Fixed submission:
s=input()

i=0 
j=len(s)-1
ans=0
while i<=j:
  if s[i]==s[j]:
    i+=1
    j-=1
  elif s[i]=="x":
    ans+=1
    i+=1
  elif s[j]=="x":
    ans+=1
    j-=1
  else:  break
if i <=j :
  print(-1)
  exit(0) 
else: print(ans)

Buggy submission (verdict: Runtime Error):
s=input()
baks=s[:]
s="".join(list(filter(lambda x:x!="x",s)))
revs="".join(list(reversed(s)))
i=0 
j=len(s-1)
ans=0
while i<=j:
  if s[i]==s[j]:
    i+=1
    j-=1
  elif s[i]=="x":
    ans+=1
    i+=1
  elif s[j]=="x":
    ans+=1
    j-=1
  else:  break
if i <=j :
  print(-1)
  exit(0) 
else: print(ans)
Problem p03593 (python)

Fixed submission:
H,W=map(int,input().split())
A=[input() for _ in range(H)]
from collections import defaultdict
d=defaultdict(int)
for a in A:
  for j in a:
    #print("j: ",j)
    d[j]+=1

four=0
two=0
one=0

for i in  range(26):
  c=chr(ord("a")+i)
  if d[c]>=4:
    four+=d[c]//4 
    d[c]%=4
  if d[c]>=2:
    two+=d[c]//2
    d[c]%=2
  if d[c]>=1:
    one+=d[c]
    d[c]-=1

if four<(H//2)*(W//2):    
  print("No")
  exit(0)
four-=(H//2)*(W//2)
two+=four*2

if H%2==1:
  if two < W//2:
    print("No")
    exit()
  two-=W//2
if W%2==1:
  if two <H//2:
    print("No")
    exit()
  two-=H//2

print("Yes")

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[[int(j) for j in input().split()] for _ in range(H)]
from collections import defaultdict
d=defaultdict(int)
for a in A:
  for j in a:
    d[j]+=1

four=0
two=0
one=0

for i in  range(26):
  c=chr(ord("a")+i)
  if d[c]>=4:
    four+=d[c]//4 
    d[c]%=4
  if d[c]>=2:
    two+=d[c]//2
    d[c]%=2
  if d[c]>=1:
    one+=d[c]
    d[c]-=1
    
if four<=(H//2)*(W//2):    
  print("No")
  exit(0)
four-=(H//2)*(W//2)
two+=four*2

if H%2==1:
  if two < W//2:
    print("No")
    exit()
  two-=W//2
if W%2==1:
  if two <H//2:
    print("No")
    exit()
  two-=H//2

print("Yes")
Problem p03614 (python)

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

lst = []
ans = 0
for e,p in enumerate(P,1):
    if e == p:
        ans += 1

        if e < N:
            P[e] = 0
print(ans)
exit(0)

st = False
ans = 0
for a,b,c in zip(lst[::2], lst[1::2] + [-1], lst[2::2] + [-1, -1]):
    print(a,b,c)
    if b == -1:
        if st:
            break
        ans += 1
        break

    if c == -1:
        if not st and a +1 == b:
            ans += 1
        elif st :
            ans += 1
        else:
            ans += 2
        break

    if not st and a+1 == b:
        ans += 1
        continue
    if not st and b+1 == c:
        st = True
        ans += 1
    if st and b+1 == c:
        ans += 1

    st = False
    ans += 2
print(ans)

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

lst = []
ans = 0
skip = False
for e,p in enumerate(P,1):
    if skip:
        skip = False
        continue
    if e == p:
        ans += 1
        if e-1 < N and P[e] == e+1:
            skip = True
        # lst.append(e)
print(ans)
exit(0)

st = False
ans = 0
for a,b,c in zip(lst[::2], lst[1::2] + [-1], lst[2::2] + [-1, -1]):
    print(a,b,c)
    if b == -1:
        if st:
            break
        ans += 1
        break

    if c == -1:
        if not st and a +1 == b:
            ans += 1
        elif st :
            ans += 1
        else:
            ans += 2
        break

    if not st and a+1 == b:
        ans += 1
        continue
    if not st and b+1 == c:
        st = True
        ans += 1
    if st and b+1 == c:
        ans += 1

    st = False
    ans += 2
print(ans)
Problem p03640 (python)

Fixed submission:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
ANS = [ [0]*W for _ in range(H)]
nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    for x in range(W):
      nct-=1
      ANS[y][x] = str(nc)
      if nct==0 and nc<N:
        nct=A[nc]
        nc+=1
  else:
    for x in range(W-1,-1,-1):
      nct-=1
      ANS[y][x] = str(nc) 
      if nct==0 and nc<N:
        nct=A[nc]
        nc+=1
        
      
for y in range(H):
    print(" ".join(ANS[y]) )

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=""
    for x in range(W):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
  else:
    st=""
    for x in range(W-1,-1,-1):
      nc-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st="".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(ans[y])
Problem p03662 (python)

Fixed submission:
N=int(input())

import sys
sys.setrecursionlimit(10**5)
ab=[list(map(int, input().split())) for _ in range (N-1)]
con=[[] for _ in range(N+1)]

#print(ab)
for a,b in ab :
  con[a].append(b)
  con[b].append(a)

#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[N]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")

Buggy submission (verdict: Runtime Error):
N=int(input())
import sys
ab=[[int(j) for j in sys.stdin.readline()] for _ in range (N-1)]
con=[[] for _ in range(N+1)]

for a,b in ab :
  con[a].append(b)
  con[b].append(a)

#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[1]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")
Problem p03666 (python)

Fixed submission:
N,A,B,C,D = map(int, input().split())

n = N-1

found = False

B = abs(A-B)
for i in range(0, n+1):
    if C*(n-i)-D*(i) <= B <= D*(n-i)-C*(i):
        found = True
        break

if found:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N,A,B,C,D=map(int,input().split())


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  target=abs(target)
  if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
 　target-=D
    
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")
Problem p03702 (python)

Fixed submission:
N,A,B=map(int,input().split())
H=[int(input()) for _ in range(N)]
H=sorted(H,reverse=True)

ok=max(H)//B+1
ng=0
mid=(ok+ng)//2
while ok-ng>1:
  cntlive=0
  for h in H:
    h-=B*mid
    if h>0:
      cntlive+=(h+A-B-1)//(A-B)
  if cntlive<=mid:
    ok=mid
  else:
    ng=mid
  mid=(ok+ng)//2
print(ok)

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
H=[inp(input()) for _ in range(N)]
H=sorted(H,reverse=True)

ok=max(H)//B+1
ng=0
mid=(ok+ng)//2
while ok-ng>1:
  cntlive=0
  for h in H:
    h-=B*mid
    if h>0:
      cntlive+=1
  if cntlive<=mid:
    ok=mid
  else:
    ng=mid
  mid=(ok+ng)//2
print(ok)
Problem p03722 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

N,M = map(int, input().split())
abc = [[int(j) for j in input().split()] for _ in range(M)]
con=[[] for _ in range (N+1)]
inf = float("inf")

allcost = [ -inf] * (N+1)
allcost[1] = 0

for i in range(M):
    a,b,c = abc[i]
    con[a].append(b)

for n in range(1, N):
    for edge in range(M):
        a,b,c = abc[edge]
        if allcost[b] < allcost[a] + c:
            allcost[b] = allcost[a] + c
neg=[False]*(N+1)
for edge in range(M):
    a,b,c = abc[edge]
    if allcost[a] + c > allcost[b]:
        neg[b]=True
    if neg[a]==True:
      neg[b]=True
if neg[N]:
  print("inf")
  exit(0)
print(allcost[N])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,M = map(int, input().split())
abc = [[int(j) for j in input().split()] for _ in range(M)]
con=[[] for _ in range (N+1)]
inf = float("inf")

allcost = [ -inf] * (N+1)
allcost[1] = 0

for i in range(M):
    a,b,c = abc[i]
    con[a].append(b)

for n in range(1, N):
    for edge in range(M):
        a,b,c = abc[edge]
        if allcost[b] < allcost[a] + c:
            allcost[b] = allcost[a] + c
def dfs(a):
  if N in con[a]:
    return True
  if len(con[a])==0:
    return False
  tmp=False 
  for ch in con[a]:
    if dfs(ch):
      tmp=True 
      break
  return tmp
for edge in range(M):
    a,b,c = abc[edge]
    if allcost[a] + c > allcost[b]:
        if dfs(a):
          print("inf")
          exit(0)

print(allcost[N])

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N,M = map(int, input().split())
abc = [[int(j) for j in input().split()] for _ in range(M)]
con=[[] for _ in range (N+1)]
inf = float("inf")

allcost = [ -inf] * (N+1)
allcost[1] = 0

for i in range(M):
    a,b,c = abc[i]
    con[a].append(b)

for n in range(1, N):
    for edge in range(M):
        a,b,c = abc[edge]
        if allcost[b] < allcost[a] + c:
            allcost[b] = allcost[a] + c
def dfs(a):
  if N in con[a]:
    return True
  if len(con[a])==0:
    return False
  tmp=False 
  for ch in con[a]:
    if dfs(ch):
      tmp=True 
      break
  return tmp
for edge in range(M):
    a,b,c = abc[edge]
    if allcost[a] + c > allcost[b]:
        if dfs(b):
          print("inf")
          exit(0)

print(allcost[N])
Problem p03734 (python)

Fixed submission:
N,W=map(int,input().split())
wv=[ tuple([int(j) for j in input().split()]) for _ in range(N) ]
w1=wv[0][0]
w2=w1+1
w3=w1+2 
w4=w1+3

wv=sorted(wv,key=lambda x:x[1],reverse=True)
wv=sorted(wv,key=lambda x:x[0])
wvv = list(map(lambda x:x[1], wv))

# print(wv)
inf = float("inf")
ans=0
from collections import defaultdict
counter = defaultdict(int)

for i in range(N):
    w,v = wv[i]
    counter[w] += 1

from bisect import bisect_left as bll

for e1 in range(0, counter[w1]+1):
  for e2 in range(0, counter[w2]+1):
    for e3 in range(0,counter[w3]+1):
      for e4 in range(0, counter[w4]+1):
          tmp=0

          if w1*e1 + w2*e2 + w3*e3 + w4*e4 > W:
              continue

          i1=bll(wv, (w1,-inf))
          i2=bll(wv, (w2,-inf))
          i3=bll(wv, (w3,-inf))
          i4=bll(wv, (w4,-inf))

          tmp= tmp \
             +sum(wvv[i1:i1+e1])  \
             +sum(wvv[i2:i2+e2])  \
             +sum(wvv[i3:i3+e3])  \
             +sum(wvv[i4:i4+e4])

          ans=max(ans,tmp)
      
print(ans)

Buggy submission (verdict: Runtime Error):
N,W=map(int,input().split())
wv=[[int(j) for j in input().split()] for _ in range(N) ]
w0=wv[0][0]
w1=w0+1
w2=w1+1 
w3=w2+1
wv=sorted(wv,key=lambda x:x[1],reverse=True)
wv=sorted(wv)

ans=0
from bisect import bisect_left as bll
for e1 in range(0,W//w0+1):
  l2=W-w0*e1
  for e2 in range(0,l2//(w0+1)+1):
    l3=l2-(w0+1)*e2
    for e3 in range(0,l3//(w0+2)+1):
      l4=l3- (w0+2)*e3
      e4 =l4//(w0+3)    
      tmp=0
      i1=bll(wv, (w0,inf))
      i2=bll(wv, (w1,inf))
      i3=bll(wv, (w2,inf))
      i4=bll(wv, (w3,inf))
      tmp+=sum(wv[i1:i1+e1])  \
         +sum(wv[i2:i2+e2])  \
         +sum(wv[i3:i3+e3])  \
        +sum(wv[i4:i4+e4])
      ans=max(ans,tmp)
      
print(ans)
Problem p03761 (python)

Fixed submission:
N=int(input())
from collections import Counter,defaultdict
s=input()
ddict=defaultdict(int)
for c in s:
  ddict[c]+=1
for i in range(N-1):
  s=input()
  cnt=Counter(s)
  for k in cnt.keys():
    ddict[k]=min(ddict[k],cnt[k])
  for k in ddict.keys():
    if not k in cnt.keys():
      ddict[k]=0
ans=""
for k in range(26):    
  c =chr(ord("a")+k)
  ans+=c*ddict[c]
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
from collections import Counter,defaultdict
s=input()
ddict=defaultdict(int)
for c in s:
  ddict[c]+=1
for i in range(N-1):
  s=input()
  cnt=Counter[s]
  for k in cnt.keys():
    ddict[k]=min(ddict[k],cnt[k])
ans=""
for k in range(26):    
  c =chr(ord("a")+k)
  ans+=c*ddict[c]
print(ans)
Problem p03837 (python)

Fixed submission:
N,M = map(int, input().split())
inp = []
for i in range(M):
    a,b,c = map(int,input().split())
    inp.append( (a-1, b-1, c) )

inf = float("inf")
dist  =  [[inf] * N for _ in range(N)]

for i in range(M):
    dist[inp[i][0]][inp[i][1]] = inp[i][2]
    dist[inp[i][1]][inp[i][0]] = inp[i][2]

for mid in range(N):
    for start in range(N):
        for end in range(N):
            dist[start][end] = min(dist[start][end],
                    dist[start][mid] + dist[mid][end])


ans = 0
for ai,bi,ci in inp:
    if dist[ai][bi] != ci:
        ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
sx,sy,tx,ty = map(int, input().split())

ans = ""

#UP
ans += "U" * (ty-sy)
ans += "R" * (tx-sx)
ans += "D" * (ty-sy)
ans += "L" * (tx-sx)
ans += "L" + "U"* (ty-sy+1) + "R" * (tx-sx+1) + "D"
ans += "R" + "D" * (ty-sy+1) + "L"*(tx-sx+1) + "U"

print(ans)
Problem p03958 (python)

Fixed submission:
K,T=map(int,input().split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
d2=deque(A)
ans=A[0]
mod=1
while d:
  if len(d)==1:
    print(d[0]-1)
    exit()
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  if not b==1:
    d.appendleft(b-1)
print(0)

Buggy submission (verdict: Runtime Error):
K,T=map(int,input().split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
d2=deque(A)
ans=A[0]
mod=1
while d:
  if len(d)==1:
    print(d[0]-1)
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  if not b==1:
    d.appendleft(b-1)

Buggy submission (verdict: Runtime Error):
K,T=map(int,input.split())
A=list(map(int,input().split()))
from heapq import heappush,heappop
from collections import deque

A.sort(reverse=True)
d=deque(A)
while d:
  if len(d)==1:
    print(d-1)
    exit()
  a=d.pop()
  b=d.popleft()
  if not a==1:
    d.append(a-1)
  d.appendleft(b-1)
Problem p03994 (python)

Fixed submission:
s=input()
K=int(input())
ans=[]

for c in s:
  if c=="a":
    ans.append(c)
    continue
  if ord("z")+1- ord(c)<=K:
    K-=ord("z")+1-ord(c)
    ans.append("a")
    continue
    
  ans.append(c)
    
if K:
  ans[-1]=chr( (ord(ans[-1])+K%26 -ord("a"))%26+ord("a") )
print("".join(ans))

Buggy submission (verdict: Runtime Error):
s=input()
K=int(input())
ans=[]

for c in s:
  if c=="a":
    ans.append(c)
    continue
  if ord("z")+1- ord(c)<=K:
    K-=ord("z")+1-ord(c)
    ans.append("a")
    continue
    
  ans.append(c)
    
if K:
  ans[-1]=chr( ord(ans[-1])+K)
print("".join(ans))
Problem p04006 (python)

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

ans = float("inf")
bik = A[:]

get_idx_back = lambda idx,b: idx-b if idx>=b else idx+N-b

for loop in range(0, N+1):
  if loop == 0:
      bik = A[:]
  else: 
      for i in range(N):
          bik[i] = min(bik[i], A[ get_idx_back(i, loop) ])

  tmp = (loop)*X + sum(bik)

  ans = min(tmp, ans)
print(ans)
exit(0)

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

# ans = 10**13
ans = float("inf")

for k in range(N):
    tmp = k * X  

    for i in range(2*N):
        j = (i-k+N*4) % N
        A[i] = min(A[i], A[j])
    tmp += sum(A)

    ans = min(ans, tmp)
print(ans)
Problem p04020 (python)

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

ans=0
idx=[]
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

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

ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
  
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
  
n=0
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
#0,1,2のみにする
for i in range(N):
  a=A[i]
  if a>=2 and a%2==0:
    A[i]=2
    ans+=(a-2)//2
  elif a%2==1:
    A[i]=1
    ans+=(a-1)//2
  elif a==0:
    pass
  

for i in range(1,N-1):
  b,a,c=A[i-1:i+1]
  if a==2:
    if b%2==1 and c %2==1:
      A[i-1]-=1 
      A[i+1]-=1
      A[i]-=2
      ans+=2
    
for i in range(1,N):
  a,b=A[i-1:i+1]
  if a%2==1 and b%2==1:
    ans+=1
    A[i-1]-=1
    A[i]-=1  

ans+=len(list(filter(lambda x:x==2,A)))
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(1,N+1):
  if A[i-1]>=A[i]:
    ans+=A[i]
    ans+=(A[i-1]-A[i])//2
    A[i]=0
  else:
    ans+=A[i-1]
    ans+=(A[i]-A[i-1])//2
    A[i]-=A[i-1]
    
print(ans)