#include using namespace std; int main() { int n, w; cin >> n >> w; vector a(n), s(n + 1); for (int i = 0; i < n; i++) { cin >> a.at(i); s.at(i + 1) = s.at(i) + a.at(i); } int discard = 0, ans = 0; set t; for (int i = 0; i < n; i++) { if (t.find(a.at(i)) == t.end()) { t.insert(a.at(i)); while (s.at(i + 1) - s.at(discard) > w) { t.erase(a.at(discard)); discard++; } } else { while (a.at(discard) != a.at(i)) { discard++; } discard++; } ans = max(ans, i + 1 - discard); } cout << ans << endl; }