use std::io;

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

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

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

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

    input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let n: isize = 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 = 0;
    let mut cards_left = n;
    if (a1 * k1) < (a2 * k2) {
        cards_left -= a1 * k1;
        maximum += if cards_left >= 0 { a1 } else { n / k1 } + (cards_left / k2);
    } else {
        cards_left -= a2 * k2;
        println!("{}", cards_left);
        maximum += if cards_left >= 0 { a2 } else { n / k2 } + (cards_left / k1);
    }

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


use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

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

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

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

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

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

    let a: i32 = scan.token();
    let b: i32 = scan.token();
    let c: i32 = scan.token();
    let d: i32 = scan.token();

    if a == 0 && (c > 0 || d > 0) {
        writeln!(out, "0")?;
        return Ok(());
    }

    writeln!(out, "{}", match a == d {
        true => 1,
        false => 0,
    })?;

    Ok(())
}


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

	std::io::stdin().read_line(&mut line)
	.expect("Reading n error!");

	let mut iter = line.split_whitespace();

	let n:usize = iter.next().expect("").parse()
	.expect("Error while parsing!");

	let m:usize = iter.next().expect("").parse()
	.expect("Error while parsing!");

	let d:i64 = iter.next().expect("").parse()
	.expect("Error while parsing!");

	let mut v1 = Vec::new();
	let mut v2 = Vec::new();

	for i in 0..n {
	    let mut line = String::new();
	    std::io::stdin().read_line(&mut line).expect("");
	    let mut iter = line.split_whitespace();

	    let c:i64 = iter.next().expect("").parse().expect("");
	    let w:i64 = iter.next().expect("").parse().expect("");

	    v1.push((c, -w));
	}

	for i in 0..m {
	    let mut line = String::new();
	    std::io::stdin().read_line(&mut line).expect("");
	    let mut iter = line.split_whitespace();

	    let c:i64 = iter.next().expect("").parse().expect("");
	    let w:i64 = iter.next().expect("").parse().expect("");

	    v2.push((c, -w));
	}

	v1.sort();
	v2.sort();

	if v1[n - 1].0 + v2[m - 1].0 > d
	{
	    println!("0");
	    return;
	}

	for i in 0..n {
	    v1[i].1 = -v1[i].1;
	}

	for i in 0..m {
	    v2[i].1 = -v2[i].1;
	}

	for i in 1..n {
	    v1[n - i - 1].0 += v1[n - i].0;
	    v1[n - i - 1].1 += v1[n - i].1;
	}

	for i in 1..m {
	    v2[m - i - 1].0 += v2[m - i].0;
	    v2[m - i - 1].1 += v2[m - i].1;
	}

	let mut ans:i64 = 0 as i64;

	for i in v1 {
	    let mut lo:usize = 1;
	    let mut hi:usize = m;
	    while lo <= hi
	    {
	        let mid = (lo + hi) / 2;
	        if i.1 + v2[mid - 1].1 > d
	        {
	            lo = mid + 1;
	        }
	        else
	        {
	            ans = std::cmp::max(ans, i.0 + v2[mid - 1].0);
	            hi = mid - 1;
	        }
	    }
	}

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


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

fn main() {
    let a = split_input!(usize);
    let l = a[1] - a[0] + 1;
    if l < 3 || l == 3 && a[1] & 1 > 0 {
        println!("-1");
    } else {
        let mut s = a[0];
        if s & 1 == 1 {
            s += 1;
        }
        println!("{} {} {}", s, s + 1, s + 2);
    }
}


#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

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

impl Scanner {

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

   fn process(&mut self) -> String {
      if self.buffer.len() == 0 {
         let mut input = String::new();
         std::io::stdin().read_line(&mut input).ok();
         for word in input.split_whitespace() {
            self.buffer.push_back(word.to_string())
         }
      }

      self.buffer.pop_front().unwrap()
   }

   fn next<T : std::str::FromStr >(&mut self) -> T {
      self.process().parse::<T>().ok().unwrap()
   }

   #[allow(dead_code)]
   fn next_char(&mut self) -> char {
      self.process().into_bytes()[0] as char
   }
}

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

   let n = sin.next();

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

   for _ in 0..n {
      let a = sin.next();
      array.push(a);
   }

   let num_non_zeros = array.iter()
      .fold(0, |acc, &x| acc + if x != 0 {1} else {0});

   let mut answers : Vec<(usize, usize)> = Vec::new();

   if num_non_zeros == 0 {
      println!("NO");
   } else if num_non_zeros == 1 {
      println!("YES");
      println!("1");
      println!("{} {}", 1, array.len());
   } else {
      println!("YES");

      let mut left = 0;
      let mut right = 0;
      let mut limit = array.len();

      for i in (0..n).rev() {
         if array[i] != 0 {
            limit = i;
            break;
         }
      }

      for _ in 0..limit {
         if array[right] == 0 {
            right += 1;
         } else {
            answers.push((left + 1, right + 1));
            left = right + 1;
            right += 1;
         }
      }

      answers.push((left + 1, array.len()));

      println!("{}", answers.len());
      for t in answers {
         println!("{} {}", t.0, t.1);
      }
   }
}


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

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

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

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

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

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

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

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

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

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

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

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

    const MOD: u64 = 998244353;

    input!{
      w: usize,
      h: usize,
    }

    let mut ans = 4;
    for _ in 0..w-1 {
        ans *= 2;
        ans %= MOD;
    }
    for _ in 0..h-1 {
        ans *= 2;
        ans %= MOD;
    }
    puts!("{}\n", ans);
}


