Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
x=x-a
x=x%b
print(x)

Fixed submission:
x=int(input())
a=int(input())
b=int(input())
x=x-a
x=x%b
print(x)
Buggy python submission (verdict: Runtime Error):
s=input()
print(s.cout('a'))

Fixed submission:
s=input()
print(s.count('1'))
Buggy python submission (verdict: Runtime Error):
s=input()
if 'AC' in S:
  print("Yes")
else:
  print("No")

Fixed submission:
s=input()
if 'AC' in s:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, c, d = [int(x) for x in input().split()]
ans = a*c
n_ans = a*c
for i in range(a, b+1):
  for j in range(c, d+1):
    n_ans = i*j
    ans = max(ans, n_ans)
print(ans)

Fixed submission:
a, b, c, d = [int(x) for x in input().split()]
ans = [a*c, a*d, b*c, b*d]
print(max(ans))
Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
c = [str(x) for x in list(input())]
R = sum([1 for i, x in enumerate(c) if(x=='R')])
W = 0
if(R==N)or(R==0):
  print(0)
  sys.exit()
ans = R
i = 0
while True:
  if(c[i] == 'W'):
    W += 1
  else:
    R -= 1
  n_ans = max(W,R)
  if(n_ans>ans):
    print(ans)
    sys.exit()
  ans = n_ans
  i += 1


Fixed submission:
import sys
N = int(input())
c = [str(x) for x in list(input())]
R = sum([1 for i, x in enumerate(c) if(x=='R')])
W = 0
if(R==N)or(R==0):
  print(0)
  sys.exit()
ans = R
i = 0
while True:
  if(i==N):
    print(ans)
    sys.exit()
  if(c[i] == 'W'):
    W += 1
  else:
    R -= 1
  n_ans = max(W,R)
  if(n_ans>ans):
    print(ans)
    sys.exit()
  ans = n_ans
  i += 1
Buggy python submission (verdict: Runtime Error):
import numpy as np
N = int(input())
ans = np.zeros((10**4+5))
for i in range(1,100):
  for j in range(1,100):
    for l in range(1,100):
      f = (i+j)**2+(j+l)**2+(l+i)**2
      if((f%2==0) and (f<=2*10**4)):
        ans[int(f/2)] += 1

for i in range(1,N+1):
  print(int(ans[i]))

Fixed submission:
L, R, d = [int(x) for x in input().split()]
ans = 0
for i in range(L, R+1):
  if(i%d == 0):
    ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
N, M, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
B = [float(x) for x in input().split()]
 
AB = list()
a = 0
b = 0
for i in range(N+M):
  if ((a < N) and (b < M)):
    if(A[a] == B[b]):
      AB.append(A[a])
      a += 1
      AB.append(B[b])
      b += 1
    elif(A[a] < B[b]):
      AB.append(A[a])
      a += 1
    else:
      AB.append(B[b])
      b += 1
  elif(a == N):
    for j in range(M-b):
      AB.append(B[b])
      b += 1
    break
  elif(b == M):
    for j in range(N-a):
      AB.append(A[a])
      a += 1
    break
    
ans = 0
K = float(K)
while K >= 0:
  K -= AB[ans]
  ans += 1
  if((ans == (N+M)) and (K > 0)):
    print(N+M)
    sys.exit()
  
print(ans-1)

Fixed submission:
import sys
import numpy as np
N, M, K = [int(x) for x in input().split()]
A = [float(x) for x in input().split()]
B = [float(x) for x in input().split()]
a = [0]
b = [0]
for i in range(N):
  a.append(A[i] + a[i])
for i in range(M):
  b.append(B[i] + b[i])
ans, j = 0, M
for i in range(N+1):
  if(a[i]>K):
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i+j)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 0
for j in range(1, N+1):
  for i in range(1,N+1):
    if(i%j == 0):
      ans += i
print(ans)

Fixed submission:
N = int(input())
ans = 0
for j in range(1, N+1):
  Y = int(N / j)
  ans += (j * Y*(Y+1)/2)
print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
NM = 10**7+5

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
if __name__ == '__main__':
  
  ans = 0
  for i in range(1, N+1):
    f = make_divisors(i)
    ans += (i*len(f))
  print(ans)

Fixed submission:
N = int(input())
ans = 0
for j in range(1, N+1):
  Y = int(N / j)
  ans += (j * Y*(Y+1)/2)
