Polycarp loves ciphers. He has invented his own cipher called Right-Left.Right-Left cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \dots s_{n}$$$ Polycarp uses the following algorithm:  he writes down $$$s_1$$$,  he appends the current word with $$$s_2$$$ (i.e. writes down $$$s_2$$$ to the right of the current result),  he prepends the current word with $$$s_3$$$ (i.e. writes down $$$s_3$$$ to the left of the current result),  he appends the current word with $$$s_4$$$ (i.e. writes down $$$s_4$$$ to the right of the current result),  he prepends the current word with $$$s_5$$$ (i.e. writes down $$$s_5$$$ to the left of the current result),  and so on for each position until the end of $$$s$$$. For example, if $$$s$$$="techno" the process is: "t" $$$\to$$$ "te" $$$\to$$$ "cte" $$$\to$$$ "cteh" $$$\to$$$ "ncteh" $$$\to$$$ "ncteho". So the encrypted $$$s$$$="techno" is "ncteho".Given string $$$t$$$ — the result of encryption of some string $$$s$$$. Your task is to decrypt it, i.e. find the string $$$s$$$.

The only line of the input contains $$$t$$$ — the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is between $$$1$$$ and $$$50$$$, inclusive.

Print such string $$$s$$$ that after encryption it equals $$$t$$$.

use std::io;

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

fn main() {
    let message = readln!();
    let message = message.chars().collect::<Vec<_>>();

    if message.len() % 2 == 0 {
        for index in 0..message.len() / 2 {
            print!("{}{}", message[message.len() / 2 - 1 - index], message[message.len() / 2 + index]);
        }
    } else {
        print!("{}", message[message.len() / 2]);
        for index in 0..message.len() / 2 {
            print!("{}{}", message[message.len() / 2 + 1 + index], message[message.len() / 2 - 1 - index]);
        }
    }

    println!();
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    let s = s.trim();
    let mut i: usize = 0;
    let mut j: usize = s.len()-1;

    let mut r = String::new();
    let mut last = s.len() % 2 == 0;

    for _ in 0..s.len() {
        if last {
            let c = s.chars().nth(j).unwrap();
            r.push(c);
            j -= 1;
        } else {
            let c = s.chars().nth(i).unwrap();
            r.push(c);
            i += 1;
        }
        last = !last;
    }
    println!("{}", r.chars().rev().collect::<String>());
}

#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::{BTreeMap,BTreeSet};
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

#[allow(unused_macros)]
macro_rules! ite {
    ($c:expr, $t:expr, $f:expr) => {{
        if $c { $t } else { $f }
    }};
}

// ref: tanakh <https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8>
// diff: using Parser
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut parser = Parser::from_str($s);
        input_inner!{parser, $($r)*}
    };
    (parser = $parser:ident, $($r:tt)*) => {
        input_inner!{$parser, $($r)*}
    };
    (new_stdin_parser = $parser:ident, $($r:tt)*) => {
        let stdin = std::io::stdin();
        let reader = std::io::BufReader::new(stdin.lock());
        let mut $parser = Parser::new(reader);
        input_inner!{$parser, $($r)*}
    };
    ($($r:tt)*) => {
        input!{new_stdin_parser = parser, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($parser:ident) => {};
    ($parser:ident, ) => {};
    ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($parser, $t);
        input_inner!{$parser $($r)*}
    };
}

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

fn main() {
    input! {
        s: chars,
    }
    if s.len() % 2 == 0 {
        let n = s.len();
        let m = s.len() / 2;
        let mut res = String::new();
        for i in (0..m).rev() {
            res.push(s[i]);
            res.push(s[n-i-1]);
        }
        println!("{}", res);
    }
    else {
        let n = s.len();
        let m = s.len() / 2;
        let mut res = String::new();
        res.push(s[m]);
        for i in (0..m).rev() {
            res.push(s[n-i-1]);
            res.push(s[i]);
        }
        println!("{}", res);
    }
}

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

// ref: tatsuya6502 <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e>
// ref: wariuni <https://qiita.com/tatsuya6502/items/cd448486f7ef7b5b8c7e#comment-7040a5ae96305e884eb9>
// diff: using std::io::BufRead::fill_buf()
pub struct Parser<R> {
    reader: R,
    buf: Vec<u8>,
    pos: usize,
}

impl Parser<io::Empty> {
    pub fn from_str(s: &str) -> Parser<io::Empty> {
        Parser {
            reader: io::empty(),
            buf: s.as_bytes().to_vec(),
            pos: 0,
        }
    }
}

impl<R:BufRead> Parser<R> {
    pub fn new(reader: R) -> Parser<R> {
        Parser {
            reader: reader,
            buf: vec![],
            pos: 0,
        }
    }
    pub fn update_buf(&mut self) {
        self.buf.clear();
        self.pos = 0;
        loop {
            let (len,complete) = {
                let buf2 = self.reader.fill_buf().unwrap();
                self.buf.extend_from_slice(buf2);
                let len = buf2.len();
                (len, buf2[len-1] <= 0x20)
            };
            self.reader.consume(len);
            if complete {
                break;
            }
        }
    }
    pub fn next<T:str::FromStr>(&mut self) -> Result<T, T::Err> {
        loop {
            let mut begin = self.pos;
            while begin < self.buf.len() && (self.buf[begin] <= 0x20) {
                begin += 1;
            }
            let mut end = begin;
            while end < self.buf.len() && (self.buf[end] > 0x20) {
                end += 1;
            }
            if begin != self.buf.len() {
                self.pos = end;
                return str::from_utf8(&self.buf[begin..end]).unwrap().parse::<T>();
            }
            else {
                self.update_buf();
            }
        }
    }
}

pub fn continuous_division<T:PartialEq+Eq+Clone+Copy>(xs: &[T]) -> Vec<(T,usize)> {
    let mut res = vec![];
    let n = xs.len();
    for i in 0..n {
        if i == 0 || xs[i-1] != xs[i] {
            res.push((xs[i], 1));
        }
        else {
            let m = res.len();
            res[m-1].1 += 1;
        }
    }
    res
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!();
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!();
}

use std::io;

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

fn next_index(len: usize, curr: usize, go_left: bool) -> Option<usize> {
    if len % 2 == 0 {
        if go_left {
            if len >= curr + 1 {
                Some(len - curr - 1)
            } else {
                None
            }
        } else {
            if len >= curr + 2 {
                Some(len - curr - 2)
            } else {
                None
            }
        }
    } else {
        if go_left {
            if len >= curr + 1 {
                Some(len - curr - 1)
            } else {
                None
            }
        } else {
            if len >= curr && len - curr < len {
                Some(len - curr)
            } else {
                None
            }
        }
    }
}

fn main() {
    let message = readln!();
    let message = message.chars().collect::<Vec<_>>();

    if message.len() == 1 {
        println!("z");
        return;
    }

    let mut index = (message.len() - 1) / 2;
    let mut go_left = true;
    loop {
        print!("{}", message[index]);

        match next_index(message.len(), index, go_left) {
            None => break,
            Some(new_index) => index = new_index
        };
        go_left = !go_left;
    }
    println!();
}


