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 = int(input())
a_ls = [int(input()) for i in range(N)]

# dp[i][j] := i番目のAの値までみて、i-1番目をj(0or1)個残した時の最大ペア数
dp = [[0,0] for _ in range(N)]
dp[0][0] = a_ls[0] // 2
dp[0][1] = (a_ls[0]-1)//2
for i in range(1,N):
    if a_ls[i] % 2 == 0:
        # a_ls[i]を1こも余らせない
        dp[i][0] = max(dp[i-1][0] + a_ls[i]//2, dp[i-1][1] + (a_ls[i]-1)//2 + 1)
        # a_ls[i]を1こ余らせる
        dp[i][1] = max(dp[i-1][0] + (a_ls[i]-1)//2, dp[i-1][1] + (a_ls[i]-2)//2 + 1)
    else:
        # a_ls[i]を1こも余らせない
        dp[i][0] = max(dp[i-1][0] + a_ls[i]//2, dp[i-1][1] + (a_ls[i]-1)//2 + 1)
        # a_ls[i]を1こ余らせる
        dp[i][1] = max(dp[i-1][0] + (a_ls[i]-1)//2, dp[i-1][1] + (a_ls[i]-2)//2 + 1)
print(max(dp[-1][0],dp[-1][1]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
l = []
for i in range(N):
  l.append(int(input()))
  
ans = 0
for i in range(N):
  ans += l[i] // 2
  l[i] = l[i] % 2
  if (0<i) and (l[i-1]+l[i]==2):
    ans += 1
    l[i-1], l[i] = 0, 0
print(ans)

Submission status: Wrong Answer

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

c = 0

for i in range(n):
  c += a[i]//2
  a[i] -= (a[i]//2)*2

for i in range(n-1):
  if a[i] + a[i+1] == 2:
    c += 1
    a[i] -= 1
    a[i+1] -= 1
print (c)

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = [int(input()) for i in range(n)]

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

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

print(ans)

Submission status: Wrong Answer

Solution code:

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

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

    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:

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

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


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

ans = 0

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

Submission status: Wrong Answer

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
A = []
ans = 0
for i in range(n):
    a = ni()
    ans+=a//2
    if a%2==0:
        A.append(0)
    else:
        A.append(1)
for i in range(n-1):
    if A[i]==1:
        if A[i+1]==1:
            ans+=1
            A[i+1]=0
print(ans)

Submission status: Wrong Answer

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

s = 0
m = 0
for i in range(n):
    s += A[i] // 2
    if A[i] % 2 == 0:
        m = 0
    else:
        if m == 1:
            s += 1
            m = 0
        else:
            m=1
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=[0]*n
for i in range(n):
  A[i]=int(input())
  
s=0
m=0
for i in range(n):
  s+=A[i]//2
  if A[i]%2==0:
    m=0
  else:
    if m==1:
      s+=1
      m=0
print(s)

Submission status: Wrong Answer

Solution code:
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):
    a = A[i]
    if a > 2:
        ans += (A[i]-1)//2
        A[i] -= ((A[i]-1)//2)*2

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

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):
    ans += A[i] // 2
    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)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = [inp() for _ in range(n)]
res = 0
f = False
for i,x in enumerate(a):
    if x%2:
        if f: res += 1; f = False
        else: f = True
    else:
        f = False
    res += x//2
print(res)

Submission status: Wrong Answer

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = [inp() for _ in range(n)]
res = 0
f = False
for i,x in enumerate(a):
    if x%2:
        if f: res += 1
        else: f = True
    else:
        f = False
    res += x//2
print(res)

Submission status: Wrong Answer

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

ans = 0
for key,val in enumerate(A):
    if key < N-1:
        ans += int(val/2)

    if key < N-1 and int(val/2)*2 != val and A[key+1] != 0:
        A[key+1] -= 1
        ans += 1
print(ans)

Submission status: Wrong Answer

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

res = 0
for i, a in enumerate(A):
    res += a // 2
    A[i] = int(a % 2 == 1)

while i < N - 1:
    if A[i] == 1 and A[i + 1] == 1:
        res += 1
        i += 1
    i += 1

print(res)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
pre = int(input())
ans = 0
for _ in range(N - 1):
    i = int(input())
    if pre <= i:
        ans += pre
        pre = i - pre
    else:
        ans += i + (pre - i) // 2             
        pre = 0

print(ans + pre // 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
pre = int(input())
ans = 0
for _ in range(N - 1):
    i = int(input())
    if pre <= i:
        ans += pre
        pre = i - pre
    else:
        ans += i + (pre - i) // 2             
        pre = 0

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):
    ans += a[i] // 2
    a[i] %= 2

for i in range(n - 1, 0, -1):
    num = min(a[i - 1], a[i])
    ans += num

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for k in range(N)]
ans = 0
r = 0
for e in A:
    t = e+r
    ans += t//2
    r = e%2
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
ans = 0
B = 0
for i in range(N):
    A = int(input())
    C = A+B
    ans += C//2
    B = A % 2
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 - 1, 0, -1):
    num = min(a[i - 1], a[i])
    ans += num
    a[i - 1] -= num
    a[i] -= num
    ans += a[i] // 2
ans += a[0] // 2

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):
    ans+=a[i]//2
    a[i]%=2

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

print(ans)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc003/tasks/agc003_b

import sys
# sys.setrecursionlimit(100000)
from collections import defaultdict


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n = input_int()
    d = defaultdict(int)
    ans = 0
    for i in range(1, n + 1):
        a = input_int()
        ans += a // 2
        if a % 2 == 1 and d[i - 1] == 1:
            ans += 1
            d[i - 1] -= 1
        elif a % 2 == 1:
            d[i] = 1

    print(ans)

    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
for i in range(N):
    ans += A[i] // 2
    A[i] %= 2
    if N == 1 and i < N-1 and A[i+1] > 0:
        A[i+1] -= 1
        ans += 1
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):
    ans += A[i] // 2
    N %= 2
    if N == 1 and i < N-1 and A[i+1] > 0:
        A[i+1] -= 1
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
l=[0]*N
for i in range(N):
   ans+=int(input())//2
for i in range(1,N):
   if l[i]==1 and l[i-1]==1:
      ans+=1
      l[i]=0
print(ans)

Submission status: Wrong Answer

Solution code:

max2 = lambda x,y: x if x > y else y

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

res = 0

for i in range(N-1):
    x = max2(A[i],A[i+1])
    A[i] -= x
    A[i+1] -= x
    res += x

for a in A:
    res += a//2

print(res)

Submission status: Wrong Answer

Solution code:

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

res = 0
b = 0

for a in A:
    res += a//2
    a %= 2
    if a+b == 2:
        res += 1
        b = 0
    else:
        b = a

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(input()) for i in range(n)]
num = 0
s = 0
for h in a:
    if s == 0:
        num += h//2
        s = h%2
    else:
        if h == 0:
            s = 0
        else:
            num += 1 + (h-1)//2
            s = (h-2)%2
