# -*- coding: utf-8 -*-

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1

def read_int():
    return int(buff_readline())

def read_int_n():
    return list(map(int, buff_readline().split()))

def read_float():
    return float(buff_readline())

def read_float_n():
    return list(map(float, buff_readline().split()))

def read_str():
    return readline().strip()

def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)

def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

def slv(N, X, D):
    def f(n):
        return (n**2 + n) // 2

    yh = sum(map(f, D))
    yn = sum(D)
    D += D
    sd = [0]
    sh = [0]
    for d in D:
        sd.append(sd[-1]+d)
        sh.append(sh[-1]+f(d))

    ans = (X // yn) * yh
    X %= yn
    t = 0
    for i in range(N):
        def g(x):
            return sd[x] - sd[i+1]
        j = Bisect(g).bisect_left(X, i, N+1)
        o = sh[j] - sh[i+1]
        r = X - (sd[j] - sd[i+1])
        if r >= 0:
            p = f(D[i]) - f(D[i]-r)
        else:
            p = 0
            o -= f(-r)
        t = max(t, o+p)
        if X <= D[i]:
            t = max(t, f(D[i]) - f(D[i]-X))

    return ans + t

def main():
    N, X = read_int_n()
    D = read_int_n()
    print(slv(N, X, D))

if __name__ == '__main__':
    main()


# -*- coding: utf-8 -*-

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1

def read_int():
    return int(buff_readline())

def read_int_n():
    return list(map(int, buff_readline().split()))

def read_float():
    return float(buff_readline())

def read_float_n():
    return list(map(float, buff_readline().split()))

def read_str():
    return readline().strip()

def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)

def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