There is an infinite board of square tiles. Initially all tiles are white.Vova has a red marker and a blue marker. Red marker can color $$$a$$$ tiles. Blue marker can color $$$b$$$ tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be exactly $$$a$$$ red tiles and exactly $$$b$$$ blue tiles across the board.Vova wants to color such a set of tiles that:  they would form a rectangle, consisting of exactly $$$a+b$$$ colored tiles;  all tiles of at least one color would also form a rectangle. Here are some examples of correct colorings:  Here are some examples of incorrect colorings:  Among all correct colorings Vova wants to choose the one with the minimal perimeter. What is the minimal perimeter Vova can obtain?It is guaranteed that there exists at least one correct coloring.

A single line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^{14}$$$) — the number of tiles red marker should color and the number of tiles blue marker should color, respectively.

Print a single integer — the minimal perimeter of a colored rectangle Vova can obtain by coloring exactly $$$a$$$ tiles red and exactly $$$b$$$ tiles blue. It is guaranteed that there exists at least one correct coloring.

NoteThe first four examples correspond to the first picture of the statement.Note that for there exist multiple correct colorings for all of the examples.In the first example you can also make a rectangle with sides $$$1$$$ and $$$8$$$, though its perimeter will be $$$18$$$ which is greater than $$$8$$$.In the second example you can make the same resulting rectangle with sides $$$3$$$ and $$$4$$$, but red tiles will form the rectangle with sides $$$1$$$ and $$$3$$$ and blue tiles will form the rectangle with sides $$$3$$$ and $$$3$$$.

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

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

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

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

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

impl<T: Iterator> IteratorExt for T {}

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

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn divs(n: i64) -> Vec<i64> {
    let r = (n as f64).sqrt().ceil() as i64;

    let mut xs = vec![];

    for k in 1..r + 1 {
        if n % k == 0 {
            xs.push(k);
        }
    }

    xs
}

fn solve_core(a: i64, b: i64) -> i64 {
    let mut ts = divs(a);
    let ss = ts.iter().rev().map(|&t| a / t).vec();
    ts.extend(ss);

    let ys = divs(a + b);

    // debug!((a, b), ts, ys);

    let mut l = 0;
    let mut r = 0;
    let mut q: BinaryHeap<(Rev<i64>, usize)> = BinaryHeap::new();
    let mut mi = std::i64::MAX;

    for ti in 0..ts.len() {
        let t = ts[ti];

        while l < ys.len() && ys[l] < t {
            l += 1;
        }

        r = max(r, l);

        while r < ys.len() && (a + b) / ys[r] >= a / t {
            let y = ys[r];
            let x = (a + b) / y;
            q.push((Rev(2 * (y + x)), r));

            r += 1;
        }

        while let Some(&(_, yi)) = q.peek() {
            if l <= yi {
                break;
            }

            q.pop();
        }

        // debug!((ti, t, l, r));

        if let Some((Rev(p), _)) = q.pop() {
            // debug!(p);
            mi = min(mi, p);
        }
    }

    mi
}

fn solve(a: i64, b: i64) -> i64 {
    let mut mi = solve_core(a, b);
    if a != b {
        mi = min(mi, solve_core(b, a));
    }
    mi
}

fn main() {
    let (a, b) = read!(i64, i64);
    println!("{}", solve(a, b))
}

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

use std::ops::Range;

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

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

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

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

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

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

use std::io;

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

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

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

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

use std::io;

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

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

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

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

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

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let rin = buf.split_whitespace().map(|c| c.parse::<u64>().unwrap()).collect::<Vec<_>>();
    let n = rin[0] + rin[1];
    let m = cmp::min(rin[0], rin[1]);
    let ret1 = factors(n);
    let ret2 = factors(m);
    let mut p: u64 = 0;
    'find: for i in ret1.iter() {
        let x1 = i;
        let y1 = n / x1;
        for j in ret2.iter() {
            let x2 = j;
            let y2 = m / x2;
            if x2 <= x1 && y2 <= y1 {
                p = (x1 + y1) * 2;
                break 'find;
            }
        }
    }
    println!("{}", p);
}

fn factors(n: u64) -> Vec<u64> {
    let sqrt = (n as f64).sqrt() as u64;
    let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::<Vec<_>>();
    return ret;
}

use std::io;

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

    let ret1 = factors(n);
//    println!("{:?}", ret1);
    let ret3 = factors(rin[0]);
    let ret4 = factors(rin[1]);

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

fn factors(n: u64) -> Vec<u64> {
    let sqrt = (n as f64).sqrt() as u64;
    let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::<Vec<_>>();
    return ret;
}

use std::io;

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

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

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

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


You are given two lists of non-zero digits.Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?

The first line contains two integers n and m (1 ≤ n, m ≤ 9) — the lengths of the first and the second lists, respectively. The second line contains n distinct digits a1, a2, ..., an (1 ≤ ai ≤ 9) — the elements of the first list. The third line contains m distinct digits b1, b2, ..., bm (1 ≤ bi ≤ 9) — the elements of the second list.

NoteIn the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among them is 1, because it's the smallest positive integer.

use std::io;
use std::io::BufRead;

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

    lines.next().unwrap().unwrap();

    let mut first_list = [false; 10];
    let mut second_list = [false; 10];

    lines.next().unwrap().unwrap().split(" ")
        .map(|x| x.parse::<usize>().unwrap())
        .for_each(|x| first_list[x] = true);
    lines.next().unwrap().unwrap().split(" ")
        .map(|x| x.parse::<usize>().unwrap())
        .for_each(|x| second_list[x] = true);

    let mut min_first = 10;
    let mut min_second = 10;

    for i in 1..10 {
        if first_list[i] && second_list[i] {
            println!("{}", i);
            return;
        }
        if first_list[i] && min_first > i {
            min_first = i;
        }
        if second_list[i] && min_second > i {
            min_second = i;
        }
    }

    let result = if min_first > min_second {
        min_second * 10 + min_first
    } else {
        min_first * 10 + min_second
    };

    println!("{}", result);

}

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

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

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

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

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

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

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

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

fn main() {
    let (_n, _m): (usize, usize) = util::get2();
    let a: HashSet<usize> = util::gets().iter().cloned().collect();
    let b: HashSet<usize> = util::gets().iter().cloned().collect();

    for i in 1..100 {
        if i < 10 {
            if a.contains(&i) && b.contains(&i) {
                println!("{}", i);
                return;
            }
        } else {
            if (a.contains(&(i / 10)) || a.contains(&(i % 10))) &&
                (b.contains(&(i / 10)) || b.contains(&(i % 10)))
            {
                println!("{}", i);
                return;
            }
        }
    }
}

use std::io::{self, BufReader, Stdin};
use std::io::prelude::*;
use std::collections::BTreeSet;
use std::iter::Map;
use std::str::SplitWhitespace;

fn main() {
    let mut reader = ReadIn::new();

    reader.read_line();
    let a: BTreeSet<i32> = reader.read_iter().collect();
    let b: BTreeSet<i32> = reader.read_iter().collect();
    let c: BTreeSet<i32> = a.intersection(&b).map(|&x| x).collect();
    let res = (if !c.is_empty() { c.iter().map(|&x| x).next() } else {
        a.iter().next().and_then(
            |&ax| b.iter().next().map(
                |&bx| if (ax < bx) { ax * 10 + bx } else { bx * 10 + ax }))
    }).unwrap();
    print!("{}", res);
}

struct ReadIn { reader: BufReader<Stdin>, buf: String }

