#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) //#define ATCODER #ifdef ATCODER #include #endif typedef long long ll; typedef unsigned long long ull; #define LINF 9223300000000000000 #define LINF2 1223300000000000000 #define LINF3 1000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; #ifdef ATCODER using namespace atcoder; #endif void solve() { vector v0(4); ll n; scanf("%d%d%d%d%lld", &v0[0], &v0[1], &v0[2], &v0[3], &n); vector v(5); v[0] = v0[0]; vector v00 = v; map, int> mp; mp[v] = 0; int p = 0, q = 0; int found = 0; for (ll i = 1; i <= n; i++) { int i1 = i % 4; int i0 = (i + 3) % 4; int tmp = min(v[i0], v0[i1] - v[i1]); v[i1] += tmp; v[i0] -= tmp; v[4] = i1; auto it = mp.find(v); if (it != mp.end()) { found = 1; p = it->second; q = i; break; } mp[v] = (int)i; } if (found == 0) { printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]); } else { assert(n >= q); int r = (n - q) % (q - p); int x = p + r; v = v00; for (int i = 1; i <= x; i++) { int i1 = i % 4; int i0 = (i + 3) % 4; int tmp = min(v[i0], v0[i1] - v[i1]); v[i1] += tmp; v[i0] -= tmp; } printf("%d %d %d %d\n", v[0], v[1], v[2], v[3]); } return; } int main() { #if 1 solve(); #else int T, t; scanf("%d", &T); for (t = 0; t < T; t++) { //printf("Case #%d: ", t + 1); solve(); } #endif return 0; }