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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

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

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn main() {
    input! {
        s: chars,
    }

    let mut ans = (s.len() + 1) / 2;

    let mut ok = false;
    for i in 1..s.len() {
        if s[i] == '1' {
            ok = true;
        }
    }
    if !ok {
        ans -= 1;
    }

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


use std::io;

macro_rules! parse_input {
    ($x:expr, $t:ident) => ($x.parse::<$t>().unwrap())
}

macro_rules! parse_inputs {
    ($x:expr, $t:ident) => ($x.map(|s| s.parse::<$t>().unwrap()).collect::<Vec<$t>>())
}

macro_rules! print_err {
    ($($arg:tt)*) => (
        {
            use std::io::Write;
            writeln!(&mut ::std::io::stderr(), $($arg)*).ok();
        }
    )
}

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

    let mut max = 0;
    let mut j = 0;
    for c in cs {
        j += 1;
        if c == 'A' || c == 'I' || c == 'U' || c == 'E' || c == 'O' || c == 'Y' {
            if max < j {
                max = j;
            }
            j = 0;
        }
    }
    j += 1;
    if max < j {
        max = j;
    }
    println!("{}", max);
}


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

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

    let m = "AEIOU".chars().collect::<std::collections::HashSet<_>>();
    let mut s = String::from("A");
    s.push_str(input.sl());
    s.push_str("A");
    let i = s.chars().enumerate().filter(|(_,c)| m.contains(c)).map(|(a,_)| a);
    let j = i.clone();
    let sol = i.skip(1).zip(j).map(|(a,b)| a - b).max().unwrap();
    println!("{}", sol);
}


fn is_vowel(c: char) -> bool {
    return c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U';
}
fn _main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("Fail to read");
    let mut result = 0usize;
    let mut index = 0usize;
    for c in line.trim().chars() {
        index += 1;
        if is_vowel(c) {
            result = result.max(index);
            index = 0;
        }
    }
    index += 1;
    result = result.max(index);
    println!("{}", result);
}

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


fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let ints = s.split_whitespace().map(|x| x.parse().unwrap()).collect::<Vec<i32>>();
    let mut n1 = ints[0];
    let mut n2 = ints[1];
    let mut k =  std::collections::HashMap::new();
    k.insert(true,ints[2]);
    k.insert(false,ints[3]);

    let mut firstplayer = true;

    loop {
        if (k[&true]>n1 && k[&true]> n2) || k[&false] > n1 && k[&false] > n2 {
            break;
        }

        if n1 > n2 {
            if (k[&firstplayer]>n1) {
                break;
            }
            n1-=k[&firstplayer];
        } else{
            if (k[&firstplayer]>n2) {
                break;
            }
            n2-=k[&firstplayer];
        }
        firstplayer = !firstplayer;
    }
    println!("{}", if !firstplayer {"First"} else {"Second"});
 }


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

fn main() -> () {

    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();

    handle.read_to_string(&mut buffer).expect("stdin");

    let mut arr : Vec<_> = buffer.split_whitespace().map(|x| x.parse::<i64>().unwrap() ).collect();

    let n = arr[0] as usize;
    let a = arr[1];
    let b = arr[2];

    let v = arr.drain(3..).collect::<Vec<i64>>();

    let mut cost = 0;

    for i in 0..n / 2 + 1 {
        if v[i] != 2 && v[n-1-i] != 2 {
            if v[i] != v[n-1-i] {
                println!("-1");
                return
            }
        } else if v[i] == 2 && v[n-1-i] == 2 {
            use std::cmp;
            cost += cmp::min( a, b ) * if i != n-1-i { 2 } else { 1 };
        } else if v[i] != 2 && i != n-1-i {
            cost += if v[i] == 0 { a } else { b };
        } else if v[n-1-i] != 2 && i != n-1-i {
            cost += if v[n-1-i] == 0 { a } else { b };
        } else {
            panic!();
        }
    }

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


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

fn main() -> () {

    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();

    handle.read_to_string(&mut buffer).expect("stdin");

    let mut arr : Vec<_> = buffer.split_whitespace().map(|x| x.parse::<i64>().unwrap() ).collect();

    let n = arr[0];
    let m = arr[1];

    let max_seats = arr.iter().skip(2).max().unwrap();
    let min_seats = arr.iter().skip(2).min().unwrap();
    let s = arr.iter().skip(2).sum::<i64>();
    let b = (s + m)/n + if (s+m) % n != 0 { 1 } else { 0 };

    use std::cmp;

    println!("{} {}", cmp::max( min_seats, &b ), max_seats + m );
}


// 991A
use std::io;

fn main() {
    let (a, b, c, n): (u32, u32, u32, u32) = read_two(&io::stdin());
    if a + b - c + 1 > n {
        println!("{}", -1);
    } else {
        println!("{}", n - (a + b - c));
    }
}

fn read_two<T>(stdin: &io::Stdin) -> (T, T, T, T)
where
    T: std::str::FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin.read_line(&mut s).unwrap();
    let mut iter = s.trim().split_whitespace().map(|x| x.parse().unwrap());
    (
        iter.next().unwrap(),
        iter.next().unwrap(),
        iter.next().unwrap(),
        iter.next().unwrap(),
    )
}


use std::io::stdin;

fn main() {
    let (n, _) = {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        let mut it = input.split_whitespace().map(|k| k.parse::<usize>().unwrap());
        (it.next().unwrap(), it.next().unwrap())
    };

    let mut a = String::new();
    stdin().read_line(&mut a).unwrap();
    let a = a.split_whitespace().map(|k| k.parse::<usize>().unwrap());
    let (al, n_al) = a.fold((0, 0), |(al, n_al), ai| (al + ai % 2, n_al + ai / 2));

    if  al + n_al <= n * 4 {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

    let mut it = input.split_whitespace();

    let p: usize = it.next().unwrap().parse().unwrap();
    let y: usize = it.next().unwrap().parse().unwrap();

    let mut bl = vec![false; y + 1];

    bl[0] = true;
    bl[1] = true;

    for i in 2..p + 1 {
        for j in (1..).take_while(|&j| i * j <= y) {
            bl[i * j] = true;
        }
    }

    let ans = bl.into_iter().rposition(|x| !x);

    match ans {
        Some(ans) => println!("{}", ans),
        None => println!("-1"),
    }
}


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

    let mut it = input.split_whitespace();

    let p: u64 = it.next().unwrap().parse().unwrap();
    let y: u64 = it.next().unwrap().parse().unwrap();

    let ans = (3..y + 1).rev().find(|&i| {
        let k = std::cmp::min(p, (y as f64).sqrt().floor() as u64);
        (2..k + 1).all(|j| i % j != 0) && i > p
    });

    match ans {
        Some(ans) => println!("{}", ans),
        None => println!("-1"),
    }
}


use std::io::stdin;
use std::io::prelude::*;
use std::iter::*;
use std::str::SplitWhitespace;
use std::cmp::min;

fn main() {
    let mut input = InRead::new();
    let n = input.int();
    let a = input.int();
    let b = input.int();
    let c = input.int();
    let x = min(a, b);
    let res = x + min(x, c) * (n - 2);
    println!("{}", res);
}

struct InRead(String);

impl InRead {
    fn new() -> InRead {
        InRead(String::new())
    }
    fn get_line(self: &mut Self) {
        self.0.clear();
        stdin().read_line(&mut self.0);
    }
    fn parse_int(s: &str) -> i32 { s.parse().unwrap() }
    fn ints(self: &mut Self) -> Map<SplitWhitespace, fn(&str) -> i32> {
        self.get_line();
        self.0.split_whitespace().map(InRead::parse_int)
    }
    fn int_vec(self: &mut Self) -> Vec<i32> { self.ints().collect() }
    fn int(self: &mut Self) -> i32 { self.ints().next().unwrap() }
}


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

fn main(){
    let n = read_int();
    let a = read_int();
    let b = read_int();
    let c = read_int();

    let mut location = "R";
    let mut dist = 0;
    let mut meals = 1;
    while meals < n{
        let trip = match location {
            "R" => {
                if a < b{
                    location = "O";
                    a
                }else{
                    location = "E";
                    b
                }
            },
            "E" => {
                if c < b{
                    location = "O";
                    c
                }else{
                    location = "R";
                    b
                }
            },
            "O" => {
                if a < c{
                    location = "R";
                    a
                }else{
                    location = "E";
                    c
                }
            },
            _ => {break},
        };
        meals = meals + 1;
        dist = dist + trip;
    }
    println!("{}", dist);
}


