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

Fixed submission:
import math
from itertools import accumulate
def is_prime(n):
  if n==1:
    return False
  for i in range(2,int(math.sqrt(n)+1)):
    if n%i==0:
      return False
  return True
q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=list(map(int,input().split()))
min_l=min(l)
max_r=max(r)
a=[]
for i in range(min_l,max_r+1):
  if i%2==0:
    a.append(0)
  else:
    if is_prime(i) and is_prime((i+1)/2):
      a.append(1)
    else:
      a.append(0)
check=[0]+a
check=list(accumulate(check))
for i in range(q):
  print(check[r[i]-min_l+1]-check[l[i]-min_l])

Buggy submission (verdict: Runtime Error):
import math
from itertools import accumulate
def is_prime(n):
  if n==2:
    return True
  for i in range(2,int(math.sqrt(n)+1)):
    if n%i==0:
      return False
  return True
q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=map(int,input().split())
min_l=min(l)
max_r=max(r)
a=[]
for i in range(min_l,max_r+1):
  if i%2==0:
    a.append(0)
  else:
    if is_prime(i) and is_prime((i+1)/2):
      a.append(1)
check=[0]+a
check=list(accumulate(check))
for i in range(q):
  print(check[r[i]-min_l+1]-check[l[i]-min_l])

Buggy submission (verdict: Runtime Error):
import math
from itertools import accumulate
def is_prime(n):
  if n==2:
    return True
  for i in range(2,int(math.sqrt(n)+1)):
    if n%i==0:
      return False
  return True
q=int(input())
l=[0]*q
r=[0]*q
for i in range(q):
  l[i],r[i]=map(int,input().split(""))
min_l=min(l)
max_r=max(r)
a=[]
for i in range(min_l,max_l+1):
  if i%2==0:
    a.append(0)
  else:
    if is_prime(n) and is_prime((i+1)/2):
      a.append(1)
check=[0]+check
check=list(accumulate(check))
for i in range(q):
  print(check(r[i+1])-check(l[i]))
Problem p03545 (python)

Fixed submission:
s=list(input())
#sのi番目の次に＋かーを入れる。それまでの文字列char,合計sum
def dfs(i,char,sum):
  if i==3:
    if sum==7:
      print(char+"=7")
      exit()
  else:
    dfs(i+1,char+"+"+s[i+1],sum+int(s[i+1]))  
    dfs(i+1,char+"-"+s[i+1],sum-int(s[i+1]))
        
    
      
    
      
dfs(0,s[0],int(s[0]))

Buggy submission (verdict: Runtime Error):
=list(input())
#sのi番目の次に＋かーを入れる。それまでの文字列char,合計sum
def dfs(i,char,sum):
  if i==3:
    if sum==7:
      print(char+"=7")
      exit()
  else:
    dfs(i+1,char+"+"+s[i+1],sum+int(s[i+1]))  
    dfs(i+1,char+"-"+s[i+1],sum-int(s[i+1]))
        
    
      
    
      
dfs(0,s[0],int(s[0]))

Buggy submission (verdict: Runtime Error):
s=list(int(input()))
#sのi番目までの合計をsumとする
def dfs(i,sum):
  if i==4:
    return sum==7
  if dfs(i+1,sum+s[i]):
    return True
  if dfs(i+1,sum-s[i]):
    return True
  else:
    return False
if dfs(0,s[0]):
  print("Yes")
else:
  print("No")
Problem p03557 (python)

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect.bisect_left(A, b) # 挿入点はどの同じ値よりも左
    c = bisect.bisect_right(C, b) # 挿入点はどの同じ値よりも右
    ans += a * (len(C)-c)
print (ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort()
b.sort()
c.sort()

import bisect
ans=0
for i in b:
    a=bisect.bisect_left(i)
    b=bisect.bisect_right(i)
    ans=ans+a*(n-b)
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a.sort
b.sort
c.sort
ans=0
for i in b:
  A=bisect.bisect_left(a,b[i])
  B=bisect.bisect_right(c,b[i])
  ans=ans+A*(n-B)
print(ans)
Problem p03722 (python)

Fixed submission:
#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
    cnt+=1
    if not update:
      break
    if cnt==n-1:
      memo=d[n-1]
    if cnt==n:
      #正のループがある
      if d[n-1]>memo:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n-1])
        sys.exit()
  print(d[n-1])
  
Bellmanford(n,m,0,es)

Buggy submission (verdict: Runtime Error):
#ベルマンフォード法
#正の閉路がない時は普通のベルマンフォード法
n,m=list(map(int,input().split()))
es=[]
for i in range(m):
  a,b,c=list(map(int,input().split()))
  es.append((a-1,b-1,c))
