#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ALL(x) (x).begin(), (x).end() #define PC(x) __builtin_popcount(x) #define PCL(x) __builtin_popcountll(x) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; typedef tuple tp; struct edge { int to, cost, id; }; const double PI = 3.14159265358979323846; const double PI2 = PI * 2.0; const double EPS = 1E-09; const ll MOD = 1E+09 + 7; // =998244353; const ll INFL = 1E18; const int INFI = 1E09; const int MAX_N = 2E+05; ll dx[4] = { 0, -1, 0, 1 }, dy[4] = { 1, 0, -1, 0 }; ll N; int V[4]; tp dp[101][101][101][65]; tp calc(tp t) { vector v; v.push_back(get<0>(t)); v.push_back(get<1>(t)); v.push_back(get<2>(t)); int sum = 0; for (int i = 0; i < 3; ++i) { sum += v[i]; } v.push_back(V[0] - sum); for (int i = 0; i < 4; ++i) { int next = (i + 1) % 4; if (V[next] - v[next] > v[i]) { v[next] += v[i]; v[i] = 0; } else { v[i] -= V[next] - v[next]; v[next] = V[next]; } } return { v[0], v[1], v[2] }; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> V[0] >> V[1] >> V[2] >> V[3] >> N; for (int v0 = 0; v0 <= V[0]; ++v0) { for (int v1 = 0; v0 + v1 <= V[0]; ++v1) { for (int v2 = 0; v0 + v1 + v2 <= V[0]; ++v2) { dp[v0][v1][v2][0] = calc({ v0, v1, v2 }); } } } for (int k = 0; k < 64; ++k) { for (int v0 = 0; v0 <= V[0]; ++v0) { for (int v1 = 0; v0 + v1 <= V[0]; ++v1) { for (int v2 = 0; v0 + v1 + v2 <= V[0]; ++v2) { auto t = dp[v0][v1][v2][k]; dp[v0][v1][v2][k + 1] = dp[get<0>(t)][get<1>(t)][get<2>(t)][k]; } } } } tp ans = { V[0], 0, 0 }; int kk = 0; ll r = N % 4; N /= 4; while (N > 0) { if (N & 1) { ans = dp[get<0>(ans)][get<1>(ans)][get<2>(ans)][kk]; } kk++; N /= 2; } vector v = { get<0>(ans), get<1>(ans), get<2>(ans) }; for (int i = 0; i < r; ++i) { int next = (i + 1) % 4; if (V[next] - v[next] > v[i]) { v[next] += v[i]; v[i] = 0; } else { v[i] -= V[next] - v[next]; v[next] = V[next]; } } // for (int i = 0; i < N; i++) { // for (int j = 0; j < N; j++) { // cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; // } // } int sum = v[0] + v[1] + v[2]; cout << v[0] << " " << v[1] << " " << v[2] << " " << V[0] - sum << "\n"; return 0; }