You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. 

You immediately decided to take a vacation and visit Coronavirus-chan. Your vacation lasts exactly $x$ days and that's the exact number of days you will spend visiting your friend. You will spend exactly $x$ consecutive (successive) days visiting Coronavirus-chan.

They use a very unusual calendar in Naha: there are $n$ months in a year, $i$-th month lasts exactly $d_i$ days. Days in the $i$-th month are numbered from $1$ to $d_i$. There are no leap years in Naha.

The mood of Coronavirus-chan (and, accordingly, her desire to hug you) depends on the number of the day in a month. In particular, you get $j$ hugs if you visit Coronavirus-chan on the $j$-th day of the month.

You know about this feature of your friend and want to plan your trip to get as many hugs as possible (and then maybe you can win the heart of Coronavirus-chan). 

Please note that your trip should not necessarily begin and end in the same year.


-----Input-----

The first line of input contains two integers $n$ and $x$ ($1 \le n \le 2 \cdot 10^5$) — the number of months in the year and the number of days you can spend with your friend.

The second line contains $n$ integers $d_1, d_2, \ldots, d_n$, $d_i$ is the number of days in the $i$-th month ($1 \le d_i \le 10^6$).

It is guaranteed that $1 \le x \le d_1 + d_2 + \ldots + d_n$.


-----Output-----

Print one integer — the maximum number of hugs that you can get from Coronavirus-chan during the best vacation in your life.


-----Examples-----
Input
3 2
1 3 1

Output
5
Input
3 6
3 3 3

Output
12
Input
5 6
4 2 3 1 3

Output
15


-----Note-----

In the first test case, the numbers of the days in a year are (indices of days in a corresponding month) $\{1,1,2,3,1\}$. Coronavirus-chan will hug you the most if you come on the third day of the year: $2+3=5$ hugs.

In the second test case, the numbers of the days are $\{1,2,3,1,2,3,1,2,3\}$. You will get the most hugs if you arrive on the third day of the year: $3+1+2+3+1+2=12$ hugs.

In the third test case, the numbers of the days are $\{1,2,3,4,1,2, 1,2,3, 1, 1,2,3\}$. You will get the most hugs if you come on the twelfth day of the year: your friend will hug you $2+3+1+2+3+4=15$ times.

Difficulty: interview

Starter code:

Solutions:
def sum_first(di):
    return di * (di + 1) // 2


n, x = list(map(int, input().split()))
n *= 2
d = tuple(map(int, input().split())) * 2
ans = 0
i = 0
j = 0
cur_ans = 0
total_days = 0
while j <= n:
    if total_days < x:
        if j == n:
            break
        cur_ans += sum_first(d[j])
        total_days += d[j]
        j += 1
    else:
        ans = max(ans, cur_ans - sum_first(total_days - x))
        cur_ans -= sum_first(d[i])
        total_days -= d[i]
        i += 1
print(ans)


def sumprog(a, b):
    return (a + b) * (b - a + 1) // 2


n, x = map(int, input().split())
d = list(map(int, input().split())) * 2
max_hugs = 0
i = 0
j = 0
days = 0
hugs = 0
while i < n:
    if days + d[j] <= x:
        days += d[j]
        hugs += sumprog(1, d[j])
        j += 1
    else:
        max_hugs = max(max_hugs, hugs + sumprog(d[j] - (x - days) + 1, d[j]))
        hugs -= sumprog(1, d[i])
        days -= d[i]
        i += 1
print(max_hugs)

import sys
readline = sys.stdin.readline

