Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def silnia(n):
    c = n
    s = 1
    while c > 1:
        s = s*c
        c = c-1
    return s

class N_po_K:
    def __init__(self, modulo = 10**9+7): 
        self.modulo = modulo 
        
    def dwumian(self, N, K):
        if N < K: 
            return 0
        return silnia(N)//silnia(K)//silnia(N-K)%self.modulo

def min_max_sums(): 
    N, K = wczytaj_liste()
    A = wczytaj_liste()
    A.sort()
    suma_min = 0 
    suma_max = 0
    dwumianator = N_po_K()
    for i in range(N):
        suma_min += dwumianator.dwumian(N-i-1, K-1)*A[i]
        suma_max += dwumianator.dwumian(N-i-1, K-1)*A[-i-1]
    print((suma_max - suma_min)%(10**9+7))

min_max_sums()

Fixed submission:
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 


class N_po_K:
    def __init__(self, maxN, modulo = 10**9+7): 
        self.modulo = modulo
        self.silnie = [1]
        for i in range(1, maxN + 1):
            self.silnie.append(self.silnie[i - 1] * i % self.modulo)
        
    def dwumian(self, N, K):
        if N < K: 
            return 0
        return self.silnie[N] * pow(self.silnie[K], self.modulo - 2, self.modulo)\
                              * pow(self.silnie[N-K], self.modulo - 2, self.modulo) % self.modulo

def min_max_sums(): 
    N, K = wczytaj_liste()
    A = wczytaj_liste()
    A.sort()
    suma_min = 0 
    suma_max = 0
    dwumianator = N_po_K(N)
    for i in range(N):
        suma_min += dwumianator.dwumian(N-i-1, K-1)*A[i]
        suma_max += dwumianator.dwumian(N-i-1, K-1)*A[-i-1]
    print((suma_max - suma_min)%(10**9+7))

min_max_sums()
Buggy python submission (verdict: Runtime Error):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def B_strings(): 
    N = wczytaj_liste()[0]
    S = input()
    T = input()
    odp = []
    for i in range(N): 
        odp.append(S[i])
        odp.append(T[i])
    print(''.join(odp))

B_strings()

Fixed submission:
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def B_strings(): 
    N = wczytaj_liste()[0]
    wczytaj = input()
    S, T = wczytaj.split()
    odp = []
    for i in range(N): 
        odp.append(S[i])
        odp.append(T[i])
    print(''.join(odp))

B_strings()
Buggy python submission (verdict: Time Limit Exceeded):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def japonska_gierka(): 
    N = wczytaj_liste()[0]
    A = wczytaj_liste()
    X = 0
    Y = 0
    wynik = {}
    for dlugosc_kolejki in range(N+1):
        zabrano = N - dlugosc_kolejki
        for lewo in range(zabrano+1): 
            prawo = zabrano - lewo
            if dlugosc_kolejki == 0: 
                wynik[lewo,prawo] = 0 
            else:
                wynik[lewo,prawo] = max(A[lewo]-wynik[lewo+1, prawo], A[-prawo-1]-wynik[lewo,prawo+1])
    print(wynik[0,0])
    
japonska_gierka()

Fixed submission:
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def japonska_gierka(): 
    N = wczytaj_liste()[0]
    A = wczytaj_liste()
    X = 0
    Y = 0
    wynik = [[None for i in range(N+1)] for j in range(N+1)]
    for dlugosc_kolejki in range(N+1):
        zabrano = N - dlugosc_kolejki
        for lewo in range(zabrano+1): 
            prawo = zabrano - lewo
            if dlugosc_kolejki == 0: 
                wynik[lewo][prawo] = 0 
            else:
                wynik[lewo][prawo] = max(A[lewo]-wynik[lewo+1][prawo], A[-prawo-1]-wynik[lewo][prawo+1])
    print(wynik[0][0])
    
japonska_gierka()
Buggy python submission (verdict: Time Limit Exceeded):
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def potworny_Jan_Kanty():
    N = wczytaj_liste()[0]
    potwory = wczytaj_liste()
    wynik = {}
    for dlugosc_przedzialu in range(1,len(potwory)+1):
        for poczatek in range(len(potwory)-dlugosc_przedzialu+1): 
            koniec = dlugosc_przedzialu + poczatek
            if dlugosc_przedzialu == 1:
                wynik[poczatek,koniec] = 0
            else:
                odp = 10**18
                for i in range(1, dlugosc_przedzialu):
                    kandydat = wynik[poczatek+i,koniec]+wynik[poczatek, poczatek+i]
                    if kandydat < odp: 
                        odp = kandydat
                wynik[poczatek, koniec] = odp+sum(potwory[poczatek:koniec])
    print(wynik[0, N])
    
