The Fair Nut lives in $$$n$$$ story house. $$$a_i$$$ people live on the $$$i$$$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $$$x$$$-th floor, but $$$x$$$ hasn't been chosen yet. When a person needs to get from floor $$$a$$$ to floor $$$b$$$, elevator follows the simple algorithm:   Moves from the $$$x$$$-th floor (initially it stays on the $$$x$$$-th floor) to the $$$a$$$-th and takes the passenger.  Moves from the $$$a$$$-th floor to the $$$b$$$-th floor and lets out the passenger (if $$$a$$$ equals $$$b$$$, elevator just opens and closes the doors, but still comes to the floor from the $$$x$$$-th floor).  Moves from the $$$b$$$-th floor back to the $$$x$$$-th.  The elevator never transposes more than one person and always goes back to the floor $$$x$$$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $$$a$$$-th floor to the $$$b$$$-th floor requires $$$|a - b|$$$ units of electricity.Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $$$x$$$-th floor. Don't forget than elevator initially stays on the $$$x$$$-th floor.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of floors. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 100$$$) — the number of people on each floor.

In a single line, print the answer to the problem — the minimum number of electricity units.

NoteIn the first example, the answer can be achieved by choosing the second floor as the $$$x$$$-th floor. Each person from the second floor (there are two of them) would spend $$$4$$$ units of electricity per day ($$$2$$$ to get down and $$$2$$$ to get up), and one person from the third would spend $$$8$$$ units of electricity per day ($$$4$$$ to get down and $$$4$$$ to get up). $$$4 \cdot 2 + 8 \cdot 1 = 16$$$.In the second example, the answer can be achieved by choosing the first floor as the $$$x$$$-th floor.

use std::io;

fn main() {
    let n = read_one::<usize>();
    let an = read::<usize>();
    let mut ans = 0;

    for i in 0..n {
        ans += an[i] * i * 4;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

#[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),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

fn main() {
    input!{
      n: usize,
      aa: [i64; n],
    }
    let mut ans: i64 = 1 << 32;
    for i in 0i64..n as i64 {
        let mut cost = 0;
        for j in 0i64..n as i64 {
            cost += ((j-i).abs() + j + i) * 2 * aa[j as usize] as i64;
        }
        ans = min(cost, ans);
    }
    println!("{}", ans);
}

use std::cmp::{max, min};
use std::io::stdin;
fn main() {
    let mut text = String::new();
    stdin().read_line(&mut text).unwrap();
    text.clear();
    stdin().read_line(&mut text).unwrap();
    let text: Vec<usize> = text
        .trim()
        .split_whitespace()
        .map(|e| e.parse().unwrap())
        .collect();
    let mut v: Vec<usize> = vec![];
    for x in 1..(text.len() + 1) {
        let mut value = 0;
        for a in 1..(text.len() + 1) {
            value += (abs(x, a) + abs(1, a) + abs(1, x)) * text[a - 1] * 2
        }
        v.push(value)
    }
    v.sort();

    println!("{}", v[0]);
}
fn abs(a: usize, b: usize) -> usize {
    max(a, b) - min(a, b)
}

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

fn main() {
    let n = read_one::<usize>();
    let an = read::<usize>();
    let mut ans = 100_000_000;

    for i in 0..n { // i + 1 : x_th
        let mut tmp = 0;
        for j in 0..n { // a_th
            tmp += (an[j] as isize) * ((i as isize - j as isize).abs()) * 2; // x -> a
            tmp += (an[j] * j * 2) as isize; // a -> ground
            tmp += (2 * i) as isize; // g -> x
        }
        ans = cmp::min(ans, tmp);
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines). The new rectangle should have no common points with the previous one. Note that when we paint a rectangle, we always paint only the border, the rectangles aren't filled.Nobody wins the game — Anna and Maria simply play until they have done k moves in total. Count the number of different ways to play this game.

The first and only line contains three integers: n, m, k (1 ≤ n, m, k ≤ 1000).

Print the single number — the number of the ways to play the game. As this number can be very big, print the value modulo 1000000007 (109 + 7).

NoteTwo ways to play the game are considered different if the final pictures are different. In other words, if one way contains a rectangle that is not contained in the other way.In the first sample Anna, who performs her first and only move, has only one possible action plan — insert a 1 × 1 square inside the given 3 × 3 square.In the second sample Anna has as much as 9 variants: 4 ways to paint a 1 × 1 square, 2 ways to insert a 1 × 2 rectangle vertically, 2 more ways to insert it horizontally and one more way is to insert a 2 × 2 square.

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

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input!{$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, 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")
    };
}

const MOD: i64 = 1000000007;

// assume a, b positive
fn gcd(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (1, 0, a)
    }
    else {
        let (x, y, d) = gcd(b, a%b); // xb + y(a-qb) = d   where q = a/b
        (y, x-y*(a/b), d)
    }
}

fn factorial_mod(a: i64) -> i64 {
    if a == 0 {
        1
    }
    else {
        a * factorial_mod(a-1) % MOD
    }
}

fn binomial_mod(n: i64, k: i64) -> i64 {
    let a = factorial_mod(k);
    let b = factorial_mod(n-k);
    let (inv_a, _, _) = gcd(a, MOD);
    let (inv_b, _, _) = gcd(b, MOD);
    let result = factorial_mod(n) * inv_a % MOD * inv_b % MOD;
    if result < 0 { result + MOD } else { result }
}

fn main() {
    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! {next,
        n: i64,
        m: i64,
        k: i64,
    }
    if 2*k > n-1 || 2*k > m-1 {
        println!("0");
    }
    else {
        println!("{}", binomial_mod(n-1,2*k)*binomial_mod(m-1,2*k) % MOD);
    }
}


Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers.Vanya wants to know how many digits he will have to write down as he labels the books.

The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.

Print the number of digits needed to number all the books.

NoteNote to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.

//spnauti-rust
use std::io::*;
use std::str::*;
use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::*;
#[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 {
    ($i:ident . $e:tt : $t:ty, $($a:ident),*) => {
        $( let $a: $t = $i.$e(); )*
    };
    ($i:ident . $e:tt, $($a:ident),*) => {
        $( let $a = $i.$e(); )*
    };
}

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 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 std::iter::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()
    }
}

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

    let n: i64 = input.p();
    let mut sol = n * 0;
    let mut d = 1;
    let mut x = 1;
    loop {
        let xx = x * 10;
        if n < xx {
            sol += (n - x + 1) * d;
            break;
        } else {
            sol += (xx - x) * d;
            x = xx;
            d += 1;
        }
    }
    println!("{}", sol);
}

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


Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy.We'll consider the table rows numbered from top to bottom from 1 to n, and the columns — numbered from left to right from 1 to n. Initially there is exactly one switched on cell with coordinates (x, y) (x is the row number, y is the column number), and all other cells are switched off. Then each second we switch on the cells that are off but have the side-adjacent cells that are on.For a cell with coordinates (x, y) the side-adjacent cells are cells with coordinates (x - 1, y), (x + 1, y), (x, y - 1), (x, y + 1).In how many seconds will Mr. Bender get happy?

