/* MLE */ #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; const ll INF=1LL<<60; typedef pair P; typedef pair PP; const ll MOD=1e9+7; typedef tuple TP; //typedef vector TP; vector V(4); TP func(const TP& t,int idx){ TP res=t; auto [t0,t1,t2,t3]=t; if(idx==0){ get<0>(res) =t0 - min(V[1]-t1,t0); get<1>(res) =t1 + min(V[1]-t1,t0); } else if(idx==1){ get<1>(res) =t1 - min(V[2]-t2,t1); get<2>(res) =t2 + min(V[2]-t2,t1); }else if(idx==2){ get<2>(res) =t2 - min(V[3]-t3,t2); get<3>(res) =t3 + min(V[3]-t3,t2); }else if(idx==3){ get<3>(res) =t3 - min(V[0]-t0,t3); get<0>(res) =t0 + min(V[0]-t0,t3); } return res; } /* TP func(const TP &t,int idx){ TP res=t; get<0>(res); //変数でのアクセスが無理 get(res) = get(t) - ; res[idx]=t[idx] - min(V[(idx+1)%4] - t[(idx+1)%4],t[idx]); res[(idx+1)%4]=t[(idx+1)%4] + min(V[(idx+1)%4] - t[(idx+1)%4],t[idx]); return res; } */ int main(){ ll N; for(int i=0;i<4;i++){ cin>>V[i]; } cin>>N; vector history; map mp; auto now=make_tuple(V[0],0,0,0); int sz=0; int offset=-1; vector cyclehistory; while(1){ if(mp.count(now)){ if(offset==-1){ offset=mp[now]; cyclehistory.push_back(now); }else{ if(mp[now]==offset){ break; } cyclehistory.push_back(now); } }else{ mp[now]=sz; } history.push_back(now); auto nx=func(now,sz%4); /* for(int v:nx){ cout<