import sys
def Bellmanford(n,m,s,es):
  d=[-float("INF")]*n
  d[s]=0
  cnt=0
  while(1):
    update=False
    for p,q,r in es:
      if d[p]!=-float("INF") and d[q]<d[p]+r:
        d[q]=d[p]+r
        update=True
    cnt+=1
    if not update:
      break
    if cnt==n-1:
      memo=d[n-1]
    if cnt==n:
      #正のループがある
      if d[n-1]>memo:
        print(float("INF"))
        sys.exit()
      else:
        print(d[n])
  print(d[n-1])
  
Bellmanford(n,m,0,es)
Problem p02639 (python)

Fixed submission:
a = list(map(int, input().split()))
res = 0
for i in range(len(a)):
    if a[i] == 0:
        res = i + 1
        break
print(res)

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
res = 0
for i in range(len(a)):
	if a[i] == i:
		res = i + 1
        break
print(res)

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
res = 0
for i in range(len(a)):
  	if a[i] == i:
      	res = i + 1
print(res)
Problem p03493 (python)

Fixed submission:
s = list(input())
print(s.count("1"))

Buggy submission (verdict: Runtime Error):
a = int(input())

count = 0
for i in range(len(a)):
  if a[i] == 1:
    count += 1

print(count)
Problem p03494 (python)