The first line contains four space-separated integers n, x, y, c (1 ≤ n, c ≤ 109; 1 ≤ x, y ≤ n; c ≤ n2).

In a single line print a single integer — the answer to the problem.

NoteInitially the first test has one painted cell, so the answer is 0. In the second test all events will go as is shown on the figure. .

use std::cmp;

fn calcu_size(ix: i32, iy: i32, n: i32, second: i32) -> i64 {
    let mut total = 0i64;
    // middle
    let lefty: i32 = cmp::max(iy - second, 1);
    let righty: i32 = cmp::min(iy + second, n);

    total += (righty - lefty) as i64 + 1;

    // upper
    for i in 0..cmp::min(second, ix - 1) {
        let _row = ix - i - 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += (righty - lefty) as i64 + 1;
    }

    // lower
    for i in 0..cmp::min(second, n - ix) {
        let _row = ix + i + 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += (righty - lefty) as i64 + 1;
    }

    return total;
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_line(&mut input_str).expect("read error");
    let mut iter = input_str.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    let mut left = -1;
    let mut right = 2 * (((2.0 * (c as f64)).sqrt() as i32) + 1);
    while left != right - 1 {
        let mid = (left + right) >> 1;
        if calcu_size(x, y, n, mid) < c as i64 {
            left = mid;
        } else {
            right = mid;
        }
    }
    println!("{}", right);
}

use std::cmp;

fn calcu_size(ix: i32, iy: i32, n: i32, second: i32) -> i32 {
    let mut total = 0;
    // middle
    let lefty: i32 = cmp::max(iy - second, 1);
    let righty: i32 = cmp::min(iy + second, n);

    total += righty - lefty + 1;

    // upper
    for i in 0..cmp::min(second, ix - 1) {
        let _row = ix - i - 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += righty - lefty + 1;
    }

    // lower
    for i in 0..cmp::min(second, n - ix) {
        let _row = ix + i + 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += righty - lefty + 1;
    }

    return total;
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_line(&mut input_str).expect("read error");
    let mut iter = input_str.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    let mut left = -1;
    let mut right = 2 * (((2.0 * (c as f64)).sqrt() as i32) + 1);
    while left != right - 1 {
        let mid = (left + right) >> 1;
        if calcu_size(x, y, n, mid) < c {
            left = mid;
        } else {
            right = mid;
        }
    }
    println!("{}", right);
}

use std::cmp;

fn calcu_size(ix: i32, iy: i32, n: i32, second: i32) -> i32 {
    let mut total = 0;
    // middle
    let lefty: i32 = cmp::max(iy - second, 1);
    let righty: i32 = cmp::min(iy + second, n);

    total += righty - lefty + 1;

    // upper
    for i in 0..cmp::min(second, ix - 1) {
        let _row = ix - i - 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += righty - lefty + 1;
    }

    // lower
    for i in 0..cmp::min(second, n - ix) {
        let _row = ix + i + 1;
        let lefty = cmp::max(iy - second + i + 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += righty - lefty + 1;
    }

    return total;
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_line(&mut input_str).expect("read error");
    let mut iter = input_str.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    let mut left = -1;
    let mut right = ((2.0 * (c as f64)).sqrt() as i32) + 1;
    while left != right - 1 {
        let mid = (left + right) >> 1;
        if calcu_size(x, y, n, mid) < c {
            left = mid;
        } else {
            right = mid;
        }
    }
    println!("{}", right);
}

use std::cmp;

fn calcu_size(ix: i32, iy: i32, n: i32, second: i32) -> i32 {
    let mut total = 0;
    // middle
    let lefty: i32 = cmp::max(iy - second, 1);
    let righty: i32 = cmp::min(iy + second, n);

    total += righty - lefty + 1;

    // upper
    for i in 0..cmp::min(second, ix - 1) {
        let _row = ix - i - 1;
        let lefty = cmp::max(iy - second - i - 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += righty - lefty + 1;
    }

    // lower
    for i in 0..cmp::min(second, n - ix) {
        let _row = ix + i + 1;
        let lefty = cmp::max(iy - second - i - 1, 1);
        let righty = cmp::min(iy + second - i - 1, n);
        total += righty - lefty + 1;
    }

    return total;
}

fn main() {
    let mut input_str = String::new();
    std::io::stdin().read_line(&mut input_str).expect("read error");
    let mut iter = input_str.split_whitespace();
    let n: i32 = iter.next().unwrap().parse().unwrap();
    let x: i32 = iter.next().unwrap().parse().unwrap();
    let y: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    let mut left = -1;
    let mut right = ((2.0 * (c as f64)).sqrt() as i32) + 1;
    while left != right - 1 {
        let mid = (left + right) >> 1;
        if calcu_size(x, y, n, mid) < c {
            left = mid;
        } else {
            right = mid;
        }
    }
    println!("{}", right);
}


A little girl loves problems on bitwise operations very much. Here's one of them.You are given two integers l and r. Let's consider the values of  for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all considered ones.Expression  means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal — as "xor".

The single line contains space-separated integers l and r (1 ≤ l ≤ r ≤ 1018). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

In a single line print a single integer — the maximum value of  for all pairs of integers a, b (l ≤ a ≤ b ≤ r).

//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!(l,r: i64 = input.p());
    if l == r {
        println!("0");
    } else {
        let mut x = l ^ r;
        for i in 0..=5 {
            x |= x >> (1 << i);
        }
        println!("{}", x);
    }
}

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

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

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let (l, r) = parse_line!(u64, u64);
    let mut bit = 1u64 << 63;
    while bit != 0 && l & bit == r & bit {
        bit >>= 1;
    }
    if bit == 0 {
        writeln!(writer, "0").unwrap();
    }else{
        writeln!(writer, "{}", bit | (bit - 1)).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);
    }
}


