#![allow(unused_imports)]
#![allow(unused_must_use)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(clippy::too_many_arguments)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::needless_range_loop)]
#![allow(clippy::comparison_chain)]

use std::cmp::{max, min, Reverse};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, prelude::*};
use std::str;

fn solve<R: BufRead, W: Write>(sc: &mut Scanner<R>, wr: &mut W) {
    const MOD: i64 = 1_000_000_007;
    let n: usize = sc.tok();
    let lowest = sieve(n);
    let mut phi = vec![1; n + 1];
    for k0 in 2..=n {
        let p = lowest[k0];
        let mut pow = 1;
        let mut k = k0;
        while k % p == 0 {
            k /= p;
            pow *= p;
        }
        phi[k0] = phi[k] * ((p - 1) * (pow / p)) as i64;
    }
    let mut res = 0;
    for g in 1..=n as i64 - 1 {
        let mut s = 2 * g;
        while s < n as i64 {
            res += phi[(s / g) as usize] * lcm(g, n as i64 - s) % MOD;
            if res >= MOD {
                res -= MOD;
            }
            s += g;
        }
    }
    writeln!(wr, "{}", res);
}

pub fn gcd(mut a: i64, mut b: i64) -> i64 {
    a = a.abs();
    b = b.abs();
    while b > 0 {
        a %= b;
        (a, b) = (b, a);
    }
    a
}

pub fn lcm(a: i64, b: i64) -> i64 {
    if (a, b) == (0, 0) {
        0
    } else {
        a / gcd(a, b) * b
    }
}
fn sieve(max: usize) -> Vec<usize> {
    let mut primes = vec![];
    let mut lowest = vec![0; max + 1];
    for n in 2..=max {
        if lowest[n] == 0 {
            lowest[n] = n;
            primes.push(n);
        }
        for &p in &primes {
            if p > lowest[n] || p * n > max {
                break;
            }
            lowest[p * n] = p;
        }
    }
    lowest
}

use std::marker::PhantomData;
macro_rules! recursive_function {
    ($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {
        pub trait $trait<$($type, )*Output> {
            fn call(&mut self, $($arg: $type,)*) -> Output;
        }

        pub struct $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            f: F,
            $($arg: PhantomData<$type>,
            )*
            phantom_output: PhantomData<Output>,
        }

        impl<F, $($type, )*Output> $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            pub fn new(f: F) -> Self {
                Self {
                    f,
                    $($arg: Default::default(),
                    )*
                    phantom_output: Default::default(),
                }
            }
        }

        impl<F, $($type, )*Output> $trait<$($type, )*Output> for $name<F, $($type, )*Output>
        where
            F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,
        {
            fn call(&mut self, $($arg: $type,)*) -> Output {
                let const_ptr = &self.f as *const F;
                let mut_ptr = const_ptr as *mut F;
                unsafe { (&mut *mut_ptr)(self, $($arg, )*) }
            }
        }
    }
}

recursive_function!(RecursiveFunction0, Callable0, ());
recursive_function!(RecursiveFunction, Callable, (Arg arg,));
recursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));
recursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));
recursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));
recursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));
recursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));
recursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));
recursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));
recursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));

#[macro_export]
macro_rules! dbg{
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        eprintln!(
            concat!("{}:{}:{}: ",$(stringify!($a), " = {:?}, "),*),
            file!(), line!(), column!(), $($a),*
        );
        #[cfg(not(debug_assertions))]
        {};
    }
}
struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn tok<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

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::char;
use std::fs::File;
use std::io::Read;

// fn pow_speedt_with_mod(mut p: i64, mut q: i64, m: i64) -> i64 {
//     p %= m;
//     let mut r = p;
//     let mut ret: i64 = 1;
//     while q > 0 {
//         ret *= if q % 2 == 1 {r} else {1};
//         r *= r;
//         r %= m;
//         q /= 2;
//         ret %= m;
//     }
//     return ret;
// }

fn main() {
    let inputstatus = 1;

    let mut buf = String::new();
    let filename = "inputrust.txt";

    if inputstatus == 0 {
        let mut f = File::open(filename).expect("file not found");
        f.read_to_string(&mut buf)
            .expect("something went wrong reading the file");
    } else {
        std::io::stdin().read_to_string(&mut buf).unwrap();
    }

    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let mut v = Vec::<i32>::new();
    let mut v_commpress = Vec::<i32>::new();

    for _ in 0..n {
        v.push(iter.next().unwrap().parse().unwrap());
    }
    v.sort();

    for (i, vi) in v.iter().enumerate() {
        if i == 0 {
            v_commpress.push(*vi);
        } else if v[i - 1] != v[i] {
            v_commpress.push(*vi);
        }
    }

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

    let ans = if v_commpress.len() <= 1 {
        0
    } else if v_commpress.len() == 2 && (v_commpress[1] - v_commpress[0]) % 2 == 0 {
        (v_commpress[1] - v_commpress[0]) / 2
    } else if v_commpress.len() == 2 && (v_commpress[1] - v_commpress[0]) % 2 == 1 {
        v_commpress[1] - v_commpress[0]
    } else if v_commpress.len() == 3 && (v_commpress[2] + v_commpress[0]) == 2 * v_commpress[1] {
        v_commpress[1] - v_commpress[0]
    } else {
        -1
    };
    println!("{}", ans);

    // if p + 1 >= m

    // println!("{}", n);
    // println!("{}", k);
    // println!("{:?}", num);
    // println!("{:?}", cum_num);
}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ===

const MAX_CORD: i128 = 1e18 as i128;

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

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

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

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

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

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

    assert!(n >= 2);

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

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


use std::io;

fn main()
{
	let mut s = String::new();
	let mut n = String::new();
	io::stdin().read_line(&mut n).unwrap();
	let n = n.trim().parse::<u8>().unwrap();
	io::stdin().read_line(&mut s).unwrap();
	s = s.trim().to_string();
	let val: Vec<i8> = s.split(" ").map(|x: &str| x.parse::<i8>().unwrap()).collect();

	if let Ok(res) = match val[val.len()-1] {
		0 => Ok("UP"),
		15 => Ok("DOWN"),
		_ => if val.len() > 1 {
			match val[val.len()-1] - val[val.len()-2] {
				1 => Ok("UP"),
				-1 => Ok("DOWN"),
				_ => Err("invalid input"),
			}
		} else {
			print!("{}", -1);
			return;
		}
	} {
		print!("{}", res);
	}
	else {
		print!("{}", "invalid input");
	}

}


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

impl Scanner {
    pub fn new() -> Scanner {
        Scanner {
            buffer: std::collections::VecDeque::new(),
        }
    }
    pub fn next<T: std::str::FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut input = String::new();
            std::io::stdin().read_line(&mut input).ok();
            self.buffer = input.split_whitespace().map(ToString::to_string).collect();
        }
        let front = self.buffer.pop_front().unwrap();
        front.parse::<T>().ok().unwrap()
    }
}

fn main() {
    let mut scanner = Scanner::new();
    let days = scanner.next::<usize>();
    let mut time = scanner.next::<i32>();
    let mut used_time_by_day = Vec::with_capacity(days);
    let mut remaining_time_by_day = Vec::with_capacity(days);
    for _ in 0..days {
        let min = scanner.next::<u8>();
        let max = scanner.next::<u8>();
        time -= min as i32;
        used_time_by_day.push(min);
        remaining_time_by_day.push(max - min);
    }
    if time < 0 {
        println!("NO");
        return;
    }
    for i in 0..days {
        let delta = u8::min(remaining_time_by_day[i], time as u8);
        time -= delta as i32;
        used_time_by_day[i] += delta;
        if time == 0 {
            break;
        }
    }
    if time == 0 {
        println!("YES");
        for i in 0..days {
            print!("{} ", used_time_by_day[i]);
        }
    } else {
        println!("NO");
    }
}


fn input_sum() -> f32 {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|elem| elem.parse::<f32>().unwrap())
        .sum()
}

