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

Solution (Python):

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


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



if __name__ == '__main__':
    solve()

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):

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))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):

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()

Solution (Python):
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)

Solution (Python):
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()

Solution (Python):
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()

Solution (Python):


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

Solution (Python):
n = int(input())
A = [int(input()) for i in range(n)]

ans = 0
for i in range(n):
    m = A[i] // 2
    ans += m
    A[i] -= 2*m
    if i <= n-2 and min(A[i], A[i+1]) == 1:
        ans += 1
        A[i] -= 1
        A[i+1] -= 1
print(ans)

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

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

print(ans)

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

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

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

Solution (Python):
def examA():
    S = SI()
    if "W" in S and not "E" in S:
        print("No")
    elif "E" in S and not "W" in S:
        print("No")
    elif "N" in S and not "S" in S:
        print("No")
    elif "S" in S and not "N" in S:
        print("No")
    else:
        print("Yes")
    return

def examB():
    N = I()
    A = [I()for _ in range(N)]
    ans = 0
    for i in range(N-1):
        ans += A[i]//2
        if A[i]%2 and A[i+1]>=1:
            ans += 1
            A[i+1] -= 1
    ans += A[N-1]//2
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    S = [I()for _ in range(N)]

    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examB()

"""

"""

Solution (Python):

from collections import Counter, deque







import sys



ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
now, bef = 0, 0
ans = 0
for i in range(n):
  now = int(input())
  if now == 0 and bef == 1:
    bef = 0
  if (now+bef)%2 == 0:
    if bef == 0:
      ans += now//2
      bef = 0
    else:
      ans += (now+bef)//2
      bef = 0
  else:
    if bef == 0:
      ans += now//2
      bef = 1
    else:
      ans += (now+bef)//2
      bef = 1

print(ans)

Solution (Python):
N = int(input())

result = 0
remainder = 0
for _ in range(N):
    A = int(input())
    result += (A + remainder) // 2
    if A == 0:
        remainder = 0
    else:
        remainder = (A + remainder) % 2
print(result)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,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()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
A = [inp() for i in range(n)]
rem = 0
res = 0
for i,a in enumerate(A):
    res += (a+rem)//2
    if a != 0:
        rem = (a+rem)%2
    else:
        rem = 0
print(res)

Solution (Python):
def main():
    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
        ans += min(a[i], a[i+1])
        a[i+1] -= min(a[i], a[i+1])
    ans += a[n-1] // 2
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = [0]
for i in range(1,n+1):
    a.append(inn())
ddprint(a)
sm = 0
while len(a)>0:
    sm += a[-1]//2
    if len(a)>1 and a[-1]%2==1 and a[-2]>0:
        sm += 1
        a[-2] -= 1
    a.pop()
print(sm)

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
A=A+[0]
ans=0
d=0
for i in A:
  if i!=0:
    d+=i
  else:
    ans+=d//2
    d=0
print(ans)

Solution (Python):
n = int(input())
hold = 0
res = 0
for i in range(n):
    a = int(input())
    if i==0:
        res += a//2
        hold = a%2
    else:
        if a < hold:
            res += a
            hold = 0
        else:
            res += hold
            a -= hold
            res += a//2
            hold = a%2
print(res)

Solution (Python):
n=int(input())
ans=int(0)
s=int(0)
for i in range(n):
    now=int(input())
    if now==0:
        ans+=int(s/2)
        s=int(0)
    else:
        s+=now
ans+=int(s/2)
print(ans)

Solution (Python):

n = int(input())
cnt = 0
merge = 0
for _ in range(n):
    v = int(input())
    if v==0:
        merge = 0
    else:
        q,r = divmod(v,2)
        cnt += q
        cnt += (merge * r)
        merge = (1-merge)*r + (1-r)*merge
print(cnt)

Solution (Python):


N = int(input())
A = list(int(input()) for _ in range(N))

s = 0
s2 = 0

for a in A:
    if a != 0:
        s2 += a
    else:
        s += s2//2
        s2 = 0

s += s2//2

print(s)

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

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

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

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

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

print(ans)

