ZhenlongDai/ACPR huggingface dataset:
Problem: p02537
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
class SegTree:
	
	def __init__(self,size,func,init_val,undef):
		self.specSize = size
		self.datSize = 1
		self.compareFunc = func		
		self.INIT_VAL = init_val	
		self.UNDEFINED_VAL = undef	
		
		self.datSize = 2**size.bit_length()

		
		
		self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)]

	def update(self, i, val ):
		
		
		
		i += self.datSize
		self.datTree[i] = val
		while 1 < i:
			i >>= 1
			self.datTree[i] = self.compareFunc( self.datTree[i<<1|0], self.datTree[i<<1|1] )

	def query(self,a,b):
		return self.query_(a,b,1,0,self.datSize)

	def query_(self,a,b,i,l,r):
		
		ret = self.UNDEFINED_VAL

		a += self.datSize
		b += self.datSize
		while a < b:
			if b & 1:
				b -= 1
				ret = self.compareFunc(ret, self.datTree[b])

			if a & 1:
				ret = self.compareFunc(ret, self.datTree[a])
				a += 1

			a >>= 1; b >>= 1

		return ret

	def printTree(self):
		print(self.datTree)


def LongestSeaquence(A,K):
	N = len(A)
	lis = 0

	
	MAX_A = max(A)
	tree = SegTree(MAX_A+1,max,0,-1e18)
	

	for n in range(N):
		x = A[n]
		l = max(1,x-K)
		r = min(MAX_A,x+K)
		tree.update( x, tree.query(l,r+1)+1 )

	
	lis = tree.query(0,MAX_A+1)

	return lis

def main():
	N,K = map(int,input().split())
	A = [ int(input()) for _ in range(N)]

	print(LongestSeaquence(A,K))



if __name__ == "__main__":
	main()

Failing test case input:
8 0
0
2
4
0
5
6
13
7
4
4

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
class SegTree:
	
	def __init__(self,size,func,init_val,undef):
		self.specSize = size
		self.datSize = 1
		self.compareFunc = func		
		self.INIT_VAL = init_val	
		self.UNDEFINED_VAL = undef	
		
		self.datSize = 2**size.bit_length()

		
		
		self.datTree = [self.INIT_VAL for _ in range(2*self.datSize+1)]

	def update(self, i, val ):
		
		
		
		i += self.datSize
		self.datTree[i] = val
		while 1 < i:
			i >>= 1
			self.datTree[i] = self.compareFunc( self.datTree[i<<1|0], self.datTree[i<<1|1] )

	def query(self,a,b):
		return self.query_(a,b,0,0,self.datSize)

	def query_(self,a,b,i,l,r):
		
		ret = self.UNDEFINED_VAL

		a += self.datSize
		b += self.datSize
		while a < b:
			if b & 1:
				b -= 1
				ret = self.compareFunc(ret, self.datTree[b])

			if a & 1:
				ret = self.compareFunc(ret, self.datTree[a])
				a += 1

			a >>= 1; b >>= 1

		return ret

	def printTree(self):
		print(self.datTree)


def LongestSeaquence(A,K):
	N = len(A)
	lis = 0

	
	MAX_A = max(A)
	tree = SegTree(MAX_A+1,max,0,-1e18)
	

	for n in range(N):
		x = A[n]
		l = max(0,x-K)
		r = min(MAX_A,x+K)
		tmp = tree.query(l,r+1)+1
		tree.update( x, tmp )
		lis = max(lis, tmp)

	return lis

def main():
	N,K = map(int,input().split())
	A = [ int(input()) for _ in range(N)]

	print(LongestSeaquence(A,K))



if __name__ == "__main__":
	main()
Problem: p02549
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N,K=map(int,input().split())
x=998244353
S=[]
for i in range(K):
    l,r=map(int,input().split())
    S.append(l)
    S.append(r)
S=list(set(S))
dp=[0 for i in range(N)]
print(S)
for i in range(N):
    for j in range(len(S)):
        if(i-S[j]>0):
            dp[i]+=dp[i-S[j]]
            dp[i]=dp[i]%x
        elif(i-S[j]==0):
            dp[i]+=1
            dp[i]=dp[i]%x
print(dp)

Failing test case input:
10 2
1 2
5 4

Expected output:
55


Actual output:
[1, 2, 4, 5]
[0, 1, 2, 3, 6, 11, 20, 36, 65, 118]


Fixed submission (verdict: Accepted):
N,K=map(int,input().split())
x=998244353
dp=[0 for i in range(N)]
sdp=[0 for i in range(N)]
L=[]
R=[]
dp[0]=1
sdp[0]=1
for i in range(K):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r) 
for i in range(1,N):
    for j in range(K):
        dp[i]+=(sdp[max(i-L[j],-1)]-sdp[max(i-R[j]-1,-1)])
        dp[i]%=x
    sdp[i]=(sdp[i-1]+dp[i])%x
print(dp[-1]%x)

Problem: p02549
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
mod = 998244353


def main(N, S):
    dp = [0 if n != 0 else 1 for n in range(N)]     
    A = [0 if n != 0 else 1 for n in range(N)]      

    for i in range(1, N):   
        for l, r in S:  
            if i - l < 0:   
                break
            else:           
                dp[i] += A[i-l] - A[max(i-r-1, 0)]  
        dp[i] %= mod
        A[i] = (A[i-1] + dp[i]) % mod
    print(dp[-1])

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    S = {tuple(map(int, input().split())) for k in range(K)}
    S = sorted(list(S), key = lambda x:x[0])    
    main(N, S)

Failing test case input:
84 3
5 4
1 1
1 27

Expected output:
894733340


Actual output:
0


Fixed submission (verdict: Accepted):
mod = 998244353


def main(N, S):
    dp = [0 if n != 0 else 1 for n in range(N)]     
    A = [0 if n != 0 else 1 for n in range(N)]      

    for i in range(1, N):   
        for l, r in S:  
            if i - l < 0:   
                break
            else:           
                dp[i] += A[i-l] - A[max(i-r, 0)-1]  
        dp[i] %= mod
        A[i] = (A[i-1] + dp[i]) % mod
    print(dp[-1])

if __name__ == '__main__':
    N, K = list(map(int, input().split()))
    S = {tuple(map(int, input().split())) for k in range(K)}
    S = sorted(list(S), key = lambda x:x[0])    
    main(N, S)
