ZhenlongDai/ACPR huggingface dataset:
Problem: p00026
Buggy submission (Python3, verdict: Wrong Answer):
import sys
n1 = [[0, 1], [1, 0], [-1, 0], [0, -1]]
n2 = n1 + [[a, b] for a in [-1,1] for b in [-1, 1]]
n3 = n2 + [[a*2, b*2] for a, b in n1]
mas = [[0]*10 for i in range(10)]
for i in sys.stdin:
    try:
        x, y, a = list(map(int,i.split(",")))
        mas[y][x] += 1
        for j in eval("n"+str(a)):
            try:
                mas[y+j[1]][x+j[0]] += 1
            except IndexError:
                continue
    except:
        break
print(len([i for x in mas for i in x if not i]))
print(max([max(v) for v in mas]))

Failing test case input:
2,5,3
1,6,3
3,4,2
4,5,2
3,6,3
2,4,1

Expected output:
73
5


Actual output:
72
5


Fixed submission (verdict: Accepted):
import sys
n1 = [[0, 1], [1, 0], [-1, 0], [0, -1]]
n2 = n1 + [[a, b] for a in [-1, 1] for b in [-1, 1]]
n3 = n2 + [[a*2, b*2] for a, b in n1]
mas = [[0]*10 for i in range(10)]
for i in sys.stdin:
    try:
        x, y, a = list(map(int, i.split(",")))
        mas[y][x] += 1
        for k,l in eval("n"+str(a)):
            try:
                if y+l >= 0 and x+k >= 0:
                    mas[y+l][x+k] += 1
            except IndexError:
                continue
    except ValueError:
        break
print(len([i for x in mas for i in x if not i]))
print(max([max(v) for v in mas]))
Problem: p00026
Buggy submission (Python3, verdict: Wrong Answer):


paper = [0 for i in range(100)]
white_points = None
deep_points = None

def small(x, y):
    p = [[x, y]]
    for i, j in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
        p.append([x + i, y + j])
    return p

def middle(x, y):
    p = small(x, y)
    for i, j in zip([1, -1] * 2, [1, 1, -1, -1]):
        p.append([x + i, y + j])
    return p

def big(x, y):
    p = middle(x, y)
    for i, j in zip([-2, 0, 2, 0], [0, -2, 0, 2]):
        p.append([x + i, y + j])
    return p

while True:
    try:
        x, y, size = map(int, input().split(','))
    except:
        print(paper.count(0))
        print(max(paper))
        break

    if size == 1:
        bp = small(x, y)
    elif size == 2:
        bp = middle(x, y)
    elif size == 3:
        bp = big(x, y)
    for p in bp:
        if not 0 <= p[0] * 10 + p[1] <= 99: continue
        paper[p[0] * 10 + p[1]] += 1

Failing test case input:
1,5,2
6,1,3
1,4,3
4,6,3
3,7,3
2,4,2

Expected output:
56
3


Actual output:
55
3


Fixed submission (verdict: Accepted):


paper = [[0] * 10 for i in range(10)]

def small(x, y):
    p = [[x, y]]
    for i, j in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
        p.append([x + i, y + j])
    return p

def middle(x, y):
    p = small(x, y)
    for i, j in zip([1, -1, 1, -1], [1, 1, -1, -1]):
        p.append([x + i, y + j])
    return p

def big(x, y):
    p = middle(x, y)
    for i, j in zip([-2, 0, 2, 0], [0, -2, 0, 2]):
        p.append([x + i, y + j])
    return p

while True:
    try:
        x, y, size = map(int, input().split(','))
    except:
        break

    if size == 1:
        bp = small(x, y)
    elif size == 2:
        bp = middle(x, y)
    elif size == 3:
        bp = big(x, y)
    for p in bp:
        if 0 <= p[0] < 10 and 0 <= p[1] < 10:
            paper[p[1]][p[0]] += 1

print(sum(paper[y][x] == 0 for y in range(10) for x in range(10)))
print(max(paper[y][x] for y in range(10) for x in range(10)))
Problem: p00026
Buggy submission (Python3, verdict: Wrong Answer):
a = [[0] * 14 for _ in range(14)]
while True:
    try:
        x, y, s = map(int, input().split(','))
    except:
        break
    x += 2
    y += 2
    for d in [(0, 0), (0, -1), (0, 1), (-1, 0), (1, 0)]:
        a[x + d[0]][y + d[1]] += 1
    if s >= 2:
        for d in [(1, 1), (1, -1), (-1, 1), (-1, -1)]:
            a[x + d[0]][y + d[1]] += 1
    if s == 3:
        for d in [(0, 2), (0, -2), (2, 0), (-2, 0)]:
            a[x + d[0]][y + d[1]] += 1
print(sum(a[i][2:12].count(0) for i in range(2, 12)))
print(max(max(a[i]) for i in range(14)))
print(a)

Failing test case input:
1,5,3
3,6,2
2,4,3
6,3,2
2,7,3
2,4,1

Expected output:
63
5


Actual output:
63
5
[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 2, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 2, 3, 2, 2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 1, 2, 3, 5, 4, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 1, 2, 3, 2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]


Fixed submission (verdict: Accepted):
a = [[0] * 14 for _ in range(14)]
while True:
    try:
        x, y, s = map(int, input().split(','))
    except:
        break
    x += 2
    y += 2
    for d in [(0, 0), (0, -1), (0, 1), (-1, 0), (1, 0)]:
        a[x + d[0]][y + d[1]] += 1
    if s >= 2:
        for d in [(1, 1), (1, -1), (-1, 1), (-1, -1)]:
            a[x + d[0]][y + d[1]] += 1
    if s == 3:
        for d in [(0, 2), (0, -2), (2, 0), (-2, 0)]:
            a[x + d[0]][y + d[1]] += 1