Solution (Python):
N,*A=map(int, open(0).read().split())
acc=A[0]&1
ans=A[0]//2
for a in A[1:]:
    b=min(acc,a)
    ans+=b
    a-=b
    ans+=a//2
    acc=a&1
ans+=acc//2
print(ans)

Solution (Python):
N = int(input())
r = 0
b = 0
for _ in range(N):
    a = int(input())
    a += b

    r += a//2
    if a == 1 and b == 1:
        b = 0
    elif a%2:
        b = 1
    else:
        b = 0
print(r)

Solution (Python):
import sys
stdin = sys.stdin
import itertools

mod = 10**9 + 7

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

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

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LIN(N)
    ans = 0
    for i in range(N-1):
        ans += A[i]//2
        A[i]&=1
        use = min(A[i],A[i+1])
        ans += use 
        A[i+1]-= use 
        A[i]-= use 
    ans += A[-1] // 2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    ans = 0
    for i in range(N):
        ans += A[i]//2
        A[i] %= 2
        if i < N - 1 and A[i] > 0 and A[i+1] > 0:
            ans += 1
            A[i] -= 1
            A[i+1] -= 1
    print(ans)


if __name__ == '__main__':
    main()

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

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

print(ans)

Solution (Python):
N=int(input())
A=[0]
for i in range(1,N+1):
    A.append(int(input()))

ans=0
i=1
while i<=N:
    
    
    if A[i]>=2:
        ans+=A[i]//2
        A[i]%=2
    
    if i<N and A[i]==1 and A[i+1]>=1:
        ans+=1
        A[i]-=1
        A[i+1]-=1
    
    
    i+=1

print(ans)

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
for i in range(N-1):
  dup1 = A[i] // 2
  A[i] -= dup1 * 2
  dup2 = min(A[i], A[i+1])
  A[i+1] -= dup2
  ans += dup1 + dup2
dup1 = A[-1] // 2
ans += dup1
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    ans = 0
    for i in range(1, N):
        if A[i-1] > 1:
            ans += A[i-1] // 2
            A[i-1] %= 2
        if A[i-1] & 1 and A[i] > 1:
            ans += 1
            A[i-1] -= 1
            A[i] -= 1
    ans += A[-1] // 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n, *a = map(int, open(0).read().split())

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

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
temp = 0
for i in range(n):
    ans += (A[i]+temp)//2
    if A[i] != 0:
        temp = (A[i]+temp)%2
    else:
        temp = 0
print(ans)

Solution (Python):
n=int(input())
a=[int(input())  for i in range(n)]
ans=0
for i in range(n)[::-1]:
    if i<n-1:
        x=min(a[i+1],a[i])
        ans+=x
        a[i]-=x
    ans+=a[i]//2
    a[i]-=2*(a[i]//2)
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

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

ans = 0
for i in range(N):
    
    Lpair = A[i] // 2
    ans += Lpair
    A[i] -= 2 * Lpair

    if A[i] > 0 and A[i + 1] > 0:
        ans += 1
        A[i] -= 1
        A[i + 1] -= 1


print(ans)

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

c = ans = 0
for a in A:
    if a==0:
        ans += c//2
        c = 0
    else:
        c += a
ans += c//2
print(ans)

Solution (Python):
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] <= A[i+1]:
        ans += A[i]
        A[i+1] -= A[i]
ans += A[N-1]//2

print(ans)

Solution (Python):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))


ans, a[0] = divmod(a[0], 2)
for i in range(1,n):
    pair = 0
    if a[i-1] > 0:
        pair = min(a[i-1], a[i])
        a[i-1] -= pair
        a[i] -= pair
    ans += pair
    pair, a[i] = divmod(a[i], 2)
    ans += pair
print(ans)

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]
count = 0
point = 0
for i in li:
    if i == 0:
        point += count//2
        count = 0
    else:
        count += i
point += count//2
print(point)

Solution (Python):
from sys import stdin
from itertools import groupby
n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]
count = 0
point = 0
for i in li:
    if i == 0:
        point += count//2
        count = 0
    else:
        count += i
point += count//2
print(point)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





n=ii()
arr=lin(n)+[0]
cnt=0
for i in range(n):
    if arr[i]//2 >=1:
        cnt+=arr[i]//2
        if arr[i]%2==1 and arr[i+1]>0:
            cnt+=1
            arr[i+1]-=1
