#![allow(dead_code, unused_macros, unused_imports)]
use std::{cell::{Cell, RefCell, UnsafeCell}, cmp::{Ordering, Reverse, max, min}, collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, hash_map::{DefaultHasher, RandomState}}, error::Error, fmt::{Display, Write as FmtWrite}, hash::{BuildHasher, Hash, Hasher}, io::{BufWriter, Read, Stdin, Stdout, Write}, iter::{FromIterator, Peekable}, mem::swap, ops::*, process::exit, rc::Rc, str::{FromStr, from_utf8_unchecked}, time::{Duration, Instant}, convert::{TryInto, TryFrom}, marker::PhantomData};

const IO_BUF_SIZE: usize = 1 << 16;
type Input = Scanner<Stdin>;
type Output = BufWriter<Stdout>;
fn _init_input() -> Input { Scanner::new(std::io::stdin()) }
fn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) }

#[repr(transparent)] struct Unsync<T>(T);
unsafe impl<T> Sync for Unsync<T> {}

type BadLazy<T> = Unsync<UnsafeCell<Option<T>>>;
impl<T> BadLazy<T> {
    const fn new() -> Self { Self(UnsafeCell::new(None)) }
}

static INPUT: BadLazy<Input> = BadLazy::new();
static OUTPUT: BadLazy<Output> = BadLazy::new();

fn inp<F: FnOnce(&mut Input) -> R, R>(f: F) -> R {
    unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) }
}
fn out<F: FnOnce(&mut Output) -> R, R>(f: F) -> R {
    unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) }
}

macro_rules! read {
    () => { read() };
    ($t: ty) => { read::<$t>() };
    ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) };
    [$t: ty; $n: expr] => { read_vec::<$t>($n) };
}
macro_rules! println {
    () => { out(|x| { let _ = writeln!(x); }) };
    ($exp: expr) => { out(|x| { let _ = writeln!(x, "{}", $exp); }) };
    ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = writeln!(x, $fmt, $($arg)*); }) }
}
macro_rules! print {
    ($exp: expr) => { out(|x| { let _ = write!(x, "{}", $exp); }) };
    ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = write!(x, $fmt, $($arg)*); }) }
}

fn out_flush() { out(|x| { let _ = x.flush(); }); }

fn input_is_eof() -> bool { inp(|x| x.eof()) }
fn read_byte() -> u8 { inp(|x| x.byte()) }
fn read_bytes_no_skip(n: usize) -> Vec<u8> { inp(|x| x.bytes_no_skip(n)) }
fn read_bytes(n: usize) -> Vec<u8> { inp(|x| x.bytes(n)) }
fn read_bytes2(n: usize, m: usize) -> Vec<Vec<u8>> { inp(|x| x.bytes2(n, m)) }
fn read_token() -> Vec<u8> { inp(|x| x.token_bytes()) }
fn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } }
fn read_line() -> Vec<u8> { inp(|x| x.line_bytes()) }
fn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } }
fn read<T: FromStr>() -> T { read_token_str().parse::<T>().ok().expect("failed parse") }
fn read_vec<T: FromStr>(n: usize) -> Vec<T> { (0..n).map(|_| read()).collect() }
fn read_vec2<T: FromStr>(n: usize, m: usize) -> Vec<Vec<T>> { (0..n).map(|_| read_vec(m)).collect() }

struct Scanner<R: Read> {
    src: R,
    _buf: Vec<u8>,
    _pt: usize, // pointer
    _rd: usize, // bytes read
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(src: R) -> Scanner<R> {
        Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }
    }

    fn _check_buf(&mut self) {
        if self._pt == self._rd {
            self._rd = self.src.read(&mut self._buf).unwrap_or(0);
            self._pt = (self._rd == 0) as usize;
        }
    }

    // returns true if end of file
    fn eof(&mut self) -> bool {
        self._check_buf();
        self._rd == 0
    }

    // filters \r, returns \0 if eof
    fn byte(&mut self) -> u8 {
        loop {
            self._check_buf();
            if self._rd == 0 { return 0; }
            let res = self._buf[self._pt];
            self._pt += 1;
            if res != b'\r' { return res; }
        }
    }

    fn bytes_no_skip(&mut self, n: usize) -> Vec<u8> { (0..n).map(|_| self.byte()).collect() }
    fn bytes(&mut self, n: usize) -> Vec<u8> {
        let res = self.bytes_no_skip(n);
        self.byte();
        res
    }
    fn bytes2(&mut self, n: usize, m: usize) -> Vec<Vec<u8>> { (0..n).map(|_| self.bytes(m)).collect() }

    fn token_bytes(&mut self) -> Vec<u8> {
        let mut res = Vec::new();
        let mut c = self.byte();
        while c <= b' ' {
            if c == b'\0' { return res; }
            c = self.byte();
        }
        loop {
            res.push(c);
            c = self.byte();
            if c <= b' ' { return res; }
        }
    }

    fn line_bytes(&mut self) -> Vec<u8> {
        let mut res = Vec::new();
        let mut c = self.byte();
        while c != b'\n' && c != b'\0' {
            res.push(c);
            c = self.byte();
        }
        res
    }
}

trait JoinToStr {
    fn join_to_str(self, sep: &str) -> String;
    fn concat_to_str(self) -> String;
}
impl<T: Display, I: Iterator<Item = T>> JoinToStr for I {
    fn join_to_str(mut self, sep: &str) -> String {
        match self.next() {
            Some(first) => {
                let mut res = first.to_string();
                while let Some(item) = self.next() {
                    res.push_str(sep);
                    res.push_str(&item.to_string());
                }
                res
            }
            None => { String::new() }
        }
    }

    fn concat_to_str(self) -> String {
        let mut res = String::new();
        for item in self { res.push_str(&item.to_string()); }
        res
    }
}
trait AsStr { fn as_str(&self) -> &str; }
impl AsStr for [u8] { fn as_str(&self) -> &str {std::str::from_utf8(self).expect("attempt to convert non-UTF8 byte string.")} }

macro_rules! veci {
    ($n:expr , $i:ident : $gen:expr) => {{
        let _veci_n = $n;
        let mut _veci_list = Vec::with_capacity(_veci_n);
        for $i in 0.._veci_n {
            _veci_list.push($gen);
        }
        _veci_list
    }};
    ($n:expr , $gen:expr) => { veci!($n, _veci_: $gen) }
}

fn abs_diff<T: Sub<Output = T> + PartialOrd>(x: T, y: T) -> T {
    if x < y { y - x } else { x - y }
}

trait CommonNumExt {
    fn div_ceil(self, b: Self) -> Self;
    fn div_floor(self, b: Self) -> Self;
    fn gcd(self, b: Self) -> Self;
    fn highest_one(self) -> Self;
    fn lowest_one(self) -> Self;
    fn sig_bits(self) -> u32;
}

macro_rules! impl_common_num_ext {
    ($($ix:tt = $ux:tt),*) => {
        $(
            impl CommonNumExt for $ux {
                fn div_ceil(self, b: Self) -> Self {
                    let q = self / b; let r = self % b;
                    if r != 0 { q + 1 } else { q }
                }
                fn div_floor(self, b: Self) -> Self { self / b }
                fn gcd(self, mut b: Self) -> Self {
                    let mut a = self;
                    if a == 0 || b == 0 { return a | b; }
                    let shift = (a | b).trailing_zeros();
                    a >>= a.trailing_zeros();
                    b >>= b.trailing_zeros();
                    while a != b {
                        if a > b { a -= b; a >>= a.trailing_zeros(); }
                        else { b -= a; b >>= b.trailing_zeros(); }
                    }
                    a << shift
                }
                #[inline] fn highest_one(self) -> Self {
                    if self == 0 { 0 } else { const ONE: $ux = 1; ONE << self.sig_bits() - 1 }
                }
                #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }
                #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ux>() as u32 * 8 - self.leading_zeros() }
            }

            impl CommonNumExt for $ix {
                fn div_ceil(self, b: Self) -> Self {
                    let q = self / b; let r = self % b;
                    if self ^ b >= 0 && r != 0 { q + 1 } else { q }
                }
                fn div_floor(self, b: Self) -> Self {
                    let q = self / b; let r = self % b;
                    if self ^ b < 0 && r != 0 { q - 1 } else { q }
                }
                fn gcd(self, b: Self) -> Self {
                    fn w_abs(x: $ix) -> $ux { (if x.is_negative() { x.wrapping_neg() } else { x }) as _ }
                    w_abs(self).gcd(w_abs(b)) as _
                }
                #[inline] fn highest_one(self) -> Self { (self as $ux).highest_one() as _ }
                #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }
                #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ix>() as u32 * 8 - self.leading_zeros() }
            }
        )*
    }
}
impl_common_num_ext!(i8 = u8, i16 = u16, i32 = u32, i64 = u64, i128 = u128, isize = usize);

trait ChMaxMin<T> {
    fn chmax(&mut self, v: T) -> bool;
    fn chmin(&mut self, v: T) -> bool;
}
impl<T: PartialOrd> ChMaxMin<T> for Option<T> {
    fn chmax(&mut self, v: T) -> bool { if self.is_none() || v > *self.as_ref().unwrap() { *self = Some(v); true } else { false } }
    fn chmin(&mut self, v: T) -> bool { if self.is_none() || v < *self.as_ref().unwrap() { *self = Some(v); true } else { false } }
}
impl<T: PartialOrd> ChMaxMin<T> for T {
    fn chmax(&mut self, v: T) -> bool { if v > *self { *self = v; true } else { false } }
    fn chmin(&mut self, v: T) -> bool { if v < *self { *self = v; true } else { false } }
}

// * end commons * //

#[macro_use]
#[allow(dead_code)]
mod modint {
    use std::{fmt::{Display, Formatter}, marker::PhantomData, mem::swap, ops::*, str::FromStr, cell::Cell};
    use crate::ModInt;

    pub trait RemEuclidU32: Copy {
        /// Calculates `self` _mod_ `modulus` losslessly.
        fn rem_euclid_u32(self, modulus: u32) -> u32;
    }

    macro_rules! impl_rem_euclid_u32_for_small_signed {
        ($($ty:tt),*) => {
            $(
                impl RemEuclidU32 for $ty {
                    #[inline]
                    fn rem_euclid_u32(self, modulus: u32) -> u32 {
                        (self as i64).rem_euclid(i64::from(modulus)) as _
                    }
                }
            )*
        }
    }

    impl_rem_euclid_u32_for_small_signed!(i8, i16, i32, i64, isize);

