#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter};
use std::io::*;
use std::ops::*;
use std::*;

// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        {
            let entries = [$(&stringify!([$arg]:), &$arg as &Debug),*];
            stderr().write_fmt(format_args!("{:#?}\n", entries)).unwrap();
        }
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

pub fn main() {
    let (_, d) = read!(usize, i64);
    let mut A = read![[i64]];
    A.sort();

    let mut l = 0;
    let mut r = 0;
    let mut ma = 0;
    while l < A.len() {
        while r < A.len() && A[r] - A[l] <= d {
            r += 1;
        }

        ma = max(ma, r - l);
        l += 1;
    }

    println!("{}", A.len() - ma);
    return;
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

#[allow(unused_macros)]
macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let n = parse_line!(u32);
    let m = parse_line!(u32);
    if n > 30 {
        writeln!(writer, "{}", m).unwrap();
    }else{
        writeln!(writer, "{}", m % (1 << n)).unwrap();
    }
}

fn main() {
    let mut writer = std::io::BufWriter::new(std::io::stdout());
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve(&mut writer);
    }
}


use std::io;
use std::io::Read;

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

    let n = get!(u64);
    let m = get!(u64);

    if n > 63 {
        println!("{}", m);
    } else {
        let x = (1 << n) - 1;
        println!("{}", m & x);
    }

}


use std::io::{self, Write};
use std::vec::Vec;
use std::string::String;

struct Point {
    x: i8,
    y: i8,
}

fn get_line() -> String {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line).expect("Failed to get input line");
    return line.trim().to_string();
}

fn main() {
    let target: Point = Point{
        x: 2,
        y: 2
    };
    let mut number_one: Point = Point{
        x: 2,
        y: 2,
    };
    for i in 0..5 {
        let line: String = get_line();
        let numbers: Vec<i8> = line.split_whitespace().map(
            |n| n.parse().unwrap()
        ).collect();
        for j in 0..5 {
            if numbers[j] == 1 {
                number_one = Point{
                    x: (i as i8),
                    y: (j as i8),
                };
            }
        }
    }
    let mut result: i8 = 0;
    result += (number_one.x - target.x).abs();
    result += (number_one.y - target.y).abs();
    println!("{}", result);

    io::stdout().flush().unwrap();
}


use std::io::Read;

fn main() {
    let inp = read_input();

    let index = inp.iter().position(|&i| i == 1).unwrap() as i32;
    let ans = (2 - ((index as f64 / 5 as f64).floor()) as i32).abs() + (2 - (index % 5)).abs();

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

fn read_input() -> Vec<i32> {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    s.split_whitespace().map(|i| i.parse().unwrap()).collect()
}


use std::io::{BufReader, BufRead};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let line = BufReader::new(std::io::stdin())
        .lines()
        .map(Result::unwrap)
        .skip(1)
        .next()
        .unwrap();

    let mut days = line.chars();
    let mut location = days.next().unwrap();
    let mut seattle_to_sf = 0;
    let mut sf_to_seattle = 0;
    for day in days {
        match (location, day) {
        | ('S', 'F') => seattle_to_sf += 1,
        | ('F', 'S') => sf_to_seattle += 1,
        | _ => (),
        }
        location = day;
    }

    println!("{}", if seattle_to_sf > sf_to_seattle { "YES" } else { "NO" });
    Ok(())
}


use std::io;

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

    io::stdin().read_line(&mut input)?;

    let n = input.trim().parse::<usize>().unwrap();
    input.clear();

    io::stdin().read_line(&mut input)?;

    let s = input.trim();

    let mut diff = 0;

    for i in 0..n - 1 {
        let t = &s[i..i + 2];
        if t == "SF" {
            diff += 1;
        } else if t == "FS" {
            diff -= 1;
        }
    }

    if diff > 0 {
        println!("YES");
    } else {
        println!("NO");
    }

    Ok(())
}


#![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 * //

#[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!(i64);
        let m = read!(i64);

        let ans = if m == 1 {n-1} else {n * (m-1)};
        println!(ans);
    }

    out_flush();
}


use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s = s.trim().to_string();
    let n = s.len();
    let mut flag = 1;   // 0,一般，1,开头, 2,中间
    let mut i = 0;
    while i < n {
        if i+2 < n && s[i..i+3] == String::from("WUB") {
            i += 3;
            if flag == 1 {

            } else if flag == 2 {

            } else {    // flag == 0
                flag = 2;
                print!(" ");
            }
        }
        else {
            flag = 0;
            print!("{}", s.as_bytes()[i] as char);
            i += 1;
        }
    }
}


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 x: String = read(sin);

    let ans: Vec<&str> = x.split("WUB").filter(|x| *x != "").collect();

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


