Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
tbl=[[0]*(N+1) for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  tbl[a][b]=1
  tbl[b][a]=1            # グラフの行列を用いた表現
def dfs(s,visited):
  if len(visited)==N:
    return 1
  
  ans=0
  for i in range(1,N+1):
    if i==s: continue     #自己閉路は関係ない。
    if tbl[s][i]==1 and (i not in visited):
      visited.append(i)
      ans+=dfs(i,visited)
      visited.pop()　　　　　#dfsを考えているからiをpopする。
  return ans 

answer=dfs(1,[1,])
print(answer)
      

Fixed submission:
N,M=map(int,input().split())
tbl=[[0]*(N+1) for _ in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  tbl[a][b]=1
  tbl[b][a]=1            # グラフの行列を用いた表現
def dfs(s,visited):
  if len(visited)==N:
    return 1
  
  ans=0
  for i in range(1,N+1):
    if i==s: continue
    if tbl[s][i]==1 and (i not in visited):
      visited.append(i)
      ans+=dfs(i,visited)
      visited.pop()
  return ans 

answer=dfs(1,[1,])
print(answer)
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
ans=0
l=[i for i in range(K+1)]
for x in range(K+1):
  for y in range(K+1):
    if (S-x-y in l)==True:
      ans+=1
print(ans)

Fixed submission:
K,S=map(int,input().split())
ans=0
for x in range(K+1):
  for y in range(K+1):
    if 0<=S-x-y<=K:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
ans=0
for z in range(0,K+1):
  for y in range(0,z+1):
    for x in range(0,y+1):
      if x+y+z==S:
        if x==y==z:
          ans+=1
        elif x!=y!=z:
          ans+=6
        else:
          ans+=3
print(ans)



Fixed submission:
K,S=map(int,input().split())
ans=0
for x in range(K+1):
  for y in range(K+1):
    if 0<=S-x-y<=K:
      ans+=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
ans=0
for x in range(0,K+1):
  for y in range(0,K+1):
    for z in range(0,K+1):
      if x+y+z==S:
        ans+=1
print(ans)

Fixed submission:
K,S=map(int,input().split())
ans=0
for x in range(K+1):
  for y in range(K+1):
    if 0<=S-x-y<=K:
      ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]

N = getInt()
A = getIntList()
B = getIntList()
sum = 0
sum += min(A[0],B[0])
sum += min(A[1],B[0]-min(A[0],B[0]))
for i in range(N-1):
    sum += min(A[i+1],B[i+1])
    sum += min(A[i+2],B[i+1]-min(A[i+1],B[i+1]))
print(sum)

Fixed submission:
def getIntList(): return [int(x) for x in input().split()]

x = getIntList()
if((x[0]+x[1])%2==0):
    print(int((x[0]+x[1])/2))
else:
    print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
S = int(input())
K = int(input())

lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst[0])
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

Fixed submission:
S = int(input())
K = int(input())

lst = [0]*100
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst)
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

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

lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst[0])
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

Fixed submission:
S = int(input())
K = int(input())

lst = [0]*100
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst)
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

Buggy python submission (verdict: Runtime Error):
S = input()
K = input()

lst = []
i = int(S)
while i > 0:
    lst.append(i%10)
    i //= 10 # 必須
lst.reverse()
print(lst[0])
if K == 1:
    print(lst[0])
else:
    if lst[0] == 1:
        print(lst[1])
    else:
        print(lst[0])

Fixed submission:
S = int(input())
K = int(input())

lst = [0]*100
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst)
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])
Buggy python submission (verdict: Runtime Error):
a, b = input().split(" ")
a = int(a)
b = int(b)

if a%2 + b%2)==2:
    print("Odd")
else:
    print("Even")

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

if (a%2 + b%2)==2:
    print("Odd")
else:
    print("Even")
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from random import *

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

p = 1000000000 + 7

n = readln()[0]
f = [0 for i in range(0,n+1)]
f[1] = n
f[2] = n * n
s = f[:]
s[2] = f[1] + f[2]
for i in range(3,n+1):
    f[i] = f[i-1] + (n - 1) * (n - 1)
    f[i] = f[i] + s[i - 3] + (n - i + 2)
    f[i] = f[i] % p
    s[i] = s[i - 1] + f[i]
    s[i] = s[i] % p
print(f[n])


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from random import *

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

p = 1000000000 + 7

n = readln()[0]
f = [0 for i in range(0,n+10)]
f[1] = n
f[2] = n * n
s = f[:]
s[2] = f[1] + f[2]
for i in range(3,n+1):
    f[i] = f[i-1] + (n - 1) * (n - 1)
    f[i] = f[i] + s[i - 3] + (n - i + 2)
    f[i] = f[i] % p
    s[i] = s[i - 1] + f[i]
    s[i] = s[i] % p
