n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.Your task is to write a program that will find the minimum and the maximum number of pairs of friends that could have formed by the end of the competition.

The only line of input contains two integers n and m, separated by a single space (1 ≤ m ≤ n ≤ 109) — the number of participants and the number of teams respectively.

The only line of the output should contain two integers kmin and kmax — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively.

NoteIn the first sample all the participants get into one team, so there will be exactly ten pairs of friends.In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.In the third sample minimum number of newly formed friendships can be achieved if participants were split on teams consisting of 2 people, maximum number can be achieved if participants were split on teams of 1, 1 and 4 people.

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

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

    let f = |n,x| x * n * (n - 1) / 2;
    let n: i64 = input.p();
    let m: i64 = input.p();
    let r = n % m;
    writeln!(bout, "{} {}", f(n/m, m-r) + f(n/m+1, r), f(n-m+1, 1)).ok();
}

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

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

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

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

fn foo(x : i32) -> i64 {
    let x : i64 = x as i64;
    return (x*(x-1))/2;
}

fn main() {
    let (n,m) = readln!(i32,i32);
    let a1 = foo(n-m+1);
    let r = n%m;
    let q = n/m;
    let a2 = r as i64*foo(q+1) + (m-r) as i64 *foo(q);
    println!("{} {}",a2,a1);
}

fn c2 (x:i64) -> i64 { let y=x as i64; y * (y-1)/2 }

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut ints = s.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    let n = ints.next().unwrap();
    let t = ints.next().unwrap();
    if n == t {
        println!("0 0");
    } else {
        let max = c2(n - t + 1);
        let a = n/t;
        let b = n%t;
        let min = b*c2(a+1)+(t-b)*c2(a);
        println!("{} {}",min, max);
  }

}

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

fn read_line() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).expect("Failed to read a line");
    buf
}

fn read<T>() -> T
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    read_line().trim().parse::<T>().unwrap()
}

fn read_vector<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    read_line().trim().split_whitespace().map(|x| x.parse::<T>().unwrap()).collect()
}

fn calculate_min_max_pairs(n: u64, m: u64) -> (u64, u64) {
    let get_pair_count = |x| x * (x - 1) / 2;
    let max_count = get_pair_count(n - m + 1);
    let (d, r) = (n / m, n % m);
    let min_count = (m - r) * get_pair_count(d) + r * get_pair_count(d + 1);
    (min_count, max_count)
}

fn main() {
    let (n, m) = {
        let v = read_vector::<u64>();
        (v[0], v[1])
    };
    let result = calculate_min_max_pairs(n, m);
    println!("{} {}", result.0, result.1);
}

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

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

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

}

fn _main() {
    let mut scan = Scan::new();
    let n: u64 = scan.next();
    let m: u64 = scan.next();
    let maxcalc = (n-m+1) * (n-m) / 2;
    let minval1 = n/m + 1;
    let minval2 = n/m;
    let minn1 = n%m;
    let minn2 = m - minn1;
    let mincalc = (minval1*(minval1-1)/2)*minn1
        + (minval2*(minval2-1)/2)*minn2;
    println!("{} {}", mincalc, maxcalc);
}

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

fn solve() {
    let (n, m): (i64, i64) = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut ws = buf.split_whitespace();
        let n = ws.next().unwrap().parse().unwrap();
        let m = ws.next().unwrap().parse().unwrap();
        (n, m)
    };

    let min = {
        let a = n / m;
        let b = n - a * m;
        (a + 1) * a / 2 * b + a * (a - 1) / 2 * (m - b)
    };

    let max = {
        let t = n - (m - 1);
        t * (t - 1) / 2
    };

    println!("{} {}", min, max);
}

fn main() {
    // let t: u32 = {
    //     let mut buf = String::new();
    //     std::io::stdin().read_line(&mut buf).unwrap();
    //     buf.trim_end().parse().unwrap()
    // };

    // for _ in 0..t {}
    solve();
}

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

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

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

}

fn _main() {
    let mut scan = Scan::new();
    let n: u64 = scan.next();
    let m: u64 = scan.next();
    if n == m {
        println!("{} {}", m, m);
        return;
    }
    let maxcalc = (n-m+1) * (n-m) / 2;
    let minval1 = n/m + 1;
    let minval2 = n/m;
    let minn1 = n%m;
    let minn2 = m - minn1;
    let mincalc = (minval1*(minval1-1)/2)*minn1
        + (minval2*(minval2-1)/2)*minn2;
    println!("{} {}", mincalc, maxcalc);
}

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


Getting closer and closer to a mathematician, Serval becomes a university student on math major in Japari University. On the Calculus class, his teacher taught him how to calculate the expected length of a random subsegment of a given segment. Then he left a bonus problem as homework, with the award of a garage kit from IOI. The bonus is to extend this problem to the general case as follows.You are given a segment with length $$$l$$$. We randomly choose $$$n$$$ segments by choosing two points (maybe with non-integer coordinates) from the given segment equiprobably and the interval between the two points forms a segment. You are given the number of random segments $$$n$$$, and another integer $$$k$$$. The $$$2n$$$ endpoints of the chosen segments split the segment into $$$(2n+1)$$$ intervals. Your task is to calculate the expected total length of those intervals that are covered by at least $$$k$$$ segments of the $$$n$$$ random segments.You should find the answer modulo $$$998244353$$$.

First line contains three space-separated positive integers $$$n$$$, $$$k$$$ and $$$l$$$ ($$$1\leq k \leq n \leq 2000$$$, $$$1\leq l\leq 10^9$$$).

Output one integer — the expected total length of all the intervals covered by at least $$$k$$$ segments of the $$$n$$$ random segments modulo $$$998244353$$$. Formally, let $$$M = 998244353$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.

NoteIn the first example, the expected total length is $$$\int_0^1 \int_0^1 |x-y| \,\mathrm{d}x\,\mathrm{d}y = {1\over 3}$$$, and $$$3^{-1}$$$ modulo $$$998244353$$$ is $$$332748118$$$.

// ---------- 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) -> Self::Output {
        let mut d = self.0 + rhs.0;
        if d >= MOD {
            d -= MOD;
        }
        ModInt(d)
    }
}

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

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

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

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

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

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

/*
impl std::fmt::Display for ModInt {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
*/

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % 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 *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        self.pow(MOD - 2)
    }
    pub fn comb(n: u32, k: u32) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        let k = std::cmp::min(k, n - k);
        let mut nu = ModInt::one();
        let mut de = ModInt::one();
        for i in 0..k {
            nu *= ModInt(n - i);
            de *= ModInt(i + 1);
        }
        nu * de.inv()
    }
}

