#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; //output(water); next_size = check.size(); }while(prev_size != next_size); //cout << "------------------------------" << endl; //output(history); 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; //cout << "prev:" << prev << endl; n -= need; if(n < 0){ need = 0; } //cout << "after:" << n << endl; int loop_size = history.size() - start_pos; int all = loop_size * 4; n %= all; //cout << "loop_size:" << loop_size << endl; //cout << "final:" << n << endl; vector ans; LL result_pos = start_pos; while(true){ if(n < 4){ ans = history.at(result_pos); //cout << "---------------" << endl; //output(ans); //cout << "=----------" << endl; break; } n %= 4; result_pos++; if(result_pos == history.size()){ result_pos = start_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; }