Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(3*10**5)

n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
mod = 10 ** 9 + 7
def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

N = 10 ** 5 + 10
fact = [0] * (N)
fact[0] = 1
for i in range(1, N):
    fact[i] = (fact[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(fact[a], fact[a-b]), fact[b])

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

d = [{} for _ in range(n)]

def dfs(v, p):
    if p in d[v]:
        return d[v][p]
    num, count = 0, 1
    for next in connect[v]:
        if next != p:
            i, c = dfs(next, v)
            num += i
            count *= c
            count %= mod
            count *= comb(num, i)
            count %= mod
    num += 1
    d[v][p] = num, count
    return num, count

for i in range(n):
    dfs(i, -1)
    print(d[i][-1][1])

Fixed submission:
s = input()

if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(C):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)

Fixed submission:
X, Y, A, B, C = map(int, input().split())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
R = list(map(int, input().split()))

P.sort(reverse=True)
Q.sort(reverse=True)
R.sort(reverse=True)

a = sorted(P[:X] + Q[:Y])
ans = sum(a)

for i in range(min(X+Y, C)):
    if a[i] < R[i]:
        ans += R[i] - a[i]

print(ans)
Buggy python submission (verdict: Runtime Error):
n = list(map(int, list(input())))
k = int(input())

# 上の桁からDP
# 大きさが微妙な場合は分ける
# dp[桁][0の個数]

def solve(n, k):
    if k == 0:
        return 1
    dp = [[0 for _ in range(k+1)] for _ in range(len(n))]
    dp[0][0] = 1
    dp[0][1] = n[0] - 1
    for i in range(len(n) - 1):
        for j in range(k + 1):
            if j == 0:
                dp[i+1][0] = dp[i][0]
            else:
                dp[i+1][j] = dp[i][j-1] * 9 + dp[i][j]
    # first non-0
    i = 1
    while i < len(n) and n[i] == 0:
        i += 1
    return dp[len(n) - 1][k] + solve(n[i:], k-1)

print(solve(n, k))

Fixed submission:
n = list(map(int, list(input())))
k = int(input())

# 上の桁からDP
# 大きさが微妙な場合は分ける
# dp[桁][0の個数]

def solve(n, k):
    if k == 0:
        return 1
    if n == []:
        return 0
    dp = [[0 for _ in range(k+1)] for _ in range(len(n))]
    dp[0][0] = 1
    dp[0][1] = n[0] - 1
    for i in range(len(n) - 1):
        for j in range(k + 1):
            if j == 0:
                dp[i+1][0] = dp[i][0]
            else:
                dp[i+1][j] = dp[i][j-1] * 9 + dp[i][j]
    # first non-0
    i = 1
    while i < len(n) and n[i] == 0:
        i += 1
    return dp[len(n) - 1][k] + solve(n[i:], k-1)

print(solve(n, k))
Buggy python submission (verdict: Runtime Error):
u, l, d, r = map(int, input().split())
mod = 10 ** 9 + 7

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