potworny_Jan_Kanty()

Fixed submission:
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def potworny_Jan_Kanty():
    N = wczytaj_liste()[0]
    potwory = wczytaj_liste()
    wynik = [[None for i in range(N+1)]for j in range(N+1)]
    for dlugosc_przedzialu in range(1,len(potwory)+1):
        for poczatek in range(len(potwory)-dlugosc_przedzialu+1): 
            koniec = dlugosc_przedzialu + poczatek
            if dlugosc_przedzialu == 1:
                wynik[poczatek][koniec] = 0
            else:
                odp = 10**18
                for i in range(1, dlugosc_przedzialu):
                    kandydat = wynik[poczatek+i][koniec]+wynik[poczatek][poczatek+i]
                    if kandydat < odp: 
                        odp = kandydat
                wynik[poczatek][koniec] = odp+sum(potwory[poczatek:koniec])
    print(wynik[0][N])
    
potworny_Jan_Kanty()
Buggy python submission (verdict: Runtime Error):
a,b,c = int(input().split())
if(a+b+c >= 22):
  print("bust")
else:
  print("win")

Fixed submission:
a,b,c = map(int, input().split())
if(a +b+c >= 22):
  print("bust")
else:
  print("win")
Buggy python submission (verdict: Runtime Error):
print(7 - ['SUN', 'MUN', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(input()))

Fixed submission:
print(7 - ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(input()))

Buggy python submission (verdict: Runtime Error):
l = ['SUN', 'MUN', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];print(len(l) - l.index(input()))

Fixed submission:
print(7 - ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'].index(input()))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
tree = []
diff = 10 ** 9
for n in range(N):
    tree.append(int(input()))
tree.sort()
for i in range(N - (K - 1)):
    print(tree[i], tree[i + 1], tree[i + 2])
    if tree[i + K - 1] - tree[i] < diff:
        diff = tree[i + K - 1] - tree[i]
print(diff)

Fixed submission:
N, K = map(int, input().split())
tree = [int(input()) for n in range(N)]
diff = 10 ** 9
tree.sort()
for i in range(N - (K - 1)):
    if tree[i] == tree[i + 1] == tree[i + 2]:
        diff = 0
        break
    elif tree[i + K - 1] - tree[i] < diff:
        diff = tree[i + K - 1] - tree[i]
print(diff)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = input().split()
if (k >= len(h)):
    h.clear()
else:
    for i in range(k):
        m = max(h)
        h.remove(m)
b = 0
sum(h)
print(b)

Fixed submission:
a, b = map(int, input().split())
c = a//b
if (a%b == 0):
    d = c
else :
    d = c+1
print(d)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
h = input().split()
if (k > len(h)):
    h.clear()
else:
    for i in range(k):
        m = max(h)
        h.remove(m)
b = 0
for i in range(len(h)):
    b += int(h[i])

print(b)

Fixed submission:
a, b = map(int, input().split())
c = a//b
if (a%b == 0):
    d = c
else :
    d = c+1
print(d)

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = input().split()
b = 0
def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n):
    b += int(a[i])
if (h > b):
    print("No")
else:
    print("Yes")

Fixed submission:
a, b = map(int, input().split())
c = a//b
if (a%b == 0):
    d = c
else :
    d = c+1
print(d)

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = input().split()
b = 0
def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n):
    b += int(a[i])
if (h > b or has_duplicates(a) or len(a) > n ):
    print("No")
else:
    print("Yes")

Fixed submission:
a, b = map(int, input().split())
c = a//b
if (a%b == 0):
    d = c
else :
    d = c+1
print(d)
Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = input().split()
b = 0
for i in range(n):
    b += int(a[i])
if (h < b and has_duplicates(a) and len(a)>n ):
    print("No")
else:
    print("Yes")


Fixed submission:
h, n = map(int, input().split())
a = input().split()
b = 0
def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n):
    b += int(a[i])
if (h > b ):
    print("No")
else:
    print("Yes")

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
a = input().split()
b = 0
for i in range(n):
    b += int(a[i])
if (h < b and has_duplicates(a)):
    print("No")
else:
    print("Yes")


Fixed submission:
h, n = map(int, input().split())
a = input().split()
b = 0
def has_duplicates(seq):
    return len(seq) != len(set(seq))

for i in range(n):
    b += int(a[i])
if (h > b ):
    print("No")
else:
    print("Yes")
Buggy python submission (verdict: Runtime Error):
h = int(input())

sum = [0] * (h+1)

#print(sum)