impl ReadIn {
    fn new() -> ReadIn { ReadIn { reader: BufReader::new(io::stdin()), buf: String::new() } }
    fn read_i32(s: &str) -> i32 { s.parse().unwrap() }
    fn read_line(&mut self) {
        self.buf.clear();
        self.reader.read_line(&mut self.buf);
    }
    fn read_iter(&mut self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.read_line();
        self.buf.split_whitespace().map(ReadIn::read_i32)
    }
    fn read_vec(&mut self) -> Vec<i32> {
        self.read_iter().collect()
    }
}

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

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

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

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

const N: i64 = 998_244_353;

fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {
    if b == 0 {
        (a, 1, 0)
    } else {
        let (d0, x0, y0) = extended_euclid(b, a % b);
        (d0, y0, x0 - a / b * y0)
    }
}

fn main() {
    let (n, m) = {
        let input = get_line();
        let mut it = input.split_whitespace().map(|k| k.parse::<usize>().unwrap());
        (
            it.next().unwrap(),
            it.next().unwrap(),
            )
    };

    let f_v: Vec<usize> = get_vec();
    let s_v: Vec<usize> = get_vec();

    let first_list = f_v.into_iter()
        .fold(vec![false; 9], |mut acc, d| {
            acc[d - 1] = true;
            acc
        });

    let second_list = s_v.into_iter()
        .fold(vec![false; 9], |mut acc, d| {
            acc[d - 1] = true;
            acc
        });

    if let Some(i) = (0..first_list.len()).filter(|&i| first_list[i] && second_list[i]).min() {
        println!("{}", i + 1);
    } else {
        let f = first_list.into_iter().position(|p| p).unwrap() + 1;
        let s = second_list.into_iter().position(|p| p).unwrap() + 1;
        print!("{}", min(f, s));
        println!("{}", max(f, s));
    }
}

use std::boxed::Box;
use std::cmp::*;
use std::io;

struct Rand {
    state: u64,
}

impl Rand {
    pub fn new() -> Self {
        Rand { state: 13 }
    }

    pub fn rand(&mut self) -> u64 {
        self.state = ((self.state ^ 1000000007) * 10000009) % 1000000013;
        self.state
    }
}

#[derive(Clone)]
struct Node<T: Ord + Clone> {
    pub key: T,
    pub weight: u64,
    pub left: Option<Box<Node<T>>>,
    pub right: Option<Box<Node<T>>>,
}

impl<T: Ord + Clone> Node<T> {
    fn new(value: T, weight: u64) -> Self {
        Node {
            key: value,
            weight: weight,
            left: None,
            right: None,
        }
    }

    pub fn split(
        node: Option<Box<Node<T>>>,
        key: &T,
    ) -> (Option<Box<Node<T>>>, Option<Box<Node<T>>>) {
        match node {
            None => (None, None),
            Some(mut node) => match node.key.cmp(key) {
                Ordering::Less => {
                    let (l, r) = Self::split(node.right, key);
                    node.right = l;
                    (Some(node), r)
                }
                _ => {
                    let (l, r) = Self::split(node.left, key);
                    node.left = r;
                    (l, Some(node))
                }
            },
        }
    }

    pub fn merge(left: Option<Box<Node<T>>>, right: Option<Box<Node<T>>>) -> Option<Box<Node<T>>> {
        match (left, right) {
            (None, None) => None,
            (left, None) => left,
            (None, right) => right,
            (Some(mut left), Some(mut right)) => match left.weight.cmp(&right.weight) {
                Ordering::Less => {
                    left.right = Self::merge(left.right, Some(right));
                    Some(left)
                }
                _ => {
                    right.left = Self::merge(Some(left), right.left);
                    Some(right)
                }
            },
        }
    }

    fn find(node: &Option<Box<Node<T>>>, key: &T) -> bool {
        match node {
            None => false,
            Some(node) => match node.key.cmp(key) {
                Ordering::Less => Self::find(&node.right, key),
                Ordering::Greater => Self::find(&node.left, key),
                Ordering::Equal => true,
            },
        }
    }

    fn less(node: &Box<Node<T>>) -> T {
        match node.left {
            None => node.key.clone(),
            Some(ref left) => Self::less(left),
        }
    }
}

struct Treap<T: Ord + Clone> {
    root: Option<Box<Node<T>>>,
}

impl<T: Ord + Clone + std::fmt::Display> Treap<T> {
    pub fn insert(&mut self, key: T, weight: u64) {
        let (mut l, r) = Node::split(self.root.take(), &key);
        l = Node::merge(l, Some(Box::new(Node::new(key, weight))));
        self.root = Node::merge(l, r);
    }

    pub fn delete(&mut self, key: &T) {
        let (l, mut r) = Node::split(self.root.take(), key);
        r = match r {
            None => None,
            Some(node) => {
                if &node.key == key {
                    Node::merge(node.left, node.right)
                } else {
                    Some(node)
                }
            }
        };
        self.root = Node::merge(l, r);
    }

    pub fn find(&self, key: &T) -> bool {
        Node::find(&self.root, key)
    }

    pub fn less(&self) -> Option<T> {
        match self.root {
            Some(ref root) => Some(Node::less(root)),
            _ => None,
        }
    }

    pub fn new() -> Self {
        Treap { root: None }
    }
}

fn main() {
    let mut buffer = String::new();
    let mut rand = Rand::new();
    io::stdin().read_line(&mut buffer);
    buffer = String::new();
    io::stdin().read_line(&mut buffer);
    buffer.retain(|s| s != '\r' && s != '\n');
    let a: Vec<u64> = buffer
        .split_whitespace()
        .map(|n| n.parse::<u64>().unwrap())
        .collect();

    buffer = String::new();
    io::stdin().read_line(&mut buffer);
    buffer.retain(|s| s != '\r' && s != '\n');
    let b: Vec<u64> = buffer
        .split_whitespace()
        .map(|n| n.parse::<u64>().unwrap())
        .collect();

    let mut t1 = Treap::new();
    let mut t2 = Treap::new();
    //println!("{:?} | {:?}", &a, &b);
    for n in a {
        t1.insert(n, rand.rand() as u64);
    }
    let mut m3 = 99;
    for n in b {
        t2.insert(n, rand.rand() as u64);
        if t1.find(&n) {
            m3 = std::cmp::min(m3, n);
        }
    }
    let (m1, m2) = (t1.less().unwrap(), t2.less().unwrap());

    if m1 != m2 && m3 < 99 {
        println!("{}", m3);
    } else {
        match m1.cmp(&m2) {
            Ordering::Less => println!("{}{}", m1, m2),
            Ordering::Greater => println!("{}{}", m2, m1),
            Ordering::Equal => println!("{}", m2),
        }
    }
}

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

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

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

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

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

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

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

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

fn main() {
    let (_n, _m): (usize, usize) = util::get2();
    let a: HashSet<usize> = util::gets().iter().cloned().collect();
    let b: HashSet<usize> = util::gets().iter().cloned().collect();

    for i in 1..99 {
        if i < 10 {
            if a.contains(&i) && b.contains(&i) {
                println!("{}", i);
                return;
            }
        } else {
            if a.contains(&(i / 10)) && b.contains(&(i % 10)) {
                println!("{}", i);
                return;
            }
        }
    }
}

use std::io::{self, BufReader, Stdin};
use std::io::prelude::*;
use std::collections::BTreeSet;
use std::iter::Map;
use std::str::SplitWhitespace;

