Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] == "a": continue
		k -= ord('z') - ord(s[i]) + 1
		s[i] = "a"

	i += 1
k = k%26
s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

Fixed submission:

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] != "a":
			k -= ord('z') - ord(s[i]) + 1
			s[i] = "a"

	i += 1
k = k%26
s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

Buggy python submission (verdict: Runtime Error):

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] == "a": continue
		k -= ord('z') - ord(s[i]) + 1
		s[i] = "a"

	i += 1

s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

Fixed submission:

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] != "a":
			k -= ord('z') - ord(s[i]) + 1
			s[i] = "a"

	i += 1
k = k%26
s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

Buggy python submission (verdict: Runtime Error):

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= (aord + 26 - ord(s[i])):
		k -= (aord + 26 - ord(s[i]))
		s[i] = "a"

	i += 1

s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)

Fixed submission:

aord = ord("a")
s = list(raw_input())
k = int(input())
i = 0

while k > 0 and i < len(s):
	if k >= ord('z') - ord(s[i]) + 1:
		if s[i] != "a":
			k -= ord('z') - ord(s[i]) + 1
			s[i] = "a"

	i += 1
k = k%26
s[len(s)-1] = chr(ord(s[len(s)-1]) + k)
print ''.join(s)
Buggy python submission (verdict: Runtime Error):
n = int(input())

arr = [map(int,raw_input().split()) for i in range(n)]

count = 0
for i in range(n-1):
	for j in range(i+1,n):
			s = sum(arr[i]) + sum(arr[j])
			comb = s*(s-1)/2
			count += comb

print count%(1000000000+7)

Fixed submission:
n = int(input())

arr = map(int,raw_input().split())

arr.sort()

count = 0
for i in range(n):
	count += arr[i*2]

print count
Buggy python submission (verdict: Runtime Error):
N=input()
if N%2==0:
    print((N)/2-1)
else:
    print((N-1)/2)

Fixed submission:
N=int(input())
if N%2==0:
    print(int((N)/2-1))
else:
    print(int((N-1)/2))

Buggy python submission (verdict: Runtime Error):
if N%2==0:
    print((N)/2-1)
else:
    print((N-1)/2)

Fixed submission:
N=int(input())
if N%2==0:
    print(int((N)/2-1))
else:
    print(int((N-1)/2))

Buggy python submission (verdict: Runtime Error):
 if N%2==0 :
    print((N)/2-1)
 else:
  print((N-1)/2)

Fixed submission:
N=int(input())
if N%2==0:
    print(int((N)/2-1))
else:
    print(int((N-1)/2))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = a * b

if c % 2 == 0:
  print("Even")
  
elif c % 2 != 0:
  print("Odd")

Fixed submission:
a, b = input().rsplit()
c = int(a) * int(b)

if c % 2 == 0:
  print("Even")
  
elif c % 2 != 0:
  print("Odd")

Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = a * b

if c % 2 == 0:
  print("Even")
  
else:
  print("Odd")

Fixed submission:
a, b = input().rsplit()
c = int(a) * int(b)

if c % 2 == 0:
  print("Even")
  
elif c % 2 != 0:
  print("Odd")
Buggy python submission (verdict: Runtime Error):
s = input()
a = [0] * (len(s) + 1)
cur = 0
for i in range(len(s)):
  a[i] = cur
  cur = 0 if s[i] == '>' else cur + 1 
a[-1] = cur
cur = 0
for i in range(len(s)).reversed():
  a[i + 1] = max(a[i + 1], cur)
  cur = 0 if s[i] == '<' else cur + 1
a[0] = max(a[0], cur)
print(sum(a))

Fixed submission:
s = input()
a = [0] * (len(s) + 1)
cur = 0
for i in range(len(s)):
  a[i] = cur
  cur = 0 if s[i] == '>' else cur + 1 
a[-1] = cur
cur = 0
for i in reversed(range(len(s))):
  a[i + 1] = max(a[i + 1], cur)
  cur = 0 if s[i] == '<' else cur + 1