print(sum(a[i][2:12].count(0) for i in range(2, 12)))
print(max(max(a[i][2:12]) for i in range(2, 12)))
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans=[]
for i in range(n-1):
    if a[i]==a[i+1]:
        ans.append(a[i])
        i=i+2
if len(ans) >= 2:
    print(ans[0]*ans[1])    
else:
    print(0)


Failing test case input:
10
3 3 6 3 4 4 1 5 5 5

Expected output:
20


Actual output:
25


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
ans=[]
i=0
while i<n-1:
    if a[i]==a[i+1]:
        ans.append(a[i])
        i+=1
    i+=1
if len(ans) >= 2:
    print(ans[0]*ans[1])    
else:
    print(0)

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

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
cnt=1
ans=[]
for i in range(N-1):
    
    if A[i]==A[i+1]:
        cnt+=1
    elif cnt>=2:
        ans.append(A[i-1])
        cnt=1
        if len(ans)==2:
            break

if len(ans)<=1:
    print(0)
else:
    print(ans[0]*ans[1])

Failing test case input:
10
-2 2 1 2 4 2 2 15 0 2

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):

N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=[]
l=0
while l<N-1:
    
    if A[l]==A[l+1]:
        ans.append(A[l])
        if len(ans)==2:
            break
        else:
            l+=2
    else:
        l+=1

if len(ans)<=1:
    print(0)
else:
    print(ans[0]*ans[1])

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1
    edge = [ [k, v] for k, v in edge.items() if v >= 2 ]
    print(edge)
    edge.sort(key = lambda x : x[0])
    print(edge)

    if len(edge) >= 2 :
        print(edge[-1][0]*edge[-2][0])

    elif len(edge) == 1:
        if edge[-1][1] >= 4:
            print(edge[-1][0]**2)
        else:
            print(0)
    else:
        print(0)

if __name__ == "__main__":
    main()

Failing test case input:
6
0 -1 -1 5 0 11

Expected output:
0


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


Fixed submission (verdict: Accepted):
from collections import defaultdict
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    edge = defaultdict(int)

    for i in range(N):
        edge[A[i]] += 1

    edge = [ [k, v] for k, v in edge.items() if v >= 2 ]
    edge.sort(key = lambda x : x[0])

    if len(edge) >= 2 :
        if edge[-1][1] >= 4:
            print(max(edge[-1][0]**2, edge[-1][0]*edge[-2][0]))
        else:
            print(edge[-1][0]*edge[-2][0])
        
    elif len(edge) == 1:
        if edge[-1][1] >= 4:
            print(edge[-1][0]**2)
        else:
            print(0)
    else:
        print(0)

if __name__ == "__main__":
    main()
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections as cl

N = int(input())
sticks = [int(i) for i in input().split()]

sticks.sort(reverse=True)

w = 0
h = 0

for k,v in sorted(cl.Counter(sticks).items(), key=lambda x: x[0], reverse=True):
    if (v < 2) :
        continue
    
    if (v >= 4) :
        
        w = k
        h = k
        break
    
    if (v >= 2) :
        if (w == 0) :
            w = k
        else :
            h = k
            break


print(w*h)

Failing test case input:
10
-2 2 1 1 4 2 1 41 -1 1

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import collections as cl

N = int(input())
sticks = [int(i) for i in input().split()]

sticks.sort(reverse=True)

w = 0
h = 0

for k,v in sorted(cl.Counter(sticks).items(), key=lambda x: x[0], reverse=True):
    if (v < 2) :
        continue
    
    if (v >= 4) :
        
        if (w == 0) :
            w = k
            h = k
        else :
            h = k
        break
    
    if (v >= 2) :
        if (w == 0) :
            w = k
        else :
            h = k
            break


print(w*h)

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    cnt=Counter(aa)
    mx=-1
    for a,an in sorted(cnt.items(),reverse=True):
        if an>3 and mx==-1:
            print(a*a)
        elif an>1:
            if mx==-1:mx=a
            else:
                print(mx*a)
                break
    else:
        print(0)



main()

Failing test case input:
10
-1 1 1 3 1 2 4 15 1 0

Expected output:
1


Actual output:
1
0


Fixed submission (verdict: Accepted):
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    cnt=Counter(aa)
    mx=-1
    for a,an in sorted(cnt.items(),reverse=True):
        if an>3 and mx==-1:
            print(a*a)
            break
        elif an>1:
            if mx==-1:mx=a
            else:
                print(mx*a)
                break
    else:
        print(0)



main()
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
pre = 0
e1, e2 = 0, 0
for a in A:
  if pre == a:
    if e1 == 0:
      e1 = a
    elif e2 == 0:
      e2 == a
    pre = 0
  else:
    pre = a
print(e1 * e2)

Failing test case input:
10
0 2 1 2 4 2 4 15 0 0

Expected output:
8


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)
pre = 0
e1, e2 = 0, 0
for a in A:
  if pre == a:
    if e1 == 0:
      e1 = a
    elif e2 == 0:
      e2 = a
    pre = 0
  else:
    pre = a
print(e1 * e2)

Problem: p03625
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
S = sorted(A, reverse=True)
w, h = 0, 0

cnt = 0
tmp = 0
l = S[0]
for i in range(N):
  if S[i] != l:
    if cnt == 0:
      if tmp > 3:
        w, h = l, l
        break
      elif tmp > 1:
        w = l
        tmp = 1
        l = S[i]
        cnt += 1
      else:
        tmp = 1
        l = S[i]
    else:
      h = l
      break
  else:
    tmp += 1
    if i == N-1:
      h = l