A monster is attacking the Cyberland!Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF.Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF. All numbers in input are integer and lie between 1 and 100 inclusively.

The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.

NoteFor the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.

// ---------- 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::cmp::*;

fn run() {
    input! {
        yang: (i64, i64, i64),
        mons: (i64, i64, i64),
        h: i64,
        a: i64,
        d: i64,
    }
    let win = |h: i64, a: i64, b: i64| -> bool {
        let yang = (yang.0 + h, yang.1 + a, yang.2 + b);
        let x = max(yang.1 - mons.2, 0);
        if x <= 0 {
            return false;
        }
        let y = max(mons.1 - yang.2, 0);
        if y <= 0 {
            return true;
        }
        let a = (yang.0 + y - 1) / y;
        let b = (mons.0 + x - 1) / x;
        a > b
    };
    // DEFを100, ATK を100買えば勝てる、これ以下
    let mut ans = 100 * a + 100 * d;
    for i in 0..=21000 {
        if i * h > ans {
            break;
        }
        for j in 0..=200 {
            if j * a > ans - i * h {
                break;
            }
            for k in 0..=200 {
                if win(i, j, k) {
                    ans = min(ans, i * h + j * a + k * d);
                }
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

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

fn resolve(hy: i64, ay: i64, dy: i64, hm: i64, am: i64, dm: i64) -> bool {
    let ay = ay - dm;
    let am = am - dy;
    if ay <= 0 {
        return false;
    }
    if am <= 0 {
        return true;
    }
    let yt = (hy - 1) / am;
    let mt = (hm - 1) / ay;
    yt > mt
}

fn solve() {
    let (hy, ay, dy) = parse_line!(i64, i64, i64);
    let (hm, am, dm) = parse_line!(i64, i64, i64);
    let (h, a, d) = parse_line!(i64, i64, i64);
    let mut ans = std::i64::MAX;
    for aadd in 0..200 {
        for dadd in 0..100 {
            let ay = ay + aadd;
            let dy = dy + dadd;
            let mut l: i64 = -1;
            let mut r: i64 = 10001;
            if !resolve(hy + r, ay, dy, hm, am, dm) {
                continue;
            }
            while r - l > 1 {
                let m = (l + r) / 2;
                let hy = hy + m;
                if resolve(hy, ay, dy, hm, am, dm) {
                    r = m;
                }else{
                    l = m;
                }
            }
            let cost = aadd * a + dadd * d + r * h;
            if cost < ans {
                ans = cost;
            }
        }
    }
    println!("{}", ans);
}

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

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

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

fn resolve(hy: i64, ay: i64, dy: i64, hm: i64, am: i64, dm: i64) -> bool {
    let ay = ay - dm;
    let am = am - dy;
    if ay <= 0 {
        return false;
    }
    if am <= 0 {
        return true;
    }
    let yt = (hy - 1) / am;
    let mt = (hm - 1) / ay;
    yt > mt
}

fn solve() {
    let (hy, ay, dy) = parse_line!(i64, i64, i64);
    let (hm, am, dm) = parse_line!(i64, i64, i64);
    let (h, a, d) = parse_line!(i64, i64, i64);
    let mut ans = std::i64::MAX;
    for aadd in 0..500 {
        for dadd in 0..500 {
            let ay = ay + aadd;
            let dy = dy + dadd;
            let mut l: i64 = -1;
            let mut r: i64 = 100001;
            while r - l > 1 {
                let m = (l + r) / 2;
                let hy = hy + m;
                if resolve(hy, ay, dy, hm, am, dm) {
                    r = m;
                }else{
                    l = m;
                }
            }
            let cost = aadd * a + dadd * d + r * h;
            ans = std::cmp::min(ans, cost);
        }
    }
    println!("{}", ans);
}

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

// ---------- 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::cmp::*;

fn run() {
    input! {
        yang: (i64, i64, i64),
        mons: (i64, i64, i64),
        h: i64,
        a: i64,
        d: i64,
    }
    let win = |h: i64, a: i64, b: i64| -> bool {
        let yang = (yang.0 + h, yang.1 + a, yang.2 + b);
        let x = max(yang.1 - mons.2, 0);
        if x <= 0 {
            return false;
        }
        let y = max(mons.1 - yang.2, 0);
        if y <= 0 {
            return true;
        }
        let a = (yang.0 + y - 1) / y;
        let b = (mons.0 + x - 1) / x;
        a > b
    };
    // DEFを100, ATK を100買えば勝てる、これ以下
    let mut ans = 100 * a + 100 * d;
    for i in 0..=10000 {
        if i * h > ans {
            break;
        }
        for j in 0..=100 {
            if j * a > ans - i * h {
                break;
            }
            for k in 0..=100 {
                if win(i, j, k) {
                    ans = min(ans, i * h + j * a + k * d);
                }
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}

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

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

fn resolve(hy: i64, ay: i64, dy: i64, hm: i64, am: i64, dm: i64) -> bool {
    let ay = std::cmp::max(0, ay - dm);
    let am = std::cmp::max(0, am - dy);
    if ay == 0 {
        return false;
    }
    if am == 0 {
        return true;
    }
    let yt = (hy - 1) / am + 1;
    let mt = (hm - 1) / ay + 1;
    yt > mt
}

fn solve() {
    let (hy, ay, dy) = parse_line!(i64, i64, i64);
    let (hm, am, dm) = parse_line!(i64, i64, i64);
    let (h, a, d) = parse_line!(i64, i64, i64);
    let mut ans = std::i64::MAX;
    for aadd in 0..200 {
        for dadd in 0..100 {
            let ay = ay + aadd;
            let dy = dy + dadd;
            let mut l: i64 = -1;
            let mut r: i64 = 10001;
            while r - l > 1 {
                let m = (l + r) / 2;
                let hy = hy + m;
                if resolve(hy, ay, dy, hm, am, dm) {
                    r = m;
                }else{
                    l = m;
                }
            }
            let cost = aadd * a + dadd * d + r * h;
            ans = std::cmp::min(ans, cost);
        }
    }
    println!("{}", ans);
}

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


We consider a positive integer perfect, if and only if the sum of its digits is exactly $$$10$$$. Given a positive integer $$$k$$$, your task is to find the $$$k$$$-th smallest perfect positive integer.

A single line with a positive integer $$$k$$$ ($$$1 \leq k \leq 10\,000$$$).

A single number, denoting the $$$k$$$-th smallest perfect integer.

NoteThe first perfect integer is $$$19$$$ and the second one is $$$28$$$.

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 digit_sum(n: u32) -> u32 {
    let mut ans = 0;
    let mut n = n;
    while n > 0 {
        ans += n % 10;
        n /= 10;
    }
    ans
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {

    let mut k: usize = scan.token();
    let mut num = 0;
    while k > 0 {
        num += 1;
        if digit_sum(num) == 10 {
            k -= 1;
        }
    }
    writeln!(out, "{}", num).ok();
}

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

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

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

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

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

    let k = input.u();
    let sol = (1..).filter(|&a| {
        let mut b = a;
        let mut s = 0;
        while b > 0 {
            s += b % 10;
            b /= 10;
        }
        s == 10
    }).nth(k - 1).unwrap();
    println!("{}", sol);
}

#[allow(unused_imports)]
use std::io::{stdin, Read, StdinLock};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};
#[allow(unused_imports)]
use std::vec::Vec;

#[allow(dead_code)]
const INF: i32 = 1000_000_000;
#[allow(dead_code)]
const INFLL: i64 = 1000_000_000_000_000_000;
#[allow(dead_code)]
const EPS: f64 = 1.0e-10;
#[allow(dead_code)]
const MOD: i32 = 1000_000_007;
#[allow(dead_code)]
const MODLL: i64 = 1000_000_007;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let k: usize = sc.read();
    let mut cnt = 0;
    for i in 0..1000_000_00 {
        let mut sum = 0;
        let mut x = i;
        while x > 0 {
            sum += x % 10;
            x /= 10;
        }
        if sum == 10 {
            cnt += 1;
        }

        if cnt == k {
            println!("{}", i);
            break;
        }
    }
}

#![allow(unused_imports, unused_macros, dead_code)]
use std::f64::*;
use std::cmp::*;
use std::collections::*;

macro_rules! dump{
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const INF: i64 = 0x3f3f3f3f3f3f3f3f;
const MOD: i64 = 1000000007;
const NOTHING: usize = std::usize::MAX;
const DX: [usize; 4] = [1, 0, std::usize::MAX, 0];
const DY: [usize; 4] = [0, 1, 0, std::usize::MAX];

fn main() {
    let mut k: u64 = readln();
    let mut i = 0;
    while k > 0 {
        i += 1;
        let mut x = i;
        let mut s = 0;
        while x > 0 {
            s += x % 10;
            x /= 10;
        }
        if s == 10 {
            k -= 1;
        }
    }
    println!("{}", i);
}

trait Read {
    fn read(s: &str) -> Self;
}

fn readln<T: Read>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    T::read(buf.trim_right())
}

macro_rules! read_impl{
    ($($t:ty)*) => ($(
        impl Read for $t {
            fn read(s: &str) -> $t{
                s.parse().unwrap()
            }
        }
    )*)
}
read_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }

impl Read for String {
    fn read(s: &str) -> Self {
        s.to_string()
    }
}

impl Read for Vec<char> {
    fn read(s: &str) -> Self {
        s.chars().collect()
    }
}

impl<T: Read> Read for Vec<T> {
    fn read(s: &str) -> Self {
        s.split_whitespace().map(T::read).collect()
    }
}

impl<A: Read, B: Read> Read for (A, B) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]))
    }
}