    impl RemEuclidU32 for i128 {
        #[inline]
        fn rem_euclid_u32(self, modulus: u32) -> u32 {
            self.rem_euclid(i128::from(modulus)) as _
        }
    }

    macro_rules! impl_rem_euclid_u32_for_small_unsigned {
        ($($ty:tt),*) => {
            $(
                impl RemEuclidU32 for $ty {
                    #[inline]
                    fn rem_euclid_u32(self, modulus: u32) -> u32 {
                        self as u32 % modulus
                    }
                }
            )*
        }
    }

    macro_rules! impl_rem_euclid_u32_for_large_unsigned {
        ($($ty:tt),*) => {
            $(
                impl RemEuclidU32 for $ty {
                    #[inline]
                    fn rem_euclid_u32(self, modulus: u32) -> u32 {
                        (self % (modulus as $ty)) as _
                    }
                }
            )*
        }
    }

    impl_rem_euclid_u32_for_small_unsigned!(u8, u16, u32);
    impl_rem_euclid_u32_for_large_unsigned!(u64, u128);

    #[cfg(target_pointer_width = "32")]
    impl_rem_euclid_u32_for_small_unsigned!(usize);

    #[cfg(target_pointer_width = "64")]
    impl_rem_euclid_u32_for_large_unsigned!(usize);
    #[inline]
    pub fn mul_mod_u32(a: u32, b: u32, m: u32) -> u32 {
        (a as u64 * b as u64 % m as u64) as u32
    }

    // for a, b < m, unspecified otherwise
    #[inline]
    fn add_mod_raw(a: u32, b: u32, m: u32) -> u32 {
        let (r, c) = a.wrapping_sub(m).overflowing_add(b);
        if c { r } else { a + b }
    }
    #[inline]
    fn sub_mod_raw(a: u32, b: u32, m: u32) -> u32 {
        let (r, c) = a.overflowing_sub(b);
        if c { r.wrapping_add(m) } else { r }
    }
    fn pow_mod_raw(a: u32, mut k: u64, m: u32) -> u32 {
        if m == 1 { return 0; }
        let mut a = a as u64;
        let m = m as u64;
        let mut r: u64 = 1;
        while k > 0 {
            if k & 1 == 1 {
                r = r * a % m;
            }
            k >>= 1;
            a = a * a % m;
        }
        r as u32
    }

    /// # Parameters
    /// * `b` `1 <= b`
    /// # Returns
    /// (x, g) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g
    fn inv_gcd(a: i64, b: i64) -> (i64, i64) {
        let a = a.rem_euclid(b);
        if a == 0 { return (0, b); }
        let mut s = b;
        let mut t = a;
        let mut m0 = 0;
        let mut m1 = 1;

        while t != 0 {
            let u = s / t;
            s -= t * u;
            m0 -= m1 * u;
            swap(&mut s, &mut t);
            swap(&mut m0, &mut m1);
        }

        if m0 < 0 { m0 += b / s; }
        (m0, s)
    }

    pub trait Modulus: Copy + Eq {
        fn get_modulus() -> u32;
        fn mul(a: u32, b: u32) -> u32;
    }

    #[derive(Clone, Copy, PartialEq, Eq, Hash)]
    #[repr(transparent)]
    pub struct ModIntBase<M: Modulus> {
        val: u32,
        _phantom: PhantomData<M>
    }

    impl <M: Modulus> ModIntBase<M> {
        #[inline(always)]
        pub fn modulus() -> u32 { M::get_modulus() }
        #[inline] pub fn new<I: RemEuclidU32>(val: I) -> Self { Self::raw(val.rem_euclid_u32(Self::modulus())) }
        #[inline] pub fn raw(val: u32) -> Self { Self { val, _phantom: PhantomData } }
        pub fn inv(self) -> Self {
            let (x, gcd) = inv_gcd(self.val.into(), Self::modulus().into());
            debug_assert!(gcd == 1, "the multiplicative inverse {}^-1 mod {} does not exist", self.val, Self::modulus());
            Self::raw(x as u32)
        }
        #[inline] pub fn val(self) -> u32 { self.val }
        #[inline] pub fn pow(self, k: u64) -> Self {
            Self::raw(pow_mod_raw(self.val, k, Self::modulus()))
        }
        pub fn powi(self, k: i64) -> Self { if k < 0 { self.inv().pow(-k as _) } else { self.pow(k as _) } }
        pub fn pow_vec(self, n: usize) -> Vec<Self> {
            let mut res = vec![Self::raw(0); n+1];
            res[0] += 1;
            for i in 1..=n {
                res[i] = res[i-1] * self;
            }
            res
        }

        pub fn invs(a: &[Self]) -> Vec<Self> {
            let n = a.len();
            if n == 0 { return vec![]; }
            let mut acc = Self::new(1);
            let mut res = Vec::with_capacity(n);
            for i in 0..n {
                if a[i].val() != 0 { acc *= a[i]; }
                res.push(acc);
            }
            acc = acc.inv();
            for i in (1..n).rev() {
                res[i] = acc * res[i-1];
                if a[i].val() != 0 { acc *= a[i]; }
            }
            res[0] = acc;
            res
        }
    }

    #[inline]
    pub fn mi<I: RemEuclidU32>(val: I) -> ModInt { ModIntBase::new(val) }
    #[inline] pub fn mir(v: u32) -> ModInt { ModIntBase::raw(v) }

    impl<V: RemEuclidU32, M: Modulus> From<V> for ModIntBase<M> {
        #[inline]
        fn from(from: V) -> Self { Self::new(from) }
    }
    impl<M: Modulus> Default for ModIntBase<M> {
        fn default() -> Self { Self::raw(0) }
    }
    impl<M: Modulus> FromStr for ModIntBase<M> {
        type Err = std::convert::Infallible;
        #[inline]
        fn from_str(s: &str) -> Result<Self, Self::Err> {
            Ok(s.parse::<i64>()
            .map(Self::new)
            .unwrap_or_else(|_| todo!("parsing as an arbitrary precision integer?")))
        }
    }
    impl<M: Modulus> Display for ModIntBase<M> {
        #[inline]
        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
            self.val.fmt(f)
        }
    }
    impl<M: Modulus> std::fmt::Debug for ModIntBase<M> {
        #[inline]
        fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
            std::fmt::Debug::fmt(&self.val, f)
        }
    }
    impl<M: Modulus> Neg for ModIntBase<M> {
        type Output = Self;

        #[inline]
        fn neg(self) -> Self::Output {
            Self::raw(0) - self
        }
    }

    impl<V: Into<ModIntBase<M>>, M: Modulus> Add<V> for ModIntBase<M> {
        type Output = Self;
        #[inline]
        fn add(self, rhs: V) -> Self::Output {
            Self::raw(add_mod_raw(self.val, rhs.into().val, Self::modulus()))
        }
    }
    impl<V: Into<ModIntBase<M>>, M: Modulus> Sub<V> for ModIntBase<M> {
        type Output = Self;
        #[inline]
        fn sub(self, rhs: V) -> Self::Output {
            Self::raw(sub_mod_raw(self.val, rhs.into().val, Self::modulus()))
        }
    }
    impl<V: Into<ModIntBase<M>>, M: Modulus> Mul<V> for ModIntBase<M> {
        type Output = Self;
        #[inline]
        fn mul(self, rhs: V) -> Self::Output {
            Self::raw(M::mul(self.val, rhs.into().val))
        }
    }
    impl<V: Into<ModIntBase<M>>, M: Modulus> Div<V> for ModIntBase<M> {
        type Output = Self;
        #[inline]
        fn div(self, rhs: V) -> Self::Output { self * rhs.into().inv() }
    }

    impl <V: Into<ModIntBase<M>>, M: Modulus> AddAssign<V> for ModIntBase<M> {
        #[inline]
        fn add_assign(&mut self, rhs: V) { *self = *self + rhs; }
    }
    impl <V: Into<ModIntBase<M>>, M: Modulus> SubAssign<V> for ModIntBase<M> {
        #[inline]
        fn sub_assign(&mut self, rhs: V) { *self = *self - rhs; }
    }
    impl <V: Into<ModIntBase<M>>, M: Modulus> MulAssign<V> for ModIntBase<M> {
        #[inline]
        fn mul_assign(&mut self, rhs: V) { *self = *self * rhs; }
    }
    impl <V: Into<ModIntBase<M>>, M: Modulus> DivAssign<V> for ModIntBase<M> {
        #[inline]
        fn div_assign(&mut self, rhs: V) { *self = *self / rhs; }
    }

    impl <M: Modulus> std::iter::Sum for ModIntBase<M> {
        #[inline] fn sum<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(Self::raw(0), Add::add)
        }
    }
    impl <M: Modulus> std::iter::Product for ModIntBase<M> {
        #[inline] fn product<I: Iterator<Item = Self>>(iter: I) -> Self {
            iter.fold(1.into(), Mul::mul)
        }
    }
    impl<'a, M: Modulus> std::iter::Sum<&'a Self> for ModIntBase<M> {
        #[inline] fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> ModIntBase<M> {
            iter.fold(Self::raw(0), |a, &b| a + b)
        }
    }
    impl<'a, M: Modulus> std::iter::Product<&'a Self> for ModIntBase<M> {
        #[inline] fn product<I: Iterator<Item = &'a Self>>(iter: I) -> ModIntBase<M> {
            iter.fold(1.into(), |a, &b| a * b)
        }
    }

    macro_rules! const_modulus {
        ($mint: ident, $name: ident, $modulus: expr) => {
            #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
            pub enum $name {}
            impl Modulus for $name {
                #[inline(always)] fn get_modulus() -> u32 { $modulus }
                fn mul(a: u32, b: u32) -> u32 {
                    mul_mod_u32(a, b, Self::get_modulus())
                }
            }
            pub type $mint = ModIntBase<$name>;
        }
    }

    #[derive(Debug, Clone, Copy)]
    pub struct ModulusCalc {
        pub modulus: u32,
        pub inv: u64
    }

    macro_rules! dynamic_modulus {
        ($mint: ident, $name: ident, $modulus: ident) => {
            static $modulus: crate::Unsync<Cell<ModulusCalc>> = crate::Unsync(Cell::new(ModulusCalc { modulus: 0, inv: 0 }));
            #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
            pub enum $name {}
            impl Modulus for $name {
                fn get_modulus() -> u32 { $modulus.0.get().modulus }
                fn mul(a: u32, b: u32) -> u32 {
                    let ModulusCalc { modulus, inv } = $modulus.0.get();
                    let p = a as u64 * b as u64;
                    let g = ((p as u128 * inv as u128) >> 64) as u64;
                    let (r, c) = p.overflowing_sub(g * modulus as u64);
                    if c { (r as u32).wrapping_add(modulus) } else { r as u32 }
                }
            }
            impl $name {
                pub fn set_modulus(val: u32) {
                    let inv = (1u64.wrapping_neg() / val as u64).wrapping_add(1);
                    $modulus.0.set(ModulusCalc { modulus: val, inv })
                }
            }
            pub type $mint = ModIntBase<$name>;
        }
    }

    const_modulus!(ModInt998_244_353, Mod998_244_353, 998_244_353);
    const_modulus!(ModInt1_000_000_007, Mod1_000_000_007, 1_000_000_007);
    dynamic_modulus!(DynamicModInt, DynamicModulus, DYNAMIC_MODULUS);
}

