#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
/* #pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
typedef unsigned long long ll;
const ll MAXN = 1e5 + 2;
const ll MAXK = 5e2 + 2;
const ll MOD = 1e9 + 7;
const ll MODH = 1e9 + 9;
const int MAXLG = 20;
const long double PI = acos(-1);
const ll sp = 41;
const long double EPS = 1e-4;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//inline ll rand(ll a, ll b) {ll c = rng(); return a+((ll)abs(c))%(b-a+1);}
//ll binpow(ll a, ll b, ll m) {a %= m;ll res = 1;while (b > 0) {if (b & 1){res = res * a % m;}a = a * a % m;b >>= 1;
//}return res;}
int main() {
int n;
ll k;
cin >> n >> k;
ll all = 0;
vector<int> a(n);
for(int i = 0 ; i < n ; i++){
cin >> a[i];
all+=a[i];
}
ll lo = 0 , hi = 1e9;
ll iter = 0;
while(lo <= hi)
{
ll mid = (lo + hi) / 2;
ll sum = mid * (mid + 1) / 2;
if(sum > k/all)
{
hi = mid - 1;
}
else
{
iter = mid;
lo = mid + 1;
}
}
ll Ans = iter * n;
k-=((iter * (iter + 1) / 2) * all);
if(iter & 1)
reverse(a.begin(),a.end());
for(int i = 0 ; i < n ; i++)
{
ll cost = (iter + 1) * a[i];
if( cost <= k)
{
Ans++;
k-=cost;
}
else
break;
}
cout << Ans;
}
Copy