#[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::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      m: usize,
      a: usize,
      b: usize,
      g0: u64,
      x: u64,
      y: u64,
      z: u64,
    }

    let mut hs = vec![vec![0; m]; n];
    let mut g = g0;
    for i in 0..n*m {
        let a = i/m;
        let b = i%m;
        hs[a][b] = g;
        g = (g * x  + y) % z;
    }

    // debug!(n, m, a, b, hs);

    let mut min_table = vec![];

    // スライド最小値
    use std::collections::VecDeque;
    for i in 0..n {
        let mut q: VecDeque<(usize,usize)> = VecDeque::new();
        let mut row_mins = vec![];
        for j in 0..m {
            let h = hs[i][j];

            while q.len() > 0 {
                let (x, y) = *q.back().unwrap();
                if h <= hs[x][y] {
                    q.pop_back();
                } else {
                    break;
                }
            }
            q.push_back((i, j));

            if j < b-1 {
                continue;
            }
            if j >= b {
                let (_,y) = *q.front().unwrap();
                if y == j-b {
                    q.pop_front();
                }
            }

            // debug!(i, j, q);
            let (x,y) = *q.front().unwrap();
            row_mins.push(hs[x][y]);
        }
        min_table.push(row_mins);
    }

    let mut ans = 0;
    for j in 0..m-b+1 {
        let mut q: VecDeque<(usize,usize)> = VecDeque::new();
        for i in 0..n {
            let h = min_table[i][j];

            while q.len() > 0 {
                let (x, y) = *q.back().unwrap();
                if h <= min_table[x][y] {
                    q.pop_back();
                } else {
                    break;
                }
            }
            q.push_back((i, j));

            if i < a-1 {
                continue;
            }
            if i >= a {
                let (x,_) = *q.front().unwrap();
                if x == i-a {
                    q.pop_front();
                }
            }

            let (x,y) = *q.front().unwrap();
            ans += min_table[x][y];

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


use std::io::Read;

fn sliding_minimum_elements(a: &[u64], l: usize) -> Vec<u64> {
    assert!(a.len() >= l && l > 0);
    let mut d = std::collections::VecDeque::<(u64, usize)>::new();
    for (i, &a) in a[..(l - 1)].iter().enumerate() {
        while let Some(p) = d.back() {
            if p.0 >= a {
                d.pop_back();
            } else {
                break;
            }
        }
        d.push_back((a, i));
    }
    let mut b = Vec::with_capacity(a.len() - l + 1);
    for (i, &a) in a[(l - 1)..].iter().enumerate() {
        while let Some(p) = d.back() {
            if p.0 >= a {
                d.pop_back();
            } else {
                break;
            }
        }
        d.push_back((a, i + l - 1));
        if d.front().unwrap().1 < i {
            d.pop_front();
        }
        b.push(d.front().unwrap().0);
    }
    b
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let a: usize = it.next().unwrap().parse().unwrap();
    let b: usize = it.next().unwrap().parse().unwrap();
    let mut g: u64 = it.next().unwrap().parse().unwrap();
    let x: u64 = it.next().unwrap().parse().unwrap();
    let y: u64 = it.next().unwrap().parse().unwrap();
    let z: u64 = it.next().unwrap().parse().unwrap();
    let mut h = vec![vec![0; m]; n];
    for i in 0..n {
        for j in 0..m {
            h[i][j] = g;
            g = (g * x + y) % z;
        }
    }
    for h in &mut h {
        *h = sliding_minimum_elements(h, b);
    }
    let mut ans = 0u64;
    for j in 0..(m + 1 - b) {
        let mut c = vec![0; n];
        for i in 0..n {
            c[i] = h[i][j];
        }
        ans += sliding_minimum_elements(&c, a).into_iter().fold(0, |s, a| s + a);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


// ---------- begin Matrix ----------

#[allow(dead_code)]
mod matrix {
    use std::ops::Add;
    use std::ops::Mul;
    pub trait SemiRing: Add<Output = Self> + Mul<Output = Self> + Copy {
        fn zero() -> Self;
        fn one() -> Self;
    }
    #[derive(Clone)]
    pub struct SquareMatrix<T: SemiRing> {
        n: usize,
        a: Vec<T>,
    }
    impl<T: SemiRing> SquareMatrix<T> {
        pub fn zero(n: usize) -> Self {
            let z = T::zero();
            SquareMatrix {
                n: n,
                a: vec![z; n * n],
            }
        }
        pub fn identity(n: usize) -> Self {
            let mut m = Self::zero(n);
            for i in 0..n {
                m.a[i * n + i] = T::one();
            }
            m
        }
        pub fn set_at(&mut self, i: usize, j: usize, v: T) {
            debug_assert!(i < self.n && j < self.n);
            self.a[i * self.n + j] = v;
        }
        pub fn get_at(&self, i: usize, j: usize) -> T {
            debug_assert!(i < self.n && j < self.n);
            self.a[i * self.n + j]
        }
        pub fn matmul(l: Self, r: Self) -> Self {
            l * r
        }
    }
    impl<T: SemiRing> Add for SquareMatrix<T> {
        type Output = Self;
        fn add(self, rhs: Self) -> Self {
            debug_assert!(self.n == rhs.n);
            let n = self.n;
            let mut c = Self::zero(n);
            for i in 0..(n * n) {
                c.a[i] = self.a[i] + rhs.a[i];
            }
            c
        }
    }
    impl<T: SemiRing> Mul for SquareMatrix<T> {
        type Output = Self;
        fn mul(self, rhs: Self) -> Self {
            debug_assert!(self.n == rhs.n);
            let n = self.n;
            let mut c = Self::zero(n);
            for i in 0..n {
                for k in 0..n {
                    let a = self.a[i * n + k];
                    for (x, y) in c.a[(i * n)..((i + 1) * n)].iter_mut().zip(rhs.a[(k * n)..((k + 1) * n)].iter()) {
                        *x = *x + a * *y;
                    }
                }
            }
            c
        }
    }
}

// ---------- end Matrix ----------
// ---------- begin ModInt ----------

//https://github.com/kenkoooo/competitive-programming-rs/blob/master/src/math/mod_int.rs
//を参考にしています
#[allow(dead_code)]
mod modint {
    pub const MOD: u32 = 1000000000 + 7;
    use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
    #[derive(Clone, Copy)]
    pub struct ModInt<T: Copy + Clone>(pub T);
    pub type Num = u32;
    impl Add<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn add(self, other: ModInt<Num>) -> ModInt<Num> {
            let mut d = self.0 + other.0;
            if d >= MOD {
                d -= MOD;
            }
            ModInt(d)
        }
    }
    impl AddAssign<ModInt<Num>> for ModInt<Num> {
        fn add_assign(&mut self, other: ModInt<Num>) {
            *self = *self + other;
        }
    }
    impl Sub<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn sub(self, other: ModInt<Num>) -> ModInt<Num> {
            let mut d = self.0 + MOD - other.0;
            if d >= MOD {
                d -= MOD;
            }
            ModInt(d)
        }
    }
    impl SubAssign<ModInt<Num>> for ModInt<Num> {
        fn sub_assign(&mut self, other: ModInt<Num>) {
            *self = *self - other;
        }
    }
    impl Mul<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn mul(self, other: ModInt<Num>) -> ModInt<Num> {
            ModInt(((self.0 as u64) * (other.0 as u64) % (MOD as u64)) as u32)
        }
    }
    impl MulAssign<ModInt<Num>> for ModInt<Num> {
        fn mul_assign(&mut self, other: ModInt<Num>) {
            *self = *self * other;
        }
    }
    impl Div<Num> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn div(self, other: Num) -> ModInt<Num> {
            self * ModInt(other).pow(MOD - 2)
        }
    }
    impl Div<ModInt<Num>> for ModInt<Num> {
        type Output = ModInt<Num>;
        fn div(self, other: ModInt<Num>) -> ModInt<Num> {
            self * other.pow(MOD - 2)
        }
    }
    impl DivAssign<ModInt<Num>> for ModInt<Num> {
        fn div_assign(&mut self, other: ModInt<Num>) {
            *self = *self / other;
        }
    }
    impl Neg for ModInt<Num> {
        type Output = ModInt<Num>;
        fn neg(self) -> ModInt<Num> {
            ModInt(if self.0 == 0 { 0 } else { MOD - self.0 })
        }
    }
    impl ModInt<Num> {
        pub fn new(v: u32) -> ModInt<Num> {
            ModInt(v % MOD)
        }
        pub fn pow(self, mut n: u32) -> ModInt<Num> {
            let mut t = ModInt::new(1);
            let mut s = self;
            while n > 0 {
                if (n & 1) == 1 {
                    t *= s;
                }
                s *= s;
                n >>= 1;
            }
            t
        }
    }
    pub struct Precalc {
        n: usize,
        inv: Vec<ModInt<Num>>,
        fact: Vec<ModInt<Num>>,
        ifact: Vec<ModInt<Num>>,
    }
    impl Precalc {
        pub fn new(n: usize) -> Precalc {
            let mut inv = vec![ModInt(1); n + 1];
            let mut fact = vec![ModInt(1); n + 1];
            let mut ifact = vec![ModInt(1); n + 1];
            for i in 1..(n + 1) {
                if i > 2 {
                    inv[i] = -inv[(MOD as usize) % i] * ModInt(MOD / (i as u32));
                }
                fact[i] = ModInt(i as u32) * fact[i - 1];
                ifact[i] = inv[i] * ifact[i - 1];
            }
            Precalc {
                n: n,
                inv: inv,
                fact: fact,
                ifact: ifact,
            }
        }
        pub fn fact(self, n: usize) -> ModInt<Num> {
            self.fact[n]
        }
        pub fn inv(self, x: usize) -> ModInt<Num> {
            self.inv[x]
        }
        pub fn ifact(self, x: usize) -> ModInt<Num> {
            self.ifact[x]
        }
        pub fn comb(self, n: usize, k: usize) -> ModInt<Num> {
            if !(k <= n) {
                return ModInt(0);
            }
            self.fact[n] * self.ifact[k] * self.ifact[n - k]
        }
    }
    use std;
    impl std::fmt::Display for ModInt<Num> {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }
}