#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

struct ContestPrinter {
    s: String,
}

impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter {
        s: String::new(),
        }
    }

    fn print<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}", x).as_str());
    }

    fn println<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}

impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}

fn main() {
    let mut printer = ContestPrinter::new();

    let s = readl!(String);
    let cs: Vec<char> = s.chars().collect();

    let mut next: u8 = 0; // a
    let mut done = [false; 26];
    let mut out = String::new();
    for c in cs {
        let num = c as u8 - 'a' as u8;
        if next >= num {
            done[next as usize] = true;
            next += 1;
            out.push(('a' as u8 + next - 1 + if ((next - 1 - num) == 0) { 0 } else {next - 2 - num})  as char);
        } else {
            out.push(c);
        }
        if next >= 26 { break; }
    }
    let mut okay = true;
    for d in done.iter() { if !d { okay = false; } }
    if okay { printer.println(out); }
    else { printer.println(-1); }
}


fn read_ints() -> Vec<i64> {
    let mut ln = String::new();
    std::io::stdin().read_line(&mut ln).expect("");
    ln.split_whitespace().filter_map(|w| w.parse().ok()).collect()
}

const MODULUS: i64 = 1000000007;
const NEG_INV2: i64 = (MODULUS - 1) / 2;

fn qpow(mut base: i64, mut exp: i64) -> i64 {
    let mut ans = 1i64;
    while exp > 0 {
        if exp % 2 == 1 { ans = (ans * base) % MODULUS; }
        base = (base * base) % MODULUS;
        exp >>= 1;
    }
    ans
}

fn main() {
    let (x, k);
    if let [_x, _k] = read_ints()[..] { x = _x; k = _k; } else { panic!("> <"); }

    if x == 0 {
        println!(0);
    } else {
        println!("{}", ((x + NEG_INV2) * qpow(2, k + 1) + 1) % MODULUS);
    }
}


use std::io;

fn read_line() -> String {
    let mut input_line = String::new();
    io::stdin().read_line(&mut input_line).unwrap();
    return String::from(input_line.trim());
}

fn digits(mut n: u64) -> u64 {
    let mut count = 0u64;
    while n > 0 {
        count += 1;
        n /= 10;
    }
    return count;
}

fn main() {
    let n: u64 = read_line().parse().unwrap();

    let d = digits(n);
    let mut nums_counted = 0u64;
    let mut nines = 9u64;
    let mut res = 0u64;
    for i in 1 .. d {
        let cur_len = nines - nums_counted;
        nines = nines * 10 + 9;
        res += cur_len * i;
        nums_counted += cur_len;
    }

    let cur_len = n - nums_counted;
    res += cur_len * d;

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


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

    let mut it = input.split_whitespace().map(|x| {
        x.parse::<u32>().unwrap()
    });

    let (mut a, b, c) = (
        it.next().unwrap(),
        it.next().unwrap(),
        it.next().unwrap(),
        );

    let mut ans = -1;
    let mut cnt = 0;

    for _ in 0..b + 10 {
        cnt += 1;
        a *= 10;
        let q = a / b;
        if q == c {
            ans = cnt;
            break;
        }
        a -= q * b;
    }

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


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

enum Direction {
    South,
    East,
    North,
    West,
}

#[derive(Debug, Clone)]
struct DirectionError;

impl FromStr for Direction {
    type Err = DirectionError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "South" => Ok(Direction::South),
            "East" => Ok(Direction::East),
            "North" => Ok(Direction::North),
            "West" => Ok(Direction::West),
            _ => Err(DirectionError),
        }
    }
}

impl fmt::Display for Direction {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Direction::South => write!(f, "South"),
            Direction::East => write!(f, "East"),
            Direction::North => write!(f, "North"),
            Direction::West => write!(f, "West"),
        }
    }
}

struct Step {
    t: i32,
    dir: Direction,
}
#[derive(Debug, Clone)]
struct StepError;

impl FromStr for Step {
    type Err = StepError;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let mut lines = s.trim().split_whitespace();
        let t = match lines.next() {
            Some(s_t) => match s_t.parse::<i32>() {
                Ok(n_t) => Ok(n_t),
                Err(_) => Err(StepError),
            },
            None => Err(StepError),
        }?;
        let dir = match lines.next() {
            Some(s_dir) => match s_dir.parse::<Direction>() {
                Ok(n_dir) => Ok(n_dir),
                Err(_) => Err(StepError),
            },
            None => Err(StepError),
        }?;
        Ok(Step { t, dir })
    }
}

impl fmt::Display for Step {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{} {}", self.t, self.dir)
    }
}

fn main() {
    let stdin = io::stdin();

    let mut lines = stdin.lock().lines();
    let n = lines
        .next()
        .unwrap()
        .unwrap()
        .trim()
        .parse::<usize>()
        .unwrap();

    let a = lines
        .take(n)
        .map(|s| s.unwrap().parse::<Step>().unwrap())
        .fold(0, |sum, step| {
            match step.dir {
                Direction::South => {
                    if sum >= 40000 {
                        println!("NO");
                        std::process::exit(0);
                    }
                    return sum + step.t;
                },
                Direction::North => {
                    if sum <= 0 {
                        println!("NO");
                        std::process::exit(0);
                    }
                    return sum - step.t;
                },
                Direction::East | Direction::West => {
                    if sum == 0 || sum == 40000 {
                        println!("NO");
                        std::process::exit(0);
                    }
                    return sum;
                }
            }
        });

    if a != 0 {
        println!("NO");
    } else {
        println!("YES");
    }
}


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

    #[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 main() {
    let (n, k, x): (usize, usize, usize) = util::get3();
    let a: Vec<usize> = util::gets();

    println!("{}", a[..n - k].iter().sum::<usize>() + k * x);
}