Problem: p02549
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
lr = [IL() for i in range(K)]
lr.sort()

dp = [0]*(N+1)
dp[1] = 1
data = [0]*(N+1)
data[1] = 1

for i in range(2,N+1):
  tmp = 0
  for l,r in lr:
    if tmp >= r:
      continue
    elif l <= tmp < r:
      l = tmp+1
    if 1 <= i-l:
      dp[i] += data[i-l] - data[max(i-r-1, 0)]
  data[i] = (data[i-1] + dp[i]) %mod
print(dp[N])

Failing test case input:
60 3
5 4
2 6
3 15

Expected output:
754365377


Actual output:
-243878976


Fixed submission (verdict: Accepted):
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 998244353
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
lr = [IL() for i in range(K)]
lr.sort()

dp = [0]*(N+1)
dp[1] = 1
data = [0]*(N+1)
data[1] = 1

for i in range(2,N+1):
  tmp = 0
  for l,r in lr:
    if tmp >= r:
      continue
    elif l <= tmp < r:
      l = tmp+1
    if 1 <= i-l:
      dp[i] += data[i-l] - data[max(i-r-1, 0)]
  data[i] = (data[i-1] + dp[i]) %mod
print(dp[N] %mod)

Problem: p02549
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, K = map(int, input().split())

DP = [0]*(N+1)
DP[1] = 1

S = []
for i in range(K):
    S.append(list(map(int, input().split())))

for i in range(2, N+1):
    for l, r in S:
            DP[i] += (DP[max(i-r, 0)] - DP[max(i-l-1, 0)])%998244353
    DP[i] += DP[i-1]

print(DP[N]%998244353)

Failing test case input:
50 3
5 4
1 3
1 20

Expected output:
465231607


Actual output:
829714759


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())

DP = [0]*(N+1)
DP[1] = 1

S = []
for i in range(K):
    S.append(list(map(int, input().split())))

for i in range(2, N+1):
    for l, r in S:
            DP[i] += (DP[max(i-l, 0)] - DP[max(i-r-1, 0)])
    DP[i] += DP[i-1]
    DP[i] %= 998244353

print((DP[N] - DP[N-1])%998244353)
Problem: p02549
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

n, k = list(map(int, input().split()))
s = list()
for i in range(k):
     l, r = list(map(int, input().split()))
     s.append((l, r))

mod = 998244353
i = 1
dp = [0] * (n+1)
dp[1] = 1
dpsum = [0] * (n+1)
dpsum[1] = 1
for i in range(2, n+1):
    for l, r in s:
        li = i-r
        ri = i-l
        if ri < 1: continue
        li = max(li, 1)
        dp[i] += dpsum[ri] - dpsum[li-1]
    dpsum[i] = (dpsum[i-1] + dp[i]) % mod
    
print(dp[n])


Failing test case input:
84 3
5 4
1 3
1 20

Expected output:
613452135


Actual output:
-1383036571


Fixed submission (verdict: Accepted):

n, k = list(map(int, input().split()))
s = list()
for i in range(k):
     l, r = list(map(int, input().split()))
     s.append((l, r))

mod = 998244353
i = 1
dp = [0] * (n+1)
dp[1] = 1
dpsum = [0] * (n+1)
dpsum[1] = 1
for i in range(2, n+1):
    for l, r in s:
        li = i-r
        ri = i-l
        if ri < 1: continue
        li = max(li, 1)
        dp[i] = (dp[i] + dpsum[ri] - dpsum[li-1]) % mod
    dpsum[i] = (dpsum[i-1] + dp[i]) % mod
    
print(dp[n])

Problem: p02549
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n, k = map(int, input().split())
cum = [0, 1]
dp = [0, 1]

lr = [list(map(int, input().split())) for _ in range(k)]    
mod = 998244353

def check(i):
    res = 0
    for l, r in lr:
        if i - l < 1:
            break
        res += cum[i-l] - cum[max(i-r-1,0)]
        res %= mod
    return res


for i in range(2,n+1):
    dp.append(check(i))
    cum.append((cum[-1]+dp[-1])%mod)

print(dp[-1])

Failing test case input:
84 3
5 4
1 2
1 27

Expected output:
282478460


Actual output:
75035283


Fixed submission (verdict: Accepted):
n, k = map(int, input().split())
cum = [0, 1]
dp = [0, 1]

lr = [list(map(int, input().split())) for _ in range(k)]    
mod = 998244353

def check(i):
    res = 0
    for l, r in lr:
        if i - l < 1:
            continue
        res += cum[i-l] - cum[max(i-r-1,0)]
        res %= mod
    return res


for i in range(2,n+1):
    dp.append(check(i))
    cum.append((cum[-1]+dp[-1])%mod)

print(dp[-1])
Problem: p02549
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def resolve():
    n, k = map(int, input().split())
    S = []
    for _ in range(k):
        l1, r1 = map(int, input().split())
        S.append(l1)
        S.append(r1)
    S = list(set(S))

    dp = [[0 for i in range(n + 1)] for j in range(len(S) + 1)]
    for i in range(len(S) + 1):
        dp[i][1] = 1
    for i in range(1, len(S) + 1):
        for j in range(2, n + 1):
            if j - S[i - 1] >= 0 and dp[i][j - S[i - 1]] > 0:
                dp[i][j] = dp[i][j - S[i - 1]] + dp[i - 1][j]
            else:
                dp[i][j] = dp[i - 1][j]

    print(dp[-1][n] % 998244353)

resolve()


Failing test case input:
10 1
1 0
7 17

Expected output:
0


Actual output:
1


Fixed submission (verdict: Accepted):
def resolve():
    n, k = map(int, input().split())
    S = []
    L, R = [], []
    for _ in range(k):
        l1, r1 = map(int, input().split())
        L.append(l1)
        R.append(r1)

    dp = [0 for i in range(n + 1)]
    dpsum = [0 for i in range(n + 1)]
    dp[1] = 1
    dpsum[1] = 1
    for i in range(2, n + 1):
        for j in range(k):
            Li = i - R[j]
            Ri = i - L[j]
            if Ri < 0:
                continue
            Li = max(1, Li)
            dp[i] += dpsum[Ri] - dpsum[Li - 1]  
            dp[i] %=  998244353

        dpsum[i] = (dpsum[i - 1] + dp[i]) % 998244353

    print(dp[n])

resolve()

