Problem:


Score : 300 points

Problem Statement

There are N boxes arranged in a row.
Initially, the i-th box from the left contains a_i candies.

Snuke can perform the following operation any number of times:

Choose a box containing at least one candy, and eat one of the candies in the chosen box.

His objective is as follows:

Any two neighboring boxes contain at most x candies in total.

Find the minimum number of operations required to achieve the objective.

Constraints

2 ≤ N ≤ 10^5

0 ≤ a_i ≤ 10^9

0 ≤ x ≤ 10^9

Input

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

N x
a_1 a_2 ... a_N

Output

Print the minimum number of operations required to achieve the objective.

Sample Input 1

3 3
2 2 2

Sample Output 1

1

Eat one candy in the second box.
Then, the number of candies in each box becomes (2, 1, 2).

Sample Input 2

6 1
1 6 1 2 0 4

Sample Output 2

11

For example, eat six candies in the second box, two in the fourth box, and three in the sixth box.
Then, the number of candies in each box becomes (1, 0, 1, 0, 0, 1).

Sample Input 3

5 9
3 1 4 1 5

Sample Output 3

0

The objective is already achieved without performing operations.

Sample Input 4

2 0
5 5

Sample Output 4

10

All the candies need to be eaten.



Sample input:
3 3
2 2 2


Sample output:
1

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 11 09:54:00 2019

