class Integer def mod_inverse(mod) self.pow(mod - 2, mod) end end MOD = 10 ** 9 + 7 def mul(a, b) ret = Array.new(a.size) { Array.new(b[0].size, 0) } a.size.times do |i| b.size.times do |k| b[0].size.times do |j| ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % MOD end end end ret end def pow(a, n) h = a.size w = a[0].size ret = Array.new(h) { Array.new(w, 0) } h.times do |i| ret[i][i] = 1 end while n > 0 ret = mul(ret, a) if n % 2 == 1 a = mul(a, a) n /= 2 end ret end A = [ [1, 1, 1, 1, 1, 1], [6, 0, 0, 0, 0, 0], [0, 6, 0, 0, 0, 0], [0, 0, 6, 0, 0, 0], [0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 6, 0], ] N = gets.to_i B = pow(A, N) puts 6.pow(N, MOD).mod_inverse(MOD) * B[0][0] % MOD