use crate::modint::*;
// type ModInt = ModInt998_244_353;
type ModInt = ModInt1_000_000_007;
// const_modulus!(ModInt, DefaultModulus, 1_000_000_009);
// type ModInt = DynamicModInt;

struct FactorMap {
    map: Vec<u32>
}
impl FactorMap {
    pub fn new(limit: usize) -> FactorMap {
        let limit = limit + 1;
        let mut map = vec![0; limit >> 1];
        for p in (3..limit).step_by(2) {
            if map[p >> 1] != 0 { continue; }
            let sq = p * p;
            if sq >= limit { break; }
            for i in (sq..limit).step_by(p*2) {
                if map[i >> 1] == 0 { map[i >> 1] = p as u32; }
            }
        }

        FactorMap { map }
    }

    pub fn least_prime_factor(&self, n: usize) -> usize {
        if n & 1 == 0 { return 2; }
        let p = self.map[n >> 1] as usize;
        if p == 0 { n } else { p }
    }

    pub fn factorize(&self, n: usize) -> FactorIterator {
        FactorIterator { fm: self, n }
    }

    pub fn is_prime(&self, n: usize) -> bool { n > 1 && self.least_prime_factor(n) == n }

    /// lists divisors, unsorted
    pub fn divisors(&self, mut n: usize) -> Vec<usize> {
        let mut res = vec![1];

        while n > 1 {
            let p = self.least_prime_factor(n);
            let mut x = 0;
            loop {
                n /= p;
                x += 1;
                if p != self.least_prime_factor(n) { break; }
            }
            for i in 0..res.len() {
                let mut a = res[i];
                for _ in 0..x {
                    a *= p;
                    res.push(a);
                }
            }
        }

        res
    }

    pub fn euler_totient(&self, mut n: usize) -> usize {
        let mut res = n;

        while n > 1 {
            let p = self.least_prime_factor(n);
            loop {
                n /= p;
                if p != self.least_prime_factor(n) { break; }
            }
            res = res / p * (p-1);
        }

        res
    }

    pub fn new_with_mobius(limit: usize) -> (FactorMap, Vec<i8>) {
        let fm = Self::new(limit);
        let mut mu = vec![1i8; limit + 1];
        mu[0] = 0;

        for i in 2..=limit {
            let p = fm.least_prime_factor(i);
            mu[i] = if p == fm.least_prime_factor(i/p) { 0 } else { -mu[i/p] };
        }

        (fm, mu)
    }
}
struct FactorIterator<'a> {
    fm: &'a FactorMap,
    n: usize
}
impl Iterator for FactorIterator<'_> {
    type Item = usize;

    fn next(&mut self) -> Option<Self::Item> {
        if self.n <= 1 { return None; }
        let p = self.fm.least_prime_factor(self.n);
        self.n /= p;
        Some(p)
    }

    fn size_hint(&self) -> (usize, Option<usize>) { (0, Some(32)) }
}

#[allow(non_snake_case, non_upper_case_globals)]
fn main() {
    let num_cases: usize = 1;//read();

    for _case_num in 1..=num_cases {
        let n = read!(usize);

        let mut ans = 0i128;
        let fm = FactorMap::new(n);
        for c in 1..=n-2 {
            for d in fm.divisors(n-c) { if d != n-c {
                let l = c / c.gcd(d) * d;
                ans += l as i128 * fm.euler_totient((n-c)/d) as i128;
            }}
        }

        ans %= 1_000_000_007;
        println!(ans);
    }

    out_flush();
}


// ---------- begin scanner -----------
#[allow(unused_imports)]
use std::io::{BufWriter, stdin, stdout, Read, Write, Stdout};
use std::str::FromStr;

pub struct Scanner<'a> {
    it: std::str::SplitWhitespace<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    pub fn new(s: &'a String) -> Scanner<'a> {
        Scanner {
            it: s.split_whitespace(),
        }
    }
    pub fn next<T: FromStr>(&mut self) -> T {
        self.it.next().expect("read EOF").parse::<T>().ok().expect("parse failed")
    }
    pub fn next_n<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }
    pub fn next_n_index1<T: FromStr + Default>(&mut self, n: usize) -> Vec<T> {
        std::iter::once(T::default()).chain((0..n).map(|_| self.next())).collect()
    }
    pub fn next_chars(&mut self) -> Vec<char> { self.it.next().unwrap().chars().collect() }
    pub fn next_bytes(&mut self) -> Vec<u8> { self.it.next().unwrap().bytes().collect() }
    pub fn next_digits(&mut self) -> Vec<u8> {
        self.it.next().unwrap().bytes().map(|c|c-C0).collect()
    }
}
// ---------- end scanner -------------

// ---------- begin utils -------------
#[allow(dead_code)]
const C0: u8 = '0' as u8;

// ---------- end utils ---------------

// ---------- begin debugger ----------
#[cfg(feature = "my_debug")]
#[macro_export]
macro_rules! debug {
    () => {
        eprintln!("[{}:{}]", file!(), line!())
    };
    ($val:expr $(,)?) => {
        eprintln!("[{}:{}] {} = {:?}", file!(), line!(), stringify!($val), &($val))
    };
    ($($val:expr),+ $(,)?) => {
        ($(debug!($val)),+,)
    };
}

#[cfg(not(feature = "my_debug"))]
#[macro_export]
macro_rules! debug {
    ($( $args:expr ),*) => {}
}
// ---------- end debugger ------------

fn main() {
    debug!("Ish: good luck and high rating!");

    #[cfg(not(feature = "my_debug"))]
        let s = {
        let mut s = String::new();
        stdin().read_to_string(&mut s).unwrap();
        s
    };
    #[cfg(feature = "my_debug")]
        let s = std::fs::read_to_string("in.txt").unwrap();

    let mut sc = Scanner::new(&s);
    let out = &mut BufWriter::new(stdout());

    // let cases: u32 = sc.next();
    let cases: u32 = 1;
    debug!(cases);
    for _case in 1..=cases { debug!(_case);
        run(&mut sc, out);
    }
}

/** Write your mind here.

lcm(c, gcd(a,b))

c*gcd(a,b)/ gcd(a,b,c)

枚举 c，设 m = n-c = a+b, 所有的 a+b 组合成 m，他们的 gcd 值和 c 取 lcm。

5000
1 4999
2 4998

m 分化。
如果 a 和 b 的 gcd 不是 1，只有可能是 10 分成 6 和 4。

m 本身是 x 的倍数
分出来 ax 和 bx。

12
1 11    1 * 2
2 10    2 * 2
3 9     3 * 2
4 8     4 * 2
5 7     1 * 2
6 6     6 * 1

因数个数，如果能枚，还是可以的。

14
1 2 7
  6 1

240

 */

fn gcd(a: i32, b: i32) -> i32 {
    if b == 0 { return a; }
    return gcd(b, a%b);
}

fn lcm(a: i32, b: i32) -> i64 {
    a as i64 * b as i64 / gcd(a, b) as i64
}

fn run(sc: &mut Scanner, out: &mut BufWriter<Stdout>) {
    let n = sc.next::<i32>();

    let mut ans = 0;
    for c in 1..=n-2 {
        let m = n-c;

        let factors = {
            let mut fc = vec![1];
            for i in 2..m {
                if i*i > m { break; }
                if i*i == m { fc.push(i); continue; }
                if m%i == 0 { fc.push(i); fc.push(m/i); }
            }
            fc.sort();
            fc
        };

        let tot = factors.len();
        let cnt = {
            let mut cnt = vec![0; tot];
            for i in (0..tot).rev() {
                cnt[i] = m / factors[i] - 1;

                for j in i+1..tot {
                    if factors[j] % factors[i] == 0 {
                        cnt[i] -= cnt[j];
                    }
                }
            }
            cnt
        };

        let mut tmp = 0i64;
        for i in 0..tot {
            let p = lcm(c, factors[i]);
            tmp += p * cnt[i] as i64;

        }
        // tmp %= 1_000_000_007;

        ans = ans + tmp;
        ans %= 1_000_000_007;
    }

    // let ans = if arr == brr {"YES"} else {"NO"};

    // let ans = 1;
    // let mut ok = true;
    // let ans = if ok {"Yes"} else {"No"};
    writeln!(out, "{ans}").ok();
    // for ans in ans {
    //     for num in ans { write!(out, "{num}").ok(); }
    //     writeln!(out).ok();
    // }
}

#[test]
fn test() {
    let n = 2048;
    let mut count = vec![0; n as usize];
    for a in 1..n {
        let b = n-a;
        let g = gcd(a, b);
        count[g as usize] += 1;
    }
    let mut cnt = 0;
    for i in 0..n as usize {
        if count[i] > 0 {
            debug!((i, count[i]));
            cnt += 1;
        }
    }
    debug!(cnt);
}


#![allow(unused_imports)]
#![allow(unused_must_use)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::comparison_chain)]

use std::cmp::{max, min, Reverse};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, prelude::*};
use std::str;

fn solve<R: BufRead, W: Write>(sc: &mut Scanner<R>, wr: &mut W) {
    const MOD: i64 = 1_000_000_007;
    let n: usize = sc.tok();
    let lowest = sieve(n);
    let mut phi = vec![1; n + 1];
    for k0 in 2..=n {
        let p = lowest[k0];
        let mut pow = 1;
        let mut k = k0;
        while k % p == 0 {
            k /= p;
            pow *= p;
        }
        phi[k0] = phi[k] * ((p - 1) * (pow / p)) as i64;
    }
    let mut res = 0;
    for g in 1..=n as i64 - 1 {
        let mut s = 2 * g;
        while s < n as i64 {
            res += phi[(s / g) as usize] * lcm(g, n as i64 - s) % MOD;
            if res >= MOD {
                res -= MOD;
            }
            s += g;
        }
    }
    writeln!(wr, "{}", res);
}