impl<A: Read, B: Read, C: Read> Read for (A, B, C) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))
    }
}

impl<A: Read, B: Read, C: Read, D: Read> Read for (A, B, C, D) {
    fn read(s: &str) -> Self {
        let tokens: Vec<_> = s.split_whitespace().collect();
        (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))
    }
}

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

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

use std::io::Write;

fn good(mut a: u32) -> bool {
    let mut sum = 0;
    while a != 0 {
        sum += a % 10;
        a /= 10;
    }
    return sum == 10;
}

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let mut k = parse_line!(usize);
    let mut result = 0;
    while k > 0 {
        result += 1;
        if good(result) {
            k -= 1;
        }
    }
    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);
    }
}

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

fn main() {
    let n: i32 = read_line().unwrap().parse().unwrap();
    fn sum_digits(mut n: i64) -> i32 {
        let mut sum = 0;
        while n > 0 {
            sum += (n % 10) as i32;
            n /= 10;
        }
        sum
    }
    let mut a = 19;
    let mut m = 0;
    loop {
        let sum = sum_digits(a);
        if sum == 10 {
            m += 1;
            if m == n {
                println!("{}", a);
                break;
            }
        }
        if sum >= 10 {
            a += 10 - a % 10;
        } else {
            a += 1;
        }
    }
}

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 b(n: u32) -> bool {
    let mut sum = 0;
    let mut k = n;
    while k > 0 {
        sum += k % 10;
        k /= 10;
    }
    return sum == 10;
}

fn main() {
    let mut k: u32 = read_line().parse().unwrap();
    let mut i = 0u32;
    while k > 0 {
        i += 1;
        if b(i) {
            k -= 1;
        }
    }

    println!("{}", i);

}


Seven boys and seven girls from Athens were brought before King Minos. The evil king laughed and said "I hope you enjoy your stay in Crete".With a loud clang, the doors behind them shut, and darkness reigned. The terrified children huddled together. In the distance they heard a bellowing, unholy roar.Bravely, they advanced forward, to their doom.

$$$n$$$ ($$$1 \le n \le 100$$$) — the dimensions of the labyrinth.  Each of the next $$$n$$$ lines contains a string of lowercase English letters of length $$$n$$$.

10
atzxcodera
mzhappyayc
mineodteri
trxesonaac
mtollexcxc
hjikeoutlc
eascripsni
rgvymnjcxm
onzazwswwg
geothermal

#![allow(dead_code)]

use std::str::FromStr;

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

fn read_val<T: FromStr>() -> T {
    read_line().parse::<T>().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read_line().split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}

fn read_arr<T: FromStr, const N: usize>() -> [T; N] {
    read_vec().try_into().ok().unwrap()
}

