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:
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()
    a = []
    ans = 0
    for _ in range(n):
        ai = ni()
        ans += ai // 2
        a.append(ai % 2)

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

    print(ans)


if __name__ == '__main__':
    main()

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()
    a = [ni() for _ in range(n)]

    if n == 1:
        print(a[0] // 2)
        exit(0)

    ans = 0
    continueFlg = False
    for i in range(n - 1):
        if continueFlg:
            continueFlg = False
            continue

        if a[i] // 2 + a[i + 1] // 2 < min(a[i], a[i + 1]):
            ans += min(a[i], a[i + 1])
            continueFlg = True
        else:
            ans += a[i] // 2

    if not continueFlg:
        ans += a[-1] // 2

    print(ans)


if __name__ == '__main__':
    main()

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()
    a = [ni() for _ in range(n)]

    if n == 0:
        print(a[0] // 2)
        exit(0)

    ans = 0
    continueFlg = False
    for i in range(n - 1):
        if continueFlg:
            continueFlg = False
            continue

        if a[i] // 2 + a[i + 1] // 2 < min(a[i], a[i + 1]):
            ans += min(a[i], a[i + 1])
            continueFlg = True
        else:
            ans += a[i] // 2

    if not continueFlg:
        ans += a[-1] // 2

    print(ans)


if __name__ == '__main__':
    main()

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()
    a = [ni() for _ in range(n)]

    ans = 0
    continueFlg = False
    for i in range(n - 1):
        if continueFlg:
            continueFlg = False
            continue

        if a[i] // 2 + a[i + 1] // 2 < min(a[i], a[i + 1]):
            ans += min(a[i], a[i + 1])
        else:
            ans += a[i] // 2 + a[i + 1] // 2
        continueFlg = True

    print(ans)


if __name__ == '__main__':
    main()

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()
    a = [ni() for _ in range(n)]

    ans = 0
    continueFlg = False
    for i in range(n - 1):
        if continueFlg:
            continueFlg = False
            continue

        if a[i] // 2 + a[i + 1] // 2 < min(a[i], a[i + 1]):
            ans += min(a[i], a[i + 1])
            continueFlg = True
        else:
            ans += a[i] // 2

    if not continueFlg:
        ans += a[-1] // 2

    print(ans)


if __name__ == '__main__':
    main()

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()
    a = [ni() for _ in range(n)]

    ans = 0
    continueFlg = False
    for i in range(n - 1):
        if continueFlg:
            continueFlg = False
            continue

        if a[i] // 2 + a[i - 1] // 2 < min(a[i], a[i - 1]):
            ans += min(a[i], a[i - 1])
            continueFlg = True
        else:
            ans += a[i - 1] // 2

    if not continueFlg:
        ans += a[-1] // 2

    print(ans)


if __name__ == '__main__':
    main()

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()
    a = [ni() for _ in range(n)]

    ans = 0
    continueFlg = False
    for i in range(n - 1):
        if continueFlg:
            continueFlg = False
            continue

        if a[i] // 2 + a[i - 1] // 2 < min(a[i], a[i - 1]):
            ans += min(a[i], a[i - 1])
            continueFlg = True
        else:
            ans += a[i] // 2

    if not continueFlg:
        ans += a[-1] // 2

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
As = [int(input()) for i in range(n)]

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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
As = [int(input()) for i in range(n)]

ans = sum([a//2 for a in As])
As = [a%2 for a in As]
# print(ans, As)
for i in range(1,n):
    if As[i-1] == As[i] == 1:
        ans += 1
        As[i-1] -= 1
        As[i] -= 1
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n = int(input())
  la = [int(input()) for _ in range(n)]
  cnt = 0
  for i in range(n):
    if i < n-1:
      n_pair = min(la[i], la[i+1])
      cnt += n_pair
      la[i] -= n_pair
      la[i+1] -= n_pair
    cnt += (la[i]//2)
  print(cnt)
  
if __name__=='__main__':
  main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(input())for i in range(N)]
ans=0
prev=A[0]
ans2=0
for i in range(1,N):
  x=min(A[i-1],A[i])
  ans+=x
  A[i-1]-=x
  A[i]-=x
  ans+=(A[i-1]//2)
ans+=A[N-1]//2
for i in range(N-1):
  x=min(A[N-1-i],A[N-2-i])
  ans2+=x
  A[N-1-i]-=x
  A[N-2-i]-=x
  ans2+=(A[N-i-2]//2)
ans2+=A[0]//2
print(max(ans,ans2))

Submission status: Wrong Answer

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

for i in range(1,N):
  x=min(A[i-1],A[i])
  ans+=x
  A[i-1]-=x
  A[i]-=x
  ans+=(A[i-1]//2)
ans+=A[N-1]//2
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = [0]*n
res = 0
for i in range(n):
    s = int(input())
    a[i] = s
#3つの要素に注目した時最大のペア数
#3つの要素に注目した時真ん中の要素をi
#a[i-1]+a[i+1]<a[i]であれば各a[i-1]とa[i+1]にa[i]を結びsつける
#そうでないならa[i-1]だけで組み、次の3つに着目。
i = 1
while i<n:
    if i<n-1 and a[i]>=a[i-1]+a[i+1]:
        res += a[i-1]+a[i+1]
        a[i]-=(a[i-1]+a[i+1])
        a[i+1]=0
        a[i-1]=0
        if a[i]>1:res+=a[i]//2
        i+=2
    else:
        res += a[i-1]//2
        if a[i-1]%2==1 and a[i]>0:
            a[i]-=1
            res+=1
        i+=1
print(res)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
dd = defaultdict(int)
for i in range(n):
    s = int(input())
    dd[i+1] = s
res = 0
tmp = 0
for key in dd.keys():
    res+=((dd[key]+tmp)//2)
    tmp = dd[key]%2  #余った分
print(res)

Submission status: Wrong Answer

Solution code:
import copy

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = [Z() for _ in range(N)]
    B = copy.deepcopy(A)
    B = B[::-1]
    output = 0
    for i in range(N-1):
        x = min(A[i], A[i+1])
        output += x
        A[i] -= x
        A[i+1] -= x
        output += A[i]//2
        A[i] %= 2
    output += A[N-1]//2

    output1 = 0
    for i in range(N-1):
        x = min(B[i], B[i+1])
        output1 += x
        B[i] -= x
        B[i+1] -= x
        output1 += B[i]//2
        B[i] %= 2
    output1 += B[N-1]//2
    print(max(output, output1))

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = [Z() for _ in range(N)]
    output = 0
    for i in range(N-1):
        x = min(A[i], A[i+1])
        output += x
        A[i] -= x
        A[i+1] -= x
        output += A[i]//2
        A[i] %= 2
    output += A[N-1]//2
    print(output)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = [Z() for _ in range(N)]
    output = 0
    for i in range(N):
        output += A[i]//2
        A[i] %= 2
    for i in range(N-1):
        x = min(A[i], A[i+1])
        output += x
        A[i] -= x
        A[i+1] -= x
    print(output)

    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
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])//2
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
if N == 1:
    print(N//2)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
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])//2
    A[i+1] = min(A[i+1], (A[i] + A[i+1]) % 2)
print(ans)

Submission status: Wrong Answer

Solution code:
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])//2
    A[i-1] = min(A[i-1], (A[i] + A[i-1]) % 2)
print(ans)

Submission status: Wrong Answer

Solution code:
R=[0]
L=list()
N=int(input())
for i in range(N):
  k=int(input())
  L.append(k)
  if k==0:
    R.append(len(L))
S=sum(L)
R.append(N)
for i in range(len(R)-1):
  if sum(L[R[i]-1:R[i+1]])%2==1:
    S=S-1
print(S//2)

Submission status: Wrong Answer

Solution code:
R = list()
L = list()
N = int(input())
R.append(-1)
for i in range(N):
    k = int(input())
    L.append(k)
    if k == 0:
        R.append(len(L))
R.append(N)
S = sum(L)
for i in range(len(R) - 1):
    if sum(L[R[i] + 1 : R[i + 1]]) % 2 == 1:
        S = S - 1
print(S // 2)

Submission status: Wrong Answer

Solution code:
R = list()
L = list()
N = int(input())
R.append(0)
for i in range(N):
    k = int(input())
    L.append(k)
    if k == 0:
        R.append(len(L))
S = sum(L)
R.append(S)
for i in range(len(R) - 1):
    if sum(L[R[i] + 1 : R[i + 1]]) % 2 == 1:
        S = S - 1
print(S // 2)

Submission status: Wrong Answer

Solution code:
R = list()
L = list()
N = int(input())
R.append(0)
for i in range(N):
    k = int(input())
    L.append(k)
    if k == 0:
        R.append(len(L))
R.append(N)
S = sum(L)
for i in range(len(R) - 1):
    if sum(L[R[i] + 1 : R[i + 1]]) % 2 == 1:
        S = S - 1
print(S // 2)

Submission status: Wrong Answer

Solution code:
R=list()
L=list()
N=int(input())
for i in range(N):
  k=int(input())
  L.append(k)
  if k==0:
    R.append(len(L))
S=sum(L)
for i in range(len(R)-1):
  if sum(L[R[i]-1:R[i+1]])%2==1:
    S=S-1
print(S//2)

Submission status: Wrong Answer

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

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

print(dp[-1])

Submission status: Wrong Answer

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

ans = 0
i = 0
while i < N:
  a = A[i]
  if a % 2 == 0:
    ans += a // 2
  else:
    aa = A[i+1]
    if a == aa:
      ans += a
      i += 1
    else:
      ans += a // 2
  i += 1

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
l=[0]*(n+1)
for i in range(n):
    l[i+1]=int(input())
ans=0
for i in range(1,n):
    num=min(l[i],l[i+1])
    l[i]-=num
    l[i+1]-=num
    ans+=num
for i in range(1,n+1):
    ans+=l[i]//2
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans=0
p=0
for _ in range(N):
    a=int(input())
    ans+=(a+p)//2
    p=a%2
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
for _ in range(n):
  a = int(input())
  A.append(a)
if n == 1:
  cnt = A[0]//2
  print(cnt)
else:
  cnt = 0
  for i in range(n-1):
    m = min(A[i], A[i+1])
    cnt += m
    A[i] -= m
    A[i+1] -= m
    cnt += A[i]//2
  cnt += A[n-1]//2
  print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
for _ in range(n):
  a = int(input())
  A.append(a)
if n == 1:
  cnt = A[0]//2
else:
  cnt = 0
  for i in range(n-1):
    m = min(A[i], A[i+1])
    cnt += m
    A[i] -= m
    A[i+1] -= m
    cnt += A[i]//2
  cnt += A[n-1]//2
  print(cnt)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = []
for _ in range(n):
  a = int(input())
  A.append(a)
if n == 1:
  cnt = A[0]//2
else:
  cnt = 0
  for i in range(n-1):
    m = min(A[i], A[i+1])
    cnt += m
    A[i] -= m
    A[i+1] -= m
    cnt += A[i]//2
  print(cnt)

Submission status: Wrong Answer

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

for i in range(1,N):
    #print(i,A[i],B[i-1], (B[i-1]+A[i])//2 )
    pair= (B[i-1]+A[i])//2
    ans += pair
    if (A[i]+B[i-1]) %2==1 and A[i]%2==1:
        B[i] = 1
    else:
        B[i] = 0

#print(ans,B)
print(ans)

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

cnt = 0
tmp = 0
for i in range(N):
    cnt += A[i] // 2
    A[i] %= 2
    
    if A[i] == 1:
        tmp += 1
    else:
        cnt += tmp // 2
        tmp = 0
else:
    cnt += tmp // 2

print(cnt)

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

cnt = 0
tmp = 0
for i in range(N):
    cnt += A[i] // 2
    A[i] %= 2
    
    if A[i] == 1:
        tmp += 1
    else:
        cnt += tmp // 2
        tmp = 0

print(cnt)

Submission status: Wrong Answer

Solution code:
N, *A = map(int, open(0).read().split())

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

tmp = 0
for i in range(N):
    if A[i] == 1:
        tmp += 1
    else:
        cnt += tmp // 2
        tmp = 0
        
print(cnt)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())

A = []
for _ in range(N):
    A.append(int(sys.stdin.readline().rstrip()))

pairs = 0
res = 0
for a_i in A:
    r = (a_i + res) // 2
    pairs += r
    res = a_i - 2*r

print(pairs)

Submission status: Wrong Answer

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())

A = []
for _ in range(N):
    A.append(int(sys.stdin.readline().rstrip()))

pairs = 0
pre_res = 0
for a_i in A:
    r = a_i // 2
    pairs += r
    res = a_i - 2*r
    if res + pre_res == 2:
        pairs += 1
        res = 0
    
    pre_res = res

print(pairs)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(int(input()) for _ in range(n))

    res = 0
    for i in range(1, n):
        cnt = min(A[i - 1], A[i])
        A[i - 1] -= cnt
        A[i] -= cnt
        res += cnt
        if A[i - 1]:
            res += (A[i - 1]) // 2

    if A[n - 1]:
        res += (A[n - 1]) // 2

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(int(input()) for _ in range(n))

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

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[0]*n
x=0
for i in range(n):
  t=int(input())
  if t%2:
    x+=t//2
    l[i]=1
  elif t==0:
    l[i]=0
  else:
    x+=(t-2)//2
    l[i]=2
for i in range(n-1):
  if l[i]==1 and l[i+1]==1:
    x+=1
    l[i]=0
    l[i+1]=0
l=[0]+l+[0]
for i in range(1,n+1):
  if l[i]==2:
    if l[i-1]==0:
      l[i]=0
      x+=1
    elif l[i-1]==1:
      if l[i+1]==1:
        x+=2
        l[i-1]=0
        l[i]=0
        l[i+1]=0
      else:
        x+=1
        l[i-1]=0
        l[i]=1
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

al = [int(input()) for _ in range(n)]

if n == 1:
    print(al[0] // 2 * 2)
    exit()
ans = 0
for i in range(n-1):
    rest = ((al[i] + al[i+1]) // 2) * 2
    ans += rest
    for j in range(2):
        if al[i+j] >= rest:
            al[i+j] -= rest
            break
        else:
            rest -= al[i+j]
            al[i+j] = 0


print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())

al = [int(input()) for _ in range(n)]

ans = 0
for i in range(n-1):
    rest = ((al[i] + al[i+1]) // 2) * 2
    ans += rest
    for j in range(2):
        if al[i+j] >= rest:
            al[i+j] -= rest
            break
        else:
            rest -= al[i+j]
            al[i+j] = 0


print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())

al = [int(input()) for _ in range(n)]

ans = 0
for i in range(n-1):
    rest = ((al[i] + al[i+1]) // 2) * 2
    ans += rest
    for j in range(2):
        if al[i+j] > rest:
            al[i+j] -= rest
            break
        else:
            rest -= al[i+j]
            al[i+j] = 0


print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())

al = [int(input()) for _ in range(n)]

ans = 0
for i in range(n-1):
    rest = (al[i] + al[i+1]) // 2 * 2
    ans += rest
    for j in range(2):
        if al[i+j] > rest:
            al[i+j] -= rest
            break
        else:
            rest -= al[i+j]
            al[i+j] = 0


print(ans//2)

Submission status: Wrong Answer

Solution code:
n = int(input())

al = [int(input()) for _ in range(n)]

ans = 0
for i in range(n-2):
    rest = (al[i] + al[i+1]) // 2 * 2
    ans += rest
    for j in range(2):
        if al[i+j] > rest:
            al[i+j] -= rest
            break
        else:
            rest -= al[i+j]
            al[i+j] = 0


print(ans//2)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))

ans = 0
lst2 = []
for i in lst1:
    i -= 2
    if i >= 0:
        ans += (i+1)//2
    if i == -2:
        lst2.append(0)
    elif even(i):
        lst2.append(2)
    else:
        lst2.append(1)

now = 0
while now < n:
    if now == 0:
        if lst2[now] == 2:
            ans += 1
            lst2[now] = 0
        now += 1
        continue
    if now < n-1:
        if lst2[now-1] == 1 and lst2[now] == 2 and lst2[now+1] == 1:
            ans += 2
            lst2[now+1] = 0
            now += 2
            continue

    if lst2[now-1] == 1 and lst2[now] == 1:
        ans += 1
        lst2[now] = 0
        now += 1
        continue
    
    if lst2[now] == 2:
        ans += 1
        lst2[now] = 0
        now += 1
        continue
    now += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))

ans = 0
lst2 = []
for i in lst1:
    ans += i//2
    lst2.append(i%2)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())

ans = 0
tmp = -10
for i in range(N):
    a = int(input())
    ans += a//2
    if a%2 == 1:
        if tmp == i-1:
            ans += 1
        else:
            tmp = i
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a_list = []
for i in range(n):
  a_list.append(int(input()))
  
count = 0
for i in range(n-1):
  a = min(a_list[i],a_list[i+1])
  count += a
  a_list[i] = a_list[i] - a
  a_list[i+1] = a_list[i+1] -  a
  count += a_list[i]//2
count += a_list[-1]//2 
print(count)

Submission status: Wrong Answer

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

ans = 0
nokori = 0

ans = ai[0] // 2
ai[0] %= 2

for i in range(1,n):
    ans += ai[i] // 2
    if ai[i] % 2 == 1:
        if ai[i-1] == 1:
            ans += 1
        else:
            ai[i] = 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
nokori = 0

for i in range(1,n):
    ans += ai[i] // 2
    if ai[i] % 2 == 1:
        if ai[i-1] == 1:
            ans += 1
        else:
            ai[i] = 1

print(ans)

Submission status: Wrong Answer

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

ans = 0
nokori = 0

for i in range(n):
    if ai[i] % 2 == 1:
        if nokori == 1:
            nokori = 0
            ans += ai[i] // 2 + 1
        else:
            nokori = 1
            ans += ai[i] // 2
    else:
        ans += ai[i] // 2
        nokori = 0

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))


dp = [[0]*(2) for _ in range(n+1)]

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

# print(dp)
print(max(dp[n]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))


dp = [[0]*(2) for _ in range(n)]

# dp[i][amari]

if a[0]%2==1:
    dp[0][1] = a[0]//2
else:
    dp[0][0] = a[0]//2

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

# print(dp)
print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))


dp = [[0]*(2) for _ in range(n)]

# dp[i][amari]

if a[0]%2==1:
    dp[0][1] = a[0]//2
else:
    dp[0][0] = a[0]//2

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

print(max(dp[n-1]))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))