use std::io;

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

  let mut ln = String::new();
  stdin.read_line(&mut ln).unwrap();
  let mut iter = ln.split_whitespace();
  let n:u32 = iter.next().unwrap().parse().unwrap();
  let mut m:u32 = iter.next().unwrap().parse::<u32>().unwrap() / n;

  let mut count = 0;
  while m > 1 && m % 2 == 0 {
    m /= 2;
    count += 1;
  }
  while m > 1 {
    m /= 3;
    count += 1;
  }
  println!("{}", count);
}


#![allow(unused_imports)]

use std::cmp::*;
use std::collections::*;

fn power(n: i64, p: i64) -> i64 {
    let mut i = 0;
    let mut r = n;
    while r % p == 0 {
        r = r / p;
        i += 1;
    }
    return i;
}

fn main() {
    let nn = read_ints();
    let (n, m) = (nn[0], nn[1]);

    let n2 = power(n, 2);
    let n3 = power(n, 3);
    let m2 = power(m, 2);
    let m3 = power(m, 3);
    if m2 < n2 || m3 < n3 {
        println!("{}", -1);
    } else {
        println!("{}", m2 + m3 - n2 - n3);
    }
}

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

fn read_ints() -> Vec<i64> {
    return read_line()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
}


#![allow(dead_code, clippy::many_single_char_names, unused_variables, non_snake_case, unused_macros, unused_imports, non_upper_case_globals)]
use std::{
    collections::*,
    io::{stdin, StdinLock, stdout, StdoutLock, BufReader, BufRead, BufWriter, Write},
    mem::swap
};

fn parse<T: std::str::FromStr>(n: &str) -> T {
    match n.parse::<T>() {
        Ok(x) => x,
        _ => panic!()
    }
}

macro_rules! fill {
    ($r: expr, str, $($x: ident),+) => { fill!($r, str, 30, $($x),+) };
    ($r: expr, $t: ty, $($x: ident),+) => { fill!($r, $t, 30, $($x),+) };
    ($r: expr, str, $c: expr, $($x: ident),+) => {
        let t = read!($r, $c);
        let mut t = t.split(' ');

        $(
            $x = t.next().unwrap();
        )+
    };
    ($r: expr, $t: ty, $c: expr, $($x: ident),+) => {
        let t = read!($r, $c);
        let mut t = t.split(' ').map(parse::<$t>);

        $(
            $x = t.next().unwrap();
        )+
    }
}

macro_rules! read {
    ($r: expr) => { read!($r, 20) };
    ($r: expr, str) => { read!($r, 20) };
    ($r: expr, $t: ty) => { parse::<$t>(&read!($r, 20)) };
    ($r: expr, str, $c: expr) => { read!($r, $c) };
    ($r: expr, $t: ty, $c: expr) => { parse::<$t>(&read!($r, $c)) };
    ($r: expr, $c: expr) => {
        {
            let mut s = String::with_capacity($c+2);
            $r.read_line(&mut s).unwrap();

            assert!(s.len() <= $c+2);

            if s.ends_with('\n') {
                s.pop();
                if s.ends_with('\r') {
                    s.pop();
                }
            }
            s
        }
    }
}

macro_rules! read_vec {
    ($r: expr) => { read_vec!($r, str, 10_000) };
    ($r: expr, str) => { read_vec!($r, str, 10_000) };
    ($r: expr, $t: ty) => { read_vec!($r, $t, 10_000) };
    ($r: expr, $c: expr) => { read_vec!($r, str, $c) };
    ($r: expr, str, $c: expr) => {
        {
            let v = read!($r, $c).split(' ').collect::<Vec<_>>();
            assert!(v.len() <= $c); // $c is upper bound of string
            v
        }
    };
    ($r: expr, $t: ty, $c: expr) => {
        {
            let v = read!($r, $c).split(' ').map(parse::<$t>).collect::<Vec<_>>();
            assert!(v.len() <= $c);
            v
        }
    };
}

fn main() {
    let r = stdin();
    let mut r = BufReader::with_capacity(10000, r.lock());

    let w = stdout();
    let mut w = BufWriter::with_capacity(10000, w.lock());
    unsafe { solve(&mut r, &mut w); }
}

const M: usize = std::usize::MAX;

unsafe fn solve(r: &mut BufReader<StdinLock>, w: &mut BufWriter<StdoutLock>) {
    let (a, b);
    fill!(r, usize, 19, a, b);

    if b%a != 0 {
        write!(w, "-1").unwrap();
    } else {
        let m = b/a;
        let mut acc = m.trailing_zeros();

        let mut m = m>>acc;

        while m != 1 {
            acc += 1;
            m /= 3;
        }
        write!(w, "{}", acc).unwrap();
    }
}


#![allow(dead_code, clippy::many_single_char_names, unused_variables, non_snake_case, unused_macros, unused_imports, non_upper_case_globals)]
use std::{
    collections::*,
    io::{stdin, StdinLock, stdout, StdoutLock, BufReader, BufRead, BufWriter, Write},
    mem::swap
};

fn parse<T: std::str::FromStr>(n: &str) -> T {
    match n.parse::<T>() {
        Ok(x) => x,
        _ => panic!()
    }
}

macro_rules! fill {
    ($r: expr, str, $($x: ident),+) => { fill!($r, str, 30, $($x),+) };
    ($r: expr, $t: ty, $($x: ident),+) => { fill!($r, $t, 30, $($x),+) };
    ($r: expr, str, $c: expr, $($x: ident),+) => {
        let t = read!($r, $c);
        let mut t = t.split(' ');

        $(
            $x = t.next().unwrap();
        )+
    };
    ($r: expr, $t: ty, $c: expr, $($x: ident),+) => {
        let t = read!($r, $c);
        let mut t = t.split(' ').map(parse::<$t>);

        $(
            $x = t.next().unwrap();
        )+
    }
}

macro_rules! read {
    ($r: expr) => { read!($r, 20) };
    ($r: expr, str) => { read!($r, 20) };
    ($r: expr, $t: ty) => { parse::<$t>(&read!($r, 20)) };
    ($r: expr, str, $c: expr) => { read!($r, $c) };
    ($r: expr, $t: ty, $c: expr) => { parse::<$t>(&read!($r, $c)) };
    ($r: expr, $c: expr) => {
        {
            let mut s = String::with_capacity($c+2);
            $r.read_line(&mut s).unwrap();

            assert!(s.len() <= $c+2);

            if s.ends_with('\n') {
                s.pop();
                if s.ends_with('\r') {
                    s.pop();
                }
            }
            s
        }
    }
}

macro_rules! read_vec {
    ($r: expr) => { read_vec!($r, str, 10_000) };
    ($r: expr, str) => { read_vec!($r, str, 10_000) };
    ($r: expr, $t: ty) => { read_vec!($r, $t, 10_000) };
    ($r: expr, $c: expr) => { read_vec!($r, str, $c) };
    ($r: expr, str, $c: expr) => {
        {
            let v = read!($r, $c).split(' ').collect::<Vec<_>>();
            assert!(v.len() <= $c); // $c is upper bound of string
            v
        }
    };
    ($r: expr, $t: ty, $c: expr) => {
        {
            let v = read!($r, $c).split(' ').map(parse::<$t>).collect::<Vec<_>>();
            assert!(v.len() <= $c);
            v
        }
    };
}

fn main() {
    let r = stdin();
    let mut r = BufReader::with_capacity(10000, r.lock());

    let w = stdout();
    let mut w = BufWriter::with_capacity(10000, w.lock());
    unsafe { solve(&mut r, &mut w); }
}

const M: usize = std::usize::MAX;