#[allow(dead_code)]
struct Precalc {
    inv: Vec<ModInt>,
    fact: Vec<ModInt>,
    ifact: Vec<ModInt>,
}

#[allow(dead_code)]
impl Precalc {
    pub fn new(n: usize) -> Precalc {
        let mut inv = vec![ModInt::one(); n + 1];
        let mut fact = vec![ModInt::one(); n + 1];
        let mut ifact = vec![ModInt::one(); n + 1];
        for i in 2..(n + 1) {
            inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);
            fact[i] = fact[i - 1] * ModInt(i as u32);
            ifact[i] = ifact[i - 1] * inv[i];
        }
        Precalc {
            inv: inv,
            fact: fact,
            ifact: ifact,
        }
    }
    pub fn inv(&self, n: usize) -> ModInt {
        self.inv[n]
    }
    pub fn fact(&self, n: usize) -> ModInt {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt {
        self.ifact[n]
    }
    pub fn comb(&self, n: usize, k: usize) -> ModInt {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end ModInt ----------

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let l: u32 = it.next().unwrap().parse().unwrap();
    let pc = Precalc::new(2 * n + 1);
    let mut dp = vec![ModInt::zero(); 2 * n + 1];
    dp[0] = ModInt::one();
    for i in 0..n {
        for j in (0..=(2 * i)).rev() {
            let p = dp[j];
            dp[j + 2] -= ModInt(2) * p;
            dp[j + 1] += ModInt(2) * p;
            dp[j] = ModInt(0);
        }
    }
    let mut ans = ModInt::zero();
    for i in (k..=n).rev() {
        let mut eval = ModInt::zero();
        for j in 0..=(2 * n) {
            eval += dp[j] * pc.inv(j + 1)
        }
        ans += pc.comb(n, i) * eval;
        let f = ModInt(2).inv();
        let mut next = vec![ModInt::zero(); 2 * n + 1];
        for j in (2..=(2 * n)).rev() {
            let v = dp[j];
            dp[j - 1] += v;
            next[j - 2] = -v * f;
        }
        dp = next;
        for j in (0..=(2 * (n - 1))).rev() {
            let v = dp[j];
            dp[j + 2] += ModInt(2) * v;
            dp[j + 1] -= ModInt(2) * v;
        }
    }
    ans *= ModInt(l);
    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 {
    ($($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/arc093/submissions/3968098
mod mod_int {
    use std::ops::*;
    pub trait Mod: Copy { fn m() -> i64; }
    #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
    pub struct ModInt<M> { pub x: i64, phantom: ::std::marker::PhantomData<M> }
    impl<M: Mod> ModInt<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 }
        }
        pub fn pow(self, mut e: i64) -> Self {
            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, T: Into<ModInt<M>>> Add<T> for ModInt<M> {
        type Output = Self;
        fn add(self, other: T) -> Self {
            let other = other.into();
            let mut sum = self.x + other.x;
            if sum >= M::m() { sum -= M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Sub<T> for ModInt<M> {
        type Output = Self;
        fn sub(self, other: T) -> Self {
            let other = other.into();
            let mut sum = self.x - other.x;
            if sum < 0 { sum += M::m(); }
            ModInt::new_internal(sum)
        }
    }
    impl<M: Mod, T: Into<ModInt<M>>> Mul<T> for ModInt<M> {
        type Output = Self;
        fn mul(self, other: T) -> Self { ModInt::new(self.x * other.into().x % M::m()) }
    }
    impl<M: Mod, T: Into<ModInt<M>>> AddAssign<T> for ModInt<M> {
        fn add_assign(&mut self, other: T) { *self = *self + other; }
    }
    impl<M: Mod, T: Into<ModInt<M>>> SubAssign<T> for ModInt<M> {
        fn sub_assign(&mut self, other: T) { *self = *self - other; }
    }
    impl<M: Mod, T: Into<ModInt<M>>> MulAssign<T> for ModInt<M> {
        fn mul_assign(&mut self, other: T) { *self = *self * other; }
    }
    impl<M: Mod> Neg for ModInt<M> {
        type Output = Self;
        fn neg(self) -> Self { ModInt::new(0) - self }
    }
    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)
        }
    }
    impl<M: Mod> From<i64> for ModInt<M> {
        fn from(x: i64) -> Self { Self::new(x) }
    }
} // 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, verified as NTT only)
/// R: Ring + Copy
/// Verified by: https://codeforces.com/contest/1096/submission/47672373
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: &mut [R], zeta: R, one: R)
        where R: Copy +
        Add<Output = R> +
        Sub<Output = R> +
        Mul<Output = R> {
        let n = f.len();
        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 { f.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 base = zetapow.pop().unwrap();
            let mut r = 0;
            while r < n {
                let mut w = one;
                for s in r .. r + m {
                    let u = f[s];
                    let d = f[s + m] * w;
                    f[s] = u + d;
                    f[s + m] = u - d;
                    w = w * base;
                }
                r += 2 * m;
            }
            m *= 2;
        }
    }
}

use fft::*;

// Depends on ModInt.rs
fn fact_init(w: usize) -> (Vec<ModInt>, Vec<ModInt>) {
    let mut fac = vec![ModInt::new(1); w];
    let mut invfac = vec![0.into(); w];
    for i in 1 .. w {
        fac[i] = fac[i - 1] * i as i64;
    }
    invfac[w - 1] = fac[w - 1].inv();
    for i in (0 .. w - 1).rev() {
        invfac[i] = invfac[i + 1] * (i as i64 + 1);
    }
    (fac, invfac)
}

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,
        l: i64,
    }
    const N: usize = 4096;
    let (fac, invfac) = fact_init(N);

    let mut p = vec![ModInt::new(0); N];
    let mut q = vec![ModInt::new(0); N];
    p[1] = ModInt::new(2);
    p[2] = -ModInt::new(2);
    q[0] = ModInt::new(1);
    q[1] = -ModInt::new(2);
    q[2] = ModInt::new(2);

    let zeta = ModInt::new(3).pow((MOD - 1) / N as i64);
    transform(&mut p, zeta, ModInt::new(1));
    transform(&mut q, zeta, ModInt::new(1));

    let mut ans = vec![ModInt::new(0); N];
    let mut coef = vec![ModInt::new(0); N];
    for i in k..n + 1 {
        coef[i] = fac[n] * invfac[n - i] * invfac[i];
    }
    for j in 0..N {
        let mut pp = p[j].pow(k as i64);
        let mut qp = q[j].pow((n - k) as i64);
        let mut qinv = q[j].inv();
        for i in k..n + 1 {
            let coef = coef[i];
            ans[j] += pp * qp * coef;
            pp *= p[j];
            qp *= qinv;
        }
    }
    transform(&mut ans, zeta.inv(), ModInt::new(1));
    // eprintln!("ans = {:?}", &ans[0..10]);
    let mut tot = ModInt::new(0);
    for i in 0..2 * n + 1 {
        tot += ans[i] * ModInt::new((i + 1) as i64).inv();
    }
    tot *= ModInt::new(N as i64).inv();
    puts!("{}\n", tot * l);
}

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


Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.

