const MODULUS: usize = 1_000_000_007;

fn main() {
    let stdout = std::io::stdout();
    let mut writer = std::io::BufWriter::new(stdout.lock());
    #[allow(unused_macros)] macro_rules! print { ($($tt:tt)*) => {{ use std::io::Write; std::write!(writer, $($tt)*).unwrap(); }}; }
    #[allow(unused_macros)] macro_rules! println { ($($tt:tt)*) => {{ use std::io::Write; std::writeln!(writer, $($tt)*).unwrap(); }}; }

    input! {
        n: usize
    }
    let (_, _, phi) = prime_sieve(n);
    let mut divisors = vec![];
    let mut ans = 0;
    for c in 1..=n-2 {
        let sum_ab = n - c;
        divisors.clear();
        for i in 1.. {
            if i * i > sum_ab {
                break;
            }
            if sum_ab % i == 0 {
                divisors.push(i);
                if i * i < sum_ab {
                    divisors.push(sum_ab / i);
                }
            }
        }
        for &divisor in divisors.iter() {
            if divisor == sum_ab {
                continue
            }
            let cnt = phi[sum_ab / divisor];
            let lcm = c / c.gcd(divisor) * divisor;
            ans += lcm % MODULUS * cnt % MODULUS;
            ans %= MODULUS;
        }
    }
    println!("{}", ans);
}

trait BinaryGCD {
    fn gcd(self, b: Self) -> Self;
}

macro_rules! impl_binary_gcd_uint {
    ($($t:ty),*) => {
        $(
            impl BinaryGCD for $t {
                fn gcd(self, mut b: Self) -> Self {
                    let mut a = self;

                    if b == 0 {
                        return a
                    }
                    if a == 0 {
                        return b
                    }
                    let shifts = (a|b).trailing_zeros();
                    a >>= a.trailing_zeros();
                    b >>= b.trailing_zeros();

                    loop {
                        if a < b {
                            std::mem::swap(&mut a, &mut b);
                        }
                        a -= b;
                        if a == 0 {
                            return b << shifts
                        }
                        a >>= a.trailing_zeros();
                    }
                }
            }
        )*
    };
}

impl_binary_gcd_uint!(u8, u16, u32, u64, usize, u128);

fn prime_sieve(n: usize) -> (Vec<usize>, Vec<usize>, Vec<usize>) {
    let mut primes = vec![];
    let mut min_div = vec![0; n + 1];
    let mut phi = vec![0; n + 1];
    phi[1] = 1;
    for i in 2..=n {
        if min_div[i] == 0 {
            min_div[i] = i;
            phi[i] = i - 1;
            primes.push(i)
        }
        for &p in primes.iter() {
            if i * p > n {
                break
            }
            min_div[i * p] = p;
            if i % p == 0 {
                phi[i * p] = phi[i] * p;
                break
            }
            phi[i * p] = phi[i] * (p - 1);
        }
    }
    (primes, min_div, phi)
}

// input macro with modifications (to better align with proconio)
// based on https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

#[macro_export]
macro_rules! input {
    (@lock_stdin $reader:ident) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut $reader = move || -> String {
            unsafe {
                String::from_utf8_unchecked(
                    bytes
                        .by_ref()
                        .map_while(Result::ok)
                        .skip_while(|c| c.is_ascii_whitespace())
                        .take_while(|c| !c.is_ascii_whitespace())
                        .collect()
                )
            }
        };
    };

    (@inner $reader:ident) => {};
    (@inner $reader:ident, ) => {};

    (@inner $reader:ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($reader, $t);
        input!{@inner $reader $($r)*}
    };

    (@inner $reader:ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($reader, $t);
        input!{@inner $reader $($r)*}
    };

    (@inner $reader:ident $($r:tt)*) => {
        compile_error!(stringify!(unable to read $($r)*))
    };

    (line = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_ascii_whitespace();
        let mut next = || { iter.next().unwrap_or_default() };
        input!{@inner next, $($r)*}
    };
    (name = $reader:ident, $($r:tt)*) => {
        input!{@lock_stdin $reader};
        input!{@inner $reader, $($r)*}
    };
    (use $reader:ident, $($r:tt)*) => {
        input!{@inner $reader, $($r)*}
    };
    ($($r:tt)*) => {
        input!{@lock_stdin reader};
        input!{@inner reader, $($r)*};
    };
}

#[macro_export]
macro_rules! read_value {
    ($reader:ident, ( $($t:tt),* )) => {
        ( $(read_value!($reader, $t)),* )
    };

    ($reader:ident, [ $t:tt ]) => {{
        let len = read_value!($reader, usize);
        read_value!($reader, [ $t ; len])
    }};

    ($reader:ident, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($reader, $t)).collect::<Vec<_>>()
    };

    ($reader:ident, chars) => {
        read_value!($reader, String).chars().collect::<Vec<char>>()
    };

    ($reader:ident, bytes) => {
        read_value!($reader, String).into_bytes()
    };

    ($reader:ident, usize1) => {
        read_value!($reader, usize) - 1
    };

    ($reader:ident, $t:tt) => {
        $reader().parse::<$t>().expect(stringify!(parse error($t)))
    };
}


#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_variables)]
use std::cmp::*;
use std::collections::BTreeSet;
use std::io;
use std::{io::prelude::*, io::*, str};

struct IO {
    buffer: Vec<String>,
    out: BufWriter<Stdout>,
}
impl IO {
    fn new() -> Self {
        Self {
            buffer: vec![],
            out: BufWriter::new(stdout()),
        }
    }
    fn read<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 read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }
}

fn transform(x: u64, d: u64) -> u64 {
    if x & (1u64 << 63) != 0 {
        return 0;
    }
    let mut x = (x << 1) | d;
    while x & 1 == 0 {
        x >>= 1;
    }
    let mut y = 0;
    while x != 0 {
        y = (y << 1) | (x & 1);
        x >>= 1;
    }

    y
}

fn solve(io: &mut IO) -> Result<()> {
    let (a, b): (u64, u64) = (io.read(), io.read());
    let mut mp = BTreeSet::<u64>::new();
    let mut vis = BTreeSet::<u64>::new();
    mp.insert(a);

    while let Some(&x) = mp.iter().next() {
        if x == b {
            return writeln!(io.out, "YES");
        }

        vis.insert(x);
        mp.remove(&x);

        for d in 0..=1 {
            let y = transform(x, d);
            if y != 0 && !vis.contains(&y) {
                mp.insert(y);
            }
        }
    }
    return writeln!(io.out, "NO");
}

fn main() -> io::Result<()> {
    let mut io = IO::new();

    solve(&mut io)
}


struct Scanner<R> {
    reader: R,
    line: Vec<u8>,
    ptr: usize

}

