#![allow(unused_imports)] #![allow(dead_code)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] use std::cmp::*; use std::collections::*; use std::ops::*; use std::io::{Write, BufWriter}; // static MOD: usize = 998244353; static MOD: usize = 1000000007; // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 macro_rules! input { ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; } macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; } macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::>() }}; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; } use mod_int::ModInt; pub mod mod_int { use super::MOD; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign}; type Num = usize; #[derive(Clone, Copy, Debug)] pub struct ModInt(pub T); impl Add> for ModInt { type Output = ModInt; fn add(self, rhs: ModInt) -> ModInt { self + rhs.0 } } impl Add for ModInt { type Output = ModInt; fn add(self, rhs: Num) -> ModInt { let mut t = rhs + self.0; if t >= MOD { t = t - MOD; } ModInt(t) } } impl Sub for ModInt { type Output = ModInt; fn sub(self, rhs: Num) -> ModInt { let rhs = if rhs >= MOD { rhs % MOD } else { rhs }; let value = if self.0 < rhs { self.0 + MOD } else { self.0 }; ModInt(value - rhs) } } impl Sub> for ModInt { type Output = ModInt; fn sub(self, rhs: ModInt) -> ModInt { self - rhs.0 } } impl AddAssign for ModInt { fn add_assign(&mut self, other: Num) { *self = *self + other; } } impl AddAssign> for ModInt { fn add_assign(&mut self, other: ModInt) { *self = *self + other; } } impl SubAssign for ModInt { fn sub_assign(&mut self, other: Num) { *self = *self - other; } } impl SubAssign> for ModInt { fn sub_assign(&mut self, other: ModInt) { *self = *self - other; } } impl Div for ModInt { type Output = ModInt; fn div(self, rhs: Num) -> ModInt { self * ModInt(rhs).pow(MOD - 2) } } impl Div> for ModInt { type Output = ModInt; fn div(self, rhs: ModInt) -> ModInt { self / rhs.0 } } impl DivAssign for ModInt { fn div_assign(&mut self, rhs: Num) { *self = *self / rhs } } impl DivAssign> for ModInt { fn div_assign(&mut self, rhs: ModInt) { *self = *self / rhs } } impl Mul> for ModInt { type Output = ModInt; fn mul(self, rhs: ModInt) -> ModInt { self * rhs.0 } } impl Mul for ModInt { type Output = ModInt; fn mul(self, rhs: Num) -> ModInt { let t = (self.0 * rhs) % MOD; ModInt(t) } } impl MulAssign for ModInt { fn mul_assign(&mut self, rhs: Num) { *self = *self * rhs; } } impl MulAssign> for ModInt { fn mul_assign(&mut self, rhs: ModInt) { *self = *self * rhs; } } impl ModInt { pub fn pow(self, e: usize) -> ModInt { let mut result = ModInt(1); let mut cur = self; let mut e = e; while e > 0 { if e & 1 == 1 { result *= cur; } e >>= 1; cur *= cur; } result } } } fn solve() { input! { n: i64, } let k = ((n-4)%6)as usize; let x = ModInt(((n-4)/6 % MOD as i64) as usize); let mut ans = (ModInt(3)*x+k)*(x+1); if k==0 {ans = ModInt(3)*x*(x+1)+1;} let test = (3*x.0+k)%MOD*(x.0+1)%MOD; println!("{} ", ans.0); } fn main() { // In order to avoid potential stack overflow, spawn a new thread. let stack_size = 104_857_600; // 100 MB let thd = std::thread::Builder::new().stack_size(stack_size); thd.spawn(|| solve()).unwrap().join().unwrap(); }