f = [0] * (2 * 10 ** 6 + 2)
f[0] = 1
for i in range(1, 2 * 10 ** 6 + 2):
    f[i] = (f[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(f[a+b], f[a]), f[b])

ans = 0
d += 1
r += 1
ans += comb(d, r)
ans += comb(u, l)
ans -= comb(d, l)
ans -= comb(u, r)
print(ans % mod)

Fixed submission:
u, l, d, r = map(int, input().split())
mod = 10 ** 9 + 7

def extGCD(a, b):
    if b == 0:
        return a, 1, 0
    g, y, x = extGCD(b, a%b)
    y -= a//b * x
    return g, x, y

def moddiv(a, b):
    _, inv, _ = extGCD(b, mod)
    return (a * inv) % mod

f = [0] * (2 * 10 ** 6 + 10)
f[0] = 1
for i in range(1, 2 * 10 ** 6 + 10):
    f[i] = (f[i-1] * i) % mod

def comb(a, b):
    return moddiv(moddiv(f[a+b], f[a]), f[b])

ans = 0
d += 1
r += 1
ans += comb(d, r)
ans += comb(u, l)
ans -= comb(d, l)
ans -= comb(u, r)
print(ans % mod)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
score = list(map(int, input().split()))
t = input()
hand = 'rsp'

d = {'': 0}
for i in range(n):
    h = hand.index(t[i])
    dd = {}
    for s, x in d.items():
        for j in range(3):
            if i < k or s[0] != hand[j]:
                point = 0
                if (j - h) % 3 == 2:
                    point = score[j]
                if k == 1:
                    news = hand[j]
                else:
                    news = s[-k+1:] + hand[j]
                if news in dd:
                    dd[news] = max(dd[news], x + point)
                else:
                    dd[news] = x + point
    d = dd
print(max(d.values()))

Fixed submission:
n, k = map(int, input().split())
score = list(map(int, input().split()))
t_str = input()
hand = 'rsp'
t = []
for x in t_str:
    t.append(hand.index(x))

ans = 0
for r in range(k):
    d = [0] * 3
    for h in t[r::k]:
        dd = [0] * 3
        for i in range(3):
            for j in range(3):
                if i != j:
                    point = 0
                    if (j - h) % 3 == 2:
                        point = score[j]
                    dd[j] = max(dd[j], d[i] + point)
        d = dd
    ans += max(d)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, u, v = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

du = [0] * n
dv = [0] * n

def dfs(v, dis, ng, d):
    d[v] = dis
    ng.add(v)
    for w in connect[v]:
        if w not in ng:
            dfs(w, dis+1, ng, d)

dfs(u, 0, set(), du)
dfs(v, 0, set(), dv)

print(du)
print(dv)
ans = 0
for i in range(n):
    if du[i] < du[i]:
        ans = max(ans, du[v]-1)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(2*10**5)

n, u, v = map(int, input().split())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]
u -= 1
v -= 1

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

du = [0] * n
dv = [0] * n

def dfs(v, dis, ng, d):
    d[v] = dis
    ng.add(v)
    for w in connect[v]:
        if w not in ng:
            dfs(w, dis+1, ng, d)

dfs(u, 0, set(), du)
dfs(v, 0, set(), dv)

ans = 0
for i in range(n):
    if du[i] < dv[i]:
        ans = max(ans, dv[i]-1)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
law = 10 ** 9 + 7

bitsum = [0 for _ in range(60)]
for x in a:
    for i in range(60):
        bitsum[i] += bool(x & (1 << i))

ans = 0
for x in a:
    for i in range(60):
        k = bitsum[i]
        if (x & (1 << i)):
            k = n - k
        ans += k << i
        ans %= law
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + law) // 2)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
law = 10 ** 9 + 7

bitsum = [0 for _ in range(60)]
for x in a:
    for i in range(60):
        bitsum[i] += bool(x & (1 << i))

ans = 0
for x in a:
    for i in range(60):
        k = bitsum[i]
        if (x & (1 << i)):
            k = n - k
        ans += k << i
    ans %= law