The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.

Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower).

NoteIn the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.

use std::io;

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

    let a: Vec<u32> = {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        input.split_whitespace().map(|k| k.parse().unwrap()).collect()
    };

    let ans = n % 2 == 1 && a.first().unwrap() % 2 == 1 && a.last().unwrap() % 2 == 1;

    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}

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

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

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

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

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

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

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

trait Ext {
    fn is_odd(&self) -> bool;
    fn is_even(&self) -> bool;
}

impl Ext for i32 {
    #[inline]
    fn is_odd(&self) -> bool {
        self % 2 != 0
    }

    #[inline]
    fn is_even(&self) -> bool {
        self % 2 == 0
    }
}

fn main() {
    let (n,) = scan_line!(usize);
    let array = scan_line_to_vec!(i32);

    let mut result = true;
    result &= array[0].is_odd();
    result &= array[n - 1].is_odd();
    result &= (array.len() as i32).is_odd();

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

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

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

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

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

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

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

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

trait Ext {
    fn is_odd(&self) -> bool;
    fn is_even(&self) -> bool;
}

impl Ext for i32 {
    #[inline]
    fn is_odd(&self) -> bool {
        self % 2 != 0
    }

    #[inline]
    fn is_even(&self) -> bool {
        self % 2 == 0
    }
}

fn main() {
    let (n,) = scan_line!(usize);
    let array = scan_line_to_vec!(i32);

    let mut result = true;

    let mut i = 0;
    let mut segment_count = 0;
    let mut count_evens = 0;

    while i < (n - 1) {
        if array[i].is_odd() && array[i+1].is_odd() {
            segment_count += 1;
        } else if array[i].is_odd() && array[i+1].is_even() {
            count_evens += 1;
        } else if array[i].is_even() && array[i+1].is_even() {
            count_evens += 1;
        } else if array[i].is_even() && array[i+1].is_odd() {
            if count_evens.is_odd() {
                count_evens = 0;
                segment_count += 1;
                i += 1;
            } else {
                result = false;
                break;
            }
        }
        i += 1;
    }

    if i == n - 1 && array[n - 1].is_odd() {
        segment_count += 1;
    } else if i == n - 1 {
        result = false;
    }

    if segment_count.is_even() {
        result = false;
    }

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


Your friend has n cards.You know that each card has a lowercase English letter on one side and a digit on the other.Currently, your friend has laid out the cards on a table so only one side of each card is visible.You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.

The first and only line of input will contain a string s (1 ≤ |s| ≤ 50), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.

Print a single integer, the minimum number of cards you must turn over to verify your claim.

NoteIn the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.In the third sample, we need to flip the second and fourth cards.

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

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

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

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

    let s = "aeiou13579";
    let sol = input.sl().chars().filter(|&c| s.chars().any(|a| a == c)).count();
    println!("{}", sol);
}

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

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

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

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

fn is_vowel(z: char)->bool {
  let s = "aeoiu";
  return s.chars().any(|x|x==z);
}

fn is_odd(z: char)->bool {
  let s = "13579";
  return s.chars().any(|x|x==z);
}

fn main() {
let s = readln!();
println!("{}",s.chars().filter(|&x| is_vowel(x) || is_odd(x)).count());
}

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

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

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

fn is_vowel(ch: char) -> bool {
    return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
}

fn _main() {
    let mut scan = Scan::new();
    let mut result = 0usize;
    for ch in scan.next::<String>().chars() {
        if is_vowel(ch) || ch.to_digit(10).unwrap_or(2) % 2 == 1 {
            result += 1;
        }
    }
    println!("{}", result);
}

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

fn read_line() -> Option<String> {
    let stdin = std::io::stdin();
    let mut line = String::new();
    if stdin.read_line(&mut line).unwrap_or(0) > 0 {
        Some(line.trim().into())
    } else {
        None
    }
}

fn main() {
    fn should_flip(c: char) -> bool {
        (
            (c.is_digit(10) && (c as u8 - '0' as u8) % 2 == 1) ||
            (['a', 'e', 'i', 'o', 'u'].iter().find(|&&a| a == c).is_some())
        )
    }
    let flips = read_line()
        .expect("should have line")
        .chars()
        .fold(0, |acc, c| if should_flip(c) { acc + 1 } else { acc });
    println!("{}", flips);
}

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

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($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);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        s: chars,
    }
    let c = s.iter().filter(|&&c| {
        if c <= '9' {
            (c as u8 - b'0') % 2 == 1
        } else {
            ['a', 'e', 'i', 'o', 'u'].iter().find(|&&x| x == c).is_some()
        }
    }).count();
    puts!("{}\n", c);
}

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

fn read_line() -> Option<String> {
    let stdin = std::io::stdin();
    let mut line = String::new();
    if stdin.read_line(&mut line).unwrap_or(0) > 0 {
        Some(line.trim().into())
    } else {
        None
    }
}

fn main() {
    fn should_flip(c: char) -> bool {
        (
            (c.is_digit(10) && (c as u8 - '0' as u8) % 2 == 0) ||
            (['a', 'e', 'i', 'o', 'u'].iter().find(|&&a| a == c).is_some())
        )
    }
    let flips = read_line()
        .expect("should have line")
        .chars()
        .fold(0, |acc, c| if should_flip(c) { acc + 1 } else { acc });
    println!("{}", flips);
}


A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive.

Input contains one integer number n (1 ≤ n ≤ 3000).

Output the amount of almost prime numbers between 1 and n, inclusive.

