#include long long modpow(long long n, long long k, long long m) { long long res = 1; while (k > 0) { if (k & 1) res = res * n % m; k = k >> 1; n = n * n % m; } return res; } int main() { long long n, a, b, c; std::cin >> n >> a >> b >> c; const long long mod = 1000000007; n--; long long loop = (n - 1) / 6; long long surp = 1 + (n - 1) % 6; long long A, B, C; A = a * modpow(-27, loop, mod) % mod; B = b * modpow(-27, loop, mod) % mod; C = c * modpow(-27, loop, mod) % mod; for (int i = 0; i < surp; i++) { long long nxtA, nxtB, nxtC; nxtA = (A - B) % mod; nxtB = (B - C) % mod; nxtC = (C - A) % mod; A = nxtA; B = nxtB; C = nxtC; //std::cout << A << " " << B << " " << C << std::endl; } if (A < 0) A = mod + A; if (B < 0) B = mod + B; if (C < 0) C = mod + C; std::cout << A << " " << B << " " << C << std::endl; }