#include using namespace std; typedef long long LL; typedef long double LD; #define rep(i,n) for(LL i=0;i<(n);i++) template void output(vector &data){ rep(i,data.size()){ cout << data.at(i) << " "; } cout << endl; } template<> void output(vector &data){ rep(i,data.size()){ cout << data.at(i) << endl; } } template void output(vector> &data){ rep(i,data.size()){ rep(j,data.at(i).size()){ cout << data.at(i).at(j) << " "; } cout << endl; } } template <> void output(vector> &data){ rep(i,data.size()){ rep(j,data.at(i).size()){ if(data.at(i).at(j)){ cout << "*"; } else{ cout << "-"; } } cout << endl; } } template void input(vector &data,LL n){ rep(i,n){ LL a; cin >> a; data.push_back(a); } } template<> void input(vector &data,LL n){ rep(i,n){ string s; cin >> s; data.push_back(s); } } template void input(vector> &data,LL h, LL w){ rep(i,h){ vector add; rep(j,w){ T a; cin >> a; add.push_back(a); } data.push_back(add); } } int main(){ int n; vector v; vector water; input(v,4); cin >> n; rep(i,v.size()){ if(i == 0){ water.push_back(v.at(i)); } else{ water.push_back(0); } } set> check; check.insert(water); vector> history; vector last; int prev_size = check.size(); int next_size = check.size(); do{ prev_size = check.size(); history.push_back(water); rep(i,v.size()){ int from_pos = i; int to_pos = (i+1)%v.size(); int pur = std::min(water.at(from_pos),v.at(to_pos) - water.at(to_pos)); water.at(from_pos) -= pur; water.at(to_pos) += pur; } check.insert(water); last = water; next_size = check.size(); }while(prev_size != next_size); int start_pos = -1; // loop start rep(i,history.size()){ if(history.at(i) == last){ start_pos = i; break; } } int prev = start_pos; int need = prev * 4; int result_pos = start_pos; int reset_pos = start_pos; if(n >= need){ n -= need; } else{ result_pos = 0; reset_pos = 0; } int loop_size = history.size() - start_pos; int all = loop_size * 4; n %= all; vector ans; while(true){ if(n < 4){ ans = history.at(result_pos); break; } n %= 4; result_pos++; if(result_pos == history.size()){ result_pos = reset_pos; } } rep(i,n){ int from_pos = i; int to_pos = (i+1)%v.size(); int pur = std::min(ans.at(from_pos),v.at(to_pos) - ans.at(to_pos)); ans.at(from_pos) -= pur; ans.at(to_pos) += pur; } output(ans); return 0; } /* 9 5 7 4 0 */