ans = w * h
print(ans)


Failing test case input:
10
0 2 12 7 5 1 0 9 3 2

Expected output:
0


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
S = sorted(A, reverse=True)
w, h = 0, 0

cnt = 0
tmp = S[0]
for i in range(N):
  if S[i] == tmp:
    cnt += 1
    if cnt == 2:
      if w == 0:
        w = tmp
        cnt = 0
      else:
        h = tmp
        break
  else:
    cnt = 1
    tmp = S[i]
        
ans = w * h
print(ans)

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
p=Counter(a)
c=0
d=0
for a,b in p.items():
    if b>3:
        if c<a:
            c=a
        if d<a:
            d=a
    elif b>1:
        if c==0:
            c=a
        else:
            if d>c:
                c=a
            else:
                d=a
print(c*d)

Failing test case input:
10
3 3 6 3 4 3 2 2 5 3

Expected output:
9


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
p=Counter(a)
c=0
d=0
for a,b in p.items():
    if b>3:
        if c<a:
            c=a
        if d<a:
            d=a
    elif b>1:
        if c==0:
            c=a
        else:
            if d>c and c<a:
                c=a
            elif d<=c and d<a:
                d=a
print(c*d)
Problem: p03625
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    cnter = Counter(A)
    cnter_list = list(cnter.items())
    cnter_list.sort(key=lambda x:x[0], reverse=True)

    double_cnt = 0
    ans = 1
    for elem in cnter_list:
        if elem[1] >= 2:
            double_cnt += 1
            ans *= elem[0]
        if double_cnt >= 2:
            break
    else:
        print(0)
        return
    
    print(ans)

if __name__ == '__main__':
    solve()

Failing test case input:
10
-1 1 1 3 1 2 4 15 1 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
from collections import Counter
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    cnter = Counter(A)
    cnter_list = list(cnter.items())
    cnter_list.sort(key=lambda x:x[0], reverse=True)

    double_cnt = 0
    ans = 1
    for elem in cnter_list:
        if elem[1] >= 4:
            if double_cnt == 0:
                ans = elem[0] * elem[0]
                break

        if elem[1] >= 2:
            double_cnt += 1
            ans *= elem[0]
        if double_cnt >= 2:
            break
    else:
        print(0)
        return
    
    print(ans)

if __name__ == '__main__':
    solve()

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

import copy
import random
import bisect 
import math


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

A.sort()
len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

ans = [0,0]
for k, v in sorted(len_dic.items(),key=lambda x:-x[0]):
    if v >= 4 and ans[0] == 0:
        ans = [k,k]
    elif v >= 2:
        if ans[0]==0:
            ans[0] = k
        elif ans[1] == 0:
            ans[1] = k
    else:
        break

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


Failing test case input:
10
0 2 1 2 4 2 4 15 0 0

Expected output:
8


Actual output:
0


Fixed submission (verdict: Accepted):

import copy
import random
import bisect 
import math


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

A.sort()
len_dic = {}
for a in A:
    if a in len_dic.keys():
        len_dic[a] += 1

    else:
        len_dic[a] = 1

ans = [0,0]
for k, v in sorted(len_dic.items(),key=lambda x:-x[0]):
    if v >= 4 and ans[0] == 0:
        ans = [k,k]
    elif v >= 2:
        if ans[0]==0:
            ans[0] = k
        elif ans[1] == 0:
            ans[1] = k

print(ans[0]*ans[1])
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

tmp = []
from collections import Counter
c = Counter(a)
for k in c.keys():
    if c[k] >= 2:
        tmp.append(k)

tmp.sort()
if len(tmp) >= 2:
    print(tmp[-1] * tmp[-2])
else:
    print(0)


Failing test case input:
10
-1 1 1 3 1 2 4 15 1 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

tmp = []
from collections import Counter
c = Counter(a)
for k in c.keys():
    if c[k] >= 2:
        tmp.append(k)
    if c[k] >= 4:
        tmp.append(k)

tmp.sort()

if len(tmp) >= 2:
    print(tmp[-1] * tmp[-2])
else:
    print(0)

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    if x1>i and x2<=i:
      x2=i
print(x1*x2)
    

Failing test case input:
10
3 3 6 3 4 3 2 2 5 3

Expected output:
9


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
x1=0
x2=0
count=Counter(a)
for i in count:
  if count[i]>=4:
    if x1<=i:
      x2=i
      x1=i
  if count[i]>=2:
    if x1<=i:
      x2=x1
      x1=i
    elif x2 <= i < x1:
      x2=i
print(x1*x2)

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
counter = Counter(A_list)
counter = sorted(counter.items(), key=lambda x: -x[0])

long_side = 0
short_side = 0
choice = 0

for k, v in counter:
    if v % 4 == 0 and choice == 0:
        long_side = k
        short_side = k
        choice = 4

    elif v >= 2:
        if choice == 2:
            short_side = k
            choice = 4
        else:
            long_side = k
            choice = 2

    if choice == 4:
        print(long_side*short_side)
        exit()
print(0)

Failing test case input:
10
3 3 6 3 4 3 2 2 5 3

Expected output:
9


Actual output:
6


Fixed submission (verdict: Accepted):
from collections import Counter
N = int(input())
A_list = list(map(int, input().split()))
counter = Counter(A_list)
counter = sorted(counter.items(), key=lambda x: -x[0])

long_side = 0
short_side = 0
choice = 0

