ZhenlongDai/ACPR huggingface dataset:
Problem: p02824
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
def is_ok(index):
  s=0
  for i in range(p,index):
    s+=a[index]+m-a[i]
  return s+m*(n-index+p-1)>=m*v and a[index]+m>=a[p-1]
def binary_search(a):
  ok=-1
  ng=len(a)
  while abs(ng-ok)>1:
    mid=(ng+ok)
    if is_ok(mid):ok=mid
    else:ng=mid
  return ok+1
n,m,v,p=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
print(binary_search(a))

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

Expected output:
3


Actual output:
2


Fixed submission (verdict: Accepted):
def is_ok(index):
  s=0
  for i in range(p-1,index):
    s+=a[index]+m-a[i]
  return s+m*(n-index+p-1)>=m*v and a[index]+m>=a[p-1]
def binary_search(a):
  ok=-1
  ng=len(a)
  while abs(ng-ok)>1:
    mid=(ng+ok)
    if is_ok(mid):ok=mid
    else:ng=mid
  return ok+1
n,m,v,p=map(int,input().split())
a=sorted(list(map(int,input().split())))[::-1]
print(binary_search(a))

Problem: p02824
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m,v,p = map(int, input().split())
a = list(map(int, input().split()))

a = sorted(a)

sm = sum(a[:n-p+1])

for k in range(n-p):
    sm -= a[k]
    if (n-p-k)*(a[k]+m) - sm +(p+k)*m < v*m:
        continue
    else:
        print(n-k)
        exit()

print(p)

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

Expected output:
2


Actual output:
5


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

a = sorted(a)

sm = sum(a[:n-p+1])

for k in range(n-p+1):
    sm -= a[k]
    if a[k]+m < a[n-p]:
        continue
    elif (n-p-k)*(a[k]+m) - sm +(p+k)*m < v*m:
        continue
    else:
        print(n-k)
        exit()

Problem: p02824
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, M, V, P = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)


ans = P
S = A[P-1]
for i in range(P, N):
    if V <= P-1+N-i:
        if A[i]+M >= A[P-1]:
            ans += 1
    else:
        if S+M*(V-P+1-N+i)/(i-(P-1)) <= (A[i]+M):
            ans += 1
    S += A[i]
print(ans)


Failing test case input:
10 14 8 5
7 2 3 6 1 11 5 4 3 7

Expected output:
10


Actual output:
8


Fixed submission (verdict: Accepted):
N, M, V, P = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)


ans = P
S = A[P-1]
for i in range(P, N):
    if A[i]+M < A[P-1]:
        continue
    if V <= P-1+N-i:
        if A[i]+M >= A[P-1]:
            ans += 1
    else:
        if S+M*(V-P+1-N+i) <= (A[i]+M)*(i-(P-1)):
            ans += 1
    S += A[i]
print(ans)
Problem: p02824
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N, M, V, P = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)

S = 0
for i in range(P-1, N):
    if A[i] + M >= A[P-1] and (V - (P-1) - (N-i-1) - 1) * M <= S + (A[i] + M - A[P-1]) * (i - P + 1):
        pass
    else:
        break
    S += A[P-1] - A[i]
print(i)

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

Expected output:
6


Actual output:
5


Fixed submission (verdict: Accepted):
N, M, V, P = map(int, input().split())
A = sorted([int(x) for x in input().split()], reverse=True)

def func():
    S = 0
    c = 0
    for i in range(P-1, N):
        if A[i] + M >= A[P-1] and (V - (P-1) - (N-i-1) - 1) * M <= S + (A[i] + M - A[P-1]) * c:
            pass
        else:
            return i
        S += A[P-1] - A[i]
        c += 1
    return N
print(func())

Problem: p02824
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)
for i in range(P-1):
    x = A.pop()
    S -= x
total_score = M*(V-P+1)
kazu = N - P + 1
for i in range(N-P+1):
    a = A.pop(0)
    total_score -= M
    S -= a
    kazu -= 1
    T = (M+a)*kazu - S
    if T >= total_score:
        ans = kazu + P
        break
print(ans)
    

Failing test case input:
6 1 2 2
2 1 1 5 0 0

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)
S = sum(A)
for i in range(P-1):
    x = A.pop()
    S -= x
total_score = M*(V-P+1)
kazu = N - P + 1
for i in range(N-P+1):
    a = A.pop(0)
    total_score -= M
    S -= a
    kazu -= 1
    T = (M+a)*kazu - S
    if i == N - P:
        ans = P
    else:
        if (a+M) >= A[-1]:
            if T >= total_score:
                ans = kazu + P
                break
print(ans)

Problem: p02824
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n,m,v,p = map(int,input().split())
a = list(map(int,input().split()))

a.sort(reverse=True)

higher = a[p-1]
for i in range(p,n):
    if(a[i] == a[i-1]):
        higher += a[i]
        continue

    if(a[p-1]- a[i] > v):
        print(i)
        exit()

    if(higher - a[i]*(i-p+1) > min(n-v,p-1)*m):
        print(i)
        exit()

    higher += a[i]

print(n)

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

Expected output:
10


Actual output:
7


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

a.sort(reverse=True)

higher = a[p-1]
for i in range(p,n):
    if(a[i] == a[i-1]):
        higher += a[i]
        continue

    if(a[p-1]- a[i] > m):
        print(i)
        exit()

    if(higher - a[i]*(i-p+1) > min(n-v,i-p+1)*m):
        print(i)
        exit()

    higher += a[i]