print(cnt)

Solution (Python):
N = int(input())
ans = 0
now = 0
for i in range(N):
    a = int(input())
    if a != 0:
        now += a
    else:
        ans += now // 2
        now = 0
ans += now // 2
print(ans)

Solution (Python):


sum=0
N=int(input())
A=int(input())
sum+=A//2
a=A%2
for _ in range(1,N):
    A=int(input())
    if a==1 and A>0:
        sum+=a
        A-=a
        a=0
    sum+=A//2
    a=A%2
print(sum)

Solution (Python):
n = int(input())
S = []
for _ in range(n):
    S.append(int(input()))
ans=0
for i in range(len(S)):
    ans+= S[i] // 2

    if i==len(S)-1:
        break
    if S[i]%2 == 1 and S[i+1] >= 1:
        ans+=1
        S[i+1] -= 1
print(ans)

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

ans = 0
rest = 0
for a in A:
    ans += (a + rest) // 2
    rest = 1 if (a + rest) % 2 == 1 and a > 0 else 0

print(ans)

Solution (Python):



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

"""
i番目を見ている時に、i+1番目と組にするか考える。
i+1はi+2と組にできるので、残せるなら残す。

"""

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

    else:
        ans += A[i] // 2


print(ans)

Solution (Python):
n = int(input())
ans = 0
sums = 0
for i in range(n):
    a = int(input())
    sums += a
    if a == 0:
        ans += sums // 2
        sums = 0
ans += sums // 2
print(ans)

Solution (Python):
n = int(input())
a = []
cnt = 0
for i in range(n):
  a.append(int(input()))
stack = -1
for i in range(n):
  if i+1 - stack <= 1 and a[i] > 0:
    cnt += 1
    a[i] -= 1
    stack = -1
  cnt += a[i] // 2
  if a[i] % 2 == 1:
    stack = i+1
  else:
    stack = -1
print(cnt)

Solution (Python):
N = int(input())

ans = 0
List = []
for i in range(N):
    A = int(input())
    List.append(A)
    
def func(a, b):
    ret = 0
    for i in range(a, b + 1):
        ret += List[i] // 2
        if List[i] % 2 and i != b:
            List[i + 1] -= 1
            ret += 1
    return ret

left = 0
for right in range(N):
    if List[right] == 0:
        ans += func(left, right - 1)
        left = right + 1
    
ans += func(left, N - 1)

print(ans)

Solution (Python):
N = int(input())
a = [int(input()) for _ in range(N)] + [0]
ans = 0

for i in range(N):
    if a[i] != 0:
        add, mod = divmod(a[i], 2)
        ans += add
        if a[i + 1] != 0:
            a[i + 1] += mod

print(ans)

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

con = False
ans = 0

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


print(ans)

Solution (Python):
N = int(input())
ans = 0
prev_A = -10
prev_card_num = 0
for i in range(1,N+1):
    A = int(input())
    ans += (prev_card_num + A)//2
    if prev_card_num == 1 and A == 0:
        prev_card_num = 0
    elif (prev_card_num+A)%2 == 1:
        prev_card_num = 1
        prev_A = i
    else:
        prev_card_num = 0
        prev_A = i
print(ans)

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

ans = 0
c = a[0]
for i in range(n - 1):
    b = c
    c = a[i + 1]
    use = b // 2 * 2
    ans += use // 2
    b -= use
    if b and c >= 1:
        ans += 1
        c -= 1
ans += c // 2

print(ans)

Solution (Python):
n=int(input())
a=[int(input()) for i in range(n)]
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]-=1
ans+=a[-1]//2
print(ans)

Solution (Python):
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
from collections import defaultdict
import itertools
sys.setrecursionlimit(200000)
input = sys.stdin.readline









N, = map(int, input().split())
L = [int(input()) for _ in range(N)]

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

    if i < N - 1:
        if L[i] == 1 and L[i + 1] >= 1:
            L[i] = 0
            L[i + 1] -= 1
            ans += 1

print(ans)

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

