Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import bisect

def ctoi(char):
  return ord(char) - 97

alphabets = [[] for _ in range(26)]

#素材
ingredients = input()
#つくりたいもの
recipe = input()

# 素材のアルファベット分布リストをつくる
for i in range(len(ingredients)):
  alpha_idx = ctoi(ingredients[i])
  alphabets[alpha_idx].append(i)

ingredients_counter = [0] * 26
for i in range(26):
  ingredients_counter[i] = len(alphabets[i])
ingredients_pointer = -1
ingredients_idx_list = []
flag = True
for i in range(len(recipe)):
  alpha_idx = ctoi(recipe[i])
  if ingredients_counter[alpha_idx] == 0:
    flag = False
    break
  #今のingredients_pointerより右側に使える素材があるか探す
  pointer_candidate_idx = \
  	bisect.bisect_right(alphabets[alpha_idx], ingredients_pointer)
  #右側に無かった。ループして先頭のを使ってどうぞ
  if pointer_candidate_idx == ingredientx_counter[alpha_idx]:
    ingredients_pointer = alphabets[alpha_idx][0]
  else:
    ingredients_pointer = alphabets[alpha_idx][pointer_candidate_idx]
  ingredients_idx_list.append(ingredients_pointer)

if flag == False:
  print(-1)
else: 
  loop = 0
  idx = ingredients_idx_list[0]
  #idxのリセット分ループを数える。左より右が小さかったらループ
  for i in range(1, len(ingredients_idx_list)):
    if ingredients_idx_list[i] < idx:
      loop += 1
    idx = ingredients_idx_list[i]
  # ループx素材の長さ + つくりたいものの最後の文字のインデックス(に、+１)
  print(loop * len(ingredients) + ingredients_idx_list[-1] + 1)

Fixed submission:
import bisect

def ctoi(char):
  return ord(char) - 97


#素材
ingredients = input()
ingredients_len = len(ingredients)
#つくりたいもの
recipe = input()
recipe_len = len(recipe)

alphabets = [[] for _ in range(26)]

# 素材のアルファベット分布リストをつくる
for i in range(ingredients_len):
  alpha_idx = ctoi(ingredients[i])
  alphabets[alpha_idx].append(i)

ingredients_counter = [0] * 26
for i in range(26):
  ingredients_counter[i] = len(alphabets[i])
  
ingredients_idx_list = []
flag = True
ingredients_pointer = -1

for i in range(recipe_len):
  alpha_idx = ctoi(recipe[i])
  if ingredients_counter[alpha_idx] == 0:
    flag = False
    break
  #今のingredients_pointerより右側に使える素材があるか探す
  pointer_candidate_idx = bisect.bisect_right(alphabets[alpha_idx], ingredients_pointer)
  #右側に無かった。ループして先頭のを使ってどうぞ
  if pointer_candidate_idx == ingredients_counter[alpha_idx]:
    ingredients_pointer = alphabets[alpha_idx][0]
  else:
    ingredients_pointer = alphabets[alpha_idx][pointer_candidate_idx]
  ingredients_idx_list.append(ingredients_pointer)

if flag == False:
  print(-1)
else: 
  loop = 0
  idx = ingredients_idx_list[0]
  #idxのリセット分ループを数える。左より右が小さかったらループ
  for i in range(1, recipe_len):
    if ingredients_idx_list[i] <= idx:
      loop += 1
    idx = ingredients_idx_list[i]
  # ループx素材の長さ + つくりたいものの最後の文字のインデックス(に、+１)
  print(loop * len(ingredients) + ingredients_idx_list[-1] + 1)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())

print(max[A+B, A-B, A*B])

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

print(sorted([A+B, A-B, A*B], reverse=True)[0])
Buggy python submission (verdict: Runtime Error):
if 3200 <= a:
  print(s)
else:
  print('red')

Fixed submission:
a = int(input())
s = input()
if 3200 <= a:
  print(s)