print(f[n])
Buggy python submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from fractions import gcd

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

def calc(x,line):
    if line == 0:
        for l in v[x]:
            if e[l][0] == x: son = e[l][1]
            else: son = e[l][0]
            if a[son-1] < a[x-1] and calc(son,l) == -1:
                return 1
        return -1
    else:
        if e[line][0] == x: y = 0
        else: y = 1
        if f[x][y] != 0: return f[x][y]
        if len(v[x]) == 1:
            f[x][y] = -1
            return -1
        for l in v[x]:
            if l != line:
                if e[l][0] == x: son = e[l][1]
                else: son = e[l][0]
                if a[son-1] < a[x-1] and calc(son,l) == -1:
                    f[x][y] = 1
                    return 1
        f[x][y] = -1
        return -1

n = int(input())
v = [set([]) for i in range(0,n+1)]
e = [0 for i in range(0,n)]
a = readln()
for i in range(1,n):
    s = readln()
    v[s[0]].add(i)
    v[s[1]].add(i)
    e[i] = s

f = [[0,0] for i in range(0,n)]
ans = []
for i in range(1,n+1):
    if calc(i,0) == 1:
        ans.append(i)
ans = list(map(str,ans))
print(' '.join(ans))


Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from fractions import gcd

def readln():
    _res = list(map(int,str(input()).split(' ')))
    return _res

def calc(x,line):
    if line == 0:
        for l in v[x]:
            if e[l][0] == x: son = e[l][1]
            else: son = e[l][0]
            if a[son-1] < a[x-1] and calc(son,l) == -1:
                return 1
        return -1
    else:
        if e[line][0] == x: y = 0
        else: y = 1
        if f[line][y] != 0: return f[line][y]
        for l in v[x]:
            if l != line:
                if e[l][0] == x: son = e[l][1]
                else: son = e[l][0]
                if a[son-1] < a[x-1] and calc(son,l) == -1:
                    f[line][y] = 1
                    return 1
        f[line][y] = -1
        return -1

n = int(input())
v = [set([]) for i in range(0,n+1)]
e = [0 for i in range(0,n)]
a = readln()
for i in range(1,n):
    s = readln()
    v[s[0]].add(i)
    v[s[1]].add(i)
    e[i] = s

f = [[0,0] for i in range(0,n)]
ans = []
for i in range(1,n+1):
    if calc(i,0) == 1:
        ans.append(i)
ans = list(map(str,ans))
print(' '.join(ans))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = input().split()

for i in range(len(a)):
    a[i] = int(a[i])

x = 0
y = 0

operations = []

for i in range(n-2):
    a_sorted = sorted(a)
    x = a_sorted[0]
    y = a_sorted[1]

    a.remove(x)
    a.remove(y)
    a.append(x-y)
    operations.append(str(x) + " " + str(y))
a_sorted = sorted(a)
a_sorted_reverse = sorted(a_sorted, reverse=True)
x = a_sorted_reverse[0]
a_sorted_reverse.remove(x)
a_sorted = sorted(a_sorted_reverse)
y = a_sorted[0]
operations.append(str(x) + " " + str(y))


a.remove(x)
if y in a:
    a.remove(y)
a.append(x-y)

print(sorted(a, reverse=True)[0])
for i in operations:
    print(i)


Fixed submission:

input_data = input()
n,  k = input_data.split()

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

i  = n - k
max = i + 1
min = 1

if k == 1:
    print(0)
else:
    print(max - min)

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

for i in range(len(a)):
    a[i] = int(a[i])

x = 0
y = 0

operations = []

for i in range(n-2):
    a_sorted = sorted(a)
    x = a_sorted[0]
    y = a_sorted[1]

    a.remove(x)
    a.remove(y)
    a.append(x-y)
    operations.append(str(x) + " " + str(y))

a_sorted_reverse = sorted(a_sorted, reverse=True)
x = a_sorted_reverse[0]
a.remove(x)
y = sorted(a)[0]
operations.append(str(x) + " " + str(y))


a.remove(x)
if y in a:
    a.remove(y)
a.append(x-y)

print(sorted(a, reverse=True)[0])
for i in operations:
    print(i)


Fixed submission:

input_data = input()
n,  k = input_data.split()

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

i  = n - k
max = i + 1
min = 1

if k == 1:
    print(0)
else:
    print(max - min)
Buggy python submission (verdict: Runtime Error):
C:\acm\python\python.exe C:/acm/py/44.py
3
5 6 3 8
5 100 8
22
2
100 1 1
1 100
3
2
3 5 2
4 5
9