pub fn gcd(mut a: i64, mut b: i64) -> i64 {
    a = a.abs();
    b = b.abs();
    while b > 0 {
        a %= b;
        (a, b) = (b, a);
    }
    a
}

pub fn lcm(a: i64, b: i64) -> i64 {
    if (a, b) == (0, 0) {
        0
    } else {
        a / gcd(a, b) * b
    }
}
fn sieve(max: usize) -> Vec<usize> {
    let mut primes = vec![];
    let mut lowest = vec![0; max + 1];
    for n in 2..=max {
        if lowest[n] == 0 {
            lowest[n] = n;
            primes.push(n);
        }
        for &p in &primes {
            if p > lowest[n] || p * n > max {
                break;
            }
            lowest[p * n] = p;
        }
    }
    lowest
}

use std::marker::PhantomData;
macro_rules! recursive_function {
    ($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {
        pub trait $trait<$($type, )*Output> {
            fn call(&mut self, $($arg: $type,)*) -> Output;
        }

        pub struct $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            f: F,
            $($arg: PhantomData<$type>,
            )*
            phantom_output: PhantomData<Output>,
        }

        impl<F, $($type, )*Output> $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            pub fn new(f: F) -> Self {
                Self {
                    f,
                    $($arg: Default::default(),
                    )*
                    phantom_output: Default::default(),
                }
            }
        }

        impl<F, $($type, )*Output> $trait<$($type, )*Output> for $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            fn call(&mut self, $($arg: $type,)*) -> Output {
                let const_ptr = &self.f as *const F;
                let mut_ptr = const_ptr as *mut F;
                unsafe { (&mut *mut_ptr)(self, $($arg, )*) }
            }
        }
    }
}

recursive_function!(RecursiveFunction0, Callable0, ());
recursive_function!(RecursiveFunction, Callable, (Arg arg,));
recursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));
recursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));
recursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));
recursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));
recursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));
recursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));
recursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));
recursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));

#[macro_export]
macro_rules! dbg{
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        eprintln!(
            concat!("{}:{}:{}: ",$(stringify!($a), " = {:?}, "),*),
            file!(), line!(), column!(), $($a),*
        );
        #[cfg(not(debug_assertions))]
        {};
    }
}
struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn tok<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}


pub mod solution {

use crate::io::input::Input;
use crate::io::output::output;
use crate::math::euclid::gcd;
use crate::math::sieve::{euler_function_up_to, get_all_divisors_for_all_up_to};
use crate::{out, out_line};
use crate::math::modular::primitive::ModularType;

type Mod = ModularType<1000000007>;

fn solve(input: &mut Input, _test_case: usize) {
    let n = input.read();
    let phi = euler_function_up_to(n);
    let divisors = get_all_divisors_for_all_up_to(n);
    let mut ans = Mod::from(0);
    for c in 1..n - 1 {
        for &g in &divisors[n - c] {
            if g == n - c {
                continue;
            }
            let x = gcd(g as u64, c as u64) as usize;
            ans += Mod::from(c / x) * g.into() * phi[(n - c) / g].into();
        }
    }
    out_line!(ans);
}

pub(crate) fn run(mut input: Input) -> bool {
    solve(&mut input, 1);
    output().flush();
    input.skip_whitespace();
    !input.peek().is_some()
}

}
pub mod io {
pub mod input {
use std::fmt::Debug;
use std::io::Read;
use std::marker::PhantomData;
use std::str::FromStr;

pub struct Input<'s> {
    input: &'s mut dyn Read,
    buf: Vec<u8>,
    at: usize,
    buf_read: usize,
}

impl<'s> Input<'s> {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(input: &'s mut dyn Read) -> Self {
        Self {
            input,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn new_with_size(input: &'s mut dyn Read, buf_size: usize) -> Self {
        Self {
            input,
            buf: vec![0; buf_size],
            at: 0,
            buf_read: 0,
        }
    }

    pub fn get(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            let res = self.buf[self.at];
            self.at += 1;
            Some(res)
        } else {
            None
        }
    }

    pub fn peek(&mut self) -> Option<u8> {
        if self.refill_buffer() {
            Some(self.buf[self.at])
        } else {
            None
        }
    }

    pub fn skip_whitespace(&mut self) {
        while let Some(b) = self.peek() {
            if !char::from(b).is_whitespace() {
                return;
            }
            self.get();
        }
    }

    pub fn next_token(&mut self) -> Option<Vec<u8>> {
        self.skip_whitespace();
        let mut res = Vec::new();
        while let Some(c) = self.get() {
            if char::from(c).is_whitespace() {
                break;
            }
            res.push(c);
        }
        if res.is_empty() {
            None
        } else {
            Some(res)
        }
    }

    //noinspection RsSelfConvention
    pub fn is_exhausted(&mut self) -> bool {
        self.peek().is_none()
    }

    pub fn read<T: Readable>(&mut self) -> T {
        T::read(self)
    }

    pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
        let mut res = Vec::with_capacity(size);
        for _ in 0usize..size {
            res.push(self.read());
        }
        res
    }

    pub fn read_line(&mut self) -> String {
        let mut res = String::new();
        while let Some(c) = self.get() {
            if c == b'\n' {
                break;
            }
            if c == b'\r' {
                if self.peek() == Some(b'\n') {
                    self.get();
                }
                break;
            }
            res.push(c.into());
        }
        res
    }

    #[allow(clippy::should_implement_trait)]
    pub fn into_iter<T: Readable>(self) -> InputIterator<'s, T> {
        InputIterator {
            input: self,
            phantom: Default::default(),
        }
    }

    fn read_integer<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let res = self.read_string();
        res.parse::<T>().unwrap()
    }

    fn read_string(&mut self) -> String {
        match self.next_token() {
            None => {
                panic!("Input exhausted");
            }
            Some(res) => unsafe { String::from_utf8_unchecked(res) },
        }
    }

    fn read_char(&mut self) -> char {
        self.skip_whitespace();
        self.get().unwrap().into()
    }

    fn read_float(&mut self) -> f64 {
        self.read_string().parse().unwrap()
    }

    fn refill_buffer(&mut self) -> bool {
        if self.at == self.buf_read {
            self.at = 0;
            self.buf_read = self.input.read(&mut self.buf).unwrap();
            self.buf_read != 0
        } else {
            true
        }
    }
}

pub trait Readable {
    fn read(input: &mut Input) -> Self;
}

impl Readable for String {
    fn read(input: &mut Input) -> Self {
        input.read_string()
    }
}

impl Readable for char {
    fn read(input: &mut Input) -> Self {
        input.read_char()
    }
}

impl Readable for f64 {
    fn read(input: &mut Input) -> Self {
        input.read_float()
    }
}

impl<T: Readable> Readable for Vec<T> {
    fn read(input: &mut Input) -> Self {
        let size = input.read();
        input.read_vec(size)
    }
}

pub struct InputIterator<'s, T: Readable> {
    input: Input<'s>,
    phantom: PhantomData<T>,
}

impl<'s, T: Readable> Iterator for InputIterator<'s, T> {
    type Item = T;

    fn next(&mut self) -> Option<Self::Item> {
        self.input.skip_whitespace();
        self.input.peek().map(|_| self.input.read())
    }
}

macro_rules! read_integer {
    ($t:ident) => {
        impl Readable for $t {
            fn read(input: &mut Input) -> Self {
                input.read_integer()
            }
        }
    };
}

read_integer!(i8);
read_integer!(i16);
read_integer!(i32);
read_integer!(i64);
read_integer!(i128);
read_integer!(isize);
read_integer!(u8);
read_integer!(u16);
read_integer!(u32);
read_integer!(u64);
read_integer!(u128);
read_integer!(usize);

macro_rules! tuple_readable {
    ( $( $name:ident )+ ) => {
        impl<$($name: Readable), +> Readable for ($($name,)+) {
            fn read(input: &mut Input) -> Self {
                ($($name::read(input),)+)
            }
        }
    }
}

tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}
}
pub mod output {
use std::io::Write;

pub struct Output {
    output: Box<dyn Write>,
    buf: Vec<u8>,
    at: usize,
    auto_flush: bool,
}

impl Output {
    const DEFAULT_BUF_SIZE: usize = 4096;

    pub fn new(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: false,
        }
    }

    pub fn new_with_auto_flush(output: Box<dyn Write>) -> Self {
        Self {
            output,
            buf: vec![0; Self::DEFAULT_BUF_SIZE],
            at: 0,
            auto_flush: true,
        }
    }

    pub fn flush(&mut self) {
        if self.at != 0 {
            self.output.write_all(&self.buf[..self.at]).unwrap();
            self.at = 0;
            self.output.flush().expect("Couldn't flush output");
        }
    }

    pub fn print<T: Writable>(&mut self, s: &T) {
        s.write(self);
    }

    pub fn put(&mut self, b: u8) {
        self.buf[self.at] = b;
        self.at += 1;
        if self.at == self.buf.len() {
            self.flush();
        }
    }

    pub fn maybe_flush(&mut self) {
        if self.auto_flush {
            self.flush();
        }
    }

    pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
        for i in arg {
            i.write(self);
            self.put(b'\n');
        }
    }

    pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }

    pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator<Item = &'a T>>(&mut self, iter: I) {
        let mut first = true;
        for e in iter {
            if first {
                first = false;
            } else {
                self.put(b' ');
            }
            e.write(self);
        }
    }
}

impl Write for Output {
    fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
        let mut start = 0usize;
        let mut rem = buf.len();
        while rem > 0 {
            let len = (self.buf.len() - self.at).min(rem);
            self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
            self.at += len;
            if self.at == self.buf.len() {
                self.flush();
            }
            start += len;
            rem -= len;
        }
        if self.auto_flush {
            self.flush();
        }
        Ok(buf.len())
    }

    fn flush(&mut self) -> std::io::Result<()> {
        self.flush();
        Ok(())
    }
}

pub trait Writable {
    fn write(&self, output: &mut Output);
}