N, X = list(map(int, readline().split()))
D = list(map(int, readline().split()))
AD = D+D + [0]
S = [d*(d+1)//2 for d in D]
S = S+S + [0]
for i in range(1, 2*N):
    AD[i] += AD[i-1]
    S[i] += S[i-1]

D = D + D + [0]

ans = 0
for r in range(N, 2*N):
    ng = -1
    ok = r
    while abs(ok-ng) > 1:
        med = (ok+ng)//2
        if AD[r] - AD[med] < X:
            ok = med
        else:
            ng = med
    l = ok
    res = S[r] - S[l-1] 
    dd = D[l] - (X-(AD[r]-AD[l])) 
    res -= dd*(dd+1)//2
    ans = max(ans, res)
print(ans)
    


import sys
input = sys.stdin.readline
n,x=map(int,input().split())
d=list(map(int,input().split()))
mx=0
i=n-1
j=n-1
k=0
cursum=0
miss=x
while d[j]<miss:
    miss-=d[j]
    cursum+=(d[j]*(d[j]+1))//2
    j-=1
k=d[j]-miss
cursum+=(d[j]*(d[j]+1))//2
cursum-=(k*(k+1))//2
miss=0
mx=cursum
while i>=0:
    miss=d[i]
    cursum-=(d[i]*(d[i]+1))//2
    cursum+=(k*(k+1))//2
    cursum-=(d[j]*(d[j]+1))//2
    miss-=k
    miss+=d[j]
    while d[j]<miss:
        miss-=d[j]
        cursum+=(d[j]*(d[j]+1))//2
        j-=1
        if j<0:
            j=n-1
    k=d[j]-miss
    cursum+=(d[j]*(d[j]+1))//2
    cursum-=(k*(k+1))//2
    miss=0
    mx=max(mx,cursum)
    i-=1
print(mx)

N, X = [int(_) for _ in input().split()]
D = [int(_) for _ in input().split()]

days_per_year = sum(D)
year_value = sum([(d * (d+1)) // 2 for d in D])


answer = year_value * (X // days_per_year)
X = X % days_per_year

# print('pre_answer', answer)
# print(X, 'days in last year to add')

answer_year = 0
i = N
pm = N-1
pd = D[N-1]
c = 0
to_add = None
while i >= 0:
    if i < N:
        c -= (D[i]*(D[i]+1))//2
    # print('after removing previous month', c)
    if to_add is None:
        to_add = X
    else:
        to_add = D[i]
    while D[pm] - (D[pm]-pd) <= to_add:
        to_add -= D[pm] - (D[pm]-pd)
        c += (pd*(pd+1))//2
        # print('after adding month', pm, ':', c)
        pm -= 1
        if pm < 0:
            pm = N-1
        pd = D[pm]
        # print('still', to_add, 'days to add')
    h = pd
    pd -= to_add
    l = pd
    # print(to_add, 'days to add', l, h)
    c += ((h*(h+1))//2) - ((l*(l+1))//2)
    # print('after adding last days', c)
    answer_year = max(answer_year, c)
    # print(i, c)
    i -= 1

answer += answer_year
print(answer)


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

d = [int(x) for x in input().split()]

dd = d + d

def b2(k):
    return k*(k+1)//2

# end_pt points to the month of which we want to end on the final day.
end_pt = 0
days = 0

# best keeps track of the best number of hugs we can get.
best = 0

# cur_hugs is the number of hugs we currently get if we end at the last day of
# month end_pt.
cur_hugs = b2(dd[0])
while days + dd[end_pt] < x:
    days += dd[end_pt]
    end_pt += 1
    cur_hugs += b2(dd[end_pt])

# start_pt points towards the month in which we start, specifically on day start_day
# we are doing our months 0-indexed (to match dd) but our days 1-indexed.
start_pt = 0
start_day = days + dd[end_pt] - x + 1

while start_day > dd[start_pt]:
    start_day -= dd[start_pt]
    cur_hugs -= b2(dd[start_pt])
    start_pt += 1

cur_hugs -= b2(start_day - 1)
best = cur_hugs

if False:
    print("Initial:")
    print("dd = ", dd)
    print("end_month = ", end_pt)
    print("start_month = ", start_pt)
    print("start_day = ", start_day)
    print("cur_hugs = best = ", best)

while end_pt + 1 < len(dd):
    end_pt += 1
    cur_hugs += b2(dd[end_pt])
    cur_hugs += b2(start_day - 1)
    start_day += dd[end_pt]
    while start_day > dd[start_pt]:
        start_day -= dd[start_pt]
        cur_hugs -= b2(dd[start_pt])
        start_pt += 1
    cur_hugs -= b2(start_day - 1)
    best = max(best, cur_hugs)

print(best)


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

def get_sum(l, r) :
    return sm(r) - sm(l - 1)

n, x = list(map(int, input().split()))
d = [int(i) for i in input().split()]
d = d[:] + d[:]
n *= 2
pre = [d[0]]
month, day, days, tot = n - 1, d[n - 1] + 1, 0, 0
ans = 0
for i in range(n - 1, -1, -1) :
    while days < x and month >= 0:
        if day > 1 :
            cnt = min(x - days, day - 1)
            tot += get_sum(day - cnt, day - 1)
            days += cnt
            day -= cnt
        else :
            month -= 1
            day = d[month] + 1
    ans = max(ans, tot)
    tot -= get_sum(1, d[i])
    days -= d[i]
print(ans)



from collections import deque
n,x = map(int,input().split())
d = list(map(int,input().split()))

q = deque([])
sum_q = 0

sq = deque([])
sum_sq = 0

for i in range(n):
    
    q.append(d[i])
    sum_q +=d[i]

    sq.append( (d[i]+1)*d[i]//2 )
    sum_sq += (d[i]+1)*d[i]//2

ans = 0

for i in range(n):

    q.append(d[i])
    sum_q += d[i]
    sq.append( (d[i]+1)*d[i]//2 )
    sum_sq += (d[i]+1)*d[i]//2

    while sum_q - q[0] >= x:
        sum_q  -= q.popleft()
        sum_sq -= sq.popleft()
    #print (q,sq,sum_q,sum_sq)

    origin = sum_sq - sq[0]
    remday = x - ( sum_q - q[0] )
    differ = (q[0] + q[0]-remday+1)*remday//2
    #print (origin,remday,differ)


    ans = max(ans , origin + differ)

print (ans)

from sys import stdin,stderr
def rl():
    return [int(w) for w in stdin.readline().split()]

n, end_day = rl()
d = rl()

start_month = start_day = end_month = hugs = 0
while end_month < n and end_day >= d[end_month]:
    hugs += (d[end_month] * (d[end_month] + 1)) // 2
    end_day -= d[end_month]
    end_month += 1
hugs += (end_day * (end_day + 1)) // 2

max_hugs = hugs
if end_month < n:
    while start_month < n:
        step = min(d[start_month] - start_day, d[end_month] - end_day)
        hugs += step * (end_day - start_day)
        start_day += step
        if start_day >= d[start_month]:
            start_day = 0
            start_month += 1
        end_day += step
        if end_day >= d[end_month]:
            end_day = 0
            end_month += 1
            if end_month >= n:
                end_month = 0
        if hugs > max_hugs:
            max_hugs = hugs

print(max_hugs)


import sys
input = sys.stdin.readline

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

D2=[x*(x+1)//2 for x in D]

from itertools import accumulate

S=[0]+list(accumulate(D+D))
S2=[0]+list(accumulate(D2+D2))

ANS=0

import bisect

for i in range(2*n+1):
    if S[i]-x<0:
        continue
    y=bisect.bisect_left(S,S[i]-x)

    score=S2[i]-S2[y]
    rest=x-(S[i]-S[y])

    #print(score,i,rest,D[(y-1)%n])
    MAX=D[(y-1)%n]

    score+=(MAX+(MAX-rest+1))*rest//2

    #print(score)

    ANS=max(ANS,score)

print(ANS)
    
    


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

arr += arr[::]
arr2 = [i * (i + 1) // 2 for i in arr]

ans = 0
for now_month in range(n, n * 2):
    if now_month == n:
        last_month = now_month
        count_obnim = 0
        count_days = 0
        while count_days + arr[last_month] <= x:
            count_days += arr[last_month]
            count_obnim += arr2[last_month]
            last_month -= 1

        dop_days = x - count_days
        nodop_days = arr[last_month] - dop_days
        dop_obnim = arr2[last_month] - nodop_days * (nodop_days + 1) // 2
        count_days += dop_days
        count_obnim += dop_obnim
    else:
        count_days += arr[now_month]
        count_days -= dop_days
        count_obnim += arr2[now_month]
        count_obnim -= dop_obnim

        while count_days > x:
            count_days -= arr[last_month + 1]
            count_obnim -= arr2[last_month + 1]
            last_month += 1

        dop_days = x - count_days
        nodop_days = arr[last_month] - dop_days
        dop_obnim = arr2[last_month] - nodop_days * (nodop_days + 1) // 2
        count_days += dop_days
        count_obnim += dop_obnim

    ans = max(ans, count_obnim)

print(ans)


n, x = list(map(int, input().split()))
d = list(map(int, input().split()))
accum = (3 * n) * [0]
accum2 = (3*n)*[0]
for i in range(3 * n):
    if i > 0:
        accum[i] = accum[i-1]
        accum2[i] = accum2[i-1]
    accum[i] += (((d[i % n] + 1) * d[i % n]) // 2)
    accum2[i] += d[i % n]

ans = 0
temp_ans = (d[0] + 1) * d[0] // 2
j = 0
days = d[0]
for i in range(n):
    while days < x:
        j += 1
        days += d[j % n]
        temp_ans += (d[j % n] + 1) * d[j % n] // 2

    dif = days - x
    if dif == 0:
        ans = max(temp_ans, ans)
    else:
        ans = max(temp_ans-(dif+1)*dif//2, ans)
    days -= d[i]
    temp_ans -= (d[i]+1)*d[i]//2
print(ans)


from bisect import *
n, x = list(map(int, input().split()))
d = list(map(int, input().split()))
d.extend(d)

date_acc = [0]
tot_acc = [0]
for i in range(n*2):
    date_acc.append(date_acc[i]+d[i])
    tot_acc.append(tot_acc[i]+(d[i]*(d[i]+1))//2)

ans = 0
for i in range(n+1, 2*n+1):
    now = date_acc[i]
    start_i = bisect_left(date_acc, now-x)
    start = date_acc[start_i]
    remain = x - (now - start)
    temp = tot_acc[i] - tot_acc[start_i]
    temp += (remain*(2*d[start_i-1]-remain+1))//2
    ans = max(ans, temp)

print(ans)


def right_m(me, num):
    k = min(me, num)
    return k * (k + 1) // 2
def left_m(me, num):
    k = me
    if me <= num:
        return k * (k + 1) // 2
    l = me - num
    return k * (k + 1) // 2 - l * (l + 1) // 2
def ans(lm, rm, num):
    if num <= lm:
        return left_m(lm, num)
    ans = right_m(rm, num)
    num -= rm
    if num > 0:
        ans += left_m(lm, num)
    return ans
n, x = map(int, input().split())
lst = list(map(int,input().split()))
daysnum = [0] * n * 2
ansnum = [0] * n * 2
daysnum[0] = lst[0]
ansnum[0] = (lst[0] + 1) * lst[0] // 2
for i in range(1, 2 * n):
    daysnum[i] = daysnum[i-1] + lst[i%n]
    ansnum[i] = ansnum[i-1] + (lst[i%n] + 1) * lst[i%n] // 2
leftnum = 0
rightnum = 1
maxans = 0
while leftnum < n and rightnum < 2 * n:
    if leftnum == rightnum:
        rightnum += 1
        continue
    ihave = x - daysnum[rightnum - 1] + daysnum[leftnum]
    if ihave < 0:
        leftnum += 1
        continue
    ansnow = ansnum[rightnum - 1] - ansnum[leftnum]
    ansnow += ans(lst[leftnum%n], lst[rightnum%n], ihave)
    maxans = max(maxans, ansnow)
    rightnum += 1
print(maxans)