fn main() {
    let n: usize = read_val();
    let mut a: Vec<Vec<char>> = vec![vec![]; n];
    let word = "theseus".to_owned();

    for i in 0..n {
        a[i] = read_line().chars().collect::<Vec<char>>();
    }
    for i in 0..n {
        if i + 7 < n {
            for j in 0..n {
                if j + 7 < n {
                    let mut s1 = String::new();
                    let mut s2 = String::new();
                    let mut s3 = String::new();
                    for k in 0..7 {
                        s1.push(a[i][j+k]);
                        s2.push(a[i+k][j]);
                        s3.push(a[i+k][j+k]);
                    }
                    if word == s1 || word == s2 || word == s3 {
                        println!("Yes");
                        return;
                    }
                }
            }
        }
    }
    println!("No")
}

#![allow(dead_code)]

use std::str::FromStr;

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

fn read_val<T: FromStr>() -> T {
    read_line().parse::<T>().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read_line().split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}

fn read_arr<T: FromStr, const N: usize>() -> [T; N] {
    read_vec().try_into().ok().unwrap()
}

fn main() {
    let n: usize = read_val();
    let mut a: Vec<Vec<char>> = vec![vec![]; n];
    let word = "theseus".to_owned();

    for i in 0..n {
        a[i] = read_line().chars().collect::<Vec<char>>();
    }
    println!("{a:?}");
    for i in 0..n {
        if i + 7 < n {
            for j in 0..n {
                if j + 7 < n {
                    let mut s1 = String::new();
                    let mut s2 = String::new();
                    let mut s3 = String::new();
                    for k in 0..7 {
                        s1.push(a[i][j+k]);
                        s2.push(a[i+k][j]);
                        s3.push(a[i+k][j+k]);
                    }
                    if word == s1 || word == s2 || word == s3 {
                        println!("Yes");
                        return;
                    }
                }
            }
        }
    }
    println!("No")
}

#![allow(dead_code)]

use std::str::FromStr;

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

fn read_val<T: FromStr>() -> T {
    read_line().parse::<T>().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read_line().split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}

fn read_arr<T: FromStr, const N: usize>() -> [T; N] {
    read_vec().try_into().ok().unwrap()
}

fn main() {
    let n: i32 = read_val();
    let mut happy = false;
    let mut code = false;
    let mut geothermal = false;

    for i in 0..n {
        let s = read_line();
        if !happy && s.contains("happy") {
            happy = true;
        }
        if !code && s.contains("code") {
            code = true;
        }
        if !geothermal && s == "geothermal" {
            geothermal = true;
        }
    }
    println!("{}", if happy & code || geothermal { "Yes" } else { "No" });
}

#![allow(dead_code)]

use std::str::FromStr;

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

fn read_val<T: FromStr>() -> T {
    read_line().parse::<T>().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read_line().split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}

fn read_arr<T: FromStr, const N: usize>() -> [T; N] {
    read_vec().try_into().ok().unwrap()
}

fn main() {
    let n: i32 = read_val();
    let mut happy = false;
    let mut code = false;

    for i in 0..n {
        let s = read_line();
        if !happy && s.contains("happy") {
            happy = true;
        }
        if !code && s.contains("code") {
            code = true;
        }
    }
    println!("{}", if happy & code { "Yes" } else { "No" });

}


Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was n integers a1, a2, ..., an. These numbers mean that Greg needs to do exactly n exercises today. Besides, Greg should repeat the i-th in order exercise ai times.Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the n-th exercise.Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training.

The first line contains integer n (1 ≤ n ≤ 20). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 25) — the number of times Greg repeats the exercises.

Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous.

NoteIn the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the most exercise.

fn input_count() -> [u8; 3] {
    let mut buf = String::new();
    let mut body = [0; 3];
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|elem| elem.parse::<u8>().unwrap())
        .zip(0..)
        .for_each(|(a_i, i)| body[i % 3] += a_i);
    body
}

fn main() {
    {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
    }
    println!(
        "{}",
        input_count()
            .iter()
            .zip(["chest", "biceps", "back"].iter())
            .max()
            .unwrap()
            .1
    );
}

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

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

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

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

    let n = input.u();
    let mut a = vec![0; 3];
    for i in 0..n {
        a[i % 3] += input.i();
    }
    let max = a.iter().max().unwrap();
    for (x,y) in vec!["chest","biceps","back"].into_iter().zip(a.iter()) {
        if max == y {
            println!("{}", x);
        }
    }
}

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

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

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

fn _main() {
    let mut scan = Scan::new();
    let n: usize = scan.next();
    let mut cnt = [0usize; 3];
    let ex_msg = ["chest", "biceps", "back"];
    let mut maxa = 0usize;
    let mut maxi = 0usize;
    for i in 0..n {
        let a: usize = scan.next();
        let exi = i % 3;
        cnt[exi] += a;
        if cnt[exi] > maxa {
            maxa = cnt[exi];
            maxi = exi;
        }
    }
    println!("{}", ex_msg[maxi]);
}

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


Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption.Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one):  After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in.Slastyona managed to have spinner rotating for exactly n seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this.

There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: v (ASCII code 118, lowercase v), < (ASCII code 60), ^ (ASCII code 94) or > (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number n is given (0 ≤ n ≤ 109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a n second spin in any of the directions, assuming the given starting position.

Output cw, if the direction is clockwise, ccw – if counter-clockwise, and undefined otherwise.

#[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!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
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 modu(x: i32, y: i32) -> i32 {
  let res = x % y;
  if res < 0 { res + y } else { res }
}

fn main() {
  scanln!(start: String, end: String);
  scanln!(rotations: i32);
  let start = match &start as &str {
    "^" => 0i32,
    ">" => 1i32,
    "v" => 2i32,
    "<" => 3i32,
    _ => unreachable!()
  };
  let end = match &end as &str {
    "^" => 0i32,
    ">" => 1i32,
    "v" => 2i32,
    "<" => 3i32,
    _ => unreachable!()
  };
  let cw = modu(start + (rotations % 4), 4);
  let ccw = modu(start - (rotations % 4), 4);
  if cw == end && ccw == end {
    println!("undefined");
  } else if cw == end {
    println!("cw");
  } else if ccw == end {
    println!("ccw");
  } else {
    println!("undefined");
  }
}

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

fn read_int() -> u64 {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("Failed");
    let x = input.trim().parse::<u64>().unwrap();
    input.clear();
    x
}

fn main(){
    let s = read_string();
    let vec: Vec<&str> = s.split("").collect();
    let start_pos_as_char = vec[1].chars().next().unwrap() as u8;
    let end_pos_as_char = vec[3].chars().next().unwrap() as u8;
    let x = read_int();
    let cases = vec![118, 60, 94, 62]; // down left up right
    let sp = cases.iter().position(|&r| r == start_pos_as_char).unwrap();
    let ep = cases.iter().position(|&r| r == end_pos_as_char).unwrap();
    let is_even = ((x % 2) + 2) % 2;
    let result = (((x+sp as u64) % 4) + 4) % 4;
    if is_even == 0{
        println!("undefined");
    } else if (sp < 4) && (cases[result as usize] == end_pos_as_char) || (cases[result as usize] == end_pos_as_char) && (ep == 4){
        println!("cw");
    } else {
        println!("ccw");
    }

}

fn dir(c: char) -> i32 {
    match c {
        'v' => 0,
        '<' => 1,
        '^' => 2,
        '>' => 3,
        _ => panic!("Invalid character"),
    }
}

fn modu(a: i32) -> i32 {
    if a < 0 {
        a % 4 + 4
    } else {
        a % 4
    }
}

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

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

    let mut iter = input.chars();

    let start = iter.next().unwrap();
    iter.next().unwrap();
    let end = iter.next().unwrap();

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

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

    let n = it.next().unwrap();

    if n % 2 == 0 {
        println!("undefined");
    } else if n % 4 == modu(dir(end) - dir(start)) {
        println!("cw");
    } else {
        println!("ccw");
    }
}

fn read_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect(
        "Could not read line",
    );
    String::from(&line[..line.len() - 1])
}