impl Writable for &str {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for String {
    fn write(&self, output: &mut Output) {
        output.write_all(self.as_bytes()).unwrap();
    }
}

impl Writable for char {
    fn write(&self, output: &mut Output) {
        output.put(*self as u8);
    }
}

impl<T: Writable> Writable for [T] {
    fn write(&self, output: &mut Output) {
        output.print_iter_ref(self.iter());
    }
}

impl<T: Writable> Writable for Vec<T> {
    fn write(&self, output: &mut Output) {
        self[..].write(output);
    }
}

macro_rules! write_to_string {
    ($t:ident) => {
        impl Writable for $t {
            fn write(&self, output: &mut Output) {
                self.to_string().write(output);
            }
        }
    };
}

write_to_string!(u8);
write_to_string!(u16);
write_to_string!(u32);
write_to_string!(u64);
write_to_string!(u128);
write_to_string!(usize);
write_to_string!(i8);
write_to_string!(i16);
write_to_string!(i32);
write_to_string!(i64);
write_to_string!(i128);
write_to_string!(isize);
write_to_string!(f32);
write_to_string!(f64);

impl<T: Writable, U: Writable> Writable for (T, U) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
    }
}

impl<T: Writable, U: Writable, V: Writable> Writable for (T, U, V) {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
        output.put(b' ');
        self.1.write(output);
        output.put(b' ');
        self.2.write(output);
    }
}

pub static mut OUTPUT: Option<Output> = None;

pub fn output() -> &'static mut Output {
    unsafe {
        match &mut OUTPUT {
            None => {
                panic!("Panic");
            }
            Some(output) => output,
        }
    }
}

#[macro_export]
macro_rules! out {
    ($first: expr $(,$args:expr )*) => {
        output().print(&$first);
        $(output().put(b' ');
        output().print(&$args);
        )*
    }
}

#[macro_export]
macro_rules! out_line {
    ($first: expr $(, $args:expr )* ) => {
        out!($first $(,$args)*);
        output().put(b'\n');
    };
    () => {
        output().put(b'\n');
    };
}
}
}
pub mod math {
pub mod euclid {

pub fn gcd(mut a: u64, mut b: u64) -> u64 {
    while b != 0 {
        let t = a % b;
        a = b;
        b = t;
    }
    a
}

pub fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}
}
pub mod modular {
pub mod primitive {
use crate::io::output::{Output, Writable};
use std::ops::{Add, AddAssign, Mul, Neg};

#[derive(Copy, Clone)]
pub struct ModularType<const M: u32>(u32);

pub trait Modular:
    Add<Output = Self>
    + AddAssign
    + Mul<Output = Self>
    + Neg<Output = Self>
    + From<usize>
    + From<i32>
    + From<u32>
    + From<u64>
    + Writable
    + Copy
{
    const MODULO: u32;
    fn value(&self) -> u32;
    fn usize(&self) -> usize {
        self.value() as usize
    }
}

impl<const M: u32> Modular for ModularType<M> {
    const MODULO: u32 = M;

    fn value(&self) -> u32 {
        self.0
    }
}

impl<const M: u32> Add for ModularType<M> {
    type Output = ModularType<M>;

    fn add(self, rhs: Self) -> Self::Output {
        let result = self.0 + rhs.0;
        ModularType(if result >= M { result - M } else { result })
    }
}

impl<const M: u32> AddAssign for ModularType<M> {
    fn add_assign(&mut self, rhs: Self) {
        self.0 += rhs.0;
        if self.0 >= M {
            self.0 -= M;
        }
    }
}

impl<const M: u32> Mul for ModularType<M> {
    type Output = ModularType<M>;

    fn mul(self, rhs: Self) -> Self::Output {
        Self((self.0 as u64 * rhs.0 as u64 % M as u64) as u32)
    }
}

impl<const M: u32> Neg for ModularType<M> {
    type Output = ModularType<M>;

    fn neg(self) -> Self::Output {
        Self(if self.0 == 0 { 0 } else { M - self.0 })
    }
}

impl<const M: u32> From<u32> for ModularType<M> {
    fn from(x: u32) -> Self {
        Self(x % M)
    }
}

impl<const M: u32> From<i32> for ModularType<M> {
    fn from(x: i32) -> Self {
        Self(x.rem_euclid(M as i32) as u32)
    }
}

impl<const M: u32> From<usize> for ModularType<M> {
    fn from(x: usize) -> Self {
        Self((x % M as usize) as u32)
    }
}

impl<const M: u32> Into<usize> for ModularType<M> {
    fn into(self) -> usize {
        self.0 as usize
    }
}

impl<const M: u32> Writable for ModularType<M> {
    fn write(&self, output: &mut Output) {
        self.0.write(output);
    }
}

impl<const M: u32> From<u64> for ModularType<M> {
    fn from(x: u64) -> Self {
        Self((x % M as u64) as u32)
    }
}
}
}
pub mod sieve {

pub fn get_all_divisors_for_all_up_to(n: usize) -> Vec<Vec<usize>> {
    let mut d = vec![Vec::new(); n + 1];
    for i in 1..=n {
        for j in (i..=n).step_by(i) {
            d[j].push(i);
        }
    }
    d
}

pub fn euler_function_up_to(n: usize) -> Vec<usize> {
    let mut phi = vec![0; n + 1];
    for i in 1..=n {
        phi[i] = i;
    }
    for i in 2..=n {
        if phi[i] == i {
            for j in (i..=n).step_by(i) {
                phi[j] -= phi[j] / i;
            }
        }
    }
    phi
}
}
}
fn main() {
    let mut sin = std::io::stdin();
    let input = crate::io::input::Input::new(&mut sin);
    unsafe {
        crate::io::output::OUTPUT = Some(crate::io::output::Output::new(Box::new(std::io::stdout())));
    }
    crate::solution::run(input);
}


use std::io;

#[derive(Debug, Copy, Clone, PartialEq)]
enum Color {
    C,
    Y,
    M,
    U,
}

impl Color {
    fn create(c: char) -> Self {
        match c {
            'C' => Color::C,
            'Y' => Color::Y,
            'M' => Color::M,
            _ => Color::U,
        }
    }
}

pub fn main() {
    let input = get_input();
    let length = input.len();
    let mut unknowns = 0;
    let mut two_solutions = false;
    let mut unknown_location = 0;
    //println!("{:?}", input);
    if input[0] == Color::U {
        two_solutions = true;
    }
    for i in 1..length {
        if input[i] == Color::U {
            if i == length - 1 || i == 0 ||
                input[i + 1] == input[i - 1] || input[i - 1] == Color::U {
                two_solutions = true;
            }
        } else if input[i] == input[i - 1] {
            println!("No");
            return;
        }
    }
    if two_solutions {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn get_input() -> Vec<Color> {
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    let mut input = String::new();
    io::stdin().read_line(&mut input);
    input.trim().chars().map(|c| Color::create(c)).collect()
}


macro_rules! read {
    ( $( $type_:ty ),+ ) => {
        {
            let mut line = String::new();
            io::stdin().read_line(&mut line).expect("error while reading line");
            let tokens : Vec<String> = line.as_str().split_whitespace().map(|x| x.to_string()).collect();
            let mut _tokens : &[String] = &tokens;
            ($(
                {
                    let tmp : $type_ = _tokens[0].parse().expect("error while parsing value");
                    _tokens = &_tokens[1..];
                    tmp
                }
            ),*)
        }
    };
}
macro_rules! read_vec {
    ( $type_:ty ) => {
        {
            let mut line = String::new();
            io::stdin().read_line(&mut line).expect("error while reading line");
            line.as_str().split_whitespace().map(|x| x.parse().expect("error while parsing")).collect::<Vec<$type_>>()
        }
    };
}
macro_rules! lazy_constant {
    (static $name:ident: $type_:ty = $initializer:expr;) => {
        use std::sync::{Once, ONCE_INIT};
        use std::boxed::Box;
        static INIT: Once = ONCE_INIT;
        static mut VALUE: *const $type_ = 0 as * const $type_;
        INIT.call_once(|| {
            unsafe {
                VALUE = Box::into_raw(Box::new($initializer));
            }
        });
        let $name: & $type_ = unsafe { VALUE.as_ref().unwrap() };
    };
}
use std::io;
fn main() {
    let _ = read!(i32);
    let text = read!(String);
    let text = text.as_bytes();
    for i in 1 .. text.len() {
        if text[i - 1] == text[i] && text[i] != b'?' {
            println!("No");
            return;
        }
    }
    for i in 0 .. text.len() {
        if text[i] == b'?' {
            if i == 0 || i == (text.len() - 1) {
                println!("Yes");
                return;
            }
            if text[i + 1] == b'?' {
                println!("Yes");
                return;
            }
            if text[i - 1] == text[i + 1] {
                println!("Yes");
                return;
            }
        }
    }
    println!("No");
}


struct Scan {
    buffer: std::collections::VecDeque<String>,
}

impl Scan {
    fn new() -> Scan {
        Scan {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }
}

fn _gcd(a: usize, b: usize) -> usize {
    let mut x = a.max(b);
    let mut y = a.min(b);
    while y != 0 {
        let aux = x;
        x = y;
        y = aux % y;
    }
    x
}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let m: usize = scan.next();
    let z: usize = scan.next();
    let gcd_nm = _gcd(n, m);
    let mcm_nm = n * m / gcd_nm;
    println!("{}", z / mcm_nm);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1 << 23)
        .spawn(_main)
        .unwrap()
        .join()
        .unwrap();
}


#[allow(unused_imports)]
use std::cmp::{max,min};

#[allow(unused)]
fn read_string() -> String {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string)
        .ok()
        .expect("Ошибка чтения ввода");
    string.trim().to_string()
}

#[allow(unused)]
fn read_vec_i32() -> Vec::<i32> {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string)
        .ok()
        .expect("Ошибка чтения ввода");
    let mut v = Vec::new();
    for value in string.split_whitespace() {
        let value = value.parse::<i32>().unwrap();
        v.push(value);
    }
    return v;
}

fn main() {

    let params = read_vec_i32();
    let n = params[0] as usize;
    let m = params[1] as usize;
    let z = params[2] as usize;

    let mut res: i32 = 0;
    for i in 1 .. z + 1 {
        if i % n == 0 && i % m == 0 {
            res += 1;
        }
    }
    println!("{}", res);
}


#[allow(unused_imports)]
use std::cmp::{max,min,Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap,HashSet,VecDeque};

#[allow(unused_macros)]
macro_rules! readln {
    () => {{
        use std::io;

        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        buf.trim().to_string()
    }};
    ( $t:ty ) => {{
        let input = readln!();
        input.parse::<$t>().unwrap()
    }};
    ( $( $t:ty ),+ ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        (
            $(
                input.next().unwrap().parse::<$t>().unwrap(),
            )+
        )
    }}
}

#[allow(unused_macros)]
macro_rules! readvec {
    ( $t:ty ) => {{
        let input = readln!();
        let mut input = input.split_whitespace();
        let mut result = Vec::new();
        for elem in input {
            result.push(elem.parse::<$t>().unwrap());
        }
        result
    }}
}

