pub mod plat {
    pub mod classic {
        pub mod solution {
            use crate::{input, output};

            use super::io::Io;

            pub const IS_MULTITEST: bool = false;

            pub fn solve(io: &mut Io) {
                input! { io =>
                    n: usize,
                    m: u64
                }
                let mut is_prime = vec![true; n+1];
                for v in 2..=n {
                    if !is_prime[v] {
                        continue;
                    }
                    for d in (v..=n).step_by(v).skip(1) {
                        is_prime[d] = false;
                    }
                }
                let md = 998244353u64;
                let mut tot = m % md;
                let mut pos = m % md;
                let mut ans = 0;
                let mut mul = 1u64;
                for k in 2..=n {
                    tot = (tot * (m % md)) % md;
                    if is_prime[k] && mul <= m {
                        mul *= k as u64;
                    }
                    pos = (m / mul % md * pos) % md;
                    ans = (ans + md + tot - pos) % md;
                }
                output! { io => ans; }
            }
        }

        pub mod io {
            use std::{fmt::Debug, io::BufRead, str::FromStr};

            use crate::utils::io::{InputSource, OutputTarget};

            #[macro_export]
            macro_rules! read_value {
                ($io:ident, [$type:tt; $len:expr]) => {
                    (0..$len).map(|_| $crate::read_value!($io, $type)).collect::<Vec<_>>()
                };
                ($io:ident, ($($type:tt),+)) => {
                    ($( $crate::read_value!($io, $type), )*)
                };
                ($io:ident, usize1) => {
                    $crate::read_value!($io, usize) - 1
                };
                ($io:ident, $type:ty) => {
                    $io.reader.read::<$type>()
                }
            }

            /// # Examples
            /// ```
            /// input! { io =>
            ///     (n, m): usize,
            ///     a: [[i32; m]; n]
            /// }
            /// input! { io =>
            ///     (n, m): usize,
            ///     edges: [(usize1, usize1); m]
            /// }
            /// ```
            #[macro_export]
            macro_rules! input {
                ($io:ident => ) => {};
                ($io:ident => $var:ident: $type:tt) => {
                    let $var = $crate::read_value!($io, $type);
                };
                ($io:ident => ($($var:ident),+): $type:tt) => {
                    $( $crate::input!{ $io => $var: $type } )*
                };
                ($io:ident => $($vars:tt: $type:tt),+) => {
                    $( $crate::input!{ $io => $vars: $type } )*
                }
            }

            /// # Examples
            /// ```
            /// let (n, m) = (1, 2);
            /// let a = vec![1, 2, 3];
            /// let ans = false;
            /// output! { io =>
            ///     n, m;
            ///     sl(a);
            ///     yn(ans);
            /// }
            /// ```
            #[macro_export]
            macro_rules! output {
                ($io:ident => ) => {};
                ($io:ident => ;) => {
                    $io.printer.print(&'\n');
                };
                ($io:ident => ,) => {
                    $io.printer.print(&' ');
                };
                ($io:ident => $val:expr) => {
                    $io.printer.print(&$val);
                };
                ($io:ident => sl $val:tt $($tail:tt)*) => {
                    $io.printer.print_vec(&$val, ' ');
                    $crate::output!{ $io => $($tail)* }
                };
                ($io:ident => nl $val:tt $($tail:tt)*) => {
                    $io.printer.print_vec(&$val, '\n');
                    $crate::output!{ $io => $($tail)* }
                };
                ($io:ident => yn $val:tt $($tail:tt)*) => {
                    #[allow(unused_parens)]
                    $io.printer.print(&(if $val { "Yes" } else { "No" }));
                    $crate::output!{ $io => $($tail)* }
                };
                ($io:ident => $head:tt $($tail:tt)*) => {
                    $crate::output!{ $io => $head }
                    $crate::output!{ $io => $($tail)* }
                }
            }

            #[derive(Default)]
            pub struct Io {
                pub reader: InputReader,
                pub printer: OutputPrinter,
            }

            pub struct InputReader {
                source: InputSource,
                splitter: WhitespaceSplitter,
            }

            pub struct OutputPrinter {
                target: OutputTarget,
            }

            pub trait Parsable {
                fn parse(s: &str) -> Self;
            }

            impl<T> Parsable for T
            where
                T: FromStr,
                <T as FromStr>::Err: Debug,
            {
                fn parse(s: &str) -> Self {
                    T::from_str(s).unwrap()
                }
            }

            impl Default for InputReader {
                fn default() -> Self {
                    Self {
                        source: InputSource::from_env(),
                        splitter: WhitespaceSplitter::default(),
                    }
                }
            }

            impl InputReader {
                pub fn read<T: Parsable>(&mut self) -> T {
                    self.splitter.parse_next(self.source.reader())
                }
            }

            impl Default for OutputPrinter {
                fn default() -> Self {
                    Self {
                        target: OutputTarget::from_env(),
                    }
                }
            }

            impl OutputPrinter {
                pub fn print<T: ToString>(&mut self, v: &T) {
                    self.target
                        .writer()
                        .write(v.to_string().as_bytes())
                        .unwrap();
                }

                pub fn print_vec<T: ToString>(&mut self, a: &Vec<T>, sep: char) {
                    let mut is_first = true;
                    for item in a {
                        if !is_first {
                            self.print(&sep)
                        }
                        is_first = false;
                        self.print(item)
                    }
                }
            }

            #[derive(Default)]
            pub struct WhitespaceSplitter {
                buf: Vec<u8>,
            }

            impl WhitespaceSplitter {
                pub fn parse_next<T: Parsable>(&mut self, buf_read: &mut dyn BufRead) -> T {
                    self.buf.clear();
                    while let Some(byte) = consume_next_byte(buf_read) {
                        match byte {
                            b'\r' => {}
                            b' ' | b'\n' => {
                                if !self.buf.is_empty() {
                                    break;
                                }
                            }
                            symbol => {
                                self.buf.push(symbol);
                            }
                        }
                    }
                    if self.buf.is_empty() {
                        panic!("Read nothing")
                    }
                    let s = std::str::from_utf8(&self.buf).unwrap();
                    T::parse(s)
                }
            }

            fn consume_next_byte(buf_read: &mut dyn BufRead) -> Option<u8> {
                if let Some(&byte) = buf_read.fill_buf().unwrap().get(0) {
                    buf_read.consume(1);
                    Some(byte)
                } else {
                    None
                }
            }
        }

        pub fn run() {
            let mut io = io::Io::default();
            let test_cnt = if solution::IS_MULTITEST {
                io.reader.read::<usize>()
            } else { 1 };
            for _ in 0..test_cnt {
                solution::solve(&mut io);
            }
        }
    }

    pub mod leetcode {
        use self::io::{InputReader, OutputPrinter};

        pub mod solution {
            impl Solution {
                pub fn hardest_worker(_n: i32, _logs: Vec<Vec<i32>>) -> i32 {
                    0
                }
            }

            use crate::{plat::leetcode::io::{InputReader, ToLeetcodeValueNode}, with_input};
            pub const TEST_COUNT: usize = 1;

            pub fn exec(r: &mut InputReader) -> impl ToLeetcodeValueNode {
                with_input!{ r => hardest_worker, 2 }
            }

            struct Solution;
        }

        pub mod defs {
            use std::{cell::RefCell, rc::Rc};

            #[derive(Debug, PartialEq, Eq)]
            pub struct TreeNode {
                pub val: i32,
                pub left: Option<Rc<RefCell<TreeNode>>>,
                pub right: Option<Rc<RefCell<TreeNode>>>,
            }

            impl TreeNode {
                #[inline]
                pub fn new(val: i32) -> Self {
                    TreeNode {
                        val,
                        left: None,
                        right: None,
                    }
                }
            }
        }

        pub mod io {
            use std::{cell::RefCell, collections::VecDeque, rc::Rc};

            use crate::utils::io::{InputSource, OutputTarget};

            use self::parser::LeetcodeValueNode;

            use super::defs::TreeNode;

            mod parser {
                #[derive(Debug)]
                pub enum LeetcodeValueNode {
                    Null,
                    Int(i64),
                    Str(String),
                    Bool(bool),
                    Array(Vec<LeetcodeValueNode>),
                }

                impl LeetcodeValueNode {
                    pub fn parse_node(s: &str) -> Self {
                        let mut rest = s;
                        let node = parse_next(&mut rest);
                        rest = rest.trim();
                        if !rest.is_empty() {
                            panic!("Unexpected {rest}");
                        }
                        node
                    }
                }