Problem: p02549
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N, K = map(int, input().split())

L = []
R = []

for _ in range(K):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
  
dp = [0]*(N+5)
dp[1] = 1

for i in range(2, N+1):
  dp[i] = dp[i-1]
  for j in range(K):
    if i-L[j] >= 0:
      dp[i] += dp[i-L[j]]
    if i-R[j]-1 >= 0:
      dp[i] -= dp[i-R[j]-1]
    dp[i] %= 998244353
    
print(dp[N]-dp[N-1])

Failing test case input:
93 3
4 4
3 4
1 5

Expected output:
754902149


Actual output:
-243342204


Fixed submission (verdict: Accepted):
N, K = map(int, input().split())

L = []
R = []

for _ in range(K):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
  
dp = [0]*(N+5)
dp[1] = 1

for i in range(2, N+1):
  dp[i] = dp[i-1]
  for j in range(K):
    if i-L[j] >= 0:
      dp[i] += dp[i-L[j]]
    if i-R[j]-1 >= 0:
      dp[i] -= dp[i-R[j]-1]
    dp[i] %= 998244353
    
print((dp[N]-dp[N-1])%998244353)
Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=int(input())
a=[0]*2001
x=(10**9)+7
if s<3:
  print(0)
  exit()
  
elif 3<=x<6:
  for i in range(3,6):
    a[i]=1
    
else:
  for i in range(6,2001):
    a[i]=(sum(a[3:i-2])+1)%(x)

print(a[s])
  

Failing test case input:
1175

Expected output:
531468532


Actual output:
248010664


Fixed submission (verdict: Accepted):
s=int(input())
a=[0]*2001
x=(10**9)+7
if s<3:
    print(0)
    exit()

    
else:

    for i in range(3,6):
        a[i]=1

    for i in range(6,2001):
        a[i]=(sum(a[3:i-2])+1)%(x)

print(a[s])

Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = int(input())

table = [1, 0, 0]
for i in range(s):
  table.append(table[i]+table[i+2])
print(table[s])

Failing test case input:
1729

Expected output:
294867501

Actual output:
20623129494060967456366223709273865563628093762746947890246341055212602771464188569813325316144677694087201739670918472849917544924566330064252812731523016425621144482930837956507880328589243453432111379713861047677638988102574174614354113225747243223940031366884262872309431202186642723


Fixed submission (verdict: Accepted):
s = int(input())
mod = 10**9+7
table = [1, 0, 0]
for i in range(s):
  table.append((table[i]+table[i+2])%mod)
print(table[s])

Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s=int(input())
a=[0]*(s+1)
a[0]=1
for i in range(3,s+1):
    a[i]=a[i-3]+a[i-1]
print(a[s])


Failing test case input:
1175

Expected output:
531468532


Actual output:
222082587837603619274593483203391180802037866641192048751248765122136742137783076324009281892235152635363849727350867532428947938145250190943173841430893752789035492017850556523457835441497662096


Fixed submission (verdict: Accepted):
s=int(input())
a=[0]*(s+1)
a[0]=1
mod=10**9+7
for i in range(3,s+1):
    a[i]=a[i-3]+a[i-1]
print(a[s]%mod)

Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = int(input())

a = [0] * 2000
a[0] = 0
a[1] = 0
a[2] = 1
a[3] = 1
a[4] = 1
a[5] = 2
k = 0
for i in range(6, S):
  for l in range(2, i-2):
    k += a[l]
  a[i] = 1 + k
  
p = a[S-1] % (10**9 + 7)
print(p)

Failing test case input:
1175

Expected output:
531468532


Actual output:
604218241


Fixed submission (verdict: Accepted):
S = int(input())

a = [0] * 2000
a[0] = 0
a[1] = 0
a[2] = 1
a[3] = 1
a[4] = 1
a[5] = 2

for i in range(6, S):
  k = 0
  for l in range(2, i-2):
    k += a[l]
  a[i] = 1 + k
  
p = a[S-1] % (10**9 + 7)
print(p)

Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S=int(input())
MOD=10**9+7
dp=[0]*(S+1)
dp[0]=1
for i in range(1,S+1):
    for j in range(0,S-2):
        dp[i]+=dp[j]
        dp[i]%=MOD
print(dp[S])

Failing test case input:
1175

Expected output:
531468532


Actual output:
245605920


Fixed submission (verdict: Accepted):
S=int(input())
MOD=10**9+7
dp=[0]*(S+1)
dp[0]=1
for i in range(1,S+1):
    for j in range(0,i-2):
        dp[i]+=dp[j]
        dp[i]%=MOD
print(dp[S])
Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
mod=10**9+7

S=int(input())
ans=0
L=[-1]*(S+1)

def f(n):
    if n==0:
        return 1
    elif n<0:
        return 0
    elif L[n]!=-1:
        return L[n]
    else:
        tmp=0
        for i in range(3,10):
            tmp+=f(n-i)
        L[n]=tmp%mod
        return L[n]
print(f(S))

Failing test case input:
1729

Expected output:
294867501

Actual output:
332215981


Fixed submission (verdict: Accepted):
mod=10**9+7

S=int(input())
ans=0
L=[-1]*(S+1)

def f(n):
    if n==0:
        return 1
    elif n<0:
        return 0
    elif L[n]!=-1:
        return L[n]
    else:
        tmp=0
        for i in range(3,n+1):
            tmp+=f(n-i)
        L[n]=tmp
        return tmp
print(f(S)%mod)

Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from math import comb
mod = 10**9 + 7
s = 1729
ans = 0
n = 1
while s - 2*n - 1 >= 0:
    ans += comb(s-2*n-1, n-1)
    ans %= mod
    n += 1
print(ans)

Failing test case input:
1175

Expected output:
531468532


Actual output:
294867501


Fixed submission (verdict: Accepted):
from math import comb
mod = 10**9 + 7
s = int(input())
ans = 0
n = 1
while s - 2*n - 1 >= 0:
    ans += comb(s-2*n-1, n-1)
    ans %= mod
    n += 1
print(ans)

Problem: p02555
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):

n = int(input())
mod = 10**9+7
dp = [0]*(n+1)
for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, 10):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])


Failing test case input:
1175

Expected output:
531468532


Actual output:
778758794


Fixed submission (verdict: Accepted):
n = int(input())
mod = 10**9+7
dp = [1]*(n+1)
if n <= 2:
    print(0)
    exit()