impl<R: std::io::BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self{reader, line: vec![], ptr: 0}
    }

    fn scan<T: std::str::FromStr>(&mut self) -> T {
        loop {
            while self.ptr < self.line.len() && self.line[self.ptr].is_ascii_whitespace() {
                self.ptr += 1;
            }
            if self.ptr != self.line.len() {
                let start = self.ptr;
                while self.ptr < self.line.len() && !self.line[self.ptr].is_ascii_whitespace() {
                    self.ptr += 1;
                }
                return std::str::from_utf8(&self.line[start..self.ptr]).unwrap().parse().ok().
                    expect("parse error");
            }
            self.line.clear();
            self.reader.read_until(b'\n', &mut self.line).expect("read error");
            self.ptr = 0;
        }
    }

    fn line(&mut self) -> Vec<u8> {
        if self.ptr == self.line.len() {
            self.line.clear();
            self.reader.read_until(b'\n', &mut self.line).expect("read error");
            self.ptr = 0;
        }
        let result = self.line[self.ptr..].to_vec();
        self.ptr = self.line.len();
        return result;
    }

    fn eof(&mut self) -> bool {
        loop {
            while self.ptr < self.line.len() && self.line[self.ptr].is_ascii_whitespace() {
                self.ptr += 1;
            }
            if self.ptr != self.line.len() {
                return false;
            }
            self.line.clear();
            self.ptr = 0;
            if let Ok(0) = self.reader.read_until(b'\n', &mut self.line) {
                return true;
            }
        }
    }

}

fn solve<R: std::io::BufRead, W: std::io::Write>(scanner: &mut Scanner<R>, writer: &mut W) {
    let mut x: i64 = scanner.scan();
    let mut y: i64 = scanner.scan();
    if y % 2 == 0 {
        writeln!(writer, "{}", if x == y {"YES"} else {"NO"}).unwrap();
        return;
    }
    let mut a = Vec::new();
    while x != 0 {
        a.push(x % 2);
        x /= 2;
    }
    let mut b = Vec::new();
    while y != 0 {
        b.push(y % 2);
        y /= 2;
    }
    a.reverse();
    b.reverse();
    let mut result = false;
    let mut aa = vec![a; 3];
    aa[1].push(1);
    aa[1].reverse();
    while let Some(&0) = aa[2].last() {
        aa[2].pop();
    }
    aa[2].reverse();
    for mut a in aa {
        loop {
            for i in 0..b.len() {
                if i + a.len() > b.len() {
                    break;
                }
                let mut ok = true;
                for j in 0..a.len() {
                    ok &= a[j] == b[i + j];
                }
                for j in 0..i {
                    ok &= b[j] == 1;
                }
                for j in i + a.len()..b.len() {
                    ok &= b[j] == 1;
                }
                if ok {
                    result = true;
                }
            }
            if let Some(1) = a.pop() {
                break;
            }
            while let Some(&0) = a.last() {
                a.pop();
            }
        }
    }
    writeln!(writer, "{}", if result {"YES"} else {"NO"}).unwrap();
}

fn main() {
    let (stdin, stdout) = (std::io::stdin(), std::io::stdout());
    let mut writer = std::io::BufWriter::new(stdout.lock());
    let mut scanner = Scanner::new(stdin.lock());
    let tests: usize = 1;
    for _ in 0..tests {
        solve(&mut scanner, &mut writer);
    }
}


#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      n: u64,
    }
    if n%2 == 1 {
        println!("{}", 0);
    } else {
        let ans = 1 << (n/2);
        println!("{}", ans);
    }
}


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(),
            )+
        )
    }}
}

fn main() {
    let length = readln!(usize);

    if length % 2 == 0 {
        println!("{}", 1 << (length / 2));
    } else {
        println!("0");
    }
}


#[allow(unused_imports)]
use std::cmp::{max,min};
#[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() {
    readln!();
    let a = readvec!(i32);
    let last = a[a.len()-1];
    if last == 0 {
        println!("UP");
    } else if last == 15 {
        println!("DOWN");
    } else if a.len() == 1 {
        println!("-1");
    } else if a[a.len()-2] < a[a.len()-1] {
        println!("UP");
    } else if a[a.len()-2] > a[a.len()-1] {
        println!("DOWN");
    }
}


use std::io;

fn main()
{
	let mut s = String::new();
	let mut n = String::new();
	io::stdin().read_line(&mut n).unwrap();
	let n = n.trim().parse::<u8>().unwrap();
	io::stdin().read_line(&mut s).unwrap();
	s = s.trim().to_string();
	let val: Vec<i8> = s.split(" ").map(|x: &str| x.parse::<i8>().unwrap()).collect();

	if let Ok(res) = match val[val.len()-1] {
		0 => Ok("UP"),
		15 => Ok("DOWN"),
		_ => if val.len() > 1 {
			match val[val.len()-1] - val[val.len()-2] {
				1 => Ok("UP"),
				-1 => Ok("DOWN"),
				_ => Err("invalid input"),
			}
		} else {
			print!("{}", -1);
			return;
		}
	} {
		print!("{}", res);
	}
	else {
		print!("{}", "invalid input");
	}

}


struct FenwickTree {
    val: Vec<i64>,
}

impl FenwickTree {
    fn new(n: usize) -> Self {
        FenwickTree {
            val: vec![0; n + 1],
        }
    }
    fn add(&mut self, mut x: usize, v: i64) {
        while let Some(p) = self.val.get_mut(x) {
            *p += v;
            x += x & (!x + 1);
        }
    }
    fn sum(&mut self, mut x: usize) -> i64 {
        assert!(x < self.val.len());
        let mut ans = 0;
        while x > 0 {
            ans += self.val[x];
            x -= x & (!x + 1);
        }
        ans
    }
}