                impl ToString for LeetcodeValueNode {
                    fn to_string(&self) -> String {
                        match self {
                            LeetcodeValueNode::Null => "null".to_string(),
                            LeetcodeValueNode::Int(v) => v.to_string(),
                            LeetcodeValueNode::Str(s) => s.to_string(),
                            LeetcodeValueNode::Bool(v) => v.to_string(),
                            LeetcodeValueNode::Array(a) => format!(
                                "[{}]",
                                a.iter()
                                    .map(|el| el.to_string())
                                    .collect::<Vec<_>>()
                                    .join(",")
                            ),
                        }
                    }
                }

                fn parse_next(s: &mut &str) -> LeetcodeValueNode {
                    trim_start(s);
                    match s.chars().next().unwrap() {
                        'n' => parse_next_null(s),
                        '0'..='9' => parse_next_int(s),
                        't' | 'f' => parse_next_bool(s),
                        '"' => parse_next_str(s),
                        '[' => parse_next_array(s),
                        other => panic!("Unexpected char {other}"),
                    }
                }

                fn parse_next_null(s: &mut &str) -> LeetcodeValueNode {
                    if !consume_start(s, "null") {
                        panic!("Can't parse null from {s}");
                    };
                    LeetcodeValueNode::Null
                }

                fn parse_next_int(s: &mut &str) -> LeetcodeValueNode {
                    let mut v = 0;
                    while let Some(ch) = s.chars().next() {
                        if let Some(d) = ch.to_digit(10) {
                            v = 10 * v + d as i64;
                            consume_next_char(s);
                        } else {
                            break;
                        }
                    }
                    LeetcodeValueNode::Int(v)
                }

                fn parse_next_str(s: &mut &str) -> LeetcodeValueNode {
                    let mut v = String::new();
                    consume_next_char(s);
                    loop {
                        if let Some(ch) = consume_next_char(s) {
                            if ch == '"' {
                                break;
                            } else {
                                v.push(ch);
                            }
                        } else {
                            panic!("Failed to find matching \"");
                        }
                    }
                    LeetcodeValueNode::Str(v)
                }

                fn parse_next_bool(s: &mut &str) -> LeetcodeValueNode {
                    let v = if consume_start(s, "true") {
                        true
                    } else if consume_start(s, "false") {
                        false
                    } else {
                        panic!("Can't parse bool from {s}");
                    };
                    LeetcodeValueNode::Bool(v)
                }

                fn parse_next_array(s: &mut &str) -> LeetcodeValueNode {
                    let mut res = Vec::new();
                    consume_next_char(s);
                    trim_start(s);
                    loop {
                        if let Some(ch) = s.chars().next() {
                            match ch {
                                ']' => {
                                    consume_next_char(s);
                                    break;
                                }
                                ',' => {
                                    consume_next_char(s);
                                }
                                _ => {
                                    res.push(parse_next(s));
                                }
                            }
                            trim_start(s);
                        } else {
                            panic!("Unmatched [");
                        }
                    }
                    LeetcodeValueNode::Array(res)
                }

                fn consume_start(s: &mut &str, v: &str) -> bool {
                    if s.starts_with(v) {
                        *s = &s[v.len()..];
                        true
                    } else { false }
                }

                fn trim_start(s: &mut &str) {
                    *s = s.trim_start();
                }

                fn consume_next_char(s: &mut &str) -> Option<char> {
                    let res = s.chars().next();
                    *s = &s[1..];
                    res
                }
            }

            pub struct InputReader {
                source: InputSource,
            }

            #[macro_export]
            macro_rules! with_input {
                ($r:ident => $func:ident, 1) => {
                    crate::plat::leetcode::solution::Solution::$func($r.read())
                };
                ($r:ident => $func:ident, 2) => {
                    crate::plat::leetcode::solution::Solution::$func($r.read(), $r.read())
                };
                ($r:ident => $func:ident, 3) => {
                    crate::plat::leetcode::solution::Solution::$func($r.read(), $r.read(), $r.read())
                };
            }

            pub struct OutputPrinter {
                target: OutputTarget,
            }

            impl InputReader {
                pub fn read<T: FromLeetcodeValueNode>(&mut self) -> T {
                    let mut line = String::new();
                    self.source.reader().read_line(&mut line).unwrap();
                    let node = LeetcodeValueNode::parse_node(&line);
                    T::from_leetcode_input_node(&node)
                }
            }

            impl Default for InputReader {
                fn default() -> Self {
                    Self {
                        source: InputSource::from_env(),
                    }
                }
            }

            impl OutputPrinter {
                pub fn print(&mut self, v: &impl ToLeetcodeValueNode) {
                    let s = v.to_leetcode_value_node();
                    self.target
                        .writer()
                        .write(s.to_string().as_bytes())
                        .unwrap();
                }
            }

            impl Default for OutputPrinter {
                fn default() -> Self {
                    Self {
                        target: OutputTarget::from_env(),
                    }
                }
            }

            pub trait FromLeetcodeValueNode {
                fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self;
            }

            pub trait ToLeetcodeValueNode {
                fn to_leetcode_value_node(&self) -> LeetcodeValueNode;
            }

            macro_rules! impl_from_leetcode_int {
                ($($type:ty),+) => {
                    $(
                        impl FromLeetcodeValueNode for $type {
                            fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self {
                                if let LeetcodeValueNode::Int(v) = node {
                                    (*v) as $type
                                } else {
                                    panic!("{:?} is not int", node)
                                }
                            }
                        }
                    )*
                };
            }

            impl_from_leetcode_int!(i32, i64);

            impl<T: FromLeetcodeValueNode> FromLeetcodeValueNode for Option<T> {
                fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self {
                    match node {
                        LeetcodeValueNode::Null => None,
                        other => Some(T::from_leetcode_input_node(other)),
                    }
                }
            }

            impl FromLeetcodeValueNode for Option<Rc<RefCell<TreeNode>>> {
                fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self {
                    match node {
                        LeetcodeValueNode::Array(a) => convert_to_tree_node(a),
                        other => panic!("{:?} cannot be parsed to TreeNode, expected array", other),
                    }
                }
            }

            fn create_tree_node(node: Option<&LeetcodeValueNode>) -> Option<Rc<RefCell<TreeNode>>> {
                match node {
                    None | Some(LeetcodeValueNode::Null) => None,
                    Some(LeetcodeValueNode::Int(v)) => Some(Rc::new(RefCell::new(TreeNode::new(*v as i32)))),
                    other => panic!("expected int or null, got {:?}", other),
                }
            }

            fn convert_to_tree_node(a: &[LeetcodeValueNode]) -> Option<Rc<RefCell<TreeNode>>> {
                let mut q = VecDeque::<Rc<RefCell<TreeNode>>>::new();
                let root = create_tree_node(a.get(0));
                if let Some(ref rc) = root {
                    q.push_back(rc.clone());
                } else {
                    return None;
                }
                let mut i = 1;
                while let Some(rc) = q.pop_front() {
                    let mut node = rc.borrow_mut();
                    node.left = create_tree_node(a.get(i));
                    node.right = create_tree_node(a.get(i + 1));
                    i += 2;
                    for child in [&node.left, &node.right] {
                        if let Some(rc) = child {
                            q.push_back(rc.clone());
                        }
                    }
                }
                if i < a.len() {
                    panic!("{:?} contains redundant elements, consumed {}", a, i + 1);
                }
                root
            }

            impl FromLeetcodeValueNode for String {
                fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self {
                    if let LeetcodeValueNode::Str(s) = node {
                        String::from(s)
                    } else {
                        panic!("{:?} is not str", node)
                    }
                }
            }

            impl FromLeetcodeValueNode for bool {
                fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self {
                    if let LeetcodeValueNode::Bool(v) = node {
                        *v
                    } else {
                        panic!("{:?} is not bool", node)
                    }
                }
            }

            impl<T: FromLeetcodeValueNode> FromLeetcodeValueNode for Vec<T> {
                fn from_leetcode_input_node(node: &LeetcodeValueNode) -> Self {
                    if let LeetcodeValueNode::Array(a) = node {
                        a.iter().map(|el| T::from_leetcode_input_node(el)).collect()
                    } else {
                        panic!("{:?} is not array", node)
                    }
                }
            }

