{"source_code": "fn main() {\n let mut input = String::new();\n use std::io;\n use std::io::prelude::*;\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let a: i32 = it.next().unwrap().parse().unwrap();\n let b: i32 = it.next().unwrap().parse().unwrap();\n\n let d = (b - a).abs();\n\n let q = d / 2;\n let r = d % 2;\n\n let ans = q * (q + 1) + if r == 1 { q + 1 } else { 0 };\n\n println!(\"{}\", ans);\n}\n", "src_uid": "d3f2c6886ed104d7baba8dd7b70058da"} {"source_code": "#![allow(unused_imports)]\nuse std::io::*;\nuse std::cmp::*;\nuse std::collections::*;\n\nmacro_rules! debug(\n ($($arg:tt)*) => { {\n let r = writeln!(&mut ::std::io::stderr(), $($arg)*);\n r.expect(\"failed printing to stderr\");\n } }\n);\n\nstruct Scanner {\n buffer : std::collections::VecDeque\n}\n\nimpl Scanner {\n\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn process(&mut self) -> String {\n if self.buffer.len() == 0 {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n for word in input.split_whitespace() {\n self.buffer.push_back(word.to_string())\n }\n }\n\n self.buffer.pop_front().unwrap()\n }\n\n fn next(&mut self) -> T {\n self.process().parse::().ok().unwrap()\n }\n\n #[allow(dead_code)]\n fn next_char(&mut self) -> char {\n self.process().into_bytes()[0] as char\n }\n}\n\nfn cost(x : i64, n : i64, k : i64) -> i64 {\n let left_limit = min(k, x - 1);\n let right_limit = min(n - k - 1, x - 1);\n\n let left_cost = left_limit*x - (left_limit*(left_limit+1)/2);\n let right_cost = right_limit*x - (right_limit*(right_limit+1)/2);\n\n let left_extra = max(k - left_limit, 0);\n let right_extra = max((n - k - 1) - right_limit, 0);\n\n x + left_cost + right_cost + left_extra + right_extra\n}\n\nfn search(n : i64, k : i64, m : i64) -> i64 {\n let mut upper = m;\n let mut lower = 1;\n let mut middle = 0;\n\n while lower <= upper {\n middle = (lower + upper)/2;\n let c = cost(middle, n, k);\n debug!(\"l: {}, m: {}, u: {}, c: {}\", lower, middle, upper, c);\n\n if c < m {\n lower = middle + 1;\n } else if c > m {\n upper = middle - 1;\n } else {\n break;\n }\n }\n\n while cost(middle, n, k) > m {\n middle -= 1;\n }\n\n middle\n}\n\nfn main() {\n let mut sin = Scanner::new();\n let (n, m, k) : (i64, i64, i64) = (sin.next(), sin.next(), sin.next());\n\n println!(\"{}\", search(n, k - 1, m));\n}\n", "src_uid": "da9ddd00f46021e8ee9db4a8deed017c"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Read};\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok().unwrap();\n ret\n}\nfn get_word() -> String {\n let mut stdin = std::io::stdin();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\nmod pollard_rho {\n use std::collections::HashMap;\n /// binary gcd\n pub fn gcd(mut x: i64, mut y: i64) -> i64 {\n if y == 0 { return x; }\n if x == 0 { return y; }\n let mut sh = 0;\n while ((x | y) & 1) == 0 {\n x >>= 1; y >>= 1; sh += 1;\n }\n while (x & 1) == 0 { x >>= 1; }\n while y != 0 {\n while (y & 1) == 0 { y >>= 1; }\n if x > y { let t = x; x = y; y = t; }\n y -= x;\n }\n x << sh\n }\n\n fn add_mod(x: i64, y: i64, n: i64) -> i64 {\n let z = x + y;\n if z >= n { z - n } else { z }\n }\n\n fn mul_mod(x: i64, mut y: i64, n: i64) -> i64 {\n assert!(x >= 0);\n assert!(x < n);\n let mut sum = 0;\n let mut cur = x;\n while y > 0 {\n if (y & 1) == 1 {\n sum = add_mod(sum, cur, n);\n }\n cur = add_mod(cur, cur, n);\n y >>= 1;\n }\n sum\n }\n\n fn mod_pow(x: i64, mut e: i64, n: i64) -> i64 {\n let mut prod = if n == 1 { 0 } else { 1 };\n let mut cur = x % n;\n while e > 0 {\n if (e & 1) == 1 {\n prod = mul_mod(prod, cur, n);\n }\n cur = mul_mod(cur, cur, n);\n e >>= 1;\n }\n prod\n }\n\n pub fn is_prime(n: i64) -> bool {\n if n <= 1 { return false; }\n let small = [2, 3, 5, 7, 11, 13];\n if small.iter().any(|&u| u == n) { return true; }\n if small.iter().any(|&u| n % u == 0) { return false; }\n let mut d = n - 1;\n let mut e = 0;\n while (d & 1) == 0 {\n d >>= 1;\n e += 1;\n }\n let a = [2, 325, 9375, 28178, 450775, 9780504, 1795265022];\n a.iter().all(|&a| {\n if a >= n { return true; }\n let mut x = mod_pow(a, d, n);\n if x == 1 { return true; }\n for _ in 0 .. e {\n if x == n - 1 {\n return true;\n }\n x = mul_mod(x, x, n);\n if x == 1 { return false; }\n }\n x == 1\n })\n }\n\n fn pollard_rho(n: i64, c: &mut i64) -> i64 {\n if n % 2 == 0 { return 2; }\n loop {\n let mut x: i64 = 2;\n let mut y = 2;\n let mut d = 1;\n let cc = *c;\n let f = |i| add_mod(mul_mod(i, i, n), cc, n);\n while d == 1 {\n x = f(x);\n y = f(f(y));\n d = gcd((x - y).abs(), n);\n }\n if d == n {\n *c += 1;\n continue;\n }\n return d;\n }\n }\n\n /// Outputs (p, e) in p's ascending order.\n pub fn factorize(x: i64) -> Vec<(i64, usize)> {\n if x <= 1 {\n return Vec::new();\n }\n let mut hm = HashMap::new();\n let mut pool = vec![x];\n let mut c = 1;\n while let Some(u) = pool.pop() {\n if is_prime(u) {\n *hm.entry(u).or_insert(0) += 1;\n continue;\n }\n let p = pollard_rho(u, &mut c);\n pool.push(p);\n pool.push(u / p);\n }\n let mut v: Vec<_> = hm.into_iter().collect();\n v.sort();\n v\n }\n} // mod pollard_rho\n\n\nuse pollard_rho::*;\n\nfn solve() {\n let n = get();\n let x: i64 = get();\n let y: i64 = get();\n if y % x != 0 {\n println!(\"0\");\n return;\n }\n let a: Vec = (0 .. n).map(|_| get()).collect();\n let b: Vec = a.iter().filter_map(|&a| if a % x == 0 { Some(a / x) } else { None }).collect();\n let c: Vec = a.iter().filter_map(|&a| if y % a == 0 { Some(y / a) } else { None }).collect();\n let y = y / x;\n let fac = factorize(y);\n let m = fac.len();\n let mut pat1 = vec![0i64; 1 << m];\n let mut pat2 = vec![0i64; 1 << m];\n for &b in &b {\n let mut hot = 0;\n for i in 0 .. m {\n let p = fac[i].0;\n if b % p == 0 {\n hot |= 1 << i;\n }\n }\n pat1[hot] += 1;\n }\n for &c in &c {\n let mut hot = 0;\n for i in 0 .. m {\n let p = fac[i].0;\n if c % p == 0 {\n hot |= 1 << i;\n }\n }\n pat2[hot] += 1;\n }\n // zeta\n for i in 0 .. m {\n for bits in 0 .. 1 << m {\n if (bits & 1 << i) != 0 {\n pat2[bits] += pat2[bits ^ 1 << i];\n }\n }\n }\n let mut ans = 0;\n for bits in 0 .. 1 << m {\n ans += pat1[bits] * pat2[(1 << m) - 1 - bits];\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "8d43a542d5bf79d15926c4a6a5ff608f"} {"source_code": "fn main() {\n use std::io;\n use std::io::prelude::*;\n\n let stdin = io::stdin();\n let mut lc = 1;\n let mut str_len = 0;\n for line in stdin.lock().lines() {\n \tmatch lc {\n \t\t1 => {\n \t\t\tstr_len = line.unwrap().parse::().unwrap();\n \t\t},\n \t\t2 => {\n \t\t\tlet s = line.unwrap();\n \t\t\t// println!(\"{:?}\", s);\n \t\t\tlet mut num = 0;\n \t\t\tlet mut chars = s.chars();\n \t\t\tlet mut prev_ch = '1';\n \t\t\tfor ch in chars {\n \t\t\t\tmatch ch {\n\t \t\t\t\t'1' => num += 1,\n\t \t\t\t\t'0' => { print!(\"{}\", num); num = 0; }, \n\t \t\t\t\t_ => panic!(\"SOS\"),\n \t\t\t\t}\n \t\t\t\tprev_ch = ch;\n \t\t\t}\n \t\t\tif num > 0 {\n\t \t\t\tprintln!(\"{}\", num);\n \t\t\t}\n \t\t\tif prev_ch == '0' {\n \t\t\t\tprint!(\"0\");\n \t\t\t}\n \t\t}\n \t\t_ => {\n \t\t\tpanic!(\"SOS\");\n \t\t}\n \t}\n \tlc += 1;\n }\n}\n", "src_uid": "a4b3da4cb9b6a7ed0a33a862e940cafa"} {"source_code": "use std::io::stdin;\nuse std::cmp::min;\n\nfn main() {\n let mut input_line = String::new();\n stdin().read_line(&mut input_line);\n\n let mut input_iter = input_line.\n split_whitespace().\n map(|x| x.parse::().unwrap());\n\n let owned = input_iter.next().unwrap();\n let price1 = input_iter.next().unwrap();\n let price2 = input_iter.next().unwrap();\n let price3 = input_iter.next().unwrap();\n\n if owned % 4 == 0 {\n // Already meet criteria\n println!(\"0\");\n return;\n }\n\n let purchase = 4 - owned % 4;\n let result = match purchase {\n 1 => min(price1, min(price3 * 3, price2 + price3)),\n 2 => min(price2, min(price1 * 2, price3 * 2)),\n 3 => min(price3, min(price1 * 3, price2 + price1)),\n _ => u64::max_value()\n };\n\n println!(\"{}\", result);\n}", "src_uid": "c74537b7e2032c1d928717dfe15ccfb8"} {"source_code": "use std::io::*;\n\nfn read(i: &mut StdinLock) -> T {\n let mut s = String::new();\n i.by_ref().read_line(&mut s).ok();\n s.trim().parse().ok().unwrap()\n}\n\nfn volume_of(word: &str) -> usize {\n word.chars().filter(|x| x.is_uppercase()).count()\n}\n\nfn main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let _n: usize = read(sin);\n let s: String = read(sin);\n\n println!(\"{}\", s.split(\" \").map(|x| volume_of(x)).max().unwrap_or(0));\n}\n", "src_uid": "d3929a9acf1633475ab16f5dfbead13c"} {"source_code": "macro_rules! parse_line {\n ($t: ty) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let a_str = a_str.trim();\n a_str.parse::<$t>().expect(\"parse error\")\n });\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().expect(\"parse error\"),\n )+\n )\n })\n}\n\nmacro_rules! parse_line_to_vec {\n ($t: ty) => {{\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n (a_str\n .split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect::>())\n }};\n}\n\nfn solve() {\n let field: Vec> = (0..10).map(|_| parse_line!(String).bytes().collect()).collect();\n let mut ok = false;\n for i in 0..10 {\n for j in 0..10 {\n if i + 5 <= 10 {\n let mut xs = 0;\n let mut os = 0;\n for d in 0..5 {\n if field[i + d][j] == b'X' {\n xs += 1;\n }else if field[i + d][j] == b'O' {\n os += 1;\n }\n }\n if os == 0 && xs >= 4 {\n ok = true;\n }\n }\n if j + 5 <= 10 {\n let mut xs = 0;\n let mut os = 0;\n for d in 0..5 {\n if field[i][j + d] == b'X' {\n xs += 1;\n }else if field[i][j + d] == b'O' {\n os += 1;\n }\n }\n if os == 0 && xs >= 4 {\n ok = true;\n }\n }\n if i + 5 <= 10 && j + 5 <= 10 {\n let mut xs = 0;\n let mut os = 0;\n for d in 0..5 {\n if field[i + d][j + d] == b'X' {\n xs += 1;\n }else if field[i + d][j + d] == b'O' {\n os += 1;\n }\n }\n if os == 0 && xs >= 4 {\n ok = true;\n }\n }\n if i + 5 <= 10 && j >= 4 {\n let mut xs = 0;\n let mut os = 0;\n for d in 0..5 {\n if field[i + d][j - d] == b'X' {\n xs += 1;\n }else if field[i + d][j - d] == b'O' {\n os += 1;\n }\n }\n if os == 0 && xs >= 4 {\n ok = true;\n }\n }\n }\n }\n println!(\"{}\", if ok {\"YES\"} else {\"NO\"});\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n", "src_uid": "d5541028a2753c758322c440bdbf9ec6"} {"source_code": "#![allow(unused_imports)]\nuse std::io::*;\nuse std::cmp::*;\nuse std::collections::*;\n\nmacro_rules! debug(\n ($($arg:tt)*) => { {\n let r = writeln!(&mut ::std::io::stderr(), $($arg)*);\n r.expect(\"failed printing to stderr\");\n } }\n);\n\nstruct Scanner {\n buffer : std::collections::VecDeque\n}\n\nimpl Scanner {\n\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn process(&mut self) -> String {\n if self.buffer.len() == 0 {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n for word in input.split_whitespace() {\n self.buffer.push_back(word.to_string())\n }\n }\n\n self.buffer.pop_front().unwrap()\n }\n\n fn next(&mut self) -> T {\n self.process().parse::().ok().unwrap()\n }\n\n fn next_char(&mut self) -> char {\n self.process().into_bytes()[0] as char\n }\n}\n\nfn main() {\n let mut s = Scanner::new();\n let (n, m) = (s.next(), s.next());\n\n let mut color = false;\n for _ in 0..n {\n for _ in 0..m {\n let c = s.next_char();\n match c {\n 'C' | 'M' | 'Y' => color = true,\n _ => { }\n }\n }\n }\n\n if color {\n println!(\"#Color\");\n } else {\n println!(\"#Black&White\");\n }\n}\n", "src_uid": "19c311c02380f9a73cd477e4fde27454"} {"source_code": "use std::io;\n\nfn read_line() -> Vec\nwhere\n T: std::str::FromStr,\n{\n let mut input = String::new();\n io::stdin()\n .read_line(&mut input)\n .expect(\"Error reading line\");\n\n input\n .trim()\n .split_ascii_whitespace()\n .map(|e| e.parse().ok().expect(\"Parsing error\"))\n .collect()\n}\n\nfn main() {\n let mut n = read_line::()[0];\n\n if n == 1 {\n println!(\"1\");\n } else {\n let mut sum = n;\n let mut button = 2;\n n = n - 1;\n while n > 1 {\n sum += 1 + button * (n - 1);\n n -= 1;\n button += 1;\n }\n sum += 1;\n println!(\"{}\", sum);\n }\n}\n", "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\nuse std::io::{StdinLock, stdin, BufRead};\nuse std::collections::*;\nuse std::cmp::*;\n\nfn scan_helper(lock : &mut StdinLock) -> String {\n let mut buffer = String::new();\n lock.read_line(&mut buffer).ok();\n buffer\n}\n\nmacro_rules! scan {\n ($lock:ident, $t:ty) => ({\n scan_helper(&mut $lock).split_whitespace()\n .next().unwrap()\n .parse::<$t>().unwrap()\n });\n ($lock:ident, $($t:ty),+) => ({\n let buffer = scan_helper(&mut $lock);\n let mut iter = buffer.split_whitespace();\n ($(\n {\n iter.next().unwrap()\n .parse::<$t>().unwrap()\n },\n )+)\n })\n}\n\nmacro_rules! scan_iter {\n ($lock:ident, $t:ty) => ({\n scan_helper(&mut $lock).split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect()\n })\n}\n\ntrait Ext {\n fn idx(&self) -> usize;\n fn num(&self) -> i64;\n}\n\nmacro_rules! ext {\n ($t:ty) => (\n impl Ext for $t {\n #[inline]\n fn idx(&self) -> usize {\n *self as usize\n }\n\n #[inline]\n fn num(&self) -> i64 {\n *self as i64\n }\n }\n )\n}\next!(i64);\next!(usize);\n\nmacro_rules! derive_regular {\n ($t:ty) => (\n impl Ord for $t {\n fn cmp(&self, other : &$t) -> Ordering {\n self.partial_cmp(other).unwrap()\n }\n }\n impl PartialEq for $t {\n fn eq(&self, other : &$t) -> bool {\n self.cmp(other) == Ordering::Equal\n }\n }\n impl Eq for $t {}\n )\n}\n\nfn solve(v : &Vec, n : i64, d : bool, memo : &mut HashMap<(i64, bool), (i64, i64)>) -> (i64, i64) {\n if n == v.len().num() {\n if d {\n return (0, 0);\n } else {\n return (0, 0);\n }\n }\n if let Some(&x) = memo.get(&(n, d)) {\n return x;\n }\n\n let mut take = solve(v, n+1, !d, memo);\n if d {\n take.1 += v[n.idx()];\n } else {\n take.0 += v[n.idx()];\n }\n let mut defer = solve(v, n+1, d, memo);\n if d {\n defer.0 += v[n.idx()];\n } else {\n defer.1 += v[n.idx()];\n }\n\n let result = if d {\n if take.1 >= defer.1 {\n take\n } else {\n defer\n }\n } else {\n if take.0 >= defer.0 {\n take\n } else {\n defer\n }\n };\n memo.insert((n, d), result);\n\n result\n}\n\nfn main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let n = scan!(s, i64);\n let data : Vec<_> = scan_iter!(s, i64);\n\n let mut memo = HashMap::new();\n\n let result = solve(&data, 0, true, &mut memo);\n println!(\"{} {}\", result.0, result.1);\n}", "src_uid": "414540223db9d4cfcec6a973179a0216"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn linear_sieve(n: u64) -> (Vec, Vec) {\n let n = n as usize;\n let mut mpf = vec![0u64; n + 1];\n let mut primes = Vec::new();\n for i in 2..=n {\n if mpf[i] == 0 {\n mpf[i] = i as u64;\n primes.push(i as u64);\n }\n // for (int j = 0; j < primes.size() && i * primes[j] <= n && primes[j] <= mpf[i]) {\n // mpf[i * primes[j]] = primes[j]\n // }\n for &p in primes.iter() {\n let num = i * p as usize;\n if num > n || p > mpf[i] {\n break;\n }\n mpf[num] = p;\n }\n }\n (primes, mpf)\n}\n\nfn get_mpf(n: u64, primes: &[u64], mpf: &[u64]) -> u64 {\n if (n as usize) < mpf.len() {\n return mpf[n as usize];\n }\n for &p in primes {\n if n % p == 0 {\n return p;\n }\n }\n n\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let (primes, mpf) = linear_sieve(1000000);\n let mut n: u64 = scan.token();\n let mut ans = n;\n while n > 1 {\n let factor = n / get_mpf(n, &primes, &mpf);\n ans += factor;\n n = factor;\n }\n writeln!(out, \"{}\", ans).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "821c0e3b5fad197a47878bba5e520b6e"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let ts: usize = scan.next();\n for _ in 0..ts {\n let n: usize = scan.next();\n if n <= 7 {\n println!(\"1\");\n continue;\n }\n let result = n / 7 + if n % 7 != 0 { 1 } else { 0 };\n println!(\"{}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "a661b6ce166fe4b2bbfd0ace56a7dc2c"} {"source_code": "use std::io::Read;\n\nfn triangle(a: i32, b: i32, c: i32) -> bool {\n return a < b + c && b < c + a && c < a + b;\n}\nfn segment(a: i32, b: i32, c: i32) -> bool {\n return a == b + c || b == c + a || c == a + b;\n}\n\nfn main() {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut tokens = buf.split_whitespace();\n let a:i32 = tokens.next().unwrap().parse().unwrap();\n let b:i32 = tokens.next().unwrap().parse().unwrap();\n let c:i32 = tokens.next().unwrap().parse().unwrap();\n let d:i32 = tokens.next().unwrap().parse().unwrap();\n if triangle(a,b,c) || triangle(a,b,d) || triangle(a,c,d) || triangle(b,c,d) {\n println!(\"TRIANGLE\");\n } else if segment(a,b,c) || segment(a,b,d) || segment(a,c,d) || segment(b,c,d) {\n println!(\"SEGMENT\");\n } else {\n println!(\"IMPOSSIBLE\");\n }\n}\n", "src_uid": "8f5df9a41e6e100aa65b9fc1d26e447a"} {"source_code": "#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n let mut next = || { iter.next().unwrap() };\n input_inner!{next, $($r)*}\n };\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n\n ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n #[cfg(debug_assertions)]\n writeln!(&mut std::io::stderr(), concat!(\"[DEBUG] \", $(stringify!($a), \"={:?} \"),*), $($a),*);\n }\n}\n\n#[allow(unused_imports)]\nuse std::cmp::{min, max};\n\n#[allow(unused_imports)]\nuse std::io::Write;\n\nfn main() {\n input!{\n n: usize,\n aa: [i64; n]\n }\n let h = n/2 + n%2;\n let mut pos = 0;\n let mut neg = 0;\n for i in 0..n {\n if aa[i] > 0 {\n pos += 1;\n }\n if aa[i] < 0 {\n neg += 1;\n }\n }\n if pos >= h {\n println!(\"{}\", 1);\n } else if neg >= h {\n println!(\"{}\", -1);\n } else {\n println!(\"{}\", 0);\n }\n}\n", "src_uid": "a13cb35197f896cd34614c6c0b369a49"} {"source_code": "macro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn main() {\n let (a,b) = readln!(i32,i32);\n let mut live = a;\n let mut dead = 0;\n let mut res = 0;\n while live>0 {\n res += live;\n dead += live;\n live = 0;\n live += (dead/b);\n dead %= b;\n }\n println!(\"{}\",res);\n}\n", "src_uid": "a349094584d3fdc6b61e39bffe96dece"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next_line(&self) -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n line\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let line = self.next_line();\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn get_order(x: usize, y: usize) -> usize {\n if x == 0 {\n return 0;\n }\n let mut x = x;\n let mut count = 0usize;\n while x % y == 0 {\n x /= y;\n count += 1;\n }\n count\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let mut a: usize = scan.next();\n let mut b: usize = scan.next();\n let mut result = 0usize;\n let possible: Vec = vec![2, 3, 5];\n for i in possible {\n let ia = get_order(a, i);\n let ib = get_order(b, i);\n let diff = ia.max(ib) - ia.min(ib);\n result += diff;\n\n if ia > ib {\n a /= i.pow(diff as u32);\n } else if ia < ib {\n b /= i.pow(diff as u32);\n }\n }\n if a != b {\n println!(\"-1\");\n } else {\n println!(\"{}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "75a97f4d85d50ea0e1af0d46f7565b49"} {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s = s.trim().to_string();\n let mut cnt1 = 0;\n let mut cnt2 = 0;\n for c in s.chars() {\n if (c as i32) >= ('a' as i32) {\n cnt1 += 1;\n } else {\n cnt2 += 1;\n }\n }\n for c in s.chars() {\n if cnt1 >= cnt2 {\n print!(\"{}\", c.to_lowercase());\n } else {\n print!(\"{}\", c.to_uppercase());\n }\n }\n}", "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn main() {\n let n: usize = get_line().trim().parse().unwrap();\n\n let a: Vec = get_vec();\n\n let dist = |a, b| {\n if a < b {\n b - a\n } else {\n a - b\n }\n };\n\n let prefix_sums: Vec<_> = (0..1).chain(a.into_iter().scan(0, |state, a| {\n *state += a;\n Some(*state)\n })).collect();\n\n let mut ans = None;\n\n for i in 0..n {\n for j in i + 1..n + 1 {\n let y = prefix_sums[j] - prefix_sums[i];\n let x = dist(y, 180);\n match ans {\n Some(ans) if ans < x => (),\n _ => {\n ans = Some(x);\n },\n }\n }\n }\n\n println!(\"{}\", 2 * ans.unwrap());\n}\n", "src_uid": "1b6a6aff81911865356ec7cbf6883e82"} {"source_code": "use std::io;\nfn main(){\n let mut s=String::new();\n io::stdin().read_line(&mut s).expect(\"Something is wrong\");\n let n=&s[0..s.find(' ').unwrap()];\n let mut n:i64=n.trim().parse().unwrap();\n let k=&s[s.find(' ').unwrap()+1..s.len()]; \n let mut k:i64=k.trim().parse().unwrap();\n let mut a:i64=n;\n let mut p:i64=0;\n while a%10==0{\n p+=1;\n a/=10;\n }\n if p>=k{println!(\"{}\",n)}\n else{k=k-p;\n match a%10{\n 1|3|7|9=>{for c in 0..k{n*=10}println!(\"{}\",n)},\n 5=>{while a%5==0{p+=1;a/=5;}if k>=p{for c in 0..p{n*=2}for c in 0..k-p{n*=10}}else{for c in 0..k{n*=2}}println!(\"{}\",n);},\n _=>{while a%2==0{p+=1;a/=2;}if k>=p{for c in 0..p{n*=5}for c in 0..k-p{n*=10}}else{for c in 0..k{n*=5}}println!(\"{}\",n);},\n }\n}\n}", "src_uid": "73566d4d9f20f7bbf71bc06bc9a4e9f3"} {"source_code": "use std::cmp::Ordering;\n\nfn main() {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let (n, k) = {\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|a| a.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n let (mut index, mut jump) = (n / 2, n / 2);\n loop {\n let sum_n = index * (index + 1) / 2;\n let eaten = n - index;\n\n if eaten > sum_n {\n jump = 1.max(jump / 2);\n index += jump;\n continue;\n }\n\n match k.cmp(&(sum_n - eaten)) {\n Ordering::Equal => break,\n Ordering::Greater => {\n jump = 1.max(jump / 2);\n index += jump;\n }\n Ordering::Less => {\n jump = 1.max(jump / 2);\n index -= jump;\n }\n }\n }\n\n println!(\"{}\", n - index);\n}", "src_uid": "17b5ec1c6263ef63c668c2b903db1d77"} {"source_code": "use std::io::{self, Write};\n\nconst MOD: i64 = 1e9 as i64 + 7;\n\nfn pow(mut a: i64, mut b: i64) -> i64 {\n let mut ans: i64 = 1;\n while b > 0 {\n if b & 1 == 1 {\n ans = (ans as i64 * a as i64) % MOD;\n }\n a = (a * a) % MOD;\n b >>= 1;\n }\n ans\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut sc = cf_scanner::Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n\n for _ in 0..sc.next() {\n writeln!(out, \"{}\", pow(sc.next(), sc.next())).unwrap();\n }\n}\n\n#[allow(dead_code)]\nmod cf_scanner {\n use std::io;\n use std::str::{FromStr, SplitAsciiWhitespace};\n\n pub struct Scanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n }\n\n impl Scanner {\n pub fn new(reader: R) -> Scanner {\n Scanner {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = std::str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n }\n}\n", "src_uid": "2e7a9f3a97938e4a7e036520d812b97a"} {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(overflowing_literals)]\n#![allow(unused_must_use)]\n#![allow(non_camel_case_types)]\n\nuse std::collections::*;\nuse std::io::*;\nuse std::cmp::{max, min, Ordering};\nuse std::f64::consts::*;\nuse std::mem::{swap, size_of_val, size_of};\nuse std::fs::File;\nuse std::rc::*;\nuse std::ascii::*;\nuse std::ops::*;\nuse std::num::*;\nuse std::process::*;\n//use std::ptr::*;\nuse std::iter::{once, repeat};\n\nconst INF: i32 = std::i32::MAX;\nconst LINF: i64 = std::i64::MAX;\nconst MOD: usize = 1000000007;\n\nstruct Input {\n\tbuffer: Buf,\n}\n\nimpl Input {\n\tfn read_char(&mut self) -> char {\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\tx[0] as char\n\t}\n\tfn read_line(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] < b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] >= b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\n\tfn read_word(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] <= b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] > b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n}\n\nmacro_rules! read {\n () => {};\n\t($inf:ident, $t:ty) => ($inf.read_word().parse::<$t>().expect(\"Parsing error\"));\n\t($inf:ident, $($t:ty),*) => (($($inf.read_word().parse::<$t>().expect(\"Parsing error\")),*));\n}\nfn gcd(mut a: T, mut b: T) -> T\n\twhere T: ShrAssign + BitAnd + Ord + From + Clone + SubAssign + ShlAssign + Copy\n{\n\tlet one = T::from(1);\n\tlet zero = T::from(0);\n\tlet mut ans = 0;\n\tif a < b {\n\t\tswap(&mut a, &mut b);\n\t}\n\twhile b > zero {\n\t\tif (a & one > zero) && (b & one > zero) {\n\t\t\ta -= b;\n\t\t} else if a & one > zero {\n\t\t\tb >>= one;\n\t\t} else if b & one > zero {\n\t\t\ta >>= one;\n\t\t} else {\n\t\t\tans += 1;\n\t\t\ta >>= one;\n\t\t\tb >>= one;\n\t\t}\n\t\tif a < b {\n\t\t\tswap(&mut a, &mut b);\n\t\t}\n\t}\n\ta <<= ans;\n\ta\n}\n\nfn powmod(mut base: X, mut exp: Y, mm: X) -> X\n\twhere X: Copy + Clone + Mul + Rem + From,\n\t Y: ShrAssign + Copy + Clone + BitAnd + From + Ord\n{\n\tlet mut res = X::from(1);\n\twhile exp > Y::from(0) {\n\t\tif exp & Y::from(1) > Y::from(0) {\n\t\t\tres = res * base % mm;\n\t\t}\n\t\tbase = base * base % mm;\n\t\texp >>= Y::from(1);\n\t}\n\tres\n}\n\nfn main() {\n\tmatch std::env::var(\"home\") {\n\t\tOk(_x) => {\n\t\t\tlet mut inf = Input { buffer: BufReader::new(File::open(\"input.txt\").expect(\"File not found\")) };\n\t\t\tlet stdout = stdout();\n\t\t\tlet ostr = stdout.lock();\n\t\t\tlet mut ouf = BufWriter::new(ostr);\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t\tErr(_e) => {\n\t\t\tlet stdin = stdin();\n\t\t\tlet istr = stdin.lock();\n\t\t\tlet mut inf = Input { buffer: BufReader::new(istr) };\n\t\t\tlet stdout = stdout();\n\t\t\tlet ostr = stdout.lock();\n\t\t\tlet mut ouf = BufWriter::new(ostr);\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t}\n}\n\n\nfn solve(inf: &mut Input, ouf: &mut Output) {\n\tlet (n, d) = read!(inf,usize,i32);\n\tlet mut a = vec![0; n];\n\tfor i in 0..n {\n\t\ta[i] = read!(inf,i32);\n\t}\n\ta.sort_unstable();\n\tlet mut ans = n;\n\tfor i in 0..n {\n\t\tfor j in i..n {\n\t\t\tif a[j] - a[i] <= d {\n\t\t\t\tans = min(ans, i + n - 1 - j);\n\t\t\t}\n\t\t}\n\t}\n\twriteln!(ouf, \"{}\", ans);\n}", "src_uid": "6bcb324c072f796f4d50bafea5f624b2"} {"source_code": "#![allow(unused_variables)]\n#![allow(unused_must_use)]\nuse std::io::{self, prelude::*};\nuse std::cmp::min;\n\n\nfn gcd(a: i64, b: i64) -> i64 {\n if b == 0 {\n return a\n }\n return gcd(b, a%b)\n\n}\nfn solve(mut input: FastInput, mut w: W) {\n let a: i64 = input.token();\n let b: i64 = input.token();\n let mut x: i64 = input.token();\n let mut y: i64 = input.token();\n let g = gcd(x,y);\n x = x / g;\n y = y / g;\n write!(w, \"{}\\n\", min(a/x, b/y));\n\n \n}\n \n\nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n let input = FastInput::from(stdin.lock());\n let output = io::BufWriter::new(stdout.lock());\n solve(input, output)\n}\n\ntrait TokenStream {\n fn token(&mut self) -> T;\n}\n \nstruct FastInput {\n stdin: R,\n pos: usize,\n}\n \nimpl From for FastInput {\n fn from(r: R) -> Self {\n FastInput { stdin: r, pos: 0 }\n }\n}\n \nimpl TokenStream for FastInput {\n fn token(&mut self) -> u8 {\n loop {\n if let Ok(buf) = self.stdin.fill_buf() {\n while self.pos < buf.len() {\n self.pos += 1;\n if buf[self.pos - 1] > 32 {\n return buf[self.pos - 1];\n }\n }\n if self.pos == 0 {\n return 0;\n }\n } else {\n return 0;\n }\n self.stdin.consume(self.pos);\n self.pos = 0;\n }\n }\n}\n \nimpl TokenStream> for FastInput {\n fn token(&mut self) -> Vec {\n let mut ans = Vec::new();\n let mut parse_token = false;\n loop {\n if let Ok(buf) = self.stdin.fill_buf() {\n if !parse_token {\n while self.pos < buf.len() && buf[self.pos] <= 32 {\n self.pos += 1;\n }\n }\n while self.pos < buf.len() && buf[self.pos] > 32 {\n parse_token = true;\n ans.push(buf[self.pos]);\n self.pos += 1;\n }\n if self.pos != buf.len() || self.pos == 0 {\n return ans;\n }\n }\n self.stdin.consume(self.pos);\n self.pos = 0;\n }\n }\n}\n \nmacro_rules! impl_token_stream {\n ($($t:ident),+) => {$(\n impl TokenStream<$t> for FastInput {\n fn token(&mut self) -> $t {\n let mut ans = 0;\n let mut parse_token = false;\n loop {\n if let Ok(buf) = self.stdin.fill_buf() {\n if !parse_token {\n while self.pos < buf.len() && buf[self.pos] <= 32 {\n self.pos += 1;\n }\n }\n while self.pos < buf.len() && buf[self.pos] > 32 {\n parse_token = true;\n ans = ans * 10 + (buf[self.pos] - b'0') as $t;\n self.pos += 1;\n }\n if self.pos != buf.len() || self.pos == 0 {\n return ans;\n }\n }\n self.stdin.consume(self.pos);\n self.pos = 0;\n }\n }\n }\n )+}\n}\n\n\nimpl_token_stream!(i64);", "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"source_code": "use std::io;\nuse std::io::Write;\n\n// Outline\n// read in numberse first and parse\n\nfn main() {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)\n .expect(\"Couldn't read line.\");\n\n let input: Vec = input\n .split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect();\n\n let number_of_pages: i32 = input[0];\n let current_page: i32 = input[1];\n let range_of_pages: i32 = input[2];\n\n let lower_bound = {\n if current_page - range_of_pages <= 0 {\n 1\n } else {\n current_page - range_of_pages\n }\n };\n\n let higher_bound = {\n if current_page + range_of_pages > number_of_pages {\n number_of_pages\n } else {\n current_page + range_of_pages\n }\n };\n\n if higher_bound != number_of_pages && lower_bound != 1 {\n print!(\"<< \");\n io::stdout().flush().unwrap();\n for page in lower_bound..higher_bound+1 {\n if page == current_page {\n print!(\"({}) \", page);\n io::stdout().flush().unwrap();\n } else {\n print!(\"{} \", page);\n io::stdout().flush().unwrap();\n }\n }\n print!(\">>\");\n io::stdout().flush().unwrap();\n } else if higher_bound == number_of_pages && lower_bound != 1 {\n print!(\"<< \");\n io::stdout().flush().unwrap();\n for page in lower_bound..higher_bound+1 {\n if page == current_page {\n print!(\"({}) \", page);\n io::stdout().flush().unwrap();\n } else {\n print!(\"{} \", page);\n io::stdout().flush().unwrap();\n }\n }\n } else if higher_bound == number_of_pages && lower_bound == 1 {\n for page in lower_bound..higher_bound+1 {\n if page == current_page {\n print!(\"({}) \", page);\n io::stdout().flush().unwrap();\n } else {\n print!(\"{} \", page);\n io::stdout().flush().unwrap();\n }\n }\n } else if higher_bound != number_of_pages && lower_bound == 1 {\n for page in lower_bound..higher_bound+1 {\n if page == current_page {\n print!(\"({}) \", page);\n io::stdout().flush().unwrap();\n } else {\n print!(\"{} \", page);\n io::stdout().flush().unwrap();\n }\n }\n print!(\">>\");\n io::stdout().flush().unwrap();\n }\n}\n", "src_uid": "526e2cce272e42a3220e33149b1c9c84"} {"source_code": "// ---------- begin BitSet ----------\n#[derive(Clone)]\nstruct BitSet {\n size: usize,\n a: Vec,\n}\n\nfn bit_size() -> usize {\n 8 * std::mem::size_of::()\n}\n\nfn quot_rem(n: usize) -> (usize, usize) {\n let w = bit_size();\n (n / w, n % w)\n}\n\n#[allow(dead_code)]\nimpl BitSet {\n fn new(size: usize) -> Self {\n let w = bit_size();\n BitSet {\n size: size,\n a: vec![0; (size + w - 1) / w],\n }\n }\n fn set_at(&mut self, x: usize) {\n assert!(x < self.size);\n let (q, r) = quot_rem(x);\n self.a[q] |= 1 << r;\n }\n fn clear_at(&mut self, x: usize) {\n assert!(x < self.size);\n let (q, r) = quot_rem(x);\n self.a[q] &= !(1 << r);\n }\n fn get_at(&self, x: usize) -> bool {\n if x >= self.size {\n return false;\n }\n let (q, r) = quot_rem(x);\n (self.a[q] >> r) & 1 == 1\n }\n fn any(&self) -> bool {\n self.a.iter().any(|a| *a != 0)\n }\n fn fix(&mut self) {\n let (q, r) = quot_rem(self.size);\n if r != 0 {\n self.a[q] &= (1 << r) - 1;\n }\n }\n fn clear(&mut self) {\n let len = self.a.len();\n self.a.clear();\n self.a.resize(len, 0);\n }\n fn truncate(&mut self, len: usize) {\n if len >= self.size {\n return;\n }\n let w = bit_size();\n self.a.truncate((len + w - 1) / w);\n self.size = len;\n self.fix();\n }\n fn popcnt(&self) -> usize {\n self.a.iter().fold(0, |s, a| s + a.count_ones() as usize)\n }\n fn shift_left(&self, rhs: usize) -> Self {\n let (q, r) = quot_rem(rhs);\n let mut ans = BitSet::new(self.size + rhs);\n if r == 0 {\n for (x, y) in ans.a[q..].iter_mut().zip(self.a.iter()) {\n *x = *y;\n }\n } else {\n let w = bit_size();\n let mut prev = 0;\n for (x, y) in ans.a[q..].iter_mut().zip(self.a.iter()) {\n *x = (*y << r) | (prev >> (w - r));\n prev = *y;\n }\n *ans.a.last_mut().unwrap() |= prev >> (w - r);\n }\n ans.fix();\n ans\n }\n fn shift_right(&self, rhs: usize) -> Self {\n if rhs >= self.size {\n return BitSet::new(1);\n }\n let (q, r) = quot_rem(rhs);\n let mut ans = BitSet::new(self.size - rhs);\n if r == 0 {\n for (x, y) in ans.a.iter_mut().zip(self.a[q..].iter()) {\n *x = *y;\n }\n } else {\n let w = bit_size();\n let mut prev = 0;\n for (x, y) in ans.a.iter_mut().zip(self.a[q..].iter()).rev() {\n *x |= (*y >> r) | (prev << (w - r));\n prev = *y;\n }\n }\n ans.fix();\n ans\n }\n fn bitwise_or(&self, rhs: &Self) -> Self {\n let (x, y) = if self.size >= rhs.size {\n (self, rhs)\n } else {\n (rhs, self)\n };\n let mut a = x.a.clone();\n for (a, y) in a.iter_mut().zip(y.a.iter()) {\n *a |= *y;\n }\n BitSet { size: x.size, a: a }\n }\n fn bitwise_and(&self, rhs: &Self) -> Self {\n let (x, y) = if self.size <= rhs.size {\n (self, rhs)\n } else {\n (rhs, self)\n };\n let mut a = x.a.clone();\n for (a, y) in a.iter_mut().zip(y.a.iter()) {\n *a &= *y;\n }\n BitSet { size: x.size, a: a }\n }\n fn bitwise_xor(&self, rhs: &Self) -> Self {\n let (x, y) = if self.size >= rhs.size {\n (self, rhs)\n } else {\n (rhs, self)\n };\n let mut a = x.a.clone();\n for (a, y) in a.iter_mut().zip(y.a.iter()) {\n *a ^= *y;\n }\n BitSet { size: x.size, a: a }\n }\n fn bitwise_or_assign(&mut self, rhs: &Self) {\n if self.size < rhs.size {\n self.size = rhs.size;\n self.a.resize(rhs.a.len(), 0);\n }\n for (a, b) in self.a.iter_mut().zip(rhs.a.iter()) {\n *a |= *b;\n }\n }\n fn bitwise_and_assign(&mut self, rhs: &Self) {\n if self.size > rhs.size {\n self.size = rhs.size;\n self.a.resize(rhs.a.len(), 0);\n }\n for (a, b) in self.a.iter_mut().zip(rhs.a.iter()) {\n *a &= *b;\n }\n }\n fn bitwise_xor_assign(&mut self, rhs: &Self) {\n if self.size < rhs.size {\n self.size = rhs.size;\n self.a.resize(rhs.a.len(), 0);\n }\n for (a, b) in self.a.iter_mut().zip(rhs.a.iter()) {\n *a ^= *b;\n }\n }\n}\n// ---------- end BitSet ----------\n//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, bytes) => {\n read_value!($iter, String).bytes().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\n// \u7570\u306a\u308b\u5024\u304c\u542b\u307e\u308c\u308b\u3084\u3064\u306f\u3069\u3063\u3061\u304c\u3069\u3063\u3061\u304b\u308f\u304b\u3089\u306a\u3044\u306e\u3067\u4e0d\u53ef\u80fd\n// \u540c\u3058\u5024\u306e\u307f\u3092\u805e\u304d\u51fa\u3059\u6226\u7565\n// \u540c\u3058\u5024\u306e\u307f\u3092\u6b8b\u305b\u308b\u3088\u3046\u306b\u805e\u304f\u6226\u7565\n// \u540c\u3058\u5024\u3092\u6b8b\u305b\u308b\u3088\u3046\u306b\u805e\u304f\u6226\u7565\u304c\u3067\u304d\u308b\u306a\u3089\u306e\u307f\u3092\u805e\u304d\u51fa\u3059\u3053\u3068\u3082\u53ef\u80fd\n//\n// \u540c\u3058\u5024\u306e\u307f\u3092\u6b8b\u3059\n// a \u3092k \u500b\u805e\u304d\u51fa\u305b\u308b\u6761\u4ef6\u306f\n// a\u3092\u4f7f\u308f\u306a\u3044\u3067(k - i) * a \u3092\u4f5c\u308c\u306a\u3044\u3053\u3068\n// \u5206\u5272\u7d71\u6cbbbitset?\n\nfn calc(a: &[(usize, usize)], dp: &[BitSet]) -> usize {\n let n = a.len();\n if n == 1 {\n let (a, c) = a[0];\n let mut ans = 1;\n for k in 2..=c {\n let mut ok = true;\n for j in 0..k {\n ok &= !dp[k - j].get_at(a * (k - j));\n }\n if ok {\n ans = k;\n }\n }\n return ans;\n }\n let (l, r) = a.split_at(n / 2);\n let mut p = vec![];\n p.extend_from_slice(dp);\n for &(a, c) in l.iter() {\n for _ in 0..c {\n for i in (1..dp.len()).rev() {\n let mut set = p[i].bitwise_or(&p[i - 1].shift_left(a));\n set.truncate(dp[0].size);\n p[i] = set;\n }\n }\n }\n let a = calc(r, &p);\n let mut p = vec![];\n p.extend_from_slice(dp);\n for &(a, c) in r.iter() {\n for _ in 0..c {\n for i in (1..dp.len()).rev() {\n let mut set = p[i].bitwise_or(&p[i - 1].shift_left(a));\n set.truncate(dp[0].size);\n p[i] = set;\n }\n }\n }\n std::cmp::max(a, calc(l, &p))\n}\n\nfn run() {\n input! {\n n: usize,\n a: [usize; n],\n }\n let mut a = a.into_iter().map(|a| (a, 1)).collect::>();\n a.sort();\n a.dedup_by(|a, b| {\n a.0 == b.0 && {\n b.1 += a.1;\n true\n }\n });\n if a.len() <= 2 {\n println!(\"{}\", n);\n return;\n }\n let w = n * 100;\n let mut dp = vec![BitSet::new(w + 1); n + 1];\n dp[0].set_at(0);\n let ans = calc(&a, &dp);\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "ccc4b27889598266e8efe73b8aa3666c"} {"source_code": "use std::io::{self, Read};\nuse std::cmp;\n \nfn main() {\n let mut buffer = String::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n handle.read_to_string(&mut buffer).unwrap();\n\n let arr : Vec<_> = buffer.split_whitespace().map(|x| x.parse::().unwrap() ).collect();\n let n = arr[0];\n let mut d = 0;\n let mut h = n;\n while h > 0 {\n d += 1;\n h = h / 10;\n }\n use std::cmp;\n let mut a = 0;\n 'outer: for i in 0..d {\n // println!(\"{}\",a);\n let mut r = 0;\n for j in 0..10 {\n let y = j * 10u64.pow(i);\n if a + y <= n {\n r = cmp::max(a + y, r);\n // println!(\"{}\",r);\n }\n }\n a = r;\n }\n let mut b = n - a;\n // println!(\"{} {}\", a, b);\n let mut ans = 0;\n while a > 0 {\n ans += a % 10;\n a = a / 10;\n }\n while b > 0 {\n ans += b % 10;\n b = b / 10;\n }\n println!(\"{}\", ans);\n}\n", "src_uid": "5c61b4a4728070b9de49d72831cd2329"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n let mut next = || { iter.next().unwrap() };\n input_inner!{next, $($r)*}\n };\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }};\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n/// Verified by: https://atcoder.jp/contests/pakencamp-2018-day3/submissions/3878249\nmod mod_int {\n use std::ops::*;\n pub trait Mod: Copy + Clone { fn m() -> i64; }\n #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]\n pub struct ModInt { pub x: i64, phantom: ::std::marker::PhantomData<*const M> }\n impl ModInt {\n fn check_integrity(self) {\n debug_assert!(self.x >= 0);\n debug_assert!(self.x < M::m());\n }\n // x >= 0\n pub fn new(x: i64) -> Self { ModInt::new_internal(x % M::m()) }\n fn new_internal(x: i64) -> Self {\n ModInt { x: x, phantom: ::std::marker::PhantomData }\n }\n #[allow(dead_code)]\n pub fn mul_fast(self, other: Self) -> Self {\n self.check_integrity();\n other.check_integrity();\n ModInt::new_internal(self.x * other.x % M::m())\n }\n #[allow(dead_code)]\n pub fn mul_slow(self, other: Self) -> Self {\n // Naive multiplication in order to avoid overflow\n self.check_integrity();\n other.check_integrity();\n let mut sum = ModInt::new_internal(0);\n let mut cur = self;\n let mut e = other.x;\n if self.x < other.x {\n cur = other;\n e = self.x;\n }\n while e > 0 {\n if e % 2 == 1 { sum += cur; }\n cur += cur;\n e /= 2;\n }\n sum\n }\n pub fn pow(self, mut e: i64) -> Self {\n self.check_integrity();\n debug_assert!(e >= 0);\n let mut sum = ModInt::new_internal(1);\n let mut cur = self;\n while e > 0 {\n if e % 2 != 0 { sum *= cur; }\n cur *= cur;\n e /= 2;\n }\n sum\n }\n #[allow(dead_code)]\n pub fn inv(self) -> Self { self.pow(M::m() - 2) }\n }\n impl Add for ModInt {\n type Output = Self;\n fn add(self, other: Self) -> Self {\n self.check_integrity();\n other.check_integrity();\n let mut sum = self.x + other.x;\n if sum >= M::m() { sum -= M::m(); }\n ModInt::new_internal(sum)\n }\n }\n impl Sub for ModInt {\n type Output = Self;\n fn sub(self, other: Self) -> Self {\n self.check_integrity();\n other.check_integrity();\n let mut sum = self.x - other.x;\n if sum < 0 { sum += M::m(); }\n ModInt::new_internal(sum)\n }\n }\n impl Mul for ModInt {\n type Output = Self;\n fn mul(self, other: Self) -> Self { self.mul_fast(other) }\n }\n impl AddAssign for ModInt {\n fn add_assign(&mut self, other: Self) { *self = *self + other; }\n }\n impl SubAssign for ModInt {\n fn sub_assign(&mut self, other: Self) { *self = *self - other; }\n }\n impl MulAssign for ModInt {\n fn mul_assign(&mut self, other: Self) { *self = *self * other; }\n }\n impl ::std::fmt::Display for ModInt {\n fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {\n self.x.fmt(f)\n }\n }\n impl ::std::fmt::Debug for ModInt {\n fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {\n self.x.fmt(f)\n }\n }\n} // mod mod_int\n\nmacro_rules! define_mod {\n ($struct_name: ident, $modulo: expr) => {\n #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]\n struct $struct_name {}\n impl mod_int::Mod for $struct_name { fn m() -> i64 { $modulo } }\n }\n}\nconst MOD: i64 = 998244353;\ndefine_mod!(P, MOD);\ntype ModInt = mod_int::ModInt

;\n\n/// FFT (in-place)\n/// R: Ring + Copy\n/// Verified by: ATC001-C (http://atc001.contest.atcoder.jp/submissions/1175827)\nmod fft {\n use std::ops::*;\n /// n should be a power of 2. zeta is a primitive n-th root of unity.\n /// one is unity\n /// Note that the result should be multiplied by 1/sqrt(n).\n pub fn transform(f: &mut [R], zeta: R, one: R)\n where R: Copy +\n Add +\n Sub +\n Mul {\n let n = f.len();\n assert!(n.is_power_of_two());\n {\n let mut i = 0;\n for j in 1 .. n - 1 {\n let mut k = n >> 1;\n loop {\n i ^= k;\n if k <= i { break; }\n k >>= 1;\n }\n if j < i {\n f.swap(i, j);\n }\n }\n }\n let mut zetapow = Vec::new();\n {\n let mut m = 1;\n let mut cur = zeta;\n while m < n {\n zetapow.push(cur);\n cur = cur * cur;\n m *= 2;\n }\n }\n let mut m = 1;\n while m < n {\n let m2 = 2 * m;\n let base = zetapow.pop().unwrap();\n let mut r = 0;\n while r < n {\n let mut w = one;\n for x in 0 .. m {\n let s = x + r;\n let u = f[s];\n let d = f[s + m] * w;\n f[s] = u + d;\n f[s + m] = u - d;\n w = w * base;\n }\n r += m2;\n }\n m *= 2;\n }\n }\n}\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (write!(out,$($format)*).unwrap());\n }\n input! {\n n: usize,\n k: usize,\n d: [usize; k],\n }\n const N: usize = 1 << 22;\n let one = ModInt::new(1);\n let mut f = vec![ModInt::new(0); N];\n let zeta = ModInt::new(3).pow((MOD - 1) / N as i64);\n for i in 0 .. k {\n f[d[i]] += one;\n }\n fft::transform(&mut f, zeta, one);\n for i in 0 .. N {\n f[i] = f[i].pow(n as i64 / 2);\n }\n fft::transform(&mut f, zeta.inv(), one);\n let factor = ModInt::new(N as i64).inv();\n for i in 0 .. N {\n f[i] *= factor;\n }\n let mut tot = ModInt::new(0);\n for i in 0 .. N {\n tot += f[i].pow(2);\n }\n puts!(\"{}\\n\", tot);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "279f1f7d250a4be6406c6c7bfc818bbf"} {"source_code": "\nuse std::io;\n\n#[derive(Debug, Copy, Clone, PartialEq)]\nenum Color {\n C,\n Y,\n M,\n U,\n}\n\nimpl Color {\n fn create(c: char) -> Self {\n match c {\n 'C' => Color::C,\n 'Y' => Color::Y,\n 'M' => Color::M,\n _ => Color::U,\n }\n }\n}\n\npub fn main() {\n let input = get_input();\n let length = input.len();\n let mut unknowns = 0;\n let mut two_solutions = false;\n let mut unknown_location = 0;\n //println!(\"{:?}\", input);\n if input[0] == Color::U {\n two_solutions = true;\n }\n for i in 1..length {\n if input[i] == Color::U {\n if i == length - 1 || i == 0 ||\n input[i + 1] == input[i - 1] || input[i - 1] == Color::U {\n two_solutions = true;\n }\n } else if input[i] == input[i - 1] {\n println!(\"No\");\n return;\n }\n }\n if two_solutions {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n}\n\nfn get_input() -> Vec {\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n input.trim().chars().map(|c| Color::create(c)).collect()\n}\n", "src_uid": "f8adfa0dde7ac1363f269dbdf00212c3"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn main() {\n let n: usize = get_line().trim().parse().unwrap();\n\n let s = get_line().trim().to_string();\n\n let it = s.split_terminator(char::is_uppercase);\n\n let ans = it.map(|s| {\n s.bytes().fold(vec![false; 26], |mut acc, c| {\n acc[(c - b'a') as usize] = true;\n acc\n }).into_iter().filter(|&b| b).count()\n }).max().unwrap();\n\n println!(\"{}\", ans);\n}\n", "src_uid": "567ce65f87d2fb922b0f7e0957fbada3"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: i64 = scan.token();\n let m: i64 = scan.token();\n let mut ans: i64 = 0;\n for x in 1..=n {\n // How many multiples of 5 minus x are there in [1, m]?\n ans += (m + x) / 5 - (x + 5) / 5 + 1;\n }\n writeln!(out, \"{}\", ans).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "df0879635b59e141c839d9599abd77d2"} {"source_code": "use std::io;\n\nfn main() -> io::Result<()> {\n let mut s = String::new();\n let stdin = io::stdin();\n\n let _ = stdin.read_line(&mut s)?;\n s = s.trim().to_string();\n\n let word = \"hello\";\n if calc(word, &s) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n Ok(())\n}\n\nfn calc(sub: &str, s: &str) -> bool {\n calc2(sub.as_bytes(), s.as_bytes())\n}\n\nfn calc2<'a, T>(sub: T, s: T) -> bool\nwhere\n T: IntoIterator,\n T::IntoIter: Clone\n{\n let mut sub_iter = sub.into_iter();\n let mut s_iter = s.into_iter();\n\n if let Some(c) = sub_iter.next() {\n while let Some(c2) = s_iter.next() {\n if c == c2 && calc2(sub_iter.clone(), s_iter.clone()) {\n return true\n }\n }\n false\n } else {\n true\n }\n}", "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"source_code": "fn read_string() -> String {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).expect(\"Failed\");\n input\n}\n\nfn main(){\n \n let mut x = read_string();\n x = x.replace(\"\\r\", \"\");\n let vec: Vec<&str> = x.split(\"\").collect();\n let mut found: bool = false;\n for n in 2..(vec.len()-3){\n if ((vec[n] != \".\") && (vec[n+1] != \".\") && (vec[n-1] != \".\")) &&\n ((vec[n] != vec[n+1]) && (vec[n-1] != vec[n+1]) && (vec[n] != vec[n-1]))\n {\n found = true;\n break\n }\n }\n println!(\"{}\", if found {\"YES\"} else {\"NO\"});\n}\n", "src_uid": "ba6ff507384570152118e2ab322dd11f"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::Read;\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok().unwrap();\n ret\n}\nfn get_word() -> String {\n let mut stdin = std::io::stdin();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\nfn solve() {\n let mut n: i64 = get();\n let k: i32 = get();\n let mut cnt = 0;\n let mut kk = k;\n while kk > 0 {\n if n == 0 {\n cnt = max(cnt + k - kk - 1, 0);\n break;\n }\n if n % 10 != 0 {\n cnt += 1;\n } else {\n kk -= 1;\n }\n n /= 10;\n }\n println!(\"{}\", cnt);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "7a8890417aa48c2b93b559ca118853f9"} {"source_code": "pub trait Readable {\n type Output;\n fn words_count() -> usize;\n fn read_words(words: &[&str]) -> Result;\n}\n#[macro_export]\nmacro_rules! readable {\n ( $ t : ty , $ words_count : expr , |$ words : ident | $ read_words : expr ) => {\n impl Readable for $t {\n type Output = $t;\n fn words_count() -> usize {\n $words_count\n }\n fn read_words($words: &[&str]) -> Result<$t, String> {\n Ok($read_words)\n }\n }\n };\n}\nreadable!((), 1, |_ss| ());\nreadable!(String, 1, |ss| ss[0].to_string());\nimpl Readable for char {\n type Output = char;\n fn words_count() -> usize {\n 1\n }\n fn read_words(words: &[&str]) -> Result {\n let chars: Vec = words[0].chars().collect();\n if chars.len() == 1 {\n Ok(chars[0])\n } else {\n Err(format!(\"cannot parse `{}` as a char\", words[0]))\n }\n }\n}\npub struct Chars();\nimpl Readable for Chars {\n type Output = Vec;\n fn words_count() -> usize {\n 1\n }\n fn read_words(words: &[&str]) -> Result, String> {\n Ok(words[0].chars().collect())\n }\n}\nmacro_rules ! impl_readable_for_ints { ( $ ( $ t : ty ) * ) => { $ ( impl Readable for $ t { type Output = Self ; fn words_count ( ) -> usize { 1 } fn read_words ( words : & [ & str ] ) -> Result <$ t , String > { use std :: str :: FromStr ; <$ t >:: from_str ( words [ 0 ] ) . map_err ( | _ | { format ! ( \"cannot parse `{}` as {}\" , words [ 0 ] , stringify ! ( $ t ) ) } ) } } ) * } ; }\nimpl_readable_for_ints ! ( i8 u8 i16 u16 i32 u32 i64 u64 isize usize f32 f64 ) ;\nmacro_rules ! define_one_origin_int_types { ( $ new_t : ident $ int_t : ty ) => { # [ doc = \" Converts 1-origin integer into 0-origin when read from stdin.\" ] # [ doc = \"\" ] # [ doc = \" # Example\" ] # [ doc = \"\" ] # [ doc = \" ```no_run\" ] # [ doc = \" # #[macro_use] extern crate atcoder_snippets;\" ] # [ doc = \" # use atcoder_snippets::read::*;\" ] # [ doc = \" // Stdin: \\\"1\\\"\" ] # [ doc = \" read!(a = usize_);\" ] # [ doc = \" assert_eq!(a, 0);\" ] # [ doc = \" ```\" ] # [ allow ( non_camel_case_types ) ] pub struct $ new_t ; impl Readable for $ new_t { type Output = $ int_t ; fn words_count ( ) -> usize { 1 } fn read_words ( words : & [ & str ] ) -> Result < Self :: Output , String > { <$ int_t >:: read_words ( words ) . map ( | n | n - 1 ) } } } ; ( $ new_t : ident $ int_t : ty ; $ ( $ inner_new_t : ident $ inner_int_t : ty ) ;* ) => { define_one_origin_int_types ! ( $ new_t $ int_t ) ; define_one_origin_int_types ! ( $ ( $ inner_new_t $ inner_int_t ) ;* ) ; } ; }\ndefine_one_origin_int_types ! ( u8_ u8 ; u16_ u16 ; u32_ u32 ; u64_ u64 ; usize_ usize ) ;\nmacro_rules ! impl_readable_for_tuples { ( $ t : ident $ var : ident ) => ( ) ; ( $ t : ident $ var : ident ; $ ( $ inner_t : ident $ inner_var : ident ) ;* ) => { impl_readable_for_tuples ! ( $ ( $ inner_t $ inner_var ) ;* ) ; impl <$ t : Readable , $ ( $ inner_t : Readable ) ,*> Readable for ( $ t , $ ( $ inner_t ) ,* ) { type Output = ( <$ t >:: Output , $ ( <$ inner_t >:: Output ) ,* ) ; fn words_count ( ) -> usize { let mut n = <$ t >:: words_count ( ) ; $ ( n += <$ inner_t >:: words_count ( ) ; ) * n } # [ allow ( unused_assignments ) ] fn read_words ( words : & [ & str ] ) -> Result < Self :: Output , String > { let mut start = 0 ; let $ var = <$ t >:: read_words ( & words [ start .. start +<$ t >:: words_count ( ) ] ) ?; start += <$ t >:: words_count ( ) ; $ ( let $ inner_var = <$ inner_t >:: read_words ( & words [ start .. start +<$ inner_t >:: words_count ( ) ] ) ?; start += <$ inner_t >:: words_count ( ) ; ) * Ok ( ( $ var , $ ( $ inner_var ) ,* ) ) } } } ; }\nimpl_readable_for_tuples ! ( T8 x8 ; T7 x7 ; T6 x6 ; T5 x5 ; T4 x4 ; T3 x3 ; T2 x2 ; T1 x1 ) ;\npub trait ReadableFromLine {\n type Output;\n fn read_line(line: &str) -> Result;\n}\nfn split_into_words(line: &str) -> Vec<&str> {\n #[allow(deprecated)]\n line.trim_right_matches('\\n').split_whitespace().collect()\n}\nimpl ReadableFromLine for T {\n type Output = T::Output;\n fn read_line(line: &str) -> Result {\n let words = split_into_words(line);\n if words.len() != T::words_count() {\n return Err(format!(\n \"line `{}` has {} words, expected {}\",\n line,\n words.len(),\n T::words_count()\n ));\n }\n T::read_words(&words)\n }\n}\nmacro_rules ! impl_readable_from_line_for_tuples_with_from_iterator { ( $ u : ident : $ ( + $ bound : path ) * => $ seq_in : ty , $ seq_out : ty ; $ t : ident $ var : ident ) => { impl <$ u : Readable > ReadableFromLine for $ seq_in where <$ u as Readable >:: Output : Sized $ ( + $ bound ) * { type Output = $ seq_out ; fn read_line ( line : & str ) -> Result <$ seq_out , String > { let n = $ u :: words_count ( ) ; let words = split_into_words ( line ) ; if words . len ( ) % n != 0 { return Err ( format ! ( \"line `{}` has {} words, expected multiple of {}\" , line , words . len ( ) , n ) ) ; } let mut result = Vec :: new ( ) ; for chunk in words . chunks ( n ) { match $ u :: read_words ( chunk ) { Ok ( v ) => result . push ( v ) , Err ( msg ) => { let flagment_msg = if n == 1 { format ! ( \"word {}\" , result . len ( ) ) } else { let l = result . len ( ) ; format ! ( \"words {}-{}\" , n * l + 1 , ( n + 1 ) * l ) } ; return Err ( format ! ( \"{} of line `{}`: {}\" , flagment_msg , line , msg ) ) ; } } } Ok ( result . into_iter ( ) . collect ( ) ) } } impl < T : Readable , $ u : Readable > ReadableFromLine for ( T , $ seq_in ) where <$ u as Readable >:: Output : Sized $ ( + $ bound ) * { type Output = ( T :: Output , $ seq_out ) ; fn read_line ( line : & str ) -> Result < Self :: Output , String > { let n = T :: words_count ( ) ; # [ allow ( deprecated ) ] let trimmed = line . trim_right_matches ( '\\n' ) ; let words_and_rest : Vec <& str > = trimmed . splitn ( n + 1 , ' ' ) . collect ( ) ; if words_and_rest . len ( ) < n { return Err ( format ! ( \"line `{}` has {} words, expected at least {}\" , line , words_and_rest . len ( ) , n ) ) ; } let words = & words_and_rest [ .. n ] ; let empty_str = \"\" ; let rest = words_and_rest . get ( n ) . unwrap_or ( & empty_str ) ; Ok ( ( T :: read_words ( words ) ?, <$ seq_in >:: read_line ( rest ) ? ) ) } } } ; ( $ u : ident : $ ( + $ bound : path ) * => $ seq_in : ty , $ seq_out : ty ; $ t : ident $ var : ident , $ ( $ inner_t : ident $ inner_var : ident ) ,+ ) => { impl_readable_from_line_for_tuples_with_from_iterator ! ( $ u : $ ( + $ bound ) * => $ seq_in , $ seq_out ; $ ( $ inner_t $ inner_var ) ,+ ) ; impl <$ t : Readable , $ ( $ inner_t : Readable ) ,+ , $ u : Readable > ReadableFromLine for ( $ t , $ ( $ inner_t ) ,+ , $ seq_in ) where <$ u as Readable >:: Output : Sized $ ( + $ bound ) * { type Output = ( $ t :: Output , $ ( $ inner_t :: Output ) ,+ , $ seq_out ) ; fn read_line ( line : & str ) -> Result < Self :: Output , String > { let mut n = $ t :: words_count ( ) ; $ ( n += $ inner_t :: words_count ( ) ; ) + # [ allow ( deprecated ) ] let trimmed = line . trim_right_matches ( '\\n' ) ; let words_and_rest : Vec <& str > = trimmed . splitn ( n + 1 , ' ' ) . collect ( ) ; if words_and_rest . len ( ) < n { return Err ( format ! ( \"line `{}` has {} words, expected at least {}\" , line , words_and_rest . len ( ) , n ) ) ; } let words = & words_and_rest [ .. n ] ; let empty_str = \"\" ; let rest = words_and_rest . get ( n ) . unwrap_or ( & empty_str ) ; let ( $ var , $ ( $ inner_var ) ,* ) = < ( $ t , $ ( $ inner_t ) ,+ ) >:: read_words ( words ) ?; Ok ( ( $ var , $ ( $ inner_var ) ,* , <$ seq_in >:: read_line ( rest ) ? ) ) } } } ; }\n#[macro_export]\nmacro_rules ! readable_collection { ( $ u : ident => $ collection_in : ty , $ collection_out : ty ) => { impl_readable_from_line_for_tuples_with_from_iterator ! ( $ u : => $ collection_in , $ collection_out ; T8 x8 , T7 x7 , T6 x6 , T5 x5 , T4 x4 , T3 x3 , T2 x2 , T1 x1 ) ; } ; ( $ u : ident : $ ( $ bound : path ) ,* => $ collection_in : ty , $ collection_out : ty ) => { impl_readable_from_line_for_tuples_with_from_iterator ! ( $ u : $ ( + $ bound ) * => $ collection_in , $ collection_out ; T8 x8 , T7 x7 , T6 x6 , T5 x5 , T4 x4 , T3 x3 , T2 x2 , T1 x1 ) ; } }\nreadable_collection ! ( U => Vec < U >, Vec < U :: Output > ) ;\nreadable_collection ! ( U => std :: collections :: VecDeque < U >, std :: collections :: VecDeque < U :: Output > ) ;\nreadable_collection ! ( U : Eq , std :: hash :: Hash => std :: collections :: HashSet < U >, std :: collections :: HashSet < U :: Output > ) ;\nreadable_collection ! ( U : Ord => std :: collections :: BTreeSet < U >, std :: collections :: BTreeSet < U :: Output > ) ;\nreadable_collection ! ( U : Ord => std :: collections :: BinaryHeap < U >, std :: collections :: BinaryHeap < U :: Output > ) ;\npub fn read() -> T::Output {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n T::read_line(&line).unwrap()\n}\n#[macro_export]\nmacro_rules ! read { ( ) => { let mut line = String :: new ( ) ; std :: io :: stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; } ; ( $ pat : pat = $ t : ty ) => { let $ pat = read ::<$ t > ( ) ; } ; ( $ ( $ pat : pat = $ t : ty ) ,+ ) => { read ! ( ( $ ( $ pat ) ,* ) = ( $ ( $ t ) ,* ) ) ; } ; }\n#[macro_export]\nmacro_rules ! readls { ( $ ( $ pat : pat = $ t : ty ) ,+ ) => { $ ( read ! ( $ pat = $ t ) ; ) * } ; }\npub fn readx() -> Vec {\n use std::io::{self, BufRead};\n let stdin = io::stdin();\n let result = stdin\n .lock()\n .lines()\n .map(|line_result| {\n let line = line_result.expect(\"read from stdin failed\");\n T::read_line(&line).unwrap()\n })\n .collect();\n result\n}\n#[macro_export]\nmacro_rules ! readx_loop { ( |$ pat : pat = $ t : ty | $ body : expr ) => { { use std :: io :: BufRead ; let stdin = std :: io :: stdin ( ) ; for line in stdin . lock ( ) . lines ( ) { let line = line . expect ( \"read from stdin failed\" ) ; let $ pat = <$ t >:: read_line ( & line ) . unwrap ( ) ; $ body } } } ; ( |$ ( $ pat : pat = $ t : ty ) ,*| $ body : expr ) => { readx_loop ! ( | ( $ ( $ pat ) ,* ) = ( $ ( $ t ) ,* ) | $ body ) ; } ; }\npub fn readn(n: usize) -> Vec {\n use std::io::{self, BufRead};\n let stdin = io::stdin();\n let result: Vec = stdin\n .lock()\n .lines()\n .take(n)\n .map(|line_result| {\n let line = line_result.expect(\"read from stdin failed\");\n T::read_line(&line).unwrap()\n })\n .collect();\n if result.len() < n {\n panic!(\n \"expected reading {} lines, but only {} lines are read\",\n n,\n result.len()\n );\n }\n result\n}\n#[macro_export]\nmacro_rules ! readn_loop { ( $ n : expr , |$ pat : pat = $ t : ty | $ body : expr ) => { { use std :: io :: BufRead ; let stdin = std :: io :: stdin ( ) ; let mut lock = stdin . lock ( ) ; for _ in 0 ..$ n { let mut line = String :: new ( ) ; lock . read_line ( & mut line ) . expect ( \"read from stdin failed\" ) ; let $ pat = <$ t >:: read_line ( & line ) . unwrap ( ) ; $ body } } } ; ( $ n : expr , |$ ( $ pat : pat = $ t : ty ) ,*| $ body : expr ) => { readn_loop ! ( $ n , | ( $ ( $ pat ) ,* ) = ( $ ( $ t ) ,* ) | $ body ) ; } ; }\npub trait Words {\n fn read(&self) -> T::Output;\n}\nimpl<'a> Words for [&'a str] {\n fn read(&self) -> T::Output {\n T::read_words(self).unwrap()\n }\n}\nimpl<'a> Words for &'a str {\n fn read(&self) -> T::Output {\n T::read_words(&[self]).unwrap()\n }\n}\n\nfn main() {\n read!(d_a = u32, d_b = u32);\n if d_a == d_b {\n println!(\"{} {}\", d_a*10, d_a*10+1);\n } else if d_b == d_a+1 {\n println!(\"{} {}\", d_a*10+9, d_b*10);\n } else if d_b == 1 && d_a == 9 {\n println!(\"9 10\");\n } else {\n println!(\"-1\");\n }\n}\n", "src_uid": "3eff6f044c028146bea5f0dfd2870d23"} {"source_code": "fn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let size = s.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n let mut c = -1;\n if size.iter().fold(true, |acc, &x| acc && (x==0)) == true {\n c=-1;\n } else {\n for i in 0..=100 {\n if size.iter().map(|x| x-i).sum::() == 0 {\n c = i;\n break;\n }\n }\n }\n println!(\"{}\",c );\n}\n", "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\r\nuse std::{cell::{Cell, RefCell, UnsafeCell}, cmp::{Ordering, Reverse, max, min}, collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, hash_map::{DefaultHasher, RandomState}}, error::Error, fmt::{Display, Write as FmtWrite}, hash::{BuildHasher, Hash, Hasher}, io::{BufWriter, Read, Stdin, Stdout, Write}, iter::{FromIterator, Peekable}, mem::swap, ops::*, process::exit, rc::Rc, str::{FromStr, from_utf8_unchecked}, time::{Duration, Instant}, convert::{TryInto, TryFrom}, marker::PhantomData};\r\n\r\nconst IO_BUF_SIZE: usize = 1 << 16;\r\ntype Input = Scanner;\r\ntype Output = BufWriter;\r\nfn _init_input() -> Input { Scanner::new(std::io::stdin()) }\r\nfn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) }\r\n\r\n#[repr(transparent)] struct Unsync(T);\r\nunsafe impl Sync for Unsync {}\r\n \r\ntype BadLazy = Unsync>>;\r\nimpl BadLazy {\r\n const fn new() -> Self { Self(UnsafeCell::new(None)) }\r\n}\r\n \r\nstatic INPUT: BadLazy = BadLazy::new();\r\nstatic OUTPUT: BadLazy = BadLazy::new();\r\n \r\nfn inp R, R>(f: F) -> R {\r\n unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) }\r\n}\r\nfn out R, R>(f: F) -> R {\r\n unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) }\r\n}\r\n\r\nmacro_rules! read {\r\n () => { read() };\r\n ($t: ty) => { read::<$t>() };\r\n ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) };\r\n [$t: ty; $n: expr] => { read_vec::<$t>($n) };\r\n}\r\nmacro_rules! println { \r\n () => { out(|x| { let _ = writeln!(x); }) };\r\n ($exp: expr) => { out(|x| { let _ = writeln!(x, \"{}\", $exp); }) }; \r\n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = writeln!(x, $fmt, $($arg)*); }) }\r\n}\r\nmacro_rules! print { \r\n ($exp: expr) => { out(|x| { let _ = write!(x, \"{}\", $exp); }) }; \r\n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = write!(x, $fmt, $($arg)*); }) }\r\n}\r\n\r\nfn out_flush() { out(|x| { let _ = x.flush(); }); }\r\n\r\nfn input_is_eof() -> bool { inp(|x| x.eof()) }\r\nfn read_byte() -> u8 { inp(|x| x.byte()) }\r\nfn read_bytes_no_skip(n: usize) -> Vec { inp(|x| x.bytes_no_skip(n)) }\r\nfn read_bytes(n: usize) -> Vec { inp(|x| x.bytes(n)) }\r\nfn read_bytes2(n: usize, m: usize) -> Vec> { inp(|x| x.bytes2(n, m)) }\r\nfn read_token() -> Vec { inp(|x| x.token_bytes()) }\r\nfn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } }\r\nfn read_line() -> Vec { inp(|x| x.line_bytes()) }\r\nfn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } }\r\nfn read() -> T { read_token_str().parse::().ok().expect(\"failed parse\") }\r\nfn read_vec(n: usize) -> Vec { (0..n).map(|_| read()).collect() }\r\nfn read_vec2(n: usize, m: usize) -> Vec> { (0..n).map(|_| read_vec(m)).collect() }\r\n\r\nstruct Scanner {\r\n src: R,\r\n _buf: Vec,\r\n _pt: usize, // pointer\r\n _rd: usize, // bytes read\r\n}\r\n\r\n#[allow(dead_code)]\r\nimpl Scanner {\r\n fn new(src: R) -> Scanner {\r\n Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }\r\n }\r\n \r\n fn _check_buf(&mut self) {\r\n if self._pt == self._rd {\r\n self._rd = self.src.read(&mut self._buf).unwrap_or(0);\r\n self._pt = (self._rd == 0) as usize;\r\n }\r\n }\r\n \r\n // returns true if end of file\r\n fn eof(&mut self) -> bool {\r\n self._check_buf();\r\n self._rd == 0\r\n }\r\n \r\n // filters \\r, returns \\0 if eof\r\n fn byte(&mut self) -> u8 {\r\n loop {\r\n self._check_buf();\r\n if self._rd == 0 { return 0; }\r\n let res = self._buf[self._pt];\r\n self._pt += 1;\r\n if res != b'\\r' { return res; }\r\n }\r\n }\r\n\r\n fn bytes_no_skip(&mut self, n: usize) -> Vec { (0..n).map(|_| self.byte()).collect() }\r\n fn bytes(&mut self, n: usize) -> Vec {\r\n let res = self.bytes_no_skip(n);\r\n self.byte();\r\n res\r\n }\r\n fn bytes2(&mut self, n: usize, m: usize) -> Vec> { (0..n).map(|_| self.bytes(m)).collect() }\r\n \r\n fn token_bytes(&mut self) -> Vec {\r\n let mut res = Vec::new();\r\n let mut c = self.byte();\r\n while c <= b' ' {\r\n if c == b'\\0' { return res; }\r\n c = self.byte();\r\n }\r\n loop {\r\n res.push(c);\r\n c = self.byte();\r\n if c <= b' ' { return res; }\r\n }\r\n }\r\n \r\n fn line_bytes(&mut self) -> Vec {\r\n let mut res = Vec::new();\r\n let mut c = self.byte();\r\n while c != b'\\n' && c != b'\\0' {\r\n res.push(c);\r\n c = self.byte();\r\n }\r\n res\r\n }\r\n}\r\n\r\ntrait JoinToStr { \r\n fn join_to_str(self, sep: &str) -> String;\r\n fn concat_to_str(self) -> String;\r\n}\r\nimpl> JoinToStr for I { \r\n fn join_to_str(mut self, sep: &str) -> String {\r\n match self.next() {\r\n Some(first) => {\r\n let mut res = first.to_string();\r\n while let Some(item) = self.next() {\r\n res.push_str(sep);\r\n res.push_str(&item.to_string());\r\n }\r\n res\r\n }\r\n None => { String::new() }\r\n }\r\n }\r\n \r\n fn concat_to_str(self) -> String {\r\n let mut res = String::new();\r\n for item in self { res.push_str(&item.to_string()); }\r\n res\r\n }\r\n}\r\ntrait AsStr { fn as_str(&self) -> &str; }\r\nimpl AsStr for [u8] { fn as_str(&self) -> &str {std::str::from_utf8(self).expect(\"attempt to convert non-UTF8 byte string.\")} }\r\n\r\nmacro_rules! veci {\r\n ($n:expr , $i:ident : $gen:expr) => {{\r\n let _veci_n = $n;\r\n let mut _veci_list = Vec::with_capacity(_veci_n);\r\n for $i in 0.._veci_n {\r\n _veci_list.push($gen);\r\n }\r\n _veci_list\r\n }};\r\n ($n:expr , $gen:expr) => { veci!($n, _veci_: $gen) }\r\n}\r\n\r\nfn abs_diff + PartialOrd>(x: T, y: T) -> T {\r\n if x < y { y - x } else { x - y }\r\n}\r\n\r\ntrait CommonNumExt {\r\n fn div_ceil(self, b: Self) -> Self;\r\n fn div_floor(self, b: Self) -> Self;\r\n fn gcd(self, b: Self) -> Self;\r\n fn highest_one(self) -> Self;\r\n fn lowest_one(self) -> Self;\r\n fn sig_bits(self) -> u32;\r\n}\r\n\r\nmacro_rules! impl_common_num_ext {\r\n ($($ix:tt = $ux:tt),*) => {\r\n $(\r\n impl CommonNumExt for $ux {\r\n fn div_ceil(self, b: Self) -> Self {\r\n let q = self / b; let r = self % b;\r\n if r != 0 { q + 1 } else { q }\r\n }\r\n fn div_floor(self, b: Self) -> Self { self / b }\r\n fn gcd(self, mut b: Self) -> Self {\r\n let mut a = self;\r\n if a == 0 || b == 0 { return a | b; }\r\n let shift = (a | b).trailing_zeros();\r\n a >>= a.trailing_zeros();\r\n b >>= b.trailing_zeros();\r\n while a != b {\r\n if a > b { a -= b; a >>= a.trailing_zeros(); }\r\n else { b -= a; b >>= b.trailing_zeros(); }\r\n }\r\n a << shift\r\n }\r\n #[inline] fn highest_one(self) -> Self { \r\n if self == 0 { 0 } else { const ONE: $ux = 1; ONE << self.sig_bits() - 1 } \r\n }\r\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\r\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ux>() as u32 * 8 - self.leading_zeros() }\r\n }\r\n\r\n impl CommonNumExt for $ix {\r\n fn div_ceil(self, b: Self) -> Self {\r\n let q = self / b; let r = self % b;\r\n if self ^ b >= 0 && r != 0 { q + 1 } else { q }\r\n }\r\n fn div_floor(self, b: Self) -> Self { \r\n let q = self / b; let r = self % b;\r\n if self ^ b < 0 && r != 0 { q - 1 } else { q }\r\n }\r\n fn gcd(self, b: Self) -> Self {\r\n fn w_abs(x: $ix) -> $ux { (if x.is_negative() { x.wrapping_neg() } else { x }) as _ }\r\n w_abs(self).gcd(w_abs(b)) as _\r\n }\r\n #[inline] fn highest_one(self) -> Self { (self as $ux).highest_one() as _ }\r\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\r\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ix>() as u32 * 8 - self.leading_zeros() }\r\n }\r\n )*\r\n }\r\n}\r\nimpl_common_num_ext!(i8 = u8, i16 = u16, i32 = u32, i64 = u64, i128 = u128, isize = usize);\r\n\r\ntrait ChMaxMin {\r\n fn chmax(&mut self, v: T) -> bool;\r\n fn chmin(&mut self, v: T) -> bool;\r\n}\r\nimpl ChMaxMin for Option {\r\n fn chmax(&mut self, v: T) -> bool { if self.is_none() || v > *self.as_ref().unwrap() { *self = Some(v); true } else { false } }\r\n fn chmin(&mut self, v: T) -> bool { if self.is_none() || v < *self.as_ref().unwrap() { *self = Some(v); true } else { false } }\r\n}\r\nimpl ChMaxMin for T {\r\n fn chmax(&mut self, v: T) -> bool { if v > *self { *self = v; true } else { false } }\r\n fn chmin(&mut self, v: T) -> bool { if v < *self { *self = v; true } else { false } }\r\n}\r\n\r\n// * end commons * //\r\n#[macro_use]\r\n#[allow(dead_code)]\r\nmod modint {\r\n use std::{fmt::{Display, Formatter}, marker::PhantomData, mem::swap, ops::*, str::FromStr, cell::Cell};\r\n use crate::ModInt;\r\n \r\n pub trait RemEuclidU32: Copy {\r\n /// Calculates `self` _mod_ `modulus` losslessly.\r\n fn rem_euclid_u32(self, modulus: u32) -> u32;\r\n }\r\n \r\n macro_rules! impl_rem_euclid_u32_for_small_signed {\r\n ($($ty:tt),*) => {\r\n $(\r\n impl RemEuclidU32 for $ty {\r\n #[inline]\r\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\r\n (self as i64).rem_euclid(i64::from(modulus)) as _\r\n }\r\n }\r\n )*\r\n }\r\n }\r\n \r\n impl_rem_euclid_u32_for_small_signed!(i8, i16, i32, i64, isize);\r\n \r\n impl RemEuclidU32 for i128 {\r\n #[inline]\r\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\r\n self.rem_euclid(i128::from(modulus)) as _\r\n }\r\n }\r\n \r\n macro_rules! impl_rem_euclid_u32_for_small_unsigned {\r\n ($($ty:tt),*) => {\r\n $(\r\n impl RemEuclidU32 for $ty {\r\n #[inline]\r\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\r\n self as u32 % modulus\r\n }\r\n }\r\n )*\r\n }\r\n }\r\n \r\n macro_rules! impl_rem_euclid_u32_for_large_unsigned {\r\n ($($ty:tt),*) => {\r\n $(\r\n impl RemEuclidU32 for $ty {\r\n #[inline]\r\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\r\n (self % (modulus as $ty)) as _\r\n }\r\n }\r\n )*\r\n }\r\n }\r\n \r\n impl_rem_euclid_u32_for_small_unsigned!(u8, u16, u32);\r\n impl_rem_euclid_u32_for_large_unsigned!(u64, u128);\r\n \r\n #[cfg(target_pointer_width = \"32\")]\r\n impl_rem_euclid_u32_for_small_unsigned!(usize);\r\n \r\n #[cfg(target_pointer_width = \"64\")]\r\n impl_rem_euclid_u32_for_large_unsigned!(usize);\r\n #[inline]\r\n pub fn mul_mod_u32(a: u32, b: u32, m: u32) -> u32 {\r\n (a as u64 * b as u64 % m as u64) as u32\r\n }\r\n \r\n // for a, b < m, unspecified otherwise\r\n #[inline]\r\n fn add_mod_raw(a: u32, b: u32, m: u32) -> u32 {\r\n let (r, c) = a.wrapping_sub(m).overflowing_add(b);\r\n if c { r } else { a + b }\r\n }\r\n #[inline]\r\n fn sub_mod_raw(a: u32, b: u32, m: u32) -> u32 {\r\n let (r, c) = a.overflowing_sub(b);\r\n if c { r.wrapping_add(m) } else { r }\r\n }\r\n fn pow_mod_raw(a: u32, mut k: u64, m: u32) -> u32 {\r\n if m == 1 { return 0; }\r\n let mut a = a as u64;\r\n let m = m as u64;\r\n let mut r: u64 = 1;\r\n while k > 0 {\r\n if k & 1 == 1 {\r\n r = r * a % m;\r\n }\r\n k >>= 1;\r\n a = a * a % m;\r\n }\r\n r as u32\r\n }\r\n \r\n /// # Parameters\r\n /// * `b` `1 <= b`\r\n /// # Returns\r\n /// (x, g) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g\r\n fn inv_gcd(a: i64, b: i64) -> (i64, i64) {\r\n let a = a.rem_euclid(b);\r\n if a == 0 { return (0, b); }\r\n let mut s = b;\r\n let mut t = a;\r\n let mut m0 = 0;\r\n let mut m1 = 1;\r\n \r\n while t != 0 {\r\n let u = s / t;\r\n s -= t * u;\r\n m0 -= m1 * u;\r\n swap(&mut s, &mut t);\r\n swap(&mut m0, &mut m1);\r\n }\r\n \r\n if m0 < 0 { m0 += b / s; }\r\n (m0, s)\r\n }\r\n \r\n pub trait Modulus: Copy + Eq {\r\n fn get_modulus() -> u32;\r\n fn mul(a: u32, b: u32) -> u32;\r\n }\r\n \r\n #[derive(Clone, Copy, PartialEq, Eq, Hash)]\r\n #[repr(transparent)]\r\n pub struct ModIntBase { \r\n val: u32,\r\n _phantom: PhantomData\r\n }\r\n \r\n impl ModIntBase {\r\n #[inline(always)]\r\n pub fn modulus() -> u32 { M::get_modulus() }\r\n #[inline] pub fn new(val: I) -> Self { Self::raw(val.rem_euclid_u32(Self::modulus())) }\r\n #[inline] pub fn raw(val: u32) -> Self { Self { val, _phantom: PhantomData } }\r\n pub fn inv(self) -> Self { \r\n let (x, gcd) = inv_gcd(self.val.into(), Self::modulus().into());\r\n debug_assert!(gcd == 1, \"the multiplicative inverse {}^-1 mod {} does not exist\", self.val, Self::modulus());\r\n Self::raw(x as u32)\r\n }\r\n #[inline] pub fn val(self) -> u32 { self.val }\r\n #[inline] pub fn pow(self, k: u64) -> Self {\r\n Self::raw(pow_mod_raw(self.val, k, Self::modulus()))\r\n }\r\n pub fn powi(self, k: i64) -> Self { if k < 0 { self.inv().pow(-k as _) } else { self.pow(k as _) } }\r\n pub fn pow_vec(self, n: usize) -> Vec {\r\n let mut res = vec![Self::raw(0); n+1];\r\n res[0] += 1;\r\n for i in 1..=n {\r\n res[i] = res[i-1] * self;\r\n }\r\n res\r\n }\r\n\r\n pub fn invs(a: &[Self]) -> Vec {\r\n let n = a.len();\r\n if n == 0 { return vec![]; }\r\n let mut acc = Self::new(1);\r\n let mut res = Vec::with_capacity(n);\r\n for i in 0..n {\r\n if a[i].val() != 0 { acc *= a[i]; }\r\n res.push(acc);\r\n }\r\n acc = acc.inv();\r\n for i in (1..n).rev() {\r\n res[i] = acc * res[i-1];\r\n if a[i].val() != 0 { acc *= a[i]; }\r\n }\r\n res[0] = acc;\r\n res\r\n }\r\n }\r\n \r\n #[inline]\r\n pub fn mi(val: I) -> ModInt { ModIntBase::new(val) }\r\n #[inline] pub fn mir(v: u32) -> ModInt { ModIntBase::raw(v) }\r\n \r\n impl From for ModIntBase {\r\n #[inline]\r\n fn from(from: V) -> Self { Self::new(from) }\r\n }\r\n impl Default for ModIntBase {\r\n fn default() -> Self { Self::raw(0) }\r\n }\r\n impl FromStr for ModIntBase {\r\n type Err = std::convert::Infallible;\r\n #[inline]\r\n fn from_str(s: &str) -> Result {\r\n Ok(s.parse::()\r\n .map(Self::new)\r\n .unwrap_or_else(|_| todo!(\"parsing as an arbitrary precision integer?\")))\r\n }\r\n }\r\n impl Display for ModIntBase {\r\n #[inline]\r\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\r\n self.val.fmt(f)\r\n }\r\n }\r\n impl std::fmt::Debug for ModIntBase {\r\n #[inline]\r\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\r\n std::fmt::Debug::fmt(&self.val, f)\r\n }\r\n }\r\n impl Neg for ModIntBase {\r\n type Output = Self;\r\n \r\n #[inline]\r\n fn neg(self) -> Self::Output {\r\n Self::raw(0) - self\r\n }\r\n }\r\n \r\n impl>, M: Modulus> Add for ModIntBase {\r\n type Output = Self;\r\n #[inline]\r\n fn add(self, rhs: V) -> Self::Output {\r\n Self::raw(add_mod_raw(self.val, rhs.into().val, Self::modulus()))\r\n }\r\n }\r\n impl>, M: Modulus> Sub for ModIntBase {\r\n type Output = Self;\r\n #[inline]\r\n fn sub(self, rhs: V) -> Self::Output {\r\n Self::raw(sub_mod_raw(self.val, rhs.into().val, Self::modulus()))\r\n }\r\n }\r\n impl>, M: Modulus> Mul for ModIntBase {\r\n type Output = Self;\r\n #[inline]\r\n fn mul(self, rhs: V) -> Self::Output {\r\n Self::raw(M::mul(self.val, rhs.into().val))\r\n }\r\n }\r\n impl>, M: Modulus> Div for ModIntBase {\r\n type Output = Self;\r\n #[inline]\r\n fn div(self, rhs: V) -> Self::Output { self * rhs.into().inv() }\r\n }\r\n \r\n impl >, M: Modulus> AddAssign for ModIntBase {\r\n #[inline]\r\n fn add_assign(&mut self, rhs: V) { *self = *self + rhs; }\r\n }\r\n impl >, M: Modulus> SubAssign for ModIntBase {\r\n #[inline]\r\n fn sub_assign(&mut self, rhs: V) { *self = *self - rhs; }\r\n }\r\n impl >, M: Modulus> MulAssign for ModIntBase {\r\n #[inline]\r\n fn mul_assign(&mut self, rhs: V) { *self = *self * rhs; }\r\n }\r\n impl >, M: Modulus> DivAssign for ModIntBase {\r\n #[inline]\r\n fn div_assign(&mut self, rhs: V) { *self = *self / rhs; }\r\n }\r\n \r\n impl std::iter::Sum for ModIntBase {\r\n #[inline] fn sum>(iter: I) -> Self {\r\n iter.fold(Self::raw(0), Add::add)\r\n }\r\n }\r\n impl std::iter::Product for ModIntBase {\r\n #[inline] fn product>(iter: I) -> Self {\r\n iter.fold(1.into(), Mul::mul)\r\n }\r\n }\r\n impl<'a, M: Modulus> std::iter::Sum<&'a Self> for ModIntBase {\r\n #[inline] fn sum>(iter: I) -> ModIntBase {\r\n iter.fold(Self::raw(0), |a, &b| a + b)\r\n }\r\n }\r\n impl<'a, M: Modulus> std::iter::Product<&'a Self> for ModIntBase {\r\n #[inline] fn product>(iter: I) -> ModIntBase {\r\n iter.fold(1.into(), |a, &b| a * b)\r\n }\r\n }\r\n \r\n macro_rules! const_modulus {\r\n ($mint: ident, $name: ident, $modulus: expr) => {\r\n #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\r\n pub enum $name {}\r\n impl Modulus for $name {\r\n #[inline(always)] fn get_modulus() -> u32 { $modulus }\r\n fn mul(a: u32, b: u32) -> u32 { \r\n mul_mod_u32(a, b, Self::get_modulus())\r\n }\r\n }\r\n pub type $mint = ModIntBase<$name>;\r\n }\r\n }\r\n\r\n #[derive(Debug, Clone, Copy)]\r\n pub struct ModulusCalc {\r\n pub modulus: u32,\r\n pub inv: u64\r\n }\r\n \r\n macro_rules! dynamic_modulus {\r\n ($mint: ident, $name: ident, $modulus: ident) => {\r\n static $modulus: crate::Unsync> = crate::Unsync(Cell::new(ModulusCalc { modulus: 0, inv: 0 }));\r\n #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\r\n pub enum $name {}\r\n impl Modulus for $name {\r\n fn get_modulus() -> u32 { $modulus.0.get().modulus }\r\n fn mul(a: u32, b: u32) -> u32 {\r\n let ModulusCalc { modulus, inv } = $modulus.0.get();\r\n let p = a as u64 * b as u64;\r\n let g = ((p as u128 * inv as u128) >> 64) as u64;\r\n let (r, c) = p.overflowing_sub(g * modulus as u64);\r\n if c { (r as u32).wrapping_add(modulus) } else { r as u32 }\r\n }\r\n }\r\n impl $name {\r\n pub fn set_modulus(val: u32) { \r\n let inv = (1u64.wrapping_neg() / val as u64).wrapping_add(1);\r\n $modulus.0.set(ModulusCalc { modulus: val, inv })\r\n }\r\n }\r\n pub type $mint = ModIntBase<$name>;\r\n }\r\n }\r\n \r\n const_modulus!(ModInt998_244_353, Mod998_244_353, 998_244_353);\r\n const_modulus!(ModInt1_000_000_007, Mod1_000_000_007, 1_000_000_007);\r\n dynamic_modulus!(DynamicModInt, DynamicModulus, DYNAMIC_MODULUS);\r\n}\r\n \r\nuse crate::modint::*;\r\ntype ModInt = ModInt998_244_353;\r\n// type ModInt = ModInt1_000_000_007;\r\n// const_modulus!(ModInt, DefaultModulus, 1_000_000_009);\r\n// type ModInt = DynamicModInt;\r\n\r\npub struct ModFft {\r\n n_inv: ModInt,\r\n w: Vec\r\n}\r\nimpl ModFft {\r\n pub fn primitive_root() -> ModInt { ModInt::raw(3) /* for 998244353 */}\r\n pub fn good_len(deg: usize) -> usize { (deg + 1).next_power_of_two() }\r\n pub fn prepare(arr: &[ModInt], deg: usize) -> Vec { \r\n let n = Self::good_len(deg);\r\n let mut res = Vec::with_capacity(n);\r\n res.extend_from_slice(arr);\r\n res.resize(n, ModInt::raw(0));\r\n res\r\n }\r\n\r\n pub fn new(max_deg: usize) -> Self {\r\n let n = Self::good_len(max_deg);\r\n Self {\r\n n_inv: ModInt::new(n).inv(),\r\n w: ModInt::pow_vec(Self::primitive_root().pow((ModInt::modulus() - 1) as u64 / n as u64), n-1)\r\n }\r\n }\r\n\r\n pub fn transform(&self, a: &mut [ModInt]) { self.transform_impl(a, false) }\r\n pub fn transform_inv(&self, a: &mut [ModInt]) { self.transform_impl(a, true) }\r\n\r\n pub fn fft(&self, a: &[ModInt]) -> Vec { self.fft_deg(a, a.len() - 1) }\r\n pub fn fft_deg(&self, a: &[ModInt], deg: usize) -> Vec { \r\n let mut a = Self::prepare(a, deg);\r\n self.transform(&mut a);\r\n a\r\n }\r\n pub fn fft_inv(&self, a: &[ModInt]) -> Vec { \r\n let mut a = Self::prepare(a, a.len() - 1);\r\n self.transform_inv(&mut a);\r\n a\r\n }\r\n\r\n pub fn max_deg(&self) -> usize { self.w.len() - 1 }\r\n\r\n #[inline] fn transform_impl(&self, a: &mut [ModInt], invert: bool) {\r\n let sz = a.len();\r\n if sz <= 1 { return }\r\n let n = self.w.len();\r\n debug_assert!(sz <= n && sz.is_power_of_two(), \"Array size {} must be <= {} and a power of 2\", sz, n);\r\n let sh = sz.leading_zeros() + 1;\r\n\r\n for i in 0..sz {\r\n let j = i.reverse_bits() >> sh;\r\n if i < j { a.swap(i, j) }\r\n }\r\n\r\n let mut len = 2usize;\r\n let mut ang = (n >> 1) as isize;\r\n if invert { ang = -ang; }\r\n while len <= sz {\r\n let h = len >> 1;\r\n for i in (0..sz).step_by(len) {\r\n let mut k = 0usize;\r\n for j in i..i+h {\r\n let u = a[j];\r\n let v = a[j+h] * self.w[k];\r\n a[j] = u + v;\r\n a[j+h] = u - v;\r\n k = k.wrapping_add(ang as usize) & (n-1);\r\n }\r\n }\r\n len <<= 1;\r\n ang >>= 1;\r\n }\r\n\r\n if invert {\r\n let sz_inv = self.n_inv * (n / sz);\r\n for i in 0..sz { a[i] *= sz_inv; }\r\n }\r\n }\r\n\r\n const NAIVE_THRESHOLD: usize = 60;\r\n fn naive_mul(a: &[ModInt], b: &[ModInt]) -> Vec {\r\n let n = a.len();\r\n let m = b.len();\r\n let mut ans = vec![ModInt::raw(0); n + m - 1];\r\n for i in 0..n { for j in 0..m {\r\n ans[i + j] += a[i] * b[j];\r\n }}\r\n ans\r\n }\r\n\r\n pub fn mul(&self, a: &[ModInt], b: &[ModInt]) -> Vec {\r\n if a.is_empty() || b.is_empty() { return vec![]; }\r\n let deg = a.len() + b.len() - 2;\r\n debug_assert!(deg < self.w.len(), \"FFT capacity {} too small for polynomial of degree {}\", self.w.len(), deg);\r\n if min(a.len(), b.len()) <= Self::NAIVE_THRESHOLD { return Self::naive_mul(a, b); }\r\n let mut a = Self::prepare(a, deg);\r\n let mut b = Self::prepare(b, deg);\r\n self.transform(&mut a);\r\n self.transform(&mut b);\r\n for i in 0..a.len() { a[i] *= b[i]; }\r\n self.transform_inv(&mut a);\r\n a.truncate(deg + 1);\r\n a\r\n }\r\n\r\n pub fn sq(&self, a: &[ModInt]) -> Vec {\r\n if a.is_empty() { return vec![]; }\r\n let deg = a.len() * 2 - 2;\r\n debug_assert!(deg < self.w.len(), \"FFT capacity {} too small for polynomial of degree {}\", self.w.len(), deg);\r\n if a.len() <= Self::NAIVE_THRESHOLD { return Self::naive_mul(a, a); }\r\n let mut a = Self::prepare(a, deg);\r\n self.transform(&mut a);\r\n for i in 0..a.len() { let ai = a[i]; a[i] = ai * ai; }\r\n self.transform_inv(&mut a);\r\n a.truncate(deg + 1);\r\n a\r\n }\r\n\r\n pub fn pow(&self, a: &[ModInt], exp: usize) -> Vec {\r\n if a.is_empty() { return vec![]; }\r\n let deg = (a.len() - 1) * exp;\r\n debug_assert!(deg < self.w.len(), \"FFT capacity {} too small for polynomial of degree {}\", self.w.len(), deg);\r\n let mut a = Self::prepare(a, deg);\r\n self.transform(&mut a);\r\n for i in 0..a.len() { a[i] = a[i].pow(exp as u64) }\r\n self.transform_inv(&mut a);\r\n a.truncate(deg + 1);\r\n a\r\n }\r\n\r\n pub fn product(&self, mut polys: VecDeque>) -> Vec {\r\n while let Some(p) = polys.pop_front() {\r\n if let Some(q) = polys.pop_front() {\r\n polys.push_back(self.mul(&p, &q));\r\n } else { return p; }\r\n }\r\n\r\n vec![ModInt::new(1)]\r\n }\r\n}\r\n\r\n#[allow(non_snake_case, non_upper_case_globals)]\r\nfn main() {\r\n let num_cases: usize = 1;//read();\r\n \r\n for _case_num in 1..=num_cases {\r\n let n = read!(usize);\r\n\t\tlet k = read!(usize);\r\n\t\tlet f = read!(usize);\r\n\t\t\r\n\t\tlet ff = ModFft::new(2*k);\r\n\t\tlet mut dp = vec![mi(1); k+1];\r\n\t\tfor _ in 1..n {\r\n\t\t\tlet sq = ff.sq(&dp);\r\n\t\t\tlet mut sm = sq[k+1..].iter().sum::();\r\n\t\t\tfor i in (0..=k).rev() {\r\n\t\t\t\tdp[i] = sq[i] * (k + 1 - i) + sm;\r\n\t\t\t\tsm += sq[i];\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tdp.resize(f+1, mi(0));\r\n\t\tlet ans = (0..=f).map(|i| dp[i] * dp[f-i]).sum::();\r\n\t\tprintln!(ans);\r\n }\r\n \r\n out_flush();\r\n}", "src_uid": "4b8161259545e44c7d1046be2e4fe014"} {"source_code": "use std::collections::VecDeque;\nuse std::io::{self, Write};\nuse std::str::FromStr;\nuse core::cmp::min;\nuse core::cmp::max;\n \nstruct Scanner {\n stdin: io::Stdin,\n buffer: VecDeque,\n}\n \nimpl Scanner {\n fn new() -> Self {\n Scanner {\n stdin: io::stdin(),\n buffer: VecDeque::new(),\n }\n } \n \n fn cin(&mut self) -> T {\n while self.buffer.is_empty() {\n let mut line = String::new();\n let _ = self.stdin.read_line(&mut line);\n for w in line.split_whitespace() {\n self.buffer.push_back(String::from(w));\n }\n }\n self.buffer.pop_front().unwrap().parse::().ok().unwrap()\n }\n}\n\nfn main() {\n let mut sc = Scanner::new();\n let n: u32 = sc.cin();\n let (mut a1, mut b1, mut c1): (u32, u32, u32) = (sc.cin(), sc.cin(), sc.cin());\n let (mut a2, mut b2, mut c2): (u32, u32, u32) = (sc.cin(), sc.cin(), sc.cin());\n let mut ans = n;\n let res = min(a1, b2) + min(b1, c2) + min(c1, a2);\n if a2 >= a1 + b1 || b2 >= b1 + c1 || c2 >= c1 + a1 {\n if a2 >= a1 + b1 {\n ans = min(ans, a2 - a1 - b1);\n }\n if b2 >= b1 + c1 {\n ans = min(ans, b2 - b1 - c1);\n }\n if c2 >= c1 + a1 {\n ans = min(ans, c2 - c1 - a1);\n }\n ans = max(ans, 0);\n print!(\"{}\", ans);\n } else {\n print!(\"0\");\n }\n println!(\" {}\", res);\n}", "src_uid": "e6dc3bc64fc66b6127e2b32cacc06402"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nfn get_pair() -> (i32, i32) {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input).expect(\"\");\n\n let v = input\n .trim()\n .split_whitespace()\n .map(|s| i32::from_str(s).unwrap())\n .collect::>();\n\n (v[0], v[1])\n}\n\nfn main() {\n let (n, m) = get_pair();\n\n let mut c = 0;\n for a in 0..=1000 {\n for b in 0..=100 {\n if a * a + b == n && a + b * b == m {\n c += 1;\n }\n }\n }\n\n println!(\"{}\", c);\n}\n", "src_uid": "03caf4ddf07c1783e42e9f9085cc6efd"} {"source_code": "fn main() {\n let n: u32 = get_input().parse().unwrap();\n let v= get_fib(n);\n println!(\"{} {} {}\", v.2, v.1, v.0);\n \n}\n\nfn get_input() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Failed\");\n buffer.trim().to_owned()\n}\n\nfn get_input_usize() -> usize {\n get_input().parse().unwrap()\n}\n\nfn get_fib(n: u32) -> (u32, u32, u32) {\n if n == 3 {\n (1,1,1)\n } else {\n let mut prev = 0;\n let mut curr = 1;\n let mut vec = vec![0, 0, 0, 0, 1];\n\n while curr <= n {\n vec.push(curr);\n let temp = prev;\n prev = curr;\n curr = curr + temp;\n \n }\n\n let len = vec.len();\n (vec[len - 2], vec[len - 4], vec[len - 5])\n }\n}", "src_uid": "db46a6b0380df047aa34ea6a8f0f93c1"} {"source_code": "// ---------- begin Matrix ----------\r\nmod matrix {\r\n use std::ops::*;\r\n pub trait SemiRing: Add + Mul + Copy {\r\n fn zero() -> Self;\r\n fn one() -> Self;\r\n }\r\n pub trait Inverse: SemiRing {\r\n fn is_zero() -> bool;\r\n fn inv(self) -> Self;\r\n }\r\n #[derive(Clone)]\r\n pub struct SquareMatrix {\r\n size: usize,\r\n buf: Box<[R]>,\r\n }\r\n #[allow(dead_code)]\r\n impl SquareMatrix {\r\n pub fn zero(size: usize) -> Self {\r\n SquareMatrix {\r\n size: size,\r\n buf: vec![R::zero(); size * size].into_boxed_slice(),\r\n }\r\n }\r\n pub fn identity(size: usize) -> Self {\r\n let mut e = Self::zero(size);\r\n for i in 0..size {\r\n e.buf[i * size + i] = R::one();\r\n }\r\n e\r\n }\r\n pub fn set_at(&mut self, x: usize, y: usize, val: R) {\r\n assert!(x < self.size && y < self.size);\r\n self.buf[x * self.size + y] = val;\r\n }\r\n pub fn get_at(&self, x: usize, y: usize) -> R {\r\n assert!(x < self.size && y < self.size);\r\n self.buf[x * self.size + y]\r\n }\r\n pub fn get_mut(&mut self, x: usize, y: usize) -> &mut R {\r\n assert!(x < self.size && y < self.size);\r\n &mut self.buf[x * self.size + y]\r\n }\r\n pub fn matadd(&self, rhs: &Self) -> Self {\r\n assert!(self.size == rhs.size);\r\n let buf: Vec = self\r\n .buf\r\n .iter()\r\n .zip(rhs.buf.iter())\r\n .map(|p| *p.0 + *p.1)\r\n .collect();\r\n SquareMatrix {\r\n size: self.size,\r\n buf: buf.into_boxed_slice(),\r\n }\r\n }\r\n pub fn matmul(&self, rhs: &Self) -> Self {\r\n let size = self.size;\r\n assert!(size == rhs.size);\r\n let mut res = Self::zero(size);\r\n for (x, a) in res.buf.chunks_mut(size).zip(self.buf.chunks(size)) {\r\n for (a, b) in a.iter().zip(rhs.buf.chunks(size)) {\r\n for (x, b) in x.iter_mut().zip(b.iter()) {\r\n *x = *x + *a * *b;\r\n }\r\n }\r\n }\r\n res\r\n }\r\n pub fn mat_pow(&self, mut n: usize) -> Self {\r\n let size = self.size;\r\n let mut t = Self::identity(size);\r\n let mut s = self.clone();\r\n while n > 0 {\r\n if n & 1 == 1 {\r\n t = t.matmul(&s);\r\n }\r\n s = s.matmul(&s);\r\n n >>= 1;\r\n }\r\n t\r\n }\r\n }\r\n #[allow(dead_code)]\r\n impl> SquareMatrix {\r\n pub fn matsub(&self, rhs: &Self) -> Self {\r\n assert!(self.size == rhs.size);\r\n let buf: Vec = self\r\n .buf\r\n .iter()\r\n .zip(rhs.buf.iter())\r\n .map(|p| *p.0 - *p.1)\r\n .collect();\r\n SquareMatrix {\r\n size: self.size,\r\n buf: buf.into_boxed_slice(),\r\n }\r\n }\r\n }\r\n /*\r\n #[allow(dead_code)]\r\n impl> SquareMatrix {\r\n pub fn inverse(&self) -> Self {\r\n }\r\n }\r\n */\r\n}\r\n// ---------- end Matrix ----------\r\n// ---------- begin ModInt ----------\r\n// \u30e2\u30f3\u30b4\u30e1\u30ea\u4e57\u7b97\u3092\u7528\u3044\u308b\r\n// \u307b\u307cCodeforces\u7528\r\n// \u6ce8\u610f\r\n// new_unchecked \u306f\u5024x\u304c 0 <= x < modulo \u3067\u3042\u308b\u3053\u3068\u3092\u4eee\u5b9a\r\n// ModInt \u306e\u4e2d\u8eab\u306f\u6b63\u898f\u5316\u3055\u308c\u305f\u5024\u3067\u6301\u3063\u3066\u308b\u306e\u3067\u76f4\u63a5\u8aad\u3093\u3060\u308a\u66f8\u3044\u305f\u308a\u3059\u308b\u3068\u3076\u3063\u58ca\u308c\u308b\r\n// \u5947\u7d20\u6570\u306e\u307f\r\nmod modint {\r\n\r\n use std::marker::*;\r\n use std::ops::*;\r\n\r\n pub trait Modulo {\r\n fn modulo() -> u32;\r\n fn rem() -> u32;\r\n fn ini() -> u64;\r\n fn reduce(x: u64) -> u32 {\r\n assert!(x < (Self::modulo() as u64) << 32);\r\n let b = (x as u32 * Self::rem()) as u64;\r\n let t = x + b * Self::modulo() as u64;\r\n let mut c = (t >> 32) as u32;\r\n if c >= Self::modulo() {\r\n c -= Self::modulo();\r\n }\r\n c as u32\r\n }\r\n }\r\n\r\n #[allow(dead_code)]\r\n pub enum Mod1_000_000_007 {}\r\n\r\n impl Modulo for Mod1_000_000_007 {\r\n fn modulo() -> u32 {\r\n 1_000_000_007\r\n }\r\n fn rem() -> u32 {\r\n 2226617417\r\n }\r\n fn ini() -> u64 {\r\n 582344008\r\n }\r\n }\r\n\r\n #[allow(dead_code)]\r\n pub enum Mod998_244_353 {}\r\n\r\n impl Modulo for Mod998_244_353 {\r\n fn modulo() -> u32 {\r\n 998_244_353\r\n }\r\n fn rem() -> u32 {\r\n 998244351\r\n }\r\n fn ini() -> u64 {\r\n 932051910\r\n }\r\n }\r\n\r\n #[allow(dead_code)]\r\n pub fn generate_umekomi_modulo(p: u32) {\r\n assert!(\r\n p < (1 << 31)\r\n && p > 2\r\n && p & 1 == 1\r\n && (2u32..).take_while(|v| v * v <= p).all(|k| p % k != 0)\r\n );\r\n let mut t = 1u32;\r\n let mut s = !p + 1;\r\n let mut n = !0u32 >> 2;\r\n while n > 0 {\r\n if n & 1 == 1 {\r\n t *= s;\r\n }\r\n s *= s;\r\n n >>= 1;\r\n }\r\n let mut ini = (1u64 << 32) % p as u64;\r\n ini = (ini << 32) % p as u64;\r\n assert!(t * p == !0);\r\n println!(\"pub enum Mod{} {{}}\", p);\r\n println!(\"impl Modulo for Mod{} {{\", p);\r\n println!(\" fn modulo() -> u32 {{\");\r\n println!(\" {}\", p);\r\n println!(\" }}\");\r\n println!(\" fn rem() -> u32 {{\");\r\n println!(\" {}\", t);\r\n println!(\" }}\");\r\n println!(\" fn ini() -> u32 {{\");\r\n println!(\" {}\", ini);\r\n println!(\" }}\");\r\n println!(\"}}\");\r\n let mut f = vec![];\r\n let mut n = p - 1;\r\n for i in 2.. {\r\n if i * i > n {\r\n break;\r\n }\r\n if n % i == 0 {\r\n f.push(i);\r\n while n % i == 0 {\r\n n /= i;\r\n }\r\n }\r\n }\r\n if n > 1 {\r\n f.push(n);\r\n }\r\n let mut order = 1;\r\n let mut n = p - 1;\r\n while n % 2 == 0 {\r\n n /= 2;\r\n order <<= 1;\r\n }\r\n let z = (2u64..)\r\n .find(|z| {\r\n f.iter()\r\n .all(|f| mod_pow(*z, ((p - 1) / *f) as u64, p as u64) != 1)\r\n })\r\n .unwrap();\r\n let zeta = mod_pow(z, ((p - 1) / order) as u64, p as u64);\r\n println!(\"impl transform::NTTFriendly for Mod{} {{\", p);\r\n println!(\" fn order() -> usize {{\");\r\n println!(\" {}\", order);\r\n println!(\" }}\");\r\n println!(\" fn zeta() -> u32 {{\");\r\n println!(\" {}\", zeta);\r\n println!(\" }}\");\r\n println!(\"}}\");\r\n }\r\n\r\n pub struct ModInt(u32, PhantomData);\r\n\r\n impl Clone for ModInt {\r\n fn clone(&self) -> Self {\r\n ModInt::build(self.0)\r\n }\r\n }\r\n\r\n impl Copy for ModInt {}\r\n\r\n impl Add for ModInt {\r\n type Output = ModInt;\r\n fn add(self, rhs: Self) -> Self::Output {\r\n let mut d = self.0 + rhs.0;\r\n if d >= T::modulo() {\r\n d -= T::modulo();\r\n }\r\n Self::build(d)\r\n }\r\n }\r\n\r\n impl AddAssign for ModInt {\r\n fn add_assign(&mut self, rhs: Self) {\r\n *self = *self + rhs;\r\n }\r\n }\r\n\r\n impl Sub for ModInt {\r\n type Output = ModInt;\r\n fn sub(self, rhs: Self) -> Self::Output {\r\n let mut d = T::modulo() + self.0 - rhs.0;\r\n if d >= T::modulo() {\r\n d -= T::modulo();\r\n }\r\n Self::build(d)\r\n }\r\n }\r\n\r\n impl SubAssign for ModInt {\r\n fn sub_assign(&mut self, rhs: Self) {\r\n *self = *self - rhs;\r\n }\r\n }\r\n\r\n impl Mul for ModInt {\r\n type Output = ModInt;\r\n fn mul(self, rhs: Self) -> Self::Output {\r\n Self::build(T::reduce(self.0 as u64 * rhs.0 as u64))\r\n }\r\n }\r\n\r\n impl MulAssign for ModInt {\r\n fn mul_assign(&mut self, rhs: Self) {\r\n *self = *self * rhs;\r\n }\r\n }\r\n\r\n impl Neg for ModInt {\r\n type Output = ModInt;\r\n fn neg(self) -> Self::Output {\r\n if self.0 == 0 {\r\n Self::zero()\r\n } else {\r\n Self::build(T::modulo() - self.0)\r\n }\r\n }\r\n }\r\n\r\n impl std::fmt::Display for ModInt {\r\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\r\n write!(f, \"{}\", self.get())\r\n }\r\n }\r\n\r\n impl std::fmt::Debug for ModInt {\r\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\r\n write!(f, \"{}\", self.get())\r\n }\r\n }\r\n\r\n impl std::str::FromStr for ModInt {\r\n type Err = std::num::ParseIntError;\r\n fn from_str(s: &str) -> Result {\r\n let val = s.parse::()?;\r\n Ok(ModInt::new(val))\r\n }\r\n }\r\n\r\n impl From for ModInt {\r\n fn from(val: usize) -> ModInt {\r\n ModInt::new_unchecked((val % T::modulo() as usize) as u32)\r\n }\r\n }\r\n\r\n impl From for ModInt {\r\n fn from(val: u64) -> ModInt {\r\n ModInt::new_unchecked((val % T::modulo() as u64) as u32)\r\n }\r\n }\r\n\r\n impl From for ModInt {\r\n fn from(val: i64) -> ModInt {\r\n let m = T::modulo() as i64;\r\n ModInt::new((val % m + m) as u32)\r\n }\r\n }\r\n\r\n #[allow(dead_code)]\r\n impl ModInt {\r\n fn build(d: u32) -> Self {\r\n ModInt(d, PhantomData)\r\n }\r\n pub fn zero() -> Self {\r\n Self::build(0)\r\n }\r\n pub fn is_zero(&self) -> bool {\r\n self.0 == 0\r\n }\r\n }\r\n\r\n #[allow(dead_code)]\r\n impl ModInt {\r\n pub fn new_unchecked(d: u32) -> Self {\r\n Self::build(T::reduce(d as u64 * T::ini()))\r\n }\r\n pub fn new(d: u32) -> Self {\r\n Self::new_unchecked(d % T::modulo())\r\n }\r\n pub fn one() -> Self {\r\n Self::new_unchecked(1)\r\n }\r\n pub fn get(&self) -> u32 {\r\n T::reduce(self.0 as u64)\r\n }\r\n pub fn pow(&self, mut n: u64) -> Self {\r\n let mut t = Self::one();\r\n let mut s = *self;\r\n while n > 0 {\r\n if n & 1 == 1 {\r\n t *= s;\r\n }\r\n s *= s;\r\n n >>= 1;\r\n }\r\n t\r\n }\r\n pub fn inv(&self) -> Self {\r\n assert!(!self.is_zero());\r\n self.pow((T::modulo() - 2) as u64)\r\n }\r\n }\r\n\r\n pub fn mod_pow(mut r: u64, mut n: u64, m: u64) -> u64 {\r\n let mut t = 1 % m;\r\n while n > 0 {\r\n if n & 1 == 1 {\r\n t = t * r % m;\r\n }\r\n r = r * r % m;\r\n n >>= 1;\r\n }\r\n t\r\n }\r\n}\r\n// ---------- end ModInt ----------\r\n\r\nuse modint::*;\r\n\r\ntype M = ModInt;\r\n\r\n// ---------- begin input macro ----------\r\n// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\r\nmacro_rules! input {\r\n (source = $s:expr, $($r:tt)*) => {\r\n let mut iter = $s.split_whitespace();\r\n input_inner!{iter, $($r)*}\r\n };\r\n ($($r:tt)*) => {\r\n let s = {\r\n use std::io::Read;\r\n let mut s = String::new();\r\n std::io::stdin().read_to_string(&mut s).unwrap();\r\n s\r\n };\r\n let mut iter = s.split_whitespace();\r\n input_inner!{iter, $($r)*}\r\n };\r\n}\r\n\r\nmacro_rules! input_inner {\r\n ($iter:expr) => {};\r\n ($iter:expr, ) => {};\r\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\r\n let $var = read_value!($iter, $t);\r\n input_inner!{$iter $($r)*}\r\n };\r\n}\r\n\r\nmacro_rules! read_value {\r\n ($iter:expr, ( $($t:tt),* )) => {\r\n ( $(read_value!($iter, $t)),* )\r\n };\r\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\r\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\r\n };\r\n ($iter:expr, chars) => {\r\n read_value!($iter, String).chars().collect::>()\r\n };\r\n ($iter:expr, bytes) => {\r\n read_value!($iter, String).bytes().collect::>()\r\n };\r\n ($iter:expr, usize1) => {\r\n read_value!($iter, usize) - 1\r\n };\r\n ($iter:expr, $t:ty) => {\r\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\r\n };\r\n}\r\n// ---------- end input macro ----------\r\n\r\n// \u884c\u5217\u7d2f\u4e57\u3063\u307d\u3044\u304c\u72b6\u614b\u6570\u53b3\u3057\u3052\u3067\u306f...\r\n\r\nuse matrix::*;\r\ntype Mat = SquareMatrix;\r\n\r\nimpl SemiRing for M {\r\n fn zero() -> Self {\r\n M::zero()\r\n }\r\n fn one() -> Self {\r\n M::one()\r\n }\r\n}\r\n\r\nfn lcp(x: &[u8], y: &[u8]) -> usize {\r\n x.iter().zip(y).take_while(|p| *p.0 == *p.1).count()\r\n}\r\n\r\nfn run() {\r\n input! {\r\n n: usize,\r\n m: usize,\r\n s: [bytes; n],\r\n }\r\n let mut id = 0;\r\n let mut map = std::collections::BTreeMap::new();\r\n for s in s.iter() {\r\n for i in 0..s.len() {\r\n let s = s[i..].iter().cloned().collect::>();\r\n map.entry(s).or_insert_with(|| {\r\n let v = id;\r\n id += 1;\r\n v\r\n });\r\n }\r\n }\r\n map.insert(vec![], id);\r\n id += 1;\r\n let mut edge = vec![];\r\n for (x, &src) in map.iter() {\r\n if x.is_empty() {\r\n for a in s.iter() {\r\n for b in s.iter() {\r\n let len = lcp(a, b);\r\n let a = a[len..].iter().cloned().collect::>();\r\n let b = b[len..].iter().cloned().collect::>();\r\n if !a.is_empty() && !b.is_empty() {\r\n continue;\r\n }\r\n let mut pre = src;\r\n for _ in 1..len {\r\n edge.push((pre, id));\r\n pre = id;\r\n id += 1;\r\n }\r\n if a.is_empty() {\r\n let dst = *map.get(&b).unwrap();\r\n edge.push((pre, dst));\r\n } else if b.is_empty() {\r\n let dst = *map.get(&a).unwrap();\r\n edge.push((pre, dst));\r\n }\r\n }\r\n }\r\n } else {\r\n for a in s.iter() {\r\n let len = lcp(a, x);\r\n let a = a[len..].iter().cloned().collect::>();\r\n let b = x[len..].iter().cloned().collect::>();\r\n if !a.is_empty() && !b.is_empty() {\r\n continue;\r\n }\r\n let mut pre = src;\r\n for _ in 1..len {\r\n edge.push((pre, id));\r\n pre = id;\r\n id += 1;\r\n }\r\n if a.is_empty() {\r\n let dst = *map.get(&b).unwrap();\r\n edge.push((pre, dst));\r\n } else if b.is_empty() {\r\n let dst = *map.get(&a).unwrap();\r\n edge.push((pre, dst));\r\n }\r\n }\r\n }\r\n }\r\n let mut mat = Mat::zero(id);\r\n for &(a, b) in edge.iter() {\r\n *mat.get_mut(a, b) += M::one();\r\n }\r\n let pow = mat.mat_pow(m);\r\n let v = *map.get(&vec![]).unwrap();\r\n let ans = pow.get_at(v, v);\r\n println!(\"{}\", ans);\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n", "src_uid": "711d15e11016d0164fb2b0c3756e4857"} {"source_code": "use std::io::{self, Write};\n\nfn gcd(a: usize, b: usize) -> usize {\n if b == 0 {a} else {gcd(b, a % b)}\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut sc = cf_scanner::Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n\n for _ in 0..sc.next() {\n let x: usize = sc.next();\n let y = 100 - x;\n let z = gcd(x, y);\n writeln!(out, \"{}\", x / z + y / z).unwrap();\n }\n}\n\n#[allow(dead_code)]\nmod cf_scanner {\n use std::io;\n use std::str::{FromStr, SplitAsciiWhitespace};\n\n pub struct Scanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n }\n\n impl Scanner {\n pub fn new(reader: R) -> Scanner {\n Scanner {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = std::str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n\n pub fn next_vec(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next()).collect()\n }\n\n pub fn next_str(&mut self) -> Vec {\n self.next::().chars().collect()\n }\n }\n}\n", "src_uid": "19a2bcb727510c729efe442a13c2ff7c"} {"source_code": "use std::io;\n\nfn main () {\n // read\n let mut s = String::new();\n io::stdin().read_line(&mut s);\n\n let int_vec: Vec =s.trim()\n .split(\" \")\n .map(|x|{\n x.parse::().expect(\"not an integer\")\n })\n .collect();\n\n let mut a :f64 = int_vec[0];\n let mut b : f64 = int_vec[1];\n let mut m : f64 = int_vec[2];\n\n let mut lado_a = (a/m).ceil();\n let mut lado_b = (b/m).ceil();\n\n println!(\"{}\",lado_a*lado_b);\n\n}", "src_uid": "ef971874d8c4da37581336284b688517"} {"source_code": "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 ) *} } ;}\nmacro_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 ) *} } ;}\nmacro_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 ::>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect (\"Parse error\" ) } ;}\ntrait Monoid {\n fn id() -> Self;\n fn f(a: Self, b: Self) -> Self;\n}\n#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]\nenum MaxInt {\n Minimal,\n Val(i64),\n}\nimpl std::ops::Mul for MaxInt {\n type Output = Self;\n fn mul(self, other: Self) -> Self {\n if self > other {\n self\n } else {\n other\n }\n }\n}\nimpl MaxInt {\n fn unwrap(self) -> i64 {\n if let Self::Val(x) = self {\n x\n } else {\n panic!();\n }\n }\n fn map(self, f: F) -> Self\n where\n F: Fn(i64) -> i64,\n {\n if let Self::Val(x) = self {\n Self::Val(f(x))\n } else {\n Self::Minimal\n }\n }\n}\nimpl Monoid for MaxInt {\n fn id() -> Self {\n MaxInt::Minimal\n }\n fn f(a: Self, b: Self) -> Self {\n a * b\n }\n}\nuse MaxInt::*;\n\nfn main() {\n input! {\n n: usize,\n k: usize,\n s: String,\n t: String,\n }\n let s = s.chars().map(|c| c as u8).collect::>();\n let t = t.chars().map(|c| c as u8).collect::>();\n if t[0] == t[1] {\n let mut ans = 0;\n let mut c = 0;\n let mut k = k;\n for i in 0..n {\n if k != 0 && s[i] != t[0] {\n ans += c;\n c += 1;\n k -= 1;\n }\n if s[i] == t[0] {\n ans += c;\n c += 1;\n }\n }\n println!(\"{}\", ans);\n return;\n }\n if k == 0 {\n let mut ans = 0;\n let mut c = 0;\n for i in 0..n {\n if s[i] == t[0] {\n c += 1;\n }\n if s[i] == t[1] {\n ans += c;\n }\n }\n println!(\"{}\", ans);\n return;\n }\n\n let mut dp = vec![vec![vec![Minimal; n + 1]; k + 2]; n + 1];\n dp[0][0][0] = Val(0);\n for i in 0..n {\n for k in 0..=k {\n for c in 0..=i {\n if s[i] == t[0] {\n dp[i + 1][k][c + 1] = dp[i + 1][k][c + 1] * dp[i][k][c];\n } else {\n dp[i + 1][k + 1][c + 1] = dp[i + 1][k + 1][c + 1] * dp[i][k][c];\n }\n if s[i] == t[1] {\n dp[i + 1][k][c] = dp[i + 1][k][c] * dp[i][k][c].map(|v| v + c as i64);\n } else {\n dp[i + 1][k + 1][c] = dp[i + 1][k + 1][c] * dp[i][k][c].map(|v| v + c as i64);\n }\n if s[i] != t[0] && s[i] != t[1] {\n dp[i + 1][k][c] = dp[i + 1][k][c] * dp[i][k][c];\n }\n }\n }\n }\n let mut ans = Minimal;\n for k in 0..=k {\n for c in 0..=n {\n ans = ans * dp[n][k][c];\n }\n }\n println!(\"{}\", ans.unwrap());\n}\n", "src_uid": "9c700390ac13942cbde7c3428965b18a"} {"source_code": "#[doc = \" https://github.com/hatoo/competitive-rust-snippets\"]\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[macro_export]\nmacro_rules ! chmax { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: max ( $ x ,$ v ) ; ) + } ; }\n#[macro_export]\nmacro_rules ! chmin { ( $ x : expr , $ ( $ v : expr ) ,+ ) => { $ ( $ x = std :: cmp :: min ( $ x ,$ v ) ; ) + } ; }\n#[macro_export]\nmacro_rules ! max { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: max ( $ x , max ! ( $ ( $ xs ) ,+ ) ) } ; }\n#[macro_export]\nmacro_rules ! min { ( $ x : expr ) => ( $ x ) ; ( $ x : expr , $ ( $ xs : expr ) ,+ ) => { std :: cmp :: min ( $ x , min ! ( $ ( $ xs ) ,+ ) ) } ; }\n#[macro_export]\nmacro_rules ! dvec { ( $ t : expr ; $ len : expr ) => { vec ! [ $ t ; $ len ] } ; ( $ t : expr ; $ len : expr , $ ( $ rest : expr ) ,* ) => { vec ! [ dvec ! ( $ t ; $ ( $ rest ) ,* ) ; $ len ] } ; }\n#[doc = \" main\"]\n#[allow(unused_imports)]\nuse std::io::{stdin, stdout, BufWriter, Write};\n#[macro_export]\nmacro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; }\n#[macro_export]\nmacro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; }\n#[macro_export]\nmacro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( \"Parse error\" ) } ; }\nuse std::io;\nuse std::io::BufRead;\nuse std::str;\npub struct Parser {\n reader: R,\n buf: Vec,\n pos: usize,\n}\nimpl Parser {\n pub fn from_str(s: &str) -> Parser {\n Parser {\n reader: io::empty(),\n buf: s.as_bytes().to_vec(),\n pos: 0,\n }\n }\n}\nimpl Parser {\n pub fn new(reader: R) -> Parser {\n Parser {\n reader: reader,\n buf: vec![],\n pos: 0,\n }\n }\n pub fn update_buf(&mut self) {\n self.buf.clear();\n self.pos = 0;\n loop {\n let (len, complete) = {\n let buf2 = self.reader.fill_buf().unwrap();\n self.buf.extend_from_slice(buf2);\n let len = buf2.len();\n if len == 0 {\n break;\n }\n (len, buf2[len - 1] <= 0x20)\n };\n self.reader.consume(len);\n if complete {\n break;\n }\n }\n }\n pub fn next(&mut self) -> Result {\n loop {\n let mut begin = self.pos;\n while begin < self.buf.len() && (self.buf[begin] <= 0x20) {\n begin += 1;\n }\n let mut end = begin;\n while end < self.buf.len() && (self.buf[end] > 0x20) {\n end += 1;\n }\n if begin != self.buf.len() {\n self.pos = end;\n return str::from_utf8(&self.buf[begin..end]).unwrap().parse::();\n } else {\n self.update_buf();\n }\n }\n }\n}\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) ; } }\n#[doc = \" https://github.com/hatoo/competitive-rust-snippets\"]\nconst BIG_STACK_SIZE: bool = true;\n#[allow(dead_code)]\nfn main() {\n use std::thread;\n if BIG_STACK_SIZE {\n thread::Builder::new()\n .stack_size(32 * 1024 * 1024)\n .name(\"solve\".into())\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n } else {\n solve();\n }\n}\nfn solve() {\n let out = stdout();\n let mut out = BufWriter::new(out.lock());\n input!{\n n:i64,\n }\n let mut tot = 0;\n for i in 2..=n-1 {\n tot += i * (i+1);\n }\n writeln!(out,\"{}\",tot);\n}", "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"source_code": "// https://codeforces.com/contest/1271/problem/E\n//\n#![allow(unused_imports)]\nuse std::io::*;\nuse std::fmt::*;\nuse std::str::*;\nuse std::cmp::*;\nuse std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n\n ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($iter:expr, [ next / $t:tt ]) => {\n {\n let len = read_value!($iter, usize);\n (0..len).map(|_| read_value!($iter, $t)).collect::>()\n }\n };\n\n ($iter:expr, switch) => {\n {\n let ty = read_value!($iter, i32);\n if ty == 1 {\n vec![ty, read_value!($iter, i32), read_value!($iter, i32)]\n } else if ty == 2 {\n vec![ty, read_value!($iter, i32)]\n } else {\n vec![ty, read_value!($iter, i32)]\n }\n }\n };\n\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! dvec {\n ($t:expr ; $len:expr) => {\n vec![$t; $len]\n };\n\n ($t:expr ; $len:expr, $($rest:expr),*) => {\n vec![dvec!($t; $($rest),*); $len]\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! ifv {\n ($t:expr, $a:expr, $b: expr) => {\n if $t { $a } else { $b }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! fill {\n ($t:expr, $v:expr) => {\n for i in 0..$t.len() {\n $t[i] = $v;\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! join {\n ($t:expr, $glue:expr) => {\n $t.into_iter().map(|w| w.to_string()).collect::>().join($glue)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn exp(upto: usize, k: usize) {\n let mut cnt = vec![0; upto];\n for w in 1..upto {\n let mut ww = w;\n loop {\n cnt[ww] += 1;\n if ww == 1 {\n break;\n }\n if ww % 2 == 0 {\n ww /= 2;\n } else {\n ww -= 1;\n }\n }\n }\n let mut up = 0;\n for w in (1..upto).rev() {\n if cnt[w] > up {\n up = cnt[w];\n // debug!(w, up);\n }\n }\n for w in (1..upto).rev() {\n if cnt[w] >= k {\n println!(\"{}\", w);\n break;\n }\n }\n}\n\nfn main() {\n input! {\n n: i64, k: i64\n };\n\n if n <= 100 {\n exp((n+1) as usize, k as usize);\n return;\n }\n\n let mut ans = -1;\n let mut tbl = vec![(n, 1), (n-1, ifv!(n % 2 == 0, 1, 2)), (n-2, ifv!(n % 2 == 0, 2, 1))];\n loop {\n // debug!(tbl);\n for &(f, l) in &tbl {\n if k <= l {\n ans = f;\n break;\n }\n }\n if tbl[0].0 <= 1 {\n break;\n }\n if ans != -1 {\n break;\n }\n\n\n let mut ntbl: Vec<(i64, i64)> = vec![];\n let tn = tbl.len();\n for nex in 0..4 {\n let to = tbl[0].0 / 2 - nex;\n let mut add = 1;\n\n // find 2*to\n {\n let mut f2 = false;\n for f in 0..tn {\n if tbl[f].0 == 2*to {\n add += tbl[f].1;\n f2 = true;\n break;\n }\n }\n if !f2 {\n for f in 0..nex {\n if ntbl[f as usize].0 == 2*to {\n add += ntbl[f as usize].1;\n f2 = true;\n break;\n }\n }\n }\n\n if !f2 {\n for f in (0..tn).rev() {\n if tbl[f].0 % 2 == 0 {\n add += tbl[f].1;\n break;\n }\n }\n }\n }\n\n // find to+1\n if to % 2 == 0 {\n // we already have that one...\n if nex >= 1 {\n add += ntbl[(nex-1) as usize].1;\n } else {\n for f in (0..tn).rev() {\n if tbl[f].0 % 2 == 1 {\n add += tbl[f].1;\n break;\n }\n }\n }\n }\n ntbl.push((to, add));\n }\n tbl = ntbl;\n }\n\n // exp((n+1) as usize);\n println!(\"{}\", ans);\n}\n", "src_uid": "783c4b3179c558369f94f4a16ac562d4"} {"source_code": "// ---------- begin ModInt ----------\nconst MOD: u32 = 998_244_353;\n#[derive(Clone, Copy)]\nstruct ModInt(u32);\n\nimpl std::ops::Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: ModInt) -> ModInt {\n let mut d = self.0 + rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: ModInt) -> ModInt {\n ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)\n }\n}\n\nimpl std::ops::Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: ModInt) -> ModInt {\n let mut d = self.0 + MOD - rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> ModInt {\n if self.0 == 0 {self} else {ModInt(MOD - self.0)}\n }\n}\n\nimpl std::ops::AddAssign for ModInt {\n fn add_assign(&mut self, rhs: ModInt) {\n *self = *self + rhs;\n }\n}\n\nimpl std::ops::MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: ModInt) {\n *self = *self * rhs;\n }\n}\n\nimpl std::ops::SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: ModInt) {\n *self = *self - rhs;\n }\n}\n\nimpl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n\nimpl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n}\n\n#[allow(dead_code)]\nimpl ModInt {\n pub fn new(v: u32) -> ModInt {\n ModInt(v % MOD)\n }\n pub fn zero() -> ModInt {\n ModInt(0)\n }\n pub fn one() -> ModInt {\n ModInt(1)\n }\n pub fn pow(self, mut n: u32) -> ModInt {\n let mut t = ModInt::one();\n let mut s = self;\n while n > 0 {\n if n & 1 == 1 {\n t = t * s;\n }\n s = s * s;\n n >>= 1;\n }\n t\n }\n pub fn inv(self) -> ModInt {\n self.pow(MOD - 2)\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\n#[allow(dead_code)]\nstruct Precalc {\n n: usize,\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n}\n\n#[allow(dead_code)]\nimpl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);\n fact[i] = fact[i - 1] * ModInt(i as u32);\n ifact[i] = ifact[i - 1] * inv[i];\n }\n Precalc {\n n: n,\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n pub fn inv(&self, n: usize) -> ModInt {\n self.inv[n]\n }\n}\n\n// ---------- end Precalc ----------\n// ---------- begin NTT ----------\nfn ntt(f: &mut [ModInt]) {\n let n = f.len();\n assert!(n.count_ones() == 1);\n let len = n.trailing_zeros() as usize;\n for i in 1..(n - 1){\n let mut x = i;\n let mut j = 0;\n for _ in 0..len {\n j = (j << 1) | (x & 1);\n x >>= 1;\n }\n if i < j {\n f.swap(i, j);\n }\n }\n for k in 0..(n.trailing_zeros() as usize) {\n let m = 1 << k;\n let z = ModInt(3).pow((MOD - 1) >> (k + 1) as u32);\n for f in f.chunks_mut(2 * m) {\n let mut q = ModInt::one();\n let (x, y) = f.split_at_mut(m);\n for (x, y) in x.iter_mut().zip(y.iter_mut()) {\n let a = *x;\n let b = q * *y;\n *x = a + b;\n *y = a - b;\n q *= z;\n }\n }\n }\n}\n\nfn intt(f: &mut [ModInt]) {\n ntt(f);\n f[1..].reverse();\n let ik = ModInt(f.len() as u32).inv();\n for f in f.iter_mut() {\n *f *= ik;\n }\n}\n\nfn multiply(a: &[ModInt], b: &[ModInt]) -> Vec {\n let n = a.len() + b.len() - 1;\n let mut k = 1;\n while k < n {\n k *= 2;\n }\n assert!(k <= (1 << 23));\n let mut f = Vec::with_capacity(k);\n let mut g = Vec::with_capacity(k);\n f.extend_from_slice(a);\n f.resize(k, ModInt::zero());\n ntt(&mut f);\n g.extend_from_slice(b);\n g.resize(k, ModInt::zero());\n ntt(&mut g);\n for (f, g) in f.iter_mut().zip(g.iter()) {\n *f *= *g;\n }\n intt(&mut f);\n f.truncate(n);\n f\n}\n\n// ---------- end NTT ----------\n\nfn calc(n: usize, p: ModInt, k: usize) -> Vec {\n if n == 1 {\n let mut ans = vec![ModInt::one()];\n for _ in 1..=k {\n ans.push(p);\n }\n ans\n } else if n % 2 == 1 {\n let mut dp = calc(n - 1, p, k);\n let mut v = calc(1, p, k);\n let pc = Precalc::new(2 * k);\n for i in 0..=k {\n dp[i] *= pc.ifact(i);\n v[i] *= pc.ifact(i);\n }\n let mut ans = multiply(&dp, &v);\n for i in 0..=k {\n ans[i] *= pc.fact(i);\n }\n ans.truncate(k + 1);\n ans\n } else {\n let mut dp = calc(n / 2, p, k);\n let pc = Precalc::new(2 * k);\n for i in 0..=k {\n dp[i] *= pc.ifact(i);\n }\n let mut ans = multiply(&dp, &dp);\n for i in 0..=k {\n ans[i] *= pc.fact(i);\n }\n ans.truncate(k + 1);\n ans\n }\n}\n\nfn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let mut it = s.trim().split_whitespace();\n let n: usize = it.next().unwrap().parse().unwrap();\n let m: u32 = it.next().unwrap().parse().unwrap();\n let k: usize = it.next().unwrap().parse().unwrap();\n let ans = calc(n, ModInt(m).inv(), k);\n println!(\"{}\", ans[k]);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "e6b3e559b5fd4e05adf9f1cd1b22126b"} {"source_code": "const N:usize = 505; \r\n\r\n\r\nfn main() {\r\n\r\n let mut str = String::new();\r\n\tstd::io::stdin().read_line(&mut str).expect(\"\");\r\n let input :Vec<&str> = str.trim().split(\" \").collect();\r\n let n = input[0].parse::().unwrap();\r\n let modn = input[1].parse::().unwrap();\r\n let mut dp0:Vec = vec![0;N*N];\r\n let mut dp1:Vec = vec![0;N*N];\r\n //let mut temp_dp0:Vec = vec![0;N*N];\r\n //let mut temp_dp1:Vec = vec![0;N*N];\r\n let shift = N*N/2;\r\n dp1[shift]=1;\r\n for _i in 1..n{\r\n let mut new_dp0 :Vec = vec![0;N*N];\r\n let mut new_dp1 :Vec = vec![0;N*N];\r\n\r\n //let mut new_dp0 = temp_dp0;\r\n //let mut new_dp1 = temp_dp1;\r\n //for j in 0..(N*N){\r\n // new_dp0[j]=0;\r\n // new_dp1[j]=0;\r\n ///}\r\n let i = _i as usize;\r\n for _j in 0..(N*N-1){\r\n let j = _j as usize;\r\n if dp1[j]==0 && dp0[j]==0{\r\n continue;\r\n }\r\n new_dp1[j-i] = (new_dp1[j-i]+dp1[j])%modn;\r\n new_dp1[j+1] = (new_dp1[j+1]-2*dp1[j] + modn + modn)%modn;\r\n new_dp1[j+i+2]=(new_dp1[j+i+2]+dp1[j])%modn;\r\n\r\n new_dp0[j+1] = (new_dp0[j+1]+dp1[j]*(i as i64))%modn;\r\n new_dp0[j] = (new_dp0[j]+(modn-dp1[j])*(i as i64+1))%modn;\r\n new_dp0[j-i] = (new_dp0[j-i]+dp1[j])%modn;\r\n\r\n let t:i64 = (i as i64 +1)*dp0[j]%modn;\r\n new_dp0[j] = (new_dp0[j]+t)%modn;\r\n new_dp0[j+1] = (new_dp0[j+1]+(modn-t)*2)%modn;\r\n new_dp0[j+2] = (new_dp0[j+2]+t)%modn;\r\n }\r\n //for j in shift-10..shift+11{\r\n // println!(\"{} {}\",j as i32-shift as i32,new_dp[j][0])\r\n //}\r\n for j in 0..(N*N-1){\r\n new_dp0[j+1]=(new_dp0[j+1]+new_dp0[j])%modn;\r\n new_dp1[j+1]=(new_dp1[j+1]+new_dp1[j])%modn;\r\n }\r\n for j in 0..(N*N-1){\r\n new_dp0[j+1]=(new_dp0[j+1]+new_dp0[j])%modn;\r\n new_dp1[j+1]=(new_dp1[j+1]+new_dp1[j])%modn;\r\n }\r\n //temp_dp0 = dp0;\r\n //temp_dp1 = dp1;\r\n dp0 = new_dp0;\r\n dp1 = new_dp1;\r\n }\r\n let mut ans:i64 = 0;\r\n for j in shift+1..N*N{\r\n ans = (ans + dp0[j])%modn;\r\n }\r\n println!(\"{}\",ans);\r\n\r\n}\r\n", "src_uid": "ae0320a57d73fab1d05f5d10fbdb9e1a"} {"source_code": "use std::cmp::max;\n\nfn main() {\n let mut input = io::Input::new();\n\n let (n, k): (usize, usize) = (input.next(), input.next());\n\n let mut v = [0i32; 200];\n for i in 0..n {\n v[i] = input.next();\n }\n\n let mut maximum = std::i32::MIN;\n for b in 0..n {\n let mut c = 0;\n for i in 0..n {\n if (b + i) % k != 0 {\n c += v[i];\n }\n }\n maximum = max(c.abs(), maximum);\n }\n\n println!(\"{}\", maximum);\n}\n\n#[allow(unused)]\npub mod io {\n\n const BUFFER_SIZE: usize = 8192;\n\n use std::collections::VecDeque;\n use std::str::FromStr;\n use std::io;\n use std::io::Read;\n\n type AsciiStr = Vec;\n\n pub struct Input {\n token_buffer: VecDeque,\n remaining: String,\n }\n\n impl Input {\n\n pub fn new() -> Input {\n Input {\n token_buffer: VecDeque::with_capacity(100),\n remaining: String::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where T::Err: ::std::fmt::Debug\n {\n self.fill_buffer();\n self.token_buffer.pop_front().unwrap().parse().unwrap()\n }\n\n pub fn next_ascii_string(&mut self) -> AsciiStr {\n self.fill_buffer();\n Vec::from(self.token_buffer.pop_front().unwrap().as_bytes())\n }\n\n fn fill_buffer(&mut self) {\n while self.token_buffer.is_empty() {\n let mut minibuffer = [0u8; BUFFER_SIZE];\n let size = io::stdin().read(&mut minibuffer[..]).unwrap();\n\n self.remaining += &String::from_utf8_lossy(&minibuffer[..size]);\n\n if self.remaining.trim().len() > 0 {\n for token in self.remaining.trim().split_whitespace() {\n self.token_buffer.push_back(String::from(token))\n }\n\n if size > 0 && ! self.remaining.ends_with(|c: char|char::is_ascii_whitespace(&c)) {\n self.remaining = self.token_buffer.pop_back().unwrap();\n } else {\n self.remaining.clear();\n }\n\n } else if size == 0 {\n panic!(\"EOF\");\n }\n }\n }\n }\n}\n", "src_uid": "6119258322e06fa6146e592c63313df3"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io::prelude::*;\n use std::io;\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let n: u64 = it.next().unwrap().parse().unwrap();\n let k: u64 = it.next().unwrap().parse().unwrap();\n let a: u64 = it.next().unwrap().parse().unwrap();\n let b: u64 = it.next().unwrap().parse().unwrap();\n\n if k == 1 {\n let ans = (n - 1) * a;\n println!(\"{}\", ans);\n return;\n }\n\n let mut x = n;\n\n let mut ans = 0;\n\n loop {\n let rem = x % k;\n if rem > 0 {\n x -= rem;\n ans += rem * a;\n } else {\n let q = x / k;\n let y = std::cmp::min((k - 1) * q * a, b);\n\n ans += y;\n x = q;\n }\n if x == 1 {\n println!(\"{}\", ans);\n break;\n } else if x == 0 {\n println!(\"{}\", ans - a);\n break;\n }\n }\n}\n", "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next_line(&self) -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n line\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let line = self.next_line();\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn mult(m1: &[[u64; 4]; 4], m2: &[[u64; 4]; 4]) -> [[u64; 4]; 4] {\n let mut result = [[0u64; 4]; 4];\n for i in 0..4 {\n for j in 0..4 {\n let mut sum = 0u64;\n for k in 0..4 {\n sum = (sum + m1[i][k] * m2[k][j]) % 1000000007;\n }\n result[i][j] = sum;\n }\n }\n result\n}\n\nfn exp(m: &[[u64; 4]; 4], mut e: u64) -> [[u64; 4]; 4] {\n let mut m2 = m.clone();\n let mut result = [[0u64; 4]; 4];\n result[0][0] = 1;\n result[1][1] = 1;\n result[2][2] = 1;\n result[3][3] = 1;\n while e > 0 {\n if e & 1 == 1 {\n result = mult(&result, &m2);\n }\n e >>= 1;\n m2 = mult(&m2, &m2);\n }\n result\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: u64 = scan.next();\n let mat: [[u64; 4]; 4] = [[0, 1, 1, 1], [1, 0, 1, 1], [1, 1, 0, 1], [1, 1, 1, 0]];\n let result = exp(&mat, n);\n println!(\"{}\", result[0][0]);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "77627cc366a22e38da412c3231ac91a8"} {"source_code": "#![allow(dead_code, unused_macros, unused_variables, clippy::many_single_char_names)]\nuse std::io::{stdin, stdout, StdinLock, StdoutLock, BufWriter, prelude::*};\n\nmacro_rules! spread {\n ($w: expr, $v: expr) => {\n for x in $v.iter() {\n write!($w, \"{} \", x).unwrap();\n }\n writeln!($w).unwrap();\n };\n}\n\nstruct Reader<'a> {\n stdin: StdinLock<'a>,\n last_pos: usize\n}\n\nmacro_rules! read {\n ($s: ident) => {\n {\n // $s.stdin.consume($s.last_pos+1);\n\n let buf = $s.stdin.fill_buf().unwrap();\n let mut i = 0;\n \n while i < buf.len() {\n if buf[i] > 32 {\n i += 1;\n } else {\n break;\n }\n }\n\n $s.last_pos = i;\n &buf[..i]\n }\n };\n}\n\nmacro_rules! read_int {\n ($s: ident, $t: ty) => {\n {\n let mut v: $t = 0;\n let num: &[u8] = read!($s);\n let l = $s.last_pos;\n\n assert!(num.len() == l); // hopefully remove bound checks\n \n if num[0] == b'-' {\n for d in &num[1..l] { // use release for wrapping op\n v = v*10 - (*d as $t) + (b'0' as $t);\n }\n } else {\n for d in &num[..l] {\n v = v*10 + (*d as $t) - (b'0' as $t);\n }\n }\n v\n }\n }\n}\n\nfn main() {\n let stdin = stdin();\n let stdout = stdout();\n solve(&mut Reader {stdin: stdin.lock(), last_pos: 0}, &mut BufWriter::new(stdout.lock()));\n}\n\nfn solve(r: &mut Reader, w: &mut BufWriter) {\n for c in read!(r) {\n let c = *c;\n let c = if (c as u8) < 97 {(c as u8) + 32} else {c};\n \n match c {\n b'a' | b'e' | b'i' | b'o' | b'u' | b'y' => {},\n _ => write!(w, \".{}\", c as char).unwrap()\n }\n }\n}", "src_uid": "db9520e85b3e9186dd3a09ff8d1e8c1b"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, std::io::stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut buffer = String::new();\n let mut input = WordReader::from_stdin(&mut buffer);\n\n use std::collections::HashMap;\n const K: &[u8] = b\"qwertyuiopasdfghjkl;zxcvbnm,./\";\n let ml = K.iter().zip(K.iter().skip(1)).collect::>();\n let mr = K.iter().skip(1).zip(K.iter()).collect::>();\n let c = input.bs()[0];\n let s = input.bs();\n let m = if c == b'L' { ml } else { mr };\n for x in s {\n print!(\"{}\", *(m[x]) as char);\n }\n}\n\n", "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"source_code": "use std::io;\n\nfn read_u8() -> u8 {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().parse().unwrap()\n}\n\nfn read_string() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n}\n\nfn main() {\n let n = read_u8();\n let n_sqrt = (n as f64).sqrt() as u8;\n let mut s = read_string();\n\n let mut divs: Vec = vec!();\n for i in 1..=n_sqrt {\n if n%i == 0 {\n divs.push(i as usize);\n if i*i != n {\n divs.push((n/i) as usize);\n }\n }\n }\n divs.sort();\n\n for i in divs.iter() {\n let t = s.split_off(*i);\n s = s.chars().rev().collect();\n s.push_str(&t);\n }\n\n println!(\"{}\", s);\n\n return;\n}\n", "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nconst M: i64 = 1_000_000_007;\n\n// fn mul(a: i64, b: i64) -> i64 { a * b % M }\nfn add(a: i64, b: i64) -> i64 {\n let mut x = (a + b) % M;\n if x < 0 { x += M; }\n x\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.u();\n let tt = input.i();\n let mut t = vec![0; n];\n let mut g = vec![0; n];\n let mut z = vec![0; 4];\n for i in 0..n {\n t[i] = input.i();\n g[i] = input.i();\n z[g[i] as usize] += 1;\n }\n\n let f = |a,b| if a == b { 1 } else { 0 };\n\n let dp1 = {\n let mut dp = HashMap::<(i32,i32,i32,i32),i64>::new();\n dp.insert((0,0,0,0), 1);\n for i in 0..n {\n let mut d = HashMap::<(i32,i32,i32,i32),i64>::new();\n let x = t[i];\n let g = g[i];\n for (&(t,a,b,c), &y) in dp.iter() {\n let key = (t + x, a + f(g, 1), b + f(g, 2), c + f(g, 3));\n let res = *d.get(&key).unwrap_or(&0);\n d.insert(key, add(res, y));\n }\n for (key, y) in d.into_iter() {\n let res = *dp.get(&key).unwrap_or(&0);\n dp.insert(key, add(res, y));\n }\n }\n dp\n };\n // for ((t,a,b,c),x) in dp1.iter() {\n // println!(\"dp1 {} {} {} {} : {}\", t,a,b,c,x);\n // }\n\n let dp2 = {\n let mut dp2 = HashMap::<(i32,i32,i32),i64>::new();\n let mut dp = HashMap::<(i32,i32,i32,i32,i32),i64>::new();\n for g in 1..4 {\n dp.insert((0,0,0,0,g), 1);\n }\n for _i in 0..n {\n let mut d = HashMap::<(i32,i32,i32,i32,i32),i64>::new();\n for ((h,a,b,c,l), y) in dp.into_iter() {\n let mut p = [0,a,b,c];\n for g in 1..4 {\n if (h == 0 && g != l) || (h > 0 && g == l) {\n continue;\n }\n p[g as usize] += 1;\n if (1..4).all(|i| p[i] <= z[i]) {\n let key = (h + 1, p[1], p[2], p[3], g);\n let res = add(y * p[g as usize] as i64, *d.get(&key).unwrap_or(&0));\n d.insert(key, res);\n }\n p[g as usize] -= 1;\n }\n }\n\n for (&(_,a,b,c,_),&x) in d.iter() {\n let key = (a,b,c);\n let res = *dp2.get(&key).unwrap_or(&0);\n dp2.insert(key, add(res, x));\n }\n dp = d;\n // println!(\"\\n-----------------------: {}\", _i);\n // for ((h,a,b,c,g),x) in dp.iter() {\n // println!(\"{} {} {} {} {}: {}\", h,a,b,c,g,x);\n // }\n }\n dp2\n };\n // for ((a,b,c),x) in dp2.iter() {\n // println!(\"dp2 {} {} {} : {}\", a,b,c,x);\n // }\n\n let mut sol: i64 = 0;\n for a in 0..z[1]+1 {\n let a = a as i32;\n for b in 0..z[2]+1 {\n let b = b as i32;\n for c in 0..z[3]+1 {\n let c = c as i32;\n let x = dp1.get(&(tt,a,b,c)).unwrap_or(&0);\n let y = dp2.get(&(a,b,c)).unwrap_or(&0);\n sol = add(sol, x * y);\n }\n }\n }\n println!(\"{}\", sol);\n}\n\n", "src_uid": "ac2a37ff4c7e89a345b189e4891bbf56"} {"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let read_in = buf.split_whitespace().map(|c| c.trim().parse::().unwrap()).collect::>();\n let n = read_in[0];\n// let m = read_in[1];\n\n buf.clear();\n io::stdin().read_line(&mut buf).unwrap();\n let mut nums = buf.split_whitespace().map(|c| c.trim().parse::().unwrap()).collect::>();\n nums.sort();\n\n let ret = nums.windows(n as usize).fold(None, |acc: Option, v| {\n let m = v[n - 1] - v[0];\n let r = match acc {\n None => m,\n Some(acc_n)if m > acc_n => acc_n,\n _ => m,\n };\n Some(r)\n });\n println!(\"{}\", ret.unwrap());\n}\n", "src_uid": "7830aabb0663e645d54004063746e47f"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan { buffer: std::collections::VecDeque::new() }\n }\n\n fn next(&mut self)-> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: isize = scan.next();\n let m: isize = scan.next();\n let mut twomoves: isize = n / 2;\n let mut onemoves: isize = n % 2;\n for _ in 0..m {\n if (twomoves + onemoves ) % m == 0 {\n println!(\"{}\", twomoves+onemoves);\n return;\n }\n if twomoves > 0 {\n twomoves -= 1;\n onemoves += 2;\n }\n }\n println!(\"-1\");\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "src_uid": "0fa526ebc0b4fa3a5866c7c5b3a4656f"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let sum = (0..2).fold(0, |s,_| s + input.i().abs());\n let s = input.i();\n if s >= sum && (s - sum) % 2 == 0 {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n}\n\n", "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"source_code": "// 991E\nuse std::io;\n\nfn main() {\n let mut a = String::new();\n io::stdin().read_line(&mut a).unwrap();\n let a = a.trim();\n\n let mut counts = [0u64; 10];\n\n for c in a.chars() {\n counts[c.to_digit(10).unwrap() as usize] += 1;\n }\n\n let mut fa = [0u64; 30];\n\n let with_zero = count(&mut counts, 0, &mut fa);\n let mut correct = with_zero;\n if counts[0] > 0 {\n counts[0] -= 1;\n correct -= count(&mut counts, 0, &mut fa);\n if counts[0] > 0 {\n counts[0] = 0;\n correct -= count(&mut counts, 0, &mut fa);\n }\n }\n println!(\"{}\", correct);\n}\n\nfn factorial(n: u64, fa: &mut [u64]) -> u64 {\n if n == 0 {\n fa[n as usize] = 1;\n } else if fa[n as usize] == 0 {\n fa[n as usize] = factorial(n - 1, fa) * n;\n }\n return fa[n as usize];\n}\n\nfn count(counts: &mut [u64], change_here: usize, fa: &mut [u64]) -> u64 {\n if change_here == 10 {\n // All numbers are fixed now\n let numerator = factorial(counts.iter().sum(), fa);\n let mut denominator = 1;\n for c in counts {\n denominator *= factorial(*c, fa);\n }\n return numerator / denominator;\n }\n\n if counts[change_here] == 0 {\n return count(counts, change_here + 1, fa);\n }\n\n let mut add = 0;\n for i in 1..(counts[change_here] + 1) {\n counts[change_here] = i;\n add += count(counts, change_here + 1, fa);\n }\n return add;\n}\n", "src_uid": "7f4e533f49b73cc2b96b4c56847295f2"} {"source_code": "use std::io::{self, Stdin};\nuse std::str::{self, FromStr};\nuse std::error::Error;\nuse std::thread;\nuse std::cmp::*;\nfn exec() {\n let mut sc = Scanner::new();\n let _: usize = sc.ne();\n let k: usize = sc.ne();\n let a = sc.ne::().into_bytes();\n let start = a.iter().position(|&x| x == b'G').unwrap();\n let goal = a.iter().position(|&x| x == b'T').unwrap();\n let s = min(start, goal);\n let g = max(start, goal);\n let mut ok = true;\n if (g - s) % k != 0 {\n println!(\"NO\");\n std::process::exit(0);\n }\n let mut cur = s;\n while cur != g {\n if a[cur] == b'#' {\n ok = false;\n }\n cur += k;\n }\n println!(\"{}\", if ok { \"YES\" } else { \"NO\" });\n}\n\n\nfn main() {\n const DEFAULT_STACK: usize = 16 * 1024 * 1024;\n let builder = thread::Builder::new();\n let th = builder.stack_size(DEFAULT_STACK);\n let handle = th.spawn(|| { exec(); }).unwrap();\n let _ = handle.join();\n}\n\n#[allow(dead_code)]\nstruct Scanner {\n stdin: Stdin,\n id: usize,\n buf: Vec,\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new() -> Scanner {\n Scanner {\n stdin: io::stdin(),\n id: 0,\n buf: Vec::new(),\n }\n }\n fn next_line(&mut self) -> Option {\n let mut res = String::new();\n match self.stdin.read_line(&mut res) {\n Ok(0) => return None,\n Ok(_) => Some(res),\n Err(why) => panic!(\"error in read_line: {}\", why.description()),\n }\n }\n fn next(&mut self) -> Option {\n while self.buf.len() == 0 {\n self.buf = match self.next_line() {\n Some(r) => {\n self.id = 0;\n r.trim().as_bytes().to_owned()\n }\n None => return None,\n };\n }\n let l = self.id;\n assert!(self.buf[l] != b' ');\n let n = self.buf.len();\n let mut r = l;\n while r < n && self.buf[r] != b' ' {\n r += 1;\n }\n let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::() {\n Ok(s) => Some(s),\n Err(_) => panic!(\"parse error\"),\n };\n while r < n && self.buf[r] == b' ' {\n r += 1;\n }\n if r == n {\n self.buf.clear();\n } else {\n self.id = r;\n }\n res\n }\n fn ne(&mut self) -> T {\n self.next::().unwrap()\n }\n}\n", "src_uid": "189a9b5ce669bdb04b9d371d74a5dd41"} {"source_code": "use std::io::{Read,stdin};\n\nconst M: i128 = 1_000_000_007;\n \nfn main() {\n let mut buf = String::new();\n stdin().read_to_string(&mut buf).unwrap();\n let mut tok = buf.split_whitespace();\n let mut get = || tok.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(i128));\n }\n \n let x = get!();\n let n = get!();\n \n let mut ps = vec![];\n let mut y = x;\n for i in 2 ..= x {\n if i * i > y {\n break;\n }\n if y % i != 0 {\n continue;\n }\n ps.push(i);\n while y % i == 0 {\n y /= i;\n }\n }\n if y > 1 {\n ps.push(y);\n }\n let mut ans = 1;\n for &p in ps.iter() {\n let mut es = vec![];\n let mut e = p;\n while e <= n {\n es.push(e);\n e *= p;\n }\n let mut t = 0;\n while let Some(e) = es.pop() {\n let c = n / e - t;\n ans = ans * pow(e, c) % M;\n t = n / e;\n }\n }\n println!(\"{}\", ans);\n}\n\nfn pow(a: i128, b: i128) -> i128 {\n if b == 0 {\n 1\n } else if b % 2 == 0 {\n pow(a * a % M, b / 2)\n } else {\n a * pow(a, b - 1) % M\n }\n}", "src_uid": "04610fbaa746c083dda30e21fa6e1a0c"} {"source_code": "macro_rules! parse_line {\n ($t: ty) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let a_str = a_str.trim();\n a_str.parse::<$t>().expect(\"parse error\")\n });\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().expect(\"parse error\"),\n )+\n )\n })\n}\n\n#[allow(unused_macros)]\nmacro_rules! parse_line_to_vec {\n ($t: ty) => {{\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n (a_str\n .split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect::>())\n }};\n}\n\nuse std::io::Write;\n\nfn solve(writer: &mut std::io::BufWriter) {\n let ss: Vec = parse_line!(String).bytes().collect();\n let b = ss.iter().filter(|c| **c == b'B').count() as u64;\n let s = ss.iter().filter(|c| **c == b'S').count() as u64;\n let c = ss.iter().filter(|c| **c == b'C').count() as u64;\n let (nb, ns, nc) = parse_line!(u64, u64, u64);\n let (pb, ps, pc) = parse_line!(u64, u64, u64);\n let r = parse_line!(u64);\n let mut l = 0;\n let mut u = 10000000000000;\n while u - l > 1 {\n let m = (l + u) / 2;\n let need =\n if b * m <= nb {0} else {pb * (b * m - nb)} +\n if s * m <= ns {0} else {ps * (s * m - ns)} +\n if c * m <= nc {0} else {pc * (c * m - nc)};\n if need <= r {\n l = m;\n }else{\n u = m;\n }\n }\n writeln!(writer, \"{}\", l).unwrap();\n}\n\nfn main() {\n let mut writer = std::io::BufWriter::new(std::io::stdout());\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve(&mut writer);\n }\n}\n", "src_uid": "8126a4232188ae7de8e5a7aedea1a97e"} {"source_code": "use std::io::{self, Read};\n\nfn main() -> io::Result<()> {\n let mut buf = String::new();\n io::stdin().read_to_string(&mut buf)?;\n let v: Vec = buf\n .split_ascii_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n let (k, mut l) = (v[0], v[1]);\n\n let mut ans = -1;\n while l % k == 0 {\n l /= k;\n ans += 1;\n }\n\n if l == 1 {\n println!(\"YES\");\n println!(\"{}\", ans);\n } else {\n println!(\"NO\");\n }\n\n Ok(())\n}\n", "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"source_code": "use std::io;\n\nfn main() {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let n: u32 = buffer.trim().parse().expect(\"invalid input\");\n\n println!(\"{}\", 2 * n * (n - 1) + 1);\n}", "src_uid": "758d342c1badde6d0b4db81285be780c"} {"source_code": "use std::io::{stdin, BufRead, BufReader};\nuse std::vec::Vec;\nuse std::process;\n\nconst MAX_DIFF: i32 = 90;\n\nfn digit_sum(n: i32) -> i32 {\n let mut result = 0;\n let mut t = n;\n while t > 0 {\n result = result + (t % 10);\n t = t / 10;\n }\n result\n}\n\nfn solve(n: i32) -> Vec {\n let mut result: Vec = Vec::new();\n for x in 1..MAX_DIFF {\n let t = n - x;\n if digit_sum(t) == x {\n result.push(t);\n }\n }\n result\n}\n\n#[allow(non_snake_case)]\n#[allow(unused_variables)]\nfn main() {\n let mut reader = BufReader::new(stdin());\n let mut s = String::new();\n reader.read_line(&mut s).unwrap();\n let N = s.trim_right().parse::().unwrap();\n let mut solved = solve(N);\n let mut result = solved.as_mut_slice();\n result.sort();\n println!(\"{}\", result.len());\n if result.len() == 0 {\n process::exit(0);\n }\n s.clear();\n for i in 0..result.len() {\n s.push_str(result[i].to_string().as_str());\n if i != result.len() - 1 {\n s.push(' ');\n }\n }\n println!(\"{}\", s);\n}\n", "src_uid": "ae20ae2a16273a0d379932d6e973f878"} {"source_code": "// -------- begin template -------- \r\n \r\n#![allow(\r\n dead_code, unused_imports, unused_variables, \r\n unused_must_use, unused_macros, unused_mut, unused_assignments\r\n)]\r\n \r\nuse std::io::{self, Read, Write};\r\nuse std::cmp::{min, max};\r\nuse std::mem::swap;\r\nuse std::collections::{VecDeque, HashMap, HashSet, BTreeSet};\r\n \r\nmacro_rules! dbg {\r\n ($first_val:expr, $($val:expr),+ $(,)?) => {\r\n eprint!(\"[{}:{}] {} = {:?}\",\r\n file!(), line!(), stringify!($first_val), &$first_val);\r\n ($(eprint!(\", {} = {:?}\", stringify!($val), &$val)),+,);\r\n eprintln!();\r\n };\r\n ($first_val:expr) => {\r\n eprintln!(\"[{}:{}] {} = {:?}\",\r\n file!(), line!(), stringify!($first_val), &$first_val);\r\n };\r\n}\r\n \r\nenum InputSource {\r\n Stdin,\r\n FromFile(Vec),\r\n}\r\n \r\nstruct Scanner {\r\n buffer: Vec,\r\n input_source: InputSource,\r\n}\r\n \r\nimpl Scanner {\r\n fn new() -> Self {\r\n Self {\r\n buffer: vec![],\r\n input_source: InputSource::Stdin,\r\n }\r\n }\r\n \r\n fn new_file(filename: &str) -> Self {\r\n let file = std::fs::read_to_string(filename).unwrap();\r\n let mut lines: Vec = file.lines().map(|line| String::from(line)).collect();\r\n lines.reverse();\r\n Self {\r\n buffer: vec![],\r\n input_source: InputSource::FromFile(lines),\r\n }\r\n }\r\n \r\n fn usize(&mut self) -> usize { self.next::() }\r\n fn bytes(&mut self) -> Vec { self.next::().into_bytes() }\r\n fn chars(&mut self) -> Vec { self.next::().chars().collect() }\r\n fn string(&mut self) -> String { self.next::() }\r\n fn i64(&mut self) -> i64 { self.next::() }\r\n fn f64(&mut self) -> f64 { self.next::() }\r\n fn i32(&mut self) -> i32 { self.next::() }\r\n fn f32(&mut self) -> f32 { self.next::() }\r\n \r\n fn vec(&mut self, n: usize) -> Vec {\r\n (0..n).map(|_| self.next::()).collect()\r\n }\r\n \r\n fn parse_next_line(&mut self) -> bool {\r\n let mut input = String::new();\r\n match &mut self.input_source {\r\n InputSource::Stdin => {\r\n if std::io::stdin().read_line(&mut input).expect(\"Failed read\") == 0 {\r\n return false;\r\n }\r\n }\r\n InputSource::FromFile(lines) => match lines.pop() {\r\n Some(line) => input = line,\r\n None => return false,\r\n },\r\n }\r\n \r\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\r\n return true;\r\n }\r\n \r\n fn next(&mut self) -> T {\r\n loop {\r\n if let Some(token) = self.buffer.pop() {\r\n return token.parse().ok().expect(\"Failed parse\");\r\n }\r\n self.parse_next_line();\r\n }\r\n }\r\n \r\n fn has_more_elements(&mut self) -> bool {\r\n loop {\r\n if !self.buffer.is_empty() { return true; }\r\n if !self.parse_next_line() { return false; }\r\n }\r\n }\r\n}\r\n \r\n// -------- end template -------- \r\n \r\nfn to2(x: i64) -> Vec {\r\n let mut res: Vec = Vec::new();\r\n let mut tmp = x;\r\n while tmp > 0 {\r\n res.push(tmp & 1);\r\n tmp >>= 1;\r\n }\r\n res.reverse();\r\n res\r\n}\r\n\r\nfn to10(d: &Vec) -> i64 {\r\n if d.len() > 60 {\r\n return 0;\r\n }\r\n let (mut exp, mut res) = (1, 0);\r\n for i in (0..d.len()).rev() {\r\n if d[i] == 1 {\r\n res += exp;\r\n }\r\n exp *= 2;\r\n }\r\n res\r\n}\r\n\r\nfn go(x: i64, d: i64) -> i64 {\r\n let mut a = to2(x);\r\n a.push(d);\r\n a.reverse();\r\n to10(&a)\r\n}\r\n\r\nfn solve(x: i64, y: i64) -> bool {\r\n let mut q: VecDeque = VecDeque::new();\r\n let mut vis: HashSet = HashSet::new();\r\n q.push_back(x);\r\n while let Some(cur) = q.pop_front() {\r\n if cur == 0 { continue; }\r\n if vis.contains(&cur) { continue; }\r\n vis.insert(cur);\r\n if cur == y { return true; }\r\n\r\n q.push_back(go(cur, 0));\r\n q.push_back(go(cur, 1));\r\n }\r\n false\r\n} \r\n\r\nfn main() {\r\n let stdout = io::stdout();\r\n let mut out = std::io::BufWriter::new(stdout.lock());\r\n let mut sc = Scanner::new();\r\n\r\n \r\n let (x, y) = (sc.i64(), sc.i64());\r\n writeln!(out, \"{}\", if solve(x, y) { \"YES\" } else { \"NO \"});\r\n}\r\n\r\n \r\n\r\n\r\n\r\n\r\n\r\n \r\n", "src_uid": "9f39a3c160087beb0efab2e3cb510e89"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nuse std::cmp::{max, min};\n\nfn run() {\n input! {\n a: i32,\n b: i32,\n x: i32,\n y: i32,\n n: i32,\n }\n let mut f = n;\n let mut g = 0;\n for i in 0..=n {\n if x * a < i || y * b < n - i{\n continue;\n }\n let mut p = 0;\n let mut q = 0;\n if (x - 1) * a < i {\n p += i - (x - 1) * a;\n }\n q += i / x;\n if (y - 1) * b < n - i {\n p += n - i - (y - 1) * b;\n }\n q += (n - i) / y;\n f = min(f, p);\n g = max(g, q);\n }\n println!(\"{} {}\", f, g);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "2be8e0b8ad4d3de2930576c0209e8b91"} {"source_code": "use std::io;\nuse std::str::SplitWhitespace;\n\nfn main() {\n let mut input: String = String::new();\n io::stdin().read_line(&mut input).unwrap();\n let mut it_input: SplitWhitespace = input.split_whitespace();\n let n: i32 = it_input.next().unwrap().parse().unwrap();\n let m: i32 = it_input.next().unwrap().parse().unwrap();\n let r: i32 = it_input.next().unwrap().parse().unwrap();\n let mut n_input: String = String::new();\n let mut m_input: String = String::new();\n io::stdin().read_line(&mut n_input).unwrap();\n io::stdin().read_line(&mut m_input).unwrap();\n let mut it_n: SplitWhitespace = n_input.split_whitespace();\n let mut it_m: SplitWhitespace = m_input.split_whitespace();\n let mut n_min: i32 = 1001;\n let mut m_max: i32 = 0;\n for _i in 0..n {\n let a: i32 = it_n.next().unwrap().parse().unwrap();\n if a < n_min {\n n_min = a;\n }\n }\n for _i in 0..m {\n let a: i32 = it_m.next().unwrap().parse().unwrap();\n if a > m_max {\n m_max = a;\n }\n }\n if r / n_min * m_max + r % n_min > r {\n print!(\"{}\", r / n_min * m_max + r % n_min);\n } else {\n print!(\"{}\", r);\n }\n}\n", "src_uid": "42f25d492bddc12d3d89d39315d63cb9"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\n\nfn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(\n &mut std::io::stdin(),\n &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(i64));\n }\n \n let h = get!(usize);\n let w = get!(usize);\n let p = 998244353;\n let mut ans = 4;\n for i in 1 .. w {\n ans = (ans * 2) % p;\n }\n for j in 1 .. h {\n ans = (ans * 2) % p;\n }\n println!(\"{}\", ans);\n}", "src_uid": "8b2a9ae21740c89079a6011a30cd6aee"} {"source_code": "//spnauti-rusT {{{\nuse std::io::*; use std::str::{self,*}; use std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)] macro_rules! min {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! max {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! l {\n\t($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};\n\t($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};\n\t(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};\n}\n#[allow(unused_macros)] macro_rules! v {\n\t([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};\n\t([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};\n}\n#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }\n#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }\n#[allow(dead_code)] fn writer() -> BufWriter { BufWriter::new(stdout()) }\nstruct WordReaderC {buf: Vec, pos: usize, q: std::io::StdinLock<'static>}//'\n#[allow(dead_code)] impl WordReaderC {\n\tfn new() -> Self {\n\t\tlet r = unsafe {&*Box::into_raw(Box::new(stdin()))};\n\t\tSelf { q: r.lock(), buf: Vec::new(), pos: 0 }\n\t}\n\tfn next_line(&mut self) -> bool {\n\t\tself.buf.clear(); self.pos = 0;\n\t\tself.q.read_until(b'\\n', &mut self.buf).unwrap_or(0) > 0\n\t}\n\tfn is_ws(c: u8) -> bool {\n\t\tc == b' ' || c == b'\\r' || c == b'\\n' || c == b'\\t'\n\t}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos == self.buf.len() { if !self.next_line() { return None; } }\n\t\tself.pos += 1; Some(self.buf[self.pos - 1])\n\t}\n\tfn vb(&mut self) -> Vec {\n\t\tlet mut s = Vec::with_capacity(8);\n\t\tlet mut f = false;\n\t\tloop {\n\t\t\tif let Some(c) = self.byte() {\n\t\t\t\tif !Self::is_ws(c) {\n\t\t\t\t\ts.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t} else if f { break; }\n\t\t\t} else { break; }\n\t\t}\n\t\ts\n\t}\n\tfn s(&mut self) -> String { String::from_utf8(self.vb()).expect(\"invalid utf8\") }\n\tfn i(&mut self) -> i32 { self.p() }\n\tfn l(&mut self) -> i64 { self.p() }\n\tfn u(&mut self) -> usize { self.p() }\n\tfn f(&mut self) -> f64 { self.p() }\n\tfn vi(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vl(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vu(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn p(&mut self) -> T where T::Err: Debug {\n\t\tlet w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap()\n\t}\n\tfn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n\t\t(0..n).map(|_|self.p()).collect()\n\t}\n\tfn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n\t\tself.vp(n).into_iter()\n\t}\n}\n//------------------- End rusT }}}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tlet n = rin.u();\n\tl!(x,y = rin.l());\n\tlet mut dp = v!([n+1]);\n\tdp.push(x);\n\tdp.push(x);\n\tfor i in 2..=n {\n\t\tlet z = dp[i-1] + x;\n\t\tlet ii = i >> 1;\n\t\tdp.push(z);\n\t\tif i & 1 == 0 {\n\t\t\tmin!(dp[i], dp[ii] + y);\n\t\t} else {\n\t\t\tmin!(dp[i], dp[ii].min(dp[ii+1]) + y + x);\n\t\t}\n\t}\n\twriteln!(rout, \"{}\", dp[n]).ok();\n}\n", "src_uid": "0f270af00be2a523515d5e7bd66800f6"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.i();\n if n == 1 {\n println!(\"-1\");\n } else {\n println!(\"{} {}\", n, n);\n }\n}\n\n", "src_uid": "883f67177474d23d7a320d9dbfa70dd3"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn is_prime(n: i64) -> bool {\n let mut d = 2;\n while d * d <= n {\n if n % d == 0 {\n return false;\n }\n d += 1;\n }\n true\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let t: u32 = scan.token();\n for _ in 0..t {\n let a: i64 = scan.token();\n let b: i64 = scan.token();\n if a - b == 1 && is_prime(a + b) {\n writeln!(out, \"YES\").ok();\n } else {\n writeln!(out, \"NO\").ok();\n }\n }\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "5a052e4e6c64333d94c83df890b1183c"} {"source_code": "#![allow(unused_imports)]\nuse std::io::*;\nuse std::cmp::*;\nuse std::collections::*;\n\nmacro_rules! debug(\n ($($arg:tt)*) => { {\n let r = writeln!(&mut ::std::io::stderr(), $($arg)*);\n r.expect(\"failed printing to stderr\");\n } }\n);\n\nstruct Scanner {\n buffer : std::collections::VecDeque\n}\n\nimpl Scanner {\n\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn process(&mut self) -> String {\n if self.buffer.len() == 0 {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n for word in input.split_whitespace() {\n self.buffer.push_back(word.to_string())\n }\n }\n\n self.buffer.pop_front().unwrap()\n }\n\n #[allow(dead_code)]\n fn next(&mut self) -> T {\n self.process().parse::().ok().unwrap()\n }\n\n #[allow(dead_code)]\n fn next_char(&mut self) -> char {\n self.process().into_bytes()[0] as char\n }\n}\n\nfn main() {\n let mut sin = Scanner::new();\n let mut n = sin.next();\n let mut result = vec![];\n result.push(1);\n n -= 1;\n let mut k = 2;\n let mut i = 0;\n\n while result[i] < n && n >= k {\n result.push(k);\n n -= k;\n k += 1;\n i += 1;\n }\n\n result[i] += n;\n\n println!(\"{}\", result.len());\n print!(\"{}\", result[0]);\n for j in result.iter().skip(1) {\n print!(\" {}\", *j);\n }\n}\n", "src_uid": "356a7bcebbbd354c268cddbb5454d5fc"} {"source_code": "use std::cmp::max;\nuse std::cmp::min;\nuse std::io;\nuse std::io::Stdin;\n\nfn read_line(stdin : &Stdin, line : &mut String) {\n match stdin.read_line(line) {\n Ok(_) => return,\n Err(msg) => panic!(\"Could not read line! Message: {}.\", msg),\n }\n}\n\nfn read_file(c : char) -> i64 {\n if c == 'a' {\n 1\n } else if c == 'b' {\n 2\n } else if c == 'c' {\n 3\n } else if c == 'd' {\n 4\n } else if c == 'e' {\n 5\n } else if c == 'f' {\n 6\n } else if c == 'g' {\n 7\n } else if c == 'h' {\n 8\n } else {\n panic!(\"Unknown file: {}\", c);\n }\n}\n\nfn read_rank(c : char) -> i64 {\n c.to_digit(10).unwrap() as i64\n}\n\nfn read_square(stdin : &Stdin) -> (i64, i64) {\n let mut line = String::new();\n read_line(&stdin, &mut line);\n let mut cs = line.trim().chars();\n let x = read_file(cs.next().unwrap());\n let y = read_rank(cs.next().unwrap());\n (x, y)\n}\n\nfn get_moves(d_x : i64, d_y : i64) -> (String, String) {\n let move_d;\n let move_s;\n let abs_d_x = d_x.abs();\n let abs_d_y = d_y.abs();\n if d_x < 0 {\n if d_y < 0 {\n move_d = String::from(\"LD\");\n if abs_d_x < abs_d_y {\n move_s = String::from(\"D\");\n } else if abs_d_x == abs_d_y {\n move_s = String::from(\"\");\n } else {\n move_s = String::from(\"L\");\n }\n } else if d_y == 0 {\n move_d = String::from(\"\");\n move_s = String::from(\"L\");\n } else {\n move_d = String::from(\"LU\");\n if abs_d_x < abs_d_y {\n move_s = String::from(\"U\");\n } else if abs_d_x == abs_d_y {\n move_s = String::from(\"\");\n } else {\n move_s = String::from(\"L\");\n }\n }\n } else if d_x == 0 {\n if d_y < 0 {\n move_s = String::from(\"D\");\n } else if d_y == 0 {\n move_s = String::from(\"\");\n } else {\n move_s = String::from(\"U\");\n }\n move_d = String::from(\"\");\n } else {\n if d_y < 0 {\n move_d = String::from(\"RD\");\n if abs_d_x < abs_d_y {\n move_s = String::from(\"D\");\n } else if abs_d_x == abs_d_y {\n move_s = String::from(\"\");\n } else {\n move_s = String::from(\"R\");\n }\n } else if d_y == 0 {\n move_s = String::from(\"R\");\n move_d = String::from(\"\");\n } else {\n move_d = String::from(\"RU\");\n if abs_d_x < abs_d_y {\n move_s = String::from(\"U\");\n } else if abs_d_x == abs_d_y {\n move_s = String::from(\"\");\n } else {\n move_s = String::from(\"R\");\n }\n }\n }\n (move_d, move_s)\n}\n\nfn print_path(s_x : i64, s_y : i64, t_x : i64, t_y : i64) {\n let d_x = t_x - s_x;\n let d_y = t_y - s_y;\n let abs_d_x = d_x.abs();\n let abs_d_y = d_y.abs();\n let n = max(abs_d_x, abs_d_y);\n let m = min(abs_d_x, abs_d_y);\n let (diagonal_move, straight_move) = get_moves(d_x, d_y);\n println!(\"{}\", n);\n for _ in 0 .. m {\n println!(\"{}\", diagonal_move);\n }\n for _ in 0 .. (n - m) {\n println!(\"{}\", straight_move);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let (s_x, s_y) = read_square(&stdin);\n let (t_x, t_y) = read_square(&stdin);\n print_path(s_x, s_y, t_x, t_y);\n}\n", "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let sent: String = scan.next();\n let received: String = scan.next();\n let mut pos: isize = 0;\n for mov in sent.chars() {\n if mov == '+' {\n pos += 1;\n } else if mov == '-' {\n pos -= 1;\n }\n }\n let mut new_pos: isize = 0;\n let mut unknown: isize = 0;\n for mov in received.chars() {\n if mov == '+' {\n new_pos += 1;\n } else if mov == '-' {\n new_pos -= 1;\n } else {\n unknown += 1;\n }\n }\n let needed = pos - new_pos;\n if needed > unknown {\n println!(\"{:.10}\", 0.0f64);\n } else {\n let total: usize = 2usize.pow(unknown as u32);\n let mut valid = 0isize;\n for i in 0..total {\n if (2 * i.count_ones() as isize - unknown as isize) == needed {\n valid += 1;\n }\n }\n let result = (valid as f64) / (total as f64);\n println!(\"{:.10}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "f7f68a15cfd33f641132fac265bc5299"} {"source_code": "//! http://codeforces.com/contest/265/problem/A\n\nfn main() {\n use std::io;\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let s = buf.trim().to_string();\n buf.clear();\n io::stdin().read_line(&mut buf).unwrap();\n let t = buf.trim().to_string();\n let ss = s.as_bytes();\n\n let mut i = 1;\n for &u in t.as_bytes() {\n if u == ss[i-1] { i += 1; }\n }\n println!(\"{}\", i);\n}\n", "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"source_code": "use std::io::stdin;\nuse std::vec::Vec;\nuse std::convert::From;\n\nfn main() {\n let mut mat : Vec> = vec![];\n for i in 0..6 {\n let mut input = \"\".to_string();\n stdin().read_line(&mut input).unwrap();\n mat.push(input.trim().chars().collect());\n }\n \n let idxs = vec![3, 4, 11, 12, 0, 1, 6, 7, 8, 9, 14, 15, 19, 20, 27, 28, 16, 17, 22, 23, 24, 25, 30, 31, 35, 36, 43, 44, 32, 33, 38, 39, 40, 41, 46, 47];\n \n for idx in idxs {\n if mat[idx / 8][idx % 8] == '.' {\n mat[idx / 8][idx % 8] = 'P';\n break\n }\n }\n \n for line in mat {\n for ch in line {\n print!(\"{}\", ch);\n }\n println!();\n }\n}", "src_uid": "35503a2aeb18c8c1b3eda9de2c6ce33e"} {"source_code": "\n#![allow(unused_imports)]\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::str::FromStr;\nuse std::collections::{VecDeque, HashMap};\n\nfn main() {\n let stdin = io::stdin();\n let mut input = stdin.lock();\n let mut line = String::new();\n input.read_line(&mut line).unwrap();\n let n = get_numbers::(&line)[0];\n line.clear();\n input.read_line(&mut line).unwrap();\n let arr = get_numbers::(&line);\n\n let min_i = arr.iter().position(|&v| v == 1).unwrap();\n let max_i = arr.iter().position(|&v| v == n).unwrap();\n\n let d_min = f64::abs(min_i as f64 - ((n-1) as f64 / 2.0)); // distance to center\n let d_max = f64::abs(max_i as f64 - ((n-1) as f64 / 2.0));\n \n // pick closest to center to move\n let d = if d_min < d_max {\n if min_i < max_i { // move min to 0\n max_i\n } else {\n (n-1)-max_i // move min to end\n }\n } else {\n if max_i < min_i {\n min_i\n } else {\n (n-1)-min_i\n }\n };\n\n println!(\"{}\", d);\n}\n\n/*\n * Utility Functions\n */\n\n// get numbers from line seperated by spaces\nfn get_numbers(line: &str) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n line.split_whitespace()\n .map(|chunk| chunk.parse::().expect(\"failed to parse\"))\n .collect()\n}\n\n", "src_uid": "1d2b81ce842f8c97656d96bddff4e8b4"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn get_mpf(n: u64) -> u64 {\n let mut d = 2;\n while d * d <= n {\n if n % d == 0 {\n return d;\n }\n d += 1;\n }\n n\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: u64 = scan.token();\n let mpf = get_mpf(n);\n let ans;\n if mpf % 2 != 0 {\n if n == mpf {\n ans = 1;\n } else {\n ans = 1 + (n - mpf) / get_mpf(n - mpf);\n }\n } else {\n ans = n / mpf;\n }\n writeln!(out, \"{}\", ans).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "a1e80ddd97026835a84f91bac8eb21e6"} {"source_code": "use std::collections::VecDeque;\n\nfn main() {\n let m: i32 = get_input().split_ascii_whitespace().last().unwrap().parse().unwrap();\n let children: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n\n let candies: Vec = children.iter().enumerate().map(|(index, value)| {\n let candy = Candy::new(*value, index + 1);\n candy\n }).collect();\n\n let mut stack = VecDeque::new();\n\n for candy in candies {\n stack.push_back(candy);\n };\n\n while stack.len() > 1 {\n let next = stack.pop_front().unwrap();\n let temp = next.value - m;\n\n if temp > 0 {\n stack.push_back(Candy::new(temp, next.index));\n }\n }\n \n\n println!(\"{}\", stack.pop_front().unwrap().index);\n}\n\n\nfn get_input() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Failed\");\n buffer.trim().to_owned()\n}\n\nfn get_input_usize() -> usize {\n get_input().parse().unwrap()\n}\n\n#[derive(Debug)]\nstruct Candy {\n value: i32, \n index: usize,\n}\n\nimpl Candy {\n pub fn new(value: i32, index: usize) -> Self {\n Candy {\n value, \n index\n }\n } \n}", "src_uid": "c0ef1e4d7df360c5c1e52bc6f16ca87c"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, [graph1; $len:expr]) => {{\n let mut g = vec![vec![]; $len];\n let ab = read_value!($next, [(usize1, usize1)]);\n for (a, b) in ab {\n g[a].push(b);\n g[b].push(a);\n }\n g\n }};\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n ($next:expr, usize1) => (read_value!($next, usize) - 1);\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n read_value!($next, [$t; len])\n }};\n ($next:expr, $t:ty) => ($next().parse::<$t>().expect(\"Parse error\"));\n}\n\n#[allow(unused)]\nmacro_rules! debug {\n ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());\n}\n#[allow(unused)]\nmacro_rules! debugln {\n ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());\n}\n\n/// Verified by https://atcoder.jp/contests/arc093/submissions/3968098\nmod mod_int {\n use std::ops::*;\n pub trait Mod: Copy { fn m() -> i64; }\n #[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]\n pub struct ModInt { pub x: i64, phantom: ::std::marker::PhantomData }\n impl ModInt {\n // x >= 0\n pub fn new(x: i64) -> Self { ModInt::new_internal(x % M::m()) }\n fn new_internal(x: i64) -> Self {\n ModInt { x: x, phantom: ::std::marker::PhantomData }\n }\n pub fn pow(self, mut e: i64) -> Self {\n debug_assert!(e >= 0);\n let mut sum = ModInt::new_internal(1);\n let mut cur = self;\n while e > 0 {\n if e % 2 != 0 { sum *= cur; }\n cur *= cur;\n e /= 2;\n }\n sum\n }\n #[allow(dead_code)]\n pub fn inv(self) -> Self { self.pow(M::m() - 2) }\n }\n impl>> Add for ModInt {\n type Output = Self;\n fn add(self, other: T) -> Self {\n let other = other.into();\n let mut sum = self.x + other.x;\n if sum >= M::m() { sum -= M::m(); }\n ModInt::new_internal(sum)\n }\n }\n impl>> Sub for ModInt {\n type Output = Self;\n fn sub(self, other: T) -> Self {\n let other = other.into();\n let mut sum = self.x - other.x;\n if sum < 0 { sum += M::m(); }\n ModInt::new_internal(sum)\n }\n }\n impl>> Mul for ModInt {\n type Output = Self;\n fn mul(self, other: T) -> Self { ModInt::new(self.x * other.into().x % M::m()) }\n }\n impl>> AddAssign for ModInt {\n fn add_assign(&mut self, other: T) { *self = *self + other; }\n }\n impl>> SubAssign for ModInt {\n fn sub_assign(&mut self, other: T) { *self = *self - other; }\n }\n impl>> MulAssign for ModInt {\n fn mul_assign(&mut self, other: T) { *self = *self * other; }\n }\n impl Neg for ModInt {\n type Output = Self;\n fn neg(self) -> Self { ModInt::new(0) - self }\n }\n impl ::std::fmt::Display for ModInt {\n fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {\n self.x.fmt(f)\n }\n }\n impl ::std::fmt::Debug for ModInt {\n fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {\n let (mut a, mut b, _) = red(self.x, M::m());\n if b < 0 {\n a = -a;\n b = -b;\n }\n write!(f, \"{}/{}\", a, b)\n }\n }\n impl From for ModInt {\n fn from(x: i64) -> Self { Self::new(x) }\n }\n // Finds the simplest fraction x/y congruent to r mod p.\n // The return value (x, y, z) satisfies x = y * r + z * p.\n fn red(r: i64, p: i64) -> (i64, i64, i64) {\n if r.abs() <= 10000 {\n return (r, 1, 0);\n }\n let mut nxt_r = p % r;\n let mut q = p / r;\n if 2 * nxt_r >= r {\n nxt_r -= r;\n q += 1;\n }\n if 2 * nxt_r <= -r {\n nxt_r += r;\n q -= 1;\n }\n let (x, z, y) = red(nxt_r, r);\n (x, y - q * z, z)\n }\n} // mod mod_int\n\nmacro_rules! define_mod {\n ($struct_name: ident, $modulo: expr) => {\n #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]\n struct $struct_name {}\n impl mod_int::Mod for $struct_name { fn m() -> i64 { $modulo } }\n }\n}\nconst MOD: i64 = 1_000_000_007;\ndefine_mod!(P, MOD);\ntype ModInt = mod_int::ModInt

;\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (let _ = write!(out,$($format)*););\n }\n input! {\n k: usize, pa: i64, pb: i64,\n }\n let mut dp = vec![vec![ModInt::new(0); k + 1]; k + 1];\n let pa = ModInt::new(pa);\n let pb = ModInt::new(pb);\n let pab = pa + pb;\n let pabinv = pab.inv();\n for i in (0..k).rev() {\n dp[i][k] = pa * pb.inv() + ModInt::new((i + k) as i64);\n for j in (1..k).rev() {\n let mut val = dp[i][j + 1] * pa;\n if i + j < k {\n val += dp[min(k, i + j)][j] * pb;\n } else {\n val += pb * ModInt::new((i + j) as i64);\n }\n dp[i][j] = val * pabinv;\n }\n let val = dp[i][1];\n dp[i][0] = val;\n }\n puts!(\"{}\\n\", dp[0][0]);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "0dc9f5d75143a2bc744480de859188b4"} {"source_code": "use std::collections::HashMap;\nuse std::io;\n\nfn main() {\n const BLOBS: &'static str = \"RBYG\";\n\n let mut failure_count: HashMap = HashMap::new();\n let mut pattern_position: HashMap = HashMap::new();\n\n let mut garland = String::new();\n\n io::stdin().read_line(&mut garland).unwrap();\n\n for (index, blob) in garland.chars().enumerate() {\n let position = index % BLOBS.len();\n match blob {\n '!' => {\n *failure_count.entry(position).or_insert(0) += 1;\n },\n x => {\n pattern_position.insert(x, position);\n }\n }\n }\n\n for blob in BLOBS.chars() {\n match pattern_position.get(&blob) {\n Some(position) => {\n print!(\"{} \", *failure_count.entry(*position).or_insert(0));\n },\n None => {\n println!(\"Cannot infer position of {} from input\", blob);\n }\n }\n }\n}", "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"source_code": "use std::io::{stdin, stdout, BufWriter, Write};\n\n#[derive(Default)]\nstruct Scanner {\n buffer: Vec,\n}\nimpl Scanner {\n #[inline]\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while b != 0 {\n let tmp = b;\n b = a % b;\n a = tmp;\n }\n a\n}\n\nfn lcm(a: u64, b: u64) -> u64 {\n let gcd_ab = gcd(a, b);\n a / gcd_ab * b / gcd_ab\n}\n\nfn main() {\n let mut scan = Scanner::default();\n let out = &mut BufWriter::new(stdout());\n let n = scan.next::();\n let mut mx = n;\n let mut p = 1;\n let mut i = 2;\n while i * i <= n {\n if n % i == 0 {\n let b = n / i;\n if lcm(i, b) == n && b < mx {\n p = i;\n mx = b;\n }\n }\n i += 1;\n }\n writeln!(out, \"{} {}\", p, mx).ok();\n}\n", "src_uid": "e504a04cefef3da093573f9df711bcea"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n\nmacro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn main() {\n let (n,x) = readln!(i64,i64);\n let mut res = 0;\n for i in 1..(n+1) {\n if x%i == 0 && x/i <= n{\n res += 1;\n }\n }\n println!(\"{}\",res);\n}\n", "src_uid": "c4b139eadca94201596f1305b2f76496"} {"source_code": "// ---------- begin ModInt ----------\nconst MOD: u32 = 1_000_000_007;\n\n#[derive(Clone, Copy)]\nstruct ModInt(u32);\n\nimpl std::ops::Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::AddAssign for ModInt {\n fn add_assign(&mut self, rhs: ModInt) {\n *self = *self + rhs;\n }\n}\n\nimpl std::ops::Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + MOD - rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: ModInt) {\n *self = *self - rhs;\n }\n}\n\nimpl std::ops::Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: ModInt) -> Self::Output {\n ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)\n }\n}\n\nimpl std::ops::MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: ModInt) {\n *self = *self * rhs;\n }\n}\n\nimpl std::ops::Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n ModInt(if self.0 == 0 {0} else {MOD - self.0})\n }\n}\n\n/* \nimpl std::fmt::Display for ModInt {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n*/\n\n#[allow(dead_code)]\nimpl ModInt {\n pub fn new(n: u32) -> ModInt {\n ModInt(n % MOD)\n }\n pub fn zero() -> ModInt {\n ModInt(0)\n }\n pub fn one() -> ModInt {\n ModInt(1)\n }\n pub fn pow(self, mut n: u32) -> ModInt {\n let mut t = ModInt::one();\n let mut s = self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(self) -> ModInt {\n self.pow(MOD - 2)\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\n#[allow(dead_code)]\nstruct Precalc {\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n}\n\n#[allow(dead_code)]\nimpl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);\n fact[i] = fact[i - 1] * ModInt(i as u32);\n ifact[i] = ifact[i - 1] * inv[i];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n}\n// ---------- end Precalc ----------\n\nfn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n: usize = s.trim().parse().unwrap();\n let mut len = 0;\n while (2 << len) <= n {\n len += 1;\n }\n let mut cnt = vec![0; len + 2];\n for i in 0..=len {\n cnt[i] = n / (1 << i);\n }\n let mut dp = vec![ModInt::zero(); len + 2];\n dp[len] = ModInt::one();\n for i in 1..n {\n let mut next = vec![ModInt::zero(); len + 2];\n for j in 0..len {\n if cnt[j] > i {\n next[j] += dp[j] * ModInt((cnt[j] - i) as u32);\n next[j] += dp[j + 1] * ModInt((cnt[j] - cnt[j + 1]) as u32);\n }\n }\n dp = next;\n }\n let mut ans = dp[0];\n if (1 << len) / 2 * 3 <= n {\n let len = len - 1;\n let mut cnt = vec![vec![0; len + 2]; 2];\n for i in 0..=len {\n cnt[0][i] = n / (1 << i);\n cnt[1][i] = n / (1 << i) / 3;\n }\n let mut dp = vec![vec![ModInt::zero(); len + 2]; 2];\n dp[1][len] = ModInt::one();\n for i in 1..n {\n let mut next = vec![vec![ModInt::zero(); len + 2]; 2];\n for j in 0..=len {\n if cnt[0][j] > i {\n next[0][j] += dp[0][j] * ModInt((cnt[0][j] - i) as u32);\n next[0][j] += dp[1][j] * ModInt((cnt[0][j] - cnt[1][j]) as u32);\n next[0][j] += dp[0][j + 1] * ModInt((cnt[0][j] - cnt[0][j + 1]) as u32);\n }\n if cnt[1][j] > i {\n next[1][j] += dp[1][j] * ModInt((cnt[1][j] - i) as u32);\n next[1][j] += dp[1][j + 1] * ModInt((cnt[1][j] - cnt[1][j + 1]) as u32);\n }\n }\n dp = next;\n }\n ans += dp[0][0];\n }\n println!(\"{}\", ans.0);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "b2d59b1279d891dba9372a52364bced2"} {"source_code": "#![allow(non_snake_case, unused_imports, deprecated, dead_code)]\n\n// Input macros\nmacro_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)*} }; }\nmacro_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)*} }; }\nmacro_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::>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($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\") }; }\n\n// Module\nuse std::cmp::{min,max};\nuse std::collections::{VecDeque,HashMap,HashSet,BTreeMap,BTreeSet,BinaryHeap};\n// Module for v1.15.1\nuse std::ascii::AsciiExt; // deprecated since 1.26.0: use inherent method instead\n\n// Functions\n\n// Main\nfn main() {\n\n input! {\n N: usize,\n T: usize,\n mut S: chars\n }\n\n for _ in 0..T {\n let mut ci = vec![];\n for i in 0..N-1 {\n if S[i]=='B' && S[i+1]=='G' {\n ci.push(i);\n }\n }\n for i in ci {\n S[i] = 'G';\n S[i+1] = 'B';\n }\n }\n\n println!(\"{}\", S.iter().collect::());\n}", "src_uid": "964ed316c6e6715120039b0219cc653a"} {"source_code": "use std::io;\r\nuse std::io::Write;\r\n\r\n/**************************************************\r\n\r\n START OF TEMPLATE CODE\r\n\r\n *************************************************/\r\n#[allow(unused_macros)]\r\nmacro_rules! dbg {\r\n ($first_val:expr, $($val:expr),+ $(,)?) => {\r\n eprint!(\"[{}:{}] {} = {:?}\",\r\n file!(), line!(), stringify!($first_val), &$first_val);\r\n ($(eprint!(\", {} = {:?}\", stringify!($val), &$val)),+,);\r\n eprintln!();\r\n };\r\n ($first_val:expr) => {\r\n eprintln!(\"[{}:{}] {} = {:?}\",\r\n file!(), line!(), stringify!($first_val), &$first_val);\r\n };\r\n}\r\n\r\nenum InputSource {\r\n Stdin,\r\n FromFile(Vec),\r\n}\r\n\r\nstruct Scanner {\r\n buffer: Vec,\r\n input_source: InputSource,\r\n}\r\n\r\n\r\nimpl Scanner {\r\n #[allow(dead_code)]\r\n fn new() -> Self {\r\n Self { buffer: vec![], input_source: InputSource::Stdin }\r\n }\r\n\r\n #[allow(dead_code)]\r\n fn new_file(filename: &str) -> Self {\r\n let file = std::fs::read_to_string(filename).unwrap();\r\n let mut lines: Vec = file.lines().map(|line| String::from(line)).collect();\r\n lines.reverse();\r\n Self { buffer: vec![], input_source: InputSource::FromFile(lines) }\r\n }\r\n\r\n\r\n #[allow(dead_code)]\r\n fn i64(&mut self) -> i64 {\r\n self.next::()\r\n }\r\n\r\n #[allow(dead_code)]\r\n fn i32(&mut self) -> i32 {\r\n self.next::()\r\n }\r\n\r\n #[allow(dead_code)]\r\n fn usize(&mut self) -> usize {\r\n self.next::()\r\n }\r\n\r\n #[allow(dead_code)]\r\n fn vec(&mut self, n: usize) -> Vec {\r\n (0..n).map(|_| self.next::()).collect()\r\n }\r\n\r\n fn parse_next_line(&mut self) -> bool {\r\n let mut input = String::new();\r\n match &mut self.input_source {\r\n | InputSource::Stdin => {\r\n if std::io::stdin().read_line(&mut input).expect(\"Failed read\") == 0 {\r\n return false;\r\n }\r\n }\r\n | InputSource::FromFile(lines) => {\r\n match lines.pop() {\r\n Some(line) => input = line,\r\n None => return false,\r\n }\r\n }\r\n }\r\n\r\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\r\n return true;\r\n }\r\n\r\n fn next(&mut self) -> T {\r\n loop {\r\n if let Some(token) = self.buffer.pop() {\r\n return token.parse().ok().expect(\"Failed parse\");\r\n }\r\n\r\n self.parse_next_line();\r\n }\r\n }\r\n\r\n #[allow(dead_code)]\r\n fn has_more_elements(&mut self) -> bool {\r\n loop {\r\n if !self.buffer.is_empty() {\r\n return true;\r\n }\r\n if !self.parse_next_line() {\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n\r\n #[allow(dead_code)]\r\n fn string(&mut self) -> Vec {\r\n self.next::().into_bytes()\r\n }\r\n}\r\n\r\nmod modulo {\r\n const MODULO: i32 = 998244353;\r\n\r\n #[derive(Copy, Clone, Eq, PartialEq)]\r\n pub struct Mod(i32);\r\n\r\n impl Mod {\r\n #[allow(unused)]\r\n pub const ZERO: Self = Self(0);\r\n\r\n #[allow(unused)]\r\n pub const ONE: Self = Self(1);\r\n\r\n fn rev_rec(a: i32, m: i32) -> i32 {\r\n if a == 1 {\r\n return a;\r\n }\r\n return ((1 - Self::rev_rec(m % a, a) as i64 * m as i64) / a as i64 + m as i64) as i32;\r\n }\r\n\r\n #[allow(dead_code)]\r\n fn inv(self) -> Mod {\r\n Mod(Self::rev_rec(self.0, MODULO))\r\n }\r\n\r\n #[allow(dead_code)]\r\n pub fn new(mut x: i32) -> Self {\r\n if x < 0 {\r\n x += MODULO;\r\n } else if x >= MODULO {\r\n x -= MODULO;\r\n }\r\n assert!(0 <= x && x < MODULO);\r\n Self(x)\r\n }\r\n }\r\n\r\n impl std::fmt::Display for Mod {\r\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\r\n write!(f, \"{}\", self.0)\r\n }\r\n }\r\n\r\n impl std::fmt::Debug for Mod {\r\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\r\n const MAX: usize = 100;\r\n if self.0 <= MAX as i32 {\r\n write!(f, \"{}\", self.0)\r\n } else if self.0 >= MODULO - MAX as i32 {\r\n write!(f, \"-{}\", MODULO - self.0)\r\n } else {\r\n for denum in 1..MAX {\r\n for num in 1..MAX {\r\n if Mod(num as i32) / Mod(denum as i32) == *self {\r\n return write!(f, \"{}/{}\", num, denum);\r\n }\r\n }\r\n }\r\n write!(f, \"(?? {} ??)\", self.0)\r\n }\r\n }\r\n }\r\n\r\n impl std::ops::Add for Mod {\r\n type Output = Mod;\r\n\r\n fn add(self, rhs: Self) -> Self::Output {\r\n let res = self.0 + rhs.0;\r\n if res >= MODULO {\r\n Mod(res - MODULO)\r\n } else {\r\n Mod(res)\r\n }\r\n }\r\n }\r\n\r\n impl std::ops::AddAssign for Mod {\r\n fn add_assign(&mut self, rhs: Self) {\r\n self.0 += rhs.0;\r\n if self.0 >= MODULO {\r\n self.0 -= MODULO;\r\n }\r\n }\r\n }\r\n\r\n impl std::ops::Sub for Mod {\r\n type Output = Mod;\r\n\r\n fn sub(self, rhs: Self) -> Self::Output {\r\n let res = self.0 - rhs.0;\r\n if res < 0 {\r\n Mod(res + MODULO)\r\n } else {\r\n Mod(res)\r\n }\r\n }\r\n }\r\n\r\n impl std::ops::SubAssign for Mod {\r\n fn sub_assign(&mut self, rhs: Self) {\r\n self.0 -= rhs.0;\r\n if self.0 < 0 {\r\n self.0 += MODULO;\r\n }\r\n }\r\n }\r\n\r\n impl std::ops::Mul for Mod {\r\n type Output = Mod;\r\n\r\n fn mul(self, rhs: Self) -> Self::Output {\r\n let res = (self.0 as i64) * (rhs.0 as i64) % (MODULO as i64);\r\n Mod(res as i32)\r\n }\r\n }\r\n\r\n impl std::ops::MulAssign for Mod {\r\n fn mul_assign(&mut self, rhs: Self) {\r\n self.0 = ((self.0 as i64) * (rhs.0 as i64) % (MODULO as i64)) as i32;\r\n }\r\n }\r\n\r\n impl std::ops::Div for Mod {\r\n type Output = Mod;\r\n\r\n fn div(self, rhs: Self) -> Self::Output {\r\n let rhs_inv = rhs.inv();\r\n self * rhs_inv\r\n }\r\n }\r\n\r\n impl std::ops::DivAssign for Mod {\r\n fn div_assign(&mut self, rhs: Self) {\r\n *self *= rhs.inv();\r\n }\r\n }\r\n}\r\n\r\nuse modulo::*;\r\n\r\n/**************************************************\r\n\r\n END OF TEMPLATE CODE\r\n\r\n *************************************************/\r\n\r\n\r\npub fn main() {\r\n let stdout = io::stdout();\r\n let mut out = std::io::BufWriter::new(stdout.lock());\r\n let mut sc = Scanner::new();\r\n\r\n let n = sc.usize();\r\n let mut res = vec![Mod::ZERO; n + 1];\r\n for delta in 1..=n {\r\n for sum in (delta..=n).step_by(delta) {\r\n res[sum] += Mod::ONE;\r\n }\r\n }\r\n let mut sum = Mod::ZERO;\r\n for i in 0..=n {\r\n res[i] += sum;\r\n sum += res[i];\r\n }\r\n writeln!(out, \"{}\", res[n]).unwrap();\r\n}\r\n", "src_uid": "09be46206a151c237dc9912df7e0f057"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\n//const INF: i32 = 0x3f3f3f3f;\n\nstruct Scanner {\n buffer: std::collections::VecDeque\n}\n\nimpl Scanner {\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn next(&mut self) -> T {\n while self.buffer.is_empty() {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n self.buffer = input.split_whitespace()\n .map(ToString::to_string).collect();\n }\n let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn gcd(a: i64, b: i64) -> i64 {\n if b == 0 {\n return a\n }\n else {\n return gcd(b, a % b);\n }\n}\n\nfn main1() {\n let mut scan = Scanner::new();\n let n = scan.next::();\n let k = scan.next::();\n let a = scan.next::();\n let b = scan.next::();\n let len = n * k;\n \n // all offsets are in [0, k]\n let mut offsets = vec![a+b, max(a,b)-min(a,b)];\n let neg1 = k - offsets[0];\n let neg2 = k - offsets[1];\n offsets.push(neg1);\n offsets.push(neg2);\n \n let mut lo = len;\n let mut hi = 0;\n for offset in offsets {\n for i in 0..n {\n let l = offset + k * i;\n let stops = len / gcd(l, len);\n lo = min(lo, stops);\n hi = max(hi, stops);\n }\n }\n println!(\"{} {}\", lo, hi);\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}", "src_uid": "5bb4adff1b332f43144047955eefba0c"} {"source_code": "#[allow(unused_macros)]\nmacro_rules! scan {\n () => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n };\n (;;$n:expr) => {\n (0..$n).map(|_| scan!()).collect::>()\n };\n ($t:ty) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty;;) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n ($t:ty;;$n:expr) => {\n (0..$n).map(|_| scan!($t;;)).collect::>()\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n scan!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n scan!($($t),*)\n ).collect::>()\n };\n}\n\nfn main() {\n let (w1, h1, w2, h2) = scan!(i64, i64, i64, i64);\n println!(\"{}\", w1 + 2 * h1 + 4 + w2 + 2 * h2 + w1 - w2);\n}\n", "src_uid": "b5d44e0041053c996938aadd1b3865f6"} {"source_code": "\n#![allow(unused_imports)]\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::str::FromStr;\nuse std::collections::{VecDeque, HashMap};\nuse std::ops::Sub;\n\nfn main() {\n let stdin = io::stdin();\n let mut input = stdin.lock();\n let mut line = String::new();\n input.read_line(&mut line).unwrap();\n let x = get_numbers(&line)[0];\n line.clear(); input.read_line(&mut line).unwrap();\n let nums = get_numbers(&line);\n\n let get_up = Time::new(nums[0], nums[1]);\n\n let mut snoozed = 0;\n let mut cur_time = get_up;\n while cur_time.lucky() == false {\n cur_time = cur_time - x;\n snoozed += 1;\n //println!(\"{} -> {}:{}\", snoozed, cur_time.hh, cur_time.mm);\n }\n\n println!(\"{}\", snoozed);\n}\n\n#[derive(Debug, Clone, Copy)]\nstruct Time {\n hh: u8,\n mm: u8,\n}\n\nimpl Time {\n fn new(hour: u8, min: u8) -> Time {\n Time {\n hh: hour,\n mm: min,\n }\n }\n\n fn lucky(&self) -> bool {\n // 7 cannot be appear in the 10s spot so we only have to check ones\n self.mm % 10 == 7 || self.hh % 10 == 7\n }\n}\n\nimpl Sub for Time {\n type Output = Time;\n\n fn sub(self, mins: u8) -> Time {\n if mins <= self.mm {\n Time { hh: self.hh, mm: self.mm - mins }\n } else if self.hh >= 1 {\n Time { hh: self.hh - 1, mm: self.mm + 60 - mins }\n } else {\n // going back a day\n Time { hh: 23, mm: self.mm + 60 - mins }\n }\n }\n}\n\n/*\n * Utility Functions\n */\n\n// get numbers from line seperated by spaces\nfn get_numbers(line: &str) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n line.split_whitespace()\n .map(|chunk| chunk.parse::().expect(\"failed to parse\"))\n .collect()\n}\n\n", "src_uid": "5ecd569e02e0164a5da9ff549fca3ceb"} {"source_code": "use std::io;\n\nfn solve(n :i32, x :i32, numbers :&Vec) -> i32 {\n let mut r = 0;\n for elem in numbers.iter() {\n if elem > &x {\n break;\n } else if elem < &x {\n r = r + 1;\n } else {\n r = r - 1;\n }\n }\n x - r\n}\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input).expect(\"io error\");\n let arr: Vec = input.trim_right().split_whitespace().map(|x| {\n let r: i32 = x.parse().expect(\"not a number\");\n r\n }).collect();\n let n = arr[0];\n let x = arr[1];\n input.clear();\n io::stdin().read_line(&mut input).expect(\"io error\");\n let mut numbers: Vec = input.trim_right().split_whitespace().map(|x| {\n let r: i32 = x.parse().expect(\"not a number\");\n r\n }).collect();\n numbers.sort();\n println!(\"{}\", solve(n, x, numbers.as_ref()));\n}\n", "src_uid": "21f579ba807face432a7664091581cd8"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::io::stdin;\nmod util {\n use std::io::stdin;\n use std::str::FromStr;\n use std::fmt::Debug;\n #[allow(dead_code)]\n pub fn line() -> String {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n #[allow(dead_code)]\n pub fn gets() -> Vec\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse().unwrap())\n .collect()\n }\n}\n#[allow(unused_macros)]\nmacro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) ; } }\n\nuse std::cmp::Reverse;\n\nfn main() {\n let mut aa: Vec = util::line().chars().collect();\n let bb: Vec = util::line().chars().collect();\n\n let mut amap = HashMap::new();\n let mut bmap = HashMap::new();\n\n for &a in &aa {\n *amap.entry(a).or_insert(0) += 1;\n }\n\n for &b in &bb {\n *bmap.entry(b).or_insert(0) += 1;\n }\n\n if amap == bmap {\n println!(\n \"{}\",\n bb.iter()\n .map(|x| x.to_string())\n .collect::>()\n .join(\"\")\n );\n return;\n }\n\n if aa.len() < bb.len() {\n aa.sort_by_key(|&x| Reverse(x));\n println!(\n \"{}\",\n aa.iter()\n .map(|x| x.to_string())\n .collect::>()\n .join(\"\")\n );\n return;\n }\n\n let ans = (0..aa.len())\n .filter_map(|i| {\n let mut res = Vec::new();\n let mut amap = amap.clone();\n\n for &b in &bb[..i] {\n let c = amap.entry(b).or_insert(0);\n if *c > 0 {\n *c -= 1;\n res.push(b);\n } else {\n return None;\n }\n }\n\n if let Some((&x, _)) = amap.iter().filter(|&(&k, &v)| v > 0 && k < bb[i]).max() {\n res.push(x);\n *amap.entry(x).or_insert(0) -= 1;\n } else {\n return None;\n }\n\n let mut rest = Vec::new();\n for (&k, &v) in amap.iter() {\n for _ in 0..v {\n rest.push(k);\n }\n }\n\n rest.sort_by_key(|&x| Reverse(x));\n\n res.append(&mut rest);\n\n Some(res)\n })\n .max()\n .unwrap();\n\n println!(\n \"{}\",\n ans.iter()\n .map(|x| x.to_string())\n .collect::>()\n .join(\"\")\n );\n}\n", "src_uid": "bc31a1d4a02a0011eb9f5c754501cd44"} {"source_code": "// https://codeforces.com/problemset/problem/750/A\nuse std::io;\n\nfn cumulative(n: i64) -> i64 {\n let mut sum = 0;\n for i in 1..n+1 {\n sum += i*5;\n }\n sum\n}\n\nfn main() {\n let mut line = String::new();\n\n io::stdin()\n .read_line(&mut line)\n .unwrap();\n\n let words: Vec =\n line\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let n = words[0];\n let k = words[1];\n\n let mut left = 0;\n let mut right = n;\n\n while left <= right {\n let middle = (right+left)/2;\n if (cumulative(middle)+k) <= 240 {\n left = middle+1;\n } else {\n right = middle-1;\n }\n }\n println!(\"{}\", right);\n}\n\n", "src_uid": "41e554bc323857be7b8483ee358a35e2"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::*;\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok();\n return ret;\n}\nfn get_word() -> String {\n let mut stdin = std::io::stdin();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = std::string::String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\nfn parse(s: &str) -> T { s.parse::().ok().unwrap() }\n\n#[allow(dead_code)]\nfn get() -> T { parse(&get_word()) }\n\nfn main() {\n let k: i64 = get();\n let a: i64 = get();\n let b: i64 = get();\n let aq = a / k;\n let bq = b / k;\n let res: i64 = if (aq == 0 && b % k != 0) || (bq == 0 && a % k != 0) {\n -1\n } else {\n a / k + b / k\n };\n println!(\"{}\", res);\n}\n", "src_uid": "6e3b8193d1ca1a1d449dc7a4ad45b8f2"} {"source_code": "#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]\nuse std::io::{stdin, Read, StdinLock};\nuse std::str::FromStr;\nuse std::fmt::*;\nuse std::str::*;\nuse std::cmp::*;\nuse std::collections::*;\nfn getline() -> String {\n let mut res = String::new();\n std::io::stdin().read_line(&mut res).ok();\n res\n}\nmacro_rules ! readl { ( $ t : ty ) => { { let s = getline ( ) ; s . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,+ ) => { { let s = getline ( ) ; let mut iter = s . trim ( ) . split ( ' ' ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; }\nmacro_rules ! readlvec { ( $ t : ty ) => { { let s = getline ( ) ; let iter = s . trim ( ) . split ( ' ' ) ; iter . map ( | x | x . parse ( ) . unwrap ( ) ) . collect ::< Vec <$ t >> ( ) } } }\nmacro_rules ! mvec { ( $ v : expr , $ s : expr ) => { vec ! [ $ v ; $ s ] } ; ( $ v : expr , $ s : expr , $ ( $ t : expr ) ,* ) => { vec ! [ mvec ! ( $ v , $ ( $ t ) ,* ) ; $ s ] } ; }\nmacro_rules ! debug { ( $ x : expr ) => { println ! ( \"{}: {:?}\" , stringify ! ( $ x ) , $ x ) } }\nfn printiter<'a, T>(v: &'a T)\nwhere\n &'a T: std::iter::IntoIterator,\n <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display,\n{\n for (i, e) in v.into_iter().enumerate() {\n if i != 0 {\n print!(\" \");\n }\n print!(\"{}\", e);\n }\n println!(\"\");\n}\nstruct ContestPrinter {\n s: String,\n}\nimpl ContestPrinter {\n fn new() -> ContestPrinter {\n ContestPrinter { s: String::new() }\n }\n fn print(&mut self, x: T)\n where\n T: std::fmt::Display,\n {\n self.s.push_str(format!(\"{}\", x).as_str());\n }\n fn println(&mut self, x: T)\n where\n T: std::fmt::Display,\n {\n self.s.push_str(format!(\"{}\\n\", x).as_str());\n }\n}\nimpl std::ops::Drop for ContestPrinter {\n fn drop(&mut self) {\n print!(\"{}\", self.s);\n }\n}\nstatic MOD: i64 = 1e9 as i64 + 7;\nfn is_max_i64(num: i64) -> bool {\n if num == i64::max_value() {\n true\n } else {\n false\n }\n}\nfn main() {\n let mut pr = ContestPrinter::new();\n let N = readl!(usize);\n let s = readl!(String);\n let sc = s.chars().collect::>();\n let mut idx = 1;\n let mut ans = 1;\n if N == 1 {\n pr.println(1);\n return;\n }\n while idx < N {\n if ((sc[idx - 1] == 'R') & (sc[idx] == 'U')) |\n ((sc[idx - 1] == 'U') & (sc[idx] == 'R')) {\n idx += 1;\n }\n idx += 1;\n if idx <= N { ans += 1; }\n }\n pr.println(ans);\n}", "src_uid": "986ae418ce82435badadb0bd5588f45b"} {"source_code": "use std::io;\nfn main(){\n let mut s:String=String::new();\n io::stdin().read_line(&mut s).unwrap();\n let mut c:usize=0;\n let mut n:usize=0;\n let mut a:Vec=Vec::new();\n while c=Vec::new();\n while ca/b[c] && a%b[c]==0{\n n=a/b[c];\n }\n }\n println!(\"{}\",n)\n}", "src_uid": "80520be9916045aca3a7de7bc925af1f"} {"source_code": "use std::io;\nuse std::str;\n\nfn count_bits(n: u64) -> u64 {\n let mut n = n;\n let mut ans = 0;\n while n > 0 {\n ans += 1;\n n >>= 1;\n }\n ans\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: u64 = scan.token();\n let k: u64 = scan.token();\n // Maximize the xor-sum of at most k numbers from 1 to n\n // For any bit pattern that represents a positive number, its negation is always less than the number itself.\n // For example, n = 6 = 110 -> neg(n) = 001\n // n ^ neg(n) = 111\n // The answer is num_bits(n) ones, if k >= 2\n if k == 1 {\n writeln!(out, \"{}\", n).ok();\n return;\n }\n let num_bits = count_bits(n);\n let mut ans = 0u64;\n for i in 0..(num_bits) {\n ans = ans | (1 << i);\n }\n writeln!(out, \"{}\", ans).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n\n pub fn tokens(&mut self) -> Vec {\n assert!(self.buffer.is_empty());\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n input\n .split_whitespace()\n .map(|x| x.parse().ok().expect(\"Failed parse\"))\n .collect()\n }\n}\n", "src_uid": "16bc089f5ef6b68bebe8eda6ead2eab9"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nfn run() {\n input! {\n a: usize,\n b: usize,\n c: usize,\n }\n if a <= std::cmp::min(b, c) {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n}\n\nfn main() {\n run();\n}\n", "src_uid": "6cd07298b23cc6ce994bb1811b9629c4"} {"source_code": "//! http://codeforces.com/contest/80/problem/A\n\n#[macro_export]\nmacro_rules! scanln {\n ($($var:ident : $ty:path),+) => {\n $(let $var: $ty;)+\n {\n use std::io;\n let mut __buf = String::new();\n io::stdin().read_line(&mut __buf).unwrap();\n let mut eles = __buf.split_whitespace();\n $($var = Scan::scan(&mut eles);)+\n }\n }\n}\n\npub trait Scan {\n fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator;\n}\n\nmacro_rules! impl_scan_single {\n ($ty:ty) => {\n impl Scan for $ty {\n fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator {\n let next = eles.next().unwrap();\n match next.parse() {\n Ok(res) => res,\n Err(_) => panic!()\n }\n }\n }\n }\n}\n\nimpl_scan_single!(u8);\nimpl_scan_single!(u16);\nimpl_scan_single!(u32);\nimpl_scan_single!(u64);\nimpl_scan_single!(usize);\nimpl_scan_single!(i8);\nimpl_scan_single!(i16);\nimpl_scan_single!(i32);\nimpl_scan_single!(i64);\nimpl_scan_single!(f32);\nimpl_scan_single!(f64);\nimpl_scan_single!(isize);\nimpl_scan_single!(String);\n\nconst __IMPL_SCAN_FOR_VEC: () = {\n use std::str::FromStr;\n impl Scan for Vec where T: FromStr {\n fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator {\n eles.map(|str| match str.parse() {\n Ok(res) => res,\n Err(_) => panic!()\n }).collect()\n }\n }\n};\n\n// -----------------------------------------------------------------------------\n\nfn main() {\n let mut sieve = vec![true; 51];\n for i in 2..50 {\n let mut j = 2 * i;\n while j < 51 {\n sieve[j] = false;\n j += i;\n }\n }\n scanln!(n: usize, m: usize);\n let mut next_prime = n;\n for i in n+1..51 {\n if sieve[i] { next_prime = i; break; }\n }\n if next_prime == m {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"source_code": "#![allow(unused_macros)]\n#![allow(unused_mut)]\n\n#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io;\nuse std::io::Write;\nuse std::str;\n#[allow(unused_imports)]\nuse std::prelude::*;\n\n// credit tanakh input macro\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let mut s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// credit ebtech scanner\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: str::SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n}\n\n\nfn solve() {\n #[allow(unused_variables)]\n let (stdin, stdout) = (io::stdin(), io::stdout());\n //let mut scan = UnsafeScanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n\n input! {\n a: usize,\n s: String,\n }\n let mut v = Vec::new();\n for c in s.chars() {\n v.push(c);\n }\n\n if a == 1 { writeln!(out, \"{}\", 0).ok();}\n else {\n let mut op = 0;\n for i in 0..(v.len() - 1) {\n if v[i] == v[i+1] {\n op += 1;\n }\n }\n writeln!(out, \"{}\", op).ok();\n }\n\n}\n\n\n// credit kobae964\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}", "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::io::{stdin, stdout, BufWriter, StdoutLock, Write};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_macros)]\nmacro_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 ) * } } ; }\n#[allow(unused_macros)]\nmacro_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 ) * } } ; }\n#[allow(unused_macros)]\nmacro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( \"Parse error\" ) } ; }\n#[allow(dead_code)]\npub fn with_bufwriter) -> ()>(f: F) {\n let out = stdout();\n let writer = BufWriter::new(out.lock());\n f(writer)\n}\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) } ; }\n#[allow(dead_code)]\nfn main() {\n input!{\n w: i64,\n h: i64,\n u1: i64,\n d1: i64,\n u2: i64,\n d2: i64,\n }\n let mut ans = w;\n let mut height = h;\n while height > 0 {\n ans += height;\n if d1 == height {\n ans -= u1;\n }\n if d2 == height {\n ans -= u2;\n }\n if ans < 0 {\n ans = 0;\n }\n height -= 1;\n }\n println!(\"{}\", ans);\n}", "src_uid": "084a12eb3a708b43b880734f3ee51374"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap,HashSet,VecDeque};\n\n#[allow(unused_macros)]\nmacro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn main() {\n let mut s = String::from(\"A\");\n s += readln!().as_ref();\n s += \"A\";\n let v : Vec = s.chars().enumerate().filter(|&(i,c)|c=='A' || c=='E' || c=='I' || c=='O' || c=='U' || c=='Y').map(|(i,c)|i).collect();\n let u : usize = v.iter().skip(1).zip(v.iter()).map(|(i,j)|i-j).max().unwrap();\n println!(\"{}\",u);\n}\n", "src_uid": "1fc7e939cdeb015fe31f3cf1c0982fee"} {"source_code": "use std::io::{self};\n\nfn is_paly(x: i32) -> bool {\n let h = (x / 60) % 24;\n let m = x % 60;\n h % 10 * 10 + h / 10 == m\n}\n\nfn find_paly(x: i32) -> i32 {\n for i in x..3000{\n if is_paly(i) {return i - x}\n }\n -1\n}\n\nfn read_time() -> Result {\n let mut str = String::new();\n try!(io::stdin().read_line(&mut str).map_err(|e| e.to_string()));\n let parts: Vec<&str> = str.split(':').collect();\n if parts.len() != 2 { return Err(String::from(\"wrong format, should have single : delimiter\")) };\n let x = try!(parts[0].trim().parse::().map_err(|e|e.to_string()));\n let y = try!(parts[1].trim().parse::().map_err(|e|e.to_string()));\n Ok(x * 60 + y)\n}\n\nfn main() {\n let tt = read_time().unwrap();\n print!(\"{}\", find_paly(tt));\n}\n", "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next_line(&self) -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n line\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let line = self.next_line();\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: usize = scan.next();\n println!(\n \"{}\",\n match n {\n 11..=19 | 21 => {\n 4\n }\n 20 => {\n 15\n }\n _ => {\n 0\n }\n }\n );\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "5802f52caff6015f21b80872274ab16c"} {"source_code": "#![allow(non_snake_case, unused_imports, deprecated, dead_code)]\n\n// Input macros\nmacro_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)*} }; }\nmacro_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)*} }; }\nmacro_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::>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($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\") }; }\n\n// Module\nuse std::cmp::{min,max};\nuse std::collections::{VecDeque,HashSet,HashMap,BinaryHeap};\n// Module for v1.15.1\nuse std::ascii::AsciiExt; // deprecated since 1.26.0: use inherent method instead\n\n// Functions\n\n// Main\nfn main() {\n\n input! {\n N: chars,\n }\n \n let mut ans = \"YES\";\n let mut cnt_4 = 0; \n\n // \u6700\u4e0a\u4f4d\u306f 1 \u5fc5\u9808\n if N[0] != '1' {\n ans = \"NO\";\n } else {\n for i in 1..N.len() {\n if N[i] == '1' {\n cnt_4 = 0;\n continue;\n // 4 \u306f\u9023\u7d9a2\u56de\u307e\u3067\n } else if N[i] == '4' {\n cnt_4 += 1;\n if cnt_4 > 2 {\n ans = \"NO\";\n break;\n }\n } else {\n ans = \"NO\";\n break;\n }\n }\n }\n println!(\"{}\", ans);\n}", "src_uid": "3153cfddae27fbd817caaf2cb7a6a4b5"} {"source_code": "use std::collections::HashSet;\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s);\n let s = s.trim();\n\n let count: HashSet<_> = s.chars().collect();\n if count.contains(&'H') || count.contains(&'Q') || count.contains(&'9') {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::io::stdin;\n\nmod util {\n use std::io::stdin;\n use std::str::FromStr;\n use std::fmt::Debug;\n\n #[allow(dead_code)]\n pub fn line() -> String {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn gets() -> Vec\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse().unwrap())\n .collect()\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn f(i: usize, k: u64, ll: &Vec) -> char {\n let mut i = i;\n let mut k = k;\n\n loop {\n if i == 0 {\n let f0 = \"What are you doing at the end of the world? Are you busy? Will you save us?\";\n return if f0.len() as u64 > k {\n f0.chars().nth(k as usize).unwrap()\n } else {\n '.'\n };\n } else {\n if k < 34 {\n let s1 = \"What are you doing while sending \\\"\";\n return s1.chars().nth(k as usize).unwrap();\n } else if k < 34 + ll[i - 1] {\n // f(i - 1, k - 34, ll)\n i -= 1;\n k -= 34;\n } else if k < 34 + ll[i - 1] + 32 {\n let s2 = \"\\\"? Are you busy? Will you send \\\"\";\n return s2.chars().nth((k - 34 - ll[i - 1]) as usize).unwrap();\n } else if k < 34 + ll[i - 1] + 32 + ll[i - 1] {\n // f(i - 1, k - 34 - ll[i - 1] - 32, ll)\n k -= 34 + ll[i - 1] + 32;\n i -= 1;\n } else if k < 34 + ll[i - 1] + 32 + ll[i - 1] + 2 {\n let s3 = \"\\\"?\";\n return s3.chars()\n .nth((k - 34 - ll[i - 1] - 32 - ll[i - 1]) as usize)\n .unwrap();\n } else {\n return '.';\n }\n }\n }\n\n}\n\nfn main() {\n let k_max: u64 = 1000000000000000000;\n\n let mut ll = Vec::new();\n ll.push(75u64);\n let mut n = 0;\n for i in 1..100001 {\n n = ll[i - 1] * 2 + 68;\n ll.push(n);\n if n > k_max {\n break;\n }\n }\n while ll.len() < 100001 {\n ll.push(n);\n }\n\n let mut ans = Vec::new();\n\n let n = get!(usize);\n\n for _ in 0..n {\n let (n, k) = get!(usize, u64);\n ans.push(f(n, k - 1, &ll));\n }\n\n println!(\"{}\", ans.into_iter().collect::());\n}\n", "src_uid": "da09a893a33f2bf8fd00e321e16ab149"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.u();\n let mut a = std::collections::HashMap::::new();\n for _ in 0..n {\n let x = input.i();\n let k = 1 + if let Some(&k) = a.get(&x) { k } else { 0 };\n a.insert(x, k);\n }\n let sol = a.into_iter().map(|(_,k)| k).max().unwrap();\n println!(\"{}\", sol);\n}\n\n", "src_uid": "f30329023e84b4c50b1b118dc98ae73c"} {"source_code": "#![allow(unused_imports)]\nuse std::io::*;\nuse std::cmp::*;\nuse std::collections::*;\n\nmacro_rules! debug(\n ($($arg:tt)*) => { {\n let r = writeln!(&mut ::std::io::stderr(), $($arg)*);\n r.expect(\"failed printing to stderr\");\n } }\n);\n\nstruct Scanner {\n buffer : std::collections::VecDeque\n}\n\nimpl Scanner {\n\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn process(&mut self) -> String {\n if self.buffer.len() == 0 {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n for word in input.split_whitespace() {\n self.buffer.push_back(word.to_string())\n }\n }\n\n self.buffer.pop_front().unwrap()\n }\n\n fn next(&mut self) -> T {\n self.process().parse::().ok().unwrap()\n }\n\n fn next_char(&mut self) -> char {\n self.process().into_bytes()[0] as char\n }\n}\n\nfn main() {\n let mut sin = Scanner::new();\n let (m, d) : (usize, i32) = (sin.next(), sin.next());\n\n let month_days = vec![31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\n let mut days = month_days[m-1];\n\n let mut columns = 1;\n days -= 7 - d + 1;\n\n while days > 7 {\n columns += 1;\n days -= 7;\n }\n\n if days > 0 {\n columns += 1;\n }\n\n println!(\"{}\", columns);\n}\n", "src_uid": "5b969b6f564df6f71e23d4adfb2ded74"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n l!(a,b,c,d = input.i());\n let mut ans = false;\n let mut f = |x: i32, y: i32| {\n if x == y {\n ans = true;\n }\n };\n f(a, b+c+d);\n f(b, a+c+d);\n f(c, a+b+d);\n f(d, a+b+c);\n f(a+b, c+d);\n f(a+c, b+d);\n f(a+d, b+c);\n if ans {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n\n", "src_uid": "5a623c49cf7effacfb58bc82f8eaff37"} {"source_code": "use std::collections::HashMap;\n\n\nfn main(){\n let cin = std::io::stdin();\n let mut mp = HashMap::with_capacity(10);\n let mut origs = String::new();\n cin.read_line(&mut origs)\n .expect(\"lol\");\n for i in 0u32..11u32{\n let mut s = String::new();\n cin.read_line(&mut s)\n .expect(\"lol\");\n mp.insert(String::from(s.trim()),i);\n }\n for i in 0..=7{\n let sl: &str = &origs[i*10..i*10+10];\n let s = String::from(sl);\n let val: &u32 = mp.get(&s).expect(\"\");\n print!(\"{}\",val);\n }\n println!(\"\");\n}", "src_uid": "0f4f7ca388dd1b2192436c67f9ac74d9"} {"source_code": "use std::io;\n\nstatic ALPHABET: &str = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\nfn find_number_of_ops(length_of_string: usize, s: String) -> usize {\n let mut number_of_ops = vec![];\n for i in 0..length_of_string-3 {\n let substring = &s[i..i+4];\n let mut ops = 0;\n for (index_of_letter_in_substring, letter) in substring.chars().enumerate() {\n if letter != \"ACTG\".chars().nth(index_of_letter_in_substring).unwrap() {\n // number of operations is not zero for this letter\n let position_of_letter_in_alphabet = ALPHABET.find(letter).unwrap();\n let position_of_target_in_alphabet = ALPHABET.find(\"ACTG\".chars().nth(index_of_letter_in_substring).unwrap()).unwrap();\n let x: usize = (position_of_letter_in_alphabet as isize - position_of_target_in_alphabet as isize).abs() as usize;\n let y: usize = 26 - (position_of_target_in_alphabet as isize - position_of_letter_in_alphabet as isize).abs() as usize;\n ops += if x < y {x} else {y};\n }\n if index_of_letter_in_substring == 3 {\n number_of_ops.push(ops);\n }\n }\n }\n let mut minimum_ops = number_of_ops[0];\n for ops in number_of_ops.iter() {\n if ops < &minimum_ops {\n minimum_ops = *ops;\n }\n }\n minimum_ops\n}\n\nfn main() {\n let mut length_of_string = String::new();\n io::stdin().read_line(&mut length_of_string).unwrap();\n let length_of_string: usize = length_of_string.trim().parse().unwrap();\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n println!(\"{}\", find_number_of_ops(length_of_string, s.trim().to_string()));\n}\n", "src_uid": "ee4f88abe4c9fa776abd15c5f3a94543"} {"source_code": "use std::io::{self, prelude::*};\n\n\n#[allow(unused_must_use)]\nfn solve(mut scan: Scanner, mut w: W) {\n //let n = scan.token::();\n let mut input: Vec = scan.token::().chars().collect();\n input[0] = input[0].to_uppercase().nth(0).unwrap();\n let ans: String = input.into_iter().collect();\n writeln!(w, \"{}\", ans);\n}\n \nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n let reader = Scanner::new(stdin.lock());\n let writer = io::BufWriter::new(stdout.lock());\n solve(reader, writer);\n}\n\n#[allow(dead_code)]\nfn matrix_to_str(matrix: &Vec>, separator: &str) -> String { \n use std::fmt::Write;\n let mut ans = String::new();\n for line in matrix.iter() {\n for elem in line.iter() {\n write!(&mut ans, \"{}{}\", elem.to_string(), separator).unwrap();\n }\n write!(&mut ans, \"\\n\").unwrap();\n }\n ans\n}\npub struct Scanner {\n reader: B,\n buf_str: Vec,\n buf_iter: std::str::SplitWhitespace<'static>,\n}\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_whitespace()\n }\n }\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader.read_until(b'\\n', &mut self.buf_str).expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = std::str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_whitespace()) }\n }\n }\n pub fn get_matrix(&mut self, m: usize, n: usize) -> Vec> {\n // m rows and n columns\n let mut ans: Vec> = Vec::with_capacity(m);\n for i in 0..m {\n ans.push(Vec::with_capacity(n));\n for _ in 0..n {\n ans[i].push(self.token::());\n }\n }\n ans\n }\n}\n", "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"source_code": "#![allow(unused_imports)]\r\n#![allow(unused_must_use)]\r\n#![allow(unused_macros)]\r\n#![allow(non_snake_case)]\r\n#![allow(clippy::too_many_arguments)]\r\n#![allow(clippy::many_single_char_names)]\r\n#![allow(clippy::needless_range_loop)]\r\n#![allow(clippy::comparison_chain)]\r\n\r\nuse std::cmp::{max, min, Reverse};\r\nuse std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};\r\nuse std::io::{self, prelude::*};\r\nuse std::str;\r\n\r\nfn solve(sc: &mut Scanner, wr: &mut W) {\r\n const MOD: i64 = 1_000_000_007;\r\n let n: usize = sc.tok();\r\n let lowest = sieve(n);\r\n let mut phi = vec![1; n + 1];\r\n for k0 in 2..=n {\r\n let p = lowest[k0];\r\n let mut pow = 1;\r\n let mut k = k0;\r\n while k % p == 0 {\r\n k /= p;\r\n pow *= p;\r\n }\r\n phi[k0] = phi[k] * ((p - 1) * (pow / p)) as i64;\r\n }\r\n let mut res = 0;\r\n for g in 1..=n as i64 - 1 {\r\n let mut s = 2 * g;\r\n while s < n as i64 {\r\n res += phi[(s / g) as usize] * lcm(g, n as i64 - s) % MOD;\r\n if res >= MOD {\r\n res -= MOD;\r\n }\r\n s += g;\r\n }\r\n }\r\n writeln!(wr, \"{}\", res);\r\n}\r\n\r\npub fn gcd(mut a: i64, mut b: i64) -> i64 {\r\n a = a.abs();\r\n b = b.abs();\r\n while b > 0 {\r\n a %= b;\r\n (a, b) = (b, a);\r\n }\r\n a\r\n}\r\n\r\npub fn lcm(a: i64, b: i64) -> i64 {\r\n if (a, b) == (0, 0) {\r\n 0\r\n } else {\r\n a / gcd(a, b) * b\r\n }\r\n}\r\nfn sieve(max: usize) -> Vec {\r\n let mut primes = vec![];\r\n let mut lowest = vec![0; max + 1];\r\n for n in 2..=max {\r\n if lowest[n] == 0 {\r\n lowest[n] = n;\r\n primes.push(n);\r\n }\r\n for &p in &primes {\r\n if p > lowest[n] || p * n > max {\r\n break;\r\n }\r\n lowest[p * n] = p;\r\n }\r\n }\r\n lowest\r\n}\r\n\r\nuse std::marker::PhantomData;\r\nmacro_rules! recursive_function {\r\n ($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {\r\n pub trait $trait<$($type, )*Output> {\r\n fn call(&mut self, $($arg: $type,)*) -> Output;\r\n }\r\n\r\n pub struct $name\r\n where\r\n F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,\r\n {\r\n f: F,\r\n $($arg: PhantomData<$type>,\r\n )*\r\n phantom_output: PhantomData,\r\n }\r\n\r\n impl $name\r\n where\r\n F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,\r\n {\r\n pub fn new(f: F) -> Self {\r\n Self {\r\n f,\r\n $($arg: Default::default(),\r\n )*\r\n phantom_output: Default::default(),\r\n }\r\n }\r\n }\r\n\r\n impl $trait<$($type, )*Output> for $name\r\n where\r\n F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,\r\n {\r\n fn call(&mut self, $($arg: $type,)*) -> Output {\r\n let const_ptr = &self.f as *const F;\r\n let mut_ptr = const_ptr as *mut F;\r\n unsafe { (&mut *mut_ptr)(self, $($arg, )*) }\r\n }\r\n }\r\n }\r\n}\r\n\r\nrecursive_function!(RecursiveFunction0, Callable0, ());\r\nrecursive_function!(RecursiveFunction, Callable, (Arg arg,));\r\nrecursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));\r\nrecursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));\r\nrecursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));\r\nrecursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));\r\nrecursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));\r\nrecursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));\r\nrecursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));\r\nrecursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));\r\n\r\n#[macro_export]\r\nmacro_rules! dbg{\r\n ($($a:expr),*) => {\r\n #[cfg(debug_assertions)]\r\n eprintln!(\r\n concat!(\"{}:{}:{}: \",$(stringify!($a), \" = {:?}, \"),*),\r\n file!(), line!(), column!(), $($a),*\r\n );\r\n #[cfg(not(debug_assertions))]\r\n {};\r\n }\r\n}\r\nstruct Scanner {\r\n reader: R,\r\n buf_str: Vec,\r\n buf_iter: str::SplitWhitespace<'static>,\r\n}\r\nimpl Scanner {\r\n fn new(reader: R) -> Self {\r\n Self {\r\n reader,\r\n buf_str: vec![],\r\n buf_iter: \"\".split_whitespace(),\r\n }\r\n }\r\n fn tok(&mut self) -> T {\r\n loop {\r\n if let Some(token) = self.buf_iter.next() {\r\n return token.parse().ok().expect(\"Failed parse\");\r\n }\r\n self.buf_str.clear();\r\n self.reader\r\n .read_until(b'\\n', &mut self.buf_str)\r\n .expect(\"Failed read\");\r\n self.buf_iter = unsafe {\r\n let slice = str::from_utf8_unchecked(&self.buf_str);\r\n std::mem::transmute(slice.split_whitespace())\r\n }\r\n }\r\n }\r\n}\r\n\r\nfn main() {\r\n let (stdin, stdout) = (io::stdin(), io::stdout());\r\n let mut scan = Scanner::new(stdin.lock());\r\n let mut out = io::BufWriter::new(stdout.lock());\r\n solve(&mut scan, &mut out);\r\n}\r\n", "src_uid": "c3694a6ff95c64bef8cbe8834c3fd6cb"} {"source_code": "use std::char;\nuse std::fs::File;\nuse std::io::Read;\n\n// fn pow_speedt_with_mod(mut p: i64, mut q: i64, m: i64) -> i64 {\n// p %= m;\n// let mut r = p;\n// let mut ret: i64 = 1;\n// while q > 0 {\n// ret *= if q % 2 == 1 {r} else {1};\n// r *= r;\n// r %= m;\n// q /= 2;\n// ret %= m;\n// }\n// return ret;\n// }\n\nfn main() {\n let inputstatus = 1;\n\n let mut buf = String::new();\n let filename = \"inputrust.txt\";\n\n if inputstatus == 0 {\n let mut f = File::open(filename).expect(\"file not found\");\n f.read_to_string(&mut buf)\n .expect(\"something went wrong reading the file\");\n } else {\n std::io::stdin().read_to_string(&mut buf).unwrap();\n }\n\n let mut iter = buf.split_whitespace();\n let n: usize = iter.next().unwrap().parse().unwrap();\n let mut v = Vec::::new();\n let mut v_commpress = Vec::::new();\n\n for _ in 0..n {\n v.push(iter.next().unwrap().parse().unwrap());\n }\n v.sort();\n\n for (i, vi) in v.iter().enumerate() {\n if i == 0 {\n v_commpress.push(*vi);\n } else if v[i - 1] != v[i] {\n v_commpress.push(*vi);\n }\n }\n\n // println!(\"{:?}\", v_commpress);\n\n let ans = if v_commpress.len() <= 1 {\n 0\n } else if v_commpress.len() == 2 && (v_commpress[1] - v_commpress[0]) % 2 == 0 {\n (v_commpress[1] - v_commpress[0]) / 2\n } else if v_commpress.len() == 2 && (v_commpress[1] - v_commpress[0]) % 2 == 1 {\n v_commpress[1] - v_commpress[0]\n } else if v_commpress.len() == 3 && (v_commpress[2] + v_commpress[0]) == 2 * v_commpress[1] {\n v_commpress[1] - v_commpress[0]\n } else {\n -1\n };\n println!(\"{}\", ans);\n\n // if p + 1 >= m\n\n // println!(\"{}\", n);\n // println!(\"{}\", k);\n // println!(\"{:?}\", num);\n // println!(\"{:?}\", cum_num);\n}\n", "src_uid": "d486a88939c132848a7efdf257b9b066"} {"source_code": "// https://codeforces.com/contest/1293/problem/D\n//\n#![allow(unused_imports)]\nuse std::io::*;\nuse std::io::Write;\nuse std::fmt::*;\nuse std::str::*;\nuse std::cmp::*;\nuse std::collections::*;\n\n// Input macros.\n// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\n#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n\n ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($iter:expr, [ next / $t:tt ]) => {\n {\n let len = read_value!($iter, usize);\n (0..len).map(|_| read_value!($iter, $t)).collect::>()\n }\n };\n\n ($iter:expr, switch) => {\n {\n let ty = read_value!($iter, i32);\n if ty == 1 {\n vec![ty, read_value!($iter, i32), read_value!($iter, i32)]\n } else if ty == 2 {\n vec![ty, read_value!($iter, i32)]\n } else {\n vec![ty, read_value!($iter, i32)]\n }\n }\n };\n\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_line {\n ($t:tt) => {\n {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n s.trim_right().parse::<$t>().unwrap()\n }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! dvec {\n ($t:expr ; $len:expr) => {\n vec![$t; $len]\n };\n\n ($t:expr ; $len:expr, $($rest:expr),*) => {\n vec![dvec!($t; $($rest),*); $len]\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! ifv {\n ($t:expr, $a:expr, $b: expr) => {\n if $t { $a } else { $b }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! fill {\n ($t:expr, $v:expr) => {\n for i in 0..$t.len() {\n $t[i] = $v;\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! join {\n ($t:expr, $glue:expr) => {\n $t.into_iter().map(|w| w.to_string()).collect::>().join($glue)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\n// ===\n\nconst MAX_CORD: i128 = 1e18 as i128;\n\nfn solve(mut limit: i128, start: usize, p1: usize, p2: usize, p3: usize, cost: &Vec>) -> i32 {\n if limit < 0 {\n return -10000;\n }\n let mut count = 1;\n let mut now = start;\n while now != p1 {\n let t = ifv!(now < p1, now+1, now-1);\n if limit < cost[now][t] {\n return count;\n }\n count += 1;\n limit -= cost[now][t];\n now = t;\n }\n assert_eq!(now, p1);\n assert_ne!(now, p2);\n if limit < cost[now][p2] {\n return count;\n }\n limit -= cost[now][p2];\n count += 1;\n now = p2;\n\n while now != p3 {\n let t = ifv!(now < p3, now+1, now-1);\n if limit < cost[now][t] {\n return count;\n }\n count += 1;\n limit -= cost[now][t];\n now = t;\n }\n count\n}\n\nfn main() {\n input! {\n x0: i128, y0: i128, ax: i128, ay: i128, bx: i128, by: i128,\n sx: i128, sy: i128, limit: i128\n };\n\n let mut points = vec![(x0, y0)];\n loop {\n let (lx, ly) = *points.last().unwrap();\n if lx > MAX_CORD || ly > MAX_CORD {\n break;\n }\n points.push((lx*ax+bx, ly*ay+by));\n }\n let n = points.len();\n\n let mut first_cost = vec![];\n for i in 0..n {\n first_cost.push((sx-points[i].0).abs() + (sy-points[i].1).abs());\n }\n let mut pp_cost = dvec!(0; n, n);\n for i in 0..n {\n for j in 0..n {\n pp_cost[i][j] = (points[i].0-points[j].0).abs() + (points[i].1-points[j].1).abs();\n }\n }\n\n // debug!(points);\n // debug!(first_cost);\n\n assert!(n >= 2);\n\n let mut best = 0;\n for s in 0..n {\n if s < n-1 {\n for l in 0..=s {\n best = max(best, solve(limit - first_cost[s], s, l, s+1, n-1, &pp_cost));\n }\n }\n if s >= 1 {\n for l in s..n {\n best = max(best, solve(limit - first_cost[s], s, l, s-1, 0, &pp_cost));\n }\n }\n }\n\n println!(\"{}\", best);\n}\n", "src_uid": "d8a7ae2959b3781a8a4566a2f75a4e28"} {"source_code": "use std::io::{self, Read as _};\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_to_string(&mut input).unwrap();\n let mut input = input.split_whitespace();\n macro_rules! read(\n (($($tt:tt),+)) => (($(read!($tt)),*));\n ($ty:ty) => (input.next().unwrap().parse::<$ty>().unwrap());\n );\n\n let ((x1, y1), (x2, y2), (x3, y3)) = read!(((f64, f64), (f64, f64), (f64, f64)));\n println!(\"{:.8}\", solve((x2 - x1, y2 - y1), (x3 - x1, y3 - y1)));\n}\n\nfn solve((x1, y1): (f64, f64), (x2, y2): (f64, f64)) -> f64 {\n let cx = ((x1 * x1 + y1 * y1) * y2 - (x2 * x2 + y2 * y2) * y1) / (2.0 * (x1 * y2 - x2 * y1));\n let cy = ((x2 * x2 + y2 * y2) * x1 - (x1 * x1 + y1 * y1) * x2) / (2.0 * (x1 * y2 - x2 * y1));\n let a1 = angle((cx, cy), (cx - x1, cy - y1));\n let a2 = angle((cx, cy), (cx - x2, cy - y2));\n let n = (3..)\n .filter(|&n| {\n let a = 2.0 * std::f64::consts::PI / (n as f64);\n is_nearint(a1 / a) && is_nearint(a2 / a)\n })\n .next()\n .unwrap();\n (cx * cx + cy * cy) * (2.0 * std::f64::consts::PI / (n as f64)).sin() / 2.0 * n as f64\n}\n\nfn angle((x1, y1): (f64, f64), (x2, y2): (f64, f64)) -> f64 {\n ((x1 * x2 + y1 * y2) / (length(x1, y1) * length(x2, y2))).acos()\n}\n\nfn length(x: f64, y: f64) -> f64 {\n (x * x + y * y).sqrt()\n}\n\nfn is_nearint(x: f64) -> bool {\n (x - x.round()).abs() < 1e-5\n}\n", "src_uid": "980f4094b3cfc647d6f74e840b1bfb62"} {"source_code": "use std::io;\n\nfn main()\n{\n\tlet mut s = String::new();\n\tlet mut n = String::new();\n\tio::stdin().read_line(&mut n).unwrap();\n\tlet n = n.trim().parse::().unwrap();\n\tio::stdin().read_line(&mut s).unwrap();\n\ts = s.trim().to_string();\n\tlet val: Vec = s.split(\" \").map(|x: &str| x.parse::().unwrap()).collect();\n\n\tif let Ok(res) = match val[val.len()-1] {\n\t\t0 => Ok(\"UP\"),\n\t\t15 => Ok(\"DOWN\"),\n\t\t_ => if val.len() > 1 {\n\t\t\tmatch val[val.len()-1] - val[val.len()-2] {\n\t\t\t\t1 => Ok(\"UP\"),\n\t\t\t\t-1 => Ok(\"DOWN\"),\n\t\t\t\t_ => Err(\"invalid input\"),\n\t\t\t}\n\t\t} else {\n\t\t\tprint!(\"{}\", -1);\n\t\t\treturn;\n\t\t}\n\t} {\n\t\tprint!(\"{}\", res);\n\t}\n\telse {\n\t\tprint!(\"{}\", \"invalid input\");\n\t}\n\n}", "src_uid": "8330d9fea8d50a79741507b878da0a75"} {"source_code": "pub struct Scanner {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scanner {\n pub fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new(),\n }\n }\n pub fn next(&mut self) -> T {\n while self.buffer.is_empty() {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n self.buffer = input.split_whitespace().map(ToString::to_string).collect();\n }\n let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn main() {\n let mut scanner = Scanner::new();\n let days = scanner.next::();\n let mut time = scanner.next::();\n let mut used_time_by_day = Vec::with_capacity(days);\n let mut remaining_time_by_day = Vec::with_capacity(days);\n for _ in 0..days {\n let min = scanner.next::();\n let max = scanner.next::();\n time -= min as i32;\n used_time_by_day.push(min);\n remaining_time_by_day.push(max - min);\n }\n if time < 0 {\n println!(\"NO\");\n return;\n }\n for i in 0..days {\n let delta = u8::min(remaining_time_by_day[i], time as u8);\n time -= delta as i32;\n used_time_by_day[i] += delta;\n if time == 0 {\n break;\n }\n }\n if time == 0 {\n println!(\"YES\");\n for i in 0..days {\n print!(\"{} \", used_time_by_day[i]);\n }\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"source_code": "fn input_sum() -> f32 {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim()\n .split_whitespace()\n .map(|elem| elem.parse::().unwrap())\n .sum()\n}\n\nfn main() {\n print!(\n \"{}\",\n if (input_sum() / 5f32).ceil() + (input_sum() / 10f32).ceil() <= input_sum() {\n \"YES\"\n } else {\n \"NO\"\n }\n )\n}", "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"source_code": "use std::io;\n\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n\n let mut iter = input.split_whitespace();\n let mut a: u32 = iter.next().unwrap().parse().unwrap();\n let mut b: u32 = iter.next().unwrap().parse().unwrap();\n\n let mut output = 0;\n\n while a <= b {\n a *= 3;\n b *= 2;\n output += 1;\n }\n\n\n println!(\"{}\", output);\n}\n\n\n", "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"source_code": "use std::*;\r\nuse io::stdin;\r\nuse cmp::Ordering;\r\nuse cell::Cell;\r\n\r\nfn resolve_pool(\r\n s: &[bool], mut offset: usize, mut lhs: Vec, mut rhs: Vec,\r\n) -> Result<(Vec, usize), FailReason> {\r\n let mut l_ptr: usize = 0;\r\n let mut r_ptr: usize = 0;\r\n let mut next_pool = vec![];\r\n while l_ptr < lhs.len() && r_ptr < rhs.len() {\r\n // let l = &mut lhs[l_ptr];\r\n // let r = &mut rhs[r_ptr];\r\n let fst =\r\n if let Some(c) = s.get(offset) {\r\n c\r\n } else {\r\n return Err(FailReason::NotEnoughMerges);\r\n };\r\n if !fst {\r\n next_pool.push(lhs[l_ptr]);\r\n // l.history.get_mut().push(false);\r\n // next_pool.push(Val {\r\n // val: lhs[l_ptr].val,\r\n // history: Cell::new(lhs[l_ptr].history.take()),\r\n // });\r\n l_ptr += 1;\r\n } else {\r\n next_pool.push(rhs[r_ptr]);\r\n // r.history.get_mut().push(true);\r\n // next_pool.push(Val {\r\n // val: rhs[r_ptr].val,\r\n // history: Cell::new(rhs[r_ptr].history.take()),\r\n // });\r\n r_ptr += 1;\r\n }\r\n offset += 1;\r\n }\r\n if l_ptr < lhs.len() {\r\n next_pool.extend(lhs[l_ptr..].iter())\r\n // for i in l_ptr..lhs.len() {\r\n // lhs[i].history.get_mut().push(false);\r\n // next_pool.push(Val {\r\n // val: lhs[i].val,\r\n // history: Cell::from(lhs[i].history.take()),\r\n // })\r\n // }\r\n } else {\r\n next_pool.extend(rhs[r_ptr..].iter())\r\n // for i in r_ptr..rhs.len() {\r\n // rhs[i].history.get_mut().push(true);\r\n // next_pool.push(Val {\r\n // val: rhs[i].val,\r\n // history: Cell::from(rhs[i].history.take()),\r\n // })\r\n // }\r\n }\r\n Ok((next_pool, offset))\r\n}\r\n\r\nenum FailReason {\r\n NotEnoughMerges,\r\n TooManyMerges,\r\n}\r\n\r\ntype Val = usize;\r\n\r\n// struct Val {\r\n// val: usize,\r\n// history: Cell>,\r\n// }\r\n\r\nfn solve(s: &[bool]) -> Vec {\r\n fn solve_with_assumed_size(s: &[bool], vals: Vec) -> Result, FailReason> {\r\n fn rec_resolve(\r\n mut rg: Vec, s: &[bool], offset: usize,\r\n ) -> Result<(Vec, usize), FailReason> {\r\n if rg.len() <= 1 {\r\n return Ok((rg, offset));\r\n }\r\n let lhs_upper = rg.len() >> 1;\r\n let rhs = rg.drain(lhs_upper..).collect();\r\n let lhs = rg;\r\n let (left_part_of_pool, offset) = rec_resolve(lhs, s, offset)?;\r\n let (right_part_of_pool, offset) = rec_resolve(rhs, s, offset)?;\r\n\r\n Ok(resolve_pool(s, offset, left_part_of_pool, right_part_of_pool)?)\r\n }\r\n\r\n // let merge_count = f64::log2(sz as f64) as usize;\r\n // let mut known_relations = vec![vec![None; vals.len()]; vals.len()];\r\n\r\n let (vals, offset) = rec_resolve(vals, s, 0)?;\r\n match offset.cmp(&s.len()) {\r\n Ordering::Less => Err(FailReason::TooManyMerges),\r\n Ordering::Greater => Err(FailReason::NotEnoughMerges),\r\n\r\n Ordering::Equal => {\r\n let mut ans = vec![0; vals.len()];\r\n for (i, pos) in vals.into_iter().enumerate() {\r\n ans[pos] = i + 1;\r\n }\r\n Ok(ans)\r\n }\r\n }\r\n }\r\n\r\n let mut lower_bound = 2;\r\n let mut upper_bound = 1e3 as usize;\r\n let mut vals = Vec::with_capacity(upper_bound);\r\n for i in 0..upper_bound {\r\n vals.push(i)\r\n // vals.push(Val { val: i, history: Cell::new(vec![]) });\r\n }\r\n let mut prev_assumed_size = None;\r\n loop {\r\n let assumed_size = {\r\n let assumed_size = lower_bound + (upper_bound - lower_bound) / 2;\r\n if assumed_size == 999 && prev_assumed_size.unwrap() == assumed_size {\r\n 1000\r\n } else {\r\n assumed_size\r\n }\r\n };\r\n let mut vals_to_pass = vec![];\r\n for i in 0..assumed_size {\r\n vals_to_pass.push(i);\r\n // let val = &mut vals[i];\r\n // vals_to_pass.push(Val {\r\n // val: val.val,\r\n // history: Cell::new(val.history.get_mut().clone()),\r\n // })\r\n }\r\n match solve_with_assumed_size(s, vals_to_pass) {\r\n Ok(ans) => return ans,\r\n Err(FailReason::NotEnoughMerges) => {\r\n upper_bound = assumed_size;\r\n }\r\n Err(FailReason::TooManyMerges) => {\r\n lower_bound = assumed_size;\r\n }\r\n }\r\n prev_assumed_size = Some(assumed_size);\r\n }\r\n}\r\n\r\nfn main() {\r\n let mut buffer = String::new();\r\n stdin().read_line(&mut buffer);\r\n let buffer = Vec::from(buffer\r\n .chars()\r\n .filter_map(|x| {\r\n match x {\r\n '0' => Some(false),\r\n '1' => Some(true),\r\n _ => None\r\n }\r\n })\r\n .collect::>());\r\n let ans = solve(&buffer);\r\n println!(\"{}\", ans.len());\r\n for v in ans {\r\n print!(\"{} \", v);\r\n }\r\n}\r\n", "src_uid": "b2ee84d23d73947fa84faaaebfde85c8"} {"source_code": "#![warn(\r\n clippy::all,\r\n rust_2018_idioms,\r\n missing_copy_implementations,\r\n missing_debug_implementations,\r\n single_use_lifetimes,\r\n trivial_casts,\r\n unused_import_braces,\r\n unused_qualifications,\r\n unused_results\r\n)]\r\n#![allow(\r\n clippy::many_single_char_names,\r\n non_snake_case,\r\n unused_imports,\r\n unused_macros,\r\n dead_code\r\n)]\r\n\r\n#[cfg(test)]\r\nmacro_rules! debugln {\r\n () => {\r\n println!();\r\n };\r\n ($val:expr) => {\r\n print!(\"{:?} \", &$val);\r\n };\r\n ($($val:expr),+ $(,)?) => {\r\n $(debugln!($val);)+\r\n };\r\n}\r\n\r\n#[cfg(not(test))]\r\nmacro_rules! debugln {\r\n ($($tt:tt)*) => {\r\n let _ = ($($tt)*);\r\n };\r\n}\r\n\r\n#[cfg(not(test))]\r\nmacro_rules! println {\r\n ($($tt:tt)*) => {\r\n let _ = ($($tt)*);\r\n };\r\n}\r\n\r\n#[cfg(not(test))]\r\nmacro_rules! print {\r\n ($($tt:tt)*) => {\r\n let _ = ($($tt)*);\r\n };\r\n}\r\n\r\nmod task {\r\n use crate::io::Io;\r\n use crate::util::*;\r\n use std::io::{BufRead, Write};\r\n\r\n pub const MODE: Mode = Mode::Single;\r\n\r\n pub fn solution(io: &mut Io) {\r\n use crate::*;\r\n use core::cmp::Ordering::{Equal, Greater, Less};\r\n use core::cmp::{max, min};\r\n use core::iter::{empty, once, repeat, FromIterator};\r\n use core::mem::swap;\r\n use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};\r\n\r\n //const N_MAX: usize = 100;\r\n //let mut a = [0; N_MAX];\r\n //let n: usize = io.read();\r\n //let a: Vec = io.read_n(n).collect();\r\n //let a: Vec<(i64, i64)> = io.read_n_pairs(n).collect();\r\n //let a: Vec<(i64, i64, i64)> = io.read_n_triplets(n).collect();\r\n //let a: Vec = (0..n).map(|_| io.read()).collect();\r\n //let a: &str = io.read_str();\r\n //let a: Vec = io.read_bytes().to_vec();\r\n //let a: Vec = io.read_decimal().collect();\r\n //let a: Vec = io.read_bits(b'1').collect();\r\n //debugln!([false, true].pm_fmt());\r\n\r\n let h: usize = io.read();\r\n let w: usize = io.read();\r\n let mut a = [[false; 10]; 10];\r\n for y in 0..h {\r\n let b: Vec = io.read_bits(b'*').collect();\r\n for x in 0..w {\r\n a[y][x] = b[x];\r\n }\r\n }\r\n\r\n let mut ans = 0;\r\n let mut x = 0;\r\n let mut y = 0;\r\n 'outer: while x < w - 1 && y < h - 1 {\r\n ans += a[y][x] as i64;\r\n for j in 1..5 {\r\n if a[y][x + j] {\r\n x += 1;\r\n continue 'outer;\r\n } else if a[y + j][x] {\r\n y += 1;\r\n continue 'outer;\r\n }\r\n }\r\n x += 1;\r\n continue;\r\n }\r\n\r\n while x < w - 1 {\r\n ans += a[y][x] as i64;\r\n x += 1;\r\n }\r\n\r\n while y < h - 1 {\r\n ans += a[y][x] as i64;\r\n y += 1;\r\n }\r\n\r\n ans += a[y][x] as i64;\r\n\r\n io.writeln(ans);\r\n }\r\n\r\n #[cfg(test)]\r\n fn alternative(_io: &mut Io) {\r\n panic!()\r\n }\r\n\r\n #[cfg(test)]\r\n #[test]\r\n fn test_example() {\r\n let output = |input: &str| output_for(|io| solution(io), Mode::Multiple, &input);\r\n assert_eq!(\r\n output(\r\n \"4\r\n 4 3\r\n *..\r\n .*.\r\n ..*\r\n ...\r\n 4 4\r\n .*..\r\n *...\r\n ...*\r\n ..*.\r\n 3 4\r\n ..**\r\n *...\r\n ....\r\n 5 5\r\n ..*..\r\n .....\r\n **...\r\n **...\r\n **...\r\n \"\r\n ),\r\n \"3\\n2\\n1\\n1\\n\".reformat_with_trim(),\r\n );\r\n }\r\n\r\n /*#[cfg(test)]\r\n #[test]\r\n fn test_custom() {\r\n let output = |input: &str| output_for(|io| solution(io), Mode::Single, &input);\r\n assert_eq!(output(\"5 5 1 2 3 4 5\"), \"1\\n2\\n3\\n4\\n5\\n\");\r\n }*/\r\n\r\n /*#[cfg(test)]\r\n #[test]\r\n fn test_matched() {\r\n let matched = |input: &str| matched_for(\r\n |io| solution(io), |io| alternative(io), Mode::Single, &input,\r\n );\r\n }*/\r\n}\r\n\r\npub fn main() {\r\n use std::io::{stdin, stdout, BufReader, BufWriter};\r\n\r\n use task::{solution, MODE};\r\n\r\n let mut reader = BufReader::new(stdin());\r\n let mut writer = BufWriter::new(stdout());\r\n let mut io = Io::new(IoPair::new(&mut reader, &mut writer));\r\n solve(solution, MODE, &mut io);\r\n io.flush();\r\n}\r\n\r\nuse ceil::*;\r\nmod ceil {\r\n use core::ops::{Add, Div, Sub};\r\n\r\n use crate::div_euclid::DivEuclid;\r\n use crate::one::One;\r\n\r\n #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]\r\n pub struct Ceil(pub T);\r\n\r\n impl Div for Ceil\r\n where\r\n T: Add + Clone + DivEuclid + One + Sub,\r\n {\r\n type Output = T;\r\n\r\n fn div(self, rhs: T) -> Self::Output {\r\n (self.0 + rhs.clone() - T::one()).div_euclid(rhs)\r\n }\r\n }\r\n}\r\n\r\nuse each::*;\r\nmod each {\r\n #[allow(single_use_lifetimes)]\r\n pub trait Each<'a> {\r\n type Iter;\r\n fn each(&'a self) -> Self::Iter;\r\n }\r\n\r\n impl<'a, I> Each<'a> for [I]\r\n where\r\n I: 'a + Clone + IntoIterator,\r\n {\r\n type Iter = SliceEach<'a, I>;\r\n fn each(&'a self) -> Self::Iter {\r\n SliceEach::new(self)\r\n }\r\n }\r\n\r\n #[allow(clippy::type_complexity)]\r\n #[derive(Clone, Debug)]\r\n pub struct SliceEach<'a, I>(Option<(&'a [I], Vec, Vec)>)\r\n where\r\n I: Clone + IntoIterator;\r\n\r\n impl<'a, I> SliceEach<'a, I>\r\n where\r\n I: Clone + IntoIterator,\r\n {\r\n pub fn new(iter: &'a [I]) -> Self {\r\n Self(Some((iter, Vec::new(), Vec::new())))\r\n }\r\n }\r\n\r\n impl Iterator for SliceEach<'_, I>\r\n where\r\n I: Clone + IntoIterator,\r\n I::Item: Clone,\r\n {\r\n type Item = Vec;\r\n\r\n fn next(&mut self) -> Option {\r\n self.0.take().and_then(|mut data| loop {\r\n if data.2.len() < data.1.len() {\r\n let mut last = data.1.pop().unwrap();\r\n if let Some(value) = last.next() {\r\n data.1.push(last);\r\n data.2.push(value);\r\n } else {\r\n let _ = data.2.pop()?;\r\n }\r\n } else if data.1.len() < data.0.len() {\r\n data.1.push(data.0[data.1.len()].clone().into_iter());\r\n } else {\r\n let item = data.2.clone();\r\n let _ = data.2.pop();\r\n self.0 = Some(data);\r\n return Some(item);\r\n }\r\n })\r\n }\r\n }\r\n}\r\n\r\nuse into_vec::*;\r\nmod into_vec {\r\n pub trait IntoVec {\r\n fn into_vec(self) -> Vec;\r\n }\r\n\r\n impl IntoVec for I\r\n where\r\n Self: Sized,\r\n I: IntoIterator,\r\n {\r\n fn into_vec(self) -> Vec {\r\n self.into_iter().collect()\r\n }\r\n }\r\n}\r\n\r\nuse io::*;\r\nmod io {\r\n use std::fmt::{Debug, Display};\r\n use std::io::{self, BufRead, Read, Write};\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct IoPair {\r\n reader: R,\r\n writer: W,\r\n }\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct Io {\r\n io: B,\r\n reader_line: String,\r\n reader_offset: usize,\r\n is_writer_bol: bool,\r\n }\r\n\r\n impl IoPair {\r\n pub fn new(reader: R, writer: W) -> Self {\r\n Self { reader, writer }\r\n }\r\n\r\n pub fn reader_ref(&self) -> &R {\r\n &self.reader\r\n }\r\n\r\n pub fn writer_ref(&self) -> &W {\r\n &self.writer\r\n }\r\n\r\n pub fn reader_mut(&mut self) -> &mut R {\r\n &mut self.reader\r\n }\r\n\r\n pub fn writer_mut(&mut self) -> &mut W {\r\n &mut self.writer\r\n }\r\n }\r\n\r\n impl Read for IoPair {\r\n fn read(&mut self, buf: &mut [u8]) -> io::Result {\r\n self.reader.read(buf)\r\n }\r\n }\r\n\r\n impl BufRead for IoPair {\r\n fn fill_buf(&mut self) -> io::Result<&[u8]> {\r\n self.reader.fill_buf()\r\n }\r\n\r\n fn consume(&mut self, amt: usize) {\r\n self.reader.consume(amt)\r\n }\r\n }\r\n\r\n impl Write for IoPair {\r\n fn write(&mut self, buf: &[u8]) -> io::Result {\r\n self.writer.write(buf)\r\n }\r\n\r\n fn flush(&mut self) -> std::io::Result<()> {\r\n self.writer.flush()\r\n }\r\n }\r\n\r\n impl Io {\r\n pub fn new(io: B) -> Self {\r\n Self {\r\n io,\r\n reader_line: String::new(),\r\n reader_offset: 0,\r\n is_writer_bol: true,\r\n }\r\n }\r\n\r\n pub fn get_ref(&self) -> &B {\r\n &self.io\r\n }\r\n\r\n pub fn get_mut(&mut self) -> &mut B {\r\n &mut self.io\r\n }\r\n\r\n pub fn try_read_str(&mut self) -> Result<&str, io::Error> {\r\n loop {\r\n if self.reader_offset >= self.reader_line.len() {\r\n self.reader_line.clear();\r\n let _ = self.io.read_line(&mut self.reader_line)?;\r\n self.reader_offset = 0;\r\n } else if self.reader_line.as_bytes()[self.reader_offset].is_ascii_whitespace() {\r\n self.reader_offset += 1;\r\n } else {\r\n let line = self.reader_line.as_bytes();\r\n let start = self.reader_offset;\r\n let mut end = start + 1;\r\n while end < self.reader_line.len() && !line[end].is_ascii_whitespace() {\r\n end += 1;\r\n }\r\n self.reader_offset = end + 1;\r\n let word = unsafe { std::str::from_utf8_unchecked(&line[start..end]) };\r\n return Ok(word);\r\n }\r\n }\r\n }\r\n\r\n pub fn try_read(&mut self) -> Result\r\n where\r\n ::Err: Debug,\r\n {\r\n Ok(self.try_read_str()?.parse::().unwrap())\r\n }\r\n\r\n pub fn try_read_bytes(&mut self) -> Result<&[u8], io::Error> {\r\n Ok(self.try_read_str()?.as_bytes())\r\n }\r\n\r\n pub fn try_read_decimal(&mut self) -> Result, io::Error> {\r\n Ok(self.try_read_bytes()?.iter().map(|ch| ch - b'0'))\r\n }\r\n\r\n pub fn try_read_bits(\r\n &mut self,\r\n one: u8,\r\n ) -> Result, io::Error> {\r\n Ok(self.try_read_bytes()?.iter().map(move |ch| *ch == one))\r\n }\r\n\r\n pub fn read_str(&mut self) -> &str {\r\n self.try_read_str().unwrap()\r\n }\r\n\r\n pub fn read(&mut self) -> T\r\n where\r\n ::Err: Debug,\r\n {\r\n self.try_read().unwrap()\r\n }\r\n\r\n pub fn read_n(&mut self, n: usize) -> impl '_ + Iterator\r\n where\r\n ::Err: Debug,\r\n {\r\n (0..n).map(move |_| self.read())\r\n }\r\n\r\n pub fn read_n_pairs(\r\n &mut self,\r\n n: usize,\r\n ) -> impl '_ + Iterator\r\n where\r\n ::Err: Debug,\r\n ::Err: Debug,\r\n {\r\n (0..n).map(move |_| (self.read(), self.read()))\r\n }\r\n\r\n pub fn read_n_triplets<\r\n T1: std::str::FromStr,\r\n T2: std::str::FromStr,\r\n T3: std::str::FromStr,\r\n >(\r\n &mut self,\r\n n: usize,\r\n ) -> impl '_ + Iterator\r\n where\r\n ::Err: Debug,\r\n ::Err: Debug,\r\n ::Err: Debug,\r\n {\r\n (0..n).map(move |_| (self.read(), self.read(), self.read()))\r\n }\r\n\r\n pub fn read_bytes(&mut self) -> &[u8] {\r\n self.try_read_bytes().unwrap()\r\n }\r\n\r\n pub fn read_decimal(&mut self) -> impl '_ + Iterator {\r\n self.try_read_decimal().unwrap()\r\n }\r\n\r\n pub fn read_bits(&mut self, one: u8) -> impl '_ + Iterator {\r\n self.try_read_bits(one).unwrap()\r\n }\r\n\r\n pub fn write(&mut self, value: T) -> &mut Self {\r\n if self.is_writer_bol {\r\n write!(self.io, \"{}\", value).unwrap();\r\n } else {\r\n write!(self.io, \" {}\", value).unwrap();\r\n }\r\n self.is_writer_bol = false;\r\n self\r\n }\r\n\r\n pub fn writeln(&mut self, value: T) {\r\n if self.is_writer_bol {\r\n writeln!(self.io, \"{}\", value).unwrap();\r\n } else {\r\n writeln!(self.io, \" {}\", value).unwrap();\r\n }\r\n self.is_writer_bol = true;\r\n }\r\n\r\n pub fn write_all>(&mut self, iter: U) -> &mut Self {\r\n for value in iter.into_iter() {\r\n let _ = self.write(value);\r\n }\r\n self\r\n }\r\n\r\n pub fn writeln_all>(&mut self, iter: U) {\r\n self.write_all(iter).ln();\r\n }\r\n\r\n pub fn write_bytes(&mut self, bytes: &[u8]) -> &mut Self {\r\n self.write(std::str::from_utf8(bytes).unwrap())\r\n }\r\n\r\n pub fn writeln_bytes(&mut self, bytes: &[u8]) {\r\n self.write_bytes(bytes).ln();\r\n }\r\n\r\n pub fn write_join(&mut self, value: T) -> &mut Self {\r\n write!(self.io, \"{}\", value).unwrap();\r\n self.is_writer_bol = false;\r\n self\r\n }\r\n\r\n pub fn ln(&mut self) {\r\n writeln!(self.io).unwrap();\r\n self.is_writer_bol = true;\r\n }\r\n\r\n pub fn yes(&mut self) {\r\n self.writeln(\"YES\");\r\n }\r\n\r\n pub fn no(&mut self) {\r\n self.writeln(\"NO\");\r\n }\r\n\r\n pub fn flush(&mut self) {\r\n let _ = self.io.flush();\r\n }\r\n\r\n pub fn writeln_flush(&mut self, value: T) {\r\n self.writeln(value);\r\n self.flush();\r\n }\r\n\r\n pub fn writeln_all_flush>(&mut self, iter: U) {\r\n self.writeln_all(iter);\r\n self.flush();\r\n }\r\n\r\n pub fn ln_flush(&mut self) {\r\n self.ln();\r\n self.flush();\r\n }\r\n }\r\n}\r\n\r\nuse target::*;\r\nmod target {\r\n #[cfg(test)]\r\n #[test]\r\n fn test_32bit_target() {\r\n use core::mem::size_of;\r\n assert_eq!(size_of::(), 4, \"Codeforces use 32-bit targets\");\r\n }\r\n}\r\n\r\nuse to_iterator::*;\r\nmod to_iterator {\r\n pub trait ToIterator: Clone + IntoIterator {\r\n fn to_iter(&self) -> Self::IntoIter;\r\n }\r\n\r\n impl ToIterator for T\r\n where\r\n T: Clone + IntoIterator,\r\n {\r\n fn to_iter(&self) -> Self::IntoIter {\r\n self.clone().into_iter()\r\n }\r\n }\r\n}\r\n\r\nuse to_vec::*;\r\nmod to_vec {\r\n use crate::to_iterator::ToIterator;\r\n\r\n pub trait ToVec {\r\n fn to_vec(&self) -> Vec;\r\n }\r\n\r\n impl ToVec for I\r\n where\r\n Self: Sized,\r\n I: ToIterator,\r\n {\r\n fn to_vec(&self) -> Vec {\r\n self.to_iter().collect()\r\n }\r\n }\r\n}\r\n\r\nuse util::*;\r\nmod util {\r\n use std::io::BufRead;\r\n use std::io::Write;\r\n\r\n use crate::io::{Io, IoPair};\r\n\r\n #[derive(Clone, Copy, Debug, Eq, PartialEq)]\r\n pub enum Mode {\r\n Single, // If only the single test case is expected\r\n Multiple, // If multiple test cases are expected\r\n }\r\n\r\n pub fn solve(func: F, mode: Mode, io: &mut Io)\r\n where\r\n F: Fn(&mut Io),\r\n B: BufRead + Write,\r\n {\r\n match mode {\r\n Mode::Single => {\r\n func(io);\r\n io.flush();\r\n }\r\n Mode::Multiple => {\r\n let n: usize = io.read();\r\n for _ in 0..n {\r\n func(io);\r\n io.flush();\r\n }\r\n }\r\n }\r\n }\r\n\r\n pub fn output_for(func: F, mode: Mode, input: &str) -> String\r\n where\r\n F: Fn(&mut Io>>),\r\n {\r\n let reader = input.as_bytes();\r\n let writer = Vec::new();\r\n let mut io = Io::new(IoPair::new(reader, writer));\r\n solve(func, mode, &mut io);\r\n std::str::from_utf8(io.get_ref().writer_ref())\r\n .unwrap()\r\n .to_string()\r\n }\r\n\r\n #[cfg(test)]\r\n pub fn matched_for(solution: F1, alternative: F2, mode: Mode, input: &str)\r\n where\r\n F1: Fn(&mut Io>>),\r\n F2: Fn(&mut Io>>),\r\n {\r\n assert_eq!(\r\n output_for(|io| solution(io), mode, input),\r\n output_for(|io| alternative(io), mode, input),\r\n \"Where left is `solution`, right is `alternative`, and input is: {}\",\r\n input\r\n );\r\n }\r\n\r\n #[cfg(test)]\r\n pub fn join_to_string(items: I) -> String\r\n where\r\n T: ToString,\r\n I: IntoIterator,\r\n {\r\n items\r\n .into_iter()\r\n .map(|item| item.to_string())\r\n .collect::>()\r\n .join(\" \")\r\n }\r\n\r\n pub trait ReformatWithTrim {\r\n fn reformat_with_trim(self) -> String;\r\n }\r\n\r\n impl ReformatWithTrim for &str {\r\n fn reformat_with_trim(self) -> String {\r\n let lines: Vec = self\r\n .trim()\r\n .lines()\r\n .map(|line| line.trim_start().to_string())\r\n .collect();\r\n lines.join(\"\\n\") + \"\\n\"\r\n }\r\n }\r\n\r\n pub trait FormatBits {\r\n fn pm_fmt(self) -> String;\r\n }\r\n\r\n impl FormatBits for &[bool] {\r\n fn pm_fmt(self) -> String {\r\n self.iter()\r\n .map(|item| if *item { \"+\" } else { \"-\" })\r\n .collect()\r\n }\r\n }\r\n}\r\n\r\nuse div_euclid::*;\r\nmod div_euclid {\r\n pub trait DivEuclid {\r\n fn div_euclid(self, rhs: Self) -> Self;\r\n }\r\n\r\n macro_rules! impl_ops {\r\n ($($type:tt)*) => {\r\n $(\r\n impl DivEuclid for $type {\r\n fn div_euclid(self, rhs: Self) -> Self {\r\n self.div_euclid(rhs)\r\n }\r\n }\r\n )*\r\n };\r\n }\r\n\r\n impl_ops!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);\r\n}\r\n\r\nuse one::*;\r\nmod one {\r\n pub trait One {\r\n fn one() -> Self;\r\n fn is_one(&self) -> bool;\r\n }\r\n\r\n macro_rules! impl_ops {\r\n ($($type:tt)*) => {\r\n $(\r\n impl One for $type {\r\n fn one() -> Self {\r\n 1\r\n }\r\n\r\n fn is_one(&self) -> bool {\r\n *self == 1\r\n }\r\n }\r\n )*\r\n };\r\n }\r\n\r\n impl_ops!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);\r\n}\r\n", "src_uid": "f985d7a6e7650a9b855a4cef26fd9b0d"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::io::stdin;\n\nmod util {\n use std::io::stdin;\n use std::str::FromStr;\n use std::fmt::Debug;\n\n #[allow(dead_code)]\n pub fn line() -> String {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn gets() -> Vec\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse().unwrap())\n .collect()\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn main() {\n let n = get!(u64);\n let m9 = (0..)\n .take_while(|&x| (2 * n - 1) >= 10u64.pow(x as u32) - 1)\n .last()\n .unwrap();\n\n let mut ans = 0;\n for i in 0.. {\n let y = i as u64 * 10u64.pow(m9 as u32) + 10u64.pow(m9 as u32) - 1;\n if y > 2 * n - 1 {\n break;\n }\n if y <= 2 * n - 1 && y > 0 {\n if y > n {\n ans += (n - (y - n) - 1) / 2 + 1;\n } else {\n ans += (y - 1) / 2;\n }\n }\n }\n\n println!(\"{}\", ans);\n}\n", "src_uid": "c20744c44269ae0779c5f549afd2e3f2"} {"source_code": "fn main() {\n let (_, l) = {\n let r = getvec::();\n (r[0] as usize, r[1])\n };\n let a = getvec::();\n let b = getvec::();\n let am = calc(&a, l);\n // for x in am.clone() {\n // println!(\"{}\", x);\n // }\n let bm = calc(&b, l);\n println!(\"{}\",\n match ok(&am, &bm) {\n true => \"YES\",\n false => \"NO\",\n });\n}\nfn ok(a: &Vec, b: &Vec) -> bool {\n let n = a.len();\n for i in 0..n {\n let mut r = true;\n for j in 0..n {\n let j_ = (j + i) % n;\n if a[j] != b[j_] {\n r = false;\n break;\n }\n }\n if r {\n return true;\n }\n }\n false\n}\nfn calc(seq: &Vec, l: i32) -> Vec {\n let mut res = Vec::new();\n let n = seq.len();\n for i in 0..n - 1 {\n res.push(seq[i + 1] - seq[i]);\n }\n res.push(l - seq[n - 1] + seq[0]);\n res\n}\n#[allow(dead_code)]\nfn next_line() -> String {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n input\n}\n\n#[allow(dead_code)]\nfn getnum() -> T {\n let res = next_line();\n res.trim().parse::().ok().unwrap()\n}\n\n#[allow(dead_code)]\nfn getvec() -> Vec {\n let res = next_line();\n res.split_whitespace().map(|x| x.parse::().ok().unwrap()).collect()\n}\n", "src_uid": "3d931684ca11fe6141c6461e85d91d63"} {"source_code": "// This code is licensed under the terms of Apache-2.0 or MIT License , at your choice.\n\nuse crate::comprog_lib::scanner::Scanner;\nuse std::cmp::min;\nuse std::io::{self, Read, Write};\npub fn solve(read: R, out: &mut W) -> io::Result<()> {\n let mut sc = Scanner::from(read);\n let n = sc.usize();\n let s = sc.token();\n let mut next = vec![[n; 26]; n + 1];\n for i in (0..n).rev() {\n next[i] = next[i + 1].clone();\n next[i][(s[i] - b'a') as usize] = i;\n }\n #[allow(non_snake_case)]\n let INF = std::i32::MAX;\n let mut dp = vec![vec![INF; n + 1]; n + 1];\n let mut dp2 = vec![vec![[INF; 26]; n + 1]; n + 1];\n for i in 0..=n {\n dp[i][i] = 0;\n for a in 0..26 {\n dp2[i][i][a] = 0;\n }\n }\n for len in 1..=n {\n for l in 0..=n - len {\n let r = l + len;\n for a in 0..26 {\n let mut x = len as i32;\n if (s[r - 1] - b'a') as usize == a {\n x = min(x, dp2[l][r - 1][a]);\n }\n for k in l + 1..r {\n x = min(x, dp2[l][k][a] + dp[k][r]);\n }\n dp2[l][r][a] = x;\n }\n dp[l][r] = dp2[l][r].iter().cloned().min().unwrap() + 1;\n }\n }\n let ans = dp[0][n];\n writeln!(out, \"{}\", ans)?;\n Ok(())\n}\nfn main() {\n let stdin = io::stdin();\n let mut stdout = io::BufWriter::new(io::stdout());\n solve(stdin.lock(), &mut stdout).unwrap();\n}\nmod comprog_lib {\n // comprog_lib-0.1.0\n pub mod scan_buf {\n use std::io::{self, Read};\n #[derive(Debug, Clone)]\n pub struct ScanBuf {\n buf: Vec,\n pos: usize,\n end: usize,\n }\n #[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]\n pub struct ScanRange(pub usize, pub usize);\n impl ScanRange {\n pub fn slice(self, buf: &ScanBuf) -> &[u8] {\n &buf.buf[self.0..self.1]\n }\n }\n impl ScanBuf {\n pub fn new(initial_capacity: usize) -> Self {\n ScanBuf {\n buf: vec![0; initial_capacity],\n pos: 0,\n end: 0,\n }\n }\n pub fn scan bool>(\n &mut self,\n mut reader: R,\n mut pred: P,\n ) -> io::Result {\n let start = self.pos;\n loop {\n if self.pos >= self.end {\n if self.pos >= self.buf.len() {\n let new_len = std::cmp::max(self.buf.len(), 1) * 2;\n self.buf.resize(new_len, 0);\n }\n self.end += match reader.read(&mut self.buf[self.pos..]) {\n Ok(0) => return Ok(ScanRange(start, self.pos)),\n Ok(n) => n,\n Err(ref e) if e.kind() == io::ErrorKind::Interrupted => 0,\n Err(e) => return Err(e),\n };\n }\n assert!(self.end <= self.buf.len());\n while self.pos < self.end {\n if pred(self.buf[self.pos]) {\n return Ok(ScanRange(start, self.pos));\n }\n self.pos += 1;\n }\n }\n }\n }\n }\n pub mod scanner {\n use crate::comprog_lib::scan_buf::{ScanBuf, ScanRange};\n use std::io::Read;\n #[derive(Debug, Clone)]\n pub struct Scanner {\n pub reader: R,\n pub buf: ScanBuf,\n }\n impl From for Scanner {\n fn from(r: R) -> Self {\n Scanner {\n reader: r,\n buf: ScanBuf::new(8192),\n }\n }\n }\n impl Scanner {\n pub fn scan bool>(&mut self, pred: P) -> ScanRange {\n self.buf.scan(&mut self.reader, pred).unwrap()\n }\n fn digits(&mut self) -> (bool, &[u8]) {\n self.scan(|b| b' ' < b);\n let mut negative = false;\n self.scan(|b| b != b'-' || std::mem::replace(&mut negative, true));\n let digits = self.scan(|b| b < b'0' || b'9' < b);\n (negative, digits.slice(&self.buf))\n }\n pub fn token_range(&mut self) -> ScanRange {\n self.scan(|b| b' ' < b);\n self.scan(|b| b <= b' ')\n }\n pub fn token(&mut self) -> Vec {\n self.token_range().slice(&self.buf).to_owned()\n }\n }\n macro_rules! impl_scan_int { ($($name:ident),*) => { impl Scanner { $( #[allow(unused)] pub fn $name(&mut self) -> $name { let (neg, digits) = self.digits(); if !neg { digits.iter().fold($name::default(), |x, b| x * 10 + $name::from(b - b'0')) } else { digits.iter().fold($name::default(), |x, b| x * 10 - $name::from(b - b'0')) } } )* } } }\n impl_scan_int!(u32, i32, u64, i64, usize);\n }\n}\n// Module comprog_lib contains code from comprog_lib licensed under Apache-2.0 OR MIT\n// Built by comprog-0.1.0 \n", "src_uid": "516a89f4d1ae867fc1151becd92471e6"} {"source_code": "//spnauti-rusT {{{\nuse std::io::*; use std::str::{self,*}; use std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)] macro_rules! min {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! max {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! l {\n\t($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};\n\t($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};\n\t(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};\n}\n#[allow(unused_macros)] macro_rules! v {\n\t([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};\n\t([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};\n}\n#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }\n#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }\n#[allow(dead_code)] fn writer() -> BufWriter { BufWriter::new(stdout()) }\nstruct WordReaderC {buf: Vec, pos: usize, q: std::io::StdinLock<'static>}//'\n#[allow(dead_code)] impl WordReaderC {\n\tfn new() -> Self {\n\t\tlet r = unsafe {&*Box::into_raw(Box::new(stdin()))};\n\t\tSelf { q: r.lock(), buf: v!([]), pos: 0 }\n\t}\n\tfn next_line(&mut self) -> bool {\n\t\tself.buf.clear(); self.pos = 0;\n\t\tself.q.read_until(b'\\n', &mut self.buf).unwrap_or(0) > 0\n\t}\n\tfn is_ws(c: u8) -> bool {\n\t\tc == b' ' || c == b'\\r' || c == b'\\n' || c == b'\\t'\n\t}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos == self.buf.len() { if !self.next_line() { return None; } }\n\t\tself.pos += 1; Some(self.buf[self.pos - 1])\n\t}\n\tfn vb(&mut self) -> Vec {\n\t\tlet mut s = v!([8]);\n\t\tlet mut f = false;\n\t\tloop {\n\t\t\tif let Some(c) = self.byte() {\n\t\t\t\tif !Self::is_ws(c) {\n\t\t\t\t\ts.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t} else if f { break; }\n\t\t\t} else { break; }\n\t\t}\n\t\ts\n\t}\n\tfn board(&mut self, r: usize, c: Option) -> Vec> {\n\t\tlet mut res = v!([r]);\n\t\tlet c = c.unwrap_or(0);\n\t\trep!{[r]\n\t\t\tlet t = self.vb();\n\t\t\tassert!(c == 0 || t.len() == c);\n\t\t\tres.push(t);\n\t\t}\n\t\tres\n\t}\n\tfn framed_board(&mut self, r: usize, c: usize, f: u8) -> Vec> {\n\t\tlet mut res = v!([r+2]);\n\t\tres.push( v!([c+2] = f) );\n\t\trep!{[r]\n\t\t\tlet mut t = self.vb();\n\t\t\tassert!(t.len() == c);\n\t\t\tt.reserve(2);\n\t\t\tt.insert(0,f);\n\t\t\tt.push(f);\n\t\t\tres.push(t);\n\t\t}\n\t\tres.push( v!([c+2] = f) );\n\t\tres\n\t}\n\tfn s(&mut self) -> String { String::from_utf8(self.vb()).expect(\"invalid utf8\") }\n\tfn i(&mut self) -> i32 { self.p() }\n\tfn l(&mut self) -> i64 { self.p() }\n\tfn u(&mut self) -> usize { self.p() }\n\tfn f(&mut self) -> f64 { self.p() }\n\tfn vi(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vl(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vu(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn p(&mut self) -> T where T::Err: Debug {\n\t\tlet w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap()\n\t}\n\tfn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n\t\t(0..n).map(|_|self.p()).collect()\n\t}\n\tfn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n\t\tself.vp(n).into_iter()\n\t}\n\tfn graph(&mut self, n: usize, m: usize) -> Vec> {\n\t\tlet mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); e[a].push(b); e[b].push(a); } e\n\t}\n\tfn graph_w(&mut self, n: usize, m: usize) -> Vec> where T::Err: Debug {\n\t\tlet mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); let c: T = self.p(); e[a].push((b,c)); e[b].push((a,c)); } e\n\t}\n}\n//------------------- End rusT }}}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tlet s = rin.vb();\n\tlet n = s.len();\n\tlet mut sol = 1000;\n\tfor (y,x) in vec![(b'2',b'5'), (b'5',b'0'), (b'7',b'5'), (b'0',b'0')] {\n\t\tl!(mut px,py = n);\n\t\tfor i in (0..n).rev() {\n\t\t\tif px == n && s[i] == x {\n\t\t\t\tpx = i;\n\t\t\t} else if py == n && s[i] == y {\n\t\t\t\tpy = i;\n\t\t\t}\n\t\t}\n\t\tif px < n && py < n {\n\t\t\tlet mut res = 2*n - 3 - px - py;\n\t\t\tif px < py {\n\t\t\t\tres += 1;\n\t\t\t}\n\t\t\tlet mut add = 0;\n\t\t\tlet mut done = false;\n\t\t\tfor i in 0..n {\n\t\t\t\tif i == px || i == py {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif s[i] != b'0' {\n\t\t\t\t\tdone = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tadd += 1;\n\t\t\t}\n\t\t\tres += add;\n\t\t\tmin!(sol, res);\n\t\t}\n\t}\n\tif sol < 1000 {\n\t\twriteln!(rout, \"{}\", sol).ok();\n\t} else {\n\t\twriteln!(rout, \"-1\").ok();\n\t}\n}\n", "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"source_code": "//spnauti-rusT {{{\nuse std::io::*; use std::str::{self,*}; use std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)] macro_rules! min {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! max {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! l {\n\t($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};\n\t($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};\n\t(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};\n}\n#[allow(unused_macros)] macro_rules! v {\n\t([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};\n\t([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};\n}\n#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }\n#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }\n#[allow(dead_code)] fn writer() -> BufWriter { BufWriter::new(stdout()) }\nstruct WordReaderC {buf: Vec, pos: usize, q: std::io::StdinLock<'static>}//'\n#[allow(dead_code)] impl WordReaderC {\n\tfn new() -> Self {\n\t\tlet r = unsafe {&*Box::into_raw(Box::new(stdin()))};\n\t\tSelf { q: r.lock(), buf: v!([]), pos: 0 }\n\t}\n\tfn next_line(&mut self) -> bool {\n\t\tself.buf.clear(); self.pos = 0;\n\t\tself.q.read_until(b'\\n', &mut self.buf).unwrap_or(0) > 0\n\t}\n\tfn is_ws(c: u8) -> bool {\n\t\tc == b' ' || c == b'\\r' || c == b'\\n' || c == b'\\t'\n\t}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos == self.buf.len() { if !self.next_line() { return None; } }\n\t\tself.pos += 1; Some(self.buf[self.pos - 1])\n\t}\n\tfn vb(&mut self) -> Vec {\n\t\tlet mut s = v!([8]);\n\t\tlet mut f = false;\n\t\tloop {\n\t\t\tif let Some(c) = self.byte() {\n\t\t\t\tif !Self::is_ws(c) {\n\t\t\t\t\ts.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t} else if f { break; }\n\t\t\t} else { break; }\n\t\t}\n\t\ts\n\t}\n\tfn vvb(&mut self, r: usize, c: Option) -> Vec> {\n\t\tlet mut res = v!([r]);\n\t\tlet c = c.unwrap_or(0);\n\t\trep!{[r]\n\t\t\tlet t = self.vb();\n\t\t\tassert!(c == 0 || t.len() == c);\n\t\t\tres.push(t);\n\t\t}\n\t\tres\n\t}\n\tfn s(&mut self) -> String { String::from_utf8(self.vb()).expect(\"invalid utf8\") }\n\tfn i(&mut self) -> i32 { self.p() }\n\tfn l(&mut self) -> i64 { self.p() }\n\tfn u(&mut self) -> usize { self.p() }\n\tfn f(&mut self) -> f64 { self.p() }\n\tfn vi(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vl(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vu(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn p(&mut self) -> T where T::Err: Debug {\n\t\tlet w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap()\n\t}\n\tfn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n\t\t(0..n).map(|_|self.p()).collect()\n\t}\n\tfn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n\t\tself.vp(n).into_iter()\n\t}\n}\n//------------------- End rusT }}}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\tconst A: usize = 60;\n\tconst X: i32 = 1000000;\n\n\tlet n = rin.u();\n\tlet a = rin.vi(n);\n\tlet mut p = v!([]);\n\tfor i in 2..A {\n\t\tp.push(i);\n\t\tfor j in 2..i {\n\t\t\tif i % j == 0 {\n\t\t\t\tp.pop();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\tlet mut b = v!([A] = 0);\n\tfor i in 2..A {\n\t\tlet mut bb = 0;\n\t\tfor j in 0..p.len() {\n\t\t\tif i % p[j] == 0 {\n\t\t\t\tbb |= 1 << j;\n\t\t\t}\n\t\t}\n\t\tb[i] = bb;\n\t}\n\tlet m = p.len();\n\tlet mut dp = v!([n+1][1<().unwrap()).collect::>();\n input = String::new();\n stdin().read_line(&mut input).unwrap();\n let b = input.split_whitespace().map(|k| k.parse::().unwrap()).collect::>();\n (a, b)\n };\n\n if b.len() != 1 {\n println!(\"Yes\");\n } else {\n let a: Vec<_> = a.into_iter().map(|k| if k == 0 {b[0]} else {k}).collect();\n for (x, y) in a.iter().zip(a.iter().skip(1)) {\n if y <= x {\n println!(\"Yes\");\n std::process::exit(0);\n }\n }\n println!(\"No\");\n }\n}\n", "src_uid": "40264e84c041fcfb4f8c0af784df102a"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nfn get_num() -> i32 {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)\n .expect(\"\");\n\n i32::from_str(input.trim()).unwrap()\n}\n\nfn get_nums() -> Vec {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)\n .expect(\"\");\n\n input.trim()\n .split_whitespace()\n .map(|s| i32::from_str(s).unwrap())\n .collect::>()\n}\n\nfn main() {\n let n = get_num();\n let s = get_nums().iter().sum::();\n \n let mut c = 0;\n for i in 1..=5 {\n if (s + i - n - 2) % (n + 1) != 0 {\n c += 1;\n }\n }\n\n println!(\"{}\", c);\n}\n\n", "src_uid": "ff6b3fd358c758324c19a26283ab96a4"} {"source_code": "use std::error::Error;\nuse std::io;\nuse std::collections::HashMap;\n\nfn main() {\n if let Err(e) = run() {\n println!(\"{}\", e);\n }\n}\n\nfn run() -> Result<(), Box> {\n let mut s = String::new();\n io::stdin().read_line(&mut s)?;\n let s: Vec<&str> = s.trim().split(\" \").collect();\n let _: i32 = s[0].parse()?;\n let k: i32 = s[1].parse()?;\n let mut s = String::new();\n io::stdin().read_line(&mut s)?;\n let mut m = HashMap::new();\n for b in s.trim().as_bytes() {\n match m.get(b).cloned() {\n Some(x) => m.insert(b, x + 1),\n _ => m.insert(b, 1)\n };\n }\n for (_, x) in &m {\n if *x > k {\n println!(\"NO\");\n return Ok(())\n }\n }\n println!(\"YES\");\n Ok(())\n}\n", "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"source_code": "use std::io::{self, BufRead};\nuse std::cmp;\n\nfn largest_prime_factor(mut n: u32) -> u32 {\n let mut k = 2;\n let mut last_factor = 1;\n while k*k <= n {\n while n % k == 0 {\n n = n / k;\n last_factor = k;\n }\n k += 1;\n }\n if n > 1 { n } else { last_factor }\n}\n\nfn candidate(n: u32) -> u32 {\n let p = largest_prime_factor(n);\n if p == n {\n n\n } else {\n n - p + 1\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock().lines().next().unwrap().unwrap();\n let n: u32 = line.parse().unwrap();\n let low = candidate(n);\n let mut ans = low;\n for i in low..n+1 {\n ans = cmp::min(ans, candidate(i));\n }\n println!(\"{}\", ans);\n}\n", "src_uid": "43ff6a223c68551eff793ba170110438"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, bytes) => {\n read_value!($iter, String).bytes().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nfn run() {\n input! {\n n: usize,\n a: [usize; n],\n }\n let mut a = a;\n a.sort();\n a.dedup();\n let n = a.len();\n let mut ans = \"NO\";\n for i in 2..n {\n let s = a[i - 2];\n if a[(i - 2)..=i] == [s, s + 1, s + 2] {\n ans = \"YES\";\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "d6c876a84c7b92141710be5d76536eab"} {"source_code": "use std::io::{self, Write};\n\nfn inv(mut a: i64, modulo: i64) -> i64 {\n let mut b: i64 = modulo - 2;\n let mut ans: i64 = 1;\n while b > 0 {\n if b & 1 == 1 {\n ans = (ans * a) % modulo;\n }\n a = (a * a) % modulo;\n b >>= 1;\n }\n ans\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut sc = cf_scanner::Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n\n let (n, modulo): (usize, i64) = (sc.next(), sc.next());\n\n let mut pow2: Vec = vec![1; n + 1];\n (1..=n).for_each(|i| pow2[i] = (2 * pow2[i-1]) % modulo);\n\n let mut fact: Vec = vec![1; n + 1];\n (1..=n).for_each(|i| fact[i] = (i as i64 * fact[i-1]) % modulo);\n\n let i_fact: Vec = (0..=n).map(|i| inv(fact[i], modulo)).collect();\n\n let mut choose: Vec> = vec![vec![0; n + 1]; n + 1];\n for i in 0..=n {\n for j in 0..=i {\n choose[i][j] = ((fact[i] * i_fact[j]) % modulo * i_fact[i - j]) % modulo;\n }\n }\n\n let mut dp: Vec> = vec![vec![0; n + 5]; n + 5];\n dp[0][0] = 1;\n for i in 1..=n {\n dp[i][i] = pow2[i-1];\n for j in 1..=i {\n for k in 1..j {\n if i < k + 1 {\n break;\n } \n dp[i][j] += ((pow2[k-1] * choose[j][k]) % modulo * dp[i - k - 1][j - k]) % modulo;\n dp[i][j] %= modulo;\n }\n }\n }\n \n let ans: i64 = (1..=n).fold(0 as i64, |x, y| (x + dp[n][y]) % modulo);\n\n writeln!(out, \"{}\", ans).unwrap();\n}\n\n#[allow(dead_code)]\nmod cf_scanner {\n use std::io;\n use std::str::{FromStr, SplitAsciiWhitespace};\n\n pub struct Scanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n }\n\n impl Scanner {\n pub fn new(reader: R) -> Scanner {\n Scanner {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = std::str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n\n pub fn next_vec(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next()).collect()\n }\n }\n}\n", "src_uid": "4f0e0d1deef0761a46b64de3eb98e774"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nfn run() {\n input! {\n a: u64,\n b: u64,\n }\n if a > b || (a & 1) != (b & 1) {\n println!(\"-1\");\n return;\n }\n if a == b {\n if a == 0 {\n println!(\"0\");\n } else {\n println!(\"1\\n{}\", a);\n }\n return;\n }\n let x = (b - a) / 2;\n if (a & x) == 0 {\n println!(\"2\\n{} {}\", a ^ x, x);\n } else {\n println!(\"3\\n{} {} {}\", a, x, x);\n }\n // a + x + x = b\n // a ^ x ^ x = a\n}\n\nfn main() {\n run();\n}\n", "src_uid": "490f23ced6c43f9e12f1bcbecbb14904"} {"source_code": "\nfn main(){\n let mut whiteCount = 0; let mut blackCount = 0; let mut i = 1;\n while i <= 8{\n \n let mut input1 = String::new(); let inp = std::io::stdin().read_line(&mut input1).unwrap();\n \n for charC in input1.chars(){ \n whiteCount =whiteCount+ white_valueof(charC); blackCount= blackCount + black_valueof(charC); \n }\n i =i+ 1; \n }\n \n \n if whiteCount < blackCount{\n println!(\"Black\");\n }\n else if whiteCount > blackCount{\n println!(\"White\");\n }\n else{\n println!(\"Draw\");\n }\n }\n \nfn white_valueof(c:char) -> i32{\n match c{'Q'=> 9,'R'=> 5,'B'=> 3,'N'=> 3,'P'=> 1,_ => 0,}\n \n}\nfn black_valueof(c:char) -> i32{\n match c{'q'=> 9, 'r'=> 5, 'b'=> 3, 'n'=> 3,'p'=> 1, _ => 0, }\n}", "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"source_code": "use std::io::stdin;\nuse std::collections::HashMap;\n\nmacro_rules! readln {\n () => {{ let mut line = String::new(); stdin().read_line(&mut line).unwrap(); line }};\n ($type:ty) => {{ readln!().split_whitespace().next().unwrap().parse::<$type>().unwrap() }};\n (|$type_vec:ty|) => {{ readln!().split_whitespace().map(|it| it.parse().unwrap()).collect::>() }};\n ($($type:ty),*) => {{ let line = readln!(); let mut iter = line.split_whitespace(); ($(iter.next().unwrap().parse::<$type>().unwrap(),)*) }};\n ($($type:ty),*, |$type_vec:ty|) => {{ let line = readln!(); let mut iter = line.split_whitespace();\n ($(iter.next().unwrap().parse::<$type>().unwrap(),)*iter.map(|it| it.parse().unwrap()).collect::>(),)}};\n}\n\nfn main() {\n let t = readln!(usize);\n for _ in 0..t {\n let (n, k, d) = readln!(usize, usize, usize);\n let a = readln!(|usize|);\n\n let mut count = HashMap::with_capacity(k);\n\n for i in 0..d {\n *count.entry(a[i]).or_insert(0usize) += 1;\n }\n\n let mut size = count.len();\n let mut min_size = size;\n for i in d..n {\n let x = count.entry(a[i - d]).or_insert(0);\n *x -= 1;\n if *x == 0 {\n size -= 1;\n }\n\n let y = count.entry(a[i]).or_insert(0);\n *y += 1;\n if *y == 1 {\n size += 1;\n }\n min_size = min_size.min(size);\n }\n println!(\"{}\", min_size);\n }\n}", "src_uid": "56da4ec7cd849c4330d188d8c9bd6094"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.u();\n let mut a = input.vi(n);\n a.sort();\n let sol: i32 = a.iter().zip(a.iter().skip(1)).step_by(2).map(|(&a,&b)| b - a).sum();\n println!(\"{}\", sol);\n}\n\n", "src_uid": "55485fe203a114374f0aae93006278d3"} {"source_code": "use std::io::{self, Stdin};\nuse std::str::{self, FromStr};\nuse std::error::Error;\n\nfn exec() {\n let mut sc = Scanner::new();\n let n: usize = sc.ne();\n let a: Vec = (0..n).map(|_| sc.ne()).collect();\n let b: Vec = (0..n).map(|_| sc.ne()).collect();\n let mut cnt = vec![0i32; 6];\n for &x in &a {\n cnt[x] += 1;\n }\n for &x in &b {\n cnt[x] += 1;\n }\n let mut ok = true;\n for i in 1..6 {\n if cnt[i] & 1 == 1 {\n ok = false;\n }\n }\n if ok {\n let mut cnt2 = vec![0; 6];\n for &x in &a {\n cnt2[x] += 1;\n }\n let mut ans = 0;\n for i in 1..6 {\n let a = cnt[i] / 2;\n ans += (a - cnt2[i]).abs();\n }\n println!(\"{}\", ans / 2);\n } else {\n println!(\"-1\");\n }\n}\n\nfn main() {\n const STACK: usize = 16 * 1024 * 1024;\n let _ = std::thread::Builder::new()\n .stack_size(STACK)\n .spawn(|| { exec(); })\n .unwrap()\n .join()\n .unwrap();\n}\n\n#[allow(dead_code)]\nstruct Scanner {\n stdin: Stdin,\n id: usize,\n buf: Vec,\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new() -> Scanner {\n Scanner {\n stdin: io::stdin(),\n id: 0,\n buf: Vec::new(),\n }\n }\n fn next_line(&mut self) -> Option {\n let mut res = String::new();\n match self.stdin.read_line(&mut res) {\n Ok(0) => None,\n Ok(_) => Some(res),\n Err(why) => panic!(\"error in read_line: {}\", why.description()),\n }\n }\n fn next(&mut self) -> Option {\n while self.buf.len() == 0 {\n self.buf = match self.next_line() {\n Some(r) => {\n self.id = 0;\n r.trim().as_bytes().to_owned()\n }\n None => return None,\n };\n }\n let l = self.id;\n assert!(self.buf[l] != b' ');\n let n = self.buf.len();\n let mut r = l;\n while r < n && self.buf[r] != b' ' {\n r += 1;\n }\n let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::() {\n Ok(s) => Some(s),\n Err(_) => {\n panic!(\"parse error, {:?}\",\n String::from_utf8(self.buf[l..r].to_owned()))\n }\n };\n while r < n && self.buf[r] == b' ' {\n r += 1;\n }\n if r == n {\n self.buf.clear();\n } else {\n self.id = r;\n }\n res\n }\n fn ne(&mut self) -> T {\n self.next::().unwrap()\n }\n}\n", "src_uid": "47da1dd95cd015acb8c7fd6ae5ec22a3"} {"source_code": "fn main() {\n let n = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim_end().parse::().unwrap()\n };\n if n % 2 == 0 {\n println!(\"{}\", n / 2);\n } else {\n println!(\"-{}\", n / 2 + 1);\n }\n}\n", "src_uid": "689e7876048ee4eb7479e838c981f068"} {"source_code": "// ---------- begin chmin, chmax ----------\ntrait ChangeMinMax {\n fn chmin(&mut self, x: Self) -> bool;\n fn chmax(&mut self, x: Self) -> bool;\n}\n\nimpl ChangeMinMax for T {\n fn chmin(&mut self, x: Self) -> bool {\n *self > x && {\n *self = x;\n true\n }\n }\n fn chmax(&mut self, x: Self) -> bool {\n *self < x && {\n *self = x;\n true\n }\n }\n}\n// ---------- end chmin, chmax ----------\n// ---------- begin input macro ----------\n// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, bytes) => {\n read_value!($iter, String).bytes().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n// ---------- end input macro ----------\n\nfn run() {\n input! {\n n: u64,\n }\n let mul = |a: &[(u64, u64)], b: &[(u64, u64)]| -> Vec<(u64, u64)> {\n let mut c = vec![];\n for a in a.iter() {\n for b in b.iter() {\n c.push((a.0 + b.0, a.1 + b.1 - 1));\n }\n }\n c.sort_unstable();\n c.dedup_by(|a, b| {\n a.0 <= b.1 && {\n b.1.chmax(a.1);\n true\n }\n });\n c\n };\n let mut t = vec![(0, 1)];\n let mut s = vec![(1, 2), (5, 6), (10, 11), (50, 51)];\n let mut n = n;\n while n > 0 {\n if n & 1 == 1 {\n t = mul(&t, &s);\n }\n s = mul(&s, &s);\n n >>= 1;\n }\n let ans = t.iter().fold(0, |s, a| s + a.1 - a.0);\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "75ec99318736a8a1b62a8d51efd95355"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::*;\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($i:ident . $e:tt : $t:ty; $($a:ident),*) => {\n $( let $a: $t = $i.$e(); )*\n };\n ($i:ident . $e:tt; $($a:ident),*) => {\n $( let $a = $i.$e(); )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.s().into_bytes();\n let sol = (1..).flat_map(|a| iter::repeat(a).take(1<().unwrap();\n }\n\n let outcome = (-vec[1] * vec[0] - vec[3] * 2) + (vec[2] * vec[0] + vec[4] * 2);\n\n if outcome > 0 {\n println!(\"First\");\n } else if outcome < 0 {\n println!(\"Second\");\n } else {\n println!(\"Friendship\");\n }\n\n}", "src_uid": "10226b8efe9e3c473239d747b911a1ef"} {"source_code": "fn run() {\r\n input! {\r\n a: (usize, i64),\r\n b: (usize, i64),\r\n e: (usize, usize),\r\n }\r\n let inf = std::i64::MAX / 2;\r\n let mut memo = vec![inf; e.0 + 1];\r\n for i in 0..=e.0 {\r\n for j in 0..=e.0 {\r\n let d = e.0.min(i * (a.0 - e.1) + j * (b.0 - e.1));\r\n let t = (i as i64 * a.1).max(j as i64 * b.1);\r\n memo[d] = memo[d].min(t);\r\n }\r\n }\r\n for i in 1..=e.0 {\r\n for j in 1..=e.0 {\r\n let t = (i as i64 * a.1).max(j as i64 * b.1);\r\n let d = (i - 1) * (a.0 - e.1) + (j - 1) * (b.0 - e.1) + a.0 + b.0 - e.1;\r\n for k in 0..=(e.0 / d + 1) {\r\n let d = (k * d).min(e.0);\r\n memo[d] = memo[d].min(t * k as i64);\r\n }\r\n }\r\n }\r\n for i in (0..e.0).rev() {\r\n memo[i] = memo[i].min(memo[i + 1]);\r\n }\r\n for i in 1..=e.0 {\r\n let t = memo[i];\r\n for j in (i + 1)..=e.0 {\r\n memo[j] = memo[j].min(memo[j - i] + t);\r\n }\r\n }\r\n println!(\"{}\", memo[e.0]);\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n\r\n// ---------- begin input macro ----------\r\n// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\r\n#[macro_export]\r\nmacro_rules! input {\r\n (source = $s:expr, $($r:tt)*) => {\r\n let mut iter = $s.split_whitespace();\r\n input_inner!{iter, $($r)*}\r\n };\r\n ($($r:tt)*) => {\r\n let s = {\r\n use std::io::Read;\r\n let mut s = String::new();\r\n std::io::stdin().read_to_string(&mut s).unwrap();\r\n s\r\n };\r\n let mut iter = s.split_whitespace();\r\n input_inner!{iter, $($r)*}\r\n };\r\n}\r\n\r\n#[macro_export]\r\nmacro_rules! input_inner {\r\n ($iter:expr) => {};\r\n ($iter:expr, ) => {};\r\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\r\n let $var = read_value!($iter, $t);\r\n input_inner!{$iter $($r)*}\r\n };\r\n}\r\n\r\n#[macro_export]\r\nmacro_rules! read_value {\r\n ($iter:expr, ( $($t:tt),* )) => {\r\n ( $(read_value!($iter, $t)),* )\r\n };\r\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\r\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\r\n };\r\n ($iter:expr, chars) => {\r\n read_value!($iter, String).chars().collect::>()\r\n };\r\n ($iter:expr, bytes) => {\r\n read_value!($iter, String).bytes().collect::>()\r\n };\r\n ($iter:expr, usize1) => {\r\n read_value!($iter, usize) - 1\r\n };\r\n ($iter:expr, $t:ty) => {\r\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\r\n };\r\n}\r\n// ---------- end input macro ----------\r\n", "src_uid": "ca9d48e48e69b931236907a9ac262433"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n: i64 = input.p();\n let x = n * (n + 1) / 2;\n println!(\"{}\", x % 2);\n}\n\n", "src_uid": "fa163c5b619d3892e33e1fb9c22043a9"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nuse std::cmp::*;\nuse std::collections::BTreeMap;\n\nfn run() {\n input! {\n n: usize,\n p: [usize; n],\n }\n let mut cnt = [0; 2];\n for p in p.iter() {\n if *p == 0 {\n continue;\n }\n cnt[*p % 2] += 1;\n }\n let even = n / 2 - cnt[0];\n let odd = (n + 1) / 2 - cnt[1];\n let inf = n;\n let mut dp = BTreeMap::<(usize, usize, usize), usize>::new();\n dp.insert((0, even, odd), 0);\n dp.insert((1, even, odd), 0);\n for p in p.iter().rev() {\n let mut next = BTreeMap::<(usize, usize, usize), usize>::new();\n for ((b, x, y), v) in dp {\n if *p == 0 {\n if x > 0 {\n let po = next.entry((0, x - 1, y)).or_insert(inf);\n *po = min(*po, v + (b ^ 0));\n }\n if y > 0 {\n let po = next.entry((1, x, y - 1)).or_insert(inf);\n *po = min(*po, v + (b ^ 1));\n }\n } else {\n let po = next.entry((*p % 2, x, y)).or_insert(inf);\n *po = min(*po, v + (b ^ (*p & 1)));\n }\n }\n dp = next;\n }\n let mut ans = inf;\n for (_, v) in dp {\n ans = min(ans, v);\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "90db6b6548512acfc3da162144169dba"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes.by_ref().map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, [graph1; $len:expr]) => {{\n let mut g = vec![vec![]; $len];\n let ab = read_value!($next, [(usize1, usize1)]);\n for (a, b) in ab {\n g[a].push(b);\n g[b].push(a);\n }\n g\n }};\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n ($next:expr, usize1) => (read_value!($next, usize) - 1);\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n read_value!($next, [$t; len])\n }};\n ($next:expr, $t:ty) => ($next().parse::<$t>().expect(\"Parse error\"));\n}\n\n#[allow(unused)]\nmacro_rules! debug {\n ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());\n}\n#[allow(unused)]\nmacro_rules! debugln {\n ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());\n}\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (let _ = write!(out,$($format)*););\n }\n #[allow(unused)]\n macro_rules! putvec {\n ($v:expr) => {\n for i in 0..$v.len() {\n puts!(\"{}{}\", $v[i], if i + 1 == $v.len() {\"\\n\"} else {\" \"});\n }\n }\n }\n input!(s: [chars]);\n for s in s {\n let c = (s[0] as u8 - b'0') as usize;\n let n = s.len();\n puts!(\"{}\\n\", 10 * (c - 1) + n * (n + 1) / 2);\n }\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "289a55128be89bb86a002d218d31b57f"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\nuse std::collections::{*};\nuse std::io::{BufWriter, stdin, stdout, Write};\nconst BITS: usize = 19;\n \n#[derive(Default)]\nstruct Scanner {\n buffer: Vec\n}\nimpl Scanner {\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n \nfn main() {\n let mut scanner = Scanner::default();\n let s: String = scanner.next();\n let mut i = s.chars();\n while let Some(c) = i.next(){\n \tif c == '-' {\n \t\tif let Some(nc) = i.next(){\n \t\t\tif nc == '-'{\n \t\t\t\tprint![\"2\"];\n \t\t\t}\n \t\t\telse {\n \t\t\t\tprint![\"1\"];\n \t\t\t}\n \t\t}\n \t} else {\n \t\tprint![\"0\"];\n \t}\n }\n}", "src_uid": "46b5a1cd1bd2985f2752662b7dbb1869"} {"source_code": "use std::collections::HashMap;\nuse std::io;\nuse std::str::FromStr;\n\nfn get_num() -> usize {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input).expect(\"\");\n\n usize::from_str(input.trim()).unwrap()\n}\n\nfn main() {\n let mut m = HashMap::new();\n\n m.insert(0, \"zero\");\n m.insert(1, \"one\");\n m.insert(2, \"two\");\n m.insert(3, \"three\");\n m.insert(4, \"four\");\n m.insert(5, \"five\");\n m.insert(6, \"six\");\n m.insert(7, \"seven\");\n m.insert(8, \"eight\");\n m.insert(9, \"nine\");\n m.insert(10, \"ten\");\n m.insert(11, \"eleven\");\n m.insert(12, \"twelve\");\n m.insert(13, \"thirteen\");\n m.insert(14, \"fourteen\");\n m.insert(15, \"fifteen\");\n m.insert(16, \"sixteen\");\n m.insert(17, \"seventeen\");\n m.insert(18, \"eighteen\");\n m.insert(19, \"nineteen\");\n m.insert(20, \"twenty\");\n m.insert(30, \"thirty\");\n m.insert(40, \"forty\");\n m.insert(50, \"fifty\");\n m.insert(60, \"sixty\");\n m.insert(70, \"seventy\");\n m.insert(80, \"eighty\");\n m.insert(90, \"ninety\");\n\n let n = get_num();\n\n if n < 20 || m.contains_key(&n) {\n println!(\"{}\", m.get(&n).unwrap());\n } else {\n println!(\n \"{}-{}\",\n m.get(&(n / 10 * 10)).unwrap(),\n m.get(&(n % 10)).unwrap()\n );\n }\n}\n", "src_uid": "a49ca177b2f1f9d5341462a38a25d8b7"} {"source_code": "use std::io::stdin;\n\nuse std::cmp::{min,max};\n\nfn main() {\n let a = {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n input.trim().chars().map(|k| k.to_digit(10).unwrap()).collect::>()\n };\n\n let la: Vec<_> = a.iter().cloned().take(3).collect();\n let ra: Vec<_> = a.iter().cloned().skip(3).collect();\n\n let l: u32 = a.iter().cloned().take(3).sum();\n let r: u32 = a.iter().cloned().skip(3).sum();\n\n let diff = r as i32 - l as i32;\n\n if diff == 0 {\n println!(\"0\");\n std::process::exit(0);\n }\n\n let (mut up, mut down) = if diff > 0 {\n (ra, la)\n } else {\n (la, ra)\n };\n\n let mut v = Vec::new();\n v.append(&mut up);\n v.append(&mut down);\n\n for a in v.iter_mut().skip(3) {\n *a = 9 - *a;\n }\n\n v.sort();\n\n let diff = diff.abs();\n\n let mut sum = 0u32;\n\n for (i, k) in v.into_iter().rev().enumerate() {\n if sum >= diff as u32 {\n println!(\"{}\", i);\n std::process::exit(0);\n }\n sum += k;\n }\n}\n", "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"source_code": "//codeforces.com:1.19\nuse std::{io,cmp};\nfn main(){\n let mut z=String::new();io::stdin().read_line(&mut z);let y:Vec<&str>=z.split_whitespace().collect();let a:i32=y[0].parse().unwrap();let b:i32=y[1].parse().unwrap();\n if a==0&&b>0{print!(\"Impossible\");return}\n print!(\"{} {}\",cmp::max(a,b),cmp::max(a+b-1,a+0))\n}", "src_uid": "1e865eda33afe09302bda9077d613763"} {"source_code": "use std::cmp::Ordering;\nuse std::collections::HashSet;\nuse std::collections::VecDeque;\nuse std::error::Error;\nuse std::io::{self, Read};\ntype Result = ::std::result::Result>;\nfn main() -> Result<()> {\n let mut input = String::new();\n io::stdin().read_to_string(&mut input)?;\n let mut lines = input.lines();\n let mut args = lines.next().unwrap().split_whitespace();\n let n: usize = args.next().unwrap().parse()?;\n let x: u64 = args.next().unwrap().parse()?;\n if check(x, n) {\n println!(\"1\");\n return Ok(());\n }\n let mut vals = HashSet::new();\n vals.insert(x);\n let mut queue = VecDeque::new();\n queue.push_front(x);\n let mut depth = 1;\n let mut cur_width = 1;\n let mut next_width = 0;\n while !queue.is_empty() {\n let v = queue.pop_back().unwrap();\n cur_width -= 1;\n\n let v_d = digits(v);\n let mut flag = [false; 10];\n for d in v_d {\n if d != 0 && d != 1 {\n let tmp = v * d as u64;\n if check(tmp, n) {\n println!(\"{}\", depth);\n return Ok(());\n }\n if !vals.contains(&tmp) {\n queue.push_front(tmp);\n next_width += 1;\n vals.insert(tmp);\n }\n }\n }\n if cur_width == 0 {\n depth += 1;\n cur_width = next_width;\n next_width = 0;\n }\n }\n println!(\"-1\");\n Ok(())\n}\nfn digits(num: u64) -> impl Iterator {\n num.to_string()\n .chars()\n .map(|d| d.to_digit(10).unwrap())\n .collect::>()\n .into_iter()\n}\nfn check(num: u64, n: usize) -> bool {\n if num.to_string().len() >= n {\n true\n } else {\n false\n }\n}\n#[test]\nfn test_split() {}\n", "src_uid": "cedcc3cee864bf8684148df93804d029"} {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::{cell::{Cell, RefCell, UnsafeCell}, cmp::{Ordering, Reverse, max, min}, collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, hash_map::{DefaultHasher, RandomState}}, error::Error, fmt::{Display, Write as FmtWrite}, hash::{BuildHasher, Hash, Hasher}, io::{BufWriter, Read, Stdin, Stdout, Write}, iter::{FromIterator, Peekable}, mem::swap, ops::*, process::exit, rc::Rc, str::{FromStr, from_utf8_unchecked}, time::{Duration, Instant}, convert::{TryInto, TryFrom}, marker::PhantomData};\n\nconst IO_BUF_SIZE: usize = 1 << 16;\ntype Input = Scanner;\ntype Output = BufWriter;\nfn _init_input() -> Input { Scanner::new(std::io::stdin()) }\nfn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) }\n\n#[repr(transparent)] struct Unsync(T);\nunsafe impl Sync for Unsync {}\n \ntype BadLazy = Unsync>>;\nimpl BadLazy {\n const fn new() -> Self { Self(UnsafeCell::new(None)) }\n}\n \nstatic INPUT: BadLazy = BadLazy::new();\nstatic OUTPUT: BadLazy = BadLazy::new();\n \nfn inp R, R>(f: F) -> R {\n unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) }\n}\nfn out R, R>(f: F) -> R {\n unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) }\n}\n\nmacro_rules! read {\n () => { read() };\n ($t: ty) => { read::<$t>() };\n ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) };\n [$t: ty; $n: expr] => { read_vec::<$t>($n) };\n}\nmacro_rules! println { \n () => { out(|x| { let _ = writeln!(x); }) };\n ($exp: expr) => { out(|x| { let _ = writeln!(x, \"{}\", $exp); }) }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = writeln!(x, $fmt, $($arg)*); }) }\n}\nmacro_rules! print { \n ($exp: expr) => { out(|x| { let _ = write!(x, \"{}\", $exp); }) }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = write!(x, $fmt, $($arg)*); }) }\n}\n\nfn out_flush() { out(|x| { let _ = x.flush(); }); }\n\nfn input_is_eof() -> bool { inp(|x| x.eof()) }\nfn read_byte() -> u8 { inp(|x| x.byte()) }\nfn read_bytes_no_skip(n: usize) -> Vec { inp(|x| x.bytes_no_skip(n)) }\nfn read_bytes(n: usize) -> Vec { inp(|x| x.bytes(n)) }\nfn read_bytes2(n: usize, m: usize) -> Vec> { inp(|x| x.bytes2(n, m)) }\nfn read_token() -> Vec { inp(|x| x.token_bytes()) }\nfn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } }\nfn read_line() -> Vec { inp(|x| x.line_bytes()) }\nfn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } }\nfn read() -> T { read_token_str().parse::().ok().expect(\"failed parse\") }\nfn read_vec(n: usize) -> Vec { (0..n).map(|_| read()).collect() }\nfn read_vec2(n: usize, m: usize) -> Vec> { (0..n).map(|_| read_vec(m)).collect() }\n\nstruct Scanner {\n src: R,\n _buf: Vec,\n _pt: usize, // pointer\n _rd: usize, // bytes read\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new(src: R) -> Scanner {\n Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }\n }\n \n fn _check_buf(&mut self) {\n if self._pt == self._rd {\n self._rd = self.src.read(&mut self._buf).unwrap_or(0);\n self._pt = (self._rd == 0) as usize;\n }\n }\n \n // returns true if end of file\n fn eof(&mut self) -> bool {\n self._check_buf();\n self._rd == 0\n }\n \n // filters \\r, returns \\0 if eof\n fn byte(&mut self) -> u8 {\n loop {\n self._check_buf();\n if self._rd == 0 { return 0; }\n let res = self._buf[self._pt];\n self._pt += 1;\n if res != b'\\r' { return res; }\n }\n }\n\n fn bytes_no_skip(&mut self, n: usize) -> Vec { (0..n).map(|_| self.byte()).collect() }\n fn bytes(&mut self, n: usize) -> Vec {\n let res = self.bytes_no_skip(n);\n self.byte();\n res\n }\n fn bytes2(&mut self, n: usize, m: usize) -> Vec> { (0..n).map(|_| self.bytes(m)).collect() }\n \n fn token_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c <= b' ' {\n if c == b'\\0' { return res; }\n c = self.byte();\n }\n loop {\n res.push(c);\n c = self.byte();\n if c <= b' ' { return res; }\n }\n }\n \n fn line_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c != b'\\n' && c != b'\\0' {\n res.push(c);\n c = self.byte();\n }\n res\n }\n}\n\ntrait JoinToStr { \n fn join_to_str(self, sep: &str) -> String;\n fn concat_to_str(self) -> String;\n}\nimpl> JoinToStr for I { \n fn join_to_str(mut self, sep: &str) -> String {\n match self.next() {\n Some(first) => {\n let mut res = first.to_string();\n while let Some(item) = self.next() {\n res.push_str(sep);\n res.push_str(&item.to_string());\n }\n res\n }\n None => { String::new() }\n }\n }\n \n fn concat_to_str(self) -> String {\n let mut res = String::new();\n for item in self { res.push_str(&item.to_string()); }\n res\n }\n}\ntrait AsStr { fn as_str(&self) -> &str; }\nimpl AsStr for [u8] { fn as_str(&self) -> &str {std::str::from_utf8(self).expect(\"attempt to convert non-UTF8 byte string.\")} }\n\nmacro_rules! veci {\n ($n:expr , $i:ident : $gen:expr) => {{\n let _veci_n = $n;\n let mut _veci_list = Vec::with_capacity(_veci_n);\n for $i in 0.._veci_n {\n _veci_list.push($gen);\n }\n _veci_list\n }};\n ($n:expr , $gen:expr) => { veci!($n, _veci_: $gen) }\n}\n\nfn abs_diff + PartialOrd>(x: T, y: T) -> T {\n if x < y { y - x } else { x - y }\n}\n\ntrait CommonNumExt {\n fn div_ceil(self, b: Self) -> Self;\n fn div_floor(self, b: Self) -> Self;\n fn gcd(self, b: Self) -> Self;\n fn highest_one(self) -> Self;\n fn lowest_one(self) -> Self;\n fn sig_bits(self) -> u32;\n}\n\nmacro_rules! impl_common_num_ext {\n ($($ix:tt = $ux:tt),*) => {\n $(\n impl CommonNumExt for $ux {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { self / b }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self;\n if a == 0 || b == 0 { return a | b; }\n let shift = (a | b).trailing_zeros();\n a >>= a.trailing_zeros();\n b >>= b.trailing_zeros();\n while a != b {\n if a > b { a -= b; a >>= a.trailing_zeros(); }\n else { b -= a; b >>= b.trailing_zeros(); }\n }\n a << shift\n }\n #[inline] fn highest_one(self) -> Self { \n if self == 0 { 0 } else { const ONE: $ux = 1; ONE << self.sig_bits() - 1 } \n }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ux>() as u32 * 8 - self.leading_zeros() }\n }\n\n impl CommonNumExt for $ix {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if self ^ b >= 0 && r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { \n let q = self / b; let r = self % b;\n if self ^ b < 0 && r != 0 { q - 1 } else { q }\n }\n fn gcd(self, b: Self) -> Self {\n fn w_abs(x: $ix) -> $ux { (if x.is_negative() { x.wrapping_neg() } else { x }) as _ }\n w_abs(self).gcd(w_abs(b)) as _\n }\n #[inline] fn highest_one(self) -> Self { (self as $ux).highest_one() as _ }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ix>() as u32 * 8 - self.leading_zeros() }\n }\n )*\n }\n}\nimpl_common_num_ext!(i8 = u8, i16 = u16, i32 = u32, i64 = u64, i128 = u128, isize = usize);\n\ntrait ChMaxMin {\n fn chmax(&mut self, v: T) -> bool;\n fn chmin(&mut self, v: T) -> bool;\n}\nimpl ChMaxMin for Option {\n fn chmax(&mut self, v: T) -> bool { if self.is_none() || v > *self.as_ref().unwrap() { *self = Some(v); true } else { false } }\n fn chmin(&mut self, v: T) -> bool { if self.is_none() || v < *self.as_ref().unwrap() { *self = Some(v); true } else { false } }\n}\nimpl ChMaxMin for T {\n fn chmax(&mut self, v: T) -> bool { if v > *self { *self = v; true } else { false } }\n fn chmin(&mut self, v: T) -> bool { if v < *self { *self = v; true } else { false } }\n}\n\n// * end commons * //\n\npub trait BinarySearchExt {\n fn binary_search_by Ordering>(&self, f: F) -> Result;\n\n fn partition_point bool>(&self, mut f: F) -> T {\n self.binary_search_by(|x| if f(x) { Ordering::Less } else { Ordering::Greater }).err().unwrap()\n }\n}\nmacro_rules! impl_binary_search_ext_integer {\n ($($ty:tt),*) => {\n $(\n impl BinarySearchExt<$ty> for std::ops::Range<$ty> {\n fn binary_search_by Ordering>(&self, mut f: F) -> Result<$ty, $ty> {\n let mut low = self.start;\n let mut high = self.end;\n \n while low < high {\n let mid = (low & high) + ((low ^ high) >> 1);\n let cmp = f(mid);\n if cmp == Ordering::Less {\n low = mid + 1;\n } else if cmp == Ordering::Greater {\n high = mid;\n } else {\n return Ok(mid);\n }\n }\n Err(low)\n }\n }\n )*\n }\n}\nimpl_binary_search_ext_integer!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);\n\n#[allow(non_snake_case, non_upper_case_globals)]\nfn main() {\n let num_cases: usize = 1;//read();\n\t\n for _case_num in 1..=num_cases {\n\t\tlet n = read!(u32);\n\t\t\n\t\tlet ans = (3..2*n+2).partition_point(|x| x.saturating_sub(1) / 2 + x.saturating_sub(4) / 4 < n);\n\t\tprintln!(ans);\n }\n \n out_flush();\n}", "src_uid": "d0a8604b78ba19ab769fd1ec90a72e4e"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nfn run() {\n input! {\n n: usize,\n a: [usize; n],\n }\n let m = 5000;\n let mut weight = vec![0; m + 1];\n for a in a {\n if a == 0 {\n weight[1] += 1;\n } else {\n weight[a] += 1;\n }\n }\n let mut factor: Vec = vec![m; m + 1];\n let mut prime = vec![];\n for i in 2..=m {\n if factor[i] == m {\n for j in 1..=(m / i) {\n factor[j * i] = prime.len();\n }\n prime.push(i);\n }\n }\n let mut cnt = vec![vec![0; prime.len()]; m + 1];\n for i in 2..=m {\n let mut c = cnt[i - 1].clone();\n let mut t = i;\n while t > 1 {\n let k = factor[t];\n let p = prime[k];\n while t % p == 0 {\n c[k] += 1;\n t /= p;\n }\n }\n cnt[i] = c;\n }\n let cnt = cnt;\n let mut root_sum = 0u64;\n for i in 1..=m {\n root_sum += cnt[i].iter().fold(0, |s, a| s + *a) * weight[i];\n }\n let all = n as u64;\n let root_sum = root_sum;\n let mut dfs = vec![(2, m + 1, prime.len() - 1, 0, all - weight[1], root_sum)];\n let mut ans = root_sum;\n while let Some((l, r, index, num, sum, w)) = dfs.pop() {\n ans = std::cmp::min(ans, w);\n if 2 * sum <= all || l >= r || index >= prime.len() {\n continue;\n }\n assert!(num <= cnt[l][index]);\n if cnt[l][index] > num {\n dfs.push((l, r, index, num + 1, sum, w + all - 2 * sum));\n } else if cnt[l][index] == cnt[r - 1][index] {\n dfs.push((l, r, index - 1, 0, sum, w));\n } else {\n let mut zero = 0;\n let mut k = l;\n while k < r && cnt[k][index] == cnt[l][index] {\n zero += weight[k];\n k += 1;\n }\n dfs.push((l, k, index - 1, 0, zero, w));\n dfs.push((k, r, index, num, sum - zero, w));\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "40002052843ca0357dbd3158b16d59f4"} {"source_code": "use std::io;\n\nfn main() {\n let mut nk = String::new();\n io::stdin().read_line(&mut nk).expect(\"\");\n let nk: Vec<&str> = nk.trim().split(\" \").collect();\n let n: u64 = nk[0].parse().expect(\"\");\n let k: u64 = nk[1].parse().expect(\"\");\n if (n / k) & 1 == 1 {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "05fd61dd0b1f50f154eec85d8cfaad50"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n// use proconio::input;\nuse std::cmp::Ordering::*;\nuse std::collections::{BTreeMap, BTreeSet};\nuse std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\n\n// I have no idea what I'm doing\n\nmacro_rules! answer {\n ($out:ident, $ans:expr) => {\n writeln!($out, \"{}\", $ans)\n };\n}\n\nfn solve(mut a: Vec, i: usize) -> i32 {\n a.remove(i);\n a.windows(2).map(|v| v[1] - v[0]).max().unwrap()\n}\n\nfn main() -> Result<(), io::Error> {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = UnsafeScanner::new(stdin.lock());\n let mut out = BufWriter::new(stdout.lock());\n\n let n: usize = scan.token();\n let a: Vec = (0..n).map(|_| scan.token()).collect();\n\n let ans = (1..n-1).map(|i| solve(a.clone(), i)).min().unwrap();\n\n answer!(out, ans)\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n\n pub fn pair(&mut self) -> (T, T) {\n (self.token(), self.token())\n }\n}\n", "src_uid": "8a8013f960814040ac4bf229a0bd5437"} {"source_code": "// ---------- begin Matrix ----------\nmod matrix {\n use std::ops::*;\n pub trait SemiRing: Add + Mul + Copy {\n fn zero() -> Self;\n fn one() -> Self;\n }\n #[derive(Clone)]\n pub struct SquareMatrix {\n size: usize,\n buf: Box<[R]>,\n }\n #[allow(dead_code)]\n impl SquareMatrix {\n pub fn zero(size: usize) -> Self {\n SquareMatrix {\n size: size,\n buf: vec![R::zero(); size * size].into_boxed_slice(),\n }\n }\n pub fn identity(size: usize) -> Self {\n let mut e = Self::zero(size);\n for i in 0..size {\n e.buf[i * size + i] = R::one();\n }\n e\n }\n pub fn get(&self, x: usize, y: usize) -> &R {\n assert!(x < self.size && y < self.size);\n &self.buf[x * self.size + y]\n }\n pub fn get_mut(&mut self, x: usize, y: usize) -> &mut R {\n assert!(x < self.size && y < self.size);\n &mut self.buf[x * self.size + y]\n }\n pub fn matadd(&self, rhs: &Self) -> Self {\n assert!(self.size == rhs.size);\n let buf: Vec = self\n .buf\n .iter()\n .zip(rhs.buf.iter())\n .map(|p| *p.0 + *p.1)\n .collect();\n SquareMatrix {\n size: self.size,\n buf: buf.into_boxed_slice(),\n }\n }\n pub fn matmul(&self, rhs: &Self) -> Self {\n let size = self.size;\n assert!(size == rhs.size);\n let mut res = Self::zero(size);\n for (x, a) in res.buf.chunks_mut(size).zip(self.buf.chunks(size)) {\n for (a, b) in a.iter().zip(rhs.buf.chunks(size)) {\n for (x, b) in x.iter_mut().zip(b.iter()) {\n *x = *x + *a * *b;\n }\n }\n }\n res\n }\n pub fn mat_pow(&self, mut n: usize) -> Self {\n let size = self.size;\n let mut t = Self::identity(size);\n let mut s = self.clone();\n while n > 0 {\n if n & 1 == 1 {\n t = t.matmul(&s);\n }\n s = s.matmul(&s);\n n >>= 1;\n }\n t\n }\n }\n #[allow(dead_code)]\n impl> SquareMatrix {\n pub fn matsub(&self, rhs: &Self) -> Self {\n assert!(self.size == rhs.size);\n let buf: Vec = self\n .buf\n .iter()\n .zip(rhs.buf.iter())\n .map(|p| *p.0 - *p.1)\n .collect();\n SquareMatrix {\n size: self.size,\n buf: buf.into_boxed_slice(),\n }\n }\n }\n}\n// ---------- end Matrix ----------\n// ---------- begin ModInt ----------\nmod modint {\n\n #[allow(dead_code)]\n pub struct Mod;\n impl ConstantModulo for Mod {\n const MOD: u32 = 1_000_000_007;\n }\n\n #[allow(dead_code)]\n pub struct StaticMod;\n static mut STATIC_MOD: u32 = 0;\n impl Modulo for StaticMod {\n fn modulo() -> u32 {\n unsafe { STATIC_MOD }\n }\n }\n\n #[allow(dead_code)]\n impl StaticMod {\n pub fn set_modulo(p: u32) {\n unsafe {\n STATIC_MOD = p;\n }\n }\n }\n\n use std::marker::*;\n use std::ops::*;\n\n pub trait Modulo {\n fn modulo() -> u32;\n }\n\n pub trait ConstantModulo {\n const MOD: u32;\n }\n\n impl Modulo for T\n where\n T: ConstantModulo,\n {\n fn modulo() -> u32 {\n T::MOD\n }\n }\n\n pub struct ModInt(pub u32, PhantomData);\n\n impl Clone for ModInt {\n fn clone(&self) -> Self {\n ModInt::new_unchecked(self.0)\n }\n }\n\n impl Copy for ModInt {}\n\n impl Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: Self) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= T::modulo() {\n d -= T::modulo();\n }\n ModInt::new_unchecked(d)\n }\n }\n\n impl AddAssign for ModInt {\n fn add_assign(&mut self, rhs: Self) {\n *self = *self + rhs;\n }\n }\n\n impl Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: Self) -> Self::Output {\n let mut d = T::modulo() + self.0 - rhs.0;\n if d >= T::modulo() {\n d -= T::modulo();\n }\n ModInt::new_unchecked(d)\n }\n }\n\n impl SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: Self) {\n *self = *self - rhs;\n }\n }\n\n impl Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: Self) -> Self::Output {\n let v = self.0 as u64 * rhs.0 as u64 % T::modulo() as u64;\n ModInt::new_unchecked(v as u32)\n }\n }\n\n impl MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: Self) {\n *self = *self * rhs;\n }\n }\n\n impl Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n if self.0 == 0 {\n Self::zero()\n } else {\n Self::new_unchecked(T::modulo() - self.0)\n }\n }\n }\n\n impl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n }\n\n impl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n }\n\n impl From for ModInt {\n fn from(val: usize) -> ModInt {\n ModInt::new_unchecked((val % T::modulo() as usize) as u32)\n }\n }\n\n impl From for ModInt {\n fn from(val: u64) -> ModInt {\n ModInt::new_unchecked((val % T::modulo() as u64) as u32)\n }\n }\n\n impl From for ModInt {\n fn from(val: i64) -> ModInt {\n let m = T::modulo() as i64;\n ModInt::new((val % m + m) as u32)\n }\n }\n\n #[allow(dead_code)]\n impl ModInt {\n pub fn new_unchecked(d: u32) -> Self {\n ModInt(d, PhantomData)\n }\n pub fn zero() -> Self {\n ModInt::new_unchecked(0)\n }\n pub fn one() -> Self {\n ModInt::new_unchecked(1)\n }\n pub fn is_zero(&self) -> bool {\n self.0 == 0\n }\n }\n\n #[allow(dead_code)]\n impl ModInt {\n pub fn new(d: u32) -> Self {\n ModInt::new_unchecked(d % T::modulo())\n }\n pub fn pow(&self, mut n: u64) -> Self {\n let mut t = Self::one();\n let mut s = *self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(&self) -> Self {\n assert!(self.0 != 0);\n self.pow(T::modulo() as u64 - 2)\n }\n }\n\n #[allow(dead_code)]\n pub fn mod_pow(r: u64, mut n: u64, m: u64) -> u64 {\n let mut t = 1 % m;\n let mut s = r % m;\n while n > 0 {\n if n & 1 == 1 {\n t = t * s % m;\n }\n s = s * s % m;\n n >>= 1;\n }\n t\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\nmod precalc {\n use super::modint::*;\n #[allow(dead_code)]\n pub struct Precalc {\n inv: Vec>,\n fact: Vec>,\n ifact: Vec>,\n }\n #[allow(dead_code)]\n impl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n fact[i] = fact[i - 1] * ModInt::new_unchecked(i as u32);\n }\n ifact[n] = fact[n].inv();\n if n > 0 {\n inv[n] = ifact[n] * fact[n - 1];\n }\n for i in (1..n).rev() {\n ifact[i] = ifact[i + 1] * ModInt::new_unchecked((i + 1) as u32);\n inv[i] = ifact[i] * fact[i - 1];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n assert!(n > 0);\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn perm(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[n - k]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n }\n}\n// ---------- end Precalc ----------\n// ---------- begin input macro ----------\n// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, bytes) => {\n read_value!($iter, String).bytes().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n// ---------- end input macro ----------\n\nuse modint::*;\ntype M = ModInt;\n\nuse matrix::*;\ntype Mat = SquareMatrix;\n\nimpl SemiRing for M {\n fn zero() -> Self {\n M::zero()\n }\n fn one() -> Self {\n M::one()\n }\n}\n\nfn run() {\n input! {\n w: [usize; 7],\n }\n // 0: \u7f6e\u3044\u3066ok\n // 1: \u304a\u3044\u305f\u3089\u30c0\u30e1\n let mut mat = vec![];\n for i in 1..=7 {\n let mut m = Mat::zero(1 << i);\n for j in 0..(1 << i) {\n for k in 0..(1 << (2 * i - 1)) {\n if j & k > 0 {\n continue;\n }\n let mut next = 0;\n for x in 0..i {\n let left = x == 0 || (k >> (i + x - 1)) & 1 == 1;\n let down = k >> x & 1 == 1;\n let right = x == i - 1 || (k >> (i + x)) & 1 == 1;\n if left && down && right {\n next |= 1 << x;\n }\n }\n *m.get_mut(next, j) += M::one();\n }\n }\n mat.push(m);\n let mut m = Mat::zero(1 << i);\n for j in 0..(1 << i) {\n *m.get_mut(j, j) = M::one();\n }\n mat.push(m);\n }\n let mul = |m: &Mat, b: &[M]| -> Vec {\n let mut res = vec![M::zero(); b.len()];\n for i in 0..b.len() {\n for j in 0..b.len() {\n res[i] += *m.get(i, j) * b[j];\n }\n }\n res\n };\n let mut b = vec![M::zero(); 1 << 7];\n let mut ini = false;\n let mut w = w;\n for (i, (w, mat)) in w.iter_mut().zip(mat.chunks(2)).enumerate().rev() {\n if !ini && *w > 0 {\n *w -= 1;\n ini = true;\n let i = i + 1;\n for k in 0..(1 << (i - 1)) {\n let mut bit = 0;\n for x in 0..i {\n let left = x == 0 || k >> (x - 1) & 1 == 1;\n let down = true;\n let right = x == i - 1 || k >> x & 1 == 1;\n if left && right && down {\n bit |= 1 << x;\n }\n }\n b[bit] += M::one();\n }\n }\n b = mul(&mat[1], &b);\n b = mul(&mat[0].mat_pow(*w), &b);\n b.truncate(1 << i);\n }\n let ans = b[0];\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "a4bda63b95dc14185c47a08652fe41bd"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if b == 0 {\n return (a, 1, 0);\n }\n let (g, x1, y1) = egcd(b, a % b);\n (g, y1, x1 - (a / b) * y1)\n}\n\nfn ceil_div(num: i64, denom: i64) -> i64 {\n (num + denom - 1).div_euclid(denom)\n}\n\n// Check if the diophantine equation a * x + b * y = c has non-negative solutions.\nfn solve(scan: &mut Scanner, out: &mut W) {\n let a: i64 = scan.token();\n let b: i64 = scan.token();\n let c: i64 = scan.token();\n let (g, xg, yg) = egcd(a, b);\n if c % g == 0 {\n let x0 = xg * c / g;\n let y0 = yg * c / g;\n // xk = x0 + k * b / g\n // yk = y0 - k * a / g\n // xk >= 0 and yk >= 0\n // After solving for k:\n let ans = (y0 * g).div_euclid(a) - ceil_div(-x0 * g, b) + 1;\n if ans > 0 {\n writeln!(out, \"Yes\").ok();\n } else {\n writeln!(out, \"No\").ok();\n }\n } else {\n writeln!(out, \"No\").ok();\n }\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "e66ecb0021a34042885442b336f3d911"} {"source_code": "use std::io;\nuse std::io::prelude::*;\n\nfn main() {\n let stdin = io::stdin();\n let mut stdin = stdin.lock().lines();\n\n let n: usize = stdin.next().unwrap().unwrap().parse().unwrap();\n let s: Vec = stdin.next().unwrap().unwrap()\n .chars().map(|x| x == '1').collect();\n\n let diff = s.iter().fold(0, |acc, &x| if x { acc + 1 } else { acc - 1 });\n\n if diff == 0 {\n println!(\"2\");\n println!(\"{} {}\",\n &s[..s.len()-1].iter()\n .map(|&x| if x { \"1\" } else { \"0\" })\n .map(String::from)\n .collect::>().join(\"\"),\n &s[s.len()-1..].iter()\n .map(|&x| if x { \"1\" } else { \"0\" })\n .map(String::from)\n .collect::>().join(\"\"))\n } else {\n println!(\"1\");\n println!(\"{}\", s.iter().map(|&x| if x { \"1\" } else { \"0\" })\n .map(String::from)\n .collect::>().join(\"\"));\n }\n}\n", "src_uid": "4ebed264d40a449602a26ceef2e849d1"} {"source_code": "\n#![allow(unused_imports)]\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::str::FromStr;\nuse std::collections::{VecDeque, HashMap};\n\nfn main() {\n let stdin = io::stdin();\n let mut input = stdin.lock();\n let mut line = String::new();\n input.read_line(&mut line).unwrap();\n let nums = get_numbers::(&line);\n let n = nums[0];\n let k = nums[1] - 1; // k is numbered from 1\n\n let length = u64::pow(2, n as u32) - 1;\n\n let mut val = n;\n let mut ind = length / 2;\n let mut lower = 0;\n let mut upper = length;\n\n while ind != k {\n val = val - 1;\n if ind > k {\n upper = ind;\n ind = (lower + upper) / 2;\n } else {\n lower = ind;\n ind = (lower + upper) / 2;\n }\n }\n\n println!(\"{}\", val);\n}\n\n/*\n * Utility Functions\n */\n\n// get numbers from line seperated by spaces\nfn get_numbers(line: &str) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n line.split_whitespace()\n .map(|chunk| chunk.parse::().expect(\"failed to parse\"))\n .collect()\n}\n\n", "src_uid": "0af400ea8e25b1a36adec4cc08912b71"} {"source_code": "use std::io;\n\n\nfn read_line() -> String{\n let mut line = String::new();\n\n io::stdin().read_line(&mut line)\n .expect(\"Failed to read line\");\n\n line.trim().to_string()\n}\n\nfn gcd(a: i32, b: i32) -> i32{\n if b > a {return gcd(b, a)}\n if b == 0 {return a}\n gcd(b, (a % b))\n}\n\n\nfn main() {\n let vals = read_line()\n .split_whitespace()\n .map(|x| x.parse().expect(\"parse int error\"))\n .collect::>();\n let n = vals.get(0).unwrap();\n let m = vals.get(1).unwrap();\n let z = vals.get(2).unwrap();\n let lcm = n / gcd(*n, *m) * m;\n let res = z / lcm;\n\n println!(\"{}\", res);\n}", "src_uid": "e7ad55ce26fc8610639323af1de36c2d"} {"source_code": "fn input_split() -> Vec {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect()\n}\n\nfn main() {\n let (y_chr, b_chr) = {\n let temp = input_split();\n (temp[0], temp[1])\n };\n let (y, g, b) = {\n let temp = input_split();\n (temp[0], temp[1], temp[2])\n };\n\n let mut req_chr = 0u64;\n req_chr += u64::from((2 * y + g).max(y_chr) - y_chr);\n req_chr += u64::from((3 * b + g).max(b_chr) - b_chr);\n println!(\"{}\", req_chr);\n}", "src_uid": "35202a4601a03d25e18dda1539c5beba"} {"source_code": "#[allow(unused_imports)]\nuse std::io::{BufWriter, stdin, stdout, Write};\n\n#[derive(Default)]\nstruct Scanner {\n buffer: Vec\n}\nimpl Scanner {\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn main() {\n let mut scan = Scanner::default();\n let n: (i32,i32) = (scan.next::(),scan.next::());\n let mut result = 0i32;\n\n result = (n.0 * n.1) - (n.0 * n.1)%2;\n result /=2;\n\n println!(\"{}\", result);\n}\n", "src_uid": "e840e7bfe83764bee6186fcf92a1b5cd"} {"source_code": "use std::io;\n\n\n// type Matrix = Vec>;\n\nfn read_line() -> String {\n let mut input_line = String::new();\n io::stdin().read_line(&mut input_line).unwrap();\n return String::from(input_line.trim());\n}\n\nfn read_line_vec() -> Vec {\n return read_line().split(' ')\n .map(|s| s.parse().unwrap())\n .collect();\n}\n\nfn read_line_pair() -> (i64, i64) {\n let vec = read_line_vec();\n return (vec[0], vec[1]);\n}\n\n\nfn main() {\n \n let (mut n, mut m) = read_line_pair();\n \n let mut count = 0;\n \n while n > 0 && m > 0 {\n if n > m {\n n -= 2;\n m -= 1;\n } else {\n n -= 1;\n m -= 2;\n }\n if n >= 0 && m >= 0 {\n count += 1; \n }\n \n }\n \n println!(\"{}\", count);\n\n // println!(\"{:?} {:?}\", l, r);\n \n}\n", "src_uid": "0718c6afe52cd232a5e942052527f31b"} {"source_code": "#![allow(unused_imports)]\n#![allow(non_snake_case)]\n\nuse std::cell::RefCell;\nuse std::cmp::{max, min, Ordering};\nuse std::collections::*;\nuse std::fmt::{Debug, Formatter, Write as FmtWrite};\nuse std::io::*;\nuse std::mem::{replace, swap};\nuse std::ops::*;\nuse std::rc::Rc;\n\n// -----------------------------------------------\n\n#[allow(unused_macros)]\nmacro_rules! read {\n ([$t:ty] ; $n:expr) =>\n ((0..$n).map(|_| read!([$t])).collect::>());\n ($($t:ty),+ ; $n:expr) =>\n ((0..$n).map(|_| read!($($t),+)).collect::>());\n ([$t:ty]) =>\n (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::>());\n ($t:ty) =>\n (rl().parse::<$t>().unwrap());\n ($($t:ty),*) => {{\n let buf = rl();\n let mut w = buf.split_whitespace();\n ($(w.next().unwrap().parse::<$t>().unwrap()),*)\n }};\n}\n\n#[allow(dead_code)]\nfn reads(i: &mut StdinLock) -> Vec {\n let mut s = String::new();\n i.by_ref().read_line(&mut s).ok();\n s.trim()\n .split_whitespace()\n .map(|e| e.parse().ok().unwrap())\n .collect()\n}\n\n#[allow(dead_code)]\nfn rl() -> String {\n let mut buf = String::new();\n stdin().read_line(&mut buf).unwrap();\n buf.trim_right().to_owned()\n}\n\ntrait IteratorExt: Iterator + Sized {\n fn vec(self) -> Vec {\n self.collect()\n }\n}\n\nimpl IteratorExt for T {}\n\n// -----------------------------------------------\n// Solution\n// -----------------------------------------------\n\nfn main() {\n // let sin = std::io::stdin();\n // let mut sin = sin.lock();\n // let sin = &mut sin;\n\n // #################################\n\n let _n: u32 = read!(u32);\n let input: String = rl();\n\n let mut set = HashSet::new();\n\n for c in input.to_lowercase().as_str().chars() {\n set.insert(c);\n }\n\n let ans = if set.len() == 26 { \"YES\" } else { \"NO\" };\n\n println!(\"{}\", ans);\n}\n", "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"source_code": "use std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\n\n// I have no idea what I'm doing\n\nfn main() -> Result<(), io::Error> {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = UnsafeScanner::new(stdin.lock());\n let mut out = BufWriter::new(stdout.lock());\n\n let n: usize = scan.token();\n let (l, r) = scan.pair::();\n\n const M: i64 = 1_000_000_007;\n\n let m0 = r/3 - (l-1)/3;\n let m1 = m0\n - if r%3 == 0 { 1 } else { 0 }\n + if (l-1)%3 == 0 { 1 } else { 0 };\n let m2 = m0\n - if r%3 <= 1 { 1 } else { 0 }\n + if (l-1)%3 <= 1 { 1 } else { 0 };\n\n dbg!(m0);\n dbg!(m1);\n dbg!(m2);\n\n let mut ans = [1_i64, 0, 0];\n for _ in 0..n {\n let mut nxt = [0_i64; 3];\n nxt[0] = m0 * ans[0] % M + m1 * ans[2] % M + m2 * ans[1];\n nxt[1] = m0 * ans[1] % M + m1 * ans[0] % M + m2 * ans[2];\n nxt[2] = m0 * ans[2] % M + m1 * ans[1] % M + m2 * ans[0];\n\n for i in 0..3 {\n ans[i] = nxt[i] % M;\n }\n }\n\n writeln!(out, \"{}\", ans[0])?;\n\n Ok(())\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n\n pub fn pair(&mut self) -> (T, T) {\n (self.token(), self.token())\n }\n}\n", "src_uid": "4c4852df62fccb0a19ad8bc41145de61"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n\n fn next_n(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next::()).collect()\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let mut nums: Vec = scan.next_n(3);\n nums[0] = nums[0].min(nums[1] - 1);\n nums[1] = nums[1].min(nums[2] - 1).min(nums[0] + 1);\n nums[2] = nums[2].min(nums[1] + 1);\n nums[0] = nums[0].min(nums[1] - 1);\n println!(\"{}\", nums[0] + nums[1] + nums[2]);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "03ac8efe10de17590e1ae151a7bae1a5"} {"source_code": "use std::io;\nuse std::io::{Write};\nuse std::str;\nuse std::collections::HashSet;\n\n/// Reads white-space separated tokens one at a time.\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n /// Use \"turbofish\" syntax token::() to select data type of next token.\n ///\n /// # Panics\n ///\n /// Panics if there's an I/O error or if the token cannot be parsed as T.\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: str::SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n}\n\npub fn scanner_from_file(filename: &str) -> Scanner> {\n let file = std::fs::File::open(filename).expect(\"Input file not found\");\n Scanner::new(io::BufReader::new(file))\n}\n\npub fn writer_to_file(filename: &str) -> io::BufWriter {\n let file = std::fs::File::create(filename).expect(\"Output file not found\");\n io::BufWriter::new(file)\n}\n\nfn uniq(n: usize) -> bool {\n let mut p = n;\n let mut digits = HashSet::new();\n while p > 0 {\n digits.insert(p%10);\n p /= 10;\n }\n\n digits.len() == 4\n}\n\nfn solve() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n let mut n = scan.token::();\n n += 1;\n while !uniq(n) {\n n += 1;\n }\n out.write(format!(\"{}\", n).as_bytes()).unwrap();\n // let k = scan.token::();\n // let mut arr = scan.token::().chars().collect::>();\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(64 * 1024 * 1024)\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "d62dabfbec52675b7ed7b582ad133acd"} {"source_code": "// ---------- begin ModInt ----------\nconst MOD: u32 = 998_244_353;\n\n#[derive(Clone, Copy)]\nstruct ModInt(u32);\n\nimpl std::ops::Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::AddAssign for ModInt {\n fn add_assign(&mut self, rhs: ModInt) {\n *self = *self + rhs;\n }\n}\n\nimpl std::ops::Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + MOD - rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: ModInt) {\n *self = *self - rhs;\n }\n}\n\nimpl std::ops::Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: ModInt) -> Self::Output {\n ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)\n }\n}\n\nimpl std::ops::MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: ModInt) {\n *self = *self * rhs;\n }\n}\n\nimpl std::ops::Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n ModInt(if self.0 == 0 {0} else {MOD - self.0})\n }\n}\n\nimpl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n\nimpl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n}\n\nimpl From for ModInt {\n fn from(val: usize) -> ModInt {\n ModInt((val % MOD as usize) as u32)\n }\n}\n\n#[allow(dead_code)]\nimpl ModInt {\n pub fn new(n: u32) -> ModInt {\n ModInt(n % MOD)\n }\n pub fn zero() -> ModInt {\n ModInt(0)\n }\n pub fn one() -> ModInt {\n ModInt(1)\n }\n pub fn pow(self, mut n: u32) -> ModInt {\n let mut t = ModInt::one();\n let mut s = self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(self) -> ModInt {\n assert!(self.0 > 0);\n self.pow(MOD - 2)\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\n#[allow(dead_code)]\nstruct Precalc {\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n}\n\n#[allow(dead_code)]\nimpl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);\n fact[i] = fact[i - 1] * ModInt(i as u32);\n ifact[i] = ifact[i - 1] * inv[i];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n}\n// ---------- end Precalc ----------\n//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nfn run() {\n input! {\n n: usize,\n k: usize,\n }\n let mut ans = ModInt::zero();\n let pc = Precalc::new(n + k);\n for i in 1..=n {\n let x = n / i - 1;\n let y = k - 1;\n if x >= y {\n ans += pc.comb(x, y);\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "8e8eb64a047cb970a549ee870c3d280d"} {"source_code": "use std::io;\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input).expect(\"failed to read input\");\n let mut input_iter = input.split_whitespace();\n let a = input_iter.next().unwrap();\n let b = input_iter.next().unwrap();\n if a == b {\n println!(\"{}\", a);\n } else {\n println!(\"1\");\n }\n}", "src_uid": "9c5b6d8a20414d160069010b2965b896"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let (n,d) = (input.i(), input.i());\n let sum = d - input.vp::(n as usize)\n .into_iter().sum::();\n println!(\"{}\", if sum >= 10 * (n - 1) {\n sum / 5\n } else {\n -1\n });\n}\n\n", "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"source_code": "use std::io::stdin;\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[derive(Default)]\nstruct Scanner {\n buffer: Vec,\n}\n\nimpl Scanner {\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn can_remove(index: usize, phrase: &mut Vec) -> bool {\n let phrase_length = phrase.len();\n let (current, previous, next) = (\n phrase[index] as i32,\n if index == 0 {\n phrase[index] as i32\n } else {\n phrase[index - 1] as i32\n },\n if index == (phrase_length - 1) {\n phrase[index] as i32\n } else {\n phrase[index + 1] as i32\n },\n );\n (current as i32 - next as i32) == 1 || (current as i32 - previous as i32) == 1\n}\n\nfn try_remove_next<'a>(phrase: &mut Vec) -> bool {\n let mut bigger = 'a' as i32 - 1;\n let mut candidate: usize = 101;\n for (i, charac) in phrase.clone().iter().enumerate() {\n if *charac as i32 > bigger && can_remove(i, phrase) {\n candidate = i;\n bigger = *charac as i32;\n }\n }\n if candidate == 101 {\n false\n } else {\n phrase.remove(candidate);\n true\n }\n}\nfn main() {\n let mut scan = Scanner::default();\n let _ = scan.next::();\n let mut stra: Vec = scan.next::().chars().collect();\n let chars: &mut Vec = &mut stra.as_mut();\n let mut totals = 0;\n loop {\n let removed = try_remove_next(chars);\n if removed {\n totals += 1;\n } else {\n break;\n }\n }\n println!(\"{}\", totals)\n}\n", "src_uid": "9ce37bc2d361f5bb8a0568fb479b8a38"} {"source_code": "#[allow(unused_imports)]\nuse std::io::{stdin, Read, StdinLock};\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::str::FromStr;\n#[allow(unused_imports)]\nuse std::collections::{HashSet, HashMap, BinaryHeap};\n#[allow(unused_imports)]\nuse std::vec::Vec;\n\n#[allow(dead_code)]\nconst INF: i32 = 1000_000_000;\n#[allow(dead_code)]\nconst INFLL: i64 = 1000_000_000_000_000_000;\n#[allow(dead_code)]\nconst EPS: f64 = 1.0e-10;\n#[allow(dead_code)]\nconst MOD: i32 = 1000_000_007;\n\nstruct Scanner<'a> {\n cin: StdinLock<'a>,\n}\n\nimpl<'a> Scanner<'a> {\n #[allow(dead_code)]\n fn new(cin: StdinLock<'a>) -> Scanner<'a> {\n Scanner {cin: cin}\n }\n\n #[allow(dead_code)]\n fn read1(&mut self) -> Option {\n let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect::();\n token.parse::().ok()\n }\n\n #[allow(dead_code)]\n fn read(&mut self) -> T {\n self.read1().unwrap()\n }\n}\n\n\nfn main() {\n let cin = stdin();\n let cin = cin.lock();\n let mut sc = Scanner::new(cin);\n\n let r1: i32 = sc.read();\n let r2: i32 = sc.read();\n let c1: i32 = sc.read();\n let c2: i32 = sc.read();\n let d1: i32 = sc.read();\n let d2: i32 = sc.read();\n let mut ans: Vec> = vec![vec![-1; 4]; 4];\n for a in 1..10 {\n for b in 1..10 {\n for c in 1..10 {\n for d in 1..10 {\n let mut s: Vec = vec![a, b, c, d];\n s.sort(); s.dedup();\n if s.len() != 4 {\n continue;\n }\n if a + b == r1 && c + d == r2 && a + c == c1 && b + d == c2 && a + d == d1 && b + c == d2 {\n ans[0][0] = a;\n ans[0][1] = b;\n ans[1][0] = c;\n ans[1][1] = d;\n }\n }\n }\n }\n }\n if ans[0][0] != -1 {\n for i in 0..2 {\n println!(\"{} {}\", ans[i][0], ans[i][1]);\n }\n } else {\n println!(\"-1\");\n }\n}", "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan { buffer: std::collections::VecDeque::new() }\n }\n\n fn next(&mut self)-> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let mut _n: u64 = scan.next();\n println!(\"25\");\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "src_uid": "dcaff75492eafaf61d598779d6202c9d"} {"source_code": "macro_rules! parse_line {\n ($t: ty) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let a_str = a_str.trim();\n a_str.parse::<$t>().expect(\"parse error\")\n });\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().expect(\"parse error\"),\n )+\n )\n })\n}\n\n#[allow(unused_macros)]\nmacro_rules! parse_line_to_vec {\n ($t: ty) => {{\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n (a_str\n .split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect::>())\n }};\n}\n\nuse std::io::Write;\n\nfn solve(writer: &mut std::io::BufWriter) {\n let n = parse_line!(usize);\n let mut v = std::collections::HashSet::::new();\n v.insert(0);\n for _ in 0..n {\n let a = parse_line!(i32);\n let mut new = std::collections::HashSet::::new();\n for x in v {\n new.insert((x + a) % 360);\n new.insert((x - a) % 360);\n }\n v = new;\n }\n writeln!(writer, \"{}\", if v.contains(&0) {\"YES\"} else {\"NO\"}).unwrap();\n}\n\nfn main() {\n let mut writer = std::io::BufWriter::new(std::io::stdout());\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve(&mut writer);\n }\n}\n", "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: usize = scan.next();\n let k: usize = scan.next();\n let d: usize = scan.next();\n let mut dp = [[0usize; 2]; 128];\n dp[0][0] = 1;\n for i in 1..=n {\n for j in 1..=k {\n if i < j {\n continue;\n }\n if j < d {\n dp[i][0] = (dp[i][0] + dp[i - j][0]) % 1000000007;\n dp[i][1] = (dp[i][1] + dp[i - j][1]) % 1000000007;\n } else {\n dp[i][1] = (dp[i][1] + dp[i - j][0]) % 1000000007;\n dp[i][1] = (dp[i][1] + dp[i - j][1]) % 1000000007;\n }\n }\n }\n println!(\"{}\", dp[n][1]);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "894a58c9bba5eba11b843c5c5ca0025d"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let mut a = input.i();\n let mut b = input.i();\n let mut sol = 0;\n while a > 0 && b > 0 && a + b > 2 {\n if a < b {\n a += 1;\n b -= 2;\n } else {\n a -= 2;\n b += 1;\n }\n sol += 1;\n }\n println!(\"{}\", sol);\n}\n\n", "src_uid": "ba0f9f5f0ad4786b9274c829be587961"} {"source_code": "#![allow(unused_variables)]\n#![allow(unused_must_use)]\n#![allow(unused_imports)]\n#![allow(non_snake_case)]\n#![allow(dead_code)]\n\nuse std::u64;\nuse std::io;\nuse std::cmp;\nuse std::io::prelude::*;\nuse std::fs::File;\nuse std::collections::HashSet;\n\nuse std::str::FromStr;\n\nfn solve(sum: i64, max: i64, n: i64) -> i64 {\n let mut ans = 2 * sum / n;\n while 2 * sum >= ans * n {\n ans += 1;\n }\n\n cmp::max(max, ans)\n}\n\nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n let stderr = io::stderr();\n\n //let r = &mut io::BufReader::new(File::open(\"input.txt\").unwrap()).lines();\n let r = &mut io::BufReader::new(stdin.lock()).lines();\n let w = &mut io::BufWriter::new(stdout.lock());\n let e = &mut io::BufWriter::new(stderr.lock());\n\n let n: usize = read_var(r);\n let a: Vec = read_vec(r); \n let mut sum: i64 = 0;\n let mut max: i64 = 0;\n for ai in a.into_iter() {\n sum += ai;\n max = cmp::max(max, ai);\n }\n\n // writeln!(e, \"sum: {}, max: {}\", sum, max);\n writeln!(w, \"{}\", solve(sum, max, n as i64));\n}\n\nfn to_vec(res: io::Result) -> Vec {\n res.unwrap().split(' ').map(|x| x.trim().parse().ok().unwrap()).collect()\n}\n\nfn read_vec(r: &mut io::Lines) -> Vec {\n to_vec(r.next().unwrap())\n}\n\nfn read_var(r: &mut io::Lines) -> T {\n r.next().unwrap().unwrap().trim().parse().ok().unwrap()\n}\n", "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\n#![allow(unused_labels)]\n\nuse std::char::*;\nuse std::cmp::*;\nuse std::collections::*;\nuse std::io::*;\nuse std::str::FromStr;\n\nmacro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);}}\nmacro_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 ) * } } ; }\nmacro_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 ) * } } ; }\nmacro_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\" ) } ; }\n\n\nfn read() -> T {\n let stdin = stdin();\n let stdin = stdin.lock();\n let token: String = stdin\n .bytes()\n .map(|c| c.expect(\"failed to read char\") as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect();\n token.parse().ok().expect(\"failed to parse token\")\n}\n\nuse std::f64;\n\nfn min(a:T, b:T) -> T {\n if a < b { a }\n else { b }\n}\n\nfn max(a:T, b:T) -> T {\n if a < b { b }\n else { a }\n}\n\nconst MAX:usize = 30;\nconst INF:i64 = std::i64::MAX;\nconst MOD:i64 = 1e9 as i64 + 7;\n\nstruct Graph {\n e: Vec>,\n v: Vec,\n u: Vec,\n f: Vec,\n c: i64,\n vc: Vec,\n}\n\nimpl Graph {\n fn new(n:usize) -> Self {\n Graph {\n e: vec![vec![];n],\n v: vec![],\n u: vec![n;n],\n f: vec![false;n],\n c: 0,\n vc: vec![0;n],\n }\n }\n\n fn dfs(&mut self, crt: usize) {\n if self.f[crt] { return; }\n self.c += 1;\n self.f[crt] = true;\n self.v.push(crt);\n self.vc[crt] = self.c;\n self.u[crt] = self.v.len()-1;\n for i in 0..self.e[crt].len() {\n self.dfs(self.e[crt][i]);\n }\n //debug!(crt, self.c, self.vc[crt]);\n self.vc[crt] = self.c - self.vc[crt];\n }\n}\n\nfn main() {\n //let t:usize = read();\n //'outer: for _ in 0..t {\n let a:i64 = read();\n let b:i64 = read();\n let mut x:i64 = read();\n\n let mut aa = b-1;\n let mut bb = a;\n let mut xx = x;\n\n let mut v = vec![1];\n let mut f = if xx==1 {true} else {xx-=1; false};\n loop {\n //debug!(aa,bb,xx,f);\n if xx == 0 {\n if f {\n if aa > 0 {\n v.push(1);\n aa -= 1;\n } else {\n break;\n }\n } else {\n if bb > 0 {\n v.push(0);\n bb -= 1;\n } else {\n break;\n }\n }\n }\n else if xx == 1 {\n if f {\n if aa > 0 {\n v.push(1);\n aa -= 1;\n } else if bb > 0 {\n v.push(0);\n bb -= 1;\n xx -= 1;\n f = false;\n } else {\n break;\n }\n } else {\n if bb > 0 {\n v.push(0);\n bb -= 1;\n } else if aa > 0 {\n v.push(1);\n aa -= 1;\n xx -= 1;\n f = true;\n } else {\n break;\n }\n }\n }\n else {\n if f {\n if aa > 0 {\n v.push(1);\n aa -= 1;\n f = false;\n xx -= 1;\n } else {\n break;\n }\n } else {\n if bb > 0 {\n v.push(0);\n bb -= 1;\n f = true;\n xx -= 1;\n } else {\n break;\n }\n }\n }\n }\n debug!(v);\n\n if xx == 0 && v.len() == (a+b) as usize {\n for e in v { print!(\"{}\", e); } println!();\n return;\n }\n\n let mut aa = b;\n let mut bb = a-1;\n\n let mut v = vec![0];\n let mut f = if x==1 {false} else {x-=1; true};\n loop {\n //debug!(aa,bb,x,f);\n if x == 0 {\n if f {\n if aa > 0 {\n v.push(1);\n aa -= 1;\n } else {\n break;\n }\n } else {\n if bb > 0 {\n v.push(0);\n bb -= 1;\n } else {\n break;\n }\n }\n }\n else if x == 1 {\n if f {\n if aa > 0 {\n v.push(1);\n aa -= 1;\n } else if bb > 0 {\n v.push(0);\n bb -= 1;\n x -= 1;\n f = false;\n } else {\n break;\n }\n } else {\n if bb > 0 {\n v.push(0);\n bb -= 1;\n } else if aa > 0 {\n v.push(1);\n aa -= 1;\n x -= 1;\n f = true;\n } else {\n break;\n }\n }\n }\n else {\n if f {\n if aa > 0 {\n v.push(1);\n aa -= 1;\n f = false;\n x -= 1;\n } else {\n break;\n }\n } else {\n if bb > 0 {\n v.push(0);\n bb -= 1;\n f = true;\n x -= 1;\n } else {\n break;\n }\n }\n }\n }\n debug!(v);\n\n if x == 0 && v.len() == (a+b) as usize {\n for e in v { print!(\"{}\", e); } println!();\n return;\n }\n\n\n //}\n}\n\n/*\n\n\n*/\n", "src_uid": "ef4123b8f3f3b511fde8b79ea9a6b20c"} {"source_code": "//! http://codeforces.com/contest/584/problem/A\n\n#[macro_export]\nmacro_rules! scanln {\n ($($var:ident : $ty:path),+) => {\n $(let $var: $ty;)+\n {\n use std::io;\n let mut __buf = String::new();\n io::stdin().read_line(&mut __buf).unwrap();\n let mut eles = __buf.split_whitespace();\n $($var = Scan::scan(&mut eles);)+\n }\n }\n}\n\npub trait Scan {\n fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator;\n}\n\nmacro_rules! impl_scan_single {\n ($ty:ty) => {\n impl Scan for $ty {\n fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator {\n let next = eles.next().unwrap();\n match next.parse() {\n Ok(res) => res,\n Err(_) => panic!()\n }\n }\n }\n }\n}\n\nimpl_scan_single!(u8);\nimpl_scan_single!(u16);\nimpl_scan_single!(u32);\nimpl_scan_single!(u64);\nimpl_scan_single!(usize);\nimpl_scan_single!(i8);\nimpl_scan_single!(i16);\nimpl_scan_single!(i32);\nimpl_scan_single!(i64);\nimpl_scan_single!(isize);\nimpl_scan_single!(String);\n\nconst __IMPL_SCAN_FOR_VEC: () = {\n use std::str::FromStr;\n impl Scan for Vec where T: FromStr {\n fn scan<'a, I>(eles: &mut I) -> Self where I: Iterator {\n eles.map(|str| match str.parse() {\n Ok(res) => res,\n Err(_) => panic!()\n }).collect()\n }\n }\n};\n\n// -----------------------------------------------------------------------------\n\nfn main() {\n scanln!(n: u32, t: u32);\n if t == 10 && n == 1 {\n println!(\"-1\");\n } else if t == 10 {\n print!(\"1\");\n for _ in 0..n-1 { print!(\"0\"); }\n println!(\"\");\n } else {\n print!(\"{}\", t);\n for _ in 0..n-1 { print!(\"0\"); }\n println!(\"\");\n }\n}\n", "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"source_code": "use std::io::{self, Stdin, stdin};\nuse std::str::FromStr;\nuse std::error::Error;\n\nfn main() -> Result<(), Box> {\n let stdin = stdin();\n\n let cases = {\n let l = line(&stdin)?;\n let mut ite = l.trim().split(' ');\n usize::from_str(ite.next().unwrap())?\n };\n\n for _ in 0..cases {\n let it = {\n let l = line(&stdin)?;\n let mut ite = l.trim().split(' ');\n u32::from_str(ite.next().unwrap())?\n };\n\n let mut best: u32 = 1;\n for d in 2..=f64::sqrt(it as f64) as u32 {\n if it % d == 0 {\n let nd = it / d;\n if nd > best {\n best = nd;\n }\n }\n }\n println!(\"{} {}\", best, it - best);\n }\n\n Ok(())\n}\n\nfn line(s: &Stdin) -> io::Result {\n let mut i = String::new();\n s.read_line(&mut i)?;\n Ok(i)\n}\n", "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n#![allow(unused_macros)]\n\nuse std::char::*;\nuse std::cmp::*;\nuse std::collections::*;\nuse std::io::*;\nuse std::str::FromStr;\n\nmacro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);}}\nmacro_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 ) * } } ; }\nmacro_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 ) * } } ; }\nmacro_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\" ) } ; }\n\n#[derive(PartialEq, PartialOrd)]\npub struct Total(pub T);\nimpl Eq for Total {}\nimpl Ord for Total { fn cmp(&self, other: &Total) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}\n\nconst MAX:usize = 5;\nconst MOD:i64 = 1e9 as i64 + 7;\n\n\nfn read() -> T {\n let stdin = stdin();\n let stdin = stdin.lock();\n let token: String = stdin\n .bytes()\n .map(|c| c.expect(\"failed to read char\") as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect();\n token.parse().ok().expect(\"failed to parse token\")\n}\n\nfn read_vec() -> Vec {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).ok();\n s.trim().split_whitespace()\n .map(|e| e.parse().ok().unwrap()).collect()\n}\n\n\nuse std::f64;\n\nfn min(a:T, b:T) -> T {\n if a < b { a }\n else { b }\n}\n\nuse std::hash::Hash;\nfn inc(map:&mut BTreeMap, key:T) {\n let count = map.entry(key).or_insert(0);\n *count += 1;\n}\n\nfn mod_pow(x:i64, n:i64, m:i64) -> i64 {\n let mut x = x;\n let mut n = n;\n let mut res = 1i64;\n while n > 0 {\n if n & 1 > 0 {\n res = res * x % m;\n }\n x = x * x % m;\n n >>= 1;\n }\n res\n}\n\n\nfn main() {\n input!{n:usize};\n let mut ans = 0i64;\n for i in 1..n+1 {\n ans += 2i64.pow(i as u32);\n }\n println!(\"{}\", ans);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "src_uid": "f1b43baa14d4c262ba616d892525dfde"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nconst p: i64 = 1_000_000_007;\n\nfn main() {\n let (n, m, k) = {\n let input = get_line();\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n (\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n )\n };\n\n // (2^{n - 1})^{m - 1}\n // 2^{n + m - 2}\n\n if k == -1 && (n + m) % 2 != 0 {\n println!(\"0\");\n return;\n }\n\n let n0 = {\n let p0 = p - 1;\n ((n - 1) % p0) * ((m - 1) % p0) % p0\n };\n\n let mut two_pow_two_pow = Vec::new();\n\n let mul = |a, b| {\n ((a % p) * (b % p)) % p\n };\n\n let mut i = 2;\n for _ in 0..40 {\n two_pow_two_pow.push(i);\n i = mul(i, i);\n }\n\n let mut ans = 1;\n\n for i in 0..40 {\n if n0 & (1 << i) != 0 {\n ans = mul(ans, two_pow_two_pow[i]);\n }\n }\n\n println!(\"{}\", ans);\n}\n", "src_uid": "6b9eff690fae14725885cbc891ff7243"} {"source_code": "#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n let mut next = || { iter.next().unwrap() };\n input_inner!{next, $($r)*}\n };\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n\n ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n #[cfg(debug_assertions)]\n writeln!(&mut std::io::stderr(), concat!(\"[DEBUG] \", $(stringify!($a), \"={:?} \"),*), $($a),*);\n }\n}\n\n#[allow(unused_imports)]\nuse std::cmp::{min, max};\n#[allow(unused_imports)]\nuse std::io::{stdout, stdin, BufWriter, Write};\n\nfn main() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (writeln!(out,$($format)*).unwrap());\n }\n\n input!{\n n: usize,\n m: usize,\n a: usize,\n b: usize,\n g0: u64,\n x: u64,\n y: u64,\n z: u64,\n }\n\n let mut hs = vec![vec![0; m]; n];\n let mut g = g0;\n for i in 0..n*m {\n let a = i/m;\n let b = i%m;\n hs[a][b] = g;\n g = (g * x + y) % z;\n }\n\n // debug!(n, m, a, b, hs);\n\n let mut min_table = vec![];\n\n // \u30b9\u30e9\u30a4\u30c9\u6700\u5c0f\u5024\n use std::collections::VecDeque;\n for i in 0..n {\n let mut q: VecDeque<(usize,usize)> = VecDeque::new();\n let mut row_mins = vec![];\n for j in 0..m {\n let h = hs[i][j];\n\n while q.len() > 0 {\n let (x, y) = *q.back().unwrap();\n if h <= hs[x][y] {\n q.pop_back();\n } else {\n break;\n }\n }\n q.push_back((i, j));\n\n if j < b-1 {\n continue;\n }\n if j >= b {\n let (_,y) = *q.front().unwrap();\n if y == j-b {\n q.pop_front();\n }\n }\n\n // debug!(i, j, q);\n let (x,y) = *q.front().unwrap();\n row_mins.push(hs[x][y]);\n }\n min_table.push(row_mins);\n }\n\n let mut ans = 0;\n for j in 0..m-b+1 {\n let mut q: VecDeque<(usize,usize)> = VecDeque::new();\n for i in 0..n {\n let h = min_table[i][j];\n\n while q.len() > 0 {\n let (x, y) = *q.back().unwrap();\n if h <= min_table[x][y] {\n q.pop_back();\n } else {\n break;\n }\n }\n q.push_back((i, j));\n\n if i < a-1 {\n continue;\n }\n if i >= a {\n let (x,_) = *q.front().unwrap();\n if x == i-a {\n q.pop_front();\n }\n }\n\n let (x,y) = *q.front().unwrap();\n ans += min_table[x][y];\n\n }\n }\n puts!(\"{}\", ans);\n}\n", "src_uid": "4618fbffb2b9d321a6d22c11590a4773"} {"source_code": "\nuse std::io::prelude::*;\n\nuse std::cmp::*;\nuse std::*;\n\n\nfn main() {\n let stdin = std::io::stdin();\n let n = {\n let mut buf = String::new();\n stdin.read_line(&mut buf).unwrap();\n buf.trim().parse::().unwrap()\n };\n\n let mut a = vec![0; n];\n for (i, cur) in stdin.lock().split(b' ').enumerate() {\n let str = String::from_utf8(cur.unwrap()).unwrap();\n a[i] = str.trim().parse::().unwrap();\n }\n\n let mut dp1 = vec![0; n + 1];\n let mut dp2 = vec![0; n + 1];\n\n for i in 1..n + 1 {\n {\n let do_nothing = min(dp1[i - 1], dp2[i - 1]) + 1;\n dp1[i] = do_nothing;\n dp2[i] = do_nothing;\n }\n\n let cur = a[i - 1];\n\n if cur & 1 != 0 {\n dp1[i] = min(dp1[i], dp2[i - 1]);\n }\n\n if cur & 2 != 0 {\n dp2[i] = min(dp2[i], dp1[i - 1]);\n }\n }\n\n println!(\"{}\", min(dp2[n], dp1[n]));\n}\n", "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"source_code": "// 991A\nuse std::cmp::min;\nuse std::io;\n\nfn main() {\n let (a, b, c, n): (u32, u32, u32, u32) = read_two(&io::stdin());\n if a + b - c + 1 > n || c > min(a, b) {\n println!(\"{}\", -1);\n } else {\n println!(\"{}\", n - (a + b - c));\n }\n}\n\nfn read_two(stdin: &io::Stdin) -> (T, T, T, T)\nwhere\n T: std::str::FromStr,\n ::Err: std::fmt::Debug,\n{\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let mut iter = s.trim().split_whitespace().map(|x| x.parse().unwrap());\n (\n iter.next().unwrap(),\n iter.next().unwrap(),\n iter.next().unwrap(),\n iter.next().unwrap(),\n )\n}\n", "src_uid": "959d56affbe2ff5dd999a7e8729f60ce"} {"source_code": "use std::char;\nuse std::fs::File;\nuse std::io::Read;\n\n// fn pow_speedt_with_mod(mut p: i64, mut q: i64, m: i64) -> i64 {\n// p %= m;\n// let mut r = p;\n// let mut ret: i64 = 1;\n// while q > 0 {\n// ret *= if q % 2 == 1 {r} else {1};\n// r *= r;\n// r %= m;\n// q /= 2;\n// ret %= m;\n// }\n// return ret;\n// }\n\nfn main() {\n let inputstatus = 1;\n\n let mut buf = String::new();\n let filename = \"inputrust.txt\";\n\n if inputstatus == 0 {\n let mut f = File::open(filename).expect(\"file not found\");\n f.read_to_string(&mut buf)\n .expect(\"something went wrong reading the file\");\n } else {\n std::io::stdin().read_to_string(&mut buf).unwrap();\n }\n\n let mut iter = buf.split_whitespace();\n let n: usize = iter.next().unwrap().parse().unwrap();\n let mut p: usize = n;\n let mut q: usize = 0;\n let s: String = iter.next().unwrap().parse().unwrap();\n let mut v = vec![0; 26];\n let mut words = vec![];\n\n for c in s.chars() {\n if v[c as usize - 97] == 0 {\n v[c as usize - 97] = 1;\n if p > 0 {\n words.push(String::new());\n p -= 1;\n q += 1;\n }\n }\n words[q - 1].push(c);\n }\n if q == n {\n println!(\"YES\");\n for w in &words {\n println!(\"{}\", w);\n }\n } else {\n println!(\"NO\");\n }\n\n // if p + 1 >= m\n\n // println!(\"{}\", n);\n // println!(\"{}\", k);\n // println!(\"{:?}\", num);\n // println!(\"{:?}\", cum_num);\n}\n", "src_uid": "c1b071f09ef375f19031ce99d10e90ab"} {"source_code": "macro_rules! parse_line {\n ($t: ty) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let a_str = a_str.trim();\n a_str.parse::<$t>().expect(\"parse error\")\n });\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().expect(\"parse error\"),\n )+\n )\n })\n}\n\nmacro_rules! parse_line_to_vec {\n ($t: ty) => {{\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n (a_str\n .split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect::>())\n }};\n}\n\nfn solve() {\n let (n, k) = parse_line!(usize, usize);\n let a = parse_line_to_vec!(u32);\n let mut counts = std::collections::HashMap::::new();\n let mut max = 0;\n for x in a {\n *counts.entry(x).or_insert(0) += 1;\n max = std::cmp::max(max, counts[&x]);\n }\n println!(\"{}\", ((max - 1) / k + 1) * k * counts.len() - n);\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n", "src_uid": "c03ff0bc6a8c4ce5372194e8ea18527f"} {"source_code": "#![allow(unused_imports)]\nuse std::mem;\nuse std::io;\nuse std::string;\nuse std::cmp::*;\nuse std::collections::*;\n\nfn load() -> Vec {\n let mut line = String::new();\n io::stdin().read_line(&mut line).expect(\"Failed to read line\");\n let vec: Vec<&str> = line.split(\" \").collect();\n let mut data : Vec = Vec::new();\n for i in vec {\n let el : i64 = i.trim().parse().unwrap();\n data.push(el);\n }\n data\n}\nfn maxv(v : &Vec) -> i64{\n let mut s=v[0];\n for i in v {s=max(s,*i);}\n return s;\n}\nfn minv(v : &Vec) -> i64{\n let mut s=v[0];\n for i in v {s=min(s,*i);}\n return s;\n}\n\nfn main() {\n let s = load()[0];\n let mut num = 0;\n let mut sum = 0;\n let mut last = 0;\n for i in 1..s+1 {\n num+=i;\n sum+=num;\n if sum > s {break;}\n last = i;\n }\n println!(\"{}\", last);\n}\n// min, max\n// HashSet, insert, contains\n// Vec, len, sort\n// primitive retype: i as f64\n", "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin()\n .read_line(&mut s)\n .unwrap();\n\n let words: Vec = s\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n for i in 1..10 {\n if i * words[0] % 10 == words[1] || i * words[0] % 10 == 0 {\n println!(\"{}\", i);\n break;\n }\n }\n}\n", "src_uid": "18cd1cd809df4744bb7bcd7cad94e2d3"} {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::{cell::{Cell, RefCell, UnsafeCell}, cmp::{Ordering, Reverse, max, min}, collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, hash_map::{DefaultHasher, RandomState}}, error::Error, fmt::{Display, Write as FmtWrite}, hash::{BuildHasher, Hash, Hasher}, io::{BufWriter, Read, Stdin, Stdout, Write}, iter::{FromIterator, Peekable}, mem::swap, ops::*, process::exit, rc::Rc, str::{FromStr, from_utf8_unchecked}, time::{Duration, Instant}};\n\nconst IO_BUF_SIZE: usize = 1 << 16;\ntype Input = Scanner;\ntype Output = BufWriter;\nfn _init_input() -> Input { Scanner::new(std::io::stdin()) }\nfn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) }\n\n#[repr(transparent)] struct Unsync(T);\nunsafe impl Sync for Unsync {}\n \ntype BadLazy = Unsync>>;\nimpl BadLazy {\n const fn new() -> Self { Self(UnsafeCell::new(None)) }\n}\n \nstatic INPUT: BadLazy = BadLazy::new();\nstatic OUTPUT: BadLazy = BadLazy::new();\n \nfn inp R, R>(f: F) -> R {\n unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) }\n}\nfn out R, R>(f: F) -> R {\n unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) }\n}\n\nmacro_rules! read {\n () => { read() };\n ($t: ty) => { read::<$t>() };\n ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) };\n [$t: ty; $n: expr] => { read_vec::<$t>($n) };\n}\nmacro_rules! println { \n () => { out(|x| { let _ = writeln!(x); }) };\n ($exp: expr) => { out(|x| { let _ = writeln!(x, \"{}\", $exp); }) }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = writeln!(x, $fmt, $($arg)*); }) }\n}\nmacro_rules! print { \n ($exp: expr) => { out(|x| { let _ = write!(x, \"{}\", $exp); }) }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = write!(x, $fmt, $($arg)*); }) }\n}\n\nfn out_flush() { out(|x| { let _ = x.flush(); }); }\n\nfn input_is_eof() -> bool { inp(|x| x.eof()) }\nfn read_byte() -> u8 { inp(|x| x.byte()) }\nfn read_bytes_no_skip(n: usize) -> Vec { inp(|x| x.bytes_no_skip(n)) }\nfn read_bytes(n: usize) -> Vec { inp(|x| x.bytes(n)) }\nfn read_bytes2(n: usize, m: usize) -> Vec> { inp(|x| x.bytes2(n, m)) }\nfn read_token() -> Vec { inp(|x| x.token_bytes()) }\nfn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } }\nfn read_line() -> Vec { inp(|x| x.line_bytes()) }\nfn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } }\nfn read() -> T { read_token_str().parse::().ok().expect(\"failed parse\") }\nfn read_vec(n: usize) -> Vec { (0..n).map(|_| read()).collect() }\nfn read_vec2(n: usize, m: usize) -> Vec> { (0..n).map(|_| read_vec(m)).collect() }\n\nstruct Scanner {\n src: R,\n _buf: Vec,\n _pt: usize, // pointer\n _rd: usize, // bytes read\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new(src: R) -> Scanner {\n Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }\n }\n \n fn _check_buf(&mut self) {\n if self._pt == self._rd {\n self._rd = self.src.read(&mut self._buf).unwrap_or(0);\n self._pt = (self._rd == 0) as usize;\n }\n }\n \n // returns true if end of file\n fn eof(&mut self) -> bool {\n self._check_buf();\n self._rd == 0\n }\n \n // filters \\r, returns \\0 if eof\n fn byte(&mut self) -> u8 {\n loop {\n self._check_buf();\n if self._rd == 0 { return 0; }\n let res = self._buf[self._pt];\n self._pt += 1;\n if res != b'\\r' { return res; }\n }\n }\n\n fn bytes_no_skip(&mut self, n: usize) -> Vec { (0..n).map(|_| self.byte()).collect() }\n fn bytes(&mut self, n: usize) -> Vec {\n let res = self.bytes_no_skip(n);\n self.byte();\n res\n }\n fn bytes2(&mut self, n: usize, m: usize) -> Vec> { (0..n).map(|_| self.bytes(m)).collect() }\n \n fn token_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c <= b' ' {\n if c == b'\\0' { return res; }\n c = self.byte();\n }\n loop {\n res.push(c);\n c = self.byte();\n if c <= b' ' { return res; }\n }\n }\n \n fn line_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c != b'\\n' && c != b'\\0' {\n res.push(c);\n c = self.byte();\n }\n res\n }\n}\n\ntrait JoinToStr { \n fn join_to_str(self, sep: &str) -> String;\n fn concat_to_str(self) -> String;\n}\nimpl> JoinToStr for I { \n fn join_to_str(mut self, sep: &str) -> String {\n match self.next() {\n Some(first) => {\n let mut res = first.to_string();\n while let Some(item) = self.next() {\n res.push_str(sep);\n res.push_str(&item.to_string());\n }\n res\n }\n None => { String::new() }\n }\n }\n \n fn concat_to_str(self) -> String {\n let mut res = String::new();\n for item in self { res.push_str(&item.to_string()); }\n res\n }\n}\ntrait AsStr { fn as_str(&self) -> &str; }\nimpl AsStr for [u8] { fn as_str(&self) -> &str {std::str::from_utf8(self).expect(\"attempt to convert non-UTF8 byte string.\")} }\n\nmacro_rules! veci {\n ($n:expr , $i:ident : $gen:expr) => {{\n let _veci_n = $n;\n let mut _veci_list = Vec::with_capacity(_veci_n);\n for $i in 0.._veci_n {\n _veci_list.push($gen);\n }\n _veci_list\n }};\n ($n:expr , $gen:expr) => { veci!($n, _veci_: $gen) }\n}\n\nfn abs_diff + PartialOrd>(x: T, y: T) -> T {\n if x < y { y - x } else { x - y }\n}\n\ntrait CommonNumExt {\n fn div_ceil(self, b: Self) -> Self;\n fn div_floor(self, b: Self) -> Self;\n fn gcd(self, b: Self) -> Self;\n fn highest_one(self) -> Self;\n fn lowest_one(self) -> Self;\n fn sig_bits(self) -> u32;\n}\n\nmacro_rules! impl_common_num_ext {\n ($($ix:tt = $ux:tt),*) => {\n $(\n impl CommonNumExt for $ux {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { self / b }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }\n b\n }\n #[inline] fn highest_one(self) -> Self { \n if self == 0 { 0 } else { const ONE: $ux = 1; ONE.rotate_right(1) >> self.leading_zeros() } \n }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ux>() as u32 * 8 - self.leading_zeros() }\n }\n\n impl CommonNumExt for $ix {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if self ^ b >= 0 && r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { \n let q = self / b; let r = self % b;\n if self ^ b < 0 && r != 0 { q - 1 } else { q }\n }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }\n b.abs()\n }\n #[inline] fn highest_one(self) -> Self { (self as $ux).highest_one() as _ }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ix>() as u32 * 8 - self.leading_zeros() }\n }\n )*\n }\n}\nimpl_common_num_ext!(i8 = u8, i16 = u16, i32 = u32, i64 = u64, i128 = u128, isize = usize);\n\ntrait ChMaxMin {\n fn set_max(&mut self, v: T) -> bool;\n fn set_min(&mut self, v: T) -> bool;\n}\nimpl ChMaxMin for T {\n fn set_max(&mut self, v: T) -> bool { if v > *self { *self = v; true } else { false } }\n fn set_min(&mut self, v: T) -> bool { if v < *self { *self = v; true } else { false } }\n}\n\n// * end commons * //\n \n#[allow(non_snake_case, non_upper_case_globals)]\nfn main() {\n let num_cases: usize = read();\n \n for _case_num in 1..=num_cases {\n let n = read!(u32);\n\n let rt = |k: u32| {\n let mut g = (n as f64).powf(1./(k as f64)).floor() as u32 - 1;\n while (g+1).pow(k) <= n { g += 1; }\n g\n };\n\n let ans = rt(2) + rt(3) - rt(6);\n println!(ans);\n }\n \n out_flush();\n}", "src_uid": "015afbefe1514a0e18fcb9286c7b6624"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn parse_bin_val(s: &str) -> Vec {\n s.bytes().map(|byte| match byte {\n b'0' => false,\n b'1' => true,\n _ => panic!(\"NOT A BIT!\"),\n }).collect()\n}\n\nfn main() {\n let (h, m, s, t1, t2) = {\n let input = get_line();\n let mut it = input.split_whitespace().map(|k| k.parse::().unwrap());\n (\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n )\n };\n\n let modulo = |a, b| {\n if a % b < 0 {\n a % b + b\n } else {\n a % b\n }\n };\n\n let convert = |x| {\n modulo(x, 12) * 5\n };\n\n // println!(\"{} {} {}\", convert(h), convert(t1), convert(t2));\n\n let mut arr = vec![convert(h) + 1, m, s, convert(t1), convert(t2)];\n\n arr.sort();\n\n let i1 = arr.iter().position(|&x| x == convert(t1)).unwrap() as i64;\n let i2 = arr.iter().position(|&x| x == convert(t2)).unwrap() as i64;\n\n // println!(\"{} {}\", i1, i2);\n\n let ans = modulo(i2 - i1, 5) == 1 || modulo(i1 - i2, 5) == 1;\n\n if ans {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "912c8f557a976bdedda728ba9f916c95"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap,BTreeSet};\n#[allow(unused_imports)]\nuse std::ops::*;\n#[allow(unused_imports)]\nuse std::collections::BinaryHeap;\n\n#[allow(unused_macros)]\nmacro_rules! ite {\n ($c:expr, $t:expr, $f:expr) => {{\n if $c { $t } else { $f }\n }};\n}\n\n// ref: tanakh \n// diff: using Parser\n#[macro_export]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut parser = Parser::from_str($s);\n input_inner!{parser, $($r)*}\n };\n (parser = $parser:ident, $($r:tt)*) => {\n input_inner!{$parser, $($r)*}\n };\n (new_stdin_parser = $parser:ident, $($r:tt)*) => {\n let stdin = std::io::stdin();\n let reader = std::io::BufReader::new(stdin.lock());\n let mut $parser = Parser::new(reader);\n input_inner!{$parser, $($r)*}\n };\n ($($r:tt)*) => {\n input!{new_stdin_parser = parser, $($r)*}\n };\n}\n\n#[macro_export]\nmacro_rules! input_inner {\n ($parser:ident) => {};\n ($parser:ident, ) => {};\n ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($parser, $t);\n input_inner!{$parser $($r)*}\n };\n}\n\n#[macro_export]\nmacro_rules! read_value {\n ($parser:ident, ( $($t:tt),* )) => {\n ( $(read_value!($parser, $t)),* )\n };\n ($parser:ident, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($parser, $t)).collect::>()\n };\n ($parser:ident, chars) => {\n read_value!($parser, String).chars().collect::>()\n };\n ($parser:ident, usize1) => {\n read_value!($parser, usize) - 1\n };\n ($parser:ident, $t:ty) => {\n $parser.next::<$t>().expect(\"Parse error\")\n };\n}\n\nfn prime_factorization(n: i64) -> Vec<(i64,usize)> {\n let mut res = vec![];\n let mut x = n;\n let mut i = 2;\n while i * i <= x {\n let mut count = 0;\n while x % i == 0 {\n count += 1;\n x /= i;\n }\n if count != 0 {\n res.push((i, count));\n }\n i += 1;\n }\n if x != 1 {\n res.push((x,1));\n }\n res\n}\n\nfn dfs(ps: &Vec<(i64,usize)>, table: &Vec>, i: usize, x: i64, prob: Mod) -> Mod {\n if i == ps.len() {\n return prob * Mod::new(x as u64);\n }\n let mut res = Mod::new(0);\n for k in 0..ps[i].1+1 {\n res += dfs(ps, table, i+1, x * ps[i].0.pow(k as u32), prob * table[i][k]);\n }\n res\n}\n\nfn main() {\n input! {\n n: i64,\n m: u64,\n }\n let ps = prime_factorization(n);\n\n let mut inv_table = vec![Mod::new(1), Mod::new(1)];\n for i in 2..1000 {\n inv_table.push(Mod::new(1) / Mod::new(i));\n }\n\n let mut table = vec![];\n for &(p,count) in &ps {\n let mut dp = vec![Mod::new(0); count+1];\n dp[count] = Mod::new(1);\n for _ in 0..m {\n let mut dp2 = vec![Mod::new(0); count+1];\n for j in 0..count+1 {\n for k in 0..j+1 {\n // dp2[k] += dp[j] / Mod((j+1) as u64);\n dp2[k] += dp[j] * inv_table[j+1];\n }\n }\n dp = dp2;\n }\n table.push(dp);\n }\n\n let res = dfs(&ps, &table, 0, 1, Mod::new(1));\n println!(\"{}\", res.0);\n}\n\nuse std::ops::*;\n\nconst MOD : u64 = 1_000_000_007;\n#[derive(Clone,Copy,PartialEq,Debug)]\npub struct Mod (pub u64);\n\nimpl Mod {\n pub fn new(x: u64) -> Mod {\n Mod(x % MOD)\n }\n pub fn pow(self, n: u64) -> Mod {\n if n == 0 {\n return Mod(1);\n }\n let t = self.pow(n/2);\n if n % 2 == 0 {\n t * t\n }\n else {\n t * t * self\n }\n }\n}\n\nimpl Add for Mod {\n type Output = Self;\n fn add(self, rhs: Self) -> Self::Output {\n Mod((self.0 + rhs.0) % MOD)\n }\n}\n\nimpl AddAssign for Mod {\n fn add_assign(&mut self, rhs: Self) {\n *self = *self + rhs;\n }\n}\n\nimpl Sub for Mod {\n type Output = Self;\n fn sub(self, rhs: Self) -> Self::Output {\n Mod((self.0 + MOD - rhs.0 % MOD) % MOD)\n }\n}\n\nimpl SubAssign for Mod {\n fn sub_assign(&mut self, rhs: Self) {\n *self = *self - rhs;\n }\n}\n\nimpl Neg for Mod {\n type Output = Mod;\n fn neg(self) -> Mod {\n Mod(MOD - self.0)\n }\n}\n\nimpl Mul for Mod {\n type Output = Self;\n fn mul(self, rhs: Self) -> Self::Output {\n Mod((self.0 % MOD) * (rhs.0 % MOD) % MOD)\n }\n}\n\nimpl MulAssign for Mod {\n fn mul_assign(&mut self, rhs: Self) {\n *self = *self * rhs;\n }\n}\n\nimpl Div for Mod {\n type Output = Self;\n fn div(self, rhs: Self) -> Self::Output {\n if rhs.0 == 0 {\n loop {}\n }\n assert!(rhs.0 != 0);\n self * rhs.pow(MOD-2)\n }\n}\n\nuse std::io::BufRead;\nuse std::io;\nuse std::str;\n\n// ref: tatsuya6502 \n// ref: wariuni \n// diff: using std::io::BufRead::fill_buf()\npub struct Parser {\n reader: R,\n buf: Vec,\n pos: usize,\n}\n\nimpl Parser {\n pub fn from_str(s: &str) -> Parser {\n Parser {\n reader: io::empty(),\n buf: s.as_bytes().to_vec(),\n pos: 0,\n }\n }\n}\n\nimpl Parser {\n pub fn new(reader: R) -> Parser {\n Parser {\n reader: reader,\n buf: vec![],\n pos: 0,\n }\n }\n pub fn update_buf(&mut self) {\n self.buf.clear();\n self.pos = 0;\n loop {\n let (len,complete) = {\n let buf2 = self.reader.fill_buf().unwrap();\n self.buf.extend_from_slice(buf2);\n let len = buf2.len();\n (len, buf2[len-1] <= 0x20)\n };\n self.reader.consume(len);\n if complete {\n break;\n }\n }\n }\n pub fn next(&mut self) -> Result {\n loop {\n let mut begin = self.pos;\n while begin < self.buf.len() && (self.buf[begin] <= 0x20) {\n begin += 1;\n }\n let mut end = begin;\n while end < self.buf.len() && (self.buf[end] > 0x20) {\n end += 1;\n }\n if begin != self.buf.len() {\n self.pos = end;\n return str::from_utf8(&self.buf[begin..end]).unwrap().parse::();\n }\n else {\n self.update_buf();\n }\n }\n }\n}\n\nuse std::fmt::Display;\n#[allow(dead_code)]\nfn write_vec(xs: &Vec) {\n if xs.len() == 0 {\n println!();\n return;\n }\n print!(\"{}\", xs[0]);\n for i in 1..xs.len() {\n print!(\" {}\", xs[i]);\n }\n println!();\n}\n", "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2"} {"source_code": "/*\n *\n * Author : fcbruce \n *\n * Time : Sat 10 Feb 2018 20:02:28\n *\n */\n\nfn main() {\n\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).unwrap();\n let mut numbers = buffer.split_whitespace();\n let n: u64 = numbers.next().unwrap().parse::().unwrap();\n let k: u64 = numbers.next().unwrap().parse::().unwrap();\n\n let max: usize = 100000;\n\n let mut remainders = vec![false; max];\n\n let mut min = k + 1;\n\n for i in 1..std::cmp::min::(max as u64, k + 1) {\n let r: usize = (n % i) as usize;\n if remainders[r] {\n min = i;\n break;\n }\n remainders[r] = true;\n }\n\n if k == 1 || k < min {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n\n}\n", "src_uid": "5271c707c9c72ef021a0baf762bf3eb2"} {"source_code": "#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]\nuse std::io::{stdin, Read, StdinLock};\nuse std::str::FromStr;\nuse std::fmt::*;\nuse std::str::*;\nuse std::cmp::*;\nuse std::collections::*;\n\nfn getline() -> String{\n let mut res = String::new();\n std::io::stdin().read_line(&mut res).ok();\n res\n}\n\nmacro_rules! readl {\n ($t: ty) => {\n {\n let s = getline();\n s.trim().parse::<$t>().unwrap()\n }\n };\n ($( $t: ty),+ ) => {\n {\n let s = getline();\n let mut iter = s.trim().split(' ');\n ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) \n }\n };\n}\n\nmacro_rules! readlvec {\n ($t: ty) => {\n {\n let s = getline();\n let iter = s.trim().split(' ');\n iter.map(|x| x.parse().unwrap()).collect::>()\n }\n }\n}\n\nmacro_rules! mvec {\n ($v: expr, $s: expr) => {\n vec![$v; $s]\n };\n ($v: expr, $s: expr, $($t: expr),*) => {\n vec![mvec!($v, $($t),*); $s]\n };\n}\n\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {:?}\", stringify!($x), $x)\n }\n}\n\nfn printiter<'a, T>(v: &'a T)\nwhere\n &'a T: std::iter::IntoIterator, \n <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {\n for (i,e) in v.into_iter().enumerate() {\n if i != 0 {\n print!(\" \");\n }\n print!(\"{}\", e);\n }\n println!(\"\");\n}\n\nstruct ContestPrinter {\n s: String,\n}\n\nimpl ContestPrinter {\n fn new() -> ContestPrinter {\n ContestPrinter {\n s: String::new(),\n }\n }\n\n fn print(&mut self, x: T)\n where T: std::fmt::Display {\n self.s.push_str(format!(\"{}\", x).as_str());\n }\n\n fn println(&mut self, x: T)\n where T: std::fmt::Display {\n self.s.push_str(format!(\"{}\\n\", x).as_str());\n }\n}\n\nimpl std::ops::Drop for ContestPrinter {\n fn drop(&mut self) {\n print!(\"{}\", self.s);\n }\n}\n\nfn main() {\n let mut printer = ContestPrinter::new();\n \n let (L, R, A) = readl!(i32, i32, i32);\n let mut l = L;\n let mut r = R;\n if l > r {\n r += A;\n } else {\n l += A;\n }\n while (l - r).abs() > 1 {\n if l > r {\n if l == L { break; }\n l -= 1;\n r += 1;\n } else {\n if r == R { break; }\n r -= 1;\n l += 1;\n }\n }\n printer.println(2 * min(l, r));\n}", "src_uid": "e8148140e61baffd0878376ac5f3857c"} {"source_code": "fn kth(v: &mut Vec, l: usize, r: usize, k: usize) -> usize {\n let p = v[r];\n let mut s = l;\n for i in l..r {\n if p < v[i] {\n v.swap(s, i);\n s += 1;\n }\n }\n\n v.swap(s, r);\n if k == s {\n return v[k];\n } else if k < s {\n return kth(v, 0, s - 1, k);\n }\n\n return kth(v, s + 1, r, k);\n}\n\nfn main() {\n // The input n and k\n let mut s0 = String::new();\n std::io::stdin().read_line(&mut s0).unwrap();\n let v0: Vec = s0.trim().split_whitespace().map(|x| x.parse::().unwrap()).collect();\n let k = v0[1] - 1;\n\n // The input Ai\n let mut s1 = String::new();\n std::io::stdin().read_line(&mut s1).unwrap();\n let mut v1: Vec = s1.trim().split_whitespace().map(|x| x.parse::().unwrap()).collect();\n\n // The kth smallest element\n v1.sort();\n let s = v1.len() - 1;\n let e = kth(&mut v1, 0, s, k);\n let cnt = v1.iter().fold(0, |cnt, x| cnt + ((x > &0 && x >= &e) as usize));\n\n // Display the result\n println!(\"{}\", cnt);\n}\n", "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io::{self, prelude::*};\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let n: usize = it.next().unwrap().parse().unwrap();\n let mut g: Vec = it.take(n).map(|x| x.parse().unwrap()).collect();\n g.sort_unstable();\n\n let t: Vec<_> = std::iter::once(0).chain(g.into_iter().rev().scan(0, |state, x| {\n *state += 2 * x;\n Some(*state)\n })).collect();\n\n let target = 9 * n;\n\n let ans = match t.into_iter().rev().enumerate().position(|(i, x)| x + 10 * i >= target) {\n None => n,\n Some(p) => p,\n };\n println!(\"{}\", ans);\n}\n", "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"source_code": "// A. Chess Placing http://codeforces.com/contest/985/problem/A\n\nfn main() {\n let stdin = std::io::stdin();\n let mut buf = String::new();\n stdin.read_line(&mut buf).unwrap(); // discard\n buf.clear();\n stdin.read_line(&mut buf).unwrap();\n let mut arr: Vec = buf.split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect();\n arr[..].sort_unstable();\n let f = |mut m: i32| {\n let mut total = 0;\n for n in &arr {\n total += (n - m).abs();\n m += 2;\n }\n total\n };\n let ans: i32 = vec![1, 2].into_iter().map(f).min().unwrap();\n println!(\"{}\", ans);\n}\n", "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io::prelude::*;\n std::io::stdin().read_to_string(&mut input).unwrap();\n let mut it = input.split_whitespace();\n\n let n: usize = it.next().unwrap().parse().unwrap();\n\n let a: Vec = it.take(n).map(|x| x.parse().unwrap()).collect();\n\n let ms = vec![31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,\n 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\n let ans = (0..ms.len() - n).any(|i| a.iter().zip(ms.iter().skip(i)).all(|(&a, &m)| a == m));\n\n if ans {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"source_code": "#![allow(dead_code,unused_imports)]\n#[rustfmt::skip] mod prefix_sum {use std::fmt::{self, Debug, Formatter};use std::ops::Add;#[derive(Clone)] pub struct PrefixOp where I: Iterator, F: Fn(T, T) -> T, { iter: I, acc: Option, f: F, } impl Iterator for PrefixOp where I: Iterator, F: Fn(T, T) -> T, T: Clone, { type Item = T;fn next(&mut self) -> Option { let next = self.iter.next();if let Some(next) = next { if let Some(acc) = self.acc.take() { self.acc = Some((self.f)(acc, next));} else { self.acc = Some(next);} Some(self.acc.clone().unwrap()) } else { None } } } impl Debug for PrefixOp where I: Iterator + Debug, F: Fn(T, T) -> T, T: Debug, { fn fmt(&self, f: &mut Formatter) -> fmt::Result { f.debug_struct(\"PrefixOp\") .field(\"acc\", &self.acc) .field(\"iter\", &self.iter) .finish() } } pub trait CreatePrefixOps: Iterator + Sized where F: Fn(T, T) -> T, { fn prefix_ops(self, op: F) -> PrefixOp;} impl CreatePrefixOps for I where I: Iterator, F: Fn(T, T) -> T, { fn prefix_ops(self, op: F) -> PrefixOp { PrefixOp { iter: self, acc: None, f: op, } } } macro_rules! prefix_op_specialisation { ($trait_name:ident, $fn_name:ident, $fn:expr, $($bound_token:tt)+) => { pub trait $trait_name: Iterator + Sized where $($bound_token)+ { fn $fn_name(self) -> PrefixOp T>;} impl $trait_name for I where I: Iterator, $($bound_token)+ { fn $fn_name(self) -> PrefixOp T> { PrefixOp { iter: self, acc: None, f: $fn, } } } };} prefix_op_specialisation!(CreatePrefixSums, prefix_sums, T::add, T: Add);prefix_op_specialisation!(CreatePrefixMax, prefix_max, T::max, T: Ord);prefix_op_specialisation!(CreatePrefixMin, prefix_min, T::min, T: Ord);}\n#[rustfmt::skip] mod scanner {use std::io::{stdin, BufReader, Bytes, Error as IoError, Read, Stdin};use std::str::{self, FromStr, Utf8Error};#[derive(Debug)] pub struct Scanner { bytes: Bytes>, buf: Vec, } #[derive(Debug)] pub enum ScanError { Io(IoError), Parse(T::Err, String), NonUtf8(Utf8Error, Vec), } impl Scanner { pub fn stdin() -> Self { Self::new(stdin()) } } impl Scanner { pub fn new(reader: R) -> Self { Self { bytes: BufReader::new(reader).bytes(), buf: Vec::new(), } } #[allow(clippy::should_implement_trait)] pub fn next(&mut self) -> Result> { assert!(self.buf.is_empty());for b in &mut self.bytes { let b = b.map_err(ScanError::Io)?;if b.is_ascii_whitespace() { if self.buf.is_empty() { continue;} else { break;} } else { self.buf.push(b);} } match str::from_utf8(&self.buf) { Err(err) => Err(ScanError::NonUtf8(err, std::mem::take(&mut self.buf))), Ok(s) => { let ret = s.parse().map_err(|err| ScanError::Parse(err, s.to_owned()));self.buf.clear();ret } } } } #[macro_export] macro_rules! scan { ($scanner:expr) => { $scanner.next().expect(\"failed to read token\") };($scanner:expr, $type:ty) => { $scanner .next::<$type>() .expect(concat!(\"failed to read token of type \", stringify!($type))) };($scanner:expr, $type:ty; $n:expr) => { (0..$n).map(|_| scan!($scanner)).collect::>() };($scanner:expr, $($type:ty),+) => { ($( scan!($scanner, $type), )+) };} }\n#[rustfmt::skip] mod writer {use std::fmt::Display;use std::io::{stdout, BufWriter, Error as IoError, Stdout, Write};#[derive(Debug)] pub struct Writer { writer: BufWriter, } impl Writer { pub fn stdout() -> Self { Self::new(stdout()) } } impl Writer { pub fn new(writer: W) -> Self { Self { writer: BufWriter::new(writer), } } pub fn write>(&mut self, val: T) -> Result<(), IoError> { val.write_to(&mut self.writer) } pub fn flush(&mut self) -> Result<(), IoError> { self.writer.flush() } } pub trait Writable { fn write_to(self, w: &mut W) -> Result<(), IoError>;} #[non_exhaustive] pub struct Single;impl Writable for T { fn write_to(self, w: &mut W) -> Result<(), IoError> { writeln!(w, \"{}\", self) } } #[non_exhaustive] pub struct Many;impl Writable for I where I: Iterator, I::Item: Display, { fn write_to(mut self, w: &mut W) -> Result<(), IoError> { if let Some(x) = self.next() { write!(w, \"{}\", x)?;} else { return Ok(());} for x in self { write!(w, \" {}\", x)?;} writeln!(w) } } #[non_exhaustive] pub struct Array;impl Writable for &[T] { fn write_to(self, w: &mut W) -> Result<(), IoError> { self.iter().write_to(w) } } }\n#[rustfmt::skip] mod util { pub trait IntoVec { fn into_vec(self) -> Vec;} #[non_exhaustive] pub struct Owned;impl IntoVec for I where I: Iterator, { fn into_vec(self) -> Vec { self.collect() } } #[non_exhaustive] pub struct Reference;impl<'a, I, T> IntoVec for I where I: Iterator, T: Clone + 'a, { fn into_vec(self) -> Vec { self.cloned().collect() } } pub trait Argmax { fn argmax(self) -> Option;} impl Argmax for I where I: Iterator, I::Item: Ord, { fn argmax(self) -> Option { self.fold((0, None), |(i, mx), next| { if let Some((mx_i, mx_v)) = mx { if next.gt(&mx_v) { (i + 1, Some((i, next))) } else { (i + 1, Some((mx_i, mx_v))) } } else { (i + 1, Some((i, next))) } }) .1 .map(|x| x.0) } } pub trait Sorted { fn sorted(self) -> Self;} impl Sorted for Vec where T: Ord, { fn sorted(mut self) -> Self { self.sort();self } } pub trait Choose { fn choose(self, a: T, b: T) -> T;} impl Choose for bool { fn choose(self, a: T, b: T) -> T { if self { a } else { b } } } }\n\nuse prefix_sum::{CreatePrefixOps, CreatePrefixSums, CreatePrefixMax, CreatePrefixMin};\nuse scanner::Scanner;\nuse writer::Writer;\nuse util::{IntoVec, Argmax, Sorted, Choose};\n\nconst MOD: i64 = 1_000_000_007;\nfn main() {\n let mut sc = Scanner::stdin();\n let mut wr = Writer::stdout();\n for _ in 0..scan!(sc, usize) {\n let (n, k) = scan!(sc, i64, i64);\n\n if n % 2 == 0 {\n let mut total = 0;\n let a = modexp(2, n - 1) - 1;\n let b = modexp(2, n);\n for i in 0..k {\n total = (total + modexp(a, i) * modexp(b, k - i - 1)) % MOD;\n }\n total = (total + modexp(a, k)) % MOD;\n wr.write(total).unwrap();\n } else {\n let c = (modexp(2, n - 1) - 1 + 2 * (n % 2)) % MOD;\n let total = modexp(c, k);\n wr.write(total).unwrap();\n }\n }\n}\n\nconst fn modexp(a: i64, b: i64) -> i64 {\n if b == 0 { 1 }\n else if b % 2 == 0 { modexp((a * a) % MOD, b / 2) }\n else { (modexp((a * a) % MOD, b / 2) * a) % MOD}\n}\n\nconst fn modinv(a: i64) -> i64 {\n modexp(a, MOD - 2)\n}\n", "src_uid": "02f5fe43ea60939dd4a53299b5fa0881"} {"source_code": "fn main() {\n let mut n: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\n };\n let mut group = 1;\n while n > group * 5 {\n n -= group * 5;\n group *= 2;\n }\n let index = (n - 1) / group;\n let names = vec![\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"];\n println!(\"{}\", names[index as usize]);\n}\n", "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"source_code": "use std::io::stdin;\nuse std::cmp::*;\n\nfn main() {\n let (n, k) = {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let mut it = input.split_whitespace().map(|k| k.parse::().unwrap());\n (it.next().unwrap(), it.next().unwrap())\n };\n\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let it = input.split_whitespace().map(|k| k.parse::().unwrap());\n\n let mut ac = 0;\n let mut bc = 0;\n\n for (i, a) in it.enumerate() {\n ac += a;\n bc += min(ac, 8);\n ac -= min(ac, 8);\n if k <= bc {\n println!(\"{}\", i + 1);\n std::process::exit(0);\n }\n }\n\n println!(\"-1\");\n}\n", "src_uid": "24695b6a2aa573e90f0fe661b0c0bd3a"} {"source_code": "struct Scanner<'a, T: std::io::Read> {\n reader: &'a mut T,\n buffer: [u8; 4096],\n position: usize,\n size: usize\n}\n\nimpl<'a, T: std::io::Read> Scanner<'a, T> {\n fn new(reader: &'a mut T) -> Scanner<'a, T> {\n Scanner {\n reader,\n buffer: [0; 4096],\n position: 0,\n size: 0\n }\n }\n\n fn read_block(&mut self) {\n self.size = self.reader.read(&mut self.buffer).unwrap();\n self.position = 0;\n }\n\n fn read_char(&mut self) -> i32 {\n if self.position >= self.size {\n self.read_block();\n if self.position >= self.size {\n return -1;\n }\n }\n \n let ch = self.buffer[self.position];\n self.position += 1;\n \n ch as i32\n }\n\n fn read_int(&mut self) -> Option {\n const SPACES: [i32; 4] = [\n ' ' as i32,\n '\\n' as i32,\n '\\t' as i32,\n '\\r' as i32];\n const ZERO: i32 = '0' as i32;\n const NINE: i32 = '9' as i32;\n const NEG: i32 = '-' as i32;\n \n let mut ch = self.read_char();\n while ch != -1 && SPACES.contains(&ch) {\n ch = self.read_char();\n }\n\n if ch == -1 {\n return None;\n }\n\n let mut negative = false;\n if ch == NEG {\n negative = true;\n ch = self.read_char();\n }\n\n let mut result = 0;\n while ch != -1 && ch >= ZERO && ch <= NINE {\n result = result * 10 + ch - ZERO;\n ch = self.read_char();\n }\n\n Some(if negative {\n -result\n } else {\n result\n })\n }\n}\n\nstruct Party {\n id: i32,\n pop: i32\n}\n\nfn main() {\n let mut stdin = std::io::stdin();\n let mut reader = Scanner::new(&mut stdin);\n \n let n = reader.read_int().unwrap();\n let mut a: Vec = Vec::new();\n for i in 1..=n {\n a.push(Party {\n id: i,\n pop: reader.read_int().unwrap()\n });\n }\n \n let total_seats: i32 = a.iter().map(|x| x.pop).sum();\n let half_seats = total_seats / 2;\n let master_seats = a[0].pop;\n a.sort_unstable_by_key(|party| party.pop);\n\n let mut total = master_seats;\n let mut selected = vec![1];\n for party in a {\n if party.id == 1 {\n continue;\n }\n if party.pop > master_seats / 2 {\n break;\n }\n if total > half_seats {\n break;\n }\n\n selected.push(party.id);\n total += party.pop;\n }\n\n if total <= half_seats {\n println!(\"0\");\n return;\n }\n\n println!(\"{}\", selected.len());\n for x in selected {\n print!(\"{} \", x);\n }\n println!(\"\");\n}\n", "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"source_code": "#![allow(unused_parens)]\n#![allow(unused_imports)]\n#![allow(non_upper_case_globals)]\n#![allow(non_snake_case)]\n#![allow(unused_mut)]\n#![allow(unused_variables)]\n#![allow(dead_code)]\n\ntype Vec2 = Vec>;\ntype Vec3 = Vec>>;\n\n#[allow(unused_macros)]\nmacro_rules! invec {\n ( $ t : ty ) => {{\n let mut s = String::new();\n match std::io::stdin().read_line(&mut s) {\n Ok(0) => Vec::<$t>::new(),\n Ok(n) => s\n .trim()\n .split_whitespace()\n .map(|s| s.parse::<$t>().unwrap())\n .collect::>(),\n Err(_) => Vec::<$t>::new(),\n }\n }};\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n ($t:ty ;; $n:expr) => {\n (0..$n).map(|_| get!($t ;;)).collect::>()\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let mut s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($next:expr, [$t:tt]) => {\n {\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\n#[cfg(debug_assertions)]\nmacro_rules! mydbg {\n //($arg:expr) => (dbg!($arg))\n //($arg:expr) => (println!(\"{:?}\",$arg));\n ($($a:expr),*) => {\n eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n#[cfg(not(debug_assertions))]\nmacro_rules! mydbg {\n ($($arg:expr),*) => {};\n}\n\nmacro_rules! echo {\n ($($a:expr),*) => {\n $(println!(\"{}\",$a))*\n }\n}\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::ops::{Add, Div, Mul, Sub};\n\n#[allow(dead_code)]\nstatic INF_I64: i64 = i64::max_value() / 2;\n#[allow(dead_code)]\nstatic INF_I32: i32 = i32::max_value() / 2;\n#[allow(dead_code)]\nstatic INF_USIZE: usize = usize::max_value() / 2;\n#[allow(dead_code)]\nstatic M_O_D: usize = 1000000007;\n#[allow(dead_code)]\nstatic PAI: f64 = 3.1415926535897932;\n\ntrait IteratorExt: Iterator {\n fn toVec(self) -> Vec;\n}\n\nimpl IteratorExt for T {\n fn toVec(self) -> Vec {\n self.collect()\n }\n}\n\ntrait CharExt {\n fn toNum(&self) -> usize;\n fn toAlphabetIndex(&self) -> usize;\n fn toNumIndex(&self) -> usize;\n}\nimpl CharExt for char {\n fn toNum(&self) -> usize {\n return *self as usize;\n }\n fn toAlphabetIndex(&self) -> usize {\n return self.toNum() - 'a' as usize;\n }\n fn toNumIndex(&self) -> usize {\n return self.toNum() - '0' as usize;\n }\n}\n\ntrait VectorExt {\n fn joinToString(&self, s: &str) -> String;\n}\nimpl VectorExt for Vec {\n fn joinToString(&self, s: &str) -> String {\n return self\n .iter()\n .map(|x| x.to_string())\n .collect::>()\n .join(s);\n }\n}\n\ntrait StringExt {\n fn get_reverse(&self) -> String;\n}\nimpl StringExt for String {\n fn get_reverse(&self) -> String {\n self.chars().rev().collect::()\n }\n}\n\ntrait UsizeExt {\n fn pow(&self, n: usize) -> usize;\n}\nimpl UsizeExt for usize {\n fn pow(&self, n: usize) -> usize {\n return ((*self as u64).pow(n as u32)) as usize;\n }\n}\n\n#[derive(Debug, Copy, Clone)]\npub struct ModInt {\n x: i64,\n global_mod: i64,\n}\nimpl ModInt {\n pub fn new(p: i64) -> Self {\n let gm = 998244353;\n let a = (p % gm + gm) % gm;\n return ModInt {\n x: a,\n global_mod: gm,\n };\n }\n pub fn inv(self) -> Self {\n return self.pow(self.global_mod - 2);\n }\n pub fn pow(self, t: i64) -> Self {\n if (t == 0) {\n return ModInt::new(1);\n };\n let mut a = self.pow(t >> 1);\n a = a * a;\n if (t & 1 != 0) {\n a = a * self\n };\n return a;\n }\n}\nimpl Add for ModInt {\n type Output = ModInt;\n fn add(self, other: ModInt) -> ModInt {\n let ret = self.x + other.x;\n return ModInt::new(ret);\n }\n}\nimpl Sub for ModInt {\n type Output = ModInt;\n fn sub(self, other: ModInt) -> ModInt {\n let ret = self.x - other.x;\n return ModInt::new(ret);\n }\n}\nimpl Mul for ModInt {\n type Output = ModInt;\n fn mul(self, other: ModInt) -> ModInt {\n let ret = self.x * other.x;\n return ModInt::new(ret);\n }\n}\nimpl Div for ModInt {\n type Output = ModInt;\n fn div(self, other: ModInt) -> ModInt {\n let ret = self.x * other.inv().x;\n return ModInt::new(ret);\n }\n}\nimpl std::string::ToString for ModInt {\n fn to_string(&self) -> String {\n return self.x.to_string();\n }\n}\npub struct Combination {\n fact: Vec,\n ifact: Vec,\n}\nimpl Combination {\n pub fn new(n: i32) -> Self {\n if n > 3000000 {\n panic!(\"error\");\n }\n let mut fact = vec![ModInt::new(0); (n + 1) as usize];\n let mut ifact = vec![ModInt::new(0); (n + 1) as usize];\n fact[0] = ModInt::new(1);\n for i in 1..n + 1 {\n fact[i as usize] = fact[(i - 1) as usize] * ModInt::new(i as i64)\n }\n ifact[n as usize] = fact[n as usize].inv();\n for i in (1..n + 1).rev() {\n ifact[(i - 1) as usize] = ifact[i as usize] * ModInt::new(i as i64)\n }\n let a = Combination {\n fact: fact,\n ifact: ifact,\n };\n return a;\n }\n #[macro_use]\n pub fn gen(&mut self, n: i32, k: i32) -> ModInt {\n if (k < 0 || k > n) {\n return ModInt::new(0 as i64);\n };\n return self.fact[n as usize] * self.ifact[k as usize] * self.ifact[(n - k) as usize];\n }\n pub fn P(&mut self, n: i32, k: i32) -> ModInt {\n self.fact[n as usize] * self.ifact[(n - k) as usize]\n }\n}\n\nfn main() {\n let N = get!(usize);\n\n let mut dp = vec![ModInt::new(0); N + 10];\n\n dp[0] = ModInt::new(1);\n\n let mut e = vec![ModInt::new(0); N + 2];\n let mut o = vec![ModInt::new(0); N + 2];\n\n for i in 0..N + 1 {\n if i % 2 == 0 {\n dp[i] = dp[i] + o[i];\n e[i + 1] = e[i] + dp[i];\n o[i + 1] = o[i];\n } else {\n dp[i] = dp[i] + e[i];\n o[i + 1] = o[i] + dp[i];\n e[i + 1] = e[i];\n }\n }\n\n mydbg!(dp[N]);\n let mut ans = ModInt::new(1) / ModInt::new(2).pow(N as i64);\n ans = ans * dp[N];\n echo!(ans.to_string());\n}\n", "src_uid": "cec37432956bb0a1ce62a0188fe2d805"} {"source_code": "fn read_ints() -> Vec {\n let mut ln = String::new();\n std::io::stdin().read_line(&mut ln).expect(\"\");\n ln.split_whitespace().filter_map(|w| w.parse().ok()).collect()\n}\n\nfn gcd(x: i32, y: i32) -> i32 {\n if y == 0 { x } else { gcd(y, x % y) }\n}\n\nfn main() {\n let (mut l, mut r, mut x, mut y) = (0, 0, 0, 0);\n if let [_l, _r, _x, _y] = read_ints()[..] { l = _l; r = _r; x = _x; y = _y; }\n\n if y % x != 0 {\n println!(0);\n return;\n }\n l = (l + x - 1) / x;\n r /= x;\n y /= x;\n\n let mut ans = 0i64;\n for i in 1..=(y as f64).sqrt() as i32 {\n if y % i == 0 && gcd(i, y / i) == 1 &&\n i >= l && i <= r &&\n y / i >= l && y / i <= r\n {\n ans += 2 - (i * i == y) as i64;\n }\n }\n println!(\"{}\", ans);\n}\n", "src_uid": "d37dde5841116352c9b37538631d0b15"} {"source_code": "macro_rules! parse_line {\n ($t: ty) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let a_str = a_str.trim();\n a_str.parse::<$t>().expect(\"parse error\")\n });\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().expect(\"parse error\"),\n )+\n )\n })\n}\n\nmacro_rules! parse_line_to_vec {\n ($t: ty) => {{\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n (a_str\n .split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect::>())\n }};\n}\n\nfn solve_part(v: &Vec<(usize, i64)>) -> Option {\n let diff = v[1].1 - v[0].1;\n let mut was_skipped = false;\n let mut skipped_id = v[0].0;\n let mut last = v[0].1 - diff;\n for (_, (pos, x)) in v.iter().enumerate() {\n if last + diff != *x {\n if was_skipped {\n return None;\n }\n was_skipped = true;\n skipped_id = *pos;\n continue;\n }\n last = *x;\n }\n Some(skipped_id as i64 + 1)\n}\n\nfn solve() {\n let s: Vec<_> = parse_line!(String).bytes().collect();\n let n = parse_line!(usize);\n let mut same = false;\n let mut first = false;\n let mut second = false;\n for _ in 0..n {\n let q: Vec<_> = parse_line!(String).bytes().collect();\n same |= s[0] == q[0] && s[1] == q[1];\n first |= s[0] == q[1];\n second |= s[1] == q[0];\n }\n println!(\"{}\", if same || (first && second) {\"YES\"} else {\"NO\"})\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n", "src_uid": "cad8283914da16bc41680857bd20fe9f"} {"source_code": "// Practice Codeforces\n// author: Leonardone @ NEETSDKASU\n\n// \u89e3\u8aac\u8aad\u5f8c\n\nfn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(\n &mut std::io::stdin(),\n &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(i64));\n }\n \n let n = get!();\n let m = get!(usize);\n \n if n < -2000 {\n let ans = brute_force(n, m as i64);\n println!(\"{}\", ans);\n }\n \n let mut xs = vec![0; m];\n \n for i in 0..m {\n let mut c = n / m as i64;\n if i as i64 <= n % m as i64 {\n c += 1;\n }\n xs[i] += c;\n }\n xs[0] -= 1;\n // println!(\"{:?}\", xs);\n let mut ans = 0;\n let c = n / m as i64;\n for i in 0..xs.len() {\n for j in 0..xs.len() {\n let k = (i*i+j*j) % m;\n if k == 0 {\n ans += xs[i] * xs[j];\n }\n }\n }\n\n println!(\"{}\", ans);\n}\n\nfn gcd(a: i64, b: i64) -> i64 {\n fn _gcd(a: i64, b: i64) -> i64 {\n if a == 0 { b } else { _gcd(b % a, a) }\n }\n let a = a.abs();\n let b = b.abs();\n if a < b { _gcd(a, b) } else { _gcd(b, a) }\n}\n\nfn brute_force(n: i64, m: i64) -> i64 {\n let mut ret = 0;\n for i in 1..=n {\n for j in 1..=n {\n let k = i * i + j * j;\n if k % m == 0 {\n ret += 1;\n }\n }\n }\n ret\n}\n", "src_uid": "2ec9e7cddc634d7830575e14363a4657"} {"source_code": "use std::io;\nuse std::io::prelude::*;\n\nconst PRIMES: [u128; 8] = [2, 3, 5, 7, 11, 13, 17, 19];\nconst WEIGHTS: [u128; 9] = [\n 2 * 7 * 17,\n 2 * 11,\n 2 * 13 * 19,\n 7 * 3,\n 11 * 3 * 19 * 17,\n 3 * 13,\n 5 * 7 * 19,\n 5 * 11,\n 5 * 13 * 17,\n];\n\nfn count_powers_of(x: u128, y: u128) -> u128 {\n let mut x = x;\n let mut n = 0;\n while x != 0 && x % y == 0 {\n n += 1;\n x /= y;\n }\n n\n}\n\nfn ix(c: char) -> usize {\n match c {\n 'X' => 1,\n _ => 0,\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let lines = stdin.lock().lines();\n let board = lines.map(|r| r.unwrap()).take(3).collect::();\n let mut count = vec![0, 0];\n let mut prod = vec![1u128, 1];\n let mut wins = vec![0, 0];\n for (i, c) in board.chars().enumerate().filter(|p| p.1 != '.') {\n count[ix(c)] += 1;\n prod[ix(c)] *= WEIGHTS[i];\n }\n for i in 0..2 {\n for p in PRIMES.iter() {\n if count_powers_of(prod[i], *p) == 3 {\n wins[i] += 1;\n }\n }\n }\n if count[0] != count[1] && count[0] != count[1] - 1\n || wins[0] > 2\n || wins[1] > 2\n || wins[0] * wins[1] != 0\n || wins[0] > 0 && count[0] != count[1]\n || wins[1] > 0 && count[0] != count[1] - 1\n {\n println!(\"illegal\");\n } else if count[0] == 4 && count[1] == 5 && wins[0] + wins[1] == 0 {\n println!(\"draw\");\n } else if wins[0] > 0 {\n println!(\"the second player won\");\n } else if wins[1] > 0 {\n println!(\"the first player won\");\n } else if count[0] == count[1] {\n println!(\"first\");\n } else {\n println!(\"second\");\n }\n}\n", "src_uid": "892680e26369325fb00d15543a96192c"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan { buffer: std::collections::VecDeque::new() }\n }\n\n fn next(&mut self)-> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n1: usize = scan.next();\n let n2: usize = scan.next();\n let _k1: usize = scan.next();\n let _k2: usize = scan.next();\n println!(\"{}\", if n2>=n1 {\"Second\"} else {\"First\"});\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "src_uid": "aed24ebab3ed9fd1741eea8e4200f86b"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap,HashSet,VecDeque};\n\n#[allow(unused_macros)]\nmacro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn main() {\n let s = String::from(\"a\") + readln!().as_ref();\n let ans = s.chars().zip(s.chars().skip(1)).map(|(x,y)|{ min((x as u8 + 26 - y as u8) % 26, (y as u8 + 26 - x as u8) % 26) as i32 } ).sum::();\n println!(\"{}\",ans);\n}\n", "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"source_code": "fn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get { () => (get().parse().unwrap()) }\n \n let k: u64 = get!();\n let p: u64 = get!();\n let mut ans: u64 = 0;\n for i in 1..k+1 {\n let mut x = i;\n let mut y = i;\n let mut r = 0;\n while x > 0 {\n r = r * 10 + x % 10;\n x /= 10;\n y *= 10;\n }\n ans = (y + r + ans) % p;\n }\n println!(\"{}\", ans);\n}\n", "src_uid": "00e90909a77ce9e22bb7cbf1285b0609"} {"source_code": "// CodeForces 414b Rust Solution\n// (from CF 414b Solution with ruby)\n\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut line = String::new();\n let modulo = 1_000_000_000 + 7;\n if let Ok(_) = stdin.read_line(&mut line) {\n let words = line.split_whitespace();\n let parsed: Vec = words.map( |s| s.parse::().unwrap() ).collect();\n let n = parsed[0];\n let k = parsed[1];\n let mut dp:Vec> = vec![vec![0; n + 1usize]; k + 1usize];\n \n for j in 1..=n {\n dp[1][j] = 1;\n }\n \n for i in 2..=k {\n for j in 1..=n {\n let mut l = j;\n while l <= n {\n dp[i][l] = (dp[i][l] + dp[i-1][j])%modulo;\n l += j;\n }\n }\n }\n\n //println!(\"{:?}\", dp);\n let mut sum: i64 = 0i64;\n for value in &dp[k] {\n sum = (sum + value)%modulo;\n }\n\n println!(\"{}\", sum);\n }\n}\n\n// # coding: utf-8\n// # Good sequence\uc758 \uae38\uc774\ub294 k, \uc22b\uc790 \uc81c\ud55c\uc740 n\uae4c\uc9c0\n// # 1\ubd80\ud130 n\uae4c\uc9c0 \uac10\uc18c \uc5c6\ub294 \ubc29\ud5a5\uc73c\ub85c (\uc99d\uac00 or \uac19\uc74c)\uc73c\ub85c \ub9cc\ub4e4\uc5b4\uc9c0\ub294 Good seq\uc758 \uc218\n// # Good seq\uc5d0\uc11c\ub294 \uc774\uc804 \uc22b\uc790\uac00 \ub2e4\uc74c\uc22b\uc790\ub97c \ub098\ub220\ub3c4 \uc798 \ub5a8\uc5b4\uc9c4\ub2e4\n// # \ubb38\uc81c \uc774\ud574\ub97c \uc81c\ub300\ub85c \ud558\uace0 \uc2dc\uc791\ud569\uc2dc\ub2e4.\n// # \uc5ec\uae30\ub294 1\ub85c \ub05d\ub098\ub3c4 \ub418\uace0 2\ub85c \ub05d\ub098\ub3c4 \ub418\uace0 n\uc73c\ub85c \ub05d\ub098\ub3c4 \ub428\n// # \uc989 \ubc14\ub2e5\ubd80\ud130 \ubaa8\ub4e0 \uacbd\uc6b0\uac00 \ub098\uc640\uc57c\ud55c\ub2e4.\n// # n = 3, k = 3 \uc5d0\uc11c \ud55c\ubc88 \ud2b8\ub9ac \ubd84\uae30\ub97c \ubd10\ubcf4\uba74\n// # R\n// # 1 2 3\n// # 1 2 3 2 3\n// # \uaf34\ub85c \ubc18\ubcf5 \ub41c\ub2e4. \uc774 \ud574\ubc95\uc740 CF 414b\uc758 \uae30\uc874 \uc815\ub2f5\uacfc\ub3c4 \ub3d9\uc77c\ud568\n// # (1,1) (1,2), (1,3) (2,2), (3,3) total 5 tuples.\n// # \uc774 \uac1c\uc218\ub294 tree\uc758 k depth\uc5d0\uc11c\uc758 child \uc218\ub97c \uad6c\ud558\ub294 \uac83\uacfc \ub3d9\uc77c\ud558\ub2e4.\n// # child\uc5d0\uc11c 1 2 3 \uc774 \uac01\uac01 \uba87\ud68c \ub098\uc624\ub294\uc9c0 \uce74\uc6b4\ud2b8 \ud55c\ub2e4\uba74 \ucda9\ubd84\ud560 \uac83 \uac19\uc74c\n// #\n// # \uc544 \uadfc\ub370 \uc790\uafb8 \ud0c0\uc784\uc544\uc6c3\ub098\uc11c \ub488\uc9c8 \uac83 \uac19\ub124\uc5ec\n\n// # << \uc774 \ubb38\uc81c\ub294 Ruby\uc758 \ud37c\ud3ec\uba3c\uc2a4 \ubb38\uc81c\ub85c \uc77c\ub2e8 \uc81c\ucd9c \uc911\ub2e8\ud569\ub2c8\ub2e4. >>\n\n// n, k = gets.split.map(&:to_i)\n// MODULO_BASE = 10 ** 9 + 7\n// dpcounters = []\n// init = Array.new(n + 1) { 1 } # k = 1\uc5d0\uc11c\ub294 \uac01 \ud558\ub098\uc529\n// init[0] = 0 # \ub2f9\uc5f0\ud788 0\uc774\uc8e0\n// dpcounters << init\n\n// for a in 2..k\n// sub_dpcounter = Array.new(n + 1) { 0 }\n// for b in 1..n\n// c = b\n// while c <= n\n// sub_dpcounter[c] = (sub_dpcounter[c] + dpcounters.last[b]) % MODULO_BASE\n// c += b\n// end\n// end\n// dpcounters << sub_dpcounter\n// end\n\n// puts dpcounters.last.inject { |sum, n| (sum + n) % MODULO_BASE }\n", "src_uid": "c8cbd155d9f20563d37537ef68dde5aa"} {"source_code": "// ---------- begin ModInt ----------\nconst MOD: u32 = 998_244_353;\n\n#[derive(Clone, Copy)]\nstruct ModInt(u32);\n\nimpl std::ops::Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::AddAssign for ModInt {\n fn add_assign(&mut self, rhs: ModInt) {\n *self = *self + rhs;\n }\n}\n\nimpl std::ops::Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + MOD - rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: ModInt) {\n *self = *self - rhs;\n }\n}\n\nimpl std::ops::Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: ModInt) -> Self::Output {\n ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)\n }\n}\n\nimpl std::ops::MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: ModInt) {\n *self = *self * rhs;\n }\n}\n\nimpl std::ops::Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n ModInt(if self.0 == 0 {0} else {MOD - self.0})\n }\n}\n\nimpl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n\nimpl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n}\n\n#[allow(dead_code)]\nimpl ModInt {\n pub fn new(n: u32) -> ModInt {\n ModInt(n % MOD)\n }\n pub fn zero() -> ModInt {\n ModInt(0)\n }\n pub fn one() -> ModInt {\n ModInt(1)\n }\n pub fn pow(self, mut n: u32) -> ModInt {\n let mut t = ModInt::one();\n let mut s = self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(self) -> ModInt {\n assert!(self.0 > 0);\n self.pow(MOD - 2)\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\n#[allow(dead_code)]\nstruct Precalc {\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n}\n\n#[allow(dead_code)]\nimpl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);\n fact[i] = fact[i - 1] * ModInt(i as u32);\n ifact[i] = ifact[i - 1] * inv[i];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n}\n// ---------- end Precalc ----------\n// ---------- begin Matrix ----------\n#[allow(dead_code)]\nmod matrix {\n use std::ops::{Add, Mul};\n pub trait SemiRing: Add + Mul + Copy {\n fn zero() -> Self;\n fn one() -> Self;\n }\n pub const SIZE: usize = 2;\n #[derive(Clone)]\n pub struct SquareMatrix {\n buf: [[T; SIZE]; SIZE],\n }\n impl SquareMatrix {\n pub fn zero() -> Self {\n let z = T::zero();\n SquareMatrix {\n buf: [[z; SIZE]; SIZE],\n }\n }\n pub fn identity() -> Self {\n let mut m = Self::zero();\n for i in 0..SIZE {\n m.buf[i][i] = T::one();\n }\n m\n }\n pub fn set_at(&mut self, i: usize, j: usize, v: T) {\n self.buf[i][j] = v;\n }\n pub fn get_at(&self, i: usize, j: usize) -> T {\n self.buf[i][j]\n }\n pub fn matmul(&self, rhs: &Self) -> Self {\n let mut res = Self::zero();\n for (x, a) in res.buf.iter_mut().zip(self.buf.iter()) {\n for (a, b) in a.iter().zip(rhs.buf.iter()) {\n for (x, b) in x.iter_mut().zip(b.iter()) {\n *x = *x + *a * *b;\n }\n }\n }\n res\n }\n pub fn matadd(&self, rhs: &Self) -> Self {\n let mut c = Self::zero();\n for (c, (a, b)) in c.buf.iter_mut().zip(self.buf.iter().zip(rhs.buf.iter())) {\n for (c, (a, b)) in c.iter_mut().zip(a.iter().zip(b.iter())) {\n *c = *a + *b;\n }\n }\n c\n }\n pub fn matpow(&self, mut n: usize) -> Self {\n let mut t = Self::identity();\n let mut s = self.clone();\n while n > 0 {\n if n & 1 == 1 {\n t = t.matmul(&s);\n }\n s = s.matmul(&s);\n n >>= 1;\n }\n t\n }\n }\n}\n// ---------- end Matrix ----------\n//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nuse matrix::*;\nuse std::io::Write;\n\nimpl SemiRing for ModInt {\n fn zero() -> Self {\n ModInt::zero()\n }\n fn one() -> Self {\n ModInt::one()\n }\n}\n\nfn run() {\n input! {\n h: usize,\n w: usize,\n l: u32,\n r: u32,\n }\n let d = r - l + 1;\n let x = ModInt(d / 2);\n let y = ModInt(d) - x;\n let mut mat = SquareMatrix::::zero();\n mat.set_at(0, 0, y);\n mat.set_at(1, 1, y);\n mat.set_at(0, 1, x);\n mat.set_at(1, 0, x);\n let p = mat.matpow(h);\n let q = p.matpow(w);\n let a = q.get_at(0, 0);\n let b = q.get_at(1, 0);\n let mut ans = a;\n if h % 2 == 1 && w % 2 == 1 {\n ans += b;\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "ded299fa1cd010822c60f2389a3ba1a3"} {"source_code": "fn main() {\n use std::io::prelude::*;\n use std::io;\n\n let mut input = String::new();\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let k: i32 = it.next().unwrap().parse().unwrap();\n let n: i32 = it.next().unwrap().parse().unwrap();\n let s: i32 = it.next().unwrap().parse().unwrap();\n let p: i32 = it.next().unwrap().parse().unwrap();\n\n // For one person:\n // s * (ans - 1) < n <= s * ans\n // 0 < n - s * (ans - 1) <= s\n // 0 <= n - s * (ans - 1) - 1 < s\n // 0 <= n - 1 - s * (ans - 1) < s\n // ans - 1 = (n - 1) / s\n // ans = (n - 1) / s + 1\n let sn = (n - 1) / s + 1;\n // p * (ans - 1) < k * sn <= p * ans\n // 0 < k * sn - p * (ans - 1) <= p\n // 0 <= k * sn - 1 - p * (ans - 1) < p\n // ans - 1 = (k * sn - 1) / p\n let ans = (k * sn - 1) / p + 1;\n println!(\"{}\", ans);\n}\n", "src_uid": "73f0c7cfc06a9b04e4766d6aa61fc780"} {"source_code": "use std::io;\nuse std::io::prelude::*;\nfn main() {\n let mut score = String::new();\n io::stdin().read_line(&mut score).expect(\"Error\");\n if score.contains(\"1111111\") || score.contains(\"0000000\"){\n println!(\"YES\");\n }\n else{\n println!(\"NO\");\n }\n}\n", "src_uid": "ed9a763362abc6ed40356731f1036b38"} {"source_code": "struct FenwickTree {\n val: Vec,\n}\n\nimpl FenwickTree {\n fn new(n: usize) -> Self {\n FenwickTree {\n val: vec![0; n + 1],\n }\n }\n fn add(&mut self, mut x: usize, v: i64) {\n while let Some(p) = self.val.get_mut(x) {\n *p += v;\n x += x & (!x + 1);\n }\n }\n fn sum(&mut self, mut x: usize) -> i64 {\n assert!(x < self.val.len());\n let mut ans = 0;\n while x > 0 {\n ans += self.val[x];\n x -= x & (!x + 1);\n }\n ans\n }\n}\n\nfn sieve(n: usize) -> Vec {\n let mut is_prime = vec![true; n + 1];\n for i in 2.. {\n if i * i > n {\n break;\n }\n if is_prime[i] {\n let mut j = i * i;\n while j <= n {\n is_prime[j] = false;\n j += i;\n }\n }\n }\n let len = is_prime.iter().skip(2).filter(|p| **p).count();\n let mut prime = Vec::with_capacity(len);\n for (i, is_prime) in is_prime.into_iter().enumerate().skip(2) {\n if is_prime {\n prime.push(i as i64);\n }\n }\n prime\n}\n\nstruct PrimeCountSolver {\n query: Vec,\n memo: Vec,\n}\n\nimpl PrimeCountSolver {\n fn new() -> Self {\n PrimeCountSolver {\n query: vec![],\n memo: vec![],\n }\n }\n fn add(&mut self, n: i64) {\n self.query.push(n);\n }\n fn build(&mut self) {\n self.query.sort();\n self.query.dedup();\n let n = self.query.last().map_or(1, |n| *n);\n let mut m = 1;\n while (m + 1) * (m + 1) <= n {\n m += 1;\n }\n let p = sieve(m as usize);\n let bound = (n as f64).cbrt().powi(2) as i64 + 2;\n let mut stack = vec![];\n for &v in self.query.iter() {\n let k = match p.binary_search_by(|&p| (p * p).cmp(&v)) {\n Ok(k) => k + 1,\n Err(k) => k,\n };\n stack.push((v, k));\n }\n let mut query = vec![];\n while let Some((n, k)) = stack.pop() {\n if k == 0 {\n continue;\n }\n let q = p[k - 1];\n if q * q > n {\n let x = match p[..k].binary_search_by(|&p| (p * p).cmp(&n)) {\n Ok(k) => k + 1,\n Err(k) => k,\n };\n stack.push((n, x));\n } else if n <= bound {\n query.push((k, n));\n } else {\n stack.push((n, k - 1));\n stack.push((n / q, k - 1));\n }\n }\n query.sort();\n query.dedup();\n let m = bound as usize;\n let mut bit = FenwickTree::new(m);\n for i in 1..=m {\n bit.add(i, 1);\n }\n let mut is_prime = vec![true; m + 1];\n let mut memo = vec![0; query.len()];\n let mut pos = 0;\n for (i, p) in p.iter().enumerate() {\n let p = *p as usize;\n let mut j = p;\n while j <= m {\n if is_prime[j] {\n bit.add(j, -1);\n }\n is_prime[j] = false;\n j += p;\n }\n while let Some(&(k, n)) = query.get(pos) {\n if k > i + 1 {\n break;\n } else {\n memo[pos] = bit.sum(n as usize);\n pos += 1;\n }\n }\n if pos >= query.len() {\n break;\n }\n }\n self.memo.clear();\n self.memo.resize(self.query.len(), 0);\n let mut stack = vec![];\n for (i, &n) in self.query.iter().enumerate() {\n let k = match p.binary_search_by(|&p| (p * p).cmp(&n)) {\n Ok(k) => k + 1,\n Err(k) => k,\n };\n self.memo[i] += k as i64 - 1;\n stack.push((n, k, 1, i));\n }\n while let Some((n, k, sign, i)) = stack.pop() {\n if k == 0 {\n self.memo[i] += sign * n;\n continue;\n }\n let q = p[k - 1];\n if q * q > n {\n let x = match p[..k].binary_search_by(|p| (p * p).cmp(&n)) {\n Ok(k) => k + 1,\n Err(k) => k,\n };\n self.memo[i] += -sign * (k - x) as i64;\n stack.push((n, x, sign, i));\n } else if n <= bound {\n self.memo[i] += sign * memo[query.binary_search(&(k, n)).unwrap()];\n } else {\n stack.push((n, k - 1, sign, i));\n stack.push((n / q, k - 1, -sign, i));\n }\n }\n }\n fn get(&self, n: i64) -> i64 {\n self.memo[self.query.binary_search(&n).unwrap()]\n }\n}\n\nfn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n: i64 = s.trim().parse().unwrap();\n let p = sieve((n as f64).sqrt() as usize + 2);\n let mut ans = 0i64;\n for p in p.iter() {\n if p.pow(3) <= n {\n ans += 1;\n } else {\n break;\n }\n }\n let mut solver = PrimeCountSolver::new();\n for (i, p) in p.iter().enumerate() {\n if p.pow(2) <= n {\n ans -= i as i64 + 1;\n solver.add(n / *p);\n }\n }\n solver.build();\n for p in p.iter() {\n if p.pow(2) <= n {\n ans += solver.get(n / *p);\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "ffb7762f1d60dc3f16e9b27ea0ecdd7d"} {"source_code": "use std::io;\n\nfn main() {\n let mut n = String::new();\n io::stdin().read_line(&mut n).unwrap();\n let n: u16 = n.trim().parse().unwrap();\n\n if n % 4 == 0 {\n println!(\"YES\");\n } else if n % 7 == 0 {\n println!(\"YES\");\n } else if n % 44 == 0 {\n println!(\"YES\");\n } else if n % 47 == 0 {\n println!(\"YES\");\n } else if n % 74 == 0 {\n println!(\"YES\");\n } else if n % 77 == 0 {\n println!(\"YES\");\n } else if n % 444 == 0 {\n println!(\"YES\");\n } else if n % 447 == 0 {\n println!(\"YES\");\n } else if n % 474 == 0 {\n println!(\"YES\");\n } else if n % 477 == 0 {\n println!(\"YES\");\n } else if n % 744 == 0 {\n println!(\"YES\");\n } else if n % 747 == 0 {\n println!(\"YES\");\n } else if n % 774 == 0 {\n println!(\"YES\");\n } else if n % 777 == 0 {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n\n\n", "src_uid": "78cf8bc7660dbd0602bf6e499bc6bb0d"} {"source_code": "fn main() {\n let mut sin = ReadIn::new();\n let a = sin.intvec();\n let s: i32 = a.iter().sum();\n let x = (0..64).any(|b| if count(b) != 3 { false } else {\n (0..6)\n .filter_map(|i| if b & (1 << i) != 0 { Some(a[i as usize]) } else { None })\n .sum::() * 2 == s\n });\n println!(\"{}\", if x {\"YES\"} else {\"NO\"});\n}\n\nfn count(i: i32) -> i32 {\n if i == 0 { 0 } else { 1 + count(i & (i - 1)) }\n}\n\nuse std::iter::*;\nuse std::str::SplitWhitespace;\nuse std::io::stdin;\nuse std::mem::forget;\n\npub struct ReadIn(pub String);\n\nimpl ReadIn {\n pub fn new() -> ReadIn { ReadIn(String::new()) }\n fn read_i32(s: &str) -> i32 { s.parse().unwrap() }\n pub fn read_line(&mut self) {\n self.0.clear();\n forget(stdin().read_line(&mut self.0));\n }\n pub fn ints(&mut self) -> Map i32> {\n self.read_line();\n self.0.split_whitespace().map(ReadIn::read_i32)\n }\n pub fn intvec(&mut self) -> Vec { self.ints().collect() }\n pub fn int(&mut self) -> i32 { self.ints().next().unwrap() }\n pub fn int2(&mut self) -> (i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap())\n }\n\n pub fn int3(&mut self) -> (i32, i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap(), it.next().unwrap())\n }\n pub fn int4(&mut self) -> (i32, i32, i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap(), it.next().unwrap(), it.next().unwrap())\n }\n}", "src_uid": "2acf686862a34c337d1d2cbc0ac3fd11"} {"source_code": "#![allow(unused_imports)]\nuse std::io::{ self, Write };\nuse std::str::FromStr;\nuse std::cmp::{ min, max };\nuse std::collections::{ BinaryHeap, VecDeque };\n\n#[allow(unused_macros)]\nmacro_rules! trace {\n ($var:expr) => {\n let _ = writeln!(&mut std::io::stderr(), \">>> {} = {:?}\", stringify!($var), $var);\n };\n ($($args:expr),*) => {\n let _ = writeln!(&mut std::io::stderr(), \">>> {} = {:?}\", stringify!($($args),*), ($($args),*));\n };\n}\n\nconst M: usize = 1_000_000_007;\n\nfn main() {\n let mut sc = Scanner::new();\n let l: u64 = sc.cin();\n let r: u64 = sc.cin();\n let x: u64 = sc.cin();\n let y: u64 = sc.cin();\n let k: u64 = sc.cin();\n\n for b in x..(y + 1) {\n let a = k * b;\n if l <= a && a <= r {\n println!(\"YES\");\n return;\n }\n }\n println!(\"NO\");\n}\n\n#[allow(dead_code)]\nstruct Scanner { stdin: io::Stdin, buffer: VecDeque, }\n#[allow(dead_code)]\nimpl Scanner {\n fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }\n fn reserve(&mut self) {\n while self.buffer.len() == 0 {\n let mut line = String::new();\n let _ = self.stdin.read_line(&mut line);\n for w in line.split_whitespace() {\n self.buffer.push_back(String::from(w));\n }\n }\n }\n fn cin(&mut self) -> T {\n self.reserve();\n match self.buffer.pop_front().unwrap().parse::() {\n Ok(a) => a,\n Err(_) => panic!(\"parse err\")\n }\n }\n fn get_char(&mut self) -> char {\n self.reserve();\n let head = self.buffer[0].chars().nth(0).unwrap();\n let tail = String::from( &self.buffer[0][1..] );\n if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }\n head\n }\n}\n", "src_uid": "1110d3671e9f77fd8d66dca6e74d2048"} {"source_code": "//================================================================================\n#[allow(unused_imports)] use std::cmp::{max, min, Ordering};\n#[allow(unused_imports)] use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)] use std::iter::FromIterator;\nuse std::io::Write;\nstatic mut GLOBAL_STDIN: *mut std::io::Stdin = 0usize as _;\nstatic mut GLOBAL_STDINLOCK: *mut std::io::StdinLock<'static> = 0usize as _;\nstatic mut GLOBAL_STDOUT: *mut std::io::Stdout = 0usize as _;\nstatic mut GLOBAL_STDOUTLOCK: *mut std::io::StdoutLock<'static> = 0usize as _;\nconst BUF_SIZE: usize = 1024*1024;\nstatic mut GLOBAL_INPUT_BUF: *mut u8 = 0usize as _;\nstatic mut GLOBAL_INPUT_PTR: *const u8 = 0usize as _;\nstatic mut GLOBAL_INPUT_END: *const u8 = 0usize as _;\nfn init() {\n unsafe {\n use std::boxed::Box;\n GLOBAL_STDIN = Box::into_raw(Box::new(std::io::stdin()));\n GLOBAL_STDINLOCK = Box::into_raw(Box::new(GLOBAL_STDIN.as_ref().unwrap().lock()));\n GLOBAL_STDOUT = Box::into_raw(Box::new(std::io::stdout()));\n GLOBAL_STDOUTLOCK = Box::into_raw(Box::new(GLOBAL_STDOUT.as_mut().unwrap().lock()));\n let buf = Box::<[u8]>::into_raw(vec![0u8; BUF_SIZE].into_boxed_slice());\n GLOBAL_INPUT_BUF = (*buf).as_mut_ptr();\n GLOBAL_INPUT_PTR = GLOBAL_INPUT_BUF;\n GLOBAL_INPUT_END = GLOBAL_INPUT_BUF;\n }\n}\nfn peek() -> u8 { unsafe {\n use std::io::Read;\n if GLOBAL_INPUT_PTR == GLOBAL_INPUT_END {\n let n = GLOBAL_STDINLOCK.as_mut().unwrap().read(std::slice::from_raw_parts_mut(GLOBAL_INPUT_BUF, BUF_SIZE)).expect(\"I/O error\");\n GLOBAL_INPUT_PTR = GLOBAL_INPUT_BUF;\n GLOBAL_INPUT_END = GLOBAL_INPUT_PTR.offset(n as isize);\n }\n *GLOBAL_INPUT_PTR\n} }\nfn getchar() -> u8 { let c = peek(); unsafe { GLOBAL_INPUT_PTR = GLOBAL_INPUT_PTR.offset(1); } c }\nfn ungetc() { unsafe { GLOBAL_INPUT_PTR = GLOBAL_INPUT_PTR.offset(-1); } }\nfn skip_whitespaces() { loop { match getchar() as char { ' ' | '\\t' | '\\n' | '\\r' => { }, _ => { ungetc(); break; } } } }\ntrait FastRead { fn read() -> Self; }\nmacro_rules! read_int_impl {\n ( $signed:expr, $($T:ident,)* ) => {\n $(impl FastRead for $T {\n fn read() -> $T {\n skip_whitespaces(); let is_negative = if $signed && peek() == '-' as u8 { getchar(); true } else { false }; let mut val: $T = 0;\n loop {\n let c = getchar(); let d = c.wrapping_sub('0' as u8);\n if d >= 10 { match c as char {\n ' ' | '\\t' | '\\n' | '\\r' => { ungetc(); return if is_negative { 0-val } else { val }; },\n _ => panic!(\"invalid input character: `{}' (code: {})\", c as char, c),\n }}\n val = 10*val + (d as $T);\n }\n }\n })*\n };\n}\nmacro_rules! read_tuple_impl {\n ( ) => ();\n ( $a:ident, $($name:ident,)* ) => {\n impl<$a:FastRead, $($name:FastRead),*> FastRead for ($a, $($name,)*) { fn read() -> Self { ( $a::read(), $($name::read()),* ) } }\n read_tuple_impl!($($name,)*);\n }\n}\nmacro_rules! snd_arg_impl { ($a:expr; $e:expr) => { $e }; }\nmacro_rules! read_array_impl {\n () => {};\n ($len:expr, $($lens:expr,)*) => {\n impl FastRead for [T; $len] { fn read() -> Self { [ $(snd_arg_impl!($lens; read::())),* ] } }\n read_array_impl!($($lens,)*);\n };\n}\nunsafe fn extend_vec(v: &mut Vec, first: *const u8, last: *const u8) {\n let len = usize::wrapping_sub(last as _, first as _);\n v.extend_from_slice(&std::slice::from_raw_parts(first, len));\n}\nmacro_rules! read_string_inplace {\n ($func:ident, $($pattern:pat)|+) => {\n #[allow(unused)] fn $func(s: &mut String) -> bool {\n skip_whitespaces();\n unsafe { let mut ptr = GLOBAL_INPUT_PTR; let end = GLOBAL_INPUT_END; let v = s.as_mut_vec(); v.clear();\n loop {\n if ptr == end { extend_vec(v, GLOBAL_INPUT_PTR, end); GLOBAL_INPUT_PTR = GLOBAL_INPUT_END; peek(); ptr = GLOBAL_INPUT_PTR; }\n match *ptr as char {\n $($pattern)|+ => { extend_vec(v, GLOBAL_INPUT_PTR, ptr); GLOBAL_INPUT_PTR = ptr; return v.is_empty(); }\n _ => { ptr = ptr.offset(1); }\n }\n }\n }\n }\n };\n}\nread_string_inplace!(getword, ' ' | '\\t' | '\\n' | '\\r');\nread_string_inplace!(getline, '\\n');\n#[allow(unused)] fn read_line() -> String { let mut s = String::new(); getline(&mut s); s }\nimpl FastRead for String { fn read() -> String { let mut s = String::new(); getword(&mut s); s } }\nimpl FastRead for char { fn read() -> char { skip_whitespaces(); getchar() as char } }\nread_int_impl!(false, u8, u16, u32, u64, usize,);\nread_int_impl!(true, i8, i16, i32, i64, isize,);\nread_tuple_impl!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,);\nread_array_impl!(12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,);\n#[allow(dead_code)] fn read() -> T { T::read() }\n#[allow(unused_macros)] macro_rules! print { ($($arg:tt)*) => { write! (unsafe { GLOBAL_STDOUTLOCK.as_mut().unwrap() }, $($arg)*).unwrap() } }\n#[allow(unused_macros)] macro_rules! println { ($($arg:tt)*) => { writeln!(unsafe { GLOBAL_STDOUTLOCK.as_mut().unwrap() }, $($arg)*).unwrap() } }\n#[allow(dead_code)] fn read_vec(n: usize) -> Vec { let mut v = Vec::with_capacity(n); for _ in 0..n { v.push(read()); } v }\n#[allow(dead_code)] fn print_iter, T: std::fmt::Display>(iter: I) { let mut iter = iter; if let Some(x) = iter.next() { print!(\"{}\", x); for x in iter { print!(\" {}\", x); } } println!(\"\"); }\n#[allow(dead_code)] fn print_vec(v: &Vec) { print_iter(v.iter()); }\n#[allow(unused_macros)] macro_rules! debug { ($a:expr, $($b:expr),*) => (if cfg!(debug_assertions) { println!(concat!(\"DEBUG: \", stringify!($a), \" = {:?}\", $(\", \", stringify!($b), \" = {:?}\"),*), $a, $($b),*); } ) }\n//================================================================================\n\nfn main() {\n init();\n let n: u64 = read();\n let mut k=1u64;\n while (1u64< String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"EOF\");\n line.pop();\n return line;\n}\n\nmacro_rules! read_line {\n (Vec<$t: ty>) => {{\n read_line().split_whitespace().map(|token| {\n <$t as std::str::FromStr>::from_str(token).expect(\"Invalid token\")\n }).collect>()\n }};\n ($($t: ty),*) => {{\n let line = read_line();\n let mut iter = line.split_whitespace();\n ($({\n let token = iter.next().expect(\"Too few tokens\");\n <$t as std::str::FromStr>::from_str(token).expect(\"Invalid token\")\n }), *)\n }};\n}\n\nuse std::cmp;\n\nfn main() {\n let (n, k) = read_line!(i32, i32);\n let x = cmp::min(k * 2, n - k);\n let y = if k == 0 { 0 } else { cmp::min(1, n - k) };\n println!(\"{} {}\", y, x);\n}\n", "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"source_code": "fn main() {\n let n: usize = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim_end().parse().unwrap()\n };\n\n let v = {\n let mut v = vec![];\n for _ in 0..n {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut ws = buf.split_whitespace();\n let a: usize = ws.next().unwrap().parse().unwrap();\n let b: usize = ws.next().unwrap().parse().unwrap();\n v.push((a, b));\n }\n v\n };\n\n let mut ans = 0;\n for i in 0..n {\n for j in 0..n {\n if i == j {\n continue;\n }\n if v[i].0 == v[j].1 {\n ans += 1;\n }\n }\n }\n\n println!(\"{}\", ans);\n}\n", "src_uid": "745f81dcb4f23254bf6602f9f389771b"} {"source_code": "use std::io;\n\nfn read() -> u32 {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n let n: u32 = line.trim().parse().unwrap();\n n\n}\n\nfn is_prime(n: u32) -> bool {\n let mut i = 2;\n while i * i <= n {\n if n % i == 0 {\n return false;\n }\n i += 1;\n }\n true\n}\n\nfn main() {\n let n = read();\n for m in 1..1001 {\n if !is_prime(n * m + 1) {\n println!(\"{}\", m);\n break;\n }\n }\n}\n", "src_uid": "5c68e20ac6ecb7c289601ce8351f4e97"} {"source_code": "// https://codeforces.com/contest/1118/problem/D2\n//\n#![allow(unused_imports)]\nuse std::io::*;\nuse std::io::Write;\nuse std::fmt::*;\nuse std::str::*;\nuse std::cmp::*;\nuse std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n\n ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($iter:expr, [ next / $t:tt ]) => {\n {\n let len = read_value!($iter, usize);\n (0..len).map(|_| read_value!($iter, $t)).collect::>()\n }\n };\n\n ($iter:expr, switch) => {\n {\n let ty = read_value!($iter, i32);\n if ty == 1 {\n vec![ty, read_value!($iter, i32), read_value!($iter, i32)]\n } else if ty == 2 {\n vec![ty, read_value!($iter, i32)]\n } else {\n vec![ty, read_value!($iter, i32)]\n }\n }\n };\n\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! dvec {\n ($t:expr ; $len:expr) => {\n vec![$t; $len]\n };\n\n ($t:expr ; $len:expr, $($rest:expr),*) => {\n vec![dvec!($t; $($rest),*); $len]\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! ifv {\n ($t:expr, $a:expr, $b: expr) => {\n if $t { $a } else { $b }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! fill {\n ($t:expr, $v:expr) => {\n for i in 0..$t.len() {\n $t[i] = $v;\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! join {\n ($t:expr, $glue:expr) => {\n $t.into_iter().map(|w| w.to_string()).collect::>().join($glue)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn isok(days: usize, a: &Vec) -> i64 {\n let n = a.len();\n let mut total = 0;\n let mut cup = 0;\n let mut fr = 0;\n while fr < n {\n for i in 0..days {\n if fr == n {\n break;\n }\n total += max(0, a[fr]-cup);\n fr += 1;\n }\n cup += 1;\n }\n total\n}\n\nfn main() {\n input! {\n n: usize, m: i64,\n mut a: [i64; n]\n };\n a.sort();\n a.reverse();\n\n let mut sum = 0;\n for i in 0..n {\n sum += a[i];\n }\n if sum < m {\n println!(\"-1\");\n return;\n }\n\n let mut ng = 0;\n let mut ok = n;\n while ok - ng > 1 {\n let med = (ok + ng) / 2;\n if isok(med, &a) >= m {\n ok = med;\n } else {\n ng = med;\n }\n }\n println!(\"{}\", ok);\n}\n", "src_uid": "acb8a57c8cfdb849a55fa65aff86628d"} {"source_code": "// use rand::Rng;\n\nuse std::collections::*;\nuse std::io;\n\nfn trim_newline(s: &mut String) {\n if s.ends_with('\\n') {\n s.pop();\n if s.ends_with('\\r') {\n s.pop();\n }\n }\n}\nmacro_rules! parse_input {\n ($t:ident) => {{\n let mut input_line = String::new();\n io::stdin().read_line(&mut input_line).unwrap();\n trim_newline(&mut input_line);\n input_line.parse::<$t>().unwrap()\n }};\n}\n\nmacro_rules! split_input {\n ($t:ident) => {{\n parse_input!(String)\n .split(\" \")\n .map(|z| z.parse::<$t>().unwrap())\n .collect::>()\n }};\n}\n\nfn main() {\n let a = split_input!(u64);\n let l = a[1] - a[0] + 1;\n if l < 3 || l == 3 && a[1] & 1 > 0 {\n println!(\"-1\");\n } else {\n let mut s = a[0];\n if s & 1 == 1 {\n s += 1;\n }\n println!(\"{} {} {}\", s, s + 1, s + 2);\n }\n}\n", "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"source_code": "#![allow(unused_parens)]\n#![allow(unused_imports)]\n#![allow(non_upper_case_globals)]\n#![allow(non_snake_case)]\n#![allow(unused_mut)]\n#![allow(unused_variables)]\n#![allow(dead_code)]\n\n#[allow(unused_macros)]\nmacro_rules! invec {\n ( $ t : ty ) => {{\n let mut s = String::new();\n match std::io::stdin().read_line(&mut s) {\n Ok(0) => Vec::<$t>::new(),\n Ok(n) => s\n .trim()\n .split_whitespace()\n .map(|s| s.parse::<$t>().unwrap())\n .collect::>(),\n Err(_) => Vec::<$t>::new(),\n }\n }};\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n ($t:ty ;; $n:expr) => {\n (0..$n).map(|_| get!($t ;;)).collect::>()\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let mut s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($next:expr, [$t:tt]) => {\n {\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\n#[cfg(debug_assertions)]\nmacro_rules! mydbg {\n //($arg:expr) => (dbg!($arg))\n //($arg:expr) => (println!(\"{:?}\",$arg));\n ($($a:expr),*) => {\n eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n#[cfg(not(debug_assertions))]\nmacro_rules! mydbg {\n ($($arg:expr),*) => {};\n}\n\nmacro_rules! echo {\n ($($a:expr),*) => {\n $(println!(\"{}\",$a))*\n }\n}\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::ops::{Add, Div, Mul, Sub};\n\n#[allow(dead_code)]\nstatic INF_I64: i64 = i64::max_value() / 2;\n#[allow(dead_code)]\nstatic INF_I32: i32 = i32::max_value() / 2;\n#[allow(dead_code)]\nstatic INF_USIZE: usize = usize::max_value() / 2;\n#[allow(dead_code)]\nstatic M_O_D: usize = 1000000007;\n#[allow(dead_code)]\nstatic PAI: f64 = 3.1415926535897932;\n\ntrait IteratorExt: Iterator {\n fn toVec(self) -> Vec;\n}\n\nimpl IteratorExt for T {\n fn toVec(self) -> Vec {\n self.collect()\n }\n}\n\ntrait CharExt {\n fn toNum(&self) -> usize;\n fn toAlphabetIndex(&self) -> usize;\n fn toNumIndex(&self) -> usize;\n}\nimpl CharExt for char {\n fn toNum(&self) -> usize {\n return *self as usize;\n }\n fn toAlphabetIndex(&self) -> usize {\n return self.toNum() - 'a' as usize;\n }\n fn toNumIndex(&self) -> usize {\n return self.toNum() - '0' as usize;\n }\n}\n\ntrait VectorExt {\n fn joinToString(&self, s: &str) -> String;\n}\nimpl VectorExt for Vec {\n fn joinToString(&self, s: &str) -> String {\n return self\n .iter()\n .map(|x| x.to_string())\n .collect::>()\n .join(s);\n }\n}\n\ntrait StringExt {\n fn get_reverse(&self) -> String;\n}\nimpl StringExt for String {\n fn get_reverse(&self) -> String {\n self.chars().rev().collect::()\n }\n}\n\ntrait UsizeExt {\n fn pow(&self, n: usize) -> usize;\n}\nimpl UsizeExt for usize {\n fn pow(&self, n: usize) -> usize {\n return ((*self as u64).pow(n as u32)) as usize;\n }\n}\n\nfn main() {\n let (a, b, c) = get!(i64, i64, i64);\n let mut k = vec![];\n for i in 0..100 {\n k.push((b * ((i as i64).pow(a as u32)) + c, i));\n }\n let mut ans = vec![];\n for &(d, e) in &k {\n if d <= 0 {\n continue;\n } else if d > 10_i64.pow(9) {\n continue;\n }\n let f = d\n .to_string()\n .chars()\n .map(|x| x as usize - '0' as usize)\n .fold(0, |a, x| a + x);\n if f == e {\n ans.push(d);\n }\n }\n echo!(ans.len());\n echo!(ans.joinToString(\" \"));\n}\n", "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"source_code": "use std::io;\n\nmacro_rules! except {\n ($result: expr) => {\n match $result {\n Err(e) => panic!(\"{}\", e),\n Ok(m) => m,\n }\n };\n ($result: expr, $msg: expr) => {\n match $result {\n Err(e) => panic!(\"{}: {}\", $msg, e),\n Ok(m) => m,\n }\n };\n}\n\nfn parse_line() -> Vec {\n let mut input = String::new();\n except!(io::stdin().read_line(&mut input));\n input.trim().split_whitespace()\n .map(|x| except!(x.parse::()))\n .collect()\n}\n\n\nfn main() {\n let n = parse_line()[0] as usize;\n let a = parse_line();\n if n > a.len() {\n println!(\"0\");\n return\n }\n let mut counts = a.iter().fold([0u8; 101], |mut v, &x| {v[x as usize] += 1; v});\n counts.sort_unstable_by(|x, y| y.cmp(x));\n let mut nums = vec![0u8; n];\n for _ in 0..n {\n let (index, _) = nums.iter().enumerate()\n .max_by_key(|&(i, v)| counts[i] / (v + 1)).unwrap();\n nums[index] += 1;\n }\n let (index, _) = nums.iter().enumerate().filter(|&(_, v)| *v != 0)\n .min_by_key(|&(i, v)| counts[i] / v).unwrap();\n println!(\"{}\", counts[index] / nums[index]);\n}\n", "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"source_code": "use std::io::{ self, BufRead };\nuse std::collections::*;\n\nmacro_rules! scan_line {\n () => ({\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line: failed at `handle.read_line`.\");\n buffer\n });\n ( $($t:ty)+ ) => ({\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line: failed at `handle.read_line`.\");\n let mut chunks = buffer.split_whitespace();\n\n ($(\n {\n chunks.next()\n .expect(\"scan_line: failed at `next`, # of space separated strings not equal to requested #\")\n .parse::<$t>()\n .expect(\"scan_line: failed at `parse::<$t>`.\")\n },\n )+)\n })\n}\n\nfn main() {\n let (n, k, t) = scan_line!(i64 i64 i64);\n\n if t <= k {\n println!(\"{}\", t);\n } else if t <= n {\n println!(\"{}\", k);\n } else {\n let d = k - (t - n);\n println!(\"{}\", d);\n }\n}\n", "src_uid": "7e614526109a2052bfe7934381e7f6c2"} {"source_code": "use std::io;\n\nfn contains(n: &String, sub: &String) -> bool {\n let mut chars = sub.chars();\n let mut now = chars.next();\n for c in n.chars() {\n if let Some(nowc) = now {\n if nowc == c {\n now = chars.next();\n }\n } else {\n break;\n }\n }\n return now == None;\n}\n\nfn main() {\n let mut n = String::new();\n io::stdin().read_line(&mut n);\n n = n.trim().to_string();\n let n_len = n.chars().count();\n for k in (1..44722).rev() {\n let sub = (k * k).to_string();\n let sub_len = sub.chars().count();\n if n_len >= sub_len && contains(&n, &sub) {\n println!(\"{}\", n_len - sub_len);\n return;\n }\n }\n println!(\"-1\");\n}\n", "src_uid": "fa4b1de79708329bb85437e1413e13df"} {"source_code": "// ---------- begin ModInt ----------\nmod modint {\n\n #[allow(dead_code)]\n pub struct Mod;\n impl ConstantModulo for Mod {\n const MOD: u32 = 1_000_000_007;\n }\n\n #[allow(dead_code)]\n pub struct StaticMod;\n static mut STATIC_MOD: u32 = 0;\n impl Modulo for StaticMod {\n fn modulo() -> u32 {\n unsafe { STATIC_MOD }\n }\n }\n\n #[allow(dead_code)]\n impl StaticMod {\n pub fn set_modulo(p: u32) {\n unsafe {\n STATIC_MOD = p;\n }\n }\n }\n\n use std::marker::*;\n use std::ops::*;\n\n pub trait Modulo {\n fn modulo() -> u32;\n }\n\n pub trait ConstantModulo {\n const MOD: u32;\n }\n\n impl Modulo for T\n where\n T: ConstantModulo,\n {\n fn modulo() -> u32 {\n T::MOD\n }\n }\n\n pub struct ModInt(pub u32, PhantomData);\n\n impl Clone for ModInt {\n fn clone(&self) -> Self {\n ModInt::new_unchecked(self.0)\n }\n }\n\n impl Copy for ModInt {}\n\n impl Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: Self) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= T::modulo() {\n d -= T::modulo();\n }\n ModInt::new_unchecked(d)\n }\n }\n\n impl AddAssign for ModInt {\n fn add_assign(&mut self, rhs: Self) {\n *self = *self + rhs;\n }\n }\n\n impl Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: Self) -> Self::Output {\n let mut d = T::modulo() + self.0 - rhs.0;\n if d >= T::modulo() {\n d -= T::modulo();\n }\n ModInt::new_unchecked(d)\n }\n }\n\n impl SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: Self) {\n *self = *self - rhs;\n }\n }\n\n impl Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: Self) -> Self::Output {\n let v = self.0 as u64 * rhs.0 as u64 % T::modulo() as u64;\n ModInt::new_unchecked(v as u32)\n }\n }\n\n impl MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: Self) {\n *self = *self * rhs;\n }\n }\n\n impl Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n if self.0 == 0 {\n Self::zero()\n } else {\n Self::new_unchecked(T::modulo() - self.0)\n }\n }\n }\n\n impl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n }\n\n impl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n }\n\n impl From for ModInt {\n fn from(val: usize) -> ModInt {\n ModInt::new_unchecked((val % T::modulo() as usize) as u32)\n }\n }\n\n impl From for ModInt {\n fn from(val: u64) -> ModInt {\n ModInt::new_unchecked((val % T::modulo() as u64) as u32)\n }\n }\n\n impl From for ModInt {\n fn from(val: i64) -> ModInt {\n let m = T::modulo() as i64;\n ModInt::new((val % m + m) as u32)\n }\n }\n\n #[allow(dead_code)]\n impl ModInt {\n pub fn new_unchecked(d: u32) -> Self {\n ModInt(d, PhantomData)\n }\n pub fn zero() -> Self {\n ModInt::new_unchecked(0)\n }\n pub fn one() -> Self {\n ModInt::new_unchecked(1)\n }\n pub fn is_zero(&self) -> bool {\n self.0 == 0\n }\n }\n\n #[allow(dead_code)]\n impl ModInt {\n pub fn new(d: u32) -> Self {\n ModInt::new_unchecked(d % T::modulo())\n }\n pub fn pow(&self, mut n: u64) -> Self {\n let mut t = Self::one();\n let mut s = *self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(&self) -> Self {\n assert!(self.0 != 0);\n self.pow(T::modulo() as u64 - 2)\n }\n }\n\n #[allow(dead_code)]\n pub fn mod_pow(r: u64, mut n: u64, m: u64) -> u64 {\n let mut t = 1 % m;\n let mut s = r % m;\n while n > 0 {\n if n & 1 == 1 {\n t = t * s % m;\n }\n s = s * s % m;\n n >>= 1;\n }\n t\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\nmod precalc {\n use super::modint::*;\n #[allow(dead_code)]\n pub struct Precalc {\n inv: Vec>,\n fact: Vec>,\n ifact: Vec>,\n }\n #[allow(dead_code)]\n impl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n fact[i] = fact[i - 1] * ModInt::new_unchecked(i as u32);\n }\n ifact[n] = fact[n].inv();\n if n > 0 {\n inv[n] = ifact[n] * fact[n - 1];\n }\n for i in (1..n).rev() {\n ifact[i] = ifact[i + 1] * ModInt::new_unchecked((i + 1) as u32);\n inv[i] = ifact[i] * fact[i - 1];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n assert!(n > 0);\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn perm(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[n - k]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n }\n}\n// ---------- end Precalc ----------\n//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, bytes) => {\n read_value!($iter, String).bytes().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nuse modint::*;\nuse precalc::*;\n\ntype M = ModInt;\n\nfn run() {\n input! {\n p: u64,\n k: u64,\n }\n let ans = if k == 0 {\n M::from(p).pow(p - 1)\n } else if k == 1 {\n M::from(p).pow(p)\n } else {\n let mut phi = p - 1;\n let mut m = phi;\n for d in 2.. {\n if d * d > m {\n break;\n }\n if m % d == 0 {\n while m % d == 0 {\n m /= d;\n }\n while phi % d == 0 && mod_pow(k, phi / d, p) == 1 {\n phi /= d;\n }\n }\n }\n if m > 1 && mod_pow(k, phi / m, p) == 1 {\n phi /= m;\n }\n M::from(p).pow((p - 1) / phi)\n };\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "580bf65af24fb7f08250ddbc4ca67e0e"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n\n fn next_n(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next::()).collect()\n }\n}\n\nfn find_div(x: usize) -> Vec {\n let mut result = Vec::new();\n for i in 1..=x {\n if x % i == 0 {\n result.push(i);\n }\n }\n return result;\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: usize = scan.next();\n let mut arr: Vec = scan.next_n(n);\n let x = *arr.iter().max().unwrap();\n let div_x = find_div(x);\n for &item in div_x.iter() {\n *arr.iter_mut().find(|x| **x == item).unwrap() = 0;\n }\n let y = *arr.iter().max().unwrap();\n println!(\"{} {}\", x, y);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "868407df0a93085057d06367aecaf9be"} {"source_code": "use std::io::{ self, BufRead };\nuse std::collections::*;\n\nmacro_rules! scan_line {\n () => ({\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line: failed at `handle.read_line`.\");\n buffer\n });\n ( $($t:ty)+ ) => ({\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line: failed at `handle.read_line`.\");\n let mut chunks = buffer.split_whitespace();\n\n ($(\n {\n chunks.next()\n .expect(\"scan_line: failed at `next`, # of space separated strings not equal to requested #\")\n .parse::<$t>()\n .expect(\"scan_line: failed at `parse::<$t>`.\")\n },\n )+)\n })\n}\n\nfn main() {\n let (mut n, ) = scan_line!(i64);\n\n n -= 3;\n let mut numerator = 1;\n let mut denominator = 2;\n\n while n >= 1 {\n if numerator + 1 < denominator {\n numerator += 1;\n } else {\n denominator += 1;\n }\n n -= 1;\n }\n\n let primes = vec![2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101];\n\n loop {\n if numerator == 1 { break; }\n let mut good = true;\n for p in primes.iter() {\n if denominator % *p == 0 && numerator % *p == 0 {\n denominator += 1;\n numerator -= 1;\n good = false;\n break;\n }\n }\n if good { break; }\n }\n\n println!(\"{} {}\", numerator, denominator);\n}", "src_uid": "0af3515ed98d9d01ce00546333e98e77"} {"source_code": "macro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\nfn div_and_ceil(a: i32, b: i32) -> i32 {\n if a % b == 0 { a / b } else { a / b + 1 }\n}\n\nfn main() {\n let (guests, lists) = readln!(i32, i32);\n \n let red = div_and_ceil(2 * guests, lists);\n let green = div_and_ceil(5 * guests, lists);\n let blue = div_and_ceil(8 * guests, lists);\n \n println!(\"{}\", red + green + blue);\n}", "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"source_code": "use std::error::Error;\nuse std::io;\nuse std::process;\n\nfn main() {\n if let Err(e) = run() {\n println!(\"{}\", e);\n process::exit(1);\n }\n}\n\nfn run() -> Result<(), Box> {\n let mut n = String::new();\n io::stdin().read_line(&mut n)?;\n let mut n: usize = n.trim().parse()?;\n let mut a = String::new();\n io::stdin().read_line(&mut a)?;\n let mut a: Vec<&str> = a\n .trim()\n .split(\" \")\n .collect();\n let mut cur = 0;\n let mut pre = 0;\n let mut inc = false;\n let mut con = false;\n let mut dec = false;\n for i in 0..n {\n if i == 0 {\n cur = a[i].parse()?;\n continue;\n }\n pre = cur;\n cur = a[i].parse()?;\n if pre < cur {\n if con || dec {\n println!(\"NO\");\n return Ok(());\n }\n inc = true;\n } else if pre == cur {\n if dec {\n println!(\"NO\");\n return Ok(());\n }\n con = true;\n } else {\n dec = true;\n }\n }\n println!(\"YES\");\n Ok(())\n}\n", "src_uid": "5482ed8ad02ac32d28c3888299bf3658"} {"source_code": "// ---------- begin input macro ----------\r\n// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\r\nmacro_rules! input {\r\n (source = $s:expr, $($r:tt)*) => {\r\n let mut iter = $s.split_whitespace();\r\n input_inner!{iter, $($r)*}\r\n };\r\n ($($r:tt)*) => {\r\n let s = {\r\n use std::io::Read;\r\n let mut s = String::new();\r\n std::io::stdin().read_to_string(&mut s).unwrap();\r\n s\r\n };\r\n let mut iter = s.split_whitespace();\r\n input_inner!{iter, $($r)*}\r\n };\r\n}\r\n\r\nmacro_rules! input_inner {\r\n ($iter:expr) => {};\r\n ($iter:expr, ) => {};\r\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\r\n let $var = read_value!($iter, $t);\r\n input_inner!{$iter $($r)*}\r\n };\r\n}\r\n\r\nmacro_rules! read_value {\r\n ($iter:expr, ( $($t:tt),* )) => {\r\n ( $(read_value!($iter, $t)),* )\r\n };\r\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\r\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\r\n };\r\n ($iter:expr, chars) => {\r\n read_value!($iter, String).chars().collect::>()\r\n };\r\n ($iter:expr, bytes) => {\r\n read_value!($iter, String).bytes().collect::>()\r\n };\r\n ($iter:expr, usize1) => {\r\n read_value!($iter, usize) - 1\r\n };\r\n ($iter:expr, $t:ty) => {\r\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\r\n };\r\n}\r\n// ---------- end input macro ----------\r\n\r\nuse std::io::Write;\r\nuse std::collections::*;\r\n\r\ntype Map = BTreeMap;\r\ntype Set = BTreeSet;\r\ntype Deque = VecDeque;\r\n\r\nfn run() {\r\n input! {\r\n t: usize,\r\n ask: [(usize, usize, usize); t],\r\n }\r\n let out = std::io::stdout();\r\n let mut out = std::io::BufWriter::new(out.lock());\r\n for (h, w, k) in ask {\r\n let b = k;\r\n let a = h * w / 2 - b;\r\n let ans = match (h % 2, w % 2, a % 2, b % 2) {\r\n (0, 0, 0, 0) => \"YES\",\r\n (0, 0, _, _) => \"NO\",\r\n (0, 1, _, 0) if b <= (w - 1) * h / 2 => \"YES\",\r\n (0, 1, _, _) => \"NO\",\r\n (1, 0, 0, _) if a <= (h - 1) * w / 2 => \"YES\",\r\n _ => \"NO\",\r\n };\r\n writeln!(out, \"{}\", ans).ok();\r\n }\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n", "src_uid": "4d0c0cc8faca62eb6384f8135b30feb8"} {"source_code": "use std::io::*;\n\nfn main() {\n let mut stdin = stdin();\n let mut buffer = String::new();\n let _ = stdin.read_to_string(&mut buffer);\n let s = buffer.trim();\n\n println!(\"{}\", (s.len() + s[1..].contains(\"1\") as usize) / 2);\n}\n", "src_uid": "d8ca1c83b431466eff6054d3b422ab47"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nfn can(m: usize, a: &[usize], p: &[(usize, usize)]) -> bool {\n let mut last = m;\n let mut free = 0;\n let mut rem = vec![];\n rem.extend_from_slice(a);\n for &(d, t) in p.iter().rev() {\n if d > m {\n continue;\n }\n if last > d {\n free += last - d;\n last = d;\n }\n while rem[t] > 0 && last > 0 {\n rem[t] -= 1;\n last -= 1;\n }\n }\n free += last;\n 2 * rem.into_iter().fold(0, |s, a| s + a) <= free\n}\n\nfn run() {\n input! {\n n: usize,\n m: usize,\n a: [usize; n],\n p: [(usize, usize1); m],\n }\n let mut p = p;\n p.sort_by_key(|p| p.0);\n let mut ng = 0;\n let mut ok = 400_000;\n while ok - ng > 1 {\n let m = (ok + ng) / 2;\n if can(m, &a, &p) {\n ok = m;\n } else {\n ng = m;\n }\n }\n println!(\"{}\", ok);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "2eb101dcfcc487fe6e44c9b4c0e4024d"} {"source_code": "static PERMS: [[usize; 8]; 3] = [\n [2, 4, 6, 8, 10, 12, 23, 21],\n [13, 14, 5, 6, 17, 18, 21, 22],\n [3, 4, 17, 19, 10, 9, 16, 14]\n];\n\n\nfn shiftmod(i: usize, dir: i32) -> usize {\n let res = i as i32 + 2 * dir;\n (if res < 0 { 8 + res } else if res > 8 { res - 8 } else { res }) as usize\n}\n\n\nstruct State(Vec);\n\nimpl State {\n fn shift(&mut self, perm: &[usize; 8], dir: i32) {\n for i in 0..6 {\n self.0.swap(perm[i] - 1, perm[shiftmod(i, dir)] - 1)\n }\n }\n\n fn is_correct(&self) -> bool {\n (0..6).all(|i|\n ((i * 4)..(i * 4 + 3))\n .all(|k| self.0[k] == self.0[k + 1]))\n }\n\n fn try_move(&mut self, perm: &[usize; 8], dir: i32) -> bool {\n self.shift(perm, dir);\n let res = self.is_correct();\n self.shift(perm, -dir);\n res\n }\n\n fn single_move(&mut self) -> bool {\n PERMS.iter().any(|perm| {\n self.try_move(perm, 1) || self.try_move(perm, -1)\n })\n }\n}\n\nfn main() {\n let mut sin = ReadIn::new();\n let mut colors = State(sin.intvec());\n println!(\"{}\", if colors.single_move() { \"YES\" } else { \"NO\" });\n}\n\n\nuse std::iter::*;\nuse std::str::SplitWhitespace;\nuse std::io::stdin;\nuse std::mem::forget;\n\npub struct ReadIn(pub String);\n\nimpl ReadIn {\n pub fn new() -> ReadIn { ReadIn(String::new()) }\n fn read_i32(s: &str) -> i32 { s.parse().unwrap() }\n pub fn read_line(&mut self) {\n self.0.clear();\n forget(stdin().read_line(&mut self.0));\n }\n pub fn ints(&mut self) -> Map i32> {\n self.read_line();\n self.0.split_whitespace().map(ReadIn::read_i32)\n }\n pub fn intvec(&mut self) -> Vec { self.ints().collect() }\n pub fn int(&mut self) -> i32 { self.ints().next().unwrap() }\n pub fn int2(&mut self) -> (i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap())\n }\n\n pub fn int3(&mut self) -> (i32, i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap(), it.next().unwrap())\n }\n pub fn int4(&mut self) -> (i32, i32, i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap(), it.next().unwrap(), it.next().unwrap())\n }\n}", "src_uid": "881a820aa8184d9553278a0002a3b7c4"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\n#![allow(unused_labels)]\n\nuse std::char::*;\nuse std::cmp::*;\nuse std::collections::*;\nuse std::io::*;\nuse std::str::FromStr;\n\nmacro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);}}\nmacro_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 ) * } } ; }\nmacro_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 ) * } } ; }\nmacro_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\" ) } ; }\n\n\nfn read() -> T {\n let stdin = stdin();\n let stdin = stdin.lock();\n let token: String = stdin\n .bytes()\n .map(|c| c.expect(\"failed to read char\") as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect();\n token.parse().ok().expect(\"failed to parse token\")\n}\n\nuse std::f64;\n\nfn min(a:T, b:T) -> T {\n if a < b { a }\n else { b }\n}\n\nfn max(a:T, b:T) -> T {\n if a < b { b }\n else { a }\n}\n\nconst MAX:usize = 30;\nconst INF:i64 = std::i64::MAX;\nconst MOD:i64 = 1e9 as i64 + 7;\n\nstruct Graph {\n e: Vec>,\n v: Vec,\n u: Vec,\n f: Vec,\n c: i64,\n vc: Vec,\n}\n\nimpl Graph {\n fn new(n:usize) -> Self {\n Graph {\n e: vec![vec![];n],\n v: vec![],\n u: vec![n;n],\n f: vec![false;n],\n c: 0,\n vc: vec![0;n],\n }\n }\n\n fn dfs(&mut self, crt: usize) {\n if self.f[crt] { return; }\n self.c += 1;\n self.f[crt] = true;\n self.v.push(crt);\n self.vc[crt] = self.c;\n self.u[crt] = self.v.len()-1;\n for i in 0..self.e[crt].len() {\n self.dfs(self.e[crt][i]);\n }\n //debug!(crt, self.c, self.vc[crt]);\n self.vc[crt] = self.c - self.vc[crt];\n }\n}\n\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let mut a:Vec = (0..n).map(|_| read()).collect();\n a.reverse();\n let mut v = vec![];\n for i in 0..n {\n let mut f = false;\n for j in 0..v.len() {\n if a[i] == v[j] {\n f = true;\n }\n }\n if !f {\n v.push(a[i]);\n }\n }\n v.reverse();\n println!(\"{}\",v.len());\n for e in v {print!(\"{} \",e);} println!();\n //}\n}\n\n/*\n\n\n*/\n", "src_uid": "1b9d3dfcc2353eac20b84c75c27fab5a"} {"source_code": "use std::cmp;\nuse std::error::Error;\nuse std::io::{self, Read};\n\nfn main() -> Result<(), Box> {\n let mut stdin = io::stdin();\n let mut line = String::new();\n stdin.read_line(&mut line)?;\n let num_digits: usize = line.trim().parse()?;\n let mut digits = vec![0u8; num_digits];\n stdin.read_exact(&mut digits)?;\n let num_eights = digits.iter().filter(|c| **c == b'8').count();\n println!(\"{}\", cmp::min(num_digits / 11, num_eights));\n Ok(())\n}\n", "src_uid": "259d01b81bef5536b969247ff2c2d776"} {"source_code": "//! https://github.com/hatoo/competitive-rust-snippets\n//!\n//! MIT License\n//!\n//! Copyright (c) 2018 hatoo\n//!\n//! Permission is hereby granted, free of charge, to any person obtaining a copy\n//! of this software and associated documentation files (the \"Software\"), to deal\n//! in the Software without restriction, including without limitation the rights\n//! to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n//! copies of the Software, and to permit persons to whom the Software is\n//! furnished to do so, subject to the following conditions:\n//!\n//! The above copyright notice and this permission notice shall be included in all\n//! copies or substantial portions of the Software.\n//!\n//! THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n//! IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n//! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n//! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n//! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n//! SOFTWARE.\n#![allow(\n unused_imports,\n unused_attributes,\n unused_macros,\n dead_code,\n non_snake_case\n)]\nuse std::cmp::{max, min, Ordering};\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\nuse std::io::{stdin, stdout, BufWriter, Write};\nuse std::iter::FromIterator;\n#[macro_export]\nmacro_rules !get {(@inner [$src :expr ] chars ) =>{{let mut buf =String ::new () ;$src .read_line (&mut buf ) .unwrap () ;buf .trim () .chars () .collect ::>() } } ;(@inner [$src :expr ] usize1 ) =>{{get !(@inner [$src ] usize ) -1 } } ;(@inner [$src :expr ] [usize1 ] ) =>{{get !(@inner [$src ] [usize ] ) .into_iter () .map (|v |v -1 ) .collect ::>() } } ;(@inner [$src :expr ] [[usize1 ] ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] [usize1 ] ) ) .collect ::>() } } ;(@inner [$src :expr ] [usize1 ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] [usize1 ] ) ) .flatten () .collect ::>() } } ;(@inner [$src :expr ] [[chars ] ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] chars ) ) .collect ::>() } } ;(@inner [$src :expr ] [chars ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] chars ) ) .collect ::>() } } ;(@inner [$src :expr ] [($($tt :tt ) ,*) ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] ($($tt ) ,*) ) ) .collect ::>() } } ;(@inner [$src :expr ] ($($tt :tt ) ,*) ) =>{{let mut buf :String =String ::new () ;$src .read_line (&mut buf ) .unwrap () ;let mut iter =buf .split_whitespace () ;($(get !(@inner_elem_parse [$tt ] iter .next () .unwrap () ) ,) *) } } ;(@inner [$src :expr ] [$t :ty ] ) =>{{let mut buf =String ::new () ;$src .read_line (&mut buf ) .unwrap () ;buf .trim () .split_whitespace () .map (|t |t .parse ::<$t >() .unwrap () ) .collect ::>() } } ;(@inner [$src :expr ] [[$t :ty ] ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] [$t ] ) ) .collect ::>() } } ;(@inner [$src :expr ] [$t :ty ;$n :expr ] ) =>{{(0 ..$n ) .map (|_ |get !(@inner [$src ] [$t ] ) ) .flatten () .collect ::>() } } ;(@inner [$src :expr ] $t :ty ) =>{{let mut buf =String ::new () ;$src .read_line (&mut buf ) .unwrap () ;buf .trim () .split_whitespace () .next () .unwrap () .parse ::<$t >() .unwrap () } } ;(@inner_elem_parse [usize1 ] $elem :expr ) =>{{get !(@inner_elem_parse [usize ] $elem ) -1 } } ;(@inner_elem_parse [$t :ty ] $elem :expr ) =>{{$elem .parse ::<$t >() .unwrap () } } ;($tt :tt ) =>{{use std ::io ::BufRead ;let get_stdin =std ::io ::stdin () ;let mut locked_stdin =get_stdin .lock () ;get !(@inner [&mut locked_stdin ] $tt ) } } ;}\nmacro_rules !debug {($($a :expr ) ,*$(,) *) =>{#[cfg (debug_assertions ) ] eprintln !(concat !($(\"| \" ,stringify !($a ) ,\"={:?} \" ) ,*,\"|\" ) ,$(&$a ) ,*) ;} ;}\nmacro_rules !echo {($($a :expr ) ,*) =>{let mut s =Vec ::new () ;$(s .push (format !(\"{}\" ,$a ) ) ;) *println !(\"{}\" ,s .join (\" \" ) ) ;} }\n#[macro_export]\nmacro_rules !chmin {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_min =min !($($cmps ) ,+) ;if $base >cmp_min {$base =cmp_min ;true } else {false } } } ;}\n#[macro_export]\nmacro_rules !chmax {($base :expr ,$($cmps :expr ) ,+$(,) *) =>{{let cmp_max =max !($($cmps ) ,+) ;if $base {{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::min ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::min ($a ,min !($($rest ) ,+) ) } } ;}\n#[macro_export]\nmacro_rules !max {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::max ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::max ($a ,max !($($rest ) ,+) ) } } ;}\nconst BIG_STACK_SIZE: bool = true;\nfn main() {\n use std::thread;\n if BIG_STACK_SIZE {\n thread::Builder::new()\n .stack_size(32 * 1024 * 1024)\n .name(\"solve\".into())\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n } else {\n solve();\n }\n}\nfn solve() {\n let (a, b, c, d) = get!((i64, i64, i64, i64));\n const N: usize = 1_000_100;\n let mut imos = vec![0i64; N];\n for x in a..=b {\n let from = (x + b) as usize;\n let to = (x + c + 1) as usize;\n imos[from] += 1;\n imos[to] -= 1;\n }\n for i in 1..N {\n imos[i] += imos[i - 1];\n }\n let mut cumsum = vec![0i64; N];\n for i in 1..N {\n cumsum[i] = cumsum[i - 1] + imos[i - 1];\n }\n let mut ans = 0;\n for z in c..=d {\n ans += cumsum[N - 1] - cumsum[z as usize + 1];\n }\n echo!(ans);\n}\n\nfn solve2() {\n let (a, b, c, d) = get!((i64, i64, i64, i64));\n let height = c - b;\n let width = b - a;\n let mut appear = vec![0i64; (height + width + 10) as usize];\n for i in 0..=(height + width) {\n debug!(i, width, height);\n if min(width, height) <= i && i <= max(width, height) {\n appear[i as usize] = min(width, height) + 1;\n } else if i < min(width, height) {\n appear[i as usize] = i + 1;\n } else {\n appear[i as usize] = height + width - i + 1;\n }\n }\n let mut counts = vec![0i64; (height + width + 10) as usize];\n for i in 0..=(height + width) {\n let k = i + a + b;\n if i == 0 {\n counts[i as usize] = 0;\n } else if k < c {\n counts[i as usize] = 0;\n } else if c <= k && k <= d {\n counts[i as usize] = k - c + 1;\n } else if d < k {\n counts[i as usize] = d - c + 1;\n }\n }\n debug!(counts);\n let mut ans = 0;\n for i in 0..=(height + width) {\n let i = i as usize;\n ans += counts[i] * appear[i];\n }\n echo!(ans);\n}\n", "src_uid": "4f92791b9ec658829f667fcea1faee01"} {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin()\n .read_line(& mut s)\n .expect(\"Deu Ruim\");\n \n let s = s.trim();\n let n = s.len();\n\n let mut res = match &s[n-1..n] {\n \"a\"|\"e\"|\"i\"|\"o\"|\"u\"|\"n\" => true,\n _ => false\n };\n\n for i in 0..n-1 {\n\n match (&s[i..i+1], &s[i+1..i+2]) {\n\n (\"a\",_)|(\"e\",_)|(\"i\",_)|(\"o\",_)|(\"u\", _) => (),\n (\"n\", _) => (),\n (_,\"a\")|(_,\"e\")|(_,\"i\")|(_,\"o\")|(_,\"u\") => (),\n (_, _) => res = false,\n }\n }\n\n match res {\n true => println!(\"YES\", ),\n _ => println!(\"NO\", )\n }\n}\n", "src_uid": "a83144ba7d4906b7692456f27b0ef7d4"} {"source_code": "#![allow(clippy::many_single_char_names, dead_code, unused_imports, unused_macros, unused_variables)]\n#![recursion_limit = \"1000\"]\nuse std::{cmp::Reverse, collections::*, fmt::Binary, hash::Hash, io::{stdin, stdout, BufWriter, Read, StdinLock, StdoutLock, Write}, iter::FromIterator, mem::swap, ops::Rem};\n\nmacro_rules! parse {\n (check $n: expr, $t: ty) => { std::str::from_utf8_unchecked($n).parse::<$t>().unwrap() };\n ($n: expr, $t: ty) => {\n if cfg!(debug_assertions) {\n parse!(check $n, $t)\n } else {\n #[allow(unused_comparisons)] {\n if <$t>::default()-1 > 0 {\n parse!(unsigned $n, $t)\n } else {\n parse!(signed $n, $t)\n }\n }\n }\n };\n (unsigned $n: expr, $t: ty) => {{\n let mut num = 0;\n\n for d in $n {\n num = num*10 + (*d - b'0') as $t;\n }\n num\n }};\n (signed $n: expr, $t: ty) => {{\n if $n.get_unchecked(0) == &b'-' {\n let mut num = 0;\n\n for d in &$n[1..] {\n num = num*10 - (*d - b'0') as $t;\n }\n num\n } else {\n parse!(unsigned $n, $t)\n }\n }};\n}\n\nmacro_rules! read {\n ($r: expr) => { $r.read() };\n ($r: expr, str) => { String::from_utf8_unchecked($r.read().into()) };\n ($r: expr, f32) => { read!(check $r, f32) };\n ($r: expr, f64) => { read!(check $r, f64) };\n (check $r: expr, $t: ty) => {{\n let n = $r.read();\n parse!(check n, $t)\n }};\n ($r: expr, $t: ty) => {{\n let n = $r.read();\n parse!(n, $t)\n }}\n}\n\nmacro_rules! fill {\n (declare mut $r: expr, $t: ty, $($x: ident),+) => {\n $(\n let mut $x = read!($r, $t);\n )+\n };\n (declare $r: expr, $t: ty, $($x: ident),+) => {\n $(\n let $x = read!($r, $t);\n )+\n };\n ($r: expr, $t: ty, $($x: ident),+) => {\n $(\n $x = read!($r, $t);\n )+\n }\n}\n\nmacro_rules! read_vec {\n (const $r: expr, $t: ty, $n: expr) => {{\n let mut v = [0; $n];\n for x in &mut v {\n *x = read!($r, $t);\n }\n v\n }};\n (fill $r: expr, $t: ty, $v: expr, $n: expr) => {\n for x in &mut $v[..$n] {\n *x = read!($r, $t);\n }\n };\n ($r: expr, str, $n: expr) => {{\n let mut v = Vec::with_capacity($n);\n for _ in 0..$n {\n v.push(read!($r, str));\n // v.push(String::from_utf8_unchecked(read!($r).into()));\n }\n v\n }};\n ($r: expr, $t: ty, $n: expr) => {{\n let mut v = Vec::with_capacity($n);\n for _ in 0..$n {\n v.push(read!($r, $t));\n }\n v\n }};\n ($r: expr, str) => {{\n let mut v = Vec::with_capacity(10_000);\n loop {\n let (tmp, b) = $r.read_with_lf_check();\n v.push(String::from_utf8_unchecked(tmp.into()));\n if b {\n break v;\n }\n }\n }};\n ($r: expr, $t: ty) => {{\n let mut v = Vec::with_capacity(10_000);\n loop {\n let (tmp, b) = $r.read_with_lf_check();\n v.push(read!($r, $t));\n if b {\n break v;\n }\n }\n }};\n ($r: expr) => { read_vec!($r, str) };\n ($r: expr, $n: expr) => { read_vec!($r, str, $n) };\n}\n\nmacro_rules! w {\n ($w: expr $(, $args: expr)*) => {\n write!($w $(, $args)*).unwrap();\n };\n}\n\nmacro_rules! wl {\n ($w: expr $(, $args: expr)*) => {\n writeln!($w $(, $args)*).unwrap();\n };\n}\n\n\nmacro_rules! void {\n ($r: expr) => { void!($r, 2); };\n ($r: expr, 1) => {\n $r.cursor += 1;\n loop {\n if $r.buf.get_unchecked($r.cursor) <= &b' ' {\n if $r.cursor >= $r.buf_len {\n $r.buf_len = $r.stdin.read(&mut $r.buf).unwrap();\n $r.cursor = 0;\n } else {\n $r.cursor += 1;\n $r.reset();\n break;\n }\n } else {\n $r.cursor += 1;\n }\n }\n };\n ($r: expr, $n: expr) => {\n let mut acc = 0;\n $r.cursor += 1;\n loop {\n if $r.buf.get_unchecked($r.cursor) <= &b' ' {\n if $r.cursor >= $r.buf_len {\n $r.buf_len = $r.stdin.read(&mut $r.buf).unwrap();\n $r.cursor = 0;\n } else {\n acc += 1;\n $r.cursor += 1;\n $r.reset();\n if acc == $n {\n break;\n }\n }\n } else {\n $r.cursor += 1;\n }\n }\n };\n}\n\nstruct Reader<'a>/*'*/ {\n stdin: StdinLock<'a>/*'*/,\n cursor: usize,\n buf_len: usize,\n buf: [u8; BUF_LEN],\n temp_end: usize,\n temp: [u8; 10_000],\n}\n\nimpl Reader<'_>/*'*/ {\n #[inline]\n unsafe fn read(&mut self) -> &[u8] {\n let init = self.cursor;\n loop {\n if self.buf.get_unchecked(self.cursor) <= &b' ' {\n if self.cursor >= self.buf_len {\n let s = self.buf_len.saturating_sub(init);\n\n let src = self.buf.as_ptr().add(init);\n let dest = self.temp.as_mut_ptr().add(self.temp_end);\n std::ptr::copy_nonoverlapping(src, dest, s);\n\n self.buf_len = self.stdin.read(&mut self.buf).unwrap();\n self.temp_end += s;\n\n if self.buf_len == 0 {\n *self.temp.get_unchecked_mut(self.temp_end) = b'\\n';\n return &self.temp[..self.temp_end];\n }\n\n self.cursor = 0;\n\n if s == 0 { self.reset(); }\n return self.read();\n }\n\n if self.temp_end != 0 {\n let s = self.cursor - init;\n let n = self.temp_end + s;\n\n let src = self.buf.as_ptr().add(init);\n let dest = self.temp.as_mut_ptr().add(self.temp_end);\n std::ptr::copy_nonoverlapping(src, dest, s);\n *dest.add(s) = b'\\n';\n\n self.cursor += 1;\n self.reset();\n self.temp_end = 0;\n\n return &self.temp[..n];\n }\n\n let t = self.cursor;\n self.cursor += 1;\n self.reset();\n return &self.buf[init..t];\n }\n self.cursor += 1;\n }\n }\n #[inline(always)]\n unsafe fn reset(&mut self) {\n while self.buf.get_unchecked(self.cursor) <= &b' ' {\n self.cursor += 1;\n }\n }\n #[inline(always)]\n unsafe fn read_with_lf_check(&mut self) -> (&[u8], bool) {\n let t = self.read();\n (t, *t.as_ptr().add(t.len()) < b' ')\n }\n}\n\nconst BUF_LEN: usize = 1_000_000;\nfn main() {\n let stdin = stdin();\n let stdin = stdin.lock();\n let stdout = stdout();\n let stdout = stdout.lock();\n\n unsafe {\n solve(\n &mut Reader {\n stdin,\n cursor: 0,\n buf_len: 0,\n buf: [0; BUF_LEN],\n temp_end: 0,\n temp: [0; 10_000]\n },\n &mut BufWriter::with_capacity(100_000, stdout),\n );\n }\n}\n\nconst M: usize = std::usize::MAX;\nconst REM: usize = 1_000_000_007;\n\nfn bin_pow_rem(mut a: u64, mut b: u64, rem: u64) -> u64 {\n a %= rem;\n let mut res = 1;\n\n while b != 0 {\n if b&1 == 1 {\n res = res*a%rem;\n }\n a = a*a%rem;\n b >>= 1;\n }\n res\n}\n\n#[inline]\nunsafe fn solve(r: &mut Reader, w: &mut BufWriter) {\n let n = read!(r, u64);\n wl!(w, \"{}\", bin_pow_rem(4, (1 << n) -2, REM as u64)*6 % REM as u64);\n}", "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"source_code": "#[allow(unused_imports)]\nuse std::io::{BufReader, BufWriter, stdin, stdout, Write};\nuse std::cmp::{min, max};\nuse std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap};\n\nfn main() {\n\tlet mut inp = my_input::default();\n\tlet out = &mut BufWriter::new(stdout());\n\tlet A:i64 = inp.scan::();\n\tlet B:i64 = inp.scan::();\n\tlet C:i64 = inp.scan::();\n\tlet D:i64 = inp.scan::();\n\tlet mut v = vec![A, B, C];\n\tv.sort();\n\twriteln!(out, \"{}\", max(0, D - (v[1] - v[0])) + max(0, D - (v[2] - v[1])));\n}\n\n#[derive(Default)]\nstruct my_input {\n\tbuffer: Vec\n}\n\nimpl my_input {\n\tfn scan(&mut self) -> T {\n\t\tloop {\n\t\t\tif let Some(token) = self.buffer.pop() {\n\t\t\t\treturn token.parse().ok().expect(\"Parsing Error\");\n\t\t\t}\n\t\t\tlet mut s = String::new();\n\t\t\tstdin().read_line(&mut s).expect(\"Reading Error\");\n\t\t\tself.buffer = s.split_whitespace().rev().map(String::from).collect();\n\t\t}\n\t}\n}", "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"source_code": "// https://codeforces.com/contest/1239/problem/A\n//\n#![allow(unused_imports)]\nuse std::io::*;\nuse std::io::Write;\nuse std::fmt::*;\nuse std::str::*;\nuse std::cmp::*;\nuse std::collections::*;\n\n// Input macros.\n// Original by tanakh: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\n#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n\n ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n\n ($iter:expr, [ next / $t:tt ]) => {\n {\n let len = read_value!($iter, usize);\n (0..len).map(|_| read_value!($iter, $t)).collect::>()\n }\n };\n\n ($iter:expr, switch) => {\n {\n let ty = read_value!($iter, i32);\n if ty == 1 {\n vec![ty, read_value!($iter, i32), read_value!($iter, i32)]\n } else if ty == 2 {\n vec![ty, read_value!($iter, i32)]\n } else {\n vec![ty, read_value!($iter, i32)]\n }\n }\n };\n\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_line {\n ($t:tt) => {\n {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n s.trim_right().parse::<$t>().unwrap()\n }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! dvec {\n ($t:expr ; $len:expr) => {\n vec![$t; $len]\n };\n\n ($t:expr ; $len:expr, $($rest:expr),*) => {\n vec![dvec!($t; $($rest),*); $len]\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! ifv {\n ($t:expr, $a:expr, $b: expr) => {\n if $t { $a } else { $b }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! fill {\n ($t:expr, $v:expr) => {\n for i in 0..$t.len() {\n $t[i] = $v;\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! join {\n ($t:expr, $glue:expr) => {\n $t.into_iter().map(|w| w.to_string()).collect::>().join($glue)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\n// ===\n\nconst MOD: i64 = 1e9 as i64 + 7;\n\nfn not_consequtive3(n: usize) -> Vec {\n let mut dp = dvec![0; n+1, 5];\n dp[1] = vec![1, 0, 1, 0];\n dp[2] = vec![1, 1, 1, 1];\n for i in 2..n {\n for j in 0..4 {\n let base = dp[i][j];\n for next in 0..2 {\n let nj = j+4*next;\n if nj == 7 || nj == 0 {\n continue;\n }\n let nj = ifv!(j == 0, 2*next, nj/2);\n dp[i+1][nj] += base;\n dp[i+1][nj] %= MOD;\n }\n }\n }\n dp.into_iter().map(|row| row.into_iter().fold(0, |acc,x| (acc+x)%MOD)).collect::>()\n}\n\n\nfn solve(h: usize, w: usize) -> i64 {\n if w == 1 {\n return 2;\n }\n let dp = not_consequtive3(w+10);\n // debug!(dp);\n (dp[h] + dp[w] + MOD - 2) % MOD\n}\n\nfn main() {\n input! {\n n: usize, m: usize\n };\n let h = min(n, m);\n let w = max(n, m);\n println!(\"{}\", solve(h, w));\n}\n\n\n", "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"source_code": "fn main(){let mut z=String::new();std::io::stdin().read_line(&mut z);let a:i8=z.trim().parse().expect(\"\");print!(\"{}\",if a&1==1||a==2{\"NO\"}else{\"YES\"})}", "src_uid": "230a3c4d7090401e5fa3c6b9d994cdf2"} {"source_code": "use std::io::stdin;\nuse std::cmp::min;\n\nfn main() {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let nposlr = input.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n let (n, pos, l, r) = (nposlr[0], nposlr[1], nposlr[2], nposlr[3]);\n\n if l == 1 && r == n {\n println!(\"0\");\n } else if l == 1 {\n println!(\"{}\", (pos - r).abs() + 1);\n } else if r == n {\n println!(\"{}\", (pos - l).abs() + 1);\n } else {\n let min_dist = min((pos - l).abs(), (pos - r).abs());\n println!(\"{}\", min_dist + (r - l).abs() + 2);\n }\n\n\n\n}\n", "src_uid": "5deaac7bd3afedee9b10e61997940f78"} {"source_code": "#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n let mut next = || { iter.next().unwrap() };\n input_inner!{next, $($r)*}\n };\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n\n ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, bytes) => {\n read_value!($next, String).into_bytes()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::{BinaryHeap, HashMap};\n\n#[allow(dead_code)]\ntype Graph = Vec>;\n\nfn main() {\n input! {\n n: usize, l: usize, r: usize,\n }\n\n let mini = (1 << l) - 1 + 1 * (n - l);\n let maxi = (1 << r) - 1 + (1 << (r - 1)) * (n - r);\n\n println!(\"{} {}\", mini, maxi);\n}\n", "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(overflowing_literals)]\n#![allow(unused_must_use)]\n#![allow(non_camel_case_types)]\n\nuse std::collections::*;\nuse std::io::*;\nuse std::cmp::{max, min};\nuse std::f64::consts::*;\nuse std::mem::swap;\nuse std::fs::File;\nuse std::rc::*;\nuse std::ascii::*;\nuse std::ops::*;\n\nconst INF: i32 = std::i32::MAX;\nconst LINF: i64 = std::i64::MAX;\nconst MOD: usize = 1000000007;\n\nstruct Input {\n\tbuffer: Buf,\n}\n\nimpl Input {\n\tfn read_line(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] < b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] >= b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\n\tfn read_word(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] <= b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] > b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\t#[inline]\n\tfn read_int(&mut self) -> i32 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_long(&mut self) -> i64 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_usize(&mut self) -> usize {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_double(&mut self) -> f64 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n}\nmacro_rules! read {\n () => {};\n\t($inf:ident, $($t:ty),+) => ({($({$inf.read_word().parse::<$t>().expect(\"Parsing error\")}),*)});\n}\nfn gcd + Copy + Clone>(mut a: T, mut b: T) -> T {\n\twhile b > T::from(0) {\n\t\ta %= b;\n\t\tswap(&mut a, &mut b);\n\t}\n\ta\n}\n\nfn main() {\n\tmatch std::env::var(\"home\") {\n\t\tOk(_x) => {\n\t\t\tlet mut inf = Input {\n\t\t\t\tbuffer: BufReader::new(File::open(\"input.txt\").expect(\"File not found\"))\n\t\t\t};\n\t\t\tlet mut ouf = BufWriter::new(stdout());\n\t\t\tlet stack_size = 268_435_456 / 4; // 256 MB\n\t\t\tlet thd = std::thread::Builder::new().stack_size(stack_size);\n\t\t\tthd.spawn(move || solve(&mut inf, &mut ouf)).unwrap().join().unwrap();\n\t\t}\n\t\tErr(_e) => {\n\t\t\tlet mut inf = Input { buffer: BufReader::new(stdin()) };\n\t\t\tlet mut ouf = BufWriter::new(stdout());\n\t\t\tlet stack_size = 268_435_456 / 4; // 256 MB\n\t\t\tlet thd = std::thread::Builder::new().stack_size(stack_size);\n\t\t\tthd.spawn(move || solve(&mut inf, &mut ouf)).unwrap().join().unwrap();\n\t\t}\n\t}\n}\n\nfn dfs<'a>(g: &'a Vec>, u: &'a mut Vec, v: usize) {\n\tif u[v] {\n\t\treturn;\n\t}\n\tu[v] = true;\n\tfor &x in &g[v] {\n\t\tdfs(g, u, x);\n\t}\n}\n\ntype int = i32;\ntype long = i64;\ntype uint = u32;\ntype ulong = u64;\n\nfn solve(inf: &mut Input, ouf: &mut Output) {\n\tlet s = inf.read_word().as_bytes().to_vec();\n\tlet mut pos = 0;\n\twhile pos < s.len() && s[pos] == b'0' {\n\t\tpos += 1;\n\t}\n\tlet mut ans = 0;\n\tfor i in pos + 1..s.len() {\n\t\tif s[i] == b'0' {\n\t\t\tans += 1;\n\t\t}\n\t}\n\tif ans >= 6 {\n\t\twriteln!(ouf, \"yes\");\n\t} else {\n\t\twriteln!(ouf, \"no\");\n\t}\n}\n", "src_uid": "88364b8d71f2ce2b90bdfaa729eb92ca"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nfn run() {\n input! {\n n: usize,\n m: usize,\n a: [usize; n],\n }\n let max = *a.iter().max().unwrap() + m;\n let mut a = a;\n for _ in 0..m {\n let mut min = (1000000, 0);\n for (i, a) in a.iter().enumerate() {\n min = std::cmp::min(min, (*a, i));\n }\n a[min.1] += 1;\n }\n let min = *a.iter().max().unwrap();\n println!(\"{} {}\", min, max);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "78f696bd954c9f0f9bb502e515d85a8d"} {"source_code": "fn raw_input() -> String {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n}\n\nfn main() {\n {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n }\n\n let input = raw_input();\n let (mut x_count, mut to_remove) = (0, 0);\n for c in input.chars() {\n if c == 'x' {\n if x_count >= 2 {\n to_remove += 1;\n }\n x_count += 1;\n } else {\n x_count = 0;\n }\n }\n\n print!(\"{}\", to_remove);\n}", "src_uid": "8de14db41d0acee116bd5d8079cb2b02"} {"source_code": "use std::io;\n\nfn tanya(mut n: i64, k: i64) -> i64 {\n for _ in 0..k {\n if n % 10 == 0 {\n n /= 10;\n } else {\n n -= 1;\n }\n }\n n\n}\n\nfn main() -> io::Result<()> {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer)?;\n let mut parts = buffer.split_whitespace().map(|s| s.parse::());\n match (parts.next(), parts.next()) {\n (Some(Ok(a)), Some(Ok(b))) => println!(\"{}\", tanya(a,b)),\n _ => {},\n }\n Ok(())\n}\n", "src_uid": "064162604284ce252b88050b4174ba55"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: u32 = scan.token();\n let ans = if n == 0 {\n 1\n } else if n % 4 == 0 {\n 6\n } else if n % 4 == 1 {\n 8\n } else if n % 4 == 2 {\n 4\n } else if n % 4 == 3 {\n 2\n } else {\n 1\n };\n writeln!(out, \"{}\", ans).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\n//const INF: i32 = 0x3f3f3f3f;\n\nstruct Scanner {\n buffer: std::collections::VecDeque\n}\n\nimpl Scanner {\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn next(&mut self) -> T {\n while self.buffer.is_empty() {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).ok();\n self.buffer = input.split_whitespace()\n .map(ToString::to_string).collect();\n }\n let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn main1() {\n let mut scan = Scanner::new();\n let s = scan.next::();\n let l = s.chars().count();\n let n = s.chars().filter(|&ch| ch == 'a').count();\n let ans = min(2 * n - 1, l);\n println!(\"{}\", ans);\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}", "src_uid": "84cb9ad2ae3ba7e912920d7feb4f6219"} {"source_code": "use std::io::{self, BufRead, Write};\nuse std::str::{self, FromStr};\nuse std::fmt::Debug;\n\nconst P: i32 = 998244353;\n\nfn mul(x: i32, y: i32) -> i32 {\n ((x as i64) * (y as i64) % (P as i64)) as i32\n}\n\nfn add_mul(z: i32, x: i32, y: i32) -> i32 {\n ((z as i64 + (x as i64) * (y as i64)) % (P as i64)) as i32\n}\n\n#[allow(unused_variables)]\nfn solve(input: &mut FastDynInput<'_>, output: &mut dyn Write) -> io::Result<()> {\n let n = input.iread() as usize;\n let x = input.iread() as usize;\n let mut res: Vec> = vec![vec![0; x + 1]; n + 1];\n let mut bin: Vec> = vec![vec![0; n + 1]; n + 1];\n for i in 0..=n {\n bin[0][i] = 1;\n }\n for i in 1..=n {\n bin[i][0] = 1;\n for j in 1..=n {\n bin[i][j] = (bin[i - 1][j] + bin[i][j - 1]) % P;\n }\n }\n for i in 2..=n {\n for j in 1..=x {\n let mut cur = 1i32;\n if i - 1 >= j {\n for _ in 0..i {\n cur = mul(cur, j as i32);\n }\n } else {\n for _ in 0..i {\n cur = mul(cur, i as i32 - 1);\n }\n let mut mult = 1i32;\n for left in (2..=i).into_iter().rev() {\n let next = res[left][j - i + 1];\n cur = add_mul(cur, next, mul(mult, bin[left][i - left]));\n mult = mul(mult, i as i32 - 1);\n }\n }\n res[i][j] = cur;\n }\n }\n writeln!(output, \"{}\", res[n][x])?;\n Ok(())\n}\n\n#[test]\nfn test1() {\n test_solve(\"2 5\", \"5\");\n test_solve(\"3 3\", \"15\");\n test_solve(\"5 4\", \"1024\");\n test_solve(\"13 37\", \"976890680\");\n}\n\nfn test_solve(input: &str, output: &str) {\n let mut writer = Vec::new();\n solve(&mut FastDynInput::from(input.as_bytes()), &mut writer).unwrap();\n assert_eq!(bytes_to_str(&writer).split_ascii_whitespace().collect::>(),\n output.split_ascii_whitespace().collect::>());\n}\n\nfn bytes_to_str(vec: &[u8]) -> &str {\n str::from_utf8(vec).unwrap()\n}\n\nstruct FastDynInput<'a> {\n stdin: Box,\n}\n\nimpl<'a, R: BufRead + 'a> From for FastDynInput<'a> {\n fn from(r: R) -> Self {\n Self {\n stdin: Box::new(r),\n }\n }\n}\n\n#[allow(dead_code)]\nimpl FastDynInput<'_> {\n fn read_bytes(&mut self) -> Vec {\n let mut bytes: Vec = Vec::new();\n let mut skip_space = true;\n loop {\n if let Ok(buf) = self.stdin.fill_buf() {\n if buf.is_empty() {\n break;\n }\n let mut pos: usize = 0;\n if skip_space {\n while pos < buf.len() && buf[pos] <= 32 {\n pos += 1;\n }\n if pos < buf.len() {\n skip_space = false;\n } else {\n self.stdin.consume(pos);\n continue;\n }\n }\n while pos < buf.len() && buf[pos] > 32 {\n bytes.push(buf[pos]);\n pos += 1;\n }\n if pos < buf.len() {\n self.stdin.consume(pos);\n break;\n }\n self.stdin.consume(pos);\n } else {\n break;\n }\n }\n bytes\n }\n\n fn read_word(&mut self) -> String {\n String::from_utf8(self.read_bytes()).unwrap()\n }\n\n fn try_read_word(&mut self) -> Option {\n let result = self.read_bytes();\n if result.is_empty() {\n return None;\n }\n String::from_utf8(result).ok()\n }\n\n fn read_line_bytes(&mut self) -> Option> {\n let mut bytes: Vec = Vec::new();\n loop {\n if let Ok(buf) = self.stdin.fill_buf() {\n if buf.is_empty() {\n if bytes.is_empty() {\n return None;\n }\n break;\n }\n let mut pos: usize = 0;\n while pos < buf.len() && buf[pos] != b'\\n' {\n if buf[pos] != b'\\r' {\n bytes.push(buf[pos]);\n }\n pos += 1;\n }\n if pos < buf.len() {\n pos += 1;\n self.stdin.consume(pos);\n break;\n }\n self.stdin.consume(pos);\n } else {\n break;\n }\n }\n Some(bytes)\n }\n\n fn read_line(&mut self) -> String {\n String::from_utf8(self.read_line_bytes().unwrap()).unwrap()\n }\n\n fn try_read_line(&mut self) -> Option {\n String::from_utf8(self.read_line_bytes()?).ok()\n }\n\n fn iread(&mut self) -> i32 {\n self.read()\n }\n\n fn uread(&mut self) -> u32 {\n self.read()\n }\n\n fn dread(&mut self) -> f64 {\n self.read()\n }\n\n fn lread(&mut self) -> i64 {\n self.read()\n }\n\n fn read(&mut self) -> V\n where V: FromStr,\n V::Err: Debug {\n self.read_word().parse::().unwrap()\n }\n\n fn parse(&mut self) -> Result {\n self.read_word().parse::()\n }\n}\n\nfn main() -> io::Result<()> {\n let stdin = io::stdin();\n let mut input = FastDynInput::from(stdin.lock());\n let stdout = io::stdout();\n let stdout_lock = stdout.lock();\n let mut output = io::BufWriter::with_capacity(1 << 16, stdout_lock);\n solve(&mut input, &mut output)\n}\n", "src_uid": "1908d1c8c6b122a4c6633a7af094f17f"} {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(overflowing_literals)]\n#![allow(unused_must_use)]\n#![allow(non_camel_case_types)]\n\nuse std::collections::*;\nuse std::io::*;\nuse std::cmp::{max, min, Ordering};\nuse std::f64::consts::*;\nuse std::mem::{swap, size_of_val, size_of};\nuse std::fs::File;\nuse std::rc::*;\nuse std::ascii::*;\nuse std::ops::*;\nuse std::num::*;\nuse std::process::*;\n//use std::ptr::*;\nuse std::iter::{once, repeat};\n\nconst INF: i32 = std::i32::MAX;\nconst LINF: i64 = std::i64::MAX;\nconst MOD: usize = 1000000007;\n\nstruct Input {\n\tbuffer: Buf,\n}\n\nimpl Input {\n\tfn read_char(&mut self) -> char {\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\tx[0] as char\n\t}\n\tfn read_line(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] < b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] >= b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\n\tfn read_word(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] <= b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] > b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n}\n\nmacro_rules! read {\n () => {};\n\t($inf:ident, $t:ty) => ($inf.read_word().parse::<$t>().expect(\"Parsing error\"));\n\t($inf:ident, $($t:ty),*) => (($($inf.read_word().parse::<$t>().expect(\"Parsing error\")),*));\n}\nfn gcd(mut a: T, mut b: T) -> T\n\twhere T: ShrAssign + BitAnd + Ord + From + Clone + SubAssign + ShlAssign + Copy\n{\n\tlet one = T::from(1);\n\tlet zero = T::from(0);\n\tlet mut ans = 0;\n\tif a < b {\n\t\tswap(&mut a, &mut b);\n\t}\n\twhile b > zero {\n\t\tif (a & one > zero) && (b & one > zero) {\n\t\t\ta -= b;\n\t\t} else if a & one > zero {\n\t\t\tb >>= one;\n\t\t} else if b & one > zero {\n\t\t\ta >>= one;\n\t\t} else {\n\t\t\tans += 1;\n\t\t\ta >>= one;\n\t\t\tb >>= one;\n\t\t}\n\t\tif a < b {\n\t\t\tswap(&mut a, &mut b);\n\t\t}\n\t}\n\ta <<= ans;\n\ta\n}\n\nfn powmod(mut base: X, mut exp: Y, mm: X) -> X\n\twhere X: Copy + Clone + Mul + Rem + From,\n\t Y: ShrAssign + Copy + Clone + BitAnd + From + Ord\n{\n\tlet mut res = X::from(1);\n\twhile exp > Y::from(0) {\n\t\tif exp & Y::from(1) > Y::from(0) {\n\t\t\tres = res * base % mm;\n\t\t}\n\t\tbase = base * base % mm;\n\t\texp >>= Y::from(1);\n\t}\n\tres\n}\n\nfn main() {\n\tmatch std::env::var(\"home\") {\n\t\tOk(_x) => {\n\t\t\tlet mut inf = Input { buffer: BufReader::new(File::open(\"input.txt\").expect(\"File not found\")) };\n\t\t\tlet stdout = stdout();\n\t\t\tlet ostr = stdout.lock();\n\t\t\tlet mut ouf = BufWriter::new(ostr);\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t\tErr(_e) => {\n\t\t\tlet stdin = stdin();\n\t\t\tlet istr = stdin.lock();\n\t\t\tlet mut inf = Input { buffer: BufReader::new(istr) };\n\t\t\tlet stdout = stdout();\n\t\t\tlet ostr = stdout.lock();\n\t\t\tlet mut ouf = BufWriter::new(ostr);\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t}\n}\n\n\nfn solve(inf: &mut Input, ouf: &mut Output) {\n\tlet mut s: Vec = inf.read_line().chars().collect();\n\tlet mut c = 'a';\n\tfor i in 0..s.len() {\n\t\tif c as u8 > b'z' {\n\t\t\tbreak;\n\t\t}\n\t\tif s[i] <= c {\n\t\t\ts[i] = c;\n\t\t\tc = (c as u8 + 1) as char;\n\t\t}\n\t}\n\tif c as u8 > b'z' {\n\t\tfor c in s {\n\t\t\twrite!(ouf, \"{}\", c);\n\t\t}\n\t} else {\n\t\twriteln!(ouf, \"-1\");\n\t}\n}", "src_uid": "f8ad543d499bcc0da0121a71a26db854"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::*;\n#[allow(unused_imports)] use std::iter::*;\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($i:ident . $e:tt : $t:ty; $($a:ident),*) => {\n $( let $a: $t = $i.$e(); )*\n };\n ($i:ident . $e:tt; $($a:ident),*) => {\n $( let $a = $i.$e(); )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.u();\n let a = input.i();\n let a = a - 1;\n let mut d = vec![Vec::new(); n];\n for (i,t) in input.ii(n).enumerate() {\n let i = i as i32;\n d[(i-a).abs() as usize].push(t);\n }\n let sol: i32 = d.into_iter().map(|a| {\n let l = a.len() as i32;\n let s = a.into_iter().sum();\n if s == l { s } else { 0 }\n }).sum();\n println!(\"{}\", sol);\n}\n\n", "src_uid": "4840d571d4ce6e1096bb678b6c100ae5"} {"source_code": "use std::io::BufRead;\r\nuse std::convert::TryInto;\r\n\r\nstruct DigitalRootIt {\r\n cur: Vec\r\n}\r\n\r\nimpl Iterator for DigitalRootIt {\r\n type Item = Vec;\r\n fn next (&mut self) -> Option> {\r\n let mut sum: u64 = self.cur.iter()\r\n .map(|d| *d as u64).sum();\r\n let mut ds = Vec::::new();\r\n while sum > 0 {\r\n ds.push((sum % 10).try_into().unwrap_or(0));\r\n sum /= 10;\r\n }\r\n if ds.is_empty() {\r\n ds.push(0);\r\n }\r\n self.cur = ds;\r\n Some(self.cur.clone())\r\n }\r\n}\r\n\r\ntrait DigitalRootable {\r\n fn digital_rooted(&mut self) -> DigitalRootIt;\r\n}\r\n\r\nimpl DigitalRootable for I \r\n where I: Iterator {\r\n fn digital_rooted(&mut self) -> DigitalRootIt {\r\n let collected = self.collect::>();\r\n DigitalRootIt {cur: collected }\r\n }\r\n}\r\n\r\nfn main() {\r\n let result = std::io::stdin().lock()\r\n .lines().next().unwrap().unwrap()\r\n .chars().map(|c| c.to_digit(10).unwrap_or(0) as u8)\r\n .digital_rooted()\r\n .skip_while(|digits| digits.len() > 1)\r\n .next().unwrap_or(vec![0]);\r\n println!(\"{}\", result.first().unwrap_or(&0));\r\n}\r\n", "src_uid": "477a67877367dc68b3bf5143120ff45d"} {"source_code": "use std::io;\nuse std::fs::File;\n\nfn main() {\n let stdin = io::stdin();\n let buf :Box = if cfg!(feature = \"intxt\") {\n eprintln!(\"file mode\");\n let file = File::open(\"in.txt\").unwrap();\n Box::new(io::BufReader::new(file))\n } else {\n eprintln!(\"stdin mode\");\n Box::new(stdin.lock())\n };\n let mut sc = Scanner::new(buf);\n\n let n :i32 = sc.next();\n let mut vec = Vec::new();\n for _ in 0..n {\n let a :i32 = sc.next();\n vec.push(a);\n }\n vec.sort();\n vec.reverse();\n let mut a = vec[0];\n let mut cnt = 1;\n for x in vec {\n if x != a {\n a = x;\n if x > 0 {\n cnt += 1;\n }\n }\n }\n println!(\"{}\", cnt);\n}\n\n\nstruct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n fn next(&mut self) -> T\n where\n T::Err: std::fmt::Debug,\n {\n if let Some(s) = self.buffer.pop() {\n T::from_str(&s).unwrap()\n } else {\n let mut s = String::new();\n let r = self.reader.read_line(&mut s).unwrap();\n assert!(r > 0);\n self.buffer = s.split_whitespace().rev().map(String::from).collect();\n return self.next();\n }\n }\n}\n", "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"source_code": "fn find_or_not(s: &str, pattern: &str) -> bool {\n let mut begin = 0usize;\n let pattern_len = pattern.len();\n for i in 0..pattern_len{\n match s[begin..].find(&pattern[i..i+1]) {\n Some(target) => {\n begin = begin + target+1;\n },\n None => {\n return false;\n },\n }\n }\n return true;\n}\n\nfn solve(s : &str) {\n let max = if s.len()>4 {\n 1000\n }else {\n s.parse::().unwrap()\n };\n\n let data_base_size = max/8+1;\n let mut data_base : Vec = Vec::with_capacity(data_base_size);\n for i in 0..data_base_size as i32 {\n data_base.push(i*8);\n }\n for would_find in data_base {\n if find_or_not(s, &would_find.to_string()) {\n println!(\"YES\\n{}\",would_find);\n return;\n }\n }\n println!(\"NO\");\n\n}\n\n\nfn other_people_dp_calc(a: &[u8], rem: u8, st: usize, depth: usize, end: usize) -> Option> {\n if depth == end {\n if rem == 0 {\n return Some(vec![0; end]);\n }\n } else {\n for i in st..a.len() {\n let d = a[i] - b'0';\n if depth == 0 && end > 1 && d == 0 {\n continue;\n }\n if let Some(mut b) = other_people_dp_calc(a, (rem * 2 + d) % 8, i + 1, depth + 1, end) {\n /* |\n * a % 8 = 2 |\n * (a*10 + b) % 8 = a%8 * 10%8 + b = (rem * 2 + b) % 8\n */\n b[depth] = i;\n return Some(b);\n }\n }\n }\n None\n}\n\n\n\nfn main() {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let buf = buf.trim();\n //solve(buf);\n for i in 1..4{\n if let Some(b) = other_people_dp_calc(buf.as_bytes(), 0, 0, 0, i) {\n println!(\"YES\");\n for x in b {\n print!(\"{}\", buf.as_bytes()[x] as char);\n }\n return;\n }\n }\n println!(\"NO\");\n}\n", "src_uid": "0a2a5927d24c70aca24fc17aa686499e"} {"source_code": "use std::io::{Read, stdin};\n\nfn main() {\n let mut buf = String::new();\n stdin().read_to_string(&mut buf).unwrap();\n let mut tok = buf.split_whitespace();\n let mut get = || tok.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(usize));\n }\n \n let _n = get!();\n let k = get!();\n let s = get().as_bytes();\n let mut xs = vec![false; 30];\n for &ch in s {\n xs[ch as usize - b'a' as usize] = true;\n }\n let xs: Vec<_> = xs\n .into_iter()\n .enumerate()\n .filter(|(_, v)| *v)\n .collect();\n \n if k * 2 > 26 || xs.len() < k {\n println!(\"-1\");\n return;\n }\n \n let mut ans = 0;\n let mut b = 27;\n let mut c = 0;\n for (i, _) in xs.iter() {\n let i = *i;\n if b + 1 != i {\n ans += i + 1;\n b = i;\n c += 1;\n if c >= k {\n break;\n }\n }\n }\n if c < k {\n println!(\"-1\");\n } else {\n println!(\"{}\", ans);\n }\n \n}", "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.i();\n let a = input.i();\n let b = input.i();\n println!(\"{}\", (n - a).min(b + 1));\n}\n\n", "src_uid": "51a072916bff600922a77da0c4582180"} {"source_code": "pub mod solution {\n\nuse crate::io::input::Input;\nuse crate::io::output::output;\nuse crate::math::gcd::{gcd, lcm};\nuse crate::math::modulo::Mod_998_244_353;\nuse crate::misc::num_traits::ConvI32;\nuse crate::{dbg, out, out_line};\n\ntype Mod = Mod_998_244_353;\n\nfn solve(input: &mut Input, _test_case: usize) {\n let n = input.usize();\n let a0 = input.i64();\n let x = input.i64();\n let y = input.i64();\n let k = input.usize();\n let m = input.i64();\n\n let mut max = 1;\n for x in 2..=k {\n max = lcm(max, x);\n }\n\n let pr_choose = Mod::ONE / Mod::new(n as i32);\n let pr_not_choose = Mod::ONE - pr_choose;\n\n let mut dp = vec![Mod::ZERO; max];\n for i in (1..=k).rev() {\n for start in (0..max).step_by(i) {\n for shift in (0..i).rev() {\n let j = start + shift;\n dp[j] = pr_choose * (dp[start] + Mod::new(j as i32)) + pr_not_choose * dp[j];\n }\n }\n }\n\n let f = |value: i64| -> Mod {\n let value = value.to_i32() as usize;\n let more = value / dp.len() * dp.len();\n dp[value - more] + pr_choose * Mod::new(k as i32) * Mod::new(more as i32)\n };\n let mut res = f(a0);\n let mut prev = a0;\n for _ in 1..n {\n prev = (prev * x + y) % m;\n res += f(prev);\n }\n res *= Mod::new(n as i32).pown(k);\n out_line!(res);\n}\n\npub(crate) fn run(mut input: Input) -> bool {\n solve(&mut input, 1);\n output().flush();\n input.skip_whitespace();\n input.peek().is_none()\n}\n\n}\npub mod io {\npub mod input {\nuse crate::misc::ord_f64::OrdF64;\nuse std::fmt::Debug;\nuse std::io::Read;\nuse std::marker::PhantomData;\nuse std::str::FromStr;\n\npub struct Input<'s> {\n input: &'s mut dyn Read,\n buf: Vec,\n at: usize,\n buf_read: usize,\n}\n\nmacro_rules! read_integer_fun {\n ($t:ident) => {\n #[allow(unused)]\n pub fn $t(&mut self) -> $t {\n self.read_integer()\n }\n };\n}\n\nimpl<'s> Input<'s> {\n const DEFAULT_BUF_SIZE: usize = 4096;\n\n ///\n /// Using with stdin:\n /// ```\n /// use algo_lib::io::input::Input;\n /// let mut stdin = std::io::stdin();\n /// let input = Input::new(&mut stdin);\n /// ```\n ///\n /// Using file file:\n /// ```\n /// use algo_lib::io::input::Input;\n /// let mut file = std::fs::File::open(\"input.txt\").unwrap();\n /// let input = Input::new(&mut file);\n ///```\n ///\n ///\n pub fn new(input: &'s mut dyn Read) -> Self {\n Self {\n input,\n buf: vec![0; Self::DEFAULT_BUF_SIZE],\n at: 0,\n buf_read: 0,\n }\n }\n\n pub fn new_with_size(input: &'s mut dyn Read, buf_size: usize) -> Self {\n Self {\n input,\n buf: vec![0; buf_size],\n at: 0,\n buf_read: 0,\n }\n }\n\n pub fn get(&mut self) -> Option {\n if self.refill_buffer() {\n let res = self.buf[self.at];\n self.at += 1;\n Some(res)\n } else {\n None\n }\n }\n\n pub fn peek(&mut self) -> Option {\n if self.refill_buffer() {\n Some(self.buf[self.at])\n } else {\n None\n }\n }\n\n pub fn skip_whitespace(&mut self) {\n while let Some(b) = self.peek() {\n if !char::from(b).is_whitespace() {\n return;\n }\n self.get();\n }\n }\n\n pub fn next_token(&mut self) -> Option> {\n self.skip_whitespace();\n let mut res = Vec::new();\n while let Some(c) = self.get() {\n if char::from(c).is_whitespace() {\n break;\n }\n res.push(c);\n }\n if res.is_empty() {\n None\n } else {\n Some(res)\n }\n }\n\n //noinspection RsSelfConvention\n pub fn is_exhausted(&mut self) -> bool {\n self.peek().is_none()\n }\n\n pub fn has_more_elements(&mut self) -> bool {\n !self.is_exhausted()\n }\n\n pub fn read(&mut self) -> T {\n T::read(self)\n }\n\n pub fn read_vec(&mut self, size: usize) -> Vec {\n let mut res = Vec::with_capacity(size);\n for _ in 0usize..size {\n res.push(self.read());\n }\n res\n }\n\n pub fn read_line(&mut self) -> String {\n let mut res = String::new();\n while let Some(c) = self.get() {\n if c == b'\\n' {\n break;\n }\n if c == b'\\r' {\n if self.peek() == Some(b'\\n') {\n self.get();\n }\n break;\n }\n res.push(c.into());\n }\n res\n }\n\n #[allow(clippy::should_implement_trait)]\n pub fn into_iter(self) -> InputIterator<'s, T> {\n InputIterator {\n input: self,\n phantom: Default::default(),\n }\n }\n\n fn read_integer(&mut self) -> T\n where\n ::Err: Debug,\n {\n let res = self.read_string();\n res.parse::().unwrap()\n }\n\n fn read_string(&mut self) -> String {\n match self.next_token() {\n None => {\n panic!(\"Input exhausted\");\n }\n Some(res) => unsafe { String::from_utf8_unchecked(res) },\n }\n }\n\n pub fn string(&mut self) -> String {\n self.read_string()\n }\n\n pub fn string_as_vec(&mut self) -> Vec {\n self.read_string().into_bytes()\n }\n\n fn read_char(&mut self) -> char {\n self.skip_whitespace();\n self.get().unwrap().into()\n }\n\n fn read_float(&mut self) -> OrdF64 {\n self.read_string().parse().unwrap()\n }\n\n pub fn f64(&mut self) -> OrdF64 {\n self.read_float()\n }\n\n fn refill_buffer(&mut self) -> bool {\n if self.at == self.buf_read {\n self.at = 0;\n self.buf_read = self.input.read(&mut self.buf).unwrap();\n self.buf_read != 0\n } else {\n true\n }\n }\n\n read_integer_fun!(i32);\n read_integer_fun!(i64);\n read_integer_fun!(u32);\n read_integer_fun!(u64);\n read_integer_fun!(usize);\n}\n\npub trait Readable {\n fn read(input: &mut Input) -> Self;\n}\n\nimpl Readable for String {\n fn read(input: &mut Input) -> Self {\n input.read_string()\n }\n}\n\nimpl Readable for char {\n fn read(input: &mut Input) -> Self {\n input.read_char()\n }\n}\n\nimpl Readable for f64 {\n fn read(input: &mut Input) -> Self {\n input.read_string().parse().unwrap()\n }\n}\n\nimpl Readable for Vec {\n fn read(input: &mut Input) -> Self {\n let size = input.read();\n input.read_vec(size)\n }\n}\n\npub struct InputIterator<'s, T: Readable> {\n input: Input<'s>,\n phantom: PhantomData,\n}\n\nimpl<'s, T: Readable> Iterator for InputIterator<'s, T> {\n type Item = T;\n\n fn next(&mut self) -> Option {\n self.input.skip_whitespace();\n self.input.peek().map(|_| self.input.read())\n }\n}\n\nmacro_rules! read_integer {\n ($t:ident) => {\n impl Readable for $t {\n fn read(input: &mut Input) -> Self {\n input.read_integer()\n }\n }\n };\n}\n\nread_integer!(i8);\nread_integer!(i16);\nread_integer!(i32);\nread_integer!(i64);\nread_integer!(i128);\nread_integer!(isize);\nread_integer!(u8);\nread_integer!(u16);\nread_integer!(u32);\nread_integer!(u64);\nread_integer!(u128);\nread_integer!(usize);\n\nmacro_rules! tuple_readable {\n ( $( $name:ident )+ ) => {\n impl<$($name: Readable), +> Readable for ($($name,)+) {\n fn read(input: &mut Input) -> Self {\n ($($name::read(input),)+)\n }\n }\n }\n}\n\ntuple_readable! {T}\ntuple_readable! {T U}\ntuple_readable! {T U V}\ntuple_readable! {T U V X}\ntuple_readable! {T U V X Y}\ntuple_readable! {T U V X Y Z}\ntuple_readable! {T U V X Y Z A}\ntuple_readable! {T U V X Y Z A B}\ntuple_readable! {T U V X Y Z A B C}\ntuple_readable! {T U V X Y Z A B C D}\ntuple_readable! {T U V X Y Z A B C D E}\ntuple_readable! {T U V X Y Z A B C D E F}\n}\npub mod output {\nuse std::io::Write;\n\npub struct Output {\n output: Box,\n buf: Vec,\n at: usize,\n auto_flush: bool,\n}\n\nimpl Output {\n const DEFAULT_BUF_SIZE: usize = 4096;\n\n pub fn new(output: Box) -> Self {\n Self {\n output,\n buf: vec![0; Self::DEFAULT_BUF_SIZE],\n at: 0,\n auto_flush: false,\n }\n }\n\n pub fn new_with_auto_flush(output: Box) -> Self {\n Self {\n output,\n buf: vec![0; Self::DEFAULT_BUF_SIZE],\n at: 0,\n auto_flush: true,\n }\n }\n\n pub fn flush(&mut self) {\n if self.at != 0 {\n self.output.write_all(&self.buf[..self.at]).unwrap();\n self.at = 0;\n self.output.flush().expect(\"Couldn't flush output\");\n }\n }\n\n pub fn print(&mut self, s: &T) {\n s.write(self);\n }\n\n pub fn put(&mut self, b: u8) {\n self.buf[self.at] = b;\n self.at += 1;\n if self.at == self.buf.len() {\n self.flush();\n }\n }\n\n pub fn maybe_flush(&mut self) {\n if self.auto_flush {\n self.flush();\n }\n }\n\n pub fn print_per_line(&mut self, arg: &[T]) {\n for i in arg {\n i.write(self);\n self.put(b'\\n');\n }\n }\n\n pub fn print_iter>(&mut self, iter: I) {\n let mut first = true;\n for e in iter {\n if first {\n first = false;\n } else {\n self.put(b' ');\n }\n e.write(self);\n }\n }\n\n pub fn print_iter_ref<'a, T: 'a + Writable, I: Iterator>(&mut self, iter: I) {\n let mut first = true;\n for e in iter {\n if first {\n first = false;\n } else {\n self.put(b' ');\n }\n e.write(self);\n }\n }\n}\n\nimpl Write for Output {\n fn write(&mut self, buf: &[u8]) -> std::io::Result {\n let mut start = 0usize;\n let mut rem = buf.len();\n while rem > 0 {\n let len = (self.buf.len() - self.at).min(rem);\n self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);\n self.at += len;\n if self.at == self.buf.len() {\n self.flush();\n }\n start += len;\n rem -= len;\n }\n if self.auto_flush {\n self.flush();\n }\n Ok(buf.len())\n }\n\n fn flush(&mut self) -> std::io::Result<()> {\n self.flush();\n Ok(())\n }\n}\n\npub trait Writable {\n fn write(&self, output: &mut Output);\n}\n\nimpl Writable for &str {\n fn write(&self, output: &mut Output) {\n output.write_all(self.as_bytes()).unwrap();\n }\n}\n\nimpl Writable for String {\n fn write(&self, output: &mut Output) {\n output.write_all(self.as_bytes()).unwrap();\n }\n}\n\nimpl Writable for char {\n fn write(&self, output: &mut Output) {\n output.put(*self as u8);\n }\n}\n\nimpl Writable for [T] {\n fn write(&self, output: &mut Output) {\n output.print_iter_ref(self.iter());\n }\n}\n\nimpl Writable for Vec {\n fn write(&self, output: &mut Output) {\n self[..].write(output);\n }\n}\n\nmacro_rules! write_to_string {\n ($t:ident) => {\n impl Writable for $t {\n fn write(&self, output: &mut Output) {\n self.to_string().write(output);\n }\n }\n };\n}\n\nwrite_to_string!(u8);\nwrite_to_string!(u16);\nwrite_to_string!(u32);\nwrite_to_string!(u64);\nwrite_to_string!(u128);\nwrite_to_string!(usize);\nwrite_to_string!(i8);\nwrite_to_string!(i16);\nwrite_to_string!(i32);\nwrite_to_string!(i64);\nwrite_to_string!(i128);\nwrite_to_string!(isize);\nwrite_to_string!(f32);\nwrite_to_string!(f64);\n\nimpl Writable for (T, U) {\n fn write(&self, output: &mut Output) {\n self.0.write(output);\n output.put(b' ');\n self.1.write(output);\n }\n}\n\nimpl Writable for (T, U, V) {\n fn write(&self, output: &mut Output) {\n self.0.write(output);\n output.put(b' ');\n self.1.write(output);\n output.put(b' ');\n self.2.write(output);\n }\n}\n\npub static mut OUTPUT: Option = None;\n\npub fn set_global_output_to_stdout() {\n unsafe {\n OUTPUT = Some(Output::new(Box::new(std::io::stdout())));\n }\n}\n\npub fn output() -> &'static mut Output {\n unsafe {\n match &mut OUTPUT {\n None => {\n panic!(\"Panic\");\n }\n Some(output) => output,\n }\n }\n}\n\n#[macro_export]\nmacro_rules! out {\n ($first: expr $(,$args:expr )*) => {\n output().print(&$first);\n $(output().put(b' ');\n output().print(&$args);\n )*\n }\n}\n\n#[macro_export]\nmacro_rules! out_line {\n ($first: expr $(, $args:expr )* ) => {\n out!($first $(,$args)*);\n output().put(b'\\n');\n };\n () => {\n output().put(b'\\n');\n };\n}\n}\n}\npub mod math {\npub mod gcd {\nuse crate::misc::num_traits::Number;\n\n#[allow(dead_code)]\nfn extended_gcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {\n if a == 0 {\n *x = 0;\n *y = 1;\n return b;\n }\n let mut x1 = 0;\n let mut y1 = 0;\n let d = extended_gcd(b % a, a, &mut x1, &mut y1);\n *x = y1 - (b / a) * x1;\n *y = x1;\n d\n}\n\n///\n///\n/// Find any solution to equation A*x + B*y = C\n///\n/// Returns [false] if [C] is not divisible by gcd(A, B)\n///\n#[allow(dead_code)]\npub fn diophantine(a: i64, b: i64, c: i64, x0: &mut i64, y0: &mut i64, g: &mut i64) -> bool {\n *g = extended_gcd(a.abs(), b.abs(), x0, y0);\n if c % *g != 0 {\n return false;\n }\n *x0 *= c / *g;\n *y0 *= c / *g;\n if a < 0 {\n *x0 *= -1;\n }\n if b < 0 {\n *y0 *= -1;\n }\n true\n}\n\n#[allow(dead_code)]\npub fn gcd(x: T, y: T) -> T\nwhere\n T: Number + std::ops::Rem,\n{\n if x == T::ZERO {\n y\n } else {\n gcd(y % x, x)\n }\n}\n\npub fn lcm(x: T, y: T) -> T\nwhere\n T: Number + std::ops::Rem,\n{\n x / gcd(x, y) * y\n}\n}\npub mod modulo {\nuse crate::io::output::{Output, Writable};\nuse crate::misc::num_traits::{ConvI32, HasConstants};\nuse std::io::Write;\nuse std::marker::PhantomData;\n\npub trait Value: Clone + Copy {\n fn val() -> i32;\n}\n\n#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd)]\npub struct ModWithValue(i32, PhantomData)\nwhere\n M: Value;\n\nimpl ModWithValue\nwhere\n M: Value,\n{\n #[allow(unused)]\n pub const ZERO: Self = Self(0, PhantomData);\n\n #[allow(unused)]\n pub const ONE: Self = Self(1, PhantomData);\n\n #[allow(unused)]\n pub const TWO: Self = Self(2, PhantomData);\n\n fn rev_rec(a: i32, m: i32) -> i32 {\n if a == 1 {\n return a;\n }\n return ((1 - Self::rev_rec(m % a, a) as i64 * m as i64) / a as i64 + m as i64) as i32;\n }\n\n #[allow(dead_code)]\n fn inv(self) -> Self {\n ModWithValue(Self::rev_rec(self.0, M::val()), PhantomData)\n }\n\n #[allow(dead_code)]\n pub fn new(mut x: i32) -> Self {\n if x < 0 {\n x += M::val();\n if x < 0 {\n x %= M::val();\n x += M::val();\n }\n } else if x >= M::val() {\n x -= M::val();\n if x >= M::val() {\n x %= M::val();\n }\n }\n assert!(0 <= x && x < M::val());\n Self(x, PhantomData)\n }\n\n pub fn pown(self, pw: usize) -> Self {\n if pw == 0 {\n Self::ONE\n } else if pw == 1 {\n self\n } else {\n let half = self.pown(pw / 2);\n let res = half * half;\n if pw % 2 == 0 {\n res\n } else {\n res * self\n }\n }\n }\n}\n\nimpl std::fmt::Display for ModWithValue\nwhere\n M: Value,\n{\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n\nimpl std::fmt::Debug for ModWithValue\nwhere\n M: Value + Copy + Eq,\n{\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n const MAX: usize = 100;\n if self.0 <= MAX as i32 {\n write!(f, \"{}\", self.0)\n } else if self.0 >= M::val() - MAX as i32 {\n write!(f, \"-{}\", M::val() - self.0)\n } else {\n for denum in 1..MAX {\n for num in 1..MAX {\n if Self(num as i32, PhantomData) / Self(denum as i32, PhantomData) == *self {\n return write!(f, \"{}/{}\", num, denum);\n }\n }\n }\n write!(f, \"(?? {} ??)\", self.0)\n }\n }\n}\n\nimpl std::ops::Add for ModWithValue\nwhere\n M: Value,\n{\n type Output = Self;\n\n fn add(self, rhs: Self) -> Self::Output {\n let res = self.0 + rhs.0;\n if res >= M::val() {\n ModWithValue(res - M::val(), PhantomData)\n } else {\n ModWithValue(res, PhantomData)\n }\n }\n}\n\nimpl std::ops::AddAssign for ModWithValue\nwhere\n M: Value,\n{\n fn add_assign(&mut self, rhs: Self) {\n self.0 += rhs.0;\n if self.0 >= M::val() {\n self.0 -= M::val();\n }\n }\n}\n\nimpl std::ops::Sub for ModWithValue\nwhere\n M: Value,\n{\n type Output = Self;\n\n fn sub(self, rhs: Self) -> Self::Output {\n let res = self.0 - rhs.0;\n if res < 0 {\n ModWithValue(res + M::val(), PhantomData)\n } else {\n ModWithValue(res, PhantomData)\n }\n }\n}\n\nimpl std::ops::SubAssign for ModWithValue\nwhere\n M: Value,\n{\n fn sub_assign(&mut self, rhs: Self) {\n self.0 -= rhs.0;\n if self.0 < 0 {\n self.0 += M::val();\n }\n }\n}\n\nimpl std::ops::Mul for ModWithValue\nwhere\n M: Value,\n{\n type Output = Self;\n\n fn mul(self, rhs: Self) -> Self::Output {\n let res = (self.0 as i64) * (rhs.0 as i64) % (M::val() as i64);\n ModWithValue(res as i32, PhantomData)\n }\n}\n\nimpl std::ops::MulAssign for ModWithValue\nwhere\n M: Value,\n{\n fn mul_assign(&mut self, rhs: Self) {\n self.0 = ((self.0 as i64) * (rhs.0 as i64) % (M::val() as i64)) as i32;\n }\n}\n\nimpl std::ops::Div for ModWithValue\nwhere\n M: Value,\n{\n type Output = Self;\n\n fn div(self, rhs: Self) -> Self::Output {\n let rhs_inv = rhs.inv();\n self * rhs_inv\n }\n}\n\nimpl std::ops::DivAssign for ModWithValue\nwhere\n M: Value,\n{\n fn div_assign(&mut self, rhs: Self) {\n *self *= rhs.inv();\n }\n}\n\nimpl Writable for ModWithValue\nwhere\n M: Value,\n{\n fn write(&self, output: &mut Output) {\n output.write_fmt(format_args!(\"{}\", self.0)).unwrap();\n }\n}\n\nimpl HasConstants> for ModWithValue\nwhere\n M: Value,\n{\n // This doesn't make much sense, but hope we never use\n const MAX: ModWithValue = ModWithValue::ZERO;\n const MIN: ModWithValue = ModWithValue::ZERO;\n const ZERO: ModWithValue = ModWithValue::ZERO;\n const ONE: ModWithValue = ModWithValue::ONE;\n const TWO: ModWithValue = ModWithValue::TWO;\n}\n\nimpl ConvI32> for ModWithValue\nwhere\n M: Value,\n{\n fn from_i32(val: i32) -> ModWithValue {\n ModWithValue::new(val)\n }\n\n fn to_i32(self) -> i32 {\n self.0\n }\n}\n\npub trait ConstValue: Value + Copy {\n const VAL: i32;\n}\n\nimpl Value for V {\n fn val() -> i32 {\n Self::VAL\n }\n}\n\n#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd)]\npub struct Value7();\nimpl ConstValue for Value7 {\n const VAL: i32 = 1_000_000_007;\n}\npub type Mod7 = ModWithValue;\n\n#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd)]\npub struct Value9();\nimpl ConstValue for Value9 {\n const VAL: i32 = 1_000_000_009;\n}\npub type Mod9 = ModWithValue;\n\n#[derive(Copy, Clone, Eq, PartialEq, Default, Ord, PartialOrd)]\n#[allow(non_camel_case_types)]\npub struct Value_998_244_353();\nimpl ConstValue for Value_998_244_353 {\n const VAL: i32 = 998_244_353;\n}\n#[allow(non_camel_case_types)]\npub type Mod_998_244_353 = ModWithValue;\n\n#[cfg(test)]\nmod tests {\nuse crate::math::modulo::*;\n\n type Mod = Mod7;\n\n #[test]\n fn add() {\n let x = Mod::new(1);\n let y = Mod::new(2);\n assert_eq!(format!(\"{}\", x + y), \"3\");\n }\n\n #[test]\n fn sub() {\n let x = Mod::new(1);\n let y = Mod::new(2);\n assert_eq!(format!(\"{}\", x - y), \"1000000006\");\n assert_eq!(format!(\"{:?}\", x - y), \"-1\");\n }\n\n #[test]\n fn mul() {\n let x = Mod::new(3);\n let y = Mod::new(5);\n assert_eq!(format!(\"{}\", x * y), \"15\");\n }\n\n #[test]\n fn div() {\n let x = Mod::new(3);\n let y = Mod::new(5);\n assert_eq!(format!(\"{}\", x / y), \"200000002\");\n assert_eq!(format!(\"{:?}\", x / y), \"3/5\");\n }\n\n #[test]\n fn div_assign() {\n let mut x = Mod::new(3);\n let y = Mod::new(5);\n x /= y;\n assert_eq!(format!(\"{}\", x), \"200000002\");\n assert_eq!(format!(\"{:?}\", x), \"3/5\");\n }\n\n #[test]\n fn dbg_format() {\n let x = Mod::new(1) / Mod::new(2);\n let y = Mod::new(1) / Mod::new(3);\n assert_eq!(format!(\"{}\", x + y), \"833333340\");\n assert_eq!(format!(\"{:?}\", x + y), \"5/6\");\n }\n\n #[test]\n fn dbg_format_big() {\n let x = Mod::new(123) / Mod::new(457);\n assert_eq!(format!(\"{:?}\", x), \"(?? 262582059 ??)\");\n }\n\n #[test]\n fn dbg_format_more() {\n assert_eq!(format!(\"{:?}\", Mod::new(1)), \"1\");\n assert_eq!(format!(\"{:?}\", Mod::new(3)), \"3\");\n assert_eq!(format!(\"{:?}\", Mod::new(-5)), \"-5\");\n }\n\n #[test]\n fn consts() {\n let one = Mod::ONE - Mod::ZERO;\n assert_eq!(format!(\"{:?}\", one), \"1\");\n }\n}\n}\n}\npub mod misc {\npub mod dbg_macro {\n#[macro_export]\n#[allow(unused_macros)]\nmacro_rules! dbg {\n ($first_val:expr, $($val:expr),+ $(,)?) => {\n eprint!(\"[{}:{}] {} = {:?}\",\n file!(), line!(), stringify!($first_val), &$first_val);\n ($(eprint!(\", {} = {:?}\", stringify!($val), &$val)),+,);\n eprintln!();\n };\n ($first_val:expr) => {\n eprintln!(\"[{}:{}] {} = {:?}\",\n file!(), line!(), stringify!($first_val), &$first_val);\n };\n}\n}\npub mod num_traits {\nuse std::fmt::Debug;\nuse std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};\n\npub trait HasConstants {\n const MAX: T;\n const MIN: T;\n const ZERO: T;\n const ONE: T;\n const TWO: T;\n}\n\npub trait ConvI32 {\n fn from_i32(val: i32) -> T;\n fn to_i32(self) -> i32;\n}\n\npub trait Number:\n Copy\n + Add\n + AddAssign\n + Sub\n + SubAssign\n + Mul\n + MulAssign\n + Div\n + DivAssign\n + Ord\n + PartialOrd\n + Eq\n + PartialEq\n + HasConstants\n + Default\n + Debug\n + Sized\n + ConvI32\n{\n}\n\nimpl<\n T: Copy\n + Add\n + AddAssign\n + Sub\n + SubAssign\n + Mul\n + MulAssign\n + Div\n + DivAssign\n + Ord\n + PartialOrd\n + Eq\n + PartialEq\n + HasConstants\n + Default\n + Debug\n + Sized\n + ConvI32,\n > Number for T\n{\n}\n\nmacro_rules! has_constants_impl {\n ($t: ident) => {\n impl HasConstants<$t> for $t {\n const MAX: $t = $t::MAX;\n const MIN: $t = $t::MIN;\n const ZERO: $t = 0;\n const ONE: $t = 1;\n const TWO: $t = 2;\n }\n\n impl ConvI32<$t> for $t {\n fn from_i32(val: i32) -> $t {\n val as $t\n }\n\n fn to_i32(self) -> i32 {\n self as i32\n }\n }\n };\n}\n\nhas_constants_impl!(i32);\nhas_constants_impl!(i64);\nhas_constants_impl!(i128);\nhas_constants_impl!(u32);\nhas_constants_impl!(u64);\nhas_constants_impl!(u128);\nhas_constants_impl!(usize);\nhas_constants_impl!(u8);\n\nimpl ConvI32 for f64 {\n fn from_i32(val: i32) -> Self {\n val as f64\n }\n\n fn to_i32(self) -> i32 {\n self as i32\n }\n}\n\nimpl HasConstants for f64 {\n const MAX: Self = Self::MAX;\n const MIN: Self = -Self::MAX;\n const ZERO: Self = 0.0;\n const ONE: Self = 1.0;\n const TWO: Self = 2.0;\n}\n}\npub mod ord_f64 {\nuse crate::io::input::{Input, Readable};\nuse crate::io::output::{Output, Writable};\nuse crate::misc::num_traits::{ConvI32, HasConstants};\nuse std::cmp::{min, Ordering};\nuse std::fmt::{Debug, Display, Formatter};\nuse std::io::Write;\nuse std::ops::Neg;\nuse std::str::FromStr;\nuse std::num::ParseFloatError;\n\n#[derive(PartialOrd, PartialEq, Copy, Clone, Default)]\npub struct OrdF64(pub f64);\n\nimpl OrdF64 {\n pub(crate) const EPS: Self = Self(1e-9);\n\n pub fn abs(&self) -> Self {\n Self(self.0.abs())\n }\n\n pub fn eq_with_eps(&self, other: &Self) -> bool {\n let abs_diff = (*self - *other).abs();\n abs_diff <= Self::EPS || abs_diff <= min(self.abs(), other.abs()) * Self::EPS\n }\n\n pub fn sqrt(&self) -> Self {\n Self(self.0.sqrt())\n }\n\n pub fn powf(&self, n: f64) -> Self {\n Self(self.0.powf(n))\n }\n}\n\nimpl Eq for OrdF64 {}\n\nimpl Ord for OrdF64 {\n fn cmp(&self, other: &Self) -> Ordering {\n self.partial_cmp(other).unwrap()\n }\n}\n\nimpl std::ops::Add for OrdF64 {\n type Output = Self;\n\n fn add(self, rhs: Self) -> Self::Output {\n Self(self.0 + rhs.0)\n }\n}\n\nimpl std::ops::AddAssign for OrdF64 {\n fn add_assign(&mut self, rhs: Self) {\n self.0 += rhs.0;\n }\n}\n\nimpl std::ops::Sub for OrdF64 {\n type Output = Self;\n\n fn sub(self, rhs: Self) -> Self::Output {\n Self(self.0 - rhs.0)\n }\n}\n\nimpl std::ops::SubAssign for OrdF64 {\n fn sub_assign(&mut self, rhs: Self) {\n self.0 -= rhs.0;\n }\n}\n\nimpl std::ops::Mul for OrdF64 {\n type Output = Self;\n\n fn mul(self, rhs: Self) -> Self::Output {\n Self(self.0 * rhs.0)\n }\n}\n\nimpl std::ops::MulAssign for OrdF64 {\n fn mul_assign(&mut self, rhs: Self) {\n self.0 *= rhs.0;\n }\n}\n\nimpl std::ops::Div for OrdF64 {\n type Output = Self;\n\n fn div(self, rhs: Self) -> Self::Output {\n Self(self.0 / rhs.0)\n }\n}\n\nimpl std::ops::DivAssign for OrdF64 {\n fn div_assign(&mut self, rhs: Self) {\n self.0 /= rhs.0;\n }\n}\n\nimpl Neg for OrdF64 {\n type Output = Self;\n\n fn neg(self) -> Self::Output {\n Self(-self.0)\n }\n}\n\nimpl Display for OrdF64 {\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n Display::fmt(&self.0, f)\n }\n}\n\nimpl Debug for OrdF64 {\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n Debug::fmt(&self.0, f)\n }\n}\n\nimpl Writable for OrdF64 {\n fn write(&self, output: &mut Output) {\n output.write_fmt(format_args!(\"{}\", self.0)).unwrap();\n }\n}\n\nimpl Readable for OrdF64 {\n fn read(input: &mut Input) -> Self {\n Self(input.read::())\n }\n}\n\nimpl HasConstants for OrdF64 {\n const MAX: Self = Self(f64::MAX);\n const MIN: Self = Self(-f64::MAX);\n const ZERO: Self = Self(0.0);\n const ONE: Self = Self(1.0);\n const TWO: Self = Self(2.0);\n}\n\nimpl ConvI32 for OrdF64 {\n fn from_i32(val: i32) -> Self {\n Self(val as f64)\n }\n\n fn to_i32(self) -> i32 {\n self.0 as i32\n }\n}\n\nimpl FromStr for OrdF64 {\n type Err = ParseFloatError;\n\n fn from_str(s: &str) -> Result {\n match s.parse::() {\n | Ok(value ) => Ok(Self(value)),\n | Err(error) => Err(error),\n }\n }\n}\n}\n}\nfn main() {\n let mut sin = std::io::stdin();\n let input = crate::io::input::Input::new(&mut sin);\n unsafe {\n crate::io::output::OUTPUT = Some(crate::io::output::Output::new(Box::new(std::io::stdout())));\n }\n crate::solution::run(input);\n}\n", "src_uid": "1d45491e28d24e2b318605cd328d6ecf"} {"source_code": "use std::io::stdin;\nfn main() {\n let evolutions = [\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"];\n \n let mut entry = String::new();\n stdin().read_line(&mut entry).unwrap();\n let len:usize = entry.trim().parse().unwrap();\n entry.clear();\n stdin().read_line(&mut entry).unwrap();\n let name = entry.trim();\n let mut coord:Vec<(char, usize)> = vec!();\n for (i, c) in name.chars().enumerate(){\n if c != '.' {\n coord.push((c, i));\n }\n }\n for ev in evolutions.iter() {\n if len == ev.len(){\n let mut is_it = true;\n let chars :Vec = ev.chars().collect();\n for i in &coord{\n if i.0 != chars[i.1] {\n is_it = false;\n break;\n }\n }\n if is_it {\n println!(\"{}\", ev);\n break;\n }\n }\n }\n}\n\n\n", "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"source_code": "fn main() {\n let mut text = String::new();\n std::io::stdin().read_line(&mut text).expect(\"\");\n let n = text.trim().parse::().expect(\"\");\n\n if n > 3 && n % 2 == 1 {\n println!(\"1 {}\", (n - 3) / 2)\n } else {\n println!(\"NO\")\n }\n}\n", "src_uid": "3ff1c25a1026c90aeb14d148d7fb96ba"} {"source_code": "macro_rules! parse_line {\n ($t: ty) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let a_str = a_str.trim();\n a_str.parse::<$t>().expect(\"parse error\")\n });\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().expect(\"parse error\"),\n )+\n )\n })\n}\n\nmacro_rules! parse_line_to_vec {\n ($t: ty) => {{\n let mut a_str = String::new();\n std::io::stdin().read_line(&mut a_str).expect(\"read error\");\n (a_str\n .split_whitespace()\n .map(|x| x.parse::<$t>().unwrap())\n .collect::>())\n }};\n}\n\nfn solve() {\n let mut n = parse_line!(u64);\n if n == 1 {\n println!(\"1 0\");\n return;\n }\n let mut max: u64 = 0;\n let mut min = std::u64::MAX;\n let mut val: u64 = 1;\n for i in 2..n {\n if i * i > n {\n break;\n }\n if n % i != 0 {\n continue;\n }\n val *= i;\n let mut cnt = 0;\n while n % i == 0 {\n n /= i;\n cnt += 1;\n }\n max = std::cmp::max(max, cnt);\n min = std::cmp::min(min, cnt);\n }\n if n != 1 {\n max = std::cmp::max(max, 1);\n min = std::cmp::min(min, 1);\n val *= n;\n }\n let mult = if max != min || max & (max - 1) != 0 {1} else {0};\n if max & (max - 1) != 0 {\n max <<= 1;\n }\n while max & (max - 1) != 0 {\n max &= max - 1;\n }\n println!(\"{} {}\", val, mult + max.trailing_zeros());\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n", "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"source_code": "#![allow(unused_imports)]\nuse std::io::{self, BufRead};\nuse std::cmp::*;\nuse std::collections::*;\n\nmacro_rules! scan_to_vec {\n ($count:expr, $t:ty) => ({\n let mut result = Vec::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n\n for _ in 0..$count {\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_to_vec: failed at `handle.read_line`.\");\n result.push(buffer.trim().parse::<$t>()\n .expect(\"scan_to_vec: failed at `parse::<$t>`.\"));\n }\n result\n })\n}\n\nmacro_rules! scan_line_to_vec {\n ($t:ty) => ({\n let mut result = Vec::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n handle.read_line(&mut buffer)\n .expect(\"scan_line_to_vec: failed at `handle.read_line`.\");\n \n for s in chunks.split_whitespace() {\n result.push(s.parse::<$t>()\n .expect(\"scan_line_to_vec: failed at `parse::<$t>`.\"));\n }\n result\n })\n}\n\nmacro_rules! scan_line {\n () => ({\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line: failed at `handle.read_line`.\");\n buffer\n });\n ( $($t:ty)+ ) => ({\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line: failed at `handle.read_line`.\");\n let mut chunks = buffer.split_whitespace();\n\n ($(\n {\n chunks.next()\n .expect(\"scan_line: failed at `next`, # of space separated strings not equal to requested #\")\n .parse::<$t>()\n .expect(\"scan_line: failed at `parse::<$t>`.\")\n },\n )+)\n })\n}\n\nfn main() {\n let (l, r) = scan_line!(i64 i64);\n if l == r {\n println!(\"{}\", l);\n } else {\n println!(\"2\");\n }\n}", "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::io::stdin;\n\nmod util {\n use std::io::stdin;\n use std::str::FromStr;\n use std::fmt::Debug;\n\n #[allow(dead_code)]\n pub fn line() -> String {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn gets() -> Vec\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse().unwrap())\n .collect()\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn main() {\n let n = get!(usize);\n let games = get!(usize;n);\n\n let mut players = (1, 2);\n let mut spec = 3;\n\n for g in games {\n if g == players.0 {\n let t = spec;\n spec = players.1;\n players = (g, t);\n } else if g == players.1 {\n let t = spec;\n spec = players.0;\n players = (g, t);\n } else {\n println!(\"NO\");\n return;\n }\n }\n\n println!(\"YES\");\n}\n", "src_uid": "6c7ab07abdf157c24be92f49fd1d8d87"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::io::{stdin, stdout, BufWriter, StdoutLock, Write};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_macros)]\nmacro_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 ) * } } ; }\n#[allow(unused_macros)]\nmacro_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 ) * } } ; }\n#[allow(unused_macros)]\nmacro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( \"Parse error\" ) } ; }\n#[allow(dead_code)]\npub fn with_bufwriter) -> ()>(f: F) {\n let out = stdout();\n let writer = BufWriter::new(out.lock());\n f(writer)\n}\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) } ; }\n#[allow(dead_code)]\nfn main() {\n input!{\n n: u64,\n }\n let mut i = 1;\n while i <= 31623 {\n if i * i == n {\n println!(\"{}\", i * 2);\n return;\n }\n if i * i > n {\n if n <= i * (i - 1) {\n println!(\"{}\", i * 2 - 1);\n } else {\n println!(\"{}\", i * 2);\n }\n return;\n }\n i += 1;\n }\n}", "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"source_code": "#![allow(dead_code, clippy::many_single_char_names, unused_variables, non_snake_case, unused_macros, unused_imports, non_upper_case_globals)]\nuse std::{\n collections::*,\n io::{stdin, StdinLock, stdout, StdoutLock, BufReader, BufRead, BufWriter, Write},\n mem::swap\n};\n\nfn parse(n: &str) -> T {\n match n.parse::() {\n Ok(x) => x,\n _ => panic!()\n }\n}\n\nmacro_rules! fill {\n ($r: expr, str, $($x: ident),+) => { fill!($r, str, 30, $($x),+) };\n ($r: expr, $t: ty, $($x: ident),+) => { fill!($r, $t, 30, $($x),+) };\n ($r: expr, str, $c: expr, $($x: ident),+) => {\n let t = read!($r, $c);\n let mut t = t.split(' ');\n\n $(\n $x = t.next().unwrap();\n )+\n };\n ($r: expr, $t: ty, $c: expr, $($x: ident),+) => {\n let t = read!($r, $c);\n let mut t = t.split(' ').map(parse::<$t>);\n\n $(\n $x = t.next().unwrap();\n )+\n }\n}\n\nmacro_rules! read {\n ($r: expr) => { read!($r, 20) };\n ($r: expr, str) => { read!($r, 20) };\n ($r: expr, $t: ty) => { parse::<$t>(&read!($r, 20)) };\n ($r: expr, str, $c: expr) => { read!($r, $c) };\n ($r: expr, $t: ty, $c: expr) => { parse::<$t>(&read!($r, $c)) };\n ($r: expr, $c: expr) => {\n {\n let mut s = String::with_capacity($c+2);\n $r.read_line(&mut s).unwrap();\n\n assert!(s.len() <= $c+2);\n\n if s.ends_with('\\n') {\n s.pop();\n if s.ends_with('\\r') {\n s.pop();\n }\n }\n s\n }\n }\n}\n\nmacro_rules! read_vec {\n ($r: expr) => { read_vec!($r, str, 10_000) };\n ($r: expr, str) => { read_vec!($r, str, 10_000) };\n ($r: expr, $t: ty) => { read_vec!($r, $t, 10_000) };\n ($r: expr, $c: expr) => { read_vec!($r, str, $c) };\n ($r: expr, str, $c: expr) => {\n {\n let v = read!($r, $c).split(' ').collect::>();\n assert!(v.len() <= $c); // $c is upper bound of string\n v\n }\n };\n ($r: expr, $t: ty, $c: expr) => { \n {\n let v = read!($r, $c).split(' ').map(parse::<$t>).collect::>();\n assert!(v.len() <= $c);\n v\n }\n };\n}\n\n\nfn main() {\n let r = stdin();\n let mut r = BufReader::with_capacity(10000, r.lock());\n\n let w = stdout();\n let mut w = BufWriter::with_capacity(10000, w.lock());\n unsafe { solve(&mut r, &mut w); }\n}\n\nconst M: usize = std::usize::MAX;\n\nunsafe fn solve(r: &mut BufReader, w: &mut BufWriter) {\n let (a, b);\n fill!(r, usize, 19, a, b);\n\n if b%a != 0 {\n writeln!(w, \"-1\").unwrap();\n } else {\n let m = b/a;\n let tz = m.trailing_zeros();\n let mut m = m>>tz;\n\n let mut i = 0;\n while m != 1 {\n if m%3 != 0 {\n write!(w, \"-1\").unwrap();\n return;\n }\n m /= 3;\n i += 1;\n }\n\n write!(w, \"{}\", tz+i).unwrap();\n }\n}", "src_uid": "3f9980ad292185f63a80bce10705e806"} {"source_code": "//spnauti-rust\n#[allow(dead_code)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader {\n it : std::vec::IntoIter,\n}\n#[allow(dead_code)]\nimpl WordReader {\n fn new(mut reader: T) -> WordReader {\n let mut s = String::new();\n reader.read_to_string(&mut s).unwrap();\n WordReader {\n it : s.split_ascii_whitespace().map(String::from)\n .collect::>().into_iter()\n }\n }\n fn from_stdin() -> WordReader {\n WordReader::new(std::io::stdin())\n }\n fn s(&mut self) -> String {\n self.it.next().unwrap()\n }\n fn ab(&mut self) -> Vec {\n self.it.next().unwrap().into_bytes()\n }\n fn i(&mut self) -> i32 {\n self.it.next().unwrap().parse().unwrap()\n }\n fn ai(&mut self, n: usize) -> Vec {\n let mut a = Vec::with_capacity(n);\n for _ in 0..n { a.push(self.i()); }\n a\n }\n}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n let n = input.i() as usize;\n let mut dp = Vec::new();\n dp.resize(n + 1, -10000);\n dp[0] = 0;\n\n for _ in 0..3 {\n let a = input.i() as usize;\n for i in a..n+1 {\n a!(>, dp[i], dp[i - a] + 1);\n }\n }\n println!(\"{}\", dp[n]);\n}\n\n", "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"source_code": "fn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let mut it = s.trim().split_whitespace();\n let n: u64 = it.next().unwrap().parse().unwrap();\n let k: u64 = it.next().unwrap().parse().unwrap();\n let ans = n / k * k + k;\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}", "src_uid": "75f3835c969c871a609b978e04476542"} {"source_code": "use std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\n\n// I have no idea what I'm doing\n\n/// Copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n\n pub fn pair(&mut self) -> (T, T) {\n (self.token(), self.token())\n }\n}\n\nfn main() -> Result<(), io::Error> {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = UnsafeScanner::new(stdin.lock());\n let mut out = BufWriter::new(stdout.lock());\n\n let a: i32 = scan.token();\n let b: i32 = scan.token();\n let c: i32 = scan.token();\n let d: i32 = scan.token();\n\n if a == 0 && (c > 0 || d > 0) {\n writeln!(out, \"0\")?;\n return Ok(());\n }\n\n writeln!(out, \"{}\", match a == d {\n true => 1,\n false => 0,\n })?;\n\n Ok(())\n}\n", "src_uid": "b99578086043537297d374dc01eeb6f8"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }};\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused)]\nmacro_rules! debug {\n ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());\n}\n#[allow(unused)]\nmacro_rules! debugln {\n ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());\n}\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (let _ = write!(out,$($format)*););\n }\n input! {\n n: usize,\n s: chars,\n }\n // Dilworth\n let mut dp = vec![0; n];\n let mut tbl = vec![0; 27];\n // Find a max LDS.\n let mut len = 0;\n for i in 0..n {\n let c = (s[i] as u8 - b'a') as usize;\n let &ma = tbl[c + 1..].iter().max().unwrap();\n dp[i] = ma + 1;\n len = max(len, ma + 1);\n tbl[c] = max(tbl[c], ma + 1);\n }\n if len >= 3 {\n puts!(\"NO\\n\");\n return;\n }\n puts!(\"YES\\n\");\n for i in 0..n {\n puts!(\"{}\", dp[i] - 1);\n }\n puts!(\"\\n\");\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "9bd31827cda83eacfcf5e46cdeaabe2b"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader {\n it : std::vec::IntoIter,\n}\n#[allow(dead_code)]\nimpl WordReader {\n fn new(mut reader: T) -> WordReader {\n let mut s = String::new();\n reader.read_to_string(&mut s).unwrap();\n WordReader {\n it : s.split_ascii_whitespace().map(String::from)\n .collect::>().into_iter()\n }\n }\n fn from_stdin() -> WordReader {\n WordReader::new(std::io::stdin())\n }\n fn s(&mut self) -> String {\n self.it.next().unwrap()\n }\n fn ab(&mut self) -> Vec {\n self.it.next().unwrap().into_bytes()\n }\n fn i(&mut self) -> i32 {\n self.it.next().unwrap().parse().unwrap()\n }\n fn ai(&mut self, n: usize) -> Vec {\n let mut a = Vec::with_capacity(n);\n for _ in 0..n { a.push(self.i()); }\n a\n }\n}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n let mut a = input.ai(3);\n a.sort();\n println!(\"{}\", a[2] - a[0]);\n}\n\n", "src_uid": "7bffa6e8d2d21bbb3b7f4aec109b3319"} {"source_code": "use std::io;\nuse std::io::{Write};\nuse std::str;\n\n/// Reads white-space separated tokens one at a time.\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n /// Use \"turbofish\" syntax token::() to select data type of next token.\n ///\n /// # Panics\n ///\n /// Panics if there's an I/O error or if the token cannot be parsed as T.\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: str::SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n}\n\npub fn scanner_from_file(filename: &str) -> Scanner> {\n let file = std::fs::File::open(filename).expect(\"Input file not found\");\n Scanner::new(io::BufReader::new(file))\n}\n\npub fn writer_to_file(filename: &str) -> io::BufWriter {\n let file = std::fs::File::create(filename).expect(\"Output file not found\");\n io::BufWriter::new(file)\n}\n\n#[allow(dead_code)]\nfn max(a: T, b: T) -> T {\n if a > b { a } else { b }\n}\n\nfn solve() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n let n = scan.token::();\n let mut v = Vec::with_capacity(n as usize);\n for _ in 0..n {\n v.push(scan.token::());\n }\n v.sort();\n out.write(v.iter().map(|i| i.to_string()).collect::>().join(\" \").as_bytes()).unwrap();\n // let k = scan.token::();\n // let mut arr = scan.token::().chars().collect::>();\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(64 * 1024 * 1024)\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n}", "src_uid": "ae20712265d4adf293e75d016b4b82d8"} {"source_code": "use std::io;\n\n\nfn get_elem(i: u8, j: u8) -> u32 {\n\n\n if i == 1 {\n 1\n } else if i == j {\n 2 * get_elem(i - 1, j)\n } else if i < j {\n get_elem(i, j - 1) + get_elem(i - 1, j)\n } else {\n 0\n }\n\n}\n\nfn main() {\n let mut line = String::new();\n io::stdin().read_line(&mut line).expect(\"Failed to read line\");\n let n = line.trim().parse::().unwrap();\n\n println!(\"{}\", get_elem(n , n));\n}\n", "src_uid": "2f650aae9dfeb02533149ced402b60dc"} {"source_code": "//spnauti-rust\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nuse std::str::*;\nuse std::fmt::Debug;\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, std::io::stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\nfn main() {\n let mut buffer = String::new();\n let mut input = WordReader::from_stdin(&mut buffer);\n\n let k = input.i();\n let mut a = input.vp::(12);\n a.sort();\n a.reverse();\n let sol = (|| {\n if k == 0 { return 0; }\n let mut sum = 0;\n for i in 0..12 {\n sum += a[i as usize];\n if sum >= k {\n return i + 1;\n }\n }\n -1\n })();\n println!(\"{}\", sol);\n}\n\n", "src_uid": "59dfa7a4988375febc5dccc27aca90a8"} {"source_code": "// ---------- begin ModInt ----------\nconst MOD: u32 = 1_000_000_007;\n\n#[derive(Clone, Copy)]\nstruct ModInt(u32);\n\nimpl std::ops::Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::AddAssign for ModInt {\n fn add_assign(&mut self, rhs: ModInt) {\n *self = *self + rhs;\n }\n}\n\nimpl std::ops::Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + MOD - rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: ModInt) {\n *self = *self - rhs;\n }\n}\n\nimpl std::ops::Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: ModInt) -> Self::Output {\n ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)\n }\n}\n\nimpl std::ops::MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: ModInt) {\n *self = *self * rhs;\n }\n}\n\nimpl std::ops::Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n ModInt(if self.0 == 0 {0} else {MOD - self.0})\n }\n}\n\nimpl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n\nimpl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n}\n\n#[allow(dead_code)]\nimpl ModInt {\n pub fn new(n: u32) -> ModInt {\n ModInt(n % MOD)\n }\n pub fn zero() -> ModInt {\n ModInt(0)\n }\n pub fn one() -> ModInt {\n ModInt(1)\n }\n pub fn pow(self, mut n: u32) -> ModInt {\n let mut t = ModInt::one();\n let mut s = self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(self) -> ModInt {\n self.pow(MOD - 2)\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\n#[allow(dead_code)]\nstruct Precalc {\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n}\n\n#[allow(dead_code)]\nimpl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);\n fact[i] = fact[i - 1] * ModInt(i as u32);\n ifact[i] = ifact[i - 1] * inv[i];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n}\n// ---------- end Precalc ----------\nuse std::io::Read;\n\nfn run() {\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n let mut it = s.trim().split_whitespace();\n let n: usize = it.next().unwrap().parse().unwrap();\n let w: usize = it.next().unwrap().parse().unwrap();\n let mut a = vec![vec![]; 3];\n for _ in 0..n {\n let t: usize = it.next().unwrap().parse().unwrap();\n let g: usize = it.next().unwrap().parse().unwrap();\n a[g - 1].push(t);\n }\n let mut way = vec![vec![vec![vec![ModInt::zero(); a[2].len() + 2]; a[1].len() + 2]; a[0].len() + 2]; 3];\n way[0][1][0][0] = ModInt::one();\n way[1][0][1][0] = ModInt::one();\n way[2][0][0][1] = ModInt::one();\n for i in 0..=a[0].len() {\n for j in 0..=a[1].len() {\n for k in 0..=a[2].len() {\n for l in 0..3 {\n let v = way[l][i][j][k];\n for (g, &(x, y, z)) in [(i + 1, j, k), (i, j + 1, k), (i, j, k + 1)].iter().enumerate() {\n if g != l {\n way[g][x][y][z] += v;\n }\n }\n }\n }\n }\n }\n let mut dp1 = vec![vec![vec![ModInt::zero(); w + 1]; a[1].len() + 1]; a[0].len() + 1];\n dp1[0][0][0] = ModInt::one();\n for &b in a[0].iter() {\n for i in (1..=a[0].len()).rev() {\n for t in (b..=w).rev() {\n let v = dp1[i - 1][0][t - b];\n dp1[i][0][t] += v;\n }\n }\n }\n for &b in a[1].iter() {\n for i in 0..=a[0].len() {\n for j in (1..=a[1].len()).rev() {\n for t in (b..=w).rev() {\n let v = dp1[i][j - 1][t - b];\n dp1[i][j][t] += v;\n }\n }\n }\n }\n let mut dp2 = vec![vec![ModInt::zero(); w + 1]; a[2].len() + 1];\n dp2[0][0] = ModInt::one();\n for &b in a[2].iter() {\n for i in (1..=a[2].len()).rev() {\n for t in (b..=w).rev() {\n let v = dp2[i - 1][t - b];\n dp2[i][t] += v;\n }\n }\n }\n let pc = Precalc::new(n);\n let mut ans = ModInt::zero();\n for i in 0..=a[0].len() {\n for j in 0..=a[1].len() {\n for k in 0..=a[2].len() {\n for t in 0..=w {\n let way = way[0][i][j][k] + way[1][i][j][k] + way[2][i][j][k];\n ans += dp1[i][j][t] * dp2[k][w - t] * way * pc.fact(i) * pc.fact(j) * pc.fact(k);\n }\n }\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "ed5f913afe829c65792b54233a256757"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::*;\n#[allow(unused_imports)] use std::iter::*;\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($i:ident . $e:tt : $t:ty; $($a:ident),*) => {\n $( let $a: $t = $i.$e(); )*\n };\n ($i:ident . $e:tt; $($a:ident),*) => {\n $( let $a = $i.$e(); )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let mut a = input.vi(3);\n a.sort();\n println!(\"{}\", 0.max(a[2] + 1 - a[1] - a[0]));\n}\n\n", "src_uid": "3dc56bc08606a39dd9ca40a43c452f09"} {"source_code": "use std::io;\nfn pgcd(mut a:i8,mut b:i8) -> i8 {\n while (a != b){\n if a > b {\n a = a -b;\n\n }else{\n b = b - a;\n }}\n return a;\n}\nfn main() {\n let mut line = String::new();\n io::stdin()\n .read_line(&mut line)\n .expect(\"error\");\n\n let line: String = line.trim().parse().expect(\"no\");\n let inputs: Vec = line.split(\" \")\n .map(|x| x.parse().expect(\"Not an integer!\"))\n .collect();\n let mut pgcd_a;\n let mut pgcd_b;\n\n let (mut a, mut b, mut n) = (inputs[0], inputs[1], inputs[2]);\n loop {\n pgcd_a = pgcd(a, n); // 3,9 => 3\n //println!(\"{}\",pgcd_a);\n n = n -pgcd_a; // 9 - 3 = 6\n if pgcd_a > n {\n println!(\"0\");\n break;\n }\n pgcd_b = pgcd(b,n); // 5,6 => 1\n //println!(\"{}\",pgcd_b);\n\n n = n-pgcd_b;\n if pgcd_b > n {\n println!(\"1\");\n break;\n }\n\n }\n}\n\n\n\n\n\n\n\n\n\n", "src_uid": "0bd6fbb6b0a2e7e5f080a70553149ac2"} {"source_code": "use std::io;\n\nfn poisonous_row(r: &Vec) -> bool {\n for i in 0..r.len() {\n if !r[i] { return true }\n }\n false\n}\n\nfn poisonous_col(m: &Vec>, j: usize) -> bool {\n for r in m {\n if !r[j] { return true }\n }\n false\n}\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n let a: Vec = s.split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let r = a[0];\n let c = a[1];\n\n let mut v: Vec> = vec![];\n\n for _ in 0..r {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n v.push(s.trim().chars()\n .map(|x| x == '.')\n .collect()\n );\n }\n\n let mut poisonous_rows = 0;\n let mut poisonous_cols = 0;\n for i in 0..r as usize {\n if poisonous_row(&v[i]) { poisonous_rows += 1; }\n }\n for j in 0..c as usize {\n if poisonous_col(&v, j) { poisonous_cols += 1; }\n }\n\n println!(\"{}\", r*c - poisonous_rows*poisonous_cols);\n}\n", "src_uid": "ebaf7d89c623d006a6f1ffd025892102"} {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(overflowing_literals)]\n#![allow(unused_must_use)]\n\nuse std::collections::*;\nuse std::io::*;\nuse std::cmp::{min, max};\nuse std::f64::consts::*;\nuse std::mem::swap;\nuse std::fs::File;\nuse std::rc::*;\nuse std::ascii::*;\nuse std::ops::*;\n\nconst INF: i32 = std::i32::MAX;\nconst LINF: i64 = std::i64::MAX;\nconst MOD: usize = 1000000007;\n\n#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]\nstruct Pair(A, B);\n\nstruct Input\n{\n\tbuffer: Buf\n}\n\nimpl Input\n{\n\tfn read_line(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] < b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] >= b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\n\tfn read_word(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] <= b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] > b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\t#[inline]\n\tfn read_int(&mut self) -> i32 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_long(&mut self) -> i64 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_usize(&mut self) -> usize {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_double(&mut self) -> f64 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n}\nmacro_rules! read {\n () => {};\n\t($inf:ident,$($t:ty),*) => ({($({$inf.read_word().parse::<$t>().expect(\"Parsing error\")}),*)});\n}\nfn gcd + Copy + Clone>(x: T, y: T) -> T {\n\tlet (mut a, mut b) = (x, y);\n\twhile b > T::from(0) {\n\t\ta %= b;\n\t\tswap(&mut a, &mut b);\n\t}\n\ta\n}\n\nfn main() {\n\tmatch std::env::var(\"home\") {\n\t\tOk(_x) => {\n\t\t\tlet mut inf = Input {\n\t\t\t\tbuffer: BufReader::new(File::open(\"input.txt\").expect(\"File not found\"))\n\t\t\t};\n\t\t\tlet mut ouf = BufWriter::new(stdout());\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t\tErr(_e) => {\n\t\t\tlet mut inf = Input { buffer: BufReader::new(stdin()) };\n\t\t\tlet mut ouf = BufWriter::new(stdout());\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t}\n}\n\nfn solve(inf: &mut Input, ouf: &mut Output)\n{\n\tlet mut x = read!(inf,usize);\n\twhile x % 10 == 0 {\n\t\tx /= 10;\n\t}\n\tlet mut y = format!(\"{}\", x).as_bytes().to_vec();\n\ty.reverse();\n\tif format!(\"{}\", x) == String::from_utf8(y).unwrap() {\n\t\twriteln!(ouf, \"YES\");\n\t} else {\n\t\twriteln!(ouf, \"NO\");\n\t}\n}", "src_uid": "d82278932881e3aa997086c909f29051"} {"source_code": "use std::cmp;\nuse std::io;\n\nfn main() {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)\n .expect(\"Failed to read line\");\n\n let mut number_of_n: u32 = 0;\n let mut number_of_i: u32 = 0;\n let mut number_of_t: u32 = 0;\n let mut number_of_e: u32 = 0;\n\n for char in input.chars() {\n if char == 'n' {\n number_of_n = number_of_n + 1;\n } else if char == 'i' {\n number_of_i = number_of_i + 1;\n } else if char == 't' {\n number_of_t = number_of_t + 1;\n } else if char == 'e' {\n number_of_e = number_of_e + 1;\n }\n }\n\n if number_of_n % 2 == 1 {\n number_of_n = number_of_n + (number_of_n / 2) - 1;\n } else {\n number_of_n = (number_of_n - 1) + (number_of_n - 1)/2 -1;\n }\n \n println!(\"{}\", cmp::min(cmp::min(number_of_n/3, number_of_i), cmp::min(number_of_t, number_of_e/3)))\n}\n", "src_uid": "bb433cdb8299afcf46cb2797cbfbf724"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap,HashSet,VecDeque};\n\n#[allow(unused_macros)]\nmacro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn main() {\n let s = readln!();\n let z = s.chars().enumerate().map(|(i,c)|\n if i == 0 && c == '9' {\n c\n } else {\n min(c,((9u8 - (c as u8 - '0' as u8)) + ('0' as u8)) as char)\n }).collect::().chars().skip_while(|&c|c=='0').collect::();\n println!(\"{}\",if z.is_empty() { \"9\" } else { z.as_ref() });\n}\n", "src_uid": "d5de5052b4e9bbdb5359ac6e05a18b61"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReaderB {\n bin: Box<[u8]>,\n it: RefCell>>\n}\n#[allow(dead_code)]\nimpl WordReaderB {\n fn from(mut r: T) -> Self {\n let mut bin = Vec::new();\n r.read_to_end(&mut bin).ok();\n let bin = bin.into_boxed_slice();\n let it = RefCell::new(Self::split(&bin).into_iter());\n Self { bin, it }\n }\n fn from_stdin() -> Self {\n Self::from(stdin())\n }\n fn split(a: &[u8]) -> Vec> {\n let mut res = Vec::new();\n let mut last = None;\n let mut space = vec![false; 256];\n for &c in b\" \\t\\n\\r\" {\n space[c as usize] = true;\n }\n for (i,&c) in a.iter().enumerate() {\n if space[c as usize] {\n if let Some(j) = last.take() {\n res.push(j..i);\n }\n } else {\n last.get_or_insert(i);\n }\n }\n if let Some(j) = last {\n res.push(j..a.len());\n }\n res\n }\n fn bs(&self) -> &[u8] {\n &self.bin[self.it.borrow_mut().next().expect(\"EOF\")]\n }\n fn sl(&self) -> std::borrow::Cow {\n String::from_utf8_lossy(self.bs())\n }\n fn s(&self) -> String { self.sl().into_owned() }\n fn sk(&self, n: usize) {\n self.it.borrow_mut().nth(n - 1);\n }\n fn i(&self) -> i32 { self.p() }\n fn u(&self) -> usize { self.p() }\n fn f(&self) -> f64 { self.p() }\n fn vi(&self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn vu(&self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn ii(&self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn iu(&self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn p(&self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n fn ip(&self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let rin = WordReaderB::from_stdin();\n\n let n = rin.u();\n let m: i64 = rin.p();\n let add = |x: i64, y: i64| {\n let z = x + y;\n if z >= m {\n z - m\n } else {\n z\n }\n };\n let mul = |x: i64, y: i64| {\n x * y % m\n };\n let mut fact = Vec::with_capacity(n + 1);\n fact.push(1);\n for i in 0..n {\n let x = mul(fact[i], (i + 1) as i64);\n fact.push(x);\n }\n let mut sol = 0;\n for len in 1..=n {\n let count = (n + 1 - len) as i64;\n let count2 = mul(count, count);\n sol = add(sol, mul(fact[len], mul(fact[n - len], count2)));\n }\n println!(\"{}\", sol);\n}\n\n", "src_uid": "020d5dae7157d937c3f58554c9b155f9"} {"source_code": "use std::io;\nuse std::io::{Write};\nuse std::str;\n\n/// Reads white-space separated tokens one at a time.\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n /// Use \"turbofish\" syntax token::() to select data type of next token.\n ///\n /// # Panics\n ///\n /// Panics if there's an I/O error or if the token cannot be parsed as T.\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: str::SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n}\n\npub fn scanner_from_file(filename: &str) -> Scanner> {\n let file = std::fs::File::open(filename).expect(\"Input file not found\");\n Scanner::new(io::BufReader::new(file))\n}\n\npub fn writer_to_file(filename: &str) -> io::BufWriter {\n let file = std::fs::File::create(filename).expect(\"Output file not found\");\n io::BufWriter::new(file)\n}\n\n#[allow(dead_code)]\nfn max(a: T, b: T) -> T {\n if a > b { a } else { b }\n}\n\n#[allow(dead_code)]\nfn min(a: T, b: T) -> T {\n if a < b { a } else { b }\n}\n\nfn solve() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n let n = scan.token::();\n let m = scan.token::();\n if min(n, m) % 2 == 0 {\n out.write(\"Malvika\".as_bytes()).unwrap();\n } else {\n out.write(\"Akshat\".as_bytes()).unwrap();\n }\n // let k = scan.token::();\n // let mut arr = scan.token::().chars().collect::>();\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(64 * 1024 * 1024)\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n}", "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"source_code": "#![warn(\r\n clippy::all,\r\n rust_2018_idioms,\r\n missing_copy_implementations,\r\n missing_debug_implementations,\r\n single_use_lifetimes,\r\n trivial_casts,\r\n unused_import_braces,\r\n unused_qualifications,\r\n unused_results\r\n)]\r\n#![allow(\r\n clippy::many_single_char_names,\r\n non_snake_case,\r\n unused_imports,\r\n unused_labels,\r\n unused_macros,\r\n dead_code\r\n)]\r\n\r\nuse crate::ceil::*;\r\nuse crate::const_value::*;\r\nuse crate::modular::*;\r\nuse crate::prelude::*;\r\nuse crate::prime_value::*;\r\nuse crate::primes::*;\r\nuse crate::values::*;\r\n\r\nstatic mut M: u32 = 0;\r\n\r\nmod task {\r\n use super::*;\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct Main;\r\n\r\n impl Problem for Main {\r\n fn solve(io: &mut Io) {\r\n define_io!(io);\r\n\r\n let n = re!(usize);\r\n let m = re!(u32);\r\n unsafe {\r\n M = m;\r\n };\r\n\r\n #[derive(Clone, Copy, Debug, Default)]\r\n struct Prime;\r\n\r\n impl PrimeValue for Prime {}\r\n\r\n impl ConstValue for Prime {\r\n type Output = u32;\r\n fn get() -> Self::Output {\r\n unsafe { M }\r\n }\r\n }\r\n\r\n let mut mul: Vec> = vec![Modular::from(0); n as usize + 1];\r\n let mut prob: Modular = Zero::zero();\r\n let mut dsum: Modular = Zero::zero();\r\n let mut sum: Modular = Zero::zero();\r\n for j1 in 1..=n {\r\n dsum += mul[j1];\r\n if j1 == 1 {\r\n prob = One::one();\r\n } else {\r\n prob = sum + dsum;\r\n }\r\n sum += prob;\r\n let mut j2 = j1 * 2;\r\n let mut j3 = j2 + 2;\r\n while j2 <= n {\r\n mul[j2] += prob;\r\n j2 += j1;\r\n if j3 <= n {\r\n mul[j3] -= prob;\r\n j3 += j1 + 1;\r\n }\r\n }\r\n if n < 10 {\r\n /*dln!(\r\n n,\r\n m,\r\n j1,\r\n prob.0,\r\n sum.0,\r\n ..mul.iter().enumerate().map(|kv| (kv.0, kv.1 .0))\r\n );*/\r\n }\r\n }\r\n ln!(prob.0);\r\n\r\n /*let mut div = vec![Modular::from(0); n as usize + 1];\r\n div[n as usize] = One::one();\r\n\r\n let mut sum: Modular = Zero::zero();\r\n let mut ans: Modular = Zero::zero();\r\n for j in (1..=n as usize).rev() {\r\n ans = sum;\r\n ans += div[j];\r\n sum += ans;\r\n for k in 2..=j {\r\n div[j / k] += ans;\r\n }\r\n //dln!(n, m, j, ans.0, sum.0);\r\n }\r\n //dln!(n, m, ans.0, sum.0, \":\", ..div.iter().map(|v| v.0));\r\n ln!(ans.0);*/\r\n }\r\n }\r\n\r\n #[cfg(test)]\r\n #[test]\r\n fn test_example() {\r\n Main::test(\r\n \"\r\n --\r\n ==\r\n 1 998244353\r\n --\r\n 1\r\n ==\r\n 2 998244353\r\n --\r\n 2\r\n ==\r\n 3 998244353\r\n --\r\n 5\r\n ==\r\n 5 998244353\r\n --\r\n 25\r\n ==\r\n 42 998244353\r\n --\r\n 793019428\r\n ==\r\n 200000 998244353\r\n --\r\n 730229972\r\n \",\r\n );\r\n }\r\n\r\n #[cfg(test)]\r\n #[test]\r\n fn test_custom() {\r\n /*\r\n define_logger!(Some(Writer::new(BufWriter::new(stderr()))));\r\n for a in 0..4 {\r\n for b in 0..4 {\r\n // for a in vec![1..=2, 1..=3, 1..=4].each() {}\r\n let mut input = Writer::new(Vec::new());\r\n define_writer!(input);\r\n ln!(1, ..vec![a, b]);\r\n let output = Main::output(&input.writer());\r\n define_reader!(Reader::new(BufReader::new(output.as_bytes())));\r\n let sum: i32 = re!();\r\n assert_eq!(sum, a + b);\r\n }\r\n }*/\r\n }\r\n}\r\n\r\npub fn main() {\r\n let mut reader = stdin();\r\n let mut writer = stdout();\r\n task::Main::solve(&mut Io::new(&mut reader, &mut writer));\r\n writer.flush().unwrap();\r\n}\r\n\r\n#[cfg(test)]\r\n#[test]\r\nfn test_32bit_target() {\r\n use core::mem::size_of;\r\n assert_eq!(\r\n size_of::(),\r\n 4,\r\n \"Codeforces supports only 32-bit Rust\"\r\n );\r\n}\r\n\r\n// libs\r\n\r\nmod ceil {\r\n use core::ops::{Add, Div, Sub};\r\n\r\n use crate::ops::DivEuclid;\r\n use crate::values::One;\r\n\r\n #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]\r\n pub struct Ceil(pub T);\r\n\r\n impl Div for Ceil\r\n where\r\n T: Add + Clone + DivEuclid + One + Sub,\r\n {\r\n type Output = T;\r\n\r\n fn div(self, rhs: T) -> Self::Output {\r\n (self.0 + rhs.clone() - T::one()).div_euclid(rhs)\r\n }\r\n }\r\n\r\n pub fn up(value: T) -> Ceil {\r\n Ceil(value)\r\n }\r\n}\r\n\r\nmod const_value {\r\n pub trait ConstValue: Default {\r\n type Output;\r\n fn get() -> Self::Output;\r\n }\r\n}\r\n\r\nmod modular {\r\n use core::cmp::{Ord, Ordering};\r\n use core::ops::{\r\n Add, AddAssign, BitAnd, Div, DivAssign, Mul, MulAssign, Neg, Rem, ShrAssign, Sub, SubAssign,\r\n };\r\n\r\n use crate::const_value::ConstValue;\r\n use crate::gcd::gcd;\r\n use crate::modular_mul::ModularMul;\r\n use crate::modular_pow::ModularPow;\r\n use crate::mul_div::MulDiv;\r\n use crate::ops::{Abs, RemEuclid};\r\n use crate::prime_value::{PrimeValue, P1_000_000_007, P998_244_353};\r\n use crate::unsigned::Unsigned;\r\n use crate::value::Value;\r\n use crate::value_eulers_phi::ValueEulersPhi;\r\n use crate::values::{Five, One, Ten, Three, Two, Zero};\r\n\r\n #[derive(Clone, Copy, Debug, Default, Hash)]\r\n pub struct Modular(pub T, pub M);\r\n\r\n impl Modular {\r\n pub fn new(value: T, modulus: M) -> Self\r\n where\r\n T: RemEuclid + Unsigned,\r\n M: Clone + Value,\r\n {\r\n let value = value.rem_euclid(modulus.get());\r\n Self(value, modulus)\r\n }\r\n\r\n pub fn from_raw(value: T, modulus: M) -> Self\r\n where\r\n T: Unsigned,\r\n M: Value,\r\n {\r\n Self(value, modulus)\r\n }\r\n\r\n pub fn from_raw_value(value: T) -> Self\r\n where\r\n T: Unsigned,\r\n M: ConstValue + Default + Value,\r\n {\r\n Self(value, M::default())\r\n }\r\n\r\n pub fn value(self) -> T {\r\n self.0\r\n }\r\n\r\n pub fn modulus(self) -> M {\r\n self.1\r\n }\r\n }\r\n\r\n impl From for Modular\r\n where\r\n T: RemEuclid + Unsigned,\r\n M: Copy + ConstValue,\r\n {\r\n fn from(value: T) -> Self {\r\n Self::new(value, M::default())\r\n }\r\n }\r\n\r\n impl Neg for Modular\r\n where\r\n T: Add + PartialOrd + RemEuclid + Sub + Zero,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn neg(self) -> Self {\r\n if self.0.is_zero() {\r\n self\r\n } else {\r\n Self(self.1.get() - self.0, self.1)\r\n }\r\n }\r\n }\r\n\r\n impl Add for Modular\r\n where\r\n T: Add + PartialOrd + RemEuclid + Sub,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn add(self, other: Self) -> Self {\r\n let value = self.0 + other.0;\r\n if value >= self.1.get() {\r\n Self(value - self.1.get(), self.1)\r\n } else {\r\n Self(value, self.1)\r\n }\r\n }\r\n }\r\n\r\n impl Sub for Modular\r\n where\r\n T: Add + PartialOrd + Sub + Zero,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn sub(self, other: Self) -> Self {\r\n if self.0 >= other.0 {\r\n Self(self.0 - other.0, self.1)\r\n } else {\r\n Self(self.0 + self.1.get() - other.0, self.1)\r\n }\r\n }\r\n }\r\n\r\n impl Mul for Modular\r\n where\r\n T: ModularMul,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn mul(self, other: Self) -> Self {\r\n Self(self.0.modular_mul(other.0, self.1.get()), self.1)\r\n }\r\n }\r\n\r\n impl Div for Modular\r\n where\r\n T: ModularMul + ModularPow + Sub + Two + Zero,\r\n M: PrimeValue,\r\n {\r\n type Output = Self;\r\n\r\n fn div(self, other: Self) -> Self {\r\n self.mul(other.inv().unwrap())\r\n }\r\n }\r\n\r\n impl AddAssign for Modular\r\n where\r\n T: Add + Copy + PartialOrd + RemEuclid + Sub,\r\n M: Value,\r\n {\r\n fn add_assign(&mut self, other: Self) {\r\n self.0 = (*self + other).0\r\n }\r\n }\r\n\r\n impl SubAssign for Modular\r\n where\r\n T: Add + Copy + PartialOrd + Sub + Zero,\r\n M: Value,\r\n {\r\n fn sub_assign(&mut self, other: Self) {\r\n self.0 = (*self - other).0\r\n }\r\n }\r\n\r\n impl MulAssign for Modular\r\n where\r\n T: Copy + ModularMul,\r\n M: Value,\r\n {\r\n fn mul_assign(&mut self, other: Self) {\r\n self.0 = (*self * other).0\r\n }\r\n }\r\n\r\n impl DivAssign for Modular\r\n where\r\n T: Copy + ModularMul + ModularPow + Sub + Two + Zero,\r\n M: PrimeValue,\r\n {\r\n fn div_assign(&mut self, other: Self) {\r\n self.0 = (*self / other).0\r\n }\r\n }\r\n\r\n impl Add for Modular\r\n where\r\n Self: Add,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn add(self, other: T) -> Self {\r\n let modulus = self.1;\r\n self + Self::new(other, modulus)\r\n }\r\n }\r\n\r\n impl Sub for Modular\r\n where\r\n Self: Sub,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn sub(self, other: T) -> Self {\r\n let modulus = self.1;\r\n self - Self::new(other, modulus)\r\n }\r\n }\r\n\r\n impl Mul for Modular\r\n where\r\n Self: Mul,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn mul(self, other: T) -> Self {\r\n let modulus = self.1;\r\n self * Self::new(other, modulus)\r\n }\r\n }\r\n\r\n impl Div for Modular\r\n where\r\n Self: Div,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n type Output = Self;\r\n\r\n fn div(self, other: T) -> Self {\r\n let modulus = self.1;\r\n self / Self::new(other, modulus)\r\n }\r\n }\r\n\r\n impl AddAssign for Modular\r\n where\r\n Self: AddAssign,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n fn add_assign(&mut self, other: T) {\r\n let modulus = self.1;\r\n *self += Self::new(other, modulus);\r\n }\r\n }\r\n\r\n impl SubAssign for Modular\r\n where\r\n Self: SubAssign,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n fn sub_assign(&mut self, other: T) {\r\n let modulus = self.1;\r\n *self -= Self::new(other, modulus);\r\n }\r\n }\r\n\r\n impl MulAssign for Modular\r\n where\r\n Self: MulAssign,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n fn mul_assign(&mut self, other: T) {\r\n let modulus = self.1;\r\n *self *= Self::new(other, modulus);\r\n }\r\n }\r\n\r\n impl DivAssign for Modular\r\n where\r\n Self: DivAssign,\r\n T: RemEuclid + Unsigned,\r\n M: Value,\r\n {\r\n fn div_assign(&mut self, other: T) {\r\n let modulus = self.1;\r\n *self /= Self::new(other, modulus);\r\n }\r\n }\r\n\r\n impl Modular {\r\n pub fn pow(self, exp: U) -> Self\r\n where\r\n T: ModularPow,\r\n M: Value,\r\n {\r\n Self(self.0.modular_pow(exp, self.1.get()), self.1)\r\n }\r\n }\r\n\r\n impl Modular\r\n where\r\n T: ModularPow + Sub + Two + Zero,\r\n M: PrimeValue,\r\n {\r\n // https://en.wikipedia.org/wiki/Fermat%27s_little_theorem\r\n // p: prime && a % p > 0\r\n // => a ** (p - 1) % p = 1\r\n // => a ** (p - 2) % p = a ** -1 % p\r\n pub fn inv(self) -> Option {\r\n if self.0.is_zero() {\r\n None\r\n } else {\r\n Some(self.pow(M::get() - T::two()))\r\n }\r\n }\r\n }\r\n\r\n impl Modular\r\n where\r\n T: Abs + Copy + ModularPow + One + PartialOrd + Rem + Sub + Zero,\r\n M: Value + ValueEulersPhi,\r\n {\r\n pub fn inv_with_eulers_phi(self) -> Option {\r\n if self.0.is_zero() || gcd(self.0, self.1.get()) > T::one() {\r\n None\r\n } else {\r\n Some(self.pow(self.1.eulers_phi() - T::one()))\r\n }\r\n }\r\n }\r\n\r\n impl Eq for Modular {}\r\n\r\n impl Ord for Modular {\r\n fn cmp(&self, other: &Self) -> Ordering {\r\n self.0.cmp(&other.0)\r\n }\r\n }\r\n\r\n impl PartialEq for Modular {\r\n fn eq(&self, other: &Self) -> bool {\r\n self.0.eq(&other.0)\r\n }\r\n }\r\n\r\n impl PartialOrd for Modular {\r\n fn partial_cmp(&self, other: &Self) -> Option {\r\n self.0.partial_cmp(&other.0)\r\n }\r\n }\r\n\r\n impl PartialEq for Modular {\r\n fn eq(&self, other: &T) -> bool {\r\n self.0.eq(&other)\r\n }\r\n }\r\n\r\n impl PartialOrd for Modular {\r\n fn partial_cmp(&self, other: &T) -> Option {\r\n self.0.partial_cmp(&other)\r\n }\r\n }\r\n\r\n macro_rules! def {\r\n ( $name:ident, $fn:ident, $is:ident ) => {\r\n impl $name for Modular\r\n where\r\n T: $name + PartialOrd + Unsigned,\r\n M: ConstValue + Default + Value,\r\n {\r\n fn $fn() -> Self {\r\n assert!(T::$fn() < M::default().get());\r\n Self::from_raw_value(T::$fn())\r\n }\r\n\r\n fn $is(&self) -> bool {\r\n self.0 == T::$fn()\r\n }\r\n }\r\n };\r\n }\r\n\r\n def!(Zero, zero, is_zero);\r\n def!(One, one, is_one);\r\n def!(Two, two, is_two);\r\n def!(Three, three, is_three);\r\n def!(Five, five, is_five);\r\n def!(Ten, ten, is_ten);\r\n\r\n impl Unsigned for Modular {}\r\n\r\n impl MulDiv for Modular\r\n where\r\n Self: Div + Mul,\r\n {\r\n fn mul_div(self, mul: Self, div: Self) -> Self {\r\n self.mul(mul).div(div)\r\n }\r\n }\r\n\r\n pub type M1_000_000_007 = Modular;\r\n pub type M998_244_353 = Modular;\r\n\r\n pub type M07 = M1_000_000_007;\r\n pub type M53 = M998_244_353;\r\n}\r\n\r\nmod prelude {\r\n pub use core::borrow::{Borrow, BorrowMut};\r\n pub use core::cell::RefCell;\r\n pub use core::cmp::Ordering::{Equal, Greater, Less};\r\n pub use core::cmp::{max, min};\r\n pub use core::iter::{empty, once, repeat, FromIterator};\r\n pub use core::marker::PhantomData;\r\n pub use core::mem::{replace, swap, take};\r\n pub use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};\r\n pub use std::convert::{TryFrom, TryInto};\r\n pub use std::io::{\r\n sink, stderr, stdin, stdout, BufRead, BufReader, BufWriter, Stderr, Stdout, Write,\r\n };\r\n pub use std::str::from_utf8;\r\n pub use std::sync::Arc;\r\n\r\n // pub use crate::collections;\r\n pub use crate::define_io;\r\n pub use crate::io::Io;\r\n pub use crate::mode::Mode;\r\n pub use crate::readable::Readable;\r\n pub use crate::reader::Reader;\r\n pub use crate::writer::Writer;\r\n pub use crate::{btm, bts, hm, hs, replace_expr};\r\n pub use crate::{define_logger, define_reader, define_writer, write_arg, write_args};\r\n\r\n pub use crate::joined::Joined;\r\n pub use crate::lfmt;\r\n\r\n pub use crate::problem::Problem;\r\n pub use crate::trim_lines::TrimLines;\r\n}\r\n\r\nmod prime_value {\r\n use core::ops::Sub;\r\n\r\n use crate::const_value::ConstValue;\r\n use crate::value_eulers_phi::ValueEulersPhi;\r\n use crate::values::One;\r\n\r\n pub trait PrimeValue: Copy + ConstValue {}\r\n impl PrimeValue for P1_000_000_007 {}\r\n impl PrimeValue for P998_244_353 {}\r\n\r\n impl ValueEulersPhi for T\r\n where\r\n T::Output: One + Sub,\r\n {\r\n fn eulers_phi(self) -> Self::Output {\r\n Self::get() - Self::Output::one()\r\n }\r\n }\r\n\r\n #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]\r\n pub struct P998_244_353;\r\n\r\n #[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]\r\n pub struct P1_000_000_007;\r\n\r\n impl ConstValue for P998_244_353 {\r\n type Output = u32;\r\n fn get() -> Self::Output {\r\n 998_244_353\r\n }\r\n }\r\n\r\n impl ConstValue for P1_000_000_007 {\r\n type Output = u32;\r\n fn get() -> Self::Output {\r\n 1_000_000_007\r\n }\r\n }\r\n}\r\n\r\nmod primes {\r\n use core::iter::FusedIterator;\r\n\r\n use crate::dedup_count::DedupCount;\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct Primes {\r\n sieve: Vec,\r\n len: usize,\r\n }\r\n\r\n impl Primes {\r\n pub fn new(len: usize) -> Self {\r\n let odds_len = len / 2;\r\n let mut sieve = vec![0; odds_len];\r\n let half = (len as f64).sqrt().ceil() as usize;\r\n for j in (3..half).step_by(2) {\r\n if sieve[j / 2] == 0 {\r\n for k in (j * j..len).step_by(2 * j) {\r\n if sieve[k / 2] == 0 {\r\n sieve[k / 2] = j;\r\n }\r\n }\r\n }\r\n }\r\n Self { sieve, len }\r\n }\r\n\r\n pub fn odds_sieve(&self) -> &[usize] {\r\n &self.sieve\r\n }\r\n\r\n pub fn get_sieve_value(&self, value: usize) -> usize {\r\n if value < 4 {\r\n 0\r\n } else if value & 1 == 0 {\r\n 2\r\n } else {\r\n self.sieve[value / 2]\r\n }\r\n }\r\n\r\n pub fn is_prime(&self, value: usize) -> bool {\r\n if value < 3 {\r\n value == 2\r\n } else {\r\n value & 1 == 1 && self.sieve[value / 2] == 0\r\n }\r\n }\r\n\r\n pub fn iter(&self) -> PrimesIter<'_> {\r\n PrimesIter::new(self, 0)\r\n }\r\n\r\n pub fn iter_from(&self, from: usize) -> PrimesIter<'_> {\r\n PrimesIter::new(self, from)\r\n }\r\n\r\n pub fn factorize(&self, value: usize) -> PrimesFactorizeIter<'_> {\r\n assert!(value < self.len);\r\n PrimesFactorizeIter::new(self, value)\r\n }\r\n\r\n pub fn num_divisors(&self, value: usize) -> usize {\r\n let factorization = self.factorize(value);\r\n factorization\r\n .dedup_count()\r\n .map(|(_, count)| count + 1)\r\n .product()\r\n }\r\n\r\n pub fn eulers_phi(&self, value: usize) -> usize {\r\n if value == 1 {\r\n return 0;\r\n }\r\n let factorization = self.factorize(value);\r\n factorization.dedup_count().fold(value, |mult, (prime, _)| {\r\n ((mult as u64) * (prime - 1) as u64 / prime as u64) as usize\r\n })\r\n }\r\n }\r\n\r\n /*\r\n phi(36) = phi(2^2) * phi(3^3)\r\n */\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct PrimesIter<'a>(&'a Primes, usize);\r\n\r\n impl<'a> PrimesIter<'a> {\r\n pub fn new(sieve: &'a Primes, from: usize) -> Self {\r\n Self(sieve, if from < 3 { 0 } else { from / 2 })\r\n }\r\n }\r\n\r\n impl Iterator for PrimesIter<'_> {\r\n type Item = usize;\r\n\r\n fn next(&mut self) -> Option {\r\n if self.1 == 0 {\r\n if self.0.len > 2 {\r\n self.1 = 1;\r\n Some(2)\r\n } else {\r\n None\r\n }\r\n } else {\r\n while self.1 < self.0.sieve.len() {\r\n if self.0.sieve[self.1] != 0 {\r\n self.1 += 1;\r\n } else {\r\n let item = self.1;\r\n self.1 += 1;\r\n return Some(item * 2 + 1);\r\n }\r\n }\r\n None\r\n }\r\n }\r\n }\r\n\r\n impl FusedIterator for PrimesIter<'_> {}\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct PrimesFactorizeIter<'a>(&'a Primes, usize);\r\n\r\n impl<'a> PrimesFactorizeIter<'a> {\r\n pub fn new(sieve: &'a Primes, value: usize) -> Self {\r\n Self(sieve, value)\r\n }\r\n }\r\n\r\n impl Iterator for PrimesFactorizeIter<'_> {\r\n type Item = usize;\r\n\r\n fn next(&mut self) -> Option {\r\n if self.1 > 1 {\r\n if self.1 & 1 == 0 {\r\n self.1 /= 2;\r\n Some(2)\r\n } else {\r\n let divisor = self.0.sieve[self.1 / 2];\r\n if divisor != 0 {\r\n self.1 /= divisor;\r\n Some(divisor)\r\n } else {\r\n let item = self.1;\r\n self.1 = 1;\r\n Some(item)\r\n }\r\n }\r\n } else {\r\n None\r\n }\r\n }\r\n }\r\n\r\n impl FusedIterator for PrimesFactorizeIter<'_> {}\r\n}\r\n\r\nmod values {\r\n macro_rules! def {\r\n ( $name:ident, $fn:ident, $is:ident, $value:literal ) => {\r\n pub trait $name {\r\n fn $fn() -> Self;\r\n fn $is(&self) -> bool;\r\n }\r\n def!(\r\n @impl $name, $fn, $is, $value,\r\n u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize\r\n );\r\n };\r\n ( @impl $name:ident, $fn:ident, $is:ident, $value:literal, $ty:ty $(, $($ts:ty),*)? ) => {\r\n impl $name for $ty {\r\n fn $fn() -> Self {\r\n $value\r\n }\r\n\r\n fn $is(&self) -> bool {\r\n *self == $value\r\n }\r\n }\r\n $( def!(@impl $name, $fn, $is, $value, $($ts),*); )?\r\n };\r\n }\r\n\r\n def!(Zero, zero, is_zero, 0);\r\n def!(One, one, is_one, 1);\r\n def!(Two, two, is_two, 2);\r\n def!(Three, three, is_three, 3);\r\n def!(Five, five, is_five, 5);\r\n def!(Ten, ten, is_ten, 10);\r\n}\r\n\r\nmod ops {\r\n macro_rules! def {\r\n ((\r\n $trait:ident $( ($($bounds:tt)*) )?,\r\n fn $fn:ident($($self:ident $(, $arg:ident: $arg_ty:ty)*)?) -> $ret:ty {\r\n u: $uexpr:expr, i: $iexpr:expr\r\n }\r\n )) => {\r\n pub trait $trait $( where $($bounds)* )? {\r\n fn $fn($($self $(, $arg: $arg_ty)*)?) -> $ret;\r\n }\r\n def!(@impl $trait, fn $fn($($self $(, $arg: $arg_ty)*)?) -> $ret {\r\n u8: $uexpr, u16: $uexpr, u32: $uexpr, u64: $uexpr, u128: $uexpr, usize: $uexpr,\r\n i8: $iexpr, i16: $iexpr, i32: $iexpr, i64: $iexpr, i128: $iexpr, isize: $iexpr\r\n });\r\n };\r\n ((\r\n $trait:ident $( ($($bounds:tt)*) )?,\r\n fn $fn:ident($($self:ident $(, $arg:ident: $arg_ty:ty)*)?) -> $ret:ty { $expr:expr }\r\n )) => {\r\n pub trait $trait $( where $($bounds)* )? {\r\n fn $fn($($self $(, $arg: $arg_ty)*)?) -> $ret;\r\n }\r\n def!(@impl $trait, fn $fn($($self $(, $arg: $arg_ty)*)?) -> $ret {\r\n u8: $expr, u16: $expr, u32: $expr, u64: $expr, u128: $expr, usize: $expr,\r\n i8: $expr, i16: $expr, i32: $expr, i64: $expr, i128: $expr, isize: $expr\r\n });\r\n };\r\n (@impl $trait:ident, fn $fn:ident($($tt:tt)*) -> $ret:ty {}) => {};\r\n (\r\n @impl $trait:ident,\r\n fn $fn:ident($($self:ident $(, $arg: ident: $arg_ty: ty)*)?) -> $ret:ty {\r\n $ty:tt: $expr:expr $(, $ts:tt: $es:expr)*\r\n }\r\n ) => {\r\n impl $trait for $ty {\r\n fn $fn($($self $(, $arg: $arg_ty)*)?) -> $ret {\r\n $expr\r\n }\r\n }\r\n def!(@impl $trait, fn $fn($($self $(, $arg: $arg_ty)*)?) -> $ret { $($ts: $es),* });\r\n };\r\n }\r\n\r\n def!((Min, fn min() -> Self { Self::MIN } ));\r\n def!((Max, fn max() -> Self { Self::MAX } ));\r\n def!((Abs, fn abs(self) -> Self { u: self, i: self.abs() } ));\r\n def!((TrailingZeros, fn trailing_zeros(self) -> u32 { self.trailing_zeros() } ));\r\n def!((DivEuclid, fn div_euclid(self, rhs: Self) -> Self { self.div_euclid(rhs) } ));\r\n def!((RemEuclid, fn rem_euclid(self, rhs: Self) -> Self { self.rem_euclid(rhs) } ));\r\n def!((CheckedMul(Self: Sized), fn checked_mul(self, rhs: Self) -> Option {\r\n self.checked_mul(rhs)\r\n } ));\r\n}\r\n\r\nmod gcd {\r\n use core::ops::Rem;\r\n\r\n use crate::ops::Abs;\r\n use crate::values::Zero;\r\n\r\n // https://en.wikipedia.org/wiki/Euclidean_algorithm\r\n // gcd(a, b) = gcd(a - b, a): gcd(14, 10) = gcd(4, 10)\r\n pub fn gcd(lhs: T, rhs: T) -> T\r\n where\r\n T: Abs + Clone + Rem + Zero,\r\n {\r\n if rhs.is_zero() {\r\n lhs.abs()\r\n } else {\r\n gcd(rhs.clone(), lhs % rhs)\r\n }\r\n }\r\n}\r\n\r\nmod modular_mul {\r\n pub trait ModularMul {\r\n fn modular_mul(self, other: Self, modulus: Self) -> Self;\r\n }\r\n\r\n macro_rules! def {\r\n ( $low:ty, $hi:ty $(, $rest:ty)* ) => {\r\n impl ModularMul for $low {\r\n fn modular_mul(self, other: $low, modulus: Self) -> Self {\r\n (((self as $hi) * (other as $hi)).rem_euclid(modulus as $hi)) as $low\r\n }\r\n }\r\n def!($hi $(, $rest)*);\r\n };\r\n ( $last:ty ) => {};\r\n }\r\n\r\n def!(u8, u16, u32, u64, u128);\r\n}\r\n\r\nmod modular_pow {\r\n use core::ops::{Add, BitAnd, Mul, Rem, ShrAssign};\r\n\r\n use crate::modular_mul::ModularMul;\r\n use crate::values::{One, Zero};\r\n\r\n pub trait ModularPow {\r\n fn modular_pow(self, exp: U, modulus: Self) -> Self;\r\n }\r\n\r\n macro_rules! def {\r\n ( $low:ty, $hi:ty $(, $rest:ty)* ) => {\r\n impl ModularPow for $low\r\n where\r\n U: One\r\n + BitAnd\r\n + Clone\r\n + Copy\r\n + PartialEq\r\n + PartialOrd\r\n + ShrAssign\r\n + Zero,\r\n {\r\n // https://doc.rust-lang.org/src/core/num/uint_macros.rs.html#1538-1558\r\n fn modular_pow(self, mut exp: U, modulus: Self) -> Self {\r\n if exp == U::zero() {\r\n return Self::one();\r\n }\r\n let mut base = self;\r\n let mut acc = Self::one();\r\n\r\n while exp > U::one() {\r\n if (exp & U::one()) == U::one() {\r\n acc = acc.modular_mul(base, modulus);\r\n }\r\n exp >>= U::one();\r\n base = base.modular_mul(base, modulus);\r\n }\r\n\r\n acc.modular_mul(base, modulus)\r\n }\r\n }\r\n def!($hi $(, $rest)*);\r\n };\r\n ( $last:ty ) => {};\r\n }\r\n\r\n def!(u8, u16, u32, u64, u128);\r\n}\r\n\r\nmod mul_div {\r\n pub trait MulDiv {\r\n fn mul_div(self, mul: Self, div: Self) -> Self;\r\n }\r\n\r\n macro_rules! def {\r\n ( $low:ty, $hi:ty $(, $rest:ty)* ) => {\r\n impl MulDiv for $low {\r\n fn mul_div(self, mul: Self, div: Self) -> Self {\r\n ((self as $hi) * (mul as $hi) / (div as $hi)) as $low\r\n }\r\n }\r\n def!($hi $(, $rest)*);\r\n };\r\n ( $last:ty ) => {};\r\n }\r\n\r\n def!(u8, u16, u32, u64, u128);\r\n def!(i8, i16, i32, i64, i128);\r\n}\r\n\r\nmod unsigned {\r\n pub trait Unsigned {}\r\n\r\n macro_rules! def {\r\n ( $($ty:ty),* ) => {\r\n $( impl Unsigned for $ty {} )*\r\n };\r\n }\r\n\r\n def!(u8, u16, u32, u64, u128, usize);\r\n}\r\n\r\nmod value {\r\n use crate::const_value::ConstValue;\r\n\r\n pub trait Value: Copy {\r\n type Output;\r\n fn get(self) -> Self::Output;\r\n }\r\n\r\n impl Value for (T,) {\r\n type Output = T;\r\n fn get(self) -> Self::Output {\r\n self.0\r\n }\r\n }\r\n\r\n impl Value for T {\r\n type Output = ::Output;\r\n fn get(self) -> Self::Output {\r\n Self::get()\r\n }\r\n }\r\n}\r\n\r\nmod value_eulers_phi {\r\n use crate::value::Value;\r\n\r\n pub trait ValueEulersPhi: Value {\r\n fn eulers_phi(self) -> Self::Output;\r\n }\r\n}\r\n\r\nmod collections {\r\n #[macro_export]\r\n macro_rules! replace_expr {\r\n ($_t:tt $sub:expr) => {\r\n $sub\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! bts {\r\n () => {\r\n std::collections::BTreeSet::new()\r\n };\r\n ($($x:expr),+ $(,)?) => {{\r\n let mut collection = std::collections::BTreeSet::new();\r\n $( let _ = collection.insert($x); )+\r\n collection\r\n }};\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! btm {\r\n () => {\r\n std::collections::BTreeMap::new()\r\n };\r\n ($(($k:expr, $v:expr)),+ $(,)?) => {{\r\n let mut collection = std::collections::BTreeMap::new();\r\n $( let _ = collection.insert($k, $v); )+\r\n collection\r\n }};\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! hs {\r\n () => {\r\n std::collections::HashSet::new()\r\n };\r\n ($($x:expr),+ $(,)?) => {{\r\n let mut collection = std::collections::HashSet::with_capacity([$(crate::replace_expr!($x ())),+].len());\r\n $( let _ = collection.insert($x); )+\r\n collection\r\n }};\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! hm {\r\n () => {\r\n std::collections::HashMap::new()\r\n };\r\n ($(($k:expr, $v:expr)),+ $(,)?) => {{\r\n let mut collection = std::collections::HashMap::with_capacity([$(crate::replace_expr!($v ())),+].len());\r\n $( let _ = collection.insert($k, $v); )+\r\n collection\r\n }};\r\n }\r\n}\r\n\r\nmod define_io {\r\n #[macro_export]\r\n macro_rules! define_io {\r\n ( $io:expr ) => {\r\n let _ = $io;\r\n $crate::define_reader!($io.reader);\r\n $crate::define_writer!($io.writer);\r\n $crate::define_logger!($io.logger);\r\n $crate::forbid_stdio!();\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! define_reader {\r\n ( $reader:expr ) => {\r\n let _ = $reader;\r\n $crate::define_reader!(@impl ($)($reader));\r\n };\r\n ( @impl ($d:tt)($reader:expr) ) => {\r\n #[allow(unused_macros)]\r\n macro_rules! re {\r\n () => {\r\n $reader.read().unwrap()\r\n };\r\n ( [$d ty:tt; [$d len1:expr, $d len2:expr]] ) => {{\r\n let value: NdArray<$d ty, Vec<$d ty>, _, _> =\r\n NdArray::with(|| re!($d ty), [$d len1, $d len2]);\r\n value\r\n }};\r\n ( [$d ty:tt; $d len:literal] ) => {{\r\n let mut value: [_; $d len] = core::default::Default::default();\r\n for j in 0..$d len {\r\n value[j] = re!($d ty);\r\n }\r\n value\r\n }};\r\n ( [$d ty:tt; $d len:expr] ) => {\r\n re!( Vec<_> [$d ty; $d len] );\r\n };\r\n ( vec[$d ty:tt; $d len:expr] ) => {\r\n re!( Vec<_> [$d ty; $d len] );\r\n };\r\n ( bts[$d ty:tt; $d len:expr] ) => {\r\n re!( std::collections::BTreeSet<_> [$d ty; $d len] );\r\n };\r\n ( hs[$d ty:tt; $d len:expr] ) => {\r\n re!( std::collections::HashSet<_> [$d ty; $d len] );\r\n };\r\n ( ascii ) => {\r\n re!( Ascii> ).0;\r\n };\r\n ( ascii[$d len:expr] ) => {\r\n re!( Ascii> ).0;\r\n };\r\n ( dec ) => {\r\n re!( Decimal> ).0;\r\n };\r\n ( dec[$d len:expr] ) => {\r\n re!( Decimal> ).0;\r\n };\r\n ( bits[$d ch:tt] ) => {{\r\n let value: Vec = $reader.read_bits($d ch).unwrap().collect();\r\n value\r\n }};\r\n ( bits[$d true:literal; $d len:expr] ) => {{\r\n let value: Vec = (0..$d len).map(|_|\r\n $reader.read_word().unwrap() == $d true\r\n ).collect();\r\n value\r\n }};\r\n ( $d collection:ty [$d ty:tt; $d len:expr] ) => {{\r\n #[allow(unused_qualifications)]\r\n let value: $d collection = (0..$d len).map(|_| re!($d ty)).collect();\r\n value\r\n }};\r\n ( ch ) => {{\r\n let value = $reader.read_char().unwrap();\r\n value as u8\r\n }};\r\n ( &str ) => {{\r\n let value: &str = $reader.read_word().unwrap();\r\n value\r\n }};\r\n (( $d ty:ty )) => {{\r\n let value: $d ty = $reader.read().unwrap();\r\n value\r\n }};\r\n ( $d ty:ty ) => {{\r\n let value: $d ty = $reader.read().unwrap();\r\n value\r\n }};\r\n }\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! define_writer {\r\n ( $writer:expr ) => {\r\n let _ = $writer;\r\n $crate::define_writer!(@impl ($)($writer));\r\n };\r\n ( @impl ($d:tt)($writer:expr) ) => {\r\n #[allow(unused_macros)]\r\n macro_rules! ln {\r\n ( $d($d tt:tt)* ) => {{\r\n write_args!($writer, \"\", { $writer.space() }, (), ($d($d tt)*));\r\n $writer.ln();\r\n }};\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! wr {\r\n ( $d($d tt:tt)* ) => {{\r\n write_args!($writer, \"\", { $writer.space() }, (), ($d($d tt)*));\r\n }};\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! lf {\r\n ( $d( $d tt:tt )* ) => {{\r\n writeln!($writer.writer_mut(), $d( $d tt )*).unwrap();\r\n }}\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! wf {\r\n ( $d( $d tt:tt )* ) => {{\r\n write!($writer.writer_mut(), $d( $d tt )*).unwrap();\r\n }}\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! jo {\r\n ( $d($d tt:tt)* ) => {{\r\n write_args!($writer, \"\", {}, (), ($d($d tt)*));\r\n }};\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! fl {\r\n () => { $writer.flush() }\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! yes {\r\n () => { ln!(\"YES\") }\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! no {\r\n () => { ln!(\"NO\") }\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! ask {\r\n ( $d( $d tt:tt )* ) => {{\r\n ln!( \"?\", $d( $d tt )* );\r\n $writer.flush();\r\n }}\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! ans {\r\n ( $d( $d tt:tt )* ) => {{\r\n ln!( \"!\", $d( $d tt )* );\r\n $writer.flush();\r\n }}\r\n }\r\n\r\n #[allow(unused_macros)] macro_rules! dbg { () => {} }\r\n #[allow(unused_macros)] macro_rules! print { () => {} }\r\n #[allow(unused_macros)] macro_rules! println { () => {} }\r\n #[allow(unused_macros)] macro_rules! eprint { () => {} }\r\n #[allow(unused_macros)] macro_rules! eprintln { () => {} }\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! define_logger {\r\n ( $logger:expr ) => {\r\n let _ = $logger;\r\n $crate::define_logger!(@impl ($)($logger));\r\n };\r\n ( @impl ($d:tt)($logger:expr) ) => {\r\n #[allow(unused_macros)]\r\n macro_rules! dd {\r\n { $d expr:expr } => {\r\n if $logger.is_some() {\r\n $d expr\r\n }\r\n };\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! dln {\r\n ( $d($d tt:tt)* ) => {{\r\n if let Some(logger) = $logger.as_mut() {\r\n logger.debug_line_prefix(::core::line!());\r\n write_args!(logger, \":?\", { logger.seperator(\", \") }, (), ($d($d tt)*));\r\n logger.ln();\r\n }\r\n }};\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! dwr {\r\n ( $d($d tt:tt)* ) => {{\r\n if let Some(logger) = $logger.as_mut() {\r\n logger.debug_line_prefix(::core::line!());\r\n write_args!(logger, \":?\", { logger.seperator(\", \") }, (), ($d($d tt)*));\r\n }\r\n }};\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! dlf {\r\n ( $d( $d tt:tt )* ) => {{\r\n if let Some(logger) = $logger.as_mut() {\r\n logger.debug_line_prefix(::core::line!());\r\n writeln!(logger.writer_mut(), $d( $d tt )*).unwrap();\r\n }\r\n }}\r\n }\r\n\r\n #[allow(unused_macros)]\r\n macro_rules! dwf {\r\n ( $d( $d tt:tt )* ) => {{\r\n if let Some(logger) = $logger.as_mut() {\r\n logger.debug_line_prefix(::core::line!());\r\n write!(logger.writer_mut(), $d( $d tt )*).unwrap();\r\n }\r\n }}\r\n }\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! forbid_stdio {\r\n () => {\r\n #[allow(unused_macros)]\r\n macro_rules! dbg {\r\n () => {\r\n compile_error!();\r\n };\r\n }\r\n #[allow(unused_macros)]\r\n macro_rules! print {\r\n () => {\r\n compile_error!();\r\n };\r\n }\r\n #[allow(unused_macros)]\r\n macro_rules! println {\r\n () => {\r\n compile_error!();\r\n };\r\n }\r\n #[allow(unused_macros)]\r\n macro_rules! eprint {\r\n () => {\r\n compile_error!();\r\n };\r\n }\r\n #[allow(unused_macros)]\r\n macro_rules! eprintln {\r\n () => {\r\n compile_error!();\r\n };\r\n }\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! write_args {\r\n ( $writer:expr, $format:literal, $sep:expr, (), ( $(,)? ) ) => {};\r\n ( $writer:expr, $format:literal, $sep:expr, ( $($args:expr),* ), ( .. $($rest:tt)* ) ) => {\r\n write_args!( $writer, $format, $sep, ( (\"\", \" \", \"\") $(, $args)* ), ( $($rest)* ));\r\n };\r\n ( $writer:expr, $format:literal, $sep:expr, ( $($args:expr),* ), ( ## $($rest:tt)* ) ) => {\r\n write_args!( $writer, $format, $sep, ( (\"\", \"\\n\", \"\") $(, $args)* ), ( $($rest)* ));\r\n };\r\n ( $writer:expr, $format:literal, $sep:expr, ( $($args:expr),* ), ( && $($rest:tt)* ) ) => {\r\n write_args!( $writer, $format, $sep, ( (\"\", \"\", \"\") $(, $args)* ), ( $($rest)* ));\r\n };\r\n (\r\n $writer:expr, $format:literal, $sep:expr,\r\n ( $($args:expr),* ), ( ?? $expr:expr $(, $($rest:tt)*)? )\r\n ) => {\r\n $sep;\r\n write_arg!( $writer, \"\", ::core::concat!(::core::stringify!($expr), \" = \"), (), ());\r\n write_arg!( $writer, $format, $expr, (), ( $($args),* ));\r\n write_args!( $writer, $format, $sep, (), ( $($($rest)*)? ));\r\n };\r\n (\r\n $writer:expr, $format:literal, $sep:expr,\r\n ( $($args:expr),* ), ( $expr:expr $(, $($rest:tt)*)? )\r\n ) => {\r\n $sep;\r\n write_arg!( $writer, $format, $expr, (), ( $($args),* ));\r\n write_args!( $writer, $format, $sep, (), ( $($($rest)*)? ));\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! write_arg {\r\n ( $writer:expr, $format:literal, $expr:expr, $tail:expr, ( $head:expr $(, $rest:expr)* ) ) => {\r\n write_arg!( $writer, $format, $expr, ($head, $tail), ( $($rest),* ));\r\n };\r\n ( $writer:expr, $format:literal, $expr:expr, (), () ) => {\r\n write!($writer.writer_mut(), ::core::concat!(\"{\", $format, \"}\"), &$expr).unwrap();\r\n };\r\n ( $writer:expr, $format:literal, $expr:expr, $tail:expr, () ) => {\r\n write!(\r\n $writer.writer_mut(),\r\n ::core::concat!(\"{\", $format, \"}\"),\r\n $crate::joined::Joined::new($expr, $tail)\r\n ).unwrap();\r\n };\r\n }\r\n}\r\n\r\nmod io {\r\n pub use std::io::{BufRead, BufReader, BufWriter, Read, Sink, Write};\r\n\r\n use crate::mode::Mode;\r\n use crate::reader::Reader;\r\n use crate::writer::Writer;\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct Io {\r\n pub reader: Reader,\r\n pub writer: Writer,\r\n pub logger: Option>,\r\n }\r\n\r\n impl Io, BufWriter, Sink> {\r\n pub fn new(reader: R, writer: W) -> Self {\r\n let reader = Reader::new(BufReader::new(reader));\r\n let writer = Writer::new(BufWriter::new(writer));\r\n let logger = None;\r\n Self {\r\n reader,\r\n writer,\r\n logger,\r\n }\r\n }\r\n\r\n pub fn with_logger(self, logger: L) -> Io, BufWriter, L> {\r\n let reader = self.reader;\r\n let writer = self.writer;\r\n let logger = Some(Writer::new(logger));\r\n Io {\r\n reader,\r\n writer,\r\n logger,\r\n }\r\n }\r\n }\r\n}\r\n\r\nmod mode {\r\n #[derive(Clone, Copy, Debug, Eq, PartialEq)]\r\n pub enum Mode {\r\n Release,\r\n Debug,\r\n }\r\n\r\n impl Mode {\r\n pub fn is_release(self) -> bool {\r\n self == Self::Release\r\n }\r\n\r\n pub fn is_debug(self) -> bool {\r\n self == Self::Debug\r\n }\r\n }\r\n}\r\n\r\nmod readable {\r\n use std::fmt;\r\n use std::io::{self, BufRead};\r\n\r\n use crate::reader::Reader;\r\n\r\n pub trait Readable: Sized {\r\n fn read(reader: &mut Reader) -> io::Result;\r\n }\r\n\r\n pub trait ReadableWithFromStr {}\r\n\r\n macro_rules! def {\r\n ( $($ty:ty),* ) => {\r\n $( impl ReadableWithFromStr for $ty {} )*\r\n };\r\n }\r\n def!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize, f32, f64);\r\n\r\n impl Readable for T\r\n where\r\n T: std::str::FromStr + ReadableWithFromStr,\r\n T::Err: fmt::Debug,\r\n {\r\n #[track_caller]\r\n fn read(reader: &mut Reader) -> io::Result {\r\n Ok(reader.read_word()?.parse::().unwrap())\r\n }\r\n }\r\n\r\n impl Readable for String {\r\n #[track_caller]\r\n fn read(reader: &mut Reader) -> io::Result {\r\n Ok(reader.read_word()?.to_string())\r\n }\r\n }\r\n\r\n impl Readable for char {\r\n #[track_caller]\r\n fn read(reader: &mut Reader) -> io::Result {\r\n Ok(reader.read_char()?)\r\n }\r\n }\r\n\r\n macro_rules! def {\r\n ( $($tn:ident),* ) => {\r\n def!(@impl ()( $($tn),* ));\r\n };\r\n ( @impl ( $($ts:ident),* ) ) => {\r\n impl< $($ts),* > Readable for ( $($ts,)* )\r\n where\r\n $($ts: Readable,)*\r\n {\r\n #[track_caller]\r\n fn read(reader: &mut Reader) -> io::Result {\r\n Ok(( $($ts::read(reader)?,)* ))\r\n }\r\n }\r\n };\r\n ( @impl ( $($ts:ident),* )() ) => {};\r\n ( @impl ( $($ts:ident),* )( $t1:ident $(, $tn:ident)* ) ) => {\r\n def!(@impl ( $($ts,)* $t1 ));\r\n def!(@impl ( $($ts,)* $t1 )( $($tn),* ));\r\n };\r\n }\r\n def!(T1, T2, T3, T4, T5, T6, T7, T8);\r\n}\r\n\r\nmod reader {\r\n use std::io::{self, BufRead};\r\n\r\n use crate::readable::Readable;\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct Reader {\r\n reader: R,\r\n line: String,\r\n offset: usize,\r\n }\r\n\r\n impl Reader {\r\n pub fn new(reader: R) -> Self {\r\n Self {\r\n reader,\r\n line: String::new(),\r\n offset: 0,\r\n }\r\n }\r\n\r\n pub fn reader(&self) -> &R {\r\n &self.reader\r\n }\r\n\r\n pub fn reader_mut(&mut self) -> &mut R {\r\n &mut self.reader\r\n }\r\n\r\n #[track_caller]\r\n fn goto_word(&mut self) -> io::Result<()> {\r\n loop {\r\n if self.offset >= self.line.len() {\r\n self.line.clear();\r\n let len = self.reader.read_line(&mut self.line)?;\r\n if len == 0 {\r\n panic!(\"Unexpected EOF\");\r\n }\r\n self.offset = 0;\r\n } else if self.line.as_bytes()[self.offset].is_ascii_whitespace() {\r\n self.offset += 1;\r\n } else {\r\n return Ok(());\r\n }\r\n }\r\n }\r\n\r\n #[track_caller]\r\n pub fn read_word(&mut self) -> io::Result<&str> {\r\n self.goto_word()?;\r\n let line = self.line.as_bytes();\r\n let start = self.offset;\r\n let mut end = start + 1;\r\n while end < self.line.len() && !line[end].is_ascii_whitespace() {\r\n end += 1;\r\n }\r\n self.offset = end + 1;\r\n let word = unsafe { std::str::from_utf8_unchecked(&line[start..end]) };\r\n return Ok(word);\r\n }\r\n\r\n #[track_caller]\r\n pub fn read_char(&mut self) -> io::Result {\r\n self.goto_word()?;\r\n let ch = self.line[self.offset..].chars().next().unwrap();\r\n self.offset += ch.len_utf8();\r\n return Ok(ch);\r\n }\r\n\r\n #[track_caller]\r\n pub fn read(&mut self) -> io::Result {\r\n T::read(self)\r\n }\r\n\r\n #[track_caller]\r\n pub fn read_n(\r\n &mut self,\r\n len: usize,\r\n ) -> impl '_ + Iterator> {\r\n (0..len).map(move |_| T::read(self))\r\n }\r\n\r\n #[track_caller]\r\n pub fn read_ascii(&mut self) -> Result<&[u8], io::Error> {\r\n Ok(self.read_word()?.as_bytes())\r\n }\r\n\r\n #[track_caller]\r\n pub fn read_decimal(&mut self) -> Result, io::Error> {\r\n Ok(self\r\n .read_ascii()?\r\n .iter()\r\n .inspect(|&&ch| assert!(ch >= b'0' && ch <= b'9'))\r\n .map(|ch| ch - b'0'))\r\n }\r\n\r\n #[track_caller]\r\n pub fn read_bits(&mut self, one: u8) -> Result, io::Error> {\r\n Ok(self.read_ascii()?.iter().map(move |ch| *ch == one))\r\n }\r\n }\r\n}\r\n\r\nmod writer {\r\n use core::fmt::Display;\r\n use std::io::{self, Write};\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct Writer {\r\n writer: W,\r\n is_new_line: bool,\r\n }\r\n\r\n impl Writer {\r\n pub fn new(writer: W) -> Self {\r\n Self {\r\n writer,\r\n is_new_line: true,\r\n }\r\n }\r\n\r\n pub fn writer(&self) -> &W {\r\n &self.writer\r\n }\r\n\r\n pub fn writer_mut(&mut self) -> &mut W {\r\n &mut self.writer\r\n }\r\n\r\n pub fn is_new_line(&self) -> bool {\r\n self.is_new_line\r\n }\r\n\r\n pub fn space(&mut self) {\r\n if self.is_new_line {\r\n self.is_new_line = false;\r\n } else {\r\n write!(self.writer, \" \").unwrap();\r\n }\r\n }\r\n\r\n pub fn seperator(&mut self, seperator: &str) {\r\n if self.is_new_line {\r\n self.is_new_line = false;\r\n } else {\r\n write!(self.writer, \"{}\", seperator).unwrap();\r\n }\r\n }\r\n\r\n pub fn ln(&mut self) {\r\n self.is_new_line = true;\r\n writeln!(self.writer).unwrap();\r\n }\r\n\r\n pub fn flush(&mut self) {\r\n self.writer.flush().unwrap();\r\n }\r\n\r\n pub fn debug_line_prefix(&mut self, line: u32) {\r\n if self.is_new_line {\r\n write!(self.writer, \"[{}] \", line).unwrap();\r\n }\r\n }\r\n }\r\n}\r\n\r\nmod joined {\r\n use core::cell::RefCell;\r\n use core::fmt::{self, Debug, Display, Formatter};\r\n\r\n #[derive(Clone)]\r\n pub struct Joined(RefCell>, S);\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct JoinedOnce(pub I, pub S);\r\n\r\n impl Joined {\r\n pub fn new(iterable: I, seperators: S) -> Self {\r\n let iterable = RefCell::new(Some(iterable));\r\n Self(iterable, seperators)\r\n }\r\n }\r\n\r\n impl JoinedOnce {\r\n pub fn new(iterable: I, seperators: S) -> Self {\r\n Self(iterable, seperators)\r\n }\r\n }\r\n\r\n macro_rules! def {\r\n ( $display:ident, $joined:ident ) => {\r\n pub trait $joined {\r\n fn into_fmt(self, f: &mut Formatter<'_>) -> fmt::Result;\r\n }\r\n\r\n impl $display for Joined\r\n where\r\n JoinedOnce: $joined,\r\n S: Copy,\r\n {\r\n fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {\r\n let iterable = self.0.borrow_mut().take().unwrap();\r\n JoinedOnce::new(iterable, self.1).into_fmt(f)\r\n }\r\n }\r\n\r\n impl $joined for JoinedOnce\r\n where\r\n I: IntoIterator,\r\n Ss: Copy,\r\n JoinedOnce: $joined,\r\n {\r\n fn into_fmt(self, f: &mut Formatter<'_>) -> fmt::Result {\r\n let mut iter = self.0.into_iter();\r\n f.write_str(self.1 .0 .0)?;\r\n if let Some(first) = iter.next() {\r\n JoinedOnce::new(first, self.1 .1).into_fmt(f)?;\r\n for item in iter {\r\n f.write_str(self.1 .0 .1)?;\r\n JoinedOnce::new(item, self.1 .1).into_fmt(f)?;\r\n }\r\n }\r\n f.write_str(self.1 .0 .2)?;\r\n Ok(())\r\n }\r\n }\r\n\r\n impl $joined for JoinedOnce\r\n where\r\n T: $display,\r\n {\r\n fn into_fmt(self, f: &mut Formatter<'_>) -> fmt::Result {\r\n self.0.fmt(f)\r\n }\r\n }\r\n };\r\n }\r\n\r\n def!(Display, JoinedDisplay);\r\n def!(Debug, JoinedDebug);\r\n}\r\n\r\nmod lfmt {\r\n #[macro_export]\r\n macro_rules! lfmt {\r\n () => {{ \"\" }};\r\n ( @impl ($($pattern:literal),*) $(, ($($args:tt)*))? ) => {{\r\n use ::core::fmt::{Debug, Display, Formatter, Result};\r\n\r\n #[derive(Clone, Copy)]\r\n struct LazyFormat) -> Result>(F);\r\n\r\n impl) -> Result> Debug for LazyFormat {\r\n #[inline]\r\n fn fmt(&self, f: &mut Formatter<'_>) -> Result {\r\n f.write_str(concat!(\"lazy_format(\", stringify!(\r\n ::core::concat!($($pattern)*),\r\n $(, $($args)*)?), \")\"))?;\r\n (self.0)(f)\r\n }\r\n }\r\n\r\n impl) -> Result> Display for LazyFormat {\r\n #[inline]\r\n fn fmt(&self, f: &mut Formatter<'_>) -> Result {\r\n (self.0)(f)\r\n }\r\n }\r\n\r\n LazyFormat(#[inline] move |fmt: &mut Formatter<'_>| -> Result {\r\n ::core::write!(fmt, ::core::concat!($($pattern),*) $(, $($args)*)?)\r\n })\r\n }};\r\n ( @impl $($pattern:literal: $args:expr),* ) => {{\r\n $crate::lfmt!( @impl ($($pattern),*), ($($args),*) )\r\n }};\r\n ( $pattern:literal $(, $($args:tt)*)? ) => {{\r\n $crate::lfmt!( @impl ($pattern) $(, ($($args)*))? )\r\n }};\r\n ( , $arg:expr $(, $args:expr)* ) => {{\r\n $crate::lfmt!( @impl \"{}\": $arg $(, \" {}\": $args)* )\r\n }};\r\n }\r\n}\r\n\r\nmod problem {\r\n use std::io::{self, BufRead, Write};\r\n use std::str::from_utf8;\r\n\r\n use crate::io::Io;\r\n use crate::mode::Mode;\r\n use crate::trim_lines::TrimLines;\r\n\r\n pub trait Problem {\r\n fn solve(io: &mut Io);\r\n\r\n fn output(reader: &[u8]) -> String {\r\n let mut output = Vec::new();\r\n let writer = &mut output;\r\n Self::solve(&mut Io::new(reader, writer).with_logger(io::stderr()));\r\n from_utf8(&output).unwrap().to_string()\r\n }\r\n\r\n #[track_caller]\r\n fn test(input: &str) {\r\n let mut is_ok = true;\r\n let mut splitted = input.split_whitespace();\r\n let io_seperator = splitted.next().unwrap();\r\n let case_seperator = splitted.next().unwrap();\r\n for case in input.split(case_seperator).skip(1) {\r\n let io: Vec<&str> = case.split(io_seperator).collect();\r\n assert_eq!(io.len(), 2);\r\n let input = io[0];\r\n let output = Self::output(io[0].as_bytes());\r\n let answer = io[1].trim_lines();\r\n if output != answer {\r\n let mut diff = String::new();\r\n let mut output_lines = output.trim_end().split(\"\\n\");\r\n let mut answer_lines = answer.trim_end().split(\"\\n\");\r\n loop {\r\n let (output_line, answer_line) = (output_lines.next(), answer_lines.next());\r\n if output_line.is_none() && answer_line.is_none() {\r\n break;\r\n }\r\n match (output_line, answer_line) {\r\n (None, None) => break,\r\n (Some(output_line), Some(answer_line)) => {\r\n if output_line == answer_line {\r\n diff = diff + \"\\x1b[0;33m \" + output_line + \"\\x1b[0m\\n\";\r\n } else {\r\n diff = diff + \"\\x1b[0;31m - \" + output_line + \"\\x1b[0m\\n\";\r\n diff = diff + \"\\x1b[0;32m + \" + answer_line + \"\\x1b[0m\\n\";\r\n }\r\n }\r\n (Some(output_line), None) => {\r\n diff = diff + \"\\x1b[0;31m - \" + output_line + \"\\x1b[0m\\n\";\r\n }\r\n (None, Some(answer_line)) => {\r\n diff = diff + \"\\x1b[0;32m + \" + answer_line + \"\\x1b[0m\\n\";\r\n }\r\n }\r\n }\r\n writeln!(\r\n io::stderr(),\r\n \"{}\\nInput:\\n{}Output:\\n{}Answer:\\n{}Diff:\\n{}\",\r\n \"\\x1b[0;31mError: Invalid output.\\x1b[0m\",\r\n input\r\n .trim_lines()\r\n .lines()\r\n .map(|line| format!(\" {}\\n\", line))\r\n .collect::(),\r\n output\r\n .lines()\r\n .map(|line| format!(\" {}\\n\", line))\r\n .collect::(),\r\n answer\r\n .lines()\r\n .map(|line| format!(\" {}\\n\", line))\r\n .collect::(),\r\n diff\r\n )\r\n .unwrap();\r\n is_ok = false;\r\n }\r\n }\r\n if !is_ok {\r\n panic!();\r\n }\r\n }\r\n }\r\n}\r\n\r\nmod trim_lines {\r\n pub trait TrimLines {\r\n fn trim_lines(self) -> String;\r\n }\r\n\r\n impl TrimLines for &str {\r\n fn trim_lines(self) -> String {\r\n let lines: Vec = self\r\n .trim()\r\n .lines()\r\n .map(|line| line.trim().to_string())\r\n .collect();\r\n lines.join(\"\\n\") + \"\\n\"\r\n }\r\n }\r\n}\r\n\r\nmod dedup_count {\r\n use core::iter::FusedIterator;\r\n\r\n #[derive(Clone, Debug)]\r\n pub struct DedupCountIter {\r\n iter: I,\r\n prev: Option<(T, usize)>,\r\n }\r\n\r\n impl DedupCountIter {\r\n pub fn new(iter: I) -> Self {\r\n Self { iter, prev: None }\r\n }\r\n }\r\n\r\n impl Iterator for DedupCountIter\r\n where\r\n T: Eq,\r\n I: Iterator,\r\n {\r\n type Item = (T, usize);\r\n\r\n fn next(&mut self) -> Option {\r\n loop {\r\n match (self.prev.take(), self.iter.next()) {\r\n (Some((prev, count)), Some(item)) => {\r\n if prev == item {\r\n self.prev = Some((prev, count + 1));\r\n } else {\r\n self.prev = Some((item, 1));\r\n return Some((prev, count));\r\n }\r\n }\r\n (Some((prev, count)), None) => {\r\n return Some((prev, count));\r\n }\r\n (None, Some(item)) => self.prev = Some((item, 1)),\r\n (None, None) => {\r\n return None;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n impl FusedIterator for DedupCountIter\r\n where\r\n T: Eq,\r\n I: Iterator,\r\n {\r\n }\r\n\r\n pub trait DedupCount {\r\n type Output;\r\n fn dedup_count(self) -> Self::Output;\r\n }\r\n\r\n impl DedupCount for I\r\n where\r\n I: IntoIterator,\r\n {\r\n type Output = DedupCountIter;\r\n fn dedup_count(self) -> Self::Output {\r\n DedupCountIter::new(self.into_iter())\r\n }\r\n }\r\n}\r\n", "src_uid": "a524aa54e83fd0223489a19531bf0e79"} {"source_code": "#![allow(unused_imports)]\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::fmt::Debug;\nuse std::io::{empty, Read};\nuse std::str::FromStr;\n\nfn main() {\n let nn = read_vec::();\n let (n, k) = (nn[0], nn[1]);\n\n let first = min(k - 1, n - k);\n let result = first + 3 * n;\n println!(\"{}\", result);\n}\n\n#[allow(dead_code)]\nconst DIV: i64 = 1_000_000_007;\n#[allow(dead_code)]\nconst N: usize = 200000;\n#[allow(dead_code)]\nconst CHARS: usize = 'z' as usize - 'a' as usize + 1;\n\n#[allow(dead_code)]\nfn print_vec(a: &Vec) {\n for i in 0..a.len() {\n if i != 0 {\n print!(\" \");\n }\n print!(\"{:?}\", a[i]);\n }\n println!();\n}\n\n#[allow(dead_code)]\nfn read_line() -> String {\n let mut s = String::with_capacity(N);\n std::io::stdin().read_line(&mut s).unwrap();\n s\n}\n\n#[allow(dead_code)]\nfn read_vec() -> Vec\n where T::Err: Debug\n{\n return read_line()\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n}\n", "src_uid": "24b02afe8d86314ec5f75a00c72af514"} {"source_code": "//spnauti-rusT {{{\nuse std::io::*; use std::str::{self,*}; use std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)] macro_rules! min {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! max {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! l {\n\t($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};\n\t($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};\n\t(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};\n}\n#[allow(unused_macros)] macro_rules! v {\n\t([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};\n\t([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};\n}\n#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }\n#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }\n#[allow(dead_code)] fn writer() -> BufWriter { BufWriter::new(stdout()) }\nstruct WordReaderC {buf: Vec, pos: usize, q: std::io::StdinLock<'static>}//'\n#[allow(dead_code)] impl WordReaderC {\n\tfn new() -> Self {\n\t\tlet r = unsafe {&*Box::into_raw(Box::new(stdin()))};\n\t\tSelf { q: r.lock(), buf: v!([]), pos: 0 }\n\t}\n\tfn next_line(&mut self) -> bool {\n\t\tself.buf.clear(); self.pos = 0;\n\t\tself.q.read_until(b'\\n', &mut self.buf).unwrap_or(0) > 0\n\t}\n\tfn is_ws(c: u8) -> bool {\n\t\tc == b' ' || c == b'\\r' || c == b'\\n' || c == b'\\t'\n\t}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos == self.buf.len() { if !self.next_line() { return None; } }\n\t\tself.pos += 1; Some(self.buf[self.pos - 1])\n\t}\n\tfn vb(&mut self) -> Vec {\n\t\tlet mut s = v!([8]);\n\t\tlet mut f = false;\n\t\tloop {\n\t\t\tif let Some(c) = self.byte() {\n\t\t\t\tif !Self::is_ws(c) {\n\t\t\t\t\ts.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t} else if f { break; }\n\t\t\t} else { break; }\n\t\t}\n\t\ts\n\t}\n\tfn board(&mut self, r: usize, c: Option) -> Vec> {\n\t\tlet mut res = v!([r]);\n\t\tlet c = c.unwrap_or(0);\n\t\trep!{[r]\n\t\t\tlet t = self.vb();\n\t\t\tassert!(c == 0 || t.len() == c);\n\t\t\tres.push(t);\n\t\t}\n\t\tres\n\t}\n\tfn framed_board(&mut self, r: usize, c: usize, f: u8) -> Vec> {\n\t\tlet mut res = v!([r+2]);\n\t\tres.push( v!([c+2] = f) );\n\t\trep!{[r]\n\t\t\tlet mut t = self.vb();\n\t\t\tassert!(t.len() == c);\n\t\t\tt.reserve(2);\n\t\t\tt.insert(0,f);\n\t\t\tt.push(f);\n\t\t\tres.push(t);\n\t\t}\n\t\tres.push( v!([c+2] = f) );\n\t\tres\n\t}\n\tfn s(&mut self) -> String { String::from_utf8(self.vb()).expect(\"invalid utf8\") }\n\tfn i(&mut self) -> i32 { self.p() }\n\tfn l(&mut self) -> i64 { self.p() }\n\tfn u(&mut self) -> usize { self.p() }\n\tfn f(&mut self) -> f64 { self.p() }\n\tfn vi(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vl(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vu(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn p(&mut self) -> T where T::Err: Debug {\n\t\tlet w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap()\n\t}\n\tfn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n\t\t(0..n).map(|_|self.p()).collect()\n\t}\n\tfn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n\t\tself.vp(n).into_iter()\n\t}\n\tfn graph(&mut self, n: usize, m: usize) -> Vec> {\n\t\tlet mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); e[a].push(b); e[b].push(a); } e\n\t}\n\tfn graph_w(&mut self, n: usize, m: usize) -> Vec> where T::Err: Debug {\n\t\tlet mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); let c: T = self.p(); e[a].push((b,c)); e[b].push((a,c)); } e\n\t}\n}\n//------------------- End rusT }}}\n\n// Field (mod prime) {{{\nmod field {\n\tuse std::ops::*;\n\t#[allow(dead_code)] pub const Z0: Field = Field(0);\n\t#[allow(dead_code)] pub const Z1: Field = Field(1);\n\tconst P5: i32 = 1_000_000_007;\n\tconst P6: i64 = P5 as i64;\n\t#[derive(Debug,Clone,Copy,PartialEq,Eq,PartialOrd,Ord,Default)] pub struct Field(i32);\n\t#[allow(dead_code)] impl Field {\n\t\tpub fn new>(a: T) -> Self { Self(Self::cv(a)) }\n\t\tpub fn new_unchecked(a: i32) -> Self { Self(a) }\n\t\tfn hi(mut a: i32) -> i32 { if a >= P5 { a -= P5; } a }\n\t\tfn lo(mut a: i32) -> i32 { if a < 0 { a += P5; } a }\n\t\tfn cv>(a: T) -> i32 { Self::lo((a.into() % P6) as i32) }\n\t\tpub fn inv(self) -> Self { self.pow(P5-2) }\n\t\tpub fn pow>(self, b: T) -> Self {\n\t\t\tlet b = b.into(); if b == 0 { Self(1) } else {\n\t\t\t\tlet mut res = self.pow(b/2); res *= res; if b % 2 == 1 {res *= self;} res\n\t\t\t}\n\t\t}\n\t}\n\timpl Add for Field { type Output = Self; fn add(self, a: Self) -> Self::Output { Self(Self::hi(self.0 + a.0)) }}\n\timpl Sub for Field { type Output = Self; fn sub(self, a: Self) -> Self::Output { Self(Self::lo(self.0 - a.0)) }}\n\timpl Mul for Field { type Output = Self; fn mul(self, a: Self) -> Self::Output { Self(Self::cv(self.0 as i64 * a.0 as i64)) }}\n\timpl Div for Field { type Output = Self; fn div(self, a: Self) -> Self::Output { self * a.inv() }}\n\timpl Neg for Field { type Output = Self; fn neg(self) -> Self::Output { Self(Self::lo(-self.0)) }}\n\timpl AddAssign for Field { fn add_assign(&mut self, a: Self) { *self = *self + a; } }\n\timpl SubAssign for Field { fn sub_assign(&mut self, a: Self) { *self = *self - a; } }\n\timpl MulAssign for Field { fn mul_assign(&mut self, a: Self) { *self = *self * a; } }\n\timpl DivAssign for Field { fn div_assign(&mut self, a: Self) { *self = *self / a; } }\n\tuse std::fmt::{Display, Formatter, Result};\n\timpl Display for Field { fn fmt(&self, f: &mut Formatter) -> Result { write!(f, \"{}\", self.0) } }\n}\n#[allow(unused_imports)] use field::{Field, Field as Z, Z0, Z1};\n//}}}\n// Square Matrix (Field) {{{\ntype MatT = Field;\nconst MAT_T_0: MatT = Z0;\nconst MAT_T_1: MatT = Z1;\n#[derive(Debug,Clone)] struct Mat { n: usize, a: Vec }\n#[allow(dead_code)] impl Mat {\n\tfn new(n:usize)->Self{Self{n,a:vec![MAT_T_0;n*n]}}\n\tfn diag(n:usize,v:MatT)->Self{let mut m=Self::new(n);let mut p=0;for _ in 0..n{m.a[p]=v;p+=n+1;}m}\n\tfn pow(&self,n:u64)->Self{if n==0{Self::diag(self.n,MAT_T_1)}else{let mut t=self.pow(n/2);t*=t.clone();if n%2==1{t*=self.clone();}t}}\n\tfn range(&self,r:Range,c:Range)->Vec>{if r.startMatT{self.a[r*self.n+c]}\n\tfn at_mut<'a>(&'a mut self,r:usize,c:usize)->&'a mut MatT{&mut self.a[r*self.n+c]}//'\n}\nimpl Mul for Mat{type Output=Self;fn mul(self,o:Self)->Self::Output{assert!(self.n==o.n);let n=self.n;let mut res=Self::new(n);\n\tfor ii in(0..n).map(|i|i*n){for j in 0..n{let mut t=MAT_T_0;let mut kk=j;for k in 0..n{t+=self.a[ii+k]*o.a[kk];kk+=n;}res.a[ii+j]=t;}}res}}\nimpl Add for Mat{type Output=Self;fn add(mut self,o:Self)->Self{self+=o;self}}\nimpl Sub for Mat{type Output=Self;fn sub(mut self,o:Self)->Self{self-=o;self}}\nimpl MulAssign for Mat{fn mul_assign(&mut self,a:Self){*self=self.clone()*a;}}\nimpl AddAssign for Mat{fn add_assign(&mut self,o:Self){assert!(self.n==o.n);for(x,y)in self.a.iter_mut().zip(o.a.into_iter()){*x+=y;}} }\nimpl SubAssign for Mat{fn sub_assign(&mut self,o:Self){assert!(self.n==o.n);for(x,y)in self.a.iter_mut().zip(o.a.into_iter()){*x-=y;}} }\nimpl PartialEq for Mat{fn eq(&self,o:&Self)->bool{self.n==o.n&&self.a==o.a}}impl Eq for Mat{}\n// }}}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tlet n = rin.l();\n\tlet m = rin.u();\n\tlet mut mat = Mat::new(m);\n\tfor i in 1..m {\n\t\t*mat.at_mut(i,i-1) = Z1;\n\t}\n\t*mat.at_mut(0,0) = Z1;\n\t*mat.at_mut(0,m-1) = Z1;\n\tlet mat = mat.pow(n as u64);\n\tlet sol = mat.at(0,0);\n\twriteln!(rout, \"{}\", sol).ok();\n}\n", "src_uid": "e7b9eec21d950f5d963ff50619c6f119"} {"source_code": "fn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let mut n: usize = s.trim().parse().unwrap();\n let mut ans = String::new();\n for k in 2..1000 {\n while n % k == 0 {\n ans.push_str(&format!(\"{}\", k));\n n /= k;\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}", "src_uid": "7220f2da5081547a12118595bbeda4f6"} {"source_code": "// {{{ by shik\n\nuse std::io;\n\n#[allow(dead_code)]\nfn gets() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n}\n\n#[allow(unused_macros)]\nmacro_rules! R {\n ( $ty:ty, ... ) => {\n gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap()).collect::>()\n };\n ( $($ty:ty),* ) => {{\n let line = gets();\n let mut it = line.split_whitespace();\n ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! W {\n ( $x:expr ) => {{\n println!(\"{}\", $x);\n }};\n ( $x:expr, $($xs:expr),* ) => {{\n print!(\"{} \", $x);\n W!($($xs),*);\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! join {\n ($x:expr, $($xs:expr),*; $sep:expr) => { concat!($x, $($sep, $xs),*) }\n}\n\n#[allow(unused_macros)]\nmacro_rules! dump {\n ($($x:expr),*) => {\n eprintln!(join!($(concat!(stringify!($x), \" = {:?}\")),*; \", \"), $($x),*);\n }\n}\n\n// }}}\n\nuse std::cmp;\n\nfn main() {\n let (n, ) = R!(i32);\n println!(\"{}\", cmp::max(n, cmp::max(n/10, n/100*10+n%10)));\n}\n", "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nfn run() {\n input! {\n n: i64,\n p: i64,\n }\n for k in 1..50 {\n let v = n - p * k;\n if v < 0 {\n break;\n }\n let c = v.count_ones() as i64;\n if c <= k && k <= v {\n println!(\"{}\", k);\n return;\n }\n }\n println!(\"-1\");\n}\n\nfn main() {\n run();\n}\n", "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"} {"source_code": "#![allow(unused_imports)]\nuse std::collections::{HashSet, HashMap};\nuse std::cmp::{min,max};\nuse std::io;\nuse std::str;\n \nstruct Scanner {\n reader: R,\n buf_str: Vec,\n buf_iter: str::SplitWhitespace<'static>,\n}\nimpl Scanner {\n fn new(reader: R) -> Self {\n Self { reader, buf_str: vec![], buf_iter: \"\".split_whitespace() }\n }\n fn token(&mut self) -> T {\n loop {\n // If we have another token in this line\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\"); // calls parse::() on the current token and returns it.\n }\n\n // If we do not have another token in the line then\n // we should go to the next line.\n self.buf_str.clear(); // empty out the buffer that holds the current line\n self.reader.read_until(b'\\n', &mut self.buf_str).expect(\"Failed read\"); // read a new line into the buffer\n\n // create an iterator over the white space delimited strings of the current line\n self.buf_iter = unsafe { \n let slice = str::from_utf8_unchecked(&self.buf_str); // makes a string from utf8 characters in the current line\n std::mem::transmute(slice.split_whitespace()) // transmutes the memory in place \n }\n }\n }\n}\n \nfn solve(scan: &mut Scanner, out: &mut W) {\n let mut ans = \"YES\";\n for _ in 0..8 {\n let row = scan.token::();\n if !alternates(row) {\n ans = \"NO\";\n }\n }\n writeln!(out, \"{}\", ans);\n}\n\nfn alternates(s: String) -> bool {\n s.chars().collect::>().windows(2).all(|win| win[0] != win[1])\n}\n \nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "ca65e023be092b2ce25599f52acc1a67"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }};\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\nmod pollard_rho {\n use std::collections::HashMap;\n /// binary gcd\n pub fn gcd(mut x: i64, mut y: i64) -> i64 {\n if y == 0 { return x; }\n if x == 0 { return y; }\n let mut sh = 0;\n while ((x | y) & 1) == 0 {\n x >>= 1; y >>= 1; sh += 1;\n }\n while (x & 1) == 0 { x >>= 1; }\n while y != 0 {\n while (y & 1) == 0 { y >>= 1; }\n if x > y { let t = x; x = y; y = t; }\n y -= x;\n }\n x << sh\n }\n\n fn add_mod(x: i64, y: i64, n: i64) -> i64 {\n let z = x + y;\n if z >= n { z - n } else { z }\n }\n\n fn mul_mod(x: i64, mut y: i64, n: i64) -> i64 {\n assert!(x >= 0);\n assert!(x < n);\n let mut sum = 0;\n let mut cur = x;\n while y > 0 {\n if (y & 1) == 1 {\n sum = add_mod(sum, cur, n);\n }\n cur = add_mod(cur, cur, n);\n y >>= 1;\n }\n sum\n }\n\n fn mod_pow(x: i64, mut e: i64, n: i64) -> i64 {\n let mut prod = if n == 1 { 0 } else { 1 };\n let mut cur = x % n;\n while e > 0 {\n if (e & 1) == 1 {\n prod = mul_mod(prod, cur, n);\n }\n cur = mul_mod(cur, cur, n);\n e >>= 1;\n }\n prod\n }\n\n pub fn is_prime(n: i64) -> bool {\n if n <= 1 { return false; }\n let small = [2, 3, 5, 7, 11, 13];\n if small.iter().any(|&u| u == n) { return true; }\n if small.iter().any(|&u| n % u == 0) { return false; }\n let mut d = n - 1;\n let mut e = 0;\n while (d & 1) == 0 {\n d >>= 1;\n e += 1;\n }\n let a = [2, 325, 9375, 28178, 450775, 9780504, 1795265022];\n a.iter().all(|&a| {\n if a >= n { return true; }\n let mut x = mod_pow(a, d, n);\n if x == 1 { return true; }\n for _ in 0 .. e {\n if x == n - 1 {\n return true;\n }\n x = mul_mod(x, x, n);\n if x == 1 { return false; }\n }\n x == 1\n })\n }\n\n fn pollard_rho(n: i64, c: &mut i64) -> i64 {\n if n % 2 == 0 { return 2; }\n loop {\n let mut x: i64 = 2;\n let mut y = 2;\n let mut d = 1;\n let cc = *c;\n let f = |i| add_mod(mul_mod(i, i, n), cc, n);\n while d == 1 {\n x = f(x);\n y = f(f(y));\n d = gcd((x - y).abs(), n);\n }\n if d == n {\n *c += 1;\n continue;\n }\n return d;\n }\n }\n\n /// Outputs (p, e) in p's ascending order.\n pub fn factorize(x: i64) -> Vec<(i64, usize)> {\n if x <= 1 {\n return Vec::new();\n }\n let mut hm = HashMap::new();\n let mut pool = vec![x];\n let mut c = 1;\n while let Some(u) = pool.pop() {\n if is_prime(u) {\n *hm.entry(u).or_insert(0) += 1;\n continue;\n }\n let p = pollard_rho(u, &mut c);\n pool.push(p);\n pool.push(u / p);\n }\n let mut v: Vec<_> = hm.into_iter().collect();\n v.sort();\n v\n }\n} // mod pollard_rho\n\nuse pollard_rho::*;\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (write!(out,$($format)*).unwrap());\n }\n input! {\n n: i64,\n b: i64,\n }\n let fac = factorize(b);\n let mut mi: i64 = 1 << 62;\n for (p, e) in fac {\n let mut tot = 0;\n let mut v = n;\n while v > 0 {\n v /= p;\n tot += v;\n }\n mi = min(mi, tot / e as i64);\n }\n puts!(\"{}\\n\", mi);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "491748694c1a53771be69c212a5e0e25"} {"source_code": "//spnauti-rusT {{{\nuse std::io::*; use std::str::{self,*}; use std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)] macro_rules! m {\n\t($c:tt,$x:expr,$y:expr) => {{\n\t\tlet b=$y; let a=&mut$x; if b$c*a {*a=b; true} else {false}\n\t}};\n}\n#[allow(unused_macros)] macro_rules! l {\n\t($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};\n\t($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};\n\t(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};\n}\n#[allow(unused_macros)] macro_rules! vec_dim {\n\t([$d:expr]$($s:tt)+) => {vec![vec_dim!($($s)+);$d]}; (=$e:expr) => {$e};\n}\n#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }\n#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }\n#[allow(dead_code)] fn writer() -> BufWriter { BufWriter::new(stdout()) }\nstruct WordReaderC {buf: Vec, pos: usize, q: std::io::StdinLock<'static>}//'\n#[allow(dead_code)] impl WordReaderC {\n\tfn new() -> Self {\n\t\tlet r = unsafe {&*Box::into_raw(Box::new(stdin()))};\n\t\tSelf { q: r.lock(), buf: Vec::new(), pos: 0 }\n\t}\n\tfn next_line(&mut self) -> bool {\n\t\tself.buf.clear(); self.pos = 0;\n\t\tself.q.read_until(b'\\n', &mut self.buf).unwrap_or(0) > 0\n\t}\n\tfn is_ws(c: u8) -> bool {\n\t\tc == b' ' || c == b'\\r' || c == b'\\n' || c == b'\\t'\n\t}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos == self.buf.len() { if !self.next_line() { return None; } }\n\t\tself.pos += 1; Some(self.buf[self.pos - 1])\n\t}\n\tfn vb(&mut self) -> Vec {\n\t\tlet mut s = Vec::with_capacity(8);\n\t\tlet mut f = false;\n\t\tloop {\n\t\t\tif let Some(c) = self.byte() {\n\t\t\t\tif !Self::is_ws(c) {\n\t\t\t\t\ts.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t} else if f { break; }\n\t\t\t} else { break; }\n\t\t}\n\t\ts\n\t}\n\tfn s(&mut self) -> String { String::from_utf8(self.vb()).expect(\"invalid utf8\") }\n\tfn i(&mut self) -> i32 { self.p() }\n\tfn l(&mut self) -> i64 { self.p() }\n\tfn u(&mut self) -> usize { self.p() }\n\tfn f(&mut self) -> f64 { self.p() }\n\tfn vi(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vl(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vu(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn p(&mut self) -> T where T::Err: Debug {\n\t\tlet w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap()\n\t}\n\tfn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n\t\t(0..n).map(|_|self.p()).collect()\n\t}\n\tfn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n\t\tself.vp(n).into_iter()\n\t}\n}\n//------------------- End rusT }}}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tl!(mut n,a,b = rin.l());\n\tn *= 6;\n\tif a * b < n {\n\t\tlet s = (n as f64).sqrt() as i64 + 10;\n\t\tlet flip = a > b;\n\t\tlet (a0,b0) = (a.min(b),a.max(b));\n\t\ta = a0.max(s);\n\t\tb = b0.max(s);\n\t\tfor i in 1..=n {\n\t\t\tlet j = (n + i - 1) / i;\n\t\t\tif i > j {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tlet a1 = a0.max(i);\n\t\t\tlet b1 = b0.max(j);\n\t\t\tif a1 * b1 >= n && a1 * b1 < a * b {\n\t\t\t\ta = a1;\n\t\t\t\tb = b1;\n\t\t\t}\n\t\t}\n\t\tif flip {\n\t\t\tlet c = a;\n\t\t\ta = b;\n\t\t\tb = c;\n\t\t}\n\t}\n\twriteln!(rout, \"{}\\n{} {}\", a*b, a, b).ok();\n}\n", "src_uid": "6a2a584d36008151d18e5080aea5029c"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\n\nfn solve(n: i64, m: i64, k: i64) -> (i64, i64) {\n \n if k < n {\n return (k + 1, 1);\n }\n \n let e = k - n;\n let r = e / (m - 1);\n let c = e % (m - 1);\n \n let y = n - r;\n let x = if r % 2 == 0 { c + 2 } else { m - c }; \n \n return (y, x);\n}\n\nfn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(\n &mut std::io::stdin(),\n &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(i64));\n }\n \n let n = get!();\n let m = get!();\n let k = get!();\n \n if n * m < 20 {\n for e in 0..n*m {\n let (row, col) = solve(n, m, e);\n let (r, c) = brute_force(n, m, e);\n if row != r || col != c {\n //println!(\"error {} {} {}\", n, m, e);\n //println!(\"solve {} {}\", row, col);\n //println!(\"bf {} {}\", r, c);\n //panic!();\n break;\n }\n }\n }\n \n let (row, col) = solve(n, m, k);\n \n println!(\"{} {}\", row, col);\n \n}\n\nfn brute_force(n: i64, m: i64, k: i64) -> (i64, i64) {\n let mut row = 1;\n let mut col = 1;\n let mut rem = k;\n \n if rem == 0 {\n return (row, col);\n }\n \n for _ in 0..n-1 {\n row += 1;\n rem -= 1;\n if rem == 0 {\n return (row, col);\n }\n }\n \n let mut state = 0;\n for _ in 0..rem {\n match state {\n 0 => {\n col += 1;\n if col == m {\n state += 1;\n }\n },\n 2 => {\n col -= 1;\n if col == 2 {\n state += 1;\n }\n },\n _ => {\n row -= 1;\n state = (state + 1) % 4;\n },\n }\n }\n return (row, col);\n}", "src_uid": "e88bb7621c7124c54e75109a00f96301"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn main() {\n let n: usize = get_line().trim().parse().unwrap();\n let x = get_line().trim().parse::().unwrap();\n\n // On a une permutation qui d\u00e9pend de n.\n // Premi\u00e8res valeurs :\n // 2 1 3\n // 2 3 1\n // 3 2 1\n // 3 1 2\n // 1 3 2\n // 1 2 3\n\n let perm = |i, n| {\n match i {\n 0 => (n + 1) % 6 / 2,\n 1 => match n % 3 {\n 0 => 1,\n 1 => 0,\n 2 => 2,\n _ => panic!(\"Something is WRONG.\"),\n },\n 2 => (n + 4) % 6 / 2,\n _ => panic!(\"Something is WRONG.\"),\n }\n };\n\n let ans = perm(x, n);\n\n println!(\"{}\", ans);\n}\n", "src_uid": "7853e03d520cd71571a6079cdfc4c4b0"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::io::{stdin, stdout, BufWriter, Write};\n\n#[derive(Default)]\nstruct Scanner {\n buffer: Vec,\n}\nimpl Scanner {\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn main() {\n let mut scan = Scanner::default();\n let out = &mut BufWriter::new(stdout());\n let n = scan.next::() / 2;\n\n let mut res = 1;\n\n for i in 1..n {\n res *= i;\n res *= i + n;\n }\n println!(\"{:?}\", res);\n}\n", "src_uid": "ad0985c56a207f76afa2ecd642f56728"} {"source_code": "use std::io;\n\n\nfn main() {\n let mut word = String::new();\n io::stdin().read_line(&mut word)\n .expect(\"Failed to read line\");\n \n\n let snums = word.trim().split(\"+\");\n // let nums: Vec = word.split(\"+\");\n // // .map(|s| s.parse::().unwrap())\n // // .collect();\n \n let mut nums = Vec::::new();\n for s in snums {\n let n = s.parse::().unwrap();\n nums.push(n);\n }\n\n nums.sort();\n \n match nums.pop() {\n Some(last) => {\n for n in nums {\n print!(\"{}+\", n);\n }\n println!(\"{}\", last);\n },\n None => println!(\"bad input\")\n }\n \n \n \n\n}", "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"} {"source_code": "pub use __cargo_equip::prelude::*;\r\n\r\n#[allow(unused_imports)]\r\n#[cfg_attr(cargo_equip, cargo_equip::equip)]\r\nuse crate::__cargo_equip::crates::proconio::{marker::*, *};\r\n\r\n/*#[allow(non_snake_case)]\r\n#[fastout]\r\nfn main() {\r\n input! {\r\n t: usize,\r\n }\r\n for _ in 0..t {\r\n input! {\r\n n: usize,\r\n }\r\n println!(\"{}\", 2usize.pow(n as u32)-1);\r\n }\r\n}*/\r\n#[allow(non_snake_case)]\r\nfn main() {\r\n let __proconio_stdout = ::std::io::stdout();\r\n let mut __proconio_stdout = ::std::io::BufWriter::new(__proconio_stdout.lock());\r\n #[allow(unused_macros)]\r\n macro_rules ! print { ($ ($ tt : tt) *) => { { use std :: io :: Write as _ ; :: std :: write ! (__proconio_stdout , $ ($ tt) *) . unwrap () ; } } ; }\r\n #[allow(unused_macros)]\r\n macro_rules ! println { ($ ($ tt : tt) *) => { { use std :: io :: Write as _ ; :: std :: writeln ! (__proconio_stdout , $ ($ tt) *) . unwrap () ; } } ; }\r\n let __proconio_res = {\r\n input! { t : usize , }\r\n for _ in 0..t {\r\n input! { n : usize , }\r\n println!(\"{}\", 2usize.pow(n as u32) - 1);\r\n }\r\n };\r\n <::std::io::BufWriter<::std::io::StdoutLock> as ::std::io::Write>::flush(\r\n &mut __proconio_stdout,\r\n )\r\n .unwrap();\r\n return __proconio_res;\r\n}\r\n\r\n// The following code was expanded by `cargo-equip`.\r\n\r\n/// # Bundled libraries\r\n///\r\n/// - `lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)` licensed under `MIT/Apache-2.0` as `crate::__cargo_equip::crates::__lazy_static_1_4_0`\r\n/// - `proconio 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)` licensed under `MIT OR Apache-2.0` as `crate::__cargo_equip::crates::proconio`\r\n///\r\n/// # Procedural macros\r\n///\r\n/// - `proconio-derive 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)` licensed under `MIT OR Apache-2.0`\r\n///\r\n/// # License and Copyright Notices\r\n///\r\n/// - `lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)`\r\n///\r\n/// ```text\r\n/// Copyright (c) 2010 The Rust Project Developers\r\n///\r\n/// Permission is hereby granted, free of charge, to any\r\n/// person obtaining a copy of this software and associated\r\n/// documentation files (the \"Software\"), to deal in the\r\n/// Software without restriction, including without\r\n/// limitation the rights to use, copy, modify, merge,\r\n/// publish, distribute, sublicense, and/or sell copies of\r\n/// the Software, and to permit persons to whom the Software\r\n/// is furnished to do so, subject to the following\r\n/// conditions:\r\n///\r\n/// The above copyright notice and this permission notice\r\n/// shall be included in all copies or substantial portions\r\n/// of the Software.\r\n///\r\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF\r\n/// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED\r\n/// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\r\n/// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\r\n/// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r\n/// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r\n/// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR\r\n/// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r\n/// DEALINGS IN THE SOFTWARE.\r\n/// ```\r\n///\r\n/// - `proconio 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)`\r\n///\r\n/// ```text\r\n/// The MIT License\r\n/// Copyright 2019 (C) statiolake \r\n///\r\n/// Permission is hereby granted, free of charge, to any person obtaining a copy of\r\n/// this software and associated documentation files (the \"Software\"), to deal in\r\n/// the Software without restriction, including without limitation the rights to\r\n/// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r\n/// the Software, and to permit persons to whom the Software is furnished to do so,\r\n/// subject to the following conditions:\r\n///\r\n/// The above copyright notice and this permission notice shall be included in all\r\n/// copies or substantial portions of the Software.\r\n///\r\n/// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r\n/// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r\n/// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r\n/// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r\n/// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n///\r\n/// Copyright for original `input!` macro is held by Hideyuki Tanaka, 2019. The\r\n/// original macro is licensed under BSD 3-clause license.\r\n///\r\n/// Redistribution and use in source and binary forms, with or without\r\n/// modification, are permitted provided that the following conditions are met:\r\n///\r\n/// 1. Redistributions of source code must retain the above copyright notice, this\r\n/// list of conditions and the following disclaimer.\r\n///\r\n/// 2. Redistributions in binary form must reproduce the above copyright notice,\r\n/// this list of conditions and the following disclaimer in the documentation\r\n/// and/or other materials provided with the distribution.\r\n///\r\n/// 3. Neither the name of the copyright holder nor the names of its contributors\r\n/// may be used to endorse or promote products derived from this software\r\n/// without specific prior written permission.\r\n///\r\n/// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND\r\n/// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r\n/// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r\n/// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r\n/// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r\n/// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r\n/// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r\n/// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r\n/// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r\n/// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r\n/// ```\r\n#[allow(unused)]\r\nmod __cargo_equip {\r\n pub(crate) mod crates {\r\n pub mod __lazy_static_1_4_0 {\r\n // Copyright 2016 lazy-static.rs Developers\r\n //\r\n // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be\r\n // copied, modified, or distributed except according to those terms.\r\n\r\n #![no_std]\r\n\r\n pub use crate::__cargo_equip::macros::__lazy_static_1_4_0::*;\r\n use crate::__cargo_equip::preludes::__lazy_static_1_4_0::*;\r\n #[path = \"inline_lazy.rs\"]\r\n\r\n pub mod lazy {\r\n // Copyright 2016 lazy-static.rs Developers\r\n //\r\n // Licensed under the Apache License, Version 2.0, or the MIT license , at your option. This file may not be\r\n // copied, modified, or distributed except according to those terms.\r\n\r\n use crate::__cargo_equip::preludes::__lazy_static_1_4_0::*;\r\n extern crate core;\r\n extern crate std;\r\n\r\n use self::std::cell::Cell;\r\n use self::std::hint::unreachable_unchecked;\r\n use self::std::prelude::v1::*;\r\n use self::std::sync::Once;\r\n #[allow(deprecated)]\r\n pub use self::std::sync::ONCE_INIT;\r\n\r\n // FIXME: Replace Option with MaybeUninit (stable since 1.36.0)\r\n pub struct Lazy(Cell>, Once);\r\n\r\n impl Lazy {\r\n #[allow(deprecated)]\r\n pub const INIT: Self = Lazy(Cell::new(None), ONCE_INIT);\r\n\r\n #[inline(always)]\r\n pub fn get(&'static self, f: F) -> &T\r\n where\r\n F: FnOnce() -> T,\r\n {\r\n self.1.call_once(|| {\r\n self.0.set(Some(f()));\r\n });\r\n\r\n // `self.0` is guaranteed to be `Some` by this point\r\n // The `Once` will catch and propagate panics\r\n unsafe {\r\n match *self.0.as_ptr() {\r\n Some(ref x) => x,\r\n None => {\r\n debug_assert!(false, \"attempted to derefence an uninitialized lazy static. This is a bug\");\r\n\r\n unreachable_unchecked()\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n unsafe impl Sync for Lazy {}\r\n\r\n #[macro_export]\r\n\r\n macro_rules! __cargo_equip_macro_def___lazy_static_1_4_0___lazy_static_create {\r\n ($NAME:ident, $T:ty) => {\r\n static $NAME:\r\n $crate::__cargo_equip::crates::__lazy_static_1_4_0::lazy::Lazy<$T> =\r\n $crate::__cargo_equip::crates::__lazy_static_1_4_0::lazy::Lazy::INIT;\r\n };\r\n }\r\n macro_rules!__lazy_static_create{($($tt:tt)*)=>(crate::__cargo_equip_macro_def___lazy_static_1_4_0___lazy_static_create!{$($tt)*})}\r\n }\r\n\r\n pub use core::ops::Deref as __Deref;\r\n\r\n #[macro_export(local_inner_macros)]\r\n\r\n macro_rules! /*__lazy_static_internal*/__cargo_equip_macro_def___lazy_static_1_4_0___lazy_static_internal {\r\n // optional visibility restrictions are wrapped in `()` to allow for\r\n // explicitly passing otherwise implicit information about private items\r\n ($(#[$attr:meta])* ($($vis:tt)*) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {\r\n __lazy_static_internal!(@MAKE TY, $(#[$attr])*, ($($vis)*), $N);\r\n __lazy_static_internal!(@TAIL, $N : $T = $e);\r\n lazy_static!($($t)*);\r\n };\r\n (@TAIL, $N:ident : $T:ty = $e:expr) => {\r\n impl $crate::__cargo_equip::crates::__lazy_static_1_4_0::__Deref for $N {\r\n type Target = $T;\r\n fn deref(&self) -> &$T {\r\n #[inline(always)]\r\n fn __static_ref_initialize() -> $T { $e }\r\n\r\n #[inline(always)]\r\n fn __stability() -> &'static $T {\r\n __lazy_static_create!(LAZY, $T);\r\n LAZY.get(__static_ref_initialize)\r\n }\r\n __stability()\r\n }\r\n }\r\n impl $crate::__cargo_equip::crates::__lazy_static_1_4_0::LazyStatic for $N {\r\n fn initialize(lazy: &Self) {\r\n let _ = &**lazy;\r\n }\r\n }\r\n };\r\n // `vis` is wrapped in `()` to prevent parsing ambiguity\r\n (@MAKE TY, $(#[$attr:meta])*, ($($vis:tt)*), $N:ident) => {\r\n #[allow(missing_copy_implementations)]\r\n #[allow(non_camel_case_types)]\r\n #[allow(dead_code)]\r\n $(#[$attr])*\r\n $($vis)* struct $N {__private_field: ()}\r\n #[doc(hidden)]\r\n $($vis)* static $N: $N = $N {__private_field: ()};\r\n };\r\n () => ()\r\n }\r\n macro_rules!__lazy_static_internal{($($tt:tt)*)=>(crate::__cargo_equip_macro_def___lazy_static_1_4_0___lazy_static_internal!{$($tt)*})}\r\n\r\n #[macro_export(local_inner_macros)]\r\n macro_rules! /*lazy_static*/__cargo_equip_macro_def___lazy_static_1_4_0_lazy_static {\r\n ($(#[$attr:meta])* static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {\r\n // use `()` to explicitly forward the information about private items\r\n __lazy_static_internal!($(#[$attr])* () static ref $N : $T = $e; $($t)*);\r\n };\r\n ($(#[$attr:meta])* pub static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {\r\n __lazy_static_internal!($(#[$attr])* (pub) static ref $N : $T = $e; $($t)*);\r\n };\r\n ($(#[$attr:meta])* pub ($($vis:tt)+) static ref $N:ident : $T:ty = $e:expr; $($t:tt)*) => {\r\n __lazy_static_internal!($(#[$attr])* (pub ($($vis)+)) static ref $N : $T = $e; $($t)*);\r\n };\r\n () => ()\r\n }\r\n macro_rules!lazy_static{($($tt:tt)*)=>(crate::__cargo_equip_macro_def___lazy_static_1_4_0_lazy_static!{$($tt)*})}\r\n\r\n pub trait LazyStatic {\r\n fn initialize(lazy: &Self);\r\n }\r\n\r\n pub fn initialize(lazy: &T) {\r\n LazyStatic::initialize(lazy);\r\n }\r\n }\r\n\r\n pub mod proconio {\r\n // Copyright 2019 statiolake \r\n //\r\n // Licensed under the Apache License, Version 2.0 or the MIT license , at your option. This file may not be copied, modified, or\r\n // distributed except according to those terms.\r\n\r\n #![allow(clippy::needless_doctest_main, clippy::print_literal)]\r\n\r\n pub use crate::__cargo_equip::macros::proconio::*;\r\n use crate::__cargo_equip::preludes::proconio::*;\r\n pub use proconio_derive::*;\r\n\r\n pub mod marker {\r\n // Copyright 2019 statiolake \r\n //\r\n // Licensed under the Apache License, Version 2.0 or the MIT license , at your option. This file may not be copied, modified, or\r\n // distributed except according to those terms.\r\n\r\n use crate::__cargo_equip::crates::proconio::source::{Readable, Source};\r\n use crate::__cargo_equip::preludes::proconio::*;\r\n use std::io::BufRead;\r\n\r\n pub enum Chars {}\r\n\r\n impl Readable for Chars {\r\n type Output = Vec;\r\n fn read>(source: &mut S) -> Vec {\r\n source.next_token_unwrap().chars().collect()\r\n }\r\n }\r\n\r\n pub enum Bytes {}\r\n\r\n impl Readable for Bytes {\r\n type Output = Vec;\r\n fn read>(source: &mut S) -> Vec {\r\n source.next_token_unwrap().bytes().collect()\r\n }\r\n }\r\n\r\n pub enum Usize1 {}\r\n\r\n impl Readable for Usize1 {\r\n type Output = usize;\r\n fn read>(source: &mut S) -> usize {\r\n // panic if the subtraction overflows\r\n usize::read(source)\r\n .checked_sub(1)\r\n .expect(\"attempted to read the value 0 as a Usize1\")\r\n }\r\n }\r\n\r\n pub enum Isize1 {}\r\n\r\n impl Readable for Isize1 {\r\n type Output = isize;\r\n fn read>(source: &mut S) -> isize {\r\n // FIXME: Which is appropriate, forbidding all negative values or only isize::MIN. For now\r\n // we disallow only isize::MIN.\r\n // ensure the value is more than isize::MIN, or subtract overflows.\r\n isize::read(source).checked_sub(1).unwrap_or_else(|| {\r\n panic!(\r\n concat!(\r\n \"attempted to read the value {} as a Isize1:\",\r\n \" the value is isize::MIN and cannot be decremented\"\r\n ),\r\n std::isize::MIN,\r\n )\r\n })\r\n }\r\n }\r\n }\r\n pub mod source {\r\n // Copyright 2019 statiolake \r\n //\r\n // Licensed under the Apache License, Version 2.0 or the MIT license , at your option. This file may not be copied, modified, or\r\n // distributed except according to those terms.\r\n\r\n use crate::__cargo_equip::preludes::proconio::*;\r\n use std::any::type_name;\r\n use std::fmt::Debug;\r\n use std::io::BufRead;\r\n use std::str::FromStr;\r\n\r\n pub mod line {\r\n // Copyright 2019 statiolake \r\n //\r\n // Licensed under the Apache License, Version 2.0 or the MIT license , at your option. This file may not be copied, modified, or\r\n // distributed except according to those terms.\r\n\r\n use super::Source;\r\n use crate::__cargo_equip::preludes::proconio::*;\r\n use std::io::BufRead;\r\n use std::iter::Peekable;\r\n use std::str::SplitWhitespace;\r\n\r\n pub struct LineSource {\r\n // FIXME: This is actually not 'static but it is treated as 'static for the\r\n // same reason with crate::source::once::Source. Also there is no way to\r\n // separate context and tokens since they are private field, this is safe.\r\n tokens: Peekable>,\r\n\r\n // context `tokens` reffering to\r\n current_context: Box,\r\n\r\n reader: R,\r\n }\r\n\r\n impl LineSource {\r\n pub fn new(reader: R) -> LineSource {\r\n // dummy values.\r\n LineSource {\r\n current_context: \"\".to_string().into_boxed_str(),\r\n tokens: \"\".split_whitespace().peekable(),\r\n reader,\r\n }\r\n }\r\n\r\n fn prepare(&mut self) {\r\n while self.tokens.peek().is_none() {\r\n let mut line = String::new();\r\n let num_bytes = self\r\n .reader\r\n .read_line(&mut line)\r\n .expect(\"failed to get linel maybe an IO error.\");\r\n\r\n if num_bytes == 0 {\r\n // reached EOF\r\n return;\r\n }\r\n\r\n self.current_context = line.into_boxed_str();\r\n self.tokens = unsafe {\r\n std::mem::transmute::<_, &'static str>(&*self.current_context)\r\n }\r\n .split_whitespace()\r\n .peekable();\r\n }\r\n }\r\n }\r\n\r\n impl Source for LineSource {\r\n fn next_token(&mut self) -> Option<&str> {\r\n // while tokens are empty, reads a new line.\r\n self.prepare();\r\n self.tokens.next()\r\n }\r\n\r\n fn is_empty(&mut self) -> bool {\r\n self.prepare();\r\n self.tokens.peek().is_none()\r\n }\r\n }\r\n\r\n use std::io::BufReader;\r\n\r\n impl<'a> From<&'a str> for LineSource> {\r\n fn from(s: &'a str) -> LineSource> {\r\n LineSource::new(BufReader::new(s.as_bytes()))\r\n }\r\n }\r\n }\r\n pub mod once {\r\n // Copyright 2019 statiolake \r\n //\r\n // Licensed under the Apache License, Version 2.0 or the MIT license , at your option. This file may not be copied, modified, or\r\n // distributed except according to those terms.\r\n\r\n use super::Source;\r\n use crate::__cargo_equip::preludes::proconio::*;\r\n use std::io::BufRead;\r\n use std::iter::Peekable;\r\n use std::marker::PhantomData;\r\n use std::str::SplitWhitespace;\r\n\r\n pub struct OnceSource {\r\n // Of course this is not 'static actually, but it is always valid reference\r\n // while entire `Source` is alive. The actual lifetime is the context's\r\n // inner lifetime, and it is essentially the lifetime of self. Also note\r\n // that there is no way to separate context and tokens since they are both\r\n // private field.\r\n //\r\n // FIXME: find nicer way.\r\n tokens: Peekable>,\r\n\r\n // context `tokens` is reffering to\r\n context: Box,\r\n\r\n // to consume `R`. Actually `OnceSource` is not need to have `R`, since reading is done in its\r\n // constructor. This is for the consistency with `LineSource` (To use smoothly through `AutoSource`).\r\n _read: PhantomData,\r\n }\r\n\r\n impl OnceSource {\r\n pub fn new(mut source: R) -> OnceSource {\r\n let mut context = String::new();\r\n source\r\n .read_to_string(&mut context)\r\n .expect(\"failed to read from source; maybe an IO error.\");\r\n\r\n // Boxed str is no need to check to pin.\r\n let context = context.into_boxed_str();\r\n\r\n // We can create tokens first. But doing so causes \"unused variable\r\n // `context`\" warning (here `context` is Source::context, a member of\r\n // Source`). To avoid the warning at first tokens are dummy and replace\r\n // it using Source's context.\r\n let mut res = OnceSource {\r\n context,\r\n tokens: \"\".split_whitespace().peekable(),\r\n _read: PhantomData,\r\n };\r\n\r\n use std::mem;\r\n let context: &'static str = unsafe { mem::transmute(&*res.context) };\r\n res.tokens = context.split_whitespace().peekable();\r\n\r\n res\r\n }\r\n }\r\n\r\n impl Source for OnceSource {\r\n fn next_token(&mut self) -> Option<&str> {\r\n self.tokens.next()\r\n }\r\n\r\n fn is_empty(&mut self) -> bool {\r\n self.tokens.peek().is_none()\r\n }\r\n }\r\n\r\n use std::io::BufReader;\r\n\r\n impl<'a> From<&'a str> for OnceSource> {\r\n fn from(s: &'a str) -> OnceSource> {\r\n OnceSource::new(BufReader::new(s.as_bytes()))\r\n }\r\n }\r\n }\r\n\r\n pub mod auto {\r\n\r\n #[cfg(debug_assertions)]\r\n pub use super::line::LineSource as AutoSource;\r\n #[cfg(not(debug_assertions))]\r\n pub use super::once::OnceSource as AutoSource;\r\n use crate::__cargo_equip::preludes::proconio::*;\r\n }\r\n\r\n pub trait Source {\r\n fn next_token(&mut self) -> Option<&str>;\r\n\r\n fn is_empty(&mut self) -> bool;\r\n\r\n fn next_token_unwrap(&mut self) -> &str {\r\n self.next_token().expect(concat!(\r\n \"failed to get the next token; \",\r\n \"maybe reader reached an end of input. \",\r\n \"ensure that arguments for `input!` macro is correctly \",\r\n \"specified to match the problem input.\"\r\n ))\r\n }\r\n }\r\n\r\n // &mut S where S: Source is also source.\r\n impl> Source for &'_ mut S {\r\n fn next_token(&mut self) -> Option<&str> {\r\n (*self).next_token()\r\n }\r\n\r\n fn is_empty(&mut self) -> bool {\r\n (*self).is_empty()\r\n }\r\n }\r\n\r\n pub trait Readable {\r\n type Output;\r\n fn read>(source: &mut S) -> Self::Output;\r\n }\r\n\r\n // implementations of Readable for any `FromStr` types including primitives.\r\n impl Readable for T\r\n where\r\n T::Err: Debug,\r\n {\r\n type Output = T;\r\n fn read>(source: &mut S) -> T {\r\n let token = source.next_token_unwrap();\r\n match token.parse() {\r\n Ok(v) => v,\r\n Err(e) => panic!(\r\n concat!(\r\n \"failed to parse the input `{input}` \",\r\n \"to the value of type `{ty}`: {err:?}; \",\r\n \"ensure that the input format is collectly specified \",\r\n \"and that the input value must handle specified type.\",\r\n ),\r\n input = token,\r\n ty = type_name::(),\r\n err = e,\r\n ),\r\n }\r\n }\r\n }\r\n }\r\n\r\n use crate::__cargo_equip::crates::proconio::source::auto::AutoSource;\r\n use lazy_static::lazy_static;\r\n use std::io;\r\n use std::io::{BufReader, Stdin};\r\n use std::sync::Mutex;\r\n\r\n // Prepares a short path to `Readable` to enables rust-analyzer to infer `Readable::Output`.\r\n\r\n pub use crate::__cargo_equip::crates::proconio::source::Readable as __Readable;\r\n\r\n lazy_static! {\r\n #[doc(hidden)]\r\n pub static ref STDIN_SOURCE: Mutex>> =\r\n Mutex::new(AutoSource::new(BufReader::new(io::stdin())));\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! /*input*/__cargo_equip_macro_def_proconio_input {\r\n // terminator\r\n (@from [$source:expr] @rest) => {};\r\n\r\n // parse mutability\r\n (@from [$source:expr] @rest mut $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::input! {\r\n @from [$source]\r\n @mut [mut]\r\n @rest $($rest)*\r\n }\r\n };\r\n (@from [$source:expr] @rest $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::input! {\r\n @from [$source]\r\n @mut []\r\n @rest $($rest)*\r\n }\r\n };\r\n\r\n // parse variable pattern\r\n (@from [$source:expr] @mut [$($mut:tt)?] @rest $var:tt: $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::input! {\r\n @from [$source]\r\n @mut [$($mut)*]\r\n @var $var\r\n @kind []\r\n @rest $($rest)*\r\n }\r\n };\r\n\r\n // parse kind (type)\r\n (@from [$source:expr] @mut [$($mut:tt)?] @var $var:tt @kind [$($kind:tt)*] @rest) => {\r\n let $($mut)* $var = $crate::__cargo_equip::crates::proconio::read_value!(@source [$source] @kind [$($kind)*]);\r\n };\r\n (@from [$source:expr] @mut [$($mut:tt)?] @var $var:tt @kind [$($kind:tt)*] @rest, $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::input!(@from [$source] @mut [$($mut)*] @var $var @kind [$($kind)*] @rest);\r\n $crate::__cargo_equip::crates::proconio::input!(@from [$source] @rest $($rest)*);\r\n };\r\n (@from [$source:expr] @mut [$($mut:tt)?] @var $var:tt @kind [$($kind:tt)*] @rest $tt:tt $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::input!(@from [$source] @mut [$($mut)*] @var $var @kind [$($kind)* $tt] @rest $($rest)*);\r\n };\r\n\r\n (from $source:expr, $($rest:tt)*) => {\r\n #[allow(unused_variables, unused_mut)]\r\n let mut s = $source;\r\n $crate::__cargo_equip::crates::proconio::input! {\r\n @from [&mut s]\r\n @rest $($rest)*\r\n }\r\n };\r\n ($($rest:tt)*) => {\r\n let mut locked_stdin = $crate::__cargo_equip::crates::proconio::STDIN_SOURCE.lock().expect(concat!(\r\n \"failed to lock the stdin; please re-run this program. \",\r\n \"If this issue repeatedly occur, this is a bug in `proconio`. \",\r\n \"Please report this issue from \",\r\n \".\"\r\n ));\r\n $crate::__cargo_equip::crates::proconio::input! {\r\n @from [&mut *locked_stdin]\r\n @rest $($rest)*\r\n }\r\n drop(locked_stdin); // release the lock\r\n };\r\n }\r\n macro_rules!input{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_proconio_input!{$($tt)*})}\r\n\r\n #[macro_export]\r\n macro_rules! /*read_value*/__cargo_equip_macro_def_proconio_read_value {\r\n // array and variable length array\r\n (@source [$source:expr] @kind [[$($kind:tt)*]]) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@array @source [$source] @kind [] @rest $($kind)*)\r\n };\r\n (@array @source [$source:expr] @kind [$($kind:tt)*] @rest) => {{\r\n let len = ::read($source);\r\n $crate::__cargo_equip::crates::proconio::read_value!(@source [$source] @kind [[$($kind)*; len]])\r\n }};\r\n (@array @source [$source:expr] @kind [$($kind:tt)*] @rest ; $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@array @source [$source] @kind [$($kind)*] @len [$($rest)*])\r\n };\r\n (@array @source [$source:expr] @kind [$($kind:tt)*] @rest $tt:tt $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@array @source [$source] @kind [$($kind)* $tt] @rest $($rest)*)\r\n };\r\n (@array @source [$source:expr] @kind [$($kind:tt)*] @len [$($len:tt)*]) => {{\r\n let len = $($len)*;\r\n (0..len)\r\n .map(|_| $crate::__cargo_equip::crates::proconio::read_value!(@source [$source] @kind [$($kind)*]))\r\n .collect::>()\r\n }};\r\n\r\n // tuple\r\n (@source [$source:expr] @kind [($($kinds:tt)*)]) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@tuple @source [$source] @kinds [] @current [] @rest $($kinds)*)\r\n };\r\n (@tuple @source [$source:expr] @kinds [$([$($kind:tt)*])*] @current [] @rest) => {\r\n (\r\n $($crate::__cargo_equip::crates::proconio::read_value!(@source [$source] @kind [$($kind)*]),)*\r\n )\r\n };\r\n (@tuple @source [$source:expr] @kinds [$($kinds:tt)*] @current [$($curr:tt)*] @rest) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@tuple @source [$source] @kinds [$($kinds)* [$($curr)*]] @current [] @rest)\r\n };\r\n (@tuple @source [$source:expr] @kinds [$($kinds:tt)*] @current [$($curr:tt)*] @rest, $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@tuple @source [$source] @kinds [$($kinds)* [$($curr)*]] @current [] @rest $($rest)*)\r\n };\r\n (@tuple @source [$source:expr] @kinds [$($kinds:tt)*] @current [$($curr:tt)*] @rest $tt:tt $($rest:tt)*) => {\r\n $crate::__cargo_equip::crates::proconio::read_value!(@tuple @source [$source] @kinds [$($kinds)*] @current [$($curr)* $tt] @rest $($rest)*)\r\n };\r\n\r\n // unreachable\r\n (@source [$source:expr] @kind []) => {\r\n compile_error!(concat!(\"Reached unreachable statement while parsing macro input. \", \"This is a bug in `proconio`. \", \"Please report this issue from \", \".\"));\r\n };\r\n\r\n // normal other\r\n (@source [$source:expr] @kind [$kind:ty]) => {\r\n <$kind as $crate::__cargo_equip::crates::proconio::__Readable>::read($source)\r\n }\r\n }\r\n macro_rules!read_value{($($tt:tt)*)=>(crate::__cargo_equip_macro_def_proconio_read_value!{$($tt)*})}\r\n\r\n pub fn is_stdin_empty() -> bool {\r\n use crate::__cargo_equip::crates::proconio::source::Source;\r\n let mut lock = STDIN_SOURCE.lock().expect(concat!(\r\n \"failed to lock the stdin; please re-run this program. \",\r\n \"If this issue repeatedly occur, this is a bug in `proconio`. \",\r\n \"Please report this issue from \",\r\n \".\"\r\n ));\r\n lock.is_empty()\r\n }\r\n }\r\n\r\n pub mod __proconio_derive_0_2_1 {\r\n pub use crate::__cargo_equip::macros::__proconio_derive_0_2_1::*;\r\n #[macro_export]\r\n macro_rules! __cargo_equip_macro_def___proconio_derive_0_2_1_derive_readable {\r\n ($(_:tt)*) => {\r\n ::std::compile_error!(\r\n \"`derive_readable` from `proconio-derive 0.2.1` should have been expanded\"\r\n );\r\n };\r\n }\r\n #[macro_export]\r\n macro_rules! __cargo_equip_macro_def___proconio_derive_0_2_1_fastout {\r\n ($(_:tt)*) => {\r\n ::std::compile_error!(\r\n \"`fastout` from `proconio-derive 0.2.1` should have been expanded\"\r\n );\r\n };\r\n }\r\n }\r\n }\r\n\r\n pub(crate) mod macros {\r\n pub mod __lazy_static_1_4_0 {\r\n pub use crate::{\r\n __cargo_equip_macro_def___lazy_static_1_4_0___lazy_static_create as __lazy_static_create,\r\n __cargo_equip_macro_def___lazy_static_1_4_0___lazy_static_internal as __lazy_static_internal,\r\n __cargo_equip_macro_def___lazy_static_1_4_0_lazy_static as lazy_static,\r\n };\r\n }\r\n\r\n pub mod proconio {\r\n pub use crate::{\r\n __cargo_equip_macro_def_proconio_input as input,\r\n __cargo_equip_macro_def_proconio_read_value as read_value,\r\n };\r\n }\r\n\r\n pub mod __proconio_derive_0_2_1 {\r\n pub use crate::{\r\n __cargo_equip_macro_def___proconio_derive_0_2_1_derive_readable as derive_readable,\r\n __cargo_equip_macro_def___proconio_derive_0_2_1_fastout as fastout,\r\n };\r\n }\r\n }\r\n\r\n pub(crate) mod prelude {\r\n pub use crate::__cargo_equip::{crates::*, macros::__lazy_static_1_4_0::*};\r\n }\r\n\r\n mod preludes {\r\n pub mod __lazy_static_1_4_0 {\r\n pub(in crate::__cargo_equip) use crate::__cargo_equip::macros::__lazy_static_1_4_0::*;\r\n }\r\n\r\n pub mod proconio {\r\n pub(in crate::__cargo_equip) use crate::__cargo_equip::crates::{\r\n __lazy_static_1_4_0 as lazy_static, __proconio_derive_0_2_1 as proconio_derive,\r\n };\r\n pub(in crate::__cargo_equip) use crate::__cargo_equip::macros::__lazy_static_1_4_0::*;\r\n }\r\n\r\n pub mod __proconio_derive_0_2_1 {}\r\n }\r\n}\r\n", "src_uid": "d5e66e34601cad6d78c3f02898fa09f4"} {"source_code": "#![allow(unused_imports)]\nuse std::io::{ self, Write };\nuse std::str::FromStr;\nuse std::cmp::{ min, max };\nuse std::collections::{ BinaryHeap, VecDeque };\n\nmacro_rules! trace {\n ($var:expr) => ({\n let _ = writeln!(&mut std::io::stderr(), \">>> {} = {:?}\", stringify!($var), $var);\n })\n}\nmacro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }\n\nfn main() {\n let mut sc = Scanner::new();\n let a: i32 = sc.cin();\n let b: i32 = sc.cin();\n\n let k = if a == b + 1 || (a == b && a > 0) || a + 1 == b { \"YES\" } else { \"NO\" };\n println!(\"{}\", k);\n\n}\n\n#[allow(dead_code)]\nstruct Scanner { stdin: io::Stdin, buffer: VecDeque, }\n#[allow(dead_code)]\nimpl Scanner {\n fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }\n fn reserve(&mut self) {\n while self.buffer.len() == 0 {\n let mut line = String::new();\n let _ = self.stdin.read_line(&mut line);\n for w in line.split_whitespace() {\n self.buffer.push_back(String::from(w));\n }\n }\n }\n fn cin(&mut self) -> T {\n self.reserve();\n match self.buffer.pop_front().unwrap().parse::() {\n Ok(a) => a,\n Err(_) => panic!(\"parse err\")\n }\n }\n fn get_char(&mut self) -> char {\n self.reserve();\n let head = self.buffer[0].chars().nth(0).unwrap();\n let tail = String::from( &self.buffer[0][1..] );\n if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }\n head\n }\n}\n", "src_uid": "ec5e3b3f5ee6a13eaf01b9a9a66ff037"} {"source_code": "use std::io::stdin;\nuse std::io::prelude::*;\nuse std::iter::*;\nuse std::str::SplitWhitespace;\nuse std::cmp::min;\n\nfn main() {\n let mut input = InRead::new();\n let n = input.int();\n let a = input.int();\n let b = input.int();\n let c = input.int();\n let x = min(a, b);\n let res = if n == 1 { 0 } else { x + min(x, c) * (n - 2) };\n println!(\"{}\", res);\n}\n\nstruct InRead(String);\n\nimpl InRead {\n fn new() -> InRead {\n InRead(String::new())\n }\n fn get_line(self: &mut Self) {\n self.0.clear();\n stdin().read_line(&mut self.0);\n }\n fn parse_int(s: &str) -> i32 { s.parse().unwrap() }\n fn ints(self: &mut Self) -> Map i32> {\n self.get_line();\n self.0.split_whitespace().map(InRead::parse_int)\n }\n fn int_vec(self: &mut Self) -> Vec { self.ints().collect() }\n fn int(self: &mut Self) -> i32 { self.ints().next().unwrap() }\n}\n\n\n", "src_uid": "6058529f0144c853e9e17ed7c661fc50"} {"source_code": "use std::io;\n\nfn main() {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let mut buffer_iter = buffer.split_whitespace().map(|n| n.parse::().unwrap());\n let b = buffer_iter.next().unwrap();\n let g = buffer_iter.next().unwrap();\n let n = buffer_iter.next().unwrap();\n\n let (x1, x2) = if b >= g {\n (b, g)\n } else {\n (g, b)\n };\n\n let result = if x2 < n {\n x2 + 1 - if n > x1 { n - x1 } else { 0 }\n } else {\n n + 1\n };\n println!(\"{}\", result);\n}", "src_uid": "9266a69e767df299569986151852e7b1"} {"source_code": "use std::io;\n\nfn main() {\n\tlet mut input = String::new();\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"Time to panic\");\n\tlet mut remaining:u64 = input.trim().parse().unwrap();\n\tlet mut notes:u64 = 0;\n\t//100 notes\n\tnotes += remaining/100;\n\tremaining = remaining%100;\n\t//20 notes\n\tnotes += remaining/20;\n\tremaining = remaining%20;\n\t//10 notes\n\tnotes += remaining/10;\n\tremaining = remaining%10;\n\t//5 notes\n\tnotes += remaining/5;\n\tremaining = remaining%5;\n\t//100 notes\n\tnotes += remaining;\n\n\tprintln!(\"{}\", notes);\n}\n", "src_uid": "8e81ad7110552c20297f08ad3e5f8ddc"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::io::stdin;\n\nmod util {\n use std::io::stdin;\n use std::str::FromStr;\n use std::fmt::Debug;\n\n #[allow(dead_code)]\n pub fn line() -> String {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn gets() -> Vec\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse().unwrap())\n .collect()\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn main() {\n let n = get!(u64);\n\n let ans = (1..)\n .map(|k| (2u64.pow(k as u32) - 1) * (2u64.pow(k as u32 - 1)))\n .take_while(|&x| x <= n)\n .filter(|&x| n % x == 0)\n .last()\n .unwrap();\n\n println!(\"{}\", ans);\n}\n", "src_uid": "339246a1be81aefe19290de0d1aead84"} {"source_code": "use std::io::*;\n\nfn reads(i: &mut StdinLock) -> Vec {\n let mut s = String::new();\n i.by_ref().read_line(&mut s).ok();\n s.trim()\n .split_whitespace()\n .map(|e| e.parse().ok().unwrap())\n .collect()\n}\n\nfn operate(n: i64, k: i64) -> (bool, i64) {\n // 0 1 2 3 4 5 6 7\n // 1\n // 1 2\n // 1 3 2\n // 1 3 2 4\n // 1 3 5 2 4\n // 1 3 5 2 4 6\n // 1 3 5 7 2 4 6\n // 1 3 5 7 2 4 6 8\n\n if n == 1 {\n return (false, 1);\n }\n\n let nf = n as f64;\n\n let start_of_even = (nf / 2.).ceil() as i64 + 1;\n\n let offset = if start_of_even <= k {\n k - start_of_even + 1\n } else {\n k\n };\n\n (start_of_even <= k, offset as i64)\n}\n\nfn main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let inputs: Vec = reads(sin);\n let n = inputs[0];\n let k = inputs[1];\n\n let (is_even, idx) = operate(n, k);\n\n let ans = if is_even { 2 * idx } else { 2 * idx - 1 };\n\n println!(\"{}\", ans);\n}\n", "src_uid": "1f8056884db00ad8294a7cc0be75fe97"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let mut n = input.i();\n loop {\n let mut x = n;\n let mut sum = 0;\n while x > 0 {\n sum += x % 10;\n x /= 10;\n }\n if sum % 4 == 0 {\n println!(\"{}\", n);\n break;\n }\n n += 1;\n }\n}\n\n", "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"source_code": "use std::io::BufRead;\n\nconst MOD: i64 = 1_000_000_007;\n\nfn power(a: i64, p: i64) -> i64 {\n if p == 0 {\n return 1;\n }\n let mut res = power(a, p / 2);\n res = (res * res) % MOD;\n if p % 2 != 0 {\n res = (res * a) % MOD;\n }\n res\n}\n\nfn solve(n: i64, m: i64) -> i64 {\n power((power(2, m) + MOD - 1) % MOD, n)\n}\n\nfn main() {\n let stdin = std::io::stdin();\n let mut handle = stdin.lock();\n let mut buf = String::new();\n handle.read_line(&mut buf).unwrap();\n let mut it = buf.split_whitespace();\n let (n, m): (i64, i64) = (\n it.next().unwrap().parse().unwrap(),\n it.next().unwrap().parse().unwrap(),\n );\n println!(\"{}\", solve(n, m));\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n #[test]\n fn test_power() {\n assert_eq!(power(0, 0), 1);\n assert_eq!(power(2, 1), 2);\n assert_eq!(power(2, 2), 4);\n assert_eq!(power(2, 3), 8);\n }\n\n #[test]\n fn test_solve() {\n assert_eq!(solve(1, 3), 7);\n assert_eq!(solve(2, 2), 9);\n assert_eq!(solve(1_000_000_000, 1_000_000_000), 751201557);\n }\n}\n", "src_uid": "71029e5bf085b0f5f39d1835eb801891"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap,HashSet,VecDeque};\n\n#[allow(unused_macros)]\nmacro_rules! readln {\n () => {{\n use std::io;\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn main() {\n let mut a =readvec!(i32);\n a.sort();\n let mut i1 = 10;\n let mut i2 = 10;\n if a[0] == a[3] {\n i1 = 4;\n i2 = 5;\n } else if a[1] == a[4] {\n i1 = 0;\n i2 = 5;\n } else if a[2] == a[5] {\n i1 = 0;\n i2 = 1;\n } else {\n println!(\"Alien\");\n return;\n }\n if i1 >= a.len() {\n println!(\"Alien\");\n return;\n }\n if a[i1] == a[i2] {\n println!(\"Elephant\");\n } else {\n println!(\"Bear\");\n }\n}\n", "src_uid": "43308fa25e8578fd9f25328e715d4dd6"} {"source_code": "fn main() {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).expect(\"input: read line failed\");\n let vec = input.trim().split_whitespace().map(|item| {\n item.parse::().expect(\"item: parse to usize failed\")\n }).collect::>();\n\n let (a_amount, b_amount, ab_amount) = (vec[0], vec[1], vec[2]);\n\n let length = 2 * ab_amount\n + 2 * min(a_amount, b_amount)\n + if max(a_amount, b_amount) - min(a_amount, b_amount) > 0 { 1 } else { 0 };\n println!(\"{}\", length);\n\n}\n\nfn min(one: usize, another: usize) -> usize {\n if one < another { one } else { another }\n}\n\nfn max(one: usize, another: usize) -> usize {\n if one > another { one } else { another }\n}\n\n", "src_uid": "609f131325c13213aedcf8d55fc3ed77"} {"source_code": "fn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let y: u32 = s.trim().parse().unwrap();\n let leap = |x: u32| -> bool {\n x % 400 == 0 || (x % 4 == 0 && x % 100 != 0)\n };\n let mut p = 1 + leap(y) as usize;\n let mut q = y + 1;\n while p != 0 || leap(q) != leap(y) {\n p = (p + 1) % 7;\n if leap(q) {\n p = (p + 1) % 7;\n }\n q += 1;\n }\n println!(\"{}\", q);\n}\n\nfn main() {\n run();\n}", "src_uid": "565bbd09f79eb7bfe2f2da46647af0f2"} {"source_code": "fn main() {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).expect(\"input: read line failed\");\n\n let vec = input.trim().split_whitespace().map(|item| {\n item.parse::().unwrap()\n }).collect::>();\n\n if vec[0] > vec[1] + vec[2] {\n println!(\"+\");\n } else if vec[0] + vec[2] < vec[1] {\n println!(\"-\");\n } else if vec[0] == vec[1] && vec[2] == 0 {\n println!(\"0\");\n } else {\n println!(\"?\");\n }\n}", "src_uid": "66398694a4a142b4a4e709d059aca0fa"} {"source_code": "use std::io;\nfn main(){\n let mut s:String=String::new();\n io::stdin().read_line(&mut s).unwrap();\n let n:i64=s.trim().parse::().unwrap();\n let mut b:i64=0;\n let mut p:i64=0;\n let mut m:i64=0;\n for c in 0..n{\n s.clear();\n io::stdin().read_line(&mut s).unwrap();\n b=s.trim().parse::().unwrap();\n if b%7==0 || b%3==0{println!(\"YES\")}\n else{\n p=b/7;\n m=p*7;\n while p!=0 && m!=b{\n m+=3;\n if m>b{p-=1;m=p*7}\n }\n if p==0{println!(\"NO\")}\n else{println!(\"YES\")}\n }\n } \n}", "src_uid": "cfd1182be98fb5f0c426f8b68e48d452"} {"source_code": "use std::io;\n\nfn get_count(n: u32) -> u32 {\n let mut count = 0;\n\n for i in 1..n {\n if n % i == 0 {\n count += 1;\n }\n }\n\n count\n}\n\npub fn solution() -> io::Result<()> {\n let mut number = String::new();\n\n io::stdin().read_line(&mut number)?;\n let number = number.trim().parse::().unwrap();\n\n println!(\"{}\", get_count(number));\n Ok(())\n}\n\nfn main() {\n solution();\n}\n", "src_uid": "89f6c1659e5addbf909eddedb785d894"} {"source_code": "use std::io::{self, BufWriter, Read, Write};\n\nfn main() {\n let mut stdin = io::stdin();\n // From https://keens.github.io/blog/2017/10/05/rustdekousokunahyoujunshutsuryoku/\n let stdout = io::stdout();\n let mut output = BufWriter::new(stdout.lock());\n let mut input_str = String::new();\n let _ = stdin.read_to_string(&mut input_str);\n let mut input_iter = input_str.split_ascii_whitespace();\n // From https://github.com/rust-lang-ja/atcoder-rust-resources/wiki/2020-Update#proconio\n sub_main(&mut input_iter, &mut output);\n}\n\nfn sub_main(input_iter: &mut dyn Iterator, output: &mut dyn Write) {\n macro_rules! read(() => (input_iter.next().unwrap().parse().unwrap()));\n macro_rules! print(( $( $x:expr ),*) => (write!(output, $($x,)*).unwrap()));\n macro_rules! println(( $( $x:expr ),*) => (writeln!(output, $($x,)*).unwrap()));\n // Deal with each case\n let n: usize = read!();\n let non_cyclic = ModP(2).pow(n - 1);\n let mut total_num = ModP(1);\n for i in 1..=n {\n total_num = total_num * ModP(i as u64);\n }\n let ans = total_num - non_cyclic;\n println!(\"{}\", ans.0);\n}\n\nuse std::ops::{Add, Div, Mul, Sub};\n\nconst MODULUS: u64 = 1000000007;\n\n#[derive(Clone, Copy, PartialEq, Debug)]\nstruct ModP(u64);\n\nimpl Add for ModP {\n type Output = Self;\n fn add(self, rhs: Self) -> Self {\n return ModP((self.0 + rhs.0) % MODULUS);\n }\n}\nimpl Sub for ModP {\n type Output = Self;\n fn sub(self, rhs: Self) -> Self {\n return ModP((self.0 + MODULUS - rhs.0) % MODULUS);\n }\n}\nimpl Mul for ModP {\n type Output = Self;\n fn mul(self, rhs: Self) -> Self {\n return ModP((self.0 * rhs.0) % MODULUS);\n }\n}\nimpl Div for ModP {\n type Output = Self;\n fn div(self, rhs: Self) -> Self {\n if rhs.0 == 0 {\n panic!(\"Tried to divide by ModP(0)!\");\n }\n let rhs_inv = rhs.pow((MODULUS - 2) as usize);\n return self * rhs_inv;\n }\n}\n\nimpl ModP {\n fn pow(&self, n: usize) -> Self {\n if n == 0 {\n return ModP(1);\n } else if n == 1 {\n return *self;\n } else {\n let half = self.pow(n / 2);\n if n % 2 == 0 {\n return half * half;\n } else {\n return half * half * (*self);\n }\n }\n }\n}\n", "src_uid": "3dc1ee09016a25421ae371fa8005fce1"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\n\nfn read_std() -> Vec {\n let mut buffer = String::new();\n let _ = io::stdin().read_line(&mut buffer);\n let buffvec: Vec<&str> = buffer.trim().split(\" \").collect();\n let mut numvec: Vec = vec![];\n for x in &buffvec {\n let buff: i32 = FromStr::from_str(x).unwrap();\n numvec.push(buff);\n }\n numvec\n}\n\nfn vec_to_str(smvec: Vec) -> Vec {\n let mut newvec: Vec = vec![];\n for x in smvec {\n newvec.push(format!(\"{}\", x));\n }\n newvec\n}\n\nfn main() {\n let nums = read_std();\n let n = nums[0];\n let k = nums[1];\n\n let mut delvec: Vec = vec![2];\n\n for y in 2..n+1 {\n let mut state = true;\n 'inner: for x in &delvec {\n if y % x == 0 {\n state = false;\n break 'inner;\n }\n }\n if state {\n delvec.push(y);\n }\n }\n // println!(\"{:?}\", delvec);\n let mut anvec: Vec = vec![];\n let mut last = n;\n while last > 1 {\n for x in &delvec {\n if last % x == 0 {\n anvec.push(*x);\n last /= *x;\n }\n }\n }\n\n if anvec.len() < k as usize {\n println!(\"-1\");\n } else {\n while anvec.len() > k as usize {\n anvec[0] *= anvec.pop().unwrap()\n }\n println!(\"{}\", vec_to_str(anvec).join(\" \"));\n }\n\n}", "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::Read;\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok().unwrap();\n ret\n}\nfn get_word() -> String {\n let mut stdin = std::io::stdin();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\n/// min{x | x * (x + 1) / 2 >= v }\nfn calc(v: i64) -> i64 {\n assert! (v > 0);\n let piv = (2. * v as f64).sqrt() as i64;\n for k in max(piv - 10, 0) .. piv + 10 {\n if k * (k + 1) >= 2 * v {\n return k;\n }\n }\n panic!();\n}\n\nfn solve() {\n let n: i64 = get();\n let m: i64 = get();\n if n <= m {\n println!(\"{}\", n);\n return;\n }\n println!(\"{}\", m + calc(n - m));\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "3b585ea852ffc41034ef6804b6aebbd8"} {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::{cell::{Cell, RefCell, UnsafeCell}, cmp::{Ordering, Reverse, max, min}, collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, hash_map::{DefaultHasher, RandomState}}, error::Error, fmt::{Display, Write as FmtWrite}, hash::{BuildHasher, Hash, Hasher}, io::{BufWriter, Read, Stdin, Stdout, Write}, iter::{FromIterator, Peekable}, mem::swap, ops::*, process::exit, rc::Rc, str::{FromStr, from_utf8_unchecked}, time::{Duration, Instant}, convert::TryInto, marker::PhantomData};\n\nconst IO_BUF_SIZE: usize = 1 << 16;\ntype Input = Scanner;\ntype Output = BufWriter;\nfn _init_input() -> Input { Scanner::new(std::io::stdin()) }\nfn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) }\n\n#[repr(transparent)] struct Unsync(T);\nunsafe impl Sync for Unsync {}\n \ntype BadLazy = Unsync>>;\nimpl BadLazy {\n const fn new() -> Self { Self(UnsafeCell::new(None)) }\n}\n \nstatic INPUT: BadLazy = BadLazy::new();\nstatic OUTPUT: BadLazy = BadLazy::new();\n \nfn inp R, R>(f: F) -> R {\n unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) }\n}\nfn out R, R>(f: F) -> R {\n unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) }\n}\n\nmacro_rules! read {\n () => { read() };\n ($t: ty) => { read::<$t>() };\n ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) };\n [$t: ty; $n: expr] => { read_vec::<$t>($n) };\n}\nmacro_rules! println { \n () => { out(|x| { let _ = writeln!(x); }) };\n ($exp: expr) => { out(|x| { let _ = writeln!(x, \"{}\", $exp); }) }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = writeln!(x, $fmt, $($arg)*); }) }\n}\nmacro_rules! print { \n ($exp: expr) => { out(|x| { let _ = write!(x, \"{}\", $exp); }) }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { let _ = write!(x, $fmt, $($arg)*); }) }\n}\n\nfn out_flush() { out(|x| { let _ = x.flush(); }); }\n\nfn input_is_eof() -> bool { inp(|x| x.eof()) }\nfn read_byte() -> u8 { inp(|x| x.byte()) }\nfn read_bytes_no_skip(n: usize) -> Vec { inp(|x| x.bytes_no_skip(n)) }\nfn read_bytes(n: usize) -> Vec { inp(|x| x.bytes(n)) }\nfn read_bytes2(n: usize, m: usize) -> Vec> { inp(|x| x.bytes2(n, m)) }\nfn read_token() -> Vec { inp(|x| x.token_bytes()) }\nfn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } }\nfn read_line() -> Vec { inp(|x| x.line_bytes()) }\nfn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } }\nfn read() -> T { read_token_str().parse::().ok().expect(\"failed parse\") }\nfn read_vec(n: usize) -> Vec { (0..n).map(|_| read()).collect() }\nfn read_vec2(n: usize, m: usize) -> Vec> { (0..n).map(|_| read_vec(m)).collect() }\n\nstruct Scanner {\n src: R,\n _buf: Vec,\n _pt: usize, // pointer\n _rd: usize, // bytes read\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new(src: R) -> Scanner {\n Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }\n }\n \n fn _check_buf(&mut self) {\n if self._pt == self._rd {\n self._rd = self.src.read(&mut self._buf).unwrap_or(0);\n self._pt = (self._rd == 0) as usize;\n }\n }\n \n // returns true if end of file\n fn eof(&mut self) -> bool {\n self._check_buf();\n self._rd == 0\n }\n \n // filters \\r, returns \\0 if eof\n fn byte(&mut self) -> u8 {\n loop {\n self._check_buf();\n if self._rd == 0 { return 0; }\n let res = self._buf[self._pt];\n self._pt += 1;\n if res != b'\\r' { return res; }\n }\n }\n\n fn bytes_no_skip(&mut self, n: usize) -> Vec { (0..n).map(|_| self.byte()).collect() }\n fn bytes(&mut self, n: usize) -> Vec {\n let res = self.bytes_no_skip(n);\n self.byte();\n res\n }\n fn bytes2(&mut self, n: usize, m: usize) -> Vec> { (0..n).map(|_| self.bytes(m)).collect() }\n \n fn token_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c <= b' ' {\n if c == b'\\0' { return res; }\n c = self.byte();\n }\n loop {\n res.push(c);\n c = self.byte();\n if c <= b' ' { return res; }\n }\n }\n \n fn line_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c != b'\\n' && c != b'\\0' {\n res.push(c);\n c = self.byte();\n }\n res\n }\n}\n\ntrait JoinToStr { \n fn join_to_str(self, sep: &str) -> String;\n fn concat_to_str(self) -> String;\n}\nimpl> JoinToStr for I { \n fn join_to_str(mut self, sep: &str) -> String {\n match self.next() {\n Some(first) => {\n let mut res = first.to_string();\n while let Some(item) = self.next() {\n res.push_str(sep);\n res.push_str(&item.to_string());\n }\n res\n }\n None => { String::new() }\n }\n }\n \n fn concat_to_str(self) -> String {\n let mut res = String::new();\n for item in self { res.push_str(&item.to_string()); }\n res\n }\n}\ntrait AsStr { fn as_str(&self) -> &str; }\nimpl AsStr for [u8] { fn as_str(&self) -> &str {std::str::from_utf8(self).expect(\"attempt to convert non-UTF8 byte string.\")} }\n\nmacro_rules! veci {\n ($n:expr , $i:ident : $gen:expr) => {{\n let _veci_n = $n;\n let mut _veci_list = Vec::with_capacity(_veci_n);\n for $i in 0.._veci_n {\n _veci_list.push($gen);\n }\n _veci_list\n }};\n ($n:expr , $gen:expr) => { veci!($n, _veci_: $gen) }\n}\n\nfn abs_diff + PartialOrd>(x: T, y: T) -> T {\n if x < y { y - x } else { x - y }\n}\n\ntrait CommonNumExt {\n fn div_ceil(self, b: Self) -> Self;\n fn div_floor(self, b: Self) -> Self;\n fn gcd(self, b: Self) -> Self;\n fn highest_one(self) -> Self;\n fn lowest_one(self) -> Self;\n fn sig_bits(self) -> u32;\n}\n\nmacro_rules! impl_common_num_ext {\n ($($ix:tt = $ux:tt),*) => {\n $(\n impl CommonNumExt for $ux {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { self / b }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }\n b\n }\n #[inline] fn highest_one(self) -> Self { \n if self == 0 { 0 } else { const ONE: $ux = 1; ONE << self.sig_bits() - 1 } \n }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ux>() as u32 * 8 - self.leading_zeros() }\n }\n\n impl CommonNumExt for $ix {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if self ^ b >= 0 && r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { \n let q = self / b; let r = self % b;\n if self ^ b < 0 && r != 0 { q - 1 } else { q }\n }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }\n b.abs()\n }\n #[inline] fn highest_one(self) -> Self { (self as $ux).highest_one() as _ }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n #[inline] fn sig_bits(self) -> u32 { std::mem::size_of::<$ix>() as u32 * 8 - self.leading_zeros() }\n }\n )*\n }\n}\nimpl_common_num_ext!(i8 = u8, i16 = u16, i32 = u32, i64 = u64, i128 = u128, isize = usize);\n\ntrait ChMaxMin {\n fn chmax(&mut self, v: T) -> bool;\n fn chmin(&mut self, v: T) -> bool;\n}\nimpl ChMaxMin for Option {\n fn chmax(&mut self, v: T) -> bool { if self.is_none() || v > *self.as_ref().unwrap() { *self = Some(v); true } else { false } }\n fn chmin(&mut self, v: T) -> bool { if self.is_none() || v < *self.as_ref().unwrap() { *self = Some(v); true } else { false } }\n}\nimpl ChMaxMin for T {\n fn chmax(&mut self, v: T) -> bool { if v > *self { *self = v; true } else { false } }\n fn chmin(&mut self, v: T) -> bool { if v < *self { *self = v; true } else { false } }\n}\n\n// * end commons * //\n\n#[macro_use]\n#[allow(dead_code)]\nmod modint {\n use std::{fmt::{Display, Formatter}, marker::PhantomData, mem::swap, ops::*, str::FromStr, cell::Cell};\n use crate::ModInt;\n \n pub trait RemEuclidU32: Copy {\n /// Calculates `self` _mod_ `modulus` losslessly.\n fn rem_euclid_u32(self, modulus: u32) -> u32;\n }\n \n macro_rules! impl_rem_euclid_u32_for_small_signed {\n ($($ty:tt),*) => {\n $(\n impl RemEuclidU32 for $ty {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n (self as i64).rem_euclid(i64::from(modulus)) as _\n }\n }\n )*\n }\n }\n \n impl_rem_euclid_u32_for_small_signed!(i8, i16, i32, i64, isize);\n \n impl RemEuclidU32 for i128 {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n self.rem_euclid(i128::from(modulus)) as _\n }\n }\n \n macro_rules! impl_rem_euclid_u32_for_small_unsigned {\n ($($ty:tt),*) => {\n $(\n impl RemEuclidU32 for $ty {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n self as u32 % modulus\n }\n }\n )*\n }\n }\n \n macro_rules! impl_rem_euclid_u32_for_large_unsigned {\n ($($ty:tt),*) => {\n $(\n impl RemEuclidU32 for $ty {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n (self % (modulus as $ty)) as _\n }\n }\n )*\n }\n }\n \n impl_rem_euclid_u32_for_small_unsigned!(u8, u16, u32);\n impl_rem_euclid_u32_for_large_unsigned!(u64, u128);\n \n #[cfg(target_pointer_width = \"32\")]\n impl_rem_euclid_u32_for_small_unsigned!(usize);\n \n #[cfg(target_pointer_width = \"64\")]\n impl_rem_euclid_u32_for_large_unsigned!(usize);\n #[inline]\n pub fn mul_mod_u32(a: u32, b: u32, m: u32) -> u32 {\n (a as u64 * b as u64 % m as u64) as u32\n }\n \n // for a, b < m, unspecified otherwise\n #[inline]\n fn add_mod_raw(a: u32, b: u32, m: u32) -> u32 {\n let (r, c) = a.wrapping_sub(m).overflowing_add(b);\n if c { r } else { a + b }\n }\n #[inline]\n fn sub_mod_raw(a: u32, b: u32, m: u32) -> u32 {\n let (r, c) = a.overflowing_sub(b);\n if c { r.wrapping_add(m) } else { r }\n }\n fn pow_mod_raw(a: u32, mut k: u64, m: u32) -> u32 {\n if m == 1 { return 0; }\n let mut a = a as u64;\n let m = m as u64;\n let mut r: u64 = 1;\n while k > 0 {\n if k & 1 == 1 {\n r = r * a % m;\n }\n k >>= 1;\n a = a * a % m;\n }\n r as u32\n }\n \n /// # Parameters\n /// * `b` `1 <= b`\n /// # Returns\n /// (x, g) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g\n fn inv_gcd(a: i64, b: i64) -> (i64, i64) {\n let a = a.rem_euclid(b);\n if a == 0 { return (0, b); }\n let mut s = b;\n let mut t = a;\n let mut m0 = 0;\n let mut m1 = 1;\n \n while t != 0 {\n let u = s / t;\n s -= t * u;\n m0 -= m1 * u;\n swap(&mut s, &mut t);\n swap(&mut m0, &mut m1);\n }\n \n if m0 < 0 { m0 += b / s; }\n (m0, s)\n }\n \n pub trait Modulus: Copy + Eq {\n fn get_modulus() -> u32;\n }\n \n #[derive(Clone, Copy, PartialEq, Eq, Hash)]\n #[repr(transparent)]\n pub struct ModIntBase { \n val: u32,\n _phantom: PhantomData\n }\n \n impl ModIntBase {\n #[inline(always)]\n pub fn modulus() -> u32 { M::get_modulus() }\n #[inline] pub fn new(val: I) -> Self { Self::raw(val.rem_euclid_u32(Self::modulus())) }\n #[inline] pub fn raw(val: u32) -> Self { Self { val, _phantom: PhantomData } }\n pub fn inv(self) -> Self { \n let (x, gcd) = inv_gcd(self.val.into(), Self::modulus().into());\n debug_assert!(gcd == 1, \"the multiplicative inverse {}^-1 mod {} does not exist\", self.val, Self::modulus());\n Self::raw(x as u32)\n }\n #[inline] pub fn val(self) -> u32 { self.val }\n #[inline] pub fn pow(self, k: u64) -> Self {\n Self::raw(pow_mod_raw(self.val, k, Self::modulus()))\n }\n pub fn powi(self, k: i64) -> Self { if k < 0 { self.inv().pow(-k as _) } else { self.pow(k as _) } }\n pub fn pow_vec(self, n: usize) -> Vec {\n let mut res = vec![Self::raw(0); n+1];\n res[0] += 1;\n for i in 1..=n {\n res[i] = res[i-1] * self;\n }\n res\n }\n\n pub fn invs(a: &[Self]) -> Vec {\n let n = a.len();\n if n == 0 { return vec![]; }\n let mut acc = Self::new(1);\n let mut res = Vec::with_capacity(n);\n for i in 0..n {\n if a[i].val() != 0 { acc *= a[i]; }\n res.push(acc);\n }\n acc = acc.inv();\n for i in (1..n).rev() {\n res[i] = acc * res[i-1];\n if a[i].val() != 0 { acc *= a[i]; }\n }\n res[0] = acc;\n res\n }\n }\n \n #[inline]\n pub fn mi(val: I) -> ModInt { ModIntBase::new(val) }\n #[inline] pub fn mir(v: u32) -> ModInt { ModIntBase::raw(v) }\n \n impl From for ModIntBase {\n #[inline]\n fn from(from: V) -> Self { Self::new(from) }\n }\n impl Default for ModIntBase {\n fn default() -> Self { Self::raw(0) }\n }\n impl FromStr for ModIntBase {\n type Err = std::convert::Infallible;\n #[inline]\n fn from_str(s: &str) -> Result {\n Ok(s.parse::()\n .map(Self::new)\n .unwrap_or_else(|_| todo!(\"parsing as an arbitrary precision integer?\")))\n }\n }\n impl Display for ModIntBase {\n #[inline]\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n self.val.fmt(f)\n }\n }\n impl std::fmt::Debug for ModIntBase {\n #[inline]\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n std::fmt::Debug::fmt(&self.val, f)\n }\n }\n impl Neg for ModIntBase {\n type Output = Self;\n \n #[inline]\n fn neg(self) -> Self::Output {\n Self::raw(0) - self\n }\n }\n \n impl>, M: Modulus> Add for ModIntBase {\n type Output = Self;\n #[inline]\n fn add(self, rhs: V) -> Self::Output {\n Self::raw(add_mod_raw(self.val, rhs.into().val, Self::modulus()))\n }\n }\n impl>, M: Modulus> Sub for ModIntBase {\n type Output = Self;\n #[inline]\n fn sub(self, rhs: V) -> Self::Output {\n Self::raw(sub_mod_raw(self.val, rhs.into().val, Self::modulus()))\n }\n }\n impl>, M: Modulus> Mul for ModIntBase {\n type Output = Self;\n #[inline]\n fn mul(self, rhs: V) -> Self::Output {\n Self::raw(mul_mod_u32(self.val, rhs.into().val, Self::modulus()))\n }\n }\n impl>, M: Modulus> Div for ModIntBase {\n type Output = Self;\n #[inline]\n fn div(self, rhs: V) -> Self::Output { self * rhs.into().inv() }\n }\n \n impl >, M: Modulus> AddAssign for ModIntBase {\n #[inline]\n fn add_assign(&mut self, rhs: V) { *self = *self + rhs; }\n }\n impl >, M: Modulus> SubAssign for ModIntBase {\n #[inline]\n fn sub_assign(&mut self, rhs: V) { *self = *self - rhs; }\n }\n impl >, M: Modulus> MulAssign for ModIntBase {\n #[inline]\n fn mul_assign(&mut self, rhs: V) { *self = *self * rhs; }\n }\n impl >, M: Modulus> DivAssign for ModIntBase {\n #[inline]\n fn div_assign(&mut self, rhs: V) { *self = *self / rhs; }\n }\n \n impl std::iter::Sum for ModIntBase {\n #[inline] fn sum>(iter: I) -> Self {\n iter.fold(Self::raw(0), Add::add)\n }\n }\n impl std::iter::Product for ModIntBase {\n #[inline] fn product>(iter: I) -> Self {\n iter.fold(1.into(), Mul::mul)\n }\n }\n impl<'a, M: Modulus> std::iter::Sum<&'a Self> for ModIntBase {\n #[inline] fn sum>(iter: I) -> ModIntBase {\n iter.fold(Self::raw(0), |a, &b| a + b)\n }\n }\n impl<'a, M: Modulus> std::iter::Product<&'a Self> for ModIntBase {\n #[inline] fn product>(iter: I) -> ModIntBase {\n iter.fold(1.into(), |a, &b| a * b)\n }\n }\n \n macro_rules! const_modulus {\n ($mint: ident, $name: ident, $modulus: expr) => {\n #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\n pub enum $name {}\n impl Modulus for $name {\n #[inline(always)] fn get_modulus() -> u32 { $modulus }\n }\n pub type $mint = ModIntBase<$name>;\n }\n }\n \n macro_rules! dynamic_modulus {\n ($mint: ident, $name: ident, $modulus: ident) => {\n static $modulus: crate::Unsync> = crate::Unsync(Cell::new(0));\n #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\n pub enum $name {}\n impl Modulus for $name {\n fn get_modulus() -> u32 { $modulus.0.get() }\n }\n impl $name {\n pub fn set_modulus(val: u32) { $modulus.0.set(val) }\n }\n pub type $mint = ModIntBase<$name>;\n }\n }\n \n const_modulus!(ModInt998_244_353, Mod998_244_353, 998_244_353);\n const_modulus!(ModInt1_000_000_007, Mod1_000_000_007, 1_000_000_007);\n dynamic_modulus!(DynamicModInt, DynamicModulus, DYNAMIC_MODULUS);\n}\n \nuse crate::modint::*;\ntype ModInt = ModInt998_244_353;\n// type ModInt = ModInt1_000_000_007;\n// const_modulus!(ModInt, DefaultModulus, 1_000_000_009);\n// type ModInt = DynamicModInt;\n\nfn mod_factorials(maxn: usize) -> Vec {\n let mut res = vec![ModInt::default(); maxn+1];\n res[0] = 1.into();\n for i in 1..=maxn {\n res[i] = res[i-1] * i\n }\n return res;\n}\n\nstruct ModCombinatorics {\n factorials: Vec,\n inv_factorials: Vec\n}\n#[allow(non_snake_case)]\nimpl ModCombinatorics {\n fn new(maxn: usize) -> Self {\n let factorials = mod_factorials(maxn);\n let mut inv = vec![ModInt::default(); maxn+1];\n inv[maxn] = factorials[maxn].inv();\n for i in (1..=maxn).rev() {\n inv[i-1] = inv[i] * i;\n }\n Self { factorials, inv_factorials: inv }\n }\n #[inline]\n fn factorial(&self, n: usize) -> ModInt { self.factorials[n] }\n #[inline]\n fn inv_factorial(&self, n: usize) -> ModInt { self.inv_factorials[n] }\n fn P(&self, n: usize, k: usize) -> ModInt {\n if k > n { ModInt::raw(0) } else { self.factorial(n) * self.inv_factorial(n-k) }\n }\n fn C(&self, n: usize, k: usize) -> ModInt {\n if k > n { ModInt::raw(0) } else { self.factorial(n) * self.inv_factorial(k) * self.inv_factorial(n-k) }\n }\n\n // multi-choose, be sure to adjust maxn accordingly\n fn M(&self, n: usize, k: usize) -> ModInt {\n if k == 0 { 1.into() } else { self.C(n + k - 1, k) }\n }\n}\n\npub struct ModFft {\n n_inv: ModInt,\n w: Vec\n}\nimpl ModFft {\n pub fn primitive_root() -> ModInt { ModInt::raw(3) /* for 998244353 */}\n pub fn good_len(deg: usize) -> usize { (deg + 1).next_power_of_two() }\n pub fn prepare(arr: &[ModInt], deg: usize) -> Vec { \n let n = Self::good_len(deg);\n let mut res = Vec::with_capacity(n);\n res.extend_from_slice(arr);\n res.resize(n, ModInt::raw(0));\n res\n }\n\n pub fn new(max_deg: usize) -> Self {\n let n = Self::good_len(max_deg);\n Self {\n n_inv: ModInt::new(n).inv(),\n w: ModInt::pow_vec(Self::primitive_root().pow((ModInt::modulus() - 1) as u64 / n as u64), n-1)\n }\n }\n\n pub fn transform(&self, a: &mut [ModInt]) { self.transform_impl(a, false) }\n pub fn transform_inv(&self, a: &mut [ModInt]) { self.transform_impl(a, true) }\n\n pub fn fft(&self, a: &[ModInt]) -> Vec { self.fft_deg(a, a.len() - 1) }\n pub fn fft_deg(&self, a: &[ModInt], deg: usize) -> Vec { \n let mut a = Self::prepare(a, deg);\n self.transform(&mut a);\n a\n }\n pub fn fft_inv(&self, a: &[ModInt]) -> Vec { \n let mut a = Self::prepare(a, a.len() - 1);\n self.transform_inv(&mut a);\n a\n }\n\n pub fn max_deg(&self) -> usize { self.w.len() - 1 }\n\n #[inline] fn transform_impl(&self, a: &mut [ModInt], invert: bool) {\n let sz = a.len();\n if sz <= 1 { return }\n let n = self.w.len();\n debug_assert!(sz <= n && sz.is_power_of_two(), \"Array size {} must be <= {} and a power of 2\", sz, n);\n let sh = sz.leading_zeros() + 1;\n\n for i in 0..sz {\n let j = i.reverse_bits() >> sh;\n if i < j { a.swap(i, j) }\n }\n\n let mut len = 2usize;\n let mut ang = (n >> 1) as isize;\n if invert { ang = -ang; }\n while len <= sz {\n let h = len >> 1;\n for i in (0..sz).step_by(len) {\n let mut k = 0usize;\n for j in i..i+h {\n let u = a[j];\n let v = a[j+h] * self.w[k];\n a[j] = u + v;\n a[j+h] = u - v;\n k = k.wrapping_add(ang as usize) & (n-1);\n }\n }\n len <<= 1;\n ang >>= 1;\n }\n\n if invert {\n let sz_inv = self.n_inv * (n / sz);\n for i in 0..sz { a[i] *= sz_inv; }\n }\n }\n\n pub fn mul(&self, a: &[ModInt], b: &[ModInt]) -> Vec {\n if a.is_empty() || b.is_empty() { return vec![]; }\n let deg = a.len() + b.len() - 2;\n debug_assert!(deg < self.w.len(), \"FFT capacity {} too small for polynomial of degree {}\", self.w.len(), deg);\n let mut a = Self::prepare(a, deg);\n let mut b = Self::prepare(b, deg);\n self.transform(&mut a);\n self.transform(&mut b);\n for i in 0..a.len() { a[i] *= b[i]; }\n self.transform_inv(&mut a);\n a.truncate(deg + 1);\n a\n }\n\n pub fn sq(&self, a: &[ModInt]) -> Vec {\n if a.is_empty() { return vec![]; }\n let deg = a.len() * 2 - 2;\n debug_assert!(deg < self.w.len(), \"FFT capacity {} too small for polynomial of degree {}\", self.w.len(), deg);\n let mut a = Self::prepare(a, deg);\n self.transform(&mut a);\n for i in 0..a.len() { let ai = a[i]; a[i] = ai * ai; }\n self.transform_inv(&mut a);\n a.truncate(deg + 1);\n a\n }\n\n pub fn pow(&self, a: &[ModInt], exp: usize) -> Vec {\n if a.is_empty() { return vec![]; }\n let deg = (a.len() - 1) * exp;\n debug_assert!(deg < self.w.len(), \"FFT capacity {} too small for polynomial of degree {}\", self.w.len(), deg);\n let mut a = Self::prepare(a, deg);\n self.transform(&mut a);\n for i in 0..a.len() { a[i] = a[i].pow(exp as u64) }\n self.transform_inv(&mut a);\n a.truncate(deg + 1);\n a\n }\n\n pub fn product(&self, mut polys: VecDeque>) -> Vec {\n while let Some(p) = polys.pop_front() {\n if let Some(q) = polys.pop_front() {\n polys.push_back(self.mul(&p, &q));\n } else { return p; }\n }\n\n vec![ModInt::new(1)]\n }\n}\n\nstruct FactorMap {\n map: Vec\n}\nimpl FactorMap {\n pub fn new(limit: usize) -> FactorMap {\n let limit = limit + 1;\n let mut map = vec![0; limit >> 1];\n for p in (3..limit).step_by(2) {\n if map[p >> 1] != 0 { continue; }\n let sq = p * p;\n if sq >= limit { break; }\n for i in (sq..limit).step_by(p*2) {\n if map[i >> 1] == 0 { map[i >> 1] = p as u32; }\n }\n }\n\n FactorMap { map }\n }\n\n pub fn least_prime_factor(&self, n: usize) -> usize {\n if n & 1 == 0 { return 2; }\n let p = self.map[n >> 1] as usize;\n if p == 0 { n } else { p }\n }\n\n pub fn factorize(&self, n: usize) -> FactorIterator {\n FactorIterator { fm: self, n }\n }\n\n pub fn is_prime(&self, n: usize) -> bool { n > 1 && self.least_prime_factor(n) == n }\n\n /// lists divisors, unsorted\n pub fn divisors(&self, mut n: usize) -> Vec {\n let mut res = vec![1];\n\n while n > 1 {\n let p = self.least_prime_factor(n);\n let mut x = 0;\n loop {\n n /= p;\n x += 1;\n if p != self.least_prime_factor(n) { break; }\n }\n for i in 0..res.len() {\n let mut a = res[i];\n for _ in 0..x {\n a *= p;\n res.push(a);\n }\n }\n }\n\n res\n }\n\n pub fn new_with_mobius(limit: usize) -> (FactorMap, Vec) {\n let fm = Self::new(limit);\n let mut mu = vec![1i8; limit + 1];\n mu[0] = 0;\n\n for i in 2..=limit {\n let p = fm.least_prime_factor(i);\n mu[i] = if p == fm.least_prime_factor(i/p) { 0 } else { -mu[i/p] };\n }\n\n (fm, mu)\n }\n}\nstruct FactorIterator<'a> {\n fm: &'a FactorMap,\n n: usize\n}\nimpl Iterator for FactorIterator<'_> {\n type Item = usize;\n\n fn next(&mut self) -> Option {\n if self.n <= 1 { return None; }\n let p = self.fm.least_prime_factor(self.n);\n self.n /= p;\n Some(p)\n }\n\n fn size_hint(&self) -> (usize, Option) { (0, Some(32)) }\n}\n \n#[allow(non_snake_case, non_upper_case_globals)]\nfn main() {\n let num_cases: usize = 1;//read();\n\n for _case_num in 1..=num_cases {\n let n = read!(usize);\n let k = read!(usize);\n\n let mut ans = mi(0);\n if min(n, k) == 1 { ans = mi(1); }\n else {\n let mc = ModCombinatorics::new(min(n, k));\n let ff = ModFft::new(min(n, k) * 2);\n let mu = FactorMap::new_with_mobius(n).1;\n\n let mut m = 0usize;\n let mut A = mi(0);\n let P = veci!(min(n, k)+1, j: if j & 1 == 1 { -mc.inv_factorial(j) } else { mc.inv_factorial(j) });\n\n for i in 1..=n {\n if mu[i] == 0 { continue; }\n let mn = n.div_ceil(i);\n if m != mn {\n m = mn;\n let l = min(m, k);\n let Q = veci!(l+1, j: mi(j).pow(m as _) * mc.inv_factorial(j));\n let R = ff.mul(&P[..=l], &Q);\n A = R[2..=l].iter().sum();\n }\n if mu[i] == 1 { ans += A; } else { ans -= A; }\n }\n }\n\n println!(ans);\n }\n \n out_flush();\n}", "src_uid": "eb9d24070cc5b347d020189d803628ae"} {"source_code": "use std::io;\nfn main(){\n let mut line=String::new();\n io::stdin().read_line(&mut line).expect(\"Die\");\n let arr:Vec = line.split(\" \").map(|x| x.trim().parse().expect(\"Int\")).collect();\n let (mut i,mut j):(i32,i32)=(arr[1],arr[3]);\n let mut ans=false;\n loop{\n i+=1;\n if i>arr[0]{\n i=1;\n }\n\n j-=1;\n if j<=0{\n j=arr[0];\n }\n if i==j{\n ans=true;\n break;\n }\n else if i==arr[2] || j==arr[4]{\n break;\n }\n }\n\n if ans{\n println!(\"YES\")\n }\n else{\n println!(\"NO\")\n }\n}", "src_uid": "5b889751f82c9f32f223cdee0c0095e4"} {"source_code": "use std::cmp::min;\n\nmacro_rules! read_line {\n ($v:ident) => {\n let mut temp = String::new();\n std::io::stdin().read_line(&mut temp).unwrap();\n let $v = temp;\n };\n (var, $t:ty, $($v:ident), *) => {\n read_line!(input_line);\n let mut iter = parse_token!($t, input_line);\n $(\n let $v = iter.next().unwrap();\n )*\n };\n (vec, $t:ty, $v:ident) => {\n read_line!(input_line);\n let iter = parse_token!($t, input_line);\n let $v: Vec<$t> = iter.collect();\n };\n ($($v:ident; $t:ty), *) => {\n read_line!(input_line);\n let mut iter = input_line.split_whitespace();\n $(\n let $v: $t = iter.next().unwrap().parse().unwrap();\n )*\n };\n}\n\nmacro_rules! parse_token {\n ($t:ty, $e:expr) => {\n $e.split_whitespace().map(|x| x.parse::<$t>().unwrap());\n };\n}\n\nfn main() {\n read_line!(k2;u32, k3;u32, k5;u32, k6;u32);\n let max_256 = min(min(k2, k5), k6);\n let k2_left = k2 - max_256;\n let max_32 = min(k2_left, k3);\n println!(\"{}\", max_32 * 32 + max_256 * 256);\n}", "src_uid": "082b31cc156a7ba1e0a982f07ecc207e"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io;\n use std::io::prelude::*;\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let p: u64 = it.next().unwrap().parse().unwrap();\n let y: u64 = it.next().unwrap().parse().unwrap();\n\n let ans = (p + 1..y + 1).rev().find(|&i| {\n let k = std::cmp::min(p, (y as f64).sqrt().floor() as u64);\n (2..k + 1).all(|j| i % j != 0)\n });\n\n match ans {\n Some(ans) => println!(\"{}\", ans),\n None => println!(\"-1\"),\n }\n}\n", "src_uid": "b533203f488fa4caf105f3f46dd5844d"} {"source_code": "#[allow(unused_imports)]\nuse std::io::{stdin, Read, StdinLock};\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::str::FromStr;\n#[allow(unused_imports)]\nuse std::collections::{HashSet, HashMap, BinaryHeap};\n#[allow(unused_imports)]\nuse std::vec::Vec;\n\n#[allow(dead_code)]\nconst INF: i32 = 1000_000_000;\n#[allow(dead_code)]\nconst INFLL: i64 = 1000_000_000_000_000_000;\n#[allow(dead_code)]\nconst EPS: f64 = 1.0e-10;\n#[allow(dead_code)]\nconst MOD: i32 = 1000_000_007;\n\nstruct Scanner<'a> {\n cin: StdinLock<'a>,\n}\n\nimpl<'a> Scanner<'a> {\n #[allow(dead_code)]\n fn new(cin: StdinLock<'a>) -> Scanner<'a> {\n Scanner {cin: cin}\n }\n\n #[allow(dead_code)]\n fn read1(&mut self) -> Option {\n let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect::();\n token.parse::().ok()\n }\n\n #[allow(dead_code)]\n fn read(&mut self) -> T {\n self.read1().unwrap()\n }\n}\n\n\nfn main() {\n let cin = stdin();\n let cin = cin.lock();\n let mut sc = Scanner::new(cin);\n let mut s1: Vec = Vec::new();\n for _i in 0..2 {\n let s: String = sc.read();\n let mut s: Vec = s.chars().collect();\n s1.append(&mut s);\n }\n let s2: String = sc.read();\n let mut s2: Vec = s2.chars().collect();\n s1.sort(); s2.sort();\n if s1.len() != s2.len() {\n println!(\"NO\");\n } else {\n let mut ok = true;\n for i in 0..s1.len() {\n ok &= s1[i] == s2[i];\n }\n if ok {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n }\n}", "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nconst N: i64 = 998_244_353;\n\nfn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d0, x0, y0) = extended_euclid(b, a % b);\n (d0, y0, x0 - a / b * y0)\n }\n}\n\nfn main() {\n let (a, b, c) = {\n let input = get_line();\n let mut it = input.split_whitespace().map(|k| k.parse::().unwrap());\n (\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n )\n };\n\n let mut s = [a, b, c];\n s.sort();\n let (a, b, c) = (s[0], s[1], s[2]);\n\n // Nombres d'ar\u00eates possibles :\n // a * b + b * c + c * a\n // Nombre de combinaisons possibles :\n // 2^nap\n\n let modulo = |a, b| {\n if a % b < 0 {\n a % b + b\n } else {\n a % b\n }\n };\n \n let inv = |x| {\n modulo(extended_euclid(x, N).1, N)\n };\n\n let fact: Vec = (0..5001).scan(1, |state, x| {\n if x != 0 {\n *state = x * *state % N;\n }\n Some(*state)\n }).collect();\n\n let bc = |k, n| {\n fact[n as usize] * inv(fact[(n - k) as usize]) % N * inv(fact[k as usize]) % N\n };\n\n let np = |k, n| {\n fact[n as usize] * inv(fact[(n - k) as usize]) % N\n };\n\n let foo = |a, b| {\n (0..a + 1).map(|i| bc(i, a) * np(i, b) % N).fold(0, |acc, x| (acc + x) % N)\n };\n\n let ans = foo(a, b) * foo(a, c) % N * foo(b, c) % N;\n println!(\"{}\", ans);\n}\n", "src_uid": "b6dc5533fbf285d5ef4cf60ef6300383"} {"source_code": "use std::io::Read;\n\nfn input(read_file: bool) -> String {\n if read_file {\n let mut file = std::fs::File::open(\"sample.txt\").unwrap();\n let mut buf = String::new();\n file.read_to_string(&mut buf).unwrap();\n buf\n } else {\n let mut buf = String::new();\n std::io::stdin().read_to_string(&mut buf).unwrap();\n buf.trim_end().to_owned()\n }\n}\n\nfn solve(ws: &mut std::str::SplitWhitespace) {\n let r: f64 = ws.next().unwrap().parse().unwrap();\n let x: f64 = ws.next().unwrap().parse().unwrap();\n let y: f64 = ws.next().unwrap().parse().unwrap();\n let xd: f64 = ws.next().unwrap().parse().unwrap();\n let yd: f64 = ws.next().unwrap().parse().unwrap();\n\n let dist = ((xd - x).powi(2) + (yd - y).powi(2)).sqrt();\n let r2 = 2.0 * r;\n\n println!(\"{}\", (dist / r2).ceil() as u32);\n}\n\nfn main() {\n const READ_FROM_FILE: bool = false;\n\n let s = input(READ_FROM_FILE);\n let mut ws = s.split_whitespace();\n\n solve(&mut ws);\n}\n", "src_uid": "698da80c7d24252b57cca4e4f0ca7031"} {"source_code": "//#[derive(Debug)]\nuse std::io::stdin;\n//use std::char::from_digit;\n//use std::collections::HashMap;\n\n#[derive(Default)]\nstruct Scanner {\n buffer: Vec\n}\nimpl Scanner {\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\n\n\nfn main() {\n //let mut ans= Vec::new();\n let mut scan = Scanner::default();\n //let mut mas = Vec::new();\n let mut ans:i32 = 1;\n\n let mut n= scan.next::();\n //let dig: Vec = (1..9).map(|_| scan.next()).collect();\n while n>=10\n {\n ans+=10-n%10;\n n/=10;n+=1;\n while n%10==0 {n/=10;}\n }\n\n println!(\"{}\",ans+8);\n}\n", "src_uid": "055fbbde4b9ffd4473e6e716da6da899"} {"source_code": "#![allow(unused_imports)]\n#![allow(non_snake_case)]\nuse std::cmp::*;\nuse std::collections::*;\nuse std::io::Write;\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($e:expr),*) => {\n #[cfg(debug_assertions)]\n $({\n let (e, mut err) = (stringify!($e), std::io::stderr());\n writeln!(err, \"{} = {:?}\", e, $e).unwrap()\n })*\n };\n}\n\nfn count(s: &Vec) -> i64 {\n let n = s.len();\n let mut lb_count = vec![0; n];\n lb_count[0] = if s[0] == '(' { 1 } else { 0 };\n for i in 1..n {\n lb_count[i] = lb_count[i - 1];\n if s[i] == '(' {\n lb_count[i] += 1;\n }\n }\n let lb_count = lb_count;\n let mut rb_count = vec![0; n];\n rb_count[0] = if s[0] == ')' { 1 } else { 0 };\n for i in 1..n {\n rb_count[i] = rb_count[i - 1];\n if s[i] == ')' {\n rb_count[i] += 1;\n }\n }\n\n // scan\n let mut min_depth = n as i64;\n let mut cur_depth = 0;\n for i in 0..n {\n if s[i] == '(' {\n cur_depth += 1;\n } else {\n cur_depth -= 1;\n }\n if cur_depth < min_depth {\n min_depth = cur_depth;\n }\n }\n\n let mut ans = 0;\n let mut cur_depth = 0;\n for i in 0..n {\n if s[i] == '(' {\n cur_depth += 1;\n } else {\n cur_depth -= 1;\n }\n if cur_depth == min_depth {\n ans += 1;\n }\n }\n ans\n}\n\nfn main() {\n let n = read::();\n let s = read::().chars().collect::>();\n\n let mut lb_count = vec![0; n];\n lb_count[0] = if s[0] == '(' { 1 } else { 0 };\n for i in 1..n {\n lb_count[i] = lb_count[i - 1];\n if s[i] == '(' {\n lb_count[i] += 1;\n }\n }\n let lb_count = lb_count;\n let mut rb_count = vec![0; n];\n rb_count[0] = if s[0] == ')' { 1 } else { 0 };\n for i in 1..n {\n rb_count[i] = rb_count[i - 1];\n if s[i] == ')' {\n rb_count[i] += 1;\n }\n }\n if lb_count[n - 1] != rb_count[n - 1] {\n println!(\"0\");\n println!(\"1 1\");\n return;\n }\n\n let mut ans = count(&s);\n let mut ans_pair = (1, 1);\n for i in 0..n {\n for j in i + 1..n {\n let mut s_clone = s.clone();\n let temp = s_clone[i];\n s_clone[i] = s_clone[j];\n s_clone[j] = temp;\n let temp = count(&s_clone);\n if temp > ans {\n ans = temp;\n ans_pair = (i + 1, j + 1);\n }\n }\n }\n println!(\"{}\", ans);\n println!(\"{0} {1}\", ans_pair.0, ans_pair.1);\n}\n\nfn read() -> T {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).ok();\n s.trim().parse().ok().unwrap()\n}\n\nfn read_vec() -> Vec {\n read::()\n .split_whitespace()\n .map(|e| e.parse().ok().unwrap())\n .collect()\n}\n", "src_uid": "2d10668fcc2d8e90e102b043f5e0578d"} {"source_code": "use std::io;\n\nfn main() \n{\n let mut n =String::new();\n let mut opt = String::new();\n io::stdin().read_line(&mut n);\n io::stdin().read_line(&mut opt);\n\n let n:usize = n.trim().parse().expect(\"\");\n let mut ans = 0;\n for i in 0..n\n {\n if opt.chars().nth(i) == Some('-')\n {\n ans-=1;\n if ans<0\n {\n ans=0;\n }\n }\n else\n {\n ans+=1;\n }\n }\n\n println!(\"{}\", ans);\n}\n", "src_uid": "a593016e4992f695be7c7cd3c920d1ed"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n\ntype GenError = Box;\ntype GenResult = Result;\n\nstruct Reader {\n\n}\n\nimpl Reader{\n #[allow(unused)]\n fn read_string() -> GenResult {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string)?;\n Ok(string.trim().to_string())\n }\n\n #[allow(unused)]\n fn read_tokens() -> GenResult> {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string)?;\n let mut v = Vec::new();\n for value in string.split_whitespace() {\n v.push(value.to_string());\n }\n Ok(v)\n }\n}\n\nfn main() {\n\n let tokens = Reader::read_tokens().unwrap();\n let n: i32 = tokens[0].parse().unwrap();\n let m: i32 = tokens[1].parse().unwrap();\n let k: i32 = tokens[2].parse().unwrap();\n\n let mut ans = 1000000;\n let mut index = 1;\n for value in Reader::read_tokens().unwrap() {\n let value : i32 = value.parse().unwrap();\n if value > 0 && value <= k {\n if 10 * (index - m).abs() < ans {\n ans = 10 * (index - m).abs();\n }\n }\n index += 1;\n }\n println!(\"{}\", ans);\n}", "src_uid": "57860e9a5342a29257ce506063d37624"} {"source_code": "use std::io::{self, Read};\nuse std::cmp;\n \nfn main() {\n let mut buffer = String::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n handle.read_to_string(&mut buffer).unwrap();\n\n let arr : Vec<_> = buffer.split_whitespace().collect();\n\n let n = arr[0].parse::().unwrap();\n let m = arr[1].parse::().unwrap();\n \n let mut orig = vec![ vec![0; m]; n ];\n \n for (k1,i) in arr[2..].iter().enumerate() {\n for (k2,j) in i.chars().enumerate() {\n if j == '#' {\n orig[k1][k2] = 1;\n }\n }\n }\n\n let mut v = vec![ vec![0; m]; n ];\n for i in 1..n-1 {\n for j in 1..m-1 {\n let neighbours = [ (-1,0), (0,-1), (1,0), (0,1), (-1,-1), (1,-1), (-1,1), (1,1) ];\n let mut count = 0;\n for (x,y) in neighbours.iter() {\n let (x2,y2) = ((i as isize+x) as usize ,(j as isize +y) as usize);\n if orig[x2][y2] == 1 {\n count += 1;\n }\n }\n if count == 8 {\n for (x,y) in neighbours.iter() {\n let (x2,y2) = ((i as isize+x) as usize ,(j as isize +y) as usize);\n v[x2][y2] = 1;\n }\n }\n }\n }\n\n // println!(\"{:?}\",v);\n \n let mut feasible = true;\n 'outer: for i in 0..n {\n for j in 0..m {\n if v[i][j] != orig[i][j] {\n feasible = false;\n break 'outer;\n }\n }\n }\n\n if feasible {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "49e5eabe8d69b3d27a251cccc001ab25"} {"source_code": "use std::io;\n\nfn solve() -> Vec {\n let mut input = \"\".split_ascii_whitespace();\n let mut read = || loop {\n if let Some(word) = input.next() {\n break word;\n }\n input = {\n let mut input = \"\".to_owned();\n io::stdin().read_line(&mut input).unwrap();\n if input.is_empty() {\n panic!(\"reached EOF\");\n }\n Box::leak(input.into_boxed_str()).split_ascii_whitespace()\n };\n };\n macro_rules! read(($ty:ty) => (read().parse::<$ty>().unwrap()));\n\n let mut rr = vec![\"\".to_string(); 0];\n\n let t = 1;\n for _ in 0..t {\n let n = read!(usize);\n let ca = read!(String).chars().collect::>();\n\n let mut a = vec![' '; n];\n let mut b = vec![' '; n];\n for i in 0..n {\n a[i] = ca[i];\n b[i] = ca[i + n];\n }\n\n a.sort();\n b.sort();\n let mut t = 0;\n for i in 0..n {\n if a[i] < b[i] {\n t |= 1;\n } else if a[i] > b[i] {\n t |= 2;\n } else {\n t |= 4;\n }\n }\n\n if t < 3 {\n rr.push(\"YES\".to_string());\n } else {\n rr.push(\"NO\".to_string());\n }\n }\n\n rr\n}\n\n#[allow(dead_code)]\nfn main() {\n let output = solve();\n println!(\"{}\", output.join(\"\\n\"));\n}\n", "src_uid": "e4419bca9d605dbd63f7884377e28769"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io;\n use std::io::prelude::*;\n io::stdin().read_to_string(&mut input).unwrap();\n\n let n: u64 = input.trim().parse().unwrap();\n\n let ans = n / 2 + 1;\n\n println!(\"{}\", ans)\n}\n", "src_uid": "5551742f6ab39fdac3930d866f439e3e"} {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let reader = io::stdin();\n let numbers: Vec = \n reader.lock() // (0)\n .lines().next().unwrap().unwrap() // (1)\n .split(' ').map(|s| s.trim()) // (2)\n .filter(|s| !s.is_empty()) // (3)\n .map(|s| s.parse().unwrap()) // (4)\n .collect(); // (5)\n \n let l = numbers[0];\n let r = numbers[1];\n \n let mut ans = 0;\n \n let mut num2: i64 = 1;\n for p2 in 0..32 {\n let mut num3: i64 = num2;\n for p3 in 0..20 {\n \tif num3 >= l && num3 <= r {\n \t\tans = ans + 1;\n \t}\n \tnum3 = num3 * 3;\n }\n num2 = num2 * 2;\n }\n\n println!(\"{}\", ans);\n}", "src_uid": "05fac54ed2064b46338bb18f897a4411"} {"source_code": "fn main() {\n let input = input_vec_chars();\n let d: Vec = input\n .into_iter()\n .filter(|c| *c == 'Q' || *c == 'A').collect();\n\n let mut count = 0;\n\n for (i, elm) in d.iter().enumerate() {\n if *elm == 'Q' {\n for j in i+1..d.len() {\n if d[j] == 'A' {\n for k in j+1..d.len() {\n if d[k] == 'Q' {\n count += 1;\n }\n }\n }\n } \n }\n }\n println!(\"{:?}\", count);\n}\n\nfn input_str() -> String {\n let mut buff = String::new();\n std::io::stdin().read_line(&mut buff).expect(\"Err\");\n buff\n}\n\nfn input_u64() -> u64 {\n input_str().trim().parse().unwrap()\n}\n\nfn input_vec(sep: &str) -> Vec \nwhere\n T: std::str::FromStr,\n ::Err: std::fmt::Debug,\n{\n input_str().trim().split(sep).map(|c| c.parse::().expect(\"Err pars\")).collect()\n}\n\nfn input_vec_chars() -> Vec {\n input_str().trim().chars().collect()\n}", "src_uid": "8aef4947322438664bd8610632fe0947"} {"source_code": "use std::io::{self, BufRead};\n\ntype Point = (i32, i32);\ntype Seg = (Point, Point);\n\nfn cm(base: &Point, a: &Point, b: &Point) -> i32 {\n let debug = false;\n if debug { println!(\"base {:?}, a {:?}, b {:?}\", base, a, b) }\n return (a.0 - base.0)*(b.1 - base.1) - (a.1 - base.1)*(b.0 - base.0);\n}\n\nfn inx(a: i32, b: i32, x: i32) -> bool {\n return (b >= a && x >= a && x <= b) || (b <= a && x <= a && x >= b);\n}\n\nfn ins(pa: &Point, pb: &Point, px: &Point) -> bool {\n return inx(pa.0, pb.0, px.0) && inx(pa.1, pb.1, px.1);\n}\n\nfn intersect(a: &Seg, b: &Seg) -> bool {\n let b0 = cm(&a.0, &a.1, &b.0);\n if b0 == 0 && ins(&a.0, &a.1, &b.0) { return true; }\n let b1 = cm(&a.0, &a.1, &b.1);\n if b1 == 0 && ins(&a.0, &a.1, &b.1) { return true; }\n let a0 = cm(&b.0, &b.1, &a.0);\n if a0 == 0 && ins(&b.0, &b.1, &a.0) { return true; }\n let a1 = cm(&b.0, &b.1, &a.1);\n if a1 == 0 && ins(&b.0, &b.1, &a.1) { return true; }\n return ((a0 > 0 && a1 < 0) || (a0 < 0 && a1 > 0))\n && ((b0 > 0 && b1 < 0) || (b0 < 0 && b1 > 0));\n}\n\nfn main() {\n let debug = false;\n let stdin: io::Stdin = io::stdin();\n let mut lines: io::Lines = stdin.lock().lines();\n\n let next_line = lines.next()\n .unwrap() // Option { Some(Result), None }\n .unwrap(); // Result { Ok(String), Err(io::Error) }\n\n let square_a: Vec<_> = next_line\n .trim()\n .split(' ')\n .map(|n| {\n n.parse::().unwrap()\n })\n .collect();\n\n let next_line = lines.next()\n .unwrap() // Option { Some(Result), None }\n .unwrap(); // Result { Ok(String), Err(io::Error) }\n\n let square_b: Vec<_> = next_line\n .trim()\n .split(' ')\n .map(|n| {\n n.parse::().unwrap()\n })\n .collect();\n \n // any a inside b\n if debug { println!(\"\\n\\n a inside b ?? \\n\\n\") }\n for a_i in 0..4 {\n let a = (square_a[2*a_i], square_a[2*a_i+1]);\n let mut left = false;\n let mut right = false;\n if debug { println!(\"POINT a choosen\") }\n for i in 0..4 {\n let base = (square_b[2*i], square_b[2*i+1]);\n let j = (i+1) % 4;\n let b = (square_b[2*j], square_b[2*j+1]);\n if debug { println!(\"-------------------\") }\n let cmv = cm(&base, &b, &a);\n if debug { println!(\"cmv {}\", cmv) }\n if cmv > 0 { left = true; }\n if cmv < 0 { right = true; }\n }\n if !left || !right {\n println!(\"YES\");\n return;\n }\n }\n\n // any b inside a\n if debug { println!(\"\\n\\n b inside a ?? \\n\\n\") }\n for b_i in 0..4 {\n let b = (square_b[2*b_i], square_b[2*b_i+1]);\n let mut left = false;\n let mut right = false;\n if debug { println!(\"POINT b choosen\") }\n for i in 0..4 {\n let base = (square_a[2*i], square_a[2*i+1]);\n let j = (i+1) % 4;\n let a = (square_a[2*j], square_a[2*j+1]);\n if debug { println!(\"-------------------\") }\n let cmv = cm(&base, &a, &b);\n if debug { println!(\"cmv {}\", cmv) }\n if cmv > 0 { left = true; }\n if cmv < 0 { right = true; }\n }\n if !left || !right {\n println!(\"YES\");\n return;\n }\n }\n\n // check intersect\n for a_i in 0..4 {\n let a_a = (square_a[2*a_i], square_a[2*a_i+1]);\n let a_j = (a_i + 1) % 4;\n let a_b = (square_a[2*a_j], square_a[2*a_j+1]);\n let seg_a = (a_a, a_b);\n\n for i in 0..4 {\n let b_a = (square_b[2*i], square_b[2*i+1]);\n let j = (i+1) % 4;\n let b_b = (square_b[2*j], square_b[2*j+1]);\n let seg_b = (b_a, b_b);\n if intersect(&seg_a, &seg_b) {\n println!(\"YES\");\n return;\n }\n }\n }\n\n println!(\"NO\");\n}", "src_uid": "f6a3dd8b3bab58ff66055c61ddfdf06a"} {"source_code": "#[warn(unused_variables)]\n\nfn main() {\n let n = input_::();\n println!(\"{}\", if n % 2 == 0 {2u64.pow(n/2u32)} else {0})\n}\n\nfn input_str() -> String {\n let mut buff = String::new();\n std::io::stdin().read_line(&mut buff).expect(\"Err\");\n buff\n}\n\nfn input_() -> T\nwhere\n T: std::str::FromStr,\n ::Err: std::fmt::Debug,\n{\n input_str().trim().parse::().expect(\"Err pars\")\n}\n\n\nfn input_vec(sep: &str) -> Vec \nwhere\n T: std::str::FromStr,\n ::Err: std::fmt::Debug,\n{\n input_str().trim().split(sep).map(|c| c.parse::().expect(\"Err pars\")).collect()\n}\n\nfn input_vec_chars() -> Vec {\n input_str().trim().chars().collect()\n}", "src_uid": "4b7ff467ed5907e32fd529fb39b708db"} {"source_code": "use std::io::{BufReader, BufWriter, Read, Write, stdin, stdout};\n\npub struct Scanner {\n pub buffer: Vec,\n pub reader: U,\n}\nimpl Scanner {\n pub fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_to_string(&mut input).expect(\"Failed read\");\n self.buffer = input.lines().rev().map(String::from).collect();\n }\n }\n\n pub fn new(reader: U) -> Self {\n return Scanner {\n buffer: vec![],\n reader,\n };\n }\n}\npub fn solution_of_p263a(input: &mut Read, out: &mut Write) {\n let mut scanner = Scanner::new(input);\n let mut mat: Vec> = vec![];\n for _i in 0..5 {\n let arr: Vec = scanner.next::().split(\" \").map(|e| {\n return e.parse::().unwrap();\n }).collect();\n mat.push(arr);\n }\n\n // find the cordinate of the 1 in the matrix\n let mut x = 0;\n let mut y = 0;\n for i in 0..5 {\n let row: &Vec = &mat[i];\n for j in 0..5 {\n let elem = row[j];\n if elem == 1 {\n x = i;\n y = j;\n }\n }\n }\n let mut res = 0;\n if x > 2 {\n res += x - 2;\n } else {\n res += 2-x;\n }\n if y > 2 {\n res += y - 2;\n } else {\n res += 2-y;\n }\n write!(out, \"{}\\n\", res).ok();\n}\n\nfn main() {\n solution_of_p263a(&mut stdin(), &mut stdout());\n}\n", "src_uid": "8ba7cedc3f6ae478a0bb3f902440c8e9"} {"source_code": "use std::{ io::{ self, Read, Write } };\n\nfn solve<'a, I: Iterator>(mut lines: I) -> Option> {\n\tlet count: usize = lines.next()?\n\t\t.parse().ok()?;\n\n\t(0..count).map(|_| {\n\t\tlet mut key: usize = lines.next()?\n\t\t\t.parse().ok()?;\n\t\tlet doors: [_; 3] = lines.next()?\n\t\t\t.split(' ')\n\t\t\t.map(str::parse)\n\t\t\t.collect::, _>>().ok()?\n\t\t\t.try_into().ok()?;\n\n\t\tlet mut opened: usize = 0;\n\n\t\twhile opened < 3 {\n\t\t\tkey = if key > 0 && key <= doors.len() {\n\t\t\t\tdoors[key - 1]\n\t\t\t} else {\n\t\t\t\tbreak;\n\t\t\t};\n\n\t\t\topened += 1;\n\t\t}\n\n\t\tSome(opened == 3)\n\t})\n\t\t.collect()\n}\n\nfn main() -> io::Result<()> {\n\tlet mut stdout = io::BufWriter::new(io::stdout());\n\tlet mut stdin = io::BufReader::new(io::stdin());\n\n\tlet mut input = String::new();\n\tstdin.read_to_string(&mut input)?;\n\tlet lines = input.lines();\n\n\tlet result = solve(lines).unwrap();\n\n\tfor case in result {\n\t\tstdout.write_all(if case { b\"YES\\n\" } else { b\"NO\\n\" })?;\n\t}\n\n\tOk(())\n}\n", "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"source_code": "use std::io::{stdin, stdout, Write, BufReader, BufRead, Read};\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while b != 0 {\n a %= b;\n let c = a;\n a = b;\n b = c;\n }\n return a;\n}\n\nfn solve(input: &mut BufRead, output: &mut Write) {\n let mut input = BufReader::new(input);\n\n let mut first = String::with_capacity(201);\n let mut second = String::with_capacity(201);\n\n input.read_line(&mut first).unwrap();\n input.read_line(&mut second).unwrap();\n\n let s = first.trim().as_bytes();\n let t = second.trim().as_bytes();\n\n let first = s.iter().position(|&it| it == t[0]).unwrap();\n let second = s.iter().rev().position(|&it| it == t[t.len() - 1]).unwrap();\n\n let mut answ = first.max(second);\n\n let mut pos = vec![first; t.len()];\n let mut pos_rev = vec![second; t.len()];\n\n\n let mut prev = first;\n for i in 0..t.len() {\n let mut pos1 = 0;\n for j in prev..s.len() {\n if s[j] == t[i] {\n pos1 = j;\n break;\n }\n }\n prev = pos1;\n pos[i] = prev;\n prev += 1;\n }\n\n let mut rev = s.len() - 1 -second;\n for i in (0..t.len()).rev() {\n let mut pos1 = 0;\n for j in (0..=rev).rev() {\n if s[j] == t[i] {\n pos1 = j;\n break;\n }\n }\n rev = pos1;\n pos_rev[i] = rev;\n if rev > 0 {\n rev -= 1;\n }\n }\n\n for i in 0..t.len() - 1 {\n answ = answ.max(pos_rev[i + 1] - 1 - pos[i])\n }\n\n answ = answ.max(s.len() - pos[pos.len() - 1] - 1);\n answ = answ.max(pos_rev[0]);\n\n writeln!(output, \"{}\", answ).unwrap();\n}\n\nfn main() {\n let stdin = stdin();\n let stdout = stdout();\n solve(&mut stdin.lock(), &mut stdout.lock());\n}\n\n#[cfg(test)]\nmod tests {\n use std::fs::File;\n use solve;\n use std::io::BufReader;\n\n #[test]\n fn basic_test() {\n let mut f = BufReader::new(\"bbaba\nbb\n\".as_bytes());\n let mut buf: Vec = Vec::new();\n\n solve(&mut f, &mut buf);\n\n let res = String::from_utf8(buf).unwrap();\n assert_eq!(res, \"3\\n\");\n }\n\n #[test]\n fn basic_test2() {\n let mut f = BufReader::new(\"baaba\nab\n\".as_bytes());\n let mut buf: Vec = Vec::new();\n\n solve(&mut f, &mut buf);\n\n let res = String::from_utf8(buf).unwrap();\n assert_eq!(res, \"2\\n\");\n }\n\n #[test]\n fn basic_test3() {\n let mut f = BufReader::new(\"abcde\nabcde\n\".as_bytes());\n let mut buf: Vec = Vec::new();\n\n solve(&mut f, &mut buf);\n\n let res = String::from_utf8(buf).unwrap();\n assert_eq!(res, \"0\\n\");\n }\n\n #[test]\n fn basic_test4() {\n let mut f = BufReader::new(\"asdfasdf\nfasd\n\".as_bytes());\n let mut buf: Vec = Vec::new();\n\n solve(&mut f, &mut buf);\n\n let res = String::from_utf8(buf).unwrap();\n assert_eq!(res, \"3\\n\");\n }\n}", "src_uid": "0fd33e1bdfd6c91feb3bf00a2461603f"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n: i64 = input.p();\n let mut a = 1;\n let mut b = 2;\n let mut sol = 0;\n while b <= n {\n let c = a + b;\n a = b;\n b = c;\n sol += 1;\n }\n println!(\"{}\", sol);\n}\n\n", "src_uid": "3d3432b4f7c6a3b901161fa24b415b14"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n\n pub fn tokens(&mut self) -> Vec {\n assert!(self.buffer.is_empty());\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n input\n .split_whitespace()\n .map(|x| x.parse().ok().expect(\"Failed parse\"))\n .collect()\n }\n}\n\nconst INF: i32 = 1000000000;\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: usize = scan.token();\n let jump_length: usize = scan.token();\n let s: Vec = scan.token::().chars().collect();\n let mut dp = vec![INF; n];\n dp[0] = 0;\n for i in 1..n {\n if s[i] == '1' {\n for j in 1..=jump_length {\n if i >= j {\n dp[i] = dp[i].min(dp[i - j] + 1);\n }\n }\n }\n }\n let ans = if dp[n - 1] >= INF { - 1 } else { dp[n - 1] };\n writeln!(out, \"{}\", ans).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "c08d2ecdfc66cd07fbbd461b1f069c9e"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nfn get_nums() -> (i32, i32, i32, i32, i32, i32, i32, i32) {\n\tlet mut input = String::new();\n\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"\");\n\n\tlet v = input.trim()\n\t\t\t.split_whitespace()\n\t\t\t.map(|d| i32::from_str(d).unwrap())\n\t\t\t.collect::>();\n\n\t(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7])\n}\n\nfn main() {\n\tlet (n, k, l, c, d, p, nl, np) = get_nums();\n\n\tprintln!(\"{}\", min((k*l)/nl, c*d, p/np)/n);\n\n\tfn min(x: i32, y: i32, z: i32) -> i32 {\n\t\tif x < y {\n\t\t\tif x < z {\n\t\t\t\tx\n\t\t\t} else {\n\t\t\t\tz\n\t\t\t}\n\t\t} else if y < z {\n\t\t\ty\n\t\t} else {\n\t\t\tz\n\t\t}\n\t}\t\t\t\t\t\t\t\t\t\n}", "src_uid": "67410b7d36b9d2e6a97ca5c7cff317c1"} {"source_code": "use std::collections::{HashMap, HashSet};\nuse std::cmp::max;\n\nfn read_string() -> String {\n let mut string: String = String::new();\n\n std::io::stdin().read_line(&mut string)\n .ok()\n .expect(\"Error read line!\");\n return string;\n}\n\nfn koutsu_count(koutsu : &HashMap<&str, usize> ) -> usize\n{\n koutsu.values().max().unwrap().to_owned()\n}\n\nfn shuntsu_count(shuntsu : &HashMap<&str, HashSet> ) -> usize\n{\n shuntsu.values().map(|x| suit_set_count(&x))\n .max().to_owned().unwrap()\n\n}\n\nfn suit_set_count(set : &HashSet) -> usize\n{\n if set.len() <= 1 { return set.len() }\n\n let mut list :Vec<_> = set.iter().collect();\n list.sort();\n let mut currrent_count = 1;\n let mut max_count = 1;\n let mut prev = list[0];\n for item in list\n {\n match item - prev\n {\n i if i > 2 =>\n {\n max_count = max(currrent_count, max_count);\n currrent_count = 1;\n }\n 1 =>\n {\n currrent_count += 1;\n max_count = max(currrent_count, max_count);\n }\n 2 =>\n {\n max_count = max(2, max_count);\n currrent_count = 1;\n }\n _ => { }\n\n }\n prev = item;\n }\n max_count\n}\n\nfn main() {\n\n let line : String= read_string().trim().into();\n let mut koutsu : HashMap<&str, usize> = HashMap::new();\n let mut shuntsu : HashMap<&str, HashSet> = HashMap::new();\n for elem in line.split(\" \")\n {\n koutsu.entry(elem).and_modify(|e| *e+=1).or_insert(1);\n let value = &elem[0..1].parse().unwrap();\n let suit = &elem[1..2];\n shuntsu.entry(suit).or_default().insert(*value);\n\n }\n println!(\"{}\", 3 - max(koutsu_count(&koutsu) ,shuntsu_count(&shuntsu)))\n\n}\n", "src_uid": "7e42cebc670e76ace967e01021f752d3"} {"source_code": "use std::io;\n\nfn read_line() -> io::Result {\n let mut input_str = String::new();\n\n try!(io::stdin().read_line(&mut input_str));\n\n Ok(input_str)\n}\n\nfn a_to_b(a: u32, b: u32) -> Vec {\n let mut result = Vec::new();\n let mut current_state = b;\n\n loop {\n match current_state {\n x if (x < a) || (x > a && x % 2 != 0 && x % 10 != 1) => {\n result.clear();\n break;\n }\n x => {\n result.push(x); \n match x {\n x if x == a => break, \n x if x % 2 == 0 => current_state /= 2,\n _ => current_state /= 10, \n }\n } \n }\n }\n\n result.reverse();\n result\n}\n\nfn main() { \n let input_line = read_line().expect(\"Failed to read line.\");\n let mut input_line_iter = input_line.split_whitespace();\n\n let given_number = input_line_iter.next()\n .expect(\"First number is not given.\")\n .parse::()\n .expect(\"First number is invalid.\");\n let result_number = input_line_iter.next()\n .expect(\"Second number is not given.\")\n .parse::()\n .expect(\"Second number is invalid\");\n\n let answer_sequence = a_to_b(given_number, result_number);\n\n match answer_sequence.len() {\n 0 => println!(\"NO\"),\n len => {\n println!(\"YES\\n{}\", len);\n for number in answer_sequence {\n print!(\"{} \", number);\n }\n } \n }\n}\n", "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"source_code": "#![allow(unused_imports, unused_macros)]\n\nuse kyoproio::*;\nuse std::{\n collections::*,\n io::{self, prelude::*},\n iter,\n mem::{replace, swap},\n};\n\nfn main() -> io::Result<()> {\n std::thread::Builder::new()\n .stack_size(64 * 1024 * 1024)\n .spawn(|| {\n let stdin = io::stdin();\n let stdout = io::stdout();\n run(KInput::new(stdin.lock()), io::BufWriter::new(stdout.lock()))\n })?\n .join()\n .unwrap();\n Ok(())\n}\n\nfn run(mut kin: I, mut out: O) {\n macro_rules! output { ($($args:expr),+) => { write!(&mut out, $($args),+).unwrap(); }; }\n macro_rules! outputln {\n ($($args:expr),+) => { output!($($args),+); outputln!(); };\n () => { output!(\"\\n\"); if cfg!(debug_assertions) { out.flush().unwrap(); } }\n }\n\n let k: i64 = kin.input();\n let mut a = vec![1; 10];\n for i in 0.. {\n let p: i64 = a.iter().product();\n if p >= k {\n break;\n }\n a[i % 10] += 1;\n }\n let s = b\"codeforces\";\n for i in 0..10 {\n for _ in 0..a[i] {\n output!(\"{}\", s[i] as char);\n }\n }\n outputln!();\n}\n\n// -----------------------------------------------------------------------------\npub mod kyoproio {\n use std::io::prelude::*;\n pub trait Input {\n fn str(&mut self) -> &str;\n fn input(&mut self) -> T {\n T::input(self)\n }\n fn iter(&mut self) -> Iter {\n Iter(self, std::marker::PhantomData)\n }\n fn seq>(&mut self, n: usize) -> B {\n self.iter().take(n).collect()\n }\n }\n pub struct KInput {\n src: R,\n buf: String,\n pos: usize,\n }\n impl KInput {\n pub fn new(src: R) -> Self {\n Self {\n src,\n buf: String::with_capacity(1024),\n pos: 0,\n }\n }\n pub fn src(&mut self) -> &mut R {\n &mut self.src\n }\n }\n impl Input for KInput {\n fn str(&mut self) -> &str {\n loop {\n if self.pos >= self.buf.len() {\n self.pos = 0;\n self.buf.clear();\n if self.src.read_line(&mut self.buf).expect(\"io error\") == 0 {\n return &self.buf;\n }\n }\n let range = self.pos\n ..self.buf[self.pos..]\n .find(|c: char| c.is_ascii_whitespace())\n .map(|i| i + self.pos)\n .unwrap_or_else(|| self.buf.len());\n self.pos = range.end + 1;\n if range.end > range.start {\n return &self.buf[range];\n }\n }\n }\n }\n pub struct Iter<'a, T, I: ?Sized>(&'a mut I, std::marker::PhantomData<*const T>);\n impl<'a, T: InputParse, I: Input + ?Sized> Iterator for Iter<'a, T, I> {\n type Item = T;\n fn next(&mut self) -> Option {\n Some(self.0.input())\n }\n }\n pub trait InputParse: Sized {\n fn input(src: &mut I) -> Self;\n }\n impl InputParse for Vec {\n fn input(src: &mut I) -> Self {\n src.str().as_bytes().to_owned()\n }\n }\n macro_rules! from_str_impl {\n { $($T:ty)* } => {\n $(impl InputParse for $T {\n fn input(src: &mut I) -> Self {\n src.str().parse::<$T>().expect(\"parse error\")\n }\n })*\n }\n }\n from_str_impl! {\n String char bool f32 f64 isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128\n }\n macro_rules! tuple_impl {\n ($H:ident $($T:ident)*) => {\n impl<$H: InputParse, $($T: InputParse),*> InputParse for ($H, $($T),*) {\n fn input(src: &mut I) -> Self {\n ($H::input(src), $($T::input(src)),*)\n }\n }\n tuple_impl!($($T)*);\n };\n () => {}\n }\n tuple_impl!(A B C D E F G);\n #[macro_export]\n macro_rules! kdbg {\n ($($v:expr),*) => {\n if cfg!(debug_assertions) { dbg!($($v),*) } else { ($($v),*) }\n }\n }\n}\n", "src_uid": "8001a7570766cadcc538217e941b3031"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next_line(&self) -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n line\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let line = self.next_line();\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nstatic BIG: i64 = 1e9 as i64 + 7;\nfn _main() {\n let mut scan = Scan::new();\n let mut x: i64 = scan.next();\n let mut y: i64 = scan.next();\n let mut n: i64 = scan.next();\n let mut i = 2i64;\n n = n % 6;\n // I think it would be better to precompute an\n // array with the 6 different possible values\n while i < n + 6 {\n let tmp = y;\n y = (y - x + BIG) % BIG;\n x = tmp;\n i += 1;\n }\n println!(\"{}\", (y + BIG) % BIG);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "2ff85140e3f19c90e587ce459d64338b"} {"source_code": "#[doc = \" https://github.com/hatoo/competitive-rust-snippets\"]\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::io::{stdin, stdout, BufWriter, Write};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) ; } }\n#[macro_export]\nmacro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut parser = Parser :: from_str ( $ s ) ; input_inner ! { parser , $ ( $ r ) * } } ; ( parser = $ parser : ident , $ ( $ r : tt ) * ) => { input_inner ! { $ parser , $ ( $ r ) * } } ; ( new_stdin_parser = $ parser : ident , $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let reader = std :: io :: BufReader :: new ( stdin . lock ( ) ) ; let mut $ parser = Parser :: new ( reader ) ; input_inner ! { $ parser , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { input ! { new_stdin_parser = parser , $ ( $ r ) * } } ; }\n#[macro_export]\nmacro_rules ! input_inner { ( $ parser : ident ) => { } ; ( $ parser : ident , ) => { } ; ( $ parser : ident , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ parser , $ t ) ; input_inner ! { $ parser $ ( $ r ) * } } ; }\n#[macro_export]\nmacro_rules ! read_value { ( $ parser : ident , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ parser , $ t ) ) ,* ) } ; ( $ parser : ident , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ parser , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ parser : ident , chars ) => { read_value ! ( $ parser , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ parser : ident , usize1 ) => { read_value ! ( $ parser , usize ) - 1 } ; ( $ parser : ident , $ t : ty ) => { $ parser . next ::<$ t > ( ) . expect ( \"Parse error\" ) } ; }\nuse std::io;\nuse std::io::BufRead;\nuse std::str;\npub struct Parser {\n reader: R,\n buf: Vec,\n pos: usize,\n}\nimpl Parser {\n pub fn from_str(s: &str) -> Parser {\n Parser {\n reader: io::empty(),\n buf: s.as_bytes().to_vec(),\n pos: 0,\n }\n }\n}\nimpl Parser {\n pub fn new(reader: R) -> Parser {\n Parser {\n reader: reader,\n buf: vec![],\n pos: 0,\n }\n }\n pub fn update_buf(&mut self) {\n self.buf.clear();\n self.pos = 0;\n loop {\n let (len, complete) = {\n let buf2 = self.reader.fill_buf().unwrap();\n self.buf.extend_from_slice(buf2);\n let len = buf2.len();\n if len == 0 {\n break;\n }\n (len, buf2[len - 1] <= 0x20)\n };\n self.reader.consume(len);\n if complete {\n break;\n }\n }\n }\n pub fn next(&mut self) -> Result {\n loop {\n let mut begin = self.pos;\n while begin < self.buf.len() && (self.buf[begin] <= 0x20) {\n begin += 1;\n }\n let mut end = begin;\n while end < self.buf.len() && (self.buf[end] > 0x20) {\n end += 1;\n }\n if begin != self.buf.len() {\n self.pos = end;\n return str::from_utf8(&self.buf[begin..end]).unwrap().parse::();\n } else {\n self.update_buf();\n }\n }\n }\n}\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) ; } }\n#[doc = \" https://github.com/hatoo/competitive-rust-snippets\"]\nconst BIG_STACK_SIZE: bool = true;\n#[allow(dead_code)]\nfn main() {\n use std::thread;\n if BIG_STACK_SIZE {\n thread::Builder::new()\n .stack_size(32 * 1024 * 1024)\n .name(\"solve\".into())\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n } else {\n solve();\n }\n}\nfn solve() {\n input!{\n w0: (i64,i64,i64,i64),\n b0: (i64,i64,i64,i64),\n b1: (i64,i64,i64,i64),\n }\n\n let mut xs = vec![];\n xs.push(w0.0);\n xs.push(w0.2);\n xs.push(b0.0);\n xs.push(b0.2);\n xs.push(b1.0);\n xs.push(b1.2);\n xs.sort();\n let mut x_compress = HashMap::new();\n let mut x_decompress = HashMap::new();\n let mut cur_x=0;\n for x in xs {\n if !x_compress.contains_key(&x) {\n x_compress.entry(x).or_insert(cur_x);\n x_decompress.entry(cur_x).or_insert(x);\n cur_x+=1;\n }\n }\n\n let mut ys = vec![];\n ys.push(w0.1);\n ys.push(w0.3);\n ys.push(b0.1);\n ys.push(b0.3);\n ys.push(b1.1);\n ys.push(b1.3);\n ys.sort();\n let mut y_compress = HashMap::new();\n let mut y_decompress = HashMap::new();\n let mut cur_y=0;\n for y in ys {\n if !y_compress.contains_key(&y) {\n y_compress.entry(y).or_insert(cur_y);\n y_decompress.entry(cur_y).or_insert(y);\n cur_y+=1;\n }\n }\n\n let mut table = vec![vec![false; cur_y-1]; cur_x-1];\n let x_comp = |x: i64| {\n x_compress.get(&x).unwrap().clone() as usize\n };\n let y_comp = |y: i64| {\n y_compress.get(&y).unwrap().clone() as usize\n };\n for x in x_comp(b0.0)..x_comp(b0.2) {\n for y in y_comp(b0.1)..y_comp(b0.3) {\n table[x][y]=true;\n }\n }\n for x in x_comp(b1.0)..x_comp(b1.2) {\n for y in y_comp(b1.1)..y_comp(b1.3) {\n table[x][y]=true;\n }\n }\n let mut ok = false;\n for x in x_comp(w0.0)..x_comp(w0.2) {\n for y in y_comp(w0.1)..y_comp(w0.3) {\n if !table[x][y] {\n ok=true;\n break;\n }\n }\n }\n\n if ok {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}", "src_uid": "05c90c1d75d76a522241af6bb6af7781"} {"source_code": "use std::io::{self, Stdin};\nuse std::str::{self, FromStr};\nuse std::error::Error;\nuse std::thread;\n\nfn exec() {\n let mut sc = Scanner::new();\n let s: Vec = sc.ne::().into_bytes();\n let mut ok = true;\n let mut next = b'a';\n for &c in &s {\n if c == next {\n next += 1;\n } else if c > next {\n ok = false;\n }\n }\n println!(\"{}\", if ok { \"YES\" } else { \"NO\" });\n}\n\nfn main() {\n const DEFAULT_STACK: usize = 16 * 1024 * 1024;\n let builder = thread::Builder::new();\n let th = builder.stack_size(DEFAULT_STACK);\n let handle = th.spawn(|| { exec(); }).unwrap();\n let _ = handle.join();\n}\n\n#[allow(dead_code)]\nstruct Scanner {\n stdin: Stdin,\n id: usize,\n buf: Vec,\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new() -> Scanner {\n Scanner {\n stdin: io::stdin(),\n id: 0,\n buf: Vec::new(),\n }\n }\n fn next_line(&mut self) -> Option {\n let mut res = String::new();\n match self.stdin.read_line(&mut res) {\n Ok(0) => return None,\n Ok(_) => Some(res),\n Err(why) => panic!(\"error in read_line: {}\", why.description()),\n }\n }\n fn next(&mut self) -> Option {\n while self.buf.len() == 0 {\n self.buf = match self.next_line() {\n Some(r) => {\n self.id = 0;\n r.trim().as_bytes().to_owned()\n }\n None => return None,\n };\n }\n let l = self.id;\n assert!(self.buf[l] != b' ');\n let n = self.buf.len();\n let mut r = l;\n while r < n && self.buf[r] != b' ' {\n r += 1;\n }\n let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::() {\n Ok(s) => Some(s),\n Err(_) => panic!(\"parse error\"),\n };\n while r < n && self.buf[r] == b' ' {\n r += 1;\n }\n if r == n {\n self.buf.clear();\n } else {\n self.id = r;\n }\n res\n }\n fn ne(&mut self) -> T {\n self.next::().unwrap()\n }\n}\n", "src_uid": "c4551f66a781b174f95865fa254ca972"} {"source_code": "use std::{str::FromStr, fmt::Debug};\r\nfn read_line() -> String {\r\n let mut line = String::new();\r\n std::io::stdin().read_line(&mut line).expect(\"\");\r\n return line;\r\n}\r\nfn read() -> T where ::Err: Debug{\r\n return read_line().trim().parse::().unwrap();\r\n}\r\nfn reads() -> Vec where ::Err: Debug{\r\n return read_line().trim().split(' ').map(|x| x.parse::().unwrap()).collect();\r\n}\r\nfn main() {\r\n let modint = 998244353;\r\n let nm = reads::();\r\n let n = nm[0];\r\n let m = nm[1];\r\n let mut a = Vec::::new();\r\n a.resize(n as usize + 1, 0);\r\n let mut is_prime = Vec::::new();\r\n is_prime.resize(n as usize + 1, true);\r\n a[1] = m;\r\n let mut lcm = 1;\r\n let mut x = 0;\r\n let mut y = 0;\r\n let mut p = 1;\r\n for i in 2..n + 1 {\r\n if is_prime[i as usize] {\r\n let mut j = i + i;\r\n while j <= n {\r\n is_prime[j as usize] = false;\r\n j += i;\r\n }\r\n }\r\n }\r\n for i in 1..n + 1 {\r\n p = m % modint * p % modint; \r\n x = (x + p) % modint;\r\n if is_prime[i as usize] {\r\n lcm = std::cmp::min(lcm * i, m + 1);\r\n }\r\n a[i as usize] = m / lcm;\r\n }\r\n for i in (1..n + 1).rev() {\r\n y = a[i as usize] % modint * (y + 1) % modint;\r\n }\r\n println!(\"{}\", (x + modint - y) % modint);\r\n}", "src_uid": "0fdd91ed33431848614075ebe9d2ee68"} {"source_code": "use std::{cell::{Cell, RefCell, UnsafeCell}, cmp::{Ordering, Reverse, max, min}, collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque, hash_map::{DefaultHasher, RandomState}}, error::Error, fmt::{Display, Write as FmtWrite}, hash::{BuildHasher, Hash, Hasher}, io::{BufWriter, Read, Stdin, Stdout, Write}, iter::{FromIterator, Peekable}, mem::swap, ops::{Not, Sub}, process::exit, rc::Rc, str::{FromStr, from_utf8, from_utf8_unchecked}, time::{Duration, Instant}};\n\nconst IO_BUF_SIZE: usize = 1 << 16;\ntype Input = Scanner;\ntype Output = BufWriter;\nfn _init_input() -> Input { Scanner::new(std::io::stdin()) }\nfn _init_output() -> Output { BufWriter::with_capacity(IO_BUF_SIZE, std::io::stdout()) }\n\n#[repr(transparent)] struct Unsync(T);\nunsafe impl Sync for Unsync {}\n \ntype BadLazy = Unsync>>;\nimpl BadLazy {\n const fn new() -> Self { Self(UnsafeCell::new(None)) }\n}\n \nstatic INPUT: BadLazy = BadLazy::new();\nstatic OUTPUT: BadLazy = BadLazy::new();\n \nfn inp R, R>(f: F) -> R {\n unsafe { f((&mut *INPUT.0.get()).get_or_insert_with(_init_input)) }\n}\nfn out R, R>(f: F) -> R {\n unsafe { f((&mut *OUTPUT.0.get()).get_or_insert_with(_init_output)) }\n}\n\nmacro_rules! read {\n () => { read(); };\n ($t: ty) => { read::<$t>(); };\n ($t: ty, $($tt: ty),*) => { (read::<$t>(), $(read::<$tt>(),)*) };\n [$t: ty; $n: expr] => { read_vec::<$t>($n); };\n}\nmacro_rules! println { \n () => { out(|x| { writeln!(x).ok() }); };\n ($exp: expr) => { out(|x| { writeln!(x, \"{}\", $exp).ok(); }); }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { writeln!(x, $fmt, $($arg)*).ok(); }); }\n}\nmacro_rules! print { \n ($exp: expr) => { out(|x| { write!(x, \"{}\", $exp).ok(); }); }; \n ($fmt: expr, $($arg : tt )*) => { out(|x| { write!(x, $fmt, $($arg)*).ok(); }); }\n}\n\nfn out_flush() { out(|x| x.flush().ok()); }\n\nfn input_is_eof() -> bool { inp(|x| x.eof()) }\nfn read_byte() -> u8 { inp(|x| x.byte()) }\nfn read_bytes_no_skip(n: usize) -> Vec { inp(|x| x.bytes_no_skip(n)) }\nfn read_bytes(n: usize) -> Vec { inp(|x| x.bytes(n)) }\nfn read_bytes2(n: usize, m: usize) -> Vec> { inp(|x| x.bytes2(n, m)) }\nfn read_token() -> Vec { inp(|x| x.token_bytes()) }\nfn read_token_str() -> String { unsafe { String::from_utf8_unchecked(read_token()) } }\nfn read_line() -> Vec { inp(|x| x.line_bytes()) }\nfn read_line_str() -> String { unsafe { String::from_utf8_unchecked(read_line()) } }\nfn read() -> T { read_token_str().parse::().ok().expect(\"failed parse\") }\nfn read_vec(n: usize) -> Vec { (0..n).map(|_| read()).collect() }\nfn read_vec2(n: usize, m: usize) -> Vec> { (0..n).map(|_| read_vec(m)).collect() }\n\nstruct Scanner {\n src: R,\n _buf: Vec,\n _pt: usize, // pointer\n _rd: usize, // bytes read\n}\n\n#[allow(dead_code)]\nimpl Scanner {\n fn new(src: R) -> Scanner {\n Scanner { src, _buf: vec![0; IO_BUF_SIZE], _pt: 1, _rd: 1 }\n }\n \n fn _check_buf(&mut self) {\n if self._pt == self._rd {\n self._rd = self.src.read(&mut self._buf).unwrap_or(0);\n self._pt = (self._rd == 0) as usize;\n }\n }\n \n // returns true if end of file\n fn eof(&mut self) -> bool {\n self._check_buf();\n self._rd == 0\n }\n \n // filters \\r, returns \\0 if eof\n fn byte(&mut self) -> u8 {\n loop {\n self._check_buf();\n if self._rd == 0 { return 0; }\n let res = self._buf[self._pt];\n self._pt += 1;\n if res != b'\\r' { return res; }\n }\n }\n\n fn bytes_no_skip(&mut self, n: usize) -> Vec { (0..n).map(|_| self.byte()).collect() }\n fn bytes(&mut self, n: usize) -> Vec {\n let res = self.bytes_no_skip(n);\n self.byte();\n res\n }\n fn bytes2(&mut self, n: usize, m: usize) -> Vec> { (0..n).map(|_| self.bytes(m)).collect() }\n \n fn token_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c <= b' ' {\n if c == b'\\0' { return res; }\n c = self.byte();\n }\n loop {\n res.push(c);\n c = self.byte();\n if c <= b' ' { return res; }\n }\n }\n \n fn line_bytes(&mut self) -> Vec {\n let mut res = Vec::new();\n let mut c = self.byte();\n while c != b'\\n' && c != b'\\0' {\n res.push(c);\n c = self.byte();\n }\n res\n }\n}\n\ntrait JoinToStr { \n fn join_to_str(self, sep: &str) -> String;\n fn concat_to_str(self) -> String;\n}\nimpl> JoinToStr for I { \n fn join_to_str(mut self, sep: &str) -> String {\n let mut res = String::new();\n if let Some(first) = self.next() {\n res.push_str(&first.to_string());\n while let Some(item) = self.next() {\n res.push_str(sep);\n res.push_str(&item.to_string())\n }\n }\n res\n }\n \n fn concat_to_str(self) -> String {\n let mut res = String::new();\n for item in self { res.push_str(&item.to_string()); }\n res\n }\n}\n\nmacro_rules! veci {\n ($n:expr , $i:ident : $gen:expr) => {{\n let n = $n;\n let mut list = Vec::with_capacity(n);\n for $i in 0..n {\n list.push($gen);\n }\n list\n }};\n ($n:expr , $gen:expr) => { veci!($n, __: $gen); }\n}\n\nfn abs_diff + PartialOrd>(x: T, y: T) -> T {\n if x < y { y - x } else { x - y }\n}\n\ntrait CommonNumExt {\n fn div_ceil(self, b: Self) -> Self;\n fn div_floor(self, b: Self) -> Self;\n fn gcd(self, b: Self) -> Self;\n fn highest_one(self) -> Self;\n fn lowest_one(self) -> Self;\n}\n\nmacro_rules! impl_common_num_ext {\n ($($ix:tt = $ux:tt),*) => {\n $(\n impl CommonNumExt for $ux {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { self / b }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }\n b\n }\n #[inline] fn highest_one(self) -> Self { \n if self == 0 { 0 } else { const ONE: $ux = 1; ONE.rotate_right(1) >> self.leading_zeros() } \n }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n }\n\n impl CommonNumExt for $ix {\n fn div_ceil(self, b: Self) -> Self {\n let q = self / b; let r = self % b;\n if self ^ b >= 0 && r != 0 { q + 1 } else { q }\n }\n fn div_floor(self, b: Self) -> Self { \n let q = self / b; let r = self % b;\n if self ^ b < 0 && r != 0 { q - 1 } else { q }\n }\n fn gcd(self, mut b: Self) -> Self {\n let mut a = self; while a != 0 { swap(&mut a, &mut b); a %= b; }\n b.abs()\n }\n #[inline] fn highest_one(self) -> Self { (self as $ux).highest_one() as _ }\n #[inline] fn lowest_one(self) -> Self { self & self.wrapping_neg() }\n }\n )*\n }\n}\nimpl_common_num_ext!(i8 = u8, i16 = u16, i32 = u32, i64 = u64, i128 = u128, isize = usize);\n\ntrait ChMaxMin {\n fn set_max(&mut self, v: T) -> bool;\n fn set_min(&mut self, v: T) -> bool;\n}\nimpl ChMaxMin for T {\n fn set_max(&mut self, v: T) -> bool { if v > *self { *self = v; true } else { false } }\n fn set_min(&mut self, v: T) -> bool { if v < *self { *self = v; true } else { false } }\n}\n\n// * end commons * //\n\n#[macro_use]\n#[allow(dead_code)]\nmod modint {\n use std::{fmt::{Display, Formatter}, marker::PhantomData, mem::swap, ops::*, str::FromStr, cell::Cell};\n use crate::ModInt;\n \n pub trait RemEuclidU32: Copy {\n /// Calculates `self` _mod_ `modulus` losslessly.\n fn rem_euclid_u32(self, modulus: u32) -> u32;\n }\n \n macro_rules! impl_rem_euclid_u32_for_small_signed {\n ($($ty:tt),*) => {\n $(\n impl RemEuclidU32 for $ty {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n (self as i64).rem_euclid(i64::from(modulus)) as _\n }\n }\n )*\n }\n }\n \n impl_rem_euclid_u32_for_small_signed!(i8, i16, i32, i64, isize);\n \n impl RemEuclidU32 for i128 {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n self.rem_euclid(i128::from(modulus)) as _\n }\n }\n \n macro_rules! impl_rem_euclid_u32_for_small_unsigned {\n ($($ty:tt),*) => {\n $(\n impl RemEuclidU32 for $ty {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n self as u32 % modulus\n }\n }\n )*\n }\n }\n \n macro_rules! impl_rem_euclid_u32_for_large_unsigned {\n ($($ty:tt),*) => {\n $(\n impl RemEuclidU32 for $ty {\n #[inline]\n fn rem_euclid_u32(self, modulus: u32) -> u32 {\n (self % (modulus as $ty)) as _\n }\n }\n )*\n }\n }\n \n impl_rem_euclid_u32_for_small_unsigned!(u8, u16, u32);\n impl_rem_euclid_u32_for_large_unsigned!(u64, u128);\n \n #[cfg(target_pointer_width = \"32\")]\n impl_rem_euclid_u32_for_small_unsigned!(usize);\n \n #[cfg(target_pointer_width = \"64\")]\n impl_rem_euclid_u32_for_large_unsigned!(usize);\n #[inline]\n pub fn mul_mod_u32(a: u32, b: u32, m: u32) -> u32 {\n (a as u64 * b as u64 % m as u64) as u32\n }\n \n // for a, b < m, unspecified otherwise\n #[inline]\n fn add_mod_raw(a: u32, b: u32, m: u32) -> u32 {\n let (r, c) = a.wrapping_sub(m).overflowing_add(b);\n if c { r } else { r.wrapping_add(m) }\n }\n #[inline]\n fn sub_mod_raw(a: u32, b: u32, m: u32) -> u32 {\n let (r, c) = a.overflowing_sub(b);\n if c { r.wrapping_add(m) } else { r }\n }\n fn pow_mod_raw(a: u32, mut k: u64, m: u32) -> u32 {\n if m == 1 { return 0; }\n let mut a = a as u64;\n let m = m as u64;\n let mut r: u64 = 1;\n while k > 0 {\n if k & 1 == 1 {\n r = r * a % m;\n }\n k >>= 1;\n a = a * a % m;\n }\n return r as u32;\n }\n \n /// # Parameters\n /// * `b` `1 <= b`\n /// # Returns\n /// (x, g) s.t. g = gcd(a, b), xa = g (mod b), 0 <= x < b/g\n fn inv_gcd(a: i64, b: i64) -> (i64, i64) {\n let a = a.rem_euclid(b);\n if a == 0 { return (0, b); }\n let mut s = b;\n let mut t = a;\n let mut m0 = 0;\n let mut m1 = 1;\n \n while t != 0 {\n let u = s / t;\n s -= t * u;\n m0 -= m1 * u;\n swap(&mut s, &mut t);\n swap(&mut m0, &mut m1);\n }\n \n if m0 < 0 { m0 += b / s; }\n (m0, s)\n }\n \n pub trait Modulus: Copy + Eq {\n fn get_modulus() -> u32;\n }\n \n #[derive(Clone, Copy, PartialEq, Eq, Hash)]\n #[repr(transparent)]\n pub struct ModIntBase { \n val: u32,\n _phantom: PhantomData\n }\n \n impl ModIntBase {\n #[inline(always)]\n pub fn modulus() -> u32 { M::get_modulus() }\n #[inline] pub fn new(val: I) -> Self { Self::raw(val.rem_euclid_u32(Self::modulus())) }\n #[inline] pub fn raw(val: u32) -> Self { Self { val, _phantom: PhantomData } }\n pub fn inv(self) -> Self { \n let (x, gcd) = inv_gcd(self.val.into(), Self::modulus().into());\n debug_assert!(gcd == 1, \"the multiplicative inverse {}^-1 mod {} does not exist\", self.val, Self::modulus());\n Self::raw(x as u32)\n }\n #[inline] pub fn val(self) -> u32 { self.val }\n #[inline] pub fn pow(self, k: u64) -> Self {\n Self::raw(pow_mod_raw(self.val, k, Self::modulus()))\n }\n pub fn powi(self, k: i64) -> Self { if k < 0 { self.inv().pow(-k as _) } else { self.pow(k as _) } }\n pub fn pow_vec(self, n: usize) -> Vec {\n let mut res = vec![Self::raw(0); n+1];\n res[0] += 1;\n for i in 1..=n {\n res[i] = res[i-1] * self;\n }\n res\n }\n }\n \n #[inline]\n pub fn mi(val: I) -> ModInt { ModIntBase::new(val) }\n #[inline] pub fn mir(v: u32) -> ModInt { ModIntBase::raw(v) }\n \n impl From for ModIntBase {\n #[inline]\n fn from(from: V) -> Self { Self::new(from) }\n }\n impl Default for ModIntBase {\n fn default() -> Self { Self::raw(0) }\n }\n impl FromStr for ModIntBase {\n type Err = std::convert::Infallible;\n #[inline]\n fn from_str(s: &str) -> Result {\n Ok(s.parse::()\n .map(Self::new)\n .unwrap_or_else(|_| todo!(\"parsing as an arbitrary precision integer?\")))\n }\n }\n impl Display for ModIntBase {\n #[inline]\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n self.val.fmt(f)\n }\n }\n impl std::fmt::Debug for ModIntBase {\n #[inline]\n fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {\n std::fmt::Debug::fmt(&self.val, f)\n }\n }\n impl Neg for ModIntBase {\n type Output = Self;\n \n #[inline]\n fn neg(self) -> Self::Output {\n Self::raw(0) - self\n }\n }\n \n impl>, M: Modulus> Add for ModIntBase {\n type Output = Self;\n #[inline]\n fn add(self, rhs: V) -> Self::Output {\n Self::raw(add_mod_raw(self.val, rhs.into().val, Self::modulus()))\n }\n }\n impl>, M: Modulus> Sub for ModIntBase {\n type Output = Self;\n #[inline]\n fn sub(self, rhs: V) -> Self::Output {\n Self::raw(sub_mod_raw(self.val, rhs.into().val, Self::modulus()))\n }\n }\n impl>, M: Modulus> Mul for ModIntBase {\n type Output = Self;\n #[inline]\n fn mul(self, rhs: V) -> Self::Output {\n Self::raw(mul_mod_u32(self.val, rhs.into().val, Self::modulus()))\n }\n }\n impl>, M: Modulus> Div for ModIntBase {\n type Output = Self;\n #[inline]\n fn div(self, rhs: V) -> Self::Output { self * rhs.into().inv() }\n }\n \n impl >, M: Modulus> AddAssign for ModIntBase {\n #[inline]\n fn add_assign(&mut self, rhs: V) { *self = *self + rhs; }\n }\n impl >, M: Modulus> SubAssign for ModIntBase {\n #[inline]\n fn sub_assign(&mut self, rhs: V) { *self = *self - rhs; }\n }\n impl >, M: Modulus> MulAssign for ModIntBase {\n #[inline]\n fn mul_assign(&mut self, rhs: V) { *self = *self * rhs; }\n }\n impl >, M: Modulus> DivAssign for ModIntBase {\n #[inline]\n fn div_assign(&mut self, rhs: V) { *self = *self / rhs; }\n }\n \n impl std::iter::Sum for ModIntBase {\n #[inline] fn sum>(iter: I) -> Self {\n iter.fold(Self::raw(0), Add::add)\n }\n }\n impl std::iter::Product for ModIntBase {\n #[inline] fn product>(iter: I) -> Self {\n iter.fold(1.into(), Mul::mul)\n }\n }\n impl<'a, M: Modulus> std::iter::Sum<&'a Self> for ModIntBase {\n #[inline] fn sum>(iter: I) -> ModIntBase {\n iter.fold(Self::raw(0), |a, &b| a + b)\n }\n }\n impl<'a, M: Modulus> std::iter::Product<&'a Self> for ModIntBase {\n #[inline] fn product>(iter: I) -> ModIntBase {\n iter.fold(1.into(), |a, &b| a * b)\n }\n }\n \n macro_rules! const_modulus {\n ($mint: ident, $name: ident, $modulus: expr) => {\n #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\n pub enum $name {}\n impl Modulus for $name {\n #[inline(always)] fn get_modulus() -> u32 { $modulus }\n }\n pub type $mint = ModIntBase<$name>;\n }\n }\n \n macro_rules! dynamic_modulus {\n ($mint: ident, $name: ident, $modulus: ident) => {\n static $modulus: crate::Unsync> = crate::Unsync(Cell::new(0));\n #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]\n pub enum $name {}\n impl Modulus for $name {\n fn get_modulus() -> u32 { $modulus.0.get() }\n }\n impl $name {\n pub fn set_modulus(val: u32) { $modulus.0.set(val) }\n }\n pub type $mint = ModIntBase<$name>;\n }\n }\n \n const_modulus!(ModInt998_244_353, Mod998_244_353, 998_244_353);\n const_modulus!(ModInt1_000_000_007, Mod1_000_000_007, 1_000_000_007);\n dynamic_modulus!(DynamicModInt, DynamicModulus, DYNAMIC_MODULUS);\n}\n \nuse crate::modint::*;\n// type ModInt = ModInt998_244_353;\n// type ModInt = ModInt1_000_000_007;\n// const_modulus!(ModInt, DefaultModulus, 1_000_000_009);\ntype ModInt = DynamicModInt;\n\n#[allow(non_snake_case, unused_macros)]\nfn main() {\n let num_cases: usize = 1;//read();\n \n for _case_num in 1..=num_cases {\n let n = read!(usize);\n DynamicModulus::set_modulus(read());\n \n let mut dp = vec![mir(0); n+1];\n dp[1] = mir(1);\n dp[2] = mir(2);\n for i in 2..n {\n let d = dp[i];\n dp[i+1] += d + d + mir(1);\n let d = d - dp[i-1];\n for j in (i*2..=n).step_by(i) {\n dp[j] += d;\n }\n }\n \n let ans = dp[n];\n println!(ans);\n }\n \n out_flush();\n}", "src_uid": "77443424be253352aaf2b6c89bdd4671"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let a: usize = scan.next();\n let b: usize = scan.next();\n if a == b {\n println!(\"0 6 0\");\n } else if a < b {\n let middle = a.max(b) - a.min(b) - 1;\n println!(\n \"{} {} {}\",\n a + middle / 2,\n middle % 2,\n 6 - b + 1 + middle / 2\n );\n } else {\n let middle = a.max(b) - a.min(b) - 1;\n println!(\n \"{} {} {}\",\n 6 - a + 1 + middle / 2,\n middle % 2,\n b + middle / 2\n );\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "504b8aae3a3abedf873a3b8b127c5dd8"} {"source_code": "use std::io;\nuse std::io::Read;\n\nfn main() {\n let mut buffer = String::new();\n io::stdin().read_to_string(&mut buffer).unwrap();\n let mut cin = buffer.split_whitespace().map(|x| x.parse::().unwrap());\n let n = cin.next().unwrap() as usize;\n let mut a = cin.enumerate().collect::>();\n a.sort_by_key(|x| x.1);\n for i in 0..n / 2 {\n println!(\"{} {}\", a[i].0 + 1, a[n - i - 1].0 + 1);\n }\n}\n", "src_uid": "6e5011801ceff9d76e33e0908b695132"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io;\n use std::io::prelude::*;\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let n: u32 = it.next().unwrap().parse().unwrap();\n let a: u32 = it.next().unwrap().parse().unwrap();\n let b: u32 = it.next().unwrap().parse().unwrap();\n\n let oa = a - 1;\n let ob = b - 1;\n\n let logn = 31 - n.leading_zeros();\n\n let mut flag = n >> 1;\n let mut i = 0;\n\n let xor = oa ^ ob;\n\n while flag & xor == 0 {\n i += 1;\n flag >>= 1;\n }\n\n if flag == n >> 1 {\n println!(\"Final!\");\n } else {\n println!(\"{}\", logn - i)\n }\n}\n", "src_uid": "a753bfa7bde157e108f34a28240f441f"} {"source_code": "use std::io::{self, Write};\nuse std::{fmt, ops, str};\n\nmacro_rules! read {\n ( $t:ty ) => {{\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input.trim_end().parse::<$t>().ok().unwrap()\n }};\n ( $( $t:ty ),* ) => {{\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n let mut iter = input.split_whitespace();\n ( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )\n }};\n}\n\nstruct Ios(Vec);\n\nimpl str::FromStr for Ios {\n type Err = ();\n\n fn from_str(s: &str) -> Result {\n Ok(Ios(s.chars().collect()))\n }\n}\n\nimpl fmt::Display for Ios {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n write!(f, \"{}\", self.0.iter().collect::())\n }\n}\n\n#[derive(Clone)]\nstruct Iov(Vec);\n\nimpl str::FromStr for Iov {\n type Err = T::Err;\n\n fn from_str(s: &str) -> Result {\n let iter = s.split_whitespace();\n Ok(Iov(iter.map(|x| x.parse()).collect::>()?))\n }\n}\n\nimpl fmt::Display for Iov {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n write!(f, \"{}\",\n self.0.iter().map(|x| x.to_string())\n .collect::>().join(\" \")\n )\n }\n}\n\nimpl ops::Index for Iov {\n type Output = T;\n\n fn index(&self, i: usize) -> &Self::Output {\n self.0.get(i - 1).unwrap()\n }\n}\n\nimpl ops::IndexMut for Iov {\n fn index_mut(&mut self, i: usize) -> &mut Self::Output {\n self.0.get_mut(i - 1).unwrap()\n }\n}\n\nconst MOD: i64 = 1_000_000_007;\n\nfn solve(writer: &mut io::BufWriter) {\n let (n, x, pos) = read!(i64, i64, i64);\n\n let mut ans = 1;\n let mut small = x - 1;\n let mut large = n - x;\n\n let mut left = 0;\n let mut right = n;\n while left < right {\n let middle = (left + right) / 2;\n if middle <= pos {\n left = middle + 1;\n } else {\n right = middle;\n }\n\n if middle < pos {\n ans = ans * small % MOD;\n small = small.saturating_sub(1);\n }\n if pos < middle {\n ans = ans * large % MOD;\n large = large.saturating_sub(1);\n }\n }\n\n let k = small + large;\n ans = ans * (1..=k).fold(1, |acc, x| acc * x % MOD) % MOD;\n writeln!(writer, \"{}\", ans).ok();\n}\n\nfn main() {\n let stdout = io::stdout();\n let mut writer = io::BufWriter::new(stdout.lock());\n solve(&mut writer);\n}\n", "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io::{self, prelude::*};\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n let r0 = it.next().unwrap();\n let n = r0.len();\n let r1 = it.next().unwrap();\n\n #[derive(Clone, Copy, Debug)]\n enum Cell {\n Empty,\n Pawn,\n }\n\n let mut grid: Vec<_> = r0.chars().chain(r1.chars()).map(|c| {\n match c {\n '0' => Cell::Empty,\n 'X' => Cell::Pawn,\n _ => panic!(\"Oops!\"),\n }\n }).collect();\n\n let f = |c| {\n match c {\n Cell::Empty => 1,\n Cell::Pawn => 0,\n }\n };\n\n let cnt = |c, grid: &[Cell]| {\n f(grid[c]) + f(grid[n + c])\n };\n\n let mut ans = 0;\n for c in 0..n {\n if cnt(c, &grid) == 2 {\n if c > 0 && cnt(c - 1, &grid) == 1 {\n grid[c] = Cell::Pawn;\n grid[n + c] = Cell::Pawn;\n ans += 1;\n } else if c + 1 < n {\n if let Cell::Empty = grid[c + 1] {\n grid[c + 1] = Cell::Pawn;\n grid[c] = Cell::Pawn;\n grid[n + c] = Cell::Pawn;\n ans += 1;\n } else if let Cell::Empty = grid[n + c + 1] {\n grid[n + c + 1] = Cell::Pawn;\n grid[c] = Cell::Pawn;\n grid[n + c] = Cell::Pawn;\n ans += 1;\n }\n }\n }\n }\n\n println!(\"{}\", ans);\n}\n", "src_uid": "e6b3e787919e96fc893a034eae233fc6"} {"source_code": "use std::cmp::*;\nuse std::collections::*;\nuse std::io::*;\nuse std::str::*;\n\n// scanner from https://codeforces.com/contest/1396/submission/91365784\nstruct Scanner {\n stdin: Stdin,\n buffer: VecDeque,\n}\n#[allow(dead_code)]\nimpl Scanner {\n fn new() -> Self {\n Scanner {\n stdin: stdin(),\n buffer: VecDeque::new(),\n }\n }\n fn cin(&mut self) -> T {\n while self.buffer.is_empty() {\n let mut line = String::new();\n let _ = self.stdin.read_line(&mut line);\n for w in line.split_whitespace() {\n self.buffer.push_back(String::from(w));\n }\n }\n self.buffer.pop_front().unwrap().parse::().ok().unwrap()\n }\n fn chars(&mut self) -> Vec {\n self.cin::().chars().collect()\n }\n fn vec(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.cin()).collect()\n }\n fn u(&mut self) -> usize {\n self.cin()\n }\n fn ll(&mut self) -> i64 {\n self.cin()\n }\n fn ull(&mut self) -> u64 {\n self.cin()\n }\n fn vecu(&mut self, n: usize) -> Vec {\n self.vec(n)\n }\n fn vecll(&mut self, n: usize) -> Vec {\n self.vec(n)\n }\n}\n\n#[derive(Clone, Debug, Default)]\nstruct Solver {}\n\n//\n// DSU\n//\n\n#[derive(Debug, Clone)]\nstruct DSU {\n v: Vec,\n n: usize,\n}\n\nimpl DSU {\n fn new(size: usize) -> DSU {\n let mut v = vec![0; size];\n for i in 0..size {\n v[i] = i;\n }\n DSU { v: v, n: size }\n }\n\n fn find(&mut self, x: usize) -> usize {\n if self.v[x] == x {\n x\n } else {\n self.v[x] = self.find(self.v[x]);\n self.v[x]\n }\n }\n\n fn is_same(&mut self, x: usize, y: usize) -> bool {\n self.find(x) == self.find(y)\n }\n\n fn unify(&mut self, x: usize, y: usize) {\n let xx = self.find(x);\n let yy = self.find(y);\n if xx != yy {\n self.v[yy] = xx;\n }\n }\n}\n\n//\n// Segment Tree\n//\n\n#[derive(Clone)]\nstruct SegmentTree {\n v: Vec,\n offset: usize,\n comb: fn(T, T) -> T,\n unit: T,\n}\n\n#[allow(dead_code)]\nimpl SegmentTree {\n fn new(n: usize, unit: T, comb: fn(T, T) -> T, vv: Option<&Vec>) -> SegmentTree {\n let mut x = 1;\n while x < n {\n x *= 2;\n }\n\n let mut v = vec![unit; x * 2];\n if let Some(vv) = vv {\n for i in 0..n {\n v[x + i] = (*vv)[i];\n }\n for i in (0..x).rev() {\n v[i] = comb(v[i * 2], v[i * 2 + 1]);\n }\n }\n\n SegmentTree {\n v: v,\n offset: x,\n comb,\n unit: unit,\n }\n }\n\n fn update(&mut self, pos: usize, val: T) {\n let mut p = self.offset + pos;\n self.v[p] = val;\n while p != 1 {\n p /= 2;\n self.v[p] = (self.comb)(self.v[p * 2], self.v[p * 2 + 1]);\n }\n }\n\n fn get(&self, pos: usize) -> T {\n self.v[self.offset + pos]\n }\n\n fn query_range_all(&self) -> T {\n self.query_range(0, self.offset)\n }\n\n fn query_range(&self, begin: usize, end: usize) -> T {\n self.query_range_sub(begin, end, 1, 0, self.offset)\n }\n\n // v[node] \u306f \u533a\u9593 l .. r-1 \u306e\u8a08\u7b97\u7d50\u679c\u3092\u6301\u3063\u3066\u3044\u308b\n fn query_range_sub(&self, begin: usize, end: usize, node: usize, l: usize, r: usize) -> T {\n if end <= l || r <= begin {\n return self.unit.clone();\n } else if begin <= l && r <= end {\n return self.v[node].clone();\n } else {\n let lval = self.query_range_sub(begin, end, node * 2, l, (l + r) / 2);\n let rval = self.query_range_sub(begin, end, node * 2 + 1, (l + r) / 2, r);\n return (self.comb)(lval, rval);\n }\n }\n}\n\nimpl Solver {\n fn solve(&mut self, scan: &mut Scanner, out: &mut BufWriter) {\n //1416d\n\n let n = scan.u();\n let m = scan.u();\n let q = scan.u();\n let p = scan.vecu(n);\n\n let mut edges = Vec::with_capacity(m);\n for _ in 0..m {\n let x = scan.u() - 1;\n let y = scan.u() - 1;\n edges.push((x, y));\n }\n\n let mut vq = Vec::with_capacity(q);\n let mut vq1 = Vec::with_capacity(q); // vertex : \u305d\u306e\u30b0\u30eb\u30fc\u30d7\u5185\u306e\u6700\u5927\u306ep\u30920\u306b\u3059\u308b\n let mut vq2 = Vec::with_capacity(q); // edge : (edge_id, Some(r_vertex_id)) \u3053\u306e\u30af\u30a8\u30ea\u3092\u51e6\u7406\u3059\u308b\u3068\u304d\u306b e_vertex_id \u4ee5\u964d\u3092\u5207\u308a\u96e2\u3059\n\n let mut eid_to_q2id = vec![q; m];\n for _ in 0..q {\n let x = scan.u();\n let y = scan.u();\n vq.push(x);\n\n if x == 1 {\n vq1.push(y - 1);\n } else {\n eid_to_q2id[y - 1] = vq2.len();\n vq2.push((y - 1, None));\n }\n }\n\n /*\n \u30a8\u30c3\u30b8\u524a\u9664\u306e\u30af\u30a8\u30ea\u3092\u9006\u9806\u306b\u3057\u3066\u3001\u3053\u306e\u30af\u30a8\u30ea\u306f\u3069\u306e\u30b0\u30eb\u30fc\u30d7\u3068\u3069\u306e\u30b0\u30eb\u30fc\u30d7\u3092\u304f\u3063\u3064\u3051\u308b\u304b\u3001\u3092DSU\u3092\u4f7f\u3063\u3066\u8abf\u3079\u308b\u3002\n x-y\u306b\u30a8\u30c3\u30b8\u3092\u8ffd\u52a0 = (x\u306eroot)\u306e\u5b50\u3068\u3057\u3066(y\u306eroot)\u3092\u8ffd\u52a0\n x-y\u306e\u30a8\u30c3\u30b8\u3092\u524a\u9664 = (x\u306eroot)\u304b\u3089(y\u306eroot)\u3092\u5207\u308a\u96e2\u3059\n\n */\n let mut eidq2id: Vec<(usize, usize)> = eid_to_q2id.into_iter().enumerate().collect(); // (edge_id, query2_id)\n eidq2id.sort_by_key(|x| q - x.1);\n\n let mut dsu = DSU::new(n);\n let mut child = vec![Vec::new(); n];\n for (edge_id, q2id) in eidq2id {\n let e = edges[edge_id];\n if !dsu.is_same(e.0, e.1) {\n let e0 = dsu.find(e.0);\n let e1 = dsu.find(e.1);\n dsu.unify(e0, e1);\n\n child[e0].push(e1);\n if q2id != q {\n vq2[q2id].1 = Some(e1);\n }\n }\n }\n /*\n \u9802\u70b9\u306e\u9806\u756a\u3092\u4e26\u3073\u66ff\u3048\u308b\u3002\n \u5404root\u304b\u3089dfs\u3067\u901a\u3063\u305f\u9806\u306b\u3059\u308b\u3002\n (x\u306eroot)\u304b\u3089(y\u306eroot)\u3092\u5207\u308a\u96e2\u3059 \u306f\u3001 (y\u306eroot)\u306e\u624b\u524d\u3067\u5206\u5272\u3059\u308b \u3068\u540c\u3058\u306b\u306a\u308b\n */\n let mut pos_to_vid = Vec::with_capacity(n);\n fn dfs(vid: usize, pos_to_vid: &mut Vec, child: &Vec>) {\n pos_to_vid.push(vid);\n for &child_vid in &child[vid] {\n dfs(child_vid, pos_to_vid, child);\n }\n }\n\n let mut partitions = BTreeSet::new();\n partitions.insert(0);\n for i in 0..n {\n if i == dsu.find(i) {\n dfs(i, &mut pos_to_vid, &child);\n }\n partitions.insert(pos_to_vid.len());\n }\n\n //\n let mut vid_to_pos = vec![0; n];\n let mut v = vec![(0, 0); n];\n for pos in 0..n {\n let vid = pos_to_vid[pos];\n v[pos] = (p[vid], vid);\n vid_to_pos[vid] = pos;\n }\n let mut s = SegmentTree::new(n, (0usize, 0usize), |l, r| max(l, r), Some(&v));\n\n vq1.reverse();\n vq2.reverse();\n for i in 0..q {\n // for pos in 0..n {\n // if partitions.contains(&pos) {\n // print!(\"|\");\n // }\n // let (val, vid) = s.v[s.offset + pos];\n // print!(\"({} {}) \", val, vid + 1);\n // }\n // println!(\"\");\n\n if vq[i] == 1 {\n let vid = vq1.pop().unwrap();\n let pos = vid_to_pos[vid];\n let lpos = partitions.range(..=pos).next_back().unwrap();\n let rpos = partitions.range(pos + 1..).next().unwrap();\n let (val2, vid2) = s.query_range(*lpos, *rpos);\n //println!(\"range pos{} -> {}..{} val,vid={},{}\", pos, *lpos, *rpos, val2, vid2 );\n writeln!(out, \"{}\", val2).ok();\n s.update(vid_to_pos[vid2], (0, vid2));\n } else {\n if let Some((_, Some(vid))) = vq2.pop() {\n partitions.insert(vid_to_pos[vid]);\n }\n }\n }\n }\n}\n\nfn solve() {\n let mut scan = Scanner::new();\n let out = &mut BufWriter::new(stdout());\n\n let testcase = 1;\n //let testcase: usize = scan.cin();\n for _ in 0..testcase {\n let mut s: Solver = Default::default();\n s.solve(&mut scan, out);\n }\n}\n\nfn main() {\n let th = std::thread::Builder::new().stack_size(64 * 1024 * 1024);\n th.spawn(|| solve()).unwrap().join().unwrap()\n}\n", "src_uid": "ad014bde729222db14f38caa521e4167"} {"source_code": "use std::io;\n\n\nfn read_line() -> String {\n let mut input_line = String::new();\n io::stdin().read_line(&mut input_line).unwrap();\n return String::from(input_line.trim());\n}\n\nfn read_line_vec() -> Vec {\n return read_line().split(' ')\n .map(|s| s.parse().unwrap())\n .collect();\n}\n\nfn main() {\n read_line();\n let xs = read_line_vec();\n let s: i64 = xs.iter().sum();\n\n if s == 0 {\n println!(\"EASY\");\n } else {\n println!(\"HARD\");\n }\n\n}", "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"source_code": "use std::io::{self, BufRead, BufReader};\nuse std::error::Error;\nuse std::str::from_utf8_unchecked as utf8;\n\ntype Result = std::result::Result>;\n\n\n#[inline]\nunsafe fn read() -> Result<(usize, Vec)> {\n let _stdin = io::stdin();\n let mut stdin = BufReader::new(_stdin.lock());\n let mut bytes = Vec::with_capacity(100_000);\n\n stdin.read_until(b'\\n', &mut bytes)?;\n let n = utf8(&bytes).trim_end().parse()?;\n\n bytes.clear();\n stdin.read_until(b'\\n', &mut bytes)?;\n bytes.set_len(n);\n\n Ok((n, bytes))\n}\n\n\npub fn main() {\n let (n, cmds) = match unsafe { read() } {\n Ok(ans) => ans,\n Err(err) => {\n println!(\"ERROR: {}\", err);\n return\n }\n };\n\n let l = cmds.into_iter()\n .filter(|&ch| ch == b'L')\n .count();\n let r = n - l;\n\n let moves = l + r + 1;\n println!(\"{}\", moves)\n}\n", "src_uid": "098ade88ed90664da279fe8a5a54b5ba"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\nfn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(\n &mut std::io::stdin(),\n &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(i64));\n }\n \n let n = get!();\n let k = get!();\n let mut ans = 0;\n if n >= k {\n ans = (k - 1) / 2;\n } else if k <= n + (n - 1) {\n let x = k - n;\n ans = (n - x + 1) / 2;\n }\n \n println!(\"{}\", ans);\n}", "src_uid": "98624ab2fcd2a50a75788a29e04999ad"} {"source_code": "fn main() {\n let mut num = String::new();\n std::io::stdin().read_line(&mut num);\n let num = num.trim();\n\n let n = num.as_bytes().iter().map(|c| c - 48).filter(|&c| c == 7 || c == 4).count();\n let ret = n.to_string().chars().fold(true, |res, c| res && (c == '4' || c == '7'));\n println!(\"{}\", if ret { \"YES\" } else { \"NO\" });\n}\n", "src_uid": "33b73fd9e7f19894ea08e98b790d07f1"} {"source_code": "use std::io::{Read,stdin};\n\nfn main() {\n let mut buf = String::new();\n stdin().read_to_string(&mut buf).unwrap();\n let mut tok = buf.split_whitespace();\n let mut get = || tok.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n () => (get!(i64));\n }\n \n let n = get!(usize);\n let s = get().as_bytes();\n \n let mut i = 0;\n let mut c = 1;\n let mut ans = vec![];\n while i < n {\n ans.push(s[i]);\n i += c;\n c += 1;\n }\n println!(\"{}\", String::from_utf8(ans).unwrap());\n \n }\n ", "src_uid": "08e8c0c37b223f6aae01d5609facdeaf"} {"source_code": "//spnauti-rusT {{{\nuse std::io::*; use std::str::{self,*}; use std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)] macro_rules! min {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b < *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! max {\n\t($x:expr,$y:expr) => {{ let b=$y; let a=&mut$x; if b > *a {*a=b; true} else {false} }};\n}\n#[allow(unused_macros)] macro_rules! l {\n\t($($v:ident),+ =$e:expr) => {$(let$v=$e;)+};\n\t($($v:ident),+:$t:ty=$e:expr) => {$(let$v:$t=$e;)+};\n\t(mut $($v:ident),+ =$e:expr) => {$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr) => {$(let mut$v:$t=$e;)+};\n}\n#[allow(unused_macros)] macro_rules! v {\n\t([$d:expr]$($s:tt)+) => {vec![v!($($s)+);$d]};\n\t([]) => {Vec::new()}; ([$e:expr]) => {Vec::with_capacity($e)}; (=$e:expr) => {$e};\n}\n#[allow(unused_macros)] macro_rules! rep { {[$c:expr]$($s:tt)+} => {for _ in 0..$c {$($s)+}} }\n#[allow(dead_code)] fn reader() -> WordReaderC { WordReaderC::new() }\n#[allow(dead_code)] fn writer() -> BufWriter { BufWriter::new(stdout()) }\nstruct WordReaderC {buf: Vec, pos: usize, q: std::io::StdinLock<'static>}//'\n#[allow(dead_code)] impl WordReaderC {\n\tfn new() -> Self {\n\t\tlet r = unsafe {&*Box::into_raw(Box::new(stdin()))};\n\t\tSelf { q: r.lock(), buf: v!([]), pos: 0 }\n\t}\n\tfn next_line(&mut self) -> bool {\n\t\tself.buf.clear(); self.pos = 0;\n\t\tself.q.read_until(b'\\n', &mut self.buf).unwrap_or(0) > 0\n\t}\n\tfn is_ws(c: u8) -> bool {\n\t\tc == b' ' || c == b'\\r' || c == b'\\n' || c == b'\\t'\n\t}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos == self.buf.len() { if !self.next_line() { return None; } }\n\t\tself.pos += 1; Some(self.buf[self.pos - 1])\n\t}\n\tfn vb(&mut self) -> Vec {\n\t\tlet mut s = v!([8]);\n\t\tlet mut f = false;\n\t\tloop {\n\t\t\tif let Some(c) = self.byte() {\n\t\t\t\tif !Self::is_ws(c) {\n\t\t\t\t\ts.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t} else if f { break; }\n\t\t\t} else { break; }\n\t\t}\n\t\ts\n\t}\n\tfn board(&mut self, r: usize, c: Option) -> Vec> {\n\t\tlet mut res = v!([r]);\n\t\tlet c = c.unwrap_or(0);\n\t\trep!{[r]\n\t\t\tlet t = self.vb();\n\t\t\tassert!(c == 0 || t.len() == c);\n\t\t\tres.push(t);\n\t\t}\n\t\tres\n\t}\n\tfn framed_board(&mut self, r: usize, c: usize, f: u8) -> Vec> {\n\t\tlet mut res = v!([r+2]);\n\t\tres.push( v!([c+2] = f) );\n\t\trep!{[r]\n\t\t\tlet mut t = self.vb();\n\t\t\tassert!(t.len() == c);\n\t\t\tt.reserve(2);\n\t\t\tt.insert(0,f);\n\t\t\tt.push(f);\n\t\t\tres.push(t);\n\t\t}\n\t\tres.push( v!([c+2] = f) );\n\t\tres\n\t}\n\tfn s(&mut self) -> String { String::from_utf8(self.vb()).expect(\"invalid utf8\") }\n\tfn i(&mut self) -> i32 { self.p() }\n\tfn l(&mut self) -> i64 { self.p() }\n\tfn u(&mut self) -> usize { self.p() }\n\tfn f(&mut self) -> f64 { self.p() }\n\tfn vi(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vl(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn vu(&mut self, n: usize) -> Vec { self.vp(n) }\n\tfn ii(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn iu(&mut self, n: usize) -> impl Iterator { self.ip(n).into_iter() }\n\tfn p(&mut self) -> T where T::Err: Debug {\n\t\tlet w = self.vb(); str::from_utf8(w.as_ref()).unwrap().parse::().unwrap()\n\t}\n\tfn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n\t\t(0..n).map(|_|self.p()).collect()\n\t}\n\tfn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n\t\tself.vp(n).into_iter()\n\t}\n\tfn graph(&mut self, n: usize, m: usize) -> Vec> {\n\t\tlet mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); e[a].push(b); e[b].push(a); } e\n\t}\n\tfn graph_w(&mut self, n: usize, m: usize) -> Vec> where T::Err: Debug {\n\t\tlet mut e = v!([n][]); rep!{[m] l!(a,b = self.u()-1); let c: T = self.p(); e[a].push((b,c)); e[b].push((a,c)); } e\n\t}\n}\n//------------------- End rusT }}}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tlet n = rin.u();\n\tlet a = rin.vi(n);\n\tlet mut aa = v!([n]);\n\tfor i in 0..n {\n\t\taa.push( (a[i],i) );\n\t}\n\taa.sort();\n\tlet mut bb = v!([n] = 0);\n\tfor i in 0..n {\n\t\tbb[aa[i].1] = a[aa[(i+1)%n].1];\n\t}\n\tfor i in 0..n {\n\t\twrite!(rout, \"{} \", bb[i]).ok();\n\t}\n}\n", "src_uid": "e314642ca1f82be8f223e2eba00b5531"} {"source_code": "fn main() {\n let mut input = String::new();\n use std::io::{self, prelude::*};\n io::stdin().read_to_string(&mut input).unwrap();\n\n let mut it = input.split_whitespace();\n\n let n: u32 = it.next().unwrap().parse().unwrap();\n let s: u32 = it.next().unwrap().parse().unwrap();\n\n let ans = (s - 1) / n + 1;\n\n println!(\"{}\", ans);\n}\n", "src_uid": "04c067326ec897091c3dbcf4d134df96"} {"source_code": "use std::io::Read;\n\nfn main() {\n let mut input = String::new();\n std::io::stdin().read_to_string(&mut input).expect(\"Err: read line failed\");\n let vec = input.lines().map(|line| {\n line.trim().split_whitespace().map(|word| {\n word.parse::().expect(\"Err: parse to i32 failed\")\n }).collect::>()\n }).collect::>>();\n\n for number in &vec[1] {\n for digit in &vec[2] {\n if digit == number {\n print!(\"{} \", &digit);\n }\n }\n }\n\n println!(\"\");\n}", "src_uid": "f9044a4b4c3a0c2751217d9b31cd0c72"} {"source_code": "use std::io;\n\nfn zeros_fac(n : u32) -> u32 {\n let mut i = 5;\n let mut count = 0;\n while i <= n {\n count += n / i;\n i *= 5;\n }\n count\n}\n\nfn bsearch(mut pi : u32, mut pf : u32, n : u32) -> Option {\n while pf >= pi {\n let pm = (pf + pi) / 2;\n let zeros_pm = zeros_fac(5 * pm);\n if zeros_pm < n {\n pi = pm + 1;\n } else if zeros_pm == n {\n return Some(5 * pm);\n } else {\n pf = pm - 1;\n }\n }\n return None;\n}\n\nfn main() {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let n: u32 = buffer.trim().parse().expect(\"invalid input\");\n\n match bsearch(4 * n / 5, n, n) {\n Some(x) => {\n println!(\"5\");\n println!(\"{} {} {} {} {}\", x, x + 1, x + 2, x + 3, x + 4);\n },\n None => println!(\"0\"),\n };\n}", "src_uid": "c27ecc6e4755b21f95a6b1b657ef0744"} {"source_code": "use std::io;\n\nfn main() {\n let (n, k): (u64, u64) = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n let mut iter = buffer.split_whitespace().map(|x| x.parse().unwrap());\n (iter.next().unwrap(), iter.next().unwrap())\n };\n let d = n/(2*k+2);\n println!(\"{} {} {}\", d, d*k, n-d*(k+1));\n}\n", "src_uid": "405a70c3b3f1561a9546910ab3fb5c80"} {"source_code": "fn main() {\n let (n, l): (usize, i64) = readln();\n let c: Vec = readln();\n\n let mut rest: i64 = l;\n let mut answer = i64::max_value();\n let mut used: i64 = 0;\n while rest > 0 {\n let over_cost = (0..n).filter(|x| rest <= (1i64 << x)).map(|x| c[x]).min();\n if let Some(over_cost) = over_cost {\n answer = min(answer, used + over_cost);\n }\n let last_idx = (0..n).filter(|x| rest >= (1i64 << x)).last().unwrap();\n let cost = (0..last_idx + 1)\n .map(|x| (1i64 << (last_idx - x)) * c[x])\n .min()\n .unwrap();\n let last_pow = (0..36).filter(|x| rest >= (1i64 << x)).last().unwrap();\n used += cost * 1i64 << (last_pow - last_idx);\n rest -= 1i64 << last_pow;\n }\n answer = min(answer, used);\n println!(\"{}\", answer);\n}\n\n// --- template ---\n#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::HashSet;\n\npub trait FromLn {\n fn fromln(s: &str) -> Self;\n}\npub fn readln() -> T {\n let mut buf = String::new();\n let _ = ::std::io::stdin().read_line(&mut buf).unwrap();\n T::fromln(buf.trim())\n}\npub fn readlns(n: usize) -> Vec {\n let mut vs = vec![];\n for _ in 0..n {\n vs.push(readln());\n }\n vs\n}\nmacro_rules! fromln_primitives {\n ($($t:ty),*) => { $(\n impl FromLn for $t {\n fn fromln(s: &str) -> $t {\n s.parse().unwrap()\n }\n }\n )* }\n}\nfromln_primitives!(\n String,\n bool,\n f32,\n f64,\n isize,\n i8,\n i16,\n i32,\n i64,\n usize,\n u8,\n u16,\n u32,\n u64\n);\nimpl FromLn for Vec\nwhere\n T: FromLn,\n{\n fn fromln(s: &str) -> Vec {\n s.split_whitespace().map(T::fromln).collect()\n }\n}\nimpl FromLn for Vec {\n fn fromln(s: &str) -> Vec {\n s.chars().collect()\n }\n}\nmacro_rules! fromln_tuple {\n ($($t:ident),*) => {\n impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {\n fn fromln(s: &str) -> ($($t),*) {\n let mut it = s.split_whitespace();\n let t = ($($t::fromln(it.next().unwrap())),*);\n assert_eq!(it.next(), None);\n t\n }\n }\n }\n}\nfromln_tuple!(A, B);\nfromln_tuple!(A, B, C);\nfromln_tuple!(A, B, C, D);\nfromln_tuple!(A, B, C, D, E);\nfromln_tuple!(A, B, C, D, E, F);\n", "src_uid": "04ca137d0383c03944e3ce1c502c635b"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let sol = input.i().min(input.i()/2).min(input.i()/4) * 7;\n println!(\"{}\", sol);\n}\n\n", "src_uid": "82a4a60eac90765fb62f2a77d2305c01"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nfn enumerate(a: &[u32], m: u32) -> Vec {\n let mut ans = vec![0];\n for &a in a.iter() {\n let mut next = ans.clone();\n for v in ans {\n next.push((v + a) % m);\n }\n ans = next;\n }\n ans.sort();\n ans.dedup();\n ans\n}\n\nfn run() {\n input! {\n n: usize,\n m: u32,\n a: [u32; n],\n }\n let mid = n / 2;\n let (l, r) = a.split_at(mid);\n let l = enumerate(l, m);\n let r = enumerate(r, m);\n let mut ans = (*l.last().unwrap() + *r.last().unwrap()) % m;\n let mut j = 0;\n for l in l.iter().rev() {\n while j + 1 < r.len() && *l + r[j + 1] < m {\n j += 1;\n }\n ans = std::cmp::max(ans, (*l + r[j]) % m);\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "d3a8a3e69a55936ee33aedd66e5b7f4a"} {"source_code": "#[allow(unused_imports)] use std::{*, io::*, };\n#[allow(unused)] 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)*} }; }\n#[allow(unused)] 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)*} }; }\n#[allow(unused)] 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::>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1}; ($next:expr, [ $t:tt ]) => {{ let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect(\"Parse error\")};}\n#[allow(unused)] macro_rules! debug { ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap()); }\n#[allow(unused)] macro_rules! debugln { ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap()); }\n\nfn solve() { \n let out = std::io::stdout(); \n let mut out = BufWriter::new(out.lock());\n #[allow(unused)] macro_rules! puts { ($($format:tt)*) => (let _ = write!(out,$($format)*);); }\n input!{\n a: (i64, i64),\n b: (i64, i64),\n c: (i64, i64),\n }\n puts!(\n \"{}\",\n if (a.0 - b.0).pow(2) + (a.1 - b.1).pow(2) == (b.0 - c.0).pow(2) + (b.1 - c.1).pow(2) \n && (b.0 - a.0) * (c.1 - b.1) != (b.1 - a.1) * (c.0 - b.0) \n {\"Yes\"} else {\"No\"}\n );\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n\n#[allow(dead_code)]\nfn get_word() -> String {\n let stdin = std::io::stdin();\n let mut stdin=stdin.lock();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8", "src_uid": "05ec6ec3e9ffcc0e856dc0d461e6eeab"} {"source_code": "// 992C\nuse std::io;\n\nfn main() {\n let (mut x, k) = read_2::(&io::stdin());\n let modulo = 1000000007;\n if x == 0 {\n println!(\"{}\", x);\n return;\n }\n x = x % modulo;\n let a = (mod_exp(2, k + 1, modulo) * x) % modulo;\n let b = mod_exp(2, k, modulo);\n if a >= b {\n println!(\"{}\", (a - b + 1) % modulo);\n } else {\n println!(\"{}\", ((modulo + a) - b + 1) % modulo);\n }\n}\n\nfn mod_exp(mut a: u64, mut k: u64, n: u64) -> u64 {\n let mut multiplier = 1;\n a = a % n;\n while k != 0 {\n if k % 2 == 1 {\n multiplier = (multiplier * a) % n;\n }\n a = (a * a) % n;\n k = k / 2;\n }\n multiplier\n}\n\nfn read_2(stdin: &io::Stdin) -> (T, T)\nwhere\n T: std::str::FromStr,\n ::Err: std::fmt::Debug,\n{\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let mut iter = s.trim().split_whitespace().map(|x| x.parse().unwrap());\n (iter.next().unwrap(), iter.next().unwrap())\n}\n", "src_uid": "e0e017e8c8872fc1957242ace739464d"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap,HashSet,VecDeque};\n\n#[allow(unused_macros)]\nmacro_rules! readln {\n () => {{\n use std::io;\n \n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! readvec {\n ( $t:ty ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n let mut result = Vec::new();\n for elem in input {\n result.push(elem.parse::<$t>().unwrap());\n }\n result\n }}\n}\n\nfn gcd(a: i64, b: i64) -> i64 {\n if a > b {\n return gcd(b,a);\n }\n if a == 0 {\n return 0;\n } else {\n return (b/a) + gcd(b%a,a);\n }\n}\n\nfn main() {\n let (a,b) = readln!(i64,i64);\n let res = gcd(a,b);\n println!(\"{}\",res);\n}\n", "src_uid": "ce698a0eb3f5b82de58feb177ce43b83"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.u();\n let mut k = input.i();\n let mut a = input.vi(n).into_iter().enumerate().map(|(a,b)| (b,a as i32+1)).collect::>();\n a.sort();\n let mut sol = Vec::new();\n for (x,i) in a {\n if k >= x {\n k -= x;\n sol.push(i);\n } else {\n break;\n }\n }\n println!(\"{}\", sol.len());\n for i in sol {\n print!(\"{} \", i);\n }\n}\n\n", "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let _ = input.i();\n let x = vec![7,5,3,2];\n let mut a = vec![0; 4];\n for c in input.bs() {\n for mut z in 2..(c - b'0' + 1) as i32 {\n for j in 0..4 {\n while z % x[j] == 0 {\n z /= x[j];\n a[j] += 1;\n }\n }\n }\n }\n for i in 0..4 {\n let n = a[i];\n for _ in 0..n { print!(\"{}\", x[i]); }\n for mut z in 2..x[i] + 1 {\n for j in 0..4 {\n while z % x[j] == 0 {\n z /= x[j];\n a[j] -= n;\n }\n }\n }\n }\n}\n\n", "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::Read;\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok().unwrap();\n ret\n}\nfn get_word() -> String {\n let mut stdin = std::io::stdin();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\nconst MOD: i64 = 1_000_000_007;\n\n/// Refers external ::MOD.\n/// Verified by: https://beta.atcoder.jp/contests/arc099/submissions/2893648\nmod mod_int {\n use ::MOD;\n use std::ops::*;\n #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]\n pub struct ModInt { pub x: i64 }\n impl ModInt {\n fn check_integrity(self) {\n debug_assert!(self.x >= 0);\n debug_assert!(self.x < MOD);\n }\n // x >= 0\n pub fn new(x: i64) -> Self { ModInt { x: x % MOD } }\n #[allow(dead_code)]\n pub fn mul_fast(self, other: Self) -> Self {\n self.check_integrity();\n other.check_integrity();\n ModInt { x: self.x * other.x % MOD }\n }\n #[allow(dead_code)]\n pub fn mul_slow(self, other: Self) -> Self {\n // Naive multiplication in order to avoid overflow\n self.check_integrity();\n other.check_integrity();\n let mut sum = ModInt::new(0);\n let mut cur = self;\n let mut e = other.x;\n if self.x < other.x {\n cur = other;\n e = self.x;\n }\n while e > 0 {\n if e % 2 == 1 {\n sum = sum + cur;\n }\n cur = cur + cur;\n e /= 2;\n }\n sum\n }\n pub fn pow(self, mut e: i64) -> Self {\n self.check_integrity();\n debug_assert!(e >= 0);\n let mut sum = ModInt::new(1);\n let mut cur = ModInt::new(self.x);\n while e > 0 {\n if e % 2 != 0 {\n sum = sum * cur;\n }\n cur = cur * cur;\n e /= 2;\n }\n sum\n }\n pub fn inv(self) -> Self { self.pow(MOD - 2) }\n }\n impl Add for ModInt {\n type Output = Self;\n fn add(self, other: Self) -> Self {\n self.check_integrity();\n other.check_integrity();\n let mut sum = self.x + other.x;\n if sum >= MOD { sum -= MOD; }\n ModInt { x: sum }\n }\n }\n impl Sub for ModInt {\n type Output = Self;\n fn sub(self, other: Self) -> Self {\n self.check_integrity();\n other.check_integrity();\n let mut sum = self.x - other.x;\n if sum < 0 { sum += MOD; }\n ModInt { x: sum }\n }\n }\n impl Mul for ModInt {\n type Output = Self;\n fn mul(self, other: Self) -> Self {\n self.mul_fast(other)\n }\n }\n impl ::std::fmt::Display for ModInt {\n fn fmt(&self, f: &mut::std::fmt::Formatter) -> ::std::fmt::Result {\n self.x.fmt(f)\n }\n }\n} // mod mod_int\n\nuse mod_int::*;\n\nfn solve() {\n let n: usize = get();\n let s: Vec = get_word().chars().collect();\n let m = s.len();\n let mut rev = vec![vec![0; m + 1]; 2];\n for i in 0 .. m {\n let idx = if s[i] == '(' { 0 } else { 1 };\n let opp = if s[i] == '(' { ')' } else { '(' };\n let mut grow = s[0 .. i].to_vec();\n grow.push(opp);\n let mut aa = 0;\n for j in 0 .. i + 1 {\n if grow[j ..] == s[.. i + 1 - j] {\n aa = i + 1 - j;\n break;\n }\n }\n rev[1 - idx][i] = aa;\n rev[idx][i] = i + 1;\n }\n rev[0][m] = m;\n rev[1][m] = m;\n let mut dp = vec![vec![vec![ModInt::new(0); m + 1]; n + 1]; 2 * n + 1];\n dp[0][0][0] = ModInt::new(1);\n for i in 0 .. 2 * n {\n for j in 0 .. n + 1 {\n for k in 0 .. m + 1 {\n if j < n {\n dp[i + 1][j + 1][rev[0][k]] =\n dp[i + 1][j + 1][rev[0][k]] + dp[i][j][k];\n }\n if j > 0 {\n dp[i + 1][j - 1][rev[1][k]] =\n dp[i + 1][j - 1][rev[1][k]] + dp[i][j][k];\n }\n }\n }\n }\n println!(\"{}\", dp[2 * n][0][m]);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "590a49a7af0eb83376ed911ed488d7e5"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let x1: i32 = scan.token();\n let y1: i32 = scan.token();\n let x2: i32 = scan.token();\n let y2: i32 = scan.token();\n let x: i32 = scan.token();\n let y: i32 = scan.token();\n let dx = (x2 - x1).abs();\n let dy = (y2 - y1).abs();\n if dx % (2 * x) == 0 && dy % (2 * y) == 0 {\n writeln!(out, \"YES\").ok();\n } else if dx % (2 * x) == x && dy % (2 * y) == y {\n writeln!(out, \"YES\").ok();\n } else {\n writeln!(out, \"NO\").ok();\n }\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "1c80040104e06c9f24abfcfe654a851f"} {"source_code": "fn main() {\n let mut input: String = String::new();\n std::io::stdin().read_line(&mut input).expect(\"INPUT::read line failed\");\n let amount = input.trim().parse::().unwrap();\n\n input.clear();\n std::io::stdin().read_line(&mut input).expect(\"INPUT::read line failed\");\n let vec:Vec = input.trim().chars().collect::>();\n let mut crossword: Vec = vec![];\n let mut max_len = i32::default();\n\n for _item in &vec {\n match _item {\n 'B' => max_len += 1,\n 'W' => {\n if max_len > 0 {\n crossword.push(max_len);\n max_len = 0;\n }\n },\n _ => println!(\"ERROR::letter not exist\")\n }\n\n }\n\n if max_len > 0 {\n crossword.push(max_len);\n max_len = 0;\n }\n\n match crossword.len() {\n 0 => println!(\"0\"),\n _ => {\n println!(\"{}\", crossword.len());\n for _item in &crossword {\n print!(\"{} \", _item);\n }\n }\n }\n\n\n\n //println!(\"{:?}\", vec);\n //println!(\"{:?}\", crossword);\n}", "src_uid": "e4b3a2707ba080b93a152f4e6e983973"} {"source_code": "mod util {\n use std;\n pub fn read_line() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).unwrap();\n String::from(buffer.trim_right())\n }\n #[allow(dead_code)]\n pub fn read_ascii() -> Vec {\n let line = read_line();\n debug_assert!(line.is_ascii());\n line.bytes().collect()\n }\n #[allow(dead_code)]\n pub fn read1() -> i64 {\n read_line().parse::().unwrap()\n }\n #[allow(dead_code)]\n fn read_nums() -> Vec\n where ::Err : std::fmt::Debug {\n read_line().split(' ').map(|x| x.parse::().unwrap()).collect()\n }\n #[allow(dead_code)]\n pub fn read_ints() -> Vec {\n read_nums::()\n }\n #[allow(dead_code)]\n pub fn read_floats() -> Vec {\n read_nums::()\n }\n #[allow(dead_code)]\n pub fn read2() -> (i64, i64) {\n let nums = read_ints();\n (nums[0], nums[1])\n }\n #[allow(dead_code)]\n pub fn read3() -> (i64, i64, i64) {\n let nums = read_ints();\n (nums[0], nums[1], nums[2])\n }\n #[allow(dead_code)]\n pub fn read4() -> (i64, i64, i64, i64) {\n let nums = read_ints();\n (nums[0], nums[1], nums[2], nums[3])\n }\n} // mod util\nuse util::*;\n\ntype Prime = i64;\ntype Power = usize;\ntype PrimePower = (Prime, Power);\ntype Factorization = Vec;\n\nfn primes_below(maxn: usize) -> Vec {\n if maxn <= 2 {\n return vec![];\n }\n let mut is_prime: Vec = vec![true; maxn];\n is_prime[0] = false;\n is_prime[1] = false;\n let mut iterator: i64 = 2;\n while iterator * iterator < maxn as i64 {\n if is_prime[iterator as usize] {\n let mut destroyer: i64 = iterator * iterator;\n while destroyer < maxn as i64 {\n is_prime[destroyer as usize] = false;\n destroyer += iterator;\n }\n }\n iterator += 1;\n }\n is_prime.iter().enumerate().filter(|pair| *pair.1)\n .map(|pair| pair.0 as Prime).collect()\n}\n\nfn naive_factorization(mut number: i64, primes_till_sqrt: &Vec) -> Factorization {\n let mut prime_iter: usize = 0;\n let mut prime: Prime;\n let mut answer: Factorization = vec![];\n while number != 1 {\n if prime_iter >= primes_till_sqrt.len() {\n answer.push((number, 1));\n return answer;\n }\n prime = primes_till_sqrt[prime_iter];\n if number % prime == 0 {\n let mut power: Power = 0;\n while number % prime == 0 {\n power += 1;\n number /= prime;\n }\n answer.push((prime, power));\n }\n prime_iter += 1;\n }\n answer\n}\n\nfn main() {\n let b = read1();\n let v = primes_below(100000);\n let mut ans = 1;\n for (_p, val) in naive_factorization(b, &v) {\n ans *= (val + 1);\n }\n println!(\"{}\", ans);\n}\n", "src_uid": "7fc9e7d7e25ab97d8ebc10ed8ae38fd1"} {"source_code": "// Vicfred\n// https://codeforces.com/problemset/problem/546/C\n\nuse std::io;\nuse std::collections::HashSet;\nuse std::collections::VecDeque;\n\n#[derive(Debug,PartialEq,Eq,PartialOrd,Ord,Hash)]\nstruct Pair(i64, i64);\n\nfn main() {\n let mut n = String::new();\n\n io::stdin()\n .read_line(&mut n)\n .unwrap();\n\n let mut line = String::new();\n\n io::stdin()\n .read_line(&mut line)\n .unwrap();\n\n let mut a: VecDeque =\n line\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n a.pop_front();\n\n let mut line = String::new();\n\n io::stdin()\n .read_line(&mut line)\n .unwrap();\n\n let mut b: VecDeque =\n line\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n b.pop_front();\n\n let mut ans = 0;\n\n while !a.is_empty() && !b.is_empty() {\n ans += 1;\n\n let x = a.pop_front().unwrap();\n let y = b.pop_front().unwrap();\n\n if x > y {\n a.push_back(y);\n a.push_back(x);\n } else {\n b.push_back(x);\n b.push_back(y);\n }\n if ans > 1000 {\n println!(\"-1\");\n return;\n }\n }\n\n let winner = if a.is_empty() {2} else {1};\n\n println!(\"{} {}\", ans, winner);\n}\n", "src_uid": "f587b1867754e6958c3d7e0fe368ec6e"} {"source_code": "use std::io;\nuse std::cmp;\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n let n: i32 = input.trim().parse().unwrap();\n let mut segs: Vec<(i32, i32, i32)> = vec![];\n\n for i in 0..(n+1) {\n for j in (i+1)..(n+1) {\n segs.push((j-i,i,j));\n }\n }\n segs.sort();\n let mut result: i32 = 0;\n let mut flags: Vec = vec![false; segs.len()];\n for i in (0..segs.len()).rev() {\n if flags[i] { continue; }\n let (size, mut a, mut b) = segs[i];\n flags[i] = true;\n let mut cur: i32 = size;\n while cur < n {\n let mut did_something = false;\n for j in (0..segs.len()).rev() {\n if flags[j] { continue; }\n let (s, c, d) = segs[j];\n if a == d || b == c {\n if cur + s <= n {\n a = cmp::min(a, c);\n b = cmp::max(b, d);\n cur += s;\n flags[j] = true;\n did_something = true;\n }\n }\n }\n if !did_something { break; }\n }\n result += 1;\n }\n println!(\"{}\", result);\n}\n", "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"source_code": "// use std::ops::{Index, IndexMut};\nuse std::cmp::{Ordering, min, max};\n// use std::collections::{BinaryHeap, BTreeMap};\n// use std::collections::btree_map::Entry::{Occupied, Vacant};\n// use std::clone::Clone;\n\nfn getline() -> String{\n let mut res = String::new();\n std::io::stdin().read_line(&mut res).ok();\n res\n}\n\nmacro_rules! split {\n ($x: expr) => {\n ($x).trim().split(' ').collect()\n }\n}\n\nmacro_rules! parse {\n ($x: expr) => {\n ($x).parse().unwrap()\n }\n}\n\nmacro_rules! readl {\n ($t: ty) => {\n {\n let s = getline();\n let iv: Vec<_> = split!(s);\n let mut iter = iv.into_iter();\n iter.next().unwrap().parse::<$t>().unwrap()\n }\n };\n ($( $t: ty),+ ) => {\n {\n let s = getline();\n let iv: Vec<_> = split!(s);\n let mut iter = iv.into_iter();\n ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) \n }\n };\n}\n\nmacro_rules! rvec {\n ($x: expr) => {\n ($x).into_iter().map(|x| parse!(x)).collect()\n }\n}\n\nmacro_rules! readlvec {\n ($t: ty) => {\n {\n let s = getline();\n let iv: Vec<_> = split!(s);\n iv.into_iter().map(|x| x.parse().unwrap()).collect::>()\n }\n }\n}\n\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {}\", stringify!($x), $x)\n }\n}\n\nfn printvec(v: &Vec) where T: std::fmt::Display {\n for (i,e) in v.into_iter().enumerate() {\n if i != 0 {\n print!(\" \");\n }\n print!(\"{}\", e);\n }\n println!(\"\");\n}\n\nfn main() {\n let (n, k) = readl!(usize, i64);\n let a = readlvec!(i64);\n\n let ma = a.iter().fold(0,|acc, &x| max(acc,x));\n let bo = (ma as f64).sqrt() as i64 + 2;\n let mut ans = 1;\n for i in 1..bo {\n let mut sum = 0;\n for e in &a {\n sum += (i-e%i)%i;\n }\n if sum <= k {\n ans = i;\n }\n }\n\n let mut qu = Vec::<(i64,usize)>::new();\n qu.push((bo,0));\n for i in 0..n {\n for j in 1..bo {\n if a[i]/j != 0 && bo <= a[i]/j {\n qu.push(((a[i]+j-1)/j,i));\n }\n }\n }\n qu.sort();\n let mut qui = qu.into_iter();\n let mut b = vec![0;n];\n let mut pre = -100;\n if let Some((di,i)) = qui.next() {\n for i in 0..n {\n b[i] = (a[i]+di-1)/di;\n }\n pre = di;\n }\n let mut sb = b.iter().fold(0,|acc, &x| acc+x);\n let sa = a.iter().fold(0,|acc, &x| acc+x);\n for (di, i) in qui {\n if pre*sb-sa <= k {\n let m = (k+sa-pre*sb)/sb;\n if pre+m < di {\n ans = pre+m;\n }\n }\n sb -= b[i];\n b[i] = (a[i]+di-1)/di;\n sb += b[i];\n pre = di;\n }\n if pre*sb-sa <= k {\n let m = (k+sa-pre*sb)/sb;\n ans = pre+m;\n }\n\n println!(\"{}\",ans);\n}\n\n", "src_uid": "2e1ab01d4d4440f33c840c4564a20a60"} {"source_code": "use std::io;\nuse std::io::Read;\n\nfn main() {\n let mut stdin = String::new();\n io::stdin().read_to_string(&mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n ($t:ty) => (get().parse::<$t>().unwrap());\n }\n \n let n = get!(u64);\n let m = get!(u64);\n \n if n > 63 {\n println!(\"{}\", m);\n } else {\n let x = (1 << n) - 1;\n println!(\"{}\", m & x);\n }\n \n}", "src_uid": "c649052b549126e600691931b512022f"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n// use proconio::input;\nuse std::cmp::{Ordering::*, Reverse};\nuse std::collections::{BTreeMap, BTreeSet, VecDeque, BinaryHeap};\nuse std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\n\n// I have no idea what I'm doing\n\nmacro_rules! answer {\n ($out:ident, $ans:expr) => {\n writeln!($out, \"{}\", $ans)\n };\n}\n\nfn main() -> Result<(), io::Error> {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = UnsafeScanner::new(stdin.lock());\n let mut out = BufWriter::new(stdout.lock());\n\n let _n: usize = scan.token();\n let s: Vec = scan.token::().bytes().map(|b| b - b'0').map(|x| x as u8).collect();\n let t: Vec = s.iter().scan(1, |cin, &x| {\n let y = (x + *cin) & 1;\n *cin = (x + *cin) >> 1;\n Some(y)\n }).collect();\n answer!(out, s.into_iter().zip(t.into_iter()).filter(|(x, y)| x != y).count())\n}\n\n///////////////////////////////////////////////////////////////////////////////////////////////////\n\n/// Mostly copied from https://github.com/EbTech/rust-algorithms/blob/master/src/scanner.rs\n/// Same API as Scanner but nearly twice as fast, using horribly unsafe dark arts\n/// **REQUIRES** Rust 1.34 or higher\npub struct UnsafeScanner {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'static>,\n}\n\nimpl UnsafeScanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n /// This function should be marked unsafe, but noone has time for that in a\n /// programming contest. Use at your own risk!\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse [Scanner]\");\n }\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_ascii_whitespace())\n }\n }\n }\n\n pub fn pair(&mut self) -> (T, T) {\n (self.token(), self.token())\n }\n}\n\n// aka #![feature(bool_to_option)]\ntrait BoolThen {\n fn then_(self, f: impl FnOnce() -> T) -> Option;\n}\n\nimpl BoolThen for bool {\n fn then_(self, f: impl FnOnce() -> T) -> Option {\n if self {\n Some(f())\n } else {\n None\n }\n }\n}\n\ntrait BoolToYes {\n fn yes(self) -> &'static str;\n}\n\nimpl BoolToYes for bool {\n fn yes(self) -> &'static str {\n match self {\n true => \"Yes\",\n false => \"No\",\n }\n }\n}\n", "src_uid": "54cb2e987f2cc06c02c7638ea879a1ab"} {"source_code": "// @robertkingnz https://twitter.com/robertkingNZ\r\n\r\n/// Accomplished using the EduTools plugin by JetBrains https://plugins.jetbrains.com/plugin/10081-edutools\r\n\r\n/// To modify the template, go to Preferences -> Editor -> File and Code Templates -> Other\r\n\r\nuse std::io::{self, Read};\r\n\r\nfn main() -> io::Result<()> {\r\n let mut s = String::new();\r\n io::stdin().read_to_string(&mut s)?;\r\n let mut it = s\r\n .split_whitespace()\r\n .map(|s| s.to_string());\r\n let mut out = String::new();\r\n let n: i32 = it.next().unwrap().parse().unwrap();\r\n let p: f64 = it.next().unwrap().parse().unwrap();\r\n for x in 0..=n {\r\n let x = x as f64;\r\n let n = n as f64;\r\n let c0 = (n-x)/n * (n-x-1.0)/(n-1.0) * (n-x-2.0)/(n-2.0);\r\n let c1 = x/n * (n-x)/(n-1.0) * (n-x-1.0)/(n-2.0) +\r\n (n-x)/n * x/(n-1.0) * (n-x-1.0)/(n-2.0) +\r\n (n-x)/n * (n-x-1.0)/(n-1.0) * x/(n-2.0);\r\n let c3 = x/n * (x-1.0)/(n-1.0) * (x-2.0)/(n-2.0);\r\n let c2 = 1.0 - c0 - c1 - c3;\r\n // println!(\"{} {} {} {} {}\", x, c0, c1, c2, c3);\r\n let y = c1/2.0 + c2 + c3;\r\n // println!(\"{} {} {} {}\", x, c1, c2, c3);\r\n if y >= p-0.00000001 {\r\n let ans = format!(\"{}\\n\", x);\r\n out.push_str(ans.as_str());\r\n print!(\"{}\", out);\r\n break;\r\n }\r\n }\r\n Ok(())\r\n}\r\n\r\n/*\r\nn maps\r\nP(x) >= p\r\n\r\nc0*p0 + c1*p1 +.. +c3*p3 > p\r\n\r\nc(i) = choose(n, i)/choose(n, 3)\r\np(i) =\r\nif i = 3 -> 1.0\r\nif i = 2 -> 1.0\r\nif i = 1 -> 1/3 * ( same_bad = 1/2 + other_bad = 1 + only_good = 0 ) = 1/3 * 3/2 = 1/2\r\nif i = 0 -> 0\r\n\r\nc0*0+ c1/2 + c2*1 + c3*2\r\n= c1/2 + c2 + c3\r\n\r\nn choose 3 = n*(n-1)*(n-2)\r\nx choose 1 = x\r\nx choose 2 = x*(x-1)\r\nx choose 3 = x*(x-1)*(x-3)\r\n\r\n7:\r\np(1) = 1/2\r\nc(1) = 1/2\r\n1/4\r\n\r\n1/7\r\n6/7 (\r\n1/6\r\n5/6 (\r\n1/5\r\n0\r\n)\r\n)\r\n\r\n1/7 + 6/7*(1/6+5/6*(1/5)) = 3/7 = 0.42867\r\n */", "src_uid": "788ed59a964264bd0e755e155a37e14d"} {"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::collections::HashMap;\n\nfn get_num() -> usize{\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)\n .expect(\"\");\n\n usize::from_str(input.trim()).unwrap()\n}\n\nfn main() {\n let n = get_num();\n\n let mut m = HashMap::new();\n m.insert(0, (0, 0));\n m.insert(1, (0, 1));\n m.insert(2, (0, 2));\n m.insert(3, (0, 2));\n m.insert(4, (0, 2));\n m.insert(5, (0, 2));\n m.insert(6, (1, 2));\n m.insert(7, (2, 2));\n\n if n < 8 {\n let r = m.get(&n).unwrap();\n println!(\"{} {}\", r.0, r.1);\n } else {\n let r = m.get(&(n%7)).unwrap();\n println!(\"{} {}\", (n/7) * 2 + r.0, (n/7) * 2 + r.1);\n }\n}\n", "src_uid": "8152daefb04dfa3e1a53f0a501544c35"} {"source_code": "mod max_flow {\n use std;\n type F = i32;\n pub const INF: F = 1000;\n const ZERO: F = 0;\n fn non_zero(f: F) -> bool {\n f > ZERO\n }\n fn min(a: F, b: F) -> F {\n if a < b {\n a\n } else {\n b\n }\n }\n pub struct Graph {\n n: usize,\n depth: Vec,\n it: Vec,\n g: Vec>,\n }\n impl Graph {\n pub fn new(n: usize) -> Graph {\n Graph {\n n: n,\n depth: vec![n + 1; n],\n it: vec![0; n],\n g: vec![vec![]; n],\n }\n }\n pub fn add_edge(&mut self, s: usize, t: usize, f: F) {\n let x = self.g[s].len();\n let y = self.g[t].len();\n self.g[s].push((t, f, y));\n self.g[t].push((s, ZERO, x));\n }\n fn bfs(&mut self, src: usize, dst: usize) {\n let g = &self.g;\n let n = self.n;\n let dp = &mut self.depth;\n dp.clear();\n dp.resize(n, n + 1);\n dp[src] = 0;\n let mut q = std::collections::VecDeque::new();\n q.push_back(src);\n 'outer: while let Some(v) = q.pop_front() {\n for &(u, f, _) in g[v].iter() {\n if dp[u] > dp[v] + 1 && non_zero(f) {\n dp[u] = dp[v] + 1;\n if u == dst {\n break 'outer;\n }\n q.push_back(u);\n }\n }\n }\n }\n fn dfs(&mut self, v: usize, src: usize, f: F) -> F {\n if v == src {\n return f;\n }\n while self.it[v] < self.g[v].len() {\n let (u, _, inv) = self.g[v][self.it[v]];\n if self.depth[u] < self.depth[v] && non_zero(self.g[u][inv].1) {\n let capa = min(f, self.g[u][inv].1);\n let c = self.dfs(u, src, capa);\n if non_zero(c) {\n self.g[v][self.it[v]].1 += c;\n self.g[u][inv].1 -= c;\n return c;\n }\n }\n self.it[v] += 1;\n }\n ZERO\n }\n pub fn flow(&mut self, src: usize, dst: usize) -> F {\n let mut ans = ZERO;\n loop {\n self.bfs(src, dst);\n if self.depth[dst] > self.n {\n break;\n }\n self.it.clear();\n self.it.resize(self.n, 0);\n loop {\n let f = self.dfs(dst, src, INF);\n if non_zero(f) {\n ans += f;\n } else {\n break;\n }\n }\n }\n ans\n }\n }\n}\n\nfn diff(a: usize, b: usize) -> usize {\n std::cmp::max(a, b) - std::cmp::min(a, b)\n}\n\n#[allow(dead_code)]\nfn test() {\n let n = 25;\n for h in 1..=n {\n print!(\"{:>2}: \", h);\n for w in 1..=n {\n let mut g = max_flow::Graph::new(h * w + 2);\n let src = h * w + 1;\n let dst = src - 1;\n for i in 0..h {\n for j in 0..w {\n if (i + j) & 1 == 0 {\n g.add_edge(src, i * w + j, 1);\n for k in 0..h {\n for l in 0..w {\n if diff(i, k) + diff(j, l) == 3 {\n g.add_edge(i * w + j, k * w + l, 1);\n }\n }\n }\n } else {\n g.add_edge(i * w + j, dst, 1);\n }\n }\n }\n let ans = g.flow(src, dst) * 2;\n let c = if ans as usize == h * w { ' ' } else { '!' };\n print!(\"{:>4}{}\", ans, c);\n }\n println!();\n }\n}\n\nfn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let mut it = s.trim().split_whitespace();\n let mut h: usize = it.next().unwrap().parse().unwrap();\n let mut w: usize = it.next().unwrap().parse().unwrap();\n if h > w {\n std::mem::swap(&mut h, &mut w);\n }\n if h * w <= 100 {\n let mut g = max_flow::Graph::new(h * w + 2);\n let src = h * w + 1;\n let dst = src - 1;\n for i in 0..h {\n for j in 0..w {\n if (i + j) & 1 == 0 {\n g.add_edge(src, i * w + j, 1);\n for k in 0..h {\n for l in 0..w {\n if diff(i, k) + diff(j, l) == 3 {\n g.add_edge(i * w + j, k * w + l, 1);\n }\n }\n }\n } else {\n g.add_edge(i * w + j, dst, 1);\n }\n }\n }\n let ans = g.flow(src, dst) * 2;\n println!(\"{}\", ans);\n } else if h == 1 {\n let mut ans = w / 6 * 6;\n if w % 6 >= 4 {\n ans += 2;\n }\n if w % 6 >= 5 {\n ans += 2;\n }\n println!(\"{}\", ans);\n } else if h % 2 == 1 && w % 2 == 1 {\n let ans = h as u64 * w as u64 - 1;\n println!(\"{}\", ans);\n } else {\n let ans = h as u64 * w as u64;\n println!(\"{}\", ans);\n }\n}\n\nfn main() {\n// test();\n run();\n}\n", "src_uid": "02ce135a4b276d1e9ba6a4ce37f2fe70"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n println!(\"{}\", (input.i() - 1) / 2);\n}\n\n", "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }};\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (write!(out,$($format)*).unwrap());\n }\n input! {\n n: usize, k: i64,\n s: chars,\n }\n let s: Vec<_> = s.into_iter().map(|c| c as usize - 97).collect();\n let mut dp = vec![vec![0i64; n + 1]; n + 1];\n let mut nxt = vec![[n; 26]; n + 1];\n for i in (0..n).rev() {\n nxt[i] = nxt[i + 1];\n nxt[i][s[i]] = i;\n }\n dp[n][0] = 1;\n for i in (0..n).rev() {\n dp[i][0] = dp[i][0].saturating_add(1);\n for j in 0..n {\n let mut tot: i64 = 0;\n for l in 0..26 {\n let to = nxt[i][l] + 1;\n if to <= n {\n tot = tot.saturating_add(dp[to][j]);\n }\n }\n dp[i][j + 1] = dp[i][j + 1].saturating_add(tot);\n }\n }\n let mut cost = 0;\n let mut rem = k;\n for i in (0..n + 1).rev() {\n let now = min(dp[0][i], rem);\n cost += now * (n - i) as i64;\n rem -= now;\n if rem <= 0 {\n break;\n }\n }\n puts!(\"{}\\n\", if rem > 0 { -1 } else { cost });\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "ae5d21919ecac431ea7507cb1b6dc72b"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque,\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan {\n buffer: std::collections::VecDeque::new(),\n }\n }\n\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n}\n\nfn gcd(mut a: usize, mut b: usize) -> usize {\n if b > a {\n std::mem::swap(&mut a, &mut b);\n }\n while b != 0 {\n let new_b = a % b;\n a = b;\n b = new_b;\n }\n if a == 0 {\n 1\n } else {\n a\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let a: usize = scan.next();\n let b: usize = scan.next();\n let x = 6 - a.max(b) + 1;\n let common = gcd(x, 6);\n println!(\"{}/{}\", x / common, 6 / common);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1 << 23)\n .spawn(_main)\n .unwrap()\n .join()\n .unwrap();\n}\n", "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"source_code": "#![allow(non_snake_case)]\r\nuse std::io::{BufWriter, stdin, stdout, Write};\r\n\r\nfn main() {\r\n let mut scan = Scanner::default();\r\n let out = &mut BufWriter::new(stdout());\r\n let t: usize = scan.next();\r\n for _ in 0..t {\r\n let a1: Vec = (0..2).map(|_| scan.next()).collect();\r\n let a2: Vec = (0..2).map(|_| scan.next()).collect();\r\n let s = a1.iter().sum::() + a2.iter().sum::();\r\n if s == 0 {\r\n writeln!(out, \"0\").unwrap();\r\n } else if s == 1 {\r\n writeln!(out, \"1\").unwrap();\r\n } else if s == 2 {\r\n if a1 == vec![1, 1] || a2 == vec![1, 1] {\r\n writeln!(out, \"1\").unwrap();\r\n } else {\r\n writeln!(out, \"1\").unwrap();\r\n }\r\n } else if s == 3 {\r\n writeln!(out, \"1\").unwrap();\r\n } else {\r\n writeln!(out, \"2\").unwrap();\r\n }\r\n }\r\n}\r\n\r\n#[derive(Default)]\r\nstruct Scanner {\r\n buffer: Vec\r\n}\r\nimpl Scanner {\r\n fn next(&mut self) -> T {\r\n loop {\r\n if let Some(token) = self.buffer.pop() {\r\n return token.parse().ok().expect(\"Failed parse\");\r\n }\r\n let mut input = String::new();\r\n stdin().read_line(&mut input).expect(\"Failed read\");\r\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\r\n }\r\n }\r\n}", "src_uid": "7336b8becd2438f0439240ee8f9610ec"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\nfn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(\n &mut std::io::stdin(),\n &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n () => (get!(i64));\n ($t:ty) => (get().parse::<$t>().unwrap());\n }\n \n let n = get().as_bytes();\n \n let mut p = 0;\n let mut s = 0;\n for &c in n {\n if c == b'o' {\n p += 1;\n } else {\n s += 1;\n }\n }\n \n if p < 2 || s == 0 {\n println!(\"YES\");\n return;\n }\n \n if s % p == 0 {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n \n}", "src_uid": "6e006ae3df3bcd24755358a5f584ec03"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).unwrap();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let s = input.bs();\n let n = s.len();\n let x = (0..n).zip((0..n).rev()).filter(|(a,b)| a < b && s[*a] != s[*b]).count();\n if (n % 2 == 1 && x <= 1) || (n % 2 == 0 && x == 1) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n\n", "src_uid": "fe74313abcf381f6c5b7b2057adaaa52"} {"source_code": "mod solution {\n use std::io::{self, Write, BufRead};\n\n pub fn solve() {\n let stdin = io::stdin();\n let mut iterator = stdin.lock().lines();\n iterator.next(); // Throw away first input\n let nums: Vec = iterator.next().unwrap().unwrap()\n .split(\" \")\n .into_iter()\n .map(|str_num| {\n let num: i32 = str_num.trim().parse().unwrap();\n num.abs() // Absolute value b/c -(-) -> (+)\n })\n .collect();\n let result: i32 = nums.iter().sum();\n io::stdout().write(&result.to_string().as_bytes()).unwrap();\n }\n}\n\nfn main() {\n solution::solve();\n}\n", "src_uid": "4b5d14833f9b51bfd336cc0e661243a5"} {"source_code": "#![allow(unused_imports)]\nuse std::collections::{HashSet, HashMap};\nuse std::cmp::{min,max};\nuse std::io;\nuse std::str;\n \nstruct Scanner {\n reader: R,\n buf_str: Vec,\n buf_iter: str::SplitWhitespace<'static>,\n}\nimpl Scanner {\n fn new(reader: R) -> Self {\n Self { reader, buf_str: vec![], buf_iter: \"\".split_whitespace() }\n }\n fn token(&mut self) -> T {\n loop {\n // If we have another token in this line\n if let Some(token) = self.buf_iter.next() {\n return token.parse().ok().expect(\"Failed parse\"); // calls parse::() on the current token and returns it.\n }\n\n // If we do not have another token in the line then\n // we should go to the next line.\n self.buf_str.clear(); // empty out the buffer that holds the current line\n self.reader.read_until(b'\\n', &mut self.buf_str).expect(\"Failed read\"); // read a new line into the buffer\n\n // create an iterator over the white space delimited strings of the current line\n self.buf_iter = unsafe { \n let slice = str::from_utf8_unchecked(&self.buf_str); // makes a string from utf8 characters in the current line\n std::mem::transmute(slice.split_whitespace()) // transmutes the memory in place \n }\n }\n }\n}\n \nfn solve(scan: &mut Scanner, out: &mut W) {\n let n = scan.token::();\n let mut top = 0;\n let mut bottom = 0;\n let mut flippable = false;\n for _ in 0..n {\n let t = scan.token::();\n let b = scan.token::();\n if t % 2 != b % 2 { flippable = true; }\n top += t;\n bottom += b;\n }\n let ans = {\n if top % 2 != 0 && bottom % 2 != 0 && flippable {1}\n else if top % 2 == 0 && bottom % 2 == 0 { 0 }\n else { -1 }\n };\n writeln!(out, \"{}\", ans);\n}\n \nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a> }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn f(&mut self) -> f64 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn sk(&mut self, n: usize) { self.it.nth(n - 1); }\n fn ii(&mut self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn ip(&mut self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n\n let n = input.i();\n input.sk(1);\n if input.bs()[0] == b'm' {\n println!(\"{}\", if n <= 29 {12} else if n <= 30 {11} else {7});\n } else {\n println!(\"{}\", if n == 5 || n == 6 {53} else {52});\n }\n}\n\n", "src_uid": "9b8543c1ae3666e6c163d268fdbeef6b"} {"source_code": "#[allow(unused_macros)]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n let mut next = || { iter.next().unwrap() };\n input_inner!{next, $($r)*}\n };\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n #[cfg(debug_assertions)]\n writeln!(&mut std::io::stderr(), concat!(\"[DEBUG] \", $(stringify!($a), \"={:?} \"),*), $($a),*);\n }\n}\n\n#[allow(unused_imports)]\nuse std::cmp::{min, max};\n\n#[allow(unused_imports)]\nuse std::io::Write;\n\nfn main() {\n input!{\n x: usize,\n y: usize,\n z: usize,\n a: usize,\n b: usize,\n c: usize,\n }\n\n if a < x {\n return println!(\"{}\", \"NO\");\n }\n if (a-x) + b < y {\n return println!(\"{}\", \"NO\");\n }\n if (a+b+c) < x+y+z {\n return println!(\"{}\", \"NO\");\n }\n println!(\"{}\", \"YES\");\n}\n", "src_uid": "d54201591f7284da5e9ce18984439f4e"} {"source_code": "use std::io;\nuse std::io::BufRead;\n\ntype Grid = Vec>;\n\nfn valid_index(index: isize) -> bool {\n index >= 0 && index <= 2\n}\n\nfn get_position(grid: &Grid, x: isize, y: isize) -> usize {\n if !valid_index(x) || !valid_index(y) {\n 0\n } else {\n *grid.get(y as usize).and_then(|n| n.get(x as usize).or(Some(&0))).unwrap_or(&0)\n }\n}\n\nfn main() {\n let numbers: Grid = io::stdin()\n .lock()\n .lines()\n .take(3)\n .map(|line| line.expect(\"failed to read line\")\n .trim()\n .split(\" \")\n .map(|number| number.parse::().expect(\"failed to parse number\"))\n .collect()\n )\n .collect();\n\n for y in 0 as isize..3 {\n for x in 0 as isize..3 {\n let mut n = get_position(&numbers, x, y);\n n += get_position(&numbers, x, y - 1);\n n += get_position(&numbers, x, y + 1);\n n += get_position(&numbers, x - 1, y);\n n += get_position(&numbers, x + 1, y);\n print!(\"{}\", match n % 2 {\n 0 => 1,\n 1 => 0,\n _ => unreachable!()\n });\n }\n println!(\"\");\n }\n}", "src_uid": "b045abf40c75bb66a80fd6148ecc5bd6"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::Read;\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok().unwrap();\n ret\n}\nfn get_word() -> String {\n let mut stdin = std::io::stdin();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\nfn solve() {\n let n: usize = get();\n let a: Vec = (0 .. n).map(|_| get()).collect();\n let mut ma = 0;\n for i in 0 .. (n + 1) {\n let mut tmp = 0;\n for j in 0 .. i {\n tmp += 1 - a[j];\n }\n for j in i .. n {\n tmp += a[j];\n }\n ma = max(ma, tmp);\n }\n println!(\"{}\", ma);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "c7b1f0b40e310f99936d1c33e4816b95"} {"source_code": "use std::collections::HashSet;\n\nfn main() {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n\n let name = buf.trim_end();\n let mut set: HashSet = HashSet::new();\n\n for chr in name.chars() {\n set.insert(chr);\n }\n\n if set.len() % 2 == 0 {\n println!(\"CHAT WITH HER!\");\n }\n else {\n println!(\"IGNORE HIM!\");\n }\n}\n", "src_uid": "a8c14667b94b40da087501fd4bdd7818"} {"source_code": "/// https://github.com/akiradeveloper/rust-comp-snippets\n\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n\n#[macro_export]\nmacro_rules! chmax {\n ($x:expr, $($v:expr),+) => {\n $(\n $x = std::cmp::max($x,$v);\n )+\n };\n}\n\n#[macro_export]\nmacro_rules! chmin {\n ($x:expr, $($v:expr),+) => {\n $(\n $x = std::cmp::min($x,$v);\n )+\n };\n}\n\n#[macro_export]\nmacro_rules! max {\n ($x:expr) => ( $x );\n ($x:expr, $($xs:expr),+) => {\n std::cmp::max($x, max!( $($xs),+ ))\n };\n}\n\n#[macro_export]\nmacro_rules! min {\n ($x:expr) => ( $x );\n ($x:expr, $($xs:expr),+) => {\n std::cmp::min($x, min!( $($xs),+ ))\n };\n}\n\n#[macro_export]\nmacro_rules! dvec {\n ($t:expr ; $len:expr) => {\n vec![$t; $len]\n };\n \n ($t:expr ; $len:expr, $($rest:expr),*) => {\n vec![dvec!($t; $($rest),*); $len]\n };\n}\n\n#[macro_export]\nmacro_rules! cfor {\n // for (; ...; ...) { ... }\n (; $($rest: tt)*) => {\n cfor!((); $($rest)*)\n };\n // for ($init; ; ...) { ... }\n ($($init: stmt),+; ; $($rest: tt)*) => {\n // avoid the `while true` lint\n cfor!($($init),+; !false; $($rest)*)\n };\n\n // for ($init; $cond; ) { ... }\n ($($init: stmt),+; $cond: expr; ; $body: block) => {\n cfor!{$($init),+; $cond; (); $body}\n };\n\n // for ($init; $cond; $step) { $body }\n ($($init: stmt),+; $cond: expr; $($step: expr),+; $body: block) => {\n {\n $($init;)+\n while $cond {\n let mut _first = true;\n let mut _continue = false;\n // this loop runs once, allowing us to use `break` and\n // `continue` as `goto` to skip forward to the\n // condition.\n //\n // the booleans above are very transparent to the\n // optimiser, since they are modified exactly once,\n // with nice control flow, and this this optimises to\n // be similar to C for loop.\n loop {\n // if we *don't* hit this, there was a `break` in\n // the body (otherwise the loop fell-through or\n // was `continue`d.)\n if !_first { _continue = true; break }\n _first = false;\n\n $body\n }\n if !_continue {\n // the `if` wasn't hit, so we should propagate the\n // `break`.\n break\n }\n\n $($step;)+\n }\n }\n };\n}\n\n/// main\n\n#[allow(unused_imports)]\nuse std::io::{stdin, stdout, BufWriter, Write};\n\n// ref: tanakh \n// diff: using Parser\n#[macro_export]\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut parser = Parser::from_str($s);\n input_inner!{parser, $($r)*}\n };\n (parser = $parser:ident, $($r:tt)*) => {\n input_inner!{$parser, $($r)*}\n };\n (new_stdin_parser = $parser:ident, $($r:tt)*) => {\n let stdin = std::io::stdin();\n let reader = std::io::BufReader::new(stdin.lock());\n let mut $parser = Parser::new(reader);\n input_inner!{$parser, $($r)*}\n };\n ($($r:tt)*) => {\n input!{new_stdin_parser = parser, $($r)*}\n };\n}\n\n#[macro_export]\nmacro_rules! input_inner {\n ($parser:ident) => {};\n ($parser:ident, ) => {};\n ($parser:ident, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($parser, $t);\n input_inner!{$parser $($r)*}\n };\n}\n\n#[macro_export]\nmacro_rules! read_value {\n ($parser:ident, ( $($t:tt),* )) => {\n ( $(read_value!($parser, $t)),* )\n };\n ($parser:ident, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($parser, $t)).collect::>()\n };\n ($parser:ident, chars) => {\n read_value!($parser, String).chars().collect::>()\n };\n ($parser:ident, usize1) => {\n read_value!($parser, usize) - 1\n };\n ($parser:ident, $t:ty) => {\n $parser.next::<$t>().expect(\"Parse error\")\n };\n}\n\nuse std::io::BufRead;\nuse std::io;\nuse std::str;\n\n// ref: tatsuya6502 \n// ref: wariuni \n// diff: using std::io::BufRead::fill_buf()\npub struct Parser {\n reader: R,\n buf: Vec,\n pos: usize,\n}\n\nimpl Parser {\n pub fn from_str(s: &str) -> Parser {\n Parser {\n reader: io::empty(),\n buf: s.as_bytes().to_vec(),\n pos: 0,\n }\n }\n}\n\nimpl Parser {\n pub fn new(reader: R) -> Parser {\n Parser {\n reader: reader,\n buf: vec![],\n pos: 0,\n }\n }\n pub fn update_buf(&mut self) {\n self.buf.clear();\n self.pos = 0;\n loop {\n let (len,complete) = {\n let buf2 = self.reader.fill_buf().unwrap();\n self.buf.extend_from_slice(buf2);\n let len = buf2.len();\n // diff: care when there is no empty space or line at the end\n if len == 0 {\n break;\n }\n (len, buf2[len-1] <= 0x20)\n };\n self.reader.consume(len);\n if complete {\n break;\n }\n }\n }\n pub fn next(&mut self) -> Result {\n loop {\n let mut begin = self.pos;\n while begin < self.buf.len() && (self.buf[begin] <= 0x20) {\n begin += 1;\n }\n let mut end = begin;\n while end < self.buf.len() && (self.buf[end] > 0x20) {\n end += 1;\n }\n if begin != self.buf.len() {\n self.pos = end;\n return str::from_utf8(&self.buf[begin..end]).unwrap().parse::();\n }\n else {\n self.update_buf();\n }\n }\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) ; } }\n#[doc = \" https://github.com/hatoo/competitive-rust-snippets\"]\nconst BIG_STACK_SIZE: bool = true;\n#[allow(dead_code)]\nfn main() {\n use std::thread;\n if BIG_STACK_SIZE {\n thread::Builder::new()\n .stack_size(32 * 1024 * 1024)\n .name(\"solve\".into())\n .spawn(solve)\n .unwrap()\n .join()\n .unwrap();\n } else {\n solve();\n }\n}\n\nfn solve() {\n let out = stdout();\n let mut out = BufWriter::new(out.lock());\n input!{\n n:i64,m:i64,\n }\n let mi = max(0, n-2*m);\n let fullconn = n*(n-1)/2;\n let ma = if m==0 {\n n\n } else {\n let mut i=1;\n loop {\n if i*(i-1)/2 >= m {\n break;\n }\n i += 1;\n }\n n-i\n };\n writeln!(out,\"{} {}\", mi,ma);\n}", "src_uid": "daf0dd781bf403f7c1bb668925caa64d"} {"source_code": "use std::cmp;\nuse std::fs::File;\nuse std::io::Read;\n\n// fn pow_speedt_with_mod(mut p: i64, mut q: i64, m: i64) -> i64 {\n// p %= m;\n// let mut r = p;\n// let mut ret: i64 = 1;\n// while q > 0 {\n// ret *= if q % 2 == 1 {r} else {1};\n// r *= r;\n// r %= m;\n// q /= 2;\n// ret %= m;\n// }\n// return ret;\n// }\n\nfn main() {\n let inputstatus = 1;\n\n let mut buf = String::new();\n let filename = \"inputrust.txt\";\n\n if inputstatus == 0 {\n let mut f = File::open(filename).expect(\"file not found\");\n f.read_to_string(&mut buf)\n .expect(\"something went wrong reading the file\");\n } else {\n std::io::stdin().read_to_string(&mut buf).unwrap();\n }\n\n let mut iter = buf.split_whitespace();\n let a: i32 = iter.next().unwrap().parse().unwrap();\n let b: i32 = iter.next().unwrap().parse().unwrap();\n let c: i32 = iter.next().unwrap().parse().unwrap();\n\n let v: [i32; 3] = [a / 3, b / 2, c / 2];\n let week: i32 = *v.iter().min().unwrap() as i32;\n\n let fish: i32 = a - 3 * week;\n let rabbit: i32 = b - 2 * week;\n let chicken: i32 = c - 2 * week;\n let mut ans = 0;\n let menu: [usize; 7] = [0, 1, 2, 0, 2, 1, 0];\n\n for df in 0..7 {\n let mut rest: [i32; 3] = [fish, rabbit, chicken];\n for di in 0..7 {\n let d = menu[(df + di) % 7];\n rest[d] -= 1;\n if rest[d] < 0 {\n ans = cmp::max(ans, di as i32);\n break;\n }\n }\n }\n\n println!(\"{}\", ans + week * 7);\n\n // println!(\"{}\", n);\n\n // if p + 1 >= m\n\n // println!(\"{}\", n);\n // println!(\"{}\", k);\n // println!(\"{:?}\", num);\n // println!(\"{:?}\", cum_num);\n}\n", "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\nfn main() {\n let mut stdin = String::new();\n std::io::Read::read_to_string(\n &mut std::io::stdin(),\n &mut stdin).unwrap();\n let mut stdin = stdin.split_whitespace();\n let mut get = || stdin.next().unwrap();\n macro_rules! get {\n () => (get().parse::().unwrap());\n ($t:ty) => (get().parse::<$t>().unwrap());\n }\n \n let n = get!();\n let mut ans = 0;\n for a in 1..n+1 {\n for b in a..n+1 {\n let c = a ^ b;\n if c >= b && c <= n && a + b > c {\n // println!(\"{} {} {}\", a, b, c);\n ans += 1;\n }\n }\n }\n \n println!(\"{}\", ans);\n \n}", "src_uid": "838f2e75fdff0f13f002c0dfff0b2e8d"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn triangle(a: i32, b: i32, c: i32) -> bool {\n (c - b < a && a < c + b) && (c - a < b && b < c + a) && (b - a < c && c < b + a)\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: usize = scan.token();\n let mut lengths = Vec::new();\n for _ in 0..n {\n lengths.push(scan.token::());\n }\n lengths.sort();\n for i in 0..n - 2 {\n if triangle(lengths[i], lengths[i + 1], lengths[i + 2]) {\n writeln!(out, \"YES\").ok();\n return;\n }\n }\n writeln!(out, \"NO\").ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "897bd80b79df7b1143b652655b9a6790"} {"source_code": "fn main() {\n let mut first_string = String::from(\"\");\n std::io::stdin()\n .read_line(&mut first_string)\n .expect(\"String not found\");\n \n let mut second_string = String::from(\"\");\n std::io::stdin()\n .read_line(&mut second_string)\n .expect(\"String not found\");\n\n // if first_string.len() > 100) || (second_string.len() > 100) {\n // return()\n // }\n\n if first_string.len() != second_string.len() {\n return ()\n }\n\n let first_string = first_string.to_lowercase();\n let second_string = second_string.to_lowercase();\n\n // let comp1 = first_string.eq(&second_string);\n // let comp2 = second_string.eq(&first_string);\n\n if first_string == second_string { println!(\"0\"); }\n\n else if first_string > second_string { println!(\"1\"); }\n\n else if first_string < second_string { println!(\"-1\"); }\n\n else { return () }\n\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n", "src_uid": "ffeae332696a901813677bd1033cf01e"} {"source_code": "use std::io;\nfn main() {\n let data = read();\n let mut ans = String::new();\n let mut count = 0;\n let mut lower = 0;\n for val in data.chars(){\n if count != 0 {\n if val.is_lowercase(){\n lower = 1;\n }\n }\n count += 1;\n }\n count = 0;\n if lower == 0 {\n for val in data.chars(){\n if count == 0 && val.is_lowercase(){\n let d : Vec = val.to_uppercase().collect();\n ans.push(d[0]);\n }\n else if count == 0 && val.is_uppercase(){\n let d : Vec = val.to_lowercase().collect();\n ans.push(d[0]);\n }\n else{\n let d : Vec = val.to_lowercase().collect();\n ans.push(d[0]);\n }\n count += 1;\n }\n }\n else{\n ans = data;\n }\n println!(\"{}\",ans);\n}\nfn read() -> String{\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input.trim().parse::().unwrap()\n}", "src_uid": "db0eb44d8cd8f293da407ba3adee10cf"} {"source_code": "//spnauti-rusT\nuse std::io::*;\nuse std::str::{self,*};\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::{self,*};\n#[allow(unused_imports)] use std::ops::{self,*};\n#[allow(unused_imports)] use std::iter::{self,*};\n#[allow(unused_imports)] use std::collections::*;\n#[allow(unused_imports)] use std::cell::*;\n#[allow(unused_macros)]\nmacro_rules! m {\n ($c:tt, $x:expr, $y:expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\n#[allow(unused_macros)]\nmacro_rules! l {\n ($($v:ident),* = $i:ident.$f:ident $a:tt) => {\n $( let $v = $i.$f$a; )*\n };\n ($($v:ident),*:$t:ty = $i:ident.$f:ident $a:tt) => {\n $( let $v:$t = $i.$f$a; )*\n };\n}\nstruct WordReaderB {\n bin: Box<[u8]>,\n it: Cell>>\n}\n#[allow(dead_code)]\nimpl WordReaderB {\n fn from(mut r: T) -> Self {\n let mut bin = Vec::new();\n r.read_to_end(&mut bin).ok();\n let bin = bin.into_boxed_slice();\n let it = Cell::new(Self::split(&bin).into_iter());\n Self { bin, it }\n }\n fn from_stdin() -> Self {\n Self::from(stdin())\n }\n fn split(a: &[u8]) -> Vec> {\n let mut res = Vec::new();\n let mut last = None;\n let mut space = vec![false; 256];\n for &c in b\" \\t\\n\\r\" {\n space[c as usize] = true;\n }\n for (i,&c) in a.iter().enumerate() {\n if space[c as usize] {\n if let Some(j) = last.take() {\n res.push(j..i);\n }\n } else {\n last.get_or_insert(i);\n }\n }\n if let Some(j) = last {\n res.push(j..a.len());\n }\n res\n }\n fn no_it() -> std::vec::IntoIter { \n Vec::new().into_iter()\n }\n fn bs(&self) -> &[u8] {\n let mut it = self.it.replace(Self::no_it());\n let r = it.next().expect(\"EOF\");\n self.it.set(it);\n &self.bin[r]\n }\n fn sl(&self) -> std::borrow::Cow {\n String::from_utf8_lossy(self.bs())\n }\n fn s(&self) -> String { self.sl().into_owned() }\n fn sk(&self, n: usize) {\n let mut it = self.it.replace(Self::no_it());\n it.nth(n - 1);\n self.it.set(it);\n }\n fn i(&self) -> i32 { self.p() }\n fn u(&self) -> usize { self.p() }\n fn f(&self) -> f64 { self.p() }\n fn vi(&self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn vu(&self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn ii(&self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn iu(&self, n: usize) -> impl Iterator {\n self.ip(n).into_iter()\n }\n fn p(&self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n fn ip(&self, n: usize) -> impl Iterator where T::Err: Debug {\n self.vp(n).into_iter()\n }\n}\n//------------------- End rusT\n\nfn main() {\n let rin = WordReaderB::from_stdin();\n l!(a,b = rin.i());\n println!(\"{}\", a + b);\n}\n\n", "src_uid": "b6e3f9c9b124ec3ec20eb8fcea075add"} {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(overflowing_literals)]\n#![allow(unused_must_use)]\n\nuse std::collections::*;\nuse std::io::*;\nuse std::cmp::{min, max};\nuse std::f64::consts::*;\nuse std::mem::swap;\nuse std::fs::File;\nuse std::rc::*;\nuse std::ascii::*;\nuse std::ops::*;\n\nconst INF: i32 = std::i32::MAX;\nconst LINF: i64 = std::i64::MAX;\nconst MOD: i32 = 1000000007;\n\n#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone)]\nstruct Pair(A, B);\n\nstruct Input\n{\n\tbuffer: Buf\n}\n\nimpl Input\n{\n\tfn read_line(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] < b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] >= b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\n\tfn read_word(&mut self) -> String {\n\t\tlet mut v = Vec::new();\n\t\tlet mut x = [255u8];\n\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\twhile x[0] <= b' ' && x[0] != 255u8 {\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\twhile x[0] > b' ' && x[0] != 255u8 {\n\t\t\tv.push(x[0]);\n\t\t\tx[0] = 255u8;\n\t\t\tself.buffer.read(&mut x).expect(\"EOF\");\n\t\t}\n\t\tString::from_utf8(v).unwrap()\n\t}\n\t#[inline]\n\tfn read_int(&mut self) -> i32 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_long(&mut self) -> i64 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_usize(&mut self) -> usize {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n\t#[inline]\n\tfn read_double(&mut self) -> f64 {\n\t\tself.read_word().parse::().expect(\"Parsing error\")\n\t}\n}\nmacro_rules! read {\n () => {};\n\t($inf:ident,$($t:ty),*) => ({($({$inf.read_word().parse::<$t>().expect(\"Parsing error\")}),*)});\n}\nfn gcd + Copy>(x: T, y: T) -> T {\n\tlet (mut a, mut b) = (x, y);\n\twhile b > T::from(0) {\n\t\ta %= b;\n\t\tswap(&mut a, &mut b);\n\t}\n\ta\n}\n\nfn main() {\n\tmatch std::env::var(\"home\") {\n\t\tOk(_x) => {\n\t\t\tlet mut inf = Input {\n\t\t\t\tbuffer: BufReader::new(File::open(\"input.txt\").expect(\"File not found\"))\n\t\t\t};\n\t\t\tlet mut ouf = BufWriter::new(stdout());\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t\tErr(_e) => {\n\t\t\tlet mut inf = Input { buffer: BufReader::new(stdin()) };\n\t\t\tlet mut ouf = BufWriter::new(stdout());\n\t\t\tsolve(&mut inf, &mut ouf);\n\t\t}\n\t}\n}\n\n\nfn solve(inf: &mut Input, ouf: &mut Output)\n{\n\tlet k = read!(inf,usize);\n\tlet mut v = vec![0; k];\n\tfor i in 0..k {\n\t\tv[i] = read!(inf,i32);\n\t}\n\tv.sort();\n\twriteln!(ouf, \"{}\", max(v[k - 1] - 25, 0));\n}", "src_uid": "ef657588b4f2fe8b2ff5f8edc0ab8afd"} {"source_code": "#[allow(unused_imports)]\nuse std::io::{stdin, Read, StdinLock};\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::str::FromStr;\n#[allow(unused_imports)]\nuse std::collections::{HashSet, HashMap, BinaryHeap};\n#[allow(unused_imports)]\nuse std::vec::Vec;\n\n#[allow(dead_code)]\nconst INF: i32 = 1000_000_000;\n#[allow(dead_code)]\nconst INFLL: i64 = 1000_000_000_000_000_000;\n#[allow(dead_code)]\nconst EPS: f64 = 1.0e-10;\n#[allow(dead_code)]\nconst MOD: i32 = 1000_000_007;\n\nstruct Scanner<'a> {\n cin: StdinLock<'a>,\n}\n\nimpl<'a> Scanner<'a> {\n #[allow(dead_code)]\n fn new(cin: StdinLock<'a>) -> Scanner<'a> {\n Scanner {cin: cin}\n }\n\n #[allow(dead_code)]\n fn read1(&mut self) -> Option {\n let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect::();\n token.parse::().ok()\n }\n\n #[allow(dead_code)]\n fn read(&mut self) -> T {\n self.read1().unwrap()\n }\n}\n\n\nfn main() {\n let cin = stdin();\n let cin = cin.lock();\n let mut sc = Scanner::new(cin);\n\n let a: i32 = sc.read();\n let x: i32 = sc.read();\n let y: i32 = sc.read();\n let x = 2 * x;\n let y = 2 * y;\n let a = 2 * a;\n let mut ans = -1;\n if y % a != 0 { \n if 0 < y && y < a {\n if -a / 2 < x && x < a / 2 {\n ans = 1;\n }\n } else {\n let j = (y - a) / a;\n if j % 2 == 0 {\n if -a / 2 < x && x < a / 2 {\n ans = 3 * j / 2 + 2;\n }\n } else {\n if -a < x && x < 0 {\n ans = 3 * (j + 1) / 2;\n } else if 0 < x && x < a {\n ans = 3 * (j + 1) / 2 + 1;\n }\n }\n }\n }\n\n println!(\"{}\", ans);\n}", "src_uid": "cf48ff6ba3e77ba5d4afccb8f775fb02"} {"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::fmt;\n\nfn not_all_zero(vec: &[u32]) -> bool {\n vec.iter().any(|n| *n != 0)\n}\n\nfn take_row(vec: &mut [u32]) -> u32 {\n let mut n = 0;\n\n for (i, item) in vec.iter_mut().enumerate() {\n if *item > 0 {\n n += 10_u32.pow(i as u32);\n *item -= 1;\n }\n }\n\n n\n}\n\nfn main() {\n let mut n: u32 = read();\n let mut digits = Vec::new();\n\n while n > 0 {\n digits.push(n % 10);\n n /= 10;\n }\n\n let mut nums = Vec::new();\n\n while not_all_zero(&digits) {\n nums.push(take_row(&mut digits));\n }\n\n println!(\"{}\", nums.len());\n println!(\"{}\",\n nums\n .iter()\n .map(|n| n.to_string())\n .collect::>()\n .join(\" \")\n );\n}\n\nfn read_line() -> String {\n let mut pre_n = String::new();\n io::stdin().read_line(&mut pre_n).unwrap();\n pre_n\n}\n\nfn read() -> T\n where ::Err: fmt::Debug\n{\n read_line().trim().parse().unwrap()\n}\n", "src_uid": "033068c5e16d25f09039e29c88474275"} {"source_code": "fn hash(a: &[u64], cnt: &[u64]) -> u64 {\n let mut hash = 0;\n for i in 0..10 {\n hash = (cnt[i] + 1) * hash + a[i];\n }\n hash\n}\n\nfn decode(mut hash: u64, cnt: &[u64]) -> Vec {\n let mut d = vec![];\n for i in (0..10).rev() {\n d.push(hash % (cnt[i] + 1));\n hash /= cnt[i] + 1;\n }\n d.reverse();\n d\n}\n\nfn run() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let mut it = s.trim().split_whitespace();\n let mut n: u64 = it.next().unwrap().parse().unwrap();\n let m: usize = it.next().unwrap().parse().unwrap();\n let mut cnt = vec![0; 10];\n let mut len = 0;\n while n > 0 {\n let k = (n % 10) as usize;\n cnt[k] += 1;\n len += 1;\n n /= 10;\n }\n let mut now = std::collections::BTreeMap::new();\n now.insert((hash(&cnt, &cnt), 0), 1u64);\n for p in 0..len {\n let mut next = std::collections::BTreeMap::new();\n for (k, v) in now.iter() {\n let (h, rem) = *k;\n let a = decode(h, &cnt);\n for d in 0..10 {\n if a[d] > 0 && !(p == 0 && d == 0) {\n let mut b = a.clone();\n b[d] -= 1;\n let r = (10 * rem + d) % m;\n *next.entry((hash(&b, &cnt), r)).or_insert(0u64) += *v;\n }\n }\n }\n now = next;\n }\n let mut ans = 0;\n for (k, v) in now.iter() {\n if k.1 == 0 {\n ans += *v;\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "5eb90c23ffa3794fdddc5670c0373829"} {"source_code": "struct Scan {\n buffer: std::collections::VecDeque\n}\n\nimpl Scan {\n fn new() -> Scan {\n Scan { buffer: std::collections::VecDeque::new() }\n }\n\n fn next(&mut self)-> T {\n loop {\n if let Some(token) = self.buffer.pop_front() {\n break token.parse::().ok().unwrap();\n }\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Fail to read\");\n self.buffer = line.split_whitespace().map(String::from).collect();\n }\n }\n\n}\n\nfn dfs_moves(acc: usize, current: usize, goal: usize, dist: &mut [usize;20000]) {\n if dist[current]<=acc { return; }\n dist[current] = acc;\n if current >= goal {\n dist[goal] = dist[goal].min(acc+current-goal);\n return;\n }\n dfs_moves(acc + 1, current*2, goal, dist);\n if current > 1 {\n dfs_moves(acc + 1, current-1, goal, dist);\n }\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: usize = scan.next();\n let m: usize = scan.next();\n if m<= n {\n println!(\"{}\", n - m);\n return;\n }\n let mut dist = [std::usize::MAX; 20000];\n dfs_moves(0, n, m, &mut dist);\n println!(\"{}\", dist[m]);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "src_uid": "861f8edd2813d6d3a5ff7193a804486f"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Write, BufWriter};\n// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\nmacro_rules! input {\n ($($r:tt)*) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut next = move || -> String{\n bytes\n .by_ref()\n .map(|r|r.unwrap() as char)\n .skip_while(|c|c.is_whitespace())\n .take_while(|c|!c.is_whitespace())\n .collect()\n };\n input_inner!{next, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($next:expr) => {};\n ($next:expr, ) => {};\n\n ($next:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($next, $t);\n input_inner!{$next $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($next:expr, ( $($t:tt),* )) => {\n ( $(read_value!($next, $t)),* )\n };\n\n ($next:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($next, $t)).collect::>()\n };\n\n ($next:expr, chars) => {\n read_value!($next, String).chars().collect::>()\n };\n\n ($next:expr, usize1) => {\n read_value!($next, usize) - 1\n };\n\n ($next:expr, [ $t:tt ]) => {{\n let len = read_value!($next, usize);\n (0..len).map(|_| read_value!($next, $t)).collect::>()\n }};\n\n ($next:expr, $t:ty) => {\n $next().parse::<$t>().expect(\"Parse error\")\n };\n}\n\nfn calc(g: &[Vec], revg: &[Vec], cnt: &mut [usize]) {\n let n = revg.len();\n let mut outdeg = vec![0; n];\n let mut zeroback = vec![0; n]; // zeroback[v] = #{w | (v -> u) in g, deg[v] = 1}\n let mut zero = 0;\n let mut zs = BTreeSet::new();\n for v in 0..n {\n for &w in &revg[v] {\n if outdeg[w] == 0 {\n zero -= 1;\n zs.remove(&w);\n zeroback[v] += 1;\n }\n if outdeg[w] == 1 {\n for &k in &g[w] {\n if k < v {\n zeroback[k] -= 1;\n }\n }\n }\n outdeg[w] += 1;\n }\n cnt[v] += zero;\n if zero == 1 {\n let &x = zs.iter().next().unwrap();\n cnt[v] += zeroback[x];\n }\n zero += 1;\n zs.insert(v);\n }\n}\n\nfn solve() {\n let out = std::io::stdout();\n let mut out = BufWriter::new(out.lock());\n macro_rules! puts {\n ($($format:tt)*) => (write!(out,$($format)*).unwrap());\n }\n input! {\n n: usize,\n uv: [(usize1, usize1)],\n }\n let mut g = vec![vec![]; n];\n let mut revg = vec![vec![]; n];\n for &(u, v) in &uv {\n g[u].push(v);\n revg[v].push(u);\n }\n // find a topological order\n let mut ord = vec![];\n {\n let mut indeg = vec![0; n];\n let mut que = VecDeque::new();\n for i in 0..n {\n indeg[i] = revg[i].len();\n if revg[i].is_empty() {\n que.push_back(i);\n }\n }\n while let Some(v) = que.pop_front() {\n ord.push(v);\n for &w in &g[v] {\n indeg[w] -= 1;\n if indeg[w] == 0 {\n que.push_front(w);\n }\n }\n }\n }\n assert_eq!(ord.len(), n);\n // Replace g and revg\n {\n let mut invord = vec![0; n];\n for i in 0..n {\n invord[ord[i]] = i;\n }\n for i in 0..n {\n g[i].clear();\n revg[i].clear();\n }\n for &(u, v) in &uv {\n let a = invord[u];\n let b = invord[v];\n g[a].push(b);\n revg[b].push(a);\n }\n }\n let mut cnt = vec![0; n];\n calc(&g, &revg, &mut cnt);\n cnt.reverse();\n for i in 0..n {\n for w in g[i].iter_mut() {\n *w = n - 1 - *w;\n }\n for w in revg[i].iter_mut() {\n *w = n - 1 - *w;\n }\n }\n g.reverse();\n revg.reverse();\n calc(&revg, &g, &mut cnt);\n cnt.reverse();\n let mut ans = 0;\n for i in 0..n {\n if cnt[i] <= 1 {\n ans += 1;\n }\n }\n puts!(\"{}\\n\", ans);\n}\n\nfn main() {\n // In order to avoid potential stack overflow, spawn a new thread.\n let stack_size = 104_857_600; // 100 MB\n let thd = std::thread::Builder::new().stack_size(stack_size);\n thd.spawn(|| solve()).unwrap().join().unwrap();\n}\n", "src_uid": "be26e93ca7aef1235e96e10467a6417e"} {"source_code": "use std::io;\nuse std::str;\n\npub struct Scanner {\n reader: R,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buffer: vec![],\n }\n }\n\n pub fn token(&mut self) -> T {\n loop {\n if let Some(token) = self.buffer.pop() {\n return token.parse().ok().expect(\"Failed parse\");\n }\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn gcd(a: i64, b: i64) -> i64 {\n if b == 0 {\n a\n } else {\n gcd(b, a % b)\n }\n}\n\nfn to_fraction(num: i64, denom: i64) -> (i64, i64) {\n let g = gcd(num, denom);\n (num / g, denom / g)\n}\n\nfn max_fraction(num1: i64, denom1: i64, num2: i64, denom2: i64) -> (i64, i64) {\n if num1 * denom2 < num2 * denom1 {\n to_fraction(num2, denom2)\n }\n else {\n to_fraction(num1, denom1)\n }\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let a: i64 = scan.token();\n let b: i64 = scan.token();\n let c: i64 = scan.token();\n let d: i64 = scan.token();\n\n let num1 = a * d - b * c;\n let denom1 = a * d;\n let num2 = b * c - a * d;\n let denom2 = b * c;\n\n let ans = max_fraction(num1, denom1, num2, denom2);\n writeln!(out, \"{}/{}\", ans.0, ans.1).ok();\n}\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = Scanner::new(stdin.lock());\n let mut out = io::BufWriter::new(stdout.lock());\n solve(&mut scan, &mut out);\n}\n", "src_uid": "b0f435fc2f7334aee0d07524bc37cb1e"} {"source_code": "// {{{ by shik\n\nuse std::io;\n\n#[allow(dead_code)]\nfn gets() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n}\n\n#[allow(unused_macros)]\nmacro_rules! R {\n ( $ty:ty, ... ) => {\n gets().split_whitespace().map(|x| x.parse::<$ty>().unwrap()).collect::>()\n };\n ( $($ty:ty),* ) => {{\n let line = gets();\n let mut it = line.split_whitespace();\n ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! W {\n ( $x:expr ) => {{\n println!(\"{}\", $x);\n }};\n ( $x:expr, $($xs:expr),* ) => {{\n print!(\"{} \", $x);\n W!($($xs),*);\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! join {\n ($x:expr, $($xs:expr),*; $sep:expr) => { concat!($x, $($sep, $xs),*) }\n}\n\n#[allow(unused_macros)]\nmacro_rules! dump {\n ($($x:expr),*) => {\n eprintln!(join!($(concat!(stringify!($x), \" = {:?}\")),*; \", \"), $($x),*);\n }\n}\n\n// }}}\n\nfn main() {\n let (n, m) = R!(usize, usize);\n let mut cur: usize = n;\n for day in 1.. {\n cur -= 1;\n if day % m == 0 {\n cur += 1;\n }\n if cur == 0 {\n println!(\"{}\", day);\n break;\n }\n }\n}\n", "src_uid": "42b25b7335ec01794fbb1d4086aa9dd0"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\n#![allow(unused_labels)]\n\nuse std::char::*;\nuse std::cmp::*;\nuse std::collections::*;\nuse std::io::*;\nuse std::str::FromStr;\n\nmacro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);}}\nmacro_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 ) * } } ; }\nmacro_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 ) * } } ; }\nmacro_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\" ) } ; }\n\n\nfn read() -> T {\n let stdin = stdin();\n let stdin = stdin.lock();\n let token: String = stdin\n .bytes()\n .map(|c| c.expect(\"failed to read char\") as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect();\n token.parse().ok().expect(\"failed to parse token\")\n}\n\nuse std::f64;\n\nfn min(a:T, b:T) -> T {\n if a < b { a }\n else { b }\n}\n\nfn max(a:T, b:T) -> T {\n if a < b { b }\n else { a }\n}\n\nconst MAX:usize = 30;\nconst INF:i64 = std::i64::MAX;\nconst MOD:i64 = 1e9 as i64 + 7;\n\nstruct Graph {\n e: Vec>,\n v: Vec,\n u: Vec,\n f: Vec,\n c: i64,\n vc: Vec,\n}\n\nimpl Graph {\n fn new(n:usize) -> Self {\n Graph {\n e: vec![vec![];n],\n v: vec![],\n u: vec![n;n],\n f: vec![false;n],\n c: 0,\n vc: vec![0;n],\n }\n }\n\n fn dfs(&mut self, crt: usize) {\n if self.f[crt] { return; }\n self.c += 1;\n self.f[crt] = true;\n self.v.push(crt);\n self.vc[crt] = self.c;\n self.u[crt] = self.v.len()-1;\n for i in 0..self.e[crt].len() {\n self.dfs(self.e[crt][i]);\n }\n //debug!(crt, self.c, self.vc[crt]);\n self.vc[crt] = self.c - self.vc[crt];\n }\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let k:i64 = read();\n let a:Vec = (0..n).map(|_| read()).collect();\n\n let mut idx = 0;\n for i in 0..n {\n if a[i] > k { break; }\n idx = i+1;\n }\n let mut idx2 = n;\n for i in (0..n).rev() {\n if a[i] > k { break; }\n idx2 = i;\n }\n if idx == n {\n println!(\"{}\", n);\n } else {\n println!(\"{}\", idx+(n-idx2));\n }\n //}\n}\n\n/*\n\n\n*/\n", "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::Read;\n\n#[allow(dead_code)]\nfn getline() -> String {\n let mut ret = String::new();\n std::io::stdin().read_line(&mut ret).ok().unwrap();\n ret\n}\n\nfn get_word() -> String {\n let stdin = std::io::stdin();\n let mut stdin=stdin.lock();\n let mut u8b: [u8; 1] = [0];\n loop {\n let mut buf: Vec = Vec::with_capacity(16);\n loop {\n let res = stdin.read(&mut u8b);\n if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {\n break;\n } else {\n buf.push(u8b[0]);\n }\n }\n if buf.len() >= 1 {\n let ret = String::from_utf8(buf).unwrap();\n return ret;\n }\n }\n}\n\n#[allow(dead_code)]\nfn get() -> T { get_word().parse().ok().unwrap() }\n\nfn main() {\n let s: Vec = get_word().chars().collect();\n let mut ans = 0;\n for i in 0..4_000_000 {\n let t: Vec<_> = format!(\"{}\", 25 * i).chars().collect();\n if s.len() == t.len() {\n let mut x = 0;\n let mut ok = true;\n for i in 0..s.len() {\n if s[i] != t[i] && s[i] != '_' && s[i] != 'X' {\n ok = false;\n break;\n }\n if s[i] == 'X' {\n let idx = t[i] as u8 - b'0';\n x |= 1 << idx;\n }\n }\n if ok && (x & -x) == x {\n ans += 1;\n }\n }\n }\n println!(\"{}\", ans);\n}\n", "src_uid": "4a905f419550a6c839992b40f1617af3"} {"source_code": "//spnauti-rust\nuse std::io::*;\nuse std::str::*;\nuse std::fmt::Debug;\n#[allow(unused_imports)] use std::cmp::Ordering::*;\n#[allow(unused_imports)] use std::collections::*;\n\n#[allow(unused_macros)]\nmacro_rules! a {\n ($c: tt, $x: expr, $y: expr) => {{\n let b = $y; let a = &mut $x;\n if b $c *a { *a = b; true } else { false }\n }};\n}\nstruct WordReader<'a> { it : SplitAsciiWhitespace<'a>, }\n#[allow(dead_code)]\nimpl<'a> WordReader<'a> {\n fn new(b: &mut String, mut r: T) -> WordReader {\n b.clear();\n r.read_to_string(b).ok();\n WordReader { it: b.split_ascii_whitespace() }\n }\n fn from_stdin(b: &mut String) -> WordReader {\n WordReader::new(b, stdin())\n }\n fn sl(&mut self) -> &str { self.it.next().unwrap() }\n fn bs(&mut self) -> &[u8] { self.sl().as_bytes() }\n fn s(&mut self) -> String { String::from(self.sl()) }\n fn i(&mut self) -> i32 { self.p() }\n fn u(&mut self) -> usize { self.p() }\n fn vi(&mut self, n: usize) -> Vec {\n self.vp::(n)\n }\n fn p(&mut self) -> T where T::Err: Debug {\n self.sl().parse::().unwrap()\n }\n fn vp(&mut self, n: usize) -> Vec where T::Err: Debug {\n (0..n).map(|_| self.p()).collect()\n }\n}\n\n#[allow(dead_code)]\nfn build_counting_hashmap(i: T) -> HashMap\n where T: Iterator {\n let mut m = HashMap::new();\n for k in i {\n let n = 1 + if let Some(&n) = m.get(&k) { n } else { 0 };\n m.insert(k, n);\n }\n m\n}\n\nfn main() {\n let mut bin = String::new();\n let mut input = WordReader::from_stdin(&mut bin);\n let mut bout = BufWriter::new(stdout());\n\n let n = input.u();\n let m = input.i();\n let mut c = vec![0; 101];\n let mut sum = 0;\n for _ in 0..n {\n let t = input.i();\n sum += t;\n let mut s = sum - m;\n let mut res = 0;\n if s > 0 {\n for i in (1..101).rev() {\n let x = c[i as usize];\n if x * i <= s {\n s -= x * i;\n res += x;\n } else {\n res += (s + i - 1) / i;\n break;\n }\n }\n }\n c[t as usize] += 1;\n write!(bout, \"{} \", res).ok();\n }\n}\n\n", "src_uid": "d3c1dc3ed7af2b51b4c49c9b5052c346"} {"source_code": "use std::io;\nuse std::io::Read;\n\nfn main() {\n let mut text = String::new();\n io::stdin().read_to_string(&mut text).unwrap();\n let mut iter = text.split_whitespace();//.map(|x| x.parse::().unwrap());\n let n = iter.next().unwrap().parse::().unwrap();\n let s = iter.next().unwrap();\n let mut up = true;\n let mut down = true;\n let mut left = true;\n let mut right = true;\n for c in s.chars() {\n let d = c as i64 - '0' as i64;\n if d == 1 || d == 2 || d == 3 {\n up = false;\n }\n if d == 7 || d == 9 || d == 0 {\n down = false;\n }\n if d == 1 || d == 4 || d == 7 || d == 0 {\n left = false;\n }\n if d == 3 || d == 6 || d == 9 || d == 0 {\n right = false;\n }\n }\n println!(\"{}\", if (up || down || left || right) {\"NO\"} else {\"YES\"});\n\n}\n\nfn get_pos(num: i64) -> (i64, i64) {\n if num == 0 {\n (3, 1)\n } else {\n ((num - 1) / 3, (num - 1) % 3)\n }\n}\n", "src_uid": "d0f5174bb0bcca5a486db327b492bf33"} {"source_code": "use std::io;\n\nconst M: u64 = 1_000_000_007;\n\nfn mult((a, b): (u64, u64), (c, d): (u64, u64)) -> (u64, u64) {\n ((a*c) % M, (a*d + b) % M)\n}\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n let input = input.split_whitespace().map(|s| s.parse().unwrap()).collect::>();\n let a = input[0];\n let b = input[1];\n let mut n = input[2];\n let x = input[3];\n\n let mut g = (1, 0);\n let mut f = (a, b);\n\n while n != 0 {\n if n % 2 == 1 {\n g = mult(g, f);\n }\n f = mult(f, f);\n n = n / 2;\n }\n\n let (a, b) = g;\n println!(\"{}\", (a*x + b) % M);\n}\n", "src_uid": "e22a1fc38c8b2a4cc30ce3b9f893028e"} {"source_code": "use std::io;\n\nfn main() {\n let mut val = String::new();\n\n io::stdin().read_line(&mut val)\n .expect(\"\u041d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443\");\n\n let val: i32 = val.trim().parse()\n .expect(\"\u041f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0432\u0432\u0435\u0434\u0438\u0442\u0435 \u0447\u0438\u0441\u043b\u043e!\");\n\n let ans = val / 5;\n println!(\"{}\", ans + (val % 5 > 0) as i32);\n}\n", "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"source_code": "use std::io;\n\nfn main() {\n let mut ni = String::new();\n io::stdin().read_line(&mut ni).unwrap();\n let mut si = String::new();\n io::stdin().read_line(&mut si).unwrap();\n let sf = si.trim().matches(\"SF\").collect::>().len(); \n let fs = si.trim().matches(\"FS\").collect::>().len(); \n if sf > fs {\n println!(\"YES\")\n } else {\n println!(\"NO\")\n }\n}\n", "src_uid": "ab8a2070ea758d118b3c09ee165d9517"} {"source_code": "use std::io;\n\n#[allow(dead_code)]\nfn main() {\n let mut input = \"\".split_ascii_whitespace();\n let mut read = || loop {\n if let Some(word) = input.next() {\n break word;\n }\n input = {\n let mut input = \"\".to_owned();\n io::stdin().read_line(&mut input).unwrap();\n if input.is_empty() {\n panic!(\"reached EOF\");\n }\n Box::leak(input.into_boxed_str()).split_ascii_whitespace()\n };\n };\n macro_rules! read(($ty:ty) => (read().parse::<$ty>().unwrap()));\n\n let n = read!(usize);\n let m = read!(usize);\n let mut sa = vec![\"\".to_string(); 0];\n for _ in 0..n {\n sa.push(read!(String));\n }\n let mut ca = vec![vec![' '; 0]; n];\n for i in 0..n {\n ca[i] = sa[i].chars().collect::>();\n }\n let mut ba = vec![vec![false; m]; n];\n\n for i in 0..n {\n for j in 0..m {\n if ca[i][j] != 'P' {\n continue;\n }\n if i > 0 && ca[i - 1][j] == 'W' {\n ba[i - 1][j] = true;\n }\n if i < n - 1 && ca[i + 1][j] == 'W' {\n ba[i + 1][j] = true;\n }\n if j > 0 && ca[i][j - 1] == 'W' {\n ba[i][j - 1] = true;\n }\n if j < m - 1 && ca[i][j + 1] == 'W' {\n ba[i][j + 1] = true;\n }\n }\n }\n\n let mut r = 0;\n for i in 0..n {\n for j in 0..m {\n if ba[i][j] {\n r += 1;\n }\n }\n }\n\n println!(\"{}\", r);\n}\n", "src_uid": "969b24ed98d916184821b2b2f8fd3aac"} {"source_code": "// ---------- begin ModInt ----------\nconst MOD: u32 = 998_244_353;\n\n#[derive(Clone, Copy)]\nstruct ModInt(u32);\n\nimpl std::ops::Add for ModInt {\n type Output = ModInt;\n fn add(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::AddAssign for ModInt {\n fn add_assign(&mut self, rhs: ModInt) {\n *self = *self + rhs;\n }\n}\n\nimpl std::ops::Sub for ModInt {\n type Output = ModInt;\n fn sub(self, rhs: ModInt) -> Self::Output {\n let mut d = self.0 + MOD - rhs.0;\n if d >= MOD {\n d -= MOD;\n }\n ModInt(d)\n }\n}\n\nimpl std::ops::SubAssign for ModInt {\n fn sub_assign(&mut self, rhs: ModInt) {\n *self = *self - rhs;\n }\n}\n\nimpl std::ops::Mul for ModInt {\n type Output = ModInt;\n fn mul(self, rhs: ModInt) -> Self::Output {\n ModInt((self.0 as u64 * rhs.0 as u64 % MOD as u64) as u32)\n }\n}\n\nimpl std::ops::MulAssign for ModInt {\n fn mul_assign(&mut self, rhs: ModInt) {\n *self = *self * rhs;\n }\n}\n\nimpl std::ops::Neg for ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n ModInt(if self.0 == 0 {0} else {MOD - self.0})\n }\n}\n\nimpl std::fmt::Display for ModInt {\n fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n}\n\nimpl std::str::FromStr for ModInt {\n type Err = std::num::ParseIntError;\n fn from_str(s: &str) -> Result {\n let val = s.parse::()?;\n Ok(ModInt::new(val))\n }\n}\n\n#[allow(dead_code)]\nimpl ModInt {\n pub fn new(n: u32) -> ModInt {\n ModInt(n % MOD)\n }\n pub fn zero() -> ModInt {\n ModInt(0)\n }\n pub fn one() -> ModInt {\n ModInt(1)\n }\n pub fn pow(self, mut n: u32) -> ModInt {\n let mut t = ModInt::one();\n let mut s = self;\n while n > 0 {\n if n & 1 == 1 {\n t *= s;\n }\n s *= s;\n n >>= 1;\n }\n t\n }\n pub fn inv(self) -> ModInt {\n assert!(self.0 > 0);\n self.pow(MOD - 2)\n }\n}\n// ---------- end ModInt ----------\n// ---------- begin Precalc ----------\n#[allow(dead_code)]\nstruct Precalc {\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n}\n\n#[allow(dead_code)]\nimpl Precalc {\n pub fn new(n: usize) -> Precalc {\n let mut inv = vec![ModInt::one(); n + 1];\n let mut fact = vec![ModInt::one(); n + 1];\n let mut ifact = vec![ModInt::one(); n + 1];\n for i in 2..(n + 1) {\n inv[i] = -inv[MOD as usize % i] * ModInt(MOD / i as u32);\n fact[i] = fact[i - 1] * ModInt(i as u32);\n ifact[i] = ifact[i - 1] * inv[i];\n }\n Precalc {\n inv: inv,\n fact: fact,\n ifact: ifact,\n }\n }\n pub fn inv(&self, n: usize) -> ModInt {\n self.inv[n]\n }\n pub fn fact(&self, n: usize) -> ModInt {\n self.fact[n]\n }\n pub fn ifact(&self, n: usize) -> ModInt {\n self.ifact[n]\n }\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\n }\n}\n// ---------- end Precalc ----------\n//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n// \u3053\u3053\u307e\u3067\n\nfn run() {\n input! {\n n: usize,\n m: usize,\n }\n if n <= 2 {\n println!(\"0\");\n return;\n }\n let pc = Precalc::new(n + m);\n let ans = pc.comb(m, n - 1) * ModInt((n - 2) as u32) * ModInt(2).pow((n - 3) as u32);\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "28d6fc8973a3e0076a21c2ea490dfdba"} {"source_code": "use std::io;\n\nfn main() {\n let mut input_str = String::new();\n io::stdin().read_line(&mut input_str).expect(\"read error\");\n \n let input: Vec = input_str.split_whitespace()\n .map(|x| x.parse::().expect(\"parse error\"))\n .collect();\n\n let n = input[0];\n let k = input[1];\n\n let mut divisors: Vec = vec![];\n for divisor in 1..n+1 {\n if divisor * divisor > n { break; }\n if n % divisor == 0 { divisors.push(divisor); }\n }\n\n let another_divisors: Vec;\n another_divisors = divisors.iter().map(|x| n / x).filter(|x| x * x != n).rev().collect();\n\n divisors.extend(another_divisors);\n\n if (divisors.len() as i64) < k {\n println!(\"-1\");\n } else {\n println!(\"{}\", divisors[k as usize - 1]);\n }\n}\n", "src_uid": "6ba39b428a2d47b7d199879185797ffb"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::io::stdin;\n\nmod util {\n use std::io::stdin;\n use std::str::FromStr;\n use std::fmt::Debug;\n\n #[allow(dead_code)]\n pub fn line() -> String {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn gets() -> Vec\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse().unwrap())\n .collect()\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! get {\n ($t:ty) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse::<$t>().unwrap()\n }\n };\n ($($t:ty),*) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n (\n $(iter.next().unwrap().parse::<$t>().unwrap(),)*\n )\n }\n };\n ($t:ty; $n:expr) => {\n (0..$n).map(|_|\n get!($t)\n ).collect::>()\n };\n ($($t:ty),*; $n:expr) => {\n (0..$n).map(|_|\n get!($($t),*)\n ).collect::>()\n };\n ($t:ty ;;) => {\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|t| t.parse::<$t>().unwrap())\n .collect::>()\n }\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nfn main() {\n let (n, a, b) = get!(usize, usize, usize);\n\n let mut ans = 1;\n for i in 1..n {\n let k = n - i;\n\n if a >= i && b >= k {\n ans = max(ans, min(a / i, b / k));\n }\n }\n\n println!(\"{}\", ans);\n}\n", "src_uid": "a254b1e3451c507cf7ce3e2496b3d69e"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::cmp::{max, min};\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn get_vec() -> Vec\nwhere T: FromStr,\n ::Err: std::fmt::Debug,\n{\n get_line().split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nconst N: i64 = 998_244_353;\n\nfn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d0, x0, y0) = extended_euclid(b, a % b);\n (d0, y0, x0 - a / b * y0)\n }\n}\n\nfn main() {\n let s = get_line().trim().to_string();\n\n let names = vec![\n \"Danil\",\n \"Olya\",\n \"Slava\",\n \"Ann\",\n \"Nikita\",\n ];\n\n let count = names.into_iter()\n .map(|name| s.split(name).count() - 1)\n .sum::();\n\n if count == 1 {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "db2dc7500ff4d84dcc1a37aebd2b3710"} {"source_code": "use std::io;\nuse std::io::prelude::*;\n\nfn get_line() -> String {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input\n}\n\nfn main() {\n let (n, t, k, d) = {\n let input = get_line();\n let mut it = input.split_whitespace().map(|k| k.parse::().unwrap());\n (\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n it.next().unwrap(),\n )\n };\n\n let t1 = (n - 1) / k + 1;\n\n let ta = d / t;\n\n if t1 > ta + 1 {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n", "src_uid": "32c866d3d394e269724b4930df5e4407"} {"source_code": "fn solve() {\r\n input! {\r\n mut s: i32,\r\n }\r\n let mut ans = vec![];\r\n for i in (1..10).rev() {\r\n if s >= i {\r\n ans.push(i);\r\n s -= i;\r\n }\r\n }\r\n for d in ans.into_iter().rev() {\r\n print!(\"{}\", d);\r\n }\r\n println!();\r\n}\r\n\r\nfn main() {\r\n input! {\r\n t: usize,\r\n }\r\n for _ in 0..t {\r\n solve();\r\n }\r\n}\r\n\r\nmod io {\r\n use std::cell::RefCell;\r\n use std::io::*;\r\n\r\n std::thread_local! {\r\n pub static STDIN: RefCell = RefCell::new(stdin());\r\n pub static STDOUT: RefCell> = RefCell::new(BufWriter::new(stdout()));\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! input {\r\n () => {};\r\n (mut $var:ident: $t:tt, $($rest:tt)*) => {\r\n let mut $var = __input_inner!($t);\r\n input!($($rest)*)\r\n };\r\n ($var:ident: $t:tt, $($rest:tt)*) => {\r\n let $var = __input_inner!($t);\r\n input!($($rest)*)\r\n };\r\n (mut $var:ident: $t:tt) => {\r\n let mut $var = __input_inner!($t);\r\n };\r\n ($var:ident: $t:tt) => {\r\n let $var = __input_inner!($t);\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! __input_inner {\r\n (($($t:tt),*)) => {\r\n ($(__input_inner!($t)),*)\r\n };\r\n ([$t:tt; $n:expr]) => {\r\n (0..$n).map(|_| __input_inner!($t)).collect::>()\r\n };\r\n ([$t:tt]) => {{\r\n let n = __input_inner!(usize);\r\n (0..n).map(|_| __input_inner!($t)).collect::>()\r\n }};\r\n (chars) => {\r\n __input_inner!(String).chars().collect::>()\r\n };\r\n (bytes) => {\r\n __input_inner!(String).into_bytes()\r\n };\r\n (usize1) => {\r\n __input_inner!(usize) - 1\r\n };\r\n ($t:ty) => {\r\n $crate::io::STDIN.with(|r| {\r\n use std::io::BufRead;\r\n let r = r.borrow_mut();\r\n let mut r = r.lock();\r\n let mut s = vec![];\r\n loop {\r\n let buf = r.fill_buf().unwrap();\r\n if buf.is_empty() {\r\n break;\r\n }\r\n if let Some(i) = buf.iter().position(u8::is_ascii_whitespace) {\r\n s.extend_from_slice(&buf[..i]);\r\n r.consume(i + 1);\r\n if !s.is_empty() {\r\n break;\r\n }\r\n } else {\r\n s.extend_from_slice(buf);\r\n let n = buf.len();\r\n r.consume(n);\r\n }\r\n }\r\n std::str::from_utf8(&s).unwrap().parse::<$t>().unwrap()\r\n })\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! println {\r\n () => {\r\n $crate::io::STDOUT.with(|w| {\r\n use std::io::Write;\r\n std::writeln!(w.borrow_mut()).unwrap()\r\n })\r\n };\r\n ($($arg:tt)*) => {\r\n $crate::io::STDOUT.with(|w| {\r\n use std::io::Write;\r\n std::writeln!(w.borrow_mut(), $($arg)*).unwrap()\r\n })\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! print {\r\n ($($arg:tt)*) => {\r\n $crate::io::STDOUT.with(|w| {\r\n use std::io::Write;\r\n std::write!(w.borrow_mut(), $($arg)*).unwrap()\r\n })\r\n };\r\n }\r\n\r\n #[macro_export]\r\n macro_rules! flush {\r\n () => {\r\n $crate::io::STDOUT.with(|w| {\r\n use std::io::Write;\r\n w.borrow_mut().flush().unwrap()\r\n })\r\n };\r\n }\r\n}\r\n", "src_uid": "fe126aaa93acaca8c8559bc9e7e27b9f"} {"source_code": "use std::io;\n\nmacro_rules! readln {\n () => {{\n use std::io;\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n }};\n ( $t:ty ) => {{\n let input = readln!();\n input.parse::<$t>().unwrap()\n }};\n ( $( $t:ty ),+ ) => {{\n let input = readln!();\n let mut input = input.split_whitespace();\n (\n $(\n input.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n }}\n}\n\nfn main() {\n let (width, height, count) = readln!(i32, i32, i32);\n\n let mut result = 0;\n for i in 0..count {\n let curr_width = width - 4 * i;\n let curr_height = height - 4 * i;\n\n result += 2 * (curr_width + curr_height - 2);\n }\n\n println!(\"{}\", result);\n}\n", "src_uid": "2c98d59917337cb321d76f72a1b3c057"} {"source_code": "use std::io::{self, BufRead, Write};\n\nfn solve(mut input: I, mut output: O) {\n let from = read_time(&mut input);\n let to = read_time(&mut input);\n let from_minutes = from.0 * 60 + from.1;\n let to_minutes = to.0 * 60 + to.1;\n let mid_minutes = (to_minutes + from_minutes) / 2;\n let mid = (mid_minutes / 60, mid_minutes % 60);\n writeln!(output, \"{:02}:{:02}\", mid.0, mid.1).unwrap();\n}\n\nfn read_time(mut input: I) -> (i32, i32) {\n let mut time = String::new();\n input.read_line(&mut time).unwrap();\n let time: Vec = time.split(':').map(|x| x.trim().parse().unwrap()).collect();\n (time[0], time[1])\n}\n\n#[cfg(test)]\nmod tests {\n #[test]\n fn example1() {\n assert_eq!(solve(\"10:00\\n11:00\\n\"), \"10:30\\n\");\n }\n\n #[test]\n fn example2() {\n assert_eq!(solve(\"11:10\\n11:12\\n\"), \"11:11\\n\");\n }\n\n #[test]\n fn example3() {\n assert_eq!(solve(\"01:02\\n03:02\\n\"), \"02:02\\n\");\n }\n\n fn solve(input: &str) -> String {\n let mut output = Vec::new();\n super::solve(input.as_bytes(), &mut output);\n String::from_utf8(output).unwrap()\n }\n}\n\nfn main() {\n let input = io::stdin();\n let input = input.lock();\n let output = io::stdout();\n let output = output.lock();\n solve(input, output)\n}\n", "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"source_code": "//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 \u3088\u308a\nmacro_rules! input {\n (source = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n ($($r:tt)*) => {\n let s = {\n use std::io::Read;\n let mut s = String::new();\n std::io::stdin().read_to_string(&mut s).unwrap();\n s\n };\n let mut iter = s.split_whitespace();\n input_inner!{iter, $($r)*}\n };\n}\n\nmacro_rules! input_inner {\n ($iter:expr) => {};\n ($iter:expr, ) => {};\n ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($iter, $t);\n input_inner!{$iter $($r)*}\n };\n}\n\nmacro_rules! read_value {\n ($iter:expr, ( $($t:tt),* )) => {\n ( $(read_value!($iter, $t)),* )\n };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($iter, $t)).collect::>()\n };\n ($iter:expr, chars) => {\n read_value!($iter, String).chars().collect::>()\n };\n ($iter:expr, bytes) => {\n read_value!($iter, String).bytes().collect::>()\n };\n ($iter:expr, usize1) => {\n read_value!($iter, usize) - 1\n };\n ($iter:expr, $t:ty) => {\n $iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\n };\n}\n\n//\n\nfn gcd(a: u64, b: u64) -> u64 {\n if b == 0 {\n a\n } else {\n gcd(b, a % b)\n }\n}\n\nfn run() {\n input! {\n n: usize,\n p: [usize1; n],\n }\n let mut q = p.clone();\n q.sort();\n q.dedup();\n if q.len() < n {\n println!(\"-1\");\n return;\n }\n let mut a = vec![];\n let mut used = vec![false; n];\n for i in 0..n {\n if used[i] {\n continue;\n }\n used[i] = true;\n let mut k = p[i];\n let mut c = 1;\n while k != i {\n used[k] = true;\n c += 1;\n k = p[k];\n }\n if c % 2 == 0 {\n a.push(c / 2);\n } else {\n a.push(c);\n }\n }\n a.sort();\n let ans = a.iter().fold(1, |s, a| s / gcd(s, *a) * *a);\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "src_uid": "149221131a978298ac56b58438df46c9"} {"source_code": "#[allow(unused_imports)]\nuse std::io::{stdin, Read, StdinLock};\n#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::str::FromStr;\n#[allow(unused_imports)]\nuse std::collections::{HashSet, HashMap, BinaryHeap, VecDeque};\n#[allow(unused_imports)]\nuse std::vec::Vec;\n\n#[allow(dead_code)]\nconst INF: i32 = 1000_000_000;\n#[allow(dead_code)]\nconst INFLL: i64 = 1000_000_000_000_000_000;\n#[allow(dead_code)]\nconst EPS: f64 = 1.0e-10;\n#[allow(dead_code)]\nconst MOD: i32 = 1000_000_007;\n#[allow(dead_code)]\nconst MODLL: i64 = 1000_000_007;\n\nstruct Scanner<'a> {\n cin: StdinLock<'a>,\n}\n\n#[allow(dead_code)]\nimpl<'a> Scanner<'a> {\n fn new(cin: StdinLock<'a>) -> Scanner<'a> {\n Scanner {cin: cin}\n }\n fn read1(&mut self) -> Option {\n let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)\n .skip_while(|c| c.is_whitespace())\n .take_while(|c| !c.is_whitespace())\n .collect::();\n token.parse::().ok()\n }\n fn read(&mut self) -> T {\n self.read1().unwrap()\n }\n}\n\nfn main() {\n let cin = stdin();\n let cin = cin.lock();\n let mut sc = Scanner::new(cin);\n\n let _n: usize = sc.read();\n let s: String = sc.read();\n let s: Vec = s.chars().collect();\n\n fn vowel(c: char) -> bool {\n return c == 'a' || c == 'i' || c == 'e' || c == 'o' || c == 'u' || c == 'y';\n }\n\n let mut ans: String = String::new();\n let mut last = '0';\n for c in s {\n if ans.len() == 0 {\n ans.push(c);\n last = c;\n } else {\n if vowel(last) && vowel(c) {\n continue;\n }\n ans.push(c);\n last = c;\n }\n }\n println!(\"{}\", ans);\n}", "src_uid": "63a4a5795d94f698b0912bb8d4cdf690"} {"source_code": "fn main() {\r\n let mut input_line = String::new();\r\n std::io::stdin()\r\n .read_line(&mut input_line)\r\n .expect(\"Failed to read line\");\r\n\r\n let mut parts = input_line.split_whitespace();\r\n let n: usize = parts.next().expect(\"Not enough input numbers\")\r\n .parse().expect(\"Input is not a number\");\r\n let m: usize = parts.next().expect(\"Not enough input numbers\")\r\n .parse().expect(\"Input is not a number\");\r\n\r\n if m == 1 {\r\n println!(\"{}\", n - 1)\r\n } else {\r\n println!(\"{}\", n * (m - 1));\r\n }\r\n}", "src_uid": "a91aab4c0618d036c81022232814ef44"}