fn main() {
    let mut reader = ReadIn::new();

    reader.read_line();
    let a: BTreeSet<i32> = reader.read_iter().collect();
    let b: BTreeSet<i32> = reader.read_iter().collect();
    let c: BTreeSet<i32> = a.intersection(&b).map(|&x| x).collect();
    let res = (if !c.is_empty() { c.iter().map(|&x| x).next() } else {
        a.iter().next().and_then(
            |ax| b.iter().next().map(
                |bx| ax * 10 + bx))
    }).unwrap();
    print!("{}", res);
}

struct ReadIn { reader: BufReader<Stdin>, buf: String }

impl ReadIn {
    fn new() -> ReadIn { ReadIn { reader: BufReader::new(io::stdin()), buf: String::new() } }
    fn read_i32(s: &str) -> i32 { s.parse().unwrap() }
    fn read_line(&mut self) {
        self.buf.clear();
        self.reader.read_line(&mut self.buf);
    }
    fn read_iter(&mut self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.read_line();
        self.buf.split_whitespace().map(ReadIn::read_i32)
    }
    fn read_vec(&mut self) -> Vec<i32> {
        self.read_iter().collect()
    }
}


A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.As before, the chessboard is a square-checkered board with the squares arranged in a 8 × 8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke.Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements.It goes without saying that in such business one should economize on everything — for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task.

The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row).

Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements.

WWWBWWBW
BBBBBBBB
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW
WWWBWWBW

WWWWWWWW
BBBBBBBB
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW
WWWWWWWW

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

const W: char = 'W';
const B: char = 'B';

fn parse_problem<B: BufRead>(input: B) -> io::Result<[[u8; 8]; 8]> {
    let mut matrix = [[0; 8]; 8];
    for (i, maybe_line) in input.lines().enumerate().take(8) {
        let line = maybe_line?;
        for (j, c) in line.chars().enumerate().take(8) {
            match c {
                B => matrix[i][j] = 1,
                W => {},
                _ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
                                               "not a B or W")),
            }
        }
    }
    Ok(matrix)
}

fn main() -> io::Result<()> {
    let board = parse_problem(io::stdin().lock())?;
    let mut r: u32 = 0;
    let mut c: u32 = 0;
    'outer_row: for i in 0..8 {
        for j in 0..8 {
            if board[i][j] == 0 {
                continue 'outer_row;
            }
        }
        r += 1;
    }
    'outer_col: for j in 0..8 {
        for i in 0..8 {
            if board[i][j] == 0 {
                continue 'outer_col;
            }
        }
        c += 1;
    }
    let result = if r < 8 && c < 8 { r + c } else { 8 };
    println!("{}", result);
    Ok(())
}

macro_rules! scanln {
    () => ({
        let mut buffer = String::new();
        ::std::io::stdin().read_line(&mut buffer).expect("Unable to read line");
        buffer
    });
    ($($t: ty),+) => ({
        scanln!($($t),+, |c: char| c.is_whitespace())
    });
    ($($t: ty),+, $sp: expr) => ({
        let mut buffer = scanln!();
        let mut iter = buffer.split($sp);
        ($(iter.next().unwrap().parse::<$t>().expect("Unable to parse token")),+)
    });
}

fn main() {
    let mut board = Vec::new();
    let mut count = 0;
    let mut checked = false;
    for _ in 0..8 {
        let line = scanln!(String);
        let row: Vec<char> = line.split(' ').flat_map(|s| s.chars()).collect();
        board.push(row);
    }
    for r in board {
        let blacks = r.iter().filter(|c| **c == 'B').count();
        count += if blacks == 8 {
            1
        } else if blacks > 0 && !checked {
            checked = true;
            blacks
        } else {
            0
        }
    }
    println!("{}", count);
}

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

