Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
x = []
for i in range(n):
    X,L = map(int, input().split())
    x.append([X-L,X+L])
x.sort()
y = [0]*n
ans = 0
for i in range(n-2):
    if x[i][1]>x[i+2][0]:
        ans +=1
        y[i] = -1
    elif x[i][1]>x[i+1][0] and y[i]==0:
        y[i] +=1
        y[i+1] +=1
    elif x[i][1]>x[i+1][0] and y[i]==1:
        ans +=1
        y[i] = -1
        y[i-1] = 0
        continue
if x[-1][0]<x[n-3][1]:
    y[-1] = -1
    ans +=1
elif x[-1][0]<x[n-2][1]:
    y[-1] +=1
    y[n-2] +=1

for i in range(n-1):
    if y[i]<=0:
        continue
    else:
        y[i] = 0
        y[i+1] = 0
        ans +=1
print(n-ans)

 

Fixed submission:
n = int(input())
x = []
for i in range(n):
    X,L = map(int, input().split())
    x.append([X-L,X+L])
x.sort(key=lambda x:x[0])
ans = n
tmp = x[0][1]
for i in range(1,n):
    if tmp>x[i][0]:
        ans -=1
        tmp = min(tmp,x[i][1])
    else:
        tmp = x[i][1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
INF = 1e9
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]


def bfs(sy, sx, gy, gx):
    if wall[sy][sx]=="#":
        return 0
    que = deque()
    que.append((sy, sx))
    d[sy][sx] = 0
    m = 0
    while len(que) > 0:
        y, x = que.popleft()

        for i in range(4):
            ny = y+dy[i]
            nx = x+dx[i]
            if 0 <= ny and ny < h and 0 <= nx and nx < w and wall[ny][nx] != "#" and d[ny][nx] <0:
                que.append((ny, nx))
                d[ny][nx] = d[y][x]+1
    return d[gy][gx]


h, w = map(int, input().split())
wall = [list(input()) for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        for k in range(h):
            for l in range(w):
                d = [[-1]*w for _ in range(h)]
                a = bfs(i, j, k, l)
                ans = max(ans, a)
print(ans)

Fixed submission:
from collections import deque
INF = 1e9
dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]


def bfs(sy, sx):
    if wall[sy][sx]=="#":
        return 0
    que = deque()
    que.append((sy, sx))
    d[sy][sx] = 0
    m = 0
    while len(que) > 0:
        y, x = que.popleft()

        for i in range(4):
            ny = y+dy[i]
            nx = x+dx[i]
            if 0 <= ny and ny < h and 0 <= nx and nx < w and wall[ny][nx] != "#" and d[ny][nx] == INF:
                que.append((ny, nx))
                d[ny][nx] = d[y][x]+1
                m = max(d[ny][nx],m)
    return m


h, w = map(int, input().split())
wall = [list(input()) for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        d = [[INF]*w for _ in range(h)]
        a = bfs(i, j)
        ans = max(ans, a)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9) + 7

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
b = [1]*(n+1)
for i in range(1,n+1):
    b[i] = b[i-1]*i
for i in range(k+1):
    if n-i-1<k-1:
        break
    c = b[n-1-i]//(b[k-1]*b[n-i-k])
    ans += c*a[n-1-i]
    ans -= c*a[i]
    ans = ans%MOD
print(ans)

Fixed submission:
import math
n_ = 10**5 + 3
mod = 10**9+7
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
count=0
for i in range(N-K+1):
    count=(count+((A[i]-A[N-1-i])*nCr(N-i-1,K-1)))%(10**9+7)
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9)+7
#nCr
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

n,k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ans = 0
for i in range(k+1):
    if n-1-i<k-1:
        break
    b = cmb(n-1-i,k-1)
    ans += b*a[n-1-i]
    ans -= b*a[i]
    ans = ans%MOD
print(ans)

Fixed submission:
import math
n_ = 10**5 + 3
mod = 10**9+7
fun = [1]*(n_+1)
for i in range(1,n_+1):
    fun[i] = fun[i-1]*i%mod
