func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<long long int> a, v, val;   long long int n, x;   long long int eval(long long int d, long long int i) {     if ((d + x - 1) <= a[i]) {       long long int ans = ((d + x - 1) * (d + x)) / 2 - ((d - 1) * (d)) / 2;       return ans;     } else {       long long int c = x - (a[i] - d + 1);       long long int l, r, mid, m, ans = 0;       l = i + 1;       r = 2 * n;       while (l <= r) {         mid = l + (r - l) / 2;         if ((v[mid] - v[i]) >= c) {           m = mid;           r = mid - 1;         } else           l = mid + 1;       }       ans += ((a[i]) * (a[i] + 1)) / 2 - ((d - 1) * (d)) / 2;       ans += val[m - 1] - val[i];       c -= v[m - 1] - v[i];       ans += c * (c + 1) / 2;       return ans;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int i, ans = 0, l, r, m1, m2, c, b;     cin >> n >> x;     a.resize(2 * n + 2);     v.resize(2 * n + 2);     val.resize(2 * n + 2);     for (i = 1; i <= n; i++) {       cin >> a[i];       a[i + n] = a[i];     }     for (i = 1; i <= 2 * n; i++) {       v[i] = v[i - 1] + a[i];       val[i] = val[i - 1] + (a[i] * (a[i] + 1)) / 2;     }     for (i = 1; i <= n; i++) {       l = 1;       r = a[i];       m1 = l;       while (l <= r) {         m1 = l + (r - l) / 3;         m2 = r - (r - l) / 3;         c = eval(m1, i);         b = eval(m2, i);         ans = max(ans, c);         ans = max(ans, b);         if (c >= b)           r = m2 - 1;         else           l = m1 + 1;       }       ans = max(ans, eval(m1, i));     }     cout << ans <<   n ;     return 0;   }   