            macro_rules! impl_to_leetcode_int {
                ($($type:ty),+) => {
                    $(
                        impl ToLeetcodeValueNode for $type {
                            fn to_leetcode_value_node(&self) -> LeetcodeValueNode {
                                LeetcodeValueNode::Int(*self as i64)
                            }
                        }
                    )*
                };
            }

            impl_to_leetcode_int!(i32, i64);

            impl<T: ToLeetcodeValueNode> ToLeetcodeValueNode for Option<T> {
                fn to_leetcode_value_node(&self) -> LeetcodeValueNode {
                    match self {
                        Some(v) => v.to_leetcode_value_node(),
                        None => LeetcodeValueNode::Null,
                    }
                }
            }

            impl ToLeetcodeValueNode for String {
                fn to_leetcode_value_node(&self) -> LeetcodeValueNode {
                    LeetcodeValueNode::Str(String::from(self))
                }
            }

            impl ToLeetcodeValueNode for bool {
                fn to_leetcode_value_node(&self) -> LeetcodeValueNode {
                    LeetcodeValueNode::Bool(*self)
                }
            }

            impl<T: ToLeetcodeValueNode> ToLeetcodeValueNode for Vec<T> {
                fn to_leetcode_value_node(&self) -> LeetcodeValueNode {
                    LeetcodeValueNode::Array(self.iter().map(|el| el.to_leetcode_value_node()).collect())
                }
            }
        }

        pub fn run() {
            let mut reader = InputReader::default();
            let mut printer = OutputPrinter::default();
            for _ in 0..solution::TEST_COUNT {
                let res = solution::exec(&mut reader);
                printer.print(&res);
                printer.print(&String::from("\n"));
            }
        }
    }

}

pub mod utils {
    pub mod io {
        use std::{
            env,
            fs::File,
            io::{stdin, stdout, BufRead, BufReader, BufWriter, Stdin, Stdout, Write},
        };

        pub enum InputSource {
            Stdin { reader: BufReader<Stdin> },
            File { reader: BufReader<File> },
        }

        pub enum OutputTarget {
            Stdout { writer: BufWriter<Stdout> },
            File { writer: BufWriter<File> },
        }

        impl InputSource {
            pub fn from_env() -> Self {
                if is_local() {
                    Self::from_file()
                } else {
                    Self::from_stdin()
                }
            }

            pub fn from_stdin() -> Self {
                InputSource::Stdin {
                    reader: BufReader::new(stdin()),
                }
            }

            pub fn from_file() -> Self {
                let file = File::open("input.txt").unwrap();
                InputSource::File {
                    reader: BufReader::new(file),
                }
            }

            pub fn reader(&mut self) -> &mut dyn BufRead {
                match self {
                    InputSource::Stdin { reader } => reader,
                    InputSource::File { reader } => reader,
                }
            }
        }

        impl OutputTarget {
            pub fn from_env() -> Self {
                if is_local() {
                    Self::from_file()
                } else {
                    Self::from_stdout()
                }
            }

            pub fn from_stdout() -> Self {
                OutputTarget::Stdout {
                    writer: BufWriter::new(stdout()),
                }
            }

            pub fn from_file() -> Self {
                OutputTarget::File {
                    writer: BufWriter::new(File::create("out/output.txt").unwrap()),
                }
            }

            pub fn writer(&mut self) -> &mut dyn Write {
                match self {
                    OutputTarget::Stdout { writer } => writer,
                    OutputTarget::File { writer } => writer,
                }
            }
        }

        fn is_local() -> bool {
            env::var("LOCAL").is_ok()
        }
    }

}

fn main() {
    plat::classic::run();
}


macro_rules! read_line {
    ( $($name:ident : $typ:ty),+ ) => {
        let line = get_line();
        let mut tokens = line.split_ascii_whitespace();
        $(
            let $name: $typ = tokens.next().unwrap().parse().unwrap();
        )+
            debug_assert_eq!(tokens.next(), None);
    };
}

const P: i64 = 998244353;

fn primes(n: usize) -> Vec<bool> {
    let mut ps = vec![true; n + 1];
    for i in 2..n {
        if ps[i] {
            for j in (i * i..=n).step_by(i) {
                ps[j] = false;
            }
        }
    }
    ps
}

fn primes2(ps: Vec<bool>) -> Vec<usize> {
    ps.iter()
        .enumerate()
        .filter_map(|(i, &is_prime)| if is_prime && i >= 2 { Some(i) } else { None })
        .collect()
}

fn solve(n: usize, m: i64) -> i64 {
    let mut x = m % P;
    let mut y = m % P;
    let mut ans = 0;
    let mut p = 1 as i64;
    let ps = primes(n);
    for i in 2..=n {
        if ps[i] && p <= m {
            p = p * (i as i64);
        }
        x = (x * ((m / p) % P)) % P;
        y = (y * (m % P)) % P;
        ans = (ans + (y - x + P) % P) % P;
    }
    ans
}

fn main() {
    read_line!(n: usize, m: i64);
    println!("{}", solve(n, m));
}

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

    #[test]
    fn test() {
        assert_eq!(solve(2, 3), 6);
        assert_eq!(solve(4, 2), 26);
        assert_eq!(solve(4, 6), 1494);
        assert_eq!(solve(1337, 424242424242i64), 119112628);
    }
    #[test]
    fn test_primes() {
        assert_eq!(primes2(primes(23)), vec![2, 3, 5, 7, 11, 13, 17, 19, 23]);
    }
    #[test]
    fn div() {
        assert_eq!(9 / 4, 2);
    }
}

fn get_line() -> String {
    let mut line = String::new();
    while line.is_empty() {
        std::io::stdin().read_line(&mut line).unwrap();
    }
    line.pop().unwrap();
    line
}

fn read_line_vec<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug,
{
    get_line()
        .split_ascii_whitespace()
        .map(|s| s.parse::<T>())
        .collect::<Result<Vec<T>, _>>()
        .unwrap()
}


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

     let stdin = io::stdin();
     let mut lc = 1;
     let mut str_len = 0;
     for line in stdin.lock().lines() {
     	match lc  {
     		1 => {
     			str_len = line.unwrap().parse::<usize>().unwrap();
     		},
     		2 => {
     			let s = line.unwrap();
     			// println!("{:?}", s);
     			let mut num = 0;
     			let mut chars = s.chars();
     			let mut prev_ch = '1';
     			for ch in chars {
     				match ch {
	     				'1' => {
	     					num += 1;
	     				},
	     				'0' if prev_ch == '0' => {
	     					print!("0");
	     				}
	     				'0' => {
	     					print!("{}", num);
	     					num = 0;
	     				}
	     				_ => panic!("SOS"),
     				}
     				prev_ch = ch;
     			}
     			if num > 0 {
	     			println!("{}", num);
     			}
     			if prev_ch == '0' {
     				print!("0");
     			}
     		}
     		_ => {
     			panic!("SOS");
     		}
     	}
     	lc += 1;
     }
}


use std::io;

fn main() {
    io::stdin().read_line(&mut String::new()).expect("");
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut ans = String::new();
    let mut cnt = 0;
    let mut zcnt = 0;
    for c in s.trim().chars() {
        if c == '0' {
            if cnt > 0 {
                ans += &cnt.to_string();
                cnt = 0;
            } else if zcnt > 0 {
                ans.push_str("0");
            }
            zcnt = 1;
        } else {
            zcnt = 0;
            cnt += 1;
        }
    }
    if cnt > 0 {
        ans += &cnt.to_string();
    } else {
        ans.push_str("0");
    }
    println!("{}", ans);
}


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

     let stdin = io::stdin();
     let mut lc = 1;
     let mut str_len = 0;
     for line in stdin.lock().lines() {
     	match lc  {
     		1 => {
     			str_len = line.unwrap().parse::<usize>().unwrap();
     		},
     		2 => {
     			let s = line.unwrap();
     			// println!("{:?}", s);
     			let mut num = 0;
     			let mut chars = s.chars();
     			let mut prev_ch = '1';
     			for ch in chars {
     				match ch {
	     				'1' => num += 1,
	     				'0' => { print!("{}", num); num = 0; },
	     				_ => panic!("SOS"),
     				}
     				prev_ch = ch;
     			}
     			if num > 0 {
	     			println!("{}", num);
     			}
     			if prev_ch == '0' {
     				print!("0");
     			}
     		}
     		_ => {
     			panic!("SOS");
     		}
     	}
     	lc += 1;
     }
}


//! http://codeforces.com/problemset/problem/825/A

