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: Accepted

Solution code:
import sys

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


def resolve():
    n = int(input())
    A = [0] + list(int(input()) for _ in range(n)) + [0]

    res = 0
    cnt = 0
    for i in range(n + 2):
        if A[i] == 0:
            res += cnt // 2
            cnt = 0
        else:
            cnt += A[i]

    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
from itertools import*
_, *a = map(int, open(0))
print(sum(sum(l)//2 for _, l in groupby(a, key=lambda x:x>0)))

Submission status: Accepted

Solution code:
n=int(input())
x=0
z=0
for i in range(n):
  t=int(input())
  if t:
    x+=t
  else:
    z+=x//2
    x=0
print(z+x//2)

Submission status: Accepted

Solution code:
n = int(input())

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

if n == 1:
    print(al[0] // 2 * 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: Accepted

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 lst2[now-1] == 1 and lst2[now] == 2:
        ans += 1
        lst2[now] = 1
        now += 1
        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: Accepted

Solution code:
N = int(input())

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

Submission status: Accepted

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):
    if ai[i] > 0:
        ans += ai[i] // 2
        if ai[i] % 2 == 1:
            if ai[i-1] == 1:
                ans += 1
            else:
                ai[i] = 1
        else:
            if ai[i-1] == 1:
                ai[i] = 1

print(ans)

Submission status: Accepted

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
    elif ai[i] > 0:
        if nokori == 1:
            ans += ai[i] // 2
            nokori = 1
        else:
            ans += ai[i] // 2
            nokori = 0
    elif ai[i] == 0:
        nokori = 0

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

b = []
chain = 0
for i in range(n):
    if(chain>=1 and a[i]==0):
        b.append(chain)
        chain = 0
    elif(a[i]>=1):
        chain += a[i]
ans=0
b.append(chain)
for i in b:
    ans += i//2
    #print(i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = []
from collections import Counter
for _ in range(n):
    a.append(int(input()))
a = [0] + a
    
cursum = 0
ans = 0
for i in range(1,n+1):
    if a[i] == 0:
        ans += cursum // 2
        cursum = 0
    else:
        cursum += a[i]
        
ans += cursum // 2
print(ans)

Submission status: Accepted

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:
    ans += a//2
    a = 1
  else:
    if a>2:
      ans += a//2-1
      a = 2

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(int(input()) for _ in range(n))
s=0
r=0
for i in range(n):
    if a[i]==0:
        r=0
    else:
        s+=(a[i]+r)//2
        r=(a[i]+r)%2
print(s)

Submission status: Accepted

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

Submission status: Accepted

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 = []
    C = []
    for a in A:
        if a != 0:
            C.append(a)
        else:
            B.append(C)
            C = []
    if len(C) > 0:
        B.append(C)

    res = 0
    for b in B:
        res += sum(b) // 2
    print(res)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0
t = 0
for i in range(N):
    if A[i] == 0:
        ans += t // 2
        t = 0
    else:
        t += A[i]
ans += t // 2
print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    n = int(input())
    A = [int(input()) for i in range(n)]

    ans = 0
    seq_cnt = 0
    for i in range(n):
        if A[i] != 0:
            seq_cnt += A[i]
        else:
            ans += seq_cnt // 2
            seq_cnt = 0
    ans += seq_cnt // 2

    print(ans)


resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(cnt)

Submission status: Accepted

Solution code:
N, *A = map(int, open(0).read().split())
ls = []
s = 0
ans = 0
for c in A:
  if c==0:
    ans += s//2
    s = 0
  else:
    s += c
ans += s//2
print(ans)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

n = ni()
a = nin(n)

ans = 0
cnt = 0
for i in range(n):
    if a[i] != 0:
        cnt += a[i]
    else:
        ans += cnt // 2
        cnt = 0
ans += cnt // 2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
carry = 0
for a in A:
    if a == 0:
        carry = 0
        continue
    ans += (a + carry) // 2
    carry = (a + carry) % 2
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
    a=int(input())
    A.append(a)
    B.append(a)

ans=0
if N==1:
    print(A[0]//2)
    exit()

for i in range(N):
    if i==(N-1):
        ans+=A[i]//2
        break
    if i==0:
        ans+=A[i]//2
        ans+=min(A[i]%2,A[i+1])
        A[i+1]=max(0,A[i+1]-A[i]%2)
        continue
    ans+=A[i]//2
    ans+=min(A[i]%2,A[i+1])
    A[i+1]=max(0,A[i+1]-A[i]%2)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = []
for i in range(N):
    A.append(int(input()))
    
ans = 0
for i in range(N-1):
    ans += (A[i]//2)
    A[i+1] -= min(A[i+1],A[i]%2)
    ans += min(A[i+1],A[i]%2)
ans += (A[-1]//2)
print(ans)

Submission status: Accepted

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

current_partition_cnt = 0
ans = 0
for a in An:
    if a == 0:
        ans += current_partition_cnt//2
        current_partition_cnt = 0
    else:
        current_partition_cnt += a
ans += current_partition_cnt//2
print(ans)

Submission status: Accepted

Solution code:
def solve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = 0
    for a in A:
        ans += a//2
    prev = 0
    for a in A:
        new = a%2
        if prev == 1:
            if new == 1:
                ans += 1
            elif a>0:
                prev = 1
            else:
                prev = 0
        prev = prev^new
    return ans
print(solve())

Submission status: Accepted

Solution code:
import sys

n, *aaa = map(int, sys.stdin.buffer.read().split())

ans = 0
for i in range(n - 1):
    d, m = divmod(aaa[i], 2)
    ans += d
    if m and aaa[i + 1]:
        aaa[i + 1] -= 1
        ans += 1
ans += aaa[-1] // 2
print(ans)

Submission status: Accepted

Solution code:
# 直感的に分かる貪欲（下から組を作る）だと思うんだけど、これでdiff1185は数字が高すぎじゃない? 
# 貪欲で取っていくのを考えると、非ゼロの区間が連続する場合、その連続に対して下からペアを作って、最後に0か1だけ残ることがわかり、
# 単純に書ける。こんなふうに。

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

ans = 0
temp = 0
for m in nums:
    if m == 0:
        ans += temp // 2
        temp = 0
    else:
        temp += m
ans += temp // 2
print(ans)

Submission status: Accepted

Solution code:

# 直感的に分かる貪欲（下から組を作る）だと思うんだけど、これでdiff1185は数字が高すぎじゃない? 

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

ans = 0
for idx, m in enumerate(nums):
    if m > 0:
        ans += m // 2
        # m -= (m // 2) * 2
        m = m & 1
    if m == 1 and idx != n-1 and nums[idx+1] >= 1:
        ans += 1
        m -= 1
        nums[idx+1] -= 1

print(ans)

Submission status: Accepted

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


def counter(ar):
    count = 0
    for i in range(N):
        # print(i, ar, count)
        if i > 0:
            c = min(ar[i - 1], ar[i])
            ar[i - 1] -= c
            ar[i] -= c
            count += c
        c = ar[i] // 2
        ar[i] -= c * 2
        count += c
        if i < N - 1:
            c = min(ar[i], ar[i + 1])
            ar[i] -= c
            ar[i + 1] -= c
            count += c
    return count

# print(N)
# print(A)

# greedy left -> right, left <- right, take max
AA1 = A[:]
c1 = counter(AA1)
AA2 = A[::-1]
c2 = counter(AA2)
# print(c1)
# print(c2)
print(max(c1, c2))

Submission status: Accepted

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

ans = 0
rest = 0
for i, a in enumerate(A):
    if rest == 0:
        ans += a // 2
        rest = a % 2
    else:
        if (a + rest) % 2 == 0:
            ans += (a + rest) // 2
            rest = 0
        else:
            ans += (rest + a) // 2
            rest = 1 if a != 0 else 0

print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    N = int(stdin.readline())
    ans = c = 0
    for _ in range(N):
        a = int(stdin.readline())
        if a:
            c += a
        else:
            ans += c >> 1
            c = 0
    print(ans + (c >> 1))
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]
ans = 0
for i in range(1, N):
    ans += (A[i - 1] + A[i]) >> 1
    if A[i]:
        A[i] = (A[i - 1] + A[i]) & 1
print(A[0] >> 1 if N == 1 else ans)

Submission status: Accepted

Solution code:
import sys
N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]
ans = 0
for i in range(1, N):
    ans += (A[i - 1] + A[i]) // 2
    if A[i]:
        A[i] = (A[i - 1] + A[i]) % 2
print(A[0] // 2 if N == 1 else ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def isOK(S):
    visited = [[False for _ in range(10)]for _ in range(10)]
    sx, sy = 0, 0
    for y in range(10):
        for x in range(10):
            if S[y][x] == 'o':
                sx = x
                sy = y
                break
    q = []
    q.append((sx, sy))
    while q != []:
        x, y = q.pop()
        visited[y][x] = True
        DIR = [(-1, 0), (1, 0), (0, -1), (0, 1)]
        for d in DIR:
            nx, ny = x + d[0], y + d[1]
            if not 0 <= nx < 10:
                continue
            if not 0 <= ny < 10:
                continue
            if visited[ny][nx]:
                continue
            if S[ny][nx] == 'x':
                continue
            q.append((nx, ny))
    for y in range(10):
        for x in range(10):
            if not visited[y][x] and S[y][x] == 'o':
                return False
    return True


def solve():
    N = Scanner.int()
    ans = 0
    tmp = 0
    for _ in range(N):
        A = Scanner.int()
        if A == 0:
            ans += tmp // 2
            tmp = 0
        else:
            tmp += A
    ans += tmp // 2
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:

n=int(input())
A=[int(input()) for _ in range(n)]
cnt=0
for i in range(n):
    cnt+=A[i]//2
    if A[i]%2==1 and i!=n-1:
        if A[i+1]>0:
            cnt+=1
            A[i+1]-=1

print(cnt)

Submission status: Accepted

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

enu = enumerate
ra = range
N, *A = map(int, open(0).read().split())
ans = 0


# 先に作れるのは作ったのほうが本当によいのか？←だめ
'''
反例
1...1
2...2
3...1のとき、2同士で先にペアを作る前に上と下に配ったほうがいい
'''
# 1から順にgreedyでは？反例は？なさそう
# ただしカードがないときは作れない(stockが強制的に0になる)ので注意

stock = 0  # or 1
for a in A:
    if a == 0:
        stock = 0
        continue
    a += stock
    ans += a // 2
    stock = a & 1  # %2

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from math import floor

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)] + [0]

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


print(sum(main()))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from math import floor

def main():
    n = int(input())
    A = [int(input()) for _ in range(n)]

    x = 0
    for a in A:
        if a == 0:
            yield x // 2
            x = 0
        x += a

    yield x // 2


print(sum(main()))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array([int(input()) for _ in range(N)])
ans = 0
for i in range(N-1):
    d,m = divmod(A[i],2)
    ans += d
    if m == 1:
        if A[i+1] > 0:
            A[i+1] -= 1
            ans += 1

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

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()

    if ans in [True, False]:
        YesNo(ans)
    elif ans is not None:
        print(ans)


def solve():
    N = iip(False)
    A = iipt(N)

    cur = 0
    ans = 0
    for i in A:
        if cur == 1 and i>=1:
            ans += 1
            i -= 1

        ans += i//2
        cur = i%2


    print(ans)




#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):  # 数字のinputをlistで受け取る
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(A):  # 最大公約数
    l = len(A)
    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n = II()
    a = IR(n)
    ans = 0
    for i in range(n - 1):
        if a[i] & 1 and a[i + 1]:
            ans += 1
            a[i + 1] -= 1
        ans += a[i] >> 1
    ans += a[-1] >> 1
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = []
former = 0
count = 0
for i in range(N):
    a = int(input())
    if former == 0:
        former = a%2
        count += a//2
    else:
        if a%2==0:
            if a!=0:
                former = 1
                count += a//2
            else:
                former = 0
        else:
            former = 0
            count += a//2+1 
    
    
print(count)

Submission status: Accepted

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

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

for i in A:
    ans += i // 2

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
former=0
ans=0
for i in range(0,N):
    a=int(input())
    if former==0:
        former=a%2
        ans+=a//2
    else:
        if a%2==0:
            if a!=0:
                former=1
                ans+=a//2
            else:
                former=0
        else:
            former=0
            ans+=a//2+1

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys

def solve(N: int, A: "List[int]"):
    A.append(0)
    answer = 0
    for i in range(N):
        answer += A[i]//2
        A[i] %= 2
        if A[i] > 0 and A[i+1] > 0:
            A[i+1] -= 1
            answer += 1

    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#coding:utf-8
import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    
    ans = 0
    isPreEven = False

    for _ in range(N):
        a = II()
        if isPreEven and a > 0:
            ans += 1
            a -= 1
        ans += a // 2
        if a % 2 == 1:
            isPreEven = True
        else:
            isPreEven = False
        

    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a1 = int(input())
flag = a1%2
ans = a1//2
for i in range(n-1):
    a = int(input())
    if flag:
        ans+=1 if 0<a else 0
        ans+=(a-1)//2 if a!=0 else 0
        flag=1 if a!=0 and (a-1)%2==1 else 0
    else:
        ans +=a//2
        flag=a%2
print(ans)

Submission status: Accepted

Solution code:
import sys
INF = 10 ** 10
MOD = 10 ** 9 + 7
from functools import lru_cache
sys.setrecursionlimit(100000000)

def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    for i in range(n):
        ans += a[i]//2
        if i != n - 1:
            if a[i]%2 == 1 and a[i + 1] > 0:
                ans += 1
                a[i + 1] -= 1
    
    print(ans)
if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N = int(input())
    A = [int(input()) for _ in range(N)] + [0]

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

    print(ans)



    
    


if __name__ == "__main__":
    main()