else:
  print('red')
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
if A-B < A+B and A*B < A+B:
  print(A+B)
elif A+B < A-B and A*B < A-B:
  print(A-B)
else:
  print(A*B)

Fixed submission:
a, b = map(int, input().split())
print(max(a+b, a-b, a*b))
Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if (a+b)% == 0:
  print((a+b)//2)
else:
  print('IMPOSSIBLE')


Fixed submission:
a, b = map(int, input().split())
if (a+b)%2 == 0:
  print((a+b)//2)
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
a, b = map(int, input().split())
if (a+b)% == 0:
  print((a+b)/2)
else:
  print('IMPOSSIBLE')

Fixed submission:
a, b = map(int, input().split())
if (a+b)%2 == 0:
  print((a+b)//2)
else:
  print('IMPOSSIBLE')

Buggy python submission (verdict: Runtime Error):
a,b = map(int, input())
if k = (a+b)/2:
  print(k)
else:
  print('impossible')

Fixed submission:
a, b = map(int, input().split())
if (a+b)%2 == 0:
  print((a+b)//2)
else:
  print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
n, a, b= map(int, input().split())
if b < na:
  print(b)
else:
  print(na)

Fixed submission:
n, a, b= map(int, input().split())
if b < n*a:
  print(b)
else:
  print(n*a)
Buggy python submission (verdict: Runtime Error):
a,b = map(int, input().split())
print(max([2*a-1, a+b, 2*b-1])

Fixed submission:
a,b = map(int, input().split())
print(max([2*a-1, a+b, 2*b-1]))
Buggy python submission (verdict: Runtime Error):
H,W = map(int, input().split())
h,w = map(int, input().split())
print(HW-hW-Hw+hw)

Fixed submission:
H,W = map(int, input().split())
h,w = map(int, input().split())
print(H*W-h*W-H*w+h*w)
Buggy python submission (verdict: Runtime Error):
a = int("".join(input().split("/"))))
if a <= 20190430:
  print("Heisei")
else:
  print("TBD")

Fixed submission:
a = int("".join(input().split("/")))
if a <= 20190430:
  print("Heisei")
else:
  print("TBD")
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
print((A-1)*(B-1))

Fixed submission:
A,B = map(int,input().split())
S = (A-1)*(B-1)
print(S)
Buggy python submission (verdict: Runtime Error):
#入力
A = int(input())
B = int(input())

if A>8 or B>8:
    print(":(")
elif A<=8 and B<=8:
    print("Yay!")


Fixed submission:
#入力
A,B = map(int, input().split())
 
if A>8 or B>8:
    print(":(")
elif A<=8 and B<=8:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
#最大公約数を求める
def gcd(a,b):
    #a>bとなるように入れ替え
    if a < b:
        tmp = a
        a = b
        b = tmp
    
    #ユークリッドの互除法
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    
    return b

#最小公倍数を求める
def lcm(a,b):
    return int((a*b)/gcd(a,b))

#入力
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

#Tのリストの2数のlcmを求めて範囲を広げていく
tmp_lcm = 1 #現在の範囲までのlcm
for i in range(N):
    tmp_lcm = lcm(tmp_lcm,T[i])

print(tmp_lcm)

Fixed submission:
#最大公約数を求める
def gcd(a,b):
    #a>bとなるように入れ替え
    if a < b:
        tmp = a
        a = b
        b = tmp
    
    #ユークリッドの互除法
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    
    return b

#最小公倍数を求める
def lcm(a,b):
    return int((a*b)//gcd(a,b))

#入力
N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

#Tのリストの2数のlcmを求めて範囲を広げていく
tmp_lcm = 1 #現在の範囲までのlcm
for i in range(N):
    tmp_lcm = lcm(tmp_lcm,T[i])

print(tmp_lcm)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
l = 0
r = n+1
a = input().split()
for i in range(m):
    l2,r2 = input().split()
    l2 = int(l2)
    r2 = int(r2)
    if l2 > l:
        l = l2
    if r2 < r:
        r = r2
if (r - l + 1) >= 0:
    print(r-l+1)
else:
    print("0")

Fixed submission:
import sys
input = sys.stdin.readline
n,m = input().split()
n = int(n)
m = int(m)
l = 0
r = n+1
for i in range(m):
    l2,r2 = input().split()
    l2 = int(l2)
    r2 = int(r2)
    if l2 > l:
        l = l2
    if r2 < r:
        r = r2
if (r - l + 1) >= 0:
    print(r-l+1)
else:
    print("0")
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
a = [0,0,0,0,0]
b = [[0,i] for i in range(5)]
for i in range(5):
    a[i] = int(input())
    b[i][0] = a[i] % 10
b.sort()
j = 0
while b[j][0] == 0:
    j += 1
time = 0
for i in range(5):
    if i != b[j][1]:
        if a[i] % 10 == 0:
            time += a[i]
        else:
            time += (a[i] + (10 - a[i] % 10))
time += a[b[j][1]]
print(time)

Fixed submission:
import sys
input = sys.stdin.readline
a = [0,0,0,0,0]
b = [[0,i] for i in range(5)]
for i in range(5):
    a[i] = int(input())
    b[i][0] = a[i] % 10
b.sort()
j = 0
while j < 5 and b[j][0] == 0:
    j += 1
time = 0
if j == 5:
    for i in range(5):
        time += a[i]
else:
    for i in range(5):
        if i != b[j][1]:
            if a[i] % 10 == 0:
                time += a[i]
            else:
                time += (a[i] + (10 - a[i] % 10))
    time += a[b[j][1]]
print(time)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
s = input()
n = len(s)
ok = 0
while ok == 0:
    ok = 1
    i = 0
    while i < len(s) - 1:
        str = s[i] + s[i+1]
        if str == "01" or str == "10":
            s = s[:i] + s[i+2:]
            ok = 0
        i += 1
print(n - len(s))

Fixed submission:
import sys
input = sys.stdin.readline
s = input()
n = len(s)
ok = 0
while ok == 0:
    ok = 1
    i = 0
    while i < len(s) - 1:
        str = s[i] + s[i+1]
        j = 0
        while str == "01" or str == "10":
            s = s[:i-j] + s[i+2-j:]
            ok = 0
            j += 1
            if i > j + 1:
                str = s[i-j] + s[i-j+1]
            else:
                break
        i += 1
print(n - len(s))
Buggy python submission (verdict: Time Limit Exceeded):
n,m = input().split()
plist = []
ylist = []
n = int(n)
m = int(m)
anslist = [0 for i in range(m)]
list = [[] for i in range(n+1)]
for i in range(m):
    p,y = input().split()
    p = int(p)
    y = int(y)
    plist.append(p)
    ylist.append(y)
for i in range(m):
    for j in range(n+1):
        if plist[i] == j + 1:
            list[j].append([ylist[i],i])
for i in range(n):
    list[i].sort()
    for j in range(len(list[i])):
        mtem = list[i][j][1]
        ans1 = str(plist[mtem])
        while len(ans1) < 6:
            ans1 = "0" + ans1
        ans2 = str(j+1)
        while len(ans2) < 6:
            ans2 = "0" + ans2
        anslist[mtem] = ans1 + ans2
for i in range(m):
    print(anslist[i])

Fixed submission:
n,m = input().split()
plist = []
ylist = []
n = int(n)
m = int(m)
anslist = [0 for i in range(m)]
list = [[] for i in range(n+1)]
for i in range(m):
    p,y = input().split()
    p = int(p)
    y = int(y)
    plist.append(p)
    ylist.append(y)
    list[p-1].append([ylist[i],i])
for i in range(n):
    list[i].sort()
    for j in range(len(list[i])):
        mtem = list[i][j][1]
        ans1 = str(plist[mtem])
        while len(ans1) < 6:
            ans1 = "0" + ans1
        ans2 = str(j+1)
        while len(ans2) < 6:
            ans2 = "0" + ans2
        anslist[mtem] = ans1 + ans2
for i in range(m):
    print(anslist[i])
Buggy python submission (verdict: Runtime Error):
n,m,q = input().split()
list = []
for i in range(int(m)):
    l,r = input().split()
    list.append([int(l),int(r)])
for i in range(int(q)):
    p,q = input().split()
    count = 0
    for j in range(len(list)):
        if int(p) <= list[j][0] and int(q) >= list[j][1]:
            count += 1
    print(count)

Fixed submission:
a,b = input().split()
c = (int(a)-1) * (int(b)-1)
print(c)
Buggy python submission (verdict: Runtime Error):
s = input()
k = input()
M = 5000000000000000
nlen = 0
i = 0
if s[i] != "1":
    print(s[i])
else:
    while s[i] == "1":
        i += 1
        nlen += 1
        if nlen == (int(k)-1):
            break
    print(s[i])

Fixed submission:
s = input()
k = input()
nlen = 0
i = 0
if s[i] != "1":
    print(s[i])
else:
    while s[i] == "1":
        if nlen == (int(k)-1):
            break
        i += 1
        nlen += 1
    print(s[i])

Buggy python submission (verdict: Runtime Error):
s = input()
k = input()
M = 5000000000000000
nlen = 0
i = 0
if s[i] != "1":
    print(s[i])
else:
    while s[i] == "1":
        i += 1
        nlen += 1
        if nlen == int(k):
            break
    print(s[i])

Fixed submission:
s = input()
k = input()
nlen = 0
i = 0
if s[i] != "1":
    print(s[i])
else:
    while s[i] == "1":
        if nlen == (int(k)-1):
            break
        i += 1
        nlen += 1
    print(s[i])
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
b = a
while b % 2 != 0 or b % a != 0:
    b += 1
print(b)

Fixed submission:
a = int(input())
if a % 2 == 0: 
    print(a)
else:
    print(2*a)
Buggy python submission (verdict: Runtime Error):
a = int(input())
s = input()

res = a >= 3200 ? s : "red"
print(res)

Fixed submission:
a = int(input())
s = input()

res = s if a >= 3200 else "red"
print(res)
Buggy python submission (verdict: Runtime Error):
# 最大公約数gcd, 
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

# 最小公倍数lcm
def lcm(a, b):
    return (a*b) // gcd(a,b)

a, b, c, d = (int(i) for i in input().split())

cd = lcm(c,d)
r = b-a+1

min_c = math.ceil(a/c)
max_c = math.floor(b/c)
min_d = math.ceil(a/d)
max_d = math.floor(b/d)
min_cd = math.ceil(a/cd)
max_cd = math.floor(b/cd)

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)


Fixed submission:
import math
# 最大公約数gcd, 
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

# 最小公倍数lcm
def lcm(a, b):
    return (a*b) // gcd(a,b)

a, b, c, d = (int(i) for i in input().split())

cd = lcm(c,d)
r = b-a+1

min_c = a//c + (1 if a%c!=0 else 0)
max_c = b//c
min_d = a//d + (1 if a%d!=0 else 0)
max_d = b//d
min_cd = a//cd + (1 if a%cd!=0 else 0)
max_cd = b//cd

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)

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

a, b, c, d = (int(i) for i in input().split())

cd = c*d // math.gcd(c,d)
r = b-a+1

min_c = math.ceil(a/c)
max_c = math.floor(b/c)
min_d = math.ceil(a/d)
max_d = math.floor(b/d)
min_cd = math.ceil(a/cd)
max_cd = math.floor(b/cd)

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)


Fixed submission:
import math
# 最大公約数gcd, 
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

# 最小公倍数lcm
def lcm(a, b):
    return (a*b) // gcd(a,b)

a, b, c, d = (int(i) for i in input().split())

cd = lcm(c,d)
r = b-a+1

min_c = a//c + (1 if a%c!=0 else 0)
max_c = b//c
min_d = a//d + (1 if a%d!=0 else 0)
max_d = b//d
min_cd = a//cd + (1 if a%cd!=0 else 0)
max_cd = b//cd

c_num = max_c-min_c+1
d_num = max_d-min_d+1
cd_num = max_cd-min_cd+1

print(r-c_num-d_num+cd_num)
Buggy python submission (verdict: Runtime Error):
W,H,x,y = (int(i) for i in input().split())

is_double = 0
if x == W/2 and y == H/2:
    is_double = 1

res = min(x*H,(W-x)*H)
res2 = min((H-y)*W,y*W)

print("{} {}".format(max([res,res2,res3]),is_double))

Fixed submission:
W,H,x,y = (int(i) for i in input().split())

is_double = 0
if x == W/2 and y == H/2:
    is_double = 1

print("{} {}".format(H*W/2,is_double))

Buggy python submission (verdict: Runtime Error):
W,H,x,y = (int(i) for i in input().split())

is_double = 0
if x == W//2 and y == H//2:
    is_double = 1

if x>=W//2:
    res = (W-x)*H
else:
    res = x*H

if y>=H//2:
    res2 = (H-y)*W
else:
    res2 = y*W

if x==y*W/H or x==(H-y)*W/H:
    res3 = H*W/2

print("{} {}".format(max([res,res2,res3]),is_double))

Fixed submission:
W,H,x,y = (int(i) for i in input().split())

is_double = 0
if x == W/2 and y == H/2:
    is_double = 1

print("{} {}".format(H*W/2,is_double))
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = sorted([int(i) for i in input().split()])

if a[0] <= 0 and 0 < a[-1]:
    import bisect
    print(sum(map(lambda x: abs(x), a)))
    x0 = bisect.bisect_left(a,0)

    # 0以下から正をひいていく（一番大きいものを除く）
    print("{} {}".format(a[0], a[x0-1]))
    res = a[0] - a[x0+1]

    for x in a[x0+1:-2]:
        print("{} {}".format(res, x))
        res -= x

    # 一番大きいものから上のものと負の数を引いていく
    print("{} {}".format(a[-1], res))
    res = a[-1] - res
    for x in a[1:x0]:
        print("{} {}".format(res,x))
        res -= x

elif a[0] > 0:
    print(sum(a) - 2*a[0])

    print("{} {}".format(a[0],a[1]))
    res = a[0] - a[1]
    for x in a[2:-2]:
        print("{} {}".format(res, x))
        res -= x
    
    print("{} {}".format(a[-1], res))
else:
    print(-sum(a) + 2*a[-1])

    print("{} {}".format(a[-1],a[-2]))
    res = a[-1] - a[-2]
    for x in a[:-2]:
        print("{} {}".format(res, x))
        res -= x
    

Fixed submission:
n = int(input())
a = sorted([int(i) for i in input().split()])

if n == 2:
    print(a[1] - a[0])
    print("{} {}".format(a[1], a[0]))
    exit()

if a[0] <= 0 and 0 <= a[-1]:
    import bisect
    print(sum(map(lambda x: abs(x), a)))
    x0 = bisect.bisect_left(a,0)

    # 0以下から0以上をひいていく（一番大きいものを除く）
    if a[-2] >= 0:
        if x0 == 0:
            x0 += 1
        print("{} {}".format(a[0], a[x0]))
        res = a[0] - a[x0]

        for x in a[x0+1:-1]:
            print("{} {}".format(res, x))
            res -= x
    else:
        res = a[0]

    # 一番大きいものから上のものと負の数を引いていく
    print("{} {}".format(a[-1], res))
    res = a[-1] - res
    for x in a[1:x0]:
        print("{} {}".format(res,x))
        res -= x

elif a[0] > 0:
    print(sum(a) - 2*a[0])

    print("{} {}".format(a[0],a[1]))
    res = a[0] - a[1]
    for x in a[2:-1]:
        print("{} {}".format(res, x))
        res -= x
    
    print("{} {}".format(a[-1], res))
else:
    print(-sum(a) + 2*a[-1])

    print("{} {}".format(a[-1],a[-2]))
    res = a[-1] - a[-2]
    for x in a[:-2]:
        print("{} {}".format(res, x))
        res -= x
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
ab = [[ (int(i)-1) for i in input().split()] for i in range(n-1)]
c = sorted([int(i) for i in input().split()], reverse=True)

if n==1:
    print(0)
    print(c[0])
    exit()
    
dic = {}
for i in range(n):
    dic[i] = []

cnt = [0]*n
for a,b in ab:
    dic[a].append(b)
    dic[b].append(a)
    cnt[a] += 1
    cnt[b] += 1

c_idx = 0
res = 0
res_arr = [""]*n
used = [0]*n
def f(idx):
    global c_idx, res, used
    used[idx] = 1
    res_arr[idx] = str(c[c_idx])
    for x in dic[idx]:
        if used[x] == 0:
            c_idx += 1
            res += c[c_idx]
            f(x)

f(cnt.index(1))
print(res)
print(" ".join(res_arr))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(11000)

n = int(input())
ab = [[ (int(i)-1) for i in input().split()] for i in range(n-1)]
c = sorted([int(i) for i in input().split()], reverse=True)

if n==1:
    print(0)
    print(c[0])
    exit()

dic = {}
for i in range(n):
    dic[i] = []

cnt = [0]*n
for a,b in ab:
    dic[a].append(b)
    dic[b].append(a)
    cnt[a] += 1
    cnt[b] += 1

c_idx = 0
res = 0
res_arr = [""]*n
used = [0]*n
def f(idx):
    global c_idx, res, used
    used[idx] = 1
    res_arr[idx] = str(c[c_idx])
    for x in dic[idx]:
        if used[x] == 0:
            c_idx += 1
            res += c[c_idx]
            f(x)

f(cnt.index(1))
print(res)
print(" ".join(res_arr))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

n = int(input())
ab = [[ (int(i)-1) for i in input().split()] for i in range(n-1)]
c = sorted([int(i) for i in input().split()], reverse=True)

dic = {}
for i in range(n):
    dic[i] = []

cnt = [0]*n
for a,b in ab:
    dic[a].append(b)
    dic[b].append(a)
    cnt[a] += 1
    cnt[b] += 1

c_idx = 0
res = 0
res_arr = [""]*n
used = [0]*n
def f(idx):
    global c_idx, res, used
    used[idx] = 1
    res_arr[idx] = str(c[c_idx])
    for x in dic[idx]:
        if used[x] == 0:
            c_idx += 1
            res += c[c_idx]
            f(x)

f(cnt.index(1))
print(res)
print(" ".join(res_arr))

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(11000)

n = int(input())
ab = [[ (int(i)-1) for i in input().split()] for i in range(n-1)]
c = sorted([int(i) for i in input().split()], reverse=True)

if n==1:
    print(0)
    print(c[0])
    exit()

dic = {}
for i in range(n):
    dic[i] = []

cnt = [0]*n
for a,b in ab:
    dic[a].append(b)
    dic[b].append(a)
    cnt[a] += 1
    cnt[b] += 1

c_idx = 0
res = 0
res_arr = [""]*n
used = [0]*n
def f(idx):
    global c_idx, res, used
    used[idx] = 1
    res_arr[idx] = str(c[c_idx])
    for x in dic[idx]:
        if used[x] == 0:
            c_idx += 1
            res += c[c_idx]
            f(x)

f(cnt.index(1))
print(res)
print(" ".join(res_arr))
Buggy python submission (verdict: Time Limit Exceeded):
# 高速版input
import sys
input = sys.stdin.readline

# 二分探索
import bisect

n,m = (int(i) for i in input().split())
a = sorted([int(i) for i in input().split()])
bc = [[int(i) for i in input().split()] for i in range(m)]

for b,c in bc:
    idx = bisect.bisect_left(a,c)
    a = (a[:idx] + [c]*b + a[idx:])[b:]

print(sum(a))

Fixed submission:
# 高速版input
import sys
input = sys.stdin.readline

n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]

x = []
for b,c in sorted(bc, key=lambda x: x[1], reverse=True):
    x.extend([c]*b)
    if len(x) > n:
        break
        
a.extend(x)
print(sum(sorted(a,reverse=True)[:n]))

Buggy python submission (verdict: Runtime Error):
# 高速版input
import sys
input = sys.stdin.readline

# 二分探索
import bisect
import numpy as np

n,m = (int(i) for i in input().split())
a = sorted([int(i) for i in input().split()])
bc = [[int(i) for i in input().split()] for i in range(m)]

a = a
for b,c in bc:
    idx = bisect.bisect_left(a,c)
    a = (a[:idx] + [c]*b + a[idx:])[b:]

print(sum(a))

Fixed submission:
# 高速版input
import sys
input = sys.stdin.readline

n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]