use std::collections::HashMap;
use std::io;

fn to_pairs(line: &str) -> Vec<(i32, i32)> {
	let mut iter = line.trim().split_whitespace();
	let mut ret = Vec::new();
	while let Some(x) = iter.next() {
		ret.push((x.parse().unwrap(),
		          iter.next().unwrap().parse().unwrap()));
	}
	ret.sort();
	return ret
}

fn get_unique(s1: (i32, i32), s2: (i32, i32)) -> Option<i32> {
	let mut v = Vec::new();
	v.push(s1.0);
	v.push(s1.1);
	v.push(s2.0);
	v.push(s2.1);
	v.sort();
	v.dedup();
	if v.len() != 3 { return None; }
	for x in v {
		if (x == s1.0 || x == s1.1) && (x == s2.0 || x == s2.1) {
			return Some(x);
		}
	}
	return None;
}

fn get_only_bit(x: i32) -> Option<i32> {
	let mut count = 0;
	let mut last = 0;
	for i in 1..10 {
		if (x >> i & 1) != 0 {
			count += 1;
			last = i;
		}
	}
	if count == 1 { return Some(last); }
	return None;
}

fn solve(s1: Vec<(i32, i32)>, s2: Vec<(i32, i32)>) -> i32 {
	let mut va: HashMap<(i32, i32), i32> = HashMap::new();
	let mut vb: HashMap<(i32, i32), i32> = HashMap::new();
	let mut vab = 0;
	for a in s1.iter() {
		for b in s2.iter() {
			if let Some(x) = get_unique(*a, *b) {
				va.entry(*a)
					.and_modify(|e| { *e |= 1 << x })
					.or_insert(1 << x);
				vb.entry(*b)
					.and_modify(|e| { *e |= 1 << x })
					.or_insert(1 << x);
				vab |= 1 << x;
			}
		}
	}
	if let Some(x) = get_only_bit(vab) { return x; }
	for (_, v) in va.iter() {
		if let None = get_only_bit(*v) { return -1; }
	}
	for (_, v) in vb.iter() {
		if let None = get_only_bit(*v) { return -1; }
	}
	return 0;
}

fn main() -> io::Result<()> {
	let f = io::stdin();
	let mut line = String::new();
	f.read_line(&mut line)?;
	line.clear();
	f.read_line(&mut line)?;
	let s1 = to_pairs(&line);
	line.clear();
	f.read_line(&mut line)?;
	let s2 = to_pairs(&line);
	println!("{}", solve(s1, s2));

	Ok(())
}


use std::io;
fn main()
{
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n : i32 = n.trim().parse().unwrap();
    for i in 2..(n as f64).sqrt() as i32 + 1
    {
        if n % i == 0
        {
            println!("{}{}", i, n / i);
        }
    }
}


#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator,
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

struct ContestPrinter {
    s: String,
}

impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter {
        s: String::new(),
        }
    }

    fn print<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}", x).as_str());
    }

    fn println<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}

impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}

fn main() {
    let mut printer = ContestPrinter::new();

    let (mut L, mut R, mut A) = readl!(i32, i32, i32);
    if L > R {
        R += A;
    } else {
        L += A;
    }
    while (L - R).abs() > 1 {
        if (L == 0) | (R == 0) { break; }
        if L > R {
            L -= 1;
            R += 1;
        } else {
            R -= 1;
            L += 1;
        }
    }
    printer.println(2 * min(L, R));
}


#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(overflowing_literals)]
#![allow(unused_must_use)]

use std::collections::*;
use std::io::*;
use std::cmp::{min, max};
use std::f64::consts::*;
use std::mem::swap;
use std::fs::File;
use std::rc::*;
use std::ascii::*;
use std::ops::*;

const INF: i32 = std::i32::MAX;
const LINF: i64 = std::i64::MAX;
const MOD: usize = 1000000007;

#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]
struct Pair<A: Eq + Ord + Copy + Clone, B: Eq + Ord + Copy + Clone>(A, B);

struct Input<Buf: BufRead>
{
	buffer: Buf
}