// ---------- end ModInt ----------

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

// ここまで

use matrix::SquareMatrix;
use modint::ModInt;

impl matrix::SemiRing for ModInt<modint::Num> {
    fn one() -> Self {ModInt(1)}
    fn zero() -> Self {ModInt(0)}
}

fn run() {
    input! {
        n: u64,
        m: usize,
    }
    type M = SquareMatrix<ModInt<modint::Num>>;
    let mut t = M::identity(m);
    let mut s = M::zero(m);
    for i in 1..m {
        s.set_at(i - 1, i , ModInt(1));
    }
    s.set_at(m - 1, 0, ModInt(1));
    s.set_at(m - 1, m - 1, ModInt(1));
    let mut n = n;
    while n > 0 {
        if (n & 1) == 1 {
            t = t * s.clone();
        }
        s = s.clone() * s;
        n >>= 1;
    }
    let ans = t.get_at(m - 1, m - 1);
    println!("{}", ans);
}

fn main() {
    run();
}


use std::str::FromStr;
fn read_int() -> usize {
    let stdin = std::io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line).unwrap();
    usize::from_str(&line.trim_end()).unwrap()
}

fn good_numbers(n: usize) -> usize {
    let mut set = std::collections::HashSet::new();
    for i in 1..=n {
        if i * i > n {
            break;
        }
        set.insert(i * i);
        if i * i * i > n {
            continue;
        }
        set.insert(i * i * i);
    }
    return set.len()
}
fn main() {
    let test_cases = read_int();

    for _ in 0..test_cases {
        let n = read_int();
        println!("{}", good_numbers(n));
    }
}


#[rustfmt::skip]
#[allow(unused_imports)]
use std::{cmp::*, collections::*, fmt::Debug, io::*, iter::{self, *}, ops::{self, *}, str::{self, *}};
macro_rules!v{($(:$t:ty)?=$e:expr)=>{$e$(as$t)?};([$d:expr]$(:$t:ty)?)=>{Vec::$(<$t>::)?with_capacity($d)};([]$(:$t:ty)?)=>{Vec::$(<$t>::)?new()};([$d:expr]$($s:tt)+)=>{vec![v!($($s)+);$d]};}
#[rustfmt::skip]
struct StdinReader { buf: Vec<u8>, pos: usize, x: *mut Stdin, q: StdinLock<'static>, }
#[rustfmt::skip]
#[allow(dead_code)]
impl StdinReader {
    fn new() -> Self { let x = Box::into_raw(Box::new(stdin()));let q = unsafe { &*x }.lock();Self { x, q, buf: v!([]), pos: 0, } }
    fn cache_line(&mut self) -> bool { self.buf.clear();self.pos = 0;self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0 }
    fn b(&mut self) -> Option<u8> { if self.pos == self.buf.len() && !self.cache_line() { return None; }self.pos += 1;Some(self.buf[self.pos - 1]) }
    fn bs(&mut self) -> Vec<u8> { let mut s = v!([10]);let mut f = false;while let Some(c) = self.b() { if !c.is_ascii_whitespace() { s.push(c);f = true; } else if f { break; } }s }
    fn p<T: FromStr>(&mut self) -> T where T::Err: Debug, { let w = self.bs();str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap() }
    fn u(&mut self) -> usize { self.p() }
    fn i(&mut self) -> i32 { self.p() }
}
#[rustfmt::skip]
impl Drop for StdinReader { fn drop(&mut self) { unsafe { Box::from_raw(self.x) }; } }
#[rustfmt::skip]
fn stdio() -> (StdinReader, BufWriter<Stdout>) { (StdinReader::new(), BufWriter::new(stdout())) }

fn main() {
    let (mut rin, mut rout) = stdio();
    let n = rin.u();
    let mut t = Vec::with_capacity(n);
    let mut z = vec![0; n];
    (0..n).for_each(|_| t.push(rin.u()));
    let m = *t.iter().max().unwrap();
    let mut h = HashSet::with_capacity(n);
    let (mut f2, mut f3) = (true, true);
    for i in 1..=31622usize {
        let e2 = i.pow(2);
        if e2 > m {
            f2 = false;
        }
        if f2 {
            h.insert(e2);
        }

        let e3 = i.pow(3);
        if e3 > m {
            f3 = false;
        }
        if f3 {
            h.insert(i.pow(3));
        }

        if !f2 && !f3 {
            break;
        };
    }

    for &v in h.iter() {
        for (i, &tt) in t.iter().enumerate() {
            if v <= tt {
                z[i] += 1;
            }
        }
    }
    (0..n).for_each(|i| writeln!(rout, "{}", z[i]).unwrap());
}


use std::io;

fn main() -> io::Result<()> {

    let mut input = String::new();

    io::stdin().read_line(&mut input)?;
    let k: usize = input.trim().split(" ").last().unwrap().parse().unwrap();

    input.clear();
    io::stdin().read_line(&mut input)?;
    let scores: Vec<u8> = input.trim().split(" ").map(|s| s.parse().unwrap()).collect();
    let threshold = scores[k - 1];

    let mut count = 0;
    for score in scores {
        if (score == 0) || (score < threshold) {
            break;
        }
        count += 1;
    }

    println!("{}", count);

    return Ok(());
}


fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let line = line.trim();
    let v: Vec<i32> = line.trim().split(" ").map(|s| s.parse::<i32>().unwrap()).collect();
    let n = v[1] as usize;

    let mut line = String::new();
    std::io::stdin().read_line(&mut line);
    let line = line.trim();
    let v: Vec<i32> = line.trim().split(" ").map(|s| s.parse::<i32>().unwrap()).collect();

    let mut ret = 0;
    for i in 0..v.len() {
        if v[i] == 0 {
            break;
        }
        if i >= n && v[i] != v[n - 1] {
            break;
        }
        ret += 1;
    }
    println!("{}", ret);
}