fn main() {
    let mut counter = 0;
    let mut col_checked = false;

    for i in 0..8 {
        let mut input_text = String::new();
        io::stdin()
            .read_line(&mut input_text)
            .expect("failed to read from stdin");

        let trimmed = input_text.trim();
        if (trimmed.eq("BBBBBBBB")) {
            counter = counter + 1;
            continue;
        }

        if (col_checked) {
            continue;
        }

        col_checked = true;
        for j in 0..8 {
            let char_at = trimmed.as_bytes()[j];
            if ((char_at as char) == 'B') {
                counter = counter + 1;
            }
        }
    }

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


You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors.Consider positive integers a, a + 1, ..., b (a ≤ b). You want to find the minimum integer l (1 ≤ l ≤ b - a + 1) such that for any integer x (a ≤ x ≤ b - l + 1) among l integers x, x + 1, ..., x + l - 1 there are at least k prime numbers. Find and print the required minimum l. If no value l meets the described limitations, print -1.

A single line contains three space-separated integers a, b, k (1 ≤ a, b, k ≤ 106; a ≤ b).

In a single line print a single integer — the required minimum l. If there's no solution, print -1.

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

// Be careful for n = 10^6. In Codeforces, usize is a 32-bit integer.
fn sieve(n: i64) -> (Vec<i64>, Vec<bool>) {
    let mut is_prime = vec![true; (n as usize) + 1];
    is_prime[0] = false;
    is_prime[1] = false;
    let mut primes = Vec::new();
    for i in 2..=n {
        if is_prime[i as usize] {
            primes.push(i);
            let mut j = i * i;
            while j <= n {
                is_prime[j as usize] = false;
                j += i;
            }
        }
    }
    (primes, is_prime)
}

fn lower_bound(arr: &[i64], target: i64) -> usize {
    let mut lo = 0;
    let mut hi = arr.len();
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if arr[mid] >= target {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    lo
}

fn count_primes(primes: &[i64], lo: i64, hi: i64) -> i64 {
    // How many primes are there in [lo, hi]?
    let lb_1 = lower_bound(primes, lo) as i64;
    let lb_2 = lower_bound(primes, hi + 1) as i64;
    lb_2 - lb_1
}

fn pred(a: i64, b: i64, k: i64, l: i64, primes: &[i64], is_prime: &[bool]) -> bool {
    // For ALL x in [a, b - l + 1], are there at least k prime numbers in [x, x + l - 1]?

    // window: [a, a + l - 1]
    let mut prime_count = count_primes(primes, a, a + l - 1);
    if prime_count < k {
        return false;
    }
    for x in (a + 1)..=(b - l + 1) {
    // for i in 1..(b - l - a + 2) {
    //     let x = a + i;
        // window: [x, x + l - 1]
        // previous window: [x - 1, x + l - 2]
        // if x - 1 was prime, remove it
        if is_prime[(x - 1) as usize] {
            prime_count -= 1;
        }

        // if x + l - 1 is prime, add it
        if is_prime[(x + l - 1) as usize] {
            prime_count += 1;
        }

        if prime_count < k {
            return false;
        }
    }
    true
}

fn search_l(a: i64, b: i64, k: i64, primes: &[i64], is_prime: &[bool]) -> i64 {
    let mut lo = 1;
    let mut hi = b - a + 2;
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if pred(a, b, k, mid, primes, is_prime) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    if lo == b - a + 2 {
        -1
    } else {
        lo
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let a: i64 = scan.token();
    let b: i64 = scan.token();
    let k: i64 = scan.token();

    let (primes, is_prime) = sieve(1000005);
    let ans = search_l(a, b, k, &primes, &is_prime);
    writeln!(out, "{}", ans).ok();
}

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

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

// Be careful for n = 10^6. In Codeforces, usize is a 32-bit integer.
fn sieve(n: i64) -> (Vec<i64>, Vec<bool>) {
    let mut is_prime = vec![true; (n as usize) + 1];
    let mut primes = Vec::new();
    for i in 2..=n {
        if is_prime[i as usize] {
            primes.push(i);
            let mut j = i * i;
            while j <= n {
                is_prime[j as usize] = false;
                j += i;
            }
        }
    }
    (primes, is_prime)
}

fn lower_bound(arr: &[i64], target: i64) -> usize {
    let mut lo = 0;
    let mut hi = arr.len();
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if arr[mid] >= target {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    lo
}

fn count_primes(primes: &[i64], lo: i64, hi: i64) -> i64 {
    // How many primes are there in [lo, hi]?
    let lb_1 = lower_bound(primes, lo) as i64;
    let lb_2 = lower_bound(primes, hi + 1) as i64;
    lb_2 - lb_1
}

fn pred(a: i64, b: i64, k: i64, l: i64, primes: &[i64], is_prime: &[bool]) -> bool {
    // For ALL x in [a, b - l + 1], are there at least k prime numbers in [x, x + l - 1]?

    // window: [a, a + l - 1]
    let mut prime_count = count_primes(primes, a, a + l - 1);
    if prime_count < k {
        return false;
    }
    for i in 1..(b - l - a + 2) {
        // x = a + i
        // window: [a + i, a + i + l - 1] = [x, x + l - 1]
        // previous window: [x - 1, x + l - 2]
        // if a + i - 1 was prime, remove it
        if is_prime[(a + i - 1) as usize] {
            prime_count -= 1;
        }

        // if a + i + l - 1 is prime, add it
        if is_prime[(a + i + l - 1) as usize] {
            prime_count += 1;
        }

        if prime_count < k {
            return false;
        }
    }
    true
}

fn search_l(a: i64, b: i64, k: i64, primes: &[i64], is_prime: &[bool]) -> i64 {
    let mut lo = 1;
    let mut hi = b - a + 2;
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if pred(a, b, k, mid, primes, is_prime) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    if lo == b - a + 2 {
        -1
    } else {
        lo
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let a: i64 = scan.token();
    let b: i64 = scan.token();
    let k: i64 = scan.token();

    let (primes, is_prime) = sieve(1000005);
    let ans = search_l(a, b, k, &primes, &is_prime);
    writeln!(out, "{}", ans).ok();
}

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

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 sieve(n: i64) -> Vec<i64> {
    let n = n as usize;
    let mut is_prime = vec![true; n + 1];
    let mut primes = Vec::new();
    for i in 2..=n {
        if is_prime[i] {
            primes.push(i as i64);
            let mut j = i * i;
            while j <= n {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    primes
}

fn lower_bound(arr: &[i64], target: i64) -> usize {
    let mut lo = 0;
    let mut hi = arr.len();
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if arr[mid] >= target {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    lo
}

fn at_least_k_primes(primes: &[i64], lo: i64, hi: i64, k: i64) -> bool {
    // Are there at least k prime numbers in the interval [lo, hi]?
    let lb_1 = lower_bound(primes, lo) as i64;
    let lb_2 = lower_bound(primes, hi + 1) as i64;
    (lb_2 - lb_1) >= k
}

fn pred(a: i64, b: i64, k: i64, l: i64, primes: &[i64]) -> bool {
    // For ALL x in [a, b - l + 1], are there at least k prime numbers in [x, x + l - 1]?
    for x in a..=(b - l + 1) {
        if !at_least_k_primes(primes, x, x + l - 1, k) {
            return false;
        }
    }
    true
}

fn search_l(a: i64, b: i64, k: i64, primes: &[i64]) -> i64 {
    let mut lo = 1;
    let mut hi = b - a + 2;
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if pred(a, b, k, mid, primes) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    if lo == b - a + 2 {
        -1
    }
    else {
        lo
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let a: i64 = scan.token();
    let b: i64 = scan.token();
    let k: i64 = scan.token();

    let primes = sieve(1000005);
    let ans = search_l(a, b, k, &primes);
    writeln!(out, "{}", ans).ok();
}

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

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 sieve(n: i64) -> Vec<i64> {
    let n = n as usize;
    let mut is_prime = vec![true; n + 1];
    let mut primes = Vec::new();
    for i in 2..=n {
        if is_prime[i] {
            primes.push(i as i64);
            let mut j = i * i;
            while j <= n {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    primes
}

fn lower_bound(arr: &[i64], target: i64) -> usize {
    let mut lo = 0;
    let mut hi = arr.len();
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if arr[mid] >= target {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    lo
}

fn at_least_k_primes(primes: &[i64], lo: i64, hi: i64, k: i64) -> bool {
    // Are there at least k prime numbers in the interval [lo, hi]?
    let lb_1 = lower_bound(primes, lo) as i64;
    let lb_2 = lower_bound(primes, hi + 1) as i64;
    (lb_2 - lb_1) >= k
}

fn pred(a: i64, b: i64, k: i64, l: i64, primes: &[i64]) -> bool {
    // For ALL x in [a, b - l + 1], are there at least k prime numbers in [x, x + l - 1]?
    for x in a..=(b - l + 1) {
        if !at_least_k_primes(primes, x, x + l - 1, k) {
            return false;
        }
    }
    true
}

fn search_l(a: i64, b: i64, k: i64, primes: &[i64]) -> i64 {
    let mut lo = 1;
    let mut hi = b - a + 2;
    while lo < hi {
        let mid = lo + (hi - lo) / 2;
        if pred(a, b, k, mid, primes) {
            hi = mid;
        } else {
            lo = mid + 1;
        }
    }
    if lo == b - a + 2 {
        -1
    }
    else {
        lo
    }
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let a: i64 = scan.token();
    let b: i64 = scan.token();
    let k: i64 = scan.token();

    let primes = sieve(1000000);
    let ans = search_l(a, b, k, &primes);
    writeln!(out, "{}", ans).ok();
}

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


Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.   Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

The only line contains 14 integers $$$a_1, a_2, \ldots, a_{14}$$$ ($$$0 \leq a_i \leq 10^9$$$) — the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\leq i \leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.

Output one integer, the maximum possible score after one move.

NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$.

// Try Codeforces
// author: Leonardone @ NEETSDKASU

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

    let n = 14;
    let mut xs = vec![];
    for _ in 0..n {
        let x = get!();
        xs.push(x);
    }
    let mut ans = 0;
    for i in 0..n {
        let x = xs[i];
        let d = x / 14;
        let r = (x % 14) as usize;
        xs[i] = 0;
        let mut tmp = 0;
        for j in 0..n {
            let mut e = xs[j] + d;
            if i < j && j <= i + r {
                e += 1;
            } else if i < j + 14 && j + 14 <= i + r {
                e += 1;
            }
            if e % 2 == 0 {
                tmp += e;
            }
        }
        ans = std::cmp::max(ans, tmp);
        xs[i] = x;
    }
    println!("{}", ans);
}

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

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

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

    let mut max_ans = 0;

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

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

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

            j += 1
        }

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

        if max_ans < ans {
            max_ans = ans;
        }
    }

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

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

fn main() {
    let stdin = stdin();
    let mut sc = Scanner::new(stdin.lock());
    let mut a: [usize; 14] = [0; 14];
    for i in 0..14 {
        a[i] = sc.next::<usize>();
    }
    let mut max: u64 = 0;
    for i in 0..14 {
        if a[i] == 0 {
            continue;
        }
        let mut b: [usize; 14] = a.clone();
        b[i] = 0;
        for j in 0..14 {
            b[(i + j + 1) % 14] += a[i] / 14 + (if j < a[i] % 14 { 1 } else { 0 });
        }

        let mut sum: u64 = 0;
        for j in 0..14 {
            if b[j] % 2 == 0 {
                sum += b[j] as u64;
            }
        }
        max = std::cmp::max(max, sum);
    }
    println!("{}", max);
}

// 基本的に 14 割った数足す

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

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

    pub fn next<T: 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()
        }
    }
}

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

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

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

    let mut max_ans = 0;

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

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

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

            j += 1
        }

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

        if max_ans < ans {
            max_ans = ans;
        }
    }

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

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

fn main() {
    let stdin = stdin();
    let mut sc = Scanner::new(stdin.lock());
    let mut a: [usize; 14] = [0; 14];
    for i in 0..14 {
        a[i] = sc.next::<usize>();
    }
    let mut max = 0;
    for i in 0..14 {
        if a[i] == 0 {
            continue;
        }
        let mut b: [usize; 14] = a.clone();
        b[i] = 0;
        for j in 0..14 {
            b[(i + j + 1) % 14] += a[i] / 14 + (if j < a[i] % 14 { 1 } else { 0 });
        }

        let mut sum = 0;
        for j in 0..14 {
            if b[j] % 2 == 0 {
                sum += b[j]
            }
        }
        max = std::cmp::max(max, sum);
    }
    println!("{}", max);
}

// 基本的に 14 割った数足す

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

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

    pub fn next<T: 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()
        }
    }
}


This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1  ≤  p1 < p2 < ... < pk  ≤  |s|) a subsequence of string s = s1s2... s|s|, where |s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1 = y1, x2 = y2, ..., x|y| = y|y|, or there exists such number r (r < |x|, r < |y|) that x1 = y1, x2 = y2, ..., xr = yr and xr  +  1 > yr  +  1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s| - 1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

Print the lexicographically largest palindromic subsequence of string s.

NoteAmong all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr".

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

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

    stdin.lock().read_line(&mut input).unwrap();

    let seq = input.trim().as_bytes();

    let n = seq.len();
    let mut largest = seq.to_vec();
    for i in 1..2usize.pow(n as u32) {
        let mut subseq = Vec::with_capacity(n);
        for k in 0..n {
            if i >> k & 1 == 1 {
                subseq.push(seq[k])
            }
        }
        if !is_palindrome(&subseq) {
            continue;
        }
        if is_lexicographically_larger(&subseq, &largest) {
            largest = subseq;
        }
    }
    println!("{}", String::from_utf8_lossy(&largest));
}

fn is_palindrome(seq: &[u8]) -> bool{
    for i in 0..seq.len()/2 {
        if seq[i] != seq[seq.len()-i-1] {
            return false;
        }
    }

    true
}

fn is_lexicographically_larger(a: &[u8], b: &[u8]) -> bool {
    let mut i = 0;
    let mut same = true;

    while i < a.len() && i < b.len() {
        if same {
            if a[i] != b[i] {
                same = false;
            }
        }

        if !same {
            if a[i] <= b[i] {
                return false;
            }
        }
        i += 1;
    }
    true
}


We all know that GukiZ often plays with arrays. Now he is thinking about this problem: how many arrays a, of length n, with non-negative elements strictly less then 2l meet the following condition: ? Here operation  means bitwise AND (in Pascal it is equivalent to and, in C/C++/Java/Python it is equivalent to &), operation  means bitwise OR (in Pascal it is equivalent to , in C/C++/Java/Python it is equivalent to |). Because the answer can be quite large, calculate it modulo m. This time GukiZ hasn't come up with solution, and needs you to help him!

First and the only line of input contains four integers n, k, l, m (2 ≤ n ≤ 1018, 0 ≤ k ≤ 1018, 0 ≤ l ≤ 64, 1 ≤ m ≤ 109 + 7).

In the single line print the number of arrays satisfying the condition above modulo m.

NoteIn the first sample, satisfying arrays are {1, 1}, {3, 1}, {1, 3}.In the second sample, only satisfying array is {1, 1}.In the third sample, satisfying arrays are {0, 3, 3}, {1, 3, 2}, {1, 3, 3}, {2, 3, 1}, {2, 3, 3}, {3, 3, 0}, {3, 3, 1}, {3, 3, 2}, {3, 3, 3}.

//spnauti-rusT {{{
use std::io::*; use std::str::{self,*}; use std::fmt::Debug;
#[allow(unused_imports)] use std::cmp::Ordering::{self,*};
#[allow(unused_imports)] use std::ops::{self,*};
#[allow(unused_imports)] use std::iter::{self,*};
#[allow(unused_imports)] use std::collections::*;
#[allow(unused_imports)] use std::cell::*;
#[allow(unused_macros)] macro_rules! 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),+ =$e:expr) => {$(let$v=$e;)+};
	($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};
	(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};
	(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};
}
#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }
#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }
#[allow(dead_code)] fn writer() -> BufWriter<Stdout> { BufWriter::new(stdout()) }
struct WordReaderC {buf: Vec<u8>, pos: usize, q: std::io::StdinLock<'static>}//'
#[allow(dead_code)] impl WordReaderC {
	fn new() -> Self {
		let r = unsafe {&*Box::into_raw(Box::new(stdin()))};
		Self { q: r.lock(), buf: Vec::new(), pos: 0 }
	}
	fn next_line(&mut self) -> bool {
		self.buf.clear(); self.pos = 0;
		self.q.read_until(b'\n', &mut self.buf).unwrap_or(0) > 0
	}
	fn is_ws(c: u8) -> bool {
		c == b' ' || c == b'\r' || c == b'\n' || c == b'\t'
	}
	fn byte(&mut self) -> Option<u8> {
		if self.pos == self.buf.len() { if !self.next_line() { return None; } }
		self.pos += 1; Some(self.buf[self.pos - 1])
	}
	fn vb(&mut self) -> Vec<u8> {
		let mut s = Vec::with_capacity(8);
		let mut f = false;
		loop {
			if let Some(c) = self.byte() {
				if !Self::is_ws(c) {
					s.push(c);
					f = true;
				} else if f { break; }
			} else { break; }
		}
		s
	}
	fn s(&mut self) -> String { String::from_utf8(self.vb()).expect("invalid utf8") }
	fn i(&mut self) ->    i32 { self.p() }
	fn l(&mut self) ->    i64 { self.p() }
	fn u(&mut self) ->  usize { self.p() }
	fn f(&mut self) ->    f64 { self.p() }
	fn vi(&mut self, n: usize) -> Vec<i32> { self.vp(n) }
	fn vl(&mut self, n: usize) -> Vec<i64> { self.vp(n) }
	fn vu(&mut self, n: usize) -> Vec<usize> { self.vp(n) }
	fn ii(&mut self, n: usize) -> impl Iterator<Item=i32> { self.ip(n).into_iter() }
	fn iu(&mut self, n: usize) -> impl Iterator<Item=usize> { self.ip(n).into_iter() }
	fn p<T: FromStr>(&mut self) -> T where T::Err: Debug {
		let w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::<T>().unwrap()
	}
	fn vp<T: FromStr>(&mut self, n: usize) -> Vec<T> where T::Err: Debug {
		(0..n).map(|_|self.p()).collect()
	}
	fn ip<T: FromStr>(&mut self, n: usize) -> impl Iterator<Item=T> where T::Err: Debug {
		self.vp(n).into_iter()
	}
}
//------------------- End rusT }}}