impl<Buf: BufRead> Input<Buf>
{
	fn read_line(&mut self) -> String {
		let mut v = Vec::new();
		let mut x = [255u8];
		self.buffer.read(&mut x).expect("EOF");
		while x[0] < b' ' && x[0] != 255u8 {
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		while x[0] >= b' ' && x[0] != 255u8 {
			v.push(x[0]);
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		String::from_utf8(v).unwrap()
	}

	fn read_word(&mut self) -> String {
		let mut v = Vec::new();
		let mut x = [255u8];
		self.buffer.read(&mut x).expect("EOF");
		while x[0] <= b' ' && x[0] != 255u8 {
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		while x[0] > b' ' && x[0] != 255u8 {
			v.push(x[0]);
			x[0] = 255u8;
			self.buffer.read(&mut x).expect("EOF");
		}
		String::from_utf8(v).unwrap()
	}
	#[inline]
	fn read_int(&mut self) -> i32 {
		self.read_word().parse::<i32>().expect("Parsing error")
	}
	#[inline]
	fn read_long(&mut self) -> i64 {
		self.read_word().parse::<i64>().expect("Parsing error")
	}
	#[inline]
	fn read_usize(&mut self) -> usize {
		self.read_word().parse::<usize>().expect("Parsing error")
	}
	#[inline]
	fn read_double(&mut self) -> f64 {
		self.read_word().parse::<f64>().expect("Parsing error")
	}
}
macro_rules! read {
    () => {};
	($inf:ident,$($t:ty),*) => ({($({$inf.read_word().parse::<$t>().expect("Parsing error")}),*)});
}
fn gcd<T: RemAssign + Ord + From<i32> + Copy + Clone>(x: T, y: T) -> T {
	let (mut a, mut b) = (x, y);
	while b > T::from(0) {
		a %= b;
		swap(&mut a, &mut b);
	}
	a
}

fn main() {
	match std::env::var("home") {
		Ok(_x) => {
			let mut inf = Input {
				buffer: BufReader::new(File::open("input.txt").expect("File not found"))
			};
			let mut ouf = BufWriter::new(stdout());
			solve(&mut inf, &mut ouf);
		}
		Err(_e) => {
			let mut inf = Input { buffer: BufReader::new(stdin()) };
			let mut ouf = BufWriter::new(stdout());
			solve(&mut inf, &mut ouf);
		}
	}
}

fn solve<Inner: BufRead, Output: Write>(inf: &mut Input<Inner>, ouf: &mut Output)
{
	let n = read!(inf,usize);
	let mut w = vec![0usize; 2 * n];
	for i in 0..2 * n {
		w[i] = read!(inf,usize);
	}
	w.sort();
	let mut ans = MOD;
	for i in 0..3 {
		let mut pos = i;
		let mut p = 0;
		while pos < 2 * n - 2 + i {
			p += w[pos + 1] - w[pos];
			pos += 2;
		}
		ans = min(ans, p);
	}
	writeln!(ouf, "{}", ans);
}


use std::io::stdin;
fn main(){
    let mut s:String=String::new();
    stdin().read_line(&mut s).unwrap();
    s.clear();
    stdin().read_line(&mut s).unwrap();
    s.trim();
    let b="aeyuio";
    let mut c:usize=1;
    let mut p:i32=0;
    let mut l:i32=0;
    while c<s.len(){
        match s.chars().nth(c).unwrap(){
            'a'=>p=1,
            'e'=>p=1,
            'y'=>p=1,
            'u'=>p=1,
            'i'=>p=1,
            'o'=>p=1,
            _=>p=0,
        }
        match s.chars().nth(c-1).unwrap(){
            'a'=>l=1,
            'e'=>l=1,
            'y'=>l=1,
            'u'=>l=1,
            'i'=>l=1,
            'o'=>l=1,
            _=>l=0,
        }
        if p==l{
            s.remove(c);
        }
        else{c+=1;}
    }
    println!("{}",s);
}


// use std::ops::{Index, IndexMut};
use std::cmp::{Ordering, min, max};
// use std::collections::{BinaryHeap, BTreeMap};
// use std::collections::btree_map::Entry::{Occupied, Vacant};
// use std::clone::Clone;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! split {
    ($x: expr) => {
        ($x).trim().split(' ').collect()
    }
}

macro_rules! parse {
    ($x: expr) => {
        ($x).parse().unwrap()
    }
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            let mut iter = iv.into_iter();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
}

macro_rules! rvec {
    ($x: expr) => {
        ($x).into_iter().map(|x| parse!(x)).collect()
    }
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iv: Vec<_> = split!(s);
            iv.into_iter().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {}", stringify!($x), $x)
    }
}

fn printvec<T>(v: &Vec<T>) where T: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

fn main() {
    let (n, k) = readl!(usize, i64);
    let a = readlvec!(i64);

    let inf: i64 = 1e18 as i64;
    let ma = a.iter().fold(0,|acc, &x| max(acc,x));
    let bo = (ma as f64).sqrt() as i64 + 2;
    // debug!(bo);
    let mut ans = 1;
    for i in 1..bo {
        let mut sum = 0;
        for e in &a {
            sum += (i-e%i)%i;
        }
        if sum <= k {
            ans = i;
        }
    }

    let mut qu = Vec::<(i64,usize)>::new();
    qu.push((bo,0));
    for i in 0..n {
        for j in 1..bo {
            if a[i]/j != 0 && bo <= a[i]/j {
                qu.push(((a[i]+j-1)/j,i));
            }
        }
    }
    qu.sort();
    let mut qui = qu.into_iter();
    let mut b = vec![0;n];
    let mut pre = -100;
    if let Some((di,i)) = qui.next() {
        for i in 0..n {
            b[i] = (a[i]+di-1)/di;
        }
        pre = di;
    }
    let mut sb = b.iter().fold(0,|acc, &x| acc+x);
    let sa = a.iter().fold(0,|acc, &x| acc+x);
    let mut dis = 0;
    for (di, i) in qui {
        // debug!(i);
        // debug!(pre);
        // debug!(di);

        // // printvec(&mov);
        // printvec(&b);
        // debug!(sb);

        if pre*sb-sa <= k {
            let m = (k+sa-pre*sb)/sb;
            if pre+m < di {
                ans = pre+m;
            }
        }
        sb -= b[i];
        b[i] = (a[i]+di-1)/di;
        sb += b[i];
        pre = di;
    }
    // printvec(&b);
    // debug!(sb);
    // if sm <= k {
    //     ans = pre;
    // } else {
    //     let m = (k-sm)/sb;
    //     debug!(m);
    //     {
    //         ans = pre+m;
    //     }
    // }

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


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};

const DEBUG: bool = false;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn calc_dp(s: &[i8], n: usize, fib: &[u64])
           -> (Vec<u64>, Vec<Vec<u64>>, Vec<Vec<u64>>, Vec<Vec<u64>>) {
    let m = s.len();
    // s appears as a substring of A[i]
    let mut dp0 = vec![0u64; n + 1];
    // dp1[i][j]: s.substr(0, j) == A[i].substr(A[i].len() - j, j), not covered by dp0
    let mut dp1 = vec![vec![0u64; m]; n + 1];
    // dp2[i][j]: s.substr(s.len() - j, j) == A[i].substr(0, j), not covered by dp0
    let mut dp2 = vec![vec![0u64; m]; n + 1];
    // dp3[i][j]: s.substr(j, A[i].len()) == A[i], not covered by dp0, dp1, dp2
    let mut dp3 = vec![vec![0u64; m]; n + 1];
    if m == 1 {
        dp0[s[0] as usize] = 1;
    } else {
        for i in 1 .. m - 1 {
            dp3[s[i] as usize][i] = 1;
        }
        dp1[s[0] as usize][1] = 1;
        dp2[s[m - 1] as usize][1] = 1;
    }
    for i in 2 .. n + 1 {
        dp0[i] = dp0[i - 2].saturating_add(dp0[i - 1]);
        for j in 1 .. m {
            dp0[i] = dp0[i].saturating_add(dp1[i - 2][j] * dp2[i - 1][m - j]);
        }
        for j in 1 .. m {
            dp1[i][j] = dp1[i - 1][j];
            dp2[i][j] = dp2[i - 2][j];
        }
        let l_fst = fib[i - 2];
        let l_snd = fib[i - 1];
        for j in 1 .. m {
            if (j as u64).saturating_add(l_snd) < m as u64 {
                dp1[i][j + l_snd as usize] =
                    max(dp1[i][j + l_snd as usize],
                        dp1[i - 2][j] * dp3[i - 1][j]);
            }
            if (j as u64).saturating_add(l_fst) < m as u64 {
                dp2[i][j + l_fst as usize] =
                    max(dp2[i][j + l_fst as usize],
                        dp3[i - 2][m - j - l_fst as usize]
                        * dp2[i - 1][j]);
            }
            if (j as u64).saturating_add(l_fst) < m as u64 {
                dp3[i][j]
                    = max(dp3[i][j], dp3[i - 2][j] * dp3[i - 1][j + l_fst as usize]);
            }
        }
    }
    if DEBUG {
        eprintln!("dp0 = {:?}, dp1 = {:?}, dp2 = {:?}, dp3 = {:?}", dp0, dp1, dp2, dp3);
    }
    (dp0, dp1, dp2, dp3)

}

fn calc(s: &[i8], n: usize, fib: &[u64]) -> u64 {
    if s.len() == 0 {
        return fib[n];
    }
    if n == 0 {
        return if s.len() == 1 && s[0] == 0 { 1 } else { 0 };
    }
    let (dp0, _, _, _) = calc_dp(s, n, fib);
    if DEBUG {
        eprintln!("s = {:?}, dp0 = {:?}", s, dp0);
    }
    dp0[n]
}

fn terminates(s: &[i8], n: usize, fib: &[u64]) -> u64 {
    if s.len() == 0 {
        return 0;
    }
    let m = s.len();
    if n == 0 {
        return if s.len() == 1 && s[0] == 0 { 1 } else { 0 };
    }
    // dp1[i][j]: s.substr(0, j) == A[i].substr(A[i].len() - j, j)
    let mut dp1 = vec![vec![0u64; m + 1]; n + 1];
    // dp3[i][j]: s.substr(j, A[i].len()) == A[i], not covered by dp0, dp1, dp2
    let mut dp3 = vec![vec![0u64; m]; n + 1];
    if m == 1 {
        dp1[s[0] as usize][1] = 1;
    } else {
        for i in 1 .. m {
            dp3[s[i] as usize][i] = 1;
        }
        dp1[s[0] as usize][1] = 1;
    }
    for i in 2 .. n + 1 {
        for j in 1 .. m + 1 {
            dp1[i][j] = dp1[i - 1][j];
        }
        let l_fst = fib[i - 2];
        let l_snd = fib[i - 1];
        for j in 1 .. m + 1 {
            if (j as u64).saturating_add(l_snd) <= m as u64 {
                dp1[i][j + l_snd as usize] = dp1[i - 2][j] * dp3[i - 1][j];
            }
            if (j as u64).saturating_add(l_fst) < m as u64 {
                dp3[i][j]
                    = max(dp3[i][j], dp3[i - 2][j] * dp3[i - 1][j + l_fst as usize]);
            }
        }
    }
    if DEBUG {
        eprintln!("term s = {:?}, dp1 = {:?}, dp3 = {:?}", s, dp1, dp3);
    }
    dp1[n][m]
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($format:expr) => (write!(out,$format).unwrap());
        ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())
    }
    let mut fib = vec![0u64; 100];
    fib[0] = 1;
    fib[1] = 1;
    for i in 2 .. 100 {
        fib[i] = fib[i - 1].saturating_add(fib[i - 2]);
    }
    if false {
        calc(&[1, 1], 4, &fib);
        return;
    }
    input! {
        n: usize,
        k: u64,
        m: usize,
    }
    let mut fib = vec![0u64; max(n, 2) + 1];
    fib[0] = 1;
    fib[1] = 1;
    for i in 2 .. n + 1 {
        fib[i] = fib[i - 1].saturating_add(fib[i - 2]);
    }
    let mut det = Vec::new();
    let mut acc: u64 = 0;
    for _ in 0 .. m {
        let exact = terminates(&det, n, &fib);
        if acc < k && acc + exact >= k {
            break;
        }
        if DEBUG {
            eprintln!("det = {:?}, acc = {}, exact = {}", det, acc, exact);
        }
        acc += exact;
        det.push(0i8);
        let u = calc(&det, n, &fib);
        if acc.saturating_add(u) < k {
            acc += u;
            det.pop();
            det.push(1i8);
        }
    }
    for d in det {
        puts!("{}", d);
    }
    puts!("\n");
}

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