print(n)
Problem: p02824
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A, reverse=True)
count=P
for i in range(P,N):
    dif=sum(B[P-1:i])
    if V<=(P-1)+(N-i) and B[P-1]<=B[i]+M:
        count+=1
    elif M*(V-((P-1)+(N-i)))+dif<=(B[i]+M)*(i-P+1):
        count+=1
print(count)

Failing test case input:
6 1 2 2
2 1 1 5 0 0

Expected output:
4


Actual output:
6


Fixed submission (verdict: Accepted):
N,M,V,P=map(int,input().split())
B = sorted(list(map(int, input().split())))[::-1]
count=P
dif=0
for i in range(P,N):
    dif+=B[i-1]
    if V<=(P-1)+(N-i) and B[P-1]<=B[i]+M:
        count+=1
    elif dif-B[i]*(i-P+1)<=M*(N-V) and B[P-1]<=B[i]+M:
        count+=1
print(count)
Problem: p03044
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**6)

N = int(input())
edges = [[] for _ in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    if w % 2 == 0:
        edges[u-1].append((v-1, 1))
        edges[v-1].append((u-1, 1))
    else:
        edges[u-1].append((v-1, -1))
        edges[v-1].append((u-1, -1))

colors = [None] * N
def set_color(x, c):
    colors[x] = c
    for y, sgn in edges[x]:
        if colors[y] == None:
            set_color(y, c*sgn)
set_color(1, 1)
for z in colors:
    print(z)

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

Expected output:
0
1
0


Actual output:
-1
1
-1


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**6)

N = int(input())
edges = [[] for _ in range(N)]

for i in range(N-1):
    u, v, w = map(int, input().split())
    if w % 2 == 0:
        edges[u-1].append((v-1, 1))
        edges[v-1].append((u-1, 1))
    else:
        edges[u-1].append((v-1, -1))
        edges[v-1].append((u-1, -1))

colors = [None] * N
def set_color(x, c):
    colors[x] = c
    for y, sgn in edges[x]:
        if colors[y] == None:
            set_color(y, c*sgn)
set_color(0, 1)
for z in colors:
    print((z+1)
Problem: p03801
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int,input().split()))
b = list(range(n))
s = list(zip(a,b))
s.sort(reverse=True)
s.append([0,0])
ans = [0]*n
for i in range(n):
  dif = s[i][0]-s[i+1][0]
  ans[s[i][1]] += dif*(i+1)
print(*ans,sep="\n")

Failing test case input:
10
1 3 2 3 2 4 4 5 7 1

Expected output:
10
14
0
0
0
4
0
2
2
0


Actual output:
10
6
8
0
0
4
0
2
2
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int,input().split()))
b = list(range(n))
s = list(map(list,zip(a,b)))
s.sort(reverse=True)
s.append([0,0])
ans = [0]*n
for i in range(n):
  dif = s[i][0]-s[i+1][0]
  ans[s[i][1]] += dif*(i+1)
  if s[i+1][1]>s[i][1]:
    s[i+1][1] = s[i][1]
print(*ans,sep="\n")

Problem: p03801
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N):
    b.append([a[i], i+1])
b.sort(reverse = True)
ans = [0]*(N+1)
mini = N+1

for i in range(N-1):
    mini = min(mini, b[i][1])
    if b[i+1][0] - b[i][0] < 0:
        ans[mini] += (b[i][0] - b[i+1][0])*(i+1)

ans[1] += N
for i in range(N):
    print(ans[i+1])


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

Expected output:
8
13
0
0
0
0
0
0
8
0


Actual output:
18
13
0
0
0
0
0
0
8
0


Fixed submission (verdict: Accepted):
N = int(input())
a = list(map(int, input().split()))
b = []
for i in range(N):
    b.append([a[i], i+1])
b.sort(reverse = True)
ans = [0]*(N+1)
mini = N+1

for i in range(N-1):
    mini = min(mini, b[i][1])
    if b[i+1][0] - b[i][0] < 0:
        ans[mini] += (b[i][0] - b[i+1][0])*(i+1)

ans[1] += N*b[-1][0]
for i in range(N):
    print(ans[i+1])

Problem: p03801
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = map(int, input().split())
S = sorted([[a, i] for i, a in enumerate(A)], key=lambda x: x[0], reverse=True)
B = [0 for i in range(N)]
B[0] = N
num = S[0][1]
for i in range(1, N):
  if S[i - 1][0] > S[i][0]:
   B[num] += (S[i - 1][0] - S[i][0]) * i
  num = min(num, S[i][1])
for b in B:
  print(b)

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

Expected output:
16
6
0
8
0
0
0
0
0
0


Actual output:
26
6
0
8
0
0
0
0
0
0


Fixed submission (verdict: Accepted):
N = int(input())
A = map(int, input().split())
S = sorted([[a, i] for i, a in enumerate(A)], key=lambda x: x[0], reverse=True)
S.append([0, N])
B = [0 for i in range(N)]
num = S[0][1]
for i in range(1, N + 1):
  if S[i - 1][0] > S[i][0]:
   B[num] += (S[i - 1][0] - S[i][0]) * i
  num = min(num, S[i][1])
for b in B:
  print(b)
Problem: p03801
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
N = int(input())
A = list(map(int,input().split()))

L = list(range(N))

ZIP = zip(A, L)

ZIP = sorted(ZIP, reverse = True)