//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()
	}
}
//------------------- End rusT }}}

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

	let n = rin.u();
	let k = rin.l();
	let s = rin.vb();
	let add = |a: i64, b: i64| k.min(a+b);
	let mut dp = v!([n+1][n+1] = 0);
	dp[0][0] = 1;
	for i in 1..=n {
		for l in 1..=i {
			for j in 1..=i {
				dp[i][j] = add(dp[i][j], dp[i-l][j-1]);
			}
			if l < i && s[i-1] == s[i-1-l] {
				break;
			}
		}
	}
	let mut sum = v!([n+1] = 0);
	let mut sum0 = 0;
	for i in 0..=n {
		for j in 0..=n {
			let x = dp[i][j];
			sum[j] = add(sum[j], x);
			sum0 = add(sum0, x);
		}
	}
	if sum0 < k {
		writeln!(rout, "-1").ok();
		return;
	}
	let mut sol = 0;
	let mut rem = k;
	for i in (0..=n).rev() {
		let m = sum[i].min(rem);
		sol += (n-i) as i64 * m;
		rem -= m;
	}
	writeln!(rout, "{}", sol).ok();
}


use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let a1: i128 = input.trim().parse().unwrap();

    input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let a2: i128 = input.trim().parse().unwrap();

    input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let k1: i128 = input.trim().parse().unwrap();

    input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let k2: i128 = input.trim().parse().unwrap();

    input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: i128 = input.trim().parse().unwrap();

    if n >= ((a1 * k1) + (a2 * k2)) {
        println!("{} {}", a1 + a2, a1 + a2);
        return;
    }

    // Find minimum
    let minimum = if n - (a1 * (k1 - 1)) - (a2 * (k2 - 1)) > 0 {
        n - (a1 * (k1 - 1)) - (a2 * (k2 - 1))
    } else {
        0
    };

    // Find maximum
    let mut maximum: i128 = 0;
    let mut cards_left = n;
    if k1 < k2 {
        cards_left -= a1 * k1;
        maximum += if cards_left >= 0 { a1 + (cards_left / k2) } else { n / k1 };
    } else {
        cards_left -= a2 * k2;
        maximum += if cards_left >= 0 { a2 + (cards_left / k1) } else { n / k2 };
    }

    println!("{} {}", minimum, maximum);
}


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

// ここまで

use std::cmp::{max, min};

fn run() {
    input! {
        a: i32,
        b: i32,
        x: i32,
        y: i32,
        n: i32,
    }
    let mut f = n;
    let mut g = 0;
    for i in 0..=n {
        if x * a < i || y * b < n - i{
            continue;
        }
        let mut p = 0;
        let mut q = 0;
        if (x - 1) * a < i {
            p += i - (x - 1) * a;
        }
        q += i / x;
        if (y - 1) * b < n - i {
            p += n - i - (y - 1) * b;
        }
        q += (n - i) / y;
        f = min(f, p);
        g = max(g, q);
    }
    println!("{} {}", f, g);
}

fn main() {
    run();
}


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

fn main() -> Result<(), Box<Error>> {
    let mut stdin = io::stdin();
    let mut line = String::new();
    stdin.read_line(&mut line)?;
    let num_str = line.trim();
    let num: u64 = num_str.parse()?;
    let num_nines = num_str.len() - 1;
    let remaining_num = num - (10_u64.pow(num_nines as u32) - 1);
    let rem_digit_sum: u32 = remaining_num.to_string().into_bytes().into_iter().map(|c| (c - b'0') as u32).sum();
    println!("{}", num_nines as u32 * 9 + rem_digit_sum);

    Ok(())
}


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

fn main() {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    handle.read_to_string(&mut buffer).unwrap();

    let arr : Vec<_> = buffer.split_whitespace().map(|x| x.parse::<u64>().unwrap() ).collect();
    let n = arr[0];
    let mut d = 0;
    let mut h = n;
    while h > 0 {
        d += 1;
        h = h / 10;
    }
    use std::cmp;
    let mut a = 0;
    'outer: for i in 0..d {
        // println!("{}",a);
        let mut r = 0;
        for j in 0..10 {
            let y = j * 10u64.pow(i);
            if a + y <= n {
                r = cmp::max(a + y, r);
                // println!("{}",r);
            }
        }
        a = r;
    }
    let mut b = n - a;
    // println!("{} {}", a, b);
    let mut ans = 0;
    while a > 0 {
        ans += a % 10;
        a = a / 10;
    }
    while b > 0 {
        ans += b % 10;
        b = b / 10;
    }
    println!("{}", ans);
}


use std::io;

struct Reader(Vec<u8>, usize);

impl Reader {
    fn new(r: &mut io::Read) -> Reader {
        let mut b = Vec::new();
        r.read_to_end(&mut b);

        Reader(b, 0)
    }

    fn read_byte(&mut self) -> u8 {
        self.1 += 1;
        self.0[self.1 - 1]
    }

    fn read_string(&mut self) -> String {
        for i in self.1..self.0.len() {
            match self.0[i] {
                b' ' | b'\t' | b'\n' | b'\r'  => {}
                _ => {
                    self.1 = i;
                    break;
                }
            }
        }

        let old_pos = self.1;
        for i in self.1..self.0.len() {
            match  self.0[i] {
                b' ' | b'\t' | b'\n' | b'\r'  => {
                    self.1 = i;
                    break;
                }
                _ => {}
            }
        }
        String::from_utf8(self.0[old_pos..self.1].to_vec()).unwrap()
    }

    fn read_int(&mut self) -> i32 {
        self.read_string().parse().unwrap()
    }
}

pub fn main() {
    let mut r = Reader::new(&mut io::stdin());
    let n = r.read_int();
    let k = r.read_int();
    println!("{}", (2 * n + k - 1) / k + (5 * n + k - 1) / k + (8 * n + k - 1) / k);
}


macro_rules! parse_line {
    ($t: ty) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let a_str = a_str.trim();
        a_str.parse::<$t>().expect("parse error")
    });
    ($($t: ty),+) => ({
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        let mut a_iter = a_str.split_whitespace();
        (
            $(
            a_iter.next().unwrap().parse::<$t>().expect("parse error"),
            )+
        )
    })
}

macro_rules! parse_line_to_vec {
    ($t: ty) => {{
        let mut a_str = String::new();
        std::io::stdin().read_line(&mut a_str).expect("read error");
        (a_str
            .split_whitespace()
            .map(|x| x.parse::<$t>().unwrap())
            .collect::<Vec<$t>>())
    }};
}

fn solve() {
    let (n, m, min, max) = parse_line!(usize, usize, i64, i64);
    let t = parse_line_to_vec!(i64);
    let low = t.iter().fold(std::i64::MAX, |x, &y| std::cmp::min(x, y));
    let high = t.iter().fold(std::i64::MIN, |x, &y| std::cmp::max(x, y));
    let mut fail = low < min || high > max;
    fail |= (low != min && high != max && n - m < 2) ||
        ((low != min || high != max) && n - m < 1);
    if fail {
        println!("Incorrect")
    }else{
        println!("Correct")
    }
}