for k, v in counter:
    if v >= 4 and choice == 0:
        long_side = k
        short_side = k
        choice = 4

    elif v >= 2:
        if choice == 2:
            short_side = k
            choice = 4
        else:
            long_side = k
            choice = 2

    if choice == 4:
        print(long_side*short_side)
        exit()
print(0)
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    cands = set()
    s = set()
    for i in a:
        if i in s:
            cands.add(i)
        else:
            s.add(i)
    
    x = sorted(cands, reverse=True)
    if len(x) < 2:
        return 0
    
    return x[0] * x[1]

main()


Failing test case input:
6
3 2 2 4 2 2

Expected output:
4


Actual output:
0


Fixed submission (verdict: Accepted):
def main():
    n = int(input())
    a = [int(s) for s in input().split()]
    print(solve(a))

def solve(a):
    cands = []
    s = set()
    for i in a:
        if i in s:
            cands.append(i)
            s.remove(i)
        else:
            s.add(i)
    
    x = sorted(cands, reverse=True)
    if len(x) < 2:
        return 0
    
    return x[0] * x[1]

main()

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort
        print(c[-1] * c[-2])

main()

Failing test case input:
10
-2 2 1 1 4 2 1 41 -1 1

Expected output:
2


Actual output:
1


Fixed submission (verdict: Accepted):
import collections

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    B = collections.Counter(A)

    c = []

    for k, v in B.items():
        if v >= 2:
            c.append(k)
        if v >= 4:
            c.append(k)
    if len(c) < 2:
        print(0)
    else:
        c.sort()
        print(c[-1] * c[-2])

main()

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

ans=[]
tmp=0
flag=True
for el in a:
    if len(ans)==2: break
    if el != tmp: tmp=el; flag=True
    else:
        if flag: ans.append(el); tmp=el; flag=False

try: ans=ans[0]*ans[1]
except: ans=0
print(ans)


Failing test case input:
10
-2 2 1 2 4 2 1 41 0 2

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

ans=[]
tmp=0
count=0
for el in a:
    if len(ans)==2: break
    if el != tmp: tmp=el; count=0
    else:
        if count%2==0: ans.append(el); tmp=el;
        count+=1

try: ans=ans[0]*ans[1]
except: ans=0
print(ans)
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
freq = {}
arr = map(int,input().split())
for i in arr:
    try:
        freq[i] += 1
    except KeyError:
        freq[i] = 1

to_multiply = []      
for i in sorted(freq.keys(),reverse=True):
    if freq[i] >= 2:
        to_multiply.append(i)
if len(to_multiply) >= 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")
        


Failing test case input:
10
-2 2 1 2 4 2 1 41 0 2

Expected output:
4


Actual output:
2


Fixed submission (verdict: Accepted):
N = int(input())
freq = {}
arr = map(int,input().split())
for i in arr:
    try:
        freq[i] += 1
    except KeyError:
        freq[i] = 1

to_multiply = []      
for i in sorted(freq.keys(),reverse=True):
    if freq[i] >= 4:
        to_multiply.append(i)
        to_multiply.append(i)
    elif freq[i] >= 2:
        to_multiply.append(i)
if len(to_multiply) >= 2:
    print(to_multiply[0] * to_multiply[1])
else:
    print("0")

Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
arr = sorted(list(map(int,input().split())))
b = {}
for i in arr:
    if i not in b:
        b[i] = 1
    else:
        b[i] += 1
h = 0
w = 0
for i in b:
    if b[i] >= 4 and h*w < i**2:
        h = i
        w = i
    elif b[i] >= 2:
        if w*i > h*i:
            h = i
        else:
            w = i
print(0)


Failing test case input:
10
-2 2 12 1 4 2 1 41 -1 1

Expected output:
2


Actual output:
0


Fixed submission (verdict: Accepted):
N = int(input())
arr = sorted(list(map(int,input().split())))
b = {}
for i in arr:
  if i not in b:
      b[i] = 1
  else:
      b[i] += 1
h = 0
w = 0
b1 = sorted(b)[::-1]
for i in b1:
    if b[i] >= 4:
        if h < i:
            h = i
            w = i
            break
        else:
            w = i
            break
    elif b[i] >= 2:
        if h == 0:
            h = i
        else:
            w = i
            break
        
print(h*w)
Problem: p03625
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count[0])
B.sort(reverse=True)
if len(B) < 2:
    print(0)
else:
    print(B[0]*B[1])
    

Failing test case input:
10
-1 1 1 3 1 2 4 15 1 0

Expected output:
1


Actual output:
0


Fixed submission (verdict: Accepted):
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True)

N=I()
A=LI()
B = []
counts = collections.Counter(A)
for count in counts.items():
    if count[1] >= 2:
        B.append(count)
B.sort(reverse=True)
if len(B) ==0:
    print(0)
elif len(B) == 1:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(0)
else:
    if B[0][1] >= 4:
        print(B[0][0]**2)
    else:
        print(B[0][0]*B[1][0])

Problem: p03625
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
from collections import Counter
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=Counter(a)
key=sorted(list(cnt.keys()))[::-1]
one=two=0
for i in key:
    if cnt[i]>=4:
        one=two=i
    elif cnt[i]>=2:
        if one==0:
            one=i
        else:
            two=i
            break
print(one*two)

Failing test case input:
10
3 3 6 6 4 3 1 6 3 10

Expected output:
18


Actual output:
9


Fixed submission (verdict: Accepted):
from collections import Counter
n=int(input())
a=sorted([int(i) for i in input().split()])
cnt=Counter(a)
key=sorted(list(cnt.keys()))[::-1]
one=two=0
for i in key:
    if cnt[i]>=4 and one==0:
        one=two=i
        break
    elif cnt[i]>=2:
        if one==0:
            one=i
        else:
            two=i
            break
