#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; ll modulo(string &S, ll modc){ ll res = 0; for (auto x : S){ res *= 10; res += x-'0'; res %= modc; } return res; } int main(){ ll N, cnt=0, loop=-1, res; vector v(4); for (int i=0; i<4; i++) cin >> v[i]; cin >> N; vector x(5); x = {v[0], 0, 0, 0, 0}; map, int> mp; vector> a; while(cnt < N){ mp[x] = cnt; a.push_back(x); vector y = x; y[4] = (cnt+1)%4; y[(cnt+1)%4] += min(x[cnt%4], v[(cnt+1)%4]-x[(cnt+1)%4]); y[cnt%4] = x[cnt%4] - min(x[cnt%4], v[(cnt+1)%4]-x[(cnt+1)%4]); cnt++; swap(x, y); if (mp.count(x)){ loop = cnt-mp[x]; break; } } cnt -= loop; N -= cnt; N %= loop; res = N + cnt; x = a[res]; cout << x[0] << " " << x[1] << " " << x[2] << " " << x[3] << endl; return 0; }