import std; void main () { int N, X; readln.read(N, X); int[] A = readln.split.to!(int[]); // 累積 + 二分探索(2周) long[] cum = new long[](2*N+1); cum[0] = 0; for (int i = 1; i <= 2*N; i++) cum[i] = cum[i-1] + A[(i-1)%N]; bool f (int i, int x) { x++; // 1-indexed return cum[x] - cum[i] <= X; } long ans = 0; foreach (i; 0..N) { int ok = i, ng = i+N; while (1 < abs(ok-ng)) { int mid = (ok+ng) / 2; if (f(i, mid)) { ok = mid; } else { ng = mid; } } if (cum[ok+1]-cum[i] <= X) ans = max(ans, cum[ok+1]-cum[i]); } writeln(ans); } void read (T...) (string S, ref T args) { auto buf = S.split; foreach (i, ref arg; args) { arg = buf[i].to!(typeof(arg)); } }