for i in range(1, h+1) :
    sum[i] = 2*sum[i//2] + 1

print(sum[h])

Fixed submission:
h = int(input())

count = 0
while h > 1 :
    h = h // 2
    count += 1

sum = 0
for i in range(count+1) :
    sum = sum + 2**i

print(sum)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np

N, Y = list(map(int, input().split()))

ans_x, ans_y, ans_z = -1, -1, -1

n_list = np.append([0], range(N+1))
n_list = np.append(n_list, [N])

#print(n_list)
#print(len(n_list))
#print(range(len(n_list)))
#print(range(10 ,len(n_list)))

for i in range(len(n_list)) :
  x = n_list[i]
  for j in range(i+1 ,len(n_list)) :
    y = n_list[j] - x
    z = N - x - y
    sum = 10000*x + 5000*y + 1000*z
    #print("tameshi : " + str(x) + " " + str(y) + " " + str(z))
    if sum == Y and x>=0 and y>=0 and z>=0 :
      print(str(x) + " " + str(y) + " " + str(z))
      sys.exit(0)

print(str(ans_x) + " " + str(ans_y) + " " + str(ans_z))

Fixed submission:
import sys
#import numpy as np

N, Y = list(map(int, input().split()))

ans_x, ans_y, ans_z = -1, -1, -1

#n_list = np.append([0], range(N+1))
#n_list = np.append(n_list, [N])

#print(n_list)
#print(len(n_list))
#print(range(len(n_list)))
#print(range(10 ,len(n_list)))

for i in range(N+1) :
  x = i
  #sum = 10000*x
  #if sum > Y :
  #  continue

  for j in range(N+1-x) :
    y = j
    z = N - x - y
    sum = 10000*x + 5000*y + 1000*z
    #print("tameshi : " + str(x) + " " + str(y) + " " + str(z))
    if sum == Y :
      ans_x=x
      ans_y=y
      ans_z=z

print(str(ans_x) + " " + str(ans_y) + " " + str(ans_z))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
a_ = list()

count=0
cont=1

#print(a)
#print(a[2])

while cont :
  for i in range(len(a)) :
    #print("for")
    #print(a[i])
    if a[i]%2 == 0 :
      a_.append(a[i]/2)
    else :
      cont=0
      break
  if cont==1 :
    #print("cont")
    #print(count)
    a=a_
    count += 1
  else :
    break

print(count)

Fixed submission:
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())))
#a_ = np.array()

count=0
cont=1

#print(a)
#print(a[2])

while cont :
  a_ = np.unique(a % 2)
  if a_[0]==0 and len(a_) == 1 :
    count += 1
  else :
    break

  a = a / 2

print(count)
Buggy python submission (verdict: Runtime Error):
def isdreame(s) :
    res = -1

    if len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "erase" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        res = isdreame(s[0:len(s)-5])
      else :
          res = 1

    elif len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "dream" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        res = isdreame(s[0:len(s)-5])
      else :
          res = 1

    elif len(s) - 6 >= 0 and s[len(s)-6:len(s)] == "eraser" :
      #print(s[0:len(s)-6])
      if len(s) - 6 > 0 :
        res = isdreame(s[0:len(s)-6])
      else :
          res = 1

    elif len(s) - 7 >= 0 and s[len(s)-7:len(s)] == "dreamer" :
      #print(s[0:len(s)-7])
      if len(s) - 7 > 0 :
        res = isdreame(s[0:len(s)-7])
      else :
          res = 1

    else :
        res = 0

    return res

s = input()
res = isdreame(s)

if res==1 :
    print("YES")
else :
    #print(res)
    print("NO")

Fixed submission:
s = input()
res = -1

while len(s) > 0 :

    if len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "erase" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        s = s[0:len(s)-5]
      else :
          res = 1
          s = s[0:len(s)-5]

    elif len(s) - 5 >= 0 and s[len(s)-5:len(s)] == "dream" :
      #print(s[0:len(s)-5])
      if len(s) - 5 > 0 :
        s = s[0:len(s)-5]
      else :
          res = 1
          s = s[0:len(s)-5]

    elif len(s) - 6 >= 0 and s[len(s)-6:len(s)] == "eraser" :
      #print(s[0:len(s)-6])
      if len(s) - 6 > 0 :
        s = s[0:len(s)-6]
      else :
          res = 1
          s = s[0:len(s)-6]

    elif len(s) - 7 >= 0 and s[len(s)-7:len(s)] == "dreamer" :
      #print(s[0:len(s)-7])
      if len(s) - 7 > 0 :
        s = s[0:len(s)-7]
      else :
          res = 1
          s = s[0:len(s)-7]

    else :
        res = 0
        s = ""


