#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int pow1(long long int a, long long int b,
                   long long int m = 1000000007) {
  if (b == 0)
    return 1ll;
  else if (b == 1)
    return a;
  else {
    long long int x = pow1(a, b / 2, m);
    x *= x;
    x %= m;
    if (b % 2) {
      x *= a;
      x %= m;
    }
    return x;
  }
}
template <class avgType>
avgType avg(avgType a, avgType b) {
  return (a + b) / 2;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
int randInt() { return rng() % INT_MAX; }
long long int randLL() { return rng64() % LLONG_MAX; }
vector<int> hashmods = {1000000007, 1000000009, 1000000021,
                        1000000033, 1000000087, 1000000093};
long long int n, x, d[1100000], sum[1100000], hugs[1100000], hugs_sum[1100000];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> x;
  for (int i = 1; i <= n; i++) cin >> d[i];
  for (int i = n + 1; i <= 2 * n; i++) {
    d[i] = d[i - n];
    hugs[i] = (d[i] * (d[i] + 1)) / 2;
    hugs[i - n] = hugs[i];
  }
  for (int i = 1; i <= 2 * n; i++) {
    sum[i] = sum[i - 1] + d[i];
    hugs_sum[i] = hugs_sum[i - 1] + hugs[i];
  }
  long long int ans = 0;
  for (int i = 1; i <= n; i++) {
    long long int req = sum[i - 1] + x;
    int beg = i, end = 2 * n, end_month = -1;
    while (beg <= end) {
      int mid = (beg + end) / 2;
      if (sum[mid] >= req) {
        end_month = mid;
        end = mid - 1;
      } else {
        beg = mid + 1;
      }
    }
    long long int first_month = x - (sum[end_month] - sum[i]);
    long long int middle_hugs = hugs_sum[end_month] - hugs_sum[i];
    long long int first_month_lef = d[i] - first_month;
    long long int curr =
        middle_hugs + (hugs[i] - (first_month_lef * (first_month_lef + 1)) / 2);
    ans = max(ans, curr);
  }
  cout << ans << "\n";
  return 0;
}