fn main() {
    print!(
        "{}",
        if (input_sum() / 5f32).ceil() + (input_sum() / 10f32).ceil() <= input_sum() {
            "YES"
        } else {
            "NO"
        }
    )
}


use std::io;

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

    let mut iter = input.split_whitespace();
    let mut a: u32 = iter.next().unwrap().parse().unwrap();
    let mut b: u32 = iter.next().unwrap().parse().unwrap();

    let mut output = 0;

    while a <= b {
        a *= 3;
        b *= 2;
        output += 1;
    }

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


use std::*;
use io::stdin;
use cmp::Ordering;
use cell::Cell;

fn resolve_pool(
    s: &[bool], mut offset: usize, mut lhs: Vec<Val>, mut rhs: Vec<Val>,
) -> Result<(Vec<Val>, usize), FailReason> {
    let mut l_ptr: usize = 0;
    let mut r_ptr: usize = 0;
    let mut next_pool = vec![];
    while l_ptr < lhs.len() && r_ptr < rhs.len() {
        // let l = &mut lhs[l_ptr];
        // let r = &mut rhs[r_ptr];
        let fst =
            if let Some(c) = s.get(offset) {
                c
            } else {
                return Err(FailReason::NotEnoughMerges);
            };
        if !fst {
            next_pool.push(lhs[l_ptr]);
            // l.history.get_mut().push(false);
            // next_pool.push(Val {
            //     val: lhs[l_ptr].val,
            //     history: Cell::new(lhs[l_ptr].history.take()),
            // });
            l_ptr += 1;
        } else {
            next_pool.push(rhs[r_ptr]);
            // r.history.get_mut().push(true);
            // next_pool.push(Val {
            //     val: rhs[r_ptr].val,
            //     history: Cell::new(rhs[r_ptr].history.take()),
            // });
            r_ptr += 1;
        }
        offset += 1;
    }
    if l_ptr < lhs.len() {
        next_pool.extend(lhs[l_ptr..].iter())
        // for i in l_ptr..lhs.len() {
        //     lhs[i].history.get_mut().push(false);
        //     next_pool.push(Val {
        //         val: lhs[i].val,
        //         history: Cell::from(lhs[i].history.take()),
        //     })
        // }
    } else {
        next_pool.extend(rhs[r_ptr..].iter())
        // for i in r_ptr..rhs.len() {
        //     rhs[i].history.get_mut().push(true);
        //     next_pool.push(Val {
        //         val: rhs[i].val,
        //         history: Cell::from(rhs[i].history.take()),
        //     })
        // }
    }
    Ok((next_pool, offset))
}

enum FailReason {
    NotEnoughMerges,
    TooManyMerges,
}

type Val = usize;

// struct Val {
//     val: usize,
//     history: Cell<Vec<bool>>,
// }

fn solve(s: &[bool]) -> Vec<Val> {
    fn solve_with_assumed_size(s: &[bool], vals: Vec<Val>) -> Result<Vec<Val>, FailReason> {
        fn rec_resolve(
            mut rg: Vec<Val>, s: &[bool], offset: usize,
        ) -> Result<(Vec<Val>, usize), FailReason> {
            if rg.len() <= 1 {
                return Ok((rg, offset));
            }
            let lhs_upper = rg.len() >> 1;
            let rhs = rg.drain(lhs_upper..).collect();
            let lhs = rg;
            let (left_part_of_pool, offset) = rec_resolve(lhs, s, offset)?;
            let (right_part_of_pool, offset) = rec_resolve(rhs, s, offset)?;

            Ok(resolve_pool(s, offset, left_part_of_pool, right_part_of_pool)?)
        }

        // let merge_count = f64::log2(sz as f64) as usize;
        // let mut known_relations = vec![vec![None; vals.len()]; vals.len()];

        let (vals, offset) = rec_resolve(vals, s, 0)?;
        match offset.cmp(&s.len()) {
            Ordering::Less => Err(FailReason::TooManyMerges),
            Ordering::Greater => Err(FailReason::NotEnoughMerges),

            Ordering::Equal => {
                let mut ans = vec![0; vals.len()];
                for (i, pos) in vals.into_iter().enumerate() {
                    ans[pos] = i + 1;
                }
                Ok(ans)
            }
        }
    }

    let mut lower_bound = 2;
    let mut upper_bound = 1e3 as usize;
    let mut vals = Vec::with_capacity(upper_bound);
    for i in 0..upper_bound {
        vals.push(i)
        // vals.push(Val { val: i, history: Cell::new(vec![]) });
    }
    let mut prev_assumed_size = None;
    loop {
        let assumed_size = {
            let assumed_size = lower_bound + (upper_bound - lower_bound) / 2;
            if assumed_size == 999 && prev_assumed_size.unwrap() == assumed_size {
                1000
            } else {
                assumed_size
            }
        };
        let mut vals_to_pass = vec![];
        for i in 0..assumed_size {
            vals_to_pass.push(i);
            // let val = &mut vals[i];
            // vals_to_pass.push(Val {
            //     val: val.val,
            //     history: Cell::new(val.history.get_mut().clone()),
            // })
        }
        match solve_with_assumed_size(s, vals_to_pass) {
            Ok(ans) => return ans,
            Err(FailReason::NotEnoughMerges) => {
                upper_bound = assumed_size;
            }
            Err(FailReason::TooManyMerges) => {
                lower_bound = assumed_size;
            }
        }
        prev_assumed_size = Some(assumed_size);
    }
}

fn main() {
    let mut buffer = String::new();
    stdin().read_line(&mut buffer);
    let buffer = Vec::from(buffer
        .chars()
        .filter_map(|x| {
            match x {
                '0' => Some(false),
                '1' => Some(true),
                _ => None
            }
        })
        .collect::<Vec<bool>>());
    let ans = solve(&buffer);
    println!("{}", ans.len());
    for v in ans {
        print!("{} ", v);
    }
}


#![warn(
    clippy::all,
    rust_2018_idioms,
    missing_copy_implementations,
    missing_debug_implementations,
    single_use_lifetimes,
    trivial_casts,
    unused_import_braces,
    unused_qualifications,
    unused_results
)]
#![allow(
    clippy::many_single_char_names,
    non_snake_case,
    unused_imports,
    unused_macros,
    dead_code
)]

#[cfg(test)]
macro_rules! debugln {
    () => {
        println!();
    };
    ($val:expr) => {
        print!("{:?} ", &$val);
    };
    ($($val:expr),+ $(,)?) => {
        $(debugln!($val);)+
    };
}

#[cfg(not(test))]
macro_rules! debugln {
    ($($tt:tt)*) => {
        let _ = ($($tt)*);
    };
}

#[cfg(not(test))]
macro_rules! println {
    ($($tt:tt)*) => {
        let _ = ($($tt)*);
    };
}

#[cfg(not(test))]
macro_rules! print {
    ($($tt:tt)*) => {
        let _ = ($($tt)*);
    };
}

mod task {
    use crate::io::Io;
    use crate::util::*;
    use std::io::{BufRead, Write};

    pub const MODE: Mode = Mode::Single;

    pub fn solution<B: BufRead + Write>(io: &mut Io<B>) {
        use crate::*;
        use core::cmp::Ordering::{Equal, Greater, Less};
        use core::cmp::{max, min};
        use core::iter::{empty, once, repeat, FromIterator};
        use core::mem::swap;
        use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};

        //const N_MAX: usize = 100;
        //let mut a = [0; N_MAX];
        //let n: usize = io.read();
        //let a: Vec<i64> = io.read_n(n).collect();
        //let a: Vec<(i64, i64)> = io.read_n_pairs(n).collect();
        //let a: Vec<(i64, i64, i64)> = io.read_n_triplets(n).collect();
        //let a: Vec<i64> = (0..n).map(|_| io.read()).collect();
        //let a: &str = io.read_str();
        //let a: Vec<u8> = io.read_bytes().to_vec();
        //let a: Vec<u8> = io.read_decimal().collect();
        //let a: Vec<bool> = io.read_bits(b'1').collect();
        //debugln!([false, true].pm_fmt());

