#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll sum=0; map memo;//Taroの手札,値が0=Draw,1=Taro,-1=Jiro; ll dfs(vl v){ if(memo.count(v))return memo[v]; ll x=sum;rep(i,5)x-=v[i];//x=Jiroの手札 set st; rep(i,4){ for(int j=1;j<=3;j++){ vl newv=v;newv[i]-=j; if(newv[i]<0)continue; //rep(k,4)cout << newv[k] <<" ";cout << endl; if(newv[i]==0){ if(newv[5]==1)newv[4]+=(x+1)/2; if(newv[5]==-1)newv[4]/=2; } if(newv[5]==1)newv[4]+=j; newv[5]*=-1; st.ins(dfs(newv)); } } if(st.count(v[5]))memo[v]=v[5]; else if(st.count(0))memo[v]=0; else memo[v]=-v[5]; return memo[v]; } int main(){ vl v(6);rep(i,4)cin >> v[i]; rep(i,4)sum+=v[i]; rep(i,sum+1){ vector vv(6);vv[4]=i;vv[5]=1; rep(j,2){ vv[5]*=-1; if(i==sum-i)memo[vv]=0; else if(i