Problem:


Score : 400 points

Problem Statement

Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it.
He has A_i cards with an integer i.

Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.

Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.

Constraints

1 ≦ N ≦ 10^5

0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the maximum number of pairs that Snuke can create.

Sample Input 1

4
4
0
3
2

Sample Output 1

4

For example, Snuke can create the following four pairs: (1,1),(1,1),(3,4),(3,4).

Sample Input 2

8
2
0
1
6
0
8
2
1

Sample Output 2

9



Sample input:
4
4
0
3
2


Sample output:
4

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
ctr = 0
ans = 0
for _ in range(N):
    i = int(input())
    ctr += i
    if not i:
        ans += ctr//2
        ctr = 0
ans += ctr//2

print(ans)

Submission status: Accepted

Solution code:

N=int(input())

A = []

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
cnt = 0
s = 0
for _ in range(n):
    x = int(input())
    if x==0:
        cnt += s//2
        s = 0
    else:
        s += x
print(cnt+s//2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lis=[]
for i in range(N):
  lis.append(int(input()))
ans = 0
stack = 0
for nums in lis:
  if nums > 0:
    stack += nums
  else:
    ans += stack//2
    stack = 0
ans += stack//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
lis = [int(input()) for i in range(n)]
cou = 0
num = 0
for i in range(n):
  if lis[i] == 0:
    cou += (num // 2)
    num = 0
  else:
    num += lis[i]
cou += (num // 2)
print(cou)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

a = []

f = [0 for i in range(n)]

ans = 0

for i in range(n):
    m = int(input())
    if m > 1:
        f[i] = 1
    ans += m//2
    a.append(m%2)

for i in range(n):
    if a[i] == 1 and i != n-1:
        if a[i+1] == 1:
            ans += 1
            a[i+1] = 0
        elif f[i+1] == 1:
            a[i+1] = 1
            
print(ans)

Submission status: Accepted

Solution code:
t=c=0
for _ in[0]*int(input()):i=int(input());c+=(i+t)//2;t=(i+t)%2&(i>0)
print(c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
ans=0
A=int(input())
ans+=int(A/2)
A=A%2
for i in range(N-1):
    B=int(input())
    if B==0:
        A=0
    else:
        if A==1:
            B=B-1
            ans+=1
            ans+=int(B/2)
            A=B%2
        else:
            ans+=int(B/2)
            A=B%2
            
print(ans)

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
aa = [int(input()) for i in range(N)]

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = [int(input()) for i in range(N)]
cnt=0
for i in range(N):
    if a[i]//2 >=1:
        cnt+=a[i]//2
        a[i]-=a[i]//2*2
    if i!=N-1:
        if a[i+1]>=1 and a[i]==1:
            cnt+=1
            a[i+1]-=1
            a[i]-=1
print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(input()) for _ in range(N)]
ans = 0
for i in range(N - 1):
    p, q = divmod(A[i], 2)
    ans += p
    if q and A[i + 1]:
        A[i + 1] += 1
ans += A[-1] // 2
print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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()

Submission status: Accepted

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

ans = 0
for i in range(N):
    # As[i]内でペアを作る
    ans += As[i] // 2
    As[i] %= 2

    # As[i]が1つ残って、As[i+1]も1つ以上あるならば、ペアを1つ作る
    if As[i] and As[i + 1]:
        ans += 1
        As[i] -= 1
        As[i + 1] -= 1

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0

for i in range(n - 1):
	if a[i] == 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)

Submission status: Accepted

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

Submission status: Accepted

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

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy
# sys.setrecursionlimit(1000000)

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

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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])
        # print('\t', tmp)
        ans += tmp
        As[idx] -= tmp
        As[idx+1] -= tmp
    else:
        tmp = As[idx]
        ans += tmp//2
        As[idx] = 1 * As[idx]%2
    # print(ans,As)

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])
        # print('\t', tmp)
        ans += tmp
        As[idx] -= tmp
        As[idx+1] -= tmp
    else:
        tmp = As[idx]
        ans += tmp//2
        As[idx] = 1 * As[idx]%2
    # print(ans,As)
# print('hhh')
print(ans)

Submission status: Accepted

Solution code:
import sys

#sys.stdin = open('b_2.txt', 'r')

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)

Submission status: Accepted

Solution code:
#AGC003B

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#B
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)

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

Solution code:
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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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