use std::io;

fn main() {
    let mut a_str = String::new();
    io::stdin().read_line(&mut a_str).expect("");
    let mut v_a = a_str.trim().chars()
        .map(|x| x.to_digit(10).unwrap() as i32)
        .collect::<Vec<i32>>();

    let mut b_str = String::new();
    io::stdin().read_line(&mut b_str).expect("");
    let mut v_b = b_str.trim().chars()
        .map(|x| x.to_digit(10).unwrap() as i32)
        .collect::<Vec<i32>>();

    let x: String= v_b.iter().map(|y| y.to_string()).collect();
    let n_b: i64 = x.parse().unwrap();

    let mut res = String::new();
    v_a.sort();
    for i in 0..v_a.len() {
        for j in ((i + 1)..v_a.len()) {
            let mut t = v_a.clone();
            t.swap(i, j);
            let x: String= t.iter().map(|y| y.to_string()).collect();
            let n_t: i64 = x.parse().unwrap();
            let x: String= v_a.iter().map(|y| y.to_string()).collect();
            let n_a: i64 = x.parse().unwrap();
            if (n_a < n_t && n_t < n_b) {
                v_a.swap(i, j);
            }
        }
    }
    res = v_a.iter().map(|x| x.to_string()).collect();
    println!("{}", res);
}


use std::io;

fn main() {
    let mut a_str = String::new();
    io::stdin().read_line(&mut a_str).expect("");
    let mut v_a = a_str.trim().chars()
        .map(|x| x.to_digit(10).unwrap() as i32)
        .collect::<Vec<i32>>();

    let mut b_str = String::new();
    io::stdin().read_line(&mut b_str).expect("");
    let mut v_b = b_str.trim().chars()
        .map(|x| x.to_digit(10).unwrap() as i32)
        .collect::<Vec<i32>>();

    let n_b = 1;

    let mut res = String::new();
    v_a.sort();
    for i in 0..v_a.len() {
        for j in ((i + 1)..v_a.len()) {
            let mut t = v_a;
            t.swap(i, j);
            let n_t: i64 = t.iter().map(|x| x.to_string()).collect().parse().unwrap();
            let n_a: i64 = v_a.iter().map(|x| x.to_string()).collect().parse().unwrap();
            if (n_a < n_t && n_t < n_b) {
                v_a.swap(i, j);
            }
        }
    }
    res = v_a.iter().map(|x| x.to_string()).collect();
    println!("{}", res);
}


type Pair = (u32, u32);
fn input_pair() -> Pair {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let buf: Vec<u32> = buf
        .trim()
        .split_whitespace()
        .map(|elem| elem.parse().unwrap())
        .collect();
    (buf[0], buf[1])
}

type Trio = (u32, u32, u32);
fn input_trio() -> Trio {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let buf: Vec<u32> = buf
        .trim()
        .split_whitespace()
        .map(|elem| elem.parse().unwrap())
        .collect();
    (buf[0], buf[1], buf[2])
}

fn main() {
    let (y_chr, b_chr) = input_pair();
    let (y, g, b) = input_trio();

    let mut req_chr = 0;
    req_chr += (2 * y + g).max(y_chr) - y_chr;
    req_chr += (3 * b + g).max(b_chr) - b_chr;
    println!("{}", req_chr);
}


use std::io;

const BALLS_SIZE: usize = 3;
const CRYST_SIZE: usize = 2;

enum ColorsB{
    Yell,
    Green,
    Blue
}

type CrystalsArray =  [i64; CRYST_SIZE];
type BallsArray = [i64; BALLS_SIZE];

fn count_crystals(balls :BallsArray) -> CrystalsArray{
    fn count_yellow(num: i64 ) -> CrystalsArray {
        [2*num, 0]
    }
    fn count_green(num: i64 ) -> CrystalsArray {
        [num, num]
    }
    fn count_blue(num: i64 ) -> CrystalsArray {
        [0,3*num]
    }
    println!("");
    let mut res: CrystalsArray = [0; CRYST_SIZE];
    for (ind,i) in count_yellow(balls[ColorsB::Yell as usize]).iter().enumerate(){
        res[ind] += *i;
    }
    for (ind,i) in count_green(balls[ColorsB::Green as usize]).iter().enumerate(){
        res[ind] += *i;
    }

    for (ind,i) in count_blue(balls[ColorsB::Blue as usize]).iter().enumerate(){
        res[ind] += *i;
    }
    return res ;
}

fn main() {
    let mut input: String = String::new();
    io::stdin().read_line(&mut input).expect("some error");
    let mut cryst_inp: CrystalsArray = [0; CRYST_SIZE];
    let mut balls_inp: BallsArray = [0; BALLS_SIZE];
    for (ind,i) in input.trim().split(char::is_whitespace).enumerate(){
        cryst_inp[ind] = i.trim().parse().expect("failed to parse");
    }
    input.clear();
    io::stdin().read_line(&mut input).expect("some error");
    for (ind,i) in input.trim().split(char::is_whitespace).enumerate(){
        balls_inp[ind] = i.trim().parse().expect("failed to parse");
    }
    let have_to = count_crystals(balls_inp);
    let mut sum = 0;
    for (ind,i) in  cryst_inp.iter().enumerate(){
        sum += have_to[ind] - i;
    }
    print!("{}", sum);
}


// https://codeforces.com/contest/1293/problem/D
//
#![allow(unused_imports)]
use std::io::*;
use std::io::Write;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, switch) => {
        {
            let ty = read_value!($iter, i32);
            if ty == 1 {
                vec![ty, read_value!($iter, i32), read_value!($iter, i32)]
            } else if ty == 2 {
                vec![ty, read_value!($iter, i32)]
            } else {
                vec![ty, read_value!($iter, i32)]
            }
        }
    };

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

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

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

#[allow(unused_macros)]
macro_rules! read_line {
    ($t:tt) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            s.trim_right().parse::<$t>().unwrap()
        }
    }
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

// ===

const MAX_CORD: i64 = 1e18 as i64;

fn solve(mut limit: i64, start: usize, p1: usize, p2: usize, p3: usize, cost: &Vec<Vec<i64>>) -> i64 {
    if limit < 0 {
        return -10000;
    }
    let mut count = 1;
    let mut now = start;
    while now != p1 {
        let t = ifv!(now < p1, now+1, now-1);
        if limit < cost[now][t] {
            return count;
        }
        count += 1;
        limit -= cost[now][t];
        now = t;
    }
    assert_eq!(now, p1);
    assert_ne!(now, p2);
    if limit < cost[now][p2] {
        return count;
    }
    limit -= cost[now][p2];
    count += 1;
    now = p2;

    while now != p3 {
        let t = ifv!(now < p3, now+1, now-1);
        if limit < cost[now][t] {
            return count;
        }
        count += 1;
        limit -= cost[now][t];
        now = t;
    }
    count
}

