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:
import math
n = int(input())

cards = [0] * n

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

ans = 0


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

print(ans)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(K)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

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

    print(ans)

    
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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):
  ans+=a[i]//2
  a[i]=a[i]%2
  if a[i]==1 and a[i+1]>=1:
    ans+=1
    a[i]-=1
    a[i+1]-=1
ans+=a[n-1]//2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

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

ans = 0
#print(ans,A_list)  

#まず奇数を両端のどちらかに奇数があれば、それで打ち消す
if N > 1:
    if A_list[0]%2 == 1:
        if A_list[1] > 0:
            ans += 1
            A_list[0] -= 1
            A_list[1] -= 1

    #print(ans,A_list)  

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

        #print(ans,A_list)  
            
    if N >= 2:
        if A_list[N-1]%2 == 1:
            if A_list[N-2] > 0:
                ans += 1
                A_list[N-1] -= 1
                A_list[N-2] -= 1

    #print(ans,A_list)

#残ったのを自分同士で消す
for i in range(N):
    ans += A_list[i]//2
    A_list[i] = A_list[i]%2
    #print(ans,A_list)  
    
print(ans)
#print(A_list)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/agc003/tasks/agc003_b
# 各数字について、その数字の１つ前とその数字だけでできるだけ作る。
# その数字だけでペアをできるだけ作る。
# 1については、0のカードが0枚なので、実質無視できる。
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
    num = int(input())
    d[i + 1] = num

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

Submission status: Accepted

Solution code:
import sys

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


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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

    # 奇数個の山同士を相殺して偶数個の山にした後同数字ペアを作る
    # 奇数個の山の間に0個の山が無ければ全て取れる
    # 言い換えれば0個の山の間は0,1個残しで取り切れる
    A_cum = [0] * (N + 1)
    zero = [0]
    for i in range(N):
        A_cum[i+1] = A_cum[i] + A[i]
        if A[i] == 0:
            zero.append(i)
    zero.append(N)

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

    print(ans)

if __name__ == '__main__':
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cnt += tmp//2

print(cnt)

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def renritsu(A, Y):
    # example 2x + y = 3, x + 3y = 4
    # A = [[2,1], [1,3]])
    # Y = [[3],[4]] または [3,4]
    A = np.matrix(A)
    Y = np.matrix(Y)
    Y = np.reshape(Y, (-1, 1))
    X = np.linalg.solve(A, Y)

    # [1.0, 1.0]
    return X.flatten().tolist()[0]

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        # self.init_cost()

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

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

    def pos(self, x, y):
        # 壁も含めて0-indexed 元々の座標だけ考えると1-indexed
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])
    def showsome(self, tgt):
        for t in tgt:
            print(t)
        return
    def showsomejoin(self, tgt):
        for t in tgt:
            print("".join(t))
        return

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
        # for i in range(1, self.h+1):
        #     for j in range(1, self.w+1):
        #         cx, cy = j, i
        #         for dx, dy in move_eight:
        #             nx, ny = dx + cx, dy + cy


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

        am.append(num)
    prev = 0

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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


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


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


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

Submission status: Accepted

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)
#print(points)
#for i in range(len(points)-1):
z=0
while z<len(points)-1:
    x=points[z]
    y=points[z+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:
        z+=1
        ans+=1
    z+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

#############
# Main Code #
#############

N = getN()
A = getArray(N)

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

    # 二つから
    u = min(A[i], A[i + 1])
    cnt += u
    A[i] -= u
    A[i + 1] -= u

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import copy
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


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


def main():
    # sys.setrecursionlimit(1000000)
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = [0]*n
for i in range(n):
    a[i] = INT()

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

Submission status: Accepted

Solution code:
def solve(n, a):
    res, total = 0, 0
    for x in a:
        if x == 0:
            res += total // 2
            total = 0
        else:
            total += x
    return res + total // 2

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

Submission status: Accepted

Solution code:
from collections import Counter
n = int(input())
count=0
res = 0
for _ in range(n):
  a = int(input())
  if res < a:
    tmp = (a-res)%2
    count += res+(a-tmp-res)//2
    res = tmp
  else:
    count += a
    res = 0
    
print(count)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    if N == 1:
        ans = A[0] // 2
    else:
        ans = 0
        for i in range(N - 1):
            if A[i + 1] == 0:
                ans += A[i] // 2
            else:
                q, r = divmod(A[i] + A[i + 1], 2)
                ans += q
                A[i + 1] = r

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())
ans = 0
t = 0
for i in range(n):
    a = int(sys.stdin.readline())
    if a==0:
        ans += t//2
        t = 0
    else:
        t += a
if t>0: ans += t//2
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,*aa = map(int, open(0).read().split())

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
temp = 0
ans = 0
for i in range(n):
    a = int(input())
    if a != 0:
        q, r = divmod(a+temp, 2)
        ans += q
        temp = r
    else:
        temp = 0
print(ans)

Submission status: Accepted

Solution code:
def main():
  n = int(input())
  bef = 0
  ans = 0
  for i in range(n):
    now = int(input())
    ans += min(bef, now)
    now -= min(bef, now)
    ans += now//2
    bef = now % 2
  print(ans)
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    if N == 1:
        ans = A[0] // 2
    else:
        ans = 0
        for i in range(N - 1):
            if A[i + 1] == 0:
                ans += A[i] // 2
            else:
                s = A[i] + A[i + 1]
                q, r = divmod(s, 2)
                ans += q
                A[i + 1] = r

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(int(input()) for _ in range(n))
ans = 0
for i in range(n):
    tmp = A[i]
    ans += (tmp//2)
    if i < n-1 and tmp %2 and A[i+1] > 0:
        ans += 1
        A[i+1] -= 1
print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')


def solve():
    # n, m = [int(x) for x in input().split()]
    # n, m = [int(x) for x in input().split()]
    n = int(input())
    a = []
    for i in range(n):
        a.append(int(input()))
    ans = 0
    
    x = 0
    for e in a:
        if e:
            x += e
        else:
            ans += x // 2
            x = 0
    ans += x // 2
    print(ans)




t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

"""

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ans = A[0] // 2
    s = A[0] % 2
    for a in A[1:]:
        diff_p = min(s, a)
        self_p = (a - diff_p) // 2
        ans += diff_p + self_p
        s = a - diff_p - 2 * self_p
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

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

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

for a in A:
	ans += a//2

print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

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

ans = 0
cnt = 0
for x in A:
	if x != 0:
		cnt += x
	else:
		ans += cnt//2
		cnt = 0
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-1):
    p,r = divmod(A[i], 2)
    A[i] = r
    ans += p
    if A[i]*A[i+1]:
        A[i+1] -= 1
        ans += 1
print(ans+A[-1]//2)

Submission status: Accepted

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

cnt = 0
acc = 0
for a in A:
    if a != 0:
        acc += a
    else:
        cnt += acc // 2
        acc = 0
cnt += acc // 2

print(cnt)

Submission status: Accepted

Solution code:
N = int(input())

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

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):
    p,r = divmod(a[i],2)
    ans += p
    if a[i+1]: a[i+1] += r
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    N = in_n()
    A = list(in_na())

    if N == 1:
        print(A[0] // 2)
        exit()

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

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

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans, tmp = 0, 0
for ai in a:
    ans += (ai + tmp) // 2
    tmp = (ai + tmp) % 2
    if ai == 0:
        tmp = 0
print(ans)