A, L = zip(*ZIP)

ans = []

for i in range(N-1):
    ans.append((A[i] - A[i+1]) * (i + 1))
ans.append(sum(A) - sum(ans))

ZIP = zip(L, ans)

ZIP = sorted(ZIP)

L, ans = zip(*ZIP)

for a in ans:
    print(a)

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

Expected output:
26
0
0
11
0
0
0
0
0
0


Actual output:
16
0
10
6
0
5
0
0
0
0


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

L = list(range(1, N+1))

ZIP = zip(A, L)

ZIP = sorted(ZIP, reverse = True)

A, L = zip(*ZIP)

ans = [0] * (N + 1)

MIN = float('INF')

for i in range(N-1):
    MIN = min(MIN, L[i])
    if A[i] - A[i+1] == 0:
        continue
    ans[MIN] += (A[i] - A[i+1]) * (i + 1)
ans[1] += sum(A) - sum(ans)

for i in range(1, N+1):
    print(ans[i])

Problem: p03801
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = list(map(int, input().split()))
b = [(a[i], i) for i in range(n)]
b.sort()
ans = [0 for i in range(n)]
ans[0] = b[0][0] * n
pre = b[0][0]
for i in range(1, n):
    if b[i-1][0] != b[i][0]:
        ans[b[i][1]] = (b[i][0] - pre) * (n-i)
        pre = b[i][0]
for i in range(n):
    print(ans[i])


Failing test case input:
10
3 3 1 7 1 4 1 3 2 0

Expected output:
20
0
0
5
0
0
0
0
0
0


Actual output:
5
0
9
3
0
2
0
0
6
0


Fixed submission (verdict: Accepted):
n = int(input())
a = list(map(int, input().split()))
b = [(a[i], i) for i in range(n)]
b.sort()
ans = [0 for i in range(n)]
ans[0] = b[0][0] * n
min_index = b[-1][1]
for i in range(n-1, 0, -1):
    min_index = min(min_index, b[i][1])
    if b[i-1][0] != b[i][0]:
        ans[min_index] += (b[i][0] - b[i-1][0]) * (n-i)
for i in range(n):
    print(ans[i])
Problem: p03390
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
q = int(input())
for i in range(q):
  a, b = list(map(int, input().split()))
  if a==b:
    ans = 2*a-2
  elif abs(a-b)==1:
    ans = 2*min(a, b)-2
  else:
    c = int((a*b)**0.5)
    if c*(c+1)>=a*b:
      ans = 2*c-2
    else:
      ans = 2*c-1
  print(ans)

Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Expected output:
1
12
4
11
14
57
31
671644785

Actual output:
2
12
4
11
14
57
31
671644785


Fixed submission (verdict: Accepted):
q = int(input())
for i in range(q):
  a, b = list(map(int, input().split()))
  if a==b:
    ans = 2*a-2
  elif abs(a-b)==1:
    ans = 2*min(a, b)-2
  else:
    c = (a*b)**0.5
    if c%1==0:
      c = int(c)-1
    else:
      c = int(c)
    if c*(c+1)>=a*b:
      ans = 2*c-2
    else:
      ans = 2*c-1
  print(ans)

Problem: p03390
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from math import sqrt

Q = int(input())

for i in range(Q):
    A,B = map(int, input().split())
    m=A*B
    C = int(sqrt(m))
    if C*C==m:
        C=C-1

    if C*(C+1)<m:
        ans = 2*C-1
    else:
            ans = 2*C-2
    print(ans)

Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Expected output:
1
12
4
11
14
57
31
671644785

Actual output:
1
12
3
11
14
57
31
671644785


Fixed submission (verdict: Accepted):
from math import sqrt

Q = int(input())

for i in range(Q):
    A,B = map(int, input().split())
    m=A*B

    C = int(sqrt(m))
    if C*C==m:
        C=C-1

    if A==B or B==A+1:
        ans = 2*A-2
    elif A==B+1:
        ans = 2*B-2
    elif C*(C+1)<m:
        ans = 2*C-1
    else:
        ans = 2*C-2
    print(ans)

Problem: p03390
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math 
Q=int(input())
A=[0 for i in range(Q)]
B=[0 for i in range(Q)]
for i in range(Q):
    A[i],B[i]=map(int,input().split())
for i in range(Q):
    C=A[i]*B[i]
    N=int(math.sqrt(C))
    D=0
    if N**2==C:
        N-=1
    else:
        while(True):
            if A[i]*B[i]<N**2:
                N-=1
            elif A[i]*B[i]>(N+1)**2:
                N+=1
            else:
                break
            print(N)
    M=2*N-1
    print(M)


Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Expected output:
1
12
4
11
14
57
31
671644785

Actual output:
1
13
3
11
15
57
31
671644785


Fixed submission (verdict: Accepted):
import math
Q=int(input())
for roop in range(Q):
    X,Y=map(int,input().split())
    A=min([X,Y])
    B=max([X,Y])
    if A==B:
        print(2*A-2)
    elif A+1==B:
        print(2*A-2)
    else:
        C=int(math.sqrt(A*B))
        while(True):
            if C**2>=A*B:
                C-=1
            elif (C+1)**2<A*B:
                C+=1
            else:
                break
        if C*(C+1)>=A*B:
            print(2*C-2)
        else:
            print(2*C-1)
Problem: p03390
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())