// Mint (mod any) {{{
mod mint {
	use std::ops::*;
	#[derive(Debug,Clone,Copy,PartialEq,Eq,PartialOrd,Ord,Default)] pub struct Mint(i32,i32);
	#[allow(dead_code)] impl Mint {
		pub fn new<T: Copy+Into<i64>>(a: T, m: T) -> Self { Self(Self::cv(a,m),m.into() as i32) }
		pub unsafe fn new_unchecked(a: i32, m: i32) -> Self { Self(a,m) }
		fn hi(mut a: i32, m: i32) -> i32 { if a >= m { a -= m; } a }
		fn lo(mut a: i32, m: i32) -> i32 { if a < 0 { a += m; } a }
		fn cv<T: Copy+Into<i64>>(a: T, m: T) -> i32 { Self::lo((a.into() % m.into()) as i32, m.into() as i32) }
		pub unsafe fn inv(self) -> Self { self.pow(self.1-2) } // ONLY FOR PRIMES!
		pub fn pow<T: Copy+Into<i64>>(self, b: T) -> Self {
			let b = b.into(); if b == 0 { Self(1,self.1) } else {
				let mut res = self.pow(b/2); res *= res; if b % 2 == 1 {res *= self;} res
			}
		}
	}
	impl Add for Mint { type Output = Self; fn add(self, a: Self) -> Self::Output { assert!(self.1==a.1); Self(Self::hi(self.0 + a.0, self.1), self.1) }}
	impl Sub for Mint { type Output = Self; fn sub(self, a: Self) -> Self::Output { assert!(self.1==a.1); Self(Self::lo(self.0 - a.0, self.1), self.1) }}
	impl Mul for Mint { type Output = Self; fn mul(self, a: Self) -> Self::Output { assert!(self.1==a.1); Self(Self::cv(self.0 as i64 * a.0 as i64, self.1 as i64), self.1) }}
	impl Div for Mint { type Output = Self; fn div(self, a: Self) -> Self::Output { self * unsafe {a.inv()} }}
	impl Neg for Mint { type Output = Self; fn neg(self) -> Self::Output { Self(Self::lo(-self.0, self.1), self.1) }}
	impl AddAssign for Mint { fn add_assign(&mut self, a: Self) { *self = *self + a; } }
	impl SubAssign for Mint { fn sub_assign(&mut self, a: Self) { *self = *self - a; } }
	impl MulAssign for Mint { fn mul_assign(&mut self, a: Self) { *self = *self * a; } }
	impl DivAssign for Mint { fn div_assign(&mut self, a: Self) { *self = *self / a; } }
	use std::fmt::{Display, Formatter, Result};
	impl Display for Mint { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, "{}", self.0) } }
}
use mint::Mint;
//}}}
// Square Matrix (any) {{{
type MatT = Mint;
#[derive(Debug,Clone)] struct Mat { n: usize, a: Vec<MatT>, v0: MatT, v1: MatT }
#[allow(dead_code)] impl Mat {
	fn new(n:usize,v0:MatT,v1:MatT)->Self{Self{n,a:vec![v0;n*n],v0,v1}}
	fn diag(n:usize,v0:MatT,v1:MatT,v:MatT)->Self{let mut m=Self::new(n,v0,v1);let mut p=0;for _ in 0..n{m.a[p]=v;p+=n+1;}m}
	fn pow(&self,n:u64)->Self{if n==0{Self::diag(self.n,self.v0,self.v1,self.v1)}else{let mut t=self.pow(n/2);t*=t.clone();if n%2==1{t*=self.clone();}t}}
	fn range(&self,r:Range<usize>,c:Range<usize>)->Vec<Vec<MatT>>{if r.start<r.end||c.start<c.end{Vec::new()}else{let mut res=vec![vec![self.v0;c.end-c.start];r.end-r.start];
		for i in r.start..r.end{let ir=i-r.start;let ii=i*self.n+c.start;for j in 0..c.end-c.start{res[ir][j]=self.a[ii+j];}}res}}
	fn at(&self,r:usize,c:usize)->MatT{self.a[r*self.n+c]}
	fn at_mut<'a>(&'a mut self,r:usize,c:usize)->&'a mut MatT{&mut self.a[r*self.n+c]}//'
}
impl Mul for Mat{type Output=Self;fn mul(self,o:Self)->Self::Output{assert!(self.n==o.n);let n=self.n;let mut res=Self::new(n,self.v0,self.v1);
	for ii in(0..n).map(|i|i*n){for j in 0..n{let mut t=self.v0;let mut kk=j;for k in 0..n{t+=self.a[ii+k]*o.a[kk];kk+=n;}res.a[ii+j]=t;}}res}}