fn main() {
    let tests = 1; // parse_line!(usize);
    for _ in 0..tests {
        solve();
    }
}


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

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

    fn t<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();
        }
    }

    #[allow(dead_code)]
    fn read_vec<T: str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.t()).collect()
    }

    #[allow(dead_code)]
    fn read_str(&mut self) -> Vec<u8> {
        self.t::<String>().into_bytes()
    }
}

use std::ops;

#[derive(Copy, Clone)]
struct ModGroup {
    val: usize,
}
impl ModGroup {
    const MOD: usize = 1000000007;
    const MOD64: i64 = Self::MOD as i64;

    fn new(v: usize) -> Self {
        Self { val: v }
    }

    fn from_usize(v: usize) -> Self {
        Self { val: v % Self::MOD }
    }

    fn from_i64(v: i64) -> Self {
        Self {
            val: (v % Self::MOD64) as usize,
        }
    }

    fn pow(self, mut p: usize) -> Self {
        let mut base = self;
        let mut res = Self::new(1);
        while p > 0 {
            if p % 2 > 0 {
                res = res * base;
            }
            base = base * base;
            p /= 2;
        }

        res
    }

    fn inv(self) -> Self {
        self.pow(Self::MOD - 2)
    }
}

impl ops::Add<usize> for ModGroup {
    type Output = Self;

    fn add(self, other: usize) -> Self {
        Self::from_usize(self.val + other)
    }
}
impl ops::Add<ModGroup> for ModGroup {
    type Output = Self;

    fn add(self, other: Self) -> Self {
        self + other.val
    }
}
impl ops::Sub<usize> for ModGroup {
    type Output = Self;

    fn sub(self, other: usize) -> Self {
        Self::new(if self.val > other {
            self.val - other
        } else {
            self.val + Self::MOD - other
        })
    }
}
impl ops::Sub<ModGroup> for ModGroup {
    type Output = Self;

    fn sub(self, other: Self) -> Self {
        self - other.val
    }
}
impl ops::Mul<usize> for ModGroup {
    type Output = Self;

    fn mul(self, other: usize) -> Self {
        Self::from_i64(self.val as i64 * other as i64)
    }
}
impl ops::Mul<ModGroup> for ModGroup {
    type Output = Self;

    fn mul(self, other: Self) -> Self {
        self * other.val
    }
}
impl ops::Div<usize> for ModGroup {
    type Output = Self;

    fn div(self, other: usize) -> Self {
        self * Self::new(other).inv()
    }
}
impl ops::Div<ModGroup> for ModGroup {
    type Output = Self;

    fn div(self, other: Self) -> Self {
        self * other.inv()
    }
}

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

    let n: usize = scan.t();

    let mut res = ModGroup::from_usize(1);
    for _ in 1..n {
        res = res * res * 16;
    }
    res = res * 6;

    writeln!(out, "{}", res.val)?;

    io::Result::Ok(())
}


#![allow(unused_imports, dead_code)]

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

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

const MOD: u64 = 1000_000_007;

fn solve(scan: &mut Scanner, out: &mut BufWriter<Stdout>) -> io::Result<()> {
    let n = scan.next::<u64>();
    let mut p = 1;
    for _ in 0..n-1 {
        p = (p * p * 4) % MOD
    }
    p = (p * p * 6) % MOD;
    writeln!(out, "{}", p)
}

fn main() -> io::Result<()> {
    let mut scan = Scanner::default();
    let mut out = &mut BufWriter::new(stdout());

    solve(&mut scan, &mut out)?;
    Ok(())
}


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_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 sum_1_through_n(n : u64) -> u64 {
    // Do the division before the multiplication
    // so that the result does not overflow sooner.
    if (n % 2) == 0 {
        (n / 2) * (n + 1)
    } else {
        n * ((n + 1) / 2)
    }
}

fn main() {
    let stdin = io::stdin();
    let mut knw = vec![];
    read_ts(&stdin, &mut knw);
    let k = knw[0];
    let n = knw[1];
    let w = knw[2];
    let needed_amount = k * sum_1_through_n(w);
    if needed_amount > n {
        let x = needed_amount - n;
        println!("{}", x);
    } else {
        println!("{}", 0);
    }
}


fn main() {
    let v: Vec<i32> = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        line.trim().split(" ").map(|s| s.parse::<i32>().unwrap()).collect()
    };

    let (first, total, n) = (v[0], v[1], v[2]);
    println!("{:?}",
             std::cmp::max((0..n).fold(0, |total, i| total + first * (i + 1)) - total,
                           0));

}


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

const M: u64 = 998244353;

fn pow(n: u64, p: u64) -> u64 {
  let mut q = p;
  let mut r = n;
  let mut result = 1;
  while q > 0 {
    if q % 2 == 1 {
      result = result * r % M;
    }
    r = r * r % M;
    q >>= 1;
  }
  result
}

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let xs: Vec<u64> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
  let (n, m) = (xs[0], xs[1]);
  if n == 2 || m == 2 {
    println!("0");
    return;
  }
  let mut prods: Vec<u64> = vec![0; (m + 1) as usize];
  prods[0] = 1;
  for i in 1..=m {
    prods[i as usize] = i * prods[(i-1) as usize] % M;
  }
  let mut ans: u64 = 0;
  for pivot in (n-1)..=m {
    let n_pairs = pivot - 1;
    let n_cands = (pivot - 2) as usize;
    let choose = (n - 3) as usize;
    let comb = (prods[n_cands] * pow(prods[n_cands - choose], M - 2) % M) * pow(prods[choose], M - 2) % M;
    ans = (ans + (n_pairs * comb % M) * pow(2, choose as u64) % M) % M;
  }
  println!("{}", ans);
}


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

type GenError = Box<dyn std::error::Error>;
type GenResult<T> = Result<T, GenError>;

struct Reader {

}