#[macro_export]
macro_rules! scanln {
  ($($var:ident : $ty:path),+) => {
    $(let $var: $ty;)+
    {
      use std::io;
      let mut __buf = String::new();
      io::stdin().read_line(&mut __buf).unwrap();
      let mut eles = __buf.split_whitespace();
      $($var = Scan::scan(&mut eles);)+
    }
  }
}

pub trait Scan {
  fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str>;
}

macro_rules! impl_scan_single {
  ($ty:ty) => {
    impl Scan for $ty {
      fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
        let next = eles.next().unwrap();
        match next.parse() {
          Ok(res) => res,
          Err(_) => panic!()
        }
      }
    }
  }
}

impl_scan_single!(u8);
impl_scan_single!(u16);
impl_scan_single!(u32);
impl_scan_single!(u64);
impl_scan_single!(usize);
impl_scan_single!(i8);
impl_scan_single!(i16);
impl_scan_single!(i32);
impl_scan_single!(i64);
impl_scan_single!(isize);
impl_scan_single!(f32);
impl_scan_single!(f64);
impl_scan_single!(String);

const __IMPL_SCAN_FOR_VEC: () = {
  use std::str::FromStr;
  impl<T> Scan for Vec<T> where T: FromStr {
    fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator<Item=&'a str> {
      eles.map(|str| match str.parse() {
        Ok(res) => res,
        Err(_) => panic!()
      }).collect()
    }
  }
};

// -----------------------------------------------------------------------------

fn main() {
  scanln!(_n: u32);
  scanln!(n: String);
  for segment in n.split('0') {
    print!("{}", segment.len());
  }
  println!("");
}


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

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

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