fn sieve(n: usize) -> Vec<i64> {
    let mut is_prime = vec![true; n + 1];
    for i in 2.. {
        if i * i > n {
            break;
        }
        if is_prime[i] {
            let mut j = i * i;
            while j <= n {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    let len = is_prime.iter().skip(2).filter(|p| **p).count();
    let mut prime = Vec::with_capacity(len);
    for (i, is_prime) in is_prime.into_iter().enumerate().skip(2) {
        if is_prime {
            prime.push(i as i64);
        }
    }
    prime
}

struct PrimeCountSolver {
    query: Vec<i64>,
    memo: Vec<i64>,
}

impl PrimeCountSolver {
    fn new() -> Self {
        PrimeCountSolver {
            query: vec![],
            memo: vec![],
        }
    }
    fn add(&mut self, n: i64) {
        self.query.push(n);
    }
    fn build(&mut self) {
        self.query.sort();
        self.query.dedup();
        let n = self.query.last().map_or(1, |n| *n);
        let mut m = 1;
        while (m + 1) * (m + 1) <= n {
            m += 1;
        }
        let p = sieve(m as usize);
        let bound = (n as f64).cbrt().powi(2) as i64 + 2;
        let mut stack = vec![];
        for &v in self.query.iter() {
            let k = match p.binary_search_by(|&p| (p * p).cmp(&v)) {
                Ok(k) => k + 1,
                Err(k) => k,
            };
            stack.push((v, k));
        }
        let mut query = vec![];
        while let Some((n, k)) = stack.pop() {
            if k == 0 {
                continue;
            }
            let q = p[k - 1];
            if q * q > n {
                let x = match p[..k].binary_search_by(|&p| (p * p).cmp(&n)) {
                    Ok(k) => k + 1,
                    Err(k) => k,
                };
                stack.push((n, x));
            } else if n <= bound {
                query.push((k, n));
            } else {
                stack.push((n, k - 1));
                stack.push((n / q, k - 1));
            }
        }
        query.sort();
        query.dedup();
        let m = bound as usize;
        let mut bit = FenwickTree::new(m);
        for i in 1..=m {
            bit.add(i, 1);
        }
        let mut is_prime = vec![true; m + 1];
        let mut memo = vec![0; query.len()];
        let mut pos = 0;
        for (i, p) in p.iter().enumerate() {
            let p = *p as usize;
            let mut j = p;
            while j <= m {
                if is_prime[j] {
                    bit.add(j, -1);
                }
                is_prime[j] = false;
                j += p;
            }
            while let Some(&(k, n)) = query.get(pos) {
                if k > i + 1 {
                    break;
                } else {
                    memo[pos] = bit.sum(n as usize);
                    pos += 1;
                }
            }
            if pos >= query.len() {
                break;
            }
        }
        self.memo.clear();
        self.memo.resize(self.query.len(), 0);
        let mut stack = vec![];
        for (i, &n) in self.query.iter().enumerate() {
            let k = match p.binary_search_by(|&p| (p * p).cmp(&n)) {
                Ok(k) => k + 1,
                Err(k) => k,
            };
            self.memo[i] += k as i64 - 1;
            stack.push((n, k, 1, i));
        }
        while let Some((n, k, sign, i)) = stack.pop() {
            if k == 0 {
                self.memo[i] += sign * n;
                continue;
            }
            let q = p[k - 1];
            if q * q > n {
                let x = match p[..k].binary_search_by(|p| (p * p).cmp(&n)) {
                    Ok(k) => k + 1,
                    Err(k) => k,
                };
                self.memo[i] += -sign * (k - x) as i64;
                stack.push((n, x, sign, i));
            } else if n <= bound {
                self.memo[i] += sign * memo[query.binary_search(&(k, n)).unwrap()];
            } else {
                stack.push((n, k - 1, sign, i));
                stack.push((n / q, k - 1, -sign, i));
            }
        }
    }
    fn get(&self, n: i64) -> i64 {
        self.memo[self.query.binary_search(&n).unwrap()]
    }
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: i64 = s.trim().parse().unwrap();
    let p = sieve((n as f64).sqrt() as usize + 2);
    let mut ans = 0i64;
    for p in p.iter() {
        if p.pow(3) <= n {
            ans += 1;
        } else {
            break;
        }
    }
    let mut solver = PrimeCountSolver::new();
    for (i, p) in p.iter().enumerate() {
        if p.pow(2) <= n {
            ans -= i as i64 + 1;
            solver.add(n / *p);
        }
    }
    solver.build();
    for p in p.iter() {
        if p.pow(2) <= n {
            ans += solver.get(n / *p);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


use std::io::{self, prelude::*};

#[allow(unused_must_use)]
#[allow(unused_assignments)]
#[allow(unused_variables)]
fn solve<B: BufRead, W: Write>(mut scan: Scanner<B>, mut w: W) {
    let sum = scan.token::<String>();
    let mut s: Vec<i64> = Vec::new();
    for n in sum.split('+') {
        s.push(n.parse().unwrap());
    }
    s.sort();
    let mut ans = vector_to_str(&s, "+");
    ans.pop();
    writeln!(w, "{}", ans);
}

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    solve(reader, writer);
}
#[allow(dead_code)]
fn vector_to_str<T: ToString>(vector: &Vec<T>, separator: &str) -> String {
    use std::fmt::Write;
    let mut ans = String::new();
    for line in vector.iter() {
        write!(&mut ans, "{}{}", line.to_string(), separator).unwrap();
    }
    ans
}
#[allow(dead_code)]
fn matrix_to_str<T: ToString>(matrix: &Vec<Vec<T>>, separator: &str) -> String {
    use std::fmt::Write;
    let mut ans = String::new();
    for line in matrix.iter() {
        for elem in line.iter() {
            write!(&mut ans, "{}{}", elem.to_string(), separator).unwrap();
        }
        write!(&mut ans, "\n").unwrap();
    }
    ans
}
pub struct Scanner<B> {
    reader: B,
    buf_str: Vec<u8>,
    buf_iter: std::str::SplitWhitespace<'static>,
}
impl<B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        Self {
            reader,
            buf_str: Vec::new(),
            buf_iter: "".split_whitespace()
        }
    }
    pub fn token<T: std::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 = std::str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace()) }
        }
    }
    pub fn get_matrix<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>> {
        // m rows and n columns
        let mut ans: Vec<Vec<T>> = Vec::with_capacity(m);
        for i in 0..m {
            ans.push(Vec::with_capacity(n));
            for _ in 0..n {
                ans[i].push(self.token::<T>());
            }
        }
        ans
    }
    pub fn get_vector<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut ans: Vec<T> = Vec::with_capacity(n);
        for _ in 0..n {
            ans.push(self.token::<T>());
        }
        ans
    }
}


use std::io::stdin;
fn main() {
    let mut inp = String::new();
    stdin().read_line(&mut inp).expect("msg: &str");
    let mut inp = inp.trim();
    let mut a: Vec<u8> = inp
        .split("+")
        .collect::<Vec<&str>>()
        .iter()
        .map(|e| e.parse::<u8>().unwrap())
        .collect();
    a.sort();
    let a: Vec<String> = a.iter().map(|e| format!("{}", e)).collect();
    println!("{}", a.join("+"));
}


//spnauti-rust
#[allow(unused_imports)]
use std::io::{self,Read};