use std::io::{self, BufWriter, Write};
use std::str::{self, SplitAsciiWhitespace};

// I have no idea what I'm doing

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

    let n: usize = scan.token();
    let (l, r) = scan.pair::<i64>();

    const M: i64 = 1_000_000_007;

    let m0 = r/3 - (l-1)/3;
    let m1 = m0
             - if r%3 == 0 { 1 } else { 0 }
             + if (l-1)%3 == 0 { 1 } else { 0 };
    let m2 = m0
             - if r%3 <= 1 { 1 } else { 0 }
             + if (l-1)%3 <= 1 { 1 } else { 0 };

    dbg!(m0);
    dbg!(m1);
    dbg!(m2);

    let mut ans = [1_i64, 0, 0];
    for _ in 0..n {
        let mut nxt = [0_i64; 3];
        nxt[0] = m0 * ans[0] % M + m1 * ans[2] % M + m2 * ans[1];
        nxt[1] = m0 * ans[1] % M + m1 * ans[0] % M + m2 * ans[2];
        nxt[2] = m0 * ans[2] % M + m1 * ans[1] % M + m2 * ans[0];

        for i in 0..3 {
            ans[i] = nxt[i] % M;
        }
    }

    writeln!(out, "{}", ans[0])?;

    Ok(())
}

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

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

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

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

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