        let h: usize = io.read();
        let w: usize = io.read();
        let mut a = [[false; 10]; 10];
        for y in 0..h {
            let b: Vec<bool> = io.read_bits(b'*').collect();
            for x in 0..w {
                a[y][x] = b[x];
            }
        }

        let mut ans = 0;
        let mut x = 0;
        let mut y = 0;
        'outer: while x < w - 1 && y < h - 1 {
            ans += a[y][x] as i64;
            for j in 1..5 {
                if a[y][x + j] {
                    x += 1;
                    continue 'outer;
                } else if a[y + j][x] {
                    y += 1;
                    continue 'outer;
                }
            }
            x += 1;
            continue;
        }

        while x < w - 1 {
            ans += a[y][x] as i64;
            x += 1;
        }

        while y < h - 1 {
            ans += a[y][x] as i64;
            y += 1;
        }

        ans += a[y][x] as i64;

        io.writeln(ans);
    }

    #[cfg(test)]
    fn alternative<B: BufRead + Write>(_io: &mut Io<B>) {
        panic!()
    }

    #[cfg(test)]
    #[test]
    fn test_example() {
        let output = |input: &str| output_for(|io| solution(io), Mode::Multiple, &input);
        assert_eq!(
            output(
                "4
            4 3
            *..
            .*.
            ..*
            ...
            4 4
            .*..
            *...
            ...*
            ..*.
            3 4
            ..**
            *...
            ....
            5 5
            ..*..
            .....
            **...
            **...
            **...
            "
            ),
            "3\n2\n1\n1\n".reformat_with_trim(),
        );
    }

    /*#[cfg(test)]
    #[test]
    fn test_custom() {
        let output = |input: &str| output_for(|io| solution(io), Mode::Single, &input);
        assert_eq!(output("5 5 1 2 3 4 5"), "1\n2\n3\n4\n5\n");
    }*/

    /*#[cfg(test)]
    #[test]
    fn test_matched() {
        let matched = |input: &str| matched_for(
            |io| solution(io), |io| alternative(io), Mode::Single, &input,
        );
    }*/
}

pub fn main() {
    use std::io::{stdin, stdout, BufReader, BufWriter};

    use task::{solution, MODE};

    let mut reader = BufReader::new(stdin());
    let mut writer = BufWriter::new(stdout());
    let mut io = Io::new(IoPair::new(&mut reader, &mut writer));
    solve(solution, MODE, &mut io);
    io.flush();
}

use ceil::*;
mod ceil {
    use core::ops::{Add, Div, Sub};

    use crate::div_euclid::DivEuclid;
    use crate::one::One;

    #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
    pub struct Ceil<T>(pub T);

    impl<T> Div<T> for Ceil<T>
    where
        T: Add<Output = T> + Clone + DivEuclid + One + Sub<Output = T>,
    {
        type Output = T;

        fn div(self, rhs: T) -> Self::Output {
            (self.0 + rhs.clone() - T::one()).div_euclid(rhs)
        }
    }
}

use each::*;
mod each {
    #[allow(single_use_lifetimes)]
    pub trait Each<'a> {
        type Iter;
        fn each(&'a self) -> Self::Iter;
    }

    impl<'a, I> Each<'a> for [I]
    where
        I: 'a + Clone + IntoIterator,
    {
        type Iter = SliceEach<'a, I>;
        fn each(&'a self) -> Self::Iter {
            SliceEach::new(self)
        }
    }

    #[allow(clippy::type_complexity)]
    #[derive(Clone, Debug)]
    pub struct SliceEach<'a, I>(Option<(&'a [I], Vec<I::IntoIter>, Vec<I::Item>)>)
    where
        I: Clone + IntoIterator;

    impl<'a, I> SliceEach<'a, I>
    where
        I: Clone + IntoIterator,
    {
        pub fn new(iter: &'a [I]) -> Self {
            Self(Some((iter, Vec::new(), Vec::new())))
        }
    }

    impl<I> Iterator for SliceEach<'_, I>
    where
        I: Clone + IntoIterator,
        I::Item: Clone,
    {
        type Item = Vec<I::Item>;

        fn next(&mut self) -> Option<Self::Item> {
            self.0.take().and_then(|mut data| loop {
                if data.2.len() < data.1.len() {
                    let mut last = data.1.pop().unwrap();
                    if let Some(value) = last.next() {
                        data.1.push(last);
                        data.2.push(value);
                    } else {
                        let _ = data.2.pop()?;
                    }
                } else if data.1.len() < data.0.len() {
                    data.1.push(data.0[data.1.len()].clone().into_iter());
                } else {
                    let item = data.2.clone();
                    let _ = data.2.pop();
                    self.0 = Some(data);
                    return Some(item);
                }
            })
        }
    }
}

use into_vec::*;
mod into_vec {
    pub trait IntoVec<T> {
        fn into_vec(self) -> Vec<T>;
    }

    impl<I, T> IntoVec<T> for I
    where
        Self: Sized,
        I: IntoIterator<Item = T>,
    {
        fn into_vec(self) -> Vec<T> {
            self.into_iter().collect()
        }
    }
}

use io::*;
mod io {
    use std::fmt::{Debug, Display};
    use std::io::{self, BufRead, Read, Write};

    #[derive(Clone, Debug)]
    pub struct IoPair<R, W> {
        reader: R,
        writer: W,
    }

    #[derive(Clone, Debug)]
    pub struct Io<B> {
        io: B,
        reader_line: String,
        reader_offset: usize,
        is_writer_bol: bool,
    }

    impl<R, W> IoPair<R, W> {
        pub fn new(reader: R, writer: W) -> Self {
            Self { reader, writer }
        }

        pub fn reader_ref(&self) -> &R {
            &self.reader
        }

        pub fn writer_ref(&self) -> &W {
            &self.writer
        }

        pub fn reader_mut(&mut self) -> &mut R {
            &mut self.reader
        }

        pub fn writer_mut(&mut self) -> &mut W {
            &mut self.writer
        }
    }

