#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; ll N, X, A[202020], sum[404040]; int main() { cin >> N >> X; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < 2 * N; i++) { sum[i + 1] = sum[i] + A[i % N]; } ll ans = 0; int r = 0; for (int l = 0; l < 2 * N; l++) { while (r < 2 * N && r - l + 1 <= N && sum[r + 1] - sum[l] <= X) { ans = max(ans, sum[r + 1] - sum[l]); r++; } } cout << ans << endl; return 0; }