fn sieve_of_eratosthene(n: usize) -> Vec<bool> {
    let mut is_prime = vec![true; std::cmp::max(n, 2)];

    is_prime[0] = false;
    is_prime[1] = false;

    let mut i = 2;
    loop {
        while i < n && !is_prime[i] {
            i += 1;
        }

        let cur_prime = i;

        let mut q = 2;
        while q * cur_prime < n {
            is_prime[q * cur_prime] = false;
            q += 1;
        }

        i += 1;
        if i >= n {
            return is_prime;
        }
    }
}

fn primes(is_prime: &Vec<bool>) -> Vec<usize> {
    let mut primes = Vec::new();
    for i in 0..is_prime.len() {
        if is_prime[i] {
            primes.push(i);
        }
    }

    primes
}

fn is_number_good(prime: &Vec<usize>, n: usize) -> bool {
    let mut firstmult = 0;

    for i in 0..prime.len() {
        if n % prime[i] == 0 {
            firstmult = prime[i];
            break;
        }
    }

    let mut secmult = 0;
    for i in 0..prime.len() {
        if n % prime[i] == 0 && prime[i] != firstmult {
            secmult = prime[i];
            break;
        }
    }

    if secmult == 0 {
        return false;
    }

    for i in 0..prime.len() {
        if n % prime[i] == 0 && prime[i] != firstmult && prime[i] != secmult {
                return false
            }
    }

    true
}
fn main() {
    let mut str = String::new();

    std::io::stdin().read_line(&mut str).unwrap();

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

    let is_prime = sieve_of_eratosthene(n);

    let mut c = 0;
    for i in 2..=n {
        if is_number_good(&primes(&is_prime), i) {
            c += 1;
        }
    }

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

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

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

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

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

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

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

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

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

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

    let n = input.u();
    let mut p = vec![0; n + 1];
    let mut sol = 0;
    for i in 2..=n {
        if p[i] == 0 {
            let mut j = i;
            while j <= n {
                p[j] += 1;
                j += i;
            }
        } else if p[i] == 2 {
            sol += 1;
        }
    }
    println!("{}", sol);
}

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

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

    fn next_line(&self) -> String {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).expect("Fail to read");
        line
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop_front() {
                break token.parse::<T>().ok().unwrap();
            }
            let line = self.next_line();
            self.buffer = line.split_whitespace().map(String::from).collect();
        }
    }

    fn next_n<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next::<T>()).collect()
    }
}

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let mut count = [0; 3001];
    let mut result = 0usize;
    let mut i = 2usize;
    while i <= n {
        if count[i] == 0 {
            let mut j = 2;
            while i * j <= n {
                count[i * j] += 1;
                j += 1;
            }
        }
        i += 1;
    }
    for i in 2..=n {
        if count[i] == 2 {
            result += 1;
        }
    }
    println!("{}", result);
}

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

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

struct Reader {}

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

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

//mod math;

fn generate_simple_numbers(max_value: i64) -> Vec<i64> {
    let mut src = vec![true; max_value as usize + 1];
    let mut dst = Vec::new();

    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            let mut ind = i * i;
            while ind <= max_value as usize {
                src[ind] = false;
                ind += i;
            }
        }
    }
    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            dst.push(i as i64);
        }
    }
    dst
}

fn main() {

    let n = Reader::read_string().parse::<i64>().unwrap();
    let simple_numbers = generate_simple_numbers(3000);
    let mut ans = 0_i64;
    for i in 1..=n {
        let mut number = i;
        let mut map = std::collections::BTreeSet::<i64>::new();
        for value in simple_numbers.iter() {
            if *value > number {
                break;
            }
            while number % *value == 0 {
                map.insert(*value);
                number /= *value;
            }
        }
        if map.len() == 2 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

struct Reader {}

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

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

//mod math;

fn generate_simple_numbers(max_value: i64) -> Vec<i64> {
    let mut src = vec![true; max_value as usize + 1];
    let mut dst = Vec::new();

    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            let mut ind = i * i;
            while ind <= max_value as usize {
                src[ind] = false;
                ind += i;
            }
        }
    }
    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            dst.push(i as i64);
        }
    }
    dst
}

fn main() {

    let n = Reader::read_string().parse::<i64>().unwrap();
    let simple_numbers = generate_simple_numbers(3000);
    let mut ans = 0_i64;
    for i in 1..=n {
        let mut number = i;
        let mut map = std::collections::HashMap::<i64, i32>::new();
        for value in simple_numbers.iter() {
            if *value > number {
                break;
            }
            while number % *value == 0 {
                map.insert(*value, 1);
                number /= *value;
            }
        }
        if map.len() == 2 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

struct Reader {}

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

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

//mod math;

fn generate_simple_numbers(max_value: i64) -> Vec<i64> {
    let mut src = vec![true; max_value as usize + 1];
    let mut dst = Vec::new();

    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            let mut ind = i * i;
            while ind <= max_value as usize {
                src[ind] = false;
                ind += i;
            }
        }
    }
    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            dst.push(i as i64);
        }
    }
    dst
}

