#include #include using namespace std; typedef long long ll; int T; ll k,len[10]; ll cal(ll a,ll b,ll c) { return (2*a+(c-1)*b)*c/2; } ll cal2(ll a,ll b,ll c,ll d) { return a*d*c+(a+b*d)*(c-1)*c/2+b*(c-1)*c*(c*2-1)/6; } ll solve(ll n) { ll a=len[4],b,ans=1; ll t=min(n/4,a*2); if (t<=a) ans+=cal(4,4,n/4); else { ans+=cal(4,4,a); ans+=cal(a*4,-4,t-a); } for (int i=3;i>=1;i--) { a=len[i+1]; b=len[i]; t=min(n/i,b*2); if (b=1;i--) { a=len[i+1]; b=len[i]; t=min(n/i,b*2); if (b=1;i--) scanf("%lld",&len[i]); scanf("%lld",&k); ll l=0,r=1e10; while (l>1; if (solve(mid)>=k) r=mid;else l=mid+1; } printf("%lld\n",solve2(l)-(solve(l)-k)*l); } }