a[0] = max(a[0], cur)
print(sum(a))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = n - 1
a = 1
while a * a <= n:
  if n % a == 0:
    ans = min(ans, a - 1 + (n / a) - 1)
print(ans)

Fixed submission:
n = int(input())
ans = n - 1
a = 1
while a * a <= n:
  if n % a == 0:
    ans = min(ans, a - 1 + (n // a) - 1)
  a += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
print(sum(a[0:][::2])-sum(a[1:][::2])

Fixed submission:
n = int(input())
a = sorted(map(int, input().split()))
print(abs(sum(a[0:][::2])-sum(a[1:][::2])))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
a = map(int, input().split())

def cnt(arr):
    g = c = 0
    for i in arr: g = math.gcd(g,i)
    while g%2==0:
        g/=2
        c += 1
    return c

print(cnt(a))

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

def cnt(li, c):
    arr = []
    for i in li:
        arr.append(i/2)
        if i%2!=0: return c
    return cnt(arr, c+1)

print(cnt(a,0))
Buggy python submission (verdict: Runtime Error):
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print({}.ans)
else :
    print(str(-1))A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print(ans)
else :
    print(str(-1))

Fixed submission:
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print(ans)
else :
    ans = -1
    print(ans)

Buggy python submission (verdict: Runtime Error):
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print({}.ans)
else :
    print(str(-1))

Fixed submission:
A, B = (int(i) for i in input().split())  
if 1 <= A < 10 and  1 <= B < 10 :
    ans = A * B
    print(ans)
else :
    ans = -1
    print(ans)
Buggy python submission (verdict: Runtime Error):
N = input()
n_even = int(N / 2)
n_odd = n_even + 1
chance = float(n_odd / N)
print(chance)

Fixed submission:
N = int(input())

if N % 2 == 0 :
    n_even = int(N / 2)
    n_odd = n_even
    chance = n_odd / N
    print(chance)
    
else :
    n_even = int(N / 2)
    n_odd = n_even + 1
    chance = n_odd / N
    print(chance)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def main():
  n = int(raw_input())
  parts = map(int, raw_input().split())
  result = 0
  conditions = [
    lambda a,b,c: a<b+c,
    lambda a,b,c: b<c+a,
    lambda a,b,c: c<a+b,
  ]
  for comb in itertools.combinations(parts, 3):
    if all([func(*comb) for func in conditions]):
      result += 1
  print(result)

main()

Fixed submission:
def main():
  n = int(raw_input())
  sticks = list(sorted(map(int, raw_input().split())))
  result = 0

  for x in xrange(n):
      z = x + 2
      for y in xrange(x+1, n):
          while (z < n and sticks[x] + sticks[y] > sticks[z]):
              z += 1
          result += z - y -1
  print(result)

main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  n,k,q = [int(x) for x in raw_input().split()]
  answers = [int(raw_input())-1 for x in xrange(q)]
  scores = [k,] * n
  
  for answer in answers:
    for i in xrange(n):
      if i != answer:
        scores[i] -= 1
  
  for score in scores:
    print("Yes" if score > 0 else "No")

main()


Fixed submission:
def main():
  n,k,q = [int(x) for x in raw_input().split()]
  memo = {}

  for _ in xrange(q):
      pid = int(raw_input()) - 1
      if pid not in memo:
          memo[pid] = 0
      memo[pid] += 1

  for pid in xrange(n):
      score = k - q + memo.get(pid, 0)
      print("Yes" if score > 0 else "No")

main()

Buggy python submission (verdict: Runtime Error):
def main():
  n,k,q = [int(x) for x in raw_input().split()]
  answers = [int(raw_input())-1 for x in xrange(q)]
  scores = [k,] * n
  
  for answer in answers:
    for i in xrange(q):
      if i != answer:
        scores[i] -= 1
  
  for score in scores:
    print("Yes" if score > 0 else "No")

main()

Fixed submission:
def main():
  n,k,q = [int(x) for x in raw_input().split()]
  memo = {}

  for _ in xrange(q):
      pid = int(raw_input()) - 1
      if pid not in memo:
          memo[pid] = 0
      memo[pid] += 1

  for pid in xrange(n):
      score = k - q + memo.get(pid, 0)
      print("Yes" if score > 0 else "No")

main()
Buggy python submission (verdict: Time Limit Exceeded):
def start_from(a, x):
  while a % x != 0:
    a += 1
  return a

def ends_with(b, x):
    while b % x != 0:
        b -= 1
    return b

def main():
  a, b, x = map(int, raw_input().split())
  start = start_from(a, x) / x
  end = ends_with(b, x) / x
  print(end-start+1)


main()

Fixed submission:
def start_from(a, x):
  while a % x != 0:
    a += x - a % x
  return a

def ends_with(b, x):
    while b % x != 0:
        b -= b % x
    return b

def main():
  a, b, x = map(int, raw_input().split())
  start = start_from(a, x) / x
  end = ends_with(b, x) / x
  print(end-start+1)


main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
  raw, answer = raw_input(), 0
  s = raw[0]
  for x in xrange(1, len(raw)):
      if raw[x] == s[-1]:
          continue
      s += raw[x]

  while len(set(s)) > 1:
    char, pos = "", 0
    for i in xrange(len(s)-1,-1,-1):
      if s[i] != s[-1]:
        pos, char = i, s[i]
        break
    s = s[0:pos]+char
    answer += 1
  print(answer)


main()

Fixed submission:
def main():
  raw = raw_input()
  s = raw[0]
  for x in xrange(1, len(raw)):
      if raw[x] == s[-1]:
          continue
      s += raw[x]
  print(len(s)-1)


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s, answer = raw_input(), 0
  while len(set(s)) > 1:
    char, pos = "", 0
    for i in xrange(len(s)-1,-1,-1):
      if s[i] != s[-1]:
        pos, char = i, s[i]
        break
    s = s[0:pos]+char
    answer += 1
  print(answer)


main()

Fixed submission:
def main():
  raw = raw_input()
  s = raw[0]
  for x in xrange(1, len(raw)):
      if raw[x] == s[-1]:
          continue
      s += raw[x]
  print(len(s)-1)


main()
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    if (i in mapping) and (i+1 in mapping):
      ans *= mapping[i]**(mapping[i+1])
    else:
      ans = 0
      break
  print(ans % 998244353)

Fixed submission:
N = int(input())
print((N-1)//2)

Buggy python submission (verdict: Runtime Error):
N = str(input())
print((N-1)//2)

Fixed submission:
N = int(input())
print((N-1)//2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    ans *= mapping[i]**(mapping[i+1])
  print(ans)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    if (i in mapping) and (i+1 in mapping):
      ans *= mapping[i]**(mapping[i+1])
    else:
      ans = 0
      break
  print(ans % 998244353)

Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    ans *= mapping[i]**(mapping[i+1])
print(ans)

Fixed submission:
N = int(input())
D = list(map(int, input().split()))
if (D[0]!=0) or (0 in D[1:]):
  print(0)
else:
  mapping = dict()
  max_ = 0
  for n in D[1:]:
    if n in mapping:
      mapping[n]+=1
    else:
      mapping[n]=1
      if max_ < n :
        max_ = n
  ans=1
  for i in range(1,max_):
    if (i in mapping) and (i+1 in mapping):
      ans *= mapping[i]**(mapping[i+1])
    else:
      ans = 0
      break
  print(ans % 998244353)
Buggy python submission (verdict: Runtime Error):
n = input()
s = int(input())
k = int(input())

char = s[k-1]
ans=''
for i in s:
    if i!=char:
        ans+='*'
    else:
        ans+=char
print(ans)

Fixed submission:
n = int(input())
s = input()
k = int(input())

char = s[k-1]
ans=''
for i in s:
    if i!=char:
        ans+='*'
    else:
        ans+=char
print(ans)

Buggy python submission (verdict: Runtime Error):
n,s,k = map(str, input().split('\n'))
n = int(n)
k = int(k)
char = s[k-1]
ans=''
for i in s:
    if i!=char:
        ans+='*'
    else:
        ans+=char
print(ans)

Fixed submission:
n = int(input())
s = input()
k = int(input())

char = s[k-1]
ans=''
for i in s:
    if i!=char:
        ans+='*'
    else:
        ans+=char
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=0
w = s.count('.')
for i in range(0,n-1):
    if (s[i]=='#')&&(s[i+1]=='.'):
        ans+=1
        s[i+1]='#'
print(min(ans,w,n-w))

Fixed submission:
n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='#':
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=0
w = s.count('.')
for i in range(0,n-1):
    if (s[i]=='#')&(s[i+1]=='.'):
        ans+=1
        s[i+1]='#'
print(min(ans,w,n-w))

Fixed submission:
n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='#':
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
ans=n
for i in range(0,n+1):
    cw=s[:i].count('#')
    cb=s[i:].count('.')
    if ans>=cw+cb:
        ans=cw+cb
print(ans)

Fixed submission:
n=int(input())
s=input()
w = s.count('.')
b = 0
ans=w+b
for i in s:
    if i=='#':
        b+=1
    else:
        w-=1
    if ans>=b+w:
        ans=b+w
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
o=0
for i in range(n):
  for j in range(n-i):
    if (i+1)+(i+1+j+1)==n:
      o=o+1
      
print(o)

Fixed submission:
n=int(input())
if n%2==0:
  o=int(n/2-1)
else:
  o=int((n-1)/2)
      
print(o)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    b = A.index(i + 1)
    ans[i] = b + 1
for i in range(N):
    print(ans[i])

Fixed submission:
N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    ans[A[i] - 1] = i + 1
for i in range(N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    b = A.index(i + 1)
    ans[i] = b
for i in range(N):
    c = ans[i] + 1
    print(c)

Fixed submission:
N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    ans[A[i] - 1] = i + 1
for i in range(N):
    print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(int(x) for x in input().split())
ans = []
for i in range(N):
    b = A.index(i + 1)
    ans.append(b)
for i in range(N):
    c = ans[i] + 1
    print(c)

Fixed submission:
N = int(input())
A = list(int(x) for x in input().split())
ans = [None] * N
for i in range(N):
    ans[A[i] - 1] = i + 1
for i in range(N):
    print(ans[i])
Buggy python submission (verdict: Runtime Error):
A = int( input() )
B = int( input() )
c = A + B
d = A - B
e = A * B

if c < d:
    if d < e:
        print(e)
    if d > e:
        print(d)

if c > d:
    if c > e:
        print(c)

Fixed submission:
A, B = (int(x) for x in input().split())
c = A + B
d = A - B
e = A * B

if c <= d:
    if d <= e:
        print(e)
    if d > e:
        print(d)

if c > d:
    if c >= e:
        print(c)
    if c < e:
        print(e)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())
a = 0
b = 0
for x in range(N):
    B[x] = B[x] + a
    if A[x] > B[x]:
        b = b + B[x]
        a = 0
    else:
        b = b + A[x]
        if A[x] > a:
            a = B[x] - A[x]
        else:
            a = B[x]
if A[N - 1] > B[N - 1]:
    print(b)
else:
    if A[N] > a:
        print(b + a)
    else:
        print(b + A[N])

Fixed submission:
A , B = (int(x) for x in input().split())
k = (B + A) / 2
K = (B + A) % 2
if K == 0:
    print(int(k))
else:
    print("IMPOSSIBLE")

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(int(x) for x in input().split())
B = list(int(x) for x in input().split())
a = 0
b = 0
for x in range(N):
    B[x] = B[x] + a
    if A[x] > B[x]:
        b = b + B[x]
        a = 0
    else:
        b = b + A[x]
        if A[x] > a:
            a = B[x] - A[x]
        else:
            a = B[x]
if A[N - 1] > B[N - 1]:
    print(b)
else:
    if A[N] > a:
        print(b + a)
    else:
        print(b + A[N])

Fixed submission:
A , B = (int(x) for x in input().split())
k = (B + A) / 2
K = (B + A) % 2
if K == 0:
    print(int(k))
else:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

res = 0
for p in a:
  if sum(i+j for i,j in zip(p,b)) + c > 0:
    res += 1
return res

Fixed submission:
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

res = 0
for p in a:
  if sum(i*j for i,j in zip(p,b)) + c > 0:
    res += 1
print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())
xs, us = [], []
for _ in range(n):
  x, u = input()
  xs.append(float(x))
  us.append(u)
total_yen = 0
for x, u in zip(xs, us):
  if u == 'BTC':
    total_yen += (x*380000.0)
  else:
    total_yen += x
print(total_yen)

Fixed submission:
n = int(input())
xs, us = [], []
for _ in range(n):
  x, u = input().split(' ')
  xs.append(float(x))
  us.append(u)
total_yen = 0
for x, u in zip(xs, us):
  if u == 'BTC':
    total_yen += (x*380000.0)
  else:
    total_yen += x
print(total_yen)
Buggy python submission (verdict: Runtime Error):
import numpy as np

n, a, b, c = map(int, input().split(' '))
ls = []
for _ in range(n):
    ls.append(int(input()))
n = 0
def solve(obj):
  c = len(ls)
  dp = np.zeros((obj+1, c+1), dtype=int)
  dp[1:, 0] = np.inf
  for j in range(1, c+1):
    dp[0, j] = min(ls[:j])
  for i in range(1, obj+1):
    for j in range(1, c+1):
      dp[i, j] = min(dp[i-1, j] + 1, dp[i, j-1], dp[i-ls[j-1], j-1] + 10, abs(ls[j-1]) - i)
  return dp[obj, c]

for obj in [a, b, c]:
  if obj in ls:
    continue
  else:
    n += solve(obj)
print(n)

Fixed submission:

import numpy as np

N, A, B, C = map(int, input().split(' '))
ls = []
for _ in range(N):
    ls.append(int(input()))
n = 0
INF = 10 ** 9

def dfs(n, a, b, c):
    if n == N:
        return INF if min(a, b, c) == 0 else abs(a-A) + abs(b-B) + abs(c-C) - 30
    res0 = dfs(n+1, a, b, c)
    res1 = dfs(n+1, a+ls[n], b, c) + 10
    res2 = dfs(n+1, a, b+ls[n], c) + 10
    res3 = dfs(n+1, a, b, c+ls[n]) + 10
    return min(res0, res1, res2, res3)

print(dfs(0, 0, 0, 0))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, ' '.split(input()))
if b%a == 0:
  print(a+b)
else:
  print(b-a)

Fixed submission:
a, b = map(int, input().split(' '))
if b%a == 0:
  print(a+b)
else:
  print(b-a)
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = [int(input()) for _ in range(N)]
cost = 0
for i in range(N-1):
  if H[i] > H[i+1]:
    cost += (H[i] - H[i+1])
cost += H[N-1]
print(cost)
    

Fixed submission:
N = int(input())
H = list(map(int, input().split(' ')))
cost = 0
for i in range(N-1):
  if H[i] > H[i+1]:
    cost += (H[i] - H[i+1])
cost += H[N-1]
print(cost)
Buggy python submission (verdict: Runtime Error):
import numpy as np

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

dp = np.zeros((K+1, N+1), dtype=float)
nt = [['']*(N+1) for _ in range(K+1)]
for i in range(1, K+1):
    for j in range(1, N+1):
        
        if str(TD[j - 1][0]) in list(nt[i-1][j-1]):
            t_dp = dp[i - 1, j - 1] + TD[j - 1][1]
        else:
            v = len(nt[i - 1][j - 1])
            t_dp = dp[i - 1, j - 1] + TD[j - 1][1] - v**2 + (v+1)**2

        if dp[i, j-1] >= t_dp:
            dp[i, j] = dp[i, j-1]
            nt[i][j] = nt[i][j-1]
        else:
            dp[i, j] = t_dp
            if str(TD[j-1][0]) not in list(nt[i-1][j - 1]):
                nt[i][j] = nt[i-1][j - 1] + str(TD[j-1][0])
            else:
                nt[i][j] = nt[i - 1][j - 1]

print(int(dp[K, N]))

Fixed submission:
from heapq import heappush, heappop

N, K = map(int, input().split(' '))
h = []
for _ in range(N):
    t, d = map(int, input().split(' '))
    heappush(h, (-d, t))

dsum = 0
used = {}
q = []
for _ in range(K):
    d, t = heappop(h)
    if t not in used:
        used[t] = 1
    else:
        heappush(q, (-d, t))
    dsum += -d
res = len(used)**2 + dsum

while h and q:
    d, t = heappop(h)
    if t not in used:
        used[t] = 1
        m, _ = heappop(q)
        dsum = dsum - m - d
        res = max(res, len(used)**2 + dsum)
print(res)
Buggy python submission (verdict: Runtime Error):
n = int(input())

arr = [int(a) for a in input().split()]

max_mod = 0
for i in range(1, max(arr)):

    cur_mod = 0
    for a in arr:
        cur_mod += i % a

    max_mod = max(max_mod, cur_mod)

print(max_mod)



Fixed submission:
tasks = input()

tasks = [int(t) for t in tasks.split()]

# 0, 1, 2
cost0 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[1])

# 0, 2, 1
cost1 = abs(tasks[2] - tasks[0]) + abs(tasks[2] - tasks[1])

# 1, 0, 2
cost2 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[0])

# 1, 2, 0
cost3 = abs(tasks[1] - tasks[2]) + abs(tasks[2] - tasks[0])

# 2, 0, 1
cost4 = abs(tasks[2] - tasks[0]) + abs(tasks[0] - tasks[1])

# 2, 1, 0
cost5 = abs(tasks[2] - tasks[1]) + abs(tasks[0] - tasks[1])

min_cost = min([cost0, cost1, cost2, cost3, cost4, cost5])

print(min_cost)

Buggy python submission (verdict: Runtime Error):
str1 = input()
str2 = input()

if str1 == str2:
    print('Yes')

for i in range(len(str1) - 1):

    str1 = str1[-1] + str1[:-1]

    if str1 == str2:
        print('Yes')
        break

if str1 != str2:
    print('No')

Fixed submission:
tasks = input()

tasks = [int(t) for t in tasks.split()]

# 0, 1, 2
cost0 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[1])

# 0, 2, 1
cost1 = abs(tasks[2] - tasks[0]) + abs(tasks[2] - tasks[1])

# 1, 0, 2
cost2 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[0])

