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

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

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

Solution (Python):
def solve(n, a):
    res, total = 0, 0
    for x in a:
        if x == 0:
            res += total // 2
            total = 0
        else:
            total += x
    return res + total // 2

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

Solution (Python):
from collections import Counter
n = int(input())
count=0
res = 0
for _ in range(n):
  a = int(input())
  if res < a:
    tmp = (a-res)%2
    count += res+(a-tmp-res)//2
    res = tmp
  else:
    count += a
    res = 0
    
print(count)

Solution (Python):
import sys

input = sys.stdin.readline


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

    if N == 1:
        ans = A[0] // 2
    else:
        ans = 0
        for i in range(N - 1):
            if A[i + 1] == 0:
                ans += A[i] // 2
            else:
                q, r = divmod(A[i] + A[i + 1], 2)
                ans += q
                A[i + 1] = r

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
n = int(sys.stdin.readline())
ans = 0
t = 0
for i in range(n):
    a = int(sys.stdin.readline())
    if a==0:
        ans += t//2
        t = 0
    else:
        t += a
if t>0: ans += t//2
print(ans)

Solution (Python):
def solve():
  ans = 0
  N = int(input())
  A = [int(input()) for _ in range(N)]
  rem = 0
  for i in range(N):
    ans += (A[i]+rem)//2
    if A[i]>0:
      rem = (A[i]+rem)%2
    else:
      rem = 0
  return ans
print(solve())

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

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

print(ans)

Solution (Python):
n = int(input())
temp = 0
ans = 0
for i in range(n):
    a = int(input())
    if a != 0:
        q, r = divmod(a+temp, 2)
        ans += q
        temp = r
    else:
        temp = 0
print(ans)

Solution (Python):
def main():
  n = int(input())
  bef = 0
  ans = 0
  for i in range(n):
    now = int(input())
    ans += min(bef, now)
    now -= min(bef, now)
    ans += now//2
    bef = now % 2
  print(ans)
  
if __name__ == "__main__":
  main()

Solution (Python):
import sys

input = sys.stdin.readline


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

    if N == 1:
        ans = A[0] // 2
    else:
        ans = 0
        for i in range(N - 1):
            if A[i + 1] == 0:
                ans += A[i] // 2
            else:
                s = A[i] + A[i + 1]
                q, r = divmod(s, 2)
                ans += q
                A[i + 1] = r

    print(ans)


if __name__ == "__main__":
    main()

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

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

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

print(ans)

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

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

print(ans)

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi



import string

from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    
    
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    ans = 0
    
    x = 0
    for e in a:
        if e:
            x += e
        else:
            ans += x // 2
            x = 0
    ans += x // 2
    print(ans)




t = 1

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


"""

"""

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