if res==1 :
    print("YES")
else :
    #print(res)
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
num=int(input())
line=input()
line=line.split()
count1=0
for i in range(num):
    num1=200000
    for j in range(i+1):
        if num1>=int(line[j]):
            num1=int(line[j])
    if num1==int(line[i]):
        count1+=1
print(count1)

Fixed submission:
num=int(input())
line=input()
line=line.split()
#b=list(map(int,input().split()))
count1=0
num1=200000
for i in range(num):
    if num1>=int(line[i]):
        num1=int(line[i])
        count1+=1
print(count1)

Buggy python submission (verdict: Time Limit Exceeded):
num=int(input())
line=input()
line=line.split()
count=0
count1=0
for i in range(num):
    num1=int(line[i])
    for j in range(i+1):
        if num1<=int(line[j]):
            count+=1
    if count == (i+1):
        count1+=1
    count=0
print(count1)

Fixed submission:
num=int(input())
line=input()
line=line.split()
#b=list(map(int,input().split()))
count1=0
num1=200000
for i in range(num):
    if num1>=int(line[i]):
        num1=int(line[i])
        count1+=1
print(count1)

Buggy python submission (verdict: Time Limit Exceeded):
num=int(input())
line=input()
line=line.split()
count=0
count1=0
for i in range(num):
    num1=int(line[i])
    for j in range(i+1):
        if num1<=int(line[j]):
            count+=1
    if count == (i+1):
        count1+=1
    count=0
print(count1)

Fixed submission:
num=int(input())
line=input()
line=line.split()
#b=list(map(int,input().split()))
count1=0
num1=200000
for i in range(num):
    if num1>=int(line[i]):
        num1=int(line[i])
        count1+=1
print(count1)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
print(A ^ B)

Fixed submission:
A = int(input())
B = int(input())
print(A ^ B)
Buggy python submission (verdict: Runtime Error):
A = int(input())
S = str(input())
if A >= 3200:print(S)
else print("red")

Fixed submission:
A = int(input())
S = str(input())
if A >= 3200:print(S)
else: print("red")
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if b == 1:
  print(0)
else:
  ans = 1
  while True:
    if ans * a - (ans-1) >= b:
   	  break
 	ans += 1
  print(ans)

Fixed submission:
a, b = map(int, input().split())
if b == 1:
  print(0)
else:
  ans = 1
  while True:
    if ans * a - (ans-1) >= b:
   	  break
    ans += 1
  print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
ans = 0
for i in range(n):
  ans += (1/a[i])