for i in range(3):
    dp[i] = 0

for j in range(3, 10):
    if j <= n:
        dp[j] = 1

for i in range(3, n+1):
    for j in range(3, n):
        if i+j <= n:
            dp[i+j] += dp[i]
            dp[i+j] %= mod
print(dp[-1])
Problem: p02555
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
from math import trunc
import sys
import copy
from collections import deque
import collections
import itertools
stdin = sys.stdin
import math

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()

max_div = n

if n < 3:
    print(0)
    exit(0)
elif n < 6:
    print(1)
    exit(0)
elif n < 9:
    print(n-4)
    exit(0)
    

s123 = [i for i in range(1, n-7)]

ans = n-4
for i in range(0, max_div-2):
    tmp = sum(s123[0:len(s123)-i*3])
    ans += tmp
    ans %= mod

print(ans)



Failing test case input:
1729

Expected output:
294867501

Actual output:
567853324


Fixed submission (verdict: Accepted):
from math import trunc
import sys
import copy
from collections import deque
import collections
import itertools
stdin = sys.stdin
import math

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

n = ni()

s = [0 for _ in range(2001)]
s[0] = 1
s[3] = 1
s[4] = 1
s[5] = 1

if n < 6:
    print(s[n])
    exit(0)

for i in range(6, 2001):
    s[i] = s[i-3] + s[i-1]
    s[i] %= mod
    if i==n:
        break

print(s[n])

Problem: p02555
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def resolve():
    mod = 10 ** 9 + 7
    s = int(input())
    dp = [0] * (s + 1)
    dp[s] = 1
    for i in range(s, 2, -1):
        dp[i] %= mod
        for j in range(3, 10):
            if i - j >= 0:
                dp[i - j] += dp[i]
    print(dp[0] % mod)


if __name__ == '__main__':
    resolve()


Failing test case input:
1175

Expected output:
531468532


Actual output:
778758794


Fixed submission (verdict: Accepted):
def resolve():
    mod = 10 ** 9 + 7
    s = int(input())
    dp = [0] * (s + 1)
    dp[s] = 1
    for i in range(s, 2, -1):
        dp[i] %= mod
        for j in range(3, i + 1):
            dp[i - j] += dp[i]
    print(dp[0] % mod)


if __name__ == '__main__':
    resolve()
Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
info = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    info[i] = [tuple(map(int, input().split())) for _ in range(a)]

ans = 0
for bit in range(1 << n):
    flag = True
    cnt = 0
    for i in range(n):
        if (bit >> i) & 1:
            t = 0
            cnt += 1
        else:
            t = 1
        for x, y in info[i]:
            b = (bit >> (x - 1)) & 1
            if b != abs(t - y):
                flag = False
                break
        if not flag:
            break
    if flag:
        ans = max(ans, cnt)

print(ans)


Failing test case input:
3
2
2 0
3 0
2
3 2
0 0
2
1 1
1 1

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
info = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    info[i] = [tuple(map(int, input().split())) for _ in range(a)]

ans = 0
for bit in range(1 << n):
    flag = True
    cnt = 0
    for i in range(n):
        if (bit >> i) & 1:
            cnt += 1
        else:
            continue

        for x, y in info[i]:
            b = (bit >> (x - 1)) & 1
            if b != y:
                flag = False
                break
        if not flag:
            break
    if flag:
        ans = max(ans, cnt)

print(ans)

Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = list()
xy = list()
flag = True
num = 0
output=0
for i in range(N):
  A.append(int(input()))
  xy.append([list(map(int,input().split())) for _ in range(A[i])])
for i in range(2**len(A)):
  flag = True
  num = str(format(i, 'b').zfill(len(A)))
  for j in range(len(A)):
    if ((i>>j)&1) == 1:
      for k in range(len(xy[len(A)-j-1])):
        if int(num[xy[len(A)-1-j][k][0]-1]) !=  xy[len(A)-1-j][k][1]:
          flag = False
    elif ((i>>j)&1) == 0:
      for k in range(len(xy[len(A)-j-1])):
        if int(num[xy[len(A)-1-j][k][0]-1]) ==  xy[len(A)-1-j][k][1]:
          flag = False
  if flag == True and output <= str(bin(i)).count('1') :
    output = str(bin(i)).count('1')
print(output)
        

Failing test case input:
3
2
2 0
3 0
2
3 1
1 0
2
1 1
0 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = list()
xy = list()
flag = True
num = 0
output=0
for i in range(N):
  A.append(int(input()))
  xy.append([list(map(int,input().split())) for _ in range(A[i])])
  
for i in range(2**N):
  flag = True
  num = str(format(i, 'b').zfill(N))
  for j in range(N):
    if ((i>>j)&1) == 1:
      for k in range(len(xy[N-j-1])):
        if int(num[xy[N-1-j][k][0]-1]) !=  xy[N-1-j][k][1]:
          flag = False
          break
    if flag == False:
      break
  if flag == True and output <= str(bin(i)).count('1') :
    output = str(bin(i)).count('1')
print(output)
Problem: p02837
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
evidence = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x,y = map(int,input().split())
    evidence[i].append((x-1,y))
result = 0
for j in range(1,2**N):
  consistent = True
  for k in range(N):
    if (j >> k) & 1 == 0:
      continue
    for x,y in evidence[k]:
      if (j >> x) & 1 != y:
        consistent = False
        break
    if not consistent:
      break
  else:
    result = max(result, bin(i)[2:].count("1"))
print(result)

Failing test case input:
3
1
3 1
1
2 1
0
1 0

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
N = int(input())
evidence = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x,y = map(int,input().split())
    evidence[i].append((x-1,y))
result = 0
for j in range(1,2**N):
  consistent = True
  for k in range(N):
    if (j >> k) & 1 == 0:
      continue
    for x,y in evidence[k]:
      if (j >> x) & 1 != y:
        consistent = False
        break
    if not consistent:
      break
  if consistent:
    result = max(result, bin(j)[2:].count("1"))
print(result)

Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

N=int(input())
xy =[[]for i in range(N)]
ans=0

for i in range(N):
    A=int(input())
    for j in range(A):
        x, y = map(int, input().split())
        xy[i].append((x,y))