    impl<R: Read, W> Read for IoPair<R, W> {
        fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
            self.reader.read(buf)
        }
    }

    impl<R: BufRead, W> BufRead for IoPair<R, W> {
        fn fill_buf(&mut self) -> io::Result<&[u8]> {
            self.reader.fill_buf()
        }

        fn consume(&mut self, amt: usize) {
            self.reader.consume(amt)
        }
    }

    impl<R, W: Write> Write for IoPair<R, W> {
        fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
            self.writer.write(buf)
        }

        fn flush(&mut self) -> std::io::Result<()> {
            self.writer.flush()
        }
    }

    impl<B: BufRead + Write> Io<B> {
        pub fn new(io: B) -> Self {
            Self {
                io,
                reader_line: String::new(),
                reader_offset: 0,
                is_writer_bol: true,
            }
        }

        pub fn get_ref(&self) -> &B {
            &self.io
        }

        pub fn get_mut(&mut self) -> &mut B {
            &mut self.io
        }

        pub fn try_read_str(&mut self) -> Result<&str, io::Error> {
            loop {
                if self.reader_offset >= self.reader_line.len() {
                    self.reader_line.clear();
                    let _ = self.io.read_line(&mut self.reader_line)?;
                    self.reader_offset = 0;
                } else if self.reader_line.as_bytes()[self.reader_offset].is_ascii_whitespace() {
                    self.reader_offset += 1;
                } else {
                    let line = self.reader_line.as_bytes();
                    let start = self.reader_offset;
                    let mut end = start + 1;
                    while end < self.reader_line.len() && !line[end].is_ascii_whitespace() {
                        end += 1;
                    }
                    self.reader_offset = end + 1;
                    let word = unsafe { std::str::from_utf8_unchecked(&line[start..end]) };
                    return Ok(word);
                }
            }
        }

        pub fn try_read<T: std::str::FromStr>(&mut self) -> Result<T, io::Error>
        where
            <T as std::str::FromStr>::Err: Debug,
        {
            Ok(self.try_read_str()?.parse::<T>().unwrap())
        }

        pub fn try_read_bytes(&mut self) -> Result<&[u8], io::Error> {
            Ok(self.try_read_str()?.as_bytes())
        }

        pub fn try_read_decimal(&mut self) -> Result<impl '_ + Iterator<Item = u8>, io::Error> {
            Ok(self.try_read_bytes()?.iter().map(|ch| ch - b'0'))
        }

        pub fn try_read_bits(
            &mut self,
            one: u8,
        ) -> Result<impl '_ + Iterator<Item = bool>, io::Error> {
            Ok(self.try_read_bytes()?.iter().map(move |ch| *ch == one))
        }

        pub fn read_str(&mut self) -> &str {
            self.try_read_str().unwrap()
        }

        pub fn read<T: std::str::FromStr>(&mut self) -> T
        where
            <T as std::str::FromStr>::Err: Debug,
        {
            self.try_read().unwrap()
        }

        pub fn read_n<T: std::str::FromStr>(&mut self, n: usize) -> impl '_ + Iterator<Item = T>
        where
            <T as std::str::FromStr>::Err: Debug,
        {
            (0..n).map(move |_| self.read())
        }

        pub fn read_n_pairs<T1: std::str::FromStr, T2: std::str::FromStr>(
            &mut self,
            n: usize,
        ) -> impl '_ + Iterator<Item = (T1, T2)>
        where
            <T1 as std::str::FromStr>::Err: Debug,
            <T2 as std::str::FromStr>::Err: Debug,
        {
            (0..n).map(move |_| (self.read(), self.read()))
        }

        pub fn read_n_triplets<
            T1: std::str::FromStr,
            T2: std::str::FromStr,
            T3: std::str::FromStr,
        >(
            &mut self,
            n: usize,
        ) -> impl '_ + Iterator<Item = (T1, T2, T3)>
        where
            <T1 as std::str::FromStr>::Err: Debug,
            <T2 as std::str::FromStr>::Err: Debug,
            <T3 as std::str::FromStr>::Err: Debug,
        {
            (0..n).map(move |_| (self.read(), self.read(), self.read()))
        }

        pub fn read_bytes(&mut self) -> &[u8] {
            self.try_read_bytes().unwrap()
        }

        pub fn read_decimal(&mut self) -> impl '_ + Iterator<Item = u8> {
            self.try_read_decimal().unwrap()
        }

        pub fn read_bits(&mut self, one: u8) -> impl '_ + Iterator<Item = bool> {
            self.try_read_bits(one).unwrap()
        }

        pub fn write<T: Display>(&mut self, value: T) -> &mut Self {
            if self.is_writer_bol {
                write!(self.io, "{}", value).unwrap();
            } else {
                write!(self.io, " {}", value).unwrap();
            }
            self.is_writer_bol = false;
            self
        }

        pub fn writeln<T: Display>(&mut self, value: T) {
            if self.is_writer_bol {
                writeln!(self.io, "{}", value).unwrap();
            } else {
                writeln!(self.io, " {}", value).unwrap();
            }
            self.is_writer_bol = true;
        }

        pub fn write_all<T: Display, U: IntoIterator<Item = T>>(&mut self, iter: U) -> &mut Self {
            for value in iter.into_iter() {
                let _ = self.write(value);
            }
            self
        }

        pub fn writeln_all<T: Display, U: IntoIterator<Item = T>>(&mut self, iter: U) {
            self.write_all(iter).ln();
        }

        pub fn write_bytes(&mut self, bytes: &[u8]) -> &mut Self {
            self.write(std::str::from_utf8(bytes).unwrap())
        }

        pub fn writeln_bytes(&mut self, bytes: &[u8]) {
            self.write_bytes(bytes).ln();
        }

        pub fn write_join<T: Display>(&mut self, value: T) -> &mut Self {
            write!(self.io, "{}", value).unwrap();
            self.is_writer_bol = false;
            self
        }

        pub fn ln(&mut self) {
            writeln!(self.io).unwrap();
            self.is_writer_bol = true;
        }

        pub fn yes(&mut self) {
            self.writeln("YES");
        }

        pub fn no(&mut self) {
            self.writeln("NO");
        }

        pub fn flush(&mut self) {
            let _ = self.io.flush();
        }

        pub fn writeln_flush<T: Display>(&mut self, value: T) {
            self.writeln(value);
            self.flush();
        }

        pub fn writeln_all_flush<T: Display, U: IntoIterator<Item = T>>(&mut self, iter: U) {
            self.writeln_all(iter);
            self.flush();
        }

        pub fn ln_flush(&mut self) {
            self.ln();
            self.flush();
        }
    }
}

use target::*;
mod target {
    #[cfg(test)]
    #[test]
    fn test_32bit_target() {
        use core::mem::size_of;
        assert_eq!(size_of::<usize>(), 4, "Codeforces use 32-bit targets");
    }
}

use to_iterator::*;
mod to_iterator {
    pub trait ToIterator: Clone + IntoIterator {
        fn to_iter(&self) -> Self::IntoIter;
    }

    impl<T> ToIterator for T
    where
        T: Clone + IntoIterator,
    {
        fn to_iter(&self) -> Self::IntoIter {
            self.clone().into_iter()
        }
    }
}

use to_vec::*;
mod to_vec {
    use crate::to_iterator::ToIterator;

    pub trait ToVec<T> {
        fn to_vec(&self) -> Vec<T>;
    }

    impl<I, T> ToVec<T> for I
    where
        Self: Sized,
        I: ToIterator<Item = T>,
    {
        fn to_vec(&self) -> Vec<T> {
            self.to_iter().collect()
        }
    }
}

use util::*;
mod util {
    use std::io::BufRead;
    use std::io::Write;

    use crate::io::{Io, IoPair};

    #[derive(Clone, Copy, Debug, Eq, PartialEq)]
    pub enum Mode {
        Single,   // If only the single test case is expected
        Multiple, // If multiple test cases are expected
    }

    pub fn solve<F, B>(func: F, mode: Mode, io: &mut Io<B>)
    where
        F: Fn(&mut Io<B>),
        B: BufRead + Write,
    {
        match mode {
            Mode::Single => {
                func(io);
                io.flush();
            }
            Mode::Multiple => {
                let n: usize = io.read();
                for _ in 0..n {
                    func(io);
                    io.flush();
                }
            }
        }
    }

    pub fn output_for<F>(func: F, mode: Mode, input: &str) -> String
    where
        F: Fn(&mut Io<IoPair<&[u8], Vec<u8>>>),
    {
        let reader = input.as_bytes();
        let writer = Vec::new();
        let mut io = Io::new(IoPair::new(reader, writer));
        solve(func, mode, &mut io);
        std::str::from_utf8(io.get_ref().writer_ref())
            .unwrap()
            .to_string()
    }

    #[cfg(test)]
    pub fn matched_for<F1, F2>(solution: F1, alternative: F2, mode: Mode, input: &str)
    where
        F1: Fn(&mut Io<IoPair<&[u8], Vec<u8>>>),
        F2: Fn(&mut Io<IoPair<&[u8], Vec<u8>>>),
    {
        assert_eq!(
            output_for(|io| solution(io), mode, input),
            output_for(|io| alternative(io), mode, input),
            "Where left is `solution`, right is `alternative`, and input is: {}",
            input
        );
    }

