local mmi, mma = math.min, math.max local n, w = io.read("*n", "*n") local t = {} local a = {} for i = 1, n do a[i] = io.read("*n") end local left = 1 local sum = 0 local ret = 0 for i = 1, n do local ai = a[i] if t[ai] then local newleft = t[ai] + 1 for j = left, newleft - 1 do sum = sum - a[j] t[a[j]] = nil end left = newleft end t[ai] = i sum = sum + ai while w < sum do sum = sum - a[left] t[a[left]] = nil left = left + 1 end ret = mma(ret, i - left + 1) end print(ret)