#include using namespace std; #define rep(i,n) for(int i = 0;i < n;i++) using ll = long long; /* * Modint struct * library author : @snuke * */ const int mod = 1e9 + 7; struct mint { long long x; // typedef long long ll; mint(long long x=0):x((x%mod+mod)%mod){} mint& operator+=(const mint a) { if((x+=a.x)>=mod)x-=mod;return *this;} mint& operator-=(const mint a) { if((x+=mod-a.x)>=mod)x-=mod; return *this;} mint& operator*=(const mint a) { (x *=a.x)%=mod; return *this;} mint operator+(const mint a) const { mint res(*this);return res+=a;} mint operator-(const mint a) const { mint res(*this);return res-=a;} mint operator*(const mint a) const { mint res(*this);return res*=a;} mint pow(ll t) const { if (!t) return 1;mint a = pow(t>>1);a*=a; if (t&1) a *= *this;return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return (*this) *= a.inv();} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} mint v[3]; int main(void){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin >> n; rep(i,3){ ll x;cin >> x; v[i] = x; } n--; ll x = n / 6,y = n % 6; rep(i,3) v[i] *= mint(-27).pow(x); rep(i,y){ mint tmp[3]; rep(j,3) tmp[j] = v[j]; rep(j,3) v[j] = tmp[j] - tmp[(j+1) % 3]; } cout << v[0] << ' ' << v[1] << ' ' << v[2] << '\n'; return 0; }