    #[cfg(test)]
    pub fn join_to_string<T, I>(items: I) -> String
    where
        T: ToString,
        I: IntoIterator<Item = T>,
    {
        items
            .into_iter()
            .map(|item| item.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    }

    pub trait ReformatWithTrim {
        fn reformat_with_trim(self) -> String;
    }

    impl ReformatWithTrim for &str {
        fn reformat_with_trim(self) -> String {
            let lines: Vec<String> = self
                .trim()
                .lines()
                .map(|line| line.trim_start().to_string())
                .collect();
            lines.join("\n") + "\n"
        }
    }

    pub trait FormatBits {
        fn pm_fmt(self) -> String;
    }

    impl FormatBits for &[bool] {
        fn pm_fmt(self) -> String {
            self.iter()
                .map(|item| if *item { "+" } else { "-" })
                .collect()
        }
    }
}

use div_euclid::*;
mod div_euclid {
    pub trait DivEuclid {
        fn div_euclid(self, rhs: Self) -> Self;
    }

    macro_rules! impl_ops {
        ($($type:tt)*) => {
            $(
                impl DivEuclid for $type {
                    fn div_euclid(self, rhs: Self) -> Self {
                        self.div_euclid(rhs)
                    }
                }
            )*
        };
    }

    impl_ops!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
}

use one::*;
mod one {
    pub trait One {
        fn one() -> Self;
        fn is_one(&self) -> bool;
    }

    macro_rules! impl_ops {
        ($($type:tt)*) => {
            $(
                impl One for $type {
                    fn one() -> Self {
                        1
                    }

                    fn is_one(&self) -> bool {
                        *self == 1
                    }
                }
            )*
        };
    }

    impl_ops!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
}


#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[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 n = get!(u64);
    let m9 = (0..)
        .take_while(|&x| (2 * n - 1) >= 10u64.pow(x as u32) - 1)
        .last()
        .unwrap();

    let mut ans = 0;
    for i in 0.. {
        let y = i as u64 * 10u64.pow(m9 as u32) + 10u64.pow(m9 as u32) - 1;
        if y > 2 * n - 1 {
            break;
        }
        if y <= 2 * n - 1 && y > 0 {
            if y > n {
                ans += (n - (y - n) - 1) / 2 + 1;
            } else {
                ans += (y - 1) / 2;
            }
        }
    }

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


fn main() {
    let (_, l) = {
        let r = getvec::<i32>();
        (r[0] as usize, r[1])
    };
    let a = getvec::<i32>();
    let b = getvec::<i32>();
    let am = calc(&a, l);
    // for x in am.clone() {
    //     println!("{}", x);
    // }
    let bm = calc(&b, l);
    println!("{}",
             match ok(&am, &bm) {
                 true => "YES",
                 false => "NO",
             });
}
fn ok(a: &Vec<i32>, b: &Vec<i32>) -> bool {
    let n = a.len();
    for i in 0..n {
        let mut r = true;
        for j in 0..n {
            let j_ = (j + i) % n;
            if a[j] != b[j_] {
                r = false;
                break;
            }
        }
        if r {
            return true;
        }
    }
    false
}
fn calc(seq: &Vec<i32>, l: i32) -> Vec<i32> {
    let mut res = Vec::new();
    let n = seq.len();
    for i in 0..n - 1 {
        res.push(seq[i + 1] - seq[i]);
    }
    res.push(l - seq[n - 1] + seq[0]);
    res
}
#[allow(dead_code)]
fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input
}

#[allow(dead_code)]
fn getnum<T: std::str::FromStr>() -> T {
    let res = next_line();
    res.trim().parse::<T>().ok().unwrap()
}

#[allow(dead_code)]
fn getvec<T: std::str::FromStr>() -> Vec<T> {
    let res = next_line();
    res.split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect()
}


// This code is licensed under the terms of Apache-2.0 <http://www.apache.org/licenses/LICENSE-2.0> or MIT License <https://opensource.org/licenses/MIT>, at your choice.

use crate::comprog_lib::scanner::Scanner;
use std::cmp::min;
use std::io::{self, Read, Write};
pub fn solve<R: Read, W: Write>(read: R, out: &mut W) -> io::Result<()> {
    let mut sc = Scanner::from(read);
    let n = sc.usize();
    let s = sc.token();
    let mut next = vec![[n; 26]; n + 1];
    for i in (0..n).rev() {
        next[i] = next[i + 1].clone();
        next[i][(s[i] - b'a') as usize] = i;
    }
    #[allow(non_snake_case)]
    let INF = std::i32::MAX;
    let mut dp = vec![vec![INF; n + 1]; n + 1];
    let mut dp2 = vec![vec![[INF; 26]; n + 1]; n + 1];
    for i in 0..=n {
        dp[i][i] = 0;
        for a in 0..26 {
            dp2[i][i][a] = 0;
        }
    }
    for len in 1..=n {
        for l in 0..=n - len {
            let r = l + len;
            for a in 0..26 {
                let mut x = len as i32;
                if (s[r - 1] - b'a') as usize == a {
                    x = min(x, dp2[l][r - 1][a]);
                }
                for k in l + 1..r {
                    x = min(x, dp2[l][k][a] + dp[k][r]);
                }
                dp2[l][r][a] = x;
            }
            dp[l][r] = dp2[l][r].iter().cloned().min().unwrap() + 1;
        }
    }
    let ans = dp[0][n];
    writeln!(out, "{}", ans)?;
    Ok(())
}
fn main() {
    let stdin = io::stdin();
    let mut stdout = io::BufWriter::new(io::stdout());
    solve(stdin.lock(), &mut stdout).unwrap();
}
mod comprog_lib {
    // comprog_lib-0.1.0
    pub mod scan_buf {
        use std::io::{self, Read};
        #[derive(Debug, Clone)]
        pub struct ScanBuf {
            buf: Vec<u8>,
            pos: usize,
            end: usize,
        }
        #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
        pub struct ScanRange(pub usize, pub usize);
        impl ScanRange {
            pub fn slice(self, buf: &ScanBuf) -> &[u8] {
                &buf.buf[self.0..self.1]
            }
        }
        impl ScanBuf {
            pub fn new(initial_capacity: usize) -> Self {
                ScanBuf {
                    buf: vec![0; initial_capacity],
                    pos: 0,
                    end: 0,
                }
            }
            pub fn scan<R: Read, P: FnMut(u8) -> bool>(
                &mut self,
                mut reader: R,
                mut pred: P,
            ) -> io::Result<ScanRange> {
                let start = self.pos;
                loop {
                    if self.pos >= self.end {
                        if self.pos >= self.buf.len() {
                            let new_len = std::cmp::max(self.buf.len(), 1) * 2;
                            self.buf.resize(new_len, 0);
                        }
                        self.end += match reader.read(&mut self.buf[self.pos..]) {
                            Ok(0) => return Ok(ScanRange(start, self.pos)),
                            Ok(n) => n,
                            Err(ref e) if e.kind() == io::ErrorKind::Interrupted => 0,
                            Err(e) => return Err(e),
                        };
                    }
                    assert!(self.end <= self.buf.len());
                    while self.pos < self.end {
                        if pred(self.buf[self.pos]) {
                            return Ok(ScanRange(start, self.pos));
                        }
                        self.pos += 1;
                    }
                }
            }
        }
    }
    pub mod scanner {
        use crate::comprog_lib::scan_buf::{ScanBuf, ScanRange};
        use std::io::Read;
        #[derive(Debug, Clone)]
        pub struct Scanner<R> {
            pub reader: R,
            pub buf: ScanBuf,
        }
        impl<R: Read> From<R> for Scanner<R> {
            fn from(r: R) -> Self {
                Scanner {
                    reader: r,
                    buf: ScanBuf::new(8192),
                }
            }
        }
        impl<R: Read> Scanner<R> {
            pub fn scan<P: FnMut(u8) -> bool>(&mut self, pred: P) -> ScanRange {
                self.buf.scan(&mut self.reader, pred).unwrap()
            }
            fn digits(&mut self) -> (bool, &[u8]) {
                self.scan(|b| b' ' < b);
                let mut negative = false;
                self.scan(|b| b != b'-' || std::mem::replace(&mut negative, true));
                let digits = self.scan(|b| b < b'0' || b'9' < b);
                (negative, digits.slice(&self.buf))
            }
            pub fn token_range(&mut self) -> ScanRange {
                self.scan(|b| b' ' < b);
                self.scan(|b| b <= b' ')
            }
            pub fn token(&mut self) -> Vec<u8> {
                self.token_range().slice(&self.buf).to_owned()
            }
        }
        macro_rules! impl_scan_int { ($($name:ident),*) => { impl<R: Read> Scanner<R> { $(       #[allow(unused)] pub fn $name(&mut self) -> $name { let (neg, digits) = self.digits(); if !neg { digits.iter().fold($name::default(), |x, b| x * 10 + $name::from(b - b'0')) } else { digits.iter().fold($name::default(), |x, b| x * 10 - $name::from(b - b'0')) } } )* } } }
        impl_scan_int!(u32, i32, u64, i64, usize);
    }
}
// Module comprog_lib contains code from comprog_lib <https://github.com/pcpthm/comprog_lib> licensed under Apache-2.0 OR MIT
// Built by comprog-0.1.0 <https://github.com/pcpthm/comprog_tools>


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

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

	let s = rin.vb();
	let n = s.len();
	let mut sol = 1000;
	for (y,x) in vec![(b'2',b'5'), (b'5',b'0'), (b'7',b'5'), (b'0',b'0')] {
		l!(mut px,py = n);
		for i in (0..n).rev() {
			if px == n && s[i] == x {
				px = i;
			} else if py == n && s[i] == y {
				py = i;
			}
		}
		if px < n && py < n {
			let mut res = 2*n - 3 - px - py;
			if px < py {
				res += 1;
			}
			let mut add = 0;
			let mut done = false;
			for i in 0..n {
				if i == px || i == py {
					continue;
				}
				if s[i] != b'0' {
					done = true;
					break;
				}
				add += 1;
			}
			res += add;
			min!(sol, res);
		}
	}
	if sol < 1000 {
		writeln!(rout, "{}", sol).ok();
	} else {
		writeln!(rout, "-1").ok();
	}
}


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

fn main() {
	let mut rin = reader();
	let mut rout = writer();
	const A: usize = 60;
	const X: i32 = 1000000;

	let n = rin.u();
	let a = rin.vi(n);
	let mut p = v!([]);
	for i in 2..A {
		p.push(i);
		for j in 2..i {
			if i % j == 0 {
				p.pop();
				break;
			}
		}
	}
	let mut b = v!([A] = 0);
	for i in 2..A {
		let mut bb = 0;
		for j in 0..p.len() {
			if i % p[j] == 0 {
				bb |= 1 << j;
			}
		}
		b[i] = bb;
	}
	let m = p.len();
	let mut dp = v!([n+1][1<<m] = (X,0));
	dp[0][0] = (0,0);
	for i in 0..n {
		for j in 0..1<<m {
			let z = dp[i][j].0;
			if z < X {
				for k in 1..A {
					if j & b[k] == 0 {
						let jj = j | b[k];
						if min!(dp[i+1][jj].0, z + (k as i32 - a[i]).abs()) {
							dp[i+1][jj].1 = k;
						}
					}
				}
			}
		}
	}
	let mut min = (X,0);
	let mut j = 0;
	for i in 0..1<<m {
		if min!(min, dp[n][i]) {
			j = i;
		}
	}
	let mut sol = v!([n]);
	for i in (1..=n).rev() {
		let f = dp[i][j].1;
		sol.push(f);
		j ^= b[f];
	}
	sol.reverse();
	for s in sol {
		write!(rout, "{} ", s).ok();
	}
}


use std::io::stdin;

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

    let (a, b) = {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        let a = input.split_whitespace().map(|k| k.parse::<usize>().unwrap()).collect::<Vec<_>>();
        input = String::new();
        stdin().read_line(&mut input).unwrap();
        let b = input.split_whitespace().map(|k| k.parse::<usize>().unwrap()).collect::<Vec<_>>();
        (a, b)
    };

    if b.len() != 1 {
        println!("Yes");
    } else {
        let a: Vec<_> = a.into_iter().map(|k| if k == 0 {b[0]} else {k}).collect();
        for (x, y) in a.iter().zip(a.iter().skip(1)) {
            if y <= x {
                println!("Yes");
                std::process::exit(0);
            }
        }
        println!("No");
    }
}


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

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

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