Solution (Python):
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = A[0] // 2
    s = A[0] % 2
    for a in A[1:]:
        diff_p = min(s, a)
        self_p = (a - diff_p) // 2
        ans += diff_p + self_p
        s = a - diff_p - 2 * self_p
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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 TUPLE(): return tuple(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 

from decimal import *



N = INT()
A = [INT() for _ in range(N)]

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

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

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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 TUPLE(): return tuple(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 

from decimal import *



N = INT()
A = [INT() 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):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
for i in range(n-1):
    p,r = divmod(A[i], 2)
    A[i] = r
    ans += p
    if A[i]*A[i+1]:
        A[i+1] -= 1
        ans += 1
print(ans+A[-1]//2)

Solution (Python):


import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

cnt = 0
acc = 0
for a in A:
    if a != 0:
        acc += a
    else:
        cnt += acc // 2
        acc = 0
cnt += acc // 2

print(cnt)

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

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

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
a.append(0)
ans = 0
for i in range(n):
    p,r = divmod(a[i],2)
    ans += p
    if a[i+1]: a[i+1] += r
print(ans)

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

Solution (Python):
import sys

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

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


def main():

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

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

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

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

    print(ans)


if __name__ == '__main__':
    main()

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

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

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
tmp = 0
for a in A:
    if tmp > a:
        ans += a
        tmp = 0
        continue
    else:
        ans += tmp
        a -= tmp
        ans += a // 2
        tmp = a - (a // 2) * 2
print(ans)

Solution (Python):
N, *A = map(int, open(0).read().split())
ans = 0
for i in range(N):
    q, r = divmod(A[i], 2)
    ans += q
    if r == 0 or i == N - 1:
        continue
    elif A[i + 1] != 0:
        A[i + 1] += 1
print(ans)

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


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

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

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

A = [0]*(n+1)

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

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

Solution (Python):
import sys
def input():return sys.stdin.readline().strip()

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

    for i in range(N-1):
        if A[i] >= 2:
            ans += A[i]//2
        if A[i]%2 == 1 and A[i+1] >= 1:
            ans += 1
            A[i+1] -= 1
    
    ans += A[N-1]//2
    print(ans)
if __name__ == "__main__":
    main()

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

print(ans)

Solution (Python):
N = int(input())
 
tmp = int(input())
rlt = tmp//2
tmp -= 2*(tmp//2)

for i in range(1,N):
  a = int(input())
  if a == 0:
    tmp = 0
  elif tmp == 1:
    rlt += 1
    a -= 1
  tmp = a
  rlt += tmp//2
  tmp -= 2*(tmp//2)
  
print(rlt)

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, *A = map(int, open(0))
    ans = 0
    i = 0
    prev = 0
    while i < N:
        if A[i] == 0:
            prev = 0
        else:
            ans += (A[i]+prev)//2
            prev = (A[i]+prev)%2
        
        i += 1
    print(ans)

if __name__ == "__main__":
    main()

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

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

Solution (Python):
def main():
    N = int(input())
    A = list(int(input()) for _ in range(N))
    cnt = 0
    for i in range(N):
        if i == N-1:
            cnt += A[i] // 2
            break
        cnt += A[i] // 2
        mod = A[i] % 2
        if A[i+1] >= mod:
            cnt += mod
            A[i+1] -= mod

    print(cnt)



if __name__ == "__main__":
    main()

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



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

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

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

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

    res = 0
    odd = 0

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

    print(res)
    

main()

Solution (Python):
n = int(input())
cur = 0
res = 0
for _ in range(n):
    x = int(input())
    if x == 0:
        res += cur // 2
        cur = 0
    else:
        cur += x
res += cur // 2
print(res)

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

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

print(ans)

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

Solution (Python):



def main():
    N = int(input())
    ret = 0
    pv = 0
    for _ in range(N):
        nw = int(input())
        pa = min(pv, nw)
        ret += pa
        pv = nw - pa
        ret += pv//2
        pv = pv%2
    print(ret)

if __name__ == '__main__':
    main()

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

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

Solution (Python):
def main():
    n = int(input())
    A = []
    tmp = []
    ans = 0
    for _ in range(n):
        a = int(input())
        if a != 0:
            tmp.append(a)
        else:
            A.append(tmp)
            tmp = []
    if tmp != []:
        A.append(tmp)
    for a in A:
        ans += sum(a) // 2
    print(ans)

if __name__ == '__main__':
    main()

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

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

print(ans)

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

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

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

print(ans+cnt//2)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
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

    def makeRun(i, s):
        
        if A[i] <= 0 or A[i+1] <= 0: return s
        A[i] -= 1
        A[i+1] -= 1
        s += 1
        return s

    def makeTriple(i, s):
        
        if A[i] < 0: return s
        s += A[i]//2
        A[i] %= 2
        return s

    for i in range(N-1):
        if A[i]%2: output = makeRun(i, output)
        output = makeTriple(i, output)
    output = makeTriple(N-1, output)
    print(output)

    return

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [0]*n

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

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

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


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

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

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

Solution (Python):
n,*a=map(int,open(0).read().split())
ans=0
if n==1:
  print(a[0]//2)
  exit()
for i in range(n-1):
  if (a[i]+a[i+1])%2==0:
    ans+=(a[i]+a[i+1])//2
    a[i+1]=0
  else:
    ans+=(a[i]+a[i+1])//2
    a[i+1]=(0 if a[i+1]==0 else 1)
print(ans)

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

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

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

print(ans)

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

ans = x = 0
for _ in range(n):
    a = int(input())
    if a == 0:
        ans += x//2
        x = 0
    x += a
else:
    ans += x//2

print(ans)

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

ans = 0
for i, j in zip(range(n-1), range(1, n)):
    x, y = cnt[i], cnt[j]
    z = x//2
    cnt[i] -= 2*z
    ans += z
    if cnt[i] == 0:
        continue
    if 0 < y:
        ans += 1
        cnt[i] -= 1
        cnt[j] -= 1
else:
    ans += cnt[-1]//2

print(ans)

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

N = int(readline())
A = [int(readline()) for i in range(N)]

ans = 0
for i in range(N):
  pair, mod = divmod(A[i],2)
  ans += pair
  if mod:
    if i + 1 < N and A[i + 1] > 0:
      ans += 1
      A[i + 1] -= 1
  
print(ans)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






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






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


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


def DD(arg): return defaultdict(arg)



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


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

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

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


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


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


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


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


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


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


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

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


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




N = I()
A = ILs(N)

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

Solution (Python):
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
if 0 not in A:
  ans = sum(A)//2
else:
  now = 0
  for i in range(N):
    if A[i] == 0 or i == N-1:
      ans += sum(A[now:i+1])//2
      now = i+1
print(ans)

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

A = []

for i in range (0,N):
	A.append(int(input()))

temp = 0
total = 0

import math

for i in range (0, N):
	if A[i] != 0:
		temp+=A[i]
	else:
		total+=math.floor(temp/2)
		temp=0
        
total+=math.floor(temp/2)     

print(total)

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

Solution (Python):
def main():
    n = int(input())
    cards = []
    for _ in range(n):
        cards.append(int(input()))
    cards.append(0)
    answer = 0
    tmp = 0
    for i in range(n + 1):
        if cards[i]:
            tmp += cards[i]
        else:
            answer += tmp // 2
            tmp = 0
    print(answer)


if __name__ == '__main__':
    main()

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

ans = 0
i = 0
while i < n:
    res = 0
    for j in range(i, n):
        if a[j] == 0: break
        res += a[j]
    ans += res // 2
    i = j + 1

print(ans)

Solution (Python):
import math

import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    ans = 0
    pi = 0
    for _ in range(n):
        a = int(ipt())
        if a == 0:
            pi = 0
        else:
            ans += (pi+a)//2
            pi = (pi+a)%2
    print(ans)

    return

if __name__ == '__main__':
    main()

Solution (Python):



from fractions import gcd


from collections import deque,defaultdict











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

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

n = I()
A = [I() for _ in range(n)]
ans = 0








i = 0
SUM = 0
while i < n:
    if A[i] == 0:
        ans += SUM//2
        SUM = 0
    else:
        SUM += A[i]
    i += 1
ans += SUM//2
print(ans)

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

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

ans = 0
tmp = 0
for a in A:
    if a == 0:
        tmp = 0
    a += tmp
    ans += a // 2
    tmp = a % 2

print(ans)

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
ans=0
for i in range(N):
    ans+=A[i]//2
    A[i]-=(A[i]//2*2)
    if i>0:
        d=min(A[i],A[i-1])
        ans+=d
        A[i]-=d
        A[i-1]-=d
    if i<N-1:
        d=min(A[i],A[i+1])
        ans+=d
        A[i]-=d
        A[i+1]-=d
print(ans)

Solution (Python):
n=int(input())
a=[int(input())for i in range(n)]
c=0
l=[]
l2=[]
for i in a:
    if i!=0:
        l.append(i)
    else:
        l2.append(sum(l)//2)
        l=[]
l2.append(sum(l)//2)
print(sum(l2))

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

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

    ans += a // 2
    surplus = a % 2

print(ans)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    p = 0
    for n in range(N):
        a = int(input())
        ans += min(p, a)
        p = max(0, a - p)
        ans += p // 2
        p %= 2
    print(ans)
    
if __name__ == '__main__':
    main()

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

Solution (Python):





import sys
readline = sys.stdin.readline

N = int(readline())
A = [int(readline()) for i in range(N)]

ans = 0
for i in range(N):
  pair, mod = divmod(A[i],2)
  ans += pair
  if mod == 1 and i != N - 1 and A[i + 1] > 0:
    ans += 1
    A[i + 1] -= 1
  
print(ans)

Solution (Python):
N = int(input())
listA = [int(input()) for i in range(N)]
count = 0

for x in range(N):
    check = listA[x]
    count += check // 2
    if x != N - 1 and check % 2 != 0:
        if listA[x + 1] > 0:
            count += 1
            listA[x + 1] -= 1
print(count)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

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





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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

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

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

print(ans)

Solution (Python):
n = int(input())
ans = 0
nex = 0
for i in range(n):
    now = int(input())
    if nex == 1 and now > 0:
        now -= 1
        nex = 0
        ans += 1
    elif nex == 1 and now == 0:
        nex = 0 
    ans += now//2
    if now % 2 == 1:
        nex = 1
print(ans)

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

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

print(ans)

Solution (Python):



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

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

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

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

cnt = 0
remain = 0
for n in range(N):
    if A[n] == 0:
        remain = 0
        continue
    cnt += (A[n]+remain)//2 
    remain = (A[n]+remain)%2
print(cnt)

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

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

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