struct WordReader {
    it : std::vec::IntoIter<String>,
}
#[allow(dead_code)]
impl WordReader {
    fn new<T : 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 main() {
    let mut input = WordReader::from_stdin();
    if input.s() == input.s().chars().rev().collect::<String>() {
        println!("YES");
    } else {
        println!("NO");
    }
}


#[allow(unused)] use std::io::*;
#[allow(unused)] use std::collections::*;
#[allow(unused)] use std::mem::*;
#[allow(unused)] use std::num::*;
#[allow(unused)] use std::cmp::*;
#[allow(unused)] fn strarr() -> Vec<String> {
    let mut inp = String::new();
    stdin().read_line(&mut inp).ok();
    inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).map(|x| x.to_string()).collect() }
#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{
    let s = strarr(); let mut cnt : usize = 0;
    fn next<T>(cnt: &mut usize, p: &Vec<String>) -> T
        where T:std::str::FromStr
        { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }
    ($(next::<$x>(&mut cnt, &s)), +)
    }}; }
#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{
    let mut s = strarr(); let mut v = Vec::new();
    for i in 0..$n { v.push(s[i as usize].parse::<$T>().unwrap()); } v
    }}; }

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

fn main()
{
    let s = scan!(String);
    let t = scan!(String);
    println!("{}", if s.chars().rev().collect::<Vec<char>>() == t.chars().collect::<Vec<char>>() { "YES" } else { "NO" });
}


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

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

    let number = input.trim().parse::<i32>().expect("NUMBER::Parse to i32 failed!");

    if number % 2 == 0 {
        println!("Mahmoud");
    }else {
        println!("Ehab");
    }
}


//spnauti-rust
#[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 }
    }};
}
use std::io::*;
use std::str::*;
use std::fmt::Debug;
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).unwrap();
        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()
    }
}

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

    println!("{}", ["Mahmoud","Ehab"][input.u() % 2]);
}


fn main() {
    let mut input = String::new();
    use std::io;
    use std::io::prelude::*;
    io::stdin().read_to_string(&mut input).unwrap();

    let mut it = input.split_whitespace();

    it.next().unwrap();

    let a: Vec<i32> = it.map(|x| x.parse().unwrap()).collect();

    let ans: i32 = a.into_iter().map(|x| x.abs()).sum();
    println!("{}", ans);
}


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

// ここまで

fn run() {
    input! {
        n: usize,
        a: [i32; n],
    }
    let mut ans = 0;
    for a in a {
        ans += a.abs();
    }
    println!("{}", ans);
}

fn main() {
    run();
}


use std::io;

fn read_int_line () -> i32 {
    let mut num = String::new();
    io::stdin().read_line(&mut num)
        .expect("Failed to read line");

    num.trim().parse()
        .expect("Not an integer")
}

fn main() {

	read_int_line();

	let mut string = String::new();
	io::stdin().read_line(&mut string)
		.expect("Failed to read line");

	let v: Vec<&str> = string.split(char::is_uppercase).collect();
	let mut maximum: i32 = 0;

	for s in v {
		let mut vi: Vec<char> = s.trim().chars().collect();
		vi.sort();
		vi.dedup();
		let temp: i32 = vi.len() as i32;
		if maximum < temp {
			// println!("{:?}, {:?}", s.trim(), temp);
			maximum = temp;
		}
	}
	println!("{}", maximum);
}


#[allow(unused)] use std::io::*;
#[allow(unused)] use std::collections::*;
#[allow(unused)] use std::mem::*;
#[allow(unused)] use std::num::*;
#[allow(unused)] use std::cmp::*;
#[allow(unused)] fn strarr() -> Vec<String> {
    let mut inp = String::new();
    stdin().read_line(&mut inp).ok();
    inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).map(|x| x.to_string()).collect() }
#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{
    let s = strarr(); let mut cnt : usize = 0;
    fn next<T>(cnt: &mut usize, p: &Vec<String>) -> T
        where T:std::str::FromStr
        { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }
    ($(next::<$x>(&mut cnt, &s)), +)
    }}; }
#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{
    let mut s = strarr(); let mut v = Vec::new();
    for i in 0..$n { v.push(s[i as usize].parse::<$T>().unwrap()); } v
    }}; }

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

fn main()
{
    let s = scan!(String);
    let c1 = s.chars().filter(|x| x.is_lowercase()).count();
    let c2 = s.chars().nth(0).unwrap().is_lowercase();
    if c1 == 0 || (c1 == 1 && c2 == true) {
        for i in s.chars() {
            print!("{}", if i.is_lowercase() { i.to_uppercase().nth(0).unwrap() } else { i.to_lowercase().nth(0).unwrap() });
        }
    } else {
        print!("{}", s);
    }

}


fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let line = line.trim();
    let s0 = line.to_string().to_uppercase();
    let ss = s0.as_str();
    let s1 = (&ss[0..1]).to_string().to_lowercase() + &s0[1..];

    let s2 = line.to_string().to_lowercase();
    let s3 = (&ss[0..1]).to_string().to_uppercase() + &s2[1..];

    if s0.eq(line) {
        println!("{}", s2);
    } else if s1.eq(line) {
        println!("{}", s3);
    } else {
        println!("{}", line);
    }
}


//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_imports)] use std::cell::*;
#[allow(unused_macros)] macro_rules! min {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! max {
	($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};
}
#[allow(unused_macros)] macro_rules! l {
	($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};
	($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};
	(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};
	(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};
}
#[allow(unused_macros)] macro_rules! v {
	([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};
	([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};
}
#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }
#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }
#[allow(dead_code)] fn writer() -> BufWriter<Stdout> { BufWriter::new(stdout()) }
struct WordReaderC {buf: Vec<u8>, pos: usize, q: std::io::StdinLock<'static>}//'
#[allow(dead_code)] impl WordReaderC {
	fn new() -> Self {
		let r = unsafe {&*Box::into_raw(Box::new(stdin()))};
		Self { q: r.lock(), buf: v!([]), pos: 0 }
	}
	fn next_line(&mut self) -> bool {
		self.buf.clear(); self.pos = 0;
		self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0
	}
	fn is_ws(c: u8) -> bool {
		c == b' ' || c == b'\r' || c == b'\n' || c == b'\t'
	}
	fn byte(&mut self) -> Option<u8> {
		if self.pos == self.buf.len() { if !self.next_line() { return None; } }
		self.pos += 1; Some(self.buf[self.pos - 1])
	}
	fn vb(&mut self) -> Vec<u8> {
		let mut s = v!([8]);
		let mut f = false;
		loop {
			if let Some(c) = self.byte() {
				if !Self::is_ws(c) {
					s.push(c);
					f = true;
				} else if f { break; }
			} else { break; }
		}
		s
	}
	fn vvb(&mut self, r: usize, c: Option<usize>) -> Vec<Vec<u8>> {
		let mut res = v!([r]);
		let c = c.unwrap_or(0);
		rep!{[r]
			let t = self.vb();
			assert!(c == 0 || t.len() == c);
			res.push(t);
		}
		res
	}
	fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") }
	fn i(&mut self) ->    i32 { self.p() }
	fn l(&mut self) ->    i64 { self.p() }
	fn u(&mut self) ->  usize { self.p() }
	fn f(&mut self) ->    f64 { self.p() }
	fn vi(&mut self, n: usize) -> Vec<i32> { self.vp(n) }
	fn vl(&mut self, n: usize) -> Vec<i64> { self.vp(n) }
	fn vu(&mut self, n: usize) -> Vec<usize> { self.vp(n) }
	fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> { self.ip(n).into_iter() }
	fn iu(&mut self, n: usize) -> impl Iterator<Item=usize> { self.ip(n).into_iter() }
	fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
		let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap()
	}
	fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
		(0..n).map(|_|self.p()).collect()
	}
	fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
		self.vp(n).into_iter()
	}
	fn graph(&mut self, n: usize, m: usize) -> Vec<Vec<usize>> {
		let mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); e[a].push(b); e[b].push(a); } e
	}
	fn graph_w<T: Copy+FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<(usize,T)>> where T::Err: Debug {
		let mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); let c: T = self.p(); e[a].push((b,c)); e[b].push((a,c)); } e
	}
}
//------------------- End rusT }}}

