Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(int(i))%2 == 1:
    count += 1
 
print(count)

Fixed submission:
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(str(i))%2 == 1:
    count += 1
 
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(int(i))//2 != 1:
    count += 1
 
print(count)

Fixed submission:
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(str(i))%2 == 1:
    count += 1
 
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(i)//2 != 1:
    count += 1
 
print(count)

Fixed submission:
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(str(i))%2 == 1:
    count += 1
 
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0
 
for i in n:
  if len(i)//2 != 0:
    count += 1
 
print(count)

Fixed submission:
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(str(i))%2 == 1:
    count += 1
 
print(count)

Buggy python submission (verdict: Runtime Error):
n = int(input())
count = 0

for i in n:
  if len(i)% != 0:
    count += 1

print(count)

Fixed submission:
n = int(input())
count = 0
 
for i in range(1,n+1):
  if len(str(i))%2 == 1:
    count += 1
 
print(count)
Buggy python submission (verdict: Runtime Error):
N = int(input())
p = list((int, input().split()))
cnt = 0
 
for i in range(N):
  if p[i] != i+1:
    cnt += 1
 
if cnt==0 or cnt==2 :
  print('YES')
else:
  print('NO')

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
cnt = 0
 
for i in range(N):
  if p[i] != i+1:
    cnt += 1
 
if cnt==0 or cnt==2 :
  print('YES')
else:
  print('NO')

Buggy python submission (verdict: Runtime Error):
N = int(input())
p = map(int, input().split())
cnt = 0

for i in range(1,1+N):
  if p[i]+1 != p[i+1]:
    cnt += 1

if cnt <= 3:
  print('YES')
else:
  print('NO')

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
cnt = 0
 
for i in range(N):
  if p[i] != i+1:
    cnt += 1
 
if cnt==0 or cnt==2 :
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Runtime Error):
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]
 
cnt = 0
 
for i in range(n):
  for j in range(i+1,n):
    kaijou = 0
    for k in d:
      kaijou = kaijou + abs(x[j][k]-x[i][k])**2
    if math.sqrt(kaijou).is_integer():
      cnt += 1
      
print(cnt)

Fixed submission:
n,a,b = map(int,input().split())
print(min(n*a,b))
Buggy python submission (verdict: Runtime Error):
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]
 
kaijou = 0
cnt = 0
 
for i in n:
  for j in n:
    for k in d:
      kaijou = kaijou + (x[j][k]-x[i][k])**2
    if math.sqrt(kaioju).is_integer():
      cnt += 1
 
print(cnt-n)

Fixed submission:
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]
 
cnt = 0
 
for i in range(n):
  for j in range(i+1,n):
    kaijou = 0
    for k in range(d):
      kaijou = kaijou + abs(x[j][k]-x[i][k])**2
    if math.sqrt(kaijou).is_integer():
      cnt += 1
      
print(cnt)

Buggy python submission (verdict: Runtime Error):
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]

kaijou = 0
cnt = 0

for i in n:
  for j in n:
    for k in d:
      kaijou += (x[j,k]**2-x[i,k]**2)
    if math.sqrt(kaioju).is_integer() == True:
      cnt += 1

print(cnt-n)
  


Fixed submission:
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]
 
cnt = 0
 
for i in range(n):
  for j in range(i+1,n):
    kaijou = 0
    for k in range(d):
      kaijou = kaijou + abs(x[j][k]-x[i][k])**2
    if math.sqrt(kaijou).is_integer():
      cnt += 1
      
print(cnt)
Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
 
cnt = 0
 
