pub trait SemiRing: Clone { fn zero() -> Self; fn one() -> Self; fn add(&self, rhs: &Self) -> Self; fn mul(&self, rhs: &Self) -> Self; } pub struct Kitamasa { c: Vec, tmp: std::cell::RefCell>, } impl Kitamasa { pub fn new(c: Vec) -> Self { assert!(!c.is_empty()); Self { c: c, tmp: std::cell::RefCell::new(vec![]), } } pub fn normalize(&self, d: &mut Vec) { let n = self.c.len(); for i in (n..d.len()).rev() { let v = d.pop().unwrap(); for (d, c) in d[(i - n)..].iter_mut().zip(&self.c) { *d = d.add(&v.mul(c)); } } } pub fn next(&self, d: &mut Vec) { d.insert(0, T::zero()); self.normalize(d); } pub fn twice(&self, d: &mut Vec) { assert!(!d.is_empty()); let mut tmp = self.tmp.borrow_mut(); tmp.clear(); tmp.resize(d.len() * 2 - 1, T::zero()); for (i, a) in d.iter().enumerate() { for (tmp, b) in tmp[i..].iter_mut().zip(d.iter()) { *tmp = tmp.add(&a.mul(b)); } } std::mem::swap(&mut *tmp, d); drop(tmp); self.normalize(d); } pub fn merge(&self, x: &[T], y: &[T]) -> Vec { assert!(x.len() > 0 && y.len() > 0); let mut res = vec![T::zero(); x.len() + y.len() - 1]; for (i, a) in x.iter().enumerate() { for (res, b) in res[i..].iter_mut().zip(y) { *res = a.mul(b).add(res); } } self.normalize(&mut res); res } pub fn kth_coefficient(&self, k: usize) -> Vec { let mut t = vec![T::one()]; if k > 0 { let p = (k + 1).next_power_of_two().trailing_zeros() - 1; for i in (0..=p).rev() { self.twice(&mut t); if k >> i & 1 == 1 { self.next(&mut t); } } } t.resize(self.c.len(), T::zero()); t } pub fn find_kth(&self, a: &[T], k: usize) -> T { assert_eq!(a.len(), self.c.len()); let d = self.kth_coefficient(k); a.iter() .zip(d) .fold(T::zero(), |s, a| a.0.mul(&a.1).add(&s)) } } const MOD: u64 = 1_000_000_007; impl SemiRing for u64 { fn zero() -> Self { 0 } fn one() -> Self { 1 } fn add(&self, rhs: &Self) -> Self { let mut v = *self + *rhs; if v >= MOD { v -= MOD; } v } fn mul(&self, rhs: &Self) -> Self { *self * *rhs % MOD } } // ---------- begin input macro ---------- // reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let s = { use std::io::Read; let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, bytes) => { read_value!($iter, String).bytes().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } // ---------- end input macro ---------- use std::io::Write; use std::collections::*; type Map = BTreeMap; type Set = BTreeSet; type Deque = VecDeque; fn run() { input! { n: u64, } let m = n / 2; let ans = if n % 2 == 0 { let kita = Kitamasa::new(vec![1, 1]); kita.find_kth(&[1, 1], m as usize) } else { let kita = Kitamasa::new(vec![2, 1, MOD - 2, MOD - 1]); kita.find_kth(&[1, 2, 4, 10], m as usize) * ((n + 1) / 2 % MOD) % MOD }; println!("{}", ans); } fn main() { run(); }