// Field (mod prime) {{{
mod field {
	use std::ops::*;
	#[allow(dead_code)] pub const Z0: Field = Field(0);
	#[allow(dead_code)] pub const Z1: Field = Field(1);
	const P5: i32 = 1_000_000_007;
	const P6: i64 = P5 as i64;
	#[derive(Debug,Clone,Copy,PartialEq,Eq,PartialOrd,Ord,Default)] pub struct Field(i32);
	#[allow(dead_code)] impl Field {
		pub fn new<T: Into<i64>>(a: T) -> Self { Self(Self::cv(a)) }
		pub fn new_unchecked(a: i32) -> Self { Self(a) }
		fn hi(mut a: i32) -> i32 { if a >= P5 { a -= P5; } a }
		fn lo(mut a: i32) -> i32 { if a < 0 { a += P5; } a }
		fn cv<T: Into<i64>>(a: T) -> i32 { Self::lo((a.into() % P6) as i32) }
		pub fn inv(self) -> Self { self.pow(P5-2) }
		pub fn pow<T: Into<i64>>(self, b: T) -> Self {
			let b = b.into(); if b == 0 { Self(1) } else {
				let mut res = self.pow(b/2); res *= res; if b % 2 == 1 {res *= self;} res
			}
		}
	}
	impl Add for Field { type Output = Self; fn add(self, a: Self) -> Self::Output { Self(Self::hi(self.0 + a.0)) }}
	impl Sub for Field { type Output = Self; fn sub(self, a: Self) -> Self::Output { Self(Self::lo(self.0 - a.0)) }}
	impl Mul for Field { type Output = Self; fn mul(self, a: Self) -> Self::Output { Self(Self::cv(self.0 as i64 * a.0 as i64)) }}
	impl Div for Field { type Output = Self; fn div(self, a: Self) -> Self::Output { self * a.inv() }}
	impl Neg for Field { type Output = Self; fn neg(self) -> Self::Output { Self(Self::lo(-self.0)) }}
	impl AddAssign for Field { fn add_assign(&mut self, a: Self) { *self = *self + a; } }
	impl SubAssign for Field { fn sub_assign(&mut self, a: Self) { *self = *self - a; } }
	impl MulAssign for Field { fn mul_assign(&mut self, a: Self) { *self = *self * a; } }
	impl DivAssign for Field { fn div_assign(&mut self, a: Self) { *self = *self / a; } }
	use std::fmt::{Display, Formatter, Result};
	impl Display for Field { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.0) } }
}
#[allow(unused_imports)] use field::{Field, Field as Z, Z0, Z1};
//}}}
// Binomial Coefficient (C(n,r)) {{{
#[derive(Debug,Clone)]
struct Cnr {
	n: usize,
	pub f: Box<[Field]>,
	fi: Box<[Field]>
}
#[allow(dead_code)]
impl Cnr {
	fn new(n: usize) -> Self {
		let mut f = Vec::with_capacity(n+1);
		f.push(Z1);
		for i in 1..=n {
			f.push(f[i-1] * Field::new(i as i32));
		}
		let mut fi = vec![Z1; n+1];
		fi[n] = f[n].inv();
		for i in (0..n).rev() {
			fi[i] = fi[i+1] * Field::new(i as i32 + 1);
		}
		let f = f.into_boxed_slice();
		let fi = fi.into_boxed_slice();
		Self {n, f, fi}
	}
	fn cnr(&self, n: usize, r: usize) -> Field {
		if r > n {
			Z0
		} else {
			self.f[n] * self.fi[r] * self.fi[n-r]
		}
	}
}//}}}

fn main() {
	let mut rin = reader();
	let mut rout = writer();

	l!(n,x,p = rin.u());
	let x = x-1;
	let mut lo = 0;
	let mut hi = n;
	l!(mut lo_fix,hi_fix = 0);
	while lo < hi {
		let mid = (lo + hi) / 2;
		if mid == p {
			lo = mid + 1;
		} else if mid < p {
			lo_fix += 1;
			lo = mid + 1;
		} else {
			hi_fix += 1;
			hi = mid;
		}
	}

	let f = Cnr::new(n);
	let sol = f.cnr(x, lo_fix) * f.f[lo_fix] * f.cnr(n-1-x, hi_fix) * f.f[hi_fix] * f.f[n - hi_fix - lo_fix - 1];
	writeln!(rout, "{}", sol).ok();
}


use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

const MOD: i64 = 1e9 as i64 + 7;

fn count_needed(n: i64, pos: i64) -> (i64, i64) {
    let mut l = 0;
    let mut r = n;

    let mut smaller = 0;
    let mut greater = 0;

    while l < r {
        let m = (l + r) / 2;
        if m < pos {
            smaller += 1;
            l = m + 1;
        } else if m > pos {
            greater += 1;
            r = m;
        } else {
            l = m + 1;
        }
    }
    (smaller, greater)
}

fn factorial(n: i64) -> i64 {
    let mut res = 1;
    for i in 2..=n {
        res = (res * i) % MOD;
    }
    res
}

fn permutations(n: i64) -> i64 {
    factorial(n)
}

fn euclid(a: i64, b: i64) -> (i64, i64) {
    if b == 0 {
        (1, 0)
    } else {
        let (x, y) = euclid(b, a % b);
        (y, x - a / b * y)
    }
}

fn mod_inv(num: i64) -> i64 {
    let mut inv = euclid(num, MOD).0;
    while inv < 0 {
        inv += MOD;
    }
    inv
}

