Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03695 (python)

Fixed submission:
# coding: utf-8
L = [0 for _ in range(8)]
N = int(input())
A = list(map(int, input().split()))
v = 0
for i in range(N):
    idx = A[i] // 400
    if idx >= 8:
        v += 1
    else:
        L[idx] += 1
amin, amax = 0, 0
for i in range(len(L)):
    if L[i] > 0:
        amin += 1
    # if L[i] == 0 and v > 0:
    #     L[i] += 1
    #     v -= 1
# amin = max(1, amin)
# for i in range(len(L)):
#     if L[i] > 0:
#         amax += 1
print(max(1, amin), amin + v)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
L = [0 for _ in range(8)]
N = int(input())
A = list(map(int, input().split()))
v = 0
for i in range(N):
    idx = A[i] // 400
    if idx > 8:
        v += 1
    else:
        L[idx] += 1
amin, amax = 0, 0
for i in range(len(L)):
    if L[i] > 0:
        amin += 1
    if L[i] == 0 and v > 0:
        L[i] += 1
        v -= 1
amin = max(1, amin)
for i in range(len(L)):
    if L[i] > 0:
        amax += 1
print(amin, amax)
Problem p03910 (python)

Fixed submission:
# coding: utf-8
N = int(input())
if N == 1:
    print(1)
    exit()
ans = 0
for i in range(1, N+1):
    ans += i
    if ans >= N:
        end = i
        break
res = ans - N
for i in range(1, end+1):
    if i != res:
        print(i)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
N = int(input())
if N == 1:
    print(1)
    exit()
ans = 0
for i in range(1, N+1):
    if ans < N:
        ans += i
    else:
        end = i
        break
res = ans - N
for i in range(1, end):
    if i != res:
        print(i)
Problem p04025 (python)

Fixed submission:
# coding: utf-8
from math import ceil
from statistics import median, mean
N = int(input())
A = list(map(int, input().split()))
ans = 10**9
for m in range(-100, 101):
    tmp = 0
    for i in range(N):
        tmp += (A[i] - m)**2
    ans = min(ans, tmp)