unsafe fn solve(r: &mut BufReader<StdinLock>, w: &mut BufWriter<StdoutLock>) {
    let (a, b);
    fill!(r, usize, 19, a, b);

    if ((b%3 != 0 && b%2 != 0) || b%a != 0 )&& b != a {
        write!(w, "-1").unwrap();
    } else {
        let m = b/a;
        let mut acc = m.trailing_zeros();

        let mut m = m>>acc;

        while m != 1 {
            acc += 1;
            m /= 3;
        }
        write!(w, "{}", acc).unwrap();
    }
}


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

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 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(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

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

fn main() {
    let str :Vec<char> = util::line().chars().collect();
    let mut flag = 0;
    let mut ans =0;
    for c in str {
        if c == '1' {
            flag = 1;
        } else if flag == 1 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


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 main() {
    let s = read_line();

    match s.chars().filter(|x| *x == '0').count() >= 6 {
        true => println!("yes"),
        false => println!("no")
    }

}


use std::{io, process};

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

	let mut a: Vec<u8> = {
		let mut line = String::new();
		io::stdin().read_line(&mut line).unwrap();
		line.trim().split(' ').map(|a| a.parse().unwrap()).collect()
	};

	a.sort();

	// remove duplicates
	let mut i = a.len() - 1;
	loop {
		for j in (0..a.len()).rev() {
			if i == j {
				continue;
			}
			if a[i] == a[j] {
				if i > j {
					a.remove(i);
					a.remove(j);
				} else {
					a.remove(j);
					a.remove(i);
				}
				i -= 1;
				break;
			}
		}

		if i == 0 {
			break;
		}
		i -= 1;
	}

	assert!(a.len() % 2 == 0);

	let mut pb0 = 0u32;
	for s in a
		.iter()
		.enumerate()
		.filter(|s| s.0 % 2 == 0)
		.map(|s| *s.1)
		.zip(a.iter().enumerate().filter(|s| s.0 % 2 == 1).map(|s| *s.1))
	{
		pb0 += s.1 as u32 - s.0 as u32;
	}

	if a.len() < 3 {
		println!("{}", pb0);
		process::exit(0);
	}

	let mut pb1 = 0u32;
	let mut b: Vec<u8> = a
		.iter()
		.enumerate()
		.filter(|s| s.0 % 2 == 0)
		.map(|s| *s.1)
		.collect();
	println!("{:?}", b);
	b.remove(0);
	let lasti = b.len() - 1;
	b.remove(lasti);
	for s in a
		.iter()
		.enumerate()
		.filter(|s| s.0 % 2 == 1)
		.map(|s| *s.1)
		.zip(b)
	{
		pb1 += s.1 as u32 - s.0 as u32;
	}
	pb1 += a[a.len() - 1] as u32 - a[0] as u32;

	println!("{}", pb0.min(pb1));
}


use std::io::{stdin};

fn main() {
  let mut students_count = String::new();
  stdin().read_line(&mut students_count).expect("expected count input");
  let _count : u32 = students_count.trim().parse().unwrap();
  let mut students_score = String::with_capacity(500);
  stdin().read_line(&mut students_score).expect("expected students score");
  let mut scores_arr : Vec<u32> = students_score.trim().split(" ")
                      .map(|score| score.parse::<u32>().unwrap())
                      .collect();
  scores_arr.sort();
  let mut max_diff : u32 = 0;
  for i in 0..(scores_arr.len() - 1) {
    let diff : u32 = scores_arr[i + 1] - scores_arr[i];
    if diff > max_diff {
      max_diff = diff;
    }
  }
  println!("{}", max_diff)
}


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

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

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

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

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

fn find(src: u64, num: u64, n4: usize, n7: usize, result: &mut u64) {
    if num > 1000000000 {
        return;
    }
    if n4 == n7 && num >= src && (num - src) < (*result - src) {
        *result = num;
    }
    find(src, num * 10 + 4, n4 + 1, n7, result);
    find(src, num * 10 + 7, n4, n7 + 1, result);
}

fn _main() {
    let mut scan = Scan::new();
    let n: u64 = scan.next();
    let mut result = std::u64::MAX;
    find(n, 0, 0, 0, &mut result);
    println!("{}", result);
}

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


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

fn main() -> () {
    let mut buffer = String::new();
    let stdin = io::stdin();
    let mut handle = stdin.lock();

    handle.read_to_string(&mut buffer).expect("stdin");

    let arr : Vec<_> = buffer.split_whitespace().map(|x| x.parse::<i64>().unwrap() ).collect();

    let mut n = arr.iter().nth(0).unwrap();

    let mut curr = 1;
    let mut total = 0;
    let mut count = 0;

    while total < n {
        count += 1;
        total +=  curr;
        curr = curr * 2;
    }

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


// This file is a "Hello, world!" in Rust language for wandbox.
use std::io;

fn main()
{
    let stdin = io::stdin();
    let mut buffer = String::new();
    stdin.read_line(&mut buffer).unwrap();
    let mut n = buffer.parse::<u32>().unwrap();
    let mut cnt = 0;
    while n > 0 {
        n >>= 1;
        cnt += 1;
    }

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

// Rust language references:
//   https://www.rust-lang.org/


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
using namespace std;

bool f_possible(int x, vector<int> p) {
    int perm_count = 0;
    do {
        if ((((x % p[0]) % p[1]) % p[2]) % p[3] == x) {
            perm_count++;
        }
        if (perm_count >= 7) {
            return true;
        }
    }
    while (next_permutation(p.begin(), p.end()));
    return false;
}

int solve(const vector<int>& p, int a, int b) {
    int ans = 0;
    for (int x = a; x <= b; x++) {
        if (f_possible(x, p)) {
            ans++;
        }
    }
    return ans;
}

int main() {
    vector<int> p;
    for (int i = 0; i < 4; i++) {
        int x; cin >> x;
        p.push_back(x);
    }
    sort(p.begin(), p.end());
    int a, b;
    cin >> a >> b;
    int ans = solve(p, a, b);
    cout << ans << "\n";
}


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

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

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

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

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let p1: i32 = scan.token();
    let p2: i32 = scan.token();
    let p3: i32 = scan.token();
    let p4: i32 = scan.token();
    let a: i32 = scan.token();
    let b: i32 = scan.token();
    let ans = b.min(p1).min(p2).min(p3).min(p4) - a.max(0);
    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);
}


// Practice Codeforces
// author: Leonardone @ NEETSDKASU

// 解説読後

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

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

    if n < 2000 {
        let ans = brute_force(n, m as i64);
        println!("{}", ans);
    }

    let mut xs = vec![0; m];

    for i in 0..m {
        let mut c = n / m as i64;
        if i as i64 <= n % m as i64 {
            c += 1;
        }
        xs[i] += c;
    }
    xs[0] -= 1;
    // println!("{:?}", xs);
    let mut ans = 0;
    let c = n / m as i64;
    for i in 0..xs.len() {
        for j in 0..xs.len() {
            let k = (i*i+j*j) % m;
            if k == 0 {
                ans += xs[i] * xs[j];
            }
        }
    }

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

fn brute_force(n: i64, m: i64) -> i64 {
    let mut ret = 0;
    for i in 1..=n {
        for j in 1..=n {
            let k = i * i + j * j;
            if k % m == 0 {
                ret += 1;
            }
        }
    }
    ret
}


use std::io::stdin;

pub fn process(n: i32, m: i32) -> u64 {
  let mut res: u64 = 0;
  for i in 1..=m {
    for j in 1..=m {
      if (i * i + j * j) % m != 0 { continue }
      let k = ((n - i) / m) as u64;
      let l = ((n - j) / m) as u64;
      res += ((k + 1) * (l + 1));
    }
  }
  res
}

fn main() {
  let mut s = String::new();
  stdin().read_line(&mut s).unwrap();
  let mut input = s.split_whitespace();
  let n = input.next().unwrap().parse::<i32>().unwrap();
  let m = input.next().unwrap().parse::<i32>().unwrap();

  println!("{}", process(n, m));
}

#[cfg(test)]
mod tests {
  use super::*;

  #[test]
  fn test1() {
    assert_eq!(process(3, 3), 1);
  }

  #[test]
  fn test2() {
    assert_eq!(process(6, 5), 13);
  }

  #[test]
  fn test3() {
    assert_eq!(process(1000_000_000, 1), 1000_000_000_000_000_000);
  }
}


use std::io::{self, prelude::*};
use std::str;
use std::string::String;
use std::vec::Vec;

#[allow(unused_must_use)]
fn run<B: BufRead, W: Write>(mut reader: Scanner<B>, mut writer: W) {
    let n: usize = reader.next();
    let k: usize = reader.next();

    let mut scores: Vec<i32> = reader.next_line().split_whitespace().map(|n| n.parse().unwrap()).collect();
    scores.sort_unstable();
    scores.reverse();

    let mut count: i32 = 0;
    let minimum_score: i32 = scores[k];
    for i in 0..n {
        if scores[i] >= minimum_score && scores[i] > 0 {
            count += 1;
        }
    }

    writeln!(writer, "{}", count);

    io::stdout().flush().unwrap();
}

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

    let reader = Scanner::new(stdin.lock());
    let writer = io::BufWriter::new(stdout.lock());
    run(reader, writer);
}

pub struct Scanner<B> {
    reader: B,
    buffer_string: Vec<u8>,
    buffer_iterator: str::SplitWhitespace<'static>,
}

impl <B: BufRead> Scanner<B> {
    pub fn new(reader: B) -> Self {
        return Self {
            reader,
            buffer_string: Vec::new(),
            buffer_iterator: "".split_whitespace()
        };
    }

    pub fn next<T: str::FromStr>(&mut self) -> T {
        loop {
            //if buffer already exists, just use existing buffer
            if let Some(token) = self.buffer_iterator.next() {
                return token.parse().ok().expect("Fail to parse token");
            }

            //get new line
            self.buffer_string.clear();
            self.reader.read_until(b'\n', &mut self.buffer_string).expect("Failed to read");

            //split by white space
            self.buffer_iterator = unsafe {
                let slice = str::from_utf8_unchecked(&self.buffer_string);
                std::mem::transmute(slice.split_whitespace())
            };
        }
    }

    pub fn next_line(&mut self) -> String {
        //reset buffer
        self.buffer_iterator = "".split_whitespace();
        self.buffer_string.clear();

        let mut input: String = String::new();
        self.reader.read_line(&mut input).expect("Failed to read line");
        return input.trim().to_string();
    }
}


use std::io;
fn main() {
    let mut input = String::new();
    let mut n: i64;
    let mut k : i64;
    let mut numbers: Vec<i64> = Vec::new();
    io::stdin().read_line(& mut input).expect("test");
    io::stdin().read_line(&mut input).expect("test");
    let mut vec = input.split_whitespace().map(|x| x.parse::<i64>().expect("error")).collect::<Vec<i64>>();
    let mut count = 0;
    let len = (vec[1] + 2) as usize;
    let max = vec[len];
    for i in 2..vec.len(){
        if vec[i] > 0 && vec[i] >=max {
            count+=1;
        }
    }

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


// 158A
// solved: 4

use std::io;

fn main() {
    let mut nk = String::new();
    let mut scores = String::new();
    io::stdin().read_line(&mut nk).unwrap();
    io::stdin().read_line(&mut scores).unwrap();
    let nk: Vec<_> = nk.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let mut scores: Vec<_> = scores.trim().split(" ").map(|x| x.parse::<usize>().unwrap()).collect();
    let n = nk[0];
    let k = nk[1];
    scores.sort();
    let score_to_beat = scores[n-1-k];
    let result = scores.into_iter().filter(|&x| x >= score_to_beat && x > 0).collect::<Vec<_>>().len();
    println!("{}", result);
}


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

    let sp:Vec<&str> = s.trim().split_whitespace().collect();

    let n:i64 = sp[0].trim().parse().unwrap();;
    let k:usize = sp[1].trim().parse().unwrap();;

	let mut s = String::new();
    std::io::stdin()
        .read_line(&mut s)
        .expect("failed to read input.");

    let sa:Vec<&str> = s.trim().split_whitespace().collect();

    let mut len = 0;
    let mut kNum = -1;

    for (i, s) in sa.iter().enumerate(){
    	let mut i = i + 1
    	let mut cur:i64 = s.trim().parse().unwrap();
    	if i == k  {
    		kNum = cur;
    	}
	 	if cur > 0 && (i < k || (i >= k && kNum == cur))
	 	{
	 		len += 1;
	 	}

    }

    print!("{:?}", len);
}


use std::io;

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

    match io::stdin().read_line(&mut input) {
        Ok(_) => {
            let v: Vec<usize> = input
                .trim()
                .split_whitespace()
                .map(|val| val.parse::<usize>().unwrap())
                .collect();

            let k = v[1];

            let mut nums_input = String::new();

            match io::stdin().read_line(&mut nums_input) {
                Ok(_) => {
                    let mut count = 0;
                    let nums: Vec<i32> = nums_input
                        .trim()
                        .split_whitespace()
                        .map(|val| val.parse::<i32>().unwrap())
                        .collect();

                    let threshold = nums[k];

                    for num in nums.iter() {
                        if num >= &threshold && num > &0 {
                            count += 1;
                        }
                    }

                    println!("{}", count);
                },
                Err(e) => println!("{}", e)
            }
        },
        Err(e) => println!("{}", e)
    }
}


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

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ===

