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):
n = int(input())
a = []
for i in range(n):
  a.append(int(input()))
res = 0
for i in range(n):
  res += a[i] // 2
  if a[i] % 2 == 1:
    if i != n-1:
      if a[i+1] != 0:
        res += 1
        a[i+1] -= 1
  
print(res)

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

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

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

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

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

c = 0

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

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

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

print(ans)

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

ans = 0
for i in range(n):
    temp, mod = divmod(lis[i], 2)
    ans += temp
    if i < n-1 and lis[i+1] != 0:
        lis[i+1] += mod

print(ans)

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

first = int(input())
answer = first//2
before = first%2
for _ in range(N-1):
  A = int(input())
  answer += (A+before)//2
  before = (A+before)%2
  if A == 0:
    before = 0
print(answer)

Solution (Python):

import sys

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


sys.setrecursionlimit(10**7)









INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7
def intread():
    return int(sysread())
def mapline(t = int):
    return map(t, sysread().split())
def mapread(t = int):
    return map(t, read().split())


def run():
    N, *A = mapread()
    run = False
    ans = 0
    count = 0
    for a in A:
        if run:
            if not a:
                ans += count // 2
                run = False
                count = 0
            else:
                count += a
        else:
            if not a:
                continue
            else:
                run = True
                count += a
    ans += count // 2
    print(ans)

if __name__ == "__main__":
    run()

Solution (Python):

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

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

    print(ans)


if __name__ == "__main__":
    resolve()

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

lsts = []
temp = []
for aa in a:
    if aa == 0:
        if temp:
            lsts.append(temp)
            temp = []
    else:
        temp.append(aa)
if temp: lsts.append(temp)

ans = 0

for lst in lsts:
    for i, aa in enumerate(lst):
        ans += aa // 2
        if i != len(lst)-1:
            lst[i+1] -= aa % 2
            ans += aa % 2

print(ans)

Solution (Python):
n = int(input())
a = list(int(input()) for i in range(n))
ans = 0
for i in range(n-1):
    m = a[i]//2
    ans += m
    a[i] -= m*2
    if a[i] == 1 and a[i+1] != 0:
        ans += 1
        a[i] -= 1
        a[i+1] -= 1
print(ans + a[-1]//2)

Solution (Python):
N = int(input())
a = [int(input()) for _ in range(N)]
ans = 0
for i in range(N):
    cnt, mod = divmod(a[i], 2)
    ans += cnt
    if i < N - 1 and a[i + 1] != 0:
        a[i + 1] += mod

print(ans)

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

nowodd = False
ans = 0
for i in range(N):
    a = int(input())
    if nowodd and a>0:
        a-=1
        ans+=1

    if a%2==1:
        nowodd=True
    else:
        nowodd=False
    ans+=a//2
print(ans)

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

n = ni()
A = []
ans = 0
tmp=0
for i in range(n):
    a = ni()
    if a==0:
        ans+=tmp//2
        tmp=0
    else:
        tmp+=a
ans+=tmp//2
print(ans)

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


ans = 0
tmp = 0
for i in range(len(A_list)):
    if A_list[i] != 0:
        if i == len(A_list)-1:
            tmp += A_list[i]
            ans += int(tmp/2)
        else:
            tmp += A_list[i]
    else:
        ans += int(tmp/2)
        tmp = 0

print(ans)

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

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())


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

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

print(ans)

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


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

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

print(ans)

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

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

last = 0
ans = 0
for i in range(1, N+1):
    cnt = Xs[i-1]
    if cnt<=last:
        ans += cnt
        last = 0
    else:
        ans += last
        cnt -= last
        ans += cnt//2
        last = cnt%2
print(ans)

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

n = inp()
a = [inp() for _ in range(n)]
res = 0
for i,x in enumerate(a):
    res += x//2
    if x%2:
        if i == n-1 or a[i+1] == 0: continue
        a[i+1] -= 1
        res += 1