print(num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
  A[i] = int(input())
  
ans = 0  
for i in range(N - 1):
  if A[i] >= A[i + 1]:
    now = int((A[i] - A[i + 1]) / 2)
    ans += now
    A[i] -= now * 2
    now2 = min(A[i], A[i + 1])
    ans += now2
    A[i + 1] -= now2
    A[i] -= now2
    
  else:
    now = A[i]
    ans += now
    A[i] -= now
    A[i + 1] -= now
  
ans += int(A[-1] / 2)  
#print(A)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0] * N
for i in range(N):
  A[i] = int(input())
  
ans = 0  
for i in range(N - 1):
  if A[i] >= A[i + 1]:
    now = int((A[i] - A[i + 1]) / 2)
    ans += now
    A[i] -= now * 2
    now2 = min(A[i], A[i + 1])
    ans += now2
    A[i + 1] -= now2
    A[i] -= now2
    
  else:
    now = A[i]
    ans += now
    A[i] -= now
    A[i + 1] -= now
  
#print(A)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
c = 0
b = 0
for _ in range(n):
  a = int(input())
  if a == 0:
    b = 0
    continue
  c += a // 2
  b = a % 2
print(c)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[0]*N
for i in range(N):
    A[i]=int(input())

K=0
for i in range(N-1):
    X=min(A[i],A[i+1])
    A[i]-=X
    A[i+1]-=X
    K+=X

for i in range(N):
    K+=A[i]//2

print(K)

Submission status: Wrong Answer

Solution code:
N=int(input())
K=0
A=[0]*N
for i in range(N):
    a=int(input())
    K+=a//2
    A[i]=a%2

for i in range(N-1):
    g=min(A[i],A[i+1])
    K+=g
    A[i]-=g
    A[i+1]-=g

print(K)

Submission status: Wrong Answer

Solution code:
n = int(input())
ls = [0] * n 
for i in range(n):
    ls[i] = int(input())
ans = 0
for i in range(n-1):
    if ls[i] % 2 == 1 and ls[i+1] > 0:
        ls[i] += 1
        ls[i+1] -= 1
    ans += ls[i] // 2
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-1):
    if a[i]==a[i+1] and a[i]%2==1:
        ans+=a[i]
        a[i+1]=0
    else:
        ans+=int(a[i]/2)
ans+=int(a[n-1]/2)
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-1):
    if a[i]==a[i+1]:
        ans+=a[i]
        a[i+1]=0
    elif a[i]>1:
        ans+=a[i]//2
