Problem:


Score : 400 points

Problem Statement

Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it.
He has A_i cards with an integer i.

Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.

Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.

Constraints

1 ≦ N ≦ 10^5

0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the maximum number of pairs that Snuke can create.

Sample Input 1

4
4
0
3
2

Sample Output 1

4

For example, Snuke can create the following four pairs: (1,1),(1,1),(3,4),(3,4).

Sample Input 2

8
2
0
1
6
0
8
2
1

Sample Output 2

9



Sample input:
4
4
0
3
2


Sample output:
4

Submission status: Wrong Answer

Solution code:
N,*A = map(int, open(0).read().split())
ans = 0
for i in range(N):
    if A[i] > 2:
        if A[i] % 2 == 0:
            ans += A[i] // 2 - 1
            A[i] = 2
        else:
            ans += A[i] // 2
            A[i] = 1
for i in range(1,N):
    if A[i] > 0:
        if A[i-1] > 0:
            temp = min(A[i],A[i-1])
            ans += temp
            A[i] -= temp
for i in range(N):
    if A[i] == 2:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N,*A = map(int, open(0).read().split())
ans = 0
for i in range(N):
    if A[i] > 2:
        if A[i] % 2 == 0:
            ans += A[i] // 2 - 1
            A[i] = 2
        else:
            ans += A[i] // 2
            A[i] = 1
for i in range(1,N):
    if A[i] > 0:
        if A[i-1] > 0:
            temp = min(A[i],A[i-1])
            ans += temp
            A[i] -= temp
print(ans)

Submission status: Wrong Answer

Solution code:
N,*A = map(int, open(0).read().split())
ans = 0
for i in range(N):
    d,m = divmod(A[i],2)
    ans += d
    A[i] = m
for i in range(1,N):
    if A[i] == 1:
        if A[i-1] == 1:
            ans += 1
            A[i] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
n = int(sys.stdin.readline())
ans = 0
pr_a = -100
for i in range(n):
    a = int(sys.stdin.readline())
    if a>=2:
        ans += a//2
        a %= 2
    if pr_a>0 and a>0:
        t = min(pr_a, a)
        ans += t
        a -= t
    pr_a = a
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
cnt = 0
for i in range(1,N-1):
    if A[i]==0:
        cnt += A[i-1]//2
    else:
        cnt += (A[i-1]+A[i]+A[i+1])//2
        if A[i+1]>0:
            A[i+1] = (A[i-1]+A[i]+A[i+1])%2
        A[i] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
cnt = 0
for i in range(1,N-1):
    if A[i]==0:
        cnt += A[i-1]//2
    else:
        cnt += (A[i-1]+A[i]+A[i+1])//2
        A[i+1] = (A[i-1]+A[i]+A[i+1])%2
        A[i] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
cnt = 0
for i in range(1,N-1):
    if A[i]>0:
        cnt += (A[i-1]+A[i]+A[i+1])//2
        A[i+1] = (A[i-1]+A[i]+A[i+1])%2
        A[i] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for i in range(N)]
ans = 0
for i in range(N):
    ans += A[i] // 2
    if A[i] % 2 == 1:
        A[i] = 1
    else:
        A[i] = 0

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]

cnt = 0
for i in range(n):
    if i!=0:
        if A[i] >= A[i-1]:
            A[i] -= A[i-1]
            cnt += A[i-1]
        else:
            cnt += A[i]
            A[i] = 0
    if i!=n-1:
        if A[i] >= A[i+1]:
            A[i] -= A[i+1]
            cnt += A[i+1]
            A[i+1] = 0
        else:
            A[i+1] -= A[i]
            cnt += A[i]
            A[i] = 0
for i in range(n):
    if A[i] >= 2:
        cnt += A[i]//2
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
cnt = 0
for _ in range(N):
    a = int(input())
    cnt += a//2
    A.append(a%2)
cur = 0
for i in range(N):
    if A[i]==1:
        cur += 1
    else:
        cnt += cur//2
        cur = 0