macro_rules! read_line {
    (Vec<$t: ty>) => {{
        read_line().split_whitespace().map(|token| {
            <$t as std::str::FromStr>::from_str(token).expect(
                &format!(concat!("Could not parse {} into ", stringify!($t)), token))
        }).collect::<Vec<$t>>()
    }};
    ($($t: ty),*) => {{
        let line = read_line();
        let mut iter = line.split_whitespace();
        let result = ($({
            let token = iter.next().expect("Not enough tokens");
            <$t as std::str::FromStr>::from_str(token).expect(
                &format!(concat!("Could not parse {} into ", stringify!($t)), token))
        }),*);
        if let Some(token) = iter.next() {
            panic!("Unexpected token {}", token);
        }
        result
    }};
}

fn main() {
    let (s, f) = read_line!(String, String);
    let s = s.chars().nth(0).unwrap();
    let f = f.chars().nth(0).unwrap();
    let time = read_line!(usize);
    let all = ['v', '<', '^', '>'];
    let s = all.iter().enumerate().find(|x| *x.1 == s).unwrap().0;
    let f = all.iter().enumerate().find(|x| *x.1 == f).unwrap().0;
    let canCw = (s + time) % 4 == f;
    let canCcw = s == (f + time) % 4;
    println!(
        "{}",
        match (canCw, canCcw) {
            (false, false) => panic!("impossible"),
            (true, false) => "cw",
            (false, true) => "ccw",
            (true, true) => "undefined",
        }
    );
}

fn read_line() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("EOF");
    line.pop();
    return line;
}

macro_rules! read_line {
    (Vec<$t: ty>) => {{
        read_line().split_whitespace().map(|token| {
            <$t as std::str::FromStr>::from_str(token).expect("Invalid token")
        }).collect<Vec<$t>>()
    }};
    ($($t: ty),*) => {{
        let line = read_line();
        let mut iter = line.split_whitespace();
        ($({
            let token = iter.next().expect("Too few tokens");
            <$t as std::str::FromStr>::from_str(token).expect("Invalid token")
        }), *)
    }};
}

fn spinner_position(c: char) -> i32 {
    match c {
        '^' => 0,
        '>' => 1,
        'v' => 2,
        '<' => 3,
        _ => -1,
    }
}

fn main() {
    let (s, t) = read_line!(String, String);
    let n = read_line!(i32) % 4;
    let x = spinner_position(s.chars().nth(0).expect(""));
    let y = spinner_position(t.chars().nth(0).expect(""));
    let d = (y - x + 4) % 4;
    if n % 2 == 0 {
        println!("undefined");
    } else if d == n {
        println!("cw");
    } else if d == 4 - n {
        println!("ccw");
    }
}

fn dir(c: char) -> i32 {
    match c {
        'v' => 0,
        '<' => 1,
        '^' => 2,
        '>' => 3,
        _ => panic!("Invalid character"),
    }
}

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

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

    let mut iter = input.chars();

    let start = iter.next().unwrap();
    iter.next().unwrap();
    let end = iter.next().unwrap();

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

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

    let n = it.next().unwrap();

    if n % 2 == 0 {
        println!("undefined");
    } else if n % 4 == (dir(end) - dir(start)) % 4 {
        println!("cw");
    } else {
        println!("ccw");
    }
}


Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?

The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100).

Output a single integer — the minimal possible number of piles.

NoteIn example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).

use std::io;

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

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

    let t = 1;
    for _ in 0..t {
        let n = read!(usize);
        let mut a = vec![0; n];
        for i in 0..n {
            a[i] = read!(usize);
        }

        a.sort();
        let mut v = vec![false; n];
        let mut r = 0;
        for i in 0..n {
            if v[i] {
                continue;
            }
            v[i] = true;
            r += 1;
            let mut c = 1;
            for j in (i + 1)..n {
                if !v[j] && a[j] >= c {
                    v[j] = true;
                    c += 1;
                }
            }
        }

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

    rr
}

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

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

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

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

    let t = 1;
    for _ in 0..t {
        let n = read!(usize);
        let mut a = vec![0; n];
        for i in 0..n {
            a[i] = read!(usize);
        }

        let mut c: HashMap<usize, usize> = HashMap::new();
        for i in 0..n {
            *(c.entry(a[i]).or_insert(0)) += 1;
        }

        let mut r = 1;
        for (k, t) in c.iter() {
            if r < *t {
                r = *t;
            }
        }

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

    rr
}

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


Unlucky year in Berland is such a year that its number n can be represented as n = xa + yb, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 20 + 31, 17 = 23 + 32 = 24 + 30) and year 18 isn't unlucky as there is no such representation for it.Such interval of years that there are no unlucky years in it is called The Golden Age.You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.

The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 1018, 1 ≤ l ≤ r ≤ 1018).

Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0.

NoteIn the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].In the second example the longest Golden Age is the interval [15, 22].

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