// ---------- begin chmin, chmax ----------
pub trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------
// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

use std::collections::*;

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

// アリスとボブがゲームをする
// アリスはN個の宝を持っている。
// i個目の宝には A_i 枚のコインが入っている
// またM個の鍵がある
// j個目の鍵の値段はコインB_j枚である
//
// 最初、アリスは宝のいくつかに錠をつける
// j番目の錠はj番目の鍵でのみ開くことができる
// i番目の宝にj番目の錠をつけるのにかかるコストは C_{i, j} である
//
// 錠をつけ終わった後、ボブはいくつか鍵をアリスから買って宝を開ける
// (宝から手に入ったコイン) - (鍵を買うのに使ったコイン) > 0
// を満たす時、ボブの勝ちとなる
//
// アリスはボブが勝てないように錠をつける時、最小コストを求めよ
// 不可能なら-1を出力せよ
//
// 1 <= N, M <= 6
// 1 <= A_i, B_j <= 4
// 1 <= C_{i, j} <= 10^7
//
//
// メモ
// sum b < sum a なら-1
// そうでないなら錠を全部つければとりあえずは勝てる
// 愚直解ってなんだ？
// 錠を全探索
// その後鍵の買い方を全探索
// コストを計算して利得の最大値を計算、答えの更新
// これでいい
// 計算量 O(2^(NM) * 2^(M) * N) くらい？
// 当然間に合わん
// 鍵は全探索せずともフローで解ける
// 鍵、宝でそれぞれ頂点を作る
// src -> 鍵i にb_i
// 鍵j -> 宝i に錠がついてるならinf
// 宝i -> dst にa_i
// を張ってフローを流す
// sum a_i > (流量)
// ならボブの勝ち
// これでもまだ間に合わない
//
// ボブは鍵を買わないことで常に0を達成できる
// アリスはボブの最適戦略がこれになるようにしたい
// つまりカットが常に宝->dst のところになるようにしたい
// N, M, A, B が小さいのでこれをそのままdpにする
// 宝についてループを回しつつ辺を張って流量を全部試す
// 辺を満たしたら次へ
// みたいな

fn run() {
    input! {
        n: usize,
        m: usize,
        a: [i32; n],
        b: [i32; m],
        c: [[i32; m]; n],
    }
    let mut memo = Map::new();
    memo.insert(b, 0);
    for (a, c) in a.into_iter().zip(c) {
        let mut dp = Map::new();
        for (b, v) in memo.into_iter() {
            dp.insert((a, b), v);
        }
        for (i, c) in c.into_iter().enumerate() {
            let mut next = dp.clone();
            for ((a, b), v) in dp {
                let v = v + c;
                for k in 1..=b[i].min(a) {
                    let mut b = b.clone();
                    b[i] -= k;
                    let a = a - k;
                    next.entry((a, b)).or_insert(v).chmin(v);
                }
            }
            dp = next;
        }
        memo = Map::new();
        for ((a, b), v) in dp {
            if a == 0 {
                memo.entry(b).or_insert(v).chmin(v);
            }
        }
    }
    let ans = memo.values().min().cloned().unwrap_or(-1);
    println!("{}", ans);
}