print(int(ans))
Buggy python submission (verdict: Runtime Error):
if __name__ == "__main__":
  N = int(input())
  A = [int(x) for x in input().split()]
  Q = int(input())
  for i in range(Q):
    A.sort()
    B, C = [int(x) for x in input().split()]
    A = [x if x!=B else C for x in A]
    print(sum(A))

Fixed submission:
x = str(input())
if(x.islower()):
  print('a')
else:
  print('A')
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == "__main__":
  N = int(input())
  A = [int(x) for x in input().split()]
  Q = int(input())
  for i in range(Q):
    B, C = [int(x) for x in input().split()]
    A = [x if x!=B else C for x in A]
    print(sum(A))

Fixed submission:
import numpy as np
M = 100002

if __name__ == "__main__":
  N = int(input())
  A = [int(x) for x in input().split()]
  Q = int(input())
  Num = np.zeros((M))
  Sum = sum(A)
  for i in range(N):
    Num[A[i]] += 1
  for i in range(Q):
    B, C = [int(x) for x in input().split()]
    if(Num[B] == 0):
      print(int(Sum))
    else:
      Sum = Sum + (C - B)*Num[B]
      Num[C] += Num[B]
      Num[B] = 0
      print(int(Sum))
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    t = gcd(a,b)
    for c in range(1,K+1):
      ans += gcd(t,c)
print(ans)

Fixed submission:
import math
from functools import reduce
K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for a in range(1,K+1):
  if (a==1):
    ans += K*K
    continue
  for b in range(1,K+1):
    t = gcd(a,b)
    if(t==1):
      ans += K
      continue
    for c in range(1,K+1):
      ans += gcd(t,c)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce
K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    for c in range(1,K+1):
      ans += gcd(a,b,c)
print(ans)

Fixed submission:
import math
from functools import reduce
K = int(input())

def gcd(*numbers):
  return reduce(math.gcd, numbers)

ans = 0
for a in range(1,K+1):
  if (a==1):
    ans += K*K
    continue
  for b in range(1,K+1):
    t = gcd(a,b)
    if(t==1):
      ans += K
      continue
    for c in range(1,K+1):
      ans += gcd(t,c)
print(ans)
Buggy python submission (verdict: Runtime Error):
print(int(input()/3**3))

Fixed submission:
L = int(input())
print((L/3)**3)
Buggy python submission (verdict: Runtime Error):
ans = np.full(N+1, -1)
for i in range(M):
  if(ans[s[i]]==-1):
    ans[s[i]] = c[i]
  elif(ans[s[i]]!=c[i]):
    print(-1)
    sys.exit()

if(ans[1]==0)and(N!=1):
  print(-1)
  sys.exit()
if(ans[1]==-1)and(n!=1):
  ans[1] = 1
ans = np.where(ans==-1, 0, ans)
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))

Fixed submission:
import numpy as np
import sys
N, M = [int(x) for x in input().split()]
s = []
c = []
for i in range(M):
  a, b = [int(x) for x in input().split()]
  s.append(a)
  c.append(b)
  
ans = np.full(N+1, -1)
for i in range(M):
  if(ans[s[i]]==-1):
    ans[s[i]] = c[i]
  elif(ans[s[i]]!=c[i]):
    print(-1)
    sys.exit()
if(ans[1]==-1)and(N>1):
  ans[1] = 1
ans = np.where(ans==-1, 0, ans)
 
if(ans[1]==0)and(N!=1):
  print(-1)
  sys.exit()
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))

Buggy python submission (verdict: Runtime Error):
import numpy as np
import sys
N, M = [int(x) for x in input().split()]
s = []
c = []
for i in range(M):
  a, b = [int(x) for x in input().split()]
  s.append(a)
  c.append(b)

ans = np.full(N+1, -1)
for i in range(M):
  if(ans[s[i]]==-1):
    ans[s[i]] = c[i]
  elif(ans[s[i]]!=c[i]):
    print(-1)
    sys.exit()
if(ans[1]==-1)and(n>1):
  ans[1] = 1
ans = np.where(ans==-1, 0, ans)

if(ans[1]==0)and(N!=1):
  print(-1)
  sys.exit()
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))

Fixed submission:
import numpy as np
import sys
N, M = [int(x) for x in input().split()]
s = []
c = []
for i in range(M):
  a, b = [int(x) for x in input().split()]
  s.append(a)
  c.append(b)
  
