#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; 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; } using namespace std; typedef long long ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } using T = tuple; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; vector v(4); for(int i = 0; i < 4; i++) cin >> v[i]; ll n; cin >> n; auto calc = [&](int a, int b, int c, int cnt=4){ vector u = {a, b, c, v[0]-(a+b+c)}; // cout << "=====" << endl; // print_vector(u); for(int i = 0; i < cnt; i++){ int j = (i+1)%4; if(u[i]+u[j] >= v[j]){ u[i] -= v[j]-u[j]; u[j] = v[j]; }else{ u[j] += u[i]; u[i] = 0; } // print_vector(u); } return T(u[0], u[1], u[2]); }; auto nx = vec3d(v[0]+1, v[1]+1, v[2]+1, T(0, 0, 0)); for(int a = 0; a <= v[0]; a++){ for(int b = 0; a+b <= v[0] && b <= v[1]; b++){ for(int c = 0; a+b+c <= v[0] && c <= v[2]; c++){ nx[a][b][c] = calc(a, b, c); } } } auto dist = vec3d(v[0]+1, v[1]+1, v[2]+1, -1); T cur(v[0], 0, 0); dist[v[0]][0][0] = 0; vector path; int cycle_start = -1; int cycle_len = 0; while(true){ path.push_back(cur); auto [a, b, c] = cur; auto [aa, bb, cc] = nx[a][b][c]; if(dist[aa][bb][cc] == -1){ dist[aa][bb][cc] = dist[a][b][c]+1; cur = T(aa, bb, cc); }else{ cycle_start = dist[aa][bb][cc]; cycle_len = dist[a][b][c]+1-dist[aa][bb][cc]; break; } } ll len = n/4; int rem = n%4; if(len <= cycle_start){ auto [a, b, c] = path[len]; auto [aa, bb, cc] = calc(a, b, c, rem); cout << aa << ' ' << bb << ' ' << cc << ' ' << v[0]-(aa+bb+cc) << endl; }else{ int l = (len-cycle_start)%cycle_len; auto [a, b, c] = path[cycle_start+l]; auto [aa, bb, cc] = calc(a, b, c, rem); cout << aa << ' ' << bb << ' ' << cc << ' ' << v[0]-(aa+bb+cc) << endl; } }