for i in range(2**N):
    ans_kouho=0
    
    flag=1
    
    TorF=[0]*N
    for j in range(N):
        if (i>>j) & 1:
            TorF[j]=1

    for j in range(N):
        for k in range(len(xy[j])):
            
            if TorF[j]==0:
                if TorF[xy[j][k][0]-1]==xy[j][k][1]:
                    flag=-1
                    break
            else:
                if TorF[xy[j][k][0]-1]!=xy[j][k][1]:
                    flag=-1
                    break
    
    if flag==1:
        
        ans_kouho=TorF.count(1)
        if(ans<ans_kouho):
            ans=ans_kouho   
    
               
print(ans)  
        


Failing test case input:
3
2
2 0
3 0
2
2 2
2 0
2
1 1
2 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):

N=int(input())
xy =[[]for i in range(N)]
ans=0

for i in range(N):
    A=int(input())
    for j in range(A):
        x, y = map(int, input().split())
        xy[i].append((x,y))


for i in range(2**N):
    ans_kouho=0
    
    flag=1
    
    
    TorF=[0]*N
    for j in range(N):
        if (i>>j) & 1:
            TorF[j]=1

    for j in range(N):
        for k in range(len(xy[j])):
            
            if TorF[j]==1:
                if TorF[xy[j][k][0]-1]!=xy[j][k][1]:
                    flag=-1
                    break
    
    if flag==1:
        
        ans_kouho=TorF.count(1)
        if(ans<ans_kouho):
            ans=ans_kouho   
    
               
print(ans)
Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
    
for i in range(2**N):
  contradiction = False
  max_honest = 0
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      if not j+1 in honest_p:
      	honest_p.append(j+1)
      if not j+1 in doubt_honest_p:
      	doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          if not p in honest_p:
          	honest_p.append(p)
        else:
          if not p in unkind_p: 
          	unkind_p.append(p)
    else:
      if not j+1 in unkind_p:
        unkind_p.append(j+1)
      if not j+1 in doubt_unkind_p:
      	doubt_unkind_p.append(j+1)
  if len(list(set(honest_p) & set(unkind_p))) != 0:
    contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)

Failing test case input:
3
1
3 1
1
1 0
1
2 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
a = [[] for _ in range(N)]
for i in range(N):
  A_i = int(input())
  for j in range(A_i):
    a[i].append(list(map(int, input().split())))
 
max_honest = 0
for i in range(2**N):
  contradiction = False
  honest_p = []
  unkind_p = []
  doubt_honest_p = []
  doubt_unkind_p = []
  length = len(format(2**N-1, "b"))
  bin_num = format(i, "b").zfill(length)
  for j in range(length):
    if (i >> j) & 1:
      if not j+1 in honest_p:
      	honest_p.append(j+1)
      if not j+1 in doubt_honest_p:
      	doubt_honest_p.append(j+1)
      for k in a[j]:
        p = k[0]
        t = k[1]
        if t:
          if not p in honest_p:
          	honest_p.append(p)
        else:
          if not p in unkind_p: 
          	unkind_p.append(p)
    else:
      if not j+1 in unkind_p:
        unkind_p.append(j+1)
      if not j+1 in doubt_unkind_p:
      	doubt_unkind_p.append(j+1)
  if len(list(set(honest_p) & set(unkind_p))) != 0:
    contradiction = True
  if not contradiction and max_honest <= len(doubt_honest_p):
    max_honest = len(doubt_honest_p)
    
print(max_honest)
Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())

def trust_remark(i, r):
    
    people = [-1] * n
    people[i] = 1
    for x, y in r:
        people[x - 1] = y
    return people

def check(x, y):
    new_list = []
    for a, b in zip(x, y):
        if abs(a) != abs(b):
            return False
        else:
            new_list.append(max(a, b))
    return new_list

remarks = []
for i in range(n):
    a = int(input())
    r = [tuple(map(int, input().split())) for _ in range(a)]
    remarks.append(trust_remark(i, r))

dp = []
cnt_max = 0
for i, r_i in enumerate(remarks):
    if i in dp: continue
    cnt = 0
    tmp = [0] * i + r_i[i:]
    for j, r_j in enumerate(remarks[i:]):
        j += i
        if r_i[j] == 0: continue
        if check(tmp, r_j):
            tmp = check(tmp, r_j)
            cnt += 1
        elif r_i[j] == -1:
            tmp[j] = 0
            continue
        else:
            cnt = 0
            break
    if cnt != 0:
        for j, x in enumerate(tmp):
            if x == 1: dp.append(j)
        cnt_max = max(cnt, cnt_max)

print(cnt_max)

Failing test case input:
3
1
3 1
1
2 1
1
1 0

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())


def make_remark_list(i, r):
    
    people = [-1] * n
    people[i] = 1
    for x, y in r:
        people[x - 1] = y
    return people


def check(x, y):
    new_list = []
    for a, b in zip(x, y):
        a, b = min(a, b), max(a, b)
        if (a, b) == (0, 1):
            return False
        elif (a, b) == (-1, 0):
            new_list.append(0)
        else:
            new_list.append(max(a, b))
    return new_list


remarks = []
for i in range(n):
    a = int(input())
    r = [tuple(map(int, input().split())) for _ in range(a)]
    remarks.append(make_remark_list(i, r))

def max_count(r, cnt, i = 0):
    tmp = r
    for j, r_j in enumerate(remarks):
        if j < i: continue
        if tmp[j] == 0:
            continue
        elif tmp[j] == 1:
            if check(tmp, r_j):
                tmp = check(tmp, r_j)
                cnt += 1
            else:
                cnt = 0
                break
        else:
            tmp[j] = 1
            if check(tmp, r_j):
                cnt_1, tmp_1 = max_count(tmp, cnt, j)
                tmp[j] = 0
                cnt_0, tmp_0 = max_count(tmp, cnt, j)
                if cnt_0 > cnt_1:
                    return cnt_0, tmp_0
                else:
                    return cnt_1, tmp_1
            else:
                tmp[j] = 0
    return cnt, tmp

r = [-1] * n
cnt, r = max_count(r, 0)
print(cnt)
Problem: p02837
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N = int(input())
A = [dict() for _ in range(N)] 
for i in range(N):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    x -= 1
    A[i][x] = y


res = 0
for i in range(1,2 ** N):
  i_bin = bin(i)[2:]
  i_bin = i_bin.zfill(N)
  p = [0] * N
  for j in range(N):
    p[j] = int(i_bin[j])
  for j in range(N):
    x = i_bin[j]
    if x == '1':
      for k, v in A[j].items():
        p[k] = v
  
  
  isPossible = True
  for j in range(N):
    if int(i_bin[j]) != p[j]: 
      isPossible = False
      break
  if isPossible:
    res = max(res, sum(p))

