#include using namespace std; typedef long long ll; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b V(4); for(int i=0;i<4;i++) cin>>V[i]; ll N;cin>>N; map,int> MA; vector now(4);now[0]=V[0]; MA[now]=0; int syuu=-1; for(int t=4;;t+=4){ for(int i=0;i<4;i++){ int x=min(now[i],V[(i+1)%4]-now[(i+1)%4]); now[i]-=x; now[(i+1)%4]+=x; } if(MA.count(now)){ syuu=t-MA[now]; break; }else{ MA[now]=t; } } ll can=N/syuu-2; chmax(can,0LL); for(int i=0;i<4;i++){ if(i==0) now[i]=V[0]; else now[i]=0; } for(ll t=0;t