impl Reader{
    #[allow(unused)]
    fn read_string() -> GenResult<String> {
        let mut string: String = String::new();
        std::io::stdin().read_line(&mut string)?;
        Ok(string.trim().to_string())
    }

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

fn main() {

    let tokens = Reader::read_tokens().unwrap();
    let n: i32 = tokens[0].parse().unwrap();
    let k: i32 = tokens[1].parse().unwrap();

    let mut v = Vec::new();
    for value in Reader::read_tokens().unwrap(){
        v.push(value.parse::<i32>().unwrap());
    }
    let mut ans = 0;
    let mut l = 0;
    let mut r = v.len() - 1;
    while l <= r {
        let mut L = l;
        let mut R = r;
        if v[L] <= k {
            L += 1;
            ans += 1;
        }
        if v[R] <= k && R > L {
            R -= 1;
            ans += 1;
        }
        if L == l && R == r{
            break;
        }
        l = L;
        r = R;
    }
    println!("{}", ans);
}


use std::io::{self, BufRead};
// use std::collections::*; // HashSet, HashMap, BTreeSet, BTreeMap, ...

fn main() {
    let stdin: io::Stdin = io::stdin();
    let mut lines: io::Lines<io::StdinLock> = stdin.lock().lines();

    let next_line = lines.next()
        .unwrap() // Option<Result> { Some(Result), None }
        .unwrap(); // Result<String, io::Error> { Ok(String), Err(io::Error) }

    let flv: Vec<_> = next_line
        .trim()
        .split(' ')
        .map(|n| {
            n.parse::<u64>().unwrap()
        })
        .collect();

    let n = flv[0];
    let k = flv[1];

    let next_line = lines.next()
        .unwrap() // Option<Result> { Some(Result), None }
        .unwrap(); // Result<String, io::Error> { Ok(String), Err(io::Error) }

    let slv: Vec<_> = next_line
        .trim()
        .split(' ')
        .map(|n| {
            n.parse::<u64>().unwrap()
        })
        .collect();

    let mut cs = 0;

    for num in slv.iter() {
        if *num <= k {
            cs += 1;
        } else {
            break;
        }
    }

    if cs == n {
        println!("{}", n);
        return;
    }

    for num in slv.iter().rev() {
        if *num <= k {
            cs += 1;
        } else {
            break;
        }
    }

    println!("{}", cs);

    // let mut reach: Vec<HashSet<u64>> = vec![];
    // // reach.reserve(n as usize);

    // let mut pairs: Vec<Vec<u64>> = vec![];
    // for l in lines {
    //     let lv: Vec<u64> = l.unwrap()
    //         .trim()
    //         .split(' ')
    //         .map(|n| n.parse::<u64>().unwrap() - 1)
    //         .collect();
    //     // println!("line values: ({}, {})", lv[0], lv[1]);
    //     reach[lv[0] as usize].insert(lv[1]);
    //     reach[lv[1] as usize].insert(lv[0]);
    //     pairs.push(lv);
    // }
}


// ---------- begin ModInt ----------
const MOD: u32 = 998_244_353;
#[derive(Clone, Copy)]
struct ModInt(u32);

impl std::ops::Add for ModInt {
    type Output = ModInt;
    fn add(self, rhs: ModInt) -> ModInt {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::Mul for ModInt {
    type Output = ModInt;
    fn mul(self, rhs: ModInt) -> ModInt {
        ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)
    }
}

impl std::ops::Sub for ModInt {
    type Output = ModInt;
    fn sub(self, rhs: ModInt) -> ModInt {
        let mut d = self.0 + MOD - rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

impl std::ops::Neg for ModInt {
    type Output = ModInt;
    fn neg(self) -> ModInt {
        if self.0 == 0 {self} else {ModInt(MOD - self.0)}
    }
}

impl std::ops::AddAssign for ModInt {
    fn add_assign(&mut self, rhs: ModInt) {
        *self = *self + rhs;
    }
}

impl std::ops::MulAssign for ModInt {
    fn mul_assign(&mut self, rhs: ModInt) {
        *self = *self * rhs;
    }
}

impl std::ops::SubAssign for ModInt {
    fn sub_assign(&mut self, rhs: ModInt) {
        *self = *self - rhs;
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(v: u32) -> ModInt {
        ModInt(v % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t = t * s;
            }
            s = s * s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------
// ---------- begin NTT ----------
fn ntt(f: &mut [ModInt]) {
    let n = f.len();
    assert!(n.count_ones() == 1);
    let len = n.trailing_zeros() as usize;
    for i in 1..(n - 1){
        let mut x = i;
        let mut j = 0;
        for _ in 0..len {
            j = (j << 1) | (x & 1);
            x >>= 1;
        }
        if i < j {
            f.swap(i, j);
        }
    }
    for k in 0..(n.trailing_zeros() as usize) {
        let m = 1 << k;
        let z = ModInt(3).pow((MOD - 1) >> (k + 1) as u32);
        for j in 0..(n / (2 * m)) {
            let mut q = ModInt::one();
            for i in (2 * m * j)..(2 * m * j + m) {
                let a = f[i];
                let b = q * f[i + m];
                f[i] = a + b;
                f[i + m] = a - b;
                q *= z;
            }
        }
    }
}

fn intt(f: &mut [ModInt]) {
    ntt(f);
    f[1..].reverse();
    let ik = ModInt(f.len() as u32).inv();
    for f in f.iter_mut() {
        *f *= ik;
    }
}
// ---------- end NTT ----------

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k = (n / 2 * 9 + 1).next_power_of_two();
    let mut f = vec![ModInt::zero(); k];
    it.next();
    for s in it {
        let a: usize = s.parse().unwrap();
        f[a] = ModInt::one();
    }
    ntt(&mut f);
    for f in &mut f {
        *f = f.pow((n / 2) as u32);
    }
    intt(&mut f);
    let ans = f.iter().fold(ModInt::zero(), |s, f| s + *f * *f);
    println!("{}", ans.0);
}

fn main() {
    run();
}


#[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 {
    (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)*}
    };
}

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

/// Verified by: https://atcoder.jp/contests/pakencamp-2018-day3/submissions/3878249
mod mod_int {
    use std::ops::*;
    pub trait Mod: Copy + Clone { fn m() -> i64; }
    #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
    pub struct ModInt<M> { pub x: i64, phantom: ::std::marker::PhantomData<*const M> }
    impl<M: Mod> ModInt<M> {
        fn check_integrity(self) {
            debug_assert!(self.x >= 0);
            debug_assert!(self.x < M::m());
        }
        // x >= 0
        pub fn new(x: i64) -> Self { ModInt::new_internal(x % M::m()) }
        fn new_internal(x: i64) -> Self {
            ModInt { x: x, phantom: ::std::marker::PhantomData }
        }
        #[allow(dead_code)]
        pub fn mul_fast(self, other: Self) -> Self {
            self.check_integrity();
            other.check_integrity();
            ModInt::new_internal(self.x * other.x % M::m())
        }
        #[allow(dead_code)]
        pub fn mul_slow(self, other: Self) -> Self {
            // Naive multiplication in order to avoid overflow
            self.check_integrity();
            other.check_integrity();
            let mut sum = ModInt::new_internal(0);
            let mut cur = self;
            let mut e = other.x;
            if self.x < other.x {
                cur = other;
                e = self.x;
            }
            while e > 0 {
                if e % 2 == 1 { sum += cur; }
                cur += cur;
                e /= 2;
            }
            sum
        }
        pub fn pow(self, mut e: i64) -> Self {
            self.check_integrity();
            debug_assert!(e >= 0);
            let mut sum = ModInt::new_internal(1);
            let mut cur = self;
            while e > 0 {
                if e % 2 != 0 { sum *= cur; }
                cur *= cur;
                e /= 2;
            }
            sum
        }
        #[allow(dead_code)]
        pub fn inv(self) -> Self { self.pow(M::m() - 2) }
    }
    impl<M: Mod> Add for ModInt<M> {
        type Output = Self;
        fn add(self, other: Self) -> Self {
            self.check_integrity();
            other.check_integrity();
            let mut sum = self.x + other.x;
            if sum >= M::m() { sum -= M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod> Sub for ModInt<M> {
        type Output = Self;
        fn sub(self, other: Self) -> Self {
            self.check_integrity();
            other.check_integrity();
            let mut sum = self.x - other.x;
            if sum < 0 { sum += M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod> Mul for ModInt<M> {
        type Output = Self;
        fn mul(self, other: Self) -> Self { self.mul_fast(other) }
    }
    impl<M: Mod> AddAssign for ModInt<M> {
        fn add_assign(&mut self, other: Self) { *self = *self + other; }
    }
    impl<M: Mod> SubAssign for ModInt<M> {
        fn sub_assign(&mut self, other: Self) { *self = *self - other; }
    }
    impl<M: Mod> MulAssign for ModInt<M> {
        fn mul_assign(&mut self, other: Self) { *self = *self * other; }
    }
    impl<M> ::std::fmt::Display for ModInt<M> {
        fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            self.x.fmt(f)
        }
    }
    impl<M> ::std::fmt::Debug for ModInt<M> {
        fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
            self.x.fmt(f)
        }
    }
} // mod mod_int

macro_rules! define_mod {
    ($struct_name: ident, $modulo: expr) => {
        #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
        struct $struct_name {}
        impl mod_int::Mod for $struct_name { fn m() -> i64 { $modulo } }
    }
}
const MOD: i64 = 998244353;
define_mod!(P, MOD);
type ModInt = mod_int::ModInt<P>;

/// FFT (in-place)
/// R: Ring + Copy
/// Verified by: ATC001-C (http://atc001.contest.atcoder.jp/submissions/1175827)
mod fft {
    use std::ops::*;
    /// n should be a power of 2. zeta is a primitive n-th root of unity.
    /// one is unity
    /// Note that the result should be multiplied by 1/sqrt(n).
    pub fn transform<R>(f: &[R], zeta: R, one: R) -> Vec<R>
        where R: Copy +
        Add<Output = R> +
        Sub<Output = R> +
        Mul<Output = R> {
        let n = f.len();
        let mut output = f.to_vec();
        assert!(n.is_power_of_two());
        {
            let mut i = 0;
            for j in 1 .. n - 1 {
                let mut k = n >> 1;
                loop {
                    i ^= k;
                    if k <= i { break; }
                    k >>= 1;
                }
                if j < i {
                    output.swap(i, j);
                }
            }
        }
        let mut zetapow = Vec::new();
        {
            let mut m = 1;
            let mut cur = zeta;
            while m < n {
                zetapow.push(cur);
                cur = cur * cur;
                m *= 2;
            }
        }
        let mut m = 1;
        while m < n {
            let m2 = 2 * m;
            let base = zetapow.pop().unwrap();
            let mut r = 0;
            while r < n {
                let mut w = one;
                for x in 0 .. m {
                    let s = x + r;
                    let u = output[s];
                    let d = output[s + m] * w;
                    output[s] = u + d;
                    output[s + m] = u - d;
                    w = w * base;
                }
                r += m2;
            }
            m *= 2;
        }
        output
    }
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        k: usize,
        d: [usize; k],
    }
    const N: usize = 1 << 20;
    let one = ModInt::new(1);
    let mut f = vec![ModInt::new(0); N];
    let zeta = ModInt::new(3).pow((MOD - 1) / N as i64);
    for i in 0 .. k {
        f[d[i]] += one;
    }
    let mut f = fft::transform(&f, zeta, one);
    for i in 0 .. N {
        f[i] = f[i].pow(n as i64 / 2);
    }
    let mut f = fft::transform(&f, zeta.inv(), one);
    let factor = ModInt::new(N as i64).inv();
    for i in 0 .. N {
        f[i] *= factor;
    }
    let mut tot = ModInt::new(0);
    for i in 0 .. N {
        tot += f[i].pow(2);
    }
    puts!("{}\n", tot);
}

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


 #[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 solution() {
    let mut scanner = Scanner::new();
    let mut s: String = scanner.next();
    let n = s.len();
    let mut ans = 0;
    let mut current = 1;
    for i in 0..n {
        let d = s.chars().next().unwrap().to_digit(10).unwrap() as usize;
        let x = std::cmp::max(d as i32 - 1, 1) as usize;
        ans = std::cmp::max(ans, current * x * 9_usize.pow((n - i - 1) as u32));
        current *= d;
        s = s[1..].to_string();
    }
    ans = std::cmp::max(ans, current);
    println!("{}", ans);
}

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


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

