import java.io.PrintWriter import scala.collection.mutable.* import scala.io.StdIn.* import scala.util.chaining.* import scala.math.* import scala.reflect.ClassTag import scala.util.* import scala.annotation.tailrec import scala.collection.mutable import scala.language.strictEquality inline val MOD = 1_000_000_007 class Matrix(val row: Int, val column: Int, val array: Array[Array[Long]]): def this(row: Int, column: Int)(generator: (Int, Int) => Long) = this(row, column, Array.tabulate(row){r => Array.tabulate(column){c => generator(r, c)}}) def *(other: Matrix): Matrix = val newRow = row val newColumn = other.column val mid = column Matrix(newRow, newColumn){(i, j) => (0 until mid).foldLeft(0L){(acc, k) => (acc + array(i)(k) * other.array(k)(j)) % MOD} } def pow(exp: Long): Matrix = var result = Matrix.e(row) var base = this var e = exp while e > 0 do if (e & 1) == 1 then result *= base base *= base e >>>= 1 result def apply(r: Int, c: Int): Long = array(r)(c) object Matrix: def e(size: Int): Matrix = Matrix(size, size) {(i, j) => if i == j then 1 else 0 } @main def main = val n = readLine.toLong val matrix = Matrix(4, 4, Array[Array[Long]](Array(0, 0, 1, 0), Array(0, 0, 0, 1), Array(1, 0, 1, 0), Array(1, 1, 2, 1))) val result = matrix.pow(n / 2) * Matrix(4, 1, Array[Array[Long]](Array(1), Array(1), Array(1), Array(3))) println(result((n % 2).toInt, 0))