fn generate_primes(upto: usize) -> (Vec<i64>, Vec<bool>) {
    let mut is_prime = vec![true; upto+1];
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..upto+1 {
        if is_prime[i] {
            let mut ii = i * i;
            while ii <= upto {
                is_prime[ii] = false;
                ii += i;
            }
        }
    }

    let mut primes = vec![];
    for i in 0..upto+1 {
        if is_prime[i] {
            primes.push(i as i64);
        }
    }
    (primes, is_prime)
}
//===

struct Graph {
    graph: Vec<Vec<(usize, i64)>>,
    vec: Vec<i64>,
    edges: Vec<(usize, usize, i64)>,
    mark: Vec<i64>,
    dcost: Vec<i64>,
}

impl Graph {
    fn generate_next(&mut self, cnt: i64) -> usize {
        self.vec.push(cnt);
        self.vec.len() - 1
    }
    fn add_edge(&mut self, u: usize, v: usize, len: i64) {
        self.edges.push((u, v, len));
    }
}

fn dfs(l: usize, r: usize, depth: usize, parent: usize, table: &Vec<(Vec<i64>, usize, i64)>, graph: &mut Graph) {
    if l == r {
        if table[l].1 >= 2 {
            let nid = graph.generate_next(table[l].2);
            let mut d = 0;

            let pn = table[0].0.len();
            for i in depth..pn {
                d += table[l].0[i];
            }
            graph.add_edge(parent, nid, d);
        }
        return;
    }

    if table[l].0[depth] == table[r].0[depth] {
        if table[l].0[depth] == 0 {
            dfs(l, r, depth+1, parent, table, graph);
        } else {
            let nid = graph.generate_next(0);
            graph.add_edge(parent, nid, table[l].0[depth]);
            dfs(l, r, depth+1, nid, table, graph);
        }
        return;
    }

    let mut ll = l;
    let mut last_value = 0;
    let mut cparent = parent;
    while ll <= r {
        let mut rr = ll;
        while rr <= r && table[ll].0[depth] == table[rr].0[depth] {
            rr += 1;
        }
        // [ll, rr)
        let add_len = table[ll].0[depth] - last_value;
        assert!(add_len >= 0);
        if add_len == 0 {
            dfs(ll, rr-1, depth+1, parent, table, graph);
        } else {
            let nid = graph.generate_next(0);
            graph.add_edge(cparent, nid, add_len);
            dfs(ll, rr-1, depth+1, nid, table, graph);
            cparent = nid;
        }
        last_value = table[ll].0[depth];
        ll = rr;
    }
}

fn dfs2(now: usize, par: usize, g: &mut Graph) -> (i64, i64) {
    let mut total_mark = g.vec[now];
    let mut total_cost = 0;
    for (to, len) in g.graph[now].clone() {
        if to == par {
            continue;
        }
        let (m, c) = dfs2(to, now, g);
        total_mark += m;
        total_cost += c + m * len;
    }
    g.mark[now] = total_mark;
    g.dcost[now] = total_cost;
    (total_mark, total_cost)
}

fn dfs3(now: usize, par: usize, g: &mut Graph) -> i64 {
    let mut best = g.dcost[now];
    for (to, len) in g.graph[now].clone() {
        if to == par {
            continue;
        }
        let mark_back = g.mark[to];
        let dcost_back = g.dcost[to];
        let reduce_cost = g.dcost[to] + g.mark[to] * len;
        let reduce_mark = g.mark[to];

        g.dcost[to] += (g.dcost[now] - reduce_cost) + (g.mark[now] - reduce_mark) * len;
        g.mark[to] += (g.mark[now] - reduce_mark);

        best = min(best, dfs3(to, now, g));

        g.mark[to] = mark_back;
        g.dcost[to] = dcost_back;

    }
    // debug!(now, best);
    best
}

const LIMIT: usize = 5000;

fn main() {
    input! {
        n: usize,
        k: [usize; n]
    };

    let mut deg = vec![0; LIMIT+1];
    for k in k {
        deg[k] += 1;
    }
    let (primes, is_prime) = generate_primes(LIMIT+1);

    let mut pn = primes.len();
    let mut vec = vec![];
    // let mut edges = vec![];

    let mut l = LIMIT;
    while l >= 2 {
        let mut lw = l;
        while !is_prime[lw] {
            lw -= 1;
        }

        for num in (lw..=l).rev() {
            let mut ptbl = vec![0; pn];
            for i in 0..pn {
                let mut num = num as i64;
                while num >= primes[i] {
                    ptbl[i] += num / primes[i];
                    num /= primes[i];
                }
            }
            ptbl.reverse();
            vec.push((ptbl, num, deg[num]));
        }
        l = lw-1;
    }
    vec.push((vec![0; pn], 1, deg[1]));
    vec.sort();

    let mut graph = Graph { vec: vec![], edges: vec![], graph: vec![], mark: vec![], dcost: vec![] };
    graph.generate_next(deg[1]);

    dfs(0, vec.len()-1, 0, 0, &vec, &mut graph);

    let vn = graph.vec.len();

    let mut deg = graph.vec.clone();
    let mut g = vec![vec![]; vn];
    for &(u, v, len) in &graph.edges {
        g[u].push((v, len));
        g[v].push((u, len));
    }
    graph.graph = g;
    graph.mark = vec![0; vn];
    graph.dcost = vec![0; vn];

    dfs2(0, vn, &mut graph);

    // debug!(graph.graph);
    // debug!(graph.vec);

    let ans = dfs3(0, vn, &mut graph);
    println!("{}", ans);
}


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

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ===