impl Add for Mat{type Output=Self;fn add(mut self,o:Self)->Self{self+=o;self}}
impl Sub for Mat{type Output=Self;fn sub(mut self,o:Self)->Self{self-=o;self}}
impl MulAssign for Mat{fn mul_assign(&mut self,a:Self){*self=self.clone()*a;}}
impl AddAssign for Mat{fn add_assign(&mut self,o:Self){assert!(self.n==o.n);for(x,y)in self.a.iter_mut().zip(o.a.into_iter()){*x+=y;}} }
impl SubAssign for Mat{fn sub_assign(&mut self,o:Self){assert!(self.n==o.n);for(x,y)in self.a.iter_mut().zip(o.a.into_iter()){*x-=y;}} }
impl PartialEq for Mat{fn eq(&self,o:&Self)->bool{self.n==o.n&&self.a==o.a}}impl Eq for Mat{}
// }}}

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

	l!(n,k,l,m = rin.l());
	if l <= 60 && k >= 1 << l {
		writeln!(rout, "0").ok();
		return;
	}
	let m0 = Mint::new(0,m);
	let m1 = Mint::new(1,m);

	let b1 = k.count_ones() as i64;
	let b0 = l - b1;
	let mut f = Mat::new(2,m0,m1);
	*f.at_mut(0,0) = m0;
	*f.at_mut(0,1) = m1;
	*f.at_mut(1,0) = m1;
	*f.at_mut(1,1) = m1;
	let res_f = f.pow(n as u64 + 2).at(0,1);
	let res_b = Mint::new(2,m).pow(n);
	let sol = (res_b - res_f).pow(b1) * res_f.pow(b0);
	writeln!(rout, "{}", sol).ok();
}


Let's call an array a of size n coprime iff gcd(a1, a2, ..., an) = 1, where gcd is the greatest common divisor of the arguments.You are given two numbers n and k. For each i (1 ≤ i ≤ k) you have to determine the number of coprime arrays a of size n such that for every j (1 ≤ j ≤ n) 1 ≤ aj ≤ i. Since the answers can be very large, you have to calculate them modulo 109 + 7.

