#include #ifdef LOCAL #include "./debug.cpp" #else #define debug(...) #define print_line #endif using namespace std; using ll = long long; int main() { int N; ll X; cin >> N >> X; vector A(2 * N); for (int i = 0; i < N; i++) { cin >> A[i]; A[i + N] = A[i]; } ll ans = 0, now = 0; int l = 0, r = 0; while (l < N) { while (r < l + N && now + A[r] < X) { now += A[r]; ans = max(ans, now); r++; } now -= A[l]; l++; if (r < l) { r = l; now = 0; } } cout << ans << endl; }