x = []
for b,c in sorted(bc, key=lambda x: x[1], reverse=True):
    x.extend([c]*b)
    if len(x) > n:
        break
        
a.extend(x)
print(sum(sorted(a,reverse=True)[:n]))

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

for b,c in bc:
    a.extend([c]*b)

print(sum(sorted(a,reverse=True)[:n]))

Fixed submission:
# 高速版input
import sys
input = sys.stdin.readline

n,m = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
bc = [[int(i) for i in input().split()] for i in range(m)]

x = []
for b,c in sorted(bc, key=lambda x: x[1], reverse=True):
    x.extend([c]*b)
    if len(x) > n:
        break
        
a.extend(x)
print(sum(sorted(a,reverse=True)[:n]))
Buggy python submission (verdict: Runtime Error):
n = int(input())

s = 0
for i in range(1, int(n**(1/2)+1) ):
    ans = (n-i) // i
    if n//ans == n%ans:
        s+=ans
print(s)

Fixed submission:
n = int(input())

if n==1:
    print(0)
    exit()
    
s = 0
for i in range(1, int(n**(1/2)+1) ):
    ans = (n-i) // i
    if n//ans == n%ans:
        s+=ans
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = (int(i) for i in input().split())
s = input()

start = s[0]
arr = []
pre = start
cnt = 0
for x in s:
    if x == pre:
        cnt+=1
        continue
    else:
        pre = x
        arr.append(cnt)
        cnt = 1