print(one*two)
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
from sys import stdin

a=int(stdin.readline())
A=stdin.readline().split()
sum=0
for k in range(0,a+1):
    sum+=int(A[k])

sum-=int(A[a])
ver=1
lay=1
K=0
T=0

if a==0:
    if A[0]!=0:
        print(-1)
        K=1
    else:
        print(1)
        K=1

for l in range(0,a):
    if lay-int(A[l])<=0:
        print(-1)
        K=1
        break
    if (lay-int(A[l]))*2-sum+int(A[l])<=int(A[a]):
        lay=(lay-int(A[l]))*2
        ver+=lay
        sum-=int(A[l])
        T=l
    else:
        lay-=int(A[l])
        sum-=int(A[l])
        x=lay-sum-int(A[a])
        if x==0:
           ver+=lay
        elif x<0:
           print(-1)
           K=1
           
        else:
           lay=sum+int(A[a])
           ver+=lay
        T=l
        break

if K==0:
    for u in range(T+1,a):
        lay -= int(A[u])
        sum -= int(A[u])
        ver+=lay

if K==0:
    print(ver)

Failing test case input:
4
-1 0 -1 2 10

Expected output:
35


Actual output:
-1


Fixed submission (verdict: Accepted):
from sys import stdin

a=int(stdin.readline())
A=stdin.readline().split()
sum=0
for k in range(0,a+1):
    sum+=int(A[k])

sum-=int(A[a])
ver=1
lay=1
K=0
T=0

if a==0:
    if A[0]!='1':
        print(-1)
        K=1
    else:
        print(1)
        K=1

for l in range(0,a):
    if lay-int(A[l])<=0:
        print(-1)
        K=1
        break
    if (lay-int(A[l]))*2<int(A[a]) and l==(a-1):
        print(-1)
        K=1
        break
    if (lay-int(A[l]))*2-sum+int(A[l])<=int(A[a]):
        lay=(lay-int(A[l]))*2
        ver+=lay
        sum-=int(A[l])
        T=l
    else:
        lay-=int(A[l])
        sum-=int(A[l])
        x=lay-sum-int(A[a])
        if x==0:
           ver+=lay
        elif x>0:
            print(-1)
            K=1
        else:
           lay=sum+int(A[a])
           ver+=lay
        T=l
        break

if K==0:
    for u in range(T+1,a):
        lay -= int(A[u])
        sum -= int(A[u])
        ver+=lay

if K==0:
    print(ver)
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):

N = int(input())

A = list(map(int, input().split()))
for i in range(N):
    if A[i] > 2**i:
        print(-1)
        exit()

if A[0] != 0:
    if N == 0 and A[0] == 1:
        print(1)
        exit()
    else:
        print(-1)
        exit()

limit = [1]
for i in range(1, N+1):
    if i == N:
        limit.append(A[i])
    else:
        limit.append((limit[-1]-A[i-1])*2)



ans = [A[-1]]
now_leaf = A[-1]
for i in range(N-1, -1, -1):
    
    ans.append(min(now_leaf+A[i], limit[i]))
    now_leaf = ans[-1]

print(sum(ans))


Failing test case input:
4
-2 0 -1 1 5

Expected output:
22


Actual output:
-1


Fixed submission (verdict: Accepted):

N = int(input())

A = list(map(int, input().split()))


limit = [1]
for i in range(1, N+1):
    if i == N:  
        limit.append(A[i])
    else:
        limit.append((limit[-1]-A[i-1])*2)
        if limit[-1] < 0:
            print(-1)
            exit()


if N == 0:
    if A[0] != 1:
        print(-1)
        exit()


ans = [A[-1]]
now_leaf = A[-1]  
for i in range(N-1, -1, -1):
    
    ans.append(min(now_leaf+A[i], limit[i]))
    now_leaf = ans[-1]

for i in range(N):
    
    if (ans[N-i]-A[i])*2 < A[i+1]:  
        print(-1)
        exit()
print(sum(ans))

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
def main():
    import sys
    import math
    input = sys.stdin.buffer.readline
    n = int(input())
    A = list(map(int, input().split()))
    ans = 0
    nodes = 0
    for i in range(n,-1,-1):
        if i == 0:
            ans +=1 
            break
        if math.ceil(nodes/2) + A[i] > 2**i:
           
            print(-1)
            exit(0)
        nodes += A[i]
        nodes = min(2**i,nodes)
        ans += nodes
    print(ans)

if __name__ == '__main__':
    main()

Failing test case input:
4
-1 1 -1 1 17

Expected output:
42


Actual output:
-1


Fixed submission (verdict: Accepted):
def main():
    import sys
    import math
    input = sys.stdin.buffer.readline
    n = int(input())
    A = list(map(int, input().split()))
    ans = 0
    node = 1
    max_node = sum(A)
    for i in range(n+1):
        ans += node
        max_node -= A[i]
        node = min(max_node,(node-A[i])*2)
        if node < 0:
            print(-1)
            exit(0)
    print(ans)


if __name__ == '__main__':
    main()
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a_l = list(map(int,input().split()))

if a_l[0] != 0:
    if n == 0:
        print(1)
    else:
        print(-1)
    exit()

tree = [0]*(n+1)
tree[0] = 1
for i in range(1,n+1):
    tree[i] = (tree[i-1] - a_l[i-1]) * 2


if tree[-1] < a_l[-1]:
    print(-1)
    exit()

while tree[-1] != a_l[-1]:
    tree[-1] -= 1
    i = 1
    while True:
        i += 1 
        if tree[-(i-1)] >= (tree[-i] - a_l[-i]):
            break
        tree[-i] -= 1