Fixed submission:
while True:
    try:
        sum=0
        n=eval(input())
        l1=list(map(int,input().split()))
        l2=list(map(int,input().split()))
        for i in range(n):
            ss=1
            if(l2[i]-l1[i]>0):
                s=l2[i]-l1[i]
                if l1[i+1]-s<0:
                    sum+=l1[i+1]
                    l1[i+1]=0
                else:
                    l1[i+1]-=s
                    sum+=s
                    sum+=l1[i]
                    ss=0
                if(ss!=0):sum+=l1[i]

            elif(l2[i]-l1[i]<=0):
                sum+=l2[i]
        print(sum)
    except:break
Buggy python submission (verdict: Runtime Error):
t=input():
print("Bad") if ((t[0]==t[1])or(t[1]==t[2])or(t[2]==t[3])) else print("Good")

Fixed submission:
t=input()
print("Bad") if (t[0]==t[1])or(t[1]==t[2])or(t[2]==t[3]) else print("Good")

Buggy python submission (verdict: Runtime Error):
t=input():
print("Bad") if (t[0]==t[1])or(t[1]==t[2])or(t[2]==t[3]) else print("Good")

Fixed submission:
t=input()
print("Bad") if (t[0]==t[1])or(t[1]==t[2])or(t[2]==t[3]) else print("Good")
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print("10"[1 if a<b else 2])

Fixed submission:
a,b=map(int,input().split())
print("10"[1 if a<b else 0:])
Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

temp=[[i+1] for i in range(n)]
for i in range(n-2,-1,-1):
    if len(temp[ab[i][1]-1]) >= 2:
        temp[ab[i][0]-1].extend(temp[ab[i][1]-1])
    else:
        temp[ab[i][0]-1].append(ab[i][1]) 


ans=[0 for i in range(n)]
for j in range(q):
    for _ in temp[px[j][0]-1]:
        ans[_-1]+=px[j][1]

print(" ".join(map(str,ans)))

Fixed submission:
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

parent=[0 for i in range(n)]
for i in range(n-1):
    parent[ab[i][1]-1]=ab[i][0]
ans=[0 for i in range(n)]
for i in range(q):
    ans[px[i][0]-1]+=px[i][1]
for i in range(1,n):
    if parent[i] != 0:
        ans[i]+=ans[parent[i]-1]


print(" ".join(map(str,ans)))

Buggy python submission (verdict: Time Limit Exceeded):
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

temp=[[i+1] for i in range(n)]
tempr=[]
check=[]
for i in range(n-1):
    temp[ab[i][0]-1].append(ab[i][1])
    tempr.append([ab[i][1],ab[i][0]])
    if i >= 1:
        for j in range(i):
            if ab[i][0] == tempr[j][0]:
                temp[tempr[j][1]-1].append(ab[i][1])

ans=[0 for i in range(n)]
for j in range(q):
    for _ in temp[px[j][0]-1]:
        ans[_-1]+=px[j][1]

print(" ".join(map(str,ans)))

Fixed submission:
n,q=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n-1)]
px=[list(map(int,input().split())) for i in range(q)]

parent=[0 for i in range(n)]
for i in range(n-1):
    parent[ab[i][1]-1]=ab[i][0]
ans=[0 for i in range(n)]
for i in range(q):
    ans[px[i][0]-1]+=px[i][1]
for i in range(1,n):
    if parent[i] != 0:
        ans[i]+=ans[parent[i]-1]


print(" ".join(map(str,ans)))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for i in range(n)]

std=[]
for i in range(n):
    std.append(sorted(s[i]))

cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        if std[i]==std[j]:
            cnt+=1

print(cnt)

Fixed submission:
import math

n=int(input())
s=[input() for i in range(n)]

std=[]
for i in range(n):
    std.append(sorted(s[i]))
stdx=[]
stdx=sorted(std)

cnt=0
k=1
for i in range(n-1):
    if stdx[i]==stdx[i+1]:
        k+=1
        if k>1 and i==n-2:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
    else:
        if k>1:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
            k=1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for i in range(n)]

std=[]
for i in range(n):
    std.append(sorted(s[i]))

cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        if std[i]==std[j]:
            cnt+=1

print(cnt)

Fixed submission:
import math

n=int(input())
s=[input() for i in range(n)]

std=[]
for i in range(n):
    std.append(sorted(s[i]))
stdx=[]
stdx=sorted(std)

cnt=0
k=1
for i in range(n-1):
    if stdx[i]==stdx[i+1]:
        k+=1
        if k>1 and i==n-2:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
    else:
        if k>1:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
            k=1