fn main() {

    let n = Reader::read_string().parse::<i64>().unwrap();
    let simple_numbers = generate_simple_numbers(3000);
    let mut ans = 0_i64;
    for i in 1..=n {
        let mut number = i;
        let mut map = std::collections::HashMap::<i64, i32>::new();
        for value in simple_numbers.iter() {
            while number % *value == 0 {
                map.insert(*value, 1);
                number /= *value;
            }
        }
        if map.len() == 2 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

struct Reader {}

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

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

//mod math;

pub fn generate_simple_numbers(max_value: u64) -> Vec<u64> {
    let mut src = vec![true; max_value as usize + 1];
    let mut dst = Vec::new();

    for i in 2 .. max_value as usize + 1 {
        if src[i] {
            let mut ind = i * i;
            while ind <= max_value as usize {
                src[ind] = false;
                ind += i;
            }
            dst.push(i as u64);
        }
    }
    dst
}

fn main() {
    let n = Reader::read_string().parse::<i64>().unwrap();
    let simple_numbers = generate_simple_numbers(3000);
    let mut ans = 0_u64;
    for i in 1..=n {
        let mut number = i as u64;
        let mut map = std::collections::BTreeSet::<u64>::new();
        for value in simple_numbers.iter() {
            if *value > number {
                break;
            }
            while number % *value == 0 {
                map.insert(*value);
                number /= *value;
            }
        }
        if map.len() == 2 {
            ans += 1;
        }
    }
    println!("{}", ans);
}

fn sieve_of_eratosthene(n: usize) -> Vec<bool> {
    let mut is_prime = vec![true; std::cmp::max(n, 2)];

    is_prime[0] = false;
    is_prime[1] = false;

    let mut i = 2;
    loop {
        while i < n && !is_prime[i] {
            i += 1;
        }

        let cur_prime = i;

        let mut q = 2;
        while q * cur_prime < n {
            is_prime[q * cur_prime] = false;
            q += 1;
        }

        i += 1;
        if i >= n {
            return is_prime;
        }
    }
}

fn primes(is_prime: &Vec<bool>) -> Vec<usize> {
    let mut primes = Vec::new();
    for i in 0..is_prime.len() {
        if is_prime[i] {
            primes.push(i);
        }
    }

    primes
}

fn is_number_good(prime: &Vec<usize>, n: usize) -> bool {
    let mut firstmultiplier = 0;

    for i in 0..prime.len() {
        if n % prime[i] == 0 {
            firstmultiplier = prime[i];
        }
    }

    for i in 0..prime.len() {
        if n % prime[i] == 0 && prime[i] != firstmultiplier {
            return true;
        }
    }

    false
}

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

    std::io::stdin().read_line(&mut str).unwrap();

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

    let is_prime = sieve_of_eratosthene(n);

    let mut c = 0;
    for i in 2..n {
        if is_number_good(&primes(&is_prime), i) {
            c += 1;
        }
    }

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

fn sieve_of_eratosthene(n: usize) -> Vec<bool> {
    let mut is_prime = vec![true; std::cmp::max(n, 2)];

    is_prime[0] = false;
    is_prime[1] = false;

    let mut i = 2;
    loop {
        while i < n && !is_prime[i] {
            i += 1;
        }

        let cur_prime = i;

        let mut q = 2;
        while q * cur_prime < n {
            is_prime[q * cur_prime] = false;
            q += 1;
        }

        i += 1;
        if i >= n {
            return is_prime;
        }
    }
}

fn primes(is_prime: &Vec<bool>) -> Vec<usize> {
    let mut primes = Vec::new();
    for i in 0..is_prime.len() {
        if is_prime[i] {
            primes.push(i);
        }
    }

    primes
}

fn is_number_good(prime: &Vec<usize>, n: usize) -> bool {
    let mut firstmultiplier = 0;

    for i in 0..prime.len() {
        if n % prime[i] == 0 {
            firstmultiplier = prime[i];
        }
    }

    for i in 0..prime.len() {
        if n % prime[i] == 0 && prime[i] != firstmultiplier {
            return true;
        }
    }

    false
}

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

    std::io::stdin().read_line(&mut str).unwrap();

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

    let is_prime = sieve_of_eratosthene(n);

    let mut c = 0;
    for i in 2..=n {
        if is_number_good(&primes(&is_prime), i) {
            c += 1;
        }
    }

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


Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n1 + n2 + ... + nk = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition ni ≥ 2 should hold for all i from 1 to k.Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.

The first line of the input contains a single integer n (2 ≤ n ≤ 2·109) — the total year income of mr. Funt.

Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.

//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn is_prime(n: u64) -> bool {
    if n <= 1 {
        return false;
    }
    for k in (2..).take_while(|k| k * k <= n) {
        if n % k == 0 {
            return false;
        }
    }
    true
}

fn run() {
    input! {
        n: u64,
    }
    let ans = if is_prime(n) {
        1
    } else if n % 2 == 0 {
        2
    } else if is_prime(n - 2) {
        2
    } else {
        3
    };
    println!("{}", ans);
}

fn main() {
    run();
}

use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;

fn exec() {
    let mut sc = Scanner::new();
    let n: i64 = sc.ne();
    let ans = if is_prime(n) {
        1
    } else if n & 1 == 0 || is_prime(n - 2) {
        2
    } else {
        3
    };
    println!("{}", ans);
}

fn is_prime(x: i64) -> bool {
    let mut y = 2;
    while y * y <= x {
        if x % y == 0 {
            return false;
        }
        y += 1;
    }
    x != 1
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

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

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

use std::io;

struct Prime {
    a: Vec<bool>,
    al: usize,
    t: Vec<usize>,
}

#[allow(dead_code)]
impl Prime {
    fn new(n: usize) -> Self {
        let mut t = vec![2; 1];
        let s = (n as f64).sqrt().round() as usize + 3;
        let mut a = vec![true; s];
        a[0] = false;
        a[1] = false;
        for i in (4..s).step_by(2) {
            a[i] = false;
        }
        for i in (3..s).step_by(2) {
            if !a[i] {
                continue;
            }
            t.push(i);
            if i * i < s {
                for j in ((i * i)..s).step_by(i * 2) {
                    a[j] = false;
                }
            }
        }
        let al = a.len();
        Prime { a, al, t }
    }

    fn is_prime(&self, x: usize) -> bool {
        if x < self.al {
            return self.a[x];
        }

        for c in self.t.iter() {
            if x % c == 0 {
                return false;
            }
        }

        true
    }
}

#[allow(dead_code)]
fn solve() -> Vec<String> {
    let mut input = "".split_ascii_whitespace();
    let mut read = || loop {
        if let Some(word) = input.next() {
            break word;
        }
        input = {
            let mut input = "".to_owned();
            io::stdin().read_line(&mut input).unwrap();
            if input.is_empty() {
                panic!("reached EOF");
            }
            Box::leak(input.into_boxed_str()).split_ascii_whitespace()
        };
    };
    macro_rules! read(($ty:ty) => (read().parse::<$ty>().unwrap()));

    let mut rr = vec!["".to_string(); 0];

    let t = 1;
    for _ in 0..t {
        let n = read!(usize);

        let mut r = 3;
        if n > 3 && n % 2 == 0 {
            r = 2;
        } else {
            let pr = Prime::new(n);
            if pr.is_prime(n) {
                r = 1;
            } else if pr.is_prime(n - 2) {
                r = 2;
            }
        }

        rr.push(format!("{}", r));
    }

    rr
}

#[allow(dead_code)]
fn main() {
    let output = solve();
    println!("{}", output.join("\n"));
}

use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;

fn exec() {
    let mut sc = Scanner::new();
    let n: i64 = sc.ne();
    let ans = if is_prime(n) {
        1
    } else if n & 1 == 1 {
        3
    } else {
        2
    };
    println!("{}", ans);
}

fn is_prime(x: i64) -> bool {
    let mut y = 2;
    while y * y <= x {
        if x % y == 0 {
            return false;
        }
        y += 1;
    }
    x != 1
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

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

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

use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;

fn exec() {
    let mut sc = Scanner::new();
    let n: i64 = sc.ne();
    fn solve(n: i64) -> i64 {
        if is_prime(n) {
            return 1;
        }
        let mut x = n - 2;
        while is_prime(x) == false {
            x -= 1;
        }
        1 + solve(n - x)
    }
    println!("{}", solve(n));
}

fn is_prime(x: i64) -> bool {
    let mut y = 2;
    while y * y <= x {
        if x % y == 0 {
            return false;
        }
        y += 1;
    }
    x != 1
}
const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

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

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


Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.

The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number. The following n lines contain a sequence of integers a1, a2, ..., an (one integer per line, 1 ≤ ai ≤ 100) — numbers written on the n cards.

If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.

NoteIn the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.

use std::io;
use std::cmp::Ordering;

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

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

fn main() {

    let num = read_int_line();

    let mut a: i32 = -1;
    let mut b: i32 = -1;

    let mut an: i32 = 0;
    let mut bn: i32 = 0;

    let mut foo: bool = true;

    for i in (0..num).rev(){
        let temp = read_int_line();
        if !foo {

        }
        else if a == temp {
            an += 1;
        }
        else if b == temp {
            bn += 1;
        }
        else if b == -1 {
            b = temp;
        }
        else if a == -1 {
            a = temp;
        }
        else {
            foo = false;
        }
    }

    if foo {
        match a.cmp(&b) {
            Ordering::Equal => println!("NO"),
            _ => match an.cmp(&bn) {
                Ordering::Equal => {println!("YES"); println!("{} {}", a, b);},
                _ => println!("NO"),
            },
        }
    }
    else {
        println!("NO");
    }
}

use std::io;
use std::cmp::Ordering;

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

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

fn main() {

    let num = read_int_line();

    let mut a: i32 = -1;
    let mut b: i32 = -1;

    let mut an: i32 = 0;
    let mut bn: i32 = 0;

    let mut foo: bool = true;

    for i in (0..num).rev(){
        let temp = read_int_line();
        match temp.cmp(&a) {
            Ordering::Equal => an += 1,
            _ => match temp.cmp(&b) {
                Ordering::Equal => bn += 1,
                _ => match b.cmp(&(-1)) {
                    Ordering::Equal => b = temp,
                    _ => match a.cmp(&-1) {
                        Ordering::Equal => a = temp,
                        _ => { println!("NO"); foo = false; break; } ,
                    }
                },
            },
        }
    }

    if foo {
        match a.cmp(&b) {
            Ordering::Equal => println!("NO"),
            _ => match an.cmp(&bn) {
                Ordering::Equal => {println!("YES"); println!("{} {}", a, b);},
                _ => println!("NO"),
            },
        }
    }
}

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

use std::io::prelude::*;
use std::io::BufReader;
use std::cmp::{max, min};

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

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

fn main() {
    let n: usize = get_line().trim().parse().unwrap();

    let mut set = vec![0; 100];

    for s in BufReader::new(io::stdin()).lines() {
        let s = s.unwrap();
        let a: usize = s.trim().parse::<usize>().unwrap() - 1;
        set[a] += 1;
    }

    let ans = set.iter().filter(|&&x| x != 0).count() == 2
        && {
            let mut it = set.iter().filter(|&&x| x != 0);
            it.next().unwrap() == it.next().unwrap()
        };

    if ans {
        println!("YES");
        for (i, _) in set.iter().enumerate().filter(|&(_, &x)| x != 0) {
            print!("{} ", i + 1);
        }
        println!("");
    } else {
        println!("NO");
    }
}


A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size. The burglar's rucksack can hold n matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than n matchboxes so that the total amount of matches in them is maximal.

The first line of the input contains integer n (1 ≤ n ≤ 2·108) and integer m (1 ≤ m ≤ 20). The i + 1-th line contains a pair of numbers ai and bi (1 ≤ ai ≤ 108, 1 ≤ bi ≤ 10). All the input numbers are integer.

Output the only number — answer to the problem.

#![allow(dead_code)]
#![allow(unused_imports)]
use std::cmp::{min, max};
use std::io::{BufWriter, stdin, stdout, Write};
const BITS: usize = 19;

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

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

    let n: i32 = scan.next::<i32>();
    let m: i32 = scan.next::<i32>();

    let mut arr: Vec<(i32, i32)> = Vec::new();

    for _i in 0..m {
        let a: i32 = scan.next::<i32>();
        let b: i32 = scan.next::<i32>();
        arr.push((a, b));
    }

    arr.sort_by(|a, b| a.1.cmp(&b.1));
    arr.reverse();

    let mut total: i32 = 0;
    let mut total_boxes: i32 = 0;

    'outer: for (a, b) in arr.iter() {
        if total_boxes >= n {
            break;
        }
        'inner: for _i in 0..*a {
            if total_boxes >= n {
                break 'outer;
            }
            total_boxes += 1;
            total += *b;
        }
    }

    writeln!(out, "{}", total);
}