ans = np.full(N+1, -1)
for i in range(M):
  if(ans[s[i]]==-1):
    ans[s[i]] = c[i]
  elif(ans[s[i]]!=c[i]):
    print(-1)
    sys.exit()
if(ans[1]==-1)and(N>1):
  ans[1] = 1
ans = np.where(ans==-1, 0, ans)
 
if(ans[1]==0)and(N!=1):
  print(-1)
  sys.exit()
Ans = 0
for i in range(1, N+1):
  Ans += 10**(N-i)*ans[i]
print(int(Ans))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [str(input()) for i in range(N)]
B = list(set(A))
B.sort()
Adict = {}
for i in range(len(B)):
  Adict[B[i]] = 0
for i in range(N):
  Adict[A[i]] += 1
ans = [x[0] for x in Adict.items() if x[1]==max(Adict.values())] 
for i in range(len(ans)):
  print(ans[i])

Fixed submission:
import collections
 
N,*S = open(0).read().split()
C = collections.Counter(S)
 
i = C.most_common()[0][1]
print(*sorted([k for k,v in C.most_common() if v == i]), sep='\n')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [str(input()) for i in range(N)]
A.sort()
B = list(set(A))
B.sort()
ans = [0 for _ in range(len(B))]
for i in range(len(B)):
  ans[i] = A.count(B[i])
i_max = [i for i, x in enumerate(ans) if(max(ans)==x)]
for i in range(len(i_max)):
  print(B[i_max[i]])

Fixed submission:
import collections
 
N,*S = open(0).read().split()
C = collections.Counter(S)
 
i = C.most_common()[0][1]
print(*sorted([k for k,v in C.most_common() if v == i]), sep='\n')
Buggy python submission (verdict: Runtime Error):
N, K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
H.sort()
for i in range(1,K+1):
  H[N-i] = 0
print(sum(H))

Fixed submission:
import sys
N, K = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
H.sort()
if(N<K):
  print(0)
  sys.exit()
else:
  for i in range(1,K+1):
    H[N-i] = 0
print(sum(H))
Buggy python submission (verdict: Runtime Error):
N = int(input())
D, X = [int(x) for x in input().split()]
A = [int(input()) for _ in range(N)]
ans = X
for i in range(N):
  a = 1
  l = 1
  while a <= D:
    ans += 1
    a = l*A[i] + 1
    l += 1
print(ans)N = int(input())
D, X = [int(x) for x in input().split()]
A = [int(input()) for _ in range(N)]
ans = X
for i in range(N):
  a = 1
  l = 1
  while a <= D:
    ans += 1
    a = l*A[i] + 1
    l += 1
print(ans)

Fixed submission:
N = int(input())
D, X = [int(x) for x in input().split()]
A = [int(input()) for _ in range(N)]
ans = X
for i in range(N):
  a = 1
  l = 1
  while a <= D:
    ans += 1
    a = l*A[i] + 1
    l += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
S = list(input())
s = list(set(S))
s.sort()
alfa = list('abcdefghijklmnopqrstuvwxyg')
ans = 0
if(len(s)==len(alfa)):
  print('None')
  sys.exit()
else:
  for i in range(len(s)):
    if(s[i]!=alfa[i]):
      print(alfa[i])
      sys.exit()
  print(alfa[len(s)+1])

Fixed submission:
import sys
S = list(input())
s = list(set(S))
s.sort()
alfa = list('abcdefghijklmnopqrstuvwxyz')
ans = 0
if(len(s)==len(alfa)):
  print('None')
  sys.exit()
else:
  for i in range(len(s)):
    if(s[i]!=alfa[i]):
      print(alfa[i])
      sys.exit()
  print(alfa[len(s)])

Buggy python submission (verdict: Runtime Error):
import sys
S = list(input())
s = list(set(S))
s.sort()
alfa = list('abcdefghijklmnopqrstuvwxyg')
ans = 0
if(len(s)==len(alfa)):
  print('None')
else:
  for i in range(len(s)):
    if(s[i]!=alfa[i]):
      print(alfa[i])
      sys.exit()
  print(a)

Fixed submission:
import sys
S = list(input())
s = list(set(S))
s.sort()
alfa = list('abcdefghijklmnopqrstuvwxyz')
ans = 0
if(len(s)==len(alfa)):
  print('None')
  sys.exit()