fn main() {
    input! {
        x0: i64, y0: i64, ax: i64, ay: i64, bx: i64, by: i64,
        sx: i64, sy: i64, limit: i64
    };

    let mut points = vec![(x0, y0)];
    loop {
        let (lx, ly) = *points.last().unwrap();
        if lx > MAX_CORD || ly > MAX_CORD {
            break;
        }
        points.push((lx*ax+bx, ly*ay+by));
    }
    let n = points.len();

    let mut first_cost = vec![];
    for i in 0..n {
        first_cost.push((sx-points[i].0).abs() + (sy-points[i].1).abs());
    }
    let mut pp_cost = dvec!(0; n, n);
    for i in 0..n {
        for j in 0..n {
            pp_cost[i][j] = (points[i].0-points[j].0).abs() + (points[i].1-points[j].1).abs();
        }
    }

    // debug!(points);
    // debug!(first_cost);

    assert!(n >= 2);

    let mut best = 0;
    for s in 0..n {
        if s < n-1 {
            for l in 0..=s {
                best = max(best, solve(limit - first_cost[s], s, l, s+1, n-1, &pp_cost));
            }
        }
        if s >= 1 {
            for l in s..n {
                best = max(best, solve(limit - first_cost[s], s, l, s-1, 0, &pp_cost));
            }
        }
    }

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


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

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


/*
    Brute force - http://codeforces.com/problemset/problem/271/A
    Completed: 2/7/20 16:30
*/

use std::io;

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

    let vector: Vec<&str> = input.trim().split(" ").collect();

    let bananas = &vector[2].parse::<i32>().unwrap();
    let dollars = &vector[1].parse::<i32>().unwrap();
    let initial_cost = &vector[0].parse::<i32>().unwrap();
    let mut current_banana = 0;
    let mut final_cost = 0;
    let mut borrow;

    for _ in 0..*bananas {
        current_banana += 1;
        final_cost += initial_cost * current_banana;
    }

    borrow = final_cost - *dollars;

    if borrow < 0 {
        borrow = -borrow;
    }

    println!("{}", borrow);

}


use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let read_in = buf.split_whitespace().map(|c| c.trim().parse::<usize>().unwrap()).collect::<Vec<usize>>();
    let (k, n, w) = (read_in[0], read_in[1], read_in[2]);
    let cost = w * (w + 1) / 2 * k;
    let ret: usize;
    if cost >= n {
        ret = 0;
    } else {
        ret = n - cost;
    }
    println!("{}", ret);
}


use std::io;
fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    // (unit_price, money, count)
    let v: Vec<_> = buf
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<u16>().unwrap())
        .collect();
    let total_price = (v[2] + 1) * v[2] / 2 * v[0];
    if v[1] >= total_price {
        println!("{}", 0);
    } else {
        println!("{}", total_price - v[1]);
    }
}


fn read()->Vec<i32>{
    let mut line=String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.split_whitespace().map(|x|x.parse::<i32>().unwrap()).collect()
}
fn main(){
    let a=read();
    let money=(2*a[0]+a[0]*(a[2]-1))/2*a[2];
    let owe=money-a[1];
    if owe>0{
        print!("{}",owe)
    }
    else{print!("0")}
}


use std::io;

fn read() -> String{
    let mut input=String::new();
    io::stdin().read_line(&mut input).expect("unable to read");
    input.trim().to_string()
}
fn main() {
    let inp=read();
    let list: Vec<_>=inp.split_whitespace().collect();
    let price=list[0].parse::<i32>().expect("Failed to parse");
    let money=list[1].parse::<i32>().expect("Failed to parse");
    let total=list[2].parse::<i32>().expect("Failed to parse");
    let mut sum=0;
    for i in 1..total+1{
        sum+=price*i;
    }println!("{}",sum-money);
}


use std::io::stdin;
fn main() {
    let (banana_price, dolar_amount, banana_wanted) = parse_param();
    println!("{}", fact_add(banana_wanted, banana_price) - dolar_amount)
}

fn parse_param() -> (usize, usize, usize) {
    let mut entry_text = String::new();
    stdin().read_line(&mut entry_text).expect("msg: &str");
    let a: Vec<&str> = entry_text.trim().split_whitespace().collect();
    (
        a[0].parse().expect(""),
        a[1].parse().expect(""),
        a[2].parse().expect(""),
    )
}
fn fact_add(x: usize, y: usize) -> usize {
    if x <= 1 {
        return y;
    }
    (x * y) + fact_add(x - 1, y)
}


fn read_int_line() -> Vec<i64> {
    // Read vector of integers
    let cin = std::io::stdin();
    let mut line = String::new();
    cin.read_line(&mut line).unwrap();
    let values: Vec<i64> = line
                            .split_whitespace()
                            .map(|x| x.parse::<i64>().unwrap())
                            .collect();
    values
}

fn main() {
	let values: Vec<i64> = read_int_line();
	let k: i64 = values[0];
	let n: i64 = values[1];
	let w: i64 = values[2];

	let sum: i64 = w * (w + 1) / 2 * k;
	let ans: i64 = sum - n;

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


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

fn main() {
    let stdin = io::stdin();
    let vector:Vec<u32> = stdin.lock().lines().next().unwrap().unwrap().trim().split(' ').map(|s| s.parse().unwrap()).collect();
    let mut sum = 0;
    for i in 1..(vector[2] + 1) {
        sum = sum + (i * vector[0]);
    }
    println!("{}", sum - vector[1]);
}


fn main(){
    let mut a = Vec::with_capacity(3);
    let mut val = String::new();
    std::io::stdin().read_line(&mut val).unwrap();
    let val = val.trim().parse::<String>().unwrap();
    for j in val.split_whitespace(){
        let k = j.trim().parse::<i32>().unwrap();
        a.push(k);
    }
    let mut ans : i32 = 0;
    for p in 1..a[2]+1{
        ans += a[0]*p;
    }
    let last = ans - a[1];
    println!("{}",last);
}


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

fn read_vec() -> Vec<u8> {
    read_str().trim()
        .split_whitespace()
        .map(|value| value
            .parse::<u8>()
            .expect("Error"))
        .collect()
}

fn main() {
    let mut total: u8 = 0;
    let (k, n, w): (u8, u8, u8) =  {
        let values: Vec<u8> = read_vec();
        (values[0], values[1], values[2])
    };

    for index in 1..w + 1 {
        total += index * k;
    }

    if total >= n { total -= n; }
    else { total = 0; }

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


use std::io;
use std::io::prelude::*;

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

    let mut it= s.split_whitespace();
    let k= it.next().unwrap().parse::<i64>().unwrap();
    let  n=it.next().unwrap().parse::<i64>().unwrap();
    let w=it.next().unwrap().parse::<i64>().unwrap();
    let r =(w*(w+1))/2 *k -n;
    print!("{}",r);

}


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

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

    let vec: Vec<&str> = line.split(" ").collect();
    let a: u64 = vec[0].trim().parse().unwrap();
    let b: u64 = vec[1].trim().parse().unwrap();
    let c: u64 = vec[2].trim().parse().unwrap();
    println!("{}", max(0,a*(c+1)*c/2-b));
}


use std::io;

fn main() {
	let mut inp = String::new();
	io::stdin().read_line(&mut inp).unwrap();
	let inp = inp.trim();
	let k: i32 = inp.split_whitespace().nth(0).unwrap().parse().unwrap();
	let n: i32 = inp.split_whitespace().nth(1).unwrap().parse().unwrap();
	let w: i32 = inp.split_whitespace().nth(2).unwrap().parse().unwrap();
	let mut all_money = 0;
	for i in 1..(w+1) {
		all_money += i*k;
	}
	println!("{}", all_money - n);
}


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

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

fn main() {
    let (nodes, edges) = readln!(i32, i32);

    let (min_isolated, max_isolated) = if edges == 0 {
        (nodes, nodes)
    } else {
        (
            if nodes % 2 == 0 {
                max(0, ((nodes + 1) / 2 - edges) * 2)
            } else {
                max(0, ((nodes + 1) / 2 - edges) * 2 - 1)
            },
            nodes - ((1.0 + (8.0 * edges as f64 + 1.0).sqrt()) / 2.0).ceil() as i32
        )
    };

    println!("{} {}", min_isolated, max_isolated);
}


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

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

fn main() {
    let (nodes, edges) = readln!(i64, i64);

    let (min_isolated, max_isolated) = if edges == 0 {
        (nodes, nodes)
    } else {
        (
            if nodes % 2 == 0 {
                max(0, ((nodes + 1) / 2 - edges) * 2)
            } else {
                max(0, ((nodes + 1) / 2 - edges) * 2 - 1)
            },
            nodes - ((1.0 + (8.0 * edges as f64 + 1.0).sqrt()) / 2.0).ceil() as i32
        )
    };

    println!("{} {}", min_isolated, max_isolated);
}