fn main() {
  let (n,m,z) = readln!(i32,i32,i32);
  let mut res = 0;
  for i in 1..(z+1) {
    if (i%n) == 0 && (i%m) == 0 {
      res += 1;
    }
  }
  println!("{}",res);
}


use std::io;

fn read_line() -> String{
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("Failed to read line");

    line.trim().to_string()
}

fn gcd(a: i32, b: i32) -> i32{
    if b > a {return gcd(b, a)}
    if b == 0 {return a}
    gcd(b, (a % b))
}

fn main() {
    let vals = read_line()
        .split_whitespace()
        .map(|x| x.parse().expect("parse int error"))
        .collect::<Vec<i32>>();
    let n = vals.get(0).unwrap();
    let m = vals.get(1).unwrap();
    let z = vals.get(2).unwrap();
    let lcm = n / gcd(*n, *m) * m;
    let res = z / lcm;

    println!("{}", res);
}


//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::*;
#[allow(unused_imports)] use std::collections::*;

#[allow(unused_macros)]
macro_rules! a {
    ($c: tt, $x: expr, $y: expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}

#[allow(dead_code)]
fn build_counting_hashmap<K: Eq + std::hash::Hash, T>(i: T) -> HashMap<K,usize>
    where T: Iterator<Item = K> {
    let mut m = HashMap::new();
    for k in i {
        let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };
        m.insert(k, n);
    }
    m
}

fn gcd(a: i32, b: i32) -> i32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let a = input.i();
    let b = input.i();
    let c = input.i();
    println!("{}", c * gcd(a,b) / a / b);
}


macro_rules! read_line {
    ($v:ident) => {
        let mut temp = String::new();
        std::io::stdin().read_line(&mut temp).unwrap();
        let $v = temp;
    };
    (var, $t:ty, $($v:ident), *) => {
        read_line!(input_line);
        let mut iter = parse_token!($t, input_line);
        $(
            let $v = iter.next().unwrap();
        )*
    };
    (vec, $t:ty, $v:ident) => {
        read_line!(input_line);
        let iter = parse_token!($t, input_line);
        let $v: Vec<$t> = iter.collect();
    };
    ($($v:ident; $t:ty), *) => {
        read_line!(input_line);
        let mut iter = input_line.split_whitespace();
        $(
            let $v: $t = iter.next().unwrap().parse().unwrap();
        )*
    };
}

macro_rules! parse_token {
    ($t:ty, $e:expr) => {
        $e.split_whitespace().map(|x| x.parse::<$t>().unwrap());
    };
}

fn main() {
    read_line!(call_interval;i32,come_interval;i32,day_length;i32);
    let mut min = come_interval;
    let mut count = 0;
    while min <= day_length {
        if min % call_interval == 0 {
            count += 1;
        }
        min += come_interval;
    }
    println!("{}", count);
}


use std::io;
use std::str::FromStr;

fn get_num() -> usize {
    let mut input = String::new();

    io::stdin().read_line(&mut input).expect("");

    usize::from_str(input.trim()).unwrap()
}

fn get_nums() -> Vec<usize> {
    let mut input = String::new();

    io::stdin().read_line(&mut input).expect("");

    input
        .trim()
        .split_whitespace()
        .map(|s| usize::from_str(s).unwrap())
        .collect::<Vec<_>>()
}

fn main() {
    let n = get_num();
    let a = get_nums();

    let mut mn = std::usize::MAX;
    for i in 1..n - 1 {
        let mut mx = std::usize::MIN;
        let mut v = a.clone();
        v.remove(i);

        for j in 0..v.len() - 1 {
            mx = std::cmp::max(mx, v[j + 1] - v[j]);
        }

        mn = std::cmp::min(mn, mx);
    }

    println!("{}", mn);
}


//spnauti-rusT
use std::io::*;
use std::str::{self,*};
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_macros)]
macro_rules! m {
    ($c:tt, $x:expr, $y:expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
#[allow(unused_macros)]
macro_rules! l {
    ($($v:ident),* = $i:ident.$f:ident $a:tt) => {
        $( let $v = $i.$f$a; )*
    };
    ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {
        $( let $v:$t = $i.$f$a; )*
    };
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a> }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn f(&mut self) ->    f64 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn sk(&mut self, n: usize) { self.it.nth(n - 1); }
    fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}
//------------------- End rusT

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let n = input.u();
    let a = input.vi(n);
    let mut sol = 0;
    for i in 1..n {
        m!(>, sol, a[i] - a[i-1]);
    }
    let mut res = 1000;
    for i in 1..=n-2 {
        m!(<, res, a[i+1] - a[i-1]);
    }
    println!("{}", sol.max(res));
}


use std::io::stdin;

fn main() {
    let n = {
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        iter.next().unwrap().parse::<usize>().unwrap()
    };

    let a: Vec<usize> = {
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace().map(|it| it.parse().unwrap()).collect()
    };

    let dif: Vec<usize> = (1..n)
        .map(|it| a[it] - a[it - 1])
        .collect();
    let min_sum_diff = (1..dif.len())
        .map(|it| dif[it] + dif[it - 1])
        .min()
        .unwrap();
    let max_in_diff = *dif.iter()
        .max()
        .unwrap();

    println!("{}", max_in_diff.max(min_sum_diff));
}


#![allow(unused_imports)]
#![allow(unused_macros)]
// use proconio::input;
use std::cmp::Ordering::*;
use std::collections::{BTreeMap, BTreeSet};
use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

macro_rules! answer {
    ($out:ident, $ans:expr) => {
        writeln!($out, "{}", $ans)
    };
}

fn solve(mut a: Vec<i32>, i: usize) -> i32 {
    a.remove(i);
    a.windows(2).map(|v| v[1] - v[0]).max().unwrap()
}

fn main() -> Result<(), io::Error> {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = UnsafeScanner::new(stdin.lock());
    let mut out = BufWriter::new(stdout.lock());

    let n: usize = scan.token();
    let a: Vec<i32> = (0..n).map(|_| scan.token()).collect();

    let ans = (1..n-1).map(|i| solve(a.clone(), i)).min().unwrap();

    answer!(out, ans)
}

///////////////////////////////////////////////////////////////////////////////////////////////////

/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs
/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts
/// **REQUIRES** Rust 1.34 or higher
pub struct UnsafeScanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: SplitAsciiWhitespace<'static>,
}

impl<R: io::BufRead> UnsafeScanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_ascii_whitespace(),
        }
    }

    /// This function should be marked unsafe, but noone has time for that in a
    /// programming contest. Use at your own risk!
    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_ascii_whitespace())
            }
        }
    }

    pub fn pair<T: str::FromStr>(&mut self) -> (T, T) {
        (self.token(), self.token())
    }
}


#[allow(unused_imports)]
use std::cmp::{max, min};
//const INF: i32 = 0x3f3f3f3f;

struct Scanner {
    buffer: std::collections::VecDeque<String>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            buffer: std::collections::VecDeque::new(),
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut input = String::new();
            std::io::stdin().read_line(&mut input).ok();
            self.buffer = input.split_whitespace().map(ToString::to_string).collect();
        }
        let front = self.buffer.pop_front().unwrap();
        front.parse::<T>().ok().unwrap()
    }
}

fn gcd(mut a: i64, mut b: i64) -> i64 {
    while b > 0 {
        a %= b;
        let tmp = a;
        a = b;
        b = tmp;
    }
    a
}

fn solution() {
    let mut scanner = Scanner::new();
    let n: i64 = scanner.next();
    let k: i64 = scanner.next();
    let a: i64 = scanner.next();
    let b: i64 = scanner.next();

    let mut x = std::i64::MAX;
    let mut y = 0;
    for i in 0..n {
        if a + i * k >= n * k {
            break;
        }
        for j in [b - a, a + b, a + i * k - b, a + i * k + b, i * k - a + b, i * k - a - b].iter() {
            let mut l = *j;
            if l < 0 {
                l = -l;
            }
            if l == 0 {
                l = n * k;
            }
            let m = n * k / gcd(l, n * k);
            x = std::cmp::min(x, m);
            y = std::cmp::max(y, m);
        }
    }
    println!("{} {}", x, y);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(50 << 20)
        .spawn(solution)
        .unwrap()
        .join()
        .unwrap();
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Sat 10 Feb 2018 19:40:59
 *
 */

fn check(x: i32, y: i32, z: i32) -> bool {
  return x < y && y < z && x + y > z;
}

fn main() {
  let mut buffer = String::new();
  std::io::stdin().read_line(&mut buffer).unwrap();

  let n: i32 = buffer.trim().parse::<i32>().unwrap() + 1;

  let mut sum = 0;

  for x in 1..n {
    for y in 1..x {
      let z = x ^ y;
      if z < n &&  check(y, x, z) {
        sum += 1;
      }
    }
  }

  println!("{}", sum);
}


// Try Codeforces
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        () => (get().parse::<i64>().unwrap());
        ($t:ty) => (get().parse::<$t>().unwrap());
    }

    let n = get!();
    let mut ans = 0;
    for a in 1..n+1 {
        for b in a..n+1 {
            let c = a ^ b;
            if c >= b && c <= n && a + b > c {
                // println!("{} {} {}", a, b, c);
                ans += 1;
            }
        }
    }

    println!("{}", ans);

}


use std::io::prelude::*;
use std::io;
use std::str::FromStr;
#[cfg(local)]
use std::fs::File;
#[cfg(local)]
use std::io::BufReader;

