#include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; typedef long long ll; #define rep(i,n) for (int i = 0; i < int(n);i++) int main(){ int a,b = 0,c = 0,d = 0,v1,v2,v3,v4; ll n; cin >> v1 >> v2 >> v3 >> v4 >> n; map mp; vector val; a = v1; ll count = 0; mp[1000000000LL*a + 1000000LL*b + 1000LL*c + d] = count; count++; val.push_back(1000000000LL*a + 1000000LL*b + 1000LL*c + d); ll offset = 0; ll s = 0; ll loopsize = 0; int trun = 0; a = v1; while(1){ if (trun == 0){ int diff = v2-b; b += min(a,v2-b); a -= min(a,diff); } else if (trun == 1){ int diff = v3-c; c += min(b,diff); b -= min(b,diff); } else if (trun == 2){ int diff = v4-d; d += min(c,diff); c -= min(c,diff); } else{ int diff = v1-a; a += min(d,diff); d -= min(d,diff); } ll hash = 1000000000LL*a + 1000000LL*b + 1000LL*c + d; if (mp.count(hash)){ loopsize = count-mp[hash]; offset = mp[hash]; s = hash; break; } mp[hash] = count; val.push_back(hash); count++; trun++; trun%=4; } //for (auto y:val){ // cout << y << " "; //} //cout << endl; if (n <= offset){ vector ans(4); ll z = val[n]; for (int i = 0; i < 4;i++){ ans[3-i] = z%1000; z/=1000; } for (int i = 0; i < 4;i++){ if (i == 0) cout << ans[i]; else cout << " " << ans[i]; } cout << endl; } else{ n -= offset; n%=loopsize; vector ans(4); ll z = val[n+offset]; for (int i = 0; i < 4;i++){ ans[3-i] = z%1000; z/=1000; } for (int i = 0; i < 4;i++){ if (i == 0) cout << ans[i]; else cout << " " << ans[i]; } cout << endl; } return 0; }