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: Wrong Answer

Solution code:
# coding: UTF-8
n = int(raw_input())
a =[]
for var in range(n):
    a.append(int(raw_input()))
pair = 0
flag = True
for now in range((len(a)+1)/2):

    if a[now] % 2 == 0:
        pair = pair + a[now]/2
        a[now] = 0
    elif a[now] % 2 == 1:
        pair = pair + a[now]/2
        a[now] = 1
        if now == 0:
            pass
        else:
            if a[now+1] != 0:
                pair = pair + 1
                a[now+1] = a[now+1]-1
    if now == len(a)-now-1:
        continue
    if a[len(a)-now-1] % 2 == 0:
        pair = pair + a[len(a)-now-1]/2
        a[len(a)-now-1] = 0
    elif a[len(a)-now-1] % 2 == 1:
        pair = pair + a[len(a)-now-1]/2
        a[len(a)-now-1] = 1
        if now == 0:
            pass
        else:
            if a[len(a)-now-2] != 0:
                pair = pair + 1
                a[len(a)-now-2] = a[len(a)-now-2] -1
print pair

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
xs = list(map(int, (input() for _ in range(N))))
i = 0
s = 0
while i < len(xs):
    if xs[i] == 0:
        pass
    elif xs[i] > 1:
        s += xs[i] // 2
    elif i+1 < len(xs):
        if xs[i+1] == 1:
            s += 1
            i += 1
    i += 1

print(s)

Submission status: Wrong Answer

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:
        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: Wrong Answer

Solution code:
# coding: UTF-8
n = int(raw_input())
a =[]
for var in range(n):
    a.append(int(raw_input()))
pair = 0
flag = True
for now in range((len(a)+1)/2):
    if a[now] % 2 == 0:
        pair = pair + a[now]/2
        a[now] = 0
    elif a[now] % 2 == 1:
        pair = pair + a[now]/2
        a[now] = 1
        if now == 0:
            pass
        else:
            if a[now+1] != 0:
                pair = pair + 1
                a[now+1] = a[now+1]-1

    if a[len(a)-now-1] % 2 == 0:
        pair = pair + a[len(a)-now-1]/2
        a[len(a)-now-1] = 0
    elif a[len(a)-now-1] % 2 == 1:
        pair = pair + a[len(a)-now-1]/2
        a[len(a)-now-1] = 1
        if now == 0:
            pass
        else:
            if a[len(a)-now-2] != 0:
                pair = pair + 1
                a[len(a)-now-2] = a[len(a)-now-2] -1
print pair

Submission status: Wrong Answer

Solution code:
N = input()
count = 0
flag = 0
print range(1,N+1)
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: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
N = int(input())
ans = 0
carry = 0
for n in range(N):
    a = int(input())
    ans += a // 2
    if a % 2 == 1:
        if carry:
            ans += 1
            carry = 0
        else:
            carry = 1
    else:
        carry = 0
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
l=[]
ans=chk=0
for i in range(n):
    n=int(raw_input())
    ans+=n/2
    l.append(n%2)
s=''.join(map(str,l))
ans+=s.count('11')
print ans

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = [int(input()) for k in range(N)]
B = copy.deepcopy(A)

ans1 = ans2 = 0
for k in range(N):
    ans1 += A[k]//2
    A[k] %= 2

for k in range(N-1):
    if A[k]*A[k+1] == 1:
        ans1 += 1
        A[k] = A[k+1] = 0

for k in range(N-1):
    temp = min(B[k],B[k+1])
    ans2 += temp
    B[k] -= temp
    B[k+1] -= temp

for k in range(N):
    ans2 += B[k]//2
    B[k] %= 2

for k in range(N-1):
    if B[k]*B[k+1] == 1:
        ans2 += 1
        B[k] = B[k+1] = 0

