Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m, k = map(int, input().split())
L = UnionFind(n)
F = [0] * n
B = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a] += 1
    F[b] += 1
    L.union(a, b)

for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if L.same(c, d):
        B[c] += 1
        B[d] += 1

for i in range(n):
    print(L.size(i) - F[i] - B[i] - 1)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

n, m, k = map(int, input().split())
L = UnionFind(n)
F = [0] * n
B = [0] * n

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    F[a] += 1
    F[b] += 1
    L.union(a, b)

for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if L.same(c, d):
        B[c] += 1
        B[d] += 1

for i in range(n):
    print(L.size(i) - F[i] - B[i] - 1)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

def C(n, r):
  if r == 1:
    return n
  nume = reduce(mul, range(n, n - r, -1))
  deno = reduce(mul, range(1, r+1))
  return nume // deno

n, a, b = map(int, input().split())

mod = 10 ** 9 + 7

if n == 2:
   print(0)
   exit()
                
S = pow(2, n, mod)
A = C(n, a) % mod
B = C(n, b) % mod

print(S - A - B - 1)

Fixed submission:
n, a, b = map(int, input().split())
 
mod = 10 ** 9 + 7
 
if n == 2:
   print(0)
   exit()
                
S = pow(2, n, mod) -1 

x1 = 1
y1 = 1
for i in range(a):
  x1 = x1 * (n-i) % mod
  y1 = y1 * (i+1) % mod
A = (x1 * pow(y1, mod - 2, mod)) % mod

x2 = 1
y2 = 1
for i in range(b):
  x2 = x2 * (n-i) % mod
  y2 = y2 * (i+1) % mod
B = (x2 * pow(y2, mod - 2, mod)) % mod

print((S - A - B) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n , k = map(int, input().split())
p = list(map(int, input().split()))

S = 0
reg = 0

for i in range(n-k+1):
    s = sum(p[i:i+k])
    if S < s:
        S = s
        reg = i
        
ans = 1 / 2 *(S + k)

print(ans)

Fixed submission:
n , k = map(int, input().split())
p = list(map(int, input().split()))
p_accu = [p[0] + 1]

if k == 1:
    print((max(p) + 1 ) / 2 )
    exit()
elif k == n:
    print((sum(p) + n ) / 2 )
    exit()

for i in range(1, n):
    p[i] += p[i-1] + 1
    p_accu.append(p[i])

S = p_accu[k-1]

for i in range(n - k):
    if S < p_accu[i+k] - p_accu[i]:
        S = p_accu[i+k] - p_accu[i]
    
print(S/2)

Buggy python submission (verdict: Time Limit Exceeded):
import decimal

n , k = map(int, input().split())
p = list(map(int, input().split()))

S = 0
reg = 0

for i in range(n-k+1):
    if S < sum(p[i:i+k]):
        S = sum(p[i:i+k])
        reg = i
        

ans = 0
for j in range(k):
    ans += 1 / 2 * (p[reg + j] + 1)

print(ans)

Fixed submission:
n , k = map(int, input().split())
p = list(map(int, input().split()))
p_accu = [p[0] + 1]

if k == 1:
    print((max(p) + 1 ) / 2 )
    exit()
elif k == n:
    print((sum(p) + n ) / 2 )
    exit()

for i in range(1, n):
    p[i] += p[i-1] + 1
    p_accu.append(p[i])

S = p_accu[k-1]

for i in range(n - k):
    if S < p_accu[i+k] - p_accu[i]:
        S = p_accu[i+k] - p_accu[i]
    
print(S/2)

Buggy python submission (verdict: Time Limit Exceeded):
import decimal

n , k = map(int, input().split())
p = list(map(int, input().split()))

S = 0
reg = 0

for i in range(n-k+1):
    if S < sum(p[i:i+k]):
        S = sum(p[i:i+k])
        reg = i
        

ans = 0
for j in range(k):
    ans += 1 / 2 * (p[reg + j] + 1)

print(ans)

Fixed submission:
n , k = map(int, input().split())
p = list(map(int, input().split()))
p_accu = [p[0] + 1]

if k == 1:
    print((max(p) + 1 ) / 2 )
    exit()
elif k == n:
    print((sum(p) + n ) / 2 )
    exit()

for i in range(1, n):
    p[i] += p[i-1] + 1
    p_accu.append(p[i])

S = p_accu[k-1]

for i in range(n - k):
    if S < p_accu[i+k] - p_accu[i]:
        S = p_accu[i+k] - p_accu[i]
    
print(S/2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
k = int(input())


def f(n, k):
    assert n >= 0 #例外処理
    if n < 10:
        if k == 0:
            return 1 #0しかない数 = 0
        elif k == 1:
            return n #k = 1ならn個分存在している
        return 0 #k >= 2のときは、0を返す
    
    q, r = divmod(n, 10)
    res = 0
    
    if k >= 1:
        #1の位が0でないとき
        res += f(q, k-1) * r
        res += f(q-1, k-1) * (9 - r)
    #１の位が0
    res += f(q, k)
    return res

print(f(n, k))

Fixed submission:
#maspyさんのやつ

from functools import lru_cache

n = int(input())
k = int(input())

@lru_cache(None)
def f(n, k):
    assert n >= 0 #例外処理
    if n < 10:
        if k == 0:
            return 1 #0しかない数 = 0
        elif k == 1:
            return n #k = 1ならn個分存在している
        return 0 #k >= 2のときは、0を返す
    
    q, r = divmod(n, 10)
    res = 0
    
    if k >= 1:
        #1の位が0でないとき
        res += f(q, k-1) * r
        res += f(q-1, k-1) * (9 - r)
    #１の位が0
    res += f(q, k)
    return res

print(f(n, k))
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a = []
b = []

for i in range(n):
    a_e, b_e = map(int, input().split())
    a.append(a_e), b.append(b_e)

h_dp = h + max(a)

dp = [[float("inf")] * (h_dp + 1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    dp[i][0] = 0
    for j in range(h_dp+1):
        if a[i] > h_dp:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]] + b[i])

ans = float("inf")
for i in range(h, h_dp+1):
    ans = min(ans, dp[n][i])

print(ans)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []

for i in range(n):
    a_e, b_e = map(int, input().split())
    a.append(a_e), b.append(b_e)

h_dp = h + max(a)

dp = [[float("inf")] * (h_dp + 1) for _ in range(n+1)]
dp[0][0] = 0

for i in range(n):
    dp[i][0] = 0
    for j in range(h_dp+1):
        if a[i] > h_dp:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j-a[i]] + b[i])