Solution (Python):
import sys
bbn=1000000007
	


		
def main():
	n = int(input())
	l=[0]*(n+1)
	for i in range(n):
		a=int(input())
		l[i]=a

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

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
N=int(input())
ans=0
s=0
for i in range(1,N+1):
    Ai=int(input())
    if Ai==0:
        ans+=s//2
        s=0
    else:
        s+=Ai
ans+=s//2
print(ans)

Solution (Python):
N=int(input())
pre=int(input())
ans=pre//2
pre=pre&1
for i in range(2,N+1):
    Ai=int(input())
    if pre and Ai>=1:
        ans+=1
        Ai-=1
    ans+=Ai//2
    pre=Ai&1
print(ans)

Solution (Python):
N = int(input())
A = []
a = []
for i in range(N):
    x = int(input())
    if x==0:
        b = a[:]
        A.append(b)
        a = []
    else:
        a.append(x)
A.append(a)
cnt = 0
for a in A:
    c = sum(a)
    cnt += c//2
print(cnt)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
count = A[0]//2
A[0] %= 2
for i in range(1,N):
    if A[i] == 0:
        continue
    if A[i-1] != 0:
        count += 1
        A[i] -= 1
    count += A[i]//2
    A[i] %= 2
print(count)

Solution (Python):
from _collections import deque


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
import scipy
from collections import deque
from math import sqrt
from math import floor


"""
need to consider the case that ticket is not enough to lower everything
"""
N = gi()
A = [0] * N

for i in range(N):
    A[i] = gi()

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

print(ans)

Solution (Python):
n = int(input())
c = 0
ans = 0
for _ in range(n):
  t = int(input())
  if t == 0:
    ans += c//2
    c = 0
  c += t
ans += c//2
print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

rest = 0
answer = 0
for x in A:
    if not x:
        rest = 0
        continue
    if rest:
        x -= 1
        answer += 1
    q,rest = divmod(x,2)
    answer += q

print(answer)

Solution (Python):
N = int(input())
res = 0
l = [0 for i in range(N)]
for i in range(N):
    l[i] = int(input())
    if i > 0 and l[i] >= 1 and l[i - 1] % 2 == 1:
        res += 1
        l[i] -= 1
    res += l[i] // 2
print(res)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
a = [int(input()) for i in range(n)]
a.append(0)
ans = 0
tmp = 0
for i in range(n+1):
  if a[i]!=0:
    tmp += a[i]
  else:
    ans += tmp//2
    tmp = 0
print(ans)

Solution (Python):
n=int(input())
a = [int(input()) for i in range(n)]
a.append(0)
ans = 0
tmp = 0
for i in range(n+1):
  if a[i]!=0:
    tmp += a[i]
  else:
    ans += tmp//2
    tmp = 0
print(ans)

Solution (Python):
N = int(input())
A = [int(input()) for i in range(N)]
P, S = 0, 0
for i in range(N):
  if A[i] != 0:
    S += A[i]
  else:
    P += S // 2
    S = 0
P += S // 2
print(P)

Solution (Python):
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 and A[i+1] > 0:
        ans += 1
        A[i+1] -= 1

print(ans)

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

ans = 0
cnt = 0
for x in a:
  if x != 0:
    cnt += x
  else:
    ans += cnt // 2
    cnt = 0

ans += cnt // 2

print(ans)

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])


def main():
    n=inp()
    a=inplm(n)
    ans = 0
    x = 0
    for i in range(n):
        if a[i] != 0:
            x += a[i]
        else:
            ans += x//2
            x = 0
    ans += x//2
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    mt = 0
    t = 0
    for i in range(n):
        a = int(readline())
        if a == 0:
            mt += t // 2
            t = 0
        else:
            t += a
    print(mt + t // 2)


if __name__ == '__main__':
    solve()

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

mod = 0
ans = 0
for a in A:
    if mod == 1 and a > 0:
        a += 1
        mod = 0
    ans += a // 2
    mod = a % 2

print(ans)

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

prev_mod = 0
ans = 0
for a in A:
    if prev_mod == 1 and a > 0:
        a += 1
        prev_mod = 0
    ans += a // 2
    mod = a % 2
    if mod+prev_mod == 2:
        ans += 1
        mod = 0
    prev_mod = mod

print(ans)

Solution (Python):
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  

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

print(answer)