impl Scanner {

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

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

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

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

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

fn count_char(x : char, y : char, z : char, target : char) -> i32 {
   (if x == target {1} else {0})
      + if y == target {1} else {0}
      + if z == target {1} else {0}
}

fn check_board(board: &[[char; 4];4]) -> String {
   // horizontal...
   for i in 0..4 {
      for j in 1..3 {
         let x_count = count_char(board[i][j], board[i][j+1], board[i][j-1], 'x');
         let e_count = count_char(board[i][j], board[i][j+1], board[i][j-1], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   // vertical...
   for j in 0..4 {
      for i in 1..3 {
         let x_count = count_char(board[i][j], board[i+1][j], board[i-1][j], 'x');
         let e_count = count_char(board[i][j], board[i+1][j], board[i-1][j], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   // left-diagonal...
   for j in 0..2 {
      for i in 0..2 {
         let x_count = count_char(board[i][j], board[i+1][j+1], board[i+2][j+2], 'x');
         let e_count = count_char(board[i][j], board[i+1][j+1], board[i+2][j+2], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   // right-diagonal..
   for j in 0..2 {
      for i in 2..4 {
         let x_count = count_char(board[i][j], board[i-1][j+1], board[i-2][j+2], 'x');
         let e_count = count_char(board[i][j], board[i-1][j+1], board[i-2][j+2], '.');

         if x_count == 3 || (x_count == 2 && e_count == 1) {
            return "YES".to_string();
         }
      }
   }

   return "NO".to_string();
}

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

   let mut board = [['.';4];4];

   for i in 0..4 {
      let line = sin.next::<String>().into_bytes();
      for j in 0..4 {
         board[i][j] = line[j] as char;
      }
   }

   println!("{}", check_board(&board));
}


use std::error::Error;
use std::io::stdin;

struct Digits {
    number: u64,
    divisor: u64,
}

impl Digits {
    fn new(number: u64) -> Self {
        let mut divisor = 1;
        while number >= divisor * 10 {
            divisor *= 10;
        }

        Digits {
            number,
            divisor,
        }
    }

    fn reset(&mut self, number: u64){
        let mut divisor = 1;
        while number >= divisor * 10 {
            divisor *= 10;
        }
        self.divisor = divisor;
        self.number = number;

    }
}

impl Iterator for Digits {
    type Item = u64;

    fn next(&mut self) -> Option<Self::Item> {
        if self.divisor == 0 {
            None
        } else {
            let v = Some(self.number / self.divisor);
            self.number %= self.divisor;
            self.divisor /= 10;
            v
        }

    }
}

struct InfinityCounter{
    num: Digits,
    current: u64,
}
impl InfinityCounter{
    pub fn new() -> Self{
        Self{
            current: 0,
            num: Digits::new(1),
        }
    }
}

impl Iterator for InfinityCounter{
    type Item = u64;

    fn next(&mut self) -> Option<Self::Item> {
        let next = self.num.next();
        if next.is_none() {
            self.current += 1;
            self.num.reset(self.current);
            return self.num.next();
        }
        next
    }
}

fn main() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    stdin().read_line(&mut input)?;
    let number: usize = input.trim().parse()?;
    let mut counter = InfinityCounter::new();
    if let Some(x) = counter.nth(number){
        println!("{}", x);
    }
    Ok(())
}


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

struct DigitSequenceIterator {
    inner: u64,
    state: VecDeque<char>,
}

impl Iterator for DigitSequenceIterator {
    type Item = char;

    fn next(&mut self) -> Option<char> {
        if self.state.len() == 0 {
            self.state.extend(self.inner.to_string().chars());;

            self.inner += 1;
        }

        self.state.pop_front()
    }
}

impl DigitSequenceIterator {
    pub fn new() -> Self {
        DigitSequenceIterator {
            inner: 0,
            state: VecDeque::new(),
        }
    }

    pub fn skip(mut to_skip: u64) -> impl Iterator<Item=char> {
        let mut inner = 0;

        if to_skip >= 10 {
            inner = 10;
            to_skip -= 10;
        }

        let mut can_jump = 90;
        let mut i = 2;
        while to_skip > can_jump * i {
            to_skip -= can_jump * i;
            inner *= 10;

            can_jump *= 10;
            i += 1;
        }

        // Now, all numbers between inner and the end are `i` wide.
        // So, to_skip/i is the amount of numbers we can still skip.
        if i > 2 {
            inner += to_skip/i;
            to_skip = to_skip % i;
        }

        DigitSequenceIterator {
            inner,
            state: VecDeque::new(),
        }.skip(to_skip as usize)
    }
}

fn main() {
    let stdin = io::stdin();
    let line = stdin.lock().lines().next().expect("input").expect("UTF-8");
    let index: u64 = line.parse().expect("Numeric value");

    println!("{}", DigitSequenceIterator::skip(index).next().unwrap());
}

#[test]
fn vectors() {
    let in_out = [(7, '7'), (21, '5'), (188, '9'), (192, '0'), (417, '5')];

    for (i, o) in &in_out {
        let test = DigitSequenceIterator::skip(*i).next().unwrap();
        assert_eq!(test, *o,
            "{}th should be {}, but got {}", i, *o, test);
    }
}


fn main() {
    let mut seq = String::with_capacity(10050);
    let mut stat: u32 = 0;
    while seq.len() < 10000 {
        stat += 1;
        seq.push_str(&format!("{}", stat));
    }

    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let input = input.trim().parse::<usize>().unwrap();
    println!("{}", seq.chars().nth(input-1).unwrap());
}


use std::io::*;

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

    let k: usize = {
        let mut buffer_string = String::new();
        stdin
            .read_line(&mut buffer_string)
            .expect("could not read line");
        buffer_string.trim().parse().unwrap()
    };

    let mut digits = 0;
    for n in (1..).map(|m| m.to_string()) {
        let digits_in_n = n.len();
        if digits + digits_in_n < k {
            digits += digits_in_n;
        } else {
            let index_in_n = k - digits - 1;
            println!("{}", n.chars().nth(index_in_n).unwrap());
            return;
        }
    }
}


// -*- coding:utf-8-unix -*-

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

use std::cmp::*;
use std::collections::*;
use std::fs::File;
use std::io::prelude::*;
use std::io::*;
use std::mem;
use std::str;
use std::vec;

const INF: i64 = 1223372036854775807;
const MEM_SIZE: usize = 202020;
const MOD: i64 = 1000000007;
// const MOD: i64 = 998244353;

use std::cmp::*;
use std::collections::*;
use std::io::stdin;
use std::io::stdout;
use std::io::Write;
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn readi() -> (i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    iter.next().unwrap().parse::<i64>().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn readii() -> (i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}

#[allow(dead_code)]
fn readiii() -> (i64, i64, i64) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
        iter.next().unwrap().parse::<i64>().unwrap(),
    )
}
#[allow(dead_code)]
fn readuu() -> (usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

fn readcc() -> (char, char) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<char>().unwrap(),
        iter.next().unwrap().parse::<char>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuu() -> (usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

#[allow(dead_code)]
fn readuuuu() -> (usize, usize, usize, usize) {
    let mut str = String::new();
    let _ = stdin().read_line(&mut str).unwrap();
    let mut iter = str.split_whitespace();
    (
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
        iter.next().unwrap().parse::<usize>().unwrap(),
    )
}

fn solve_part() {
    let s: String = read();
    let mut v = s.as_bytes().to_vec();
    let mut x = v[0] - '0' as u8;
    let x = x as usize;
    let mut res = (x - 1) * 10;
    for i in 0..v.len() {
        res += i + 1;
    }
    println!("{:?}", res);
    return;
}
fn solve() {
    let n: usize = read();
    for i in 0..n {
        solve_part();
    }
    return;
}

fn main() {
    solve()
}


use std::io;
fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let input = input.trim();
    let t: i32 = input.parse().unwrap();
    for _tc in 0..t {
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let input = input.trim();
        let n: i32 = input.parse().unwrap();
        let d = n % 10;
        let f = [1, 3, 6, 10];
        let answer = (d - 1) * 10 + f[input.len() - 1];
        println!("{}", answer);
    }
}


#![allow(dead_code, unused_imports)]

use std::fmt::Debug;
use std::str::FromStr;

fn read_stdin() -> String {
    let mut s = String::new();
    std::io::stdin()
        .read_line(&mut s)
        .expect("cannot read stdin");
    s.trim().to_string()
}

fn read<T>() -> T
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    read_stdin().parse::<T>().unwrap()
}

fn read_usize() -> usize {
    read::<usize>()
}

fn read_2<A, B>() -> (A, B)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    (a, b)
}

fn read_3<A, B, C>() -> (A, B, C)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    (a, b, c)
}

fn read_4<A, B, C, D>() -> (A, B, C, D)
where
    A: FromStr,
    <A as FromStr>::Err: Debug,
    B: FromStr,
    <B as FromStr>::Err: Debug,
    C: FromStr,
    <C as FromStr>::Err: Debug,
    D: FromStr,
    <D as FromStr>::Err: Debug,
{
    let s = read_stdin();
    let mut s = s.split_whitespace();
    let a = s.next().unwrap().parse::<A>().unwrap();
    let b = s.next().unwrap().parse::<B>().unwrap();
    let c = s.next().unwrap().parse::<C>().unwrap();
    let d = s.next().unwrap().parse::<D>().unwrap();
    (a, b, c, d)
}

fn read_multiple<T: FromStr>() -> Vec<T>
where
    <T as FromStr>::Err: Debug,
{
    read_stdin()
        .split_whitespace()
        .map(|x| x.parse::<T>().expect("cannot parse stdin"))
        .collect()
}

/// NOTE: sort iter beforehand if required
fn count<T>(iter: &mut impl Iterator<Item = T>) -> Vec<(T, usize)>
where
    T: std::cmp::Ord,
{
    let iter = iter.collect::<Vec<_>>();
    //iter.sort();
    let (mut v, o, c) =
        iter.into_iter()
            .fold((Vec::new(), None, 0), |(mut v, last, count), item| {
                if let Some(o) = last {
                    if item == o {
                        (v, Some(o), count + 1)
                    } else {
                        v.push((o, count));
                        (v, Some(item), 1)
                    }
                } else {
                    (v, Some(item), 1)
                }
            });
    if let Some(i) = o {
        v.push((i, c));
    }
    v
}

fn max_subarray(v: impl Iterator<Item = i64>) -> (i64, (usize, usize)) {
    //assert!(v.len() > 0);
    let mut best_sum = 0;
    let (mut best_start, mut best_end) = (0, 0);
    let mut current_sum = 0;
    let mut current_start = 0;
    for (end, val) in v.enumerate() {
        if current_sum <= 0 {
            current_start = end;
            current_sum = val;
        } else {
            current_sum += val;
        }
        if current_sum > best_sum {
            best_sum = current_sum;
            best_start = current_start;
            best_end = end + 1;
        }
    }
    (best_sum, (best_start, best_end))
}

fn gcd(mut a: u64, mut b: u64) -> u64 {
    while a != 0 {
        let old_m = a;
        a = b % a;
        b = old_m;
    }
    b
}

/// returns gcd, and pair (x, y), such that x * a + b * y == gcd
fn egcd(a: i64, b: i64) -> (i64, i64, i64) {
    if a == 0 {
        (b, 0, 1)
    } else {
        let (g, x, y) = egcd(b % a, a);
        (g, y - (b / a) * x, x)
    }
}

fn factorize(mut n: u64) -> Vec<u64> {
    if n <= 3 {
        return vec![n];
    }
    let mut v = Vec::new();
    while n % 2 == 0 {
        n /= 2;
        v.push(2);
    }
    while n % 3 == 0 {
        n /= 3;
        v.push(3);
    }
    let mut f = 6;
    while (f - 1) * (f - 1) <= n {
        while n % (f - 1) == 0 {
            n /= f - 1;
            v.push(f - 1);
        }
        while n % (f + 1) == 0 {
            n /= f + 1;
            v.push(f + 1);
        }
        f += 6;
    }
    if n > 1 {
        v.push(n);
    }
    v
}

fn compact_factors(n: u64) -> Vec<(u64, usize)> {
    count(&mut factorize(n).into_iter())
}

fn all_factors(n: u64) -> Vec<u64> {
    if n == 0 {
        return vec![0];
    } else if n == 1 {
        return vec![1];
    }
    let factors = compact_factors(n);
    let mut v = vec![1];
    for (fac, num) in factors {
        let ori = v.clone();
        for i in 1..num + 1 {
            v.append(
                &mut ori
                    .clone()
                    .into_iter()
                    .map(|f| f * fac.pow(i as u32))
                    .collect::<Vec<_>>(),
            )
        }
    }
    v.sort();
    v
}

fn abs_diff<T>(a: T, b: T) -> T
where
    T: PartialOrd + std::ops::Sub<Output = T>,
{
    if a > b {
        a - b
    } else {
        b - a
    }
}

struct Permutations<T> {
    inner: Vec<T>,
    state: Vec<usize>,
    i: usize,
    start: bool,
}

impl<T> Permutations<T> {
    fn new(inner: Vec<T>) -> Self {
        Self {
            state: vec![0; inner.len()],
            i: 0,
            start: true,
            inner,
        }
    }
}

/*impl<T, X> From<X> for Permutations<T>
where
    X: IntoIterator<Item = T>,
{
    fn from(f: X) -> Self {
        Self::new(f.into_iter().collect::<Vec<T>>())
    }
}*/

impl<T> Iterator for Permutations<T>
where
    T: Clone,
{
    type Item = Vec<T>;
    fn next(&mut self) -> Option<Self::Item> {
        if self.start {
            self.start = false;
            return Some(self.inner.clone());
        }
        while self.i < self.inner.len() {
            if self.state[self.i] < self.i {
                if self.i % 2 == 0 {
                    self.inner.swap(0, self.i)
                } else {
                    self.inner.swap(self.state[self.i], self.i)
                }
                self.state[self.i] += 1;
                self.i = 0;
                return Some(self.inner.clone());
            } else {
                self.state[self.i] = 0;
                self.i += 1;
            }
        }
        None
    }
}

use std::cmp::{max, min, Ord, Ordering};
use std::collections::{BinaryHeap, VecDeque};
use std::mem::swap;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut nums = Vec::new();
    for d in 1..=9 {
        let mut n = 0;
        let mut i = 0;
        for _ in 0..4 {
            n *= 10;
            n += d;
            i += 1;
            nums.push((n, i));
        }
    }
    //println!("{:?}", nums);
    for _ in 0..read_usize() {
        let mut chars = 0;
        let target = read_usize();
        for (n, i) in nums.iter() {
            chars += *i;
            if *n == target {
                println!("{}", chars);
            }
        }
    }
    Ok(())
}


use std::io;
fn one_integer_line() -> i32 {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let input = input.trim();
    let t: i32 = input.parse().unwrap();
    t
}
fn main() {
    let t = one_integer_line();
    for _tc in 0..t {
        let n = one_integer_line();
        let d = n % 10;
        let mut answer = (d - 1) * 10;
        for i in 0..4 {
            if n >= (10 as i32).pow(i) {
                answer += (i + 1) as i32;
            }
        }
        println!("{}", answer);
    }
}


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

use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::fmt;
use std::io::{self, Read as _};
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

pub use visualize::*;
pub mod visualize {
    pub trait Visualize {
        fn visualize(&self, split: &str);
        fn continuous(&self) {
            self.visualize("");
        }
        fn spaces(&self) {
            self.visualize(" ");
        }
        fn lines(&self) {
            self.visualize("\n");
        }
    }
    macro_rules ! impl_vis_for_sized {($ ($ t : ty ) ,+ ) => {$ (impl Visualize for $ t {fn visualize (& self , _split : & str ) {print ! ("{}" , self ) ; } } ) + } ; }
    impl_vis_for_sized! {usize , u8 , u16 , u32 , u64 , u128 , isize , i8 , i16 , i32 , i64 , i128 , String , & str , char }
    impl<T: std::fmt::Display> Visualize for [T] {
        fn visualize(&self, split: &str) {
            let n = self.iter().count();
            print!("{}", {
                let mut buf = String::new();
                for i in 0..n {
                    buf += self[i].to_string().as_str();
                    if i != n - 1 {
                        buf += split;
                    }
                }
                buf
            })
        }
    }
    #[macro_export]
    macro_rules ! vis {() => {println ! () ; } ; ($ last : expr ; ) => {$ last . lines () ; vis ! () } ; ($ last : expr => ) => {$ last . continuous () ; vis ! () ; } ; ($ last : expr $ (, ) ? ) => {$ last . spaces () ; vis ! () ; } ; ($ first : expr ; $ ($ rest : tt ) * ) => {$ first . lines () ; println ! () ; vis ! ($ ($ rest ) * ) ; } ; ($ first : expr => $ ($ rest : tt ) * ) => {$ first . continuous () ; vis ! ($ ($ rest ) * ) ; } ; ($ first : expr , $ ($ rest : tt ) * ) => {$ first . spaces () ; print ! (" " ) ; vis ! ($ ($ rest ) * ) ; } ; }
}

pub use consts::*;
pub mod consts {
    pub const MOD10E9_7: usize = 1000000007; // 10 ^ 9 + 7
    pub const MOD99_: usize = 998244353;
    pub const MAX: u64 = std::u64::MAX; // = 2 ^ 64 - 1 = 18446744073709551615 ≈ 1.8 * 10 ^ 19
    pub const INF: u64 = 2000000000000000000; // MAX / 9 < 2 * 10e18 < MAX / 10
    pub const FNI: i64 = -2000000000000000000; // == -(INF as i64)
    pub const PI: f64 = std::f64::consts::PI; // 3.141592653589793 -- 10 ^ -15
    pub const ASCII_A_LARGE: u8 = 65;
    pub const ASCII_A_SMALL: u8 = 97;
    pub const ASCII_0: u8 = 48;
    pub const ADJ4: &[(isize, isize); 4] = &[(1, 0), (0, 1), (-1, 0), (0, -1)];
    pub const ADJ8: &[(isize, isize); 8] = &[
        (1, 0),
        (1, 1),
        (0, 1),
        (-1, 1),
        (-1, 0),
        (-1, -1),
        (0, -1),
        (1, -1),
    ];
}

fn main() {
    let mut input = "".to_owned();
    io::stdin().read_to_string(&mut input).unwrap();
    let input = input.trim();
    let mut input = input.split_whitespace();

    // generate testcases
    for t in 0..input.next().unwrap().parse::<usize>().unwrap() {
        solve(&mut input);
    }
    // not testcase
    // solve(&mut input);
}

fn solve(input: &mut std::str::SplitWhitespace) {
    macro_rules! read {
        () => ();
        ([$tt:tt]) => (read!([$tt; read!(usize)]));
        ([$tt:tt; $n:expr]) => ((0..$n).map(|_| read!($tt)).collect::<Vec<_>>());
        (($($tt:tt),+)) => (($(read!($tt)),*));
        (Usize1) => (read!(usize) - 1);
        (Chars) => (read!(String).chars().collect::<Vec<char>>());
        (Byte) => (read!(char) as u8);
        (Bytes) => (read!(String).into_bytes());
        ($ty:ty) => (input.next().unwrap().trim().parse::<$ty>().unwrap());
    }
    macro_rules! input {
        ($($id:ident : $ty:tt),*) => {
            $(
                let $id = read!($ty);
            )*
        }
    }

    input! {
        n: usize
    }

    let c = n % 10;
    let l = n.to_string().len();

    let ans = (c - 1) * sum(4) + sum(l);
    vis!(ans);
}

fn sum(n: usize) -> usize {
    match n {
        1 => 1,
        2 => 3,
        3 => 6,
        4 => 10,
        _ => unreachable!()
    }
}


#[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_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

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

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut 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)*}
    };
    ($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<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $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")
    };
}

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = i64::max_value() / 2;
#[allow(dead_code)]
static INF_I32: i32 = i32::max_value() / 2;
#[allow(dead_code)]
static INF_USIZE: usize = usize::max_value() / 2;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    let T = get!(usize);
    let mut kouho = vec![];
    for i in 1..10 {
        let mut p = i;
        for j in 0..1000000 {
            kouho.push(p);
            p = p * 10 + i;
            if p > 10000 {
                break;
            }
        }
    }
    mydbg!(kouho);

    for testcase in 0..T {
        mydbg!(testcase);
        let mut ans = 0;
        let X = get!(usize);
        for i in 0..kouho.len() {
            let k = kouho[i].to_string().chars().toVec().len();
            ans += k;
            if kouho[i] == X {
                break;
            }
        }

        echo!(ans);
    }
}