use std::cmp::max;
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 solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let n: i64 = scan.token();
    let m: i64 = scan.token();
    if m == 0 {
        writeln!(out, "{} {}", 100, 100).ok();
        return;
    }
    let min_ans = max(n - 2 * m, 0);
    let k = ((1.0 + ((1 + 8 * m) as f64).sqrt()) / 2.0).ceil() as i64;
    let max_ans = n - k;
    writeln!(out, "{} {}", min_ans, max_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);
}


#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (n, m) = get!(i64, i64);

    let mini = max(0, n - 2 * m);
    let k = (1..).find(|&x| x * (x - 1) / 2 >= m).unwrap();

    println!("{} {}", mini, n - k);
}


// Try Codeforces
// author: Leonardone @ NEETSDKASU

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

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

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

    let min = std::cmp::max(0, (n + 1) / 2 - m);
    let mut max = 0;
    for i in 1..n+1 {
        let v = i * (i - 1) / 2;
        if v >= m {
            max = n - i;
            break;
        }
    }

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


/// https://github.com/akiradeveloper/rust-comp-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 {
    // for (; ...; ...) { ... }
    (; $($rest: tt)*) => {
        cfor!((); $($rest)*)
    };
    // for ($init; ; ...) { ... }
    ($($init: stmt),+; ; $($rest: tt)*) => {
        // avoid the `while true` lint
        cfor!($($init),+; !false; $($rest)*)
    };

    // for ($init; $cond; ) { ... }
    ($($init: stmt),+; $cond: expr; ; $body: block) => {
        cfor!{$($init),+; $cond; (); $body}
    };

    // for ($init; $cond; $step) { $body }
    ($($init: stmt),+; $cond: expr; $($step: expr),+; $body: block) => {
        {
            $($init;)+
            while $cond {
                let mut _first = true;
                let mut _continue = false;
                // this loop runs once, allowing us to use `break` and
                // `continue` as `goto` to skip forward to the
                // condition.
                //
                // the booleans above are very transparent to the
                // optimiser, since they are modified exactly once,
                // with nice control flow, and this this optimises to
                // be similar to C for loop.
                loop {
                    // if we *don't* hit this, there was a `break` in
                    // the body (otherwise the loop fell-through or
                    // was `continue`d.)
                    if !_first { _continue = true; break }
                    _first = false;

                    $body
                }
                if !_continue {
                    // the `if` wasn't hit, so we should propagate the
                    // `break`.
                    break
                }

                $($step;)+
            }
        }
    };
}

/// main

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

// ref: tanakh <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
// diff: using Parser
#[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::BufRead;
use std::io;
use std::str;

// ref: tatsuya6502 <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e>
// ref: wariuni <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e#comment-7040a5ae96305e884eb9>
// diff: using std::io::BufRead::fill_buf()
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();
                // diff: care when there is no empty space or line at the end
                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:i64,m:i64,
    }
    let mi = max(0, n-2*m);
    let fullconn = n*(n-1)/2;
    let ma = if m >= fullconn {
        0
    } else if m==0 {
        n
    } else {
        let mut i=1;
        loop {
            if i*(i-1)/2 >= m {
                break;
            }
            i += 1;
        }
        n-i
    };
    writeln!(out,"{} {}", mi,ma);
}


const MODULO: u64 = 1000000007;

fn main() {
    let mut scan = Scanner::default();
    let n: u64 = scan.next();
    count_cyclic(n);
}

fn count_cyclic(n: u64) {
    let nb_perm = count_permutations(n);
    let nb_acyc = count_acyclic(n);
    println!("{} {}", nb_perm, nb_acyc);
    println!("{}", (nb_perm as i64 - nb_acyc as i64).rem_euclid(MODULO as i64));
}

fn count_permutations(n: u64) -> u64 {
    let mut fac = 1;
    for i in 1..=n {
        fac = (fac * i) % MODULO;
    }
    fac
}

fn count_acyclic(n: u64) -> u64 {
    let mut pred = 2;
    for _ in 3..=n {
        pred = (2 * pred) % MODULO;
    }
    pred
}

// TEMPLATE

#[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();
            std::io::stdin().read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }
}


use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: u32 = input.trim().parse().unwrap();
    let mut pow = 1u32;
    let p = 1000000007u32;
    for _i in 0..(n-1) {
        pow = (pow as u64 * 2u64 % p as u64) as u32;
    }
    //println!("{}", pow);
    let mut fact = 1u32;
    for i in 2..(n+1) {
        fact = (fact as u64 * i as u64 % p as u64) as u32;
    }
    //println!("{}", fact);
    let ans;
    if fact < pow {
        ans = pow + p - fact;
    } else {
        ans = fact - pow;
    }
    println!("{}", ans);
}


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

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

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

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

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

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

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

fn min_possible_invert(n: u64) -> u64 {
  if n == 0 { return 0; }
  let (top, bot) = (n / 10, n % 10);
  let inv = 9 - bot;
  min_possible_invert(top) * 10 + std::cmp::min(bot, inv)
}

fn main() {
  scanln!(x: u64);
  println!("{}", min_possible_invert(x));
}


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

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

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

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

fn main() {
    let s = readln!();
    let z = s.chars().map(|c|min(c,((9u8 - (c as u8 - '0' as u8)) + ('0' as u8)) as char)).collect::<String>().chars().skip_while(|&c|c=='0').collect::<String>();
    println!("{}",if z.is_empty() { "9" } else { z.as_ref() });
}


use std::io;

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

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

	String::from(input.trim())
}

fn main() {
	let s = get_line();

	let mut r = String::new();
	for (i, c) in s.chars().enumerate() {
		let d = c.to_digit(10).unwrap();

		if i == 0 && d < 9 || i != 0 && d >= 5 {
			r.push(std::char::from_digit((9-d) as u32, 10).unwrap());
		} else {
			r.push(c);
		}
	}

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


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 mut num: u64 = scan.next();
    if num == 9 {
        println!("9");
        return;
    }
    let mut result: u64 = 0;
    let mut position: u64 = 1;
    while num > 0 {
        let dig = num%10;
        result += dig.min(9-dig)*position;
        position *= 10;
        num /= 10;
    }
    println!("{}", result);
}

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


fn solve() {
    let v: Vec<char> = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().chars().collect()
    };

    let mut ans = vec!['0'; v.len()];
    for (i, c) in v.iter().enumerate() {
        if *c == '9' || *c == '8' || *c == '7' || *c == '6' || *c == '5' {
            ans[i] = ('9' as u8 - (*c as u8) + '0' as u8) as char;
        } else {
            ans[i] = *c;
        }
    }

    let mut i = 0;
    while i < ans.len() && ans[i] == '0' {
        i += 1;
    }

    if i == ans.len() {
        println!("9");
    } else {
        for x in i..ans.len() {
            print!("{}", ans[x]);
        }
        println!();
    }
}

fn main() {
    solve();
}


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

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

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

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn check(s: &[usize]) -> bool {
    (0..6).all(|i| {
        s[4 * i] == s[4 * i + 1] && s[4 * i] == s[4 * i + 2] && s[4 * i] == s[4 * i + 3]
    })
}

fn main() {
    let seq: Vec<usize> = util::gets();

    let mut ss = seq.clone();
    let mut s1 = seq.clone();
    for i in 0..3 {
        s1[20] = ss[3];
        s1[22] = ss[1];

        s1[9] = ss[22];
        s1[11] = ss[20];

        s1[5] = ss[9];
        s1[7] = ss[11];

        s1[1] = ss[5];
        s1[3] = ss[7];

        ss = s1.clone();

        if check(&s1) && i != 1 {
            println!("YES");
            return;
        }
    }

    let mut ss = seq.clone();
    let mut s1 = seq.clone();
    for i in 0..3 {
        s1[20] = ss[16];
        s1[21] = ss[17];

        s1[17] = ss[5];
        s1[16] = ss[4];

        s1[5] = ss[13];
        s1[4] = ss[12];

        s1[13] = ss[20];
        s1[12] = ss[21];

        ss = s1.clone();

        if check(&s1) && i != 1 {
            println!("YES");
            return;
        }
    }

    println!("NO");

}


