#include using namespace std; using ll = long long; #define rep(i,m,n) for(int i=m; i bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } template bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll X; cin >> N >> X; vector A(N); rep(i, 0, N) cin >> A[i]; if(accumulate(all(A), 0) <= X){ cout << accumulate(all(A), 0LL) << endl; return 0; } vector B; rep(i, 0, 2) rep(j, 0, N) B.push_back(A[j]); vector sum(2*N + 1, 0LL); rep(i, 0, 2*N) sum[i+1] = sum[i] + B[i]; ll ans = 0LL; for(ll s : sum){ auto itr = upper_bound(all(sum), s + X); --itr; chmax(ans, *itr - s); } cout << ans << endl; return 0; }