    i32::from_str(input.trim()).unwrap()
}

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

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

    input.trim()
        .split_whitespace()
        .map(|s| i32::from_str(s).unwrap())
        .collect::<Vec<_>>()
}

fn main() {
    let n = get_num();
    let s = get_nums().iter().sum::<i32>();

    let mut c = 0;
    for i in 1..=5 {
        if (s + i - n - 2) % (n + 1) != 0 {
            c += 1;
        }
    }

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


use std::error::Error;
use std::io;
use std::collections::HashMap;

fn main() {
    if let Err(e) = run() {
        println!("{}", e);
    }
}

fn run() -> Result<(), Box<Error>> {
    let mut s = String::new();
    io::stdin().read_line(&mut s)?;
    let s: Vec<&str> = s.trim().split(" ").collect();
    let _: i32 = s[0].parse()?;
    let k: i32 = s[1].parse()?;
    let mut s = String::new();
    io::stdin().read_line(&mut s)?;
    let mut m = HashMap::new();
    for b in s.trim().as_bytes() {
        match m.get(b).cloned() {
            Some(x) => m.insert(b, x + 1),
            _ => m.insert(b, 1)
        };
    }
    for (_, x) in &m {
        if *x > k {
            println!("NO");
            return Ok(())
        }
    }
    println!("YES");
    Ok(())
}


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

fn largest_prime_factor(mut n: u32) -> u32 {
    let mut k = 2;
    let mut last_factor = 1;
    while k*k <= n {
        while n % k == 0 {
            n = n / k;
            last_factor = k;
        }
        k += 1;
    }
    if n > 1 { n } else { last_factor }
}

fn candidate(n: u32) -> u32 {
    let p = largest_prime_factor(n);
    if p == n {
        n
    } else {
        n - p + 1
    }
}

fn main() {
    let stdin = io::stdin();
    let line = stdin.lock().lines().next().unwrap().unwrap();
    let n: u32 = line.parse().unwrap();
    let low = candidate(n);
    let mut ans = low;
    for i in low..n+1 {
        ans = cmp::min(ans, candidate(i));
    }
    println!("{}", ans);
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

//

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut a = a;
    a.sort();
    a.dedup();
    let n = a.len();
    let mut ans = "NO";
    for i in 2..n {
        let s = a[i - 2];
        if a[(i - 2)..=i] == [s, s + 1, s + 2] {
            ans = "YES";
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

fn inv(mut a: i64, modulo: i64) -> i64 {
    let mut b: i64 = modulo - 2;
    let mut ans: i64 = 1;
    while b > 0 {
        if b & 1 == 1 {
            ans = (ans * a) % modulo;
        }
        a = (a * a) % modulo;
        b >>= 1;
    }
    ans
}

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

    let (n, modulo): (usize, i64) = (sc.next(), sc.next());

    let mut pow2: Vec<i64> = vec![1; n + 1];
    (1..=n).for_each(|i| pow2[i] = (2 * pow2[i-1]) % modulo);

    let mut fact: Vec<i64> = vec![1; n + 1];
    (1..=n).for_each(|i| fact[i] = (i as i64 * fact[i-1]) % modulo);

    let i_fact: Vec<i64> = (0..=n).map(|i| inv(fact[i], modulo)).collect();

    let mut choose: Vec<Vec<i64>> = vec![vec![0; n + 1]; n + 1];
    for i in 0..=n {
        for j in 0..=i {
            choose[i][j] = ((fact[i] * i_fact[j]) % modulo * i_fact[i - j]) % modulo;
        }
    }

    let mut dp: Vec<Vec<i64>> = vec![vec![0; n + 5]; n + 5];
    dp[0][0] = 1;
    for i in 1..=n {
        dp[i][i] = pow2[i-1];
        for j in 1..=i {
            for k in 1..j {
                if i < k + 1 {
                    break;
                }
                dp[i][j] += ((pow2[k-1] * choose[j][k]) % modulo * dp[i - k - 1][j - k]) % modulo;
                dp[i][j] %= modulo;
            }
        }
    }

    let ans: i64 = (1..=n).fold(0 as i64, |x, y| (x + dp[n][y]) % modulo);

    writeln!(out, "{}", ans).unwrap();
}

#[allow(dead_code)]
mod cf_scanner {
    use std::io;
    use std::str::{FromStr, SplitAsciiWhitespace};

    pub struct Scanner<R> {
        reader: R,
        buf_str: Vec<u8>,
        buf_iter: SplitAsciiWhitespace<'static>,
    }

    impl<R: io::BufRead> Scanner<R> {
        pub fn new(reader: R) -> Scanner<R> {
            Scanner {
                reader,
                buf_str: Vec::new(),
                buf_iter: "".split_ascii_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            loop {
                if let Some(token) = self.buf_iter.next() {
                    return token.parse().ok().expect("Failed parse");
                }
                self.buf_str.clear();
                self.reader
                    .read_until(b'\n', &mut self.buf_str)
                    .expect("Failed read");
                self.buf_iter = unsafe {
                    let slice = std::str::from_utf8_unchecked(&self.buf_str);
                    std::mem::transmute(slice.split_ascii_whitespace())
                }
            }
        }

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


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

// ここまで

fn run() {
    input! {
        a: u64,
        b: u64,
    }
    if a > b || (a & 1) != (b & 1) {
        println!("-1");
        return;
    }
    if a == b {
        if a == 0 {
            println!("0");
        } else {
            println!("1\n{}", a);
        }
        return;
    }
    let x = (b - a) / 2;
    if (a & x) == 0 {
        println!("2\n{} {}", a ^ x, x);
    } else {
        println!("3\n{} {} {}", a, x, x);
    }
    // a + x + x = b
    // a ^ x ^ x = a
}

fn main() {
    run();
}


fn main(){
    let mut whiteCount = 0;  let mut blackCount = 0; let mut i = 1;
    while i <= 8{

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

        for charC in input1.chars(){
            whiteCount =whiteCount+ white_valueof(charC);  blackCount= blackCount + black_valueof(charC);
        }
        i =i+ 1;
    }

    if whiteCount < blackCount{
        println!("Black");
    }
    else if whiteCount > blackCount{
        println!("White");
    }
    else{
        println!("Draw");
    }
 }

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

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


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

macro_rules! readln {
        () => {{ let mut line = String::new(); stdin().read_line(&mut line).unwrap(); line }};
        ($type:ty) => {{ readln!().split_whitespace().next().unwrap().parse::<$type>().unwrap() }};
        (|$type_vec:ty|) => {{ readln!().split_whitespace().map(|it| it.parse().unwrap()).collect::<Vec<$type_vec>>() }};
        ($($type:ty),*) => {{ let line = readln!(); let mut iter = line.split_whitespace(); ($(iter.next().unwrap().parse::<$type>().unwrap(),)*) }};
        ($($type:ty),*, |$type_vec:ty|) => {{ let line = readln!(); let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$type>().unwrap(),)*iter.map(|it| it.parse().unwrap()).collect::<Vec<$type_vec>>(),)}};
}

fn main() {
    let t = readln!(usize);
    for _ in 0..t {
        let (n, k, d) = readln!(usize, usize, usize);
        let a = readln!(|usize|);

        let mut count = HashMap::with_capacity(k);

        for i in 0..d {
            *count.entry(a[i]).or_insert(0usize) += 1;
        }

        let mut size = count.len();
        let mut min_size = size;
        for i in d..n {
            let x = count.entry(a[i - d]).or_insert(0);
            *x -= 1;
            if *x == 0 {
                size -= 1;
            }

            let y = count.entry(a[i]).or_insert(0);
            *y += 1;
            if *y == 1 {
                size += 1;
            }
            min_size = min_size.min(size);
        }
        println!("{}", min_size);
    }
}


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

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

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

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

    let n = input.u();
    let mut a = input.vi(n);
    a.sort();
    let sol: i32 = a.iter().zip(a.iter().skip(1)).step_by(2).map(|(&a,&b)| b - a).sum();
    println!("{}", sol);
}


use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let a: Vec<usize> = (0..n).map(|_| sc.ne()).collect();
    let b: Vec<usize> = (0..n).map(|_| sc.ne()).collect();
    let mut cnt = vec![0i32; 6];
    for &x in &a {
        cnt[x] += 1;
    }
    for &x in &b {
        cnt[x] += 1;
    }
    let mut ok = true;
    for i in 1..6 {
        if cnt[i] & 1 == 1 {
            ok = false;
        }
    }
    if ok {
        let mut cnt2 = vec![0; 6];
        for &x in &a {
            cnt2[x] += 1;
        }
        let mut ans = 0;
        for i in 1..6 {
            let a = cnt[i] / 2;
            ans += (a - cnt2[i]).abs();
        }
        println!("{}", ans / 2);
    } else {
        println!("-1");
    }
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


fn main() {
    let n = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse::<i64>().unwrap()
    };
    if n % 2 == 0 {
        println!("{}", n / 2);
    } else {
        println!("-{}", n / 2 + 1);
    }
}


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

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

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

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

fn run() {
    input! {
        n: u64,
    }
    let mul = |a: &[(u64, u64)], b: &[(u64, u64)]| -> Vec<(u64, u64)> {
        let mut c = vec![];
        for a in a.iter() {
            for b in b.iter() {
                c.push((a.0 + b.0, a.1 + b.1 - 1));
            }
        }
        c.sort_unstable();
        c.dedup_by(|a, b| {
            a.0 <= b.1 && {
                b.1.chmax(a.1);
                true
            }
        });
        c
    };
    let mut t = vec![(0, 1)];
    let mut s = vec![(1, 2), (5, 6), (10, 11), (50, 51)];
    let mut n = n;
    while n > 0 {
        if n & 1 == 1 {
            t = mul(&t, &s);
        }
        s = mul(&s, &s);
        n >>= 1;
    }
    let ans = t.iter().fold(0, |s, a| s + a.1 - a.0);
    println!("{}", ans);
}

fn main() {
    run();
}


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

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

    let n = input.s().into_bytes();
    let sol = (1..).flat_map(|a| iter::repeat(a).take(1<<a).enumerate().map(|(b,a)| {
        let mut v = vec![b'0'; a];
        let mut b = b;
        for x in v.iter_mut().rev() {
            *x = b'4' + (3 * (b % 2)) as u8;
            b /= 2;
        }
        v
    })).position(|x| x == n).unwrap() + 1;
    println!("{}", sol);
}


fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).expect("INPUT::read line failed");
    let mut input = input.trim().split(' ');
    let mut vec = vec![i32::default(); 5];

    for item in vec.iter_mut() {
        *item = input.next().unwrap().parse::<i32>().unwrap();
    }

    let outcome = (-vec[1] * vec[0] - vec[3] * 2) + (vec[2] * vec[0] + vec[4] * 2);

    if outcome > 0 {
        println!("First");
    } else if outcome < 0 {
        println!("Second");
    } else {
        println!("Friendship");
    }

}


