from typing import List, Union class Matrix: mod = 998244353 mod = 10**9+7 def __init__(self, a: List[List[int]]) -> None: self.n = len(a) self.m = len(a[0]) if self.n > 0 else 0 self.a = a def __add__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): return Matrix([[(sij+other)%Matrix.mod for sij in si] for si, oi in self.a]) elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m return Matrix([[(sij+oij)%Matrix.mod for sij, oij in zip(si, oi)] for si, oi in zip(self.a, other.a)]) else: raise TypeError def __sub__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): return Matrix([[(sij-other)%Matrix.mod for sij in si] for si, oi in self.a]) elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m return Matrix([[(sij+oij)%Matrix.mod for sij, oij in zip(si, oi)] for si, oi in zip(self.a, other.a)]) else: raise TypeError def __mul__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): new = [a[:] for a in self.a] for i in range(self.n): for j in range(self.m): new[i][j] *= other new[i][j] %= Matrix.mod return Matrix(new) elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m new = [a[:] for a in self.a] for i in range(self.n): for j in range(self.m): new[i][j] *= other.a[i][j] new[i][j] %= Matrix.mod return Matrix(new) else: raise TypeError def __matmul__(self, other: "Matrix") -> "Matrix": if isinstance(other, Matrix): assert self.m == other.n return Matrix([[sum(map(lambda x, y: x*y[j]%Matrix.mod, ai, other.a))%Matrix.mod for j in range(other.m)] for ai in self.a]) else: raise TypeError def __pow__(self, n: int) -> "Matrix": assert isinstance(n, int) and self.n == self.m res = [[0]*self.m for _ in range(self.n)] for i in range(self.n): res[i][i] = 1 res = Matrix(res) a = Matrix([a[:] for a in self.a]) while n > 0: if n & 1 == 1: res @= a a @= a n >>= 1 return res def __radd__(self, other: Union[int, "Matrix"]) -> "Matrix": return self.__add__(other) def __rsub__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): return Matrix([[(other-sij)%Matrix.mod for sij in si] for si, oi in self.a]) elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m return Matrix([[(oij-sij)%Matrix.mod for sij, oij in zip(si, oi)] for si, oi in zip(self.a, other.a)]) else: raise TypeError def __rmul__(self, other: Union[int, "Matrix"]) -> "Matrix": return self.__mul__(other) def __iadd__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): for i in range(self.n): for j in range(self.m): self.a[i][j] += other self.a[i][j] %= Matrix.mod elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m for i in range(self.n): for j in range(self.m): self.a[i][j] += other.a[i][j] self.a[i][j] %= Matrix.mod else: raise TypeError return self def __isub__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): for i in range(self.n): for j in range(self.m): self.a[i][j] -= other self.a[i][j] %= Matrix.mod elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m for i in range(self.n): for j in range(self.m): self.a[i][j] -= other.a[i][j] self.a[i][j] %= Matrix.mod else: raise TypeError return self def __imul__(self, other: Union[int, "Matrix"]) -> "Matrix": if isinstance(other, int): for i in range(self.n): for j in range(self.m): self.a[i][j] *= other self.a[i][j] %= Matrix.mod elif isinstance(other, Matrix): assert self.n == other.n and self.m == other.m for i in range(self.n): for j in range(self.m): self.a[i][j] *= other.a[i][j] self.a[i][j] %= Matrix.mod else: raise TypeError return self def __getitem__(self, k): return self.a[k] def __str__(self): return str(self.a) A = Matrix([[1,-1,0],[0,1,-1],[-1,0,1]]) n = int(input()) a, b, c = map(int, input().split()) res = A ** (n-1) @ Matrix([[a],[b],[c]]) print(res[0][0], res[1][0], res[2][0])