#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 void Put(vector c){ rep(i,4){ if(i!=0)cout<<' '; cout< v(4); rep(i,4)cin>>v[i]; vector c(4,0); c[0] = v[0]; long long N; cin>>N; deque> D; D.push_back(c); set> S; S.insert(c); { long long cur = 0; rep(i,Inf){ int x = i%4; int y = (i+1)%4; int m = min(v[y] - c[y],c[x]); c[x] -= m; c[y] += m; N--; if(N==0){ Put(c); } if(S.count(c)){ while(D.front()!=c)D.pop_front(); break; } else{ S.insert(c); D.push_back(c); } } } Put(D[N % D.size()]); return 0; }