use std::ops::{Mul, MulAssign}; #[derive(Clone)] struct Matrix { pub a: Vec>, } impl Matrix { const MOD: u64 = 1000000007; fn pow(self, mut n: usize) -> Matrix { let p = self.a.len(); let mut a = vec![vec![0u64; p]; p]; for i in 0..p { a[i][i] = 1; } let mut res = Matrix { a }; let mut x = self.to_owned(); while n > 0 { if n & 1 == 1 { res *= x.to_owned(); } x *= x.to_owned(); n >>= 1; } res } } impl Mul for Matrix { type Output = Matrix; fn mul(self, other: Matrix) -> Matrix { let p = self.a.len(); let q = other.a[0].len(); let r = other.a.len(); let mut a = vec![vec![0u64; q]; p]; for i in 0..p { for j in 0..q { for k in 0..r { a[i][j] += self.a[i][k] * other.a[k][j] % Self::MOD; a[i][j] %= Self::MOD; } } } Matrix { a } } } impl MulAssign for Matrix { fn mul_assign(&mut self, rhs: Matrix) { let p = self.a.len(); let q = rhs.a[0].len(); let r = rhs.a.len(); let mut a = vec![vec![0u64; q]; p]; for i in 0..p { for j in 0..q { for k in 0..r { a[i][j] += self.a[i][k] * rhs.a[k][j] % Self::MOD; a[i][j] %= Self::MOD; } } } self.a = a; } } fn main() { let n: usize = { let mut buf = String::new(); std::io::stdin().read_line(&mut buf).unwrap(); buf.trim_end().parse().unwrap() }; let mut a = vec![vec![0; 6]; 6]; for i in 0..6 { a[0][i] = 166666668; } for i in 0..5 { a[i + 1][i] = 1; } let mut b = vec![vec![0; 1]; 6]; b[0][0] = 1; let x = Matrix { a: a }; let y = Matrix { a: b }; let ans = x.pow(n) * y; println!("{}", ans.a[0][0]); }