else:
  for i in range(len(s)):
    if(s[i]!=alfa[i]):
      print(alfa[i])
      sys.exit()
  print(alfa[len(s)])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
sn = 0
while n>9:
  sn += n%10
  n = n//10
if (sn+n)%9==0:
  print("Yes")
else:
  print("No")
  

Fixed submission:
n = input()
sn = 0
ln = len(n)
for i in range(ln):
  sn += int(n[i])
if sn%9==0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
p = [0] + list(map(int,input().split()))
c = [0] + list(map(int,input().split()))
maxsc = 0
for s in range(1,n+1):
  x = s
  sc = [0]
  i = 0
  while i<k:
    x = p[x]
    sc.append(sc[i]+c[x])
    i += 1
  print(sc)
  maxsc = max(maxsc, max(sc))
print(maxsc)

Fixed submission:
n,k = map(int,input().split())
p = [0] + list(map(int,input().split()))
c = [0] + list(map(int,input().split()))
maxsc = -1E20
for s in range(1,n+1):
  x = s
  sc = [0]
  i = 0
  while i<k:
    x = p[x]
    sc.append(sc[i]+c[x])
    i += 1
    if x == s:
      loop = i
      loopsc = sc[i]
      if loopsc > 0:
        baseup = loopsc * int((k-i)/loop)
        for j in range(loop):
          sc[j+1] += baseup
        for j in range((k-i)%loop):
          sc[j+1] += loopsc
      i=k
  sc[0] = -1e20
  maxsc = max(maxsc, max(sc))
print(maxsc)
Buggy python submission (verdict: Runtime Error):
import sys
import numpy as np
input = lambda: sys.stdin.readline().rstrip()

def main():
  n,m,k = map(int, input().split())
  a = tuple(map(int, input().split()))
  b = tuple(map(int, input().split()))
  sa = [0] * (n+1)
  sb = [0] * (m+1)
  for i in range(n):
    sa[i+1] = sa[i] + a[i]
  for i in range(m):
    sb[i+1] = sb[i] + b[i]
  rx = 0
  rb = m
  for ra in range(0,n+1): 
    while (sb[rb] + sa[ra]) > k and rb>0 :
      rb-=1
    if (sb[rb] + sa[ra]) <= k:
      rx = max(rx,ra+rb)
  print(rx)

if __name__ == '__main__':
    main()

Fixed submission:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
for i in range(m):
  sb[i+1] = sb[i] + b[i]
rx = 0
rb = m
for ra in range(0,n+1): 
  while (sb[rb] + sa[ra]) > k and rb>0 :
    rb-=1
  if (sb[rb] + sa[ra]) <= k:
    rx = max(rx,ra+rb)
print(rx)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
readable = 0
for rx in range(1,n+m+1):
  if readable == rx: break
  for ra in range(0,rx+1):
    rb = rx - ra
    rt = 0
    if ra <= len(a) and rb <= len(b):
      if ra>0 :
        for i in range(0,ra):
          rt += a[i]
      if rb>0 :
        for i in range(0,rb):
          rt += b[i]
      if rt <= k:
        readable = rx
        break
print(readable)


Fixed submission:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
for i in range(m):
  sb[i+1] = sb[i] + b[i]
rx = 0
rb = m
for ra in range(0,n+1): 
  while (sb[rb] + sa[ra]) > k and rb>0 :
    rb-=1
  if (sb[rb] + sa[ra]) <= k:
    rx = max(rx,ra+rb)
print(rx)

Buggy python submission (verdict: Time Limit Exceeded):
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
readable = 0
for rx in range(1,n+m+1):
  for ra in range(0,rx+1):
    rb = rx - ra
    rt = 0
    if ra <= len(a) and rb <= len(b):
      if ra>0 :
        for i in range(0,ra):
          rt += a[i]
      if rb>0 :
        for i in range(0,rb):
          rt += b[i]
      if rt <= k: readable = rx
print(readable)

Fixed submission:
n,m,k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n+1)
sb = [0] * (m+1)
for i in range(n):
  sa[i+1] = sa[i] + a[i]
for i in range(m):
  sb[i+1] = sb[i] + b[i]
rx = 0
rb = m
for ra in range(0,n+1): 
  while (sb[rb] + sa[ra]) > k and rb>0 :
    rb-=1
  if (sb[rb] + sa[ra]) <= k:
    rx = max(rx,ra+rb)