rev = [1]*(n_+1)
rev[n_] = pow(fun[n_],mod-2,mod)
for i in range(n_-1,0,-1):
    rev[i] = rev[i+1]*(i+1)%mod
def nCr(n,r):
    if n <= 0 or r < 0 or r > n: return 0
    return fun[n]*rev[r]%mod*rev[n-r]%mod
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort(reverse=True)
count=0
for i in range(N-K+1):
    count=(count+((A[i]-A[N-1-i])*nCr(N-i-1,K-1)))%(10**9+7)
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)

n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
for i in range(n):
    if (x//a[i])%2==0:
        print(0)
        exit()
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)

Fixed submission:
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)

n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
    if x>m:
        print(0)
        exit()
for i in range(n):
    if (x//a[i])%2==0:
        print(0)
        exit()
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)

n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
for i in range(n):
    if (x//a[i])%2==0:
        print(0)
        exit()
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)

Fixed submission:
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)

n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
    if x>m:
        print(0)
        exit()
for i in range(n):
    if (x//a[i])%2==0:
        print(0)
        exit()
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)

Buggy python submission (verdict: Runtime Error):
import math

def lcm(p,q):
    return p*q//math.gcd(p,q)
n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)


Fixed submission:
from fractions import gcd
def lcm(p,q):
    return p*q//gcd(p,q)

n,m = map(int, input().split())
a = list(map(int, input().split()))
x = 1
for i in range(n):
    a[i] = a[i]//2
    x = lcm(x,a[i])
    if x>m:
        print(0)
        exit()