static PERMS: [[usize; 8]; 3] = [
    [2, 4, 6, 8, 10, 12, 23, 21],
    [13, 14, 5, 6, 17, 18, 21, 22],
    [3, 4, 17, 19, 10, 9, 16, 14]
];

fn shiftmod(i: usize, dir: i32) -> usize {
    let res = i as i32 + 2 * dir;
    (if res < 0 { 8 + res } else if res > 8 { res - 8 } else { res }) as usize
}

fn shift(perm: &[usize; 8], dir: i32, state: &mut Vec<i32>) {
    for i in 0..6 {
        state.swap(perm[i] - 1, perm[shiftmod(i, dir)] - 1)
    }
}

fn is_correct(state: &Vec<i32>) -> bool {
    (0..6).all(|i|
        ((i * 4)..(i * 4 + 3))
            .all(|k| state[k] == state[k + 1]))
}

fn single_move(state: &mut Vec<i32>) -> bool {
    PERMS.iter().any(|perm| {
        shift(perm, 1, state);
        is_correct(state) || {
            shift(perm, -1, state);
            shift(perm, -1, state);
            is_correct(state)
        }
    })
}

fn main() {
    let mut sin = ReadIn::new();
    let mut colors = sin.intvec();
    println!("{}", if single_move(&mut colors) { "YES" } else { "NO" });
}

use std::iter::*;
use std::str::SplitWhitespace;
use std::io::stdin;
use std::mem::forget;

pub struct ReadIn(pub String);

impl ReadIn {
    pub fn new() -> ReadIn { ReadIn(String::new()) }
    fn read_i32(s: &str) -> i32 { s.parse().unwrap() }
    pub fn read_line(&mut self) {
        self.0.clear();
        forget(stdin().read_line(&mut self.0));
    }
    pub fn ints(&mut self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.read_line();
        self.0.split_whitespace().map(ReadIn::read_i32)
    }
    pub fn intvec(&mut self) -> Vec<i32> { self.ints().collect() }
    pub fn int(&mut self) -> i32 { self.ints().next().unwrap() }
    pub fn int2(&mut self) -> (i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap())
    }

    pub fn int3(&mut self) -> (i32, i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
    }
    pub fn int4(&mut self) -> (i32, i32, i32, i32) {
        let mut it = self.ints();
        (it.next().unwrap(), it.next().unwrap(), it.next().unwrap(), it.next().unwrap())
    }
}


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 extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let colors: Vec<u8> = get_vec();

    let check_face = |i| {
        colors[4 * i..4 * (i + 1)].iter().all(|&x| x == colors[4usize * i])
    };

    let i = (0..6).find(|&x| check_face(x));
    if let None = i {
        println!("NO");
        return;
    }

    let i = i.unwrap();

    let opp = |i| {
        match i {
            0 => 2,
            1 => 5,
            2 => 0,
            3 => 4,
            4 => 3,
            5 => 1,
            _ => panic!(""),
        }
    };

    if !check_face(opp(i)) {
        println!("NO");
        return;
    }

    let to_check = |i| {
        match i {
            0 => (4, 14, 18),
            1 => (0, 13, 16),
            2 => (4, 14, 18),
            3 => (4, 1, 9),
            4 => (4, 1, 9),
            5 => (0, 13, 16),
            _ => panic!(""),
        }
    };

    let tc = to_check(i);
    let ans = colors[tc.0] == colors[tc.1] || colors[tc.0] == colors[tc.2];

    if ans {
        println!("YES");
    } else {
        println!("NO");
    }
}


use std::io::*;
use std::ops::*;

#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
struct Clock {
    hh: i32,
    mm: i32,
}

impl Clock {
    pub fn new (hh: i32, mm: i32) -> Self {
        Self {
            hh, mm
        }
    }
}

impl Sub<i32> for Clock {
    type Output = Clock;
    fn sub(self, m: i32) -> Clock {
        let mut c = self;
        let h = m / 60;
        c.hh -= h;
        c.mm -= m;
        if c.mm < 0 {
            c.hh -= 1;
            c.mm = 60 + self.mm;
        }
        c
    }
}

fn find_lucky(c: &Clock) -> bool {
    if c.hh / 10 == 7 || c.hh % 10 == 7 || c.mm / 10 == 7 || c.mm % 10 == 7 {
        true
    } else {
        false
    }
}

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input).expect("Can't read input");
    let x: i32 = input.trim().parse().expect("Can't parse input");
    input.clear();
    stdin().read_line(&mut input).expect("Cant' read input");
    let mut hm = input.split_whitespace().map(|s| s.parse().expect("Can't parse intput"));
    let hh: i32 = hm.next().unwrap();
    let mm = hm.next().unwrap();
    let mut c = Clock::new(hh, mm);
    let mut n = 0;
    loop {
        if find_lucky(&c) {
            println!("{}", n);
            break;
        }
        c = c - x;
        n += 1;
    }

}


#![allow(unused_imports)]
use std::io;
use std::io::prelude::*;
use std::io::BufReader;
use std::str::FromStr;
use std::collections::{VecDeque, HashMap};
use std::ops::Sub;

fn main() {
    let stdin = io::stdin();
    let mut input = stdin.lock();
    let mut line = String::new();
    input.read_line(&mut line).unwrap();
    let x = get_numbers(&line)[0];
    line.clear(); input.read_line(&mut line).unwrap();
    let nums = get_numbers(&line);

    let get_up = Time::new(nums[0], nums[1]);

    let mut snoozed = 0;
    let mut cur_time = get_up;
    while cur_time.lucky() == false {
        cur_time = cur_time - x;
        snoozed += 1;
    }

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

#[derive(Debug, Clone, Copy)]
struct Time {
    hh: u8,
    mm: u8,
}

impl Time {
    fn new(hour: u8, min: u8) -> Time {
        Time {
            hh: hour,
            mm: min,
        }
    }

    fn lucky(&self) -> bool {
        // 7 cannot be appear in the 10s spot so we only have to check ones
        self.mm % 10 == 7 || self.hh % 10 == 7
    }
}

impl Sub<u8> for Time {
    type Output = Time;

    fn sub(self, mins: u8) -> Time {
        if mins < self.mm {
            Time { hh: self.hh, mm: self.mm - mins }
        } else if self.hh >= 1 {
            Time { hh: self.hh - 1, mm: self.mm + 60 - mins }
        } else {
            // going back a day
            Time { hh: 23, mm: self.mm + 60 - mins }
        }
    }
}

/*
 * Utility Functions
 */

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


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

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

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


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

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

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

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}

fn main() {
    let input: Vec<usize> = util::gets();
    let h = input[0] % 12;
    let m = input[1];
    let s = input[2];
    let t1 = min(input[3], input[4]) % 12;
    let t2 = max(input[3], input[4]) % 12;

    let mut is_inside = Vec::new();

    is_inside.push(t1 * 5 < s && s < t2 * 5);
    let m_s = m * 60 + s;
    is_inside.push(t1 * 5 * 60 < m_s && m_s < t2 * 5 * 60);
    is_inside.push(t1 <= h && h < t2);

    if is_inside.iter().all(|&b| b) || is_inside.iter().all(|&b| !b) {
        println!("YES");
    } else {
        println!("NO");
    }

}


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

    let half = word.len() / 2;
    if word.chars().filter(|c| c.is_uppercase()).count() > half {
        word = word.chars().map(|c| c.to_ascii_uppercase()).collect();
    } else {
        word = word.chars().map(|c| c.to_ascii_lowercase()).collect();
    }

    println!("{:?}", word);
}