print(res)

Failing test case input:
3
1
3 1
1
1 1
1
1 0

Expected output:
1


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = [dict() for _ in range(N)] 
for i in range(N):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    x -= 1
    A[i][x] = y


res = 0
for i in range(1,2 ** N):
  i_bin = bin(i)[2:]
  i_bin = i_bin.zfill(N)
  p = [0] * N
  for j in range(N):
    p[j] = int(i_bin[j])
  isPossible = True
  for j in range(N):
    x = i_bin[j]
    if x == '1':
      for k, v in A[j].items():
        if p[k] != v:
          isPossible = False
          break
  if isPossible:
    res = max(res, sum(p))

print(res)

Problem: p02837
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
ALL=[]
for i in range(N):
  A=int(input())
  XY=[]
  for k in range(A):
    x,y=map(int,input().split())
    XY+=[[x,y]]
  ALL+=[XY]
ans=0  
for i in range(2**N):
  people=[-1]*N
  anssub=0
  for k in range(N):
    if ((i >> k) & 1):
      if people[k]==1:
        people[k]=-2        
      people[k]=0
      anssub+=1
      for t in ALL[k]:
        if people[t[0]-1]!=t[1] and people[t[0]-1]!=-1:
          people[t[0]-1]=-2
        else:
          people[t[0]-1]=t[1]
    else:
      if people[k]==0:
        people[k]=-2
      people[k]=1  
      for t in ALL[k]:
        if t[1]==0:
          if people[t[0]-1]!=1 and people[t[0]-1]!=-1:
            people[t[0]-1]=-2
          else:
            people[t[0]-1]=1
        else:
          if people[t[0]-1]!=0 and people[t[0]-1]!=-1:
            people[t[0]-1]=-2
          else:
            people[t[0]-1]=0
  if not -2 in people:
    ans=max(ans,anssub)
print(ans)        

Failing test case input:
3
2
2 0
3 0
2
2 1
1 0
2
1 1
2 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N=int(input())
ALL=[]
for i in range(N):
  A=int(input())
  XY=[]
  for k in range(A):
    x,y=map(int,input().split())
    XY+=[[x,y]]
  ALL+=[XY]
ans=0  
for i in range(2**N):
  people=[-1]*N
  anssub=0
  for k in range(N):
    if ((i >> k) & 1):
      if people[k]==0 or people[k]==-2:
        people[k]=-2        
      else:
        people[k]=1
      anssub+=1
      for t in ALL[k]:
        if people[t[0]-1]!=t[1] and people[t[0]-1]!=-1:
          people[t[0]-1]=-2
        else:
          people[t[0]-1]=t[1]
    else:
      if people[k]==1 or people[k]==-2:
        people[k]=-2
      else:
        people[k]=0  
  if not -2 in people:
    ans=max(ans,anssub)
print(ans)
Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
list = [list() for _ in range(N)]

for i in range(N):
  a = int(input())
  for j in range(a):
    x,y = map(int,input().split())
    list[i].append([x,y])


ans = 0
for i in range(2**N):
    flg = False
    do = [0] * N
    for j in range(N):
      if ((i >> j) & 1):
        do[j] = 1
    
    P = [-1] * N
    for n in range(N):
      if flg:break
      for p in list[n]:
        if P[p[0]-1] == -1:
          
          
          if do[n] == 1:
            P[p[0]-1] = p[1]
          else:
            if p[1] == 1:
              P[p[0]-1] = 0
            else:
              P[p[0]-1] = 1
          if P[p[0]-1] != do[p[0]-1]:
            flg = True
        else:
          if P[p[0]-1] != do[p[0]-1]:
            flg = True
          
          
          elif do[n] == 1 and P[p[0]-1] != p[1]:
            flg = True
          elif do[n] == 0 and P[p[0]-1] == p[1]:
            flg = True
        if flg:break
    
    if flg:
      continue
    
    ans = max(ans,sum(do))
    
print(ans)





Failing test case input:
3
2
2 1
3 1
2
3 1
1 0
2
1 0
2 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
list = [list() for _ in range(N)]
if N == 1:
  print(1)
  exit()

for i in range(N):
  a = int(input())
  for j in range(a):
    x,y = map(int,input().split())
    list[i].append([x,y])

ans = 0
for i in range(2**N):
    flg = False
    do = [0] * N
    for j in range(N):
      if ((i >> j) & 1):
        do[j] = 1
    P = [-1] * N
    for n in range(N):
      if flg:break
      for p in list[n]:
        if P[p[0]-1] == -1:
          if do[n] == 1:
            P[p[0]-1] = p[1]
            if P[p[0]-1] != do[p[0]-1]:
              flg = True
          
          
          
          
          
        else:
          if do[n] == 1 and P[p[0]-1] != p[1]:
            flg = True
    if flg:
      continue
    ans = max(ans,sum(do))