print(res)

Solution (Python):
N = int(input())
A = int(input())
ans = A//2
amari = A % 2
for _ in range(N-1):
    A = int(input())
    ans += (amari+A)//2
    if A == 0:
        amari = 0
    else:
        amari = (amari+A) % 2
print(ans)

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

cnt=0
ans=0
for _ in range(n):
    a=int(input())

    if a>0:
        cnt+=a
    else:
        ans+=cnt//2
        cnt=0
    
print(ans+cnt//2)

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

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:
        if A[i] * A[i + 1] > 0:
            ans += 1
            A[i] = 0
            A[i+1] -= 1
print(ans)

Solution (Python):
from collections import defaultdict
dic = defaultdict(int) 
N = int(input())
for i in range(N):
  temp = int(input())
  dic[i+1] = temp

ans = 0
L = list(dic.keys())
nokori = -1
for i in range(N):
  if dic[L[i]] >= 1 and L[i]-nokori <= 1:
    ans += 1
    dic[L[i]] -=1
    nokori = -1
  ans += dic[L[i]]//2
  if dic[L[i]]%2 == 1:
    nokori = L[i]
print(ans)

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

ans=0
cnt=0

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

print(ans)

Solution (Python):
N = int(input())
cards = 0
pairs = 0
for _ in range(N):
	A = int(input())
	if A:
		cards += A
	else:
		pairs += cards//2
		cards = 0
pairs += cards//2
print(pairs)

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

ans = 0
for key,val in enumerate(A):
    ans += int(val/2)

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

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

r = 0
ans = 0
for a in A:
    if a == 0:
        r = 0
        continue
    q, r = divmod(a + r, 2)
    ans += q
print(ans)

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

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

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

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

res = 0
n = 0
for a in A:
    if a == 0:
        res += n // 2
        n = 0
    n += a

res += n // 2

print(res)

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

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

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

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


print(ans)

Solution (Python):
N = int(input())
ans = 0
B = 0
for i in range(N):
    A = int(input())
    C = A+B
    ans += C//2
    if B == 1 and C == 1:
        B = 0
        continue
    B = C % 2
print(ans)

Solution (Python):
N = int(input())
tmp = 0
ans = 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())
A = [int(input()) for _ in range(n)]
ans = 0
for i in range(n-1):
    x,y = A[i], A[i+1]
    ans += x//2
    if x%2!=0 and y > 0:
        ans += 1
        A[i+1] -= 1
ans += A[-1]//2

print(ans)

Solution (Python):
n = int(input())
rest = 0
res = 0
for i in range(1, n + 1):
    a = int(input())
    if a == 0:
        rest = 0
    else:
        res += (rest + a) // 2
        rest = (rest + a) % 2
print(res)

Solution (Python):
n = int(input())
rest = 0
res = 0
for i in range(1, n + 1):
    a = int(input())
    if a == 0:
        rest = 0
    else:
        res += (rest + a) // 2
        rest = (rest + a) % 2
print(res)

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

A.append(0)
ans = 0

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

print(ans)

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

Solution (Python):


import sys



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


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


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


def main():
    n = input_int()
    tmp = 0
    ans = 0
    for i in range(1, n + 1):
        a = input_int()
        if a != 0:
            tmp += a
        else:
            ans += tmp // 2
            tmp = 0
    else:
        ans += tmp // 2
    print(ans)

    return


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

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

Solution (Python):

def solve(A):
    res = 0
    b = 0
    for a in A:
        a += b
        res += a//2
        if a == b:
            b = 0
        else:
            b = a%2
    return res

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    print(solve(A))

Solution (Python):
N = int(input())
A = []
for _ in range(N):
    A.append(int(input()))
res = 0
p = 0
for a in A:
    if a==0:
        p = 0
    a += p
    res += a//2
    p = a%2
print(res)

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

cards = [0] * n