ans = float("inf")
for i in range(h, h_dp+1):
    ans = min(ans, dp[n][i])

print(ans)
Buggy python submission (verdict: Runtime Error):
#from fractions import gcd
from math import gcd

def lcm(m, n): return m * n // gcd(m, n)

n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])

mulab %= MOD
ans = 0
for i in range(n):
    #フェルマーの小定理
    ans = ans + mulab * pow(a[i], MOD-2, MOD)
    ans %= MOD

print(ans)

Fixed submission:
from fractions import gcd
#from math import gcd
 
def lcm(m, n): return m * n // gcd(m, n)
 
n = int(input())
a = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])
 
mulab %= MOD
ans = 0
for i in range(n):
    #フェルマーの小定理
    ans = ans + mulab * pow(a[i], MOD-2, MOD)
    ans %= MOD
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
#from math import gcd
 
def lcm(m, n): return m * n // gcd(m, n)
 
n = int(input())
a = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])
 
ans = 0
for i in range(n):
    ans = (ans + mulab // a[i]) % MOD
 
print(ans)

Fixed submission:
from fractions import gcd
#from math import gcd
 
def lcm(m, n): return m * n // gcd(m, n)
 
n = int(input())
a = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])
 
mulab %= MOD
ans = 0
for i in range(n):
    #フェルマーの小定理
    ans = ans + mulab * pow(a[i], MOD-2, MOD)
    ans %= MOD
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
#from math import gcd

def lcm(m, n): return m * n // gcd(m, n)

n = int(input())
a = list(map(int, input().split()))

MOD = 10 ** 9 + 7

mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])