ans = 0

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

i=0
while i < n-1:
    if a[i]%2==1 and a[i+1]%2==1:
        ans+=1
        i+=1
    elif i<n-2:
        if a[i]%2==1 and a[i+1]%2==0 and a[i+2]%2==1 and a[i+1]!=0:
            ans+=1
            i+=2
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))

ans = 0

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

i=0
while i < n-1:
    if a[i] %2==1 and a[i+1]%2==1:
        ans+=1
        i+=1
    elif i<n-2:
        if a[i] %2==1 and a[i+1]%2==0 and a[i+2]%2==1:
            ans+=1
            i+=2
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list(int(input()) for i in range(n))

ans = 0

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

i=0
while i < n-2:
    if a[i] %2==1 and a[i+1]%2==0 and a[i+2]%2==1:
        ans+=1
        i+=2
    i+=1

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())


def f(lst):
  res = 0
  ex = 0
  for a in lst:
    ex += a
    res += ex//2
    ex %= 2
  return res

A = []
ans = 0
for _ in range(n):
  a = int(input())
  if a%2:
    a = 1
  else:
    a = min(a, 2)

  if a!= 0:
    A.append(a)
  elif A:
    ans += max(f(A), f(A[::-1]))
  else:
    continue
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
    
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] == 2:
        ans += 1
        a[i],a[i+1] = 0,0
        
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)

    res = 0
    for i in range(0, N - 1):
        r1 = A[i] // 2
        r2 = A[i + 1] // 2
        r3 = min(A[i], A[i + 1])
        if r1 + r2 >= r3:
            res += r1
            A[i] = A[i] % 2
        else:
            res += r3
            A[i] -= 0
            A[i + 1] -= 0

    res += A[-1] // 2
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


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


def main():
    N = int(input())
    A = []
    for _ in range(N):
        a = int(input())
        A.append(a)

    B = []
    res = 0
    for a in A:
        res += a // 2
        B.append(a % 2)

    for i in range(0, N - 1):
        if B[i] == 1 and B[i + 1] == 1:
            res += 1
            B[i] -= 1
            B[i + 1] -= 1
    print(res)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

print(ans)