#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; //#include // using namespace atcoder; // using mint = modint; #define rep(i, n) for (int i = 0; i < n; i++) #define endl '\n' #define print(n) cout << (n) << endl #define ALL(a) (a).begin(), (a).end() int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4; int vv = (v1 + 1) * (v1 + 1), vvv = vv * (v1 + 1); vector> a1(60, vector(vvv)); vector> a2(60, vector(vvv)); vector> a3(60, vector(vvv)); vector> a4(60, vector(vvv)); for (int i = 0; i <= v1; i++) { for (int j = 0; j <= v2; j++) { int s1 = i + j; if (s1 > v1) break; for (int k = 0; k <= v3; k++) { int s2 = s1 + k; if (s2 > v1) break; int key = vv * i + v1 * j + k; int l = v1 - s2; int ii = i, jj = j, kk = k, ll = l; jj += ii; ii = 0; if (jj > v2) { ii = jj - v2; jj = v2; } kk += jj; jj = 0; if (kk > v3) { jj = kk - v3; kk = v3; } ll += kk; kk = 0; if (ll > v4) { kk = ll - v4; ll = v4; } ii += ll; ll = 0; if (ii > v1) { ll = ii - v1; ii = v1; } a1[0][key] = ii; a2[0][key] = jj; a3[0][key] = kk; a4[0][key] = ll; } } } for (int idx = 1; idx < 60; idx++) { for (int i = 0; i <= v1; i++) { for (int j = 0; j <= v2; j++) { int s1 = i + j; if (s1 > v1) break; for (int k = 0; k <= v3; k++) { int s2 = s1 + k; if (s2 > v1) break; // int l = v1 - s2; int key1 = vv * i + v1 * j + k; int ii = a1[idx - 1][key1]; int jj = a2[idx - 1][key1]; int kk = a3[idx - 1][key1]; // int ll = a4[idx - 1][key1]; int key2 = vv * ii + v1 * jj + kk; int iii = a1[idx - 1][key2]; int jjj = a2[idx - 1][key2]; int kkk = a3[idx - 1][key2]; int lll = a4[idx - 1][key2]; a1[idx][key1] = iii; a2[idx][key1] = jjj; a3[idx][key1] = kkk; a4[idx][key1] = lll; } } } } ll k_; cin >> k_; ll k1 = k_ >> 2, k2 = k_ & 3; int i = v1, j = 0, k = 0, l = 0; for (int idx = 0; k1 != 0; idx++) { if ((k1 & 1) == 1) { int key = vv * i + v1 * j + k; int ii = a1[idx][key]; int jj = a2[idx][key]; int kk = a3[idx][key]; int ll = a4[idx][key]; i = ii; j = jj; k = kk; l = ll; } k1 >>= 1; } if (k2 == 0) { cout << i << " " << j << " " << k << " " << l << endl; return 0; } j += i; i = 0; if (j > v2) { i = j - v2; j = v2; } if (--k2 == 0) { cout << i << " " << j << " " << k << " " << l << endl; return 0; } k += j; j = 0; if (k > v3) { j = k - v3; k = v3; } if (--k2 == 0) { cout << i << " " << j << " " << k << " " << l << endl; return 0; } l += k; k = 0; if (l > v4) { k = l - v4; l = v4; } if (--k2 == 0) { cout << i << " " << j << " " << k << " " << l << endl; return 0; } i += l; l = 0; if (i > v1) { l = i - v1; i = v1; } if (--k2 == 0) { cout << i << " " << j << " " << k << " " << l << endl; return 0; } }