print(rx)
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
l,r=map(int,input().split())
s={i for i in range(l,r+1)}
for _ in range(M-1):
    l, r = map(int, input().split())
    t = {i for i in range(l, r + 1)}
    s = s & t
    if len(s) == 0:
        print(0)
        exit(0)
print(len(s))

Fixed submission:
N,M=map(int,input().split())
lmax=0
rmin=9999999
for i in range(M):
    l,r=map(int,input().split())
    lmax=max(lmax,l)
    rmin=min(rmin,r)

print(max(rmin-lmax+1,0))
Buggy python submission (verdict: Runtime Error):
import math
N,K=map(int,input().split())

sum=0
for deme in range(1,N+1):
    need_challenge=max(0,math.ceil(math.log2(K)-math.log2(deme)))
    sum+=float((1/N)*((1/2)**need_challenge))
print('{:.13f}'.format(sum))

Fixed submission:
import math
N,K=map(int,input().split())

sum=0
for deme in range(1,N+1):
    need_challenge=max(0,math.ceil(math.log2(K)-math.log2(deme)))
    sum+=float((1/N)*((1/2)**need_challenge))
print('{:.13f}'.format(sum))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input())
print(N - (K - 1))


Fixed submission:
N, K = map(int, input().split())
print(N - (K - 1))
Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

targets = [N - R * i for i in range(int(N / R) + 1)]
score = 0
for g in range(3001):
    for b in range(3001):
        if g + b > 3000:
            break
        if (g * G + b * B) in targets:
            score += 1

print(score)

Fixed submission:
R, G, B, N = map(int, input().split())

score = 0

for g in range(3001):
    for b in range(3001):
        if g + b > 3000:
            break
        if (N - (g * G + b * B)) >= 0 and (N - (g * G + b * B)) % R == 0:
            score += 1

print(score)

Buggy python submission (verdict: Time Limit Exceeded):
R, G, B, N = map(int, input().split())

targets = [N - R * i for i in range(int(N / R) + 1)]
score = 0
for g in range(3001):
    for b in range(3001):
        if g + b > 3000:
            break
        if (g * G + b * B) in targets:
            score += 1

print(score)

Fixed submission:
R, G, B, N = map(int, input().split())

score = 0

for g in range(3001):
    for b in range(3001):
        if g + b > 3000:
            break
        if (N - (g * G + b * B)) >= 0 and (N - (g * G + b * B)) % R == 0:
            score += 1

print(score)
Buggy python submission (verdict: Time Limit Exceeded):
S = input()
stalen = len(S)
beflen = 0
while beflen != len(S):
    beflen = len(S)
    S = S.replace('10', '')
    S = S.replace('01', '')

print(stalen - len(S))


Fixed submission:
S = input()


print( min(S.count('0'), S.count('1')) * 2)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
stalen = len(S)
beflen = 0
while beflen != len(S):
    beflen = len(S)
    S = S.replace('10', '')
    S = S.replace('01', '')

print(stalen - len(S))


Fixed submission:
S = input()


print( min(S.count('0'), S.count('1')) * 2)
Buggy python submission (verdict: Runtime Error):
# 入力
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

INF = 10 ** 9


def dfs(cursor, a, b, c):  # cursor:カーソル a,b,c:現在の竹の長さ
    if cursor == N:  # cursorが最後まで行ったら終了する。
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # abs(a - A) + abs(b - B) + abs(c - C) - 30 でなぜ30を減じているのかというと、
    # dfs(0,0,0)
    # dfs(0,0,0,0)で始まる以上、最初に選ばれるa,b,cを決定する際にもコストが10増加してしまうからである。
    # また、全探索を行う中で、a,b,cの初期値が0,0,0である以上、a,b,cのどれかが0のまま終了する場合が存在する。
    # この場合はa,b,cに竹が対応してないと言えるため、解にはならない、そこで三項演算子を利用して
    # その場合についてコストをINFとしている

    # 以下は4**Nで展開される再起処理となる。
    # カーソルの当たっている竹に対して、(A or B or Cに合成する) or (合成しない)の場合に分ける
    no_compound_pattern = dfs(cursor, a, b, c)
    compound_a_pattern = dfs(cursor, a + L[cursor], b, c)
    compound_b_pattern = dfs(cursor, a, b + L[cursor], c)
    compound_c_pattern = dfs(cursor, a, b, c + L[cursor])

    # 結果的に以下の値が返るのはそれぞれのパターンのコストが決定されてからなので
    # 以下のコードは最終的なコストの最小値
    return min(no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern)