fn main() {
    run();
}


#[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, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[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 , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
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 ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) } ; }
#[allow(dead_code)]
fn main() {
    input!{
        s: chars,
        k: usize,
    }
    let mut ans = s;
    let mut candy = 0;
    let mut snow = 0;
    for &c in &ans {
        if c == '?' {
            candy += 1;
        } else if c == '*' {
            snow += 1;
        }
    }
    let length = ans.len() - (candy + snow);
    debug!(length);
    if length < k {
        if snow < k - length {
            println!("Impossible");
            return;
        }
        let mut done = false;
        let mut i = 0;
        while i < ans.len() {
            if ans[i] == '?' {
                ans.remove(i);
                i -= 1;
            } else if ans[i] == '*' {
                ans.remove(i);
                i -= 1;
                if !done {
                    for j in 0..k-length {
                        let x = ans[i-1];
                        ans.insert(i, x);
                        i += 1;
                    }
                    done = true;
                }
            }
            i += 1;
        }
    } else {
        if length - k > candy + snow {
            println!("Impossible");
            return;
        }
        let mut del = length - k;
        let mut index = 0;
        debug!(del);
        while del > 0 {
            if ans[index] == '?' || ans[index] == '*' {
                ans.remove(index-1);
                ans.remove(index-1);
                index -= 2;
                del -= 1;
            }
            index += 1;
        }
        debug!(ans);
        debug!(length);
        while index < ans.len() {
            if ans[index] == '?' || ans[index] == '*' {
                ans.remove(index);
                index -= 1;
            }
            index += 1;
        }
    }
    let str_ans: String = ans.into_iter().collect();
    println!("{}", str_ans);
}


//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

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

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[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),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

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

fn main() {
    let (_, _, r) = read!(usize, usize, i64);
    let S = read![[i64]];
    let B = read![[i64]];

    let min_s = *S.iter().min().unwrap();
    let max_b = *B.iter().max().unwrap();

    println!(
        "{}",
        if min_s >= max_b {
            r
        } else {
            (r % min_s) + (r / min_s) * max_b
        }
    )
}


fn main() {
    use std::io::prelude::*;
    use std::io;

    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();

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

    let mut max_ans = 0;

    let modulo = |a, b| {
        if a < 0 {
            a % b + b
        } else {
            a % b
        }
    };
    let modsub = |a, b| {
        modulo(a - b, 14)
    };

    for (i, &ai) in a.iter().enumerate() {
        let q = ai / 14;
        let r = ai % 14;

        let mut ans = 0;
        let mut j = i + 1;
        for _ in 0..13 {
            let cnt = a[modulo(j, 14)] + q + if r < modsub(j, i) as i64 { 0 } else { 1 };
            if cnt % 2 == 0 {
                ans += cnt;
            }

            j += 1
        }

        if q % 2 == 0 {
            ans += q;
        }

        if max_ans < ans {
            max_ans = ans;
        }
    }

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


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

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

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

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

    let r: f64 = input.p();
    let x: f64 = input.p();
    let y: f64 = input.p();
    let xx: f64 = input.p();
    let yy: f64 = input.p();
    println!("{}", (((x - xx).powi(2) + (y - yy).powi(2)).sqrt() / (2. * r)).ceil());
}


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

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

    let n = input.i();
    let is_prime_o = |a: i32| -> bool {
        if a < 3 || a % 2 == 0 {
            return false;
        }
        let sq = ((a as f64).sqrt() + 1.0e-6) as i32;
        for i in 3..=sq {
            if a % i == 0 {
                return false;
            }
        }
        return true;
    };
    let print_exit = |sol: &[i32]| -> ! {
        println!("{}", sol.len());
        for &a in sol {
            print!("{} ", a);
        }
        std::process::exit(0);
    };

    if is_prime_o(n) {
        print_exit(&[n]);
    } else {
        const X: usize = 400;
        let mut pairs = vec![None; X];
        for i in 3..X/2 {
            if is_prime_o(i as i32) {
                for j in i..X/2 {
                    if is_prime_o(j as i32) {
                        pairs[i + j] = Some((i as i32, j as i32));
                    }
                }
            }
        }
        let pairs = pairs;
        for i in 6.. {
            assert!(i < X as i32);
            if let Some((a, b)) = pairs[i as usize] {
                if i < n && is_prime_o(n - i) {
                    print_exit(&[a, b, n - i]);
                }
            }
        }
    }
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let mut n: i64 = get();
    let k: i32 = get();
    let mut cnt = 0;
    let mut kk = k;
    while kk > 0 {
        if n == 0 {
            cnt = max(cnt + k - kk - 1, 0);
            break;
        }
        if n % 10 != 0 {
            cnt += 1;
        } else {
            kk -= 1;
        }
        n /= 10;
    }
    println!("{}", cnt);
}

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


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

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let mut input = input.split_whitespace();
    macro_rules! read(
        (($($tt:tt),+)) => (($(read!($tt)),*));
        ($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());
    );

    let (s, e) = read!((String, String));
    let mut x = e.as_bytes()[0] as i64 - s.as_bytes()[0] as i64;
    let mut y = e.as_bytes()[1] as i64 - s.as_bytes()[1] as i64;
    println!("{}", x.abs().max(y.abs()));
    while x != 0 || y != 0 {
        if x < 0 {
            print!("L");
            x += 1;
        } else if x > 0 {
            print!("R");
            x -= 1;
        }
        if y < 0 {
            print!("D");
            y += 1;
        } else if y > 0 {
            print!("U");
            y -= 1;
        }
        println!();
    }
}


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

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let mut iter = s.trim().split_whitespace().map(|x| x.parse().unwrap());
    let (n, m, a, b): (u64, u64, u64, u64) = (iter.next().unwrap(), iter.next().unwrap(), iter.next().unwrap(), iter.next().unwrap());
    let demolition_cost = (n % m) * b;
    let build_cost = (m - (n % m)) * a;
    println!("{}", cmp::min(demolition_cost, build_cost));
}