if ans % 2 == 0:
    print(ans // 2)
else:
    print((ans + law) // 2)
Buggy python submission (verdict: Runtime Error):
s = input()
if s == 'SUN':
    return 7
if s == 'MON':
    return 1
if s == 'TUE':
    return 2
if s == 'WED':
    return 3
if s == 'THU':
    return 4
if s == 'FRI':
    return 5
if s == 'SAT':
    return 6

Fixed submission:
s = input()
if s == 'SUN':
    print(7)
if s == 'MON':
    print(6)
if s == 'TUE':
    print(5)
if s == 'WED':
    print(4)
if s == 'THU':
    print(3)
if s == 'FRI':
    print(2)
if s == 'SAT':
    print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
edges = [tuple(map(int, input().split())) for _ in range(n-1)]

color = {}
C = 0
forbidden = [set() for _ in range(n+1)]
for a, b in sorted(edges):
    for c in range(n):
        if c not in forbidden[a] and c not in forbidden[b]:
            forbidden[a].add(c)
            forbidden[b].add(c)
            color[(a, b)] = c
            C = max(C, c)
            break

print(C + 1)
for a, b in edges:
    print(color[(a, b)] + 1)

Fixed submission:
n = int(input())
edge = [tuple(map(int, input().split())) for _ in range(n-1)]

connect = [set() for _ in range(n)]
for a, b in edge:
    connect[a-1].add(b-1)
    connect[b-1].add(a-1)

ans = {(-1, 0): -1}
que = {(-1, 0)}
while que:
    queque = set()
    for p, v in que:
        c = 1
        for w in connect[v]:
            if w != p:
                if c == ans[(p, v)]:
                    c += 1
                ans[(v, w)] = c
                queque.add((v, w))
                c += 1
    que = queque
pri = [0] * (n-1)
for i, (a, b) in enumerate(edge):
    a -= 1
    b -= 1
    if (a, b) in ans:
        pri[i] = ans[(a, b)]
    else:
        pri[i] = ans[(b, a)]
print(max(pri))
for x in pri:
    print(x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

l.sort()

import bisect
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])

print(ans)

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

l.sort()

import bisect
ans = 0
for i in range(n):
    for j in range(i+1, n):
        ans += bisect.bisect_left(l[j+1:], l[i] + l[j])

print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int, input().split()))

a = []
a.append(b[0])
for i in range(n-2):
    a.append(min(b[i], b[i+1]))
a.append(b[n-2])
print(sum(a))

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

ac = 1
ans = 0
while ac < b:
    ans += 1
    ac += a - 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
work = [tuple(map(int, input().split())) for _ in range(n)]
work.sort(key = lambda x: (x[1], -x[0]), reverse = True)
do = [0] * (m+1)
money = 0
for a, b in work:
    if a > m:
        continue
    while do[a] != 0:
        a += 1
        if a > m:
            break
    if a > m:
        continue
    do[a] = 1
    money += b
print(money)

Fixed submission:
import bisect as bi
n, m = map(int, input().split())
work = [tuple(map(int, input().split())) for _ in range(n)]
work.sort(key = lambda x: (x[1], -x[0]), reverse = True)
ava = list(range(0, m+1))
money = 0
for a, b in work:
    if a > m:
        continue
    l = bi.bisect_left(ava, a)
    if l >= len(ava):
        continue
    del ava[l]
    money += b
print(money)
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
dp = [0] * 13
dp[0] = 1
for c in s:
    old = dp.copy()
    for i in range(13):
        dp[i] = 0
    if c == '?':
        for n in range(10):
            for i in range(13):
                dp[(i * 10 + n) % 13] += old[i]
    else:
        n = int(c)
        for i in range(13):
            dp[(i * 10 + n) % 13] += old[i]
    for i in range(13):
        dp[i] %= 10 ** 9 + 7
print(dp[5])

Fixed submission:
s = input()
dp = [0] * 13
dp[0] = 1
for c in s:
    new = [0] * 13
    if c == '?':
        for n in range(10):
            for i in range(13):
                new[(i * 10 + n) % 13] += dp[i]
    else:
        n = int(c)
        for i in range(13):
            new[(i * 10 + n) % 13] += dp[i]
    for i in range(13):
        new[i] %= 10 ** 9 + 7
    dp = new
print(dp[5])
Buggy python submission (verdict: Runtime Error):
s = set(input())
ans = True
for i in range(3):
    ans = ans and (s[i] != s[i+1])
if ans: print('Good')
else: print('Bad')

Fixed submission:
s = input()
ans = True
for i in range(3):
    ans = ans and (s[i] != s[i+1])
if ans: print('Good')
else: print('Bad')
Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())
field = [input() for _ in range(h)]