#[cfg(local)]
fn buf_read() -> io::Result<(Vec<String>)> {
    let f = try!(File::open("input.txt"));
    let input_lines: Vec<_> = BufReader::new(f).lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

#[cfg(not(local))]
fn buf_read() -> io::Result<(Vec<String>)> {
    let stdin = io::stdin();
    let input_lines: Vec<_> = stdin.lock().lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

fn main() {
    type Element = String;
    let input = buf_read().unwrap();
    let mut input_vectors: Vec<Vec<Element>> = vec![];
    for input_line in input {
        let input_str: Vec<String> = input_line.split(' ').map(String::from).collect();
        let mut input_vector: Vec<Element> = vec![];
        for input_elem_str in input_str {
            let elem: Element = Element::from_str(input_elem_str.as_str()).unwrap();
            input_vector.push(elem);
        }
        input_vectors.push(input_vector);
    }
    let mut k = i64::from_str(&input_vectors[0][1]).unwrap();
    let mut i = 0;
    let mut str = input_vectors[1][0].char_indices();
    // let mut str2 = str.clone();
    // let mut str3 = str.clone();
    // let g_position = str2.position(|(u, c)| c == 'G').unwrap() as i64;
    // let t_position = str3.position(|(u, c)| c == 'T').unwrap() as i64;
    let mut start_flag = 0;
    let mut result_flag = 0;

    for c in str {
        if start_flag == 1 {
            i += 1;
            if i % k != 0 {
                continue;
            }
        }
        // println!("{:?}", c);
        match c {
            (n, c) => {
                if c == '#' {
                    // println!("{:?}", c);
                    if start_flag == 1 {
                        break;
                    }
                } else if c == 'G' || c == 'T' {
                    // println!("{:?}", c);
                    // println!("{:?}", start_flag);

                    if start_flag == 0 {
                        start_flag = 1;
                    } else {
                        result_flag = 1;
                        break;
                    }
                }
            }
        }
        // println!{"{:?}", c};
    }
    if result_flag == 0 {
        println!("No");
    } else {
        println!("Yes");
    }
}


use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;
use std::cmp::*;
fn exec() {
    let mut sc = Scanner::new();
    let _: usize = sc.ne();
    let k: usize = sc.ne();
    let a = sc.ne::<String>().into_bytes();
    let start = a.iter().position(|&x| x == b'G').unwrap();
    let goal = a.iter().position(|&x| x == b'T').unwrap();
    let s = min(start, goal);
    let g = max(start, goal);
    let mut ok = true;
    if (g - s) % k != 0 {
        println!("NO");
        std::process::exit(0);
    }
    let mut cur = s;
    while cur != g {
        if a[cur] == b'#' {
            ok = false;
        }
        cur += k;
    }
    println!("{}", if ok { "YES" } else { "NO" });
}

fn main() {
    const DEFAULT_STACK: usize = 16 * 1024 * 1024;
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


fn main() {
    let mut input = String::new();

    std::io::stdin().read_line(&mut input).expect("INPUT::Read line failed");

    let real_max_len = input.trim().len();
    let a_amount = input.trim().matches('a').collect::<Vec<&str>>().len();
    let theory_max_len = a_amount + a_amount - 1;

    if a_amount > real_max_len / 2  {
        println!("{}", real_max_len);
    }else {
        println!("{}", theory_max_len);
    }

}


#[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::{stderr, stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ 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 ) * } } ; }
#[allow(unused_macros)]
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 ) * } } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
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 ::< Vec < _ >> ( ) } ; ( $ next : expr , [ $ t : tt ] ) => { { let len = read_value ! ( $ next , usize ) ; ( 0 .. len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
struct Writer {
    s: String,
}
#[allow(unused_imports)]
use std::fmt::Display;
#[allow(dead_code)]
#[doc = " let mut writer = Writer::new();"]
#[doc = " writer.writeln(hoge);"]
#[doc = " writer.flush()"]
impl Writer {
    #[allow(dead_code)]
    pub fn new() -> Writer {
        Writer { s: String::new() }
    }
    #[allow(dead_code)]
    pub fn flush(&mut self) {
        print!("{}", self.s);
        self.s.clear();
    }
    pub fn write<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
    }
    pub fn writeln<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
        self.s.push('\n');
    }
    #[allow(dead_code)]
    pub fn write_vec<T: Display>(&mut self, xs: &Vec<T>) {
        if xs.len() == 0 {
            self.writeln("");
            return;
        }
        self.write(&format!("{}", xs[0]));
        for i in 1..xs.len() {
            self.write(&format!(" {}", xs[i]));
        }
        self.writeln("");
    }
}
#[allow(unused_macros)]
macro_rules ! dbg { ( $ ( $ a : expr ) ,* ) => { writeln ! ( & mut stderr ( ) , concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) . unwrap ( ) ; } }
#[allow(dead_code)]
const INF_U: u64 = 1_000_000_000_000_000;
#[allow(dead_code)]
const INF_I: i64 = 1_000_000_000_000_000;
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        s: chars
    }
    let mut a_num = 0;
    for &ss in &s {
        if ss == 'a' {
            a_num += 1;
        }
    }
    if a_num > s.len() / 2 {
        println!{"{}", s.len()};
    } else {
        println!{"{}", a_num * 2 - 1};
    }
}


use std::io::{self, stdin};

fn main() -> io::Result<()> {
    let mut buffer = String::new();
    let input = stdin();
    input.read_line(&mut buffer)?;
    let a = buffer.matches("a").count();
    let len = buffer.trim().len();
    if 2 * a > len {
        println!("{}", len);
    } else {
        println!("{}", a * 2 - 1);
    }
    Ok(())
}


#[allow(unused_imports)]
use std::cmp::{min,max};
//const INF: i32 = 0x3f3f3f3f;

struct Scanner {
    buffer: std::collections::VecDeque<String>
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            buffer: std::collections::VecDeque::new()
        }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut input = String::new();
            std::io::stdin().read_line(&mut input).ok();
            self.buffer = input.split_whitespace()
                .map(ToString::to_string).collect();
        }
        let front = self.buffer.pop_front().unwrap();
        front.parse::<T>().ok().unwrap()
    }
}

fn main1() {
    let mut scan = Scanner::new();
    let s = scan.next::<String>();
    let l = s.chars().count();
    let n = s.chars().filter(|&ch| ch == 'a').count();
    let ans = min(2 * n - 1, l);
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new().stack_size(50 << 20)
        .spawn(main1).unwrap().join().unwrap();
}


use std::io::{Read,stdin};

fn main() {
    let mut buf = String::new();
    stdin().read_to_string(&mut buf).unwrap();
    let mut tok = buf.split_whitespace();
    let mut get = || tok.next().unwrap();

    let s = get().as_bytes();
    let n = s.len();
    let a = s.iter().filter(|c|**c==b'a').count();
    let ans = if a + a > n { n } else { a + a - 1 };
    println!("{:?}", ans);

}


use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let buf = buf.trim();

    let length = buf.len();
    let count_as = buf.chars().filter(|&c| c == 'a').count();

    if (2 * count_as) > length {
        println!("{}", length);
    } else {
        println!("{}", 2 * count_as - 1);
    }
}


use std::io::{self, Read};

fn main() -> io::Result<()> {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input)?;
    let input = input.trim();

    let mut all_a = 0;
    for letter in input.chars() {
        if letter == 'a' {
            all_a += 1
        }
    }
    let len = input.len();
    if all_a > (len / 2) {
        println!("{}", len);
    } else {
        println!("{}", all_a * 2 - 1);
    }
    Ok(())
}


//spnauti-rusT
use std::io::*;
use std::str::{self,*};
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_macros)]
macro_rules! m {
    ($c:tt, $x:expr, $y:expr) => {{
        let b = $y; let a = &mut $x;
        if b $c *a { *a = b; true } else { false }
    }};
}
#[allow(unused_macros)]
macro_rules! l {
    ($($v:ident),* = $i:ident.$f:ident $a:tt) => {
        $( let $v = $i.$f$a; )*
    };
    ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {
        $( let $v:$t = $i.$f$a; )*
    };
}
struct WordReader<'a> { it : SplitAsciiWhitespace<'a> }
#[allow(dead_code)]
impl<'a> WordReader<'a> {
    fn new<T: Read>(b: &mut String, mut r: T) -> WordReader {
        b.clear();
        r.read_to_string(b).ok();
        WordReader { it: b.split_ascii_whitespace() }
    }
    fn from_stdin(b: &mut String) -> WordReader {
        WordReader::new(b, stdin())
    }
    fn sl(&mut self) ->  &str { self.it.next().unwrap() }
    fn bs(&mut self) -> &[u8] { self.sl().as_bytes()    }
    fn s(&mut self) -> String { String::from(self.sl()) }
    fn i(&mut self) ->    i32 { self.p()                }
    fn f(&mut self) ->    f64 { self.p()                }
    fn u(&mut self) ->  usize { self.p()                }
    fn sk(&mut self, n: usize) { self.it.nth(n - 1); }
    fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> {
        self.ip(n).into_iter()
    }
    fn vi(&mut self, n: usize) -> Vec<i32> {
        self.vp::<i32>(n)
    }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
        self.sl().parse::<T>().unwrap()
    }
    fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
        self.vp(n).into_iter()
    }
    fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
        (0..n).map(|_| self.p()).collect()
    }
}
//------------------- End rusT

fn main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let n: i64 = input.p();
    let mut a = 1;
    let mut b = 2;
    let mut sol = 0;
    while b <= n {
        let c = a + b;
        a = b;
        b = c;
        sol += 1;
    }
    println!("{}", sol);
}


use std::io::prelude::*;
use std::io;
use std::str::FromStr;
#[cfg(local)]
use std::fs::File;
#[cfg(local)]
use std::io::BufReader;