Polycarp is preparing the first programming contest for robots. There are $$$n$$$ problems in it, and a lot of robots are going to participate in it. Each robot solving the problem $$$i$$$ gets $$$p_i$$$ points, and the score of each robot in the competition is calculated as the sum of $$$p_i$$$ over all problems $$$i$$$ solved by it. For each problem, $$$p_i$$$ is an integer not less than $$$1$$$.Two corporations specializing in problem-solving robot manufacturing, "Robo-Coder Inc." and "BionicSolver Industries", are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results — or manipulating them. For some reason (which absolutely cannot involve bribing), Polycarp wants the "Robo-Coder Inc." robot to outperform the "BionicSolver Industries" robot in the competition. Polycarp wants to set the values of $$$p_i$$$ in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot. However, if the values of $$$p_i$$$ will be large, it may look very suspicious — so Polycarp wants to minimize the maximum value of $$$p_i$$$ over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of problems. The second line contains $$$n$$$ integers $$$r_1$$$, $$$r_2$$$, ..., $$$r_n$$$ ($$$0 \le r_i \le 1$$$). $$$r_i = 1$$$ means that the "Robo-Coder Inc." robot will solve the $$$i$$$-th problem, $$$r_i = 0$$$ means that it won't solve the $$$i$$$-th problem. The third line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$0 \le b_i \le 1$$$). $$$b_i = 1$$$ means that the "BionicSolver Industries" robot will solve the $$$i$$$-th problem, $$$b_i = 0$$$ means that it won't solve the $$$i$$$-th problem.

