N = int(input()) mod = 10**9 + 7 if N == 0: print(1) elif N == 1: print(12) elif N == 2: print(65) else: print((17 * N ** 2 + 6 * N + 1)%mod)