#[cfg(local)]
fn buf_read() -> io::Result<(Vec<String>)> {
    let f = try!(File::open("input.txt"));
    let input_lines: Vec<_> = BufReader::new(f).lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

#[cfg(not(local))]
fn buf_read() -> io::Result<(Vec<String>)> {
    let stdin = io::stdin();
    let input_lines: Vec<_> = stdin.lock().lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

fn main() {
    type Element = i64;
    let input = buf_read().unwrap();
    let mut input_vectors: Vec<Vec<Element>> = vec![];
    for input_line in input {
        let input_str: Vec<String> = input_line.split(' ').map(String::from).collect();
        let mut input_vector: Vec<Element> = vec![];
        for input_elem_str in input_str {
            let elem: Element = Element::from_str(input_elem_str.as_str()).unwrap();
            input_vector.push(elem);
        }
        input_vectors.push(input_vector);
    }

    let mut match_num = 0;
    let mut minimum_papticipants = 2;
    let mut minimum_papticipants2 = 1;
    let mut paticipants = input_vectors[0][0];

    while minimum_papticipants <= paticipants {
        let tmp = minimum_papticipants;
        minimum_papticipants = minimum_papticipants + minimum_papticipants2;
        minimum_papticipants2 = tmp;
        match_num += 1;
    }
    println!("{}", match_num);
}


//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::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: u64,
    }
    let mut ans = 1;
    let mut a = 2;
    let mut b = 3;
    while b <= n {
        ans += 1;
        let c = a + b;
        a = b;
        b = c;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


use std::io::*;

fn read<T: std::str::FromStr>(i: &mut StdinLock) -> T {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn reads<T: std::str::FromStr>(i: &mut StdinLock) -> Vec<T> {
    let mut s = String::new();
    i.by_ref().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let _n: usize = read(sin);
    let mut input: Vec<u8> = reads(sin);

    input.sort();

    let ans: Vec<String> = input.into_iter().map(|x| x.to_string()).collect();

    println!("{}", ans.join(" "));
}


use std::io;
use std::io::Stdin;
use std::str::FromStr;

fn read_line(stdin : &Stdin, line : &mut String) {
    match stdin.read_line(line) {
        Ok(_) => return,
        Err(msg) => panic!("Could not read line! Message: {}.", msg),
    }
}

fn parse_t<T : FromStr>(s : &str) -> T {
    match s.trim().parse() {
        Ok(y) => y,
        Err(_) => panic!("Could not read from string!"),
    }
}

fn read_t<T : FromStr>(stdin : &Stdin) -> T {
    let mut line = String::new();
    read_line(stdin, &mut line);
    parse_t(&line)
}

fn read_ts<T : FromStr>(stdin : &Stdin, ts : &mut Vec<T>) {
    let mut line = String::new();
    read_line(stdin, &mut line);
    let word_iter = line.split_whitespace();
    for word in word_iter {
        let x = parse_t(word);
        ts.push(x);
    }
}

fn main() {
    let stdin = io::stdin();
    let _ : u64 = read_t(&stdin);
    let mut cs : Vec<u64> = vec![];
    read_ts(&stdin, &mut cs);
    cs.sort();
    let mut first = true;
    for c in cs {
        if first {
            first = false;
            print!("{}", c);
        } else {
            print!(" {}", c);
        }
    }
    println!();
}


fn readln() -> Vec<i32> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}
fn main() {
    let mut n = readln()[0];
    let mut a = readln();
    a.sort();

    for x in a {
        print!("{} ", x);
    }
}


use std::io;
use std::io::BufRead;

use std::fmt::Write;

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    lines.next().unwrap().expect("input reading failed");
    let input_string = lines.next().unwrap().expect("input reading failed");
    let mut numbers: Vec<u8> = input_string.split(" ").map(|x| x.parse::<u8>().unwrap()).collect();
    numbers.sort();

    let mut output = String::with_capacity(500);
    let mut sorted_iter = numbers.iter();

    let first = sorted_iter.next().unwrap();

    write!(output, "{}", first).unwrap();
    for x in sorted_iter {
        write!(output, " {}", x).unwrap();
    }

    println!("{}", output);
}


use std::mem;
use std::io;
use std::string;
use std::cmp::*;

fn load() -> Vec<i32> {
    let mut line = String::new();
    io::stdin().read_line(&mut line).expect("Failed to read line");
    let vec: Vec<&str> = line.split(" ").collect();
    let mut data : Vec<i32> = Vec::new();
    for i in vec {
        let el : i32 = i.trim().parse().unwrap();
        data.push(el);
    }
    data
}

fn main() {
    let s = load();
    let mut a = load();
    a.sort();
    for i in a {
        print!("{} ", i);
    }
    println!("");
}


use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.clear();
    io::stdin().read_line(&mut s).unwrap();
    let mut a : Vec<i32> = s.split_whitespace().map(|s| s.parse().unwrap()).collect();
    a.sort();
    for e in a.iter() {
        print!("{} ", e);
    }
}


//spnauti-rust
struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T: std::io::Read>(mut reader: T) -> WordReader {
        let mut s = String::new();
        reader.read_to_string(&mut s).unwrap();
        WordReader { it : s
            .split_ascii_whitespace()
            .map(String::from).collect::<Vec<_>>()
            .into_iter()
        }
    }
    fn from_stdin() -> WordReader {
        WordReader::new(std::io::stdin())
    }
    fn s(&mut self) -> String {
        self.it.next().unwrap()
    }
    fn ab(&mut self) -> Vec<u8> {
        self.it.next().unwrap().into_bytes()
    }
    fn i(&mut self) -> i32 {
        self.it.next().unwrap().parse().unwrap()
    }
    fn ai(&mut self, n: usize) -> Vec<i32> {
        let mut a = Vec::with_capacity(n);
        for _ in 0..n { a.push(self.i()); }
        a
    }
}

fn main() {
    let mut input = WordReader::from_stdin();
    let n = input.i() as usize;
    let mut a = input.ai(n);
    a.sort();
    a.iter().for_each(|x| print!("{} ", x));
}


#[allow(unused_imports)]
use std::cmp::{min,max};
use std::io::{BufWriter, stdin, stdout, Write};

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    let out = &mut BufWriter::new(stdout());

	let n = scan.next::<usize>();
    let f = (0..n).map(|_| scan.next::<usize>()).collect::<Vec<usize>>();
    let m = f.iter().max().unwrap();

    let h = *m;
    let w = n;

    let mut mtr = vec![vec![0; n]; *m];

    for i in 0..h {
        for j in 0..w {
            let x = j;
            let y = h - i;
            if y <= f[x] {
                mtr[i][j] = 1;
            }
        }
    }
    for i in 0..h {
        mtr[i].sort();
    }

    let mut v = vec![0; w];
    for x in 0..w {
      for y in 0..h {
          v[x] = v[x] + mtr[y][x];
      }
    }

    writeln!(out, "{}", v.iter().fold(String::new(), |acc, &x| acc + &x.to_string() + " ")).expect("fail");
}


use std::io::stdin;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input).expect("error");

    let size = 'z' as i32 - 'a' as i32 + 1;

    let mut sum = 0;
    let mut old_char = 'a';

    for c in input.trim().chars() {
        sum += std::cmp::min(
            (old_char as i32 - c as i32).abs(),
            size - (old_char as i32 - c as i32).abs(),
        );
        old_char = c;
    }
    println!("{}", sum);
}


#[allow(unused_imports)]
use std::io::{stdin, stdout, Write, Read};
use std::cmp::{max, min};

type Result<T> = ::std::result::Result<T, Box<dyn (::std::error::Error)>>;
#[derive(Default)]
struct Scanner {
    buffer: Vec<String>
}
#[allow(dead_code)]
impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }

    fn next_two<T: std::str::FromStr>(&mut self) -> (T, T) {
        let a;
        loop {
            if let Some(token) = self.buffer.pop() {
                a = token.parse().ok().expect("Failed parse");
                break;
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }

        loop {
            if let Some(token) = self.buffer.pop() {
                return (a, token.parse().ok().expect("Failed parse"));
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn main() -> Result<()>{
    let mut scan = Scanner::default();

    let word: String = scan.next();

    let word: Vec<i32> = word.chars().map(|ch| ch as i32).collect();
    let mut pos = 1;
    let mut dist = 0;
    for ch in word {
        dist += min((pos - ch + 96).abs(), 26 - max(ch - 96, pos) + min(ch - 96, pos));
        pos = ch - 96;

    }
    println!("{}", dist);
    Ok(())
}


struct Scan {
    buffer: std::collections::VecDeque<String>
}

impl Scan {
    fn new() -> Scan {
        Scan { buffer: std::collections::VecDeque::new() }
    }

    fn next<T: std::str::FromStr>(&mut self)-> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).expect("Fail to read");
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

}

fn _main() {
    let mut scan = Scan::new();
    let input: String = scan.next();
    let mut current  = 0isize;
    let mut result = 0isize;
    for item in input.chars() {
        let dst: isize = item as isize - 'a' as isize;
        result += (dst - current).abs()
            .min(26 - current + dst)
            .min(26 - dst + current);
        current = dst;
    }
    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();
}


//! http://codeforces.com/contest/731/problem/A

fn forward_dist(mut c1: u8, c2: u8) -> u64 {
  let mut dist = 0;
  while c1 != c2 {
    c1 = (c1 + 1) % 26;
    dist += 1;
  }
  dist
}

fn backward_dist(mut c1: u8, c2: u8) -> u64 {
  let mut dist = 0;
  while c1 != c2 {
    if c1 == 0 { c1 = 25; }
    else { c1 -= 1; }
    dist += 1;
  }
  dist
}

fn main() {
  use std::io;
  let mut buf = String::new();
  io::stdin().read_line(&mut buf).unwrap();
  let bytes = buf.trim().as_bytes();
  let mut last = 0;
  let mut total = 0;
  for &b in bytes {
    let b = b - b'a';
    total += std::cmp::min(forward_dist(last, b), backward_dist(last, b));
    last = b;
  }
  println!("{}", total);
}


#[allow(unused_imports)]
use std::io;
use std::mem::size_of_val;
use std::cmp::{max, min};
use std::rc::Rc;
use std::collections::btree_map::BTreeMap;
use std::io::{Write, BufRead};
use std::collections::HashMap;
use std::ptr::write_volatile;

#[allow(dead_code)]
fn gets() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(unused)]
fn read_strings() -> Vec<String> {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string).unwrap();
    let mut v = Vec::new();
    for value in string.split_whitespace() {
        v.push(value.to_string());
    }
    v
}

#[allow(unused)]
fn read_array_i32() -> Vec<i32> {
    let mut string: String = String::new();
    std::io::stdin().read_line(&mut string).unwrap();
    string.split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect()
}

#[allow(unused_macros)]
macro_rules! read_array {
    ( $ty:ty, ... ) => {
        gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap())
    };
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

// mod math;
// mod binary_search;
// mod graph;
// mod structure;
// mod fibonacci;
// mod string;
// mod permutations;
// mod patterns;

#[allow(dead_code)]
fn memory_properties<T>(value: &T)
    where
        T: std::fmt::Display + ?Sized,
{
    println!(
        "Variable address in memory = {:p}, Allocated bytes for type = {}",
        value,
        size_of_val(value)
    );
}

#[allow(unused_macros)]
macro_rules! sum {
    ($($x:expr), *) => {
        {
            let mut res = 0;
            $(res += $x;)*
            res
        }
    };
}

static mut array: [[u8;51];51] = [[0u8; 51]; 51];

fn main() {
    use std::io::Write;
    let out = std::io::stdout();
    let mut out = std::io::BufWriter::new(out.lock());

    let arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
    let s = gets();
    let mut res = 0;
    let mut idx = 26;
    for ch in s.bytes() {
        let mut l = idx;
        let mut r = idx;

        while l > 0 &&  arr[l as usize] as u8 != ch {
            l -= 1;
        }
        while r < arr.len() as u8 && arr[r as usize] as u8 != ch {
            r += 1;
        }
        if idx - l <= r - idx {
            res += (idx - l) as i32;
            idx = l % 26 + 26;
        }else {
            res += (r - idx) as i32;
            idx = r % 26 + 26;
        }
    }
    writeln!(out, "{}", res);

    // writeln!(out, "{}", "Hello Rust").unwrap();
}