ans+=a[n-1]//2
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-1):
    if a[i]>1:
        ans+=a[i]//2
    elif a[i]==1 and a[i+1]==1:
        ans+=1
        a[i+1]=0
ans+=a[-1]//2
print(ans)

Submission status: Wrong Answer

Solution code:
n,*a=map(int,open(0).read().split())
ans=0
for i in range(n):
    p,a[i]=divmod(a[i],2)
    ans+=p
i=0
while i+1<n:
    if a[i]==1 and a[i+1]==1:
        ans+=1
        i+=1
    i+=1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
l = [int(input()) for i in range(n)]+[0]
def cal(lis):
    count = 0
    m = -1
    for i in range(n):
        if lis[i]%2 == 0:
            count += l[i]//2
        else:
            if lis[i+1] > 1:
                count += lis[i]//2+1
                lis[i+1] -= 1
            else:
                count += lis[i]//2
    return count

print(max(cal(l),cal(l[::-1])))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
l = [int(input()) for i in range(n)]

def cal(lis):
    count = 0
    m = -1
    p = float("INF")
    for i in range(n):
        if lis[i] %2:
            if m < 0:
                m = 1
                count += lis[i]//2
            else:
                if p > 1:
                    count += lis[i]//2+1
                    p = float("INF")
                    m = -1
                else:
                    count += lis[i]//2
                    p = float("INF")
        else:
            count += lis[i]//2
            p = min(p,lis[i])
    return count

print(max(cal(l),cal(l[::-1])))

Submission status: Wrong Answer

Solution code:
n = int(input())
ans = 0
l = [int(input()) for i in range(n)]

m = -1
p = float("INF")
for i in range(n):
    if l[i] %2:
        if m < 0:
            m = 1
            ans += l[i]//2
        else:
            if p > 1:
                ans += l[i]//2+1
                p = float("INF")
                m = -1
            else:
                ans += l[i]//2
                p = float("INF")
    else:
        ans += l[i]//2
        p = min(p,l[i])
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import math
n = int(input())
#x, y = map(int,input().split())
#A = list(map(int,input().split()))
ans = 0
A = []
for i in range(n):
    a = int(input())
    A.append(a)
for i in range(n-1):
    #print(ans)
    m = A[i]+A[i+1]
    if m%2==0:
        ans += m//2
        A[i+1]=0
    else:
        if A[i+1]%2==1:
            ans += m//2
            A[i+1]=1
        else:
            ans += m//2
            A[i+1]=0
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = [0] * N
res = 0
for i in range(N):
  x = int(input())
  res += x // 2
  a[i] = x % 2
sch = []
for i in range(N - 1):
  if a[i] == a[i + 1] == 1: sch.append((i, i + 2))
sch.sort(key = lambda x: x[1])
x = 0
for i in range(len(sch)):
  if x <= sch[i][0]:
    res += 1
    x = sch[i][1]
print(res)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
tmp = 0
for i in range(N):
    a = int(input())
    if tmp ==0:
        cnt += a//2
        tmp = a%2
    elif tmp ==1 and a>0:
        cnt += (a+tmp)//2
        tmp == (a+tmp)%2
    elif a==0:
        tmp = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
tmp = 0
for i in range(N):
    a = int(input())
    cnt += a//2
    tmp2 = a%2
    if tmp ==1 and tmp2==1:
        cnt +=1
        tmp = 0
    elif tmp == 1 and tmp2 ==0 and a>0:
        tmp = 1
    elif a==0:
        tmp = 0
    

print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
s =''
for i in range(N):
    a = int(input())
    cnt += a//2
    s += str(a%2)

print(cnt+s.count('11'))

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
tmp = 0
for i in range(N):
    a = int(input())
    cnt += a//2
    tmp2 = a%2
    if tmp ==1 and tmp2==1:
        cnt +=1
        tmp = 0
    else:
        tmp = tmp2
print(cnt)

Submission status: Wrong Answer

Solution code:
N = int(input())
cnt = 0
tmp = 0
for i in range(N):
    a = int(input())
    cnt += a//2
    tmp2 = a%2
    if tmp2*tmp:
        cnt +=1
        tmp = 0
    else:
        tmp = tmp2
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy


def solve():
    n = getN()
    am = []
    ans = 0
    for i in range(n):
        num = getN()
        ans += num // 2
        am.append(num % 2)
    prev = 0
    for a in am:
        if prev and a:
            ans += 1
            prev = 0
        else:
            prev = a
    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Submission status: Wrong Answer

Solution code:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=0
lis=[I() for i in range(n)]
for i in range(n):
    ans+=lis[i]//2
    lis[i]=lis[i]%2