@author: shinjisu
"""


# ARC 064 WA
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def dmp(x):
    global debug
    if debug:
        print(x)


def probC_try1():
    N, x = getIntList()
    a = getIntList()
    dmp((N, x, a))
    eatCnt = 0
    half = (x+1) // 2
    dmp((N,x,a,half))
    for i in range(N-1):
        if a[i]+a[i+1] > x:
            #eat = a[i]+a[i+1]-(min(a[i],half)+min(a[i+1],half))
            eat = a[i] - min(a[i],max(a[i+1]-half,half),half)
            eatCnt += eat
            a[i] = min(a[i],max(a[i+1]-half,half),half)
    eat = a[N-1] - min(a[N-1], half)
    eatCnt += eat
    a[N-1] = min(a[N-1],half)
    dmp((eatCnt,a))
    i=0
    while i<N:
        while i<N-1 and a[i]+a[i+1]<=x: i+=1
        cnt=1
        while i<N-1 and a[i]+a[i+1]>x: 
            i+=1; cnt+=1
        eatCnt += cnt//2
        dmp((cnt,eatCnt))
        i+=1
    return eatCnt


def probC():
    N, X = getIntList()
    a = getIntList()
    dmp((N, X, a))
    eatCnt = 0
    for i in range(N-1):
        dmp((eatCnt,a))
        if a[i] > X:
            eat = a[i] - X
            eatCnt += eat
            a[i] = X
        if a[i]+a[i+1] > X:
            eat = a[i]+a[i+1] - X
            eatCnt += eat
            if a[i+1] > X:
                #a[i] -= X-a[i+1]
                a[i+1] = 0
            else:
                a[i+1] -= X-a[i]
    dmp((eatCnt,a))
    return eatCnt


debug = False  # True False
print(probC())

Submission status: Wrong Answer

Solution code:
n,x=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(1,n):
    p=a[i-1]+a[i]
    c+=p-x
    a[i]=max(0,a[i]-p+x)
print(c)

Submission status: Wrong Answer

Solution code:
# ARC 064
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def db(x): 
    global debug
    if debug: print(x)
debug = False

N,x = getIntList()
a = getIntList()
eatCnt = 0
half = (x+1) // 2 
db((N,x,a,half))
for i in range(N-1):
    if a[i]+a[i+1]>x: 
        #eat = a[i]+a[i+1]-(min(a[i],half)+min(a[i+1],half))
        eat = a[i] - min(a[i],max(a[i+1]-x,0),half)
        eatCnt += eat
        a[i] = min(a[i],max(a[i+1]-x,0),half)
eat = a[N-1] - min(a[N-1],half)
eatCnt += eat
a[N-1] = min(a[N-1],half)
db((eatCnt,a))
i=0
while i<N:
    while i<N-1 and a[i]+a[i+1]<=x: i+=1
    cnt=1
    while i<N-1 and a[i]+a[i+1]>x: 
        i+=1; cnt+=1
    eatCnt += cnt//2
    db((cnt,eatCnt))
    i+=1
print(eatCnt)

Submission status: Wrong Answer

Solution code:
# ARC 064
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def db(x): 
    global debug
    if debug: print(x)
debug = False

N,x = getIntList()
a = getIntList()
eatCnt = 0
half = (x+1) // 2
db((N,x,a,half))
for i in range(N-1):
    if a[i]+a[i+1]>x: 
        eat = a[i]+a[i+1]-(min(a[i],half)+min(a[i+1],half))
        eatCnt += eat
        a[i] = min(a[i],half)
        a[i+1] = min(a[i+1],half)
db((eatCnt,a))
i=0
while i<N:
    while i<N-1 and a[i]+a[i+1]<=x: i+=1
    cnt=1
    while i<N-1 and a[i]+a[i+1]>x: 
        i+=1; cnt+=1
    eatCnt += cnt//2
    db((cnt,eatCnt))
    i+=1
print(eatCnt)

Submission status: Wrong Answer

Solution code:

n, x = map(int, input().split())
l = list(map(int, input().split()))
total = 0

for i in range(n - 1):
    diff = l[i] + l[i+1] - x
    if diff > x:
        total += diff
        if diff > l[i+1]:
            l[i+1]=0
        else:
            l[i+1] -= diff

print(total)

Submission status: Wrong Answer

Solution code:

n, x = map(int, input().split())
l = list(map(int, input().split()))
total = 0

for i in range(n - 1):
    sub = l[i] + l[i+1]
    if sub > x:
        total += sub - x
        l[i+1] -= sub - x
        if l[i+1] > x:
            l[i] -= l[i+1] - x
            total += l[i+1] - x




print(total)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
l = list(map(int, input().split()))
total = 0

for i in range(n - 1):
    sub = l[i] + l[i+1]
    if sub > x:
        total += sub - x
        l[i+1] -= sub - x




print(total)

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split())
l = list(map(int, input().split()))
total = 0

for i in range(n - 1):
    if l[i] + l[i + 1] > x:
        max_index = None
        if l[i] > l[i+1]:
            max_index = i
            o = i+1
        else:
            max_index = i+1
            o = i
        l[max_index] = x-l[o]
        total += x-l[o]

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
l = list(map(int, input().split()))

before = sum(l)
l[0] = min(x, l[0])
for i in range(1, N):
    s = l[i-1]+l[i]
    if s > x:
        l[i] = x-l[i-1]

print(l)
print(before-sum(l))

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
l = list(map(int, input().split()))

before = sum(l)
l[0] = min(x, l[0])
for i in range(1, N):
    s = l[i-1]+l[i]
    if s > x:
        l[i] = s-x

print(before-sum(l))

Submission status: Wrong Answer

Solution code:
n,x = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
copy = []
for num in a:
    copy.append(num)
    
for i in range(n-1):
    if i==0:
        if a[i]>x:
            a[i]=x
    else:
        if a[i]+a[i+1]>x:
            a[i+1] = x-a[i]

print(sum(copy)-sum(a))

Submission status: Wrong Answer

Solution code:
n,x = (int(i) for i in input().split())
a = list(int(i) for i in input().split())
copy = []
for num in a:
    copy.append(num)
    
for i in range(n-1):
    if i==0:
        if a[i]>x:
            a[i]=x
    else:
        if a[i]+a[i+1]>x:
            a[i+1] -= x-(a[i]+a[i+1])

print(sum(copy)-sum(a))

Submission status: Wrong Answer

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

ans = 0

for i in range(N - 1):
	if a[i] + a[i + 1] <= x:
		pass
	else:
		if a[i] <= x:
			ans += a[i] + a[i + 1] - x
			a[i + 1] = x - a[i]
		else:
			a[i] + a[i + 1] - x
			a[i + 1] = 0

print(ans)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        if a[i]<=x:
            b+=max(0,a[i+1]-x+a[i])
            a[i+1]=max(0,x-a[i])
        else:
            b+=a[i]-x+a[i+1]
            a[i+1]=0
            a[i]=x
            print(a,b)
b+=max(0,a[-2]+a[-1]-x)
print(b)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        if a[i]<=x:
            b+=max(0,a[i+1]-x+a[i])
            a[i+1]=max(0,x-a[i])
        else:
            b+=a[i]-x+a[i+1]
            a[i+1]=0
b+=max(0,a[-2]+a[-1]-x)
print(b)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
for i in range(N-1):
    if a[i]+a[i+1]>x:
        if a[i]<=x:
            b+=max(0,a[i+1]-x+a[i])
            a[i+1]=max(0,x-a[i])
        else:
            b+=a[i]-x+a[i+1]
            a[i+1]=0
    b+=max(0,a[-2]+a[-1]-x)
print(b)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
if N%2==1:
    for i in range(N//2):
        if max(a[2*i],a[2*(i+1)])-x<=0:
            b+=max(0,max(a[2*i],a[2*(i+1)])+a[2*i+1]-x)
        else:
            b+=max(0,min(a[2*i],x)+min(x,a[2*(i+1)])-a[2*i+1])
            a[2*(i+1)]=max(0,a[2*(i+1)]-x)
else:
    for i in range(N//2-1):
        if max(a[2*i],a[2*(i+1)])-x<=0:
            b+=max(0,max(a[2*i],a[2*(i+1)])+a[2*i+1]-x)
        else:
            b+=max(0,min(a[2*i],x)+min(x,a[2*(i+1)])-a[2*i+1])
            a[2*(i+1)]=max(0,a[2*(i+1)]-x)
    b+=max(0,a[-2]+a[-1]-x)
print(b)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
if N%2==1:
    for i in range(N//2):
        if max(a[2*i],a[2*(i+1)])-x<=0:
            b+=max(a[2*i],a[2*(i+1)])+a[2*i+1]-x
        else:
            b+=min(a[2*i],x)+min(x,a[2*(i+1)])-a[2*i+1]
            a[2*(i+1)]=max(0,a[2*(i+1)]-x)
else:
    for i in range(N//2-1):
        if max(a[2*i],a[2*(i+1)])-x<=0:
            b+=max(a[2*i],a[2*(i+1)])+a[2*i+1]-x
        else:
            b+=min(a[2*i],x)+min(x,a[2*(i+1)])-a[2*i+1]
            a[2*(i+1)]=max(0,a[2*(i+1)]-x)
    b+=max(0,a[-2]+a[-1]-x)
print(b)

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
a=list(map(int,input().split()))
b=0
if N%2==1:
    for i in range(N//2):
        b+=max(0,max(a[2*i],a[2*(i+1)])+a[2*i+1]-x)
else:
    for i in range(N//2-1):
        b+=max(0,max(a[2*i],a[2*(i+1)])+a[2*i+1]-x)
    b+=max(0,a[-2]+a[-1]-x)
print(b)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
A = list(map(int, input().split()))
n_eat = 0

if A[0] > x:
    n_eat += A[0]
    A[0] = x

for i in range(N-1):
    if A[i] + A[i+1] > x:
        dif = A[i] + A[i+1] - x
        A[i+1] -= min(dif, A[i+1])
        n_eat += dif

print(n_eat)

Submission status: Wrong Answer

Solution code:
# ARC64 Boxes and Candies
N, x = map(int, input().split())
A = list(map(int, input().split()))
n_eat = 0

if A[0] > x:
    n_eat += A[0]
    A[0] = x

for i in range(N-1):
    if A[i] + A[i+1] > x:
        dif = A[i] + A[i+1] - x
        A[i+1] -= dif
        n_eat += dif

print(n_eat)

Submission status: Wrong Answer

Solution code:
s=input();print(['Second','First'][(len(s)+(s[0]==s[-1]))%2])

Submission status: Wrong Answer

Solution code:
n, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
ans = 0
if a[0] > x:
    ans += a[0] - x
    a[0] = x
for i in range(1,len(a)):
    if a[i-1] + a[i] > x:
        ans += a[i-1] + a[i] - x
        a[i] = x - a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque
MOD = 10 ** 9 + 7


N, x = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

eat = 0
last_eat = 0
for i in range(1, N):

    a = A[i - 1] + A[i] - last_eat
    if a > x:
        last_eat = a - x
        if last_eat < 0:
            last_eat = a[i]
            eat += a - x - a[i]
        else:
            eat += last_eat
    else:
        last_eat = 0

print(eat)

sys.exit(0)

Submission status: Wrong Answer

Solution code:
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque
MOD = 10 ** 9 + 7


N, x = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

eat = 0
last_eat = 0
for i in range(1, N):

    a = A[i - 1] + A[i] - last_eat
    if a > x:
        last_eat = a - x
        if last_eat < 0:
            last_eat = a[i]
            eat += a - x - a[i]
        eat += last_eat
    else:
        last_eat = 0

print(eat)

sys.exit(0)

Submission status: Wrong Answer

Solution code:
import sys
import collections
import itertools
import math
from collections import Counter
from collections import deque
MOD = 10 ** 9 + 7


N, x = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

eat = 0
last_eat = 0
for i in range(1, N):
    a = A[i - 1] + A[i] - last_eat
    if a > x:
        last_eat = a - x
        eat += last_eat
    else:
        last_eat = 0

print(eat)

sys.exit(0)

Submission status: Wrong Answer

Solution code:
N,x =map(int, input().split())
candy = list(map(int, input().split()))
eat = 0

for i in range(N - 1):
    if(candy[i] + candy[i + 1] > x):
        eat += candy[i] + candy[i + 1] - x
        candy[i + 1] = x - candy[i]
print(eat)

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda:list(map(int,input().split(" ")))
N,x=miipt()
l1=miipt()
l2=l1[:]
a1=0
for i in range(0,N-1):
    d=l1[i]+l1[i+1]-x
    if d>0:
        a1+=d
        l1[i+1]-=d
a2=0
for i in reversed(range(0,N-1)):
    d=l2[i]+l2[i+1]-x
    if d>0:
        a2+=d
        l2[i]-=d
print(min(a1,a2))

Submission status: Wrong Answer

Solution code:
N,x=map(int,input().split())
A=list(map(int,input().split()))

ans=0
for i in range(1,N):
    if A[i-1]+A[i] > x:
        ans += A[i-1]+A[i]-x
        A[i] -= A[i-1]+A[i]-x
print(ans)

Submission status: Wrong Answer

Solution code:
iipt=lambda:int(input())
miipt=lambda:list(map(int,input().split(" ")))
N,x=miipt()
l=miipt()
ans=0
for i in range(0,N-1):
    d=l[i]+l[i+1]-x
    if d>0:
        ans+=d
        l[i+1]-=d
print(ans)

Submission status: Wrong Answer

Solution code:
n,x = map(int,input().split())
lis = list(map(int,input().split()))
cou = 0
for i in range(n-1):
  if lis[i+1] + lis[i] > x:
    cou += (lis[i+1] + lis[i] -x)
    lis[i+1] -= (lis[i+1] + lis[i] -x)
print(cou)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
line = input().split(" ")
n = int(line[0])
x = int(line[1])
a = [int(n) for n in input().split(" ")]

ret = max(0,a[0]-x)
a[0] = min(a[0],x)
for i in range(1,n):
    if a[i-1]+a[i]>x:
        r = (a[i-1]+a[i])-x
        if a[i]>=r:
            a[i] -= r
        else:
            a[i-1] -= (r-a[i])
            a[i] = 0
        ret += r

# print(ret)
print(a)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
line = input().split(" ")
n = int(line[0])
x = int(line[1])
a = [int(n) for n in input().split(" ")]
ret = 0

for i in range(n):
    if i%2==1 and i<n-1:
        if a[i]+a[i-1]>x:
            r = (a[i]+a[i-1])-x
            if a[i]>=r:
                a[i] -= r
            else:
                a[i-1] -= r-a[i]
                a[i] = 0
            ret += r
        if a[i]+a[i+1]>x:
            r = (a[i]+a[i+1])-x
            if a[i]>=r:
                a[i] -= r
            else:
                a[i+1] -= r-a[i]
                a[i] = 0
            ret += r
    if i==n-1:
        if a[i]+a[i-1]>x:
            r = (a[i]+a[i-1])-x
            if a[i]>=r:
                a[i] -= r
            else:
                a[i-1] -= r-a[i]
                a[i] = 0
            ret += r

print(ret)
# print(a)

Submission status: Wrong Answer

Solution code:
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()
    
    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

n = int(arr_data[0][0])
x = int(arr_data[0][1])

arr=[int(arr_data[1][x]) for x in range(0,n)]

cnt=0

for i in range(n-1):
    
    zan=arr[i]+arr[i+1]-x
     
    if 0<arr[i+1]<=zan:

        cnt+=arr[i+1]
        zan-=arr[i+1]
        arr[i+1]=0

    elif arr[i+1]>zan>0:

        cnt+=zan
        arr[i+1]-=zan
        zan=0

    if zan>0:

        zan-=arr[i]
        cnt+=arr[i]
        arr[i]=0

print(cnt)

Submission status: Wrong Answer

Solution code:
N,x=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
a.append(0)
r=[a[0]]
for i in range(N):
  r.append(a[i]+a[i+1])
sum=0
for i in r:
  sum+=max(i-x,0)
print(int(((sum/2)*2+1)/2))

Submission status: Wrong Answer

Solution code:
N,x=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
a.append(0)
r=[a[0]]
for i in range(N):
  r.append(a[i]+a[i+1])
sum=0
for i in r:
  sum+=max(i-x,0)
print(round(sum/2))

Submission status: Wrong Answer

Solution code:
N,x = map(int,input().split())

A = list(map(int,input().split()))
B = []
for j in range(N-1): B.append(A[j]+A[j+1])
    
ans = 0
for i in range(1,N):
    B0 = max(B[i-1]-x,0)
    B1 = max(B[i]-x,0) if i!=N-1 else max(B[i-1]-x,0)
    eat = min(max(B0,B1),A[i])
    B[i-1] -= eat
    if i!=N-1: B[i] -= eat
    ans += eat
    
ans += min(max(B[0]-x,0),A[0])
    
print(ans)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
total=sum(a)
if n%2==1:
    a.append(0)
for i in range(1,n,2):
    if k<=a[i-1]+a[i]:
        a[i]=k-a[i-1]
    if a[i]<0:
        v=abs(a[i])
        a[i]=0
        a[i-1]-=v
print(total-sum(a))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
total=sum(a)
if k<a[0]:
    a[0]=k
for i in range(n-1):
    if k<a[i]+a[i+1]:
        a[i+1]-=a[i]+a[i-1]-k
print(total-sum(a))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
total=sum(a)
if n%2==1:
    a.append(0)
for i in range(1,n,2):
    if k<=a[i-1]+a[i]:
        a[i]-=a[i-1]+a[i]-k
    if a[i]<0:
        v=abs(a[i])
        a[i]=0
        a[i-1]-=v
print(total-sum(a))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
total=sum(a)
if n%2==1:
    a.append(0)
for i in range(1,n,2):
    if k<=a[i-1]+a[i]:
        a[i]-=a[i-1]+a[i]-k
    if a[i]<0:
        v=abs(a[i])
        a[i-1]-=v
print(total-sum(a))

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import numpy as np
def readLine_int_list():return list(map(int, stdin.readline().split()))



def main():
    n, x = readLine_int_list()

    _a = readLine_int_list()
    a = _a.copy()
    
    for i in range(n-1):
        if a[i] + a[i+1] > x:
            
            if a[i] > x:
                a[i] = x
            
            if x - a[i] >= 0:
                if a[i] == 0:
                    a[i+1] = x
                elif a[i] > 0:
                    a[i+1] = 0
    print(np.sum(np.array(_a) - np.array(a)))
    
if __name__ == '__main__':\
    main()

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    tmp = (a[i] + a[i+1]) - x
    if tmp > 0:
        continue
    cnt += tmp
    a[i] -= tmp - a[i+1]
    a[i+1] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    tmp = (a[i] + a[i+1]) - x
    cnt += tmp
    a[i] -= tmp - a[i+1]
    a[i+1] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:

N, x = map(int, input().split())
a = list(map(int, input().split()))
# N, x = 6, 1
# a = [1, 6, 1, 2, 0, 4]
# N, x = 5, 9
# a = [3, 1, 4, 1, 5]
# N, x = 2, 0
# a = [5, 5]

cnt = 0
for i in range(1, N):
    if a[i-1] + a[i] > x:
        rem = a[i-1] + a[i] - x
        cnt += rem
        a[i - 1] -= rem - a[i]
        a[i] = 0
print(cnt)

Submission status: Wrong Answer

Solution code:

N, x = map(int, input().split())
a = list(map(int, input().split()))
# N, x = 6, 1
# a = [1, 6, 1, 2, 0, 4]
# N, x = 5, 9
# a = [3, 1, 4, 1, 5]
# N, x = 2, 0
# a = [5, 5]

cnt = 0
for i in range(1, N):
    if a[i-1] + a[i] > x:
        rem = a[i-1] + a[i] - x
        cnt += rem
        a[i - 1] -= rem - a[i]
        a[i] = 0
print(a)
print(cnt)

Submission status: Wrong Answer

Solution code:
y=raw_input()
t=0
if y[0]==y[len(y)-1]:
    t+=1
t+=len(y)
if t%2==0:
    print "Second"
else:
    print "First"

Submission status: Wrong Answer

Solution code:
S = input()
l = len(S)
print('First' if (l & 1) ^ (S[0] == S[-1]) else 'Second')

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = [a[i] + a[i + 1] for i in xrange(N - 1)]
ans = 0
for i in xrange((N - 1)/2):
    if b[i] > x:
	ans += b[i] - x
        b[i + 1] -= b[i] - x
        b[i] = x
    if b[-i - 1] > x:
        ans += b[-i - 1] - x
        b[-i - 2] -= b[-i - 1] - x
        b[-i - 1] = x
ans += max(0, max(b) - x)
print ans

Submission status: Wrong Answer

Solution code:
N, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = [a[i] + a[i + 1] for i in xrange(N - 1)] + [0]
ans = 0
for i in xrange(N - 1):
    if b[i] > x:
	ans += b[i] - x
        b[i + 1] -= b[i] - x
        b[i] = x
print ans

Submission status: Wrong Answer

Solution code:
# coding: utf-8
num_box, num_ans_candy = map(int, input().split())
l_box = list(map(int, input().split()))

eat_counter = 0
for index in range(num_box - 1):
    double_candy = l_box[index] + l_box[index + 1]
    if double_candy > num_ans_candy:
        num_eat_candy = double_candy - num_ans_candy
        l_box[index + 1] -= num_eat_candy
        eat_counter += num_eat_candy

print(eat_counter)

Submission status: Wrong Answer

Solution code:
def calc(A):
    B = A[1:]
    S = A[:-1] + B
    return S

N, x = map(lambda x:int(x), raw_input().split())
A = map(lambda x:int(x), raw_input().split())

result = 0
for i in range(len(A)-1):
    a0 = A[i]
    a1 = A[i+1]
    s = a0 + a1
    if s>=x:
        result += s - x
        A[i+1] = a1 - (s - x) 
    
print result

Submission status: Wrong Answer

Solution code:
import numpy as np

def calc(A):
    B = A[1:]
    S = A[:-1] + B
    return S

N, x = map(lambda x:int(x), raw_input().split())
A = np.array(map(lambda x:int(x), raw_input().split()))
"""
print 'A:', A
print 'S:', calc(A)
print 'T:', np.ones_like(calc(A))*x
print 'S-T:', calc(A) - np.ones_like(calc(A))*x
"""

result = 0
for i in range(len(A)-1):
    a0 = A[i]
    a1 = A[i+1]
    s = a0 + a1
    if s>x:
        result += s - x
        A[i+1] = a1 - (s - x) 
    
print result

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    N,x = list(map(int, input().split()))
    a=list(map(int, input().split()))

    result = 0


    for i in range(1,N):
        tot = a[i] + a[i-1]
        if tot>x:
            result += (tot - x)
            tmp = a[i]
            a[i] =  min(0, a[i]- tot +x)
            if a[i] == 0:
                a[i-1] = min(x,a[i-1])

    print(result)

Submission status: Wrong Answer

Solution code:
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
i=0
num=0

while i<n-1:
        if a[i] + a[i+1] > x:
                ans=a[i] + a[i+1] - x
                a[i+1]=a[i+1]-ans
                num=num+ans
        else:
                i=i+1

print num

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    delta = max(0, a[i] + a[i+1] - x)
    a[i+1] -= delta
    ans += delta
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
import numpy as np

a=[]

N, x = map(int, raw_input().split())
a = map(int, raw_input().split())

A=[]

for i in a:
    if i<x:
        A.append(i)
    else:
        A.append(x)

A1 = A[0:-1]
A2 = A[1:]

a =np.array(a)
A =np.array(A)
A1=np.array(A1)
A2=np.array(A2)

ADD=A1+A2
res = a-A
if x==0:
    print res.sum()+len(np.where(ADD==x)[0])-1
else:
    print res.sum()+len(np.where(ADD==x)[0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
import numpy as np

a=[]

N, x = map(int, raw_input().split())
a = map(int, raw_input().split())

A=[]

for i in a:
    if i<x:
        A.append(i)
    else:
        A.append(x)

A1 = A[0:-1]
A2 = A[1:]

a =np.array(a)
A =np.array(A)
A1=np.array(A1)
A2=np.array(A2)

ADD=A1+A2
res = a-A
print  res.sum()+len(np.where(ADD==x)[0])

Submission status: Wrong Answer

Solution code:
s=raw_input()
ans=chk=0
chk=len(s)
if s=='aba':
    print 'Second'
elif (chk%2==1 and (s[0]==s[-2] or s[1]==s[-1])):
    print 'Second'
elif (chk%2==1):
    print 'First'
else:
    print 'Second'

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import re
import math
import itertools
import collections
import bisect
#sys.stdin=file('input.txt')
#sys.stdout=file('output.txt','w')
#10**9+7
mod=1000000007
#mod=1777777777
pi=3.141592653589
IS=float('inf')
xy=[(1,0),(-1,0),(0,1),(0,-1)]
bs=[(-1,-1),(-1,1),(1,1),(1,-1)]
def niten(a,b): return abs(a-b) if a>=0 and b>=0 else  a+abs(b) if a>=0 else abs(a)+b if b>=0 else abs(abs(a)-abs(b))
def fib(n): return [(seq.append(seq[i-2] + seq[i-1]), seq[i-2])[1] for seq in [[0, 1]] for i in range(2, n)]
def gcd(a,b): return a if b==0 else gcd(b,a%b)
def lcm(a,b): return a*b/gcd(a,b)
def eucl(x1,y1,x2,y2): return ((x1-x2)**2+(y1-y2)**2)**0.5
def choco(xa,ya,xb,yb,xc,yc,xd,yd): return 1 if abs((yb-ya)*(yd-yc)+(xb-xa)*(xd-xc))<1.e-10 else 0
def pscl(num,l=[1]):
    for i in range(num):
        l = map(lambda x,y:x+y,[0]+l,l+[0])
    return l

s=raw_input()
ans=chk=0
chk=len(s)
if (chk%2==1):
    print 'First'
else:
    print 'Second'
#end = time.clock()
#print end - start

Submission status: Wrong Answer

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

res = 0
for i in range(len(a)-1):
    b = a[i]+a[i+1]
    if x < b:
        res += b-x
        a[i+1] -= max(b-x, a[i+1])

print(res)

Submission status: Wrong Answer

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

c = 0

b =[]
for i in xrange(n-1):
    b.append(a[i] + a[i+1])

# print b
for i in xrange(len(b)):
    if b[i] > x:
        d = b[i] - x
        if i+1 < len(b):
            b[i+1] -= d
        c += d
        
print c

Submission status: Wrong Answer

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

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

N, x = ln()
X = ln()

A = X[:]
result = 0
for i in xrange(1, N):
    if A[i] + A[i - 1] > x:
        diff = A[i] + A[i - 1] - x
        A[i] -= diff
        result += diff

A = X[::-1]
result2 = 0
for i in xrange(1, N):
    if A[i] + A[i - 1] > x:
        diff = A[i] + A[i - 1] - x
        A[i] -= diff
        result2 += diff


print min(result, result2)

Submission status: Wrong Answer

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

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

N, x = ln()
A = ln()

result = 0
for i in xrange(1, N):
    if A[i] + A[i - 1] > x:
        diff = A[i] + A[i - 1] - x
        A[i] -= diff
        result += diff

print result

Submission status: Time Limit Exceeded

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

a = list(map(int, input().split()))

ans = 0

for i in range(n - 1):
    while a[i] + a[i + 1] > x:
        a[i + 1] -= 1
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

a = list(map(int, input().split()))

before_sum = sum(a)

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

after_sum = sum(a)

print(before_sum - after_sum)

Submission status: Time Limit Exceeded

Solution code:
import sys

n, x=map(int, input().split())
A=list(map(int, input().split()))

ans=0
for i in range(n-1):
    while(A[i]+A[i+1]>x and A[i+1]>0):
        A[i+1]=A[i+1]-1
        ans=ans+1
    while(A[i]+A[i+1]>x and A[i]>0):
        A[i]=A[i]-1
        ans=ans+1
    if A[i]+A[i+1]>x:
        print(0)
        sys.exit()
print(ans)

Submission status: Time Limit Exceeded

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

s = [0] * (N-1)
for i in range(N-1):
    s[i] = a[i] + a[i+1]

ans = 0
for i in range(N-1):
    if i != N-2:
        while s[i] > x:
            s[i] -= 1
            s[i+1] -= 1
            ans += 1
    else:
        while s[i] > x:
            s[i] -= 1
            ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, x = map(int,input().split())
A = list(map(int,input().split()))

ans = 0
for i in range(0, N-1):
    a = A[i]
    b = A[i+1]
    while a + b > x:
        if b > 0:
            b -= 1
            ans += 1
        elif a > 0:
            a -= 1
            ans += 1
    A[i] = a
    A[i+1] = b

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
count = 0
for i in range(N):
    if ar[i] > M:
        count += ar[i] - M
        ar[i] = M
for i in range(N-1):
    if ar[i] + ar[i+1] > M:
        while ar[i] + ar[i+1] > M:
            if ar[i+1] == 0:
                ar[i] -= 1
                count += 1
            else:
                ar[i+1] -= 1
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
count = 0
for i in range(N-1):
    if ar[i] + ar[i+1] > M:
        while ar[i] + ar[i+1] > M:
            if ar[i+1] == 0:
                ar[i] -= 1
                count += 1
            else:
                ar[i+1] -= 1
                count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
i=0
num=0

while i<n-1:
        if a[i] + a[i+1] > x:
                a[i+1]=a[i+1]-1
                num=num+1
        else:
                i=i+1

print num

Submission status: Time Limit Exceeded

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

N, x = map(int, input().split())
C = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
    while C[i]+C[i+1] > x:
        cnt += 1
        C[i+1] -= 1
print(cnt)

Submission status: Accepted

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

cnt, a[0] = sum(a), min(a[0], x)
for i in range(1, n):
    if a[i - 1] + a[i] > x:
        a[i] = x - a[i - 1]
print(cnt - sum(a))