Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

reached = []
pos = 0#indexで指定
while 1:
    if pos not in reached:
        reached.append(pos)
    else:
        break
    pos = A[pos]-1
#print(reached)

if 1 in reached:
    print(reached.index(1))
else:
    print(-1)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**6

reached = []
pos = 0#indexで指定
c = 0
while c <= INF:
    reached.append(pos)
    if pos == 1:
        break
    pos = A[pos]-1
    c += 1

if 1 in reached:
    print(reached.index(1))
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for _ in range(N)]

reached = []
pos = 0#indexで指定
while 1:
    if pos not in reached:
        reached.append(pos)
    else:
        break
    pos = A[pos]-1
#print(reached)

if 1 in reached:
    print(reached.index(1))
else:
    print(-1)

Fixed submission:
N = int(input())
A = [int(input()) for _ in range(N)]
INF = 10**6

reached = []
pos = 0#indexで指定
c = 0
while c <= INF:
    reached.append(pos)
    if pos == 1:
        break
    pos = A[pos]-1
    c += 1

if 1 in reached:
    print(reached.index(1))
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
ans = [str(a.index(i + 1) + 1) for i in range(n)]
print(" ".join(ans))


Fixed submission:
# https://atcoder.jp/contests/abc142/tasks/abc142_c
n = int(input())
a = list(map(int, input().split()))
#### TLE ####
# ans = [str(a.index(i + 1) + 1) for i in range(n)]
# print(" ".join(ans))

b = [" "] * n
for i in range(n):
    b[a[i]-1] = str(i+1)

