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 bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

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

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

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

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

#bisect macro
def index(a, x):
    #Locate the leftmost value exactly equal to x
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1

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

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

###########

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

print (sum(a)-p)/2

Submission status: Accepted

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


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

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

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

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

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

ans2 += A[0] // 2


print(max(ans, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def main():
    solve()


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect

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

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

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

EPS = 1e-9

#http://www.deqnotes.net/acmicpc/2d_geometry/lines
def dot(a, b):
    return a.real * b.real + a.imag * b.imag

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

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

N = n()

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

A.append(0)

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

print c

Submission status: Accepted

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
cnt = 0
for i in range(N):
    cnt += A[i]//2
    A[i] = A[i]%2
for i in range(1,N-1):
    if A[i-1]+A[i]==2:
        cnt += 1
        A[i]=0
print(cnt)

Submission status: Runtime Error

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

def return_ans(ls):
    ans = 0
    n = len(ls)
    if n > 1:
        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
    return ans

now_ls = []
ans = 0
for i in range(N):
    if ls[i] != 0:
        now_ls.append(ls[i])
    else:
        ans += return_ans(now_ls)
        now_ls = []
if now_ls:
    ans += return_ans(now_ls)

print(ans)

Submission status: Runtime Error

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

count = 0
m = -1
for i in range(n):
    if lis[i]%2 == 0:
        count += l[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: Runtime Error

Solution code:
from copy import copy
n=int(input())
a=[int(input()) for _ in range(n)]
b=copy(a)
ans1=0
for i in range(n-1):
  ans1+=min(a[i],a[i+1])
  k=max(a[i]-a[i+1],0)
  a[i+1]=max(a[i+1]-a[i],0)
  a[i]=k
for i in a:
  ans1+=i//2
ans2=0
for i in range(n-1,0,-1):
  ans2+=min(b[i],b[i-1])
  k=max(b[i]-b[i-1],0)
  b[i+1]=max(b[i-1]-b[i],0)
  b[i]=k
for i in b:
  ans2+=i//2
print(max(ans1,ans2))

Submission status: Runtime Error

Solution code:
def solve(n, a):
    res = 0
    for i in range(n-1):
        b = min(a[i], a[i+1])
        res += b
        a[i] -= b
        a[i+1] -= b
        if a[i] > 0:
            res += a[i] // 2
    if a[-1] > 0:
        res += a[i] // 2
    return res

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

Submission status: Runtime Error

Solution code:
N = int(input())
ls = []
for i in range(N):
  n = int(input())
  ls.extend([i+1]*n)
  
count = 0
prev = ls[0]
pair = False

for i in ls[1:]:
  if pair == True:
    pair = False
    prev = i
    continue
  if i - prev <= 1:
    count += 1
    pair = True
  prev = i
    
print(count)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

dp = [0] * n
for i in range(n):
    dp[i] = max(dp[i-1] + a[i]//2,dp[i-2] + min(a[i-1], a[i]))

print(dp[-1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<long long> a(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i];
  long long res = 0, cur_sum = 0;
  for (int i = 0; i < N;)
  {
    int j = i;
    while (j < N && a[j])
      cur_sum += a[j++];
    res += cur_sum / 2;
    cur_sum = 0;
    i = j + 1;
  }
  cout << res << endl;
}

Submission status: Runtime Error

Solution code:
n = int(input())
A = []
for _ in range(n):
  a = int(input())
  A.append(a)
if n == 1:
  cnt = A[0]//2
else:
  cnt = 0
  for i in range(n-1):
    m = min(A[i], A[i+1])
    cnt += m
    A[i] -= m
    A[i+1] -= m
    cnt += A[i]//2
  cnt += A[n]//2
  print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k,s=open(0);n,r=map(int,k.split());a=0
while n>0:
 n-=1
 if s[n]<"o":n-=~-r;a=-~max(a,n)
print(a)

Submission status: Runtime Error

Solution code:
N, *A = map(int, open('0').read().split())
ans = sum(c//2 for c in A)
A = [c%2 for c in A]
for i in range(N-2):
  if A[i]==A[i+1]==1:
    A[i+1] = 0
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = []
for i in range(N):
    A.append(int(input()))
    
B = A[:]
    
ans1 = 0

for j in range(N):
    ans1 += (A[j]//2)
    A[j] = (A[j]%2)
    
for k in range(1,N):
    ans1 += min(A[k-1],A[k])
    A[k] = A[k] - min(A[k-1],A[k])
    
ans2 = 0
tmp = min(B[0],B[1])

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

B[0] -= tmp

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

print(max(ans1,ans2))

Submission status: Runtime Error

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

mod = 10**9 + 7

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

N = ni()
A = list()
for _ in range(N):
    A.append(ni())
cnt = 0
if N==1:
    print(A[0]//2)
    quit()
for i in range(N-1):
    print(A)
    ccnt = (A[i] + A[i+1]) //2
    A[i+1] -= max(0, ccnt*2 - A[i])
    A[i] = max(0, A[i]-ccnt*2)
    cnt += ccnt
print(A)
print(cnt)

Submission status: Runtime Error

Solution code:
n = int(input())
c = []
for i in range(n):
  c += [i+1]*int(input())
cnt = 0
paired = False
for i in range(len(c)-1):
  if paired:
    paired = False
    continue
  if c[i+1] - c[i] <= 1 and not paired:
    cnt += 1
    paired = True
print(cnt)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

s=''
for i,x in enumerate(a):
  if x != 0:
    s += str(i+1)*x
  else:
    s += '*'
s += '*'

ans=0
cnt=0
for c in s:
  if c != '*':
    cnt += 1
  else:
    ans += cnt // 2
    cnt=0
  
    
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[0]*N
DP=[0]*N

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

DP[0]=A[0]//2
DP[1]=max(A[0]//2+A[1]//2,min(A[0],A[1]))

for i in range(2,N):
    DP[i]=max(DP[i-2]+A[i-1]//2+A[i]//2,DP[i-2]+min(A[i-1],A[i]))

print(DP[N-1])

Submission status: Runtime Error

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

if a.count(0)==0:
    print(sum(a//2))
else:
    tmp_sum=0
    ans=0
    for i in range(n):
        if a[i]==0:
            ans+=tmp_sum//2
            tmp_sum=0
        else:
            tmp_sum+=a[i]
    ans+=tmp_sum//2

    print(ans)

Submission status: Runtime Error

Solution code:
def main():

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

    # print(A)
    pairs = 0
    for i in range(N-1):
        pairs += A[i] // 2
        A[i] = A[i] % 2
        pairs += min(A[i], A[i+1])
        A[i], A[i+1] = A[i]-min(A[i], A[i+1]), A[i+1]-min(A[i], A[i+1])
    pairs += A[i+1] // 2

    return pairs

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

Submission status: Runtime Error

Solution code:
def main():

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

    # print(A)
    pairs = 0
    for i in range(N-1):
        pairs += min(A[i], A[i+1])
        A[i], A[i+1] = A[i]-min(A[i], A[i+1]), A[i+1]-min(A[i], A[i+1])
        pairs += A[i] // 2
    pairs += A[i+1] // 2

    return pairs

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

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    ans = 0
    changing = [a[0]]
    direct_flag = False #False > True <
    for i in range(1,n):
        if len(changing) == 1:
            changing.append(a[i])
            if changing[0] < changing[1]:
                direct_flag = True
        else:
            if direct_flag and changing[-1] < a[i]:
                changing.append(a[i])
            elif not direct_flag and changing[-1] > a[i]:
                changing.append(a[i])
            else:
                m = len(changing)
                iterange = (range(m) if direct_flag else range(m)[::-1])
                for j in iterange:
                    if j != 0:
                        makable = min(changing[j-1],changing[j])
                        ans += makable
                        changing[j-1] -= makable
                        changing[j] -= makable
                    if j != m-1:
                        makable = min(changing[j],changing[j+1])
                        ans += makable
                        changing[j] -= makable
                        changing[j+1] -= makable
                    if changing[j] >= 2:
                        makable = changing[j] // 2
                        ans += makable
                        changing[j] -= makable * 2
                changing = [a[i]]
                direct_flag = False
        if i == n-1:
            if len(changing) == 1:
                ans += changing[0] // 2
            else:
                iterange = (range(m) if direct_flag else range(m)[::-1])
                for j in iterange:
                    if j != 0:
                        makable = min(changing[j-1],changing[j])
                        ans += makable
                        changing[j-1] -= makable
                        changing[j] -= makable
                    if j != m-1:
                        makable = min(changing[j],changing[j+1])
                        ans += makable
                        changing[j] -= makable
                        changing[j+1] -= makable
                    if changing[j] >= 2:
                        makable = changing[j] // 2
                        ans += makable
                        changing[j] -= makable * 2
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# keyence2019C - Exam and Wizard
def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))
    dif = sorted(i - j for i, j in zip(A, B))
    ans, shortage = 0, 0
    for i in dif:
        if i < 0:
            ans += 1
            shortage += i
        else:
            break
    for i in dif[::-1]:
        if shortage >= 0:
            print(ans)
            return
        ans += 1
        shortage += i
    print(-1)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

for i in range(N):
  array += A[i] * [i+1]
array.sort()

for j in range(len(array)-1):
  if abs(array[j] - array[j+1]) <= 1:
    ans += 1
    array[j] = -1
    array[j+1] = -1

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
l=[0]
if n<200: print(l[100])
ans=chk=0
for i in range(n):
    a=int(input())
    ans+=(a+chk)//2
    if a>0:
         chk=(a+chk)%2
    else:
        chk=0
print(ans)

Submission status: Runtime Error

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

ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
  
n=0
idx.append(N)
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
for i in range(N):
  if A[i]==0:
    idx.append(i+1)
  
n=0
for iidx in idx:
  ans+=sum(A[n:iidx])//2
  n=iidx
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(input()) for _ in range(N)]
 
ans=0
#0,1,2のみにする
for i in range(N):
  a=A[i]
  if a>=2 and a%2==0:
    A[i]=2
    ans+=(a-2)//2
  elif a%2==1:
    A[i]=1
    ans+=(a-1)//2
  elif a==0:
    pass
  

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

ans+=len(list(filter(lambda x:x==2,A)))
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,x = map(int,input().split())
a = list(map(int,input().split()))

#p[i色のスライム][j回まで色を変えられる]=色変えのコストを含まない最小コスト
p = [[0]*n for i in range(n)]

#print(p)
for i in range(n):
  p[i][0]=a[i]
  for j in range(1,n):
    if i-j>=0:
      p[i][j]=min(a[i-j],p[i][j-1])
    elif i-j == -1:
      p[i][j]=min(a[n-1],p[i][j-1])
    else:  
      p[i][j]=min(a[n-(j-i)],p[i][j-1])
p = list(zip(*p))
ans = sum(p[0])
for i in range(1,n):
  ans = min(ans,sum(p[i])+x*i)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
a = int(input())
s = 0
p =[int(input()) for _ in range(a)]
p.append(0)
def cal(n,k,s):
    #print(n,k,s,p[n])
    if n== a:return s
    s +=p[n]//2
    c = p[n]%2
    if p[n+1] >=1 and k == 1:
        s +=1
        p[n+1] -=1
        return cal(n+1,c,s)
    else:return cal(n+1,c,s)
    
print(cal(0,0,0))

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
res=0
for i in range(n):
    l.append(int(input()))
    if i>0 and l[i]>0 and l[i-1]>0:
        m=min(l[i],l[i+1])
        res+=m
        l[i]-=m
        l[i+1]-=m
for i in range(n):
    res+=l[i]//2
print(res)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=[]
for i in range(1,n+1):
  a=int(input())
  l.extend([i]*a)

c=0
s=0
while s<len(l)-1:
  if l[s+1]-l[s]<=1:
    c+=1
    s+=2
  else:
    s+=1

print(c)

Submission status: Runtime Error

Solution code:
import sys

sys.stdin = open('b_1.txt', 'r')

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

for x in range(1, N, 1):
	if ((rest[x - 1] == 1) and (rest[x] == 1)):
		pairs += 1
		rest[x] = 0

print str(pairs)

Submission status: Runtime Error

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:
        pairs = a[i] // 2
        cnt += pairs
        a[i] -= (pairs * 2)

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

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

        else:
            i += 1

    else:
        i += 1

print(cnt)

Submission status: Runtime Error

Solution code:
#coding: cp932
#M=int(input())
i = [int(input())for s in range(M)]
i = list(i)
#print(i)
N = int(i[0])
ans=0
for s in range(N-1):
	if i[1+s]==0:
		continue
	cul= int((i[1+s]+i[2+s])/2)
	ans += cul
	if i[1+s]>i[2+s]:
		amari = (i[1+s]+i[2+s])%2
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import math
from functools import reduce
if __name__ == '__main__':
    n = int(input())
    a = []
    ans = 0
    for i in range(n):
        tmp = int(input())
        a.append(tmp)
        if tmp == 0:
            ans += math.floor(reduce(lambda x, y: x + y, a) // 2)
            a.clear()
    ans += math.floor(reduce(lambda x, y: x + y, a) // 2)
    print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

int N;
int A[100005];

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> N;
  ll ans = 0;
  rep(i, N) cin >> A[i];

  rep(i, N) {
    if (A[i]%2 && A[i + 1] > 0) {
      ans += 1;
      A[i] -= 1; 
      A[i + 1] -= 1;
    }
  }
  rep(i, N) {
    ans += A[i]/2;
    A[i] %= 2;
  }
  rep(i, N) {
    ll mn = min(A[i], A[i + 1]);
    ans += mn;
    A[i] -= mn;
    A[i + 1] -= mn;
  }

  cout << ans << endl;

  return 0;
}

Submission status: Runtime Error

Solution code:
N = int(raw_input())
A = [0] * 1000000100
# A = [0] * 10
for i in xrange(N):
	A[i] = int(raw_input())

tmp = A[0]
sum_v = 0
sum_v += (tmp/2)
tmp = (A[0]%2)
min_v = 0

for i in xrange(1,N):
	if ((tmp/2) > 0):
		sum_v += (tmp/2)
		tmp = (tmp%2)
	if (A[i] > 0 and tmp > 0):
		min_v = min(A[i],tmp)
		sum_v += min_v
		if (min_v == A[i]):
			A[i] = 0
		else:
			A[i] = A[i] - tmp
	tmp = A[i]
sum_v += (A[N-1] / 2)
print sum_v