# 1, 2, 0
cost3 = abs(tasks[1] - tasks[2]) + abs(tasks[2] - tasks[0])

# 2, 0, 1
cost4 = abs(tasks[2] - tasks[0]) + abs(tasks[0] - tasks[1])

# 2, 1, 0
cost5 = abs(tasks[2] - tasks[1]) + abs(tasks[0] - tasks[1])

min_cost = min([cost0, cost1, cost2, cost3, cost4, cost5])

print(min_cost)

Buggy python submission (verdict: Runtime Error):
str1 = input()
str2 = input()

if str1 == str2:
    print('Yes')

for i in range(len(str1) - 1):
    
    str1 = str1[-1] + str1[:-1]
    
    if str1 == str2:
        print('Yes')

print('No')

Fixed submission:
tasks = input()

tasks = [int(t) for t in tasks.split()]

# 0, 1, 2
cost0 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[1])

# 0, 2, 1
cost1 = abs(tasks[2] - tasks[0]) + abs(tasks[2] - tasks[1])

# 1, 0, 2
cost2 = abs(tasks[1] - tasks[0]) + abs(tasks[2] - tasks[0])

# 1, 2, 0
cost3 = abs(tasks[1] - tasks[2]) + abs(tasks[2] - tasks[0])

# 2, 0, 1
cost4 = abs(tasks[2] - tasks[0]) + abs(tasks[0] - tasks[1])

# 2, 1, 0
cost5 = abs(tasks[2] - tasks[1]) + abs(tasks[0] - tasks[1])

min_cost = min([cost0, cost1, cost2, cost3, cost4, cost5])

print(min_cost)