for i in range(n):
    a, b = map(int, input().split())

    p=int((a*b)**(1/2))
    print(p)
    if p*(p+1) < a*b:
        ans=int(2*p-1)
    elif p**2==a*b and not a==b:
        ans=int(2*p-3)
    else:
        ans=int(2*p-2)
    print(ans)


Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Expected output:
1
12
4
11
14
57
31
671644785

Actual output:
2
1
7
12
3
4
6
11
8
14
29
57
16
31
335822393
671644785


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

    p=int((a*b)**(1/2))

    if p*(p+1) < a*b:
        ans=int(2*p-1)
    elif p**2==a*b and not a==b:
        ans=int(2*p-3)
    else:
        ans=int(2*p-2)
    l.append(ans)

for i in range(n):
    print(l[i])

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


from math import ceil, sqrt

Q = int(input())
for i in range(Q):
    A, B = sorted(map(int, input().split(" ")))
    s = A*B

    if A == B:
        print(2*A - 2)
    elif A == B + 1:
        print(2*A - 2)
    else:
        C = ceil(sqrt(s)) - 1
        print(2*C - 1)

Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Expected output:
1
12
4
11
14
57
31
671644785

Actual output:
1
13
4
11
15
57
31
671644785


Fixed submission (verdict: Accepted):


from math import ceil, sqrt

Q = int(input())
for i in range(Q):
    A, B = sorted(map(int, input().split(" ")))
    s = A*B

    if A == B:
        print(2*A - 2)
    elif A == B + 1:
        print(2*A - 2)
    else:
        C = ceil(sqrt(s)) - 1
        if C*(C+1) >= s:
            print(2*C - 2)
        else:
            print(2*C - 1)

Problem: p03390
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math 
Q=int(input())
table=[]
for i in range(Q):
    a,b=map(int,input().split())
    if a>b:
        table.append([b,a])
    else:
        table.append([a,b])
ans=[]
for a,b in table:
    s = int(math.sqrt(a*b))
    num=2*s-2
    if s-1>=a:
        num-=1
    if s*(s+1)<a*b:
        num+=2
    elif s*s<a*b:
        num+=1
    ans.append(num)
print('\n'.join(map(str,ans)))

Failing test case input:
8
1 4
10 5
3 3
4 11
8 9
22 40
8 36
314159265 358979323

Expected output:
1
12
4
11
14
57
31
671644785

Actual output:
1
12
4
11
15
57
31
671644785


Fixed submission (verdict: Accepted):
from math import sqrt 
Q = int(input())
table=[]
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        table.append([B,A])
    else:
        table.append([A,B])
def f(a,b):
    if a==b:
        return 2*a-2
    if a+1==b:
        return 2*a-2
    m = int(sqrt(a*b))
    if m**2 ==a*b:
        m-=1
    if m*(m+1) >= a*b:
        return 2*m -2
    return 2*m-1

ans = []
for a,b in table:
    ans.append(f(a,b))
print('\n'.join(map(str,ans)))
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n = int(input())
cnt = 0
a = 0
for _ in range(n):
    x = int(input())
    cnt += (a+x)
    a = (a+x)%2
print(cnt)


Failing test case input:
4
-1
0
4
1

Expected output:
1


Actual output:
7


Fixed submission (verdict: Accepted):

n = int(input())
cnt = 0
s = 0
for _ in range(n):
    x = int(input())
    if x==0:
        cnt += s
        s = 0
    else:
        s += x