for i in range(1,n-2):
  if (p[i-1] < p[i] and p[i] < p[i+1]) 
  or (p[i-1] > p[i] and p[i] > p[i+1]:
      cnt += 1
  
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
 
cnt = 0
 
for i in range(1,n-1):
  if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
     cnt += 1
  
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
 
cnt = 0
 
for i in range(1,n-2):
  if (p[i] < p[i+1] and p[i+1] < p[i+2]) 
  or (p[i] > p[i+1] and p[i+1] > p[i+2]:
      cnt += 1
  
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
 
cnt = 0
 
for i in range(1,n-1):
  if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
     cnt += 1
  
print(cnt)

Buggy python submission (verdict: Runtime Error):
n = int(input())
p = list(map(int,input().split()))
 
cnt = 0

for i in range(1,n-1):
  if (p[i] < p[i+1] and p[i+1] < p[i+2]) 
  or (p[i] > p[i+1] and p[i+1] > p[i+2]:
      cnt += 1
  
print(cnt)

Fixed submission:
n = int(input())
p = list(map(int,input().split()))
 
cnt = 0
 
for i in range(1,n-1):
  if (p[i-1] < p[i] and p[i] < p[i+1]) or (p[i-1] > p[i] and p[i] > p[i+1]):
     cnt += 1
  
print(cnt)
Buggy python submission (verdict: Runtime Error):
p,q,r = map(int, input().split())

print(min(p+q,q+r,r+p)

Fixed submission:
p, q, r = map(int, input().split())
print(min(p+q, p+r, q+r))
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
s = list(input()) 

k_lower = s[:k-1]+s[k-1].lower()+s[k:]
print(k_lower)


Fixed submission:
n,k = map(int, input().split())
s = str(input()) 

print(s[:k-1]+s[k-1].lower()+s[k:])

Buggy python submission (verdict: Runtime Error):
n,k = map(str, input().split())
s = str(input()) 

k_lower = s[:k-1]+s[k-1].lower()+s[k:]
print(k_lower)

Fixed submission:
n,k = map(int, input().split())
s = str(input()) 

print(s[:k-1]+s[k-1].lower()+s[k:])

Buggy python submission (verdict: Runtime Error):
s = str(input()) 

k_lower = s[:k-1]+s[k-1].lower()+s[k:]
print(k_lower)


Fixed submission:
n,k = map(int, input().split())
s = str(input()) 

print(s[:k-1]+s[k-1].lower()+s[k:])

Buggy python submission (verdict: Runtime Error):
n,k = map(str, input().split())
s = str(input()) 

k_lower = s.lower(k-1)
print(k_lower)


Fixed submission:
n,k = map(int, input().split())
s = str(input()) 

print(s[:k-1]+s[k-1].lower()+s[k:])
Buggy python submission (verdict: Runtime Error):
a,b,t = map(int, input())
 
print(t//a*b)

Fixed submission:
a,b,t = map(int, input().split())
 
print((t//a)*b)

Buggy python submission (verdict: Runtime Error):
a,b,t = map(int, input())

print(int((t+0.5)/a*b))

Fixed submission:
a,b,t = map(int, input().split())
 
print((t//a)*b)
Buggy python submission (verdict: Runtime Error):
enkitsui = {'A':'T','C':'G','T':'A','G':'C'}
print(enkitsui[b])

Fixed submission:
b = input()
enkitsui = {'A':'T','C':'G','T':'A','G':'C'}
print(enkitsui[b])

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

enkitsui = {'A':'T','C':'G','T':'A','G':'C'}
print(enkitsui['b'])

Fixed submission:
b = input()
enkitsui = {'A':'T','C':'G','T':'A','G':'C'}
print(enkitsui[b])

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

enkitsui = {'A':'T','C':'G','T':'A','G':'C'}
print(enkitsui.value['b'])

Fixed submission:
b = input()
enkitsui = {'A':'T','C':'G','T':'A','G':'C'}
print(enkitsui[b])
Buggy python submission (verdict: Runtime Error):
s = input()
if s <= '2019/04/19':
  print(Heisei)
else:
  print(TDB)

Fixed submission:
a = list(map(int,input().split("/")))
if a[1] > 4:
  print("TBD")
else:
  print("Heisei")

Buggy python submission (verdict: Runtime Error):
s = input()
S = s.split('/')
ymd = int(''.join(S)) 
if ymd <= 20190419:
  print(Heisei)
else:
  print(TDB)

Fixed submission:
a = list(map(int,input().split("/")))
if a[1] > 4:
  print("TBD")
else:
  print("Heisei")
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())
b = int(input())

if n==1:
  print('Hello World')
elif n[0]==2:
  print(a+b)

Fixed submission:
n = int(input())
 
if n==1:
  print('Hello World')
elif n==2:
  a = int(input())
  b = int(input())
  print(int(a+b))
Buggy python submission (verdict: Runtime Error):
n = list(input())

for i in n:
  if n[i] == 1:
    n[i]=9
  elif n[i] == 9:
    n[i]=1
print(''.join(n))

Fixed submission:
n = input()
ans = 0
for i in range(3):
  if n[i] == '1':
    ans += 10**(2-i) * 9
  else:
    ans += 10**(2-i) * 1
print(ans)

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

for i in n:
  if n[i] == 1:
    n[i]=9
  elif n[i] == 9:
    n[i]=1
print(''.join(n))

Fixed submission:
n = input()
ans = 0
for i in range(3):
  if n[i] == '1':
    ans += 10**(2-i) * 9
  else:
    ans += 10**(2-i) * 1
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input(),split())

if n%k == 0 or k%n == 0:
  print(0)
  
else:
  print(1)

Fixed submission:
N,K = map(int,input().split())
if N % K == 0:
  print(0)
else:
  print(1)
Buggy python submission (verdict: Runtime Error):
s = input()
cnt = 0
 
for i in s:
  if i = '+':
    cnt = cnt +1
  elif i = '-':
    cnt = cnt-1
 
print(cnt)

Fixed submission:
s = input()
cnt = 0
 
for i in s:
  if i == '+':
    cnt = cnt +1
  elif i == '-':
    cnt = cnt-1
 
print(cnt)

Buggy python submission (verdict: Runtime Error):
s = list(int(input()))
cnt = 0
 
for i in s:
  if i = +:
    cnt = cnt +1
  elif i = -:
    cnt = cnt-1
 
print(cnt)

Fixed submission:
s = input()
cnt = 0
 
for i in s:
  if i == '+':
    cnt = cnt +1
  elif i == '-':
    cnt = cnt-1
 
print(cnt)

Buggy python submission (verdict: Runtime Error):
s = list(input())
cnt = 0

for i in s:
  if i = '+':
    cnt = cnt +1
  if i = '-':
    cnt = cnt-1

print(cnt)

Fixed submission:
s = input()
cnt = 0
 
for i in s:
  if i == '+':
    cnt = cnt +1
  elif i == '-':
    cnt = cnt-1
 
print(cnt)
Buggy python submission (verdict: Runtime Error):
a,b = int(input().split())

if a + b <= 16:
  if a <= 8 and b <= 8:
    print('Yay!')
  else:
    print(':(')
else:
  print(':(')

Fixed submission:
a,b = map(int, input().split())
 
if a + b <= 16:
  if a <= 8 and b <= 8:
    print('Yay!')
  else:
    print(':(')
else:
  print(':(')

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

if a <= 8 and b <= 8:
  print('Yay!')
else:
  print(':(')

Fixed submission:
a,b = map(int, input().split())
 
if a + b <= 16:
  if a <= 8 and b <= 8:
    print('Yay!')
  else:
    print(':(')
else:
  print(':(')
Buggy python submission (verdict: Runtime Error):
d,n = map(int, input().split())
x = []

if d == 0 :
  for i in range(1,100):
    x.append(i)
  
elif d == 1 :
  for i in range(1,100):
    x.append(i*100)

elif d == 2 :
  for i in range(1,100):
    x.append(i*10000)

print(x[n-1])

Fixed submission:
d,n = map(int, input().split())
if n==100:
  print(100**d * 101)
else:
  print(100**d * n)
Buggy python submission (verdict: Runtime Error):
X = int(input())
c = 1
for b in range(1,X):
    for p in range(2,X):
        if b**p <= X:
            c = max(c, b**p)
        else:
            break
print(c)

Fixed submission:
a,b,c,d = map(int, input().split())
 
if abs(b-a) <= d and abs(c-b) <= d :
  print('Yes')
elif abs(a-c) <= d :
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())
 
if abs(b-a) <= d and abs(c-b) <= d :
  print('Yes')
elif: abs(a-c) <= d :
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c,d = map(int, input().split())
 
if abs(b-a) <= d and abs(c-b) <= d :
  print('Yes')
elif abs(a-c) <= d :
  print('Yes')
else:
  print('No')

Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())
 
if abs(b-a) < d and abs(c-b) < d :
  print('Yes')
elif: abs(a-c) < d :
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c,d = map(int, input().split())
 
if abs(b-a) <= d and abs(c-b) <= d :
  print('Yes')
elif abs(a-c) <= d :
  print('Yes')
else:
  print('No')

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

if abs(b-a) < d and abs(a-b) < d :
  print('Yes')
elif: abs(a-c) < d :
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c,d = map(int, input().split())
 
if abs(b-a) <= d and abs(c-b) <= d :
  print('Yes')
elif abs(a-c) <= d :
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
s = input()
print(700　+ int(s.count("o"))*100)

Fixed submission:
s=input()
print(700+int(s.count("o"))*100)

Buggy python submission (verdict: Runtime Error):
s = input()
print(700　+ int(s.count('o'))*100)

Fixed submission:
s=input()
print(700+int(s.count("o"))*100)

Buggy python submission (verdict: Runtime Error):
s = input()
print(700　+ 100*int(s.count('o')))

Fixed submission:
s=input()
print(700+int(s.count("o"))*100)

Buggy python submission (verdict: Runtime Error):
s = input()
print(700　+ 100*s.count('o'))

Fixed submission:
s=input()
print(700+int(s.count("o"))*100)

Buggy python submission (verdict: Runtime Error):
s = input()
print(700　+ 100*s.count('o')

Fixed submission:
s=input()
print(700+int(s.count("o"))*100)
Buggy python submission (verdict: Runtime Error):
c1 = input()
c2 = input()
c3 = input()

print(c1[1]+c2[2]+c3[3])

Fixed submission:
c1 = input()
c2 = input()
c3 = input()
 
print(c1[0]+c2[1]+c3[2])
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = int(input())

if n < 500 :
  if a >= n[-3:] :
    print('Yes')
  else:
    print('No')
else:
  if a >= n[-2:] :
    print('Yes')
  else:
    print('No')

Fixed submission:
n = int(input())
a = int(input())

b = n % 500
if b <= a:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
x = int(input())
a = int(input())
b = int(input())

print(x-a-(b*(x-a)//b)

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

s[3] = '8'
print(s)

Fixed submission:
s = list(input()) 
s[3] = '8'
print(''.join(s))
Buggy python submission (verdict: Runtime Error):
s = int(input())
print(s.count(1))

Fixed submission:
s = input()
print(s.count('1'))
Buggy python submission (verdict: Runtime Error):
x,y = map(int, input().split())
comp = {'A':10,'B':11,'C':12,'D':13,'E':14,'F':15}

if comp[x] > comp[y]:
  print('>')
elif comp[x] == comp[y]:
  print('=')
else:
  print('<')

Fixed submission:
x,y=map(str,input().split())
if x>y:
    print('>')
elif x<y:
    print('<')
else: print('=')
Buggy python submission (verdict: Runtime Error):
n = int(input())
ans = 0

for i in range(1,n+1):
  if i**2 <= n:
    ans = i**2

print(ans)


Fixed submission:
c1 = input()
c2 = input()

if c1[0] == c2[2] and c1[1] == c2[1] and c1[2] == c2[0]:
  print('YES')
else:
  print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans = 0
 
for i in range(1,n+1):
  if i**2 <= n:
    ans = i**2
 
print(ans)

Fixed submission:
X = int(input())
a = 1
while X >= a**2:
    a += 1
print(int((a-1)**2))
Buggy python submission (verdict: Runtime Error):
h,w = map(int, input().split())
s = [list(input() for i in range(h))]
t = s.copy()
 
 
number = []
cnt = 0
 
for i in range(h) :
  if 1 <= i and i <= h-2 :
    for j in range(w) :
      if j >= 1 and j < w-1 :
        number = [s[i-1][j-1],s[i-1][j],s[i-1][j+1],s[i][j-1],s[i][j+1],s[i+1][j-1],s[i+1][j],s[i+1][j+1]]
        cnt = number.count('#')
        t[i][j] = cnt
        
      elif j == 0 :
        number = [s[i-1][0],s[i+1][0],s[i-1][1],s[i][1],s[i+1][1]]
        cnt = number.count('#')
        t[i][0] = cnt
      
      elif j == w-1 :
        number = [s[i-1][w-1],s[i+1][w-1],s[i-1][w-2],s[i][w-2],s[i+1][w-2]]
        cnt = number.count('#')
        t[i][w-1] = cnt       
  
  elif i == 0 :
    for j in range(w) :
      if 1 <= j and j <= w-2 :
        number = [s[0][j-1],s[0][j+1],s[1][j-1],s[1][j],s[1][j+1]]
        cnt = number.count('#') 
        t[0][j] = cnt
      
      elif j == 0 :
        number = [s[0][1],s[1][0],s[1][1]]
        cnt = number.count('#') 
        t[0][0] = cnt
        
      elif j == w-1 :
        number = [s[0][w-2],s[1][w-2],s[1][w-1]]
        cnt = number.count('#') 
        t[0][w-1] = cnt        
  
  elif i == h-1 :
    for j in range(w) :
      if 1 <= j and j <= w-2 :
        number = [s[h-1][j-1],s[h-1][j+1],s[h-2][j-1],s[h-2][j],s[h-2][j+1]]
        cnt = number.count('#')
        t[h-1][j] = cnt
                
      elif j == 0 :
        number = [s[h-1][1],s[h-2][1],s[h-2][0]]
        cnt = number.count('#') 
        t[h-1][0] = cnt
        
      elif j == w-1 :
        number = [s[h-2][w-1],s[h-1][w-2],s[h-2][w-2]]
        cnt = number.count('#') 
        t[h-1][w-1] = cnt
 
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      t[i][j] = '#'
    
  
a0 = map(str,t[0])
a1 = map(str,t[1])
a2 = map(str,t[2])
print(''.join(a0))
print(''.join(a1))
print(''.join(a2))

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

if a==b:
  print(c)
elif a==c:
  print(b)
elif b==c:
  print(a)
Buggy python submission (verdict: Runtime Error):
n = int(input())

if n[0]==9 or n[1]==9:
  print('Yes')
  
else:
  print('No')

Fixed submission:
n = input()

if n[0]=='9' or n[1]=='9':
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())
l,r = [map(int, input().split()) for i in range(n)]

number = 0

for i in range(n):
  number = number + (r[i]-l[i]+1)

print(number)  

Fixed submission:
n = int(input())
l=[]
total=0
for i in range(n):
  l,r=map(int,input().split())
  total += (r-l+1)
print(total)
Buggy python submission (verdict: Runtime Error):
x,t = map(int(input()))
 
if x >= t:
  print(x-t)
else:
  print(0)

Fixed submission:
x,t = map(int,input().split())
 
if x >= t:
  print(x-t)
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
x,t = int(input())

if x >= t:
  print(x-t)
else:
  print(0)

Fixed submission:
x,t = map(int,input().split())
 
if x >= t:
  print(x-t)
else:
  print(0)
Buggy python submission (verdict: Runtime Error):
h,w = map(int, input().split())
a = [input().split() for i in range(h)]
b = []
 
for i in range(h):
  a[i].insert(0,'#')
  a[i].append('#')
  
for i in range(w+2):
  b.append('#')

a.insert(0,b)
a.append(b)
  
for i in a:
  print("".join(str(a[i])))

Fixed submission:
h,w = map(int, input().split())
a = [input().split() for i in range(h)]
b = []
 
for i in range(h):
  a[i].insert(0,'#')
  a[i].append('#')
  
for i in range(w+2):
  b.append('#')
 
a.insert(0,b)
a.append(b)
  
for i in a:
  print("".join(list(map(str,i))))

Buggy python submission (verdict: Runtime Error):
h,w = map(int, input().split())
a = [input().split() for i in range(h)]
 
a = {}
b = []
 
for i in h:
  a[i].insert(0,'#')
  a[i].append('#')
  
for i in w+2:
  b.append('#')
 
a.insert(0,b)
a.append(b)
  
for i in a:
  print("".join(list(map(str,i))))

Fixed submission:
h,w = map(int, input().split())
a = [input().split() for i in range(h)]
b = []
 
for i in range(h):
  a[i].insert(0,'#')
  a[i].append('#')
  
for i in range(w+2):
  b.append('#')
 
a.insert(0,b)
a.append(b)
  
for i in a:
  print("".join(list(map(str,i))))

Buggy python submission (verdict: Runtime Error):
h,w = map(int, input().split())
for i in h:
  a[i] = list(input())

a = {}
b = []

for i in h+2:
  b.append('#')

a.insert(0,b)
a.insert(h+2,b)

for i in w+2:
  a[i].insert(0,'#')
  a[i].insert(w+2,'#')

print(a)

Fixed submission:
h,w = map(int, input().split())
a = [input().split() for i in range(h)]
b = []
 
for i in range(h):
  a[i].insert(0,'#')
  a[i].append('#')
  
for i in range(w+2):
  b.append('#')
 
a.insert(0,b)
a.append(b)
  
for i in a:
  print("".join(list(map(str,i))))
Buggy python submission (verdict: Runtime Error):
for i, b in enumerate(B):
    if b <= A[i]:
        r += b
    else:
        b -= A[i]
        r += A[i]
        if b <= A[i+1]:
            A[i+1] -= b
            r += b
        else:
            r += A[i+1]
            A[i+1]=0
            
print(r)

Fixed submission:
n = int(input())
A= list(map(int, input().split()))
B= list(map(int, input().split()))
r = 0
for i, b in enumerate(B):
    if b <= A[i]:
        r += b
    else:
        b -= A[i]
        r += A[i]
        if b <= A[i+1]:
            A[i+1] -= b
            r += b
        else:
            r += A[i+1]
            A[i+1]=0
            
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
l=[0] * m
r=[0] * m
for i in range(m):
  l[i], r[i] = map(int, input().split())
count = 0
for i in range(n):
  for j in range(m):
    if (i+1 < l[j]) or (i+1 > r[j]):
      break
  else:
    count = count + 1
print(count)

Fixed submission:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
l=[0] * m
r=[0] * m
for i in range(m):
  l[i], r[i] = map(int, input().split())
l.sort()
r.sort()
if r[0] - l[m-1] + 1 > 0:
  print(r[0] - l[m-1] + 1)
else:
  print("0")
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
count = 0;
for j in range(m):
  for i in range(bc[j][0]):
    if a[0] < bc[j][1]:
      del a[0]
      a.append(bc[j][1])
      count = count + 1
    else:
      break
    if count > n + 1:
      break
  else: 
    continue
  break
print(sum(a))


Fixed submission:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
count = 0
s = 0
for j in range(m):
  for i in range(bc[j][0]):
    if a[count] < bc[j][1]:
      s = s + bc[j][1]
      count = count + 1
    else:
      break
    if count > n - 1 :
      break
  else: 
    continue
  break
if count > n - 1:
  print(s)
else:
  print(s + sum(a[count:]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
for j in range(m):
  a.sort()
  for i in range(bc[j][0]):
    if a[0] < bc[j][1]:
      del a[0]
      a.append(bc[j][1])
    else:
      break
  else: 
    continue
  break
print(sum(a))

Fixed submission:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
count = 0
s = 0
for j in range(m):
  for i in range(bc[j][0]):
    if a[count] < bc[j][1]:
      s = s + bc[j][1]
      count = count + 1
    else:
      break
    if count > n - 1 :
      break
  else: 
    continue
  break
if count > n - 1:
  print(s)
else:
  print(s + sum(a[count:]))

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
for j in range(m):
  for i in range(bc[j][0]):
    if a[0] < bc[j][1]:
      del a[0]
      a.append(bc[j][1])
    else:
      break
  else: 
    continue
  break
print(sum(a))

Fixed submission:
# -*- coding: utf-8 -*-
n, m = map(int, input().split())
a= list(map(int, input().split()))
bc=[[0, 0]]
for i in range(m):
  bc.append(list(map(int, input().split())))
del bc[0]
bc=sorted(bc, key=lambda x: x[1], reverse=True)
a.sort()
count = 0
s = 0
for j in range(m):
  for i in range(bc[j][0]):
    if a[count] < bc[j][1]:
      s = s + bc[j][1]
      count = count + 1
    else:
      break
    if count > n - 1 :
      break
  else: 
    continue
  break
if count > n - 1:
  print(s)
else:
  print(s + sum(a[count:]))