print(" ".join(b))
Buggy python submission (verdict: Runtime Error):
    N=int(input())
    s = [''.join(sorted(input())) for _ in range(N)]
    from collections import Counter
    c = Counter(s)
    print(sum((x*(x-1))//2 for x in c.values()))

Fixed submission:
N = int(input())
s = [''.join(sorted(input())) for _ in range(N)]
from collections import Counter

c = Counter(s)
print(sum((x * (x - 1)) // 2 for x in c.values()))
Buggy python submission (verdict: Runtime Error):
b = input()
if b == "A":
    print "T"
elif b == "T":
    print "A"
if b == "C":
    print "G"
else:
    print "C"

Fixed submission:
b = raw_input()
if b == "A":
    print "T"
elif b == "T":
    print "A"
if b == "C":
    print "G"
elif b == "G":
    print "C"
Buggy python submission (verdict: Runtime Error):
n = int(raw_input())
if n == 1:
    print("Hello World")
elif n == 2:
	a = int(raw_input())
    b = int(raw_input())
    print a + b

Fixed submission:
N = input()
if N == 1:
    print "Hello World"
else:
    A = input()
    B = input()
    print A+B

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

Fixed submission:
N = input()
if N == 1:
    print "Hello World"
else:
    A = input()
    B = input()
    print A+B

Buggy python submission (verdict: Runtime Error):
n, a, b = map(int, raw_input().split())
if n == 1:
    print("Hello World")
elif n == 2:
    print a + b

Fixed submission:
N = input()
if N == 1:
    print "Hello World"
else:
    A = input()
    B = input()
    print A+B
Buggy python submission (verdict: Runtime Error):
a = input()
b = raw_input()
x = 0
for i in range(1,n):
    z = s[0:i]
    y = s[i:n]
    arr = []
    for l in y:
        for m in z:
            if l == m and l not in arr:
                arr.append(l)
    if len(arr) > x:
        x = len(arr)
print x

Fixed submission:
a = input()
b = raw_input()
x = 0
for i in range(1,a):
    z = b[0:i]
    y = b[i:a]
    arr = []
    for l in y:
        for m in z:
            if l == m and l not in arr:
                arr.append(l)
    if len(arr) > x:
        x = len(arr)
print x
Buggy python submission (verdict: Runtime Error):
s = raw_input()
if s[1] == s[2]:
    print"No"
elif s[1] == s[3]:
    print"No"
elif s[3] == s[2]:
    print"No" 
else:
    print"Yes"

Fixed submission:
s = raw_input()
if s[0] == s[1]:
    print"No"
elif s[0] == s[2]:
    print"No"
elif s[2] == s[1]:
    print"No"
else:
    print"Yes"
Buggy python submission (verdict: Runtime Error):
n = raw_input()
c = raw_input()
if n % 500 <= c:
    print "Yes"
else:
    print"No"

Fixed submission:
n = input()
c = input()
if n % 500 <= c:
    print "Yes"
else:
    print"No"
Buggy python submission (verdict: Runtime Error):
s = input()
if s == "a":
    print "vowel"
elif s == "e":
    print "vowel"
elif s == "i":
    print "vowel"
elif s == "0":
    print "vowel"
elif s == "u":
    print "vowel"
else:
    print "consonant"

Fixed submission:
s = raw_input()
if s == "a":
    print "vowel"
elif s == "e":
    print "vowel"
elif s == "i":
    print "vowel"
elif s == "o":
    print "vowel"
elif s == "u":
    print "vowel"
else:
    print "consonant"
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = str(input())
S = list(S)

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

S1, S2 = [], []
for i, s in enumerate(S):
    if i < (N/2):
        s1.append(s)
    else:
        s2.append(s)

s1, s2 = ' ', ' '
for s in S1:
    s1 += s

for s in S2:
    s2 += s

if s1 ==s2:
    print('Yes')
else:
    print('No')


Fixed submission:
N = int(input())
S = str(input())
S = list(S)

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

S1, S2 = [], []
for i, s in enumerate(S):
    if i < (N/2):
        S1.append(s)
    else:
        S2.append(s)

s1 = ' '
for s in S1:
    s1 += s

s2 = ' '
for s in S2:
    s2 += s

if s1 == s2:
    print('Yes')
else:
    print('No')

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = str(input())
S = list(S)

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

S1, S2 = [], []
for i, s enumerate(S):
    if i < (N/2):
        s1.append(s)
    else:
        s2.append(s)

s1, s2 = ' ', ' '
for s in S1:
    s1 += s

for s in S2:
    s2 += s

if s1 ==s2:
    print('Yes')
else:
    print('No')


Fixed submission:
N = int(input())
S = str(input())
S = list(S)

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

S1, S2 = [], []
for i, s in enumerate(S):
    if i < (N/2):
        S1.append(s)
    else:
        S2.append(s)

s1 = ' '
for s in S1:
    s1 += s

s2 = ' '
for s in S2:
    s2 += s

if s1 == s2:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Time Limit Exceeded):
N, K, Q = map(int, input().split())

acc_list = []
for i in range(Q):
    acc_list.append(int(input()))

point_dict = {}
for i in range(1, N+1):
    point_dict[i] = K

for a in acc_list:
    for key, valu in point_dict.items():
        if a != key:
            point_dict[key] = valu - 1

for key, valu in point_dict.items():
    if valu <= 0:
        print('No')
    elif valu > 0:
        print('Yes')


Fixed submission:
N, K, Q = map(int, input().split())

acc_list = []
for i in range(Q):
    acc_list.append(int(input()))

point_dict = {}
for i in range(1, N+1):
    point_dict[i] = 0

for a in acc_list:
    point_dict[a] += 1

for key, valu in point_dict.items():
    if (K - Q + valu) <= 0:
        print('No')
    elif (K - Q + valu) > 0:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
h, w = map(int, input().split())

List = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(1)
    List.append(l)

for i in range(h):
    del List[i]

for j in range(w):
    for i in range(len(List)):
        del List[i][j]

count = 0
for i in range(len(List)):
    count = count + len(List[i])

print(count)


Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())

List = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(0)
    List.append(l)

for i in range(h):
    for j in range(W):
        List[i][j] = 1
for i in range(H):
    for j in range(w):
        List[i][j] = 1

count = 0
for i in range(H):
    count += List[i].count(0)

print(count)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
h, w = map(int, input().split())

List = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(1)
    List.append(l)

for i in range(h):
    del List[0]

for j in range(w):
    for i in range(len(List)):
        del List[i][j]

count = 0
for i in range(len(List)):
    count = count + len(List[i])

print(count)


Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())

List = []
for i in range(H):
    l = []
    for j in range(W):
        l.append(0)
    List.append(l)

for i in range(h):
    for j in range(W):
        List[i][j] = 1
for i in range(H):
    for j in range(w):
        List[i][j] = 1

count = 0
for i in range(H):
    count += List[i].count(0)

print(count)
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

if gcd == 1:
    print(1)
    exit()

com_div = []
count = 1
while count < gcd:
    if gcd % count == 0:
        gcd = int(gcd / count)
        com_div.append(gcd)
        com_div.append(count)
    count += 1

com_div.sort(reverse=True)
print(com_div[K-1])


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

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

if gcd == 1:
    print(1)
    exit()

com_div = []
com_div.append(gcd)
for i in range(1,gcd):
    if gcd % i == 0:
        com_div.append(i)

com_div.sort(reverse=True)
print(com_div[K-1])

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

A, B, K = map(int, input().split())

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

com_div = []
count = 1
while count <= gcd:
    if gcd % count == 0:
        gcd = int(gcd / count)
        com_div.append(gcd)
        com_div.append(count)
    count += 1

com_div.sort(reverse=True)
print(com_div[K-1])


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

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

if gcd == 1:
    print(1)
    exit()

com_div = []
com_div.append(gcd)
for i in range(1,gcd):
    if gcd % i == 0:
        com_div.append(i)

com_div.sort(reverse=True)
print(com_div[K-1])

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

A, B, K = map(int, input().split())

gcd = int(math.gcd(A, B))

com_div = []
count = 1
while count <= gcd:
    if gcd % count == 0:
        gcd = int(gcd / count)
        com_div.append(gcd)
        com_div.append(count)
    count += 1

com_div.sort(reverse=True)
print(com_div[K-1])


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

if A >= B:
    L, S = A, B
if A < B:
    L, S = B, A

while L%S != 0:
    tmp = L;
    L = S;
    S = tmp%S;

gcd = int(S)

if gcd == 1:
    print(1)
    exit()

com_div = []
com_div.append(gcd)
for i in range(1,gcd):
    if gcd % i == 0:
        com_div.append(i)

com_div.sort(reverse=True)
print(com_div[K-1])
Buggy python submission (verdict: Runtime Error):
#coding: utf-8

A = int(input())
B = int(input())

if B%A == 0:
    print(A + B)
else:
    print(B - A)


Fixed submission:
#coding: utf-8

#A = int(input())
#B = int(input())
A, B = map(int, input().split())


if B%A == 0:
    print(A + B)
else:
    print(B - A)

Buggy python submission (verdict: Runtime Error):
#coding: utf-8

A = int(input())
B = int(input())

if B%A == 0:
    print(A + B)
else:
    print(B - A)


Fixed submission:
#coding: utf-8

#A = int(input())
#B = int(input())
A, B = map(int, input().split())


if B%A == 0:
    print(A + B)
else:
    print(B - A)
Buggy python submission (verdict: Runtime Error):
#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    #print(l)
    del l[0]
    #print(l)
    List.append(l)
    #print(List[i])
    #print(List)
    #print( )

    all_and = set(all_and) & set(List[i])
    all_and = List(all_and)

all_and_list = list(all_and)
#print(all_and)
#print(all_and_list)
print(len(all_and_list))


Fixed submission:
#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    del l[0]
    List.append(l)

    if i ==0:
        all_and = List[0]
    else:
        all_and = set(all_and) & set(List[i])
        all_and = list(all_and)

#print(all_and)
print(len(all_and))

Buggy python submission (verdict: Runtime Error):
#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    #print(l)
    del l[0]
    #print(l)
    List.append(l)
    #print(List[i])
    #print(List)
    #print( )

    all_and = set(all_and) & set(List[i])
    all_and = List(all_and)

all_and_list = list(all_and)
#print(all_and)
#print(all_and_list)
print(len(all_and_list))


Fixed submission:
#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    del l[0]
    List.append(l)

    if i ==0:
        all_and = List[0]
    else:
        all_and = set(all_and) & set(List[i])
        all_and = list(all_and)

#print(all_and)
print(len(all_and))

Buggy python submission (verdict: Runtime Error):
#coding: utf-8

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

List = []
for i in range(N):
    l = list(map(int, input().split()))
    #print(l)
    del l[0]
    #print(l)
    List.append(l)
    #print(List[i])
    #print(List)
    #print( )

    if i != 0:
        all_and = set(List[i-1]) & set(List[i])

all_and_list = list(all_and)
print(len(all_and_list))



Fixed submission:
#coding: utf-8

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

List = []
all_and = []
for i in range(N):
    l = list(map(int, input().split()))
    del l[0]
    List.append(l)

    if i ==0:
        all_and = List[0]
    else:
        all_and = set(all_and) & set(List[i])
        all_and = list(all_and)

#print(all_and)
print(len(all_and))
Buggy python submission (verdict: Runtime Error):
#cording: utf-8

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

ct = [], []
for i in range(N):
    ct.append(map(int, input().split()))

if len(c) != 0:
    print(min(c))
else:
    print('TEL')


Fixed submission:
#cording: utf-8

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

ct = []
for i in range(N):
    ct.append(list(map(int, input().split())))

c_min = 1001
for i in range(N):
    if (ct[i][1] <= T) and (ct[i][0] <= c_min):
        c_min = ct[i][0]

print(c_min if c_min != 1001 else 'TLE')

Buggy python submission (verdict: Runtime Error):
#cording: utf-8

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

ct = []
for i in range(N):
    ct.append(list(map(int, input().split())))

c_min = 1001
for i in range(N):
    if (ct[i][1] <= T) and (ct[i][0] <= c_min):
        c_min = ct[i][0]

print(minc if minc != 1001 else 'TLE')


Fixed submission:
#cording: utf-8

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

ct = []
for i in range(N):
    ct.append(list(map(int, input().split())))

c_min = 1001
for i in range(N):
    if (ct[i][1] <= T) and (ct[i][0] <= c_min):
        c_min = ct[i][0]

print(c_min if c_min != 1001 else 'TLE')
Buggy python submission (verdict: Runtime Error):
S = list(str(input()))

if S[0] == 'A':
    count_C = 0
    for ind in range(3-1, len(S)-1):
        if S[ind] == 'C':
            ind_C = ind
            count_C += 1
    if count_C == 1:
        del S[0]
        del S[ind_C]
        s = 'a'
        for i in S:
            s = s + i
        if S.islower():
            print('AC')
            exit()
print('WA')


Fixed submission:
S = list(str(input()))

if S[0] == 'A':
    count_C = 0
    for ind in range(3-1, len(S)-1):
        if S[ind] == 'C':
            ind_C = ind
            count_C += 1
    if count_C == 1:
        del S[0]
        del S[ind_C - 1]
        s = 'a'
        for i in S:
            s = s + i
        if s.islower():
            print('AC')
            exit()
print('WA')
Buggy python submission (verdict: Runtime Error):
s=input()
s_=list(s)
i=0
while i<=len(s_)-2:
    if s_[i]!=s_[i+1]:
        del s_[i:i+2]
        i=i-1
    else:
        i+=1
print(len(s)-len(s_))

Fixed submission:
s=input()
s_=list(s)
s0=s_.count("0")
s1=s_.count("1")
print(len(s)-abs(s0-s1))
Buggy python submission (verdict: Runtime Error):
n,m=list(map(int,input().split(" ")))
list_x=list(map(int,input().split(" ")))

list_x.sort()
list_d=[]

if m<=n:
    print(0)
else:
    i=0
    while i<=m-2:
        list_d.append(list_x[i+1]-list_x[i])
        i+=1
    list_d.sort()
    print(sum(list_d[0:m-n:1]))

Fixed submission:
t,x=list(map(int,input().split(" ")))
print(t/x)
Buggy python submission (verdict: Runtime Error):
n=int(input())
for count in range(10):
    if 100*count+10*count+count>n-1:
        input(100*count+10*count+count)
        break
    else:
        pass

Fixed submission:
n=int(input())
for count in range(10):
    if 100*count+10*count+count>n-1:
        print(100*count+10*count+count)
        break
    else:
        pass
Buggy python submission (verdict: Runtime Error):
def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return math.sqrt(l2_norm)

N = int(input())
point = []
for i in range(N):
    a,b = map(int,input().split())
    point.append([a, b])
    
res = []
for a in itertools.permutations(range(N)):
    distance = 0
    for i in range(N-1):
        distance += calculate_distance(point[i], point[i+1])
    res.append(distance)
np.mean(res)

Fixed submission:
import itertools

def calculate_distance(x1, x2):
    l2_norm = (x1[0] - x2[0])**2 + (x1[1] - x2[1])**2
    return l2_norm**(1/2)

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

distance = 0
M = 0
for a in itertools.permutations(range(N)):
  M += 1
  
  for i in range(N-1):
        start, end = a[i], a[i+1]
        distance += calculate_distance(point[start], point[end])
print(distance/M)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

memo = [-1] * (n + 1)
memo[0] = 1
memo[1] = 1
for i in range(m):
  memo[int(input())] = 0

def fib(x):
  if memo[x] == -1:
    memo[x] = fib(x-1) + fib(x-2)
  return memo[x]

print(fib(n) % 1000000007)


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

memo = [-1] * (n + 1)
memo[0] = 1
memo[1] = 1
for i in range(m):
  memo[int(input())] = 0

def fib(x):
  if memo[x] == -1:
    memo[x] = fib(x-1) + fib(x-2)
  return memo[x]

def fib2(x):
  if x <= 1:
    return memo[x]
  else:
    for i in range(x - 1):
      if memo[i + 2] == 0:
        continue
      memo[i + 2] = memo[i] + memo[i + 1]
    return memo[x]

# print(fib2(n))
# print(memo)
print(fib2(n) % 1000000007)

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

memo = [-1] * (n + 1)
memo[0] = 1
memo[1] = 1
for i in range(m):
  memo[int(input())] = 0

def fib(x):
  if memo[x] > -1:
    return memo[x]
  else:
    memo[x] = fib(x-1) + fib(x-2)
    return memo[x]

# print(fib(n))
# print(memo)
print(fib(n) % 1000000007)


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

memo = [-1] * (n + 1)
memo[0] = 1
memo[1] = 1
for i in range(m):
  memo[int(input())] = 0

def fib(x):
  if memo[x] == -1:
    memo[x] = fib(x-1) + fib(x-2)
  return memo[x]

def fib2(x):
  if x <= 1:
    return memo[x]
  else:
    for i in range(x - 1):
      if memo[i + 2] == 0:
        continue
      memo[i + 2] = memo[i] + memo[i + 1]
    return memo[x]

# print(fib2(n))
# print(memo)
print(fib2(n) % 1000000007)

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

memo = [-1] * (n + 1)
memo[0] = 1
memo[1] = 1
for i in range(m):
  memo[int(input())] = 0

def fib(x):
  if memo[x] == 0:
    return 0
  if memo[x] > 0:
    return memo[x]
  else:
    memo[x] = fib(x-1) + fib(x-2)
    return memo[x]

# print(fib(n))
# print(memo)
print(fib(n) % 1000000007)


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

memo = [-1] * (n + 1)
memo[0] = 1
memo[1] = 1
for i in range(m):
  memo[int(input())] = 0

def fib(x):
  if memo[x] == -1:
    memo[x] = fib(x-1) + fib(x-2)
  return memo[x]

def fib2(x):
  if x <= 1:
    return memo[x]
  else:
    for i in range(x - 1):
      if memo[i + 2] == 0:
        continue
      memo[i + 2] = memo[i] + memo[i + 1]
    return memo[x]

# print(fib2(n))
# print(memo)
print(fib2(n) % 1000000007)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = list(map(int, input().split()))
sum = 0

for i in range(m):
  b, c = map(int, input().split())
  a += (b * [c])

a.sort()
l = len(a)
for i in range(l-n, l):
  sum += a[i]

print(sum)

Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = []

for i in range(n):
  s.append((a[i], 1))

for _ in range(m):
  b, c = map(int, input().split())
  s.append((c, b))
#  for j in range(b):
#    a.append(c)

s.sort(reverse=True)
idx = 0
sum = 0
for i in range(n):
  if idx + s[i][1] > n:
    sum += s[i][0] * (n-idx)
    break

  sum += s[i][0] * s[i][1]
  idx += s[i][1]


# for i in range(l-n, l):
#  sum += a[i]

print(sum)

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

for i in range(m):
  b, c = map(int, input().split())
  for j in range(b):
    a.append(c)

a.sort()
l = len(a)
for i in range(l-n, l):
  sum += a[i]

print(sum)



Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = []

for i in range(n):
  s.append((a[i], 1))

for _ in range(m):
  b, c = map(int, input().split())
  s.append((c, b))
#  for j in range(b):
#    a.append(c)

s.sort(reverse=True)
idx = 0
sum = 0
for i in range(n):
  if idx + s[i][1] > n:
    sum += s[i][0] * (n-idx)
    break

  sum += s[i][0] * s[i][1]
  idx += s[i][1]


# for i in range(l-n, l):
#  sum += a[i]

print(sum)

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

for i in range(m):
  b, c = map(int, input().split())
  for j in range(b):
    a.append(c)

a.sort()
for i in a[len(a)-n:len(a)]:
  sum += i

print(sum)


Fixed submission:
n, m = map(int, input().split())
a = list(map(int, input().split()))
s = []

for i in range(n):
  s.append((a[i], 1))

for _ in range(m):
  b, c = map(int, input().split())
  s.append((c, b))
#  for j in range(b):
#    a.append(c)

s.sort(reverse=True)
idx = 0
sum = 0
for i in range(n):
  if idx + s[i][1] > n:
    sum += s[i][0] * (n-idx)
    break

  sum += s[i][0] * s[i][1]
  idx += s[i][1]


# for i in range(l-n, l):
#  sum += a[i]

print(sum)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if a<=8 and b<=8:
    print('Yay!')
else:
    print(':(')

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

Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())
if a<=8 and b<=8:
    print('Yay!')
else:
    print(':(')

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