import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) import numpy as np mod = 10 ** 9 + 7 def getlist(): return list(map(int, input().split())) def matrixPow(A, n, N): #B:単位行列 演算の種類によって初期化方法を変える必要もある B = np.full((N, N), 0) for i in range(N): B[i, i] = 1 while n > 0: if n & 1 == 1: B = A @ B B = np.mod(B, mod) A = A @ A A = np.mod(A, mod) n = n >> 1 return B #処理内容 def main(): N = int(input()) A1, B1, C1 = getlist() start = np.array([[A1], [B1], [C1]]) mul = np.array([[1, -1, 0], [0, 1, -1], [-1, 0, 1]]) B = matrixPow(mul, N - 1, 3) # print(B) ans = B @ start ans = np.mod(ans, mod) # print(ans) anslist = [ans[0, 0], ans[1, 0], ans[2, 0]] print(*anslist) if __name__ == '__main__': main()