The first line contains two integers n and k (1 ≤ n, k ≤ 2·106) — the size of the desired arrays and the maximum upper bound on elements, respectively.

Since printing 2·106 numbers may take a lot of time, you have to output the answer in such a way: Let bi be the number of coprime arrays with elements in range [1, i], taken modulo 109 + 7. You have to print , taken modulo 109 + 7. Here  denotes bitwise xor operation (^ in C++ or Java, xor in Pascal).

NoteExplanation of the example:Since the number of coprime arrays is large, we will list the arrays that are non-coprime, but contain only elements in range [1, i]:For i = 1, the only array is coprime. b1 = 1.For i = 2, array [2, 2, 2] is not coprime. b2 = 7.For i = 3, arrays [2, 2, 2] and [3, 3, 3] are not coprime. b3 = 25.For i = 4, arrays [2, 2, 2], [3, 3, 3], [2, 2, 4], [2, 4, 2], [2, 4, 4], [4, 2, 2], [4, 2, 4], [4, 4, 2] and [4, 4, 4] are not coprime. b4 = 55.

// ---------- begin ModInt ----------
const MOD: u32 = 1_000_000_007;

#[derive(Clone, Copy)]
struct ModInt(u32);

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

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

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

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

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

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

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

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

impl std::str::FromStr for ModInt {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl From<usize> for ModInt {
    fn from(val: usize) -> ModInt {
        ModInt((val % MOD as usize) as u32)
    }
}

#[allow(dead_code)]
impl ModInt {
    pub fn new(n: u32) -> ModInt {
        ModInt(n % MOD)
    }
    pub fn zero() -> ModInt {
        ModInt(0)
    }
    pub fn one() -> ModInt {
        ModInt(1)
    }
    pub fn pow(self, mut n: u32) -> ModInt {
        let mut t = ModInt::one();
        let mut s = self;
        while n > 0 {
            if n & 1 == 1 {
                t *= s;
            }
            s *= s;
            n >>= 1;
        }
        t
    }
    pub fn inv(self) -> ModInt {
        assert!(self.0 > 0);
        self.pow(MOD - 2)
    }
}
// ---------- end ModInt ----------

fn run() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: u32 = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let mut is_prime = vec![true; k + 1];
    for i in 2.. {
        if i * i > k {
            break;
        }
        if is_prime[i] {
            let mut j = i * i;
            while let Some(p) = is_prime.get_mut(j) {
                *p = false;
                j += i;
            }
        }
    }
    let mut mobius = vec![ModInt::one(); k + 1];
    for (i, p) in is_prime.into_iter().enumerate().skip(2) {
        if !p {
            continue;
        }
        let mut j = i;
        while let Some(x) = mobius.get_mut(j) {
            *x = -*x;
            j += i;
        }
        let k = i.saturating_mul(i);
        let mut j = k;
        while let Some(x) = mobius.get_mut(j) {
            *x = ModInt::zero();
            j += k;
        }
    }
    let pow: Vec<ModInt> = (0..=k).map(|k| ModInt::from(k).pow(n)).collect();
    let mut imos = vec![ModInt::zero(); 2 * k + 1];
    for (i, v) in mobius.into_iter().enumerate().skip(2) {
        if v.0 == 0 {
            continue;
        }
        for (x, &pow) in pow.iter().enumerate().skip(1) {
            if x * i > k {
                break;
            }
            let v = v * pow;
            let l = x * i;
            let r = (x + 1) * i;
            imos[l] += v;
            imos[r] -= v;
        }
    }
    let mut ans = ModInt::zero();
    for i in 1..=k {
        imos[i] = imos[i] + imos[i - 1];
        let way = ModInt::from(i).pow(n) + imos[i];
        ans += ModInt::new(way.0 ^ i as u32);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Imp likes his plush toy a lot.  Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly x copied toys and y original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.

The only line contains two integers x and y (0 ≤ x, y ≤ 109) — the number of copies and the number of original toys Imp wants to get (including the initial one).

Print "Yes", if the desired configuration is possible, and "No" otherwise. You can print each letter in arbitrary case (upper or lower).

NoteIn the first example, Imp has to apply the machine twice to original toys and then twice to copies.

/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Sat 10 Feb 2018 18:51:25
 *
 */

fn check(copy: i32, origin: i32) -> bool {
  let y = origin - 1;
  let x = copy - y;

  return y == 0 && x == 0 || x >= 0 && y > 0 && x % 2 == 0;
}

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

  let mut numbers = buffer.split_whitespace();

  let copy:i32 = numbers.next().unwrap().parse().unwrap();
  let origin:i32 = numbers.next().unwrap().parse().unwrap();

  if check(copy, origin) {
    println!("Yes");
  } else {
    println!("No");
  }

}

// Try Codeforces
// author: Leonardone @ NEETSDKASU

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

    let x = get!();
    let y = get!();

    if y == 0 || (y == 1 && x > 0) || x < y - 1 {
        println!("No");
        return;
    }

    let d = x - (y - 1);

    if d % 2 != 0 {
        println!("No");
        return;
    }

    println!("Yes");

}

use std::io;

fn main() {

    let mut str = String::new();

    io::stdin().read_line(&mut str).expect("You are failure");

    let mut vals = [0; 2];

    let str = str.trim().split(" ");

    let mut f = 0;
    for i in str{
        vals[f] = i.parse().expect("err");
        f+=1;
    }

    let mut printable = true;

    if vals[1] == 0 || (vals[0]%2 == vals[1]%2) || (vals[1]==1 && vals[0] != 0) || vals[1] > vals[0] + 1{
        printable = false;
    }

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

}

/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Sat 10 Feb 2018 18:51:25
 *
 */
// n - c, m - o
//
// 6 3
//
// 2x + y = n
// 1 + y = m
//
// y = 2

fn check(copy: i32, origin: i32) -> bool {
  let y = origin - 1;
  let x = copy - y;

  return x >= 0 && y >= 0 && x % 2 == 0;
}

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

  let mut numbers = buffer.split_whitespace();

  let copy:i32 = numbers.next().unwrap().parse().unwrap();
  let origin:i32 = numbers.next().unwrap().parse().unwrap();

  if check(copy, origin) {
    println!("Yes");
  } else {
    println!("No");
  }

}

use std::io;

fn main() {

    let mut str = String::new();

    io::stdin().read_line(&mut str).expect("You are failure");

    let mut vals = [0; 2];

    let str = str.trim().split(" ");

    let mut f = 0;
    for i in str{
        vals[f] = i.parse().expect("err");
        f+=1;
    }

    let mut printable = true;

    if vals[1] == 0 || (vals[0]%2 == vals[1]%2) || (vals[1]==1 && vals[0] != 0) {
        printable = false;
    }

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

}

use std::io;

fn main() {

    let mut str = String::new();

    io::stdin().read_line(&mut str).expect("You are failure");

    let mut vals = [0; 2];

    let str = str.trim().split(" ");

    let mut f = 0;
    for i in str{
        vals[f] = i.parse().expect("err");
        f+=1;
    }

    let mut printable = true;

    if vals[1] == 0 || (vals[0]%2 == vals[1]%2) || (vals[1]==1 && vals[0] != 0) || vals[0] > vals[1] + 1{
        printable = false;
    }

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

}