fn run() {
    input! {
        a: (usize, i64),
        b: (usize, i64),
        e: (usize, usize),
    }
    let inf = std::i64::MAX / 2;
    let mut memo = vec![inf; e.0 + 1];
    for i in 0..=e.0 {
        for j in 0..=e.0 {
            let d = e.0.min(i * (a.0 - e.1) + j * (b.0 - e.1));
            let t = (i as i64 * a.1).max(j as i64 * b.1);
            memo[d] = memo[d].min(t);
        }
    }
    for i in 1..=e.0 {
        for j in 1..=e.0 {
            let t = (i as i64 * a.1).max(j as i64 * b.1);
            let d = (i - 1) * (a.0 - e.1) + (j - 1) * (b.0 - e.1) + a.0 + b.0 - e.1;
            for k in 0..=(e.0 / d + 1) {
                let d = (k * d).min(e.0);
                memo[d] = memo[d].min(t * k as i64);
            }
        }
    }
    for i in (0..e.0).rev() {
        memo[i] = memo[i].min(memo[i + 1]);
    }
    for i in 1..=e.0 {
        let t = memo[i];
        for j in (i + 1)..=e.0 {
            memo[j] = memo[j].min(memo[j - i] + t);
        }
    }
    println!("{}", memo[e.0]);
}

