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


INF = float('inf')


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


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

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

print(ans)

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

print(ans)

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

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())


n = ni()
a = []
for _ in range(n):
    a.append(ni())
    
res = 0
ans = 0
for ai in a:
    if ai == 0:
        ans += res//2
        res = 0
    else:
        res += ai
        
ans += res//2
    
print(ans)

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

Solution (Python):
n=int(input())
l=[int(input()) for _ in range(n)]
v,s=0,0
for i in l:
  if i:
    s+=i
  else:
    v+=(s//2)
    s=0
if s:
  v+=(s//2)
print(v)

Solution (Python):
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n = iin()
a = [iin() for _ in range(n)]

ans = 0
t = 0
for x in a:
    if x == 0:
        ans += t // 2
        t = 0
    else:
        t += x
ans += t // 2
print(ans)

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

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

Solution (Python):
N=int(input())
A=[int(input()) for i in range(N)]
L=[0]
for i in range(N):
  if A[i]==0:
    L.append(0)
  else:
    L[-1]+=A[i]
ans=0
for i in L:
  ans+=i//2
print(ans)

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

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

arr = []

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

l = 0
r = 0


ans = 0
while l < n:
	while  r+1 < n and arr[r+1] > 0:
		r += 1

	ans += sum(arr[l:r+1])/2
	l = r+1
	r = l

print ans

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    for i in range(N-1):
        if A[i] % 2 == 0:
            ans += A[i] // 2
        elif A[i+1] > 0:
            ans += (A[i] + 1) // 2
            A[i+1] -= 1
        else:
            ans += A[i] // 2
    ans += A[-1] // 2
    return ans


def main():
    N = read_int()
    A = [read_int() for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


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


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    for i in range(N-1):
        if A[i] % 2 == 0:
            ans += A[i] // 2
        elif A[i+1] > 0:
            ans += (A[i] + 1) // 2
            A[i+1] -= 1
        else:
            ans += A[i] // 2
    ans += A[-1] // 2
    return ans


def main():
    N = read_int()
    A = [read_int() for _ in range(N)]
    print(slv(N, A))


if __name__ == '__main__':
    main()

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

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

    
    if As[i] and As[i + 1]:
        ans += 1
        As[i] -= 1
        As[i + 1] -= 1

print(ans)

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

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

    print(pairs)


if __name__ == '__main__':
    main()

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

result = 0

t = 0
for a in A:
    if a == 0:
        result += t // 2
        t = 0
    else:
        t += a

result += t // 2

print(result)

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

ans = 0
a = 0
for i in range(n):
    c = int(input())
    ans += (a+c)//2
    if c == 0:
        a = 0
    elif (a+c)%2 == 1:
        a = 1
    else:
        a = 0
print(ans)

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

ans = 0
s = 0

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

print(ans + s//2)

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

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

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

print(ans)

Solution (Python):
N=int(input())
t=[]
u=0
for i in range(N):
    s=int(input())
    if s!=0:
        t.append(s)
    if s==0:
        u+=(sum(t)//2)
        t=[]
u+=(sum(t)//2)
print(u)

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

ans = 0

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

ans += a[n - 1] // 2

print(ans)

Solution (Python):
N = int(input())
cnt = 0
p = 0
t = 0
c = 0
for i in range(N):
    c = int(input())
    if t:
        t = 0
        if c:
            c -= 1
            cnt += 1
    q, m = divmod(c, 2)
    cnt += q
    t = m
print(cnt)

Solution (Python):


import sys, math, copy





HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    an = [int(input()) for i in range(n)]
    assert len(an) == n

    res = 0
    prev = 0
    for i in range(n):
        avail = prev + an[i]
        res += avail // 2
        prev = avail % 2 if an[i] > 1 else 0
    print(res)

main()

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

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

Solution (Python):

def inpl(): return map(int, input().split())
N = int(input())

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

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

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

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

tmp = ans = 0
for a in src:
    if a == 0:
        ans += tmp//2
        tmp = 0
    else:
        tmp += a
ans += tmp//2
print(ans)

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

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

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

Solution (Python):
n = int(input())
nums = []
for i in range(n):
  nums.append(int(input()))
count = 0
for j in range(n):
  if nums[j]%2 == 0:
    count += (nums[j]//2)
    nums[j] = 0
  else:
    if 0 < j and 0 < nums[j-1]:
      count += (nums[j]//2) + 1
      nums[j] = 0
      nums[j-1] = 0
    elif j < n-1 and 1 <= nums[j+1]:
      count += (nums[j]//2) + 1
      nums[j] = 0
      nums[j+1] -= 1
    else:
      count += (nums[j]//2)
      nums[j] = 1
print(count)

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

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

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

Solution (Python):
from collections import OrderedDict, deque
N = int(input())
A = OrderedDict({i: int(input()) for i in range(1, N+1)})
ans = 0

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


print(ans + A[N]//2)

Solution (Python):


n = input()
ans = 0
last = 0
for i in range(n):
    a = input() + last
    ans += a / 2
    if a > last:
        last = a % 2
    else:
        last = 0
print ans

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

Solution (Python):
N = int(input())
src = [int(input()) for i in range(N)]
ans = n = 0
for a in src:
    if a == 0:
        ans += n//2
        n = 0
    else:
        n += a
ans += n//2
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]%2 ==1 and A[i+1]:
    A[i+1] -= 1
    ans += 1
  ans+= A[i]//2
ans+=A[N-1]//2
print(ans)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    N = int(input())
    A_list = [int(input()) for i in range(N)]
    ans = 0
    pre_rest = 0
    for a in A_list:
        if pre_rest and a > 0:
            ans += 1
            a -= 1
        ans += a // 2
        pre_rest = a % 2

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin

def main():
    nums = int(stdin.readline())
    l = []
    actual = int(stdin.readline())
    total = 0
    for x in range(nums-1):
        total += actual//2
        temp = int(stdin.readline())
        if temp != 0:
            actual = actual%2 + temp
        else:
            actual = temp

    print(total+actual//2)
        
        
    
main()

Solution (Python):
N=int(input())
l=[int(input()) for _ in range(N)]
sum1,j=0,0
for i in range(N):
    if l[i]==0 or i==N-1:
        sum1+=int(sum(l[j:i+1])/2)
        j=i
print(sum1)

Solution (Python):
from sys import stdin

def main():
	N = int(stdin.readline().strip())
	i,card = 0,[-1 for x in range(N)]
	while i < N:
		x = int(stdin.readline().strip())
		card[i] = x
		i+=1
	i,ans = 0,0
	while i < N:
		if card[i]%2==0:
			ans+= card[i]//2
			card[i] = 0
		else:
			ans+=(card[i]-1)//2
			card[i] = 1
			if i+1 < N and card[i+1] >=1:
				ans+=1
				card[i],card[i+1] = 0, card[i+1]-1
		i+=1
	print(ans)
main()

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

Solution (Python):



from random import *

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

n = readline()[0]
prev = 0
ans = 0
for i in range(0,n):
    x = readline()[0]
    s = min(prev,x)
    prev = prev -s
    x = x - s
    ans = ans + s
    s = x >> 1
    ans = ans + s
    prev = x - s * 2

print(ans)

Solution (Python):
n = int(raw_input())
ls = [int(raw_input()) for _ in range(n)]
ans = 0
for i, j in enumerate(ls):
    ans += j / 2
    if i < len(ls)-1 and j % 2 == 1 and ls[i+1] > 1:
        ans += 1
        ls[i+1] -= 1
print ans

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

ans = 0
for idx,a in enumerate(As):
    if idx!=len(As)-1:
        tmp = As[idx]
        ans += tmp//2
        As[idx] = 1 * As[idx]%2

        tmp = min(As[idx], As[idx+1])
        
        ans += tmp
        As[idx] -= tmp
        As[idx+1] -= tmp
    else:
        tmp = As[idx]
        ans += tmp//2
        As[idx] = 1 * As[idx]%2
    

As = list(reversed(As))
for idx,a in enumerate(As):
    if idx!=len(As)-1:
        tmp = As[idx]
        ans += tmp//2
        As[idx] = 1 * As[idx]%2

        tmp = min(As[idx], As[idx+1])
        
        ans += tmp
        As[idx] -= tmp
        As[idx+1] -= tmp
    else:
        tmp = As[idx]
        ans += tmp//2
        As[idx] = 1 * As[idx]%2
    

print(ans)

Solution (Python):
import sys



N = int(raw_input())
rest = [0 for _ in range(N)]
ins = [0 for _ in range(N)]
pairs = 0
for x in range(N):
	n = long(raw_input())
	ins[x] = n
	pairs += n / 2
	rest[x] = n % 2

for x in range(0, N - 1, 1):
	if ((rest[x] == 1) and (rest[x + 1] == 1)):
		pairs += 1
		rest[x] = 0
		rest[x + 1] = 0
	elif ((rest[x] == 1) and (rest[x + 1] == 0) and (ins[x + 1] > 0)):
		rest[x + 1] = 1
		ins[x + 1] -= 2
		rest[x] = 0
	else:
		pass

print str(pairs)

Solution (Python):


n=int(raw_input())
s=[int(raw_input()) for i in xrange(n)]
cnt=0
temp=0
for d in s:
 cnt+=(d+temp)/2
 if d==0:
  temp=0
 else:
  temp=(d+temp)%2
print cnt

Solution (Python):
import numpy as np

N = int(raw_input())
A = [0] * N
for idx in xrange(N):
  A[idx] = int(raw_input())
total =  0
pre = 0
for item in A:
  total += (item+pre) / 2
  if item == 0:
    pre = 0
  else:
    pre = (item+pre) % 2

print total

Solution (Python):
def solve(a):
	s = 0
	loss = 0
	for k in a:
		if k == 0:
			if s % 2 == 1:
				loss += 1
			s = 0
		else:
			s += k

	return (sum(a) - loss) // 2

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

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

Solution (Python):

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

cnt = 0
i = 0
while i < n:
    if a[i] >= 2:
        pairs = a[i] // 2
        cnt += pairs
        a[i] -= (pairs * 2)

    elif a[i] == 1:
        if i + 1 >= n:
            break

        if a[i + 1] > 0:
            cnt += 1
            a[i] -= 1
            a[i + 1] -= 1

        else:
            i += 1

    else:
        i += 1

print(cnt)

Solution (Python):
N = input()
cards = [int(raw_input()) for i in xrange(N)]
ans = cards[0] / 2
cards[0] %= 2

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

print ans

Solution (Python):
n = int(input())
a = [int(input()) for _ in range(n)]
total = a[0] // 2
a[0] -= a[0] // 2 * 2
for i in range(1, n):
    r = min(a[i-1], a[i])
    total += r
    a[i-1] -= r
    a[i] -= r
    total += a[i] // 2
    a[i] -= a[i] // 2 * 2
print(total)

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

total=0
diff = 0
for a in arr:
    if a==0:
        diff=0
    total+=(a+diff)//2
    diff=(a+diff)%2

print(total)

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

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

Solution (Python):

import math
from functools import reduce
from operator import add
if __name__ == '__main__':
    n = int(input())
    a = [0]
    ans = 0
    for i in range(n):
        tmp = int(input())
        a.append(tmp)
        if tmp == 0:
            ans += math.floor(reduce(add, a) // 2)
            a.clear()
            a.append(0)
    ans += math.floor(reduce(add, a) // 2)
    print(ans)

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

A_c = [int(raw_input()) for i in range(N)]

t_pairs = 0

group_count = 0
for i in range(N):
    if A_c[i] > 0:
        group_count += A_c[i]
    else:
        t_pairs += group_count // 2
        group_count = 0

print (t_pairs + group_count//2)

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

ans = 0
temp = 0
for x in A:
    if x == 0:
        ans += temp//2
        temp = 0
    else:
        temp += x

print(ans+temp//2)

Solution (Python):
import numpy as np
N = int(raw_input())
A = []
for i in xrange(N):
    A.append(int(raw_input()))
A = np.array(A)
num_pair = (A[A % 2 == 1] / 2).sum()
A[A % 2 == 1] = 1
num_pair += (A[A > 2] / 2).sum() - (A > 2).sum()
A[A > 2] = 2
for i in xrange(len(A) - 1):
    if A[i] == 2:
        num_pair += 1
        A[i] = 0
    elif A[i] == 1 and A[i + 1] >= 1:
        num_pair += 1
        A[i] = 0
        A[i + 1] -= 1
num_pair += A[-1] / 2
print num_pair

Solution (Python):
n = input()
A = [int(raw_input()) for i in xrange(n)]
ans = 0
for i in xrange(n):
    if A[i] > 1:
        pair = A[i]/2
        ans += pair
        A[i] -= pair*2
    if i<n-1 and A[i] > 0 and A[i+1] > 1:
        A[i] -= 1
        A[i+1] -= 1
        ans += 1
print ans

Solution (Python):
import sys
n = int(sys.stdin.readline().strip())
a = [int(sys.stdin.readline().strip()) for x in range(n)]

total = 0

pre_i = 0
for i in a:
    if pre_i == 1 and i >= 1:
        total += 1
        i -= 1
    total += i / 2
    pre_i = i % 2

print total

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

Solution (Python):
ans = 0

N = int(raw_input())

A = []

for i in range(N):
  A.append(int(raw_input()))

A.append(0)

for i in range(N):

  while True:

    if A[i] == 0:
      break

    elif A[i] == 1:

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

      break

    ans += A[i] / 2

    A[i] = A[i] % 2

print ans

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

count = 0
for i in range(n - 1):
    if a[i] > 0:
        tmp = a[i] // 2
        count += tmp
        a[i] -= tmp * 2
    if a[i] > 0 and a[i + 1] > 0:
        tmp = min(a[i], a[i + 1])
        a[i + 1] -= tmp
        count += tmp

if a[-1] > 1:
    count += a[-1] // 2
print(count)

Solution (Python):
N = int(input())
a = [int(input())  for i in range(N)]
count = 0
for i in range(N) :
    if a[i] >= 2:
        count = count + a[i]//2
        a[i] = a[i] % 2
    if i+1<N :
        if a[i]==1 and a[i+1]>0:
            count = count + 1
            a[i+1] = a[i+1]-1
print('%s' % str(count))

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

Solution (Python):
N = input()
count = 0
flag = 0
for i in range(1,N+1):
    IN = input()
    if flag:
        if (flag == i - 1):
            if  IN > 0:
                IN -= 1
                count += 1
    flag = 0

    count += IN/2
    if IN%2 == 1:
        flag = i

print count

Solution (Python):


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

Solution (Python):
n = int(raw_input())
counts = [ int(raw_input()) for i in range(n) ]
counts.append(0)
result = 0
span = 0
for x in counts:
    if x == 0:
        result += span // 2
        span = 0
    else:
        span += x
print(result)

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

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

Solution (Python):
n = input()
rest = 0
s = 0

for _ in range(n):
	t = input()
	if t != 0:
		t += rest
	s += t / 2
	if t % 2 == 1:
		rest = 1
	else:
		rest = 0

print s

Solution (Python):
from sys import stdin
n=int(input())
total=0
cartes=[0]*n
for i in range(n):
    nbCarte=int(stdin.readline())
    cartes[i]=nbCarte

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

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

Solution (Python):
n=int(raw_input())
a=[int(raw_input()) for _ in xrange(n)]
cnt=0
for i in xrange(n-1):
    if a[i]==0:continue
    if a[i]%2==1:
        if a[i+1]!=0:
            cnt+=a[i]/2
            a[i+1]+=1
        else:
            cnt+=a[i]/2
    else:
        cnt+=a[i]/2
if a[n-1]==0:
    print(cnt)
else:
    cnt+=a[n-1]/2
    print(cnt)

Solution (Python):
def solve(A):
  result = 0
  prev = 0
  for a in A:
    aa = a + prev
    result += aa // 2
    prev = aa % 2 if a > 0 else 0
  return result

N = int(input())
A = [int(input()) for i in range(N)]
print(solve(A))

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m



n=i()
a=[0]*n
p=0
cnt=0
for j in range(n):
    a[j]=i()
    if a[j]==0:
        p+=cnt%2
        cnt=0
    else:
        cnt+=a[j]%2

print (sum(a)-p)/2

Solution (Python):








n = int(input())
A = [0]*n

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


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

ans += A[n-1] // 2


ans2 = 0
for i in reversed(range(1, n-1)):
	now = A[i]
	ans2 += now // 2
	if now % 2 == 1:
		if A[i-1] > 0:
			A[i-1] -= 1
			ans2 += 1

ans2 += A[0] // 2


print(max(ans, ans2))

Solution (Python):
n = input()
p = 0
r = 0
for i in xrange(n):
    ai = input()
    if r ==1 and ai > 0:
        ai += 1
    p += ai/2
    r = (ai%2)
print p

Solution (Python):
from sys import stdin
n = int(stdin.readline())
a = [int(stdin.readline()) for _ in xrange(n)]
p = 0
ans = 0
for x in a:
    if p and x:
        ans += 1
        x -= 1
    ans += x / 2
    p = x & 1
print ans

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

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


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
N = input()
A = [input() for _ in range(N)]
ans = 0
for i in range(N-1):
	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
ans += A[-1]/2
print ans

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

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

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

EPS = 1e-9


def dot(a, b):
    return a.real * b.real + a.imag * b.imag

def cross(a, b):
    return a.real * b.imag - a.imag * b.real

def distance(a, b, c):
    if dot(b-a, c-a) <= EPS:
        return abs(c-a)
    if dot(a-b, c-b) <= EPS:
        return abs(c-b)
    return abs(cross(b-a, c-a)/(b-a))

N = n()

A = []
for i in xrange(N):
    a = n()
    A.append(a)

A.append(0)

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

print c

Solution (Python):
N=int(input())
A=[int(input()) for _ in range(N)]
P,C=0,0
for i in range(N):
    W=A[i] + C
    P+=W//2
    C=min(W%2,A[i])
print(P)