hor = [[0 for _ in range(w)] for _ in range(h)]
ver = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if field[i][j] == '#':
            for k in range(j-count, j):
                hor[i][k] = count
            count = 0
            hor[i][j] = 0
        else:
            count += 1
    for k in range(w-count, w):
        hor[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if field[i][j] == '#':
            for k in range(i-count, i):
                ver[k][j] = count
            count = 0
            ver[i][j] = 0
        else:
            count += 1
    for k in range(h-count, h):
        ver[k][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hor[i][j] + ver[i][j] - 1)
print(ans)

Fixed submission:
h, w = map(int, input().split())
field = [input() for _ in range(h)]

hor = [[0 for _ in range(w)] for _ in range(h)]
ver = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if field[i][j] == '#':
            for k in range(j-count, j):
                hor[i][k] = count
            count = 0
            hor[i][j] = 0
        else:
            count += 1
    for k in range(w-count, w):
        hor[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if field[i][j] == '#':
            for k in range(i-count, i):
                ver[k][j] = count
            count = 0
            ver[i][j] = 0
        else:
            count += 1
    for k in range(h-count, h):
        ver[k][j] = count

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hor[i][j] + ver[i][j] - 1)
print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(k+1):
    r = k - l
    leftmax = 0 
    for take in range(l+1):
        ava = sorted(v[:take])
        value = sum(ava)
        for back in range(min(take, l - take, n)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        leftmax = max(leftmax, value)
    rightmax = 0
    for take in range(r+1):
        ava = sorted(v[n-take:])
        value = sum(ava)
        for back in range(min(take, r - take, n)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        rightmax = max(rightmax, value)
    maxvalue = max(maxvalue, leftmax + rightmax)
print(maxvalue)

Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(n+1):
    for r in range(l, n+1):
        ava = sorted(v[:l] + v[r:])
        takeop = len(ava)
        if takeop <= k:
            value = sum(ava)
            for i in range(min(takeop, k - takeop)):
                if ava[i] >= 0:
                    break
                else:
                    value -= ava[i]
            maxvalue = max(maxvalue, value)
print(maxvalue)

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(k+1):
    r = k - l
    leftmax = 0 
    for take in range(l+1):
        ava = sorted(v[:take])
        value = sum(ava)
        for back in range(min(take, l - take)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        leftmax = max(leftmax, value)
    rightmax = 0
    for take in range(r+1):
        ava = sorted(v[n-take:])
        value = sum(ava)
        for back in range(min(take, r - take)):
            if ava[back] >= 0:
                break
            else:
                value -= ava[back]
        rightmax = max(rightmax, value)
    maxvalue = max(maxvalue, leftmax + rightmax)
print(maxvalue)

Fixed submission:
n, k = map(int, input().split())
v = list(map(int, input().split()))
maxvalue = 0
for l in range(n+1):
    for r in range(l, n+1):
        ava = sorted(v[:l] + v[r:])
        takeop = len(ava)
        if takeop <= k:
            value = sum(ava)
            for i in range(min(takeop, k - takeop)):
                if ava[i] >= 0:
                    break
                else:
                    value -= ava[i]
            maxvalue = max(maxvalue, value)
print(maxvalue)
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])

Fixed submission:
n, k = map(int, input().split())
s = input()
for i in range(n):
    if i == k - 1:
        print(s[i].lower(), end = '')
    else:
        print(s[i], end = '')
Buggy python submission (verdict: Runtime Error):
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    print(u, c)
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5)
n = int(input())
color = [-1] * n
neighbor = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = tuple(map(int, input().split()))
    neighbor[u - 1].append((v-1, w))
    neighbor[v - 1].append((u-1, w))
def col(u, c):
    color[u] = c
    for v, w in neighbor[u]:
        if color[v] < 0:
            col(v, (c + w) % 2)
col(0, 0)
for i in range(n):
    print(color[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
b = list(map(int, input().split()))
ans = []
def dfs(x):
    if x == []:
        return True
    ret = False
    for i, a in enumerate(x):
        if i + 1 == a:
            ret = dfs(x[:i] + x[i+1:])
            if ret:
                ans.append(a)
                break
    return ret
if dfs(b):
    for a in ans:
        print(a)
else:
    print(-1)

Fixed submission:
n = int(input())
b = list(map(int, input().split()))
ans = []
for k in range(n):
    for i in reversed(range(n - k)):
        a = b[i]
        if i + 1 == a:
            ans.append(b.pop(i))
            break
if b != []:
    print(-1)
else:
    for a in reversed(ans):
        print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
place = [[] for _ in range(2 * 10 ** 5)]
for i in range(n):
    dp[i+1] = dp[i]
    for p in place[z[i] - 1]:
        dp[i+1] += dp[p]
    place[z[i] - 1].append(i)
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Fixed submission:
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
dpp = [0] * 2 * 10 ** 5
for i in range(n):
    dp[i+1] = dp[i] + dpp[z[i]-1]
    dpp[z[i]-1] += dp[i]
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
place = [set() for _ in range(2 * 10 ** 5)]
for i in range(n):
    dp[i+1] = dp[i]
    for p in place[z[i] - 1]:
        dp[i+1] += dp[p]
    place[z[i] - 1].add(i)
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Fixed submission:
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
dpp = [0] * 2 * 10 ** 5
for i in range(n):
    dp[i+1] = dp[i] + dpp[z[i]-1]
    dpp[z[i]-1] += dp[i]
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
place = {}
for i in range(n):
    dp[i+1] = dp[i]
    if z[i] not in place:
        place[z[i]] = {i}
    else:
        for p in place[z[i]]:
            dp[i+1] += dp[p]
        place[z[i]].add(i)
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])

Fixed submission:
n = int(input())
z = []
pre = 0
for _ in range(n):
    i = int(input())
    if i != pre:
        z.append(i)
    pre = i
n = len(z)
dp = [1] * (n+1)
dpp = [0] * 2 * 10 ** 5
for i in range(n):
    dp[i+1] = dp[i] + dpp[z[i]-1]
    dpp[z[i]-1] += dp[i]
    dp[i+1] %= 10 ** 9 + 7
print(dp[n])
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))
mintime = 10**20
for i in range(n-k+1):
    left = x[i]
    right = x[i+k-1]
    abss = (abs(left), abs(right))
    if left * right >= 0:
        mintime = min(mintime, max(abss))
    else:
        mintime = min(mintime, min(abss) * 2 + max(abss))
