Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
v

Fixed submission:
s = input()
n = len(s)
counter = 0
for i in range(n//2):
  if s[i] != s[n-i-1]:
    counter += 1
print(counter)
Buggy python submission (verdict: Runtime Error):
n = int(input())
import math
for i in range(50000):
  if math.floor(i*1.08) == n:
    print(i)
    exit()
    
ptiny(":(")

Fixed submission:
n = int(input())
import math

for i in range(50000):
  if math.floor(i*1.08) == n:
    print(i)
    exit()
    
print(":(")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
List = list(map(int, input().split()))

List.sort()

counter = 0

for i in range(0, n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if List[i] + List[j] > List[k]:
        counter += 1
print(counter)

Fixed submission:
import bisect
n = int(input())
lst = list(map(int, input().split()))
lst.sort()

ans = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    a = lst[i]
    b = lst[j]
    border = a + b
    dig = bisect.bisect_left(lst, border)
    ans += max(0, dig - j - 1)
    
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
length = list(map(int,input().split()))

s = 0

for i in range(0, n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      
      t = length[i]
      
      if t < length[j]:
        t = length[j]
      if t < length[k]:
        t = length[k]
        
      if t*2 < length[i] + length[j] + length[k]:
        s = s+1      
    
print(s)

Fixed submission:
import bisect
n = int(input())
lst = list(map(int, input().split()))
lst.sort()

ans = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    a = lst[i]
    b = lst[j]
    border = a + b
    dig = bisect.bisect_left(lst, border)
    ans += max(0, dig - j - 1)
    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
a, b = map(int, input().split())

def prime_factorize(n):
  border = int(n**(1/2))
  ans = []
  i = 2
  while(i <= n):
    if n % i == 0:
      ans.append(i)
      n = n // i
      i = 2
    else:
      i += 1
  return ans

list_a = list(set(prime_factorize(a)))
list_b = list(set(prime_factorize(b)))

list_ab = set(list_a) & set(list_b)
ans = len(list_ab) + 1
print(ans)

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

def factorize(n):
  
  arr = []
  temp = n
  
  for i in range(2, int(n**(1/2))+1):
    if temp % i == 0:
      while temp % i == 0:
        temp //= i
        arr.append(i)

  if temp != 1:
    arr.append(temp)

  return arr

set_a = set(factorize(a))
set_b = set(factorize(b))

set_ab = set(set_a) & set(set_b)
ans = len(set_ab) + 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
a, b = map(int, input().split())

def prime_factorize(n):
  border = int(n**(1/2))
  ans = []
  i = 2
  while(i <= n):
    if n % i == 0:
      ans.append(i)
      n = n // i
      i = 2
    else:
      i += 1
  return ans

list_a = list(set(prime_factorize(a)))
list_b = list(set(prime_factorize(b)))

list_ab = set(list_a) & set(list_b)
ans = len(list_ab) + 1
print(ans)

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

def factorize(n):
  
  arr = []
  temp = n
  
  for i in range(2, int(n**(1/2))+1):
    if temp % i == 0:
      while temp % i == 0:
        temp //= i
        arr.append(i)

  if temp != 1:
    arr.append(temp)

  return arr

set_a = set(factorize(a))
set_b = set(factorize(b))

set_ab = set(set_a) & set(set_b)
ans = len(set_ab) + 1
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
n, m = map(int, input().split())
danger = [int(input()) for i in range(m)]

MOD = 1000000007
MAX = 1000000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

def poss(n):
  n -= 1
  k = n//2
  ans = 0
  for i in range(k+1):
    ans += modcomb(n-i, i) % MOD
  return ans % MOD

ans = poss(danger[0])
for i in range(1, m):
  if danger[i] - danger[i-1] == 1:
    print(0)
    sys.exit()
  ans *= poss(danger[i] - danger[i-1] - 1)
  ans = ans % MOD
ans *= poss(n - danger[m-1])

print(ans % MOD)

Fixed submission:
import sys
n, m = map(int, input().split())
danger = [int(input()) for i in range(m)]

MOD = 1000000007
MAX = 200000           #適当な数を入力
fac, finv, inv = [[0]*MAX for i in range(3)]
def combinit():     #MAXまでの下準備
  fac[0] = fac[1] = 1
  finv[0] = finv[1] = 1
  inv[1] = 1
  for i in range(2, MAX):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD

def modcomb(n, k):      #mod(nCk)を計算、ただしn<MAX
  if (n < k):
    return 0
  if (n < 0 or k < 0):
    return 0
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
combinit()          #下準備の実行 O(MAX)

def poss(n):
  n -= 1
  k = n//2
  ans = 0
  for i in range(k+1):
    ans += modcomb(n-i, i) % MOD
  return ans % MOD
if m == 0:
  print(poss(n+1))
  sys.exit()
ans = poss(danger[0])
for i in range(1, m):
  if danger[i] - danger[i-1] == 1:
    print(0)
    sys.exit()
  ans *= poss(danger[i] - danger[i-1] - 1)
  ans = ans % MOD
ans *= poss(n - danger[m-1])

print(ans % MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
step = list(map(int, input().split()))

ans = [float('inf')]*(10**6)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

print(dp(n))

Fixed submission:
n, k = map(int, input().split())
step = list(map(int, input().split()))

ans = [float('inf')]*(10**6)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

print(dp(n))

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

ans = [float('inf')]*(10)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

print(dp(n))

Fixed submission:
n, k = map(int, input().split())
step = list(map(int, input().split()))

ans = [float('inf')]*(10**6)

ans[0] = 0
def dp(n):
  for i in range(n):
    for j in range(k+1):
      if i+j < n:
        ans[i+j] = min(ans[i+j], ans[i] + abs(step[i+j] - step[i]))
  return ans[n-1]

print(dp(n))
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(N)]

ans = [[0]*(10**5+10) for i in range(N+10)]
  
for i in range(N):
  for j in range(W+1):
    if j >= lst[i][0]:
      ans[i+1][j] = max(ans[i][j-lst[i][0]] + lst[i][1], ans[i][j])
    else:
      ans[i+1][j] = ans[i][j]
  
print(ans[N][W])
          

Fixed submission:
N, W = map(int, (input().split()))
lst = [list(map(int, input().split())) for i in range(N)]

ans = [[0]*(10**5+10) for i in range(N+10)]
  
for i in range(N):
  for j in range(W+1):
    if j >= lst[i][0]:
      ans[i+1][j] = max(ans[i][j-lst[i][0]] + lst[i][1], ans[i][j])
    else:
      ans[i+1][j] = ans[i][j]
  
print(ans[N][W])
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

counter = 0
for i in range(len(s)):
  if s[i] == "1":
    counter += 1
  else:
    ans = i
    break
  
if k <= i:
  ans = 1
else:
  ans = s[ans]
  
print(ans)

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

counter = 0
for i in range(len(s)):
  if s[i] == "1":
    counter += 1
    ans = 1
  else:
    ans = i
    break
  
if k <= counter:
  ans = 1
else:
  ans = s[ans]
  
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m, q = map(int, input().split())

dia = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
  l, r = map(int, input().split())
  dia[l][r] += 1
  
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(1, n+1):
  for j in range(i, n+1):
    lst[i][j] = lst[i][j-1] + dia[i][j]
    
for i in range(q):
  l, r = map(int, input().split())
  count = 0
  for j in range(l, r+1):
    count += lst[j][r]
  print(count)

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

dia = [[0]*(n+1) for i in range(n+1)]
for i in range(m):
  l, r = map(int, input().split())
  dia[l][r] += 1
  
lst = [[0]*(n+1) for i in range(n+1)]
for i in range(1, n+1):
  for j in range(i, n+1):
    lst[i][j] = lst[i][j-1] + dia[i][j]
    
for i in range(q):
  l, r = map(int, input().split())
  count = 0
  for j in range(l, r+1):
    count += lst[j][r]
  print(count)
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = []
for i in range(n):
  x, l = map(int, input().split())
  left = x - l
  right = x + l
  lst.append([left, right])

lst = sorted(lst, key=lambda x: x[1])

ans = 1
limit = lst[0][1]
for i in range(n):
  if lst[i][0] >= limit:
    ans += 1
    limit = lst[i][1]

print(ans)

Fixed submission:
n, m = map(int, input().split())
need = [list(map(int, input().split())) for i in range(m)]
need = sorted(need, key=lambda x: x[1])

ans = 1
stock = need[0][1]
for i in range(m):
  if stock <= need[i][0]:
    ans += 1
    stock = need[i][1]
    
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m, x = map(int, input().split())
lst = list(map(int, input().split()))

g1, g2 = 0
for i in range(x):
  if i in lst:
    g1 += 1
    
for i in range(x+1, n):
  if i in lst:
    g2 += 1
    
print(min(g1, g2))
  

Fixed submission:
n, m, x = map(int, input().split())
lst = list(map(int, input().split()))

g1, g2 = 0, 0
for i in range(x):
  if i in lst:
    g1 += 1
    
for i in range(x+1, n):
  if i in lst:
    g2 += 1
    
print(min(g1, g2))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
lst = list(map(int, input().split()))
lst.append(0)
lst.insert(0, 0)

dist = []
for i in range(n+1):
  dist.append(abs(lst[i+1]-lst[i]))

for i in range(n):
  ans = sum(dist)-(dist[i]+dist[i+1])
  ans += abs(lst[i]-lst[i+2])
  print(ans)
  

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
lst.append(0)
lst.insert(0, 0)

dist = []
for i in range(n+1):
  dist.append(abs(lst[i+1]-lst[i]))

sum_dist = sum(dist)
for i in range(n):
  ans = sum_dist-(dist[i]+dist[i+1])
  ans += abs(lst[i]-lst[i+2])
  print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
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 range(n):
  canB = bisect.bisect_right(B, A[i])
  if canB == n:
    continue
  else:
    for j in range(canB, n):
      canC = bisect.bisect_right(C, B[j])
      ans += (n - canC)
print(ans)



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 i in range(n):
  canA = bisect.bisect_left(A, B[i])
  canC = bisect.bisect_right(C, B[i])
  ans += (canA)*(n-canC)
print(ans)

Buggy python 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()

print(A)
print(B)
print(C)

ans = 0
for i in range(n):
  canB = bisect.bisect_right(B, A[i])
  if canB == n:
    continue
  else:
    for j in range(canB, n):
      canC = bisect.bisect_right(C, B[j])
      ans += (n - canC)
      print(A[i], B[j], C[canC], (n - canC))
print(ans)



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 i in range(n):
  canA = bisect.bisect_left(A, B[i])
  canC = bisect.bisect_right(C, B[i])
  ans += (canA)*(n-canC)
print(ans)
Buggy python submission (verdict: Runtime Error):
X = input()
x = int(X[-2] + X[-1])
X = (int(X)-x)//100
if x > 5*X:
    print(0)
else:
    print(1)


Fixed submission:
X = input()
if int(X) < 100:
    print(0)
    exit()
x = int(X[-2] + X[-1])
X = (int(X)-x)//100
if x > 5*X:
    print(0)
else:
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
for i in range(1, N+1):
    print(A.index(i)+1, end=' ')


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [0] * N
for (i, x) in enumerate(A):
    B[x-1] = i+1
for b in B:
    print(b, end=' ')

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
for i in range(1, N+1):
    print(A.index(i)+1, end=' ')


Fixed submission:
N = int(input())
A = list(map(int,input().split()))
B = [0] * N
for (i, x) in enumerate(A):
    B[x-1] = i+1
for b in B:
    print(b, end=' ')
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int,input().split())
D = 2
ans = 1
A_l = []
B_l = []
while True:
    if A % D == 0:
        while True:
            if A % D != 0:
                break
            A //= D
        A_l.append(D)
    if B % D == 0:
        while True:
            if B % D != 0:
                break
            B //= D
        B_l.append(D)
    if A == B == 1:
        break
    D += 1
for a in A_l:
    if a in B_l:
        ans += 1
print(ans)


Fixed submission:
A, B = map(int,input().split())
D = 2
ans = 1
A_l = []
B_l = []
MAX = max(A, B)
q_MAX = int(MAX ** (1/2))
for i in range(2, q_MAX+1):
    if A % D == 0:
        while True:
            if A % D != 0:
                break
            A //= D
        A_l.append(D)
    if B % D == 0:
        while True:
            if B % D != 0:
                break
            B //= D
        B_l.append(D)
    if i == q_MAX:
        A_l.append(A)
        B_l.append(B)
    if A == B == 1:
        break
    D += 1
for a in A_l:
    if a in B_l:
        ans += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int,input().split())
D = 2
ans = 1
A_l = []
B_l = []
while True:
    if A % D == 0:
        while True:
            if A % D != 0:
                break
            A //= D
        A_l.append(D)
    if B % D == 0:
        while True:
            if B % D != 0:
                break
            B //= D
        B_l.append(D)
    if A == B == 1:
        break
    D += 1
for a in A_l:
    if a in B_l:
        ans += 1
print(ans)


Fixed submission:
A, B = map(int,input().split())
D = 2
ans = 1
A_l = []
B_l = []
MAX = max(A, B)
q_MAX = int(MAX ** (1/2))
for i in range(2, q_MAX+1):
    if A % D == 0:
        while True:
            if A % D != 0:
                break
            A //= D
        A_l.append(D)
    if B % D == 0:
        while True:
            if B % D != 0:
                break
            B //= D
        B_l.append(D)
    if i == q_MAX:
        A_l.append(A)
        B_l.append(B)
    if A == B == 1:
        break
    D += 1
for a in A_l:
    if a in B_l:
        ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
if S = 'Sunny':
    print('Cloudy')
elif S = 'Cloudy':
    print('Rainy')
elif S = 'Rainy':
    print('Sunny')


Fixed submission:
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
elif S == 'Rainy':
    print('Sunny')
Buggy python submission (verdict: Runtime Error):
S = input()
S_o = S[::2]
S_e = S[1::2]
if 'L' in S_o or 'R' in _e:
    print('No')
else:
    print('Yes')

Fixed submission:
S = input()
S_o = S[::2]
S_e = S[1::2]
if 'L' in S_o or 'R' in S_e:
    print('No')
else:
    print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
H = list(map(int,input().split()))
if N == 1:
    print('Yes')
    exit()
for i in range(N-1):
    if H[i] == H[i+1]:
        pass
    elif H[i] < H[i+1]:
        H[i+1] -= 1
    else:
        print('No')
        exit()
input('Yes')


Fixed submission:
N = int(input())
H = list(map(int, input().split()))
if N == 1:
    print('Yes')
    exit()
for i in range(N-1):
    if H[i] == H[i+1]:
        continue
    elif H[i] < H[i+1]:
        H[i+1] -= 1
    else:
        print('No')
        exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
A_m = str(max(A))
a = A.index(int(A_m))
A = sorted(A)
if A.count(int(A_m)) >= 2:
    print((A_m + '\n')*(N-1) + A_m)
else:
    print(a)
    print((A_m + '\n')*a + str(A[-2]))
    print((A_m + '\n')*(N-(a+2)) + A_m)


Fixed submission:
r = int(input())
print(3*r**2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
A_m = max(A)
if A.count(max) >= 2:
    for i in range(N):
        print(A_m)
else:
    for i in range(N):
        if A[i] == A_m:
            del A[i]
            A_m_new = max(A)
            print(A_m_new)
            A.append(0)
        else:
            print(A_m)


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A_m = str(max(A))
a = A.index(int(A_m))
A = sorted(A)
if A.count(int(A_m)) >= 2:
    print((A_m + '\n')*(N-1) + A_m)
else:
    print((A_m + '\n')*a + str(A[-2]))
    if N-(a+1) == 1:
        print(A_m)
    elif N-(a+1) < 1:
        pass
    else:
        print((A_m + '\n')*(N-(a+2)) + A_m)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
A_m = max(A)
if A.count(max) >= 2:
    for i in range(N):
        print(A_m)
else:
    for i in range(N):
        if A[i] == A_m:
            del A[i]
            A_m_new = max(A)
            print(A_m_new)
        else:
            print(A_m)


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A_m = str(max(A))
a = A.index(int(A_m))
A = sorted(A)
if A.count(int(A_m)) >= 2:
    print((A_m + '\n')*(N-1) + A_m)
else:
    print((A_m + '\n')*a + str(A[-2]))
    if N-(a+1) == 1:
        print(A_m)
    elif N-(a+1) < 1:
        pass
    else:
        print((A_m + '\n')*(N-(a+2)) + A_m)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]
for i in range(N):
    A_new1 = A[:i] + [0]
    A_new2 = A[i+1:] + [0]
    if max(A_new1) >= max(A_new2):
        print(max(A_new1))
    else:
        print(max(A_new2))


Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
A_m = str(max(A))
a = A.index(int(A_m))
A = sorted(A)
if A.count(int(A_m)) >= 2:
    print((A_m + '\n')*(N-1) + A_m)
else:
    print((A_m + '\n')*a + str(A[-2]))
    if N-(a+1) == 1:
        print(A_m)
    elif N-(a+1) < 1:
        pass
    else:
        print((A_m + '\n')*(N-(a+2)) + A_m)
Buggy python submission (verdict: Runtime Error):
import math
def lcm(x, y):
    return x * y // math.gcd(x, y)

A, B, C, D = map(int,input().split())
E = lcm(C, D)
print((B - (B // C + B // D - B // E))-((A-1)-((A-1) // C + (A-1) // D - (A-1) // E)))


Fixed submission:
import fractions
def lcm(x, y):
    return x * y // fractions.gcd(x, y)

A, B, C, D = map(int,input().split())
E = lcm(C, D)
print((B - (B // C + B // D - B // E))-((A-1)-((A-1) // C + (A-1) // D - (A-1) // E)))
Buggy python submission (verdict: Runtime Error):
A, B = map(int,input().split())
if A >= 13:
    print(B)
elif if 6 <= A <= 12:
    print(B // 2)
else:
    print(0)


Fixed submission:
A, B = map(int,input().split())
if A >= 13:
    print(B)
elif 6 <= A <= 12:
    print(B // 2)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1), reverse=True)

idx = 0
flag = 0
for i in range(M):
    q = Q[i]
    B = q[0]
    C = q[1]
    for b in range(B):
        if A[idx] < C:
            A[idx] = C
            idx += 1
        else:
            flag = -1
    if flag == -1 or i == M-1:
        break
print(sum(A))


Fixed submission:
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1), reverse=True)

idx = 0
flag = 0
for i in range(M):
    q = Q[i]
    B = q[0]
    C = q[1]
    for b in range(B):
        if idx >= N:
            flag = -1
            break
        if A[idx] < C:
            A[idx] = C
            idx += 1
        else:
            flag = -1
    if flag == -1 or i == M-1:
        break
print(sum(A))

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1))
Q.reverse()
flag = 0
idx = 0

for q in Q:
    if flag == -1:
        break
    b = q[0]
    c = q[1]
    a = A[idx:idx+b]
    if c < max(a):
        count = 0
        for i in a:
            if i < c:
                count+=1
        A = A[:idx] + [c]*count + A[idx+count:]
        flag = -1
    else:
        a = [c]*b
        A = A[:idx] + a + A[idx+b:]
        idx += b

print(sum(A))


Fixed submission:
from operator import itemgetter

N, M = map(int,input().split())
A = sorted(list(map(int,input().split())))
Q = [list(map(int,input().split())) for _ in range(M)]
Q.sort(key=itemgetter(1), reverse=True)

idx = 0
flag = 0
for i in range(M):
    q = Q[i]
    B = q[0]
    C = q[1]
    for b in range(B):
        if idx >= N:
            flag = -1
            break
        if A[idx] < C:
            A[idx] = C
            idx += 1
        else:
            flag = -1
    if flag == -1 or i == M-1:
        break
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N, M = map(int,input().split())
Q = [list(map(int,input().split())) for _ in range(M)]
C = [[] for _ in range(N+1)]
count = 0
for q in Q:
    X = q[0]
    Y = q[1]
    C[X].append(Y)
    C[Y].append(X)

flag = [-1]*(N+1)
flag[1] = 0
def dfs(s):
    global count
    for c in C[s]:
        flag[s] = 0
        if flag[c] == -1:
            flag[c] = 0
            count += 1
            dfs(c)

for i in range(1,N+1):
    dfs(i)
print(N-count)


Fixed submission:
import sys
sys.setrecursionlimit(500*500)
N, M = map(int,input().split())
Q = [list(map(int,input().split())) for _ in range(M)]
C = [[] for _ in range(N+1)]
count = 0
for q in Q:
    X = q[0]
    Y = q[1]
    C[X].append(Y)
    C[Y].append(X)

flag = [-1]*(N+1)
flag[1] = 0
def dfs(s):
    global count
    for c in C[s]:
        flag[s] = 0
        if flag[c] == -1:
            flag[c] = 0
            count += 1
            dfs(c)

for i in range(1,N+1):
    dfs(i)
print(N-count)
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: Runtime Error):
import fractions
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
ans = 0
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
    A_new = A[:i] + A[i+1:]
    ans = max(ans, gcd(*A_new))
print(ans)


Fixed submission:
a, b, c = map(int, input().split())
result = 0
for i in range(1 , c + 1):
    if i % a == 0:
        result += b
print(result)