    std::io::stdin().read_line(&mut input);

    for ch in input.to_lowercase().chars() {
        match ch {
            'a' | 'o' | 'y' | 'e' | 'u' | 'i' | '\n' | '\r' => {
                continue;
            },
            _ => {
                print!(".{}", ch);
            }
        }
    }
}


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

    for c in s.trim().chars() {
        match c {
            'A' | 'O' | 'Y' | 'E' | 'U' | 'I' |
            'a' | 'o' | 'y' | 'e' | 'u' | 'i' => {
                continue;
            }, _ => {
                print!(".");
                if c.is_lowercase() {
                    print!("{}", c);
                } else {
                    print!("{}", (('a' as u8) + (c as u8) - ('A' as u8)) as char);
                }
            }
        }
    }

    println!("");
}


/// square root of an int
fn sqrti(b: u64) -> u64 {
    let n = 2;
    if b < 2 {
        return b
    };
    let n1 = n - 1;
    let n2 = n;
    let n3 = n1;
    let mut c = 1;
    let mut d = (n3 + b) / n2;
    let mut e = (n3 * d + b / d.pow(n1 as u32)) / n2;
    while c != d && c != e {
        c = d;
        d = e;
        e = (n3 * e + b / e.pow(n1 as u32)) / n2;
    }
    if d < e { d }
    else { e }
}

use std::ops::Range;

/// iterator that returns `(w, h)` for rectangles of provided area
struct Rects {
    area: u64,
    w: u64,
    rw: Range<u64>,
    rh: Range<u64>,
}

impl Rects {
    pub fn new(area: u64) -> Rects {
        let q = sqrti(area);
        Rects { area, rw: 1..q, rh: 1..area, w: q }
    }
    pub fn with_limits(area: u64, rw: Range<u64>, rh: Range<u64>) -> Rects {
        let q = sqrti(area);
        let maxw = q.min(area / rh.start).min(rw.end);
        let minw = (area / rh.end).max(rw.start);
        Rects { area, rw: minw..maxw, rh, w: maxw }
    }
}

impl Iterator for Rects {
    type Item = (u64, u64);
    fn next(&mut self) -> Option<(u64, u64)> {
        while self.w >= self.rw.start {
            let w = self.w;
            self.w -= 1;
            let h = self.area / w;
            if h < self.rh.start || h > self.rh.end || h * w != self.area {
                continue;
            }
            return Some((w, h));
        }
        None
    }
}

fn solve(a: u64, b: u64) -> Option<u64> {
    if a < 1 || b < 1 {
        return None;
    }
    let area = a + b;
    Rects::new(area).flat_map(|(ow, oh)| {
        let perimeter = (ow + oh) * 2;
        Rects::with_limits(a, 1..ow, 1..oh)
            .chain(Rects::with_limits(b, 1..ow, 1..oh))
            .find(|&(iw, ih)| iw <= ow && ih <= oh)
            .and(Some(perimeter))
    }).next()
}

use std::io::{stdin, BufRead};
use std::process::{exit};
fn input() -> Result<(u64, u64), String> {
    let std = stdin();
    let mut row = String::new();
    std.lock().read_line(&mut row).map_err(|_|"Cannot read stdin")?;
    let words: Vec<&str> = row.trim().split(' ').collect();
    let a: u64 = words[0].parse().map_err(|_|"Cannot parse input")?;
    let b: u64 = words[1].parse().map_err(|_|"Cannot parse input")?;
    Ok((a, b))
}

fn main() {
    let rv = input().map(|(a,b)| solve(a, b));
    match rv {
        Ok(Some(perimeter)) => {
            println!("{}", perimeter);
        }
        Ok(None) => {
            eprintln!("Error: solution not found");
            exit(1);
        }
        Err(e) => {
            eprintln!("Error: {}", e);
            exit(1);
        }
    }
}


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 input1: String = read(sin);
    let input2: String = read(sin);