fn arrangements(n: i64, k: i64) -> i64 {
    factorial(n) * mod_inv(factorial(n - k)) % MOD
}

fn solve(n: i64, x: i64, pos: i64) -> i64 {
    let (smaller, greater) = count_needed(n, pos);
    if smaller >= x || greater > (n - x) {
        return 0;
    }

    arrangements(x - 1, smaller)
        * arrangements(n - x, greater) % MOD
        * permutations(n - 1 - smaller - greater) % MOD

}

fn main() {
    let mut reader = TokenReader::new();
    let n = reader.next();
    let x = reader.next();
    let pos = reader.next();

    let res = solve(n, x, pos);
    println!("{}", res);
}


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

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: 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();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}

fn count_prime_factors(n: i32) -> i32 {
    let mut count = 0;
    let mut factor = 2;
    let mut n = n;
    while factor * factor <= n {
        let mut expo = 0;
        while n % factor == 0 {
            n /= factor;
            expo += 1;
        }
        if expo >= 1 {
            count += 1;
        }
        factor += 1;
    }
    if n > 1 {
        count += 1;
    }
    count
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let n: i32 = scan.token();
    let mut ans = 0;
    for i in 1..=n {
        let count = count_prime_factors(i);
        if count == 2 {
            ans += 1;
        }
    }
    writeln!(out, "{}", ans).ok();
}

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);
}


//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::*;
#[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).unwrap();
        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 main() {
    let mut bin = String::new();
    let mut input = WordReader::from_stdin(&mut bin);

    let res = input.bs().iter().fold(0, |a,&x| match (a,x - b'0') {
        (0...2,1) => 2,
        (y@1...2,4) => y - 1,
        _ => -1,
    }) >= 0;
    if res {
        println!("YES");
    } else {
        println!("NO");
    }
}


fn main() {
    let s = get_input();
    if is_magic_number(s) {
        println!("YES");
    } else {
        println!("NO");
    }

}

fn is_magic_number(s: String) -> bool {
    if !s.starts_with("1") {
        false
    } else {
        let mut four_count = 0;
        for c in s.chars() {
            if c == '1' {
                four_count = 0;
            } else if c == '4' {
                four_count += 1;
                if four_count > 2 {
                    return false;
                }
            } else {
                return false;
            }
        }

        true
    }
}

fn get_input() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Failed");
    buffer.trim().to_owned()
}

fn get_input_usize() -> usize {
    get_input().parse().unwrap()
}


#![allow(unused_imports)]
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let num_squares = get_numbers(&input)[0];
    input.clear();
    io::stdin().read_line(&mut input).unwrap();
    let squares: Vec<char> = input.chars().collect();

    let mut numbers = Vec::new();
    let mut n = 0;
    for i in 0..num_squares {
        if squares[i] == 'B' {
            n += 1;
        } else if n > 0 {
            numbers.push(n);
            n = 0;
        }
    }
    if n > 0 {
        numbers.push(n);
    }

    if numbers.len() == 0 {
        println!("{}", 0);
        return;
    }
    println!("{}", numbers.len());
    if numbers.len() == 1 {
        println!("{}", numbers[0]);
        return;
    }

    for i in 0..(numbers.len()-1) {
        print!("{} ", numbers[i])
    }
    println!("{}", numbers[numbers.len()-1]);
}

// get numbers from line seperated by spaces
fn get_numbers<T>(line: &str) -> Vec<T>
    where T: FromStr,
          <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    line.split_whitespace()
        .map(|chunk| chunk.parse::<T>().expect("failed to parse"))
        .collect()
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        x: [i32; 3],
        a: [i32; 3],
    }
    let mut c = 0;
    for i in 0..3 {
        c += a[i];
        if x[i] > c {
            puts!("NO\n");
            return;
        }
        c -= x[i];
    }
    puts!("YES\n");

}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


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(),
            )+
        )
    }}
}

fn main() {
    let (mut x, mut y, mut z) = readln!(i32, i32, i32);
    let (mut a, mut b, mut c) = readln!(i32, i32, i32);

    let mut ans = solve(x, y, z, a, b, c);
    println!("{}", ["YES", "NO"][ans]);
}

fn solve(x: i32, y: i32, z: i32, a: i32, b: i32, c: i32) -> usize {
  if x > a || x + y > a + b || x + y + z > a + b + c {
    1
  } else {
    0
  }
}


use std::collections::HashMap;
use std::io::{self, BufRead};
fn main() {
    let mut line = "".to_string();
    let stdin = io::stdin();
    stdin.lock().read_line(&mut line).unwrap();
    let (_, limit) = if let [Ok(a), Ok(b)] = &line
        .split_whitespace()
        .map(|s| s.parse::<usize>())
        .collect::<Vec<_>>()[..]
    {
        (*a, *b)
    } else {
        (0, 0)
    };
    line.clear();
    stdin.lock().read_line(&mut line).unwrap();
    if line
        .bytes()
        .fold(&mut HashMap::new(), |map, s| {
            *map.entry(s).or_insert(0) += 1;
            map
        })
        .iter()
        .filter(|(_, &cnt)| cnt > limit)
        .count()
        > 0
    {
        println!("NO");
    } else {
        println!("YES");
    }
}


#![allow(unused_imports)]
use std::io::{self, BufRead};
use std::cmp::*;
use std::collections::*;

macro_rules! scan_to_vec {
    ($count:expr, $t:ty) => ({
        let mut result = Vec::new();
        let stdin = io::stdin();
        let mut handle = stdin.lock();

        for _ in 0..$count {
            let mut buffer = String::new();
            handle.read_line(&mut buffer)
                .expect("scan_to_vec: failed at `handle.read_line`.");
            result.push(buffer.trim().parse::<$t>()
                .expect("scan_to_vec: failed at `parse::<$t>`."));
        }
        result
    })
}

macro_rules! scan_line_to_vec {
    ($t:ty) => ({
        let mut result = Vec::new();
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        handle.read_line(&mut buffer)
            .expect("scan_line_to_vec: failed at `handle.read_line`.");

        for s in chunks.split_whitespace() {
            result.push(s.parse::<$t>()
                .expect("scan_line_to_vec: failed at `parse::<$t>`."));
        }
        result
    })
}

macro_rules! scan_line {
    () => ({
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        let mut buffer = String::new();
        handle.read_line(&mut buffer)
            .expect("scan_line: failed at `handle.read_line`.");
        buffer
    });
    ( $($t:ty)+ ) => ({
        let stdin = io::stdin();
        let mut handle = stdin.lock();
        let mut buffer = String::new();
        handle.read_line(&mut buffer)
            .expect("scan_line: failed at `handle.read_line`.");
        let mut chunks = buffer.split_whitespace();

        ($(
            {
                chunks.next()
                    .expect("scan_line: failed at `next`, # of space separated strings not equal to requested #")
                .parse::<$t>()
                    .expect("scan_line: failed at `parse::<$t>`.")
            },
        )+)
    })
}