use std::io::{self, Write};
use std::{fmt, ops, str};

macro_rules! read {
    ( $t:ty ) => {{
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        input.trim_end().parse::<$t>().ok().unwrap()
    }};
    ( $( $t:ty ),* ) => {{
        let mut input = String::new();
        io::stdin().read_line(&mut input).unwrap();
        let mut iter = input.split_whitespace();
        ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
    }};
}

struct Ios(Vec<char>);

impl str::FromStr for Ios {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Ios(s.trim_end().chars().collect()))
    }
}

impl fmt::Display for Ios {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.0.iter().collect::<String>())
    }
}

struct Iov<T>(Vec<T>);

impl<T: str::FromStr> str::FromStr for Iov<T> {
    type Err = T::Err;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let iter = s.split_whitespace();
        Ok(Iov(iter.map(|x| x.parse()).collect::<Result<_, _>>()?))
    }
}

impl<T: fmt::Display> fmt::Display for Iov<T> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}",
            self.0.iter().map(|x| x.to_string())
                .collect::<Vec<_>>().join(" ")
        )
    }
}

impl<T> ops::Index<usize> for Iov<T> {
    type Output = T;

    fn index(&self, i: usize) -> &Self::Output {
        self.0.get(i - 1).unwrap()
    }
}

fn solve(writer: &mut io::BufWriter<io::StdoutLock>) {
    let x = read!(i32);

    let mut ans = 0;
    'outer: for i in 1..=9 {
        let mut p = 0;
        for j in 1..=4 {
            p = p * 10 + i;
            ans += j;
            if p == x { break 'outer; }
        }
    }
    writeln!(writer, "{}", ans).ok();
}

fn main() {
    let stdout = io::stdout();
    let mut writer = io::BufWriter::new(stdout.lock());
    for _ in 0..read!(usize) { solve(&mut writer); }
}


use std::io::{stdin, stdout, Write, BufReader, BufRead, Read};

fn solve(input: &mut BufRead, output: &mut Write) {
    let mut input = BufReader::new(input);

    let mut line = String::with_capacity(100);
    input.read_line(&mut line).unwrap();
    let line = line.trim();

    if line.chars().next().unwrap() == '0' {
        output.write(b"0\n");
    } else if line.chars().filter(|&it| it == '1').count() == 1 {
        output.write(format!("{}\n", line.len() / 2).as_bytes());
    } else {
        output.write(format!("{}\n", (line.len() + 1) / 2).as_bytes());
    }

}

fn main() {
    let stdin = stdin();
    let stdout = stdout();
    solve(&mut stdin.lock(), &mut stdout.lock());
}


use std::io::*;