ans = 0
for i in range(n):
    ans = (ans + mulab // a[i]) % MOD

print(ans)

Fixed submission:
from fractions import gcd
#from math import gcd
 
def lcm(m, n): return m * n // gcd(m, n)
 
n = int(input())
a = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
mulab = 1
for i in range(n):
    mulab = lcm(mulab, a[i])
 
mulab %= MOD
ans = 0
for i in range(n):
    #フェルマーの小定理
    ans = ans + mulab * pow(a[i], MOD-2, MOD)
    ans %= MOD
 
print(ans)
Buggy python submission (verdict: Runtime Error):
import itertools

n = int(input())
p = tuple(map(int, input().split())
q = tuple(map(int, input().split())

l = list(itertools.permutations(range(1, n+1)))
a = l.index(p)
b = l.index(q)

print(abs(a-b))

Fixed submission:
import itertools
 
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
 
l = list(itertools.permutations(range(1, n+1)))
a = l.index(p)
b = l.index(q)
 
print(abs(a-b))
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())

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

i = 3

m = 2 * math.floor(n/2) + 1

while i < m:
    Prime = True
    if n % i == 0:
        Prime = False
        i = 3
        n += 2
    i += 2

if Prime == True:
    print(n)
        
        

Fixed submission:
import math

n = int(input())

if n == 2:
    print(2)
    exit()
else:
    if n % 2 == 0:
        n += 1

i = 3

m = 2 * math.floor(n/2) + 1

while i < m:
    if n % i == 0:
        i = 3
        n += 2
    i += 2


print(n)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = list(map(int, input().split()))
count = 0

for i in range(N):
    if a[i] == 1:
        count += i
        k = i
        break
    elif min(a) >= 2:
        print(-1)
        exit()
        
M = 2

for i in range(k+1, N):
    if a[i] != M:
        count += 1
    else:
        M+= 1
        

print(count)        

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
count = 0

if min(a) >= 2:
        print(-1)
        exit()

for i in range(N):
    if a[i] == 1:
        count += i
        k = i
        break

M = 2

for i in range(k+1, N):
    if a[i] != M:
        count += 1
    else:
        M+= 1
        

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
count = 0

if N % 2 != 0:
    print(0)
    exit()

for i in range(0, int(N//2)):
    if (N - 2*i) % 5 == 0:
        count += 1
    
print(count)

Fixed submission:
N = int(input())
count = 0

if N % 2 != 0:
    print(0)
    exit()
P = 1
k = 2 * 5

while k <= N:  
    count += N//k
    k *= 5
    
print(count)

Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000000) 

def f(n):
    if n <= 1:
        return 1
    return n * f(n-2)

n = int(input())
F_s = str(f(n))
ans = 0

for i in range(0, len(F_s))[::-1]:
    if int(F_s[i]) == 0:
       ans += 1
    else:
         break
     
print(ans)

Fixed submission:
N = int(input())
count = 0

if N % 2 != 0:
    print(0)
    exit()
P = 1
k = 2 * 5

while k <= N:  
    count += N//k
    k *= 5
    
print(count)

Buggy python submission (verdict: Runtime Error):
def f(n):
    if n < 2:
        return 1
    return n * f(n-2)

n = int(input())
F_s = str(f(n))
ans = 0

for i in range(0, len(F_s))[::-1]:
    if int(F_s[i]) == 0:
       ans += 1
    else:
         break
     
print(ans)

Fixed submission:
N = int(input())
count = 0

if N % 2 != 0:
    print(0)
    exit()
P = 1
k = 2 * 5

while k <= N:  
    count += N//k
    k *= 5
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a_bi = []

for i in range(n):
    a_bi_e = format(a[i], 'b')
    a_bi.append(a_bi_e)

MOD = 10 ** 9 + 7
S = 0

for i in range(n-1):
    k = i + 1
    while k < n:
        string = ''
        dlen = len(a_bi[i]) - len(a_bi[k]) 
        if dlen == 0:
            for j in range(len(a_bi[i])):
                string_e = int(a_bi[i][j]) ^ int(a_bi[k][j])
                string += str(string_e)
        if dlen > 0:
            for j in range(dlen):
                string += a_bi[i][j]
            for j in range(len(a_bi[k])):
                string_e = int(a_bi[i][j+dlen]) ^ int(a_bi[k][j])
                string += str(string_e)
        if dlen < 0:
            dlen *= -1
            for j in range(dlen):
                string += a_bi[k][j]
            for j in range(len(a_bi[i])):
                string_e = int(a_bi[i][j]) ^ int(a_bi[k][j+dlen])
                string += str(string_e)
        k += 1
        S += (int(string, 2) % MOD)
S %= MOD
print(S)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
m = 1

for i in range(60):
    #mbit目に情報を持つものをすべて足し合わせる。
    #m = 1: 1bit目（2^0の位）、m=10: 2bit目（2^1の位）
    #sum = sigma(1の数 * 2^(m-1))
    one = sum(a_e & m for a_e in a)
    one //= m
    zero = n - one
    ans += one * zero * m
    ans %= MOD
    
    m <<= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a_bi = []

for i in range(n):
    a_bi_e = format(a[i], 'b')
    a_bi.append(a_bi_e)

MOD = 10 ** 9 + 7
S = 0

for i in range(n-1):
    k = i + 1
    while k < n:
        string = ''
        dlen = len(a_bi[i]) - len(a_bi[k]) 
        if dlen == 0:
            for j in range(len(a_bi[i])):
                string_e = int(a_bi[i][j]) ^ int(a_bi[k][j])
                string += str(string_e)
        if dlen > 0:
            for j in range(dlen):
                string += a_bi[i][j]
            for j in range(len(a_bi[k])):
                string_e = int(a_bi[i][j+dlen]) ^ int(a_bi[k][j])
                string += str(string_e)
        if dlen < 0:
            dlen *= -1
            for j in range(dlen):
                string += a_bi[k][j]
            for j in range(len(a_bi[i])):
                string_e = int(a_bi[i][j]) ^ int(a_bi[k][j+dlen])
                string += str(string_e)
        k += 1
        S += (int(string, 2) % MOD)
S %= MOD
print(S)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ans = 0
m = 1

for i in range(60):
    #mbit目に情報を持つものをすべて足し合わせる。
    #m = 1: 1bit目（2^0の位）、m=10: 2bit目（2^1の位）
    #sum = sigma(1の数 * 2^(m-1))
    one = sum(a_e & m for a_e in a)
    one //= m
    zero = n - one
    ans += one * zero * m
    ans %= MOD
    
    m <<= 1

print(ans)
Buggy python submission (verdict: Runtime Error):
s=str(input())
l=['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-i)

Fixed submission:
s=input()
l=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
  if s==l[i]:print(7-i)

Buggy python submission (verdict: Runtime Error):
s = str(input())
l = ['MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT', 'SUN']
 
if s == "SUN":
  print(7)
else:
  for i in range(7):
    if s == l[i]
       print(i)

Fixed submission:
s=input()
l=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
  if s==l[i]:print(7-i)

Buggy python submission (verdict: Runtime Error):
s = str(input())
l = [MON, TUE, WED, WED, THU, FRI, SAT, SUN]

if s == "SUN":
  print(7)
else:
  for i in range(7):
    if s == l[i]
       print(i)


Fixed submission:
s=input()
l=['SUN','MON','TUE','WED','THU','FRI','SAT']
for i in range(7):
  if s==l[i]:print(7-i)
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = str(input())
  
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
f = ''
 
for i in range(len(s)):
    for j in range(26):
        m = i + n
        if m >= 26:
            m -= 26
        if s[m] == alp[j]:
            f += alp[j]
print(f)

Fixed submission:
n = int(input())
s = input()
for x in s:
    st = (ord(x) +n-65)%26
    print(chr(65+st),end='')

Buggy python submission (verdict: Runtime Error):
n = int(input())
s = str(input())
  
alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
f = ''

for in range(len(s)):
    for j in range(26):
        if s[i] == alp[j]:
            f += alp[j]
print(f)

Fixed submission:
n = int(input())
s = input()
for x in s:
    st = (ord(x) +n-65)%26
    print(chr(65+st),end='')
Buggy python submission (verdict: Runtime Error):
import numpy as np

a, b, x = map(int, input().split())

if x < 1/2*a*b:
    a1 = 2*x/(a*b)
    rad = np.arctan(a1/b)
else:
    y = 2*(b-x/a**2)
    rad = np.arctan(a/y)

print(90-rad*180/np.pi)

Fixed submission:
import numpy as np
 
a, b, x = map(int, input().split())
 
if x == a**2*b:
    print(0)
    exit()
 
if x < 1/2*b*a**2:
    a1 = 2*x/(a*b)
    rad = np.arctan(a1/b)
else:
    y = 2*(b-x/a**2)
    rad = np.arctan(a/y)
 
print(90-rad*180/np.pi)
Buggy python submission (verdict: Runtime Error):
s = str(input())
k = int(input())
 
n = len(s)
l = [0] * n

for i in range(n-1):
    if s[i] == s[i+1] and l[i] == 0:
        l[i+1] = 1

if s.count(s[0]) == n:
    print(s*k//2)
elif s[0] != s[-1]:
    print(sum(l) * k)
else:
    a = 0
    b = 0
    ac = True
    bc = True
    for i in range(n):
        if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
        if s[n-i-1] == s[0] and bc == True:
            b += 1
        else: bc = False  
    sub = a//2 + b//2 - (a+b)//2
    print(sum(l)*k - sub*(k-1))
    

Fixed submission:
s = str(input())
k = int(input())
 
n = len(s)
l = [0] * n

for i in range(n-1):
    if s[i] == s[i+1] and l[i] == 0:
        l[i+1] = 1

if s.count(s[0]) == n:
    print(n*k//2)
elif s[0] != s[-1]:
    print(sum(l) * k)
else:
    a = 0
    b = 0
    ac = True
    bc = True
    for i in range(n-1):
        if s[i] == s[0] and ac == True:
            a += 1
        elif s[i] != s[0]:
            ac = False
        if s[n-1-i] == s[n-1] and bc == True:
            b += 1
        else: bc = False  
    sub = a//2 + b//2 - (a+b)//2
    print(sum(l)*k - sub*(k-1))
Buggy python submission (verdict: Runtime Error):
n = int(input())
print(n(n-1)//2)

Fixed submission:
n = int(input())
print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
x = int(input())
l = set([])
i = 1
while i < x:
    j = 2
    while j < 10:
        if i**j <= x:
            l.add(i**j)
        j += 1
    i += 1

print(max(l))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ball = [0] * n

for i in range(n)[::-1]:
    m = n//(i+1)
    count = 0
    for j in range(1, m+1):
        count += ball[j*(i+1)-1]
    ball[i] = (a[i]%2)^(count%2)

print(sum(ball))
for i in range(n):
    if ball[i] == 1:
        print(i+1)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
Ao = list(map(int, input().split()))
A = list(sorted(Ao))
for j in range(M):
    B, C = map(int, input().split())
    for i in range(B):
        if A[i] < C:
            A.remove(A[i])
            A.insert(i,C)
    A = list(sorted(A))

print(sum(A))

Fixed submission:

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
D = []
for j in range(M):
    B, C = map(int, input().split())
    D.append((B,C))
#list is sorted by C in D
D = sorted(D, key = lambda x: x[1], reverse = True) 

i = 0
for j in range(M):
    b, c = D[j]
    for k in range(i, min(N, i+b)):
        if A[k] < c:
            A[k] = c
    i = i + b
print(sum(A))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
Ao = list(map(int, input().split()))
A = list(sorted(Ao))
for j in range(M):
    B, C = map(int, input().split())
    for i in range(B):
        if A[i] < C:
            A.remove(A[i])
            A.insert(i,C)
    A = list(sorted(A))

print(sum(A))

Fixed submission:

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
D = []
for j in range(M):
    B, C = map(int, input().split())
    D.append((B,C))
#list is sorted by C in D
D = sorted(D, key = lambda x: x[1], reverse = True) 

i = 0
for j in range(M):
    b, c = D[j]
    for k in range(i, min(N, i+b)):
        if A[k] < c:
            A[k] = c
    i = i + b
print(sum(A))
Buggy python submission (verdict: Time Limit Exceeded):
import math

r, g, b, n = map(int, input().split())
ball = [0, r, g, b]
count = 0

for i in range(n+1):
    for j in range(n+1):
        m = math.floor((n-i*r-j*g)/b)
        if i*r+j*g+m*b == n and m >= 0:
            count += 1
            
print(count)

Fixed submission:
r, g, b, n = map(int, input().split())
ball = [0, r, g, b]
dp = [[0] * 4 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n+1):
    for k in range(4):
        if k == 0:
            if i != 0:
                dp[i][k] = 0
        else:
            if i - ball[k] < 0:
                dp[i][k] = dp[i][k-1]
            else:
                dp[i][k] = dp[i-ball[k]][k] + dp[i][k-1]

print(dp[n][3])

Buggy python submission (verdict: Runtime Error):
r, g, b, n = map(int, input().split())
ball = [0, r, g, b]
count = 0

for i in range(n+1):
    for j in range(n+1):
        m = math.floor((n-i*r-j*g)/b)
        if i*r+j*g+m*b == n and m >= 0:
            count += 1
            #print(i, j, m)
print(count)

Fixed submission:
r, g, b, n = map(int, input().split())
ball = [0, r, g, b]
dp = [[0] * 4 for _ in range(n+1)]
dp[0][0] = 1

for i in range(n+1):
    for k in range(4):
        if k == 0:
            if i != 0:
                dp[i][k] = 0
        else:
            if i - ball[k] < 0:
                dp[i][k] = dp[i][k-1]
            else:
                dp[i][k] = dp[i-ball[k]][k] + dp[i][k-1]

print(dp[n][3])
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
 
L = [0]*(N+2)
R = [0]*(N+2)
 
import fractions
 
for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])
 
M = [fractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))

Fixed submission:
A, B, T = map(int,input().split())

print(int((T+0.5)//A * B))

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
G = []

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            G.append(gcd(A[i], A[j]))
            

print(max(G))

Fixed submission:
A, B, T = map(int,input().split())

print(int((T+0.5)//A * B))