arr.append(cnt)

if len(arr) == 1:
    print(arr[0])
    exit()
m = 0
if start == "1":
    for i in range((len(arr)//2)-k+1):
        m = max(sum(arr[2*i:2*i+2*k+1]), m)

else:
    m = sum(arr[:2*k])
    for i in range(((len(arr)+1)//2)-k):
        m = max(sum(arr[2*i+1:2*i+2*k+2]), m)
    
print(m)
        

Fixed submission:
n,k = (int(i) for i in input().split())
s = input()

start = s[0]
arr = []
pre = start
cnt = 0
for x in s:
    if x == pre:
        cnt+=1
        continue
    else:
        pre = x
        arr.append(cnt)
        cnt = 1

arr.append(cnt)

if len(arr) == 1:
    print(arr[0])
    exit()

m = 0
if start == "1":
    now = sum(arr[:2*k+1])
    m = now
    for i in range(1, (len(arr)//2)-k+1):
        now = now - arr[2*i-1] - arr[2*i-2] + sum(arr[2*i+2*k-1:2*i+2*k+1]) 
        m = max(now, m)

else:
    m = sum(arr[:2*k])
    now = sum(arr[1:2*k+2])
    m = max(now, m)
    for i in range(1, ((len(arr)+1)//2)-k):
        now = now - arr[2*i] - arr[2*i-1] + sum(arr[2*i+2*k:2*i+2*k+2])
        m = max(now, m)
    
print(m)