#include using namespace std; using ll=long long; using vin=vector; using vll=vector; using vvin=vector>; using vvll=vector>; using vstr=vector; using vvstr=vector>; using vch=vector; using vvch=vector>; using vbo=vector; using vvbo=vector>; using vpii=vector>; using pqsin=priority_queue,greater>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<>=1; } return res; } int main(){ ll n;cin>>n; ll a,b,c;cin>>a>>b>>c; ll x,y,z; ll k=n/2; if(n%2==0){ ll tmp=modpow((ll)3,k-1,inf); if(k%2==0)tmp*=-1; if(n==2){ x=a-b; y=b-c; z=c-a; } else{ x=(tmp*(b-c))%inf; y=(tmp*(c-a))%inf; z=(tmp*(a-b))%inf; } } else{ ll tmp=modpow((ll)3,k,inf); if(k%2)tmp*=-1; if(n==3){ x=a-2*b+c; y=b-2*c+a; z=c-2*a+b; } else{ x=(tmp*b)%inf; y=(tmp*c)%inf; z=(tmp*a)%inf; } } if(x<0)x+=inf; if(y<0)y+=inf; if(z<0)z+=inf; cout<