fn main() {
  let mut buffer = String::new();
  io::stdin().read_line(&mut buffer).unwrap();
  let input : Vec<i64> = buffer.split_whitespace()
                                 .map(|x| x.trim().parse::<i64>().unwrap())
                                 .collect();
  let x = input[0];
  let y = input[1];
  let l = input[2];
  let r = input[3];

  let mut powx: Vec<i64> = vec![1];
  while r / powx.last().unwrap() >= x {
    powx.push(powx.last().unwrap() * x);
  }

  let mut powy: Vec<i64> = vec![1];
  while r / powy.last().unwrap() >= y {
    powy.push(powy.last().unwrap() * y);
  }

  let mut unluckys : Vec<i64> = vec![l-1, r+1];
  for i in &powx {
    for j in &powy {
      if i + j >= l && i + j <= r {
        unluckys.push(i+j);
      }
    }
  }
  unluckys.sort();

  let mut max_lucky : i64 = 0;
  for i in 1..unluckys.len() {
    max_lucky = cmp::max(max_lucky, unluckys[i] - unluckys[i-1]);
  }
  println!("{}", max_lucky-1);
}


Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.

The first line of input contains three integers: n (1 ≤ n ≤ 100), k (1 ≤ k ≤ 100) and x (1 ≤ x ≤ k). The next line contains n space-separated integers c1, c2, ..., cn (1 ≤ ci ≤ k). Number ci means that the i-th ball in the row has color ci. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.

Print a single integer — the maximum number of balls Iahub can destroy.

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

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

fn solve_one(pos: usize, col: usize, c: &Vec<usize>) -> usize {
    let mut s = Vec::new();
    let mut result = 0;
    for i in 0..=c.len() {
        let val = if i < pos {c[i]} else if i > pos {c[i - 1]} else {col};
        if s.is_empty() {
            s.push((val, 1));
        }else if s.last().unwrap().0 == val {
            s.last_mut().unwrap().1 += 1;
        }else{
            if s.last().unwrap().1 > 2 {
                result += s.pop().unwrap().1;
            }
            if s.is_empty() {
                s.push((val, 1));
            }else if s.last().unwrap().0 == val {
                s.last_mut().unwrap().1 += 1;
            }else{
                s.push((val, 1));
            }
        }
    }
    if let Some((_col, cnt)) = s.last() {
        if *cnt > 2 {
            result += cnt;
        }
    }
    return if result > 0 {
        result - 1
    }else{
        0
    }
}

fn solve() {
    let (n, _k, x) = parse_line!(usize, usize, usize);
    let c = parse_line_to_vec!(usize);
    let mut result = 0;
    for i in 0..=n {
        result = std::cmp::max(result, solve_one(i, x, &c));
    }
    println!("{}", result)
}

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


One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were x details in the factory storage, then by the end of the day the factory has to produce  (remainder after dividing x by m) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by m). Given the number of details a on the first day and number m check if the production stops at some moment.

The first line contains two integers a and m (1 ≤ a, m ≤ 105).

Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No".

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 mut x: i32 = scan.token();
    let m: i32 = scan.token();

    x %= m;

    let mut seen = vec![false; m as usize];

    while x > 0 && !seen[x as usize] {
        seen[x as usize] = true;
        x += x;
        if x >= m {
            x -= m;
        }
    }

    writeln!(out, "{}", match x {
        0 => "Yes",
        _ => "No",
    })?;

    Ok(())
}

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 mut x: u32 = scan.token();
    let mut m: u32 = scan.token();

    x >>= x.trailing_zeros();
    m >>= m.trailing_zeros();

    writeln!(out, "{}", if x % m == 0 { "Yes" } else { "No" })?;

    Ok(())
}

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 mut x: i32 = scan.token();
    let mut m: i32 = scan.token();

    while m % 2 == 0 {
        m /= 2;
    }
    while x % 2 == 0 {
        x /= 2;
    }

    writeln!(out, "{}", if x % m == 0 { "Yes" } else { "No" })?;

    Ok(())
}


Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers "A factorial" and "B factorial". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·...·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y.Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?

The first and single line contains two integers A and B (1 ≤ A, B ≤ 109, min(A, B) ≤ 12).

Print a single integer denoting the greatest common divisor of integers A! and B!.

NoteConsider the sample.4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.

fn main() {
  use std::io;
  use std::cmp;

  fn factorial(n: usize) -> usize {
    let mut result = 1;
    for i in 2..(n+1) {
      result *= i;
    }
    result
  }

  let mut line = String::new();
  io::stdin().read_line(&mut line).unwrap();
  let mut ns = line.split(" ").map(|str| str.trim().parse::<usize>().unwrap());
  let a = ns.next().unwrap();
  let b = ns.next().unwrap();

  println!("{}", factorial(cmp::min(a, b)));
}

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

fn factorial(n: u32) -> u32 {
    (1..=n).fold(1, |acc, x| acc * x)
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let numbers: Vec<u32> = line
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
    let a = numbers[0];
    let b = numbers[1];
    let ans = factorial(min(a, b));
    println!("{}", ans);
}

fn fact(n: u32) -> u32 {
    if n == 1 {
        1
    } else {
        n * fact(n - 1)
    }
}

fn main() {
    let (a, b) = {
        let mut buf = String::with_capacity(3);
        std::io::stdin().read_line(&mut buf).unwrap();
        let nums: Vec<u32> = buf
            .trim()
            .split_whitespace()
            .map(|a| a.parse().unwrap())
            .collect();
        (nums[0], nums[1])
    };

    print!("{}", fact(a.min(b)));
}

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

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

    println!("{}", (1..1 + (input.i().min(input.i()) as i64))
             .product::<i64>());
}

use std::io;
use std::str::{FromStr, SplitWhitespace};
use std::fmt::Debug;
use std::iter::Map;
use std::cmp::min;

fn main() {
    let (a,b) = Input::line().pair();
    let res = (1..min::<u64>(a,b) + 1).fold(1, |ref x, i| x * i) ;
    println!("{}", res);

}

pub trait UParse: FromStr {
    fn uparse(&str) -> Self;
}
impl<T> UParse for T
where
    T: FromStr,
    T::Err: Debug,
{
    fn uparse(str: &str) -> Self {
        str.trim().parse().unwrap()
    }
}

pub struct Input(String);
impl Input {
    pub fn line() -> Input {
        let mut str = String::new();
        io::stdin().read_line(&mut str).unwrap();
        Input(str)
    }

    fn trim_parse<T: UParse>(s: &str) -> T {
        UParse::uparse(s)
    }