fn generate_primes(upto: usize) -> (Vec<i64>, Vec<bool>) {
    let mut is_prime = vec![true; upto+1];
    is_prime[0] = false;
    is_prime[1] = false;
    for i in 2..upto+1 {
        if is_prime[i] {
            let mut ii = i * i;
            while ii <= upto {
                is_prime[ii] = false;
                ii += i;
            }
        }
    }

    let mut primes = vec![];
    for i in 0..upto+1 {
        if is_prime[i] {
            primes.push(i as i64);
        }
    }
    (primes, is_prime)
}
//===

struct Graph {
    graph: Vec<Vec<(usize, i64)>>,
    vec: Vec<i64>,
    edges: Vec<(usize, usize, i64)>,
    mark: Vec<i64>,
    dcost: Vec<i64>,
}

impl Graph {
    fn generate_next(&mut self, cnt: i64) -> usize {
        self.vec.push(cnt);
        self.vec.len() - 1
    }
    fn add_edge(&mut self, u: usize, v: usize, len: i64) {
        self.edges.push((u, v, len));
    }
}

fn dfs(l: usize, r: usize, depth: usize, parent: usize, table: &Vec<(Vec<i64>, usize, i64)>, graph: &mut Graph) {
    if l == r {
        if table[l].1 >= 2 {
            let nid = graph.generate_next(table[l].2);
            let mut d = 0;

            let pn = table[0].0.len();
            for i in depth..pn {
                d += table[l].0[i];
            }
            graph.add_edge(parent, nid, d);
        }
        return;
    }

    if table[l].0[depth] == table[r].0[depth] {
        if table[l].0[depth] == 0 {
            dfs(l, r, depth+1, parent, table, graph);
        } else {
            let nid = graph.generate_next(0);
            graph.add_edge(parent, nid, table[l].0[depth]);
            dfs(l, r, depth+1, nid, table, graph);
        }
        return;
    }

    let mut ll = l;
    let mut last_value = 0;
    let mut cparent = parent;
    while ll <= r {
        let mut rr = ll;
        while rr <= r && table[ll].0[depth] == table[rr].0[depth] {
            rr += 1;
        }
        // [ll, rr)
        let add_len = table[ll].0[depth] - last_value;
        assert!(add_len >= 0);
        if add_len == 0 {
            dfs(ll, rr-1, depth+1, parent, table, graph);
        } else {
            let nid = graph.generate_next(0);
            graph.add_edge(cparent, nid, add_len);
            dfs(ll, rr-1, depth+1, nid, table, graph);
            cparent = nid;
        }
        last_value = table[ll].0[depth];
        ll = rr;
    }
}

fn dfs2(now: usize, par: usize, g: &mut Graph) -> (i64, i64) {
    let mut total_mark = g.vec[now];
    let mut total_cost = 0;
    for (to, len) in g.graph[now].clone() {
        if to == par {
            continue;
        }
        let (m, c) = dfs2(to, now, g);
        total_mark += m;
        total_cost += c + m * len;
    }
    g.mark[now] = total_mark;
    g.dcost[now] = total_cost;
    (total_mark, total_cost)
}

fn dfs3(now: usize, par: usize, g: &mut Graph) -> i64 {
    let mut best = g.dcost[now];
    for (to, len) in g.graph[now].clone() {
        if to == par {
            continue;
        }
        let mark_back = g.mark[to];
        let dcost_back = g.dcost[to];
        let reduce_cost = g.dcost[to] + g.mark[to] * len;
        let reduce_mark = g.mark[to];

        g.dcost[to] += (g.dcost[now] - reduce_cost) + (g.mark[now] - reduce_mark) * len;
        g.mark[to] += (g.mark[now] - reduce_mark);

        best = min(best, dfs3(to, now, g));

        g.mark[to] = mark_back;
        g.dcost[to] = dcost_back;

    }
    // debug!(now, best);
    best
}

const LIMIT: usize = 5;

fn main() {
    input! {
        n: usize,
        k: [usize; n]
    };

    let mut deg = vec![0; LIMIT+1];
    for k in k {
        deg[k] += 1;
    }
    let (primes, is_prime) = generate_primes(LIMIT+1);

    let mut pn = primes.len();
    let mut vec = vec![];
    // let mut edges = vec![];

    let mut l = LIMIT;
    while l >= 2 {
        let mut lw = l;
        while !is_prime[lw] {
            lw -= 1;
        }

        for num in (lw..=l).rev() {
            let mut ptbl = vec![0; pn];
            for i in 0..pn {
                let mut num = num as i64;
                while num >= primes[i] {
                    ptbl[i] += num / primes[i];
                    num /= primes[i];
                }
            }
            ptbl.reverse();
            vec.push((ptbl, num, deg[num]));
        }
        l = lw-1;
    }
    vec.push((vec![0; pn], 1, deg[1]));
    vec.sort();

    let mut graph = Graph { vec: vec![], edges: vec![], graph: vec![], mark: vec![], dcost: vec![] };
    graph.generate_next(deg[1]);

    dfs(0, vec.len()-1, 0, 0, &vec, &mut graph);

    let vn = graph.vec.len();

    let mut deg = graph.vec.clone();
    let mut g = vec![vec![]; vn];
    for &(u, v, len) in &graph.edges {
        g[u].push((v, len));
        g[v].push((u, len));
    }
    graph.graph = g;
    graph.mark = vec![0; vn];
    graph.dcost = vec![0; vn];

    dfs2(0, vn, &mut graph);

    // debug!(graph.graph);
    // debug!(graph.vec);

    let ans = dfs3(0, vn, &mut graph);
    println!("{}", ans);
}


use std::io;

fn main() {
    let mut black = 0;
    let mut white = 0;
    let mut x = 0;
    let mut weights: [i32; 2];
    let mut line = String::new();
    while x < 8 {
        io::stdin().read_line(&mut line).expect("error: unable to read user input");
        weights = weight(&line);
        black += weights[0];
        white += weights[1];
        x += 1;
    }
    if black > white {
        println!("Black");
    } else if black < white {
        println!("White");
    } else {
        println!("Draw");
    }
}

fn weight(x: &str) -> [i32; 2] {
    let mut b = 0;
    let mut w = 0;
    for i in x.chars() {
        match i {
            'q' => b += 9,
            'r' => b += 5,
            'b' => b += 3,
            'n' => b += 3,
            'p' => b += 1,
            'Q' => w += 9,
            'R' => w += 5,
            'B' => w += 3,
            'N' => w += 3,
            'P' => w += 1,
            _ => (),
        };
    }
    let arr: [i32; 2] = [b, w];
    return arr;
}


use std::io;

fn main() {
    let mut black = 0;
    let mut white = 0;
    let mut x = 0;
    let mut weights: [i32; 2];
    while x < 8 {
        let line = String::new();
        io::stdin().read_line(&line).expect("error: unable to read user input");
        weights = weight(&line);
        black += weights[0];
        white += weights[1];
        x += 1;
    }
    if black > white {
        println!("Black");
    } else if black < white {
        println!("White");
    } else {
        println!("Draw");
    }
}

fn weight(x: &str) -> [i32; 2] {
    let mut b = 0;
    let mut w = 0;
    for i in x.chars() {
        match i {
            'q' => b += 9,
            'r' => b += 5,
            'b' => b += 3,
            'n' => b += 3,
            'p' => b += 1,
            'Q' => w += 9,
            'R' => w += 5,
            'B' => w += 3,
            'N' => w += 3,
            'P' => w += 1,
            _ => (),
        };
    }
    let arr: [i32; 2] = [b, w];
    return arr;
}


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

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

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

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