print(1/ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
  ans += (1/a[i])
print(1/ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for _ in range(N):
  s = list(str(input()))
  dic = dict()
  for i in s:
    if dic.get(i) is None:
      dic[i] = 1
    else:
      dic[i] += 1
  S.append(dic)

ans = 0
for i in range(N-1):
  for j in range(i+1, N):
    if S[i] == S[j]:
      ans += 1
     
print(ans)

Fixed submission:
N = int(input())
S = dict()

ans = 0
for _ in range(N):
  s = list(str(input()))
  string = "".join(sorted(s))
  if S.get(string) is None:
  	S[string] = 1
  else:
    ans += S[string]
    S[string] += 1
     
print(ans)
Buggy python submission (verdict: Runtime Error):
W,H,x,y = map(int, input().split())
if x == int(W/2) and y == int(H/2):
  print(int((W*H)/2) + " " + "1")
else:
  print(int((W*H)/2) + " " + "0")

Fixed submission:
W,H,x,y = map(int, input().split())
if int(x + x) == W and int(y + y) == H:
  print(str((W*H)/2) + " " + "1")
else:
  print(str((W*H)/2) + " " + "0")
Buggy python submission (verdict: Runtime Error):
N = int(input())

cost = 1
xy_set = []
for i in range(N):
    x, y = map(int, input().split())
    xy_set.append((x, y))
xy_set_sorted = sorted(xy_set, key=lambda a: a[0])

xy_sub_set = {}
for i in range(1, N):
    xs = xy_set_sorted[i][0] - xy_set_sorted[i-1][0]
    ys = xy_set_sorted[i][1] - xy_set_sorted[i - 1][1]
    if xy_sub_set.get((xs, ys)) is None:
        xy_sub_set[(xs, ys)] = 1
    else:
        xy_sub_set[(xs, ys)] += 1

xy_sub_set_sorted = sorted(xy_sub_set.items(), key=lambda a: a[1], reverse=True)
print(cost + (N-1) - xy_sub_set_sorted[0][1])

Fixed submission:
N = int(input())


def solve():

    initial_cost = 1

    # (x,y) list
    xy_list = []
    for i in range(N):
        x, y = map(int, input().split())
        xy_list.append((x, y))
    xy_list_sorted = sorted(xy_list, key=lambda a: a[0])

    if N == 1 or N == 2:
        return initial_cost

    xy_sub_dic = {}
    for i in range(N):
        for j in range(N):
            xs = xy_list_sorted[j][0] - xy_list_sorted[i][0]
            ys = xy_list_sorted[j][1] - xy_list_sorted[i][1]
            if xs != 0 or ys != 0:
                if xy_sub_dic.get((xs, ys)) is None:
                    xy_sub_dic[(xs, ys)] = 1
                else:
                    xy_sub_dic[(xs, ys)] += 1

    xy_sub_dic_sorted = sorted(xy_sub_dic.items(), key=lambda a: a[1], reverse=True)

    return initial_cost + (N - 1) - xy_sub_dic_sorted[0][1]
print(solve())
Buggy python submission (verdict: Runtime Error):
N = int(input())

dic = {}
order = []
for i in range(1,N+1):
    s, p = map(str, input().split())
    p = int(p)
    order.append((s, p))
    if dic.get(s) is None:
        dic[s] = [(i, p)]
    else:
        dic[s].append((i, p))

for k in dic:
    tmp = dic[k][:]
    tmp2 = sorted(tmp, key=lambda x: -x[1])
    dic[k] = tmp2

inds = []
ind = 1
for k in sorted(dic.keys(), key=lambda x: x[1]):
    for t in dic[k]:
        inds.append((t[0], ind))
        ind += 1

for ind in sorted(inds, key=lambda x: x[1]):
    print(ind[0])

Fixed submission:
N = int(input())

dic = {}
for i in range(1, N+1):
    s, p = map(str, input().split())
    p = int(p)
    if dic.get(s) is None:
        dic[s] = [(i, p)]
    else:
        dic[s].append((i, p))

for k in dic:
    tmp = sorted(dic[k][:], key=lambda x: -x[1])
    dic[k] = tmp

inds = []
ind = 1
for k in sorted(dic.keys()):
    for t in dic[k]:
        inds.append((t[0], ind))
        ind += 1

for ind in sorted(inds, key=lambda x: x[1]):
    print(ind[0])
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
    if flg:
        break
print(sum(A))

Fixed submission:
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

cb = {}
for i in range(M):
    b, c = map(int, input().split())
    if cb.get(c) is None:
        cb[c] = b
    else:
        cb[c] += b

a_ind = 0
for c in sorted(cb.keys(), reverse=True):
    flg = 0
    for b in range(cb[c]):
        if c < A[a_ind]:
            flg = 1
            break
        else:
            A[a_ind] = c
            a_ind += 1
            if a_ind == N:
                flg = 1
                break
    if flg:
        break
print(sum(A))
Buggy python submission (verdict: Runtime Error):
N = int(input())

ans = 0
dic = {"A": 0, "B": 0}
dic2 = {"AB": 0, "A": 0, "B": 0}
for i in range(N):
    S = list(str(input()))
    pre = S[0]
    for j in range(1, len(S)):
        if (S[j - 1] + S[j]) == "AB":
            ans += 1
    if S[-1] == "A":
        dic["A"] += 1
    if S[0] == "B":
        dic["B"] += 1

    if S[-1] == "A" and S[0] == "B":
        dic2["AB"] += 1
    elif S[-1] == "A":
        dic2["A"] += 1
    elif S[0] == "B":
        dic2["B"] += 1
if dic2["A"] == 0 and dic2["B"] == 0:
    print(ans + dic["AB"]//2)
else:
    print(ans + min(dic["A"], dic["B"]))


Fixed submission:
N = int(input())

ans = 0
dic = {"A": 0, "B": 0}
dic2 = {"AB": 0, "A": 0, "B": 0}
for i in range(N):
    S = list(str(input()))
    pre = S[0]
    for j in range(1, len(S)):
        if (S[j - 1] + S[j]) == "AB":
            ans += 1
    if S[-1] == "A":
        dic["A"] += 1
    if S[0] == "B":
        dic["B"] += 1

    if S[-1] == "A" and S[0] == "B":
        dic2["AB"] += 1
    elif S[-1] == "A":
        dic2["A"] += 1
    elif S[0] == "B":
        dic2["B"] += 1

if dic2["A"] == 0 and dic2["B"] == 0:
    print(ans + max(dic2["AB"] - 1, 0))
else:
    print(ans + min(dic["A"], dic["B"]))