print(cnt+s

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= ccnt*2
    cnt += ccnt
print(cnt)


Failing test case input:
8
2
0
2
9
1
5
1
1

Expected output:
10


Actual output:
129


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
if N==1:
    print(A[0]
    quit()
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt
print(cnt)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, *a = map(int, open(0).read().split())

ans = prev = 0
for i in a:
        tmp = divmod(i+prev, 2)
        ans += tmp[0]
        if i==0: prev=0
print(ans)

Failing test case input:
8
1
0
1
9
1
12
4
0

Expected output:
13


Actual output:
12


Fixed submission (verdict: Accepted):
n, *a = map(int, open(0).read().split())

ans = prev = 0
for i in a:
        tmp, prev = divmod(i+prev, 2)
        ans += tmp
        if i==0: prev=0
print(ans)

Problem: p04020
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

ans=0
      
for i in range(N-1):
    ans+=(l[i]-l[i]%2)/2
    l[i]=l[i]%2
    if l[i+1]!=0:
        ans+=l[i]
        l[i+1]-=l[i]
print(ans)
    
    

Failing test case input:
4
6
0
3
1

Expected output:
5


Actual output:
5.0


Fixed submission (verdict: Accepted):
N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

ans=0
      
for i in range(N-1):
    ans+=(l[i]-l[i]%2)/2
    l[i]=(l[i]%2)
    if l[i+1]!=0:
        ans+=l[i]
        l[i+1]-=l[i]
ans+=(l[-1]-l[-1]%2)/2
print(int(ans))

Problem: p04020
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
n=int(input())
tmp, ans=0,0
for i in range(n):
  a=int(input())
  if a==0:
    ans+=tmp
    tmp=0
  else:
    tmp+=a
print(ans)


Failing test case input:
8
1
1
1
1
1
5
0
1

Expected output:
5


Actual output:
10


Fixed submission (verdict: Accepted):
n=int(input())
tmp, ans=0,0
for i in range(n):
  a=int(input())
  if a==0:
    ans+=tmp
    tmp=0
  else:
    tmp+=a
print(ans+tmp
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N-1, 0, -1):
    ans += (A[i] + A[i-1])
    A[i-1] = min(A[i-1], (A[i] + A[i-1]) % 2)
print(ans)


Failing test case input:
8
2
0
1
9
1
5
1
1

Expected output:
10


Actual output:
22


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    ans += (A[i] + A[i+1])
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
if N == 1:
    print(A[0]
    exit()
print(ans)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for _ in range(N)]
A.append(0)

A.sort()

con = False
ans = 0
for i in range(N):
    if A[i] >=2:
        ans += A[i]
        A[i] -= A[i]
    
    mm = min(A[i+1],A[i])
    ans += mm
    A[i+1] -= mm
    A[i] -= mm


print(ans)

Failing test case input:
4
12
0
3
0

Expected output:
7


Actual output:
3


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for _ in range(N)]
A.append(0)

con = False
ans = 0

for i in range(N):
    if A[i] >=2:
        ans += A[i]
        A[i] -= (A[i]
    
    mm = min(A[i+1],A[i])
    ans += mm
    A[i+1] -= mm
    A[i] -= mm
    


print(ans)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = 0
    cnt += ccnt
print(cnt)

Failing test case input:
4
0
1
6
0

Expected output:
3


Actual output:
1


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
if N==1:
    print(A[0]
    quit()
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt
print(cnt)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, *a = map(int, open(0).read().split())

ans = prev = 0
for i in a:
        ans += i
        if i%2:
                ans += prev
                prev ^= 1
        else: prev = 0
print(ans)

Failing test case input:
8
1
1
2
0
1
4
2
1

Expected output:
6


Actual output:
13


Fixed submission (verdict: Accepted):
n, *a = map(int, open(0).read().split())

ans = prev = 0
for i in a:
        tmp, prev = divmod(i+prev, 2)
        ans += tmp
        if i==0: prev=0
print(ans)
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

n=int(input())
modlists=[0]*n
counter=0
for  i in range(n):
    s=int(input())
    a,b=divmod(s,2)
    counter+=a
    modlists[i]=b


add=0
modlists.append(0)
for i in range(n+1):
    if modlists[i]==1:
        add+=1
    else:
        counter+=add
        add=0
print(counter)


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

Expected output:
8


Actual output:
10


Fixed submission (verdict: Accepted):

n=int(input())
modlists=[0]*(n+1)
for  i in range(n):
    s=int(input())
    modlists[i]=s
add=0
lefted=0
for i in range(n):
    if modlists[i]!=0:
        add+=modlists[i]
    elif modlists[i]==0:
        lefted+=add%2
        add=0
sums=sum(modlists)
print((sums-lefted)

Problem: p04020
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

ans=0
      
for i in range(N-1):
    ans+=(l[i]-l[i]%2)/2
    l[i]=l[i]%2
    if l[i+1]!=0:
        ans+=l[i]
        l[i+1]-=l[i]
print(int(ans))
   

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

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):
N=int(input())
l=[]

for i in range(N):
    l.append(int(input()))

ans=0
      
for i in range(N-1):
    ans+=(l[i]-l[i]%2)/2
    l[i]=(l[i]%2)
    if l[i+1]!=0:
        ans+=l[i]
        l[i+1]-=l[i]
ans+=(l[-1]-l[-1]%2)/2
print(int(ans))

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] = max(0, A[i+1] - ccnt*2 - A[i])
    
    cnt += ccnt
print(cnt)

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

Expected output:
8


Actual output:
16


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
if N==1:
    print(A[0]
    quit()
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt
print(cnt)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
res = 0
for i in range(0,n):
    res += a[i] 
    a[i] = a[i] % 2

for i in range(0,n-1):
    if a[i] == 1 and a[i+1] == 1:
        res += 1
        a[i] -= 1
        a[i+1] -= 1

print(res)

Failing test case input:
4
-6
0
0
0

Expected output:
-3


Actual output:
-6


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
res = 0
if n == 1:
    print(a[0] 
else:
    for i in range(0, n):
        res += a[i] 
        if i != n - 1 and a[i] % 2 == 1 and a[i + 1] != 0:
            res += 1
            a[i + 1] -= 1
    print(res)
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n, *a = map(int, open(0).read().split())

ans = prev = 0
for i in a:
        ans += i
        if i%2: ans += prev
        else: prev = 0
print(ans)

Failing test case input:
8
1
1
0
25
4
3
5
1

Expected output:
20


Actual output:
40


Fixed submission (verdict: Accepted):
n, *a = map(int, open(0).read().split())

ans = prev = 0
for i in a:
        tmp, prev = divmod(i+prev, 2)
        ans += tmp
        if i==0: prev=0
print(ans)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    ans = 0
    L = [0]
    for i in range(N):
        num = int(input())
        ans += num
        rest = num%2
        if (L[-1] == 1 and rest == 1):
            ans += 1
            L.append(0)
        else:
            L.append(rest)
            
    print(ans)
    
if __name__ == "__main__":
    main()


Failing test case input:
8
0
0
1
1
1
5
2
2

Expected output:
6


Actual output:
14


Fixed submission (verdict: Accepted):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    ans = 0
    L = [0]
    for i in range(N):
        num = int(input())
        if L[-1] == 0:
            ans += (num
            L.append(num%2)
        else:
            if num == 0:
                L.append(num)
                continue
            else:
                num -= 1
                ans += (num
                L.append(num%2)
                
    print(ans)
            
if __name__ == "__main__":
    main()

Problem: p04020
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
for i in range(n):
    p,r = divmod(A[i], 2)
    A[i] = r
    ans += p
for i in range(n-1):
    if A[i]*A[i+1]:
        A[i+1] -= 1
        ans += 1
print(ans)

Failing test case input:
8
2
0
1
6
-1
8
2
1

Expected output:
9


Actual output:
8


Fixed submission (verdict: Accepted):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
for i in range(n-1):
    p,r = divmod(A[i], 2)
    A[i] = r
    ans += p
    if A[i]*A[i+1]:
        A[i+1] -= 1
        ans += 1
print(ans+A[-1]
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0

for i in range(N-1):
    
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt

print(cnt)

Failing test case input:
8
1
0
1
9
1
12
4
0

Expected output:
13


Actual output:
10


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
if N==1:
    print(A[0]
    quit()
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt
print(cnt)

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

n=int(input())
modlists=[0]*(n+1)
for  i in range(n):
    s=int(input())
    modlists[i]=s
add=0
for i in range(n):
    ch=min(modlists[i],modlists[i+1])
    add+=ch
    modlists[i]-=ch
    modlists[i+1]-=ch
for i in range(n):
    add+=modlists[i]
print(add)

Failing test case input:
8
0
0
1
4
0
5
1
0

Expected output:
5


Actual output:
9


Fixed submission (verdict: Accepted):

n=int(input())
modlists=[0]*(n+1)
for  i in range(n):
    s=int(input())
    modlists[i]=s
add=0
lefted=0
for i in range(n):
    if modlists[i]!=0:
        add+=modlists[i]
    elif modlists[i]==0:
        lefted+=add%2
        add=0
sums=sum(modlists)
print((sums-lefted)

Problem: p04020
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input=sys.stdin.readline

n=int(input())
a=[int(input()) for _ in range(n)]
ans=0
for i in range(n-1):
    ans+=(a[i]+a[i+1])
    a[i+1]=min(0,(a[i]+a[i+1])%2)

print(ans)


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

Expected output:
6


Actual output:
13


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

n=int(input())
a=[int(input()) for _ in range(n)]
ans=0
s=0
for i in range(n):
    s+=a[i]
    if a[i]==0:
        ans+=(s
        s=0
ans+=(s
print(ans)

Problem: p04020
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
n = int(input())
lis = [int(input()) for i in range(n)]

ans = 0
for i in range(n):
    ans += lis[i] 
    lis[i] %= 2

flag = 0
for i in lis:
    if flag and i:
        ans += 1
        flag = 0
    else:
        flag = i

print(ans)

Failing test case input:
4
0
0
6
1

Expected output:
3


Actual output:
7


Fixed submission (verdict: Accepted):
n = int(input())
lis = [int(input()) for i in range(n)]

ans = 0
for i in range(n):
    temp, mod = divmod(lis[i], 2)
    ans += temp
    if i < n-1 and lis[i+1] != 0:
        lis[i+1] += mod

print(ans)
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    ans += (A[i] + A[i+1])
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
print(ans)


Failing test case input:
4
0
1
6
0

Expected output:
3


Actual output:
9


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N-1):
    ans += (A[i] + A[i+1])
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
if N == 1:
    print(A[0]
    exit()
print(ans)

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

n = int(input())
cnt = 0
a = 0
for _ in range(n):
    x = int(input())
    cnt += (a+x)
    a = x%2
print(cnt)


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

Expected output:
7


Actual output:
19


Fixed submission (verdict: Accepted):

n = int(input())
cnt = 0
s = 0
for _ in range(n):
    x = int(input())
    if x==0:
        cnt += s
        s = 0
    else:
        s += x
print(cnt+s

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [int(input()) for k in range(N)]

ans = 0
for k in range(N-1):
    temp = min(A[k],A[k+1])
    ans += temp
    A[k] -= temp
    A[k+1] -= temp
 
for k in range(N):
    ans += A[k]

print(ans)

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

Expected output:
7


Actual output:
11


Fixed submission (verdict: Accepted):
N = int(input())
A = [int(input()) for k in range(N)]

ans = 0
temp = 0
for x in A:
    if x == 0:
        ans += temp
        temp = 0
    else:
        temp += x

print(ans+temp

Problem: p04020
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N = I()
A = [I() for _ in range(N)]

ans = 0
for i in range(N):
    ans += A[i]
    A[i] = A[i] % 2

for i in range(N-1):
    if A[i] == A[i+1] == 1:
        ans += 1
        A[i] = 0
        A[i+1] = 0

print(ans)


Failing test case input:
8
0
0
1
2
1
5
0
1

Expected output:
4


Actual output:
11


Fixed submission (verdict: Accepted):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N = I()
A = [I() for _ in range(N)]

ans = 0
for i in range(N):
    ans += A[i]
    A[i] -= 2*(A[i]
    if A[i] == 1 and i < N-1 and A[i+1] >= 1:
        ans += 1
        A[i] = 0
        A[i+1] -= 1

print(ans)
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] = max(0, A[i+1] - ccnt*2 - A[i])
    A[i] = max(0, A[i] - ccnt*2)
    cnt += ccnt
print(cnt)

Failing test case input:
8
0
0
1
1
1
5
1
2

Expected output:
5


Actual output:
11


Fixed submission (verdict: Accepted):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
if N==1:
    print(A[0]
    quit()
for i in range(N-1):
    ccnt = (A[i] + A[i+1]) 
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt
print(cnt)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N=int(input())
ans=0
A=[]
for _ in range(N):
    ipt=int(input())
    ans+=ipt
    A.append(ipt%2)

for i in range(N-1):
    if A[i+1]==1 and A[i]==1: 
        A[i+1]=0;A[i]=0
        ans+=1

print(ans)

Failing test case input:
8
1
1
1
0
1
5
0
1

Expected output:
4


Actual output:
12


Fixed submission (verdict: Accepted):
N=int(input())
A=[int(input()) for _ in range(N)]
cnt=0;ans=0
for i in range(N):
    if A[i] != 0:
        cnt+= A[i]
    else:
        ans+=(cnt
        cnt=0
print(ans+cnt

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())
A = [0] * N
count = 0
for n in range(N):
    num = int(input())
    count += num 
    A[n] = num % 2

for n in range(N - 1):
    if A[n] == 1 and A[n + 1] == 1:
        A[n] = 0
        A[n + 1] = 0
        count += 1
print(count)

Failing test case input:
8
2
0
1
9
1
8
2
1

Expected output:
12


Actual output:
25


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

A = [0] * N
count = 0
for n in range(N):
    A[n] = int(input())

if all(A):
    print(sum(A) 
    sys.exit()

index = 0
for n in range(N):
    if A[n] == 0:
        count += (sum(A[index: n]) 
        index = n
count += sum(A[index:]) 
print(count)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
res = 0
for i in range(0,n):
    res += a[i] 
    a[i] = a[i] % 2
if n > 1:
    for i in range(0,n-1):
        if a[i] == 1 and a[i+1] == 1:
            res += 1
            a[i] -= 1
            a[i+1] -= 1

print(res)

Failing test case input:
8
0
0
1
4
1
5
1
0

Expected output:
6


Actual output:
13


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
res = 0
if n == 1:
    print(a[0] 
else:
    for i in range(0, n):
        res += a[i] 
        if i != n - 1 and a[i] % 2 == 1 and a[i + 1] != 0:
            res += 1
            a[i + 1] -= 1
    print(res)
Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n = int(input())
a = [int(input()) for i in range(n)]
res = 0
for i in range(0,n-1):
    if a[i] == 0:
        continue
    elif a[i] <= a[i+1]:
        res += a[i]
        a[i+1]-= a[i]
    else:
        res += a[i+1]
        res += (a[i]- a[i+1]) 
        a[i+1]=0

print(res)

Failing test case input:
4
6
0
3
0

Expected output:
4


Actual output:
9


Fixed submission (verdict: Accepted):
n = int(input())
a = [int(input()) for i in range(n)]
res = 0
if n == 1:
    print(a[0] 
else:
    for i in range(0, n):
        res += a[i] 
        if i != n - 1 and a[i] % 2 == 1 and a[i + 1] != 0:
            res += 1
            a[i + 1] -= 1
    print(res)

Problem: p04020
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
input=sys.stdin.readline

n=int(input())
a=[int(input()) for _ in range(n)]
ans=0
for i in range(n-1):
    ans+=(a[i]+a[i+1])
    a[i+1]=min(a[i+1],(a[i]+a[i+1])%2)

print(ans)


Failing test case input:
8
1
0
2
9
1
12
5
1

Expected output:
15


Actual output:
33


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

n=int(input())
a=[int(input()) for _ in range(n)]
ans=0
s=0
for i in range(n):
    s+=a[i]
    if a[i]==0:
        ans+=(s
        s=0
ans+=(s
print(ans)

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


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0
prev = 0
for i in range(N):
    q, mod = divmod(A[i], 2)
    ans += q
    prev += mod
    if prev == 2:
        ans += 1
        prev = 0
    else:
        prev = mod

print(ans)

Failing test case input:
8
2
0
1
9
0
5
4
1

Expected output:
11


Actual output:
10


Fixed submission (verdict: Accepted):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0
prev = 0
for i in range(N):
    if prev == 1 and A[i] > 0:
        A[i] -= 1
        ans += 1
    q, mod = divmod(A[i], 2)
    ans += q
    prev = mod

print(ans)

Problem: p04020
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
N = int(input())

A = [0] * N
count = 0
for n in range(N):
    A[n] = int(input())

for n in range(N - 1):
    count += A[n] 
    if A[n] % 2 and A[n + 1] != 0:
        A[n] = 0
        A[n + 1] -= 1
        count += 1
print(count)

Failing test case input:
8
2
0
1
6
0
8
1
1

Expected output:
9


Actual output:
19


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

A = [0] * N
count = 0
for n in range(N):
    A[n] = int(input())

if all(A):
    print(sum(A) 
    sys.exit()

index = 0
for n in range(N):
    if A[n] == 0:
        count += (sum(A[index: n]) 
        index = n
count += sum(A[index:]) 
print(count)
Problem: p03938
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n=int(input())
prr = list(map(int,input().split()))
arr=[]
brr=[]
cumsum=0
for p in prr:
    cumsum+=p
    arr.append(cumsum)
cumsum=0
print(" ".join(map(str,arr)))
for p in reversed(prr):
    cumsum+=p
    brr.append(cumsum)
print(" ".join(map(str,reversed(brr))))


Failing test case input:
3
-2 0 2

Expected output:
1 4 6
6 5 2


Actual output:
-2 -2 0
0 2 2


Fixed submission (verdict: Accepted):
n=int(input())
pprr = list(map(int,input().split()))
prr=[0]*n
for ix,p in enumerate(pprr):
    prr[p-1]=ix+1

arr=[]
brr=[]
cumsum=0
for p in prr:
    cumsum+=p
    arr.append(cumsum)
cumsum=0
print(" ".join(map(str,arr)))
for p in reversed(prr):
    cumsum+=p
    brr.append(cumsum)
print(" ".join(map(str,reversed(brr))))
Problem: p03649
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math
def main():
    n = int(input())
    l = list(map(int, input().split()))
    c = 0
    while max(l) > n-1:
        l.sort(reverse=True)
        tc = [0] * n
        for i in range(n):
            if l[i] >= n:
                tc[i] = math.ceil((l[i] - n + 1)/(n-1))
                l[i] -= tc[i] * n
        stc = sum(tc)
        for i in range(n):
            l[i] += stc - tc[i]
        c += stc
    return c
print(main())


Failing test case input:
7
27 0 0 0 0 0 0

Expected output:
3

Actual output:
4


Fixed submission (verdict: Accepted):
import math
def main():
    n = int(input())
    l = list(map(int, input().split()))
    c = 0
    while max(l) > n-1:
        l.sort(reverse=True)
        tc = [0] * n
        for i in range(n):
            if l[i] >= n:
                tc[i] = math.ceil((l[i] - n + 1)/n)
                l[i] -= tc[i] * n
        stc = sum(tc)
        for i in range(n):
            l[i] += stc - tc[i]
        c += stc
    return c
print(main())

Problem: p03649
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    k=int(input())
    n=50
    q=k
    r=k%n
    A=[q+n-r+1+i for i in range(r)]+[q+i for i in range(n-r)]
    print(n)
    print(*A)
resolve()

Failing test case input:
10
1000 9 120 575 1 0 2444 23811074 1 0

Expected output:
23815160


Actual output:
50
51 52 53 54 55 56 57 58 59 60 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)

    while(max(A)>=n):
        k=sum(a
        for i in range(n):
            A[i]+=(k-A[i]

    print(s-sum(A))
resolve()
Problem: p03534
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from collections import Counter

s = input().strip()
c = Counter(s)
v = list(c.values())
if max(v) - min(v) > 1: 
  print("NO")
else:
  print("YES")

Failing test case input:
bab

Expected output:
NO


Actual output:
YES


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

s = input().strip() + "abc"
c = Counter(s)
v = list(c.values())
if max(v) - min(v) > 1: 
  print("NO")
else:
  print("YES")

Problem: p03534
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
R = list(input())
A = int(R.count("a"))
B = int(R.count("b"))
C = int(R.count("c"))
check = [A, B, C]
check.sort
if check[0] - check[2] > 1:
 print("NO")
else:
 print("YES")

Failing test case input:
acac

Expected output:
NO


Actual output:
YES


Fixed submission (verdict: Accepted):
R = list(input())
A = int(R.count("a"))
B = int(R.count("b"))
C = int(R.count("c"))
check = [A, B, C]
if sorted(check)[2] - sorted(check)[0] > 1:
 print("NO")
else:
 print("YES")

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

S = list(input())

count = dict(collections.Counter(S))
m = list(count.values())

if len(m) == 1: 
    print("YES")
elif len(m) == 2 and len(S) == 2:
    print("YES")
elif len(m) == 2 and len(S) > 2:
    print("NO")
elif (max(m) - min(m)) <= 1:
    print("YES")
else:
    print("NO")


Failing test case input:
bbb

Expected output:
NO


Actual output:
YES


Fixed submission (verdict: Accepted):
import collections
import math

S = list(input())

count = dict(collections.Counter(S))
m = list(count.values())

if len(m) == 1 and len(S) == 1: 
    print("YES")
elif len(m) == 1 and len(S) > 1:
    print("NO")
elif len(m) == 2 and len(S) == 2:
    print("YES")
elif len(m) == 2 and len(S) > 2:
    print("NO")
elif (max(m) - min(m)) <= 1:
    print("YES")
else:
    print("NO")

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

def answer(s):
    YES = 'YES'
    NO = 'NO'
    dic = collections.Counter(s)
    vals = sorted([v for k,v in dic.items()], reverse=True)
    if len(vals) == 1: return YES
    elif len(vals) == 2:
        if vals[0] == 1 and vals[1] == 1: return YES
        else: return NO
    
    _max = vals[0]
    _sum = sum(vals[1:])
    if (_max-1)*2 <= _sum:
        if vals[1]-vals[2] > 1: return NO
        else: return YES
    return NO
s = input()
print(answer(s))

Failing test case input:
bbb

Expected output:
NO


Actual output:
YES


Fixed submission (verdict: Accepted):
import collections

def answer(s):
    YES = 'YES'
    NO = 'NO'
    dic = collections.Counter(s)
    vals = sorted([v for k,v in dic.items()], reverse=True)
    if len(vals) == 1:
        if vals[0] == 1: return YES
        else: return NO
    elif len(vals) == 2:
        if vals[0] == 1 and vals[1] == 1: return YES
        else: return NO
    
    _max = vals[0]
    _sum = sum(vals[1:])
    if (_max-1)*2 <= _sum:
        if vals[1]-vals[2] > 1: return NO
        else: return YES
    return NO

s = input()
print(answer(s))