for i in range(n):
    if (x//a[i])%2==0:
        print(0)
        exit()
p = m//x
if p%2==0:
    ans = p//2
else:
    ans = p//2 +1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

a,b = map(int, input().split())
ans = a*b
ans = ans//math.gcd(a,b)
print(ans)

Fixed submission:
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

a,b = map(int, input().split())
ans = a*b
c = gcd(a,b)
print(ans//c)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)

Fixed submission:
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
p = [0]*(n+10)
ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        b = a[i]^a[j]
        b = b%MOD
        ans +=b
print(ans%MOD)

Fixed submission:
MOD = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
ans = 0
for b in range(60)[::-1]:
    ans <<=1
    c = sum(a[i]>>b & 1 for i in range(n))
    ans = (ans + c*(n-c))%MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
INF = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
col = [0,0,0]
ans = 1
for i in range(n):
        col[i] +=1
        continue
    c = set(col)
    m = 0
    for j in range(3):
        if c==col[j]:
            m +=1
    ans *= m
    
    for j in range(3):
        if i==col[j]:
            col[j] +=1
            break
        else:
            continue
    ans = ans%INF

print(ans)

Fixed submission:
n = int(input())
s = str(input())
ans = 0
for i in range(10):
    for j in range(10):
        for k in range(10):
            i_pos = s.find(str(i))

            if i_pos == -1:
                continue

            j_pos = s.find(str(j), i_pos+1)

            if j_pos == -1:
                continue

            k_pos = s.find(str(k), j_pos+1)

            if k_pos == -1:
                continue

            ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
INF = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
col = [0,0,0]
ans = 1
for i in range(n):
        col[i] +=1
        continue
    c = set(col)
    m = 0
    for j in range(3):
        if c==col[j]:
            m +=1
    ans *= m
    
    for j in range(3):
        if i==col[j]:
            col[j] +=1
            break
        else:
            continue
    ans = ans%INF

print(ans)

Fixed submission:
INF = int(1e9) + 7

n = int(input())
a = list(map(int, input().split()))
col = [0, 0, 0]
ans = 1
for i in range(n):
    m = 0
    for j in range(3):
        if a[i] ==col[j]:
            m = col.count(a[i])
    ans *= m
    
    for j in range(3):
        if a[i]==col[j]:
            col[j] +=1
            break
        else:
            continue
    ans = ans%INF

print(ans)
Buggy python submission (verdict: Runtime Error):
x,y = map(int, input().split())
ans = 0
d = [300000,200000,100000]
if 1<=x and x<=3:
    ans += d[x-1]

if 1<=y and y<=3:
    ans += d[x-1]

if x==y and x==1:
    ans += 400000

print(ans)

Fixed submission:
x,y = map(int, input().split())
ans = 0
d = [300000,200000,100000]
if 1<=x and x<=3:
    ans += d[x-1]

if 1<=y and y<=3:
    ans += d[y-1]

if x==y and x==1:
    ans += 400000

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
def factorize(n):
    b = 2
    fct = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            fct.append(b)
        b = b + 1
    if n > 1:
        fct.append(n)
    return fct

a = factorize(n)
m = len(a)
ans = 0
if m==1:
    print(a[0]-1)
elif m==2:
    print(a[0]+a[1]-2)
elif m==3:
    z = a[0]*a[1]
    print(z+a[2]-2)
else:
    ans = 10**12
    for i in range(2**m):
        x = 1
        y = 1
        for j in range(m):
            if ((i>>j)&1):
                x *=a[j]
            else:
                y*=a[j]
        ans = min(ans, x+y-2)
    print(ans)

Fixed submission:
import math

INF = 1e12
n = int(input())
ans = INF
m = math.sqrt(n)
for i in range(1,math.ceil(m)+1):
    if n%i==0:
        j = n//i
        ans = min(ans, i+j-2)
    else:
        continue
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
length = 2010

n = int(input())
L = list(map(int, input().split()))
ans = 0
L.sort()
sum_1 = [ 0 for _ in range(length)]
for i in range(n):
    sum_1[L[i]]+=1
#棒の長さで累積和
for i in range(length-1):
    sum_1[i+1] +=sum_1[i]
for i in range(n-1):
    for j in range(i+1, n):
        a = abs(L[i]-L[j])
        b = L[i]+L[j]
        ans = ans + sum_1[b-1] - sum_1[a]

        if a<L[i] and L[i]<b:
            ans -=1
        
        if a<L[j] and L[j]<b:
            ans -=1
print(ans//3)

Fixed submission:
import bisect

n = int(input())
l = list(map(int, input().split()))
ans = 0
l.sort()
for i in range(n-1, -1, -1):
    a = l[i]
    for j in range(i-1, -1, -1):
        b = l[j]
        c = bisect.bisect_right(l, a-b, lo=0, hi=j)
        ans = ans + j-c
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(m):
    a[0] = a[0]//2
    if a[0]<a[1]:
        a.sort(reverse=True)
print(sum(a))

Fixed submission:
import heapq

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

a = [-i for i in list(map(int, input().split()))]
heapq.heapify(a)

for i in range(m):
    p = heapq.heappop(a)
    p = (-p)//2
    heapq.heappush(a, -p)
    
print(-sum(a))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
for i in range(m):
    a[0] = a[0]//2
    a.sort(reverse=True)
print(sum(a))

Fixed submission:
import heapq

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

a = [-i for i in list(map(int, input().split()))]
heapq.heapify(a)

for i in range(m):
    p = heapq.heappop(a)
    p = (-p)//2
    heapq.heappush(a, -p)
    
print(-sum(a))
Buggy python submission (verdict: Runtime Error):
n = int(input())
h = list(map(int, input().split()))
a = []
ans = 0
for i in range(1,n):
    if h[i-1]>=h[i]:
        ans+=1
    else:
        a.append(ans)
        ans=0
    if i==n-1:
        a.append(ans)
a.sort(reverse=True)
print(a[0])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
a = [0]
ans = 0
for i in range(1,n):
    if h[i-1]>=h[i]:
        ans+=1
    else:
        a.append(ans)
        ans=0
    if i==n-1:
        a.append(ans)
a.sort(reverse=True)
print(a[0])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = list(map(int, input().split()))
a = []
for i in range(n):
    ans = 0
    for j in range(i+1, n):
        if h[j-1]>=h[j]:
            ans+=1
        else:
            break
    a.append(ans)
    ans = 0
a.sort(reverse=True)
print(a[0])

Fixed submission:
n = int(input())
h = list(map(int, input().split()))
a = [0]
ans = 0
for i in range(1,n):
    if h[i-1]>=h[i]:
        ans+=1
    else:
        a.append(ans)
        ans=0
    if i==n-1:
        a.append(ans)
a.sort(reverse=True)
print(a[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ans=0
for i in range(n):
    if i==n-1:
        break
    else:
        ans+=i+1
print(ans)

Fixed submission:
n = int(input())
ans = int((n-1)*n//2)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,q = map(int, input().split())
ans = [0]*n
ki = [ [] for _ in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a -=1
    b -=1
    ki[a].append(b)

def ki_add(p,x):
    ans[p] += x
    for i in ki[p]:
        ki_add(i,x)

for i in range(q):
    p,x = map(int, input().split())
    p -=1
    ki_add(p,x)
print(*ans)

Fixed submission:
import heapq

N,Q = map(int, input().split())

node = [0]*N
edge = [[] for _ in range(N)]
color = [0]*N

for i in range(N-1):
    a,b = map(int, input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

for i in range(Q):
    p,x = map(int, input().split())
    node[p-1] += x

stack = [0]
while stack:
    s = stack.pop()
    color[s] = 1
    for t in edge[s]:
        if color[t]==0:
            stack.append(t)
            node[t] += node[s]
    color[s]=2

print(*node)
Buggy python submission (verdict: Time Limit Exceeded):
s = str(input())
ans = 0
n = len(s)
A = [s[-1]]
count=0
i = n-1
while i>=0:
    if i == n-1:
        i-=1
    else:
        if A[count]==s[i]:
            A.append(s[i]+s[i-1])
            i -=2
            count+=1
        elif A[count]!=s[i] and i>1:
            A.append(s[i])
            count+=1
            i -= 1
        elif i==1 and s[i]==s[i-1]:
            A.append(s[i]+s[i-1])
            i-=2
        elif i==1 and s[i]!=s[i-1]:
            A.append(s[i])
            A.append(s[i-1])
            i-=2
print(len(A))

Fixed submission:
s = str(input())
n = len(s)
ans = 1
count = 1
tmp = s[0]
while count < n:
    if s[count] == tmp:
        if count == n-1:
            ans -=1
        tmp = s[count:count+2]
        count +=2

    else:
        tmp = s[count]
        count +=1
    ans +=1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
A= [input() for i in range(N)]
ans = 0
for i in range(N):
    j = i+1
    a = collections.Counter(A[i])
    while j < N:
        b = collections.Counter(A[j])
        if a==b:
            ans +=1
        j+=1
print(ans)

Fixed submission:
n =int(input())

S=[]
ans = 0
count=1

for i in range(n):
    tmp=input()
    S.append("".join(sorted(tmp)))

S.sort()

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count+=1
    else:
        ans+=count*(count-1)/2
        count=1

ans+=count*(count-1)/2

print(int(ans))

Buggy python submission (verdict: Time Limit Exceeded):
import collections
N = int(input())
A= [input() for i in range(N)]
ans = 0
for i in range(N):
    j = i+1
    a = collections.Counter(A[i])
    while j < N:
        b = collections.Counter(A[j])
        if a==b:
            ans +=1
        j+=1
print(ans)

Fixed submission:
n =int(input())

S=[]
ans = 0
count=1

for i in range(n):
    tmp=input()
    S.append("".join(sorted(tmp)))

S.sort()

for i in range(len(S)-1):
    if S[i] == S[i+1]:
        count+=1
    else:
        ans+=count*(count-1)/2
        count=1

ans+=count*(count-1)/2

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

Fixed submission:
a, b, c=map(int,input().split())
x = min(a-b,c)
print(c-x)
Buggy python submission (verdict: Time Limit Exceeded):
import math 

s = int(input())
s_1 = math.sqrt(s)
s_1 = int(s_1)
a = []
for i in range(1, s_1+1):
    if s%i==0:
        a.append(i)
ans = [0,0,a[-1],0,a[-1],s//a[-1]]
print(*ans)

Fixed submission:
import math 
MOD = int(1e9)

s = int(input())
if s==1000000000000000000:
    ans = [0,0,MOD,0,0,MOD]
    print(*ans)
    exit()

ans = [0,0,MOD,1]
x,y = 0,0
y = s//MOD + 1
x = MOD - s%MOD
ans.append(x)
ans.append(y)
print(*ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
L = []
R = []
for i in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
ans = 0
for i in range(n+1):
    count = 0
    for j in range(m):
        if i>=L[j] and i <=R[j]:
            count+=1
        if count==m:
            ans +=1
print(ans)

Fixed submission:
n,m = map(int,input().split())
L = []
R = []
for i in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
L.sort(reverse=True)
R.sort()
ans =0
for i in range(n+1):
    if i >=L[0] and i <=R[0]:
        ans +=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A = list(map(int, input().split()))
for i in range(m):
    A.sort()
    b,c = map(int,input().split())
    for j in range(b):
        if A[j]<c:
            A[j]=c
        else:
            break
print(sum(A))


Fixed submission:
n,m = map(int,input().split())
A = list(map(int, input().split()))
BC = []
for i in range(m):
    b,c = map(int, input().split())
    BC.append([c,b])
A.sort()
BC=sorted(BC, key=lambda x :x[0])
BC.reverse()
ans = sum(A)
cnt=0
for i in range(m):
    for j in range(cnt,BC[i][1]+cnt):
        if BC[i][0]>A[j]:
            ans+=BC[i][0]-A[j]
            cnt+=1
            if j==n-1:
                print(ans)
                exit()
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(m):
    b,c = map(int,input().split())
    for j in range(b):
        if A[j]<c:
            A[j]=c
    A.sort()
print(sum(A))

Fixed submission:
n,m = map(int,input().split())
A = list(map(int, input().split()))
BC = []
for i in range(m):
    b,c = map(int, input().split())
    BC.append([c,b])
A.sort()
BC=sorted(BC, key=lambda x :x[0])
BC.reverse()
ans = sum(A)
cnt=0
for i in range(m):
    for j in range(cnt,BC[i][1]+cnt):
        if BC[i][0]>A[j]:
            ans+=BC[i][0]-A[j]
            cnt+=1
            if j==n-1:
                print(ans)
                exit()
        else:
            break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
A = list(map(int, input().split()))
A.sort()
for i in range(m):
    b,c = map(int,input().split())
    for j in range(b):
        if A[j]<c:
            A[j]=c
    A.sort()
print(sum(A))

Fixed submission:
n,m = map(int,input().split())
A = list(map(int, input().split()))
BC = []
for i in range(m):
    b,c = map(int, input().split())
    BC.append([c,b])
A.sort()
BC=sorted(BC, key=lambda x :x[0])
BC.reverse()
ans = sum(A)
cnt=0
for i in range(m):
    for j in range(cnt,BC[i][1]+cnt):
        if BC[i][0]>A[j]:
            ans+=BC[i][0]-A[j]
            cnt+=1
            if j==n-1:
                print(ans)
                exit()
        else:
            break
print(ans)
Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
s = str(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
print(s)

Fixed submission:
n,k = map(int, input().split())
s = list(input())
if s[k-1]=="A":
    s[k-1]="a"
elif s[k-1]=="B":
    s[k-1]="b"
else:
    s[k-1]="c"
print("".join(s))
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
c = s.count(".")
ans = c
for i in range(n):
    if s[i] =="#":
        c +=1
    else:
        c -=1
    ans = min(ans,m)
print(ans)

Fixed submission:
n = int(input())
s = input()
c = s.count(".")
ans = c
for i in range(n):
    if s[i] =="#":
        c +=1
    else:
        c -=1
    ans = min(ans,c)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,q = map(int, input().split())
s = str(input())
lr = [list(map(int, input().split())) for _ in range(q)]
ans = [0]*q
i = 0
while i<n-1:

    if s[i]=="A" and s[i+1]=="C":
        for j in range(q):
            if lr[j][0]-1<=i and lr[j][1]-2>=i:
                ans[j] = ans[j]+1
            else:
                continue
        i +=2
    elif s[i+1]=="A":
        i+=1
    else:
        i +=2

for i in range(q):
    print(ans[i])

Fixed submission:
n,q = map(int, input().split())
s = input()
t = [0]*(n+1)
for i in range(n):
    if s[i:i+2]=="AC":
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for i in range(q):
    l,r = map(int, input().split())
    print(t[r-1]-t[l-1])