use std::io::stdin;
fn main() {
    let mut text = String::new();
    stdin().read_line(&mut text).unwrap();
    let text = text.trim();
    let mut counter4: usize = 0;
    let mut counter7: usize = 0;
    for i in text.chars() {
        if '4' == i {
            counter4 += 1;
        } else if '7' == i {
            counter7 += 1;
        }
    }
    if counter4 == 0 && counter7 == 0 {
        println!("-1");
    } else if counter4 >= counter7 {
        println!("4")
    } else {
        println!("7")
    }
}

fn delete_leading_zeroes(arr: Vec<char>) -> Vec<char> {
    let mut finded = false;
    let mut last = 0;
    for i in 0..arr.len() {
        if '0' == arr[i] {
            continue;
        } else {
            last = i;
            finded = true;
            break;
        }
    }
    if finded {
        arr[last..].to_vec()
    } else {
        arr
    }
}


fn main() {
    let (r1, r2) = parse();
    let (c1, c2) = parse();
    let (d1, d2) = parse();
    let mut v1 = vec![];
    let mut v2 = vec![];

    for a in 1..10 {
        for b in 1..10 {
            if a != b && a + b == d1 {
                v1.push((a, b));
            }
            if a != b && a + b == d2 {
                v2.push((a, b))
            }
        }
    }
    for a in &v1 {
        for b in &v2 {
            if a.0 + b.0 == r1
                && a.1 + b.1 == r2
                && a.0 != b.0
                && a.0 != b.1
                && a.1 != b.0
                && a.1 != b.1
            {
                print_result(*a, *b);
                return;
            }
        }
    }
    println!("-1");
}
fn print_result(a: (usize, usize), b: (usize, usize)) {
    println!("{} {}", a.0, b.0);
    println!("{} {}", b.1, a.1)
}
fn parse() -> (usize, usize) {
    let mut text = String::new();
    std::io::stdin().read_line(&mut text).unwrap();
    let text: Vec<usize> = text
        .trim()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect();
    (text[0], text[1])
}


#![allow(unused_imports)]
use std::io::*;
use std::cmp::*;
use std::collections::*;

macro_rules! debug(
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

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

impl Scanner {

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

   fn next<T : std::str::FromStr >(&mut self) -> T {

      if self.buffer.len() == 0 {
         let mut input = String::new();
         std::io::stdin().read_line(&mut input).ok();
         for word in input.split_whitespace() {
            self.buffer.push_back(word.to_string())
         }
      }

      let front = self.buffer.pop_front().unwrap();
      front.parse::<T>().ok().unwrap()
   }
}

fn main() {
   let mut s = Scanner::new();
   let input : String = s.next();
   println!("8");
}


#[warn(unused_variables)]
fn main() {
    let input = input_vec::<u64>(" ");
    let n = input[0];
    let v = input[1];

    println!("{}", if (n-1) <= v {n-1} else {(n-v+1)*(n-v)/2 + v-1})
}

fn input_str() -> String {
    let mut buff = String::new();
    std::io::stdin().read_line(&mut buff).expect("Err");
    buff
}

fn input_<T>() -> T
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    input_str().trim().parse::<T>().expect("Err pars")
}

fn input_vec<T>(sep: &str) -> Vec<T>
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    input_str().trim().split(sep).map(|c| c.parse::<T>().expect("Err pars")).collect()
}

fn input_vec_chars() -> Vec<char> {
    input_str().trim().chars().collect()
}


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

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

use std::io::Write;

const MOD: u64 = 1000000007;

fn mod_pow(mut a: u64, mut n: u64) -> u64 {
    let mut result = 1;
    while n != 0 {
        if n % 2 == 1 {
            result = result * a % MOD;
        }
        a = a * a % MOD;
        n /= 2;
    }
    return result;
}

fn calc(p: u64, mut n: u64) -> u64 {
    let mut cnt = 0;
    while n != 0 {
        n /= p;
        cnt += n;
    }
    return mod_pow(p, cnt);
}

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let (mut x, n) = parse_line!(u64, u64);
    let mut result = 1;
    for i in 2..=x {
        if i * i > x {
            break;
        }
        if x % i == 0 {
            x /= i;
            while x % i == 0 {
                x /= i;
            }
            result = result * calc(i, n) % MOD;
        }
    }
    if x != 1 {
        result = result * calc(x, n) % MOD;
    }
    writeln!(writer, "{}", result).unwrap();
}

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