#include using namespace std; typedef long long ll; typedef long double ld; #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (int i = m; i < n; ++i) #define FORR(i, m, n) for (int i = m; i >= n; --i) #define ALL(v) (v).begin(),(v).end() #define ALLR(v) (v).rbegin(),(v).rend() #define fi first #define se second #define PB push_back #define EB emplace_back using P = pair; template using PQ = priority_queue; template using QP = priority_queue,greater>; templatevoid debug(const T &v,ll h,ll w){for(ll i=0;ivoid debug(const T &v,ll n){for(ll i=0;ivoid debug(const vector&v){debug(v,v.size());} templatevoid debug(const vector>&v){for(auto &vv:v)debug(vv,vv.size());} templatevoid debug(stack st){while(!st.empty()){cout<void debug(queue st){while(!st.empty()){cout<void debug(deque st){while(!st.empty()){cout<void debug(PQ st){while(!st.empty()){cout<void debug(QP st){while(!st.empty()){cout<void debug(const set&v){for(auto z:v)cout<void debug(const multiset&v){for(auto z:v)cout<void debug(const array &a){for(auto z:a)cout<void debug(const map&v){for(auto z:v)cout<<"["<bool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b v(4); REP(i,4) cin >> v[i]; int sv=0; REP(i,4) sv+=v[i]; ll n;cin >> n; vector nx(v[0]+1,vector(v[1]+1,vector>(v[2]+1))); REP(i,v[0]+1) REP(j,v[1]+1) REP(k,v[2]+1){ int l=v[0]-i-j-k; if(l<0) continue; array nv={i,j,k,l}; REP(x,4){ int d=clamp(v[(x+1)%4]-nv[(x+1)%4],0,nv[x]); nv[x]-=d; nv[(x+1)%4]+=d; } nx[i][j][k]={nv[0],nv[1],nv[2]}; // cerr << i << " " << j << " " << k << " " << l << endl; // cerr << nv[0] << " " << nv[1] << " " << nv[2] << " " << v[0]-nv[0]-nv[1]-nv[2] << endl; // cerr << endl; } int lgn=pophigh(n); vector db(lgn+1,vector(v[0]+1,vector(v[1]+1,vector>(v[2]+1)))); REP(i,v[0]+1) REP(j,v[1]+1) REP(k,v[2]+1){ if(i+j+k>v[0]) continue; db[0][i][j][k]=nx[i][j][k]; } REP(x,lgn){ REP(i,v[0]+1) REP(j,v[1]+1) REP(k,v[2]+1){ if(i+j+k>v[0]) continue; array t=db[x][i][j][k]; db[x+1][i][j][k]=db[x][t[0]][t[1]][t[2]]; } } ll nn=n/4; array now={v[0],0,0}; REP(bit,lgn+1){ array nxt; // cerr << nn << " " << bit << endl; if(nn&(1LL< ans{now[0],now[1],now[2],v[0]-now[0]-now[1]-now[2]}; REP(x,n%4){ int d=min(ans[x],v[(x+1)%4]-ans[(x+1)%4]); ans[x]-=d; ans[(x+1)%4]+=d; } cout << ans[0] << " " << ans[1] << " " << ans[2] << " " << v[0]-ans[0]-ans[1]-ans[2] << endl; }