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)]
ans = 0
tmp = 0
for a in A:
    if tmp > a:
        ans += a
        tmp = 0
        continue
    else:
        ans += tmp
        a -= tmp
        ans += a // 2
        tmp = a - (a // 2) * 2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

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 = [0]*(n+1)

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N=int(input())

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

Submission status: Accepted

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

    print(cnt)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

# from collections import deque

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

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

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

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

    res = 0
    odd = 0

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

    print(res)
    # print("No Yes".split()[res])

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(ans+cnt//2)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A = [Z() for _ in range(N)]
    output = 0

    def makeRun(i, s):
        #A[i]とA[i+1]でシュンツ作る
        if A[i] <= 0 or A[i+1] <= 0: return s
        A[i] -= 1
        A[i+1] -= 1
        s += 1
        return s

    def makeTriple(i, s):
        #A[i]でコーツ作る
        if A[i] < 0: return s
        s += A[i]//2
        A[i] %= 2
        return s

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

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

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

#############
# Functions #
#############

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

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

#####Shorten#####
def DD(arg): return defaultdict(arg)


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

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

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

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

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

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

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

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

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

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

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

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

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

#############
# Main Code #
#############
N = I()
A = ILs(N)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

A = []

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

temp = 0
total = 0

import math

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

print(total)

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

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

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())

n = I()
A = [I() for _ in range(n)]
ans = 0
# for i in range(n):
#     cnt += A[i]//2
#     A[i] -= (A[i]//2) * 2
# for i in range(n-1):
#     if A[i] >= 1 and A[i+1] >= 1:
#         cnt += 1
#         A[i] -= 1
#         A[i+1] -= 1
i = 0
SUM = 0
while i < n:
    if A[i] == 0:
        ans += SUM//2
        SUM = 0
    else:
        SUM += A[i]
    i += 1
ans += SUM//2
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
cur_sum = 0  # 0が入るまでのsum
for i in range(n):
    if a[i] == 0:
        ans += cur_sum // 2
        cur_sum = 0
    else:
        cur_sum += a[i]
ans += cur_sum // 2
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 先頭から見ていく
# A_i // 2個は自分同士でペアを作ってよい
# 1枚余ったら、A_i+1が0でなければA_i+1から1減らしてペアを作る。
# この貪欲でOK

import sys
readline = sys.stdin.readline

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
res = 0
tmp = 0
zero = False
for i in range(n):
    s = int(input())
    a[i] = s
    if s==0:
        zero = True
if not zero:
    print(sum(a)//2)
    exit()

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
def solve(N, A):
    ret = 0
    for idx in range(N):
        ret += A[idx] // 2
        A[idx] %= 2
        if A[idx] and idx + 1 < N and A[idx + 1]:
            ret += 1
            A[idx + 1] -= 1
    return ret

if __name__ == "__main__":
    N = int(input())
    A = [0 for _ in range(N)]
    for idx in range(N):
        A[idx] = int(input())
    print(solve(N, A))

Submission status: Accepted

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

cnt = 0
for i in range(n-1):
    cnt += a_list[i] // 2
    a_list[i] = a_list[i] % 2

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

# 最後に末尾のやつを処理する
cnt += a_list[n-1] // 2

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())
ans = 0
tmp = 0
i = 0
while i < N:
  a = int(input())
  if a == 0:
    ans += tmp //2
    tmp = 0
  else:
    tmp += a
  i += 1
ans += tmp // 2
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
from collections import deque
import math
import bisect
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))


n=int(input())
l=[int(input()) for i in range(n)]
ans=0
c=0
for i in range(n):
    if l[i]==0:
        ans+=c//2
        c=0
    else:
        c+=l[i]
ans+=c//2
print(ans)

Submission status: Accepted

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

    ans += a[i] // 2
    a[i] %= 2

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
chk = 0
for i in range(n):
  a = int(input())
  p = chk+a
  ans += p//2
  if a > 0:
    chk = p%2
  else:
    chk = 0
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[0]*N
for i in range(N):
    A[i]=int(input())
B   = [0]*N
B[0]= A[0] %2
ans= A[0]//2

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
#A[i]の部分列P[i]に0が含まれない場合、P[i]にあるカードを最大限利用し、sum(P[i])//2組構成でき、あまりは一切持ち越されない。
#これより、先頭から0が現れるまで要素を加算していき、0が出たら2で割って切り捨て
#この解はコーナーケースなくできる

#sum(P[i])//2組は何らかの順序でgreedyに取れば必ず構成でき、そうすることでP[i]のどこか1つがsum(P[i])%2となる以外は全て0となる
#... 0 [ P[i] ] 0 [ P[i+1] ]...と構成するため、
#... 0 [(1/0) 0 0 ... (0/1)] 0 [p[i+1][0] p[i+1][1] ...]があまりを活用できそうな最良配置だが、
#P[i]のあまりがあったときのあまり1はどのように扱ってもP[i-1],P[i+1]に活用できることはないとわかる


N=int(input())
A=[int(input()) for _ in range(N)]
cnt=0
buf=0
#print(A)
"""
if N==1:
    print(A[0]//2)
else:
    for i in range(N-1):
        su=A[i]+A[i+1]
        cnt=cnt+su//2
        buf=(su//2)*2
        if buf>A[i]:
            A[i+1]=A[i+1]-(buf-A[i])
            A[i]=0
        else:
            A[i]=A[i]-buf
    #print(A,cnt)
    print(cnt)
"""
su=0
for i in range(N):
    if A[i]!=0:
        su=su+A[i]
    else:
        cnt=cnt+su//2
        su=0
cnt=cnt+su//2
print(cnt)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
cnt=0
buf=0
#print(A)
if N==1:
    print(A[0]//2)
else:
    for i in range(N-1):
        su=A[i]+A[i+1]
        cnt=cnt+su//2
        buf=(su//2)*2
        if buf>A[i]:
            A[i+1]=A[i+1]-(buf-A[i])
            A[i]=0
        else:
            A[i]=A[i]-buf
    #print(A,cnt)
    print(cnt)

Submission status: Accepted

Solution code:
n = int(input())
ans = 0
li = []
tmp = 0
for i in range(n):
    t = int(input())
    if t == 0:
        li.append(tmp)
        tmp = 0
    else:
        tmp += t
li.append(tmp)
for l in li:
    ans += l//2
#print(li)
print(ans)

Submission status: Accepted

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

ans = 0

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

Submission status: Accepted

Solution code:
n=int(input())

temp=0
cnt=0


for _ in range(n):
    a=int(input())
    hoge=min(a,temp)
    cnt+=hoge

    if a>hoge:
        cnt+=(a-hoge)//2
        temp=(a-hoge)-((a-hoge)//2)*2
    else:
        temp=0

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

N = int(sys.stdin.readline().rstrip())

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

pairs = 0
res = 0
for a_i in A:
    if a_i == 0:
        res = 0
        continue
    
    a_i += res
    r = a_i // 2
    pairs += r
    res = a_i - 2*r

print(pairs)

Submission status: Accepted

Solution code:
n = int(input())

total = 0

remain = 0
c = 0
for i in range(n):
    m = int(input())
    if i > c + 1:
        remain = 0
    all_ = remain + m
    total += all_//2
    if all_ % 2 != 0 and all_//2 > 0:
        remain = all_ % 2
        c = i
print(total)

Submission status: Accepted

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

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

print(cnt)