cnt += cur//2
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
cnt = 0
for _ in range(N):
    a = int(input())
    cnt += a//2
    A.append(a%2)
cur = 0
for i in range(N):
    if A[i]==1:
        cur += 1
    else:
        cnt += cur//2
        cur = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
ans=0
for _ in range(n):
    a.append(int(input()))

for i in range(n-1):
    if a[i]==a[i+1]:
        ans+=a[i]
        a[i],a[i+1]=0,0
    elif a[i]>a[i+1]:
        if a[i]%2==0:
            ans+=a[i]//2
            a[i]=0
        else:
            ans+=(a[i]-1)//2
            a[i]=1
        if a[i]<a[i+1]:
            ans+=a[i]
            a[i+1]-=a[i]
            a[i]=0
    elif a[i]<a[i+1]:
        ans+=a[i]
        a[i+1]-=a[i]
        a[i]=0

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
ans=0
for _ in range(n):
    x=int(input())
    if x%2==0:
        ans+=x//2
        a.append(0)
    else:
        ans+=(x-1)//2
        a.append(1)

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    # n, m = [int(x) for x in input().split()]
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    ans = 0
    for i in range(n):
        x = a[i] // 2
        a[i] %= 2
        ans += x
    for i in range(n-1):
        if a[i] and a[i+1]:
            ans += 1
            a[i+1] -= 1
            
    print(ans)



t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