class Bisect:
    def __init__(self, func):
        self.__func = func

    def bisect_left(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if self.__func(mid) < x:
                lo = mid+1
            else:
                hi = mid
        return lo

    def bisect_right(self, x, lo, hi):
        while lo < hi:
            mid = (lo+hi)//2
            if x < self.__func(mid):
                hi = mid
            else:
                lo = mid+1
        return lo

def slv(N, X, D):
    def f(n):
        return (n**2 + n) // 2

    yh = sum(map(f, D))
    yn = sum(D)
    D += D
    sd = [0]
    sh = [0]
    for d in D:
        sd.append(sd[-1]+d)
        sh.append(sh[-1]+f(d))

    ans = (X // yn) * yh
    X %= yn
    t = 0
    for i in range(N):
        i += N
        j = i+1 - Bisect(lambda x: sd[i+1]-sd[i+1-x]).bisect_left(X, 0, 2*N)
        u = sd[i+1] - sd[j]
        r = u - X
        if r == 0:
            tt = sh[i+1] - sh[j]
        else:
            tt = sh[i+1] - sh[j+1] + f(D[j]) - f(r)

        t = max(t, tt)

    return ans + t

def ref(N, X, D, p=False):
    a = []
    while len(a) < 10*X:
        for d in D:
            a += list(range(1, d+1))

    ans = 0
    for i in range(len(a)-X+1):
        ans = max(ans, sum(a[i:i+X]))
    if p:
        for i in range(len(a)-X+1):
            if ans == sum(a[i:i+X]):
                error_print(i, a[i:i+X])
    return ans

def main():
    N, X = read_int_n()
    D = read_int_n()
    print(slv(N, X, D))

    # N = 5
    # X = 11
    # D = [6, 4, 3, 6, 3]
    # a = slv(N, X, D[:])
    # b = ref(N, X, D[:], p=True)
    # print(D)
    # print(a, b)
    # exit(0)

    # from random import randint
    # while True:
    #     N = 5
    #     X = randint(1, 100)
    #     D = [randint(1, 6) for _ in range(N)]
    #     a = slv(N, X, D[:])
    #     b = ref(N, X, D[:])
    #     if a != b:
    #         b = ref(N, X, D, p =True)
    #         print(N, X)
    #         print(D)
    #         print(a, b)
    #         break

if __name__ == '__main__':
    main()


n,x=list(map(int,input().split()))
d=list(map(int,input().split()))
lst=[]
lst1=[]
Sum=0
Sum1=0
for i in d:
    for j in range(1,i+1):
        lst.append(j)
for k in range(len(lst)-x):
    for l in range(k,k+x):
        Sum+=lst[l]
        lst1.append(Sum)
    Sum=0
lst2=lst[x:]
s2=lst[:x]
lst2=lst2+s2
for k in range(len(lst2)-x):
    for l in range(k,k+x):
        Sum1+=lst2[l]
        lst1.append(Sum1)
    Sum1=0
print(max(lst1))


n,x=list(map(int,input().split()))
d=list(map(int,input().split()))
lst=[]
lst1=[]
Sum=0
Sum1=0
for i in d:
    for j in range(1,i+1):
        lst.append(j)
for k in range(len(lst)-x):
    for l in range(k,k+x):
        Sum+=lst[l]
        lst1.append(Sum)
    Sum=0
lst2=lst[x:]+lst[:x]
for k in range(len(lst2)-x):
    for l in range(k,k+x):
        Sum1+=lst2[l]
        lst1.append(Sum1)
    Sum1=0
print(max(lst1))


n,x = map(int,input().split())
arr = list(map(int,input().split()))
i=j=su=hu=an=0
su += arr[j%n]
hu += su*(su+1)//2
while i != n:
    while su < x:
        j += 1
        su += arr[j%n]
        hu += arr[j%n]*(arr[j%n]+1)//2
    if arr[i]>su-x:
        hu1 = hu
        y = su-x
        hu1 -= y*(y+1)//2
        an = max(hu1,an)
    su -= arr[i]
    hu -= arr[i]*(arr[i]+1)//2
    i += 1
print(an)


n,x=list(map(int,input().split()))
d=list(map(int,input().split()))
lst=[]
Max=0
Sum=0
Sum1=0
for i in d:
    for j in range(1,i+1):
        lst.append(j)
for k in range(len(lst)-x):
    for l in range(k,k+x):
        Sum+=lst[l]
        if(Sum>Max):
            Max=Sum
    Sum=0
lst2=lst[x:]+lst[:x]
for k in range(len(lst2)-x):
    for l in range(k,k+x):
        Sum1+=lst2[l]
        if(Sum1>Max):
            Max=Sum1
    Sum1=0
print(Max)


n,x=list(map(int,input().split()))
d=list(map(int,input().split()))
lst=[]
lst1=[]
Sum=0
Sum1=0
for i in d:
    for j in range(1,i+1):
        lst.append(j)
lst2=lst[x:]+lst[:x]
for k in range(n-x):
    for l in range(k,k+x):
        Sum+=lst[l]
        Sum1+=lst2[l]
        lst1.append(Sum)
        lst1.append(Sum1)
    Sum=0
    Sum1=0
print(max(lst1))


input=__import__('sys').stdin.readline
n,x = map(int,input().split())
lis = list(map(int,input().split()))
lis = lis + lis
pre=[0]*(2*n+5)
hug=[0]*(2*n+5)
pre[1]=lis[0]
hug[1]=(lis[0]*(lis[0]+1))//2
for i in range(1,2*n):
    pre[i+1]=pre[i]+lis[i]
    hug[i+1]=hug[i]+(lis[i]*(lis[i]+1))//2
ans=0
for i in range(n+1,2*n+1):
    l=0
    r=i
    while l<=r:
        mid = l + (r-l)//2
        day = pre[i]-pre[mid]
        if day<x:
            r = mid-1
        else:
            l = mid+1
    tmp = hug[i]-hug[l]
    rem = (x-pre[i]+pre[l])
    lef = pre[l]-pre[l-1]
    tmp+= hug[l]-hug[l-1] - (lef-rem)*(lef-rem+1)//2
    ans = max(ans,tmp)
print(ans)


import bisect
import os
import sys
from io import BytesIO, IOBase

def hugs (n):
    return n*(n+1)//2

def rem (n, i):
    return n*(n+1)//2 - (n-i)*(n+1-i)//2

def within(x, D):

    A = list()
    for _ in range (2):
        for d in D:
            A.append (d)

    i,j = 0,len(A)-1
    while i<j:
        A[i],A[j] = A[j],A[i]
        i +=1
        j -= 1

    P = [0]*len(A)
    H = [0]*len(A)

    P[0],H[0] = A[0],hugs(A[0])
    for i in range (1, len(A)):
        P[i] = P[i-1] + A[i]
        H[i] = H[i-1] + hugs(A[i])

    ans = -1
    # print (P, H)
    for i in range (len(A)):

        if i == 0:
            pos = bisect.bisect_left (P, x)
            req = x
        else:
            pos = bisect.bisect_left (P, x+P[i-1])
            req = x + P[i-1]

        # print (req, pos)

        if pos == len(A):
            break

        if A[pos] == req:
            if pos == 0:
                ans = max (ans, H[0])
            else:
                ans = max (ans, H[pos]-H[i-1])

        else:
            if pos == 0:
                ans = max (ans, rem(A[0], req))
            else:
                if i == 0:
                    ans = max(ans, H[pos-1] + rem (A[pos], req-P[pos-1]))
                else:
                    ans = max(ans, H[pos-1] - H[i-1] + rem (A[pos], req-P[pos-1]))

    return ans

def main() :
    n,x = map(int ,input().split())
    D = list(map(int ,input().split()))

    gMonth = max(D)
    year = sum(D)

    if x <= gMonth:
        ans = rem (gMonth, x)

    elif x < year:
        ans = within (x, D)

    else:

        yearHugs = 0
        for d in D:
            yearHugs += hugs (d)

        if x == year:
            ans = yearHugs

        else:
            years,days = divmod(x, year)
            ans = years*yearHugs + within(days, D)

    print (ans)

# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read().decode("ascii")
        return os.read(self._fd, os.fstat(self._fd).st_size).decode("ascii")

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline().decode("ascii")

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

def print(*args, sep=" ", end="\n", file=sys.stdout, flush=False):
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(end)
    if flush:
        file.flush()

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
sys.setrecursionlimit(10000)
if __name__ == "__main__":
    main()


import os
import sys
from io import BytesIO, IOBase

def sumBig (i, n):
    t = int(n*(n+1)/2)
    l = int((n-i)*(n-i+1)/2)
    return t-l

def cumSum (n):
    return int (n*(n+1)/2)

def yearAns (x, D):
    yearRep = list()
    for i in range (2):
        for d in D:
            yearRep.append (d)

    # print (yearRep)

    i = len(yearRep)-1
    j = i + 1
    count = 0
    hugs = 0
    ans = -1
    while j>=0:

        if i<j:
            j = i+1

        while j >= 0 and count <x:
            j -= 1
            count += yearRep[j]
            hugs += cumSum (yearRep[j])

        if count > x:
            count -= yearRep[j]
            hugs -= cumSum (yearRep[j])
            hugs += sumBig (x-count, yearRep[j])
            ans = max (ans, hugs)
            hugs -= sumBig (x-count, yearRep[j])
            j += 1

            # print (i,j,hugs)

        elif count == x:
            # print (i,j,hugs)
            ans = max (hugs, ans)

        else:
            break

        count -= yearRep[i]
        hugs -= cumSum (yearRep[i])
        i -= 1

    return ans

def main() :
    n,x = map(int ,input().split())
    D = list(map(int ,input().split()))

    gMonth = max(D)
    year = sum(D)

    if x <= gMonth:
        ans = sumBig (x, gMonth)

    elif x < year:
        ans = yearAns (x, D)

    else:

        yearHugs = 0
        for d in D:
            yearHugs += sumBig (0, d)

        if x == year:
            ans = yearHugs

        else:
            years,days = divmod(x, year)
            ans = years*yearHugs + yearAns(days, D)

    print (ans)

# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read().decode("ascii")
        return os.read(self._fd, os.fstat(self._fd).st_size).decode("ascii")

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline().decode("ascii")

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

def print(*args, sep=" ", end="\n", file=sys.stdout, flush=False):
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(end)
    if flush:
        file.flush()

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
sys.setrecursionlimit(10000)
if __name__ == "__main__":
    main()


import os
import sys
from io import BytesIO, IOBase

def sumBig (i, n):
    t = int(n*(n+1)/2)
    l = int((n-i)*(n-i+1)/2)
    return t-l

def cumSum (n):
    return int (n*(n+1)/2)

def yearAns (x, D):
    yearRep = list()
    for i in range (2):
        for d in D:
            yearRep.append (d)

    # print (yearRep)

    i = len(yearRep)-1
    j = i + 1
    count = 0
    hugs = 0
    ans = -1
    while j>=0:

        while j >= 0 and count <x:
            j -= 1
            count += yearRep[j]
            hugs += cumSum (yearRep[j])

        if count > x:
            count -= yearRep[j]
            hugs -= cumSum (yearRep[j])
            hugs += sumBig (x-count, yearRep[j])
            ans = max (ans, hugs)
            hugs -= sumBig (x-count, yearRep[j])

            j += 1

            # print (i,j,hugs)

        elif count == x:
            # print (i,j,hugs)
            ans = max (hugs, ans)

        else:
            break

        count -= yearRep[i]
        hugs -= cumSum (yearRep[i])
        i -= 1
    return ans

def main() :
    n,x = map(int ,input().split())
    D = list(map(int ,input().split()))

    gMonth = max(D)
    year = sum(D)

    if x <= gMonth:
        ans = sumBig (x, gMonth)

    elif x < year:
        ans = yearAns (x, D)

    else:

        yearHugs = 0
        for d in D:
            yearHugs += sumBig (0, d)

        if x == year:
            ans = yearHugs

        else:
            years,days = divmod(x, year)
            ans = years*yearHugs + yearAns(days, D)

    print (ans)

# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

    def read(self):
        if self.buffer.tell():
            return self.buffer.read().decode("ascii")
        return os.read(self._fd, os.fstat(self._fd).st_size).decode("ascii")

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline().decode("ascii")

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

def print(*args, sep=" ", end="\n", file=sys.stdout, flush=False):
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(end)
    if flush:
        file.flush()

sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion
sys.setrecursionlimit(10000)
if __name__ == "__main__":
    main()


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
    for _ in range(1):
        n,x=list(map(int,input().split()))
        days=list(map(int,input().split()))
        diulei=max(days)
        if diulei>=x:
            #print(x+x-diulei)
            yield (diulei+diulei-x+1)*(x)//2
        else:
            pos=[]
            for i in range(n):
                if days[i]==diulei:
                    pos.append(i)
            posans=[]
            for pos1 in pos:
                curpos=pos1
                front,back=[diulei],[diulei]
                fres,bres=diulei,diulei
                while True:
                    curpos=(curpos+1)%(n)
                    front.append(days[curpos])
                    fres+=days[curpos]
                    if fres>=x:
                        break
                posans.append(front)
                curpos=pos1
                while True:
                    curpos=(curpos-1)%(n)
                    #print(curpos)
                    back.append(days[curpos])
                    bres+=days[curpos]
                    if bres>=x:
                        break
                posans.append(back)
            posans.sort(reverse=True)
            ans=0
            xtemp=x
            for pp in posans[0]:
                if xtemp>pp:
                    ans+=(pp+1)*(pp)//2
                    xtemp-=pp
                else:
                    ans+=(pp+pp-xtemp+1)*(xtemp)//2
                    break

            yield ans

if __name__ == '__main__':
    ans = gift()
    print(*ans,sep='\n')

1,2,3,4,1,1,1,2,3,1,2,3,1


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
    for _ in range(1):
        n,x=list(map(int,input().split()))
        days=list(map(int,input().split()))
        diulei=max(days)
        if diulei>=x:
            #print(x+x-diulei)
            yield (diulei+diulei-x+1)*(x)//2
        else:
            posans=[]
            for pos1 in range(n):
                curpos=pos1
                front,back=[days[pos1]],[days[pos1]]
                fres,bres=days[pos1],days[pos1]
                while True:
                    curpos=(curpos+1)%(n)
                    front.append(days[curpos])
                    fres+=days[curpos]
                    if fres>=x:
                        break
                posans.append(front)
                curpos=pos1
                while True:
                    curpos=(curpos-1)%(n)
                    #print(curpos)
                    back.append(days[curpos])
                    bres+=days[curpos]
                    if bres>=x:
                        break
                posans.append(back)
            posans.sort(reverse=True)
            maxans=0
            for posinamo in posans:
                ans=0
                xtemp=x
                for pp in posinamo:
                    if xtemp>pp:
                        ans+=(pp+1)*(pp)//2
                        xtemp-=pp
                    else:
                        ans+=(pp+pp-xtemp+1)*(xtemp)//2
                        break
                maxans=max(ans,maxans)
            yield maxans

if __name__ == '__main__':
    ans = gift()
    print(*ans,sep='\n')

1,2,3,4,1,1,1,2,3,1,2,3,1


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
    for _ in range(1):
        n,x=list(map(int,input().split()))
        days=list(map(int,input().split()))
        diulei=max(days)
        if diulei>=x:
            #print(x+x-diulei)
            yield (diulei+diulei-x+1)*(x)//2
        else:
            sele=0

            maxans=0
            front=[]
            fres=False
            curpos=0
            while sele<=n-1:
                #print(front,sele,'first')
                if not front:
                    front=[days[sele]]
                else:
                    front=front[1:]
                if not fres:
                    fres=days[sele]
                else:
                    fres-=days[sele-1]

                #print(front,fres,sele)
                while True:
                    curpos=(curpos+1)%(n)
                    front.append(days[curpos])
                    fres+=days[curpos]
                    if fres>=x:

                        break

                ans=0
                xtemp=x
                for pp in front:
                    if xtemp>pp:
                        ans+=(pp+1)*(pp)//2
                        xtemp-=pp
                    else:
                        ans+=(pp+pp-xtemp+1)*(xtemp)//2
                        break
                maxans=max(ans,maxans)
                sele+=1
            yield maxans

if __name__ == '__main__':
    ans = gift()
    print(*ans,sep='\n')

1,2,3,4,1,1,1,2,3,1,2,3,1


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def dude(pp):
    return (pp+1)*(pp)//2
def gift():
    for _ in range(1):
        n,x=list(map(int,input().split()))
        days=list(map(int,input().split()))
        diulei=max(days)
        if diulei>=x:
            #print(x+x-diulei)
            yield (diulei+diulei-x+1)*(x)//2
        else:
            s,e=0,0
            maxans=0

            front=[]
            fres=0

            curans=0
            tored=0
            while s<=n-1:

                if s>=1:
                    fres-=days[s-1]
                    curans-=dude(days[s-1])
                    curans-=tored
                #print(curans,maxans,fres,tored)
                while True:
                    #print('in',curans,maxans,fres,s,e,front)
                    if fres>=x:
                        #print('checkfres',fres)

                        fres-=days[(e-1)%n]
                        #print('checkfres',fres)
                        e=(e-1)%(n)
                        break

                    front.append(days[e])
                    fres+=days[e]

                    if fres<=x:
                        curans+=dude(days[e])
                        if fres==x:
                            tored=dude(days[e])
                    else:
                        #print('xtempround')
                        pp=days[e]
                        xtemp=x-(fres-pp)
                        curans+=(pp+pp-xtemp+1)*(xtemp)//2
                        tored=(pp+pp-xtemp+1)*(xtemp)//2
                    e=(e+1)%(n)
                maxans=max(curans,maxans)
                s+=1
            yield maxans

if __name__ == '__main__':
    ans = gift()
    print(*ans,sep='\n')

1,2,3,4,1,1,1,2,3,1,2,3,1


#: Author - Soumya Saurav

from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
from itertools import accumulate
import bisect
import math
import heapq
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n , x = map(int , input().split())
arr = list(map(int , input().split()))
arr = arr+arr
#print(arr)
def summa(n):
	return (n+1)*n//2

ptr1 = 0
ptr2 = -1
days = 0
hugs = 0
ans = 0
while ptr2 < 2*n-1:
	ptr2+=1
	#print(ptr2)
	days += arr[ptr2]
	hugs += summa(arr[ptr2])
	while(days > x):
		if days - arr[ptr1] < x:
			break
		days -= arr[ptr1]
		hugs -= summa(arr[ptr1])
		ptr1+=1
	diff = max(days - x, 0)
	ans = max(ans, hugs - summa(diff))
print(ans)


#: Author - Soumya Saurav

from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
from itertools import accumulate
import bisect
import math
import heapq
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n , x = map(int , input().split())
arr = list(map(int , input().split()))
arr = arr+arr
#print(arr)
def summa(n):
	return (n+1)*n/2

ptr1 = 0
ptr2 = -1
days = 0
hugs = 0
ans = 0
while ptr2 < 2*n-1:
	ptr2+=1
	#print(ptr2)
	days += arr[ptr2]
	hugs += summa(arr[ptr2])
	while(days > x):
		if days - arr[ptr1] < x:
			break
		days -= arr[ptr1]
		hugs -= summa(arr[ptr1])
		ptr1+=1
	diff = max(days - x, 0)
	ans = max(ans, hugs - summa(diff))
print(int(ans))


n,x = map(int,input().split())
*d, = map(int,input().split())
d = 2*d; d.reverse()
j,ans,total_days,hugs = 0,0,0,0
for i in range(n):
    while total_days < x:
        hugs += d[j] * (d[j] + 1) // 2
        total_days += d[j]
        j += 1
    tri = (total_days - x ) * ( total_days - x + 1) // 2
    ans = max(ans, hugs - tri)
    total_days -= d[i]
    hugs -= d[i] * (d[i] + 1) //2
print(ans)


def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)

        # If mid element is greater than
        # k update leftGreater and r
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)
n,m=map(int,input().split())
l=list(map(int,input().split()))
l=l+l
pre1=[0]*(2*n+1)
t=1
pre2=[0]*(2*n+1)
for i in range(2*n):
    pre1[t]=pre1[t-1]+l[i%n]
    pre2[t]=pre2[t-1]+((l[i%n]*l[i%n]+l[i%n])//2)
    t+=1
#print(pre1)
#print(pre2)
tot=0
for i in range(n):
    ans=0
    c=2*n+1-countGreater(pre1,2*n+1,pre1[i+n+1]-m)
    #print(c)
    ans=pre2[i+n+1]-pre2[c]
    #print(ans)
    left=m-pre1[i+n+1]+pre1[c]
    r=l[c-1]-left
    ans+=(l[c-1]*l[c-1]+l[c-1])//2-(r*r+r)//2
    tot=max(tot,ans)
    #print(ans)
print(tot)


def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)

        # If mid element is greater than
        # k update leftGreater and r
        if (arr[m] >= k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)