fn main() {
    let (n, k) = scan_line!(i32 i32);
    let colors = scan_line!();
    let mut color_counts = vec![0; 256];

    let mut result = true;
    for c in colors.bytes() {
        color_counts[c as usize] += 1;
    }

    for c in color_counts {
        if c > k {
            result = false;
            break;
        }
    }

    if result {
        println!("YES")
    } else {
        println!("NO")
    }
}


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

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut buf).unwrap();
    let n: u32 = buf.trim().parse().unwrap();
    for k in 0..n {
        buf.clear();
        stdin.read_line(&mut buf).unwrap();
        let x: u32 = buf.trim().parse().unwrap();
        let b = x / 7;
        let a = (x % 7) % 3;
        if a == 0 || b >= (3 - a) {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}


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

// ここまで

fn run() {
    input! {
        n: u64,
    }
    let ans = (n * (n + 1) / 2) % 2;
    println!("{}", ans);
}

fn main() {
    run();
}


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 n: u64 = scan.next();
    let result = (n * (n + 1) / 2) % 2;
    println!("{}", result);
}

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


use std::io;

fn get_single_number_from_stdin() -> u64 {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).unwrap();
    buffer.trim().parse::<u64>().expect("Not an integer")
}

fn main(){
    let mut dollars = get_single_number_from_stdin();
    let denominations = vec![100,20,10,5,1];
    let mut total_bills = 0;
    for denomination in denominations {
        if dollars == 0 {
            break;
        }
        if dollars >= denomination {
            let q = (dollars/denomination) as u64;
            dollars -= denomination * q;
            total_bills += q;
        }else{
            continue;
        }
    }
    print!("{}",total_bills);
}


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

fn main() -> io::Result<()> {
    let mut buffer = String::new();
    let input = stdin();
    input.read_line(&mut buffer)?;
    let mut money: u32 = buffer.trim().parse().expect("Not int");
    let mut bills = 0;
    let denoms = [100, 20, 10, 5, 1];
    for denom in &denoms {
        bills += money / denom;
        money %= denom;
        if money == 0 {
            break;
        }
    }
    println!("{}", bills);
    Ok(())
}


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 main() {
    // initialize stdin
    let sin = std::io::stdin();
    let mut sin = sin.lock();
    let sin = &mut sin;

    let a: i64 = read(sin);
    let b: i64 = read(sin);
    let c: i64 = read(sin);

    if b == 1 {
        let ans = if a <= c {
            if c == 1 {
                // a == b == c == 1
                a + b + c
            } else {
                (a + b) * c
            }
        } else {
            a * (b + c)
        };
        println!("{}", ans);
        return;
    }

    if c == 1 && a != 1 {
        println!("{}", a * (b + c));
        return;
    }

    let pre_val = if a == 1 { a + b } else { a * b };
    let ans = if c == 1 { pre_val + c } else { pre_val * c };

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


use std::str::FromStr;

fn read_str() -> String {
    let mut buffer: String = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Error");
    buffer.trim().to_string()
}

fn read_int<T: FromStr>() -> T{
    read_str().parse::<T>().ok().expect("Error")
}

fn main() {
    let (a, b, c): (u16, u16, u16) = (read_int(), read_int(), read_int());

    if a + c == 2 { println!("{}", a + b + c); }
    else if a == 1 || b == 1 || c == 1 {
        if a < c { println!("{}", (a + b) * c); }
        else { println!("{}", a * (b + c)); }
    }
    else { println!("{}", a * b * c); }
}


//spnauti-rust
#[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 }
    }};
}
use std::io::*;
use std::str::*;
use std::fmt::Debug;
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).unwrap();
        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 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()
    }
}

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

    let n = input.i();
    let a = input.i();
    let b = input.i();
    println!("{}", (n - a).min(b + 1));
}


fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let x: usize = sc.read();
    let mut hh: usize = sc.read();
    let mut mm: usize = sc.read();
    let mut result = 24 * 60;
    for h in 0..24 {
        for m in 0..60 {
            if h == 7 || h == 17 || m == 7 || m == 17 || m == 27 || m == 37 || m == 47 || m == 57 {
                let mut cnt = 0;
                let mut tmp_h = h;
                let mut tmp_m = m;
                while tmp_h != hh || tmp_m != mm {
                    tmp_m += x;
                    if tmp_m >= 60 {
                        tmp_h += 1;
                        tmp_m %= 60;
                    }
                    if tmp_h >= 24 {
                        tmp_h = 0;
                    }
                    cnt += 1;
                    if cnt > 24 * 60 {
                        break;
                    }
                }

                result = std::cmp::min(result, cnt);
            }
        }
    }
    println!("{}", result);
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