use std::cmp::*;
use std::collections::*;
use std::io::*;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

#[derive(PartialEq, Eq, Hash, Clone, Copy)]
struct Tile {
    num: usize,
    suit: char,
}
impl CpIn for Tile {
    fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
        let s = r.read_word_str();
        let num: usize = s[..1].parse().unwrap();
        Tile {
            num: num - 1,
            suit: s[1..].parse().unwrap(),
        }
    }
}

pub fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let (t0, t1, t2) = i.read();
    writeln!(o, "{}", solve([t0, t1, t2])).unwrap();
}
fn solve(ts: [Tile; 3]) -> usize {
    let mut m = HashMap::new();
    for &t in &ts {
        *m.entry(t).or_insert(0) += 1;
    }
    let mut ans = 3 - *m.values().max().unwrap();

    for &suit in &['m', 'p', 's'] {
        let mut es = [false; 9];
        for &t in &ts {
            if t.suit == suit {
                es[t.num] = true;
            }
        }
        for i in 0..9 - 3 {
            let mut c = 0;
            for j in 0..3 {
                if es[i + j] {
                    c += 1;
                }
            }
            ans = min(ans, 3 - c);
        }
    }
    ans
}

pub mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        b: Vec<u8>,
    }
    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                b: Vec::new(),
            }
        }
        pub fn read_word(&mut self) -> &[u8] {
            self.b.clear();
            let mut consume = 0;
            loop {
                self.r.consume(consume);
                let b = self.r.fill_buf().unwrap();
                assert!(b.len() != 0);
                if let Some(p) = b.iter().position(|&x| x.is_ascii_whitespace()) {
                    self.b.extend_from_slice(&b[..p]);
                    consume = p + 1;
                    break;
                }
                self.b.extend_from_slice(b);
                consume = b.len();
            }
            self.r.consume(consume);
            consume_ws(&mut self.r);
            &self.b
        }
        pub fn read_word_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_word()) }
        }

        pub fn read_line(&mut self) -> &[u8] {
            self.b.clear();
            self.r.read_until(b'\n', &mut self.b).unwrap();
            let end = self
                .b
                .iter()
                .rposition(|x| !x.is_ascii_whitespace())
                .map(|idx| idx + 1)
                .unwrap_or(0);
            &self.b[..end]
        }
        pub fn read_line_str(&mut self) -> &str {
            unsafe { std::str::from_utf8_unchecked(self.read_line()) }
        }

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

        pub fn read_vec<T: CpIn>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
        pub fn read_iter<'a, T: CpIn>(&'a mut self, n: usize) -> CpIter<'a, R, T> {
            CpIter {
                r: self,
                n: n,
                _pd: Default::default(),
            }
        }
    }
    pub struct CpIter<'a, R: BufRead + 'a, T> {
        r: &'a mut CpReader<R>,
        n: usize,
        _pd: std::marker::PhantomData<fn() -> T>,
    }
    impl<'a, R: BufRead, T: CpIn> Iterator for CpIter<'a, R, T> {
        type Item = T;
        fn next(&mut self) -> Option<T> {
            if self.n == 0 {
                None
            } else {
                self.n -= 1;
                Some(self.r.read())
            }
        }
    }

    pub trait CpIn {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self;
    }

    impl CpIn for u64 {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_u64_fast(&mut r.r)
        }
    }
    impl CpIn for i64 {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            read_i64_fast(&mut r.r)
        }
    }
    impl CpIn for char {
        fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
            let b = r.r.fill_buf().unwrap()[0] as char;
            r.r.consume(1);
            let s = r.r.fill_buf().unwrap()[0];
            assert!(s == b' ' || s == b'\n');
            r.r.consume(1);
            b
        }
    }

    macro_rules! cpin_tuple {
        ($($t:ident),*) => {
            impl<$($t: CpIn),*> CpIn for ($($t),*) {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    ($($t::read_from(r)),*)
                }
            }
        };
    }

    macro_rules! cpin_cast {
        ($t_self:ty, $t_read:ty) => {
            impl CpIn for $t_self {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    <$t_read>::read_from(r) as $t_self
                }
            }
        };
    }
    macro_rules! cpin_parse {
        ($t:ty) => {
            impl CpIn for $t {
                fn read_from<R: BufRead>(r: &mut CpReader<R>) -> Self {
                    r.read_word_str().parse().unwrap()
                }
            }
        };
    }
    cpin_cast!(usize, u64);
    cpin_cast!(u32, u64);
    cpin_cast!(u16, u64);
    cpin_cast!(i32, i64);
    cpin_cast!(i16, i64);
    cpin_cast!(i8, i64);

    cpin_parse!(f64);

    cpin_tuple!(T1, T2);
    cpin_tuple!(T1, T2, T3);
    cpin_tuple!(T1, T2, T3, T4);
    cpin_tuple!(T1, T2, T3, T4, T5);

    fn read_u64_fast<R: BufRead>(r: &mut R) -> u64 {
        let mut value = 0;
        loop {
            let mut idx = 0;
            let buf_len;
            {
                let buf = r.fill_buf().unwrap();
                buf_len = buf.len();
                assert!(buf_len != 0);
                while idx < buf_len && b'0' <= buf[idx] && buf[idx] <= b'9' {
                    value = value * 10 + (buf[idx] - b'0') as u64;
                    idx += 1;
                }
            }
            if idx < buf_len {
                r.consume(idx);
                consume_ws(r);
                return value;
            }
            r.consume(idx);
        }
    }
    fn read_i64_fast<R: BufRead>(r: &mut R) -> i64 {
        let (consume, sign) = match r.fill_buf().unwrap()[0] {
            b'+' => (true, 1),
            b'-' => (true, -1),
            _ => (false, 1),
        };
        if consume {
            r.consume(1);
        }
        read_u64_fast(r) as i64 * sign
    }
    fn consume_ws<R: BufRead>(r: &mut R) {
        let mut c = 0;
        loop {
            r.consume(c);
            let b = r.fill_buf().unwrap();
            if b.len() == 0 {
                return;
            }
            if let Some(p) = b.iter().position(|&x| !x.is_ascii_whitespace()) {
                c = p;
                break;
            }
            c = b.len();
        }
        r.consume(c);
    }

}


fn read_string() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("Failed");
    input
}

fn main(){

    let mut x = read_string();
    x = x.replace("\r", "");
    let vec: Vec<&str> = x.split("").collect();
    let mut found: bool =  false;
    println!("{:?}", vec);
    for n in 2..(vec.len()-3){
        println!("{}", vec[n]);
        if ((vec[n] != ".") && (vec[n+1] != ".") && (vec[n-1] != ".")) &&
            ((vec[n] != vec[n+1]) && (vec[n-1] != vec[n+1]) && (vec[n] != vec[n-1]))
            {
            println!("=> {}", vec[n]);
            found = true;
            break
        }
    }
    println!("{}", if found {"YES"} else {"NO"});
}


use std::io;

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

fn main() {
    let mut result:u128 = 0;
    let (m,n,a) = parse_line!(f32,f32,f32);
    result = ((m/a).ceil() * (n/a).ceil()) as usize;
    println!("{}",result)
}


use std::io;

fn main() {
    let mut a_str = String::new();
    io::stdin().read_line(&mut a_str).expect("read error");
    let vec = a_str.split_whitespace()
        .map(|x| x.parse::<u128>().expect("parse error"))
        .collect::<Vec<u128>>();

    let m = vec[0];
    let n = vec[1];
    let a = vec[2];

    let x: u128;
    if m % a != 0 {
        x = (m / a) + 1;
    } else {
        x = m / a;
    }

    let y: u128;
    if m % a != 0 {
        y = (n / a) + 1;
    } else {
        y = n / a;
    }

    println!("{}", x*y)
}


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