print(ans)
Problem: p02837
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
testimony_list=[[[0,0] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y
print(testimony_list)

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	print(kind_l)
	for k in range(n):
		if kind_l[k]==1:
			for m in range(a):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if kind_l[subject]!=judge:
					kind_l=[0 for _ in range(n)]
					break
	ans=max(ans,sum(kind_l))
print(ans)

Failing test case input:
3
2
2 1
3 1
2
3 1
1 0
2
1 0
1 0

Expected output:
2


Actual output:
[[[1, 1], [2, 1]], [[2, 1], [0, 0]], [[0, 0], [0, 0]]]
[0, 0, 0]
[1, 0, 0]
[0, 1, 0]
[1, 1, 0]
[0, 0, 1]
[1, 0, 1]
[0, 1, 1]
[1, 1, 1]
2


Fixed submission (verdict: Accepted):
n=int(input())
testimony_list=[[[-1,0] for _ in range(n-1)] for i in range(n)]
for i in range(n):
	a=int(input())
	for j in range(a):
		x,y=map(int,input().split())
		testimony_list[i][j][0]=x-1
		testimony_list[i][j][1]=y

ans=0
for i in range(2**n):
	kind_l=[0 for _ in range(n)]
	for j in range(n):
		if ((i>>j) & 1):
			kind_l[j]=1
	flag=True
	for k in range(n):
		if kind_l[k]:
			for m in range(n-1):
				subject=testimony_list[k][m][0]
				judge=testimony_list[k][m][1]
				if subject==-1:continue
				if kind_l[subject]!=judge:
					flag=False
	if flag:
		ans=max(ans,sum(kind_l))
print(ans)
Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
from heapq import heappushpop

N = int(input())
A = [int(x) for x in input().split()]




B = []
for n,a in enumerate(A):
    arr = [(0,0),(a,n)]
    m = n
    while m:
        bit = m & (-m)
        (x,i),(y,j) = B[n-bit]
        heappushpop(arr,(x,i))
        heappushpop(arr,(y,j))
        m -= bit
    B.append(arr)

answer = [0]
for (x,i),(y,j) in B[1:]:
    z = answer[-1]
    if z < x + y:
        z = x + y
    answer.append(z)
print('\n'.join(map(str,answer[1:])))



Failing test case input:
3
12 210 47 33 0 9 17 66

Expected output:
222
222
257
257
257
257
276


Actual output:
222
222
257
257
257
257
420


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
from heapq import heappushpop

N = int(input())
A = [int(x) for x in input().split()]




B = []
for n,a in enumerate(A):
    arr = [(0,0),(a,n)]
    m = n
    while m:
        bit = m & (-m)
        (x,i),(y,j) = B[n-bit]
        if (x,i) != arr[-1]:
            heappushpop(arr,(x,i))
        if (y,j) != arr[-1]:
            heappushpop(arr,(y,j))
        m -= bit
    B.append(arr)

answer = [0]
for (x,i),(y,j) in B[1:]:
    z = answer[-1]
    if z < x + y:
        z = x + y
    answer.append(z)
print('\n'.join(map(str,answer[1:])))

Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
data=[[] for i in range(2**N)]
data[0]=[0,0]
if A[1]>A[0]:
    data[1]=[1,0]
else:
    data[1]=[0,1]
ans=[0]*2**N
ans[1]=sum(A[0:2])
for i in range(2,2**N):
    ans[i]=ans[i-1]
    h=[[A[i],i]]
    for j in range(N):
        if i&(1<<j)==0:
            continue
        else:
            kkk=i^(1<<j)
            num=data[kkk][0]
            uuu=[A[num],num]
            if not uuu in h:
                h.append(uuu)
            num=data[kkk][1]
            uuu=[A[num],num]
            if not uuu in h:
                h.append(uuu)
    h.sort(reverse=True)
    if h[0][0]+h[1][0]>ans[i]:
        ans[i]=h[0][0]+h[1][0]
        data[i]=[h[0][1],h[1][1]]
    else:
        data[i]=data[i-1][:]
for i in range(1,2**N):
    print(ans[i])

Failing test case input:
3
3 312 59 33 0 9 17 82

Expected output:
315
315
371
371
371
371
394


Actual output:
315
315
345
345
345
345
394


Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))+[0]

data=[[] for i in range(2**N)]

for i in range(1,2**N):
    for j in range(N):
        if i&(1<<j)==0:
            continue
        else:
            data[i].append(i-(1<<j))

MAX=[0]*2**N
semiMAX=[0]*2**N

semiMAX[0]=2**N

if MAX[0]<A[1]:
    MAX[1]=1
    semiMAX[1]=0
else:
    MAX[1]=0
    semiMAX[1]=1

K=[A[0]+A[1]]
for k in range(2,2**N):
    a,b=k,2**N
    for u in data[k]:
        c,d=MAX[u],semiMAX[u]
        if A[c]<=A[b]:
            c=c
        elif A[d]>=A[a]:
            a,b=c,d
        elif A[c]>A[a]:
            a,b=c,a
        elif A[a]>=A[c]>A[b] and a!=c:
            b=c
        elif A[a]>=A[d]>A[b] and a!=d:
            b=d
    MAX[k]=a
    semiMAX[k]=b
    K.append(max(K[-1],A[a]+A[b]))

for u in K:
    print(u)
Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
zeta = a[: ]
zeta2 = [0] * (1 << N)
for i in range(N):
  for j in range(1 << N):
    if (1 << i) & j:
      if zeta[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = zeta[j]
        zeta[j] = zeta[(1 << i) ^ j]
      elif zeta2[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = zeta[(1 << i) ^ j]

for i in range((1 << N) - 1):
  zeta[i + 1] = max(zeta[i + 1], zeta[i])
  zeta2[i + 1] = max(zeta2[i + 1], zeta2[i])

for i in range(1, 1 << N): print(zeta[i] + zeta2[i])

Failing test case input:
4
16 9 4 19 82 17 90 42 0 1 41 188 332 80 31 3

Expected output:
25
25
35
98
99
172
172
172
172
172
229
414
414
422
520


Actual output:
25
25
35
98
99
172
172
172
172
172
270
414
414
422
520


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
zeta = a[: ]
zeta2 = [0] * (1 << N)
for i in range(N):
  for j in range(1 << N):
    if (1 << i) & j:
      if zeta[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = max(zeta[j], zeta2[(1 << i) ^ j])
        zeta[j] = zeta[(1 << i) ^ j]
      elif zeta2[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = zeta[(1 << i) ^ j]

res = 0
for i in range(1, 1 << N):
  res = max(res, zeta[i] + zeta2[i])
  print(res)
Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



def cummax(it, first=-float('inf')):
    
    cm = first
    ret = []
    for v in it:
        cm = max(v, cm)
        ret.append(cm)
    return ret


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))



dp = [None] * (2 ** N)
for k in range(1, 2 ** N):
    dp[k] = (A[0], 0), (A[k], k)

digits = []
k = 1
while k < 2 ** N:
    digits.append(k)
    k <<= 1

for bit in range(2, N + 1):
    for ds in itertools.combinations(digits, bit):
        k = sum(ds)
        for rm in ds:
            pass
            
            
            
            

ans = [0] * (2 ** N)
for k in range(1, 2 ** N):
    (a1, _), (a2, _) = dp[k]
    ans[k] = a1 + a2

ans = cummax(ans[1:])
print(*ans, sep='\n')


Failing test case input:
4
7 2 0 1 19 3 25 34 -3 -2 43 215 11 6 28 1

Expected output:
9
9
9
26
26
44
59
59
59
59
258
258
258
258
258


Actual output:
9
9
9
26
26
32
41
41
41
50
222
222
222
222
222


Fixed submission (verdict: Accepted):
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7



def cummax(it, first=-float('inf')):
    
    cm = first
    ret = []
    for v in it:
        cm = max(v, cm)
        ret.append(cm)
    return ret


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))
SIZE = 2 ** N