ans = 0
for val in tree:
    ans += val
print(ans)

Failing test case input:
4
-1 0 -1 3 5

Expected output:
25


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a_l = list(map(int,input().split()))








tree = [0]*(n+1)
tree[0] = 1
for i in range(1,n+1):
    tree[i] = (tree[i-1] - a_l[i-1]) * 2


if tree[-1] < a_l[-1]:
    print(-1)
    exit()


tree[-1] = a_l[-1]
for i in range(2,n+2):
    
    if tree[-i] == tree[-(i-1)] + a_l[-i]:
        break
    else:
        tree[-i] = min(tree[-i], tree[-(i-1)] + a_l[-i])
    












ans = 0
for val in tree:
    ans += val
print(ans)

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())

A = list(map(int,input().split()))

B = [0] * (N+1)
B[0] = 1 - A[0]
for i in range(0,N):
    if 2*B[i] < A[i+1]:
        print("-1")
        exit()
    B_max = sum(A[i+2:])
    B[i+1] = min(2*B[i]-1,B_max)
if B[-1] != 0:
    print("-1")
else:
    print(sum(A)+sum(B))


Failing test case input:
4
-2 1 -3 4 27

Expected output:
70


Actual output:
61


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

A = list(map(int,input().split()))
s = sum(A[1:])
B = [0] * (N+1)
B[0] = 1 - A[0]
for i in range(0,N):
    s -= A[i+1]
    if 2*B[i] < A[i+1]:
        print("-1")
        exit()
    B[i+1] = min(2*B[i]-A[i+1],s)
if B[-1] != 0:
    print("-1")
else:
    print(sum(A)+sum(B))

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if A[0] != 0:
    print(-1)
    sys.exit()

for i in range(N):
    if A[i] > A[i+1]+1:
        print(-1)
        sys.exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)

Failing test case input:
4
-4 -1 0 1 17

Expected output:
64


Actual output:
-1


Fixed submission (verdict: Accepted):
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if N == 0:
    if A[0] != 1:
        print(-1)
        exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()



ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))

leaf = []
miki = []
under = 1

for i, a in enumerate(A):
    can = 2 ** i
    if a > can or under == 0:
        print(-1)
        exit()
    miki.append(under - a)
    under = miki[-1] * 2


ans = 0
child = 0
for i in reversed(range(N + 1)):
    child = min(child, miki[i]) + A[i]
    ans += child

print(ans)

Failing test case input:
4
-1 0 -1 2 19

Expected output:
50


Actual output:
-1


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

if N == 0:
    if A[0] != 1:
        print(-1)
    else:
        print(1)
    exit()


leaf = []
miki = []
under = 1

for i, a in enumerate(A):
    if a > under:
        print(-1)
        exit()
    miki.append(under - a)
    under = miki[-1] * 2


ans = 0
child = 0
for i in reversed(range(N + 1)):
    child = min(child, miki[i]) + A[i]
    ans += child

print(ans)

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
s = [0] * (N + 2)
for i in range(N + 1):
    s[i + 1] = s[i] + A[i]
node, leaf = 1, 1
for d in range(1, N + 1):
    if leaf < A[d]:
        print(-1)
        break
    leaf = min((leaf - A[d - 1]) * 2, s[N + 1] - s[d])
    if leaf < A[d]:
        print(-1)
        break
    node += leaf
else:
    print(node)

Failing test case input:
4
-1 0 -1 3 22

Expected output:
53


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
A_leaf = list(map(int, input().split()))
if N == 0:
    print(1 if A_leaf[0] == 1 else -1)
    exit()
s = [0]*(N+2)
for i in range(1, N+2):
    s[i] = s[i-1] + A_leaf[i-1]
node = [1]*(N+1)
for i in range(1, N+1):
    node[i] = min((node[i-1] - A_leaf[i-1])*2, s[N+1]-s[i])
    if node[i] < A_leaf[i]:
        print(-1)
        exit()
else:
    print(sum(node))

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A_leaf = list(map(int, input().split()))
s = [0]*(N+2)
for i in range(1, N+2):
    s[i] = s[i-1] + A_leaf[i-1]
node = [1]*(N+1)
for i in range(1, N+1):
    node[i] = min(node[i-1] - A_leaf[i-1], (s[N+1]-s[i]) / 2)*2
    if node[i] <= 0:
        print(-1)
        break
else:
    print(int(sum(node)))

Failing test case input:
3
0 1 -1 1

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
N = int(input())
A_leaf = list(map(int, input().split()))
if N == 0:
    print(1 if A_leaf[0] == 1 else -1)
    exit()
s = [0]*(N+2)
for i in range(1, N+2):
    s[i] = s[i-1] + A_leaf[i-1]
node = [1]*(N+1)
for i in range(1, N+1):
    node[i] = min((node[i-1] - A_leaf[i-1])*2, s[N+1]-s[i])
    if node[i] < A_leaf[i]:
        print(-1)
        exit()
else:
    print(sum(node))
Problem: p02665
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))

ans, cnt, node = 0, sum(a), 1
for i in range(n + 1):
    ans += node
    if node <= 0:
        print(-1)
        break
    cnt -= a[i]
    node = min(cnt, (node - a[i]) * 2)
else:
    print(ans)


Failing test case input:
3
0 1 -1 1

Expected output:
3


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))

ans, cnt, node = 0, sum(a), 1
for i in range(n + 1):
    ans += node
    cnt -= a[i]
    node = min(cnt, (node - a[i]) * 2)
    if node < 0:
        print(-1)
        break