fn main() {
    let mut weights : HashMap<String,i32> = HashMap::new();
    weights.insert(String::from("q"),9);
    weights.insert(String::from("r"),5);
    weights.insert(String::from("b"),3);
    weights.insert(String::from("n"),3);
    weights.insert(String::from("p"),3);
    weights.insert(String::from("k"),0);
    let mut a = String::new();
    for _ in 0..8 {
        a += &readln!();
    }
    let w :i32 = a.chars().filter(|c|c.is_uppercase()).map(|x|x.to_lowercase()).map(|x| {
        let sx : String = x.to_string();
        weights.get(&sx).unwrap()
    }).sum();
    let b :i32 = a.chars().filter(|c|c.is_lowercase()).map(|x|{
        let sx : String = x.to_string();
        weights.get(&sx).unwrap()
    }).sum();
    println!("{}",if w>b { "White" } else if w<b { "Black" } else { "Draw" });
}


fn main (){
    let mut ws:i32 = 0;
    let mut bs:i32 = 0;
    let mut i = 0;
    while i < 8 {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        if let Some('\n')=s.chars().next_back() {
            s.pop();
        }
        ws = ws + countwhite((*s).to_string());
        bs = bs + countblack((*s).to_string());
        i = i +1;
    }

    if ws > bs{
        println!("White");
    }
    if ws == bs{
        println!("Draw");
    }
    if ws < bs{
        println!("Black");
    }
}

fn countblack(s: String) -> i32{
    let mut b:i32 = 0;
    for x in s.chars() {
        match x {
            'Q' => b=b+9,
            'R' => b=b+5,
            'B' => b=b+3,
            'N' => b=b+3,
            'P' => b=b+1,
            _ => b=b+0
        };
    }
    return b;
}

fn countwhite(s: String) -> i32{
    let mut b:i32 = 0;
    for x in s.chars() {
        match x {
            'q' => b=b+9,
            'r' => b=b+5,
            'b' => b=b+3,
            'n' => b=b+3,
            'p' => b=b+1,
            _ => b=b+0
        };
    }
    return b;
}


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