fn main() {
    let mut stdin = stdin();
    let mut buffer = String::new();
    let _ = stdin.read_to_string(&mut buffer);
    let s = buffer.trim();

    println!("{}", (s.len() + s[1..].contains("1") as usize) / 2);
}


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

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

    let s = input.bs();
    let n = s.len();
    let sol = n / 2 + (if n % 2 == 1 && s[1..].iter().any(|x| *x == b'1') {1} else {0});
    println!("{}", sol);
}


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

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

use std::io::Write;

fn solve(writer: &mut std::io::BufWriter<std::io::Stdout>) {
    let s = parse_line!(String);
    let mut result = s.len() / 2;
    if s.len() % 2 == 1 {
        for c in s.bytes().skip(1) {
            if c == b'1' {
                result += 1;
                break;
            }
        }
    }
    writeln!(writer, "{}", result).unwrap();
}

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


use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let s: u128 = u128::from_str_radix(buf.trim(), 2).unwrap();

    let mut k = 0;
    while 4u128.pow(k) < s {
        k += 1;
    }

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


use std::io::stdin;

fn get_input(input: &mut String) {
    input.clear();
    stdin().read_line(input).expect("error");
}

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

    get_input(&mut input);
    let mut count = input.trim().chars().count();
    if input.trim().chars().map(|c| if c == '1' {1} else {0} ).sum::<u32>() >= 2 {
        count += 1;
    }
    count = count / 2;

    println!("{}", count);

}


#![allow(unused_variables)]
#![allow(unused_must_use)]

use std::io::{self, prelude::*};

fn main() {
    let stdin = io::stdin();
    let stdout = io::stdout();
    let mut input = Input::new(stdin.lock());
    let mut output = io::BufWriter::new(stdout.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(output ,$($format)*).unwrap());
    }
    let s: String = input.next();
    let s = s.into_bytes();
    let mut s2: Vec<u8> = s
        .as_slice()
        .rchunks(2)
        .map(|chunk| {
            if chunk.len() == 1 {
                chunk[0] - b'0'
            } else {
                (chunk[0] - b'0') * 2 + chunk[1] - b'0'
            }
        })
        .collect();
    s2.as_mut_slice().reverse();
    if s2[0] > 1 || s2[1..].iter().any(|&c| c != 0) {
        puts!("{}\n", s2.len());
        return;
    }
    puts!("{}\n", s2.len() - 1);
}

struct Input<R> {
    lines: io::Lines<R>,
    cur: String,
    split: std::str::SplitAsciiWhitespace<'static>, //'
}

impl<R: BufRead> Input<R> {
    fn new(reader: R) -> Input<R> {
        use std::mem::transmute;

        let mut lines = reader.lines();
        let cur = lines.next().unwrap().unwrap();
        let split = unsafe { transmute(cur.split_ascii_whitespace()) };
        Input { lines, cur, split }
    }
    fn update(&mut self) {
        use std::mem::transmute;
        self.cur = self.lines.next().unwrap().unwrap();
        unsafe { self.split = transmute(self.cur.split_ascii_whitespace()) };
    }
    fn next<F: std::str::FromStr>(&mut self) -> F {
        loop {
            if let Some(thing) = self.split.next() {
                return thing.parse().ok().unwrap();
            }
            self.update();
        }
    }
    fn iter<I: std::str::FromStr>(&mut self) -> InputIter<R, I> {
        InputIter {
            input: self,
            _phantom: std::marker::PhantomData,
        }
    }
}

struct InputIter<'a, R, I> {
    input: &'a mut Input<R>,
    _phantom: std::marker::PhantomData<I>,
}

impl<'a, R, I> Iterator for InputIter<'a, R, I>
where
    R: BufRead,
    I: std::str::FromStr,
{
    type Item = I;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.input.next())
    }
}


//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! {
        s: chars,
    }
    if s[0] == '0' {
        println!("0");
        return;
    }
    let l = s.len();
    if l % 2 == 0 {
        println!("{}", l / 2);
    } else {
        let mut ans = (l + 1) / 2;
        if !s[1..].iter().any(|c| *c == '1') {
            ans -= 1;
        }
        println!("{}", ans);
    }
}

fn main() {
    run();
}


#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_labels)]

use std::char::*;
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

macro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::f64;

fn min<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { a }
    else { b }
}

fn max<T: PartialOrd>(a:T, b:T) -> T {
    if a < b { b }
    else { a }
}

const MAX:usize = 30;
const INF:i64 = std::i64::MAX;
const MOD:i64 = 1e9 as i64 + 7;

struct Graph {
    e: Vec<Vec<usize>>,
    v: Vec<usize>,
    u: Vec<usize>,
    f: Vec<bool>,
    c: i64,
    vc: Vec<i64>,
}

impl Graph {
    fn new(n:usize) -> Self {
        Graph {
            e: vec![vec![];n],
            v: vec![],
            u: vec![n;n],
            f: vec![false;n],
            c: 0,
            vc: vec![0;n],
        }
    }

    fn dfs(&mut self, crt: usize) {
        if self.f[crt] { return; }
        self.c += 1;
        self.f[crt] = true;
        self.v.push(crt);
        self.vc[crt] = self.c;
        self.u[crt] = self.v.len()-1;
        for i in 0..self.e[crt].len() {
            self.dfs(self.e[crt][i]);
        }
        //debug!(crt, self.c, self.vc[crt]);
        self.vc[crt] = self.c - self.vc[crt];
    }
}

fn divisor(n:usize) -> Vec<usize> {
    let mut res = Vec::new();
    let mut i = 1;
    while i*i <= n {
        if n%i == 0 {
            res.push(i);
            if i != n/i { res.push(n/i); }
        }
        i += 1;
    }
    res.sort();
    res
}

fn main() {
    //let t:usize = read();

    //'outer: for _ in 0..t {
        let n:usize = read();
        let mut t:Vec<char> = read::<String>().chars().collect();

        let div = divisor(n);
        for d in div {
            //debug!(d,t);
            for i in 0..d/2 {
                t.swap(i,d-i-1);
            }
            //debug!(t);
        }
        for e in t {print!("{}",e);} println!();
    //}
}

/*

*/


use std::io;

fn main() {
    let num = read().parse::<usize>().unwrap();
    let mut data = read();
    for n in 1..num + 1{
        if num % n == 0{
            let temp = data.clone();
            let (first,last) = temp.split_at(n);
            let first = first.chars().rev().collect::<String>();

            data.clear();
            data.push_str(first.as_str());
            data.push_str(last);
        }
    }
    println!("{}",data);
}

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


use std::io::{self, BufRead};
// use std::collections::*; // HashSet, HashMap, BTreeSet, BTreeMap, ...

fn main() {
    let stdin: io::Stdin = io::stdin();
    let mut lines: io::Lines<io::StdinLock> = stdin.lock().lines();

    let next_line = lines.next()
        .unwrap() // Option<Result> { Some(Result), None }
        .unwrap(); // Result<String, io::Error> { Ok(String), Err(io::Error) }

    let flv: Vec<_> = next_line
        .trim()
        .split(' ')
        .map(|n| {
            n.parse::<usize>().unwrap()
        })
        .collect();

    let n = flv[0];

    let mut s: String = lines.next()
        .unwrap()
        .unwrap()
        .trim()
        .to_string();

    for i in 2..n {
        if n % i == 0 {
            let tmp_end = s.split_off(i);
            s = s.chars().rev().collect();
            s.push_str(&tmp_end);
            // println!("{}: {}", i, s);
        }
    }
    s = s.chars().rev().collect();

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


use std::io;

fn main() {

    let mut input_text = String::new();
    io::stdin().read_line(&mut input_text).expect("fail");
    let n = input_text.trim().parse::<u32>().expect("parse error");

    let mut string = String::new();
    io::stdin().read_line(&mut string).expect("fail");

    let string = string.chars();

    let mut vec = Vec::new();
    for c in string {
        vec.push(c);
    }

    for d in 1..n+1 {
        if n % d == 0 {
            for i in 0..d/2 {
                let t = vec[i as usize];
                vec[i as usize] = vec[d as usize - i as usize - 1usize];
                vec[d as usize - i as usize - 1usize] = t;
            }
        }
    }
    for i in 0..n {
        print!("{}", vec[i as usize]);
    }
    print!("\n");
}


use std::io;

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

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

fn main() {
    let n = read_u8();
    let n_sqrt = (n as f64).sqrt() as u8;
    let mut s = read_string();

    let mut divs: Vec<usize> = vec!();
    for i in 1..=n_sqrt {
        if n%i == 0 {
            divs.push(i as usize);
            if i*i != n {
                divs.push((n/i) as usize);
            }
        }
    }
    divs.sort();

    for i in divs.iter() {
        let t = s.split_off(*i);
        s = s.chars().rev().collect();
        s.push_str(&t);
    }

    println!("{}", s);

    return;
}


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

fn read_line() -> String {
    let mut ln = String::new();
    std::io::stdin().read_line(&mut ln).expect("");
    String::from(ln.trim_right())
}

fn main() {
    let n = read_ints()[0] as usize;
    let mut s = read_line();
    assert_eq!(n, s.len());

    for i in 2..=n {
        if n % i == 0 {
            let t = s.split_off(i);
            s = s.chars().rev().collect();
            s.push_str(&t);
        }
    }
    println!("{}", s);
}


use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let n: usize = sc.next();
    let mut s: Vec<char> = sc.next::<String>().chars().collect();

    for i in 1..=n {
        if n % i != 0 {
            continue;
        }
        s[0..i].reverse();
    }

    let ans: String = s.iter().collect();
    println!("{}", ans);
}