for i in range(n-1):
    if lis[i]==lis[i+1]==1:
        ans+=1
        lis[i]=0
        lis[i+1]=0
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
  a = int(input())
  l.append([a,i+1])
l1 = (sorted(l))
ans = 0
#print(l)
#print(l1)
while l1:
  b = l1.pop()
  j,k = b[0],b[1]
  if j%2==0:
    ans += j//2
  else:
    if k-2>=0:
      t,_ = l[k-2]
      if j==t:
        l1.remove([j,k-1])
        ans += j
      else:
        ans += j//2
    elif k+1<=n:
      s,_ = l[k]
      if j==s:
        l1.remove([j,k+1])
        ans += j
      else:
        ans += j//2
   # print(l1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = []
for i in range(n):
  a = int(input())
  l.append([a,i+1])
l1 = sorted(l)[::-1]
ans = 0
#print(l)
#print(l1)
for j,k in l1:
  print(j,k)
  if j%2==0:
    ans += j//2
  else:
    if k-2>=0:
      t,_ = l[k-2]
      if j==t:
        l1.remove([j,k-1])
        ans += j
        l1.remove([j,k])
      else:
        ans += j//2
        l1.remove([j,k])
    elif k+1<=n:
      s,_ = l[k]
      if j==s:
        l1.remove([j,k+1])
        ans += j
        l1.remove([j,k])
      else:
        ans += j//2
        l1.remove([j,k])
   # print(l1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import copy
n=int(input())
a=[int(input()) for _ in range(n)]
b=[0]*n
ans=0
for i in range(n):
  b[i]=a[i]%2
for i in range(n-1):
  if b[i]==b[i+1]:
    ans+=(a[i]+a[i+1])//2
    b[i],b[i+1]=0,0
    a[i],a[i+1]=0,0
for i in range(1,n-1):
  if b[i-1]*b[i+1] and b[i]==0:
    ans+=sum(a[i-1:i+2])//2
    b[i+1]=0
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import copy
n=int(input())
a=[int(input()) for _ in range(n)]
ans=0
for i in range(n):
  ans+=a[i]//2
  a[i]%=2
for i in range(n-1):
  ans+=min(a[i],a[i+1])
  k=max(a[i]-a[i+1],0)
  a[i+1]=max(a[i+1]-a[i],0)
  a[i]=k
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import copy
n=int(input())
a=[int(input()) for _ in range(n)]
b=copy(a)
ans1=0
for i in range(n-1):
  ans1+=min(a[i],a[i+1])
  k=max(a[i]-a[i+1],0)
  a[i+1]=max(a[i+1]-a[i],0)
  a[i]=k
for i in a:
  ans1+=i//2
ans2=0
for i in range(n-1,0,-1):
  ans2+=min(b[i],b[i-1])
  k=max(b[i]-b[i-1],0)
  b[i-1]=max(b[i-1]-b[i],0)
  b[i]=k
for i in b:
  ans2+=i//2
print(max(ans1,ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N = getN()
A = getArray(N)

cnt = 0
for i in range(N - 1):
    # 二つから
    u = min(A[i], A[i + 1])
    cnt += u
    A[i] -= u
    A[i + 1] -= u

    # 一つから
    p = A[i] // 2
    cnt += p
    A[i] -= p * 2

p = A[-1] // 2
cnt += p
A[-1] -= p * 2
print(cnt)

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-1):
    if A[i-1] == 1 and A[i] == 2 and A[i+1] == 1:
        ans += 2
        A[i-1] = 0
        A[i] = 0
        A[i+1] = 0
for i in range(1,N):
    if A[i-1] == 1 and A[i] == 1:
        ans += 1
        A[i-1] = 0
        A[i] = 0
for i in range(N):
    if A[i] == 2:
        ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = [0]*n
for i in range(n):
    a[i] = INT()

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

Submission status: Wrong Answer

Solution code:
def solve(n, a):
    res = 0
    for i in range(n-1):
        if (a[i] == a[i+1]) and (a[i] % 2 == 1):
            res += a[i]
            a[i+1] = 0
        else:
            res += a[i] // 2
        a[i] = 0
    if a[-1] > 0:
        res += a[-1] // 2
    return res

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

Submission status: Wrong Answer

Solution code:
def solve(n, a):
    res = 0
    for i in range(n-1):
        b = min(a[i], a[i+1])
        res += b
        a[i] -= b
        a[i+1] -= b
        if a[i] > 0:
            res += a[i] // 2
    if a[-1] > 0:
        res += a[-1] // 2
    return res

n = int(input())
a = [int(input()) for i in range(n)]
print(solve(n, a))

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
            A[i-1] -= temp
for i in range(N):
    if A[i] == 2:
        ans += 1
print(ans)