print(dfs(0, 0, 0, 0))


Fixed submission:

# 入力
N, A, B, C = map(int, input().split())
L = [int(input()) for i in range(N)]

INF = 10 ** 9


def dfs(cursor, a, b, c):  # cursor:カーソル a,b,c:現在の竹の長さ
    if cursor == N:  # cursorが最後まで行ったら終了する。
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    # abs(a - A) + abs(b - B) + abs(c - C) - 30 でなぜ30を減じているのかというと、
    # dfs(0,0,0)
    # dfs(0,0,0,0)で始まる以上、最初に選ばれるa,b,cを決定する際にもコストが10増加してしまうからである。
    # また、全探索を行う中で、a,b,cの初期値が0,0,0である以上、a,b,cのどれかが0のまま終了する場合が存在する。
    # この場合はa,b,cに竹が対応してないと言えるため、解にはならない、そこで三項演算子を利用して
    # その場合についてコストをINFとしている

    # 以下は4**Nで展開される再起処理となる。
    # カーソルの当たっている竹に対して、(A or B or Cに合成する) or (合成しない)の場合に分ける
    no_compound_pattern = dfs(cursor+1, a, b, c)
    compound_a_pattern = dfs(cursor+1, a + L[cursor], b, c)+10
    compound_b_pattern = dfs(cursor+1, a, b + L[cursor], c)+10
    compound_c_pattern = dfs(cursor+1, a, b, c + L[cursor])+10

    # 結果的に以下の値が返るのはそれぞれのパターンのコストが決定されてからなので
    # 以下のコードは最終的なコストの最小値
    return min(no_compound_pattern, compound_a_pattern, compound_b_pattern, compound_c_pattern)


print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
Xs=list(map(int,input().split()))


Xs.sort()
costs=[abs(Xs[i]-Xs[i+1]) for i in range(M-1)]


for i in range(N-1):
    if not costs:
        print(0)
        exit(0)
    costs.remove(max(costs))




print(sum(costs))

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


Xs.sort()
costs=[abs(Xs[i]-Xs[i+1]) for i in range(M-1)]
costs.sort(reverse=True)

for i in range(N-1):
    if not costs:
        print(0)
        exit(0)
    costs.pop(0)




print(sum(costs))

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
Xs=list(map(int,input().split()))


Xs.sort()
costs=[]

for i in range(M-1):
    costs.append(abs(int(Xs[i])-int(Xs[i+1])))

for i in range(N-1):
    if not costs:
        print(0)
        exit(0)
    costs.remove(max(costs))




print(sum(costs))

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


Xs.sort()
costs=[abs(Xs[i]-Xs[i+1]) for i in range(M-1)]
costs.sort(reverse=True)

for i in range(N-1):
    if not costs:
        print(0)
        exit(0)
    costs.pop(0)




print(sum(costs))

Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
Xs=input().split()

Xs=[int(Xs[i]) for i in range(M)]

Xs.sort()
costs=[]

for i in range(M-1):
    costs.append(abs(Xs[i]-Xs[i+1]))





for i in range(N-1):
    costs.remove(max(costs))

if not costs:
    print(0)
    exit(0)

print(sum(costs))

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


Xs.sort()
costs=[abs(Xs[i]-Xs[i+1]) for i in range(M-1)]
costs.sort(reverse=True)

for i in range(N-1):
    if not costs:
        print(0)
        exit(0)
    costs.pop(0)




print(sum(costs))
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
H=[0]+[int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    if i-K < 1:
        starter=1
    else:
        starter=i-K

    lists=[dp[i]]+[dp[x]+abs(H[x]-H[i]) for x in range(starter,i)]

    dp[i] = min(lists)


print(dp[N])



Fixed submission:
N,K=map(int,input().split())
H=[0]+[int(h) for h in input().split()]
dp = [999999999 for _ in range(N + 1)]
dp[0] = 0
dp[1] = 0
dp[2] = abs(H[2] - H[1])
for i in range(3, N + 1):
    if i-K < 1:
        starter=1
    else:
        starter=i-K

    lists=[dp[i]]+[dp[x]+abs(H[x]-H[i]) for x in range(starter,i)]

    dp[i] = min(lists)


print(dp[N])