//-----

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

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

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

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


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

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

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

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

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

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


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

fn main() {
    let (y_chr, b_chr) = {
        let temp = input_split();
        (temp[0], temp[1])
    };
    let (y, g, b) = {
        let temp = input_split();
        (temp[0], temp[1], temp[2])
    };

    let mut req_chr = 0u64;
    req_chr += u64::from((2 * y + g).max(y_chr) - y_chr);
    req_chr += u64::from((3 * b + g).max(b_chr) - b_chr);
    println!("{}", req_chr);
}


use std::cmp::min;
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let crystals = s.split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect::<Vec<i64>>();
    s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let balls = s.split_whitespace().map(|x| x.parse::<i64>().unwrap()).collect::<Vec<i64>>();

    let mut no_yb = balls[0]*2 - crystals[0];
    let rem_y = if no_yb >= 0 {0} else {let a=-no_yb;no_yb=0;a};
    let mut no_bb = balls[2]*3 - crystals[1];
    let rem_b = if no_bb >= 0 {0} else {let a=-no_bb;no_bb=0;a};
    let no_gby = if balls[1] > rem_y {balls[1] - rem_y} else {0};
    let no_gbb = if balls[1] > rem_b {balls[1] - rem_b} else {0};
    let no_gb = no_gby + no_gbb;
    println!("{}",no_yb + no_gb + no_bb);
}


use std::io;

const BALLS_SIZE: usize = 3;
const CRYST_SIZE: usize = 2;

enum ColorsB{
    Yell,
    Green,
    Blue
}

type CrystalsArray =  [i64; CRYST_SIZE];
type BallsArray = [i64; BALLS_SIZE];

fn count_crystals(balls :BallsArray) -> CrystalsArray{
    fn count_yellow(num: i64 ) -> CrystalsArray {
        [2*num, 0]
    }
    fn count_green(num: i64 ) -> CrystalsArray {
        [num, num]
    }
    fn count_blue(num: i64 ) -> CrystalsArray {
        [0,3*num]
    }
    println!("");
    let mut res: CrystalsArray = [0; CRYST_SIZE];
    for (ind,i) in count_yellow(balls[ColorsB::Yell as usize]).iter().enumerate(){
        res[ind] += *i;
    }
    for (ind,i) in count_green(balls[ColorsB::Green as usize]).iter().enumerate(){
        res[ind] += *i;
    }

    for (ind,i) in count_blue(balls[ColorsB::Blue as usize]).iter().enumerate(){
        res[ind] += *i;
    }
    return res ;
}

fn main() {
    let mut input: String = String::new();
    io::stdin().read_line(&mut input).expect("some error");
    let mut cryst_inp: CrystalsArray = [0; CRYST_SIZE];
    let mut balls_inp: BallsArray = [0; BALLS_SIZE];
    for (ind,i) in input.trim().split(char::is_whitespace).enumerate(){
        cryst_inp[ind] = i.trim().parse().expect("failed to parse");
    }
    input.clear();
    io::stdin().read_line(&mut input).expect("some error");
    for (ind,i) in input.trim().split(char::is_whitespace).enumerate(){
        balls_inp[ind] = i.trim().parse().expect("failed to parse");
    }
    let have_to = count_crystals(balls_inp);
    let mut sum = 0;
    for (ind,i) in  cryst_inp.iter().enumerate(){
        let diff =  have_to[ind] - i;
        if diff > 0 {
            sum += diff;
        }
    }
    print!("{}", sum);
}


// Try Codeforces
// author: Leonardone @ NEETSDKASU

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

    let a = get!();
    let b = get!();
    let x = get!();
    let y = get!();
    let z = get!();

    let ra = x * 2 + y;
    let rb = y + z * 3;
    let ans = std::cmp::max(0, ra - a)
            + std::cmp::max(0, rb - b);

    println!("{}", ans);

}


#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufWriter, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , [ $ t : tt ] ) => { { let len = read_value ! ( $ next , usize ) ; ( 0 .. len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
#[allow(dead_code)]
struct Writer {
    s: String,
}
#[allow(unused_imports)]
use std::fmt::Display;
#[allow(dead_code)]
#[doc = " let mut writer = Writer::new();"]
#[doc = " writer.writeln(hoge);"]
#[doc = " writer.flush()"]
impl Writer {
    #[allow(dead_code)]
    pub fn new() -> Writer {
        Writer { s: String::new() }
    }
    #[allow(dead_code)]
    pub fn flush(&mut self) {
        print!("{}", self.s);
        self.s.clear();
    }
    pub fn write<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
    }
    pub fn writeln<T: Display>(&mut self, x: T) {
        self.s.push_str(&format!("{}", x));
        self.s.push('\n');
    }
    #[allow(dead_code)]
    pub fn write_vec<T: Display>(&mut self, xs: &Vec<T>) {
        if xs.len() == 0 {
            self.writeln("");
            return;
        }
        self.write(&format!("{}", xs[0]));
        for i in 1..xs.len() {
            self.write(&format!(" {}", xs[i]));
        }
        self.writeln("");
    }
}
#[allow(unused_macros)]
macro_rules ! dbg { ( $ ( $ a : expr ) ,* ) => { writeln ! ( & mut stderr ( ) , concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) . unwrap ( ) ; } }
#[allow(dead_code)]
const INF_U: u64 = 1_000_000_000_000_000;
#[allow(dead_code)]
const INF_I: i64 = 1_000_000_000_000_000;
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        n: usize,
        m: usize,
        r: i64,
        s: [i64; n],
        b: [i64; m]
    }
    let min_s = s.iter().min().unwrap();
    let max_b = b.iter().max().unwrap();
    if min_s >= max_b {
        println!("{}", r);
        return;
    }
    let num = r / min_s;
    let mut ans = r - num * min_s;
    ans += num * max_b;
    //dbg!(num, min_s, max_b);
    println!("{}", ans);
}


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

fn main() {
    let n: usize = read();
    let m: usize = read();
    let r: usize = read();

    let s: Vec<usize> = (0..n).map(|_| read()).collect();
    let b: Vec<usize> = (0..m).map(|_| read()).collect();

    let mut min = s[0];
    for i in 1..n {
        min = std::cmp::min(min, s[i]);
    }
    let mut max = b[0];
    for i in 1..m {
        max = std::cmp::max(max, b[i]);
    }
    if min > max {
        println!("{}", r);
    } else {
        let po = r / min;
        let nokori = r - po * min;
        println!("{}", po * max + nokori);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

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

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

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

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

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

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

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

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

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

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

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

fn main() {
    input!{
      n: usize,
      m: usize,
      r: usize,
      ss: [usize; n],
      bs: [usize; m],
    }
    let s: usize = *ss.iter().min().unwrap();
    let b: usize = *bs.iter().max().unwrap();
    if s > b {
        return println!("{}", r);
    }
    let ans = r%s + r/s*b;
    println!("{}", ans);
}


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

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

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

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

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

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

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

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

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

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

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


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

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

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

}

fn _main() {
    let mut scan = Scan::new();
    let a: isize = scan.next();
    let b: isize = scan.next();
    let c: isize = scan.next();
    let mut result: isize = std::isize::MAX;
    for i in 0..=100 {
        result = result.min((i-a).abs() + (i-b).abs() + (i-c).abs());
    }
    println!("{}", result);
}

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