dp = [None] * SIZE
for k in range(1, SIZE):
    dp[k] = list(sorted([(A[0], 0), (A[k], k)]))

for k in range(1, SIZE):
    mask = k
    while mask < SIZE - 1:
        
        next_k = (mask + 1) | k
        mask |= next_k

        a1, a2 = dp[k]
        b1, b2 = dp[next_k]
        if a1 > b2:
            
            dp[next_k] = dp[k]
        elif b1 > a2:
            
            pass
        elif a2 > b2:
            dp[next_k] = b2, a2
        elif b2 > a2:
            dp[next_k] = a2, b2

ans = [0] * SIZE
for k in range(1, SIZE):
    (a1, _), (a2, _) = dp[k]
    ans[k] = a1 + a2

ans = cummax(ans[1:])
print(*ans, sep='\n')
Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def max2(a, b, c, d):
    vals = sorted((a, b, c, d), reverse=True)
    return vals[0], vals[1]


n = int(input())
a = list(map(int, input().split()))

dp = [[0] * (1 << n) for i in range(n + 1)]
dq = [[0] * (1 << n) for i in range(n + 1)]
for i in range(1 << n):
    dp[0][i] = a[i]

for i in range(n):
    for bit_state in range(1 << n):
        if (1 << i) & bit_state:
            first, second = max2(dp[i][bit_state], dq[i][bit_state], dp[i][bit_state ^ (1 << i)], dq[i][bit_state ^ (1 << i)])
        else:
            first, second = dp[i][bit_state], dq[i][bit_state]
        dp[i + 1][bit_state], dq[i + 1][bit_state] = first, second
        
for i in range((1 << n) - 1):
    dp[-1][i + 1] = max(dp[-1][i + 1], dp[-1][i])
    dq[-1][i + 1] = max(dq[-1][i + 1], dq[-1][i])



for i in range(1, 1 << n):
    print(dp[-1][i] + dq[-1][i])

Failing test case input:
4
16 7 2 19 82 17 45 53 0 0 41 175 332 60 31 3

Expected output:
23
23
35
98
99
127
135
135
135
135
216
414
414
414
507


Actual output:
23
23
35
98
99
127
135
135
135
135
228
414
414
414
507


Fixed submission (verdict: Accepted):
def max2(a, b, c, d):
    vals = sorted((a, b, c, d), reverse=True)
    return vals[0], vals[1]


n = int(input())
a = list(map(int, input().split()))

dp = [[0] * (1 << n) for i in range(n + 1)]
dq = [[0] * (1 << n) for i in range(n + 1)]
for i in range(1 << n):
    dp[0][i] = a[i]

for i in range(n):
    for bit_state in range(1 << n):
        if (1 << i) & bit_state:
            first, second = max2(dp[i][bit_state], dq[i][bit_state], dp[i][bit_state ^ (1 << i)], dq[i][bit_state ^ (1 << i)])
        else:
            first, second = dp[i][bit_state], dq[i][bit_state]
        dp[i + 1][bit_state], dq[i + 1][bit_state] = first, second

ans = 0
for i in range(1, 1 << n):
    ans = max(ans, dp[-1][i] + dq[-1][i])
    print(ans)

Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from copy import deepcopy
N=int(input())
A=[int(i) for i in input().split()]

def chmax(a,b):
    if a[0]<b[1]:
        return b
    elif a[0]<b[0]:
        return(b[0],a[0])
    elif a[1]<b[0]:
        return (a[0],b[0])
    else:
        return a
dp=[(A[i],0) for i in range(1<<N)]

for i in range(N):
    for j in range(1<<N):
        if j & (1<<i):
            
            dp[j]=chmax(dp[j],dp[j^(1<<i)])

ans =0
for i in range(1<<N):
    t = sum(dp[i])
    ans = max(ans,t)
    print(ans)

Failing test case input:
3
2 312 111 33 0 9 17 82

Expected output:
314
314
423
423
423
423
423


Actual output:
2
314
314
423
423
423
423
423


Fixed submission (verdict: Accepted):
from copy import deepcopy
N=int(input())
A=[int(i) for i in input().split()]

def chmax(a,b):
    if a[0]<b[1]:
        return b
    elif a[0]<b[0]:
        return(b[0],a[0])
    elif a[1]<b[0]:
        return (a[0],b[0])
    else:
        return a
dp=[(A[i],0) for i in range(1<<N)]

for i in range(N):
    for j in range(1<<N):
        if j & (1<<i):
            
            dp[j]=chmax(dp[j],dp[j^(1<<i)])

ans =sum(dp[0])
for i in range(1,1<<N):
    t = sum(dp[i])
    ans = max(ans,t)
    print(ans)
Problem: p03313
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
zeta = a[: ]
zeta2 = [0] * (1 << N)
for i in range(N):
  for j in range(1 << N):
    if (1 << i) & j:
      if zeta[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = max(zeta[j], zeta2[(1 << i) ^ j])
        zeta[j] = zeta[(1 << i) ^ j]
      elif zeta2[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = zeta[(1 << i) ^ j]

for i in range((1 << N) - 1):
  zeta[i + 1] = max(zeta[i + 1], zeta[i])
  zeta2[i + 1] = max(zeta2[i + 1], zeta2[i])

for i in range(1, 1 << N): print(zeta[i] + zeta2[i])

Failing test case input:
4
16 1 1 112 32 17 97 8 1 1 25 72 84 17 56 82

Expected output:
17
17
128
128
128
129
209
209
209
209
209
209
209
209
209


Actual output:
17
17
128
128
129
144
209
209
209
209
209
209
209
209
209


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
zeta = a[: ]
zeta2 = [0] * (1 << N)
for i in range(N):
  for j in range(1 << N):
    if (1 << i) & j:
      if zeta[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = max(zeta[j], zeta2[(1 << i) ^ j])
        zeta[j] = zeta[(1 << i) ^ j]
      elif zeta2[j] < zeta[(1 << i) ^ j]:
        zeta2[j] = zeta[(1 << i) ^ j]

res = 0
for i in range(1, 1 << N):
  res = max(res, zeta[i] + zeta2[i])
  print(res)