#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template void chmin(T &a,const T &b){if(a>b) a=b;} template void chmax(T &a,const T &b){if(a vec;//ll? typedef vector mat; typedef long long ll; mat mul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size())); for(int i=0;i0){ if(n&1) B=mul(B,A); A=mul(A,A); n=(n>>1); } return B; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll N; cin>>N; vector A(3); rep(i,3) cin>>A[i]; mat M(3,vec(3,0)); M[0][0]=1;M[0][1]=-1; M[1][1]=1;M[1][2]=-1; M[2][2]=1;M[2][0]=-1; mat R=pow(M,N-1); mat ans(3,vec(1,0)); /*ans[0][0]=A;ans[1][0]=B;ans[2][0]=C; ans=mul(M,ans); rep(i,3) (ans[i][0]+=MOD)%=MOD;*/ rep(i,3){ rep(j,3){ ans[i][0]+=R[i][j]*A[j]%MOD; ans[i][0]+=MOD; ans[i][0]%=MOD; } } cout<