    pub fn iter<T: UParse>(&self) -> Map<SplitWhitespace, fn(&str) -> T> {
        self.0.split_whitespace().map(Input::trim_parse)
    }

    pub fn single<T: UParse>(&self) -> T {
        Input::trim_parse(self.0.as_ref())
    }

    pub fn pair<A: UParse, B: UParse>(&self) -> (A, B) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        (a, b)
    }

    pub fn triple<A: UParse, B: UParse, C: UParse>(&self) -> (A, B, C) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        (a, b, c)
    }

    pub fn quadruple<A: UParse, B: UParse, C: UParse, D: UParse>(&self) -> (A, B, C, D) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        let d = Input::trim_parse(it.next().unwrap());
        (a, b, c, d)
    }
}

use std::io;
use std::str::{FromStr, SplitWhitespace};
use std::fmt::Debug;
use std::iter::Map;
use std::cmp::min;

fn main() {
    let (a,b) = Input::line().pair();
    let res = (1..min::<u32>(a,b) + 1).fold(1, |ref x, i| x * i) ;
    println!("{}", res);

}

pub trait UParse: FromStr {
    fn uparse(&str) -> Self;
}
impl<T> UParse for T
where
    T: FromStr,
    T::Err: Debug,
{
    fn uparse(str: &str) -> Self {
        str.trim().parse().unwrap()
    }
}

pub struct Input(String);
impl Input {
    pub fn line() -> Input {
        let mut str = String::new();
        io::stdin().read_line(&mut str).unwrap();
        Input(str)
    }

    fn trim_parse<T: UParse>(s: &str) -> T {
        UParse::uparse(s)
    }

    pub fn iter<T: UParse>(&self) -> Map<SplitWhitespace, fn(&str) -> T> {
        self.0.split_whitespace().map(Input::trim_parse)
    }

    pub fn single<T: UParse>(&self) -> T {
        Input::trim_parse(self.0.as_ref())
    }

    pub fn pair<A: UParse, B: UParse>(&self) -> (A, B) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        (a, b)
    }

    pub fn triple<A: UParse, B: UParse, C: UParse>(&self) -> (A, B, C) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        (a, b, c)
    }

    pub fn quadruple<A: UParse, B: UParse, C: UParse, D: UParse>(&self) -> (A, B, C, D) {
        let mut it = self.0.split_whitespace();
        let a = Input::trim_parse(it.next().unwrap());
        let b = Input::trim_parse(it.next().unwrap());
        let c = Input::trim_parse(it.next().unwrap());
        let d = Input::trim_parse(it.next().unwrap());
        (a, b, c, d)
    }
}

#[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 (x,y) = readln!(i64,i64);
    let p = (1..=min(x,y)).product::<i64>();
    println!("{}",p);
}

use std::io::stdin;

fn read_n() -> (u32, u32) {
    let mut buffer = String::new();
    stdin().read_line(&mut buffer).unwrap();
    let snums: Vec<&str> = buffer.trim().split(" ").collect();
    (snums[0].parse::<u32>().unwrap(), snums[1].parse::<u32>().unwrap())
}

fn factorial(x: u32) -> u32 {
    let mut n: u32 = 1;
    for i in 2..x+1 {
        n *= i;
    }
    n
}

fn main() {
    let (a, b) = read_n();
    if a < b {
        println!("{}", factorial(a));
    } else {
        println!("{}", factorial(b));
    }
}

fn factorial(n: i32) -> i32 {
    if n == 0 {
        1
    } else {
        n * factorial(n - 1)
    }
}

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

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

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

    let mut iter = input.split_whitespace().map(|p| p.parse::<i32>().unwrap());

    let a = iter.next().unwrap();
    let b = iter.next().unwrap();

    let c = cmp::min(a, b);
    println!("{}", factorial(c));
}

#[allow(unused_imports)]
use std::io;
use std::cmp::{min, max};
use std::mem;
use std::str::FromStr;
use std::cmp::Ordering;
use std::collections::BinaryHeap;

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

impl<B: io::BufRead> Scanner<B> {
    pub fn new(reader: B) -> Scanner<B> {
        Scanner {
            reader: reader,
            buffer: Vec::new(),
        }
    }

    /// Use "turbofish" syntax next::<T>() to select data type of next token.
    pub fn next<T: ::std::str::FromStr>(&mut self) -> T
        where
            T::Err: ::std::fmt::Debug,
    {
        if let Some(front) = self.buffer.pop() {
            front.parse::<T>().expect(&front)
        } else {
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Line not read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
            self.next()
        }
    }

    pub fn next_vec<T: ::std::str::FromStr>(&mut self, len: usize) -> Vec<T>
        where
            T::Err: ::std::fmt::Debug,
    {
        (0..len).map(|_| self.next::<T>()).collect::<Vec<T>>()
    }
}

fn main1() {
    let stdin = io::stdin();
    let mut input = Scanner::new(stdin.lock());
    let a: i64 = input.next();
    let b: i64 = input.next();
    let n = min(a, b);
    let answer = (1..(n + 1)).fold(1i64, |mul, x| mul * x);
    println!("{}", answer);

}

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

fn factorial(x: usize) -> usize {
    let mut result: usize = 1;
    for i in 1..=x {
        result *= i;
    }
    result
}

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 a: usize = scan.next();
    let b: usize = scan.next();
    println!("{}", factorial(a.min(b)));
}

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

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

fn factorial(x: i32) -> i32 {
    if x < 2 {
        return 1;
    } else {
        return x * factorial(x - 1);
    }
}

fn main() {
    let reader = io::stdin();
    let numbers: Vec<i32> =
        reader.lock()                           // (0)
            .lines().next().unwrap().unwrap() // (1)
            .split(' ').map(|s| s.trim())     // (2)
            .filter(|s| !s.is_empty())        // (3)
            .map(|s| s.parse().unwrap())      // (4)
            .collect();                       // (5)

    let mut min= numbers[0];
    if numbers[1] < min {
        min = numbers[1];
    }

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

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

fn factorial(n: u32) -> u32 {
    (1..=n).fold(1, |acc, x| acc * x)
}

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let numbers: Vec<u32> = line
        .split_whitespace()
        .map(|s| s.parse().unwrap())
        .collect();
    let a = numbers[0];
    let b = numbers[1];
    let ans = min(factorial(a), factorial(b));
    println!("{}", ans);
}

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

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

    println!("{}", (1..(input.i().min(input.i()) as i64))
             .product::<i64>());
}