print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8
from math import ceil
from statistics import median, mean
N = int(input())
A = list(map(int, input().split()))
A.sort()
if N % 2 == 0:
    m = ceil((A[N//2] + A[N//2+1]) / 2)
else:
    m = A[N//2]
ans = 0
for i in range(N):
    ans += (A[i] - m)**2
print(ans)
Problem p02583 (python)

Fixed submission:

N = int(input())
Ns = list(map(int, input().split()))
Ns.sort()
ans = 0

for i in range(0, N - 2):
	for j in range(i + 1, N - 1):
		for k in range(j + 1, N):
			if(Ns[i] == Ns[j] or Ns[k] == Ns[j]):
				continue

			if(Ns[i] + Ns[j] > Ns[k] and Ns[j] + Ns[k] > Ns[i] and Ns[k] + Ns[i] > Ns[j]):
				ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):

N = input()
Ns = list(map(int, input().split()))
Ns.sort()
ans = 0

for i in range(0, Ns - 2):
	for j in range(i, Ns - 1):
		for k in range(j, Ns):
			if(Ns[i] + Ns[j] > Ns[k] and Ns[j] + Ns[k] > Ns[i] and Ns[k] + Ns[i] > Ns[j]):
				ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):

Ns = list(map(int, input().split()))
Ns.sort()
ans = 0

for i in range(0, Ns - 2):
	for j in range(i, Ns - 1):
		for k in range(j, Ns):
			if(Ns[i] + Ns[j] > Ns[k]
				and Ns[j] + Ns[k] > Ns[i] 
				and Ns[k] + Ns[i] > Ns[j]):
				ans += 1
print(ans)
Problem p03760 (python)

Fixed submission:
# -*- coding: utf-8 -*-


o = list(input())
e = list(input())

i = 0

while i < max(len(o),len(e)):
    if(i<len(o)):
        print(o[i],end="")
    if(i<len(e)):
        print(e[i],end="")
    i += 1

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


o = list(input())
e = list(input())

for i in range(len(o)):
    print(o[i]+e[i],end="")
Problem p02830 (python)

Fixed submission:
num = int(input())
ans=""
(s1,s2) = input().split(" ")



for i in range(num):
    ans+=s1[i]
    ans+=s2[i]

print(ans)

Buggy submission (verdict: Runtime Error):
num = int(input())

s1 = input()
s2 = input()
ans=""
for i in range(num):
    ans+=s1[i]
    ans+=s2[i]

print(ans)
Problem p02609 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**8)

N = int(input())
X = str(input())
ones = X.count('1')
intX = int(X, 2)
def check(n, r):
    if n == 0:
        return print(r)
    d = str(bin(n)).count('1')
    check(n%d, r+1)

if ones > 1:
    Xplus = intX % (ones + 1)
    Xminus = intX % (ones - 1)
else:
    Xplus = intX % (ones + 1)
    Xminus = intX

for i in range(N):
    e = 1
    if X[i] == '0':
        num = (Xplus + pow(2, N-1-i, ones + 1)) % (ones + 1)
    elif X[i] == '1' and ones > 1:
        num = (Xminus - pow(2, N-1-i, ones - 1)) % (ones - 1)
    else:
        num = (Xminus - pow(2, N-1-i))
        e = 0
    check(num, e)

Buggy submission (verdict: Runtime Error):
# D - Anything Goes to Zero
import sys
sys.setrecursionlimit(10**8)

N = int(input())
X = str(input())
ones = X.count('1')
intX = int(X, 2)
def check(n, r):
    if n == 0:
        return print(r)
    d = str(bin(n)).count('1')
    check(n%d, r+1)

Xplus = intX % (ones + 1)
Xminus = intX % (ones - 1)
for i in range(N):
    if X[i] == '0':
        num = (Xplus + pow(2, N-1-i, ones + 1)) % (ones + 1)
    else:
        num = (Xminus - pow(2, N-1-i, ones - 1)) % (ones - 1)
    check(num, 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

N = int(input())
X = str(input())
ones = X.count('1')
intX = int(X, 2)
def check(n, r):
    if n == 0:
        return print(r)
    d = str(bin(n)).count('1')
    check(n%d, r+1)

Xplus = intX % (ones + 1)
Xminus = intX % (ones - 1)
for i in range(N):
    if X[i] == '0':
        num = (Xplus + pow(2, N-1-i)) % (ones + 1)
    else:
        num = (Xminus - pow(2, N-1-i)) % (ones - 1)
    check(num, 1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**8)

N = int(input())
X = str(input())
ones = X.count('1')
intX = int(X, 2)
def check(n, r):
    if n == 0:
        return print(r)
    d = str(bin(n)).count('1')
    check(n%d, r+1)

Xplus = intX % (ones + 1)
Xminus = intX % (ones - 1)
print(intX, ones, Xplus, Xminus)
for i in range(N):
    if X[i] == '0':
        num = (Xplus + pow(2, N-1-i)) % (ones + 1)
    else:
        num = (Xminus - pow(2, N-1-i)) % (ones - 1)
    check(num, 1)
Problem p02662 (python)

Fixed submission:
import sys
readline = sys.stdin.readline

N, S = map(int, readline().split())
A = list(int(x) for x in readline().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] = (dp[i+1][j] + dp[i][j] * 2) % MOD
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD
print(dp[N][S])

Buggy submission (verdict: Runtime Error):
N, S = map(int, input().split())
A = list(int(x) for x in input().split())
MOD = 998244353

dp = [[0] * (S+1) for _ in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        print(i, j)
        # 1,2のケース。jが変わらない遷移が2通りある。
        dp[i+1][j] += dp[i][j] * 2
        # 3のケース。j+A[i] <= Sならば、j+A[i]に遷移する。
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
        print(dp)
print(dp[N][S])
Problem p02678 (python)

Fixed submission:
# D - .. (Double Dots)

from collections import deque

N, M = map(int, input().split())
tree = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    tree[A].append(B)
    tree[B].append(A)

ans_arr = [-1] * (N)
q = deque()
ans_arr[0] = 0 
q.append(0)

while len(q)>0:
    n = q.popleft()
    for i in tree[n]:
        if ans_arr[i] == -1:
            ans_arr[i] = n+1
            q.append(i)

ans = 'Yes'
for i in ans_arr[1:]:
    if i == -1:
        ans = 'No'
        break

if ans == 'No':
    print(ans)
else:
    print(ans)
    for i in ans_arr[1:]:
        print(i)

Buggy submission (verdict: Runtime Error):
# D - .. (Double Dots)

from collections import deque
N, M = map(int, input().split())
tree = [[] for _ in range(M)]
for i in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    tree[A].append(B)
    tree[B].append(A)

ans_arr = [-1] * (N)
q = deque()
ans_arr[0] = 0 
q.append(0)

while len(q)>0:
    n = q.popleft()
    for i in tree[n]:
        if ans_arr[i] == -1:
            ans_arr[i] = n+1
            q.append(i)

ans = 'Yes'
for i in ans_arr[1:]:
    if i == -1:
        ans = 'No'
        break

if ans == 'No':
    print(ans)
else:
    print(ans)
    for i in ans_arr[1:]:
        print(i)
Problem p02690 (python)

Fixed submission:
# D - I hate Factorization

X = int(input())
fact = []
for i in range(300):
    fact.append(pow(i,5))

for i in range(300):
    for j in range(300):
        if fact[i]-fact[j]==X:
            print(i, j)
            break
        elif fact[i]+fact[j]==X:
            print(i, -j)
            break
    else:
        continue
    break

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

div = make_divisors(X)

for d in div:
    i = 1
    j = i-d
    while True:
        if pow(i,5)-pow(j,5)<X:
            i += 1
            j += 1
            continue
        if pow(i,5)-pow(j,5)==X:
            print(i,j)
            break
        elif pow(i,5)-pow(j,5)>X:
            break
Problem p02850 (python)

Fixed submission:
# D - Coloring Edges on Tree
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = []
B = []

# 2次元配列で辺（頂点,遷移先の頂点）を管理する
D = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append(b)
    D[b].append(a)
    A.append(a)
    B.append(b)

print(max([len(d) for d in D]))

C = {}

def dfs(node, par, col):
    cid = 1
    for chi in D[node]:
        if chi==par:
            continue
        else:
            if cid==col:
                cid += 1
            C[(node, chi)] = cid
            C[(chi, node)] = cid
            dfs(chi, node, cid)
            cid += 1

dfs(0,0,0)

for a, b in zip(A, B):
    print(C[(a,b)])

Buggy submission (verdict: Runtime Error):
# D - Coloring Edges on Tree

n = int(input())
A = []
B = []

# 2次元配列で辺（頂点,遷移先の頂点）を管理する
D = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append(b)
    D[b].append(a)
    A.append(a)
    B.append(b)

print(max([len(d) for d in D]))

C = {}

def dfs(node, par, col):
    cid = 1
    for chi in D[node]:
        if chi==par:
            continue
        else:
            if cid==col:
                cid += 1
            C[(node, chi)] = cid
            C[(chi, node)] = cid
            dfs(chi, node, cid)
            cid += 1

dfs(0,0,0)

for a, b in zip(A, B):
    print(C[(a,b)])

Buggy submission (verdict: Runtime Error):
# D - Coloring Edges on Tree

n = int(input())
A = []
B = []

# 2次元配列で辺（頂点,遷移先の頂点）を管理する
D = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append(b)
    D[b].append(a)
    A.append(a)
    B.append(b)

print(max([len(d) for d in D]))

C = {}

def dfs(node, par, col):
    cid = 1
    for chi in D[node]:
        if chi==par:
            continue
        else:
            if cid==col:
                cid += 1
            C[(node, chi)] = cid
            dfs(chi, node, cid)
            cid += 1

dfs(0,0,0)

for a, b in zip(A, B):
    print(C[(a,b)])

Buggy submission (verdict: Runtime Error):
# D - Coloring Edges on Tree

n = int(input())
A = []
B = []

# 2次元配列で辺（頂点,遷移先の頂点）を管理する
D = [[] for _ in range(n)]

# 2次元配列で塗る色（頂点,遷移先の頂点）を管理する
C = [[0]*n for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    D[a].append(b)
    D[b].append(a)
    A.append(a)
    B.append(b)

print(max([len(d) for d in D]))

def dfs(node, par, col):
    cid = 1
    for chi in D[node]:
        if chi==par:
            continue
        else:
            if cid==col:
                cid += 1
            C[node][chi] = cid
            dfs(chi, node, cid)
            cid += 1

dfs(0,0,0)

for a, b in zip(A, B):
    print(C[a][b])
Problem p02900 (python)

Fixed submission:
import collections

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)

def trial_division(n):
    a = []  
    while n % 2 == 0:
        a.append(2)
        n /= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n /= f
        else:
            f += 2   
    if n != 1: a.append(n)
    return a

def main():
    a, b = map(int, input().split())
    c = collections.Counter(trial_division(gcd(a, b)))
    print(len(c.keys())+1)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
a, b = map(int, input().split())
ans = []

for i in range(1,min(a,b)+1):
    if a%i == 0 and b%i ==0:
        while True:
            for j in range(2,int(math.sqrt(i))+1):
                if i%j==0:
                    break
            else:
                ans.append(i)
            break
            
print(len(ans))
Problem p02909 (python)

Fixed submission:
s = input()

if s == 'Sunny':
    print('Cloudy')
elif s == 'Cloudy':
    print('Rainy')
else:
    print('Sunny')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list([int(x) for x in input().split()])
 
for i in range(m):
    a[a.index(max(a))] = max(a)//2
print(sum(a))
Problem p02913 (python)

Fixed submission:
n = int(input())
s = input()
high = n//2
low = 1
ans = 0

while low <= high:
    t = set()
    i = (high+low)//2
    for j in range(n-i*2+1):
        t.add(s[j:i+j])
        if s[i+j:j+2*i] in t:
            if ans < i:
                ans = i
                low = i+1
                break
    if ans < i:
        high = i-1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = input()
ans = 0

for i in range(n):
    for j in range(i+1, n+1):
        print('s[i:j]:, s[j:]: ',s[i:j],s[j:], s[i:j] in s[j:], len(s[i:j]))
        if (s[i:j] in s[j:]):
            if ans < len(s[i:j]):
                ans = len(s[i:j])
        else:
            break
print(ans)
Problem p02924 (python)

Fixed submission:
n = int(input())
print(int((n-1)*n//2))

Buggy submission (verdict: Runtime Error):
N = list(range(1,int(input())))
print(sum(N))
Problem p02983 (python)

Fixed submission:
# C - Remainder Minimization 2019
import numpy as np

l, r = map(int, input().split())

ans = 2019
for i in range(l,r):
    for j in range(i+1, r+1):
        ans = min(ans, (i*j)%2019)
        if ans==0:
            break
    else:
        continue
    break

print(ans)

Buggy submission (verdict: Runtime Error):
# C - Remainder Minimization 2019
import numpy as np

l, r = map(int, input().split())

a = np.arange(l, r+1)
a = a%2019
#print(a)
b = np.copy(a)
b = 2019 - b
#print(b)
c = np.minimum(a, b)
c = np.sort(c)
#print(c)

print((c[0]*c[1])%2019)

Buggy submission (verdict: Runtime Error):
# C - Remainder Minimization 2019
import numpy as np

l, r = map(int, input().split())

a = np.arange(l, r+1)
a = a%2019
a = np.sort(a)

print((a[0]*a[1])%2019)

Buggy submission (verdict: Runtime Error):
# C - Remainder Minimization 2019
import numpy as np

l, r = map(int, input().split())

a = np.arange(l, r+1)
a = a%2019
a = np.sort(a)

print(a[0]*a[1])

Buggy submission (verdict: Runtime Error):
# C - Remainder Minimization 2019
import numpy as np

l, r = map(int, input().split())

a = np.arange(l, r+1)
a = a%2019
np.sort(a)

print(a[0]*a[1])
Problem p03007 (python)

Fixed submission:
# C - Successive Subtraction

N = int(input())
A = list(int(a) for a in input().split())

M = []
P = []
for a in A:
    if a >= 0:
        P.append(a)
    else:
        M.append(a)

P.sort(reverse=True)
M.sort()
lenP = len(P)
lenM = len(M)    

ans = []
anssum = 0

if lenM ==0:
    if lenP >= 3:
        ans.append((P[-1], P[-2]))
        tmp = P.pop() - P.pop()
        M.append(tmp)
        lenP -= 2
    else:
        ans.append((P[-2], P[-1]))
        tmp = P.pop() - P.pop()
        tmp *= -1
        P.append(tmp)
        lenP -= 2
elif lenP ==0:
    ans.append((M[-1], M[-2]))
    tmp = M.pop() - M.pop()
    P.append(tmp)
    lenP += 1
for i in range(lenP-1):
    ans.append((M[-1], P[-1]))
    tmp = M.pop() - P.pop()
    M.append(tmp)
while M != []:
    ans.append((P[-1], M[-1]))
    tmp = P.pop() - M.pop()
    P.append(tmp)
anssum = P.pop()

print(anssum)
for i in range(len(ans)):
    print(' '.join(map(str, ans[i])))

Buggy submission (verdict: Runtime Error):
# C - Successive Subtraction

N = int(input())
A = list(int(a) for a in input().split())

M = []
P = []
for a in A:
    if a >= 0:
        P.append(a)
    else:
        M.append(a)

P.sort(reverse=True)
M.sort()
lenP = len(P)
lenM = len(M)    

ans = []
anssum = 0

if lenM ==0:
    ans.append((P[-1], P[-2]))
    tmp = P.pop() - P.pop()
    M.append(tmp)
    lenP -= 2
elif lenP ==0:
    ans.append((M[-1], M[-2]))
    tmp = M.pop() - M.pop()
    P.append(tmp)
    lenP += 1
for i in range(lenP-1):
    ans.append((M[-1], P[-1]))
    tmp = M.pop() - P.pop()
    M.append(tmp)
while M != []:
    ans.append((P[-1], M[-1]))
    tmp = P.pop() - M.pop()
    P.append(tmp)
anssum = P.pop()

print(anssum)
for i in range(len(ans)):
    print(' '.join(map(str, ans[i])))
Problem p03078 (python)

Fixed submission:
# D - Cake 123

import heapq
import itertools

x, y, z, k = map(int, input().split())

A = list(int(a) for a in input().split())
B = list(int(b) for b in input().split())
C = list(int(c) for c in input().split())

hq = []
for i, j in itertools.product(A, B):
    heapq.heappush(hq, (i+j)*-1)

AB = []
while len(hq)>0 and len(AB)<=k:
    AB.append(heapq.heappop(hq)*-1)

hq = []
for i, j in itertools.product(AB, C):
    heapq.heappush(hq, (i+j)*-1)

for _ in range(k):
    print(heapq.heappop(hq)*-1)

Buggy submission (verdict: Runtime Error):
# D - Cake 123

import heapq
import itertools

x, y, z, k = map(int,input().split())

if x*y*z<3000:
    a = list(int(x) for x in input().split())
    b = list(int(x) for x in input().split())
    c = list(int(x) for x in input().split())

    anslist = []
    ip = list(itertools.product(a, b, c))   
    for i in range(len(ip)):
        heapq.heappush(anslist, sum(ip[i])*-1)

    for i in range(k):
        print(heapq.heappop(anslist)*-1)

else:
    a = list(int(x)*-1 for x in input().split())
    b = list(int(x)*-1 for x in input().split())
    c = list(int(x)*-1 for x in input().split())
    inf = 10**18

    heapq.heapify(a)
    heapq.heapify(b)
    heapq.heapify(c)

    la = [inf]
    lb = [inf]
    lc = [inf]

    while len(la)*len(lb)*len(lc)<3000:
        if a[0]<=b[0]<=c[0]:
            tmp = heapq.heappop(a)
            heapq.heappush(a, inf)
            la.append(tmp*-1)
        elif a[0]>b[0]<=c[0]:
            tmp = heapq.heappop(b)
            heapq.heappush(b, inf)
            lb.append(tmp*-1)
        else:
            tmp = heapq.heappop(b)
            heapq.heappush(c, inf)
            lc.append(tmp*-1)

    anslist = []
    ip = list(itertools.product(la, lb, lc))   
    for i in range(len(ip)):
        heapq.heappush(anslist, sum(ip[i])*-1)

    for i in range(k):
        print(heapq.heappop(anslist)*-1)
Problem p03105 (python)

Fixed submission:
# A - Favorite Sound

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

print(min(B//A, C))

Buggy submission (verdict: Runtime Error):
# D - Decayed Bridges
from collections import deque

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

graph = [[] for _ in range(N)]
AB = deque()
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    AB.append([a, b])
    graph[a].append(b)
    graph[b].append(a)

def isDivided(a, b, graph):
    d = deque()
    d.append(a)
    done = [0] * N
    while len(d)>0:
        now = d.popleft()
        done[now] = 1
        for i in graph[now]:
            if i==b:
                return 0
            elif done[i]==0:
                d.append(i)
    return sum(done)

ans = 0
for i in range(M):
    a, b = AB.popleft()
    graph[a].remove(b)
    graph[b].remove(a)
    tmpa = isDivided(a, b, graph)
    tmpb = isDivided(b, a, graph)
    if tmpa!=0:
        ans += tmpa*tmpb
        print(ans)
    else:
        print(ans)
Problem p03106 (python)

Fixed submission:
# B - K-th Common Divisor

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

cnt = 0
for i in range(1, min(A, B)+1)[::-1]:
    if A%i==0 and B%i==0:
        cnt += 1
        if cnt==K:
            print(i)
            break

Buggy submission (verdict: Runtime Error):
# B - K-th Common Divisor

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

def gcd(x, y):
    if x==0:
        return y
    else:
        return gcd(y%x, x)

gcdAB = gcd(A, B)

cdlist = [gcdAB]
for i in range(1, (int(gcdAB**0.5))+1)[::-1]:
    if gcdAB%1==0:
        cdlist.append(i)

print(cdlist[K-1])
Problem p03128 (python)

Fixed submission:
# D - Match Matching

N, M = map(int, input().split())
A = list(int(x) for x in input().split())
match_list = [('0', 6), ('1', 2), ('2', 5), ('3', 5), ('4', 4), ('5', 5), ('6', 6), ('7', 3), ('8', 7), ('9', 6)]
MA = []
for a in A:
    MA.append(match_list[a])
MA.sort(key=lambda x: x[0], reverse=True)

# dp[i] := i本のマッチを使って作れる最大桁数
dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
    for j in range(M):
        if i-MA[j][1] >= 0:
            dp[i] = max(dp[i], dp[i-MA[j][1]] + 1)

remain_keta = dp[N]
remain_match = N
ans = ''
for i in range(dp[N]):
    for ma in MA:
        # 大きい数字から一桁使った時に、
        # 残り桁がちょうど一桁減っている場合
        if remain_match >= ma[1] and dp[remain_match - ma[1]] == remain_keta - 1:
            ans +=  ma[0]
            remain_keta -= 1
            remain_match -= ma[1]
            break

print(ans)

Buggy submission (verdict: Runtime Error):
# D - Match Matching

N, M = map(int, input().split())
A = list(int(x) for x in input().split())
match_list = [(0, 6), (1, 2), (2, 5), (3, 5), (4, 4), (5, 5), (6, 6), (7, 3), (8, 7), (9, 6)]
MA = []
for a in A:
    MA.append(MATCH[a])
MA.sort(key=lambda x: x[1])

def dfs(tmp, s):
    global ans
    if s == N:
        ans = max(ans, tmp)    
    for ma in MA:
        if s+ma[1] <= N:
            tmp = tmp*10 + ma[0]
            dfs(tmp, s + ma[1])
            tmp //= 10

tmp = 0
ans = 0
dfs(tmp, 0)
print(ans)
Problem p03148 (python)

Fixed submission:
# D - Various Sushi
import sys
from collections import defaultdict
import heapq

readline = sys.stdin.readline

dd = defaultdict(list)
N, K = map(int, readline().split())
for i in range(N):
    t, d = map(int, readline().split())
    heapq.heappush(dd[t], d*-1)

dd = list(dd.values())
dd.sort()

ans = 0
fix = 0
var = []
len_var = 0
sum_var = 0
tmp_max = 0

for i in range(min(K, len(dd))):
    fix += heapq.heappop(dd[i]) * -1
    for _ in range(len(dd[i])):
        tmp = heapq.heappop(dd[i]) * -1
        heapq.heappush(var, tmp)
        len_var += 1
        sum_var += tmp
    while len_var > K-(i+1) and len_var > 0:
        del_var = heapq.heappop(var)
        len_var -= 1
        sum_var -= del_var
    if len_var == K-(i+1):
        ans = max(ans , fix+sum_var + (i+1)**2)

print(ans)

Buggy submission (verdict: Runtime Error):
# D - Various Sushi
import sys
from collections import defaultdict
import heapq
readline = sys.stdin.readline

dd = defaultdict(list)
N, K = map(int, readline().split())
for i in range(N):
    t, d = map(int, readline().split())
    heapq.heappush(dd[t], d*-1)

dd = list(dd.values())
dd.sort()

ans = 0
fix = 0
var = []
for i in range(len(dd)):
    fix += heapq.heappop(dd[i]) * -1
    while len(dd[i]) > 0:
        tmp = heapq.heappop(dd[i]) * -1
        heapq.heappush(var, tmp)
    while len(var) > K-i-1:
        heapq.heappop(var)
    if len(var) == K-i-1:
        ans = max(ans , fix+sum(var) + (i+1)**2)

print(ans)

Buggy submission (verdict: Runtime Error):
# D - Various Sushi

from collections import defaultdict
import heapq

dd = defaultdict(list)
N, K = map(int, input().split())
for i in range(N):
    t, d = map(int, input().split())
    heapq.heappush(dd[t], d*-1)

dd = list(dd.values())
dd.sort()

ans = 0
fix = 0
var = []
for i in range(len(dd)):
    fix += heapq.heappop(dd[i]) * -1
    while len(dd[i]) > 0:
        tmp = heapq.heappop(dd[i]) * -1
        heapq.heappush(var, tmp)
    while len(var) > K-i-1:
        heapq.heappop(var)
    if len(var) == K-i-1:
        ans = max(ans , fix+sum(var) + (i+1)**2)

print(ans)