fn main() {
    run();
}

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

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

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


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

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

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

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

    let n: i64 = input.p();
    let x = n * (n + 1) / 2;
    println!("{}", x % 2);
}


//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

//

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

fn run() {
    input! {
        n: usize,
        p: [usize; n],
    }
    let mut cnt = [0; 2];
    for p in p.iter() {
        if *p == 0 {
            continue;
        }
        cnt[*p % 2] += 1;
    }
    let even = n / 2 - cnt[0];
    let odd = (n + 1) / 2 - cnt[1];
    let inf = n;
    let mut dp = BTreeMap::<(usize, usize, usize), usize>::new();
    dp.insert((0, even, odd), 0);
    dp.insert((1, even, odd), 0);
    for p in p.iter().rev() {
        let mut next = BTreeMap::<(usize, usize, usize), usize>::new();
        for ((b, x, y), v) in dp {
            if *p == 0 {
                if x > 0 {
                    let po = next.entry((0, x - 1, y)).or_insert(inf);
                    *po = min(*po, v + (b ^ 0));
                }
                if y > 0 {
                    let po = next.entry((1, x, y - 1)).or_insert(inf);
                    *po = min(*po, v + (b ^ 1));
                }
            } else {
                let po = next.entry((*p % 2, x, y)).or_insert(inf);
                *po = min(*po, v + (b ^ (*p & 1)));
            }
        }
        dp = next;
    }
    let mut ans = inf;
    for (_, v) in dp {
        ans = min(ans, v);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes.by_ref().map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($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:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    #[allow(unused)]
    macro_rules! putvec {
        ($v:expr) => {
            for i in 0..$v.len() {
                puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "});
            }
        }
    }
    input!(s: [chars]);
    for s in s {
        let c = (s[0] as u8 - b'0') as usize;
        let n = s.len();
        puts!("{}\n", 10 * (c - 1) + n * (n + 1) / 2);
    }
}

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


#[allow(unused_imports)]
use std::cmp::{min,max};
use std::collections::{*};
use std::io::{BufWriter, stdin, stdout, Write};
const BITS: usize = 19;

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

fn main() {
    let mut scanner = Scanner::default();
    let s: String = scanner.next();
    let mut i = s.chars();
    while let Some(c) = i.next(){
    	if c == '-' {
    		if let Some(nc) = i.next(){
    			if nc == '-'{
    				print!["2"];
    			}
    			else {
    				print!["1"];
    			}
    		}
    	} else {
    		print!["0"];
    	}
    }
}


use std::collections::HashMap;
use std::io;
use std::str::FromStr;

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

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

    usize::from_str(input.trim()).unwrap()
}

fn main() {
    let mut m = HashMap::new();

    m.insert(0, "zero");
    m.insert(1, "one");
    m.insert(2, "two");
    m.insert(3, "three");
    m.insert(4, "four");
    m.insert(5, "five");
    m.insert(6, "six");
    m.insert(7, "seven");
    m.insert(8, "eight");
    m.insert(9, "nine");
    m.insert(10, "ten");
    m.insert(11, "eleven");
    m.insert(12, "twelve");
    m.insert(13, "thirteen");
    m.insert(14, "fourteen");
    m.insert(15, "fifteen");
    m.insert(16, "sixteen");
    m.insert(17, "seventeen");
    m.insert(18, "eighteen");
    m.insert(19, "nineteen");
    m.insert(20, "twenty");
    m.insert(30, "thirty");
    m.insert(40, "forty");
    m.insert(50, "fifty");
    m.insert(60, "sixty");
    m.insert(70, "seventy");
    m.insert(80, "eighty");
    m.insert(90, "ninety");

    let n = get_num();

    if n < 20 || m.contains_key(&n) {
        println!("{}", m.get(&n).unwrap());
    } else {
        println!(
            "{}-{}",
            m.get(&(n / 10 * 10)).unwrap(),
            m.get(&(n % 10)).unwrap()
        );
    }
}


use std::io::stdin;

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

fn main() {
    let a = {
        let mut input = String::new();
        stdin().read_line(&mut input).unwrap();
        input.trim().chars().map(|k| k.to_digit(10).unwrap()).collect::<Vec<_>>()
    };

    let la: Vec<_> = a.iter().cloned().take(3).collect();
    let ra: Vec<_> = a.iter().cloned().skip(3).collect();

    let l: u32 = a.iter().cloned().take(3).sum();
    let r: u32 = a.iter().cloned().skip(3).sum();

    let diff = r as i32 - l as i32;

    if diff == 0 {
        println!("0");
        std::process::exit(0);
    }

    let (mut up, mut down) = if diff > 0 {
        (ra, la)
    } else {
        (la, ra)
    };

    let mut v = Vec::new();
    v.append(&mut up);
    v.append(&mut down);

    for a in v.iter_mut().skip(3) {
        *a = 9 - *a;
    }

    v.sort();

    let diff = diff.abs();

    let mut sum = 0u32;

    for (i, k) in v.into_iter().rev().enumerate() {
        if sum >= diff as u32 {
            println!("{}", i);
            std::process::exit(0);
        }
        sum += k;
    }
}


//codeforces.com:1.19
use std::{io,cmp};
fn main(){
    let mut z=String::new();io::stdin().read_line(&mut z);let y:Vec<&str>=z.split_whitespace().collect();let a:i32=y[0].parse().unwrap();let b:i32=y[1].parse().unwrap();
    if a==0&&b>0{print!("Impossible");return}
    print!("{} {}",cmp::max(a,b),cmp::max(a+b-1,a+0))
}


use std::cmp::Ordering;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::error::Error;
use std::io::{self, Read};
type Result<T> = ::std::result::Result<T, Box<dyn Error>>;
fn main() -> Result<()> {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input)?;
    let mut lines = input.lines();
    let mut args = lines.next().unwrap().split_whitespace();
    let n: usize = args.next().unwrap().parse()?;
    let x: u64 = args.next().unwrap().parse()?;
    if check(x, n) {
        println!("1");
        return Ok(());
    }
    let mut vals = HashSet::new();
    vals.insert(x);
    let mut queue = VecDeque::new();
    queue.push_front(x);
    let mut depth = 1;
    let mut cur_width = 1;
    let mut next_width = 0;
    while !queue.is_empty() {
        let v = queue.pop_back().unwrap();
        cur_width -= 1;

        let v_d = digits(v);
        let mut flag = [false; 10];
        for d in v_d {
            if d != 0 && d != 1 {
                let tmp = v * d as u64;
                if check(tmp, n) {
                    println!("{}", depth);
                    return Ok(());
                }
                if !vals.contains(&tmp) {
                    queue.push_front(tmp);
                    next_width += 1;
                    vals.insert(tmp);
                }
            }
        }
        if cur_width == 0 {
            depth += 1;
            cur_width = next_width;
            next_width = 0;
        }
    }
    println!("-1");
    Ok(())
}
fn digits(num: u64) -> impl Iterator<Item = u32> {
    num.to_string()
        .chars()
        .map(|d| d.to_digit(10).unwrap())
        .collect::<Vec<_>>()
        .into_iter()
}
fn check(num: u64, n: usize) -> bool {
    if num.to_string().len() >= n {
        true
    } else {
        false
    }
}
#[test]
fn test_split() {}