// 長さ10^100 な文字列Tがある、最初全部0
// 文字列S が与えられる
// S を T のどこかにxorするみたいなことができる
// 1が二つとなるように操作する時出来上がるTの辞書順最大を求めて
//
// |S| <= 35
//
// なんかサンプル4ですごい数が出てきてる
//
// 不可能な場合って何？
// 0のみ、不可能
// それ以外で不可能な場合は？
// わからん
// 1一つ, 2つ
// 詰めて置けばいい
// ３つ以上？
// 最初の1は確定する
// というの最初を使うと最初の１は確定するし、使わないで得られた答えはスライドさせてより大きくできる
// 残った部分になんかxorしていく感じ
// やれることが前からxorしていくことしかないが
//
// S の最初、最後の0を削っておく
// なんかコンパニオン行列をかけまくって (0, 0, ..., 1) になる最小の数
// みたいな問題になる
// 線形代数ゲー？ようわからん
// S の1文字目の1を削ったやつをs, 単位ベクトルをe_i と置く
// k = |S| - 1 として
//
// s * mat [s, e_1, .., e_{k - 1}] ^n = e_k
//
// となるようなn の最小値、ないならそれ報告
// 離散対数？
// ちょっと間に合わない感
// いや2^18 程度なら間に合ってもいいんじゃ
// 間に合ってもいい気はするがなんか BS-GS に持ち込めない
// 上の前処理すると A は逆行列を持つようになる
//
// s A^n = e_k
// s A^(qx + r) = e_k
// s A^(qx) = e_k A^(-r)
// これはいけそう
//
// ところで、最小性が問題になるが
// まあなんとかなるでしょ多分

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn run(mut s: Vec<u8>) -> Option<(usize, usize)> {
    s.iter_mut().for_each(|s| *s -= b'0');
    let c = s.iter().filter(|s| **s == 1).count();
    if c == 0 {
        return None;
    }
    let f = s.iter().position(|s| *s == 1).unwrap();
    if c == 1 {
        return Some((f, f + 1));
    }
    let mut s = s;
    s.drain(..=f);
    while s.last().map_or(false, |c| *c == 0) {
        s.pop();
    }
    let s = s;
    let k = s.len();
    let mut a = vec![vec![0u8; k]; k];
    for (i, s) in s.iter().enumerate() {
        a[0][i] = *s;
    }
    for i in 1..k {
        a[i][i - 1] = 1;
    }
    let inv_a = inverse_matrix(a.clone()).unwrap();
    let mut right = vec![0; k];
    right[k - 1] = 1u8;
    let sq = 1 << (k / 2 + 1);
    let mut map = Map::new();
    for i in 0..=sq {
        map.entry(right.clone()).or_insert(i);
        let mut next = vec![0; k];
        for (right, inv_a) in right.iter().zip(inv_a.iter()) {
            for (next, inv_a) in next.iter_mut().zip(inv_a.iter()) {
                *next ^= *right & *inv_a;
            }
        }
        right = next;
    }
    let mul = |a: &[Vec<u8>], b: &[Vec<u8>]| -> Vec<Vec<u8>> {
        let mut c = vec![vec![0; k]; k];
        for (c, a) in c.iter_mut().zip(a.iter()) {
            for (a, b) in a.iter().zip(b.iter()) {
                for (c, b) in c.iter_mut().zip(b.iter()) {
                    *c ^= *a & *b;
                }
            }
        }
        c
    };
    let mut mat = vec![vec![0; k]; k];
    for i in 0..k {
        mat[i][i] = 1;
    }
    for i in (0..20).rev() {
        mat = mul(&mat, &mat);
        if sq >> i & 1 == 1 {
            mat = mul(&mat, &a);
        }
    }
    let rad = mat;
    let mut mat = vec![vec![0; k]; k];
    for i in 0..k {
        mat[i][i] = 1;
    }
    for i in 0..=sq {
        let mut b = vec![0; k];
        for (s, mat) in s.iter().zip(mat.iter()) {
            for (b, mat) in b.iter_mut().zip(mat.iter()) {
                *b ^= *s & *mat;
            }
        }
        if let Some(v) = map.get(&b) {
            return Some((f, sq * i + v + f + k));
        }
        mat = mul(&mat, &rad);
    }
    None
}

fn inverse_matrix(mut mat: Vec<Vec<u8>>) -> Option<Vec<Vec<u8>>> {
    let n = mat.len();
    assert!(mat.iter().all(|mat| mat.len() == n));
    for (i, mat) in mat.iter_mut().enumerate() {
        mat.resize(2 * n, 0);
        mat[n + i] = 1;
    }
    for i in 0..n {
        let x = (i..n).find(|x| mat[*x][i] != 0)?;
        mat.swap(i, x);
        let a = std::mem::take(&mut mat[i]);
        for mat in mat.iter_mut().filter(|mat| !mat.is_empty()) {
            let mul = mat[i];
            for (mat, a) in mat[i..].iter_mut().zip(a[i..].iter()) {
                *mat ^= mul & *a;
            }
        }
        mat[i] = a;
    }
    Some(mat.iter().map(|a| Vec::from(&a[n..])).collect())
}

fn main() {
    input! {
        s: bytes,
    }
    if let Some((a, b)) = run(s) {
        println!("{} {}", a + 1, b + 1);
    } else {
        println!("-1");
    }
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
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_export]
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_export]
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")
    };
}
// ---------- end input macro ----------


use std::io;
use std::str::FromStr;
use std::io::prelude::*;

fn get_line() -> String {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input
}

fn get_vec<T>() -> Vec<T>
where T: FromStr,
      <T as FromStr>::Err: std::fmt::Debug,
{
    get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn main() {
    let (k, p): (usize, usize) = {
        let input = get_line();
        let mut it = input.split_whitespace()
            .map(|x| x.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let p = p as u64;

    let mul = |a, b| {
        (a * b) % p
    };

    let pow10 = |k| {
        let mut ret_val = 1;
        for _ in 0..k {
            ret_val = mul(ret_val, 10);
        }
        ret_val
    };

    let mut ans = 0;

    for i in (1..).take(k) {
        let s = format!("{}", i);
        let n = s.len() as u64;
        for (ind, d) in s.bytes().enumerate() {
            let d = (d - b'0') as u64;
            let ind = ind as u64;
            ans = (ans + d * pow10(ind)) % p;
            ans = (ans + d * pow10(2 * n - 1 - ind)) % p;
        }
    }

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

struct Solver {
}

impl Solver {
}


#![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};

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; while a != 0 { swap(&mut a, &mut b); a %= b; }
                    b
                }
                #[inline] fn highest_one(self) -> Self {
                    if self == 0 { 0 } else { const ONE: $ux = 1; ONE.rotate_right(1) >> self.leading_zeros() }
                }
                #[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, mut b: Self) -> Self {
                    let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }
                    b.abs()
                }
                #[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;
    }

    #[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(mul_mod_u32(self.val, rhs.into().val, Self::modulus()))
        }
    }
    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 }
            }
            pub type $mint = ModIntBase<$name>;
        }
    }

    macro_rules! dynamic_modulus {
        ($mint: ident, $name: ident, $modulus: ident) => {
            static $modulus: crate::Unsync<Cell<u32>> = crate::Unsync(Cell::new(0));
            #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
            pub enum $name {}
            impl Modulus for $name {
                fn get_modulus() -> u32 { $modulus.0.get() }
            }
            impl $name {
                pub fn set_modulus(val: u32) { $modulus.0.set(val) }
            }
            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;

#[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 a0 = read!(u64);
        let x = read!(u64);
        let y = read!(u64);
        let k = read!(usize);
        let M = read!(u64);

        let npow = mir(n as _).pow_vec(k-1);

        let mut C = 1usize;
        for i in 2..k {
            C = C / C.gcd(i) * i;
        }
        let mut dp = vec![mi(0); C];

        let mut ans = mi(0);
        let mult = mir((k * C) as _) * npow[k-1];
        let mut a = a0;
        for _ in 0..n {
            let q = (a as usize) / C;
            let r = (a as usize) % C;

            ans += mir(q as _) * mult;
            dp[r] += 1;
            a = (a * x + y) % M;
        }

        for i in 1..=k {
            let mut dn = vec![mi(0); C];
            for j in 0..C {
                ans += dp[j] * npow[k-i] * mir(j as _);
                dn[j] += dp[j] * mir((n-1) as _);
                dn[j - j % i] += dp[j];
            }
            dp = dn;
        }

        println!(ans);
    }

    out_flush();
}