Fixed submission:
import numpy as np
N = int(input())
a = list(map(int, input().split()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 0):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = list(map(int, input().split()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 0):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = list(map(int, input().split()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 0):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = list(map(int, input().split()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 1):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = int(list(input()))

count = [0] * N
for i in range(N):
  while(a[i] % 2== 1):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = int(list(input())

count = [0] * N
for i in range(N):
  while(a[i] % 2== 1):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = map(int, input().split())

count = [0] * N
for i in range(N):
  while(a[i] % 2== 1):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))

Buggy submission (verdict: Runtime Error):
import numpy　as np
N = int(input())
a = map(int, input().split())

count = [0] * N
for i in range(N):
  while(a[i] % == 1):
    a[i] = a[i] // 2
    count[i] += 1
print(np.min(count))
Problem p03636 (python)

Fixed submission:
s = input()
num = len(s[1:-1])
s = s[0] + str(num) + s[-1]
print(s)

Buggy submission (verdict: Runtime Error):
s = input()
s = s[0] + len(s[1:-1]) + s[-1]
print(s)
Problem p04043 (python)

Fixed submission:
a, b, c = map(int, input().split())
 
if a == 5:
  if (b == 5 and c == 7) or (c == 5 and b == 7):
    print("YES")
  else:
    print("NO")
if a == 7:
  if b == 5 and c == 5:
    print("YES")
  else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())

if a == 5:
  if (b == 5 and c == 7) or (c == 5 and b == 7):
    print(YES)
  else:
    print(NO)
if a == 7:
  if b == 5 and c == 5:
    print(YES)
  else:
    print(NO)
Problem p02982 (python)

Fixed submission:
N, D= map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
count=0
for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            if i != j:
                tmp += (arr[i][k]-arr[j][k])**2
        tmp = tmp**0.5
        if tmp.is_integer():
            count = count+1
print(count)

Buggy submission (verdict: Runtime Error):
N, D= map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
count=0
for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            if i != j:
                tmp += (arr[i][k]-arr[j][k])**2
        tmp = tmp**0.5
        if tmp == int(tmp)
            count = count+1
print(count)
Problem p02983 (python)

Fixed submission:
L, R= map(int,input().split())
m = 2019
ans = 0
if R-L < m:
    ans = m
    L = L%m
    R = R%m
    lis = list(range(L,R+1))
    lis2 = [i%m for i in lis]
    for i in range(len(lis2)):
        for j in range(i+1,len(lis2)):
            if ans > (lis2[i]*lis[j])%m:
                ans = (lis2[i]*lis[j])%m
print(ans)

Buggy submission (verdict: Runtime Error):
L, R= map(int,input().split())
m = 2019
lis = list(range(L,R+1))
lis2 = [i%m for i in lis]
lis2.sort()
print(lis2[0]*lis2[1])

Buggy submission (verdict: Runtime Error):
L, R= map(int,input().split())
m = 2019
L = L % m
R = R % m
lis = list(range(L,R+1))
lis.sort()
print(lis[0]*lis[1])
Problem p02981 (python)

Fixed submission:
info = input().split(" ")
N = int(info[0])
A = int(info[1])
B = int(info[2])

if N*A <= B:
  print(N*A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
info = input().split(" ")
N = int(info[0])
A = int(info[1])
B = int(info[2])

if N*A =< B:
  print(N*A)
else:
  print(B)

Buggy submission (verdict: Runtime Error):
info = input().split(" ")
N = int(info[0])
A = int(info[1])
B = int(info[2])

if N*A =< B:
  print(N*A)
else:
  print(B)
Problem p02991 (python)

Fixed submission:
from collections import*
n, m, *t = map(int, open(0).read().split())       
*w, s, t = [a-1for a in t]         
e = [[]for _ in range(n)]        
for u, v in zip(w[::2], w[1::2]):      
    e[u].append(v)

INF = 10**10
f = [[INF]*3for _ in range(n)]        
f[s][0] = 0        
q = deque([(s, 0)])           
while q:
    vi, j = q.popleft()         
    if vi == t and j == 0:
        print(f[vi][0]//3)
        break
    for ui in e[vi]:           
        if f[ui][(j+1)%3] < INF: continue           
        f[ui][(j+1)%3] = f[vi][j] + 1
        q.append((ui, (j+1)%3))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import*
n, m, *t = map(int, open().read().split())       
*w, s, t = [a-1for a in t]         
e = [[]for _ in range(n)]        
for u, v in zip(w[::2], w[1::2]):      
    e[u].append(v)

INF = 10**10
f = [[INF]*3for _ in range(n)]        
f[s][0] = 0        
q = deque([(s, 0)])           
while q:
    vi, j = q.popleft()         
    if vi == t and j == 0:
        print(f[vi][0]//3)
        break
    for ui in e[vi]:           
        if f[ui][(j+1)%3] < INF: continue           
        f[ui][(j+1)%3] = f[vi][j] + 1
        q.append((ui, (j+1)%3))
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
from collections import*
n, m, *t = map(int, open("test").read().split())       
*w, s, t = [a-1for a in t]         
e = [[]for _ in range(n)]        
for u, v in zip(w[::2], w[1::2]):      
    e[u].append(v)

INF = 10**10
f = [[INF]*3for _ in range(n)]        
f[s][0] = 0        
q = deque([(s, 0)])           
while q:
    vi, j = q.popleft()         
    if vi == t and j == 0:
        print(f[vi][0]//3)
        break
    for ui in e[vi]:           
        if f[ui][(j+1)%3] < INF: continue           
        f[ui][(j+1)%3] = f[vi][j] + 1
        q.append((ui, (j+1)%3))
else:
    print(-1)
Problem p02983 (python)

Fixed submission:
mod=[]
answer = 2018
count = 0
sub=0
mod = [int(i) for i in input().split()]
if(mod[0]==mod[1]):
    answer = (mod[0]*mod[1])%2019

for i in range(mod[0],mod[1]+1):
    if 2019<=mod[1]-mod[0]:
        answer = 0
        break
    for j in range(i+1,mod[1]+1):
        sub = (i*j)%2019
        if sub<answer:
            answer = sub
    if count == 2018:
        break
    count = count + 1
print(answer)

Buggy submission (verdict: Runtime Error):
mod=[]
answer = 2018
count = 0
sub=0
mod = [int(i) for i in input().split()]
if(i+1==mod[1]):
    answer = (mod[0]*mod[1])%2019

for i in range(mod[0],mod[1]+1):
    for j in range(i+1,mod[1]+1):
        sub = (i*j)%2019
        if sub<answer:
            answer = sub
            print(answer)
    if count == 2018:
        break
    count = count + 1
print(answer)
Problem p02993 (python)

Fixed submission:
p=list(input())
f=0
for i in range(len(p)-1):
  if p[i]==p[i+1]:
    f+=1
    break
if f>0:
  print("Bad")
else:
  print("Good")

Buggy submission (verdict: Runtime Error):
p=list(input())
f=0
for i in range(len(l)-1):
  if l[i]==l[i+1]:
    f+=1
    break
if f>0:
  print("Bad")
else:
  print("Good")
Problem p02993 (python)

Fixed submission:
code = input()
is_bad = False
for i, s in enumerate(code):
  if i > 0 and s == code[i-1]:
    print('Bad')
    is_bad = True
    break
  if i < len(s) -1 and s == code[i+1]:
    print('Bad')
    is_bad = True
    break
if not is_bad:
  print('Good')

Buggy submission (verdict: Runtime Error):
input = input()
is_good = True
for i, s in enumerate(input):
    if i > 0 and s == input[i-1]:
        is_good = False
        break
    if i < len(input) and s == input[i+1]:
        is_good = False
        break
if is_good:
    print('Good')
else:
    print('Bad')
Problem p02995 (python)

Fixed submission:
from fractions import gcd
def floor(a, b):
  # return int((a - a%b)/b)
  return a//b
# def gcd(a, b):
#   while a % b != 0:
#       a, b = b, a % b
#   return a
def lcm(a, b):
  return floor((a * b), gcd(a, b))
input = list(map(int, input().split(' ')))
total_count = input[1] + 1 - input[0]
div_c = floor(input[1], input[2]) - floor(input[0] -1, input[2])
div_d = floor(input[1], input[3]) - floor(input[0] -1, input[3])
div_cd = floor(input[1], lcm(input[2], input[3])) - floor(input[0] -1, lcm(input[2], input[3]))
print(total_count - (div_c + div_d - div_cd))

Buggy submission (verdict: Runtime Error):
import math
def lcm(a, b):
  return (a * b) // math.gcd(a, b)
input = list(map(int, input().split(' ')))
total_count = input[1] + 1 - input[0]
div_c = math.floor(input[1] / input[2]) - math.floor(input[0] / input[2])
if input[0] % input[2] == 0:
  div_c += 1
div_d = math.floor(input[1] / input[3]) - math.floor(input[0] / input[3])
if input[0] % input[3] == 0:
  div_d += 1
div_cd = math.floor(input[1] / lcm(input[2], input[3])) - math.floor(input[0] / lcm(input[2], input[3]))
if input[0] % lcm(input[2], input[3]) == 0:
  div_cd += 1
print(total_count - (div_c + div_d - div_cd))
Problem p02995 (python)

Fixed submission:
# -*- coding: utf-8 -*-
import fractions

A, B, C, D = map(int,input().split())

lcm = C * D // fractions.gcd(C, D)

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print((B-A+1)-(lcmB-lcmA))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math


A, B, C, D = map(int,input().split())

lcm = C * D // math.gcd(C, D)

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print((B-A+1)-(lcmB-lcmA))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math


A, B, C, D = map(int,input().split())

lcm = C * D // math.gcd(C, D)

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print((B-A+1)-(lcmB-lcmA))

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
import math


A, B, C, D = map(int,input().split())

lcm = C * D // math.gcd(C, D)

maxC = B // C
maxD = B // D
maxlcm = B // lcm

minC = (A-1) // C
minD = (A-1) // D
minlcm = (A-1) // lcm

lcmB = (maxC + maxD - maxlcm)
lcmA = (minC + minD - minlcm)

print(lcmB)
print(lcmA)
print((B-A+1)-(lcmB-lcmA))
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if (a*b) % 2:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a,b=map(int(),input().split())
print("Even" if a*b%2==0 else"Odd")

Buggy submission (verdict: Runtime Error):
a,b=map(int(),input().split())
print("Even" if a*b%2==0 else"Odd")

Buggy submission (verdict: Runtime Error):
a,b=map(int(),input().split())
print("Even" if a*b%2==0 else"Odd"

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
if (a*b) % 2==0
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a*b%2==0
   print("Even")
else
   print("Odd")
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(a+b+c)
Problem p02999 (python)

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

if X >= A:
    print(10)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
N,X = map(int,input().split(" "))
L = list(map(int,input().split(" ")))
D = 0
ans = 0

for i in range(N):
  if D <= X:
    D += L[i]
    ans += 1
  else:
    break
print(ans)
Problem p03060 (python)

Fixed submission:
N = int(input())
V = list(map(int,input().split(" ")))
C = list(map(int,input().split(" ")))
P = []

for i in range(N):
    P.append(V[i] - C[i])

result = list(filter(lambda x:x>=1,P))
print(sum(result))

Buggy submission (verdict: Runtime Error):
N = int(input())
V = map(int,input().split(" "))
C = map(int,input().split(" "))
P = []

for i in range(N):
    P.append(V[i] - C[i])

result = list(filter(lambda x:x>=1,P))
print(sum(result))
Problem p02981 (python)

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

if (n * a > b):
    ans = b
else:
    ans = n * a

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy

n, d = map(int, input().split())

l = []
for v in range(n):
    l.append(list(map(int, input().split())))

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        if i == j:
            continue
        a = numpy.array(l[i])
        b = numpy.array(l[j])
        c = numpy.linalg.norm(b - a)
        if (c.is_integer()):
            ans += 1

print(ans)
Problem p02999 (python)

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

if x < a:
    print('0')

if x >= a:
    print('10')

Buggy submission (verdict: Runtime Error):
x, a = map(int, input())

if x < a:
    print('0')

if x >= a:
    print('10')
Problem p02982 (python)

Fixed submission:
import math


def is_distance_integer(p1, p2):
    n = len(p1)

    total = 0
    for i in range(n):
        total += ((p1[i] - p2[i])**2)

    dist = int(math.sqrt(total))

    return (dist**2) == total


def count_pairs(points):
    cnt = 0
    n = len(points)

    for i in range(n):
        for j in range(i + 1, n):
            if is_distance_integer(points[i], points[j]):
                cnt += 1

    return cnt


def main():
    N, D = map(int, input().split())

    points = []
    for _ in range(N):
        points.append(list(map(int, input().split())))

    ans = count_pairs(points)

    print(ans)


main()

Buggy submission (verdict: Runtime Error):
import math


def is_distance_integer(p1, p2):
    n = len(p1)

    total = 0
    for i in range(n):
        total += ((p1[i] - p2[i])**2)

    dist = math.sqrt(total)

    return (dist**2) == total


def count_pairs(points):
    cnt = 0
    n = len(points)

    for i in range(n):
        for j in range(i + 1, n):
            if is_distance_integer(points[i], points[j]):
                cnt += 1

    return cnt


def main():
    N, D = map(int, input().split())

    points = []
    for _ in range(N):
        points.append(map(int, input().split()))

    ans = count_pairs(points)

    print(ans)


main()
Problem p03972 (python)

Fixed submission:
w,h= map(int, raw_input().split())
p =[]
q = []
for i in xrange(w):
    t = input()
    p.append(t)

for i in xrange(h):
    t = input()
    q.append(t)
p =sorted(p,reverse=True)
q =sorted(q, reverse=True)
ac = p[:]
acq = q[:]
i = w-2
while i >=0:
    ac[i] += ac[i+1]
    i -=1
i = h - 2
while i >= 0:
    acq[i] += acq[i + 1]
    i -= 1
c = ac[0] + acq[0]
k = 0
# for i in xrange(h):
i = 0
while i < h:
    # for j in xrange(k,w):
        j = k
        # print i,j
        if j >= w:
            break
        if q[i] > p[j]:
            c += ac[j]
            i += 1
            # break
        else:
            c +=acq[i]
            k +=1
        # c += q[i]
print c

Buggy submission (verdict: Runtime Error):
w,h= map(int, raw_input().split())
p =[]
q = []
for i in xrange(w):
    t = input()
    p.append(t)

for i in xrange(h):
    t = input()
    q.append(t)
p =sorted(p,reverse=True)
q =sorted(q, reverse=True)
ac = p[:]
acq = q[:]
i = w-2
while i >=0:
    ac[i] += ac[i+1]
    i -=1
i = h - 2
while i >= 0:
    acq[i] += acq[i + 1]
    i -= 1
c = ac[0] + acq[0]
k = 0
# for i in xrange(h):
i = 0
while i < h:
    # for j in xrange(k,w):
        j = k
        if q[i] > p[j]:
            c += ac[j]
            i += 1
            # break
        else:
            c +=acq[i]
            k +=1
        # c += q[i]
print c
Problem p03994 (python)

Fixed submission:
s = raw_input()
k = input()
i = 0
while True:
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        print s
        exit()
        # print s, k
    elif s[i] != "a" and ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    i += 1

Buggy submission (verdict: Runtime Error):
s = raw_input()
k = input()

def solve(s, k, i):
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        return s
        # print s, k
    elif s[i] != "a" and ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)

Buggy submission (verdict: Runtime Error):
s = raw_input()
k = input()

def solve(s, k, i):
    if i >= len(s):
        # print "over"
        return s
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= ord("a")
            t %= (ord("z")-ord("a") + 1)
            t += ord("a")
        s = s[:i] + chr(t)
        # print s, k
    elif ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)

Buggy submission (verdict: Runtime Error):
s = raw_input()
k = input()

def solve(s, k, i):
    if i >= len(s):
        # print "over"
        return s
    if i == len(s)-1:
        # print "equal"
        t = ord(s[i])+k
        if t > ord("z"):
            t -= (ord("z") - ord("a")+1)
        s = s[:i] + chr(t)
        # print s, k
    elif ord(s[i]) + k > ord("z"):
        # print "carry"
        k = k - ord("z") + ord(s[i]) -1
        s = s[:i] + "a" + s[i+1:]        
        # print s,k
    return solve(s,k,i+1)
    
print solve(s,k,0)