print(mintime)


Fixed submission:
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
inf = 10 ** 10
def dfs(k, a, b, c):
    if k == n:
        if 0 in (a,b,c):
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c) - 30
    ret = [0] * 4
    ret[0] = dfs(k+1, a + l[k], b, c) + 10
    ret[1] = dfs(k+1, a, b + l[k], c) + 10
    ret[2] = dfs(k+1, a, b, c + l[k]) + 10
    ret[3] = dfs(k+1, a, b, c)
    return min(ret)
print(dfs(0, 0, 0, 0))

Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))
mintime = 10**20
for i in range(n-k+1):
    left = x[i]
    right = x[i+k-1]
    abss = (abs(left), abs(right))
    if left * right >= 0:
        mintime = min(mintime, max(abss))
    else:
        mintime = min(mintime, min(abss) * 2 + max(abss))
print(mintime)


Fixed submission:
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]
inf = 10 ** 10
def dfs(k, a, b, c):
    if k == n:
        if 0 in (a,b,c):
            return inf
        return abs(A - a) + abs(B - b) + abs(C - c) - 30
    ret = [0] * 4
    ret[0] = dfs(k+1, a + l[k], b, c) + 10
    ret[1] = dfs(k+1, a, b + l[k], c) + 10
    ret[2] = dfs(k+1, a, b, c + l[k]) + 10
    ret[3] = dfs(k+1, a, b, c)
    return min(ret)
print(dfs(0, 0, 0, 0))