If "Robo-Coder Inc." robot cannot outperform the "BionicSolver Industries" robot by any means, print one integer $$$-1$$$. Otherwise, print the minimum possible value of $$$\max \limits_{i = 1}^{n} p_i$$$, if all values of $$$p_i$$$ are set in such a way that the "Robo-Coder Inc." robot gets strictly more points than the "BionicSolver Industries" robot.

NoteIn the first example, one of the valid score assignments is $$$p = [3, 1, 3, 1, 1]$$$. Then the "Robo-Coder" gets $$$7$$$ points, the "BionicSolver" — $$$6$$$ points.In the second example, both robots get $$$0$$$ points, and the score distribution does not matter.In the third example, both robots solve all problems, so their points are equal.

use std::io;

fn main() {
    let (mut cnt1, mut cnt2);

    cnt1 = 0;
    cnt2 = 0;

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

    let n: usize = s.trim().parse().unwrap();

    s = String::new();
    io::stdin().read_line(&mut s).expect("Failed to read line");
    let a = s
        .split_whitespace()
        .map(|x| x.parse::<i32>())
        .collect::<Result<Vec<i32>, _>>()
        .unwrap();

    s = String::new();
    io::stdin().read_line(&mut s).expect("Failed to read line");
    let b = s
        .split_whitespace()
        .map(|x| x.parse::<i32>())
        .collect::<Result<Vec<i32>, _>>()
        .unwrap();

    for i in 0usize..n {
        if a[i] == 1 && b[i] == 0 {
            cnt1 = cnt1 + 1;
        } else if a[i] == 0 && b[i] == 1 {
            cnt2 = cnt2 + 1;
        }
    }

    if cnt1 == 0 {
        println!("-1");
    } else {
        println!("{}", cnt2 / cnt1 + 1);
    }
}

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

fn main() {
    let _n = get_input().trim().parse::<usize>().unwrap();
    let ra: Vec<usize> = get_input().trim().split(' ').map(|x| x.parse::<usize>().unwrap()).collect();
    let rb: Vec<usize> = get_input().trim().split(' ').map(|x| x.parse::<usize>().unwrap()).collect();
    let mut badv = 0;
    let mut rchn = 0;
    for (rv, bv) in ra.iter().zip(rb) {
        if *rv == 0 && bv == 1 {
            badv += 1;
        } else if *rv == 1 && bv == 0 {
            rchn += 1;
        }
    }

    if rchn == 0 {
        println!("{}", -1);
    } else if badv == 0 {
        println!("{}", 1);
    } else {
        let rwin = badv + 1;
        if rwin % rchn != 0 {
            println!("{}", 1 + (rwin / rchn));
        } else {
            println!("{}", rwin / rchn);
        }
    }
}

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

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();
    let _ = lines.next().unwrap().unwrap().parse::<i32>().unwrap();
    let a: Vec<i32> = lines.next().unwrap().unwrap().split(" ").map(|s| s.parse::<i32>().unwrap()).collect();
    let b: Vec<i32> = lines.next().unwrap().unwrap().split(" ").map(|s| s.parse::<i32>().unwrap()).collect();
    println!("{}", solve(a, b).unwrap_or(-1));
}

pub fn solve( a: Vec<i32>, b: Vec<i32>) -> Option<i32> {
    let b_score = a.iter().zip(b.iter()).fold(0, |mut acc, (x,y)| {
        if x < y {
            acc += 1;
        }
        acc
    });
    let outperform = a.iter().zip(b.iter()).fold(0, |mut acc, (x,y)| {
        if x > y {
            acc += 1;
        }
        acc
    });
    match outperform {
        0 => None,
        r => Some(b_score / outperform + 1),
    }
}

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 {
       if self.buffer.len() == 0 {
          let mut input = String::new();
          std::io::stdin().read_line(&mut input).ok();
          for word in input.split_whitespace() {
             self.buffer.push_back(word.to_string())
          }
       }
       let front = self.buffer.pop_front().unwrap();
       front.parse::<T>().ok().unwrap()
    }

}

fn main() {
    let mut scanner = Scanner::new();
    let n : usize = scanner.next();
    let mut r: Vec<i32> = Vec::new();
    let (mut r_win, mut b_win) = (0, 0);
    for _ in 0..n {
        let num : i32 = scanner.next();
        r.push(num);
    }
    for i in 0..n {
        let num : i32 = scanner.next();
        if num > r[i] {
            b_win += 1;
        } else if num < r[i] {
            r_win += 1;
        }
    }
    if r_win == 0 {
        println!("-1");
    } else {
        println!("{}", b_win / r_win + 1);
    }
}