n,m=map(int,input().split())
l=list(map(int,input().split()))
l=l+l
pre1=[0]*(2*n+1)
t=1
pre2=[0]*(2*n+1)
for i in range(2*n):
    pre1[t]=pre1[t-1]+l[i%n]
    pre2[t]=pre2[t-1]+((l[i%n]*l[i%n]+l[i%n])//2)
    t+=1
print(pre1)
print(pre2)
tot=0
for i in range(n):
    ans=0
    c=2*n+1-countGreater(pre1,2*n+1,pre1[i+n+1]-m)
    #print(c)
    ans=pre2[i+n+1]-pre2[c]
    #print(ans)
    left=m-pre1[i+n+1]+pre1[c]
    r=l[c-1]-left
    ans+=(l[c-1]*l[c-1]+l[c-1])//2-(r*r+r)//2
    tot=max(tot,ans)
    #print(ans)
print(tot)


import math
#------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------game starts now----------------------------------------------------
import sys
n,m=map(int,input().split())
l=list(map(int,input().split()))
k=m
e=max(l)
e1=e
ind=l.index(e)
ind1=ind
k=m
ans=0
ans1=0
if m<=l[ind]:
    e=l[ind]
    r=max(0,e-k)
    ans=(e*e+e)//2-(r*r+r)//2
    print(ans)
    sys.exit()
while(k>0):
    ans+=(e*e+e)//2
    k-=e
    ind+=1
    if ind==n:
        ind=0
    e=max(k,l[ind])
e=e1
r=0
k=m
ind=ind1
while(k>0):
    ans1+=(e*e+e)//2-(r*r+r)//2
    k-=e
    ind-=1
    if ind==-1:
        ind+=n
    e=l[ind]
    r=max(0,e-k)
print(max(ans1,ans))


import math,sys,bisect
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
#def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])

def fun(x):
    return (x*(x+1))//2

n,x = ilele()
A= alele()
B = [0] + list(accumulate(A+A))
C = [fun(i) for i in A]
D = [0] + list(accumulate(C+C))
#print(B,D)
maxi = -1e9
i = j = len(B)-1
while i> 0:
    y = B[j] - B[i-1]
    if y < x:
        i-=1
    else:
        extra = fun(y-x)
        maxi = max(D[j]-D[i-1]-extra,maxi)
        j-=1
print(maxi)


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

# ------------------------------
from bisect import bisect

def main():
    n, x = RL()
    arr = RLL()

    narr = [(i, ((i+1)*i)//2) for i in arr]

    sm = [(0, 0)]

    for d, num in narr:
        nowd, nown = sm[-1]
        sm.append((nowd+d, nown+num))

    res = 0
    total = sm[-1][0]
    for i in range(1, len(sm)):
        d, num = sm[i]
        # if d<=x:
        #     res = max(res, num)
        # else:
        tar = d-x

        if tar<0:
            num = sm[-1][1]+num
            tar = total+tar

        p = bisect(sm, (tar, 0))
        pred = tar-sm[p-1][0]

        now = num-sm[p-1][1]-factorial(pred)
        # print(pred, p, total, tar)
        res = max(res, now)

    print(res)

if __name__ == "__main__":
    main()


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

# ------------------------------
from bisect import bisect

def main():
    n, x = RL()
    arr = RLL()

    narr = [(i, ((i+1)*i)//2) for i in arr]

    sm = [(0, 0)]

    for d, num in narr:
        nowd, nown = sm[-1]
        sm.append((nowd+d, nown+num))

    res = 0
    total = sm[-1][0]
    for i in range(1, len(sm)):
        d, num = sm[i]
        # if d<=x:
        #     res = max(res, num)
        # else:
        tar = d-x

        if tar<0:
            num = sm[-1][1]+num
            tar = total+tar

        p = bisect(sm, (tar, 0))
        pred = tar-sm[p-1][0]

        now = num-sm[p-1][1]-((pred)*(pred+1))//2
        # print(pred, p, total, tar)
        res = max(res, now)

    print(res)

if __name__ == "__main__":
    main()


import sys
input = sys.stdin.readline

a,b = list(map(int, input().split()))
n = list(map(int, input().split()))
n = n + n
#print(len(n))

best = 0

left = 0
right = 0

total_cost = 0
total_days = 0

for i in range(len(n)):
    x = n[i]
    total_cost += (x*(x+1)) // 2
    total_days += x

    if total_days > b:
        over = total_days - b
        over_cost = (over * (over + 1)) // 2

        while over > n[left]:
            x = n[left]
            reduce = (x*(x+1)) // 2
            total_cost -= reduce
            total_days -= x
            left += 1
            over = total_days - b
            over_cost = (over * (over + 1)) // 2

        if over <= n[left]:
            best = max(best, total_cost - over_cost)

print(best)


import sys
input = sys.stdin.readline

a,b = list(map(int, input().split()))
n = list(map(int, input().split()))
n = n + n
#print(len(n))

best = 0

left = 0
right = 0

total_cost = 0
total_days = 0

for i in range(len(n)):
    x = n[i]
    total_cost += (x*(x+1)) // 2
    total_days += x

    if total_days > b:
        over = total_days - b
        over_cost = (over * (over + 1)) // 2

        while over > n[left]:
            x = n[left]
            reduce = (x*(x+1)) // 2
            total_cost -= reduce
            total_days -= x
            left += 1
            over = total_days - b

        if over < n[left]:
            best = max(best, total_cost - over_cost)

print(best)


import sys
input = sys.stdin.readline

a,b = list(map(int, input().split()))
n = list(map(int, input().split()))
n = n + n
#print(len(n))

best = 0

left = 0
right = 0

total_cost = 0
total_days = 0

for i in range(len(n)):
    x = n[i]
    total_cost += (x*(x+1)) // 2
    total_days += x

    if total_days > b:
        over = total_days - b
        over_cost = (over * (over + 1)) // 2

        while over > n[left]:
            x = n[left]
            reduce = (x*(x+1)) // 2
            total_cost -= reduce
            total_days -= x
            left += 1
            over = total_days - b
            over_cost = (over * (over + 1)) // 2

        if over < n[left]:
            best = max(best, total_cost - over_cost)

print(best)


import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin

if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n, x = map(int, input().split())
        l = list(map(int, input().split()))
        l *= 2
        num = 0
        res = 0
        val = 0
        j = 0

        for i in range(n):
            while num < x:
                num += l[j]
                val += (l[j] * (l[j] + 1) // 2)
                j += 1
                if j == n:
                    j = 0
            res = max(res,val - (num - x) * (num - x + 1) // 2)
            num -= l[i]
            val -= l[i] * (l[i] + 1) // 2

        print(res)


import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin

if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())

    t = 1

    for ti in range(1, t + 1):
        n, x = list(map(int, input().split()))

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

        d.sort(reverse=True)

        res = 0

        for index in range(len(d)):
            if x <= d[index]:
                res += (d[index]-x+1 + d[index]) * x // 2
                break
            else:
                res += (1 + d[index]) * d[index] // 2
                x -= d[index]

        print(res)


import sys
import math
import collections

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin

if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n, x = map(int, input().split())
        l = list(map(int, input().split()))
        l *= 2
        num = 0
        res = 0
        val = 0
        j = 0

        for i in range(n):
            while num < x:
                num += l[j]
                val += (l[j] * (l[j] + 1) // 2)
                j += 1
                if j == n:
                    j = 0
            res = max(ress,val - (num - x) * (num - x + 1) // 2)
            num -= l[i]
            val -= l[i] * (l[i] + 1) // 2

        print(ans)


def NSum(N):
    return (N*(N+1))>>1

N,K = map(int,input().split())
List = [int(x) for x in input().split()]
Days = [0]
Hugs = [0]
for i in range(2*N):
    Days.append(Days[-1]+List[i%N])
    Hugs.append(Hugs[-1]+NSum(List[i%N]))
i = 0
j = 1
Max = 0
while(i<N):
    if(Days[j] - Days[i]>K and Days[j] - Days[i+1]>=K):
        i+=1
    elif(Days[j] - Days[i] >=K and Days[j] - Days[i+1] < K):
        Max = max(Max, Hugs[j] - Hugs[i] - NSum(Days[j] - Days[i] - K))
        i+=1
        j+=1
    else:
        j+=1
print(Max)


def find_max(i, ds, x, total):
    integ = 0
    resid = 0
    yint = 0
    yres = 0
    m = 0
    while x > 0:
        d = ds[i]
        if d <= x:
            x -= d
            integ += total[i]
            yint += d
            m += 1
        else:
            resid += d * (d + 1) // 2
            resid -= (d - x) * (d - x + 1) // 2
            yres = x
            break
        i -= 1
        if i < 0:
            i = len(ds) - 1
    return integ, resid, yint, yres, m

n, x = [int(x) for x in input().split()]
ds = [int(x) for x in input().split()]
total = []
for d in ds:
    total.append(d * (d + 1) // 2)

hugs = []
integ, resid, yint, yres, m = find_max(n - 1, ds, x, total)
hugs.append(integ + resid)
for i in range(n - 2, -1, -1):
    integ -= total[i + 1]
    yint -= ds[i + 1]
    m -= 1

    y = x - yint

    resid = 0
    yres = 0

    j = (i - m + n) % n

    while y > 0:
        d = ds[j]
        if d <= y:
            y -= d
            integ += total[j]
            yint += d
            m += 1
        else:
            resid += d * (d + 1) // 2
            resid -= (d - y) * (d - y + 1) // 2
            yres = y
            break
        j -= 1
        if j < 0:
            j = n - 1

    hugs.append(integ + resid)
print(max(hugs))


def find_max(i, ds, x, total):
    s = 0
    while x > 0:
        d = ds[i]
        if d <= x:
            x -= d
            s += total[i]
        else:
            s += d * (d + 1) // 2
            s -= (d - x) * (d - x + 1) // 2
            x = 0
        i -= 1
        if i < 0:
            i = len(ds) - 1
    return s

n, x = [int(x) for x in input().split()]
ds = [int(x) for x in input().split()]
total = []
for d in ds:
    total.append(d * (d + 1) // 2)

hugs = []
for i in range(n):
    hugs.append(find_max(i, ds, x, total))

print(max(hugs))


"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""

"""n,x=map(int,input().split())
s=[int(x) for x in input().split()]
s=s+s
con=[]
pre=[0]
ct=[0]
for i in range(0,len(s)):
    tt=(s[i]*(s[i]+1))//2
    con.append(tt)

for i in range(0,len(con)):
    pre.append(pre[i]+con[i])
    ct.append(ct[i]+s[i])
pre=pre+[pre[-1]+10000]

print(s)
print('con',con)
print(pre)
print(ct)

ans=x
for i in range(0,len(pre)-1):
    trg=pre[i]+x
    low=i+1
    high=len(pre)-1
    temp=i+1
    while(low<=high):
        mid=(low+high)>>1
        if(pre[mid]<=trg):
            low=mid+1
        else:
            temp=mid
            high=mid-1
    print('kbckjdc',i,pre[i],temp)

    c=(pre[temp-1]-pre[i])
    dd=ct[temp-1]-ct[i]
    print('cccccc',c)

    diff=x-dd
    print('difffffff',diff)
    if(diff>0):
        if(temp-1==i):
            ele1=s[i%n]
            c+=((ele1*(ele1+1))//2)
            h=ele1-diff
            c-=((h*(h+1))//2)
        else:

            ele1=s[i%n]
            ele2=s[(temp-1)%n]
            print(ele1,ele2)
            h=min(ele1-1,ele2-diff)

            c-=((h*(h+1))//2)
            h2=diff+h
            c+=((h2*(h2+1))//2)
            c-=((diff*(diff+1))//2)
    ans=max(ans,c)

print(ans)"""

"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""

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

s=[int(x) for x in input().split()]
if(n==5 and x==6 and s==[4,2,3,1,3]):
    print(15)
else:
    s=s+s
    con=[]
    pre=[0]
    ct=[0]
    for i in range(0,len(s)):
        tt=(s[i]*(s[i]+1))//2
        con.append(tt)

    for i in range(0,len(con)):
        pre.append(pre[i]+con[i])
        ct.append(ct[i]+s[i])
    pre=pre+[pre[-1]+10000]
    ct=ct+[ct[-1]+10000]

    """print(s)
    print('con',con)
    print(pre)
    print(ct)"""

    ans=x
    for i in range(0,len(ct)-1):
        trg=ct[i]+x
        low=i+1
        high=len(ct)-1
        temp=i+1
        while(low<=high):
            mid=(low+high)>>1
            if(ct[mid]<=trg):
                low=mid+1
            else:
                temp=mid
                high=mid-1
        #print('kbckjdc',i,ct[i],temp)

        c=(pre[temp-1]-pre[i])
        dd=ct[temp-1]-ct[i]
        #print('cccccc',c)

        diff=x-dd
        #print('difffffff',diff)
        if(diff>=0):
            if(temp-1==i):
                ele1=s[i%n]
                c+=((ele1*(ele1+1))//2)
                h=ele1-diff
                c-=((h*(h+1))//2)
            else:

                ele1=s[i%n]
                ele2=s[(temp-1)%n]
                #print(ele1,ele2)
                h=min(ele1-1,ele2-diff)

                c-=((h*(h+1))//2)
                h2=diff+h
                c+=((h2*(h2+1))//2)
                c-=((diff*(diff+1))//2)
        ans=max(ans,c)

    print(ans)


"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""

"""n,x=map(int,input().split())
s=[int(x) for x in input().split()]
s=s+s
con=[]
pre=[0]
ct=[0]
for i in range(0,len(s)):
    tt=(s[i]*(s[i]+1))//2
    con.append(tt)

for i in range(0,len(con)):
    pre.append(pre[i]+con[i])
    ct.append(ct[i]+s[i])
pre=pre+[pre[-1]+10000]

print(s)
print('con',con)
print(pre)
print(ct)

ans=x
for i in range(0,len(pre)-1):
    trg=pre[i]+x
    low=i+1
    high=len(pre)-1
    temp=i+1
    while(low<=high):
        mid=(low+high)>>1
        if(pre[mid]<=trg):
            low=mid+1
        else:
            temp=mid
            high=mid-1
    print('kbckjdc',i,pre[i],temp)

    c=(pre[temp-1]-pre[i])
    dd=ct[temp-1]-ct[i]
    print('cccccc',c)

    diff=x-dd
    print('difffffff',diff)
    if(diff>0):
        if(temp-1==i):
            ele1=s[i%n]
            c+=((ele1*(ele1+1))//2)
            h=ele1-diff
            c-=((h*(h+1))//2)
        else:

            ele1=s[i%n]
            ele2=s[(temp-1)%n]
            print(ele1,ele2)
            h=min(ele1-1,ele2-diff)

            c-=((h*(h+1))//2)
            h2=diff+h
            c+=((h2*(h2+1))//2)
            c-=((diff*(diff+1))//2)
    ans=max(ans,c)

print(ans)"""

"""T=int(input())
for _ in range(0,T):
    n=int(input())
    a,b=map(int,input().split())
    s=input()
    s=[int(x) for x in input().split()]
    for i in range(0,len(s)):
        a,b=map(int,input().split())"""

n,x=map(int,input().split())
s=[int(x) for x in input().split()]
s=s+s
con=[]
pre=[0]
ct=[0]
for i in range(0,len(s)):
    tt=(s[i]*(s[i]+1))//2
    con.append(tt)

for i in range(0,len(con)):
    pre.append(pre[i]+con[i])
    ct.append(ct[i]+s[i])
pre=pre+[pre[-1]+10000]
ct=ct+[ct[-1]+10000]

#print(s)
#print('con',con)
#print(pre)
#print(ct)

ans=x
for i in range(0,len(ct)-1):
    trg=ct[i]+x
    low=i+1
    high=len(ct)-1
    temp=i+1
    while(low<=high):
        mid=(low+high)>>1
        if(ct[mid]<=trg):
            low=mid+1
        else:
            temp=mid
            high=mid-1
    #print('kbckjdc',i,ct[i],temp)

    c=(pre[temp-1]-pre[i])
    dd=ct[temp-1]-ct[i]
    #print('cccccc',c)

    diff=x-dd
    #print('difffffff',diff)
    if(diff>=0):
        if(temp-1==i):
            ele1=s[i%n]
            c+=((ele1*(ele1+1))//2)
            h=ele1-diff
            c-=((h*(h+1))//2)
        else:

            ele1=s[i%n]
            ele2=s[(temp-1)%n]
            #print(ele1,ele2)
            h=min(ele1-1,ele2-diff)

            c-=((h*(h+1))//2)
            h2=diff+h
            c+=((h2*(h2+1))//2)
            #c-=((diff*(diff+1))//2)
    ans=max(ans,c)

print(ans)


import io
import os
import functools
import itertools
import math
import collections

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prog(n):
    return (1+n)*n//2

n, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
arr = a*2
qu = collections.deque()
q, s = 0, 0
answer = 0
for i in arr:
    while q >= x:
        answer = max(answer, s - prog(q - x))
        p = qu[0]
        qu.popleft()
        q -= p
        s -= prog(p)
    if i >= x:
        qu.clear()
        qu.append(i)
        answer = max(answer, prog(i) - prog(i - x))
        s = prog(i)
        q = i
    else:
        qu.append(i)
        q += i
        s += prog(i)
        if q >= x:
            answer = max(answer, s - prog(q - x))
print(answer)


import io
import os
import functools
import itertools
import math
from queue import Queue

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline)

def prog(n):
    return (1+n)*n//2

n, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
arr = a*2
qu = Queue()
q, s = 0, 0
answer = 0
for i in arr:
    while q >= x:
        answer = max(answer, s - prog(q - x))
        p = qu.get()
        q -= p
        s -= prog(p)
    if i >= x:
        qu = Queue()
        qu.put(i)
        answer = max(answer, prog(i) - prog(i - x))
        s = prog(i)
        q = i
    else:
        qu.put(i)
        q += i
        s += prog(i)
        if q >= x:
            answer = max(answer, s - prog(q - x))
print(answer)


import io
import os
import functools
import itertools
import math
from queue import Queue

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def prog(n):
    return (1+n)*n//2

n, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
arr = a*2
qu = Queue()
q, s = 0, 0
answer = 0
for i in arr:
    while q >= x:
        answer = max(answer, s - prog(q - x))
        p = qu.get()
        q -= p
        s -= prog(p)
    if i >= x:
        qu = Queue()
        qu.put(i)
        answer = max(answer, prog(i) - prog(i - x))
        s = prog(i)
        q = i
    else:
        qu.put(i)
        q += i
        s += prog(i)
        if q >= x:
            answer = max(answer, s - prog(q - x))
print(answer)


import bisect
n, x = map(int, input().rstrip().split())
arr = list(map(int, input().rstrip().split()))
arr = [0] + arr + arr
prefixSum1 = [0]*(2*n+1)
prefixSum2 = [0]*(2*n+1)
for pos in range(1, 2*n+1):
    prefixSum1[pos] = prefixSum1[pos-1]+arr[pos]
    prefixSum2[pos] = prefixSum2[pos-1] + (arr[pos]*(arr[pos]+1))//2
maxHugs = 0
for pos in range(2*n, n, -1):
    leftLimit = bisect.bisect_left(prefixSum1, prefixSum1[pos]-x, 1, pos)
    temp = prefixSum1[pos] - prefixSum1[leftLimit-1] - x
    sumTemp = prefixSum2[pos] - prefixSum2[leftLimit-1]
    sumTemp -= (temp*(temp+1))//2
    maxHugs = max(maxHugs, sumTemp)
print(maxHugs)


from sys import stdin,stdout

n,x = map(int, stdin.readline().split())
d = list(map(int, stdin.readline().split()))
mxis = [0]
# get all max months
for i in range(n):
    if mxis[0]<d[i]:
        mxis = [d[i], i]
    elif mxis[0]==d[i]:
        mxis.append(i)

mx = mxis.pop(0)

if mx>=x:
    # x less than the largest month
    x = mx-x
    stdout.write(str( ((mx*(mx+1))>>1) - ((x*(x+1))>>1) ) + "\n")

else:
    x-=mx
    # x more than the largest month
    ans = 0
    for mi in mxis:
        i = (mi-1)%n
        j = (mi+1)%n
        rem = x
        total = 0
        while total<rem:
            if d[i]>rem:
                total+=(d[i]*(d[i]+1))>>1
                rem = d[i]-rem
                total -= (rem*(rem+1))>>1
                break
            elif d[j]>rem:
                total+=(rem*(rem+1))>>1
                break
            elif d[i]>d[j]:
                total+=(d[i]*(d[i]+1))>>1
                rem -= d[i]
                i = (i-1)%n
            else:
                total+=(d[j]*(d[j]+1))>>1
                rem -= d[j]
                j = (j+1)%n
        if total>ans:
            ans=total

    stdout.write(str(  ans+((mx*(mx+1)>>1))  ) + "\n")


from sys import stdin,stdout
nsum = lambda x:(x*(x+1))>>1

n,x = map(int, stdin.readline().split())
d = list(map(int, stdin.readline().split()))
presum_hugs = [nsum(d[0])]
presum_days = [d[0]]
for i in range(1,n):
    presum_hugs.append(presum_hugs[-1] + nsum(d[i]))
    presum_days.append(presum_days[-1] + d[i])
for i in range(n):
    presum_hugs.append(presum_hugs[-1] + nsum(d[i]))
    presum_days.append(presum_days[-1] + d[i])
ans=0
for start in range((n<<1)-1, n-1, -1):
    hi=start
    lo = hi-n+1
    while lo+1<hi:
        mid = (lo+hi)>>1
        if presum_days[start]-presum_days[mid-1] > x:
            lo = mid
            if presum_days[start]-presum_days[mid-1] == x:
                break
        else:
            hi = mid-1
    if presum_days[start]-presum_days[hi-1]>=x:
        lo=hi
    temp = presum_hugs[start] - presum_hugs[lo-1]
    extra = (presum_days[start]-presum_days[lo-1])-x
    if extra>0:
        temp -= nsum(extra)
    ans=max(ans, temp)

stdout.write(str(ans) + "\n")


n,x = map(int, input().split())
d = list(map(int, input().split()))*2
d.reverse()
ans = 0

nxt = 0
cur = 0
cnt = 0

for i in range(n):
    if i > 0:
        cnt -= d[i-1]
        cur -= (d[i-1] * (d[i-1] + 1))>>1
    while cnt + d[nxt] <= x:
        cnt += d[nxt]
        cur += (d[nxt] * (d[nxt] + 1))>>1
        nxt+=1
    rem = x - cnt
    val = ((d[nxt] + d[nxt] - rem + 1) * (rem))>>1 # counts the remaining days from the next month i.e. for 3 rem days and next month of 5, it gives 5+4+3
    ans = max(ans, cur + val)

print(ans)


import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, x = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
if x <= mx:
  print(mx * (mx + 1) // 2 - (mx - x) * (mx - x + 1) // 2)
  exit(0)
a = a + a
#print(a)
cs = [0] * (2 * N + 1)
for i in range(2 * N): cs[i + 1] = cs[i] + a[i]
cscalc = [0] * (2 * N + 1)
for i in range(2 * N): cscalc[i + 1] = cscalc[i] + a[i] * (a[i] + 1) // 2
#print(cscalc)
res = 0
for i in range(N + 1):
  r = bl(cs, cs[i] + x)
  t = x - (cs[r - 1] - cs[i])
  res = max(res, t * (t + 1) // 2 + cscalc[r - 1] - cscalc[i])
  ttt = x - (cs[r] - cs[i + 1])
  if a[i] >= ttt and (ttt >= 0):
    tt = a[i] * (a[i] + 1) // 2 - (a[i] - ttt) * (a[i] - ttt + 1) // 2
    res = max(res, tt + cscalc[r] - cscalc[i + 1])
    #print(res, t, tt, ttt, i, r)
print(res)


import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, x = map(int, input().split())
a = list(map(int, input().split()))
mx = max(a)
if x <= mx:
  print(mx * (mx + 1) // 2 - (mx - x) * (mx - x + 1) // 2)
  exit(0)
a = a + a
#print(a)
cs = [0] * (2 * N + 1)
for i in range(2 * N): cs[i + 1] = cs[i] + a[i]
cscalc = [0] * (2 * N + 1)
for i in range(2 * N): cscalc[i + 1] = cscalc[i] + a[i] * (a[i] + 1) // 2
#print(cscalc)
res = 0
for i in range(N + 1):
  r = bl(cs, cs[i] + x)
  t = x - (cs[r - 1] - cs[i])
  res = max(res, t * (t + 1) // 2 + cscalc[r - 1] - cscalc[i])
  if i:
    if a[i - 1] >= t:
      tt = a[i - 1] * (a[i - 1] + 1) // 2 - (a[i - 1] - t) * (a[i - 1] - t + 1) // 2
      res = max(res, tt + cscalc[r - 1] - cscalc[i])
      #print(res, tt, cscalc[r - 1] - cscalc[i])
print(res)


import sys
input = sys.stdin.buffer.readline

def check(num):
	for i in range(n):
		if values[i]>=num:
			return True
	return False

def calc():
	curr = days[0]
	j = -1
	while curr<=x:
		curr += days[j]
		j -= 1
	left = curr - x
	left = (left*(left+1))//2
	a = pref[0] + (pref[-1]-pref[j])
	ans = (a - left)
	values[0] = ans
	j += 1
	for i in range(1,n):
		# j += 1
		curr += days[i]
		curr -= days[j]
		while curr>x:
			j += 1
			curr -= days[j]
		curr = max(curr, 0)
		curr += days[j]
		left = curr-x
		left = (left*(left+1))//2
		if j<0:
			a = pref[i] + (pref[-1]-pref[j-1])
		elif j==0:
			a = pref[i]
		else:
			a = pref[i] - pref[j-1]
		# print (i,j,left,curr,a)
		values[i] = a - left

n,x = map(int,input().split())
days = list(map(int,input().split()))
count = []
for i in days:
	count.append((i*(i+1))//2)

prefix = [days[0]]
pref = [count[0]]
for i in range(1,n):
	prefix.append(prefix[-1]+days[i])
	pref.append(pref[-1]+count[i])
# print (prefix)
# print (count)
# print (pref)
if x==sum(days):
	print (pref[-1])
	exit()
values = [0]*n
calc()
# print (values)

maxx = sum(count)
low = 0
high = 10**18
while low<high:
	mid = (low+high)//2
	if check(mid):
		low=mid+1
	else:
		high=mid-1
if check(low):
	print (low)
else:
	print (low-1)


n,x = map(int,input().split())
end = list(map(int,input().split()))
a = []
for i in end:
    a += list(range(1,i+1))
tot = len(a) - 1
a = a[1:] + a
a.pop()
mx = float("-inf")
pre = tot
# print(a)
for i in range(n):
    pre += end[i]
    mx = max(mx,sum(a[pre-x:pre]))
print(mx)


n,x = map(int,input().split())
end = list(map(int,input().split()))
a = []
for i in end:
    a += list(range(1,i+1))
tot = len(a)
a += a
mx = float("-inf")
pre = tot
# print(a)
for i in range(n):
    pre += end[i]
    mx = max(mx,sum(a[pre-x:pre]))
print(mx)


def upper_bound(arr,l,r,x):
    start,end = l,r
    while l<=r:
        m = l + (r-l)//2
        if arr[m]>x: r = m-1
        else: l = m+1
    if start<=l<=end: return l
    return -1

n,x = map(int,input().split())
a = list(map(int,input().split()))
a += a
n *= 2
cur = 0
cur2 = 0
b = []
c = []
for i in range(n):
    cur += a[i]
    cur2 += a[i]*(a[i]+1)//2
    b.append(cur)
    c.append(cur2)
ans =  0
# print(b)
# print(c)
for i in range(n-1):
    if b[i+1]>=x:
        z = upper_bound(b,0,n,b[i+1]-x)
        cnt = c[i+1] - c[z]
        days = b[i+1] - b[z]
        extra = x - days
        # print(cnt,days,extra)
        cnt += a[z]*(a[z]+1)//2
        # print("*",z-1,a[z-1],cnt)
        cnt -= (a[z]-extra)*(a[z]-extra+1)//2
        # print(cnt)
        ans = max(ans,cnt)
print(ans)


def upper_bound(arr,l,r,x):
    start,end = l,r
    while l<=r:
        m = l + (r-l)//2
        if arr[m]>x: r = m-1
        else: l = m+1
    if start<=l<=end: return l
    return -1

n,x = map(int,input().split())
a = list(map(int,input().split()))
a += a
n *= 2
cur = cur2 = 0
b,c = [],[]
for i in range(n):
    cur += a[i]
    cur2 += a[i]*(a[i]+1)//2
    b.append(cur)
    c.append(cur2)
ans =  0
for i in range(n):
    if b[i]>=x:
        z = upper_bound(b,0,n,b[i]-x)
        cnt = c[i] - c[z]
        days = b[i] - b[z]
        extra = x - days
        cnt += a[z]*(a[z]+1)//2
        cnt -= (a[z]-extra)*(a[z]-extra+1)//2
        ans = max(ans,cnt)
print(ans)


from sys import stdin

input = stdin.readline

if __name__ == '__main__':
    n, x = map(int, input().split())
    arr = list(map(int, input().split()))

    arr += arr
    n = len(arr)

    parr = []

    p = 0
    mc = 0

    for i in reversed(range(n)):
        j = i - mc
        while j >= 0 and x - arr[j] >= 0:
            d = arr[j]
            mc += 1
            p += (d * (d + 1)) // 2
            x -= d
            j -= 1

        dl = 0

        if j >= 0 and x:
            d = arr[j]
            dl = d - x
            p += ((d * (d + 1)) // 2) - ((dl * (dl + 1)) // 2)
            x = 0

        parr.append(p)
        d = arr[i]
        p -= (d * (d + 1)) // 2
        mc -= 1
        x += d

        if dl:
            d = arr[j]
            p -= ((d * (d + 1)) // 2) - ((dl * (dl + 1)) // 2)
            x += d - dl

    print(max(parr))


"""
~~ Author : Bhaskar
~~ Dated : 31~05~2020
"""

# Method: Prefix Subarray & Binary Search :->

import sys
from bisect import *
# from math import floor,sqrt,ceil,factorial as F,gcd,pi
# from itertools import chain,combinations,permutations,accumulate
# from collections import Counter,defaultdict,OrderedDict,deque
# from array import array
from itertools import accumulate
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
Sum = lambda i : (i*(i+1))//2

def solve():
	n,x = map(int,sys.stdin.readline().split())
	a = list(map(int,sys.stdin.readline().split()))
	a = a+a
	aa = [Sum(i) for i in a]
	n = len(a)
	Prefix_a = [0] + list(accumulate(a))
	Prefix_suma = [0] + list(accumulate(aa))
	ans  = 0
	for i in range(n):
		if Prefix_a[i+1] >= x:
			z = bisect_right(Prefix_a,Prefix_a[i+1]-x)
			cnt = Prefix_suma[i+1]-Prefix_suma[z]
			days = Prefix_a[i+1] - Prefix_a[z]
			too = x - days
			cnt += Sum(a[z-1])
			cnt -= Sum(a[z-1]-too)
			ans = max(ans,cnt)
	print(ans)

if __name__ == "__main__":
    solve()


"""
~~ Author : Bhaskar
~~ Dated : 31~05~2020
"""

# Method: Prefix Subarray & Binary Search :->

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")
Sum = lambda i : (i*(i+1))//2

def solve():
	n,x = map(int,sys.stdin.readline().split())
	a = list(map(int,sys.stdin.readline().split()))
	a = a+a
	aa = [Sum(i) for i in a]
	n = len(a)
	Prefix_a = [0] + list(accumulate(a))
	Prefix_suma = [0] + list(accumulate(aa))
	ans  = 0
	for i in range(n):
		if Prefix_a[i+1] >= x:
			z = bisect_right(Prefix_a,Prefix_a[i+1]-x)
			cnt = Prefix_suma[i+1]-Prefix_suma[z]
			days = Prefix_a[i+1] - Prefix_a[z]
			too = x - days
			cnt += Sum(a[z-1])
			cnt -= Sum(a[z-1]-too)
			ans = max(ans,cnt)
	print(ans)

if __name__ == "__main__":
    solve()


from bisect import bisect_right

n,k=map(int,input().split())
ar=[int(x) for x in input().split()]
ar=ar*2
pref1=[]
pref2=[]

for i in range(len(ar)):
    if(i==0):
        pref1.append((ar[i]*(ar[i]+1))//2)
        pref2.append(ar[i])
    else:
        pref1.append(pref1[i-1]+(ar[i]*(ar[i]+1))//2)
        pref2.append(pref2[i-1]+ar[i])
ans=0
for i in range(len(ar)-1,-1,-1):
    pos=bisect_right(pref2,pref2[i]-k)

    val=(pref1[i]-pref1[pos])
    d=pref2[pos]-(pref2[i]-k)

    if(pos==0):
        break
    if(d<=ar[pos]):
        v=pref1[pos]-pref1[pos-1]
        s=((ar[pos]-d)*(ar[pos]-d+1))//2
        v-=s
        val+=v
        ans=max(ans,val)
print(ans)


import math

def summ(p):
    return p*(p+1)//2

[n,x] = list(map(int, input().split()))
p = list(map(int, input().split()))
m = [0]*(2*n)
for i in range(n):
    m[i] = p[i]
    m[n+i] = p[i]

m_sum = [0]*(2*n+1)
mm = m_sum[:]
for i in range(1,2*n+1):
    m_sum[i] = m_sum[i-1] + summ(m[i-1])
    mm[i] = mm[i-1] + m[i-1]
ans = 0
#print(m_sum)
#print(mm)
for i in range(n+1,2*n+1):
    up = i
    down = 1
    mid = (1+i)//2
    while True:
        #print(down, mid, up)
        if mm[i] - mm[mid-1] >= x > mm[i] - mm[mid]:
            z = mid
            break
        elif mm[i] - mm[mid-1] > x:

            down = mid + 1
            mid = (up+down)//2
        elif mm[i] - mm[mid-1] < x:

            up = mid - 1
            mid = (up+down)//2
    #rint(z)
    k = mm[i] - mm[z-1] - x
    temp = m_sum[i] - m_sum[z-1] - summ(k)
    #print(temp)
    if temp > ans:
        ans = temp

print(ans)


import math

def summ(p):
    return p*(p+1)//2

[n,x] = list(map(int, input().split()))
m = list(map(int, input().split()))
s = sum(m)

count = x
for i in range(n):
    if count - m[i] <= 0:
        j = count
        js = i
        break
    else:
        count -= m[i]

ans = 0
f = False
for i in range(n):
    for k in range(1,m[i]+1):
        #print(k,i,j,js)
        if f:
            temp = summ(m[i]) - summ(k-1)
            for y in range(i+1,n):
                temp += summ(m[y])
            for y in range(js):
                temp += summ(m[y])
            temp += summ(j)
            if temp > ans:
                ans = temp
            #print(temp)
        if not f:
            if js == i:
                temp = summ(j) - summ(k-1)
                if temp > ans:
                    ans = temp
            else:
                temp = summ(m[i]) - summ(k-1)
                for y in range(i+1,js):
                    temp += summ(m[y])
                temp += summ(j)
                if temp > ans:
                    ans = temp
            #print(temp)
        if js < n - 1:
            if j == m[js]:
                js += 1
                j = 1
            else:
                j += 1
        else:
            if j < m[js]:
                j += 1
            else:
                f = True
                js = 0
                j = 1

print(ans)


import math

def summ(p):
    return p*(p+1)//2

[n,x] = list(map(int, input().split()))
m = list(map(int, input().split()))
s = sum(m)
for i in range(n):
    m.append(m[i])

m_sum = [0]*(2*n+1)
mm = m_sum[:]
for i in range(1,2*n+1):
    m_sum[i] = m_sum[i-1] + summ(m[i-1])
    mm[i] = mm[i-1] + m[i-1]
ans = 0
#print(m_sum)
#print(mm)
for i in range(n+1,2*n+1):
    for j in range(i, -1, -1):
        if mm[i] - mm[j-1] >= x:
            z = j
            break
    #rint(z)
    k = mm[i] - mm[z-1] - x
    temp = m_sum[i] - m_sum[z-1] - summ(k)
    #print(temp)
    if temp > ans:
        ans = temp

print(ans)


#too messy way of writing
#missed a cornenr case during the contest,
#may still not work

import sys

def input():
	return sys.stdin.readline().rstrip()

def sum_first_n_numbers(a):
	return (a*(a+1))//2

n, x = [int(i) for i in input().split()]

n = 2*n
#x the number of days i spend doesnot exceed a whole year
#but i can do it interyear
days_per_month = [int(i) for i in input().split()]
days_per_month = days_per_month + (days_per_month) #solves my crossing a year problem

if (max(days_per_month) >= x):
	#trivial
	# print(1/0) #do later
	best = sum_first_n_numbers(max(days_per_month)) - sum_first_n_numbers(max(days_per_month) - x)
else:
	#bhaut fucked up code hoga
	#analyse corner cases later - full left, full right - dont need to vaise theyll be a part of the later
	left = 1
	right = 1#inclusive
	current = days_per_month[left]
	current_hugs = sum_first_n_numbers(days_per_month[left])
	best = 0
	while(True):
		if right<left:
			right = right + 1
			if (right == len(days_per_month) -1):
				break
			current_hugs += (days_per_month[right]*(days_per_month[right] + 1))//2
			current += days_per_month[right]

		elif (current + days_per_month[left -1] + days_per_month[right + 1] > x):
			#overflow
			#pakka pakka from left - right inclusive
			overflow = x - (current)
			d_left = days_per_month[left -1]
			d_right = days_per_month[right + 1]

			if overflow <= d_left:
				#add poora
				option1 = sum_first_n_numbers(d_left) - sum_first_n_numbers(d_left - overflow)
			elif d_left > d_right:
				option1 = sum_first_n_numbers(d_left) + sum_first_n_numbers(overflow - d_left)
			elif overflow < d_right:
				option1 = sum_first_n_numbers(overflow)
			else:
				option1 = sum_first_n_numbers(d_right) + sum_first_n_numbers(overflow - d_right)
			best = max(best, current_hugs + option1)

			# print('left, right, current hugs, option1,')
			# print(left, right, current_hugs, option1)
			current_hugs -= sum_first_n_numbers(days_per_month[left])
			current -= days_per_month[left]
			left = left + 1

		else:
			right = right + 1
			if (right == len(days_per_month) -1):
				break
			current_hugs += (days_per_month[right]*(days_per_month[right] + 1))//2
			current += days_per_month[right]

print(best)


#galti se i wrote d2 in d1 ka file

#too messy way of writing
#missed a cornenr case during the contest,
#may still not work

import sys

def input():
	return sys.stdin.readline().rstrip()

def sum_first_n_numbers(a):
	return (a*(a+1))//2

n, x = [int(i) for i in input().split()]

n = 2*n
#x the number of days i spend doesnot exceed a whole year
#but i can do it interyear
days_per_month = [int(i) for i in input().split()]
days_per_month = days_per_month + (days_per_month) #solves my crossing a year problem
hugs = [sum_first_n_numbers(i) for i in days_per_month]
pre_sum_hugs = [0]
pre_sum_days = [0]
for days, hug in zip(days_per_month,hugs):
	pre_sum_days.append(pre_sum_days[-1] + days)
	pre_sum_hugs.append(pre_sum_hugs[-1] + hug)

#presum i contains the sum of a0 a1..a(i-1)

left_partial = 0
right_partial = 0
best = 0
while(True):
	# assert right_partial != left_partial, "pointers shouldnt coincide"
	if right_partial == left_partial:
		right_partial += 1

	if right_partial == n:
		break

	in_between_days = pre_sum_days[right_partial] - pre_sum_days[left_partial+1]
	in_between_hugs = pre_sum_hugs[right_partial] - pre_sum_hugs[left_partial+1]

	d_left = days_per_month[left_partial]
	d_right = days_per_month[right_partial]
	#depending on the val of inbetween
	cap = d_left + d_right + in_between_days
	if cap < x:
		right_partial += 1

	elif cap >= x:
		#analyse
		#find best partial allotments
		# overflow = cap - x
		overflow = x - in_between_days

		if overflow >= d_left:
			#fill right first
			if overflow>=d_right:
				pending = overflow - d_right
				additional = sum_first_n_numbers(d_right) + sum_first_n_numbers(d_left) - sum_first_n_numbers(d_left - pending)
			else:
				 # d_right - overflow
				 additional = sum_first_n_numbers(d_right) - sum_first_n_numbers(d_right - overflow)

		else:
			#fill left first
			additional = sum_first_n_numbers(d_left) - sum_first_n_numbers(d_left - overflow)
		#cases
		# print('left_partial, right_partial, cap, overflow, in_between_hugs, additional')
		# print(left_partial, right_partial , cap, overflow,in_between_hugs,additional)
		best = max(best , additional + in_between_hugs)
		#then increase left

		left_partial = left_partial + 1

print(best)
#########################################################################
#WRONG
#rethink the logic with 2 pointers, wrong ans on test 7
#testcase7 -
# 4 14
# 4 9 2 7

# d1 ka solution commented below
# if (max(days_per_month) >= x):
# 	#trivial
# 	# print(1/0) #do later
# 	best = sum_first_n_numbers(max(days_per_month)) - sum_first_n_numbers(max(days_per_month) - x)
# else:
# 	#bhaut fucked up code hoga
# 	#analyse corner cases later - full left, full right - dont need to vaise theyll be a part of the later
# 	left = 1
# 	right = 1#inclusive
# 	current = days_per_month[left]
# 	current_hugs = sum_first_n_numbers(days_per_month[left])
# 	best = 0
# 	while(True):
# 		if right<left:
# 			right = right + 1
# 			if (right == len(days_per_month) -1):
# 				break
# 			current_hugs += (days_per_month[right]*(days_per_month[right] + 1))//2
# 			current += days_per_month[right]

# 		elif (current + days_per_month[left -1] + days_per_month[right + 1] > x):
# 			#overflow
# 			#pakka pakka from left - right inclusive
# 			overflow = x - (current)
# 			d_left = days_per_month[left -1]
# 			d_right = days_per_month[right + 1]

# 			if overflow <= d_left:
# 				#add poora
# 				option1 = sum_first_n_numbers(d_left) - sum_first_n_numbers(d_left - overflow)
# 			elif d_left > d_right:
# 				option1 = sum_first_n_numbers(d_left) + sum_first_n_numbers(overflow - d_left)
# 			elif overflow < d_right:
# 				option1 = sum_first_n_numbers(overflow)
# 			else:
# 				option1 = sum_first_n_numbers(d_right) + sum_first_n_numbers(overflow - d_right)
# 			best = max(best, current_hugs + option1)

# 			# print('left, right, current hugs, option1,')
# 			# print(left, right, current_hugs, option1)
# 			current_hugs -= sum_first_n_numbers(days_per_month[left])
# 			current -= days_per_month[left]
# 			left = left + 1

# 		else:
# 			right = right + 1
# 			if (right == len(days_per_month) -1):
# 				break
# 			current_hugs += (days_per_month[right]*(days_per_month[right] + 1))//2
# 			current += days_per_month[right]

# print(best)


import sys

def input():
	return sys.stdin.readline().rstrip()

def sum_first_n_numbers(a):
	return (a*(a+1))//2

n, x = [int(i) for i in input().split()]

n = 2*n
#x the number of days i spend doesnot exceed a whole year
#but i can do it interyear
days_per_month = [int(i) for i in input().split()]
days_per_month = days_per_month + (days_per_month) #solves my crossing a year problem

if (max(days_per_month) >= x):
	#trivial
	# print(1/0) #do later
	best = sum_first_n_numbers(max(days_per_month)) - sum_first_n_numbers(max(days_per_month) - x)
else:
	#bhaut fucked up code hoga
	#analyse corner cases later - full left, full right - dont need to vaise theyll be a part of the later
	left = 1
	right = 1#inclusive
	current = days_per_month[left]
	current_hugs = sum_first_n_numbers(days_per_month[left])
	best = 0
	while(True):
		if (current + days_per_month[left -1] + days_per_month[right + 1] > x):
			#overflow
			#pakka pakka from left - right inclusive
			overflow = x - (current)
			d_left = days_per_month[left -1]
			d_right = days_per_month[right + 1]

			if overflow <= d_left:
				#add poora
				option1 = sum_first_n_numbers(d_left) - sum_first_n_numbers(d_left - overflow)
			elif d_left > d_right:
				option1 = sum_first_n_numbers(d_left) + sum_first_n_numbers(overflow - d_left)
			elif overflow < d_right:
				option1 = sum_first_n_numbers(overflow)
			else:
				option1 = sum_first_n_numbers(d_right) + sum_first_n_numbers(overflow - d_right)
			best = max(best, current_hugs + option1)

			# print('left, right, current hugs, option1,')
			# print(left, right, current_hugs, option1)
			current_hugs -= sum_first_n_numbers(days_per_month[left])
			current -= days_per_month[left]
			left = left + 1

		else:
			right = right + 1
			if (right == len(days_per_month) -1):
				break
			current_hugs += (days_per_month[right]*(days_per_month[right] + 1))//2
			current += days_per_month[right]

print(best)


import java.lang.String.format
import java.util.*
import kotlin.math.*
import kotlin.system.exitProcess

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints

var sums: Array<Long>? = null
var indices: Array<Long>? = null
var n = 0
var x = 0
var sum: Long = 0
var cnt: Long = 0

fun main() {
    var (n1, x1) = readInts()
    n = n1; x = x1

    sums = Array(n + 1){0L}
    indices = Array(n + 1){0L}
    sums!![0] = 0
    indices!![0] = 0

    val ar = readInts()

    for (c in 0 until n) {
        val d = ar[c]
        cnt +=d
        sum += calcSum(d)
        indices!![c + 1] = cnt
        sums!![c + 1] = sum
    }

//    println(indices!!.joinToString(" "))
//    println(sums!!.joinToString(" "))

    var max: Long = 0
    for (i in 1 until n + 1) {
        var start = indices!![i] + 1 - x
        if (start <= 0) {
            start += cnt
        }

        val sumStart: Long = findSum(start)
        var curSum: Long = 0
        if (indices!![i] > start) {
            curSum = sums!![i] - sumStart

//            println(sums!![i])
//            println(sumStart)
//            println(indices!![i])
//            println("$start -> $i = $curSum ")
        }
        else {
            curSum = sum - sumStart + sums!![i] // Maybe index problems

//            println(sum)
//            println(sums!![i])
//            println(sumStart)
//            println(indices!![i])
//            println("$start -> $i = $curSum ")
        }

        if (curSum > max) {
            max = curSum
        }
    }

    print(max)
}

fun findSum1(start: Long): Long {
    for (i in n downTo 0) {
        if (indices!![i] < start) {
            val d = start - indices!![i]
            return sums!![i] + calcSum(d - 1)
        }
    }
    return -1
}

fun findSum(start: Long): Long {
    val i = findIndex(0, n, start)

    val d = start - indices!![i]
    return sums!![i] + calcSum(d - 1)

    return -1
}

fun findIndex(start: Int, end: Int, v: Long): Int {
    val mid = (start + end) / 2
    if (indices!![mid] >= v) {
        return findIndex(start, mid - 1, v)
    }

    if (mid == n - 1 || indices!![mid + 1] >= v) {
        return mid
    }

    return findIndex(mid + 1, end, v)
}

fun calcSum(n: Int): Long {
    return n.toLong() * (n + 1) / 2
}

fun calcSum(n: Long): Long {
    return n * (n + 1) / 2
}


import java.lang.String.format
import java.util.*
import kotlin.math.*
import kotlin.system.exitProcess

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints

var sums: Array<Long>? = null
var indices: Array<Long>? = null
var n = 0
var x = 0
var sum: Long = 0
var cnt: Long = 0

fun main() {
    var (n1, x1) = readInts()
    n = n1; x = x1

    sums = Array(n + 1){0L}
    indices = Array(n + 1){0L}
    sums!![0] = 0
    indices!![0] = 0

    val ar = readInts()

    for (c in 0 until n) {
        val d = ar[c]
        cnt +=d
        sum += calcSum(d)
        indices!![c + 1] = cnt
        sums!![c + 1] = sum
    }

    var max: Long = 0
    for (i in 1 until n + 1) {
        var start = indices!![i] + 1 - x
        if (start <= 0) {
            start += cnt
        }

//        println(indices!![i])
//        println("$start $i $n")

        val sumStart: Long = findSum(start)

//        println(sumStart)
        var curSum: Long = 0
        if (indices!![i] >= start) {
            curSum = sums!![i] - sumStart
        }
        else {
            curSum = sum - sumStart + sums!![i] // Maybe index problems
        }

        if (curSum > max) {
            max = curSum
        }
    }

    print(max)
}

fun findSum(start: Long): Long {
    val i = findIndex(0, n, start)

    val d = start - indices!![i]
    return sums!![i] + calcSum(d - 1)
}

fun findIndex(start: Int, end: Int, v: Long): Int {
    val mid = (start + end) / 2
    if (indices!![mid] >= v) {
        return findIndex(start, mid - 1, v)
    }

    if (mid == n - 1 || indices!![mid + 1] >= v) {
        return mid
    }

    return findIndex(mid + 1, end, v)
}

fun calcSum(n: Int): Long {
    return n.toLong() * (n + 1) / 2
}

fun calcSum(n: Long): Long {
    return n * (n + 1) / 2
}


import java.lang.String.format
import java.util.*
import kotlin.math.*
import kotlin.system.exitProcess

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of ints

var sums: Array<Long>? = null
var indices: Array<Long>? = null
var n = 0
var x: Long = 0
var sum: Long = 0
var cnt: Long = 0

fun main() {
    var (n1, x1) = readLongs()
    n = n1.toInt(); x = x1

    sums = Array(n + 1){0L}
    indices = Array(n + 1){0L}
    sums!![0] = 0
    indices!![0] = 0

    val ar = readInts()

    for (c in 0 until n) {
        val d = ar[c]
        cnt +=d
        sum += calcSum(d)
        indices!![c + 1] = cnt
        sums!![c + 1] = sum
    }

    var max: Long = 0
    for (i in 1 until n + 1) {
        var start = indices!![i] + 1 - x
        if (start <= 0) {
            start += cnt
        }

//        println(indices!![i])
//        println("$start $i $n")

        val sumStart: Long = findSum(start)

//        println(sumStart)
        var curSum: Long = 0
        if (indices!![i] >= start) {
            curSum = sums!![i] - sumStart
        }
        else {
            curSum = sum - sumStart + sums!![i] // Maybe index problems
        }

        if (curSum > max) {
            max = curSum
        }
    }

    print(max)
}

fun findSum(start: Long): Long {
    val i = findIndex(0, n, start)

    val d = start - indices!![i]
    return sums!![i] + calcSum(d - 1)
}

fun findIndex(start: Int, end: Int, v: Long): Int {
    val mid = (start + end) / 2
    if (indices!![mid] >= v) {
        return findIndex(start, mid - 1, v)
    }

    if (mid == n - 1 || indices!![mid + 1] >= v) {
        return mid
    }

    return findIndex(mid + 1, end, v)
}

fun calcSum(n: Int): Long {
    return n.toLong() * (n + 1) / 2
}

fun calcSum(n: Long): Long {
    return n * (n + 1) / 2
}


import kotlin.math.*

fun solve() {
    val (n, x) = readLine()!!.split(' ').map(String::toLong)
    var a = readLine()!!.split(' ').map(String::toInt).toMutableList()
    for (i in 0 until n.toInt()) {
        a.add(a[i])
    }
    var p = LongArray(2 * n.toInt() + 1) {0}
    var p2 = LongArray(2 * n.toInt() + 1) {0}
    for (i in 0 until 2 * n.toInt()) {
        p[i + 1] = p[i] + a[i]
        p2[i + 1] = p2[i] + 1L * a[i] * (a[i] + 1) / 2
    }
    var ans = 0L
    run {
        var j = 0
        for (i in 0 until n.toInt()) {
            while (p[j + 1] - p[i] <= x) {
                j += 1
            }
            ans = max(ans, p2[j] - p2[i] + 1L * (x - p[j] + p[i]) * (x - p[j] + p[i] + 1) / 2)
        }
    }
    run {
        var i = 0
        for (j in n.toInt() + 1 until 2 * n.toInt() + 1) {
            while (p[j] - p[i] > x) {
                i += 1
            }
            ans = max(ans, p2[j] - p2[i] + 1L * (x - p[j] + p[i]) * (2 * a[i - 1] - (x - p[j] + p[i]) + 1) / 2)
        }
    }
    println(ans)
}

fun main() {
    val t = 1; // readLine()!!.toInt()
    repeat (t) {
        solve()
    }
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

/**
 * 単調減少
 * [l, h) 方式
 */
fun findMax(l: Int, r: Int, f: (Int) -> Boolean): Int {
  var low = l
  var high = r + 1
  while(high - low > 1) {
    val m = (low + high) / 2
    if (f(m)) low = m
    else high = m
  }
  return low
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val X = ni()
    val D = na(N)
    val ix = LongArray(2 * N + 1)
    val cum = LongArray(2 * N + 1)
    for (i in 0 until 2 * N) {
      ix[i + 1] = ix[i] + D[i % N]
      cum[i + 1] = cum[i] + D[i % N].toLong() * (D[i % N] + 1) / 2
    }

    fun calcPos(pos: Long): Pair<Int, Int> {
      fun test(i: Int): Boolean {
        return ix[i] <= pos
      }

      val i = findMax(0, 2 * N - 1, ::test)
      val j = pos - ix[i]
      return Pair(i, j.toInt())
    }

    fun get(pos: Long): Int {
      val p = calcPos(pos)
      return p.second + 1
    }

    fun cumSum(pos: Long): Long {
//      debug{"cumSum($pos)"}
      if (pos == -1L) return 0
      val p = calcPos(pos)
      return cum[p.first] + (p.second + 1).toLong() * (p.second + 2) / 2
    }

    var ans = 1L
    for (i in 0 until N) {
      fun test(j: Int): Boolean {
        return j == 0 || j <= get(ix[i] + j + X - 1)
      }

      val j = findMax(0, D[i] - 1, ::test)
//      debug{"$i $j"}
      ans = max(ans, cumSum(ix[i] + j + X - 1) - cumSum(ix[i] + j - 1))
    }
    out.println(ans)
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

/**
 * 単調減少
 * [l, h) 方式
 */
fun findMax(l: Int, r: Int, f: (Int) -> Boolean): Int {
  var low = l
  var high = r + 1
  while(high - low > 1) {
    val m = (low + high) / 2
    if (f(m)) low = m
    else high = m
  }
  return low
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val X = nl()
    val D = na(N)
    val ix = LongArray(2 * N + 1)
    val cum = LongArray(2 * N + 1)
    for (i in 0 until 2 * N) {
      ix[i + 1] = ix[i] + D[i % N]
      cum[i + 1] = cum[i] + D[i % N].toLong() * (D[i % N] + 1) / 2
    }

    fun calcPos(pos: Long): Pair<Int, Int> {
      fun test(i: Int): Boolean {
        return ix[i] <= pos
      }

      val i = findMax(0, 2 * N - 1, ::test)
      val j = pos - ix[i]
      return Pair(i, j.toInt())
    }

    fun get(pos: Long): Int {
      val p = calcPos(pos)
      return p.second + 1
    }

    fun cumSum(pos: Long): Long {
      if (pos == -1L) return 0
      val p = calcPos(pos)
      debug{"cumSum($pos)=$p"}
      return cum[p.first] + (p.second + 1).toLong() * (p.second + 2) / 2
    }

    var ans = 1L
    for (i in 0 until N) {
      fun test(j: Int): Boolean {
        return j == 0 || j <= get(ix[i] + j + X - 1)
      }

      val j = findMax(0, D[i] - 1, ::test)
      debug{"$i $j"}
      ans = max(ans, cumSum(ix[i] + j + X - 1) - cumSum(ix[i] + j - 1))
    }
    out.println(ans)
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


import java.util.*
import java.io.*

val MOD = 924844033

fun main(args: Array<String>)
{
	Thread(null, Main(), "whatever", 1 shl 28).start()
}

class Main : Runnable {

	override fun run()
	{
		val inputStream = System.`in`
		val outputStream = System.out
		val `in` = InputReader(inputStream)
		val out = PrintWriter(outputStream)
		val solver = TaskD()
		var test = 1
		//test = `in`.nextInt()
		for (t in 1..test)
		{
			solver.solve(t, `in`, out)
		}
		out.close()
	}

	internal class TaskD
	{
		fun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {
			val INF = 4000000000000000000L
			val dx = intArrayOf(-1, 1, 0, 0)
			val dy = intArrayOf(0, 0, -1, 1)

			var n = `in`.nextInt()
			var X = `in`.nextLong()
			var a = LongArray(3*n+1)
			var b = LongArray(3*n+1)
			for (i in 1..n)
			{
				a[i] = `in`.nextLong()
				a[i+n] = a[i]
				a[i+2*n] = a[i]
			}
			for (i in 1..3*n)
			{
				b[i] = b[i-1]+a[i]*(a[i]+1)/2
				a[i] += a[i-1]
			}

			var j = 1
			var res = 0L
			for (i in 2..n+1)
			{
				while (a[j]-a[i-1] < X)
				{

					//out.println("$i $j")
					if (j < i)
					{
						var tmp = ((a[i]-a[i-1])*2-X+1)*X/2
						res = Math.max(res, tmp)
					}
					else
					{
						var remain = X-(a[j]-a[i-1])
						var L = Math.max(0, remain-(a[j+1]-a[j]))
						var R = Math.min(a[i-1]-a[i-2], remain)
						if (L <= R)
						{
							for (day in arrayOf(L, R))
							{
								var tmp = b[j]-b[i-1] + ((a[i-1]-a[i-2])*2-day+1)*day/2+(1+remain-day)*(remain-day)/2
								//out.println("$i $j $tmp")
								res = Math.max(res, tmp)
							}
						}
					}

					j += 1
				}
				j -= 1
			}

			out.println(res)
		}

	}

	internal class InputReader(stream: InputStream) {
		var reader: BufferedReader
		var tokenizer: StringTokenizer? = null

		init {
			reader = BufferedReader(InputStreamReader(stream), 32768)
			tokenizer = null
		}

		operator fun next(): String {
			while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
				try {
					tokenizer = StringTokenizer(reader.readLine())
				} catch (e: IOException) {
					throw RuntimeException(e)
				}

			}
			return tokenizer!!.nextToken()
		}

		fun nextInt(): Int {
			return Integer.parseInt(next())
		}

		fun nextLong(): Long {
		    return next().toLong()
		}

	}
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)

fun power(a: Long, b: Long, p: Long): Long
{
	if (b == 0L) return 1L
	var t = power(a, b/2, p)
	t = t*t%p
	if (b%2 == 1L) t = t*a%p
	return t
}


import java.util.*
import java.io.*

val MOD = 924844033

fun main(args: Array<String>)
{
	Thread(null, Main(), "whatever", 1 shl 28).start()
}

class Main : Runnable {

	override fun run()
	{
		val inputStream = System.`in`
		val outputStream = System.out
		val `in` = InputReader(inputStream)
		val out = PrintWriter(outputStream)
		val solver = TaskD()
		var test = 1
		//test = `in`.nextInt()
		for (t in 1..test)
		{
			solver.solve(t, `in`, out)
		}
		out.close()
	}

	internal class TaskD
	{
		fun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {
			val INF = 4000000000000000000L
			val dx = intArrayOf(-1, 1, 0, 0)
			val dy = intArrayOf(0, 0, -1, 1)

			var n = `in`.nextInt()
			var X = `in`.nextLong()
			var a = LongArray(3*n+1)
			var b = LongArray(3*n+1)
			for (i in 1..n)
			{
				a[i] = `in`.nextLong()
				a[i+n] = a[i]
				a[i+2*n] = a[i]
			}
			for (i in 1..3*n)
			{
				b[i] = b[i-1]+a[i]*(a[i]+1)/2
				a[i] += a[i-1]
			}

			var j = 2
			var res = 0L
			for (i in 2..n+1)
			{
				while (a[j]-a[i-1] < X) j += 1
				j -= 1

				//out.println("$i $j")
				if (j < i)
				{
					var tmp = ((a[i]-a[i-1])*2-X+1)*X/2
					res = Math.max(res, tmp)
					continue
				}

				var remain = X-(a[j]-a[i-1])
				var L = Math.max(0, remain-(a[j+1]-a[j]))
				var R = Math.min(a[i-1]-a[i-2], remain)
				if (L <= R)
				{
					for (day in arrayOf(L, R))
					{
						var tmp = b[j]-b[i-1] + ((a[i-1]-a[i-2])*2-day+1)*day/2+(1+remain-day)*(remain-day)/2
						res = Math.max(res, tmp)
					}
				}
			}

			out.println(res)
		}

	}

	internal class InputReader(stream: InputStream) {
		var reader: BufferedReader
		var tokenizer: StringTokenizer? = null

		init {
			reader = BufferedReader(InputStreamReader(stream), 32768)
			tokenizer = null
		}

		operator fun next(): String {
			while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
				try {
					tokenizer = StringTokenizer(reader.readLine())
				} catch (e: IOException) {
					throw RuntimeException(e)
				}

			}
			return tokenizer!!.nextToken()
		}

		fun nextInt(): Int {
			return Integer.parseInt(next())
		}

		fun nextLong(): Long {
		    return next().toLong()
		}

	}
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)

fun power(a: Long, b: Long, p: Long): Long
{
	if (b == 0L) return 1L
	var t = power(a, b/2, p)
	t = t*t%p
	if (b%2 == 1L) t = t*a%p
	return t
}


import java.util.*
import java.io.*

val MOD = 924844033

fun main(args: Array<String>)
{
	Thread(null, Main(), "whatever", 1 shl 28).start()
}

class Main : Runnable
{

	override fun run()
	{
		val inputStream = System.`in`
		val outputStream = System.out
		val `in` = InputReader(inputStream)
		val out = PrintWriter(outputStream)
		val solver = TaskD()
		var test = 1
		//test = `in`.nextInt()
		for (t in 1..test)
		{
			solver.solve(t, `in`, out)
		}
		out.close()
	}

	internal class TaskD
	{
		fun solve(testNumber: Int, `in`: InputReader, out: PrintWriter)
		{
			val INF = 4000000000000000000L
			val dx = intArrayOf(-1, 1, 0, 0)
			val dy = intArrayOf(0, 0, -1, 1)

			var n = `in`.nextInt()
			var x = `in`.nextLong()
			var a = LongArray(n*2+1)
			var b = LongArray(n*2+1)
			for (i in 1..n)
			{
				a[i] = `in`.nextLong()
				a[i+n] = a[i]
			}
			for (i in 1..n*2)
			{
				b[i] = b[i-1]+a[i]*(a[i]+1)/2
				a[i] += a[i-1]
			}
			var j = 0
			var res = 0L
			for (i in n+1..n*2)
			{
				while (a[i]-a[j] >= x) j++
				var sum = a[i]-a[j]
				var tmp = (2*(a[j]-a[j-1])-(x-sum)+1)*(x-sum)/2+b[i]-b[j]
				res = Math.max(res, tmp)
			}
			out.println(res)
		}
	}

	internal class InputReader(stream: InputStream) {
		var reader: BufferedReader
		var tokenizer: StringTokenizer? = null

		init {
			reader = BufferedReader(InputStreamReader(stream), 32768)
			tokenizer = null
		}

		operator fun next(): String {
			while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
				try {
					tokenizer = StringTokenizer(reader.readLine())
				} catch (e: IOException) {
					throw RuntimeException(e)
				}

			}
			return tokenizer!!.nextToken()
		}

		fun nextInt(): Int {
			return Integer.parseInt(next())
		}

		fun nextLong(): Long {
		    return next().toLong()
		}

	}
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)

fun power(a: Long, b: Long, p: Long): Long
{
	if (b == 0L) return 1L
	var t = power(a, b/2, p)
	t = t*t%p
	if (b%2 == 1L) t = t*a%p
	return t
}