fn main() {
  let l1 = read_line_iter();
  let l2 = read_line_iter();
  let l3 = read_line_iter();
  let l4 = read_line_iter();
  let l5 = read_line_iter();
  let l6 = read_line_iter();
  let l7 = read_line_iter();
  let l8 = read_line_iter();

  let L1 = l1.as_bytes();
  let L2 = l2.as_bytes();
  let L3 = l3.as_bytes();
  let L4 = l4.as_bytes();
  let L5 = l5.as_bytes();
  let L6 = l6.as_bytes();
  let L7 = l7.as_bytes();
  let L8 = l8.as_bytes();

  let mut white = 0;
  let mut black = 0;

  //println!(
  //  "L1:{},L2:{},L3:{},L4:{},L5:{},L6:{},L7:{},L8:{}",
  //  l1,l2,l3,l4,l5,l6,l7,l8
  //);
  for i in 0..8{
    match L1[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L2[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L3[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L4[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L5[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L6[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L7[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  for i in 0..8{
    match L8[i] as char{
      'p' => black += 1,
      'n' => black += 3,
      'b' => black += 3,
      'r' => black += 5,
      'q' => black += 9,
      'P' => white += 1,
      'N' => white += 3,
      'B' => white += 3,
      'R' => white += 5,
      'Q' => white += 9,
      _ => (),
    }
  }
  let advantage = white-black;
  match advantage{
    1..=40 => println!("White"),
    -40..=-1 => println!("Black"),
    _ => println!("Draw"),
  }

}

fn read_line_iter() -> String {
  let stdin = io::stdin();
  // Read one line of input iterator-style
  let input = stdin.lock().lines().next();
  input
    .expect("No lines in buffer")
    .expect("Failed to read line")
    .trim()
    .to_string()
}


use std::io;

fn main() {
    let mut points = 0;
    let mut owned_string: String = "hello ".to_owned();
    for _ in 0..8 {
        let mut input = String::new();
        match io::stdin().read_line(&mut input) {
            Ok(_) => {
                let borrowed_string: &str = &input;
                owned_string.push_str(borrowed_string);
            }
            Err(error) => println!("error: {}", error),
        }
    }
    let char_vec: Vec<char> = owned_string.chars().collect();
        for c in char_vec {
            match c {
                'q' => points = points - 9,
                'r' => points = points - 3,
                'b' => points = points - 3,
                'n' => points = points - 5,
                'p' => points = points - 1,
                'k' => points = points - 0,
                'Q' => points = points + 9,
                'R' => points = points + 3,
                'B' => points = points + 3,
                'N' => points = points + 5,
                'P' => points = points + 1,
                'K' => points = points + 0,
                '.' => points = points + 0,
                 _  => points = points + 0,
                }
            }
    if points < 0{
        println!("Black")

     }
    else if points>0 {
        println!("White")
     }
    else{
         println!("Draw")
     }

}


fn black_points(c:char) -> i32{
    match c{
        'q'=> 9,
        'r'=> 5,
        'b'=> 3,
        'n'=> 3,
        'p'=> 1,
        _  => 0,
    }

}
fn white_points(c:char) -> i32{
    match c{
        'Q'=> 9,
        'R'=> 5,
        'B'=> 3,
        'N'=> 3,
        'P'=> 1,
        _  => 0,
    }

}
fn main(){
    let mut number = 1;
    let mut whiter_counter = 0;
    let mut black_counter = 0;
    while number <= 8{
        let mut line1 = String::new();
        let b1 = std::io::stdin().read_line(&mut line1).unwrap();
        for c in line1.chars(){
            black_counter += black_points(c);
            whiter_counter += white_points(c);

        }
        number += 1;
    }
    if whiter_counter > black_counter{
        println!("White");
    }
    else{
        println!("Black");
    }
 }


use std::io;

fn main() {

    //variable a retornar, tiene que ser mutable
    let mut sum :i32 = 0;

    //para iterar
    let mut n :i32 = 0;

    //Se tiene que iterar IO sino da error en runtime
    while n < 8{
        //varible que guardara el input
        let mut input = String::new();
        //se consigue la linea
        io::stdin().read_line(&mut input).unwrap();
        //se calcula
        sum += valor(input);

        n += 1;
    }

    //match algo forzado pero interesante implementacion
    //asi obtenemos un numero unico 1 -> whit   e , 0 -> draw y -1 -> black

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

fn valor(linea: String) -> i32{
    //variable a retornar
    let mut st :i32 = 0;

    for c in linea.chars(){
        match c{
            'Q' => st += 9,
            'R' => st += 5,
            'B' => st += 3,
            'N' => st += 3,
            'P' => st += 1,
            'q' => st -= 9,
            'r' => st -= 5,
            'b' => st -= 3,
            'n' => st -= 3,
            'p' => st -= 1,
             _ => (),
        };
    }

    st
}


use std::io;

fn main() {

    //variable a retornar, tiene que ser mutable
    let mut sum :i32 = 0;

    //para iterar
    let mut n :i32 = 0;

    //Se tiene que iterar IO sino da error en runtime
    while n < 8{
        //varible que guardara el input
        let mut input = String::new();
        //se consigue la linea
        io::stdin().read_line(&mut input).unwrap();
        //se calcula
        sum += valor(input);

        n += 1;
    }

    //match algo forzado pero interesante implementacion
    //asi obtenemos un numero unico 1 -> whit e , 0 -> draw y -1 -> black

    match sum/sum.abs(){
        1 => println!("White"),
        0 => println!("Draw"),
        _ => println!("Black"),

    }
}

fn valor(linea: String) -> i32{
    //variable a retornar
    let mut st :i32 = 0;

    for c in linea.chars(){
        match c{
            'Q' => st += 9,
            'R' => st += 5,
            'B' => st += 3,
            'N' => st += 3,
            'P' => st += 1,
            'q' => st -= 9,
            'r' => st -= 5,
            'b' => st -= 3,
            'n' => st -= 3,
            'p' => st -= 1,
             _ => (),
        };
    }

    st
}


fn valores (mut ptj: i32,i:char) -> i32 {
    match i {
        'q' => ptj+=9,
        'r' => ptj+=5,
        'b' | 'n' => ptj+=3,
        'p' => ptj+=1,
        'Q' => ptj-=9,
        'R' => ptj-=5,
        'B' | 'N' => ptj-=3,
        'P' => ptj-=1,
        _ => 0,
    };
    ptj
}

fn main(){
    let mut puntaje=0;
    for i in 0..8{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        for j in input.chars(){
            puntaje=valores(puntaje,j);
        }
    }
    if puntaje<0{
        println!("Black");
    }
    else if puntaje>0{
        println!("White");
    }
    else{
        println!("Draw");
    }
}


fn valores (mut ptj: i32,i:char) -> i32 {
    match i {
        'q' => ptj+=9,
        'r' => ptj+=5,
        'b' | 'n' => ptj+=3,
        'p' => ptj+=1,
        'Q' => ptj-=9,
        'R' => ptj-=5,
        'B' | 'N' => ptj-=3,
        'P' => ptj-=1,
        _ => ptj+=0,
    };
    ptj
}

fn main(){
    let mut puntaje=0;
    for i in 0..8{
        let mut input = String::new();
        std::io::stdin().read_line(&mut input).unwrap();
        for j in input.chars(){
            puntaje=valores(puntaje,j);
        }
    }
    if puntaje<0{
        println!("Black");
    }
    else if puntaje>0{
        println!("White");
    }
    else{
        println!("Draw");
    }
}


use std::mem;

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

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

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

fn _main() {
    let mut scan = Scan::new();
    let mut n: usize = scan.next();
    let mut m: usize = scan.next();
    if n > m {
        mem::swap(&mut n, &mut m);
    }
    let over = 2.min(m - n);
    let result = (n * 2 + over) / 3;
    println!("{}", result);
}

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


use std::io;

// type Matrix = Vec<Vec<char>>;

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 read_line_vec() -> Vec<i64> {
    return read_line().split(' ')
        .map(|s| s.parse().unwrap())
        .collect();
}

fn read_line_pair() -> (i64, i64) {
    let vec = read_line_vec();
    return (vec[0], vec[1]);
}

fn main() {

    let (mut n, mut m) = read_line_pair();

    let mut count = 0;

    while n > 0 && m > 0 {
        if n > m {
            n -= 2;
            m -= 1;
        } else {
            n -= 1;
            m -= 2;
        }
        count += 1;
    }

    println!("{}", count);

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

}


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

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

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

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

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

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

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

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

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

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

    let mut res = 0;
    let s = gets();
    let mut seq = BTreeSet::<&str>::new();
    for i in 0..s.len() - 1 {
        for j in i + 1 .. s.len() + 1 {
            if seq.contains(&s[i..j]){
                res = max(res, j - i);
            } else {
                seq.insert(&s[i..j]);
            }
        }
    }
    writeln!(out, "{}", res);
    // writeln!(out, "{}", "Hello Rust").unwrap();
}


// 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 mut field = vec![vec![]; 9];
    for i in 0..9 {
        for _ in 0..3 {
            field[i].push(get().as_bytes());
        }
    }
    let y = (get!(usize) - 1) % 3;
    let x = (get!(usize) - 1) % 3;

    let mut c = 0;
    for i in 0..3 {
        for &ch in &field[y*3+i][x][..] {
            if ch == b'.' {
                c += 1;
            }
        }
    }
    if c == 0 {
        for i in 0..9 {
            for j in 0..3 {
                if j > 0 { print!(" "); }
                for k in 0..3 {
                    let ch = field[i][j][k];
                    if ch == b'.' {
                        print!("!");
                    } else {
                        print!("{}", ch as char);
                    }
                }
            }
            println!();
        }
        return;
    }
    for i in 0..9 {
        for j in 0..3 {
            if j > 0 { print!(" "); }
            for k in 0..3 {
                let ch = field[i][j][k];
                if ch == b'.' && j == x && i / 3 == y {
                    print!("!");
                } else {
                    print!("{}", ch as char);
                }
            }
        }
        println!();
    }
}


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

    let p = input.bytes().position(|b| b'0' <= b && b <= b'9').unwrap();

    let grid: Vec<_> = input.as_bytes()[0..p].iter().filter_map(|&b| match b {
        b'.' => Some(Cell::Empty),
        b'x' => Some(Cell::Chip1),
        b'o' => Some(Cell::Chip2),
        _ => None,
    }).collect();

    let check = |x: usize, y: usize, grid: &Vec<Cell>| {
        let x_off = 27 * x;
        let y_off = 3 * y;
        let mut it = grid[x_off + y_off..].iter().take(3)
            .chain(grid[x_off + y_off + 9..].iter().take(3))
            .chain(grid[x_off + y_off + 18..].iter().take(3));

        !it.all(|cell| match *cell {
            Cell::Empty => false,
            _ => true,
        })
    };

    let mut it = input[108..].split_whitespace();
    let x: usize = it.next().unwrap().parse::<usize>().unwrap() - 1;
    let y: usize = it.next().unwrap().parse::<usize>().unwrap() - 1;

    let bx = x % 3;
    let by = y % 3;

    let ans: Vec<_> = if !check(bx, by, &grid) {
        grid.into_iter().map(|cell| match cell {
            Cell::Empty => Cell::Possible,
            _ => cell,
        }).collect()
    } else {
        grid.into_iter().enumerate().map(|(i, cell)| {
            let x = i / 9;
            let y = i % 9;
            match cell {
                Cell::Empty if x / 3 == bx && y / 3 == by => Cell::Possible,
                _ => cell,
            }
        }).collect()
    };

    let mut ans_str = Vec::with_capacity(108);

    for (i, cell) in ans.into_iter().enumerate() {
        let next = match cell {
            Cell::Empty => b'.',
            Cell::Chip1 => b'x',
            Cell::Chip2 => b'o',
            Cell::Possible => b'!',
        };

        ans_str.push(next);

        if i % 9 == 8 {
            ans_str.push(b'\n');
        } else if i % 3 == 2 {
            ans_str.push(b' ');
        }
    }

    let ans = String::from_utf8(ans_str).unwrap();

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

#[derive(Debug)]
enum Cell {
    Empty,
    Chip1,
    Chip2,
    Possible,
}


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

    let p = input.bytes().position(|b| b'0' <= b && b <= b'9').unwrap();

    let grid: Vec<_> = input.as_bytes()[0..p].iter().filter_map(|&b| match b {
        b'.' => Some(Cell::Empty),
        b'x' => Some(Cell::Chip1),
        b'o' => Some(Cell::Chip2),
        _ => None,
    }).collect();

    let check = |x: usize, y: usize, grid: &Vec<Cell>| {
        let x_off = 27 * x;
        let y_off = 3 * y;
        let mut it = grid[x_off + y_off..].iter().take(3)
            .chain(grid[x_off + y_off + 9..].iter().take(3))
            .chain(grid[x_off + y_off + 18..].iter().take(3));

        !it.all(|cell| match *cell {
            Cell::Empty => false,
            _ => true,
        })
    };

    let mut it = input[p..].split_whitespace();
    let x: usize = it.next().unwrap().parse::<usize>().unwrap() - 1;
    let y: usize = it.next().unwrap().parse::<usize>().unwrap() - 1;

    let bx = x % 3;
    let by = y % 3;

    let ans: Vec<_> = if !check(bx, by, &grid) {
        grid.into_iter().map(|cell| match cell {
            Cell::Empty => Cell::Possible,
            _ => cell,
        }).collect()
    } else {
        grid.into_iter().enumerate().map(|(i, cell)| {
            let x = i / 9;
            let y = i % 9;
            match cell {
                Cell::Empty if x / 3 == bx && y / 3 == by => Cell::Possible,
                _ => cell,
            }
        }).collect()
    };

    let mut ans_str = Vec::with_capacity(2 * p);

    for (i, cell) in ans.into_iter().enumerate() {
        let next = match cell {
            Cell::Empty => b'.',
            Cell::Chip1 => b'x',
            Cell::Chip2 => b'o',
            Cell::Possible => b'!',
        };

        ans_str.push(next);

        if i % 9 == 8 {
            ans_str.push(b'\n');
        } else if i % 3 == 2 {
            ans_str.push(b' ');
        }
    }

    let ans = String::from_utf8(ans_str).unwrap();

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

#[derive(Debug)]
enum Cell {
    Empty,
    Chip1,
    Chip2,
    Possible,
}


#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let v = read_vec::<u64>();
    let n = v[0];
    let m = v[1];
    let a = v[2];

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


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

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

    let input = buf.trim();
    let input = input.parse().expect("error parsing");

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

fn can_div_melon(input: u64) -> bool {
    input % 2 == 0
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn test_pave() {
        assert_eq!(true, can_div_melon(8));
    }
}


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

    let values = line
        .trim_end()
        .split(' ')
        .map(|x| x.parse::<u32>().unwrap())
        .collect::<Vec<_>>();

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

    let rows = (m + (a - 1)) / a;
    let cols = (n + (a - 1)) / a;

    println!("{}", rows * cols);
}


use std::io;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    let a : i32 = s.trim().parse().unwrap();
    if a > 2 && a % 2 == 0 {
        println!("YES");
    }
    else {
        println!("NO");
    }
}


use std::env;

struct Theatre {
    width : u64,
    height : u64,
    stone_size : u64,
}

impl Theatre {
    fn new(w : u64, h : u64, sw : u64) -> Theatre {
        Theatre {width : w, height : h, stone_size : sw}
    }

    fn stones(self) -> u64 {
        let kw = (self.width as f64) / (self.stone_size as f64);
        let kh = (self.height as f64) / (self.stone_size as f64);

        (kw.ceil() * kh.ceil()) as u64
    }

}

fn get_args() -> Result<(Theatre), i8> {

    if env::args().count() != 4 {
        return Err(-1);
    }

    let arg = env::args().skip(1);
    let mut tmpa : [u64; 3] = [0; 3];

    for (i,a) in arg.enumerate() {
        match a.parse::<u64>() {
            Ok(v) => tmpa[i] = v,
            Err(_) => return Err(-1),
        }
    }
    Ok(Theatre::new(tmpa[0], tmpa[1], tmpa[2]))
}

fn main() {
    match get_args() {
        Ok(t) => println!("{}", t.stones()),
        Err(_) => panic!("Invalid argument"),
    }

}


use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut s = buf.split_whitespace();
    let n: u32 = s.next().unwrap().trim().parse().unwrap();
    let m: u32 = s.next().unwrap().trim().parse().unwrap();
    let a: u32 = s.next().unwrap().trim().parse().unwrap();
    let res = ((n + a - 1) / a) * ((m + a - 1) / a);
    println!("{}", res);
}


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

fn main() {
    let n: u64;
    let m: u64;
    let a: u64;

    {
        let values: Vec<u64> = read_str()
            .split_whitespace()
            .map(|value| value.parse::<u64>().expect("Error"))
            .collect();
        n = values[0];
        m = values[1];
        a = values[2];
    }

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


use std::env;

fn count_num_flagstones(n : usize, m : usize, a : usize) -> usize {
    let n_div_a = n / a;
    let n_mod_a = n % a;
    let m_div_a = m / a;
    let m_mod_a = m % a;
    let t_1 = if n_mod_a > 0 { n_div_a + 1 } else { n_div_a };
    let t_2 = if m_mod_a > 0 { m_div_a + 1 } else { m_div_a };
    t_1 * t_2
}

fn main() {
    let args : Vec<String> = env::args().collect();
    let n : usize = args[1].parse().unwrap();
    let m : usize = args[2].parse().unwrap();
    let a : usize = args[3].parse().unwrap();
    let result : usize = count_num_flagstones(n, m, a);
    println!("{}", result);
}


use std::io::Read;

fn input(read_file: bool) -> String {
    if read_file {
        let mut file = std::fs::File::open("sample.txt").unwrap();
        let mut buf = String::new();
        file.read_to_string(&mut buf).unwrap();
        buf
    } else {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();
        buf.trim_end().to_owned()
    }
}

fn solve(ws: &mut std::str::SplitWhitespace) {
    let n: i32 = ws.next().unwrap().parse().unwrap();
    let m: i32 = ws.next().unwrap().parse().unwrap();
    let a: i32 = ws.next().unwrap().parse().unwrap();

    let round_up = |a: i32, b: i32| (a + b - 1) / b;
    println!("{}", round_up(n, a) * round_up(m, a));
}

fn main() {
    const READ_FROM_FILE: bool = false;

    let s = input(READ_FROM_FILE);
    let mut ws = s.split_whitespace();

    // let t = ws.next().unwrap().parse().unwrap();
    // for _ in 0..t {}
    solve(&mut ws);
}


fn main() {
    let mut input = get_input().trim().to_string();
    let splited_str: Vec<&str> = input.split(' ').collect();
    let n = splited_str[0].parse::<f32>().unwrap();
    let m = splited_str[1].parse::<f32>().unwrap();
    let a = splited_str[2].parse::<f32>().unwrap();

    let result = (n / a).ceil() * (m / a).ceil();
    println!("{}", result);
}

fn get_input() -> String {
    use std::io::{stdin,stdout,Write};
    let mut s=String::new();
    stdout().flush().expect("Output Error!");
    stdin().read_line(&mut s).expect("Input Error!");
    if let Some('\n')=s.chars().next_back() {
        s.pop();
    }
    if let Some('\r')=s.chars().next_back() {
        s.pop();
    }

    s
}


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

macro_rules! scanln {
    ( $($ty:ty),* ) => {{
        let line = gets();
        let mut it = line.split_whitespace();
        ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )
    }}
}

fn main() -> () {

    let (n,m,a) = scanln!(i64, i64, i64);
    let ans = ((n + a - 1) / a) + ((m + a - 1) / a);
    println!("{}", ans);
}


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

macro_rules! scanln {
    ($($ty: ty),*) => {{
        let line = readln();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$ty>().unwrap()),*)
    }}
}

fn ceil(a: i32, b: i32) -> i32 {
    (a - 1) / b + 1
}

fn main() {
    let (n, m, a) = scanln!(i32, i32, i32);
    println!("{}", ceil(n, a) * ceil(m, a));
}


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::stdin;
use std::collections::HashSet;

fn read_line<'a>() -> Result<String, Box<std::error::Error>> {
    let mut line = String::new();
    stdin().read_line(&mut line)?;

    Ok(line.trim().to_owned())
}

fn main() -> Result<(), Box<std::error::Error>> {
    let line = read_line()?;
    let mut nums = line
        .split(' ')
        .map(|s| s.parse::<i32>().unwrap());

    let _ = nums.next().unwrap();
    let mut b = nums.next().unwrap();

    let line = read_line()?;

    let nums = line
        .split(' ')
        .map(|s| s.parse::<i32>().unwrap())
        .collect::<Vec<_>>();

    let evency = nums
        .iter()
        .map(|n| if n % 2 == 0 { 1 } else { -1 })
        .collect::<Vec<_>>();

    let mut split_points = HashSet::new();
    let mut s = 0;

    for (i, e) in evency[..evency.len() - 1].iter().enumerate() {
        s += e;

        // println!("{}, {}, {}", i, s, e);

        if s == 0 {
            split_points.insert(i);
        }
    }

    let mut diffs = nums
        .iter()
        .zip(&nums[1..])
        .map(|(&prev, &curr)| (curr - prev).abs())
        .enumerate()
        .collect::<Vec<_>>();

    diffs.sort_unstable_by_key(|&(_, diff)| diff);

    println!("diffs: {:?}", diffs);
    println!("split_points: {:?}", split_points);

    let mut ans = 0;

    for (i, diff) in diffs {
        if split_points.contains(&i) && b >= diff {
            println!("split at {}, price {}, current budget: {}", i, diff, b);

            ans += 1;
            b -= diff;
        }
    }

    println!("{}", ans);

    Ok(())
}


/*
 *
 * Author : fcbruce <fcbruce8964@gmail.com>
 *
 * Time : Sat 10 Feb 2018 20:02:28
 *
 */

fn main() {

  let mut buffer = String::new();
  std::io::stdin().read_line(&mut buffer).unwrap();
  let mut numbers = buffer.split_whitespace();
  let n: u64 = numbers.next().unwrap().parse::<u64>().unwrap();
  let k: u64 = numbers.next().unwrap().parse::<u64>().unwrap();

  let max: usize = 100000;

  let mut remainders = vec![false; max];

  let mut min = k + 1;

  for i in 1..std::cmp::min::<u64>(max as u64, k) {
    let r: usize = (n % i) as usize;
    if remainders[r] {
      min = i;
      break;
    }
    remainders[r] = true;
  }

  if k == 1 || k < min {
    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 n = get!();
    let k = get!();

    if k >= n {
        println!("No");
        return;
    }

    if n % k == k - 1 {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

// Input macros.
// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ===

fn main() {
    input! {
        n: usize,
        a: [usize1; n]
    };

    let INF = 1000000000i64;
    let table = vec![
        vec![-INF, 3, 4],
        vec![3, -INF, -INF],
        vec![4, -INF, -INF],
    ];

    let mut points = 0i64;
    for i in 1..n {
        points += table[a[i-1]][a[i]];
    }
    if points <= -1 {
        println!("Infinite");
    } else {
        println!("Finite");
        println!("{}", points);
    }
}


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

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

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::io::Write;
type I = usize;

fn main() {
    input!{
      n: usize,
      aa: [usize; n],
    }

    let mut ans: u64 = 0;
    for i in 1..n {
         let a1 = aa[i-1];
         let a2 = aa[i];
         let mut a = [a1, a2];
         a.sort();

         if a[0] != 1 {
             return println!("{}", "Infinite");
         }

         if a[1] == 2 {
             ans += 3;
         } else {
            ans += 4;
         }
    }
    println!("{}", "Finite");
    println!("{}", ans);
}