#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[macro_export]
macro_rules ! chmax { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: max ( $ x ,$ v ) ; ) + } ; }
#[macro_export]
macro_rules ! chmin { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: min ( $ x ,$ v ) ; ) + } ; }
#[macro_export]
macro_rules ! max { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: max ( $ x , max ! ( $ ( $ xs ) ,+ ) ) } ; }
#[macro_export]
macro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: min ( $ x , min ! ( $ ( $ xs ) ,+ ) ) } ; }
#[macro_export]
macro_rules ! dvec { ( $ t : expr ; $ len : expr ) => { vec ! [ $ t ; $ len ] } ; ( $ t : expr ; $ len : expr , $ ( $ rest : expr ) ,* ) => { vec ! [ dvec ! ( $ t ; $ ( $ rest ) ,* ) ; $ len ] } ; }
#[macro_export]
macro_rules ! cfor { ( ; $ ( $ rest : tt ) * ) => { cfor ! ( ( ) ; $ ( $ rest ) * ) } ; ( $ ( $ init : stmt ) ,+; ; $ ( $ rest : tt ) * ) => { cfor ! ( $ ( $ init ) ,+; ! false ; $ ( $ rest ) * ) } ; ( $ ( $ init : stmt ) ,+; $ cond : expr ; ; $ body : block ) => { cfor ! { $ ( $ init ) ,+; $ cond ; ( ) ; $ body } } ; ( $ ( $ init : stmt ) ,+; $ cond : expr ; $ ( $ step : expr ) ,+; $ body : block ) => { { $ ( $ init ; ) + while $ cond { let mut _first = true ; let mut _continue = false ; loop { if ! _first { _continue = true ; break } _first = false ; $ body } if ! _continue { break } $ ( $ step ; ) + } } } ; }
#[doc = " main"]
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[macro_export]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; }
#[macro_export]
macro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( "Parse error" ) } ; }
use std::io;
use std::io::BufRead;
use std::str;
pub struct Parser<R> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}
impl Parser<io::Empty> {
    pub fn from_str(s: &str) -> Parser<io::Empty> {
        Parser {
            reader: io::empty(),
            buf: s.as_bytes().to_vec(),
            pos: 0,
        }
    }
}
impl<R: BufRead> Parser<R> {
    pub fn new(reader: R) -> Parser<R> {
        Parser {
            reader: reader,
            buf: vec![],
            pos: 0,
        }
    }
    pub fn update_buf(&mut self) {
        self.buf.clear();
        self.pos = 0;
        loop {
            let (len, complete) = {
                let buf2 = self.reader.fill_buf().unwrap();
                self.buf.extend_from_slice(buf2);
                let len = buf2.len();
                if len == 0 {
                    break;
                }
                (len, buf2[len - 1] <= 0x20)
            };
            self.reader.consume(len);
            if complete {
                break;
            }
        }
    }
    pub fn next<T: str::FromStr>(&mut self) -> Result<T, T::Err> {
        loop {
            let mut begin = self.pos;
            while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                begin += 1;
            }
            let mut end = begin;
            while end < self.buf.len() && (self.buf[end] > 0x20) {
                end += 1;
            }
            if begin != self.buf.len() {
                self.pos = end;
                return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>();
            } else {
                self.update_buf();
            }
        }
    }
}
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    input!{
        n:usize,
        a:[u8;n],
        b:[u8;n],
    }
    let mut acnt = 0;
    let mut btot = 0;
    for i in 0..n {
        if a[i] == b[i] {
        } else {
            if a[i] == 1 {
                acnt += 1;
            } else {
                btot += 1;
            }
        }
    }
    if acnt == 0 {
        writeln!(out,"-1");
        return
    }
    let ars = ArithSeq::new(0,acnt);
    let nxt = ars.next(btot+1);
    writeln!(out,"{}",nxt/acnt);
}
struct ArithSeq {
    a: i64,
    b: i64,
}
impl ArithSeq {
    pub fn new(a: i64, b: i64) -> ArithSeq {
        assert!(b > 0);
        ArithSeq { a: a, b: b }
    }
    #[doc = "a+bi >= x"]
    pub fn next(&self, x: i64) -> i64 {
        if x >= self.a {
            let d = x - self.a;
            let i = (d - 1 + self.b) / self.b;
            self.a + self.b * i
        } else {
            let d = self.a - x;
            let i = d / self.b;
            self.a - self.b * i
        }
    }
    #[doc = "a+bi <= x"]
    pub fn prev(&self, x: i64) -> i64 {
        let next = self.next(x);
        if next == x {
            x
        } else {
            next - self.b
        }
    }
    #[doc = "[a+bi, n] <= [l, u]"]
    pub fn range(&self, l: i64, u: i64) -> Option<(i64, i64)> {
        if l > u {
            return None;
        }
        let x = self.next(l);
        let y = self.prev(u);
        if x > y {
            return None;
        }
        assert!(x <= y);
        if l <= x && x <= u {
            let cnt = (y - x) / self.b;
            Some((x, cnt + 1))
        } else {
            None
        }
    }
}

use std::io::stdin;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

impl Scanner {
    fn next<T: std::str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}
fn main() {
    let mut scan = Scanner::default();
    let responses = scan.next::<usize>();
    let mut robo_coder_s = String::new();
    stdin().read_line(&mut robo_coder_s).expect("Failed read");
    let robo_coder = robo_coder_s.split_whitespace().collect::<Vec<&str>>();
    let mut bionic_solver_s = String::new();
    stdin()
        .read_line(&mut bionic_solver_s)
        .expect("Failed read");
    let bionic_solver = bionic_solver_s.split_whitespace().collect::<Vec<&str>>();

    let mut only_robo_coder_wins = 0.0;
    let mut only_bionic_solver_wins = 0.0;
    for response in 0..responses {
        match (robo_coder[response], bionic_solver[response]) {
            ("1", "0") => only_robo_coder_wins += 1.0,
            ("0", "1") => only_bionic_solver_wins += 1.0,
            _ => (),
        }
    }
    let robo_code_minimum_points: f64 = if only_robo_coder_wins == 0.0 {
        -1.0
    } else {
        (only_bionic_solver_wins + 1.0) / only_robo_coder_wins
    };
    println!("{}", robo_code_minimum_points.ceil() as i32);
}

use std::io::stdin;

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

fn main() {
    let mut scan = Scanner::default();
    let n = scan.next::<usize>();
    let mut a = Vec::with_capacity(n);
    for _ in 0..n {
        a.push(scan.next::<i32>());
    }
    let mut b = Vec::with_capacity(n);
    for _ in 0..n {
        b.push(scan.next::<i32>());
    }
    let mut num_a = 0;
    let mut num_b = 0;
    for i in 0..n {
        if b[i] == 0 && a[i] == 1 {
            num_a += 1;
        } else if b[i] == 1 && a[i] == 0 {
            num_b += 1;
        }
    }
    let mut ans;
    if num_a == 0 {
        ans = -1;
    } else {
        ans = 1;
        while num_a * ans <= num_b {
            ans += 1;
        }
    }
    println!("{}", ans);
}

use std::io::stdin;

#[derive(Default)]
struct Scanner {
    buffer: Vec<String>,
}

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

fn main() {
    let mut scan = Scanner::default();
    let n = scan.next::<usize>();
    let mut a = vec![0; n];
    for i in 0..n {
        a[i] = scan.next::<i32>();
    }
    let mut b = vec![0; n];
    for i in 0..n {
        b[i] = scan.next::<i32>();
    }
    let mut num_a = 0;
    let mut num_b = 0;
    for i in 0..n {
        if a[i] == 1 && b[i] == 0 {
            num_a += 1;
        } else if a[i] == 0 && b[i] == 1 {
            num_b += 1;
        }
    }
    let ans = {
        if num_a == 0 {
            -1
        } else {
            let mut x = 1;
            while num_a * x <= num_b {
                x += 1;
            }
            x
        }
    };
    println!("{}", ans);
}