print(max(ans1,ans2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 / 2).sum()
A = A % 2
for i in xrange(len(A) - 1):
    if A[i] == 1 and A[i + 1] == 1:
        num_pair += 1
        A[i] = 0
        A[i + 1] = 0
print num_pair

Submission status: Wrong Answer

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

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

print count

Submission status: Wrong Answer

Solution code:
n=int(raw_input())
N=[]
for i in range(n):
	N.append(int(raw_input()))
add=0
for i in range(n-1):
	if N[i]==0:
		continue
	elif N[i+1]==0:
		add+=N[i]/2
	else:
		if N[i]<N[i+1]:
			add+=N[i]
			N[i+1]-=N[i]
		else:
			if N[i]/2>N[i+1]:
				add+=N[i]/2
			else:
				add+=N[i+1]
				add+=(N[i]-N[i+1])/2
				N[i+1]=0
print add

Submission status: Wrong Answer

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

for i in range(n):
	i = input()
	s += i / 2
	if s % 2 == 1:
		rest = 1

print s

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !

count = 0
flag = 0

for i in [int(input()) for i in range(int(input()))]:
    if i == 0:
        flag = 0
        continue
    else :
        count += i//2
        if i%2 == 0:
            flag = 0
        else :
            if flag == 0:
                flag = 1
            elif flag == 1:
                count += 1
                flag = 0
                
print(count)

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
counts = [ int(raw_input()) for i in range(n) ]
counts.insert(0, 0)
result = 0
for i in range(1, n + 1):
    result += counts[i] // 2
    counts[i] %= 2
for i in range(2, n + 1):
    d = min(counts[i-1], counts[i])
    counts[i-1] -= d
    counts[i] -= d
    result += d
print(result)

Submission status: Wrong Answer

Solution code:
from sys import stdin
n=int(input())
total=0
cartes=[0]*n
for i in range(n):
    nbCarte=int(stdin.readline())
    total+=nbCarte//2
    nbCarte%=2
    if i!=0 and nbCarte==1 and cartes[i-1]==1:
        total+=1
        nbCarte=0
        cartes[i-1]=0
    cartes[i]=nbCarte
print(total)

Submission status: Wrong Answer

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

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

for k in range(N-1):
    if A[k]*A[k+1] == 1:
        ans += 1
        A[k] = A[k+1] = 0

print(ans)

Submission status: Wrong Answer

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

pair = 0
for i in range(0,n-1):
    p = min(a[i],a[i+1])
    pair += p
    a[i] -= p
    a[i+1] -= p

for i in range(0,n):
    pair += a[i]/2

print pair

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#coding: utf-8                                                        
def proc(X):
    ret = 0
    for i in xrange(len(X)-1):
        if X[i] == X[i+1] == 1:
            ret += 1
        X[i] = X[i+1] = 0
    return ret

n = int(raw_input())
A = [int(raw_input()) for i in xrange(n)]

p = sum([x/2 for x in A])
A = [x%2 for x in A]
xA = list(A)
p1 = proc(xA)
A.reverse()
xA = list(A)
p2 = proc(xA)

print p + max(p1, p2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

for k in range(N-1):
    if A[k]*A[k-1] == 1:
        ans += 1
        A[k] = A[k-1] = 0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
counts = [ int(raw_input()) for i in range(n) ]
counts.insert(0, 0)
result = 0
for i in range(1, n + 1):
    d = min(counts[i-1], counts[i])
    counts[i-1] -= d
    counts[i] -= d
    result += d
    d = counts[i-1] // 2
    result += d
    counts[i-1] -= 2*d
print(result)

Submission status: Time Limit Exceeded

Solution code:
#float型を許すな
#numpyは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)
for i in range(len(points)-1):
    x=points[i]
    y=points[i+1]
    count=0
    #print(y)
    #print(x)
    for j in range(x,y+1):
        if ind[j]==0:
            count+=1
    if count==y-x+1:
        points[i+1]=-1
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

count=0

"""
for i in range(n):
    count+=a[i]//2
    a[i]=a[i]%2
"""

for i in range(n-1):
    while((a[i]>0) & (a[i+1]>0)):
        a[i]-=1
        a[i+1]-=1
        count = count+1

for i in range(n):
    count+=a[i]//2
    a[i]=a[i]%2

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
N = int(input())

A = np.zeros(N)

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

if all(A):
    print(int(sum(A) // 2))
    sys.exit()

B = np.split(A, np.where(A == 0)[0][:])
count = sum([sum(item) // 2 for item in B])
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
N = int(input())

A = np.zeros(N)
count = 0
for n in range(N):
    A[n] = int(input())

if all(A):
    print(int(sum(A) // 2))
    sys.exit()

B = np.split(A, np.where(A == 0)[0][:])
for item in B:
    count += sum(item) // 2
print(int(count))

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())

A = [0] * N
count = 0
for n in range(N):
    A[n] = int(input())

if all(A):
    print(sum(A) // 2)
    sys.exit()

import numpy as np
A = np.array(A)
B = np.split(A, np.where(A == 0)[0][:])
for item in B:
    count += sum(item) // 2
print(count)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
t=c=0
for _ in[0]*input():
 i=input()
 if i:t+=i 
 else:c+=t/2;t=0
print c+t/2

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
	N = int(stdin.readline().strip())
	value = [int(x) for x in range(N)]
	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:
			ans+=1
			card[i]-=2
		elif  i+1 < N:
			if card[i] == 1 and card[i+1]>=1:
				ans+=1
				card[i]-=1
				card[i+1]-=1
			else:
				i+=1
		else:
			i+=1
	print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
#AGC003B

n=int(raw_input())
s=[]
for i in xrange(1,n+1):
 x=int(raw_input())
 for j in xrange(x):
  s.append(i)
cnt=0
i=0
while i<len(s)-1:
 if s[i+1]-s[i]==0 or s[i+1]-s[i]==1:
  cnt+=1
  i+=2
 else:
  i+=1
print cnt

Submission status: Time Limit Exceeded

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

cnt = 0
i = 0
while True:
    if a[i] >= 2:
        cnt += 1
        a[i] -= 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: Time Limit Exceeded

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

    A[i] -= 2
    ans += 1

print ans

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = []
for i in range(n):
 a.append(int(input()))
count = 0
for i in range(n):
 while (a[i] >= 2):
  a[i] -= 2
  count += 1
 if (i != n-1):
  while (a[i] >= 1 & a[i+1] >= 1):
   a[i] -= 1
   a[i+1] -= 1
   count += 1
print (count)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
dic = defaultdict(int) 
N = int(input())
for i in range(N):
  temp = int(input())
  dic[i+1] = temp
#print(dic)
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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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] & 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)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc003/tasks/agc003_b

import sys
# sys.setrecursionlimit(100000)


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

Submission status: Accepted

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