Buggy python submission (verdict: Runtime Error):
from heapq import nlargest

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dp[i | b] = nlargest(2, dp[i] + dp[i | b])

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a)
    ans.append(tmp)
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Runtime Error):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dp[i | b] = nlargest(2, dp[i] + dp[i | b])
    dp[b] = nlargest(2, dp[0] + dp[b])

ans = list(accumulate(map(sum, dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Runtime Error):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
mask = n2 - 1
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        dp[i | b] = nlargest(2, dp[i] + dp[i | b])
        i = (i - 1) & c
    dp[b] = nlargest(2, dp[0] + dp[b])

ans = list(accumulate(map(sum, dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
mask = n2 - 1

a0 = aaa[0]
dp = [[0, a] for a in aaa]

for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        dp[i | b] = nlargest(2, dp[i] + dp[i | b])
        i = (i - 1) & c
    dp[b] = nlargest(2, dp[0] + dp[b])

ans = list(accumulate(map(sum, dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Runtime Error):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
aaa_get = aaa.__getitem__
n2 = 1 << n
mask = n2 - 1

dp = [[i, 0] for i in range(n2)]
for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        dp[i | b] = nlargest(2, set(dp[i] + dp[i | b]), key=aaa_get)
        i = (i - 1) & c

ans = list(accumulate(map(lambda x: sum(map(aaa_get, x)), dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split()))
aaa_get = aaa.__getitem__
n2 = 1 << n
mask = n2 - 1

dp = [[i, 0] for i in range(n2)]
for j in range(n):
    b = 1 << j
    c = i = mask ^ b
    while i:
        dp[i | b] = nlargest(2, set(dp[i] + dp[i | b]), key=aaa_get)
        i = (i - 1) & c

ans = list(accumulate(map(lambda x: sum(map(aaa_get, x)), dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split())) + [0]
aaa_get = aaa.__getitem__
n2 = 1 << n

dp = [[i, -1] for i in range(n2)]
for j in range(n):
    b = 1 << j
    for i in range(n2):
        if (i & b) == 0:
            dp[i | b] = nlargest(2, set(dp[i] + dp[i | b]), key=aaa_get)
ans = list(accumulate(map(lambda x: sum(map(aaa_get, x)), dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Runtime Error):
from heapq import nlargest
from itertools import accumulate

n = int(input())
aaa = list(map(int, input().split())) + [0]
aaa_get = aaa.__getitem__
n2 = 1 << n

dp = [[i, -1] for i in range(n2)]
for j in range(n):
    b = 1 << j
    for i in range(n2):
        if (i & b) == 0:
            dp[i | b] = nlargest(2, {*dp[i], *dp[i | b]}, key=aaa_get)
ans = list(accumulate(map(lambda x: sum(map(aaa_get, x)), dp[1:]), func=max))
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)

Buggy python submission (verdict: Time Limit Exceeded):
from operator import itemgetter

import numpy as np

n = int(input())
aaa = list(enumerate(map(int, input().split())))
n2 = 1 << n
arr = np.arange(n2, dtype=np.uint)
bit = np.zeros(n, dtype=np.uint)
mat = np.zeros((n, n2))
for i in range(n):
    b = 1 << i
    bit[i] = b
    mat[i] = (arr & b) > 0
count = np.zeros(n2, dtype=np.uint8)
ans = np.zeros(n2, dtype=np.uint)
aaa.sort(reverse=True, key=itemgetter(1))
for i, a in aaa:
    idx = mat[(bit & i).astype(bool)].all(axis=0) & (count < 2)
    ans[idx] += a
    count[idx] += 1
ans = np.maximum.accumulate(ans[1:])
print(*ans)


Fixed submission:
n = int(input())
aaa = list(map(int, input().split()))
n2 = 1 << n
dp = [[a, 0] for a in aaa]

for j in range(n):
    b = 1 << j
    for i in range(n2):
        if not i & b:
            dpi, dpk = dp[i], dp[i | b]
            if dpk[0] < dpi[0]:
                dpk[1] = max(dpk[0], dpi[1])
                dpk[0] = dpi[0]
            elif dpk[1] < dpi[0]:
                dpk[1] = dpi[0]

ans = []
tmp = 0
for a in dp[1:]:
    tmp = max(tmp, a[0] + a[1])
    ans.append(tmp)
print(*ans)