print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=[input() for i in range(n)]

ans=[[0 for i in range(26)] for j in range(n)]
check="abcdefghijklmnopqrstuvwxyz"

for j in range(n):
    for i in range(26):
        ans[j][i]=s[j].count(check[i])

cnt=0
for i in range(n-1):
    for j in range(i+1,n):
        if ans[i]==ans[j]:
            cnt+=1

print(cnt)

Fixed submission:
import math

n=int(input())
s=[input() for i in range(n)]

std=[]
for i in range(n):
    std.append(sorted(s[i]))
stdx=[]
stdx=sorted(std)

cnt=0
k=1
for i in range(n-1):
    if stdx[i]==stdx[i+1]:
        k+=1
        if k>1 and i==n-2:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
    else:
        if k>1:
            cnt+=math.factorial(k)//math.factorial(k-2)//math.factorial(2)
            k=1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
mod=10**9+7
l=len(s)

dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1
for i in range(l):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]%mod
    else:
        for k in range(13):
            dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
print(dp[-1][5]%mod)

Fixed submission:
s=input()
mod=10**9+7
l=len(s)

dp=[[0 for j in range(13)] for i in range(l+1)]
dp[0][0]=1
for i in range(l):
    if s[i] == "?":
        for j in range(10):
            for k in range(13):
                dp[i+1][(k*10+j)%13] += dp[i][k]%mod
    else:
        for k in range(13):
            dp[i+1][(k*10+int(s[i]))%13]+=dp[i][k]%mod
print(dp[-1][5]%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]
adic={}
for i in range(n):
    adic[i]=a[i]

temp=sorted(adic.items(),key=lambda x: x[1],reverse=True)
for i in range(n):
    if i != temp[0][0]:
        print(max(a))
    else:
        print(temp[1][1])


Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]

a_sort=sorted(a,reverse=True)

for i in range(n):
    if a_sort[0]==a[i]:
        print(a_sort[1])
    else:
        print(a_sort[0])

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[int(input()) for i in range(n)]

for i in range(n):
    b=a[:]
    del b[i]
    b.sort(reverse=True)
    print(b[0])



Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]

a_sort=sorted(a,reverse=True)

for i in range(n):
    if a_sort[0]==a[i]:
        print(a_sort[1])
    else:
        print(a_sort[0])
Buggy python submission (verdict: Runtime Error):
from math import factorial

n,k=map(int, input().split())
mod=10**9+7

#def combinations_count(n,r):
#    return factorial(n) // (factorial(n-r)*factorial(r))

def comb(m,r):
    if m < 0 or r < 0 or m < r: return 0
    if m==0 or r==0: return 1
    a=factorial(m)%mod
    b=factorial(r)%mod
    c=factorial(m-r)%mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))%mod

def power_func(a,b):
    if b == 0: return 1
    if b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    if b%2==1:
        return(a*power_func(a,b-1))%mod

ans=0
for i in range(1,k+1):
    temp=comb(n-k+1,i)
    temp2=(float(i)**(k-i))%mod
    print(int(temp*temp2)%mod)

Fixed submission:
from math import factorial

n,k=map(int, input().split())
mod=10**9+7

#def combinations_count(n,r):
#    return factorial(n) // (factorial(n-r)*factorial(r))

def comb(m,r):
    if m < 0 or r < 0 or m < r: return 0
    if m==0 or r==0: return 1
    a=factorial(m)%mod
    b=factorial(r)%mod
    c=factorial(m-r)%mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))%mod

def power_func(a,b):
    if b == 0: return 1
    if b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    if b%2==1:
        return(a*power_func(a,b-1))%mod

ans=0
for i in range(1,k+1):
    temp=comb(n-k+1,i)
    temp2=comb(k-1,i-1)
    print(int(temp*temp2)%mod)

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

n,k=map(int, input().split())
mod=10**9+7

def combinations_count(n,r):
    return factorial(n) // (factorial(n-r)*factorial(r))

ans=0
for i in range(1,k+1):
    ans =combinations_count(n-k+1,i)*(i**(k-i))%mod
    print(ans)

Fixed submission:
from math import factorial

n,k=map(int, input().split())
mod=10**9+7

#def combinations_count(n,r):
#    return factorial(n) // (factorial(n-r)*factorial(r))

def comb(m,r):
    if m < 0 or r < 0 or m < r: return 0
    if m==0 or r==0: return 1
    a=factorial(m)%mod
    b=factorial(r)%mod
    c=factorial(m-r)%mod
    return (a*power_func(b,mod-2)*power_func(c,mod-2))%mod