else:
    print(ans)

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
arr = list(map(int,input().split()))
ans = [0]*(n+1)
ans[0] = 1
c_sum = [0]*(n+1)
c_sum[0] = arr[0]
for i in range(1,n+1):
    c_sum[i] = c_sum[i-1] + arr[i]
root = [0]*(n+1)
root[0] = arr[0]
for d in range(n+1):
    if d==0:
        ans[d] = min(1-arr[0],c_sum[-1])
    else:
        ans[d] = min(root[d-1]*2,(c_sum[-1] - c_sum[d-1]))
    if ans[d] < 0:
        print(-1)
        exit()
    root[d] = ans[d] - arr[d]
print(sum(ans))




Failing test case input:
4
-2 1 -1 2 28

Expected output:
67


Actual output:
89


Fixed submission (verdict: Accepted):
n = int(input())
arr = list(map(int,input().split()))
ans = [0]*(n+1)
ans[0] = 1
c_sum = [0]*(n+1)
c_sum[0] = arr[0]
for i in range(1,n+1):
    c_sum[i] = c_sum[i-1] + arr[i]
root = [0]*(n+1)
for d in range(n+1):
    if d==0:
        ans[d] = min(1,c_sum[-1])
    else:
        ans[d] = min(root[d-1]*2,(c_sum[-1] - c_sum[d-1]))
    root[d] = ans[d] - arr[d]
    if root[d] < 0:
        print(-1)
        exit()
print(sum(ans))

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
ans = 0

l = [0]*(n+1)
l[-1] = a[-1]
for i in range(n-1,-1,-1):
    l[i] += l[i+1]+a[i]

if a[0] == 1:
    if n > 0:
        print(-1)
        exit()
    else:
        print(1)
        exit()
b = 2
ans = 1
for i in range(1,n+1):
    if b*2 < a[i]:
        print(-1)
        exit()
    else:
        if i == n:
            ans += a[-1]
        else:
            b = (b-a[i])*2
            ans += min(b,l[i+1])

print(ans)



Failing test case input:
10
0 -1 1 1 3 4 4 5 13 9 34

Expected output:
313


Actual output:
345


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
ans = 0

l = [0]*(n+1)
l[-1] = a[-1]
for i in range(n-1,-1,-1):
    l[i] += l[i+1]+a[i]

if a[0] == 1:
    if n > 0:
        print(-1)
        exit()
    else:
        print(1)
        exit()
b = 1
ans = 0
for i in range(n+1):
    if b < a[i]:
        print(-1)
        exit()
    else: 
        b = min(b,l[i])
        ans += b
        b = (b-a[i])*2   
print(ans)
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
a_l = list(map(int,input().split()))

if a_l[0] != 0:
    if n == 0:
        print(1)
    else:
        print(-1)
    exit()

tree = [0]*(n+1)
tree[0] = 1
for i in range(1,n+1):
    tree[i] = (tree[i-1] - a_l[i-1]) * 2


if tree[-1] < a_l[-1]:
    print(-1)
    exit()


tree[-1] = a_l[-1]
for i in range(2,n+2):
    
    if tree[-i] == tree[-(i-1)] + a_l[-i]:
        break
    else:
        tree[-i] = min(tree[-i], tree[-(i-1)] + a_l[-i])
    












ans = 0
for val in tree:
    ans += val
print(ans)

Failing test case input:
4
-1 0 -1 2 5

Expected output:
23


Actual output:
-1


Fixed submission (verdict: Accepted):
n = int(input())
a_l = list(map(int,input().split()))








tree = [0]*(n+1)
tree[0] = 1
for i in range(1,n+1):
    tree[i] = (tree[i-1] - a_l[i-1]) * 2


if tree[-1] < a_l[-1]:
    print(-1)
    exit()


tree[-1] = a_l[-1]
for i in range(2,n+2):
    
    if tree[-i] == tree[-(i-1)] + a_l[-i]:
        break
    else:
        tree[-i] = min(tree[-i], tree[-(i-1)] + a_l[-i])
    












ans = 0
for val in tree:
    ans += val
print(ans)

Problem: p02665
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()
if a[0]>0:
    print(1)
    sys.exit()
c = [1]*(n+1)
for i in range(1, n+1):
    c[i] = (c[i-1]-a[i-1])*2
if a[n]>c[n]:
    print(-1)
    sys.exit()
b = [0]*(n+1)
res = [0]*(n+1)
b[n] = a[n]
res[n] = a[n]
for i in range(n-1, -1, -1):
    if (c[i]-a[i])*2 <res[i+1]:
        print(-1)
        sys.exit()
    b[i] = min(c[i]-a[i], res[i+1])
    res[i] = a[i] + b[i]
print(sum(res))    

Failing test case input:
4
1 1 0 0 2

Expected output:
-1


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n = INT()
a = LIST()

c = [1]*(n+1)
for i in range(1, n+1):
    c[i] = (c[i-1]-a[i-1])*2
if a[n]>c[n]:
    print(-1)
    sys.exit()
b = [0]*(n+1)
res = [0]*(n+1)
b[n] = a[n]
res[n] = a[n]
for i in range(n-1, -1, -1):
    if (c[i]-a[i])*2 <res[i+1]:
        print(-1)
        sys.exit()
    b[i] = min(c[i]-a[i], res[i+1])
    res[i] = a[i] + b[i]
print(sum(res))
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
last = A[-1]
count = last
root = 1
for i in range(N):
  if i+1 == N and root > A[i+1]:
    root = last + A[i]
  elif root > (last + A[i+1])*2:
    root = (last + A[i+1])*2
  count+=root
  root = (root-A[i])*2
  if root < A[i+1]:
    print(-1)
    break