fn get_integers() -> Vec<i64> {
    let mut buffer = String::new();
    stdin().read_line(&mut buffer).unwrap();
    buffer.split(' ').map(|x| x.trim().parse().unwrap()).collect()
}

fn main() {
    let inputs = get_integers();
    let n = inputs[0];
    let m = inputs[1];
    let a = inputs[2];

    println!("{}", (n + a - 1) / a * (m + a - 1) / a);
}


use std::io;
use std::iter;
use std::cmp;

fn main() {
    let (a, b): (f64, f64) = {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let delta = 1.0 + 4.0 * a;
    let n1 = (delta.sqrt() - 1.0) / 2.0;
    let n1 = n1.floor();

    let n2 = b.sqrt().floor() - 1.0;

    if n2 < n1 {
        println!("Valera");
    } else {
        println!("Vladik");
    }
}


use std::io;

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

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

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

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

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

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

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

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

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


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

fn main() {

    print!("Enter the weights of Limak and Bob: ");
    if let Err(err) = io::stdout().flush() {
        println!("Could not flush, {}", err);
    }

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

    let weights: Vec<u32> = input.split(" ")
        .map( |x| x.trim_end().parse().expect("No an integer!"))
        .collect();

    let mut limak_weight = weights[0];
    let mut bob_weight = weights[1];
    let mut years = 0;

    loop {
        if limak_weight > bob_weight { break; }
        limak_weight *= 3;
        bob_weight *= 2;
        years += 1;
    }

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


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

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

    let bears_weight: Vec<u32> = buf
        .split_ascii_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    println!("{}", (bears_weight[1] as f64 / bears_weight[0] as f64).log(1.5).ceil());
}


use std::io;

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

    let words: Vec<i64> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();

    let a = words[0];
    let b = words[1];
    let years = 0;

    loop {
        if a > b {
            println!("{}", years);
        }
        a *= 3;
        b *= 2;
    }
}


use std::io;

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

    let words: Vec<i64> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();

    let mut a = words[0];
    let mut b = words[1];
    let mut years = 0;

    loop {
        if a > b {
            println!("{}", years);
        }
        a *= 3;
        b *= 2;
    }
}


use std::io::BufRead;

fn main() {
    let i: Vec<f32> = std::io::stdin()
    .lock()
    .lines()
    .next()
    .expect("stdin not work")
    .expect("stdin not work")
    .trim()
    .split(' ')
    .map(|s| s.parse::<f32>().expect("not number"))
    .collect();
    println!("{}",
        std::cmp::max(
        ((i[1]/i[0]).log2()/(3.0/2.0 as f32).log2()).ceil() as i64,
        1
    ));
}


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

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>(s: String) -> Vec<T>
    where T: FromStr,
          <T as FromStr>::Err: std::fmt::Debug,
{
    s.split_whitespace().map(|k| k.parse().unwrap()).collect()
}

fn main() {
    let (a, b): (u32, u32) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse().unwrap());
            (
                it.next().unwrap(),
                it.next().unwrap(),
                )
    };

    let wa = |n: u32| {
        (3u32.pow(n + 1) - 1) / 2 * a
    };

    let wb = |n: u32| {
        (2u32.pow(n + 1) - 1) * b
    };

    let ans = (0..).skip_while(|&n| wa(n) <= wb(n)).nth(0).unwrap();

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


use std::io;

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

    let split_input : Vec<&str> = input.as_str().split(' ').collect();
    let mut a : i32 = split_input[0].trim().parse().expect("en");
    let mut b : i32 = split_input[1].trim().parse().expect("en");
    let mut counter = 0;
    while a <= b {
        counter += 1;
        a += 3 * a;
        b += 2 * b;
    }
    println!("{}", counter);
}


fn main() {
    let mut nums = String::new();
    std::io::stdin().read_line(&mut nums).unwrap();
    let nums = nums.split_whitespace().collect::<Vec<&str>>();
    let mut a: u8 = nums[0].parse().unwrap();
    let mut b: u8 = nums[1].parse().unwrap();
    let mut i = 1;
    loop {
        a *= 3;
        b *= 2;
        if a > b {
            println!("{}", i);
            break;
        }
        i += 1;
    }
}


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

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

    let mut a = scan.next().parse::<i32>().unwrap();
    let mut b = scan.next().parse::<i32>().unwrap();

    let mut years = 0;
    while a <= b {
        years += 1;
        a *= 3;
        b *= 2;
    }

    writeln!(out, "{}", years).ok();
}

pub struct Scanner<T> {
    reader: T,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }

    pub fn next(&mut self) -> String {
        loop {
            let mut input = String::new();
            self.reader.read_line(&mut input).unwrap();

            return input.trim().to_owned();
        }
    }
}


fn read_vec() -> Vec<u8> {
    let mut buffer: String = String::new();
    std::io::stdin().read_line(&mut buffer).expect("Error");
    buffer
        .split_whitespace()
        .map(|brother|
            brother.parse::<u8>().expect("Error"))
        .collect()
}

fn main() {
    let (mut a, mut b): (u8, u8) = {
        let brothers: Vec<u8> = read_vec();
        (brothers[0], brothers[1])
    };

    let mut years: u8 = 0;
    while a <= b {
        a *= 3;
        b *= 2;
        years += 1;
    }

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


use std::io;
fn weight(mut a: i8, mut b: i8) -> i8 {
    let mut i = 0;
    while b >= a {
        a*=3;
        b*=2;
        i += 1;
    }
    i
}

fn main() -> io::Result<()> {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer)?;
    let mut res = buffer.split_whitespace().map(|s| s.parse::<i8>().unwrap());
    println!("{}", weight(res.next().unwrap(), res.next().unwrap()));
    Ok(())
}


#![allow(unused_imports)]

use std::cmp::{max, min};
use std::collections::{HashMap, HashSet};
use std::io::{stdin, stdout, BufWriter, Write};

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

fn solve () {
    let mut scan = Scanner::default();
    let a: u8 = scan.next();
    let b: u8 = scan.next();
    let mut p3 = 1;
    let mut p2 = 1;
    for x in 1.. {
        p3 *= 3;
        p2 *= 2;
        if a*p3 > b*p2 {
            println! ("{}", x);
            return
        }
    }
}

fn main() {
    let mut scan = Scanner::default();
    // let t = scan.next::<u64>();
    let t = 1;
    for _ in 0..t {
        solve();
    }
}


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

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

fn main() {
    let mut input = WordReader::from_stdin();
    let n = (input.i() - 1) as usize;
    let m = input.i();
    let mut a = Vec::with_capacity(m);
    for _ in 0..m {
        a.push(input.i());
    }
    a.sort();
    let mut sol = 1000;
    for i in n..m {
        sol = std::cmp::min(sol, a[i] - a[i - n]);
    }
    println!("{}", sol);
}


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

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

    let first = iterator.next().unwrap().unwrap();
    let second = iterator.next().unwrap().unwrap();

    let nm: Vec<usize> = first
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();

    let mut sizes: Vec<i32> = second
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();

    sizes.sort();
    let min = sizes[nm[0]-1] - sizes[0];
    println!("{}", min);
}


use std::io;

macro_rules! rt {
  ( $( $type:ty ),+ ) => ({
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut iter = s.split_whitespace();
    (
      $(
      iter.next().unwrap().parse::<$type>().unwrap(),
      )+
    )
  })
}

macro_rules! rv {
  ( $type:ty ) => ({
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let v: Vec<$type> = s.split_whitespace().map(|x|
    x.parse::<$type>().unwrap()).collect();
    v
  })
}