"""

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
n = 0
for i in range(N):
    a = int(input())
    if(a != 0 and n > 0):
        ans += 1
        a -= 1
        n = 0
    elif(a == 0):
        n = 0
        
    if(a > 1):
        ans += a//2
        n = a - a//2
    
print(ans)

Submission status: Wrong Answer

Solution code:
N,*A=open(0).read().split()
print(sum([sum(map(int,t))//2 for t in ''.join(A).split('0')]))

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    A = list(in_na())

    ans = 0
    for i in range(N):
        if A[i] >= 3:
            if A[i] % 2 == 0:
                ans += (A[i] - 2) // 2
                A[i] = 2
            else:
                ans += (A[i] - 1) // 2
                A[i] = 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    A = list(in_na())

    ans = 0
    for i in range(N):
        if A[i] >= 3:
            if A[i] % 2 == 0:
                ans += (A[i] - 2) // 2
                A[i] = 2
            else:
                ans += (A[i] - 1) // 2
                A[i] = 1

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    A = list(in_na())

    ans = 0
    for i in range(N):
        if A[i] >= 3:
            if A[i] % 2 == 0:
                ans += (A[i] - 2) // 2
                A[i] = 2
            else:
                ans += (A[i] - 1) // 2
                A[i] = 1

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

    print(A)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

ans, tmp = 0, 0
for ai in a:
    ans += (ai + tmp) // 2
    tmp = 0
    if ai == 0:
        tmp = (ai + tmp) % 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

ans, tmp = 0, 0
for ai in a:
    ans += (ai + tmp) // 2
    tmp = 0
    if ai != 0:
        tmp = (ai + tmp) % 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

ans, tmp = 0, 0
for ai in a:
    ans += (ai + tmp) // 2 
    tmp = abs(tmp - ai % 2)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

ans, tmp = 0, 0
for ai in a:
    ans += (ai + tmp) // 2
    tmp = ai % 2
print(ans)

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())
A = [0] + A + [0]
ans_forward = 0
ans_backward = 0
for i in range(N):
    ans_forward += A[i + 1] // 2 + (A[i] % 2 & A[i + 1] % 2)
for i in range(N, 0, -1):
    ans_backward += A[i] // 2 + (A[i + 1] % 2 & A[i] % 2)
print(max(ans_forward, ans_backward))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(input()) for _ in range(n)]
a = A.copy()
use = [True]*n
ans = 0

for i in range(n):
    use[i] = a[i] < 2
    ans += a[i] // 2
    a[i] %= 2

for i in range(n - 1):
    if use[i] and use[i + 1]:
        if a[i] == a[i+1] == 1:
            ans += 1
            a[i], a[i + 1] = 0, 0
    elif not (use[i] or use[i + 1]):
        if a[i] == a[i+1] == 1 and A[i] == A[i + 1]:
            ans += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
for i in range(n):
    a[i] = int(input())
ans = sum(num//2 for num in a)
a = [num%2 for num in a]
for i in range(n):
    if i+1<n and a[i] and a[i+1]:
        ans += 1
        a[i+1] = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
for i in range(n):
    a[i] = int(input())
ans = 0
for i in range(n):
    num = a[i]
    if num%2==0:
        ans += num//2
    elif i+1<n and a[i+1]%2==1:
        ans += num//2
        ans += 1
        a[i+1] -= 1
    else:
        ans += num//2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
prev = 0
for i in range(N):
  a = int(input())
  ans += a // 2
  if prev == 1 and a % 2:
    ans += 1
    a -= 1
  prev = a % 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

A = [0]*(n+1)

ans = 0
for i in range(n):
    a = int(input())
    ans += a//2
    A[i] = a%2
    
for i in range(n):
    if A[i]==1 and A[i+1]==1:
        ans += 1
        A[i] = 0
        A[i+1] = 0
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

A = [0]*(n+1)

ans = 0
for i in range(n):
    a = int(input())
    ans += a//2
    A[i] = a%2
    
for i in range(n):
    if A[i]==1 and A[i+1]==1:
        ans += 1
        A[i+1] -= 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

A = [0]*(n+1)

ans = 0
for i in range(n):
    a = int(input())
    ans += a//2
    A[i] = a%2
    
for i in range(n):
    if A[i] and A[i+1]:
        ans += 1
        A[i+1] -= 1
        
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

A = [0]*n
ans = 0
for i in range(n):
    a = int(input())
    ans += a//2
    A[i] = a%2

#print(A)

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

Submission status: Wrong Answer

Solution code:
import copy

n = int(input())

A = [0]*n
ans = 0
for i in range(n):
    a = int(input())
    ans += a//2
    A[i] = a%2

tmp1 = 0
tmp2 = 0

Ac = copy.deepcopy(A)
for i in range(n-1):
    if Ac[i] == 1:
        if Ac[i+1] == 1:
            tmp1 += 1
            Ac[i+1] = 0

Ac = copy.deepcopy(A)[::-1]
for i in range(n-1):
    if Ac[i] == 1:
        if Ac[i+1] == 1:
            tmp2 += 1
            Ac[i+1] = 0
            
print(max(ans+tmp1, ans+tmp2))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int, cnv=list):
    return cnv(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    N = int(input())
    vA = [int(input()) for _ in [0,]*N]

    res = 0
    odd = 0

    for a in vA:
        x = a//2
        q = a%2
        y = odd&q
        res += x + y
        odd = (a-y)%2
        # print(res,a,x,odd)####

    print(res)
    # print("No Yes".split()[res])

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int, cnv=list):
    return cnv(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    N = int(input())
    vA = [int(input()) for _ in [0,]*N]

    res = 0
    odd = 0

    for a in vA:
        x = (a+odd)//2
        res += x
        odd = (a+odd) - 2*x
        #print(res,a,x,odd)####

    print(res)
    # print("No Yes".split()[res])

main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

# from collections import deque

def linput(_t=int, cnv=list):
    return cnv(map(_t, input().split()))

def gcd(n,m):
    while m: n,m = m, n%m
    return n

def lcm(n,m): return n*m//gcd(n,m)

def main():
    N = int(input())
    vA = [int(input()) for _ in [0,]*N]

    res = 0
    odd = 0

    for a in vA:
        x = (a+odd)//2
        res += x
        odd = a - 2*x

    print(res)
    # print("No Yes".split()[res])

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
prev = 0
res = 0
for _ in range(n):
    x = int(input())
    #print(res,x)
    res += x // 2
    x = x % 2
    if x == 1 and prev == 1:
        res += 1
        prev = 0
    pres = x
print(res)

Submission status: Wrong Answer

Solution code:
ans=0
c=0
for i in range(int(input())):
    k=int(input())
    ans+=k//2
    if k%2:c+=1
    else:
        ans+=c//2
        c=0
print(ans+c//2)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    A = [int(input()) for _ in range(n)]
    ans = sum([a // 2 for a in A])
    A = [a % 2 for a in A]
    for i in range(n - 1):
        if A[i] == A[i + 1] == 1:
            ans += 1
            A[i] = 0
            A[i + 1] = 0
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=0
flag=0
for i in range(N):
  a=int(input())
  ans+=a//2
  a%=2
  if a==1:
    if flag:
      ans+=1
      a-=1
      flag=0
    else:
      flag=1
  else:
    flag=0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=0
flag=0
for i in range(N):
  a=int(input())
  ans+=a//2
  a%=2
  if a==1:
    if flag:
      ans+=1
      a-=1
    else:
      flag=1
  else:
    flag=0
print(ans)

Submission status: Wrong Answer

Solution code:
import math
N=int(input())
ans=0
A=[]
for i in range(N):
  a=int(input())
  
  ans+=a//2
  a%=2
  
  if i!=0:
    if A[i-1]==1 and a==1:
      ans+=1
      a-=1
  A.append(a)
print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

print(sum(A)//2)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A = map(int, read().split())

A = [0] + A
answer = 0
for i in range(1, N+1):
    n, A[i] = divmod(A[i], 2)
    answer += n
    if A[i-1] and A[i]:
        answer += 1
        A[i] = 0
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
prev = 0
for _ in range(n):
    a = int(input())
    ans += (a + prev) // 2
    if prev == 1:
        prev = a % 2
    else:
        prev = (a + 1) % 2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
prev = 0
for _ in range(n):
    a = int(input())
    ans += (a + prev) >> 1
    prev = a & 1
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = map(lambda s: map(int, list(s)), ''.join(
    [input()for _ in range(n)]).split('0'))
ans = sum(map(lambda ls: sum(ls)//2, A))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = [0]*n
for i in range(n):
    a = int(input())
    cnt[i] += a

ans = 0
# 対子
for i in range(n):
    z = cnt[i] // 2
    ans += z
    cnt[i] -= 2*z

# 塔子
for i, j in zip(range(n-1), range(1, n)):
    x, y = cnt[i], cnt[j]
    z = min(x, y)
    ans += z
    cnt[i] -= z
    cnt[j] -= z

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
cnt = [0]*n
for i in range(n):
    a = int(input())
    cnt[i] += a

ans = 0
# 塔子
for i, j in zip(range(n-1), range(1, n)):
    x, y = cnt[i], cnt[j]
    z = min(x, y)
    ans += z
    cnt[i] -= z
    cnt[j] -= z

# 対子
for i in range(n):
    z = cnt[i] // 2
    ans += z
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0))
p=0
for i in range(n-1):
    j=min(a[i],a[i+1])
    a[i]-=j
    a[i+1]-=j
    p+=j
for i in a:
    p+=i//2
print(p)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

N,*A = map(int,open(0).read().split())
A += [0]
ans = 0
for i in range(len(A)):
  if A[i] % 2 == 1 and A[i + 1] % 2 == 1:
    A[i] += 1
    A[i + 1] -= 1
  ans += A[i] // 2
  
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()
A = ILs(N)

for i in range(N-1):
  if A[i]%2 == 1:
    A[i] -= 1
    A[i] += 1
print(sum(a//2 for a in A))

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    cards = [0]
    for _ in range(n):
        cards.append(int(input()))
    cards.append(0)
    answer = 0
    for i in range(1, n + 1):
        if cards[i]:
            if cards[i] <= 2 * min(cards[i - 1] + cards[i + 1], cards[i]):
                answer += min(cards[i - 1] + cards[i + 1], cards[i])
                tmp = cards[i]
                cards[i] -= min(cards[i], cards[i - 1])
                cards[i - 1] -= min(cards[i - 1], tmp)
                if cards[i] > 0:
                    tmp = cards[i + 1]
                    cards[i + 1] -= min(cards[i], cards[i + 1])
                    cards[i] -= min(tmp, cards[i + 1])
            else:
                answer += cards[i] // 2
                cards[i] %= 2
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

dp = [0] * n
dp[0] = a[0] // 2
for i in range(1, n):
    if dp[i] < dp[i-1] + a[i] // 2:
        dp[i] = dp[i-1] + a[i] // 2
    if dp[i] < min(a[i-1], a[i]):
        dp[i] = min(a[i-1], a[i])
        a[i] -= min(a[i-1], a[i])

print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]

dp = [0] * n
dp[0] = a[0] // 2
for i in range(1, n):
    dp[i] = max(dp[i-1] + a[i]//2, min(a[i-1], a[i]))

print(dp[-1])

Submission status: Wrong Answer

Solution code:
n = int(input())
ar = [int(input()) for i in range(n)]
count = 0
for i in range(n-1):
    t = ar[i] + ar[i+1]
    count += t // 2
    ar[i+1] = (t - ar[i]) % 2
print(count)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

n = I()
A = [I() for _ in range(n)]
cnt = 0
for i in range(n):
    cnt += A[i]//2
    A[i] -= (A[i]//2) * 2
#for i in range(n-1):
#    if A[i] >= 1 and A[i+1] >= 1:
#        cnt += 1
#        A[i] -= 1
#        A[i+1] -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

n = I()
A = [I() for _ in range(n)]
cnt = 0
for i in range(n):
    cnt += A[i]//2
    A[i] -= (A[i]//2) * 2
for i in range(n-1):
    if A[i] >= 1 and A[i+1] >= 1:
        cnt += 1
        A[i] -= 1
        A[i+1] -= 1
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] + [int(input()) for i in range(N)] + [0]
B = [i for i in A]
ans = 0
for i in range(1,1+N):
    first = min(A[i-1], A[i])
    second = A[i] // 2
    thrid = min(A[i+1], A[i])
    m = max(first, second, thrid)
    ans += m
    if m == first:
        A[i] -= m
    elif m == second:
        A[i] -= m * 2
    elif m == thrid:
        A[i] -= m
        A[i+1] -= m

ans2 = 0
B.reverse()
A = B
for i in range(1,1+N):
    first = min(A[i-1], A[i])
    second = A[i] // 2
    thrid = min(A[i+1], A[i])
    m = max(first, second, thrid)
    ans2 += m
    if m == first:
        A[i] -= m
    elif m == second:
        A[i] -= m * 2
    elif m == thrid:
        A[i] -= m
        A[i+1] -= m

print(max(ans, ans2))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] + [int(input()) for i in range(N)] + [0]
ans = 0
for i in range(1,1+N):
    first = min(A[i-1], A[i])
    second = A[i] // 2
    thrid = min(A[i+1], A[i])
    m = max(first, second, thrid)
    ans += m
    if m == first:
        A[i] -= m
    elif m == second:
        A[i] -= m * 2
    elif m == thrid:
        A[i] -= m
        A[i+1] -= m
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(input())for i in range(n)]
c=0
for i in a:c+=i//2
print(c)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 0
surplus = 0
for i in range(n):
    a = int(input())
    if a == 0:
        surplus = 0
        continue
    a += surplus

    ans += a // 2
    surplus %= 2

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

ans = 0
surplus = 0
for i in range(n):
    a = int(input())
    if a == 0:
        surplus = 0
        continue
    a += surplus

    ans += a // 2
    surplus %= a

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
for i in range(n):
	if i != n-1:
		if a[i] >= 1 and a[i+1] >= 1:
			k = min(a[i], a[i+1])
			ans += k
			a[i] -= k
			a[i+1] -= k
	if a[i] >= 2:
		ans += a[i] // 2
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

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


# ===CODE===


def main():
    n = ni()
    ans = 0
    cnt = 0
    for _ in range(n):
        ai = ni()
        if ai == 0:
            ans += n // 2
            n = 0
        else:
            n += ai
    ans += n // 2

    print(ans)


if __name__ == '__main__':
    main()