else:
  print(count)


Failing test case input:
10
0 0 1 0 3 3 5 8 13 23 34

Expected output:
284


Actual output:
298


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
sa = sum(A)
last = A[-1]
count = last
root = 1
for i in range(N):
  sa -= A[i]
  if root <= A[i]:
    print(-1)
    break
  elif root-A[i] > sa:
    root = sa + A[i]
  count+=root
  root = (root-A[i])*2
else:
  if count == 0 or root < last:
    count = -1
  print(count)

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
last = A[-1]
count = last
root = 1
for i in range(N):
  if root > last + A[i]:
    root = last + A[i]
  count+=root
  root = (root-A[i])*2
  if root < A[i+1]:
    print(-1)
    break
else:
  print(count)

Failing test case input:
10
0 0 1 -1 5 6 5 9 13 23 34

Expected output:
256


Actual output:
245


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
sa = sum(A)
last = A[-1]
count = last
root = 1
for i in range(N):
  sa -= A[i]
  if root <= A[i]:
    print(-1)
    break
  elif root-A[i] > sa:
    root = sa + A[i]
  count+=root
  root = (root-A[i])*2
else:
  if count == 0 or root < last:
    count = -1
  print(count)

Problem: p02665
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
n = int(input())+1
a = list(map(int, input().split()))
m_node = [1]*n
node = 0
total = 0

if n == 1:
    if a[0] != 1:
        print("-1", end="")
        exit()
    else:
        print("1", end="")
        exit()

for i in range(1, n):
    m_node[i] = (m_node[i-1] - a[i-1])*2
    if m_node[i] <= 0:
        print("-1", end="")
        exit()
for i in reversed(range(n)):
    if a[i] >= m_node[i]:
        print("-1", end="")
        exit()
    node = min((node+a[i]), m_node[i])
    total += node

print(total, end="")

Failing test case input:
3
0 1 1 2

Expected output:
7

Actual output:
-1

Fixed submission (verdict: Accepted):
n = int(input())+1
a = list(map(int, input().split()))
m_node = [1]*n
node = 0
total = 0

if n == 1:
    if a[0] != 1:
        print("-1", end="")
        exit()
    else:
        print("1", end="")
        exit()

for i in range(1, n):
    m_node[i] = (m_node[i-1] - a[i-1])*2
    if m_node[i] <= 0:
        print("-1", end="")
        exit()
for i in reversed(range(n)):
    if a[i] > m_node[i]:
        print("-1", end="")
        exit()
    node = min((node+a[i]), m_node[i])
    total += node

print(total, end="")
Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N=int(input())
A=list(map(int,input().split()))
temp=1
summ=0
cont=0
templist=[1]
for i in range(N+1):
  
  if A[i]<temp:
    if i<N:
      summ+=temp
      temp=2*(temp-A[i])
      templist.append(temp)
    elif i==N:
      summ+=temp
      cont+=1
  elif A[i]==temp:
    if i==N:
      summ+=temp
      
      cont+=1
    else:
      print("-1")
      break
  else:
    print("-1")
    break
    
if cont==1:
  if A[N]==temp:
  	print(summ)
  else:
    
    
    comp=A[-1]
    for i in range(N):
      summ-=(templist[-(i+1)]-comp)
      comp+=A[-(i+2)]
      
      
      
      if comp>templist[-(i+2)]:
        print(summ)
        break



Failing test case input:
3
0 1 -1 1

Expected output:
3


Actual output:

Fixed submission (verdict: Accepted):
N=int(input())
A=list(map(int,input().split()))
temp=1
summ=0
cont=0
templist=[1]
for i in range(N+1):
  
  if A[i]<temp:
    if i<N:
      summ+=temp
      temp=2*(temp-A[i])
      templist.append(temp)
    elif i==N:
      summ+=temp
      cont+=1
  elif A[i]==temp:
    if i==N:
      summ+=temp
      
      cont+=1
    else:
      print("-1")
      break
  else:
    print("-1")
    break
    
if cont==1:
  if A[N]==temp:
  	print(summ)
  else:
    
    
    comp=A[-1]
    for i in range(N):
      summ-=(templist[-(i+1)]-comp)
      comp+=A[-(i+2)]
      
      
      
      if comp>templist[-(i+2)]:
        print(summ)
        break
      if i==N-1:
        print(summ)
        break

Problem: p02665
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int, input().split()))
B = [0] *(N+1)
B[0] = 1
ans = 0
for i in range(1, N+1):
    B[i] = (B[i-1] - A[i-1])*2
    if B[i] <= 0:
        ans = -1
        break
if ans == 0:
    check = 0
    for j in range(N, 0, -1):
        check += A[j]
        if check < B[j-1]:
            ans += check
        else:
            last = j
            for k in range(last+1):
                ans += B[k]
            break
print(ans)


Failing test case input:
4
0 0 -1 2 10

Expected output:
27


Actual output:
33


Fixed submission (verdict: Accepted):
N = int(input())
A = list(map(int, input().split()))
B = [0] *(N+1)
B[0] = 1
ans = 0
for i in range(1, N+1):
    B[i] = (B[i-1] - A[i-1])*2
    if B[i] <= 0:
        ans = -1
        break
if B[N] < A[N]:
    ans = -1
if ans == 0:
    check = 0
    for j in range(N, 0, -1):
        check += A[j]
        if check < B[j]:
            ans += check
        else:
            last = j
            for k in range(1, last+1):
                ans += B[k]
            break
    ans += 1
if N == 0 and A[0] == 1:
    ans = 1
print(ans)