for i in range(n):
  cards[i] = int(input())

ans = 0


for i in range(n):
  ans += math.floor(cards[i] / 2)
  cards[i] = cards[i] % 2
  if cards[i] == 1 and not(i == (n - 1)) and not(cards[i + 1] == 0):
    ans += 1
    cards[i + 1] = cards[i + 1] - 1

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 - 1):
  if A[i] >= A[i + 1]:
    now = int((A[i]) / 2)
    ans += now
    A[i] -= now * 2
    now2 = min(A[i], A[i + 1])
    ans += now2
    A[i + 1] -= now2
    A[i] -= now2
    
  else:
    now = A[i]
    ans += now
    A[i] -= now
    A[i + 1] -= now
  
ans += int(A[-1] / 2)  

print(ans)

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

Solution (Python):
n = int(input())
ans = 0
m = 0
for i in range(n):
    a = int(input())
    ans += (m+a)//2
    m = max(0,a-m)%2
print(ans)

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

K=0
S=0
for a in A:
    if a:
        S+=a
    else:
        K+=S//2
        S=0

print(K)

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    ans = 0
    amari = 0
    for a in A:
        if amari == 0:
            amari = a % 2
            ans += a // 2
        else:
            ans += min(amari, a)
            a = max(0, a - amari)
            ans += a // 2
            amari = a % 2

    print(ans)

    
    
    

if __name__ == '__main__':
    main()

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

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

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

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

a=[]

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

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

print(ans)

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

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

count = 0

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

Solution (Python):
N = int(input())
A_list = list()
for i in range(N):
    A_list.append(int(input()))

ans = 0



if N > 1:
    if A_list[0]%2 == 1:
        if A_list[1] > 0:
            ans += 1
            A_list[0] -= 1
            A_list[1] -= 1

    

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

        
            
    if N >= 2:
        if A_list[N-1]%2 == 1:
            if A_list[N-2] > 0:
                ans += 1
                A_list[N-1] -= 1
                A_list[N-2] -= 1

    


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

Solution (Python):




from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
    num = int(input())
    d[i + 1] = num

ans = 0
for i in range(1, n + 1):
    pre = d.get(i - 1, 0)
    cur = d.get(i, 0)
    t = min(pre, cur)
    ans += t
    d[i - 1] -= t
    d[i] -= t
    cur = d.get(i, 0)
    t = cur // 2
    ans += t
    d[i] -= t * 2
print(ans)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(int(readline()) for _ in range(N))

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


if __name__ == '__main__':
    main()

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

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

Solution (Python):
N = int(input())
Ls,L = [],[]
for i in range(N):
    A = int(input())
    if A==0:
        Ls.append(L)
        L = []
    else:
        L.append(A)
Ls.append(L)
out = 0
for L in Ls:
    out += sum(L)//2
print(out)

Solution (Python):
n = int(input())
ans = 0
rem = 0
for _ in range(n):
    a = int(input())
    ans += (a+rem)//2
    if (a+rem)%2 == 1 and a > 0: rem = 1
    else: rem = 0

print(ans)

Solution (Python):
n = int(input())
A = [int(input()) for _ in range(n)]
ans = 0
pre = 0
for a in A:
  d, m = divmod(pre + a, 2)
  ans += d
  if m == 1 and a > 0: pre = 1
  else: pre = 0
print(ans)

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

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

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

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

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

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

    
    
    
    A_cum = [0] * (N + 1)
    zero = [0]
    for i in range(N):
        A_cum[i+1] = A_cum[i] + A[i]
        if A[i] == 0:
            zero.append(i)
    zero.append(N)

    ans = 0
    for i in range(len(zero) - 1):
        ans += (A_cum[zero[i+1]] - A_cum[zero[i]]) // 2

    print(ans)

if __name__ == '__main__':
    resolve()

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

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

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

cnt += tmp//2

print(cnt)