    let input1 = input1.to_lowercase();
    let input2 = input2.to_lowercase();

    if input1 == input2 {
        println!("0");
    } else if input1 < input2 {
        println!("-1");
    } else if input2 < input1 {
        println!("1");
    }
}


use std::io;
use std::cmp::Ordering;
fn main() {
    let data1 = read().to_lowercase();
    let data2 = read().to_lowercase();
    let c  = data1.cmp(&data2);
    match c{
        Ordering::Greater => println!("1"),
        Ordering::Less => println!("-1"),
        _ => println!("0"),
    };
}
fn read() -> String{
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    input.trim().parse::<String>().unwrap()
}


use std::io;
use std::io::Read;
// use std::collections::VecDeque;

fn main() {
    let mut input_text = String::new();
    io::stdin().read_to_string(&mut input_text).unwrap();
    let mut iter = input_text.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    let n = iter.next().unwrap();
    let k = iter.next().unwrap();
    let mut ans = n / k * k;
    while ans <= n {
        ans += k
    }
    println!("{}", ans);
}


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

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(isize);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(n: u32);
  if n == 0 { println!("1"); }
  else {
    println!("{}",
      match n % 4 {
        1 => 8,
        2 => 4,
        3 => 2,
        0 => 6,
        _ => unreachable!()
      }
    );
  }
}


#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

fn bi(x: i64, n: i64, l0: i64, r0: i64) -> i64 {
    let mut left = l0;
    let mut right = r0;

    while right - left > 1 {
        let y = (left + right) / 2;
        if x * x + y * y <= n * n {
            left = y;
        } else {
            right = y;
        }
    }
    return left;
}

fn main() {
    let mut sc = Scanner::new();

    let n: i64 = sc.cin();

    if n == 0 {
        println!("1");
        return;
    }

    let mut a = 0;
    let mut b = 0;

    let mut l0 = 0;
    let mut r0 = n + 1;
    for x in 0..n {
        let y = bi(x, n, l0, r0);
        l0 = max(0, y - 10);
        r0 = min(y + 10, n + 1);
        // trace!((x, y));
        if x < y {
            a += 1;
        } else if x == y {
            b += 1;
            break;
        } else {
            break;
        }
    }
    let ans = 4 * (a * 2 - 1 + b);
    println!("{}", ans);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


use std::io::stdin;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input).unwrap();
    let mut input = input.split_whitespace().map(|k| k.parse::<u64>().unwrap());
    let m = input.next().unwrap();
    let b = input.next().unwrap();

    let ans = (0..(m * b + 1)).map(|x| {
        let y = b - (x + m - 1) / m;
        let tmp = (x + 1) * (y + 1) * (x + y) / 2 ;
        tmp
    }).max().unwrap();

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


fn main() {
    let mut l = String::new();
    std::io::stdin().read_line(&mut l).unwrap();
    let mut mb = l.split_whitespace().map(|s| s.parse::<u64>().unwrap());
    let m = mb.next().unwrap();
    let b = mb.next().unwrap();

    let answer: u64 = (0..(b+1)).into_iter().map(|height| {
        let width = m * (b - height);

        let height_sum = height * (height+1) / 2;
        let width_sum = width * (width+1) / 2;

        height_sum * (width+1) + width_sum * (height+1)
    }).max().unwrap();
    println!("{}", answer);
}


#[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::prelude::BufRead;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

fn main() {
    let line = read_vector::<usize>();
    let (n, m) = (line[0], line[1]);
    if m % n != 0 {
        println!("-1");
        return;
    }
    let mut quotient = m / n;
    let mut ans = 0;
    while quotient % 2 == 0 && quotient > 1 {
        quotient /= 2;
        ans += 1;
    }
    while quotient % 3 == 0 && quotient > 1 {
        quotient /= 3;
        ans += 1;
    }
    if quotient > 1 {
        println!("-1");
        return;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    return buf.trim().parse().unwrap();
}

#[allow(dead_code)]
fn read_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    let mut buf = String::with_capacity(100);
    stdin().read_line(&mut buf).unwrap();
    return buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
}

#[allow(dead_code)]
fn read_matrix<T>() -> Vec<Vec<T>>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    use std::io::prelude::*;
    let stdin = stdin();
    let mut reader = BufReader::with_capacity(100 * 1024, stdin);
    let mut line = String::with_capacity(100);
    let mut matrix: Vec<Vec<T>> = Vec::new();

    while reader.read_line(&mut line).unwrap() > 0 {
        matrix.push(
            line.trim()
                .split_whitespace()
                .map(|s| s.parse().unwrap())
                .collect(),
        );
        line.clear();
    }

    return matrix;
}

#[allow(dead_code)]
fn read_chars() -> Vec<char> {
    let stdin = stdin();
    let mut buf = String::new();
    let _bytes = stdin.read_line(&mut buf).unwrap();
    return buf.trim().chars().collect();
}


pub mod solution {

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

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 = 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);
            let z = mul((c as u64 / x) as i32, g as i32);
            add(&mut ans, mul(phi[(n - c) / g] as i32, z as i32));
        }
    }
    out_line!(ans);
}

fn add(a: &mut i32, b: i32) {
    *a += b;
    if *a >= MOD {
        *a -= MOD;
    }
}

const MOD: i32 = 1000000007;

fn mul(a: i32, b: i32) -> i32 {
    (a as i64 * b as i64 % MOD as i64) as i32
}

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