#include #include #include #include #include #include #include using namespace std; using ll = int64_t; #define rep(i, j, n) for (int i = j; i < (int)n; ++i) constexpr ll MOD = 1000000007; template class Matrix { public: vector> mat; Matrix(int h, int w) : mat(h, vector(w)) {} vector& operator[](int i) { return mat[i]; } const vector& operator[](int i) const { return mat[i]; } const size_t height() const { return mat.size(); } const size_t width() const { return mat[0].size(); } // only square matrix static Matrix identity(int n) { Matrix E(n, n); for (int i = 0; i < n; ++i) E[i][i] = 1; return E; } // O(N^3) Matrix& operator*=(const Matrix& m) { int h = m.height(), w = m.width(); vector> res(height(), vector(w)); for (int i = 0; i < height(); ++i) for (int k = 0; k < h; ++k) for (int j = 0; j < w; ++j) (res[i][j] += (*this)[i][k] * m[k][j] % MOD) %= MOD; mat.swap(res); return *this; } Matrix& operator*(const Matrix& rhs) { return Matrix(*this) *= rhs; } // O(N^3logK) Matrix operator^(T exponent) { Matrix res = Matrix::identity(height()); Matrix product = *this; while (exponent) { if (exponent & 1) res *= product; product *= product; exponent >>= 1; } return res; } }; int main() { ll n, a, b, c; cin >> n >> a >> b >> c; Matrix mat(3, 3); Matrix abc(3, 1); mat[0] = {1, MOD - 1, 0}; mat[1] = {0, 1, MOD - 1}; mat[2] = {MOD - 1, 0, 1}; abc[0] = {a}; abc[1] = {b}; abc[2] = {c}; mat = mat ^ (n - 1); mat *= abc; cout << mat[0][0] << " " << mat[1][0] << " " << mat[2][0] << endl; return 0; }