def power_func(a,b):
    if b == 0: return 1
    if b%2==0:
        d=power_func(a,b//2)
        return d*d %mod
    if b%2==1:
        return(a*power_func(a,b-1))%mod

ans=0
for i in range(1,k+1):
    temp=comb(n-k+1,i)
    temp2=comb(k-1,i-1)
    print(int(temp*temp2)%mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
x = list()
for i in range(m):
    temp = list(map(int, input().split()))
    tempall = set()
    for j in range(temp[0],temp[1]+1):
        tempall.add(j)
    x.append(tempall)

ans = set(x[0])
for i in range(m):
    ans = ans & x[i]

print(len(ans))

Fixed submission:
n, m = map(int, input().split())
l = [1,n]
for i in range(m):
    temp = list(map(int, input().split()))
    l[0] = max(l[0],temp[0])
    l[1] = min(l[1],temp[1])

print(int(max(l[1]-l[0]+1, 0)))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a)

bc = []
for i in range(m):
    temp = list(map(int, input().split()))
    bc.append(temp)

bc_sorted = sorted(bc, key = lambda x:x[1], reverse = True)
temp = 0
d=[]
for i in range(m):
    for j in range(bc_sorted[i][0]):
        d.append(bc_sorted[i][1])
        if len(d) ==n:
            break

for i in range(min(n,len(d))):
    a_sort[i] = max(a_sort[i],d[i])

print(int(sum(a_sort)))

Fixed submission:
n,m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a)

bc = []
for i in range(m):
    temp = list(map(int, input().split()))
    bc.append(temp)

bc_sorted = sorted(bc, key = lambda x:x[1], reverse = True)
temp = 0

for i in range(m):
    for j in range(temp,min(n,temp+bc_sorted[i][0])):
        if a_sort[j] < bc_sorted[i][1]:
            a_sort[j] = bc_sorted[i][1]
            temp += 1
        else:
            break

print(int(sum(a_sort)))

Buggy python submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a)

""" for i in range(m):
    temp = list(map(int, input().split()))
    for j in range(temp[0]):
        a_sort[j] = max(a_sort[j],temp[1])
    a_sort = sorted(a_sort)

print(sum(a_sort))
 """

bc = []
for i in range(m):
    temp = list(map(int, input().split()))
    bc.append(temp)

bc_sorted = sorted(bc, key = lambda x:x[1], reverse = True)

repl = [bc_sorted[0][1]]*bc_sorted[0][0]

for i in range(1,m):
    if bc_sorted[i-1][0] < bc_sorted[i][0]:
        for j in range(bc_sorted[i][0]-bc_sorted[i-1][0]):
            repl.append(bc_sorted[i][1])

for i in range(n-len(bc_sorted)):
    repl.append(0)

sum = 0
for i in range(n):
    sum = sum + max(repl[i],a_sort[i])

print(sum)


Fixed submission:
n,m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a)

bc = []
for i in range(m):
    temp = list(map(int, input().split()))
    bc.append(temp)

bc_sorted = sorted(bc, key = lambda x:x[1], reverse = True)
temp = 0

for i in range(m):
    for j in range(temp,min(n,temp+bc_sorted[i][0])):
        if a_sort[j] < bc_sorted[i][1]:
            a_sort[j] = bc_sorted[i][1]
            temp += 1
        else:
            break

print(int(sum(a_sort)))

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a)

for i in range(m):
    temp = list(map(int, input().split()))
    for j in range(temp[0]):
        a_sort[j] = max(a_sort[j],temp[1])
    a_sort = sorted(a_sort)

print(sum(a_sort))


Fixed submission:
n,m = map(int, input().split())
a = list(map(int, input().split()))
a_sort = sorted(a)

bc = []
for i in range(m):
    temp = list(map(int, input().split()))
    bc.append(temp)

bc_sorted = sorted(bc, key = lambda x:x[1], reverse = True)
temp = 0

for i in range(m):
    for j in range(temp,min(n,temp+bc_sorted[i][0])):
        if a_sort[j] < bc_sorted[i][1]:
            a_sort[j] = bc_sorted[i][1]
            temp += 1
        else:
            break

print(int(sum(a_sort)))
Buggy python submission (verdict: Time Limit Exceeded):
import copy

s = str(input())
s_origin = copy.copy(s)

while len(s) > 0:
    if "10" in s:
        s = str(s).replace("10","")
    elif "01" in s:
        s = str(s).replace("01","")
    else:
        break

print(int(len(s_origin) - len(s)))

Fixed submission:
s = str(input())

ct1 = s.count('1')
ct0 = s.count('0')

print(int(min(ct1,ct0)*2))