Solution (Python):
n = int(input())
s = 0
z = 0
for _ in range(n):
  ai = int(input())
  s += (z+ai)//2
  if z == 1 and z+ai >= 3:
    z = (ai+1)%2
  else:
    z = ai%2
print(s)

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


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

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

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

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

def fact_and_inv(SIZE):
    inv = [0] * SIZE  
    fac = [0] * SIZE  
    finv = [0] * SIZE  
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    
    
    
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    
    return X.flatten().tolist()[0]

class TwoDimGrid:
    
    def __init__(self, h, w, wall="
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        

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

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

    def pos(self, x, y):
        
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        
        
        
        
        


def solve():
    n = getN()
    am = []
    ans = 0
    for i in range(n):
        num = getN()

        am.append(num)
    prev = 0

    for a in am:
        if prev:
            if a:
                ans += 1
                a -= 1
        ans += a//2
        prev = a % 2

    print(ans)
def main():
    n = getN()
    for _ in range(n):
        solve()

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

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

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    answer = 0
    last = 0
    for _ in range(N):
        a = read_int()
        if a != 0:
            answer += (last+a)//2
            last = (last+a)%2
        else:
            last = 0
    return answer


if __name__ == '__main__':
    print(solve())

Solution (Python):


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

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


z=0
while z<len(points)-1:
    x=points[z]
    y=points[z+1]
    count=0
    
    
    for j in range(x,y+1):
        if ind[j]==0:
            count+=1
    if count==y-x+1:
        z+=1
        ans+=1
    z+=1
print(ans)

Solution (Python):
def main():
	arr =[]
	for i in range(int(input())):
		arr.append(int(input()))
	ans = 0
	now = 0

	for i in arr:
		if i==0:
			ans = ans +(now//2)
			now = 0
		else:
			now = now+i
	ans= ans+(now//2)
	print(ans)
if __name__ =="__main__":
	main()

Solution (Python):
def main():
	arr =[]
	for i in range(int(input())):
		arr.append(int(input()))
	ans = 0
	now = 0
	for i in arr:
		if i==0:
			ans = ans +(now//2)
			now = 0
		else:
			now = now+i
	ans= ans+(now//2)
	print(ans)
if __name__ =="__main__":
	main()

Solution (Python):
n = int(input())
alst = [int(input()) for _ in range(n)]
cnt = 0
bef = 0
for num in alst:
    cnt += (num + bef) // 2
    if (num + bef) % 2 == 1 and num > 0:
        bef = 1
    else:
        bef = 0
print(cnt)

Solution (Python):
from copy import copy
n=int(input())
a=[0]+[int(input()) for _ in range(n)]
ans=0
for i in range(n):
  ans+=(a[i+1]+a[i])//2
  if a[i+1]:a[i+1]=(a[i+1]+a[i])%2
print(ans)

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

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

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

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





N = getN()
A = getArray(N)

cnt = 0
for i in range(N - 1):
    
    p = A[i] // 2
    cnt += p
    A[i] -= p * 2

    
    u = min(A[i], A[i + 1])
    cnt += u
    A[i] -= u
    A[i + 1] -= u

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

Solution (Python):
N,*A = map(int, open(0).read().split())
ans = 0
cum = 0
for i in range(N):
    if A[i] > 0:
        cum += A[i]
    else:
        ans += cum // 2
        cum = 0
print(ans+cum//2)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


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 [Scanner.string() 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 [Scanner.int() for i in range(n)]


def solve():
    N = Scanner.int()
    A = Scanner.int_cols_list(N)
    ans = 0
    for i in range(N - 1):
        ans += A[i] // 2
        A[i] %= 2
        t = min(A[i], A[i + 1])
        ans += t
        A[i] -= t
        A[i + 1] -= t
    ans += A[-1] // 2
    print(ans)


def main():
    
    
    solve()


if __name__ == "__main__":
    main()

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