#[doc = " https://github.com/hatoo/competitive-rust-snippets"] #[allow(unused_imports)] use std::cmp::{max, min, Ordering}; #[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque}; #[allow(unused_imports)] use std::io::{stdin, stdout, BufWriter, Write}; #[allow(unused_imports)] use std::iter::FromIterator; mod util { use std::fmt::Debug; use std::io::{stdin, stdout, BufWriter, StdoutLock}; use std::str::FromStr; #[allow(dead_code)] pub fn line() -> String { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.trim().to_string() } #[allow(dead_code)] pub fn chars() -> Vec { line().chars().collect() } #[allow(dead_code)] pub fn gets() -> Vec where ::Err: Debug, { let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace() .map(|t| t.parse().unwrap()) .collect() } #[allow(dead_code)] pub fn with_bufwriter) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[allow(unused_macros)] macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } const BIG_STACK_SIZE: bool = true; #[allow(dead_code)] fn main() { use std::thread; if BIG_STACK_SIZE { thread::Builder::new() .stack_size(32 * 1024 * 1024) .name("solve".into()) .spawn(solve) .unwrap() .join() .unwrap(); } else { solve(); } } #[allow(dead_code)] pub const M: u64 = 1_000_000_007; #[inline] fn add(x: u64, y: u64) -> u64 { let s = x + y; if s >= M { s - M } else { s } } #[derive(Debug, Eq, Hash, PartialEq, Clone)] struct Fib { a: u64, b: u64, } impl Fib { fn new() -> Fib { Fib { a: 0, b: 1 } } #[inline] fn next(&mut self) -> u64 { let t = self.a; self.a = self.b; self.b = add(self.b, t); self.a } } fn solve() { let table = [ (0, Fib { a: 0, b: 1 }), ( 999999734, Fib { a: 21, b: 999999994, }, ), ( 999397937, Fib { a: 999999020, b: 610, }, ), ( 671232238, Fib { a: 46368, b: 999971350, }, ), ( 410141410, Fib { a: 997821698, b: 1346269, }, ), ( 510853745, Fib { a: 102334155, b: 936754021, }, ), ( 44066357, Fib { a: 192473059, b: 971215059, }, ), ( 743595923, Fib { a: 851432142, b: 416138535, }, ), ( 72124658, Fib { a: 790216554, b: 470273943, }, ), ( 435523618, Fib { a: 8390086, b: 480986305, }, ), ( 128493982, Fib { a: 815449418, b: 923369890, }, ), ]; let n = get!(u64); let i = n / 1000000000; let j = n % 1000000000; let mut ans = table[i as usize].0; let mut fib = table[i as usize].1.clone(); for _ in 0..j { let t = fib.next(); ans = add(ans, t * t % M); } /* let mut ans = 0; let mut fib = Fib::new(); for i in 0..n + 1 { if i % 1000000000 == 0 { table.push((ans, fib.clone())); } let t = fib.next(); ans = add(ans, t * t % M); } debug!(table); */ println!("{}", ans); }