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-----
3 3
2 2 2

-----Sample Output-----
1

Eat one candy in the second box.
Then, the number of candies in each box becomes (2, 1, 2).
[{"code": "N, x = [int(n) for n in input().split(\" \")]\nA = [int(a) for a in input().split(\" \")]\n\ncnt = 0\nif A[0] > x:\n  cnt += A[0] - x\n  A[0] = x\n\nfor i in range(1, len(A)):\n  if A[i] + A[i - 1] > x:\n    cnt += A[i] + A[i - 1] - x\n    A[i] = x - A[i - 1]\n\nprint(cnt)", "passed": true, "time": 0.15, "memory": 14324.0, "status": "done"}, {"code": "N,X=map(int,input().split())\n*A,=map(int,input().split())\n\nB=[0]*N\nfor i in range(N):\n    B[i] = A[i] if A[i]<=X else X\n\ncnt=sum(A)-sum(B)    \nfor i in range(N-1):\n    if X < B[i]+B[i+1]:\n        d=B[i]+B[i+1]-X\n        B[i+1]-=d\n        cnt+=d\nprint(cnt)", "passed": true, "time": 1.64, "memory": 14212.0, "status": "done"}, {"code": "#coding: utf-8\n\nN, X = (int(x) for x in input().split())\nA = [int(x) for x in input().split()]\n\nret = 0\nfor i in range(N-1):\n    if A[i] + A[i+1] > X:\n        tmp = A[i] + A[i+1] - X\n        ret += tmp\n        A[i+1] -= min(A[i+1], tmp)\n\n\nprint(ret)\n\n", "passed": true, "time": 0.2, "memory": 14320.0, "status": "done"}, {"code": "import bisect, collections, copy, heapq, itertools, math, string, sys\ninput = lambda: sys.stdin.readline().rstrip() \nsys.setrecursionlimit(10**7)\nINF = float('inf')\ndef I(): return int(input())\ndef F(): return float(input())\ndef SS(): return input()\ndef LI(): return [int(x) for x in input().split()]\ndef LI_(): return [int(x)-1 for x in input().split()]\ndef LF(): return [float(x) for x in input().split()]\ndef LSS(): return input().split()\n\ndef resolve():\n    N, x = LI()\n    a = LI()\n\n    # \u96a3\u308a\u5408\u30462\u3064\u306e\u548c\n    s = [a[i] + a[i+1] for i in range(N - 1)]\n    # \u96a3\u308a\u5408\u30462\u3064\u306e\u548c\u3092x\u4ee5\u4e0b\u306b\u3057\u305f\u3082\u306e\n    s_after = [min(i, x) for i in s]\n\n    # \u96a3\u308a\u5408\u30462\u3064\u306e\u548c\u3092x\u4ee5\u4e0b\u306b\u3057\u305f\u3082\u306e\u304b\u3089\u5143\u306e\u6570\u5217\u3092\u5fa9\u5143\n    a_after = [0] * N\n    a_after[0] = min(a[0], s_after[0])\n    for i in range(N - 1):\n        a_after[i+1] = min(s_after[i] - a_after[i], a[i+1])\n\n    ans = sum(a) - sum(a_after)\n    print(ans)\n\ndef __starting_point():\n    resolve()\n\n__starting_point()", "passed": true, "time": 0.16, "memory": 14276.0, "status": "done"}, {"code": "N,X=(int(T) for T in input().split())\nA=list(map(int,input().split()))\nans=0\nfor i in range(0,N-1):\n    if A[i]+A[i+1]>X:\n        s=A[i]+A[i+1]-X\n        ans=s+ans\n        A[i]=A[i]-max(0,A[i]-A[i+1])\n        A[i+1]=max(0,A[i+1]-s)\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14276.0, "status": "done"}, {"code": "import sys\n\nN, X = map(int, input().split())\nA = list(map(int, sys.stdin.readline().rsplit()))\nB = A[::]\n\nfor i in range(N - 1):\n    a = A[i] + A[i + 1]\n    if a > X:\n        if A[i + 1] >= a - X:\n            A[i + 1] -= a - X\n        else:\n            A[i] -= a - X - A[i + 1]\n            A[i + 1] = 0\n\nres = 0\nfor i in range(N):\n    res += B[i] - A[i]\n\nprint(res)", "passed": true, "time": 0.15, "memory": 14152.0, "status": "done"}, {"code": "N,X = (int(T) for T in input().split())\nA = [int(T) for T in input().split()]\nEat = 0\nfor AN in range(0,N-1):\n    if A[AN]+A[AN+1]>X:\n        Need = A[AN]+A[AN+1]-X\n        if A[AN+1]>=Need:\n            A[AN+1] -= Need\n        else:\n            A[AN] -= Need-A[AN+1]\n            A[AN+1] = 0\n        Eat += Need\nprint(Eat)", "passed": true, "time": 0.28, "memory": 14272.0, "status": "done"}, {"code": "def candy():\n    boxNum, x = [int(i) for i in input().split()]\n    ain = input()\n    alist = ain.split(' ')\n\n    s = 0\n    \n    for i in range(0, boxNum-1):\n        if int(alist[i+1]) + int(alist[i]) > x:\n            s = s + (int(alist[i+1]) + int(alist[i]) - x)\n            alist[i+1] = x - int(alist[i])\n            if int(alist[i+1]) < 0:\n                alist[i] = int(alist[i]) + int(alist[i+1])\n                alist[i+1] = 0\n        \n    print(s)\n    \ncandy()", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "n, x = map(int, input().split())\na = list(map(int, input().split()))\ncount = 0\nfor i in range(n-1):\n    if a[i] + a[i+1] > x:\n        y = a[i] + a[i+1] - x\n        count += y\n        a[i+1] = max(0, a[i+1]-y)\nprint(count)", "passed": true, "time": 0.16, "memory": 14292.0, "status": "done"}, {"code": "N, x = map(int,input().split())\na = list(map(int, input().split()))\n\nans = 0\n\nfor i in range(N-1):\n    if a[i] + a[i+1] > x:\n        temp = a[i] + a[i+1] - x \n        if a[i+1] - temp >= 0:\n            ans += temp\n            a[i+1] -= temp\n        else:\n            ans += temp\n            a[i+1] = 0\n            a[i] -= temp - a[i+1]\n     \nprint(ans)", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = [int(y) for y in input().split()]\nans = 0\nfor i in range(1, n):\n    d = a[i-1] + a[i]\n    if d <= x: continue\n    a[i] -= min(a[i], d - x)\n    a[i-1] -= max(d - x - a[i], 0)\n    ans += d - x\nprint(ans)\n", "passed": true, "time": 0.2, "memory": 14200.0, "status": "done"}, {"code": "N,x=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n    tmp=a[i-1]+a[i]\n    if tmp>x:\n        ans+=tmp-x\n        if a[i]>=tmp-x:\n            a[i]-=tmp-x\n        else:\n            a[i]=0\nprint(ans)", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "n, x = map(int, input().split())\narr = list(map(int, input().split()))\nsum_arr = sum(arr)\narr[0] = min(x, arr[0])\n\n\nfor i in range(n-1):\n    diff = arr[i] + arr[i+1]\n    if diff > x:\n        arr[i+1] -= diff - x\n\nprint(sum_arr - sum(arr))", "passed": true, "time": 0.2, "memory": 14124.0, "status": "done"}, {"code": "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nfor i, a in enumerate(A):\n  if i == 0:\n    ans += min(a, x)\n    now_x = x - min(a, x)\n    continue\n    \n  ans += min(a, now_x)\n  now_x = x - min(a, now_x)\n\nans2 = 0\nfor i, a in enumerate(A[::-1]):\n  if i == 0:\n    ans2 += min(a, x)\n    now_x = x - min(a, x)\n    continue\n    \n  ans2 += min(a, now_x)\n  now_x = x - min(a, now_x)\n\nprint(sum(A) - max(ans, ans2))", "passed": true, "time": 0.14, "memory": 14148.0, "status": "done"}, {"code": "N,X=map(int,input().split())\n*A,=map(int,input().split())\n\nB=[a if a<=X else X for a in A]\nc=sum(A)-sum(B)\nfor i in range(N-1):\n t=B[i]+B[i+1]\n if X < t:\n    d=t-X\n    B[i+1]-=d\n    c+=d\nprint(c)", "passed": true, "time": 0.2, "memory": 14096.0, "status": "done"}, {"code": "N,x=map(int,input().split())\na=list(map(int,input().split()))\n \nans=0\nfor i in range(1,N):\n    tmp=a[i-1]+a[i]\n    if tmp>x:\n        ans+=tmp-x\n        if a[i]>=tmp-x:\n            a[i]-=tmp-x\n        else:\n            a[i]=0\n    else:\n        continue\nprint(ans)", "passed": true, "time": 0.14, "memory": 14084.0, "status": "done"}, {"code": "N, x = map(int, input().split())\na = list(map(int, input().split()))\n\nans = 0\nfor i in range(N-1):\n  n = a[i]+a[i+1]\n  if n > x:\n    ans += n-x\n    if n-x > a[i+1]:\n      a[i], a[i+1] = a[i]-(n-x-a[i+1]), 0\n    else:\n      a[i+1] -= (n-x)\nprint(ans)", "passed": true, "time": 0.25, "memory": 14220.0, "status": "done"}, {"code": "N,x = map(int,input().split())\nls = list(map(int,input().split()))\nans = 0\nfor i in range(N-1):\n    if ls[i]+ls[i+1] <= x:\n        continue\n    else:\n        eat = - x + ls[i] + ls[i+1]\n        ls[i+1] -= eat\n        if ls[i+1] < 0:\n            ls[i+1] = 0\n        ans += eat\nprint(ans)", "passed": true, "time": 0.14, "memory": 14072.0, "status": "done"}, {"code": "N, x = map(int, input().split())\na = list(map(int, input().split()))\n\ny = min(a[0], x)\nans = a[0]-y\nfor i in range(1, N):\n    z = a[i]\n    w = max(y+z-x, 0)\n    y = z-w\n    ans += w\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14292.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\nA = tuple(map(int, input().split()))\npre = max(0, A[0] - x)\nans = pre\n\nfor i in range(n - 1):\n    a = A[i]\n    b = A[i + 1]\n    a -= pre\n    tmp = 0\n    if b > x:\n        tmp += b - x\n        b = x\n\n    if a + b > x:\n        tmp += a + b - x\n    ans += tmp\n    pre = tmp\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14176.0, "status": "done"}, {"code": "N, x = map(int, input().split())\nvalues = map(int, input().split())\ncount = 0\nv1 = next(values)\nfor v2 in values:\n    surplus = max(v1 + v2 - x, 0)\n    count += surplus\n    v1 = max(0, v2 - surplus)\nprint(count)", "passed": true, "time": 0.16, "memory": 14224.0, "status": "done"}, {"code": "N,x=map(int,input().split())\na=list(map(int,input().split()))\n\nans=0\nfor i in range(1,N):\n    tmp=a[i-1]+a[i]\n    if tmp>x:\n        ans+=tmp-x\n        if a[i]>=tmp-x:\n            a[i]-=tmp-x\n        else:\n            a[i]=0\n    else:\n        continue\nprint(ans)", "passed": true, "time": 0.21, "memory": 14176.0, "status": "done"}, {"code": "N, x = map(int, input().split())\na = list(map(int, input().split()))\nresult = 0\nif a[0] > x:\n    result += a[0] - x\n    a[0] = x\nfor i in range(N-1):\n    if a[i] + a[i+1] > x:\n        result += a[i] + a[i+1] - x\n        a[i+1] = x - a[i]\nprint(result)", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nsum_val = A[0] + A[1]\nif A[0] + A[1] > x:\n    if A[1] >= sum_val - x:\n        ans += sum_val - x\n        A[1] -= sum_val - x\n    else:\n        ans += A[1] + (A[0] - x)\n        A[0] -= (x - A[1])\n        A[1] = 0\n# print(A)\n# print(ans)\n\nfor i in range(1, N - 1):\n    sum_val = A[i] + A[i + 1]\n    if sum_val <= x:\n        continue\n    ans += sum_val - x\n    A[i + 1] -= sum_val - x\n# print(A)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "n, x = map(int, input().split())\na = list(map(int, input().split()))\nk = 0\ncnt = 0\n\nif a[1] + a[0] > x and x >= a[0] :\n    k = x - a[0]\n    cnt += a[1] + a[0] - x\n\nelif a[1] + a[0] > x and x < a[0] :\n    k = 0\n    cnt += a[1] + a[0] - x\n\nelse :\n    k = a[1]\n\nfor i in range(1, n - 1) :\n    if k + a[i + 1] <= x :\n        k = a[i + 1]     \n\n    elif x >= k :\n        cnt += k + a[i + 1] - x\n        k = x - k\n\n    else :\n        cnt += k + a[i + 1] - x\n        k = 0\n    \n\nprint(cnt)", "passed": true, "time": 0.14, "memory": 14216.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ncnt = max(0, a[0] - x)\na[0] -= cnt\nfor i in range(1, n):\n    cnt_now = max(0, a[i-1] + a[i] - x)\n    a[i] -= cnt_now\n    cnt += cnt_now\n\nprint(cnt)\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n,x = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(n-1):\n    if a[i] <= x:\n        if a[i]+a[i+1] <= x: continue\n        else:\n            ans += (a[i]+a[i+1])-x\n            a[i+1] -= (a[i]+a[i+1])-x\n    else:\n        ans += a[i]-x + a[i+1]\n        a[i], a[i+1] = x, 0\nif a[-1] > x: ans += a[-1]-x\nprint(ans)", "passed": true, "time": 0.14, "memory": 14276.0, "status": "done"}, {"code": "N,x = map(int,input().split())\na = list(map(int,input().split()))\ncnt = 0\nfor i in range(N-1):\n    if(a[i] > x):\n        cnt += a[i] - x\n        a[i] = x\n    \n    if(a[i] + a[i+1] > x):\n        cnt += a[i] + a[i+1] - x\n        a[i+1] = x - a[i]\n    \nprint(cnt)", "passed": true, "time": 0.14, "memory": 14060.0, "status": "done"}, {"code": "N, x = [int(x) for x in input().split()]\na = list([int(x) for x in input().split()])\n\ncount = 0\nfor i in range(N):\n    if a[i] > x:\n        count += a[i] - x\n        a[i] -= a[i] - x\n\n    if i - 1 >= 0:\n        if a[i] + a[i-1] > x:\n            count += (a[i] + a[i-1]) - x\n            a[i] -= (a[i] + a[i-1]) - x\n\nprint(count)\n", "passed": true, "time": 0.14, "memory": 14136.0, "status": "done"}, {"code": "N, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nans = 0\nkeep = a[0]\nfor i in range(1, N):\n    if (keep + a[i]) > x:\n        ans = ans + (keep + a[i] - x)\n        keep = max(x - keep, 0)\n    else:\n        keep = a[i]\n\n\nprint(ans)\n", "passed": true, "time": 0.15, "memory": 14336.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\nb = []\nfor i in range(1, n):\n    b.append(a[i] + a[i - 1])\nb.append(0)\n\nres = 0\nfor i in range(n - 1):\n    dif = max(b[i] - x, 0)\n    minus = min(dif, a[i + 1])\n    b[i + 1] -= minus\n    b[i] -= dif\n    res += dif\n\nprint(res)\n", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n,x=[int(i) for i in input().split()]\na=[int(i) for i in input().split()]\n\nadd_a=[]\nfor i in range(n-1):\n    add_a.append(max(a[i]+a[i+1]-x,0))\n\nans=0\nfor i in range(n-1):\n    ans+=min(add_a[i],a[i+1])\n    if i!=n-2:\n        add_a[i+1]=max(0,add_a[i+1]-min(add_a[i],a[i+1]))\n    add_a[i]-=min(add_a[i],a[i+1])\nans+=add_a[0]\n\nprint(ans)", "passed": true, "time": 0.23, "memory": 14292.0, "status": "done"}, {"code": "def boxes():\n    N, x = input().split()\n    N, x = int(N), int(x)\n    arr = [int(a) for a in input().split()]\n\n    total = 0\n    for i in range(1, N):\n        a, b = arr[i-1], arr[i]\n        extra = a + b - x\n        if extra > 0:\n            total += extra\n            if b >= extra:\n                arr[i] -= extra\n            else:\n                arr[i] = 0\n    print(total)\nboxes()", "passed": true, "time": 0.16, "memory": 14064.0, "status": "done"}, {"code": "N, x = map(int, input().split())\na = list(map(int, input().split()))\n\nr1 = sum(a)\nflow = 0\n\nfor i in range(1, N):\n    t = (a[i] + a[i - 1]) - x\n    if flow != 0:\n        a[i-1] -= flow\n        t -= flow\n        flow = 0\n\n    if t > 0:\n        if t > a[i]:\n            t -= a[i]\n            a[i - 1] -= t\n            t = a[i]\n\n        flow = t\n\na[-1] -= flow\n\nr2 = sum(a)\n\nprint(r1 - r2)", "passed": true, "time": 0.24, "memory": 14176.0, "status": "done"}, {"code": "n, x = map(int, input().split())\nA = list(map(int, input().split()))\n\nans = 0\nfor i in range(n - 1):\n    if A[i] + A[i + 1] > x:\n        ans += A[i] + A[i + 1] - x\n        A[i + 1] = max(x - A[i], 0)\nprint(ans)", "passed": true, "time": 0.16, "memory": 14112.0, "status": "done"}, {"code": "N,x = map(int,input().split())\na = list(map(int, input().split()))\nans=0\nwa=a[0]+a[1]\nif wa>x:\n    ans=wa-x\n    if a[1]<ans:\n        a[1]=0\n    else:\n        a[1]-=ans\nfor i in range(1,N-1):\n    wa=a[i]+a[i+1]\n    if wa>x:\n        ans+=wa-x\n        a[i+1]-=(wa-x)\nprint(ans)", "passed": true, "time": 0.25, "memory": 14116.0, "status": "done"}, {"code": "def solve():\n  ans = 0\n  N, x = map(int, input().split())\n  A = list(map(int, input().split()))\n  if A[0]>x:\n    ans += A[0]-x\n    A[0] = x\n  for i in range(1,N):\n    if A[i]+A[i-1]>x:\n      ans += A[i]+A[i-1]-x\n      A[i] = x-A[i-1]\n  return ans\nprint(solve())", "passed": true, "time": 0.16, "memory": 14080.0, "status": "done"}, {"code": "n, x = map(int, input().split())\na = [int(_) for _ in input().split()]\nans = max(0, a[0]-x)\na[0] -= ans\nfor i in range(n-1):\n    if a[i] + a[i+1] > x:\n        val = a[i] + a[i+1] - x\n        a[i+1] -= val\n        ans += val\nprint(ans)", "passed": true, "time": 0.16, "memory": 14140.0, "status": "done"}, {"code": "N, M = map(int, input().split())\nL = list(map(int, input().split()))\n\ncount = 0\n\nif L[0] > M:\n\tcount+= (L[0]-M)\n\tL[0]-= (L[0]-M)\n\nfor i in range (1, N):\n\tif L[i]+L[i-1] > M:\n\t\tcount+= (L[i]+L[i-1])-M\n\t\tL[i]-= (L[i]+L[i-1])-M\n    \nprint(count)", "passed": true, "time": 0.23, "memory": 14296.0, "status": "done"}, {"code": "from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf\nfrom itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement\nfrom collections import deque,defaultdict,Counter\nfrom bisect import bisect_left,bisect_right\nfrom operator import itemgetter\nfrom heapq import heapify,heappop,heappush\nfrom queue import Queue,LifoQueue,PriorityQueue\nfrom copy import deepcopy\nfrom time import time\nimport string\nimport sys\nsys.setrecursionlimit(10 ** 7)\ndef input() : return sys.stdin.readline().strip()\ndef INT()   : return int(input())\ndef MAP()   : return map(int,input().split())\ndef LIST()  : return list(MAP())\n\nn, x = MAP()\na = LIST()\nans = 0\nfor i in range(n-1):\n    if a[i] + a[i+1] > x:\n        ans += a[i] + a[i+1] - x\n        a[i+1] = max(0, x - a[i])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "n,x=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nif a[0]>x:\n  ans+=a[0]-x\n  a[0]=x\nfor i in range(n-1):\n  if a[i]+a[i+1]>x:\n    ans+=(a[i+1]-(x-a[i]))\n    a[i+1]=(x-a[i])\nprint(ans)", "passed": true, "time": 0.14, "memory": 14220.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\nA = list(map(int, input().split()))\ncnt = [0] * (n - 1)\nans1 = 0\nfor i in range(n - 1):\n    cnt[i] = A[i] + A[i + 1]\n    cnt[i] -= x\n    cnt[i] = max(cnt[i], 0)\ntemp_cnt = cnt[::]\n# print(cnt)\nfor i in range(n - 1):\n    if temp_cnt[i] == 0:\n        continue\n    if i < n - 2:\n        ans1 += temp_cnt[i]\n        temp_cnt[i + 1] -= min(A[i + 1], temp_cnt[i])\n        temp_cnt[i] = 0\n        temp_cnt[i + 1] = max(temp_cnt[i + 1], 0)\n    # print(ans1)\nans1 += temp_cnt[-1]\n\n\nprint(ans1)\n", "passed": true, "time": 0.14, "memory": 14132.0, "status": "done"}, {"code": "N, K = map(int, input().split())\nA = list(map(int, input().split()))\n\nans = 0\nfor i, j in zip(range(N - 1), range(1, N)):\n    Asum = A[i] + A[j]\n    if Asum <= K:\n        continue\n    eat = Asum - K\n    d = min(eat, A[j])\n    A[j] -= d\n    eat -= d\n    ans += d\n    d = min(eat, A[i])\n    A[i] -= d\n    ans += d\n\nprint(ans)", "passed": true, "time": 0.17, "memory": 14104.0, "status": "done"}, {"code": "n,m = map(int, input().split(\" \"))\na = list(map(int, input().split(\" \")))\ncount = 0\nfor i in range(1, n-1):\n  suma = a[i-1]+a[i]\n  if suma > m:\n    count += suma - m\n    if a[i] > suma-m:\n      a[i]-= suma - m\n    else:\n      a[i-1] -= suma-m-a[i]\n      a[i] = 0\n  #print(i, count, a)\nelse:\n  if a[-1]+a[-2] > m:\n    count += a[-2] + a[-1]-m\n    a[-1] -= a[-2] + a[-1]-m\n#print(a, count)\nif n <= 2:\n  if count + sum(a)-m >= 0:\n    print(count + sum(a)-m)\n  else:\n    print(0)\nelse:\n  print(count)", "passed": true, "time": 0.23, "memory": 14244.0, "status": "done"}, {"code": "N, x = list(map(int, input().split()))\nA = list(map(int, input().split()))\nans = 0\nif A[0] > x:\n    ans += A[0] - x\n    A[0] = x\n\nfor i in range(1, N):\n    if A[i]+A[i-1] > x:\n        ans += A[i]+A[i-1]-x\n        A[i] -= A[i]+A[i-1]-x\n\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "n,x=map(int,input().split())\na=list(map(int,input().split()))\nans=[0]*n\nif a[0]>x:\n    ans[0]=x\nelse:\n    ans[0]=a[0]\nfor i in range(1,n):\n    ans[i]=min(a[i],x-ans[i-1])\nprint(sum(a)-sum(ans))           ", "passed": true, "time": 0.14, "memory": 14284.0, "status": "done"}, {"code": "n,x = list(map(int,input().split()))\na = list(map(int,input().split()))\nif x==0:\n    print((sum(a)))\nelse:\n    eat = 0\n    for i in range(n-1):\n        tmp = 0\n        if a[i]+a[i+1]>x:\n            tmp = a[i]+a[i+1]-x\n            eat += tmp\n            if tmp>a[i+1]:\n                tmp -= a[i+1]\n                a[i+1] = 0\n                a[i] -= tmp\n            else:\n                a[i+1] -= tmp\n    print(eat)\n    #print(a)\n", "passed": true, "time": 0.15, "memory": 14344.0, "status": "done"}, {"code": "n, x = [int(s) for s in input().split()]\na_list = [int(s) for s in input().split()]\nans = 0\ntemp = a_list[0] - x\nif temp > 0:\n    ans += temp\n    a_list[0] -= temp\nfor i in range(1, n):\n    temp = a_list[i] + a_list[i - 1] - x\n    if temp > 0:\n        ans += temp\n        a_list[i] -= temp\nprint(ans)", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "\ndef resolve():\n    N, X = map(int, input().split())\n    A = list(map(int, input().split()))\n\n    ans = 0\n    for i in range(1, N):\n        diff = max((A[i - 1] + A[i]) - X, 0)\n        ans += diff\n        A[i] = max(A[i] - diff, 0)\n\n    print(ans)\n\n\ndef __starting_point():\n    resolve()\n__starting_point()", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\n\nans=0\nfor i in range(n-1):\n    pre=a[i]\n    post=a[i+1]\n    many=pre+post-x\n    if many>0:\n        ans += many\n        if many<=post:\n            a[i+1]-=many\n        else:\n            a[i]-=many-post\n            a[i+1]=0\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14300.0, "status": "done"}, {"code": "#!/usr/bin/env python\n# coding: utf-8\n\n# In[8]:\n\n\nN,x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\n\n# In[9]:\n\n\nans = 0\nif a[0] > x:\n    ans += a[0]-x\n    a[0] = x\nfor i in range(N-1):\n    if a[i]+a[i+1] > x:\n        cnt = a[i]+a[i+1]-x\n        ans += cnt\n        a[i+1] -= cnt\nprint(ans)\n\n\n# In[ ]:\n\n\n\n\n", "passed": true, "time": 0.14, "memory": 14244.0, "status": "done"}, {"code": "N, x = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nif x == 0:\n    print((sum(A)))\n    return\n\ncount = 0\nfor i in range(N - 1):\n    d = A[i] + A[i + 1] - x\n    if d <= 0:\n        continue\n    if A[i + 1] >= d:\n        A[i + 1] -= d\n        count += d\n    else:\n        count += d\n        A[i] = d - A[i + 1]\n        A[i + 1] = 0\n\n\nprint(count)\n", "passed": true, "time": 0.14, "memory": 14260.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = [int(i) for i in input().split()]\nop = 0\nfor i in range(1, n):\n    s = a[i-1] + a[i]\n    if s > x:\n        op += s - x\n        if a[i] < s - x:\n            a[i] = 0\n        else:\n            a[i] -= s - x\nprint(op)\n", "passed": true, "time": 0.14, "memory": 14244.0, "status": "done"}, {"code": "def candy():\n    n = []\n    n = input().split()\n    N = int(n[0])\n    x = int(n[1])\n    alist = [int(i) for i in input().split()]\n\n    s = 0\n    for i in range(0, N - 1):\n        c = int(alist[i])\n        d = int(alist[i + 1])\n        if int( alist[i] + alist[i + 1] ) > x:\n            if int( alist[i] ) >= x:\n                alist[i] = x\n                alist[i + 1] = 0\n            else :\n                alist[i + 1] = int(x - alist[i] )\n            s += c - int(alist[i]) + d - int(alist[i + 1])\n        \"\"\"\n        if int(alist[i]) > x:\n            s = s + int(alist[i+1])\n            alist[i+1] = 0\n\n        if int(alist[i+1]) + int(alist[i]) > x:\n            s = s + (int(alist[i+1]) + int(alist[i]) - x)\n            alist[i+1] = x - int(alist[i])\n        \"\"\"\n    print(s)\ncandy()", "passed": true, "time": 0.14, "memory": 14140.0, "status": "done"}, {"code": "#\n# abc048 c\n#\n\nimport sys\nfrom io import StringIO\nimport unittest\n\n\nclass TestClass(unittest.TestCase):\n    def assertIO(self, input, output):\n        stdout, stdin = sys.stdout, sys.stdin\n        sys.stdout, sys.stdin = StringIO(), StringIO(input)\n        resolve()\n        sys.stdout.seek(0)\n        out = sys.stdout.read()[:-1]\n        sys.stdout, sys.stdin = stdout, stdin\n        self.assertEqual(out, output)\n\n    def test_\u5165\u529b\u4f8b_1(self):\n        input = \"\"\"3 3\n2 2 2\"\"\"\n        output = \"\"\"1\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_2(self):\n        input = \"\"\"6 1\n1 6 1 2 0 4\"\"\"\n        output = \"\"\"11\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_3(self):\n        input = \"\"\"5 9\n3 1 4 1 5\"\"\"\n        output = \"\"\"0\"\"\"\n        self.assertIO(input, output)\n\n    def test_\u5165\u529b\u4f8b_4(self):\n        input = \"\"\"2 0\n5 5\"\"\"\n        output = \"\"\"10\"\"\"\n        self.assertIO(input, output)\n\n\ndef resolve():\n    N, x = list(map(int, input().split()))\n    a = list(map(int, input().split()))\n\n    ans = 0\n    for i in range(N):\n        if a[i] > x:\n            ans += (a[i] - x)\n            a[i] = x\n\n    for i in range(1, N):\n        if a[i-1] + a[i] > x:\n            ans += (a[i] + a[i-1] - x)\n            a[i] = x - a[i-1]\n\n    print(ans)\n\n\ndef __starting_point():\n     # unittest.main()\n     resolve()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14364.0, "status": "done"}, {"code": "f=lambda:map(int,input().split())\nN,X=f()\n*A,=f()\n\nB=[a if a<=X else X for a in A]\nc=sum(A)-sum(B)\nfor i in range(N-1):\n t=B[i]+B[i+1]\n if X < t:\n    d=t-X\n    B[i+1]-=d\n    c+=d\nprint(c)", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "n ,k = map(int, input().split())\na = list(map(int, input().split()))\n\nresult = 0\n\nif a[0] > k:\n        result = a[0] -k\n        a[0] = k\n\nfor i in range(n-1):\n    if a[i] + a[i+1] > k:\n        result += a[i] + a[i+1] - k #a[i] + a[i+1] -x = k\n        a[i+1] = -a[i] + k\n\nprint(result)", "passed": true, "time": 0.14, "memory": 14272.0, "status": "done"}, {"code": "N,X = map(int,input().split())\nA = list(map(int,input().split()))\nwa = []\nans = 0\n\nif A[0] > X:\n  ans += A[0]-X\n  A[0] = X\n\nfor i in range(N-1):\n  wa.append(A[i]+A[i+1])\n\nfor j in range(N-2):\n  if wa[j] > X:\n    ans += wa[j]-X\n    wa[j+1] -= wa[j]-X\n\nif wa[N-2] > X:\n  ans += wa[N-2]-X\n\nprint(ans)", "passed": true, "time": 0.15, "memory": 14164.0, "status": "done"}, {"code": "n,x=map(int,input().split())\na=list(map(int,input().split()))\nans=0\nsyaku = 0\nfor i in range(n-1):\n  if a[i]+a[i+1]>=x:\n    sa=a[i]+a[i+1]-x\n    ans+=sa\n    if sa<=a[i+1]:\n      a[i+1]-=sa\n    else:\n      a[i]=sa-a[i+1]\n      a[i+1]=0\n\nif n!=2 and a[n-2]+a[n-1]>=x:\n  sa=a[i]+a[i+1]-x\n  ans+=sa\n  if sa<=a[n-1]:\n    a[n-1]-=sa\n  else:\n    a[n-2]=sa-a[n-1]\n    a[n-1]=0\nprint(ans)", "passed": true, "time": 0.15, "memory": 14364.0, "status": "done"}, {"code": "N, x = list(map(int, input().split()))\nnums = list(map(int, input().split()))\n# print(nums)\nans = 0\nfor i in range(1, N):\n    if nums[i - 1] + nums[i] > x:\n        diff = nums[i - 1] + nums[i] - x\n        if diff > nums[i]:\n            nums[i - 1] -= (diff - nums[i])\n            nums[i] = 0\n        else:\n            nums[i] -= diff\n        ans += diff\n# print(nums)\nprint(ans)\n", "passed": true, "time": 0.16, "memory": 14084.0, "status": "done"}, {"code": "def main():\n    N, x = list(map(int, input().split()))\n    A = list(map(int, input().split()))\n    Acount = sum(A)\n    if A[0] > x:\n        A[0] = x\n    for i in range(N-1):\n        tmp = A[i] + A[i+1]\n        if tmp > x:\n            A[i+1] -= tmp - x\n    ans = Acount - sum(A)\n    print(ans)\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nif a[0]>x:\n  ans+=a[0]-x\n  a[0]=x\nfor i in range(n-1):\n  if a[i]+a[i+1]>x:\n    if a[i+1]>(x-a[i]):\n      ans+=(a[i+1]-(x-a[i]))\n      a[i+1]=(x-a[i])\nif a[-2]+a[i-1]>x:\n  if a[-1]>(x-a[-2]):\n    ans+=(a[-1]-(x-a[-2]))\n    a[-1]=(x-a[-2])\nprint(ans)\n    \n", "passed": true, "time": 0.86, "memory": 14288.0, "status": "done"}, {"code": "N, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\nSum = 0\nif a[0] - x > 0:\n    Sum += a[0] - x\n    a[0] = x\nif a[N - 1] - x > 0:\n    Sum += a[N - 1] - x\n    a[N - 1] = x\nfor i in range(1, N):\n    d = max(a[i] + a[i - 1] - x, 0)\n    a[i] -= d\n    Sum += d\n\nprint(Sum)\n\n", "passed": true, "time": 0.14, "memory": 14116.0, "status": "done"}, {"code": "N,x = map(int, input().split())\na = list(map(int, input().split()))\ncnt = 0\nfor i in range(1,N):\n    if a[i-1] > x:\n        b = a[i-1] - x\n        cnt += b\n        a[i-1] -= b\n    if a[i-1]+a[i] > x:\n        b = a[i-1] + a[i] - x\n        cnt += b\n        a[i] -= b\nprint(cnt)", "passed": true, "time": 0.16, "memory": 14132.0, "status": "done"}, {"code": "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nfor i in range(N-1):\n    n = max(0, A[i] + A[i+1] - x)\n    ans += n\n    A[i+1] = max(0, A[i+1]-n)\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14144.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\nn, x= map(int, input().split())\n\na_list = list(map(int, input().split()))\n\ncount = 0\nif a_list[0] > x:\n    count += a_list[0] - x\n    a_list[0] -= a_list[0] - x\nfor i in range(len(a_list)):\n    if i+1 == len(a_list):\n        break\n    if a_list[i] + a_list[i+1] > x:\n        count += a_list[i] + a_list[i+1] - x\n        a_list[i+1] -= a_list[i] + a_list[i+1] - x\n        \n\nprint(count)", "passed": true, "time": 0.14, "memory": 14152.0, "status": "done"}, {"code": "N,X = map(int, input().split())\n\nA = list(map(int, input().split()))\ncnt = 0\n\nfor i in range(N-1):\n    temp = 0\n    if A[i]+A[i+1] <= X:\n        continue\n    else:\n        temp = A[i]+A[i+1]-X\n        if A[i+1] < temp:\n            A[i+1] = 0\n            cnt += A[i+1]\n            temp -= A[i+1]\n        else:\n            A[i+1] -= temp\n            cnt += temp\n            temp -= A[i+1]\n\n        if A[i]+A[i+1] > X:\n            A[i] -= temp\n            cnt += temp\n\nprint(cnt)", "passed": true, "time": 0.21, "memory": 14224.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(1,n):\n    num=x\n    num2=a[i-1]+a[i]-x\n    if num2>0:\n        ans+=num2\n        a[i]=max(a[i]-num2,0)\nprint(ans)\n", "passed": true, "time": 0.25, "memory": 14096.0, "status": "done"}, {"code": "N,X = (int(T) for T in input().split())\nA = [int(T) for T in input().split()]\nEat = 0\nfor AT in range(0,N-1):\n    if A[AT]+A[AT+1]>X:\n        Need = A[AT]+A[AT+1]-X\n        Eat += Need\n        A[AT] -= max(0,Need-A[AT+1])\n        A[AT+1] = max(0,A[AT+1]-Need)\nprint(Eat)", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "N,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n    tmp=a[i-1]+a[i]\n    if tmp>x:\n        ans+=tmp-x\n        if a[i]>=tmp-x:\n            a[i]-=tmp-x\n        else:\n            a[i]=0\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "n, x = map(int, input().split())\na = list(map(int, input().split()))\nans = sum(a)\na = [i if i <= x else x for i in a]\nfor i in range(n-1):\n    if a[i]+a[i+1] > x:\n        a[i+1] = x-a[i]\nprint(ans-sum(a))", "passed": true, "time": 0.25, "memory": 14052.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\n\ncnt = 0\n\nfor i in range(n):\n   if a[i] > x:\n       cnt += a[i] - x\n       a[i] = x\n\nfor i in range(n-1):\n    dif = a[i] + a[i+1] - x\n\n    if dif > 0:\n        a[i+1] -= dif\n        cnt += dif\n\nprint(cnt)", "passed": true, "time": 0.19, "memory": 14336.0, "status": "done"}, {"code": "N, x = list(map(int, input().split()))\nA = [0] + [int(x) for x in input().split()]\nans = 0\nfor i in range(1,N+1):\n    if A[i-1] + A[i] > x:\n        ans += A[i-1] + A[i] - x\n        A[i] = x - A[i-1]\nprint(ans)\n", "passed": true, "time": 0.32, "memory": 14260.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\na = list(map(int, input().split()))\nans = 0\nfor i in range(n-1):\n    num = a[i]+a[i+1]-x\n    if num > 0:\n        a[i+1] = max(a[i+1]-num, 0)\n        ans += num\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14252.0, "status": "done"}, {"code": "n,x = list(map(int,input().split()))\nnarr = list(map(int,input().split()))\nc=0\nfor i in range(1,n):\n    total = narr[i]+narr[i-1]\n    if(total <= x):\n        continue\n    else:\n        c += (total - x)\n        narr[i] = max(0,narr[i]-(total-x))\nprint(c)\n", "passed": true, "time": 0.14, "memory": 14280.0, "status": "done"}, {"code": "f=lambda:map(int,input().split())\nN,X=f()\n*A,=f()\nA=[0]+A\n\nc=0\nfor i in range(N):\n c+=max(0,A[i]+A[i+1]-X)\n A[i+1]=min(A[i+1],X-A[i])\nprint(c)", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}, {"code": "n, x = map(int, input().split())\na = list(map(int, input().split()))\nans = 0\nfor i in range(1, n):\n    if a[i] + a[i-1] > x:\n        ans += min(a[i], a[i] + a[i-1] - x)\n        a[i] = max(0, x - a[i-1])\n    if a[i] + a[i-1] > x:\n        ans += a[i-1] - x\n        a[i-1] = x\nprint(ans)", "passed": true, "time": 0.15, "memory": 14116.0, "status": "done"}, {"code": "n,x=list(map(int,input().split()))\na=list(map(int,input().split()))\ns=0\nfor i in range(1,n):\n    b=a[i-1]+a[i]-x\n    if b>0:\n        s+=b\n        a[i]=max(a[i]-b,0)\nprint(s)\n", "passed": true, "time": 0.14, "memory": 14076.0, "status": "done"}, {"code": "n,x = map(int, input().split())\na= list(map(int, input().split()))\n \ncnt = 0\n \nif a[0] > x:\n\tcnt+= (a[0]-x)\n\ta[0]-= (a[0]-x)\n \nfor i in range (n-1):\n\tif a[i]+a[i+1] > x:\n\t\tcnt+= (a[i]+a[i+1])-x\n\t\ta[i+1]-= (a[i]+a[i+1])-x\n    \nprint(cnt)", "passed": true, "time": 0.14, "memory": 14268.0, "status": "done"}, {"code": "import collections\n\nn,x = map(int,input().split())\na = list(map(int,input().split()))\n\nans = 0\nq = collections.deque()\nif a[0] <= x:\n    q.append(a[0])\nelse:\n    ans += a[0]- x\n    q.append(x)\n\nfor i in range(1,n):\n    tmp = q[-1] + a[i] \n    if tmp <= x:\n        q.append(a[i])\n    else:\n        ans += tmp-x\n        q.append(x-q[-1])\n    q.popleft()\n\n\nprint(ans)", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "n,x=map(int,input().split())\na=list(map(int,input().split()))\ns=[0]*(n-1)\nans=0\nif a[0]>x:\n    ans+=a[0]-x\n    a[0]=x\nfor i in range(n-1):\n    s[i]=a[i]+a[i+1]\nfor i in range(n-2):\n    if s[i]>x:\n        t=s[i]-x\n        s[i+1]-=t\n        s[i]=x\n        ans+=t\nif s[n-2]>x:\n    ans+=s[n-2]-x\nprint(ans)", "passed": true, "time": 0.14, "memory": 14140.0, "status": "done"}, {"code": "N,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(N-1):\n    if a[i]+a[i+1]>x:\n        diff=a[i]+a[i+1]-x\n        ans+=diff\n        a[i+1]-=min(diff,a[i+1])\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14088.0, "status": "done"}, {"code": "N, K = map(int,input().split())\na = list(map(int,input().split()))\nif a[0] > K:\n    ans = a[0]-K\n    a[0] = K\nelse:\n    ans = 0\nfor i in range(1, N):\n    if a[i-1]+a[i] > K:\n        ans += a[i] - (K-a[i-1])\n        a[i] = K-a[i-1]\nprint(ans)", "passed": true, "time": 0.14, "memory": 14232.0, "status": "done"}, {"code": "n,x = map(int, input().split())\na = list(map(int, input().split()))\n\nt = 0\nans = 0\nfor i in a:\n  s = max(0, t+i-x) # \u4e00\u3064\u524d\u306e\u5024\u306e\u5dee\u5206\u3092\u542b\u3081\u3066\u3001x\u3068\u306e\u5dee\u5206\u3092\u53d6\u5f97\u3057\u3001\u6bd4\u8f03\n  t = i - s\n  ans += s\nprint(ans)", "passed": true, "time": 0.22, "memory": 14132.0, "status": "done"}, {"code": "n, x = list(map(int, input().split()))\nal = list(map(int, input().split()))\n\ncnt = 0\nfor i in range(n-1):\n    if al[i] + al[i+1] > x:\n        if al[i+1] > (al[i] + al[i+1]) - x:\n            cnt += al[i] + al[i+1] - x\n            al[i+1] -= (al[i] + al[i+1] - x)\n        else:\n            cnt += al[i+1] + al[i] - x\n            al[i+1] = 0\n            al[i] = x\n\nprint(cnt)\n# print(al)\n", "passed": true, "time": 0.14, "memory": 14160.0, "status": "done"}, {"code": "N, x = map(int, input().split())\nA = list(map(int, input().split()))\nans = 0\nif A[0] > x:\n    ans += A[0] - x\n    A[0] = x\n \nfor i in range(1, N):\n    if A[i]+A[i-1] > x:\n        ans += A[i]+A[i-1]-x\n        A[i] -= A[i]+A[i-1]-x\n \nprint(ans)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "import sys\n\ninput = sys.stdin.readline\n\n\ndef main():\n    N, x = list(map(int, input().split()))\n    A = list(map(int, input().split()))\n\n    ans = 0\n    for i in range(N - 1):\n        if A[i] + A[i + 1] <= x:\n            continue\n        if A[i] >= x:\n            ans += (A[i] - x) + A[i + 1]\n            A[i] = x\n            A[i + 1] = 0\n        else:\n            ans += (A[i] + A[i + 1] - x)\n            A[i + 1] = x - A[i]\n\n    print(ans)\n\n\ndef __starting_point():\n    main()\n\n__starting_point()", "passed": true, "time": 0.14, "memory": 14240.0, "status": "done"}, {"code": "n, x = map(int, input().split())\na = list(map(int, input().split()))\nk = 0\ncnt = 0\n\nif a[1] + a[0] > x and x >= a[0] :\n    k = x - a[0]\n    cnt += a[1] + a[0] - x\n\nelif a[1] + a[0] > x and x < a[0] :\n    k = 0\n    cnt += a[1] + a[0] - x\n\nelse :\n    k = a[1]\n\nfor i in range(1, n - 1) :\n    if k + a[i + 1] <= x :\n        k = a[i + 1]     \n\n    elif x >= k :\n        cnt += k + a[i + 1] - x\n        k = x - k\n\n    else :\n        cnt += k + a[i + 1] - x\n        k = 0\n    \n\nprint(cnt)", "passed": true, "time": 0.14, "memory": 14208.0, "status": "done"}, {"code": "N,x=list(map(int,input().split()))\na=list(map(int,input().split()))\nans=0\nfor i in range(1,N):\n    tmp=a[i-1]+a[i]\n    if tmp>x:\n        ans+=tmp-x\n        if a[i]>=tmp-x:\n            a[i]-=tmp-x\n        else:\n            a[i]=0\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14140.0, "status": "done"}, {"code": "#coding: utf-8\n\nN, X = (int(x) for x in input().split())\nA = [int(x) for x in input().split()]\n\ndiffs = []\nfor i in range(N-1):\n    diffs.append(A[i]+A[i+1] - X)\n\nret = 0\nfor i in range(N-1):\n    tmp = min(diffs[i], A[i+1])\n    ret += tmp\n    diffs[i]   -= tmp\n    if i+1 < len(diffs):\n        diffs[i+1] -= min(tmp, diffs[i+1]) \n    ret += diffs[i]\n\nprint((max(0, ret)))\n\n", "passed": true, "time": 0.14, "memory": 14076.0, "status": "done"}, {"code": "n,x=map(int,input().split())\nl=list(map(int,input().split()))\nc=0\nt=l[0]\nfor a in l[1:]:\n    d=t+a-x\n    if d>0:\n        if a<d:\n            a=0\n        else:\n            a-=d\n        c+=d\n    t=a\nprint(c)", "passed": true, "time": 0.14, "memory": 14328.0, "status": "done"}, {"code": "import math\nN, x = list(map(int, input().split()))\nL = [int(x) for x in input().split()]\nans = 0\nfor i in range(1,N):\n    if L[i-1] + L[i] > x:\n        if L[i-1] > x:\n            ans += L[i-1] - x\n            ans += L[i]\n            L[i] = 0\n        else:\n            ans += L[i] + L[i-1] - x\n            L[i] = x - L[i-1]\nprint(ans)\n", "passed": true, "time": 0.14, "memory": 14316.0, "status": "done"}, {"code": "n,x = map(int,input().split())\nl = list(map(int,input().split()))\ncount = 0\nfor i in range(n-1):\n  if l[i]>x:\n    count += (l[i]-x)\n    l[i] -= (l[i]-x)\n  if l[i]+l[i+1]>x:\n    count += (l[i]+l[i+1]-x)\n    l[i+1] -= (l[i]+l[i+1]-x)\nprint(count)", "passed": true, "time": 0.14, "memory": 14068.0, "status": "done"}, {"code": "def solve():\n  ans = 0\n  N, x = map(int, input().split())\n  A = [0]+list(map(int, input().split()))\n  for i in range(1,N+1):\n    if A[i]+A[i-1]>x:\n      ans += A[i]+A[i-1]-x\n      A[i] = x - A[i-1]\n  return ans\nprint(solve())", "passed": true, "time": 0.14, "memory": 14080.0, "status": "done"}, {"code": "N,x = map(int,input().split())\na = list(map(int,input().split()))\nans = 0\nfor i in range(N-1):\n    if a[i] + a[i+1] > x:\n        y = a[i] + a[i+1] - x\n        ans += y\n        a[i+1] = max(0,a[i+1]-y)\nprint(ans)", "passed": true, "time": 0.14, "memory": 14124.0, "status": "done"}, {"code": "n,x = map(int,input().split())\na = list(map(int,input().split()))\nans = 0\nif a[0] > x:\n    b = a[0] - x\n    ans = b\n    a[0] -= b\nfor i in range(1,n):\n    if a[i-1] + a[i] > x:\n        b = a[i-1] + a[i] - x\n        ans += b\n        a[i] -= b\nprint(ans)", "passed": true, "time": 0.14, "memory": 14248.0, "status": "done"}]