fn main() {
  let (n, m) = rt!(usize, usize);
  let mut v = rv!(usize);

  v.sort();

  let mut d = v[n-1] - v[0];
  for i in 1..m-n {
    let diff = v[i+n-1] - v[i];
    if diff < d {
      d = diff;
    }
  }

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


use std::collections::HashSet;
use std::io::*;

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

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

    let infos: Vec<u32> = reads(sin);
    let mut pieces: Vec<u32> = reads(sin);

    let children: usize = infos[0] as usize;
    let mut min_diff = 1000;

    pieces.sort();

    for i in 0..pieces.len() - children {
        let diff = pieces[i + children - 1] - pieces[i];
        if diff < min_diff {
            min_diff = diff;
        }
    }

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


use std::io;

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

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

    let n : Vec<_> = input.trim().split_ascii_whitespace()
        .map(|num| {
            num.parse::<usize>()
                .expect("Parsing error")
        }).collect();

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

    let mut v : Vec<i32> = input.trim().split_ascii_whitespace()
        .map(|num| {
            num.parse::<i32>()
                .expect("Parsing error")
        }).collect();

    v.sort();

    println!("{}",  v[n[1] - 1] - v[n[1] - 1 - n[0]]);
}


use std::io;

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

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

    let n : Vec<_> = input.trim().split_ascii_whitespace()
        .map(|num| {
            num.parse::<usize>()
                .expect("Parsing error")
        }).collect();

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

    let mut v : Vec<_> = input.trim().split_ascii_whitespace()
        .map(|num| {
            num.parse::<i32>()
                .expect("Parsing error")
        }).collect();

    v.sort();
    let mut best = v[n[1] - 1] - v[0];
    for i in 0 .. n[1] - n[0]{
        best = if v[i + n[0] -1] - v[i] < best { v[i + n[0] -1] - v[i] } else { best};
    }

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


use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut arr : Vec<i32> = s.split_whitespace().map(|s| s.parse().unwrap()).collect();
    let (n, m) = (arr[0], arr[1]);
    s.clear();
    io::stdin().read_line(&mut s).unwrap();
    arr = s.split_whitespace().map(|s| s.parse().unwrap()).collect();
    arr.sort();
    let mut ans = -1;
    for i in 0..m-n {
        let tmp = arr[(i+n-1) as usize] - arr[i as usize];
        if ans == -1 || tmp < ans {
            ans = tmp;
        }
    }
    println!("{}", ans);
}


use std::str::FromStr;

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

fn read_vec<T: FromStr>(split_char: char) -> Vec<T> {
    read_str()
        .split(split_char)
        .map(|value| value.parse::<T>().ok().expect("Error"))
        .collect()
}

fn main() {
    let students: usize = read_vec(' ')[0];
    let mut pieces: Vec<u16> = read_vec(' ');
    pieces.sort();
    let mut difference: u16 = u16::max_value();

    let mut index: usize = 0;
    let end: usize = pieces.len() - students;
    loop {
        difference = std::cmp::min(difference, pieces[index + students - 1] - pieces[index]);
        index += 1;
        if index >= end { break; }
    }
    print!("{}", difference);
}


std::str::FromStr;

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

fn read_vec<T: FromStr>(split_char: char) -> Vec<T> {
    read_str()
        .split(split_char)
        .map(|value| value.parse::<T>().ok().expect("Error"))
        .collect()
}

fn main() {
    let students: usize = read_vec(' ')[0];
    let mut pieces: Vec<u16> = read_vec(' ');
    pieces.sort();
    let mut difference: u16 = u16::max_value();

    let mut index: usize = 0;
    let end: usize = pieces.len() - students;
    loop {
        difference = std::cmp::min(difference, pieces[index + students - 1] - pieces[index]);
        index += 1;
        if index > end { break; }
    }
    print!("{}", difference);
}


// use rand::Rng;

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

fn trim_newline(s: &mut String) {
    if s.ends_with('\n') {
        s.pop();
        if s.ends_with('\r') {
            s.pop();
        }
    }
}
macro_rules! parse_input {
    ($t:ident) => {{
        let mut input_line = String::new();
        io::stdin().read_line(&mut input_line).unwrap();
        trim_newline(&mut input_line);
        input_line.parse::<$t>().unwrap()
    }};
}

macro_rules! split_input {
    ($t:ident) => {{
        parse_input!(String)
            .split(" ")
            .map(|z| z.parse::<$t>().unwrap())
            .collect::<Vec<$t>>()
    }};
}

struct xorrand {
    state: u64,
}
#[allow(dead_code)]
impl xorrand {
    fn rand(&mut self) -> u64 {
        let mut x = self.state;
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
        self.state = x;
        self.state.wrapping_mul(0x2545F4914F6CDD1Du64)
    }

    fn randint(&mut self, start: u64, end: u64) -> u64 {
        return (self.rand() % (end - start)) + start;
    }

    fn randfloat(&mut self) -> f64 {
        1.0 / (self.rand() as f64)
    }

    fn new(seed: u64) -> xorrand {
        xorrand { state: seed }
    }

    fn newtime() -> xorrand {
        let start = std::time::SystemTime::now();
        let ms = start
            .duration_since(std::time::UNIX_EPOCH)
            .unwrap()
            .as_secs();
        xorrand { state: ms }
    }

    fn shuffle<T: Clone>(&mut self, tgt: &mut Vec<T>) {
        for i in 0..tgt.len() - 1 {
            let j = self.randint(i as u64, tgt.len() as u64) as usize;
            let c = tgt[j].clone();
            tgt[j] = tgt[i].clone();
            tgt[i] = c;
        }
    }
}

fn main() {
    let s1 = split_input!(usize);
    let mut s2 = split_input!(usize);
    s2.sort();
    let mut best = 10000;
    for i in 0..s2.len() - s1[0] {
        let v = s2[i + s1[0] - 1] - s2[i];
        best = std::cmp::min(v, best);
    }
    println!("{}", best);
}


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

/// iterator that returns `(w, h)` for rectangles of provided area
struct Rects {
    area: u64,
    w: u64,
    q: u64,
}

impl Rects {
    pub fn new(area: u64) -> Rects {
        Rects { area, w: 0, q: sqrti(area) }
    }
}

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

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

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

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


use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let rin = buf.split_whitespace().map(|c| c.parse::<u64>().unwrap()).collect::<Vec<_>>();
    let n = rin[0] + rin[1];
    let m: u64;

    let ret1 = factors(n, None);
    let x = ret1.last().unwrap();
    let ret3 = factors(rin[0], Some(*x));
    let ret4 = factors(rin[1], Some(*x));
//    println!("{:?} {:?}", ret3, ret4);

    let ret2 = if ret3.last().unwrap() > ret4.last().unwrap() {
        m = rin[0];
        ret3
    } else {
        m = rin[1];
        ret4
    };
//    println!("{:?}", ret1);
//    println!("{:?}", ret2);
    let mut p: u64 = 0;
    'find: for i in ret1.iter().rev() {
        let x1 = i;
        let y1 = n / x1;
        for j in ret2.iter().rev() {
            let x2 = j;
            let y2 = m / x2;
//            println!("{} {}, {} {}", x1, y1, x2, y2);
            if x2 <= x1 && y2 <= y1 {
                p = (x1 + y1) * 2;
                break 'find;
            }
        }
    }
    println!("{}", p);
}

fn factors(n: u64, max: Option<u64>) -> Vec<u64> {
    let sqrt = (n as f64).sqrt() as u64;
    let mut ret = Vec::<u64>::new();
    for i in 1..=sqrt {
        match max {
            Some(x) if i > x => {
//                println!("{}, {}", i, x);
                break;
            }
            _ => {}
        }
        if n % i == 0 {
            ret.push(i);
        }
    }
//    let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::<Vec<_>>();
    return ret;
}


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

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

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

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

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

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

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

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

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

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

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

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

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


use std::io::stdin;

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

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

    let ejemaximo = std::cmp::max(line[0], line[1]);

    println!(
        "{}",
        if ejemaximo % 2 == 0 {
            "Malvika"
        } else {
            "Akshat"
        }
    );
}


