#if !__INCLUDE_LEVEL__ #include __FILE__ int main() { vl tmp(5);rep(i,5)cin >> tmp[i]; vl V(4);rep(i,4)V[i] = tmp[i]; ll N = tmp[4]; map,ll> State; map> Ind; State[{V[0],0,0,0,0}] = 0; Ind[0] = {V[0],0,0,0,0}; ll Loop = -1; ll Init = -1; int t = 0; vl W(4,0); W[0] = V[0]; rep(i,100000100){ ll sent = min({W[t],V[(t+1)%4]-W[(t+1)%4]}); W[(t+1)%4] += sent; W[t] -=sent; if(i+1==N){ cout << W << endl; exit(0); } if(State.count({W[0],W[1],W[2],W[3],(t+1)%4})==0){ State[{W[0],W[1],W[2],W[3],(t+1)%4}] = i+1; Ind[i+1] = {W[0],W[1],W[2],W[3],(t+1)%4}; } else{ Init = State[{W[0],W[1],W[2],W[3],(t+1)%4}]; Loop= i+1 - Init; break; } t+=1; t%=4; } N-=Init; N = N%Loop; ll v0,v1,v2,v3; tie(v0,v1,v2,v3,ignore) = Ind[Init+N]; cout << v0 << " " << v1 << " " << v2 << " " << v3 < #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i = 0; i < n; i++) #define rrep(i, n) for(int i = n; i >= 0; i--) #define range(i, m, n) for(int i = m; i < n; i++) #define fore(i,a) for(auto &i:a) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define sum(v) accumulate(all(v),0) typedef long long ll; typedef vector vl; typedef vector> vvl; const ll INF = 1e16; const ll MOD1 = 1000000007; const ll MOD2 = 998244353; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll SN(char s){return ll(s-'0');} ll SN(string s){return stoll(s);} int alpN(char s){return int(s-'a');} int AlpN(char s){return int(s-'a');} using Graph = vector>; using mint1 = modint1000000007; using mint2 = modint998244353; template ostream &operator<<(ostream &o,const vector&v){for(int i=0;i<(int)v.size();i++)o<<(i>0?" ":"")<