use std::io;

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

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

    let v: Vec<i32> = input.trim().split_ascii_whitespace()
        .map(|number| {
            number.parse().unwrap()
        }).collect();

    v
}

fn main(){

    let m = read_line();

    if((m[0] + m[1]) / 2) % 2 == 0 {
        println!("Malvika");
    } else {
        println!("Akshat");
    }
}


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

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

fn main() {
    let s = load();
    let (a,b)=(s[0],s[1]);
    println!("{}", (if a*b%2==0 {"Malvika"}else{"Akshat"}));
}
// min, max
// HashSet, insert, contains
// Vec, len, sort


use std::io;

fn main() -> std::io::Result<()> {
    let stdin = io::stdin();
    let mut matrix = Vec::new();
    let mut input = String::new();
    for _ in 0..5 {
        stdin.read_line(&mut input)?;
        matrix.push(
            input.split_ascii_whitespace()
                .map(|x| x.parse::<i8>().unwrap())
                .collect::<Vec<i8>>()
        );
        input.clear();
    }
    print!("{}", beautiful_matrix(matrix));
    Ok(())
}
fn beautiful_matrix(matrix: Vec<Vec<i8>>) -> i8 {
    let mut distance: i8 = 0;
    let mut count: i8 = 0;
    for v in matrix {
        count += 1;
        distance += {
            (2 - v.iter()
                .position(|&x| x == 1)
                .unwrap_or(0) as i8)
                .abs()
        };
        if distance != 0 {
            distance += {
                (2 - count).abs()
            };
            break;
        }
    }distance
}
#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test() {
        assert_eq!(beautiful_matrix(vec!(
            vec!(0, 0, 0, 0, 0),
            vec!(0, 0, 0, 0, 1),
            vec!(0, 0, 0, 0, 0),
            vec!(0, 0, 0, 0, 0),
            vec!(0, 0, 0, 0, 0))), 3);
    }
}


fn readln() -> Vec<i32> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();

    line.split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect()
}

fn main() {
    for i in 0..5 {
        let line = readln();
        for j in 0..5 {
            if line[j] == 1 {
                println!("{}", (2 - i).abs() + (2 - j).abs());
            }
        }
    }
}


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

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


#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

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

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

fn prime_factorization(mut n: u64) -> Vec<(u64, u64)> {
    let mut i = 2;
    let mut ans = vec![];
    while i*i <= n {
        let mut cnt = 0;
        while n%i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            ans.push((i, cnt));
        }
        i += 1;
    }
    if n > 1 {
        ans.push((n, 1));
    }
    ans
}

fn fact_num(n: u64, v: u64) -> u64 {
    if n < v {
        return 0;
    }
    let div = n/v;
    div + fact_num(div, v)
}

fn main() {
    input!{
      n: u64,
      b: u64,
    }
    let facts = prime_factorization(b);
    let mut ans: u64 = 1 << 32;
    for i in 0..facts.len() {
        let (v, pow) = facts[i];
        let fnum = fact_num(n, v);
        ans = min(ans, fnum/pow);
    }
    println!("{}", ans);
}


use std::io;
use std::cmp::min;

fn main() {
    let tmp = readline_ints();
    let n = tmp[0];
    let b = tmp[1];

    let fs = factor(b);
    let mut ans = std::i64::MAX;

    // println!("{:?}", fs);

    for &(p, cnt) in fs.iter() {
        //println!("{}", count(n, p) / cnt);
        ans = min(count(n, p) / cnt, ans);
    }

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

fn factor(mut n: i64) -> Vec<(i64, i64)> {
    let mut fs: Vec<(i64, i64)> = Vec::new();
    for i in 2..((n as f64).sqrt().ceil() as i64 + 1) {
        let mut cnt = 0i64;
        while n % i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            fs.push((i as i64, cnt));
        }
    }
    if n > 1 {
        fs.push((n, 1));
    }
    fs
}

fn count(n: i64, p: i64) -> i64 {
    let mut c = 0i64;
    let mut b = p;
    while n >= b {
        c += n / b;
        //println!("n = {}, b = {}, n/b = {}", n, b, n/b);
        b *= p;
    }
    c
}

fn readline_ints() -> Vec<i64> {
    let mut strs = String::new();
    let _ = io::stdin().read_line(&mut strs);
    strs.split_whitespace().map(|s| s.parse::<i64>().unwrap()).collect()
}


use std::io;
use std::cmp::min;

fn main() {
    let tmp = readline_ints();
    let n = tmp[0];
    let b = tmp[1];

    let fs = factor(b);
    let mut ans = std::i64::MAX;

    for &(p, cnt) in fs.iter() {
        ans = min(count(n, p) / cnt, ans);
    }

    println!("{}", ans);
    //println!("{:?}", fs);
}

fn factor(mut n: i64) -> Vec<(i64, i64)> {
    let mut fs: Vec<(i64, i64)> = Vec::new();
    for i in 2..((n as f64).sqrt().ceil() as i64 + 1) {
        let mut cnt = 0i64;
        while n % i == 0 {
            n /= i;
            cnt += 1;
        }
        if cnt > 0 {
            fs.push((i as i64, cnt));
        }
    }
    if n > 1 {
        fs.push((n, 1));
    }
    fs
}

fn count(n: i64, mut p: i64) -> i64 {
    let mut c = 0i64;
    while n >= p {
        c += n / p;
        p = p * p;
        // println!("n = {}, p = {}", n, p);
    }
    c
}

fn readline_ints() -> Vec<i64> {
    let mut strs = String::new();
    let _ = io::stdin().read_line(&mut strs);
    strs.split_whitespace().map(|s| s.parse::<i64>().unwrap()).collect()
}


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

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

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

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

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

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

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

impl<T: Iterator> IteratorExt for T {}

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

pub fn main() {
    let n = read!(i64);
    let k = read!(i64);
    let A = read!(i64);
    let B = read!(i64);

    let mut x = n;
    let mut s = 0;
    while n > 1 {
        if x < k {
            s += (x - 1) * A;
            break;
        }

        let r = x % k;
        if r != 0 {
            x -= r;
            s += r * A;
            continue;
        }

        let q = x / k;
        s += min((x - q) * A, B);
        x = q;
    }

    println!("{}", s);
    return;
}


use std::io;

fn main() {
    let n = getint();
    let k = getint();
    let a = getint();
    let b = getint();

    println!("{}",find_min_cost(n,k,a,b,0));
}

fn getint() -> i64 {
    let mut inpstr = String::new();
    io::stdin().read_line(&mut inpstr).expect("Could not read integer");
    let number = inpstr.trim().parse::<i64>();

    number.unwrap()

}

fn find_min_cost(n : i64, k: i64, a : i64, b : i64, acc: i64) ->  i64 {
    if n == 1 {
        return acc;
    }

    let rem = n%k;

    if rem != 0 {
        return find_min_cost(n - rem, k, a, b, acc+ a*rem);
    }

    let quo = n/k;

    if quo*a + b < n*a {
        return find_min_cost(quo, k, a, b, acc+ b);
    }

    (n-1)*a
}


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

    let mut it = input.split_whitespace();

    let n: u64 = it.next().unwrap().parse().unwrap();
    let k: u64 = it.next().unwrap().parse().unwrap();
    let a: u64 = it.next().unwrap().parse().unwrap();
    let b: u64 = it.next().unwrap().parse().unwrap();

    let mut x = n;

    let mut ans = 0;

    loop {
        let rem = x % k;
        if rem > 0 {
            x -= rem;
            ans += rem * a;
        } else {
            let q = x / k;
            let y = std::cmp::min((k - 1) * q * a, b);

            ans += y;
            x = q;
        }
        if x == 1 {
            println!("{}", ans);
            break;
        } else if x == 0 {
            println!("{}", ans - a);
            break;
        }
    }
}