{"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 (n,a,mut b) = readln!(i32,i32,i32);\n if b < 0 {\n b = -b;\n b %= n;\n b = (n-b)%n;\n }\n println!(\"{}\",1+((a-1+b)%n));\n}\n", "positive_code": [{"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.i();\n let a = input.i();\n let b = input.i();\n println!(\"{}\", ((a - 1 + b) % n + n) % n + 1);\n}\n\n"}], "negative_code": [], "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp;\nuse std::fs::File;\nuse std::io::Read;\n\n#[allow(dead_code)]\nfn pow_speedy_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\n#[allow(dead_code)]\nfn comb(n: usize, k: usize, m: i64, frac: &[i64], frac_inv: &[i64]) -> i64 {\n let mut ret = 1i64;\n if n < k {\n return 0;\n }\n ret *= frac[n] * frac_inv[n - k];\n ret %= m;\n ret *= frac_inv[k];\n ret %= m;\n 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\n let a: i64 = iter.next().unwrap().parse().unwrap();\n let mut b: i64 = iter.next().unwrap().parse().unwrap();\n let mut ans: i64 = 0;\n for i in 0..b + 1 {\n let x = a * i;\n ans = cmp::max(ans, (x + b) * (x + 1) * (b + 1) / 2);\n b -= 1;\n }\n println!(\"{}\", ans);\n // let n = iter.next().unwrap().parse().unwrap();\n\n // println!(\"{}\", n);\n // println!(\"{:?}\", cum_num);\n}\n", "positive_code": [{"source_code": "fn main() {\n let mut l = String::new();\n std::io::stdin().read_line(&mut l).unwrap();\n let mut mb = l.split_whitespace().map(|s| s.parse::().unwrap());\n let m = mb.next().unwrap();\n let b = mb.next().unwrap();\n\n let answer: u64 = (0..(b+1)).into_iter().map(|height| {\n let width = m * (b - height);\n\n let height_sum = height * (height+1) / 2;\n let width_sum = width * (width+1) / 2;\n\n height_sum * (width+1) + width_sum * (height+1)\n }).max().unwrap();\n println!(\"{}\", answer);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn main() {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let mut input = input.split_whitespace().map(|k| k.parse::().unwrap());\n let m = input.next().unwrap();\n let b = input.next().unwrap();\n\n let ans = (0..(m * b + 1)).map(|x| {\n let y = b - (x + m - 1) / m;\n let tmp = (x + 1) * (y + 1) * (x + y) / 2 ;\n tmp\n }).max().unwrap();\n\n println!(\"{}\", ans);\n}\n"}], "negative_code": [{"source_code": "use std::io::stdin;\n\nfn main() {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let mut input = input.split_whitespace().map(|k| k.parse::().unwrap());\n let m = input.next().unwrap();\n let b = input.next().unwrap();\n\n let ans = (0..(m * b + 1)).map(|x| {\n let y = b - (x + m - 1) / m;\n (x + 1) * (y + 1) / 2 * (x + y)\n }).max().unwrap();\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn main() {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let mut input = input.split_whitespace().map(|k| k.parse::().unwrap());\n let m = input.next().unwrap();\n let b = input.next().unwrap();\n\n let ans = (0..(m * b + 1)).map(|x| {\n let y = b - (x + m - 1) / m;\n let tmp = (x + 1) * (y + 1) * (x + y) / 2 ;\n tmp\n }).max().unwrap();\n\n println!(\"{}\", ans);\n}\n"}], "src_uid": "9300f1c07dd36e0cf7e6cb7911df4cf2"} {"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 let mut result = 0;\n let mut add = 1;\n while n > 1 {\n result += n / 2 * add;\n add *= 2;\n n = (n + 1) / 2;\n }\n println!(\"{}\", result);\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n", "positive_code": [{"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 bc = n.next_power_of_two().trailing_zeros();\n\n let mut cb = 1;\n let mut ans = 0;\n for _ in 0..bc {\n let t = cb * ((n - 1 + cb) / (cb << 1));\n ans += t;\n cb <<= 1;\n }\n\n println!(\"{}\", ans);\n}\n"}], "negative_code": [], "src_uid": "a98f0d924ea52cafe0048f213f075891"} {"source_code": "use std::io;\n\nmacro_rules! parse_line {\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n 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\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n let s = s.trim().as_bytes();\n let (k,) = parse_line!(i32);\n let (mut min_l, mut max_l) = (0, 0);\n for c in s.iter() {\n if c==&b'?' || c==&b'*' {\n min_l -= 1;\n } else {\n min_l += 1;\n max_l += 1;\n }\n }\n if k < min_l || (k > max_l && !s.contains(&b'*')) {\n println!(\"Impossible\");\n } else {\n let mut r = Vec::new();\n let mut d = k - min_l;\n let l = s.len();\n for i in 0..l {\n if i+1 < l && s[i+1] == b'?' {\n if d > 0 {\n r.push(s[i]);\n d -= 1;\n }\n } else if i+1 < l && s[i+1] == b'*' {\n while d > 0 {\n r.push(s[i]);\n d -= 1;\n }\n } else if s[i] != b'?' && s[i] != b'*' {\n r.push(s[i]);\n }\n }\n println!(\"{}\", String::from_utf8(r).unwrap());\n }\n}\n\n", "positive_code": [{"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 s: chars,\n k: usize,\n }\n let mut ans = s;\n let mut candy = 0;\n let mut snow = 0;\n for &c in &ans {\n if c == '?' {\n candy += 1;\n } else if c == '*' {\n snow += 1;\n }\n }\n let length = ans.len() - (candy + snow);\n debug!(length);\n if length < k {\n if snow == 0 {\n println!(\"Impossible\");\n return;\n }\n let mut done = false;\n let mut i = 0;\n while i < ans.len() {\n if ans[i] == '?' {\n ans.remove(i);\n i -= 1;\n } else if ans[i] == '*' {\n ans.remove(i);\n i -= 1;\n if !done {\n let x = ans[i];\n let insert_pos = i;\n for _j in 0..k-length {\n ans.insert(insert_pos, x);\n i += 1;\n }\n done = true;\n }\n }\n i += 1;\n }\n } else {\n if length - k > candy + snow {\n println!(\"Impossible\");\n return;\n }\n let mut del = length - k;\n let mut index = 0;\n debug!(del);\n while del > 0 {\n if ans[index] == '?' || ans[index] == '*' {\n ans.remove(index-1);\n ans.remove(index-1);\n index -= 2;\n del -= 1;\n }\n index += 1;\n }\n debug!(ans);\n debug!(length);\n while index < ans.len() {\n if ans[index] == '?' || ans[index] == '*' {\n ans.remove(index);\n index -= 1;\n }\n index += 1;\n }\n }\n let str_ans: String = ans.into_iter().collect();\n println!(\"{}\", str_ans);\n}"}, {"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\n#[derive(Debug)]\nenum Group {\n Sequence(String),\n Optional(char),\n Some(char)\n}\n\nimpl Group {\n fn is_sequence(&self) -> bool {\n match self {\n Group::Sequence(_) => true,\n _ => false\n }\n }\n\n fn get_sequence_mut(&mut self) -> &mut String {\n match self {\n Group::Sequence(ref mut seq) => seq,\n _ => panic!(\"kdkjndjfndi\")\n }\n }\n}\n\nfn get_min_len(groups: &Vec) -> usize {\n let mut result = 0;\n for group in groups {\n match group {\n Group::Sequence(seq) => result += seq.len(),\n _ => {}\n }\n }\n result\n}\n\nfn get_max_len(groups: &Vec) -> Option {\n let mut result = 0;\n for group in groups {\n match group {\n Group::Sequence(seq) => result += seq.len(),\n Group::Optional(_) => result += 1,\n Group::Some(_) => return None\n }\n }\n Some(result)\n}\n\nfn generate(groups: &Vec, min_len: usize, dest_len: usize) -> String {\n let mut result = String::new();\n let mut left = dest_len - min_len;\n for group in groups {\n match group {\n Group::Sequence(seq) => result.push_str(&seq.to_string()),\n Group::Optional(ch) if left > 0 => {\n result.push(*ch);\n left -= 1;\n },\n Group::Some(ch) if left > 0 => {\n let mut to_push = String::with_capacity(left);\n for _ in 0..left {\n to_push.push(*ch);\n }\n result.push_str(&to_push.to_string());\n left = 0;\n },\n _ => {}\n }\n }\n\n result\n}\n\nfn main() {\n let msg = readln!();\n let msg: Vec = msg.chars().collect();\n\n let mut groups = Vec::new();\n\n let mut index = 0;\n while index < msg.len() - 1 {\n let len = groups.len();\n if msg[index + 1] == '?' {\n groups.push(Group::Optional(msg[index]));\n index += 2;\n } else if msg[index + 1] == '*' {\n groups.push(Group::Some(msg[index]));\n index += 2;\n } else if len == 0 || !groups[len - 1].is_sequence() {\n let mut to_push = String::new();\n to_push.push(msg[index]);\n groups.push(Group::Sequence(to_push));\n index += 1;\n } else {\n groups[len - 1].get_sequence_mut().push(msg[index]);\n index += 1;\n }\n }\n if index == msg.len() - 1 {\n let len = groups.len();\n if len == 0 || !groups[len - 1].is_sequence() {\n let mut to_push = String::new();\n to_push.push(msg[index]);\n groups.push(Group::Sequence(to_push));\n } else {\n groups[len - 1].get_sequence_mut().push(msg[index]);\n }\n }\n\n let dest_len = readln!(usize);\n let min_len = get_min_len(&groups);\n if min_len > dest_len {\n println!(\"Impossible\");\n return;\n } if let Some(max_len) = get_max_len(&groups) {\n if max_len < dest_len {\n println!(\"Impossible\");\n return;\n }\n }\n \n println!(\"{}\", generate(&groups, min_len, dest_len));\n}\n"}], "negative_code": [], "src_uid": "90ad5e6bb5839f9b99a125ccb118a276"} {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n for i in 0..5 {\n io::stdin().read_line(&mut s).unwrap();\n }\n let arr : Vec = s.split_whitespace().map(|s| s.parse().unwrap()).collect();\n let mut cnt = 0;\n for i in 1..arr[4]+1 {\n let mut flag = true;\n for j in 0..4 {\n if i % arr[j as usize] == 0 {\n flag = false;\n }\n }\n if flag == false {\n cnt += 1;\n }\n }\n println!(\"{}\", cnt);\n}", "positive_code": [{"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n let mut v = Vec::new(); v.reserve(($n) as usize);\n for st in s { v.push(st.parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n let k = scan!(i32);\n let l = scan!(i32);\n let m = scan!(i32);\n let n = scan!(i32);\n let v = scan!(i32);\n let mut cnt = 0;\n for i in 1..v+1 {\n if i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 { cnt += 1; }\n }\n println!(\"{}\", cnt);\n}\n"}, {"source_code": "fn input() -> u32 {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n}\n\nfn main() {\n let k = input();\n let l = input();\n let m = input();\n let n = input();\n let objects = [k, l, m, n];\n let d = input(); // total number of dragons\n\n // true if hit\n let mut dragons: Vec = Vec::with_capacity(d as usize);\n for _ in 0..d {\n dragons.push(false)\n }\n\n for step in objects.iter() {\n let mut index = *step;\n while index <= d {\n dragons[(index - 1) as usize] = true;\n index += step;\n }\n }\n\n println!(\"{}\", dragons.iter().filter(|&&a| a).count());\n}"}, {"source_code": "//spnauti-rust\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n let mut a = [0; 4];\n for x in a.iter_mut() {\n *x = input.i();\n }\n let n = input.i();\n let sol = (1..n+1).filter(|x| a.iter().any(|y| x % y == 0)).count();\n println!(\"{}\", sol);\n}\n\n"}, {"source_code": "fn main() {\n let k: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let l: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let m: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let n: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let d: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let x = vec![k, l, m, n];\n let ret = (1..d + 1).fold(0, |total, i| if x.iter().any(|&k| i % k == 0) {\n total + 1\n } else {\n total\n });\n println!(\"{:?}\", ret);\n}\n"}, {"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 arr: [u64;5] = [scanner.next(), scanner.next(), scanner.next(), scanner.next(), scanner.next()];\n print![\"{}\", (1..=arr[4]).filter(|x| x % arr[0] == 0 || x % arr[1] == 0 || x % arr[2] == 0 || x % arr[3] == 0).count()];\n}"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut iterator = stdin.lock().lines();\n let mut damaged = 0;\n\n let k: i64 = iterator\n .next().unwrap().unwrap().parse().unwrap_or(0);\n let l: i64 = iterator\n .next().unwrap().unwrap().parse().unwrap_or(0);\n let m: i64 = iterator\n .next().unwrap().unwrap().parse().unwrap_or(0);\n let n: i64 = iterator\n .next().unwrap().unwrap().parse().unwrap_or(0);\n let d: i64 = iterator\n .next().unwrap().unwrap().parse().unwrap_or(0);\n\n for i in 1..=d {\n if i % k == 0 ||\n i % l == 0 ||\n i % m == 0 ||\n i % n == 0 {\n damaged += 1;\n }\n }\n\n println!(\"{}\", damaged);\n}"}, {"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 gcd(a: u32, b: u32) -> u32 {\n if b == 0 { a } else { gcd(b, a % b) }\n}\n\nfn lcm(a: u32, b:u32) -> u32 {\n a * b / gcd(a, b)\n}\n\nmacro_rules! lcm {\n ( $x:expr ) => {{\n $x\n }};\n ( $x:expr, $($xs:expr),* ) => {{\n lcm($x, lcm!($($xs),*))\n }}\n}\n\nfn main() {\n let (k, ) = R!(u32);\n let (l, ) = R!(u32);\n let (m, ) = R!(u32);\n let (n, ) = R!(u32);\n let (d, ) = R!(u32);\n println!(\"{}\",\n d/k + d/l + d/m + d/n\n - d/lcm!(k,l) - d/lcm!(k,m) - d/lcm!(k,n) - d/lcm!(l,m) - d/lcm!(l,n) - d/lcm!(m,n)\n + d/lcm!(k,l,m) + d/lcm!(k,l,n) + d/lcm!(k,m,n) + d/lcm!(l,m,n)\n - d/lcm!(k,l,m,n));\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let k: u32 = read(sin);\n let l: u32 = read(sin);\n let m: u32 = read(sin);\n let n: u32 = read(sin);\n let d: u32 = read(sin);\n\n let ans = (1..d + 1)\n .filter(|x| *x % k == 0 || *x % l == 0 || *x % m == 0 || *x % n == 0)\n .count();\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/148/A\nuse std::io;\n\nfn main() {\n let mut k = String::new();\n\n io::stdin()\n .read_line(&mut k)\n .unwrap();\n\n let k: i64 = k.trim().parse().unwrap();\n\n let mut l = String::new();\n\n io::stdin()\n .read_line(&mut l)\n .unwrap();\n\n let l: i64 = l.trim().parse().unwrap();\n\n let mut m = String::new();\n\n io::stdin()\n .read_line(&mut m)\n .unwrap();\n\n let m: i64 = m.trim().parse().unwrap();\n\n let mut n = String::new();\n\n io::stdin()\n .read_line(&mut n)\n .unwrap();\n\n let n: i64 = n.trim().parse().unwrap();\n\n let mut d = String::new();\n\n io::stdin()\n .read_line(&mut d)\n .unwrap();\n\n let d: i64 = d.trim().parse().unwrap();\n\n let mut dragons = 0;\n\n for idx in 1..d+1 {\n if idx % k == 0\n || idx % l == 0\n || idx % m == 0\n || idx % n == 0 {\n dragons += 1;\n }\n }\n\n println!(\"{}\", dragons);\n}\n\n"}, {"source_code": "use std::io::{self, prelude::*};\n\n\n#[allow(unused_must_use)]\n#[allow(unused_assignments)]\n#[allow(unused_variables)]\nfn solve(mut scan: Scanner, mut w: W) {\n let k = scan.token::();\n let l = scan.token::();\n let m = scan.token::();\n let n = scan.token::();\n let d = scan.token::();\n\n let mut arr = vec![false; d];\n\n for i in (0..d).skip(k-1).step_by(k) {\n arr[i] = true;\n }\n for i in (0..d).skip(l-1).step_by(l) {\n arr[i] = true;\n }\n for i in (0..d).skip(m-1).step_by(m) {\n arr[i] = true;\n }\n for i in (0..d).skip(n-1).step_by(n) {\n arr[i] = true;\n }\n\n let ans: usize = arr.iter().filter(|&e| *e).count();\n\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#[allow(dead_code)]\nfn vector_to_str(vector: &Vec, separator: &str) -> String { \n use std::fmt::Write;\n let mut ans = String::new();\n for line in vector.iter() {\n write!(&mut ans, \"{}{}\", line.to_string(), separator).unwrap();\n }\n ans\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 pub fn get_vector(&mut self, n: usize) -> Vec {\n let mut ans: Vec = Vec::with_capacity(n);\n for _ in 0..n {\n ans.push(self.token::());\n }\n ans\n }\n}\n"}, {"source_code": "use std::str::FromStr;\nuse std::fmt::Debug;\n\nfn main() {\n let mut c = 0;\n let k = read_line().to::();\n let l = read_line().to::();\n let m = read_line().to::();\n let n = read_line().to::();\n let d = read_line().to::();\n\n for i in 1..=d {\n if i % k == 0\n || i % l == 0\n || i % m == 0\n || i % n == 0\n {\n c += 1;\n }\n }\n\n println!(\"{}\", c);\n}\n\nfn read_line() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Ошибка чтения\");\n\n buffer.trim().to_string()\n}\n\ntrait ParseStr {\n fn to_vec(&self, separator: &str) -> Vec\n where\n T: FromStr,\n ::Err: std::fmt::Debug;\n\n fn to_vec_chars(&self) -> Vec;\n\n fn to(&self) -> T\n where\n T: FromStr + Copy,\n ::Err: Debug;\n}\n\nimpl ParseStr for String {\n \n fn to_vec(&self, separator: &str) -> Vec\n where\n T: FromStr,\n ::Err: Debug,\n {\n self.split(separator).map(|c| c.parse::().expect(\"Ошибка преобразования\")).collect()\n }\n\n fn to_vec_chars(&self) -> Vec {\n self.chars().collect()\n }\n\n fn to(&self) -> T\n where\n T: FromStr + Copy,\n ::Err: Debug,\n {\n ParseStr::to_vec::(self, \" \")[0]\n }\n}"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_t(stdin : &Stdin) -> T {\n let mut line = String::new();\n read_line(stdin, &mut line);\n parse_t(&line)\n}\n\nfn gcd(a : u64, b : u64) -> u64 {\n let mut t_a = if a > b { a } else { b };\n let mut t_b = if t_a == a { b } else { a };\n loop {\n if t_b == 0 {\n return t_a;\n } else {\n let t_a_mod_t_b = t_a % t_b;\n t_a = t_b;\n t_b = t_a_mod_t_b;\n }\n }\n}\n\nfn lcm(a : u64, b : u64) -> u64 {\n let g = gcd(a, b);\n (a / g) * b\n}\n\nmacro_rules! lcm_list {\n ($x:expr) => ($x);\n ($x:expr, $($y:expr),+) => (\n lcm($x, lcm_list!($($y),+))\n )\n}\n\nfn num_damaged_dragons(k : u64, l : u64, m : u64, n : u64, d : u64) -> u64 {\n let t_k = d / k;\n let t_l = d / l;\n let t_m = d / m;\n let t_n = d / n;\n let t_k_l = d / lcm_list!(k, l);\n let t_k_m = d / lcm_list!(k, m);\n let t_k_n = d / lcm_list!(k, n);\n let t_l_m = d / lcm_list!(l, m);\n let t_l_n = d / lcm_list!(l, n);\n let t_m_n = d / lcm_list!(m, n);\n let t_k_l_m = d / lcm_list!(k, l, m);\n let t_k_l_n = d / lcm_list!(k, l, n);\n let t_k_m_n = d / lcm_list!(k, m, n);\n let t_l_m_n = d / lcm_list!(l, m, n);\n let t_k_l_m_n = d / lcm_list!(k, l, m, n);\n let t_1 = t_k + t_l + t_m + t_n;\n let t_2 = t_k_l + t_k_m + t_k_n + t_l_m + t_l_n + t_m_n;\n let t_3 = t_k_l_m + t_k_l_n + t_k_m_n + t_l_m_n;\n let t_4 = t_k_l_m_n;\n t_1 - t_2 + t_3 - t_4\n}\n\nfn main() {\n let stdin = io::stdin();\n let k = read_t(&stdin);\n let l = read_t(&stdin); \n let m = read_t(&stdin); \n let n = read_t(&stdin); \n let d = read_t(&stdin); \n let r = num_damaged_dragons(k, l, m, n, d);\n println!(\"{}\", r);\n}\n"}, {"source_code": "use std::str::FromStr;\n \nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n \nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n \nfn main() {\n let (k, l, m, n, d): (u32, u32, u32, u32, u32) = (\n read_int(), read_int(), read_int(), read_int(), read_int());\n \n let mut total: u32 = 0;\n for index in 1..d + 1 {\n if index % k == 0 { total += 1; }\n else if index % l == 0 { total += 1; }\n else if index % m == 0 { total += 1; }\n else if index % n == 0 { total += 1; }\n }\n print!(\"{}\", total);\n}"}, {"source_code": "fn readln() -> Vec {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n\n line.split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect()\n}\n\n\nfn main() {\n let mut input = readln();\n let k = input[0];\n input = readln();\n let l = input[0];\n input = readln();\n let m = input[0];\n input = readln();\n let n = input[0];\n input = readln();\n let d = input[0];\n\n let mut ans = 0;\n for i in 1..(d + 1) {\n if i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 {\n ans += 1;\n }\n }\n\n println!(\"{}\", ans);\n}"}, {"source_code": "fn main() {\n let (k, l, m, n, d) = {\n let mut bufs: Vec = Vec::new();\n for _ in 0..5 {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n bufs.push(buf.trim_end().parse().unwrap());\n }\n (bufs[0], bufs[1], bufs[2], bufs[3], bufs[4])\n };\n\n let mut ans = 0;\n for i in 0..d {\n let num = i + 1;\n if num % k == 0 || num % l == 0 || num % m == 0 || num % n == 0 {\n ans += 1\n }\n }\n println!(\"{}\", ans);\n}\n"}, {"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\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 k = scan.token::();\n let l = scan.token::();\n let m = scan.token::();\n let n = scan.token::();\n let d = scan.token::();\n let mut ans = 0;\n for i in 1..=d {\n if i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 {\n ans += 1;\n }\n }\n out.write(format!(\"{}\", ans).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"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut k = String::new();\n\tio::stdin().read_line(&mut k).unwrap();\n\tlet k: i32 = k.trim().parse().unwrap();\n\n\tlet mut l = String::new();\n\tio::stdin().read_line(&mut l).unwrap();\n\tlet l: i32 = l.trim().parse().unwrap();\n\n\tlet mut m = String::new();\n\tio::stdin().read_line(&mut m).unwrap();\n\tlet m: i32 = m.trim().parse().unwrap();\n\n\tlet mut n = String::new();\n\tio::stdin().read_line(&mut n).unwrap();\n\tlet n: i32 = n.trim().parse().unwrap();\n\n\tlet mut d = String::new();\n\tio::stdin().read_line(&mut d).unwrap();\n\tlet d: i32 = d.trim().parse().unwrap();\n\n\tlet mut ans = 0;\n\tfor i in 1..=d {\n\t\tif i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 {\n\t\t\tans += 1;\n\t\t}\n\t}\n\n\tprintln!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut d = String::new(); \n let mut klmn: [String;4] = [String::new(), String::new(),String::new(),String::new()];\n\n io::stdin().read_line(&mut klmn[0]).unwrap();\n io::stdin().read_line(&mut klmn[1]).unwrap();\n io::stdin().read_line(&mut klmn[2]).unwrap();\n io::stdin().read_line(&mut klmn[3]).unwrap();\n io::stdin().read_line(&mut d).unwrap();\n \n let nd: i32 = d.trim().parse().unwrap();\n let mut k: [i32; 4] = [0,0,0,0];\n k[0] = klmn[0].trim().parse().unwrap();\n k[1] = klmn[1].trim().parse().unwrap();\n k[2] = klmn[2].trim().parse().unwrap();\n k[3] = klmn[3].trim().parse().unwrap();\n if k[0] == 1 || k[1] == 1 || k[2] == 1 ||k[3] == 1 {println!(\"{}\",nd);return;}\n let mut count = 0;\n for i in 1..nd+1 {\n if i % k[0] == 0 || i % k[1] == 0 || i % k[2] == 0 || i % k[3] == 0 {\n count = count + 1;\n }\n }\n println!(\"{}\",count);\n}\n\n// fn count_primes(n: i32) -> i32 {\n// let mut count = 0\n// if n <= 1 { return 0; }\n// else if n == 2 { count++; }\n// else if n % 2 == 0{ return false; }\n// else {\n// let mut i = 1;\n// while i < sqrt(n){\n// i = i + 2;\n// if n % i == 0 {\n// return false;\n// }\n// }\n// return true;\n// }\n// }\n\n// fn is_prime(n: i32) -> bool {\n// if n <= 1 { return false; }\n// else if n == 2 { return true; }\n// else if n % 2 == 0{ return false; }\n// else {\n// let mut i = 1;\n// while i < sqrt(n){\n// i = i + 2;\n// if n % i == 0 {\n// return false;\n// }\n// }\n// return true;\n// }\n// }\n"}, {"source_code": "#![allow(non_snake_case, unused_imports)]\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::{HashSet,HashMap,VecDeque,BinaryHeap};\n\n// Functions\n\n// Main\nfn main(){\n\n input!{\n K: usize,\n L: usize,\n M: usize,\n N: usize,\n D: usize\n }\n\n let mut ans = 0;\n for d in 1..D+1{\n if d%K==0 || d%L==0 || d%M==0 || d%N==0{\n ans += 1;\n } \n }\n println!(\"{}\", ans);\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\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 out = &mut BufWriter::new(stdout());\n\n\tlet k = scan.next::();\n\tlet l = scan.next::();\n\tlet m = scan.next::();\n\tlet n = scan.next::();\n\tlet d = scan.next::();\n\n let res = (1..=d).filter(|x| x % k == 0 || x % l == 0 || x % m == 0 || x % n == 0).count();\n writeln!(out, \"{}\", res).expect(\"fail\");\n}\n"}], "negative_code": [{"source_code": "fn main() {\n let k: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let l: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let m: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let n: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let d: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let x = vec![k, l, m, n];\n let ret = (0..d).fold(0, |total, i| if x.iter().any(|&k| i % k == 0) {\n total + 1\n } else {\n total\n });\n println!(\"{:?}\", ret);\n}\n"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n\nfn main() {\n let (k, l, m, n, d): (u32, u32, u32, u32, u32) = (\n read_int(), read_int(), read_int(), read_int(), read_int());\n\n let mut total: u32 = 0;\n for index in 0..d {\n if index % k == 0 { total += 1; }\n else if index % l == 0 { total += 1; }\n else if index % m == 0 { total += 1; }\n else if index % n == 0 { total += 1; }\n }\n print!(\"{}\", total);\n}"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n\nfn main() {\n let (k, l, m, n, d): (u32, u32, u32, u32, u32) = (\n read_int(), read_int(), read_int(), read_int(), read_int());\n\n let mut total: u32 = 0;\n for index in 1..d {\n if index % k == 0 { total += 1; }\n else if index % l == 0 { total += 1; }\n else if index % m == 0 { total += 1; }\n else if index % n == 0 { total += 1; }\n }\n print!(\"{}\", total);\n}"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut k = String::new();\n\tio::stdin().read_line(&mut k).unwrap();\n\tlet k: i32 = k.trim().parse().unwrap();\n\n\tlet mut l = String::new();\n\tio::stdin().read_line(&mut l).unwrap();\n\tlet l: i32 = l.trim().parse().unwrap();\n\n\tlet mut m = String::new();\n\tio::stdin().read_line(&mut m).unwrap();\n\tlet m: i32 = m.trim().parse().unwrap();\n\n\tlet mut n = String::new();\n\tio::stdin().read_line(&mut n).unwrap();\n\tlet n: i32 = n.trim().parse().unwrap();\n\n\tlet mut d = String::new();\n\tio::stdin().read_line(&mut d).unwrap();\n\tlet d: i32 = d.trim().parse().unwrap();\n\n\tlet mut ans = 0;\n\tfor i in 0..d {\n\t\tif i % k == 0 || i % l == 0 || i % m == 0 || i % n == 0 {\n\t\t\tans += 1;\n\t\t}\n\t}\n\n\tprintln!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut d = String::new(); \n let mut klmn: [String;4] = [String::new(), String::new(),String::new(),String::new()];\n\n io::stdin().read_line(&mut klmn[0]).unwrap();\n io::stdin().read_line(&mut klmn[1]).unwrap();\n io::stdin().read_line(&mut klmn[2]).unwrap();\n io::stdin().read_line(&mut klmn[3]).unwrap();\n io::stdin().read_line(&mut d).unwrap();\n \n let nd: i32 = d.trim().parse().unwrap();\n let mut k: [i32; 4] = [0,0,0,0];\n k[0] = klmn[0].trim().parse().unwrap();\n k[1] = klmn[1].trim().parse().unwrap();\n k[2] = klmn[2].trim().parse().unwrap();\n k[3] = klmn[3].trim().parse().unwrap();\n if k[0] == 1 || k[1] == 1 || k[2] == 1 ||k[3] == 1 {println!(\"{}\",nd);return;}\n let mut count = 1;\n for i in 1..nd {\n if i % k[0] == 0 || i % k[1] == 0 || i % k[2] == 0 || i % k[3] == 0 {\n count = count + 1;\n }\n }\n println!(\"{}\",count);\n}\n\n// fn count_primes(n: i32) -> i32 {\n// let mut count = 0\n// if n <= 1 { return 0; }\n// else if n == 2 { count++; }\n// else if n % 2 == 0{ return false; }\n// else {\n// let mut i = 1;\n// while i < sqrt(n){\n// i = i + 2;\n// if n % i == 0 {\n// return false;\n// }\n// }\n// return true;\n// }\n// }\n\n// fn is_prime(n: i32) -> bool {\n// if n <= 1 { return false; }\n// else if n == 2 { return true; }\n// else if n % 2 == 0{ return false; }\n// else {\n// let mut i = 1;\n// while i < sqrt(n){\n// i = i + 2;\n// if n % i == 0 {\n// return false;\n// }\n// }\n// return true;\n// }\n// }\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\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 out = &mut BufWriter::new(stdout());\n\n\tlet k = scan.next::();\n\tlet l = scan.next::();\n\tlet m = scan.next::();\n\tlet n = scan.next::();\n\tlet d = scan.next::();\n\n let res = (0..d).filter(|x| x % k == 0 || x % l == 0 || x % m == 0 || x % n == 0).count();\n writeln!(out, \"{}\", res).expect(\"fail\");\n}\n"}], "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"source_code": "use std::io;\n\nfn main() {\n let mut ss: String = String::new();\n io::stdin().read_line(&mut ss).unwrap();\n let n: u64 = ss.trim().parse().unwrap();\n\n let mut l: u64 = 1;\n let mut r: u64 = n;\n let mut m: u64;\n\n if tryv(n, 1) { println!(\"1\"); return; }\n\n loop {\n // println!(\"l: {}, r: {}\", l, r);\n if l + 1 == r {\n break;\n }\n m = (l + r) / 2;\n // println!(\"m: {}\", m);\n if tryv(n, m) {\n r = m; \n } else {\n l = m;\n } \n }\n\n if tryv(n, l) {\n println!(\"{}\", l);\n } else {\n println!(\"{}\", r);\n }\n return;\n}\n\nfn tryv(nn: u64, k: u64) -> bool {\n // println!(\"n: {}, k: {}\", nn, k);\n // println!(\"=====================\");\n if k == 0 { return false; }\n let mut n = nn;\n let mut v: u64 = 0;\n loop {\n if v >= nn/2 + nn%2{\n return true;\n } else if v + n < nn/2 + nn%2 {\n return false;\n }\n\n if k >= n {\n v += n;\n n = 0;\n } else {\n v += k;\n n -= k;\n }\n \n n -= n/10;\n // println!(\"left: {}, vasya: {}\", n, v);\n }\n}\n", "positive_code": [{"source_code": "// 991C\nuse std::io;\nfn main() {\n let n: u64 = read_one(&io::stdin());\n let mut min = 0;\n let mut max = n;\n loop {\n let mid = (min + max) / 2;\n if mid == min {\n break;\n }\n if eats_half(n, mid) {\n max = mid;\n } else {\n min = mid;\n }\n }\n println!(\"{}\", max);\n}\n\nfn eats_half(mut n: u64, k: u64) -> bool {\n let original_n = n;\n let mut v = 0;\n while n >= k {\n n -= k;\n v += k;\n n -= n / 10;\n }\n v += n;\n return 2 * v >= original_n;\n}\n\nfn read_one(stdin: &io::Stdin) -> 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 s.trim().split_whitespace().next().unwrap().parse().unwrap()\n}\n"}, {"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 n: u64 = input.trim().parse().unwrap();\n\n let check = |k| {\n let mut n = n;\n\n let mut v = 0;\n let mut p = 0;\n loop {\n if n < k {\n v += n;\n break;\n }\n n -= k;\n v += k;\n\n let q = n / 10;\n n -= q;\n p += q;\n }\n\n p <= v\n };\n\n let mut low = 0;\n let mut up = (n + 1) / 2;\n\n while low + 1 != up {\n let cur = (low + up) / 2;\n if check(cur) {\n up = cur;\n } else {\n low = cur;\n }\n }\n\n println!(\"{}\", up);\n}\n"}], "negative_code": [{"source_code": "use std::io;\n\nfn main() {\n let mut ss: String = String::new();\n io::stdin().read_line(&mut ss).unwrap();\n let n: u64 = ss.trim().parse().unwrap();\n\n let mut l: u64 = 1;\n let mut r: u64 = (n/2) + (n%2);\n let mut m: u64;\n\n if tryv(n, 1) { println!(\"1\"); return; }\n\n loop {\n if l + 1 == r {\n break;\n }\n m = (l + r) / 2;\n if tryv(n, m) {\n r = m; \n } else {\n l = m;\n } \n }\n\n println!(\"{}\", r);\n return;\n}\n\nfn tryv(nn: u64, k: u64) -> bool {\n // println!(\"n: {}, k: {}\", nn, k);\n // println!(\"=====================\");\n if k == 0 { return false; }\n let mut n = nn;\n let mut v: u64 = 0;\n loop {\n if v >= nn/2 {\n return true;\n } else if v + n < nn/2 {\n return false;\n }\n\n if k >= n {\n v += n;\n n = 0;\n } else {\n v += k;\n n -= k;\n }\n \n n -= n/10;\n // println!(\"left: {}, vasya: {}\", n, v);\n }\n}\n"}, {"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 n: u64 = input.trim().parse().unwrap();\n\n let check = |k| {\n let mut n = n;\n\n let mut v = 0;\n let mut p = 0;\n loop {\n if n < k {\n n = 0;\n v += n;\n break;\n }\n n -= k;\n v += k;\n\n let q = n / 10;\n n -= q;\n p += q;\n }\n\n p <= v\n };\n\n let mut low = 0;\n let mut up = (n + 1) / 2;\n\n while low + 1 != up {\n let cur = (low + up) / 2;\n if check(cur) {\n up = cur;\n } else {\n low = cur;\n }\n }\n\n println!(\"{}\", up);\n}\n"}], "src_uid": "db1a50da538fa82038f8db6104d2ab93"} {"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\nmacro_rules! forward_ref_unop {\n ( impl $ op : ident , $ method : ident for $ t : ty ) => {\n impl std::ops::$op for &$t {\n type Output = <$t as std::ops::$op>::Output;\n fn $method(self) -> <$t as std::ops::$op>::Output {\n std::ops::$op::$method(*self)\n }\n }\n };\n}\nmacro_rules! forward_ref_binop {\n ( impl $ op : ident , $ method : ident for $ t : ty , $ u : ty ) => {\n impl<'a> std::ops::$op<$u> for &'a $t {\n type Output = <$t as std::ops::$op<$u>>::Output;\n fn $method(self, other: $u) -> <$t as std::ops::$op<$u>>::Output {\n std::ops::$op::$method(*self, other)\n }\n }\n impl std::ops::$op<&$u> for $t {\n type Output = <$t as std::ops::$op<$u>>::Output;\n fn $method(self, other: &$u) -> <$t as std::ops::$op<$u>>::Output {\n std::ops::$op::$method(self, *other)\n }\n }\n impl std::ops::$op<&$u> for &$t {\n type Output = <$t as std::ops::$op<$u>>::Output;\n fn $method(self, other: &$u) -> <$t as std::ops::$op<$u>>::Output {\n std::ops::$op::$method(*self, *other)\n }\n }\n };\n}\nmacro_rules! forward_ref_op_assign {\n ( impl $ op : ident , $ method : ident for $ t : ty , $ u : ty ) => {\n impl std::ops::$op<&$u> for $t {\n fn $method(&mut self, other: &$u) {\n std::ops::$op::$method(self, *other);\n }\n }\n };\n}\npub trait PrimitiveInteger:\nSized\n + Ord\n + std::ops::Add\n + std::ops::Sub\n + std::ops::Div\n{\n fn one() -> Self;\n fn abs_diff(self, rhs: Self) -> Self;\n fn rem_euclid(self, rhs: Self) -> Self;\n}\nmacro_rules ! impl_primitive_integer { ( $ ( $ t : ty ) * ) => { $ ( impl PrimitiveInteger for $ t { fn one ( ) -> $ t { 1 } fn abs_diff ( self , rhs : $ t ) -> $ t { if self < rhs { rhs - self } else { self - rhs } } # [ allow ( unused_comparisons ) ] fn rem_euclid ( self , rhs : $ t ) -> $ t { let r = self % rhs ; if r < 0 { if rhs < 0 { r - rhs } else { r + rhs } } else { r } } } ) * } }\nimpl_primitive_integer ! ( u8 u16 u32 u64 usize i8 i16 i32 i64 isize ) ;\npub trait PrimitiveUnsigned: PrimitiveInteger {\n fn ceil_div(self, rhs: Self) -> Self;\n fn round_div(self, rhs: Self) -> Self;\n fn log2(self) -> Option;\n fn ceil_log2(self) -> Option;\n fn sqrt(self) -> Self;\n}\nmacro_rules ! impl_primitive_unsigned { ( $ ( $ t : ty ) * ) => { $ ( impl PrimitiveUnsigned for $ t { fn ceil_div ( self , rhs : $ t ) -> $ t { ( self + rhs - 1 ) / rhs } fn round_div ( self , rhs : $ t ) -> $ t { ( self + rhs / 2 ) / rhs } fn log2 ( mut self ) -> Option <$ t > { if self == 0 { None } else { let mut ans = 0 ; while self > 1 { ans += 1 ; self /= 2 ; } Some ( ans ) } } fn ceil_log2 ( self ) -> Option <$ t > { self . log2 ( ) . map ( | x | { ( self + ( ( 1 << x ) - 1 ) ) . log2 ( ) . unwrap ( ) } ) } fn sqrt ( self ) -> $ t { ( self as f64 ) . sqrt ( ) as $ t } } ) * } }\nimpl_primitive_unsigned ! ( u8 u16 u32 u64 usize ) ;\npub fn gcd(a: u64, b: u64) -> u64 {\n if b == 0 {\n a\n } else {\n gcd(b, a % b)\n }\n}\npub fn bezout(a: i64, b: i64) -> (i64, i64, u64) {\n let (x, y, g) = bezout_sub((a * a.signum()) as u64, (b * b.signum()) as u64);\n (x * a.signum(), y * b.signum(), g)\n}\nfn bezout_sub(a: u64, b: u64) -> (i64, i64, u64) {\n if b == 0 {\n (1, 0, a)\n } else {\n let m = (a / b) as i64;\n let (x, y, g) = bezout_sub(b, a % b);\n (y, x - m * y, g)\n }\n}\n\nfn divs(n: u64) -> Vec {\n let mut res = Vec::new();\n for d in 2..((n as f64).sqrt() as u64)+1 {\n if n % d == 0 {\n res.push(d);\n if n != d*d {\n res.push(n / d);\n }\n }\n }\n res\n}\n\nfn main() {\n read!(n = u64);\n let ans = divs(n).into_iter().fold(n, |acc, d| gcd(acc, d));\n println!(\"{}\", ans);\n}\n", "positive_code": [{"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 mut n = parse_line!(u64);\n let mut primes = Vec::new();\n for i in 2..n {\n if i * i > n {\n break;\n }\n if n % i != 0 {\n continue;\n }\n n /= i;\n while n % i == 0 {\n n /= i;\n }\n primes.push(i);\n }\n if n != 1 {\n primes.push(n);\n }\n if primes.len() == 1 {\n writeln!(writer, \"{}\", primes[0]).unwrap();\n }else{\n writeln!(writer, \"1\").unwrap();\n }\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"}, {"source_code": "use std::io::stdin;\nuse std::collections::{HashSet, BTreeSet};\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 re2(mut n: u64) -> BTreeSet {\n let mut res = BTreeSet::new();\n let mut mb = BTreeSet::new();\n let copy = n;\n let mut i = 2;\n while n != 1 && i * i <= copy && res.len() != 2 {\n if n % i == 0 {\n n /= i;\n res.insert(i);\n mb.insert(copy / i);\n } else {\n i += 1;\n }\n }\n mb.insert(n);\n res.remove(&1);\n if res.len() == 2 {\n return res;\n }\n mb.iter().for_each(|it| {\n let mut flag = true;\n for j in res.iter() {\n if *it % *j == 0 {\n flag = false;\n }\n }\n if flag {\n res.insert(*it);\n }\n });\n res.remove(&1);\n if res.is_empty() {\n res.insert(copy);\n return res;\n }\n\n res\n}\n\nfn main() {\n let mut n = readln!(u64);\n\n let res = re2(n);\n \n if res.is_empty() {\n println!(\"{}\", n);\n } else if res.len() == 1 {\n println!(\"{}\", res.iter().next().unwrap());\n } else {\n println!(\"1\")\n }\n}"}, {"source_code": "#![allow(unused_imports)]\n#![allow(non_snake_case, unused)]\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::ops::*;\n\nmacro_rules! eprint {\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = write!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! eprintln {\n\t() => { eprintln!(\"\"); };\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = writeln!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! dbg {\n\t($v:expr) => {{\n\t\tlet val = $v;\n\t\teprintln!(\"[{}:{}] {} = {:?}\", file!(), line!(), stringify!($v), val);\n\t\tval\n\t}}\n}\n\nmacro_rules! mat {\n\t($($e:expr),*) => { Vec::from(vec![$($e),*]) };\n\t($($e:expr,)*) => { Vec::from(vec![$($e),*]) };\n\t($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };\n\t($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };\n}\n\nmacro_rules! ok {\n\t($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {\n\t\t$a$([$i])*.$f($($t),*)\n\t};\n\t($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {\n\t\tlet t = $e;\n\t\tok!($a$([$i])*.$f($($es),*)$(@$t)*@t)\n\t} };\n}\n\npub fn readln() -> String {\n\tlet mut line = String::new();\n\t::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!(\"{}\", e));\n\tline\n}\n\nmacro_rules! read {\n\t($($t:tt),*; $n:expr) => {{\n\t\tlet stdin = ::std::io::stdin();\n\t\tlet ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {\n\t\t\tlet line = line.unwrap();\n\t\t\tlet mut it = line.split_whitespace();\n\t\t\t_read!(it; $($t),*)\n\t\t}).collect::>();\n\t\tret\n\t}};\n\t($($t:tt),*) => {{\n\t\tlet line = readln();\n\t\tlet mut it = line.split_whitespace();\n\t\t_read!(it; $($t),*)\n\t}};\n}\n\nmacro_rules! _read {\n\t($it:ident; [char]) => {\n\t\t_read!($it; String).chars().collect::>()\n\t};\n\t($it:ident; [u8]) => {\n\t\tVec::from(_read!($it; String).into_bytes())\n\t};\n\t($it:ident; usize1) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1\n\t};\n\t($it:ident; [usize1]) => {\n\t\t$it.map(|s| s.parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1).collect::>()\n\t};\n\t($it:ident; [$t:ty]) => {\n\t\t$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))).collect::>()\n\t};\n\t($it:ident; $t:ty) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))\n\t};\n\t($it:ident; $($t:tt),+) => {\n\t\t($(_read!($it; $t)),*)\n\t};\n}\n\npub fn main() {\n\tlet _ = ::std::thread::Builder::new().name(\"run\".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();\n}\n\nconst MOD: u32 = 1_000_000_007;\nconst INF: i64 = std::i64::MAX;\n\npub trait SetMinMax {\n\tfn setmin(&mut self, v: Self) -> bool;\n\tfn setmax(&mut self, v: Self) -> bool;\n}\nimpl SetMinMax for T where T: PartialOrd {\n\tfn setmin(&mut self, v: T) -> bool {\n\t\t*self > v && { *self = v; true }\n\t}\n\tfn setmax(&mut self, v: T) -> bool {\n\t\t*self < v && { *self = v; true }\n\t}\n}\n\nuse std::cmp::Ordering;\n\n/// Equivalent to std::lowerbound and std::upperbound in c++\npub trait BinarySearch {\n fn lower_bound(&self, x: &T) -> usize;\n fn upper_bound(&self, x: &T) -> usize;\n}\n\nimpl BinarySearch for [T] {\n // 配列a内のv以上の最小のindex\n fn lower_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less => {\n low = mid + 1;\n }\n Ordering::Equal | Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n // 配列a内のvより大きいの最小のindex\n fn upper_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less | Ordering::Equal => {\n low = mid + 1;\n }\n Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n}\n\nfn swap(a: usize, b: usize, sv: &mut [char], tv: &mut [char]) {\n\tlet tmp = sv[a];\n\tsv[a] = tv[b];\n\ttv[b] = tmp;\n}\n\nfn solve() {\n\tlet n = read!(i64);\n\tlet mut sum = 0;\n\tlet mut v = vec![];\n\tif n==1 {\n\t\tprintln!(\"{}\", 1);\n\t\treturn;\n\t}\n\tfor i in 2..((n as f64).sqrt() as i64+1) {\n\t\tif n%i==0 {\n\t\t\tsum+=2;\n\t\t\tv.push(i);\n\t\t\tv.push(n/i);\n\t\t}\n\t}\n\tif sum==0 {\n\t\tprintln!(\"{}\", n);\n\t\treturn;\n\t}\n\tlet mi = v[0];\n\tlet mut flag = true;\n\tfor &i in &v {\n\t\tif i%mi!=0 {flag=false;}\n\t}\n\tif !flag {println!(\"{}\", 1);}\n\telse{ println!(\"{}\", mi);}\n\n}\n\nfn run() {\n solve();\n}"}, {"source_code": "// https://codeforces.com/contest/1242/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#[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 gcd(a: i64, b: i64) -> i64 {\n if b == 0 {\n a\n } else {\n gcd(b, a%b)\n }\n}\n\nfn main() {\n input! {\n n: i64\n };\n\n let mut ans = n;\n for i in 1..n+1 {\n if i * i > n {\n break;\n }\n if n % i == 0 {\n if i >= 2 {\n ans = gcd(ans, i);\n }\n if n/i >= 2 {\n ans = gcd(ans, n/i);\n }\n }\n }\n println!(\"{}\", ans);\n}\n"}], "negative_code": [{"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\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 mut n = readln!(u64);\n\n let mut res = HashSet::new();\n\n let copy = n;\n let mut i = 2;\n while n != 1 && i * i <= copy {\n if n % i == 0 {\n n /= i;\n res.insert(i);\n res.insert(copy / i);\n if res.len() == 2 {\n break;\n }\n } else {\n i += 1;\n }\n }\n res.remove(&1);\n\n if res.is_empty() {\n println!(\"{}\", n);\n } else if res.len() == 1 {\n println!(\"{}\", res.iter().next().unwrap());\n } else {\n println!(\"1\")\n }\n}"}, {"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\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 division(n: u64) -> HashSet {\n let mut res = HashSet::new();\n\n if n % 2 == 0 {\n res.insert(2);\n res.insert(n / 2);\n }\n let mut i = 3;\n while i * i <= n {\n if n % i == 0 {\n res.insert(i);\n }\n i += 2;\n }\n res.remove(&1);\n res\n}\n\nfn main() {\n let n = readln!(u64);\n let divisions = division(n);\n\n if divisions.is_empty() {\n println!(\"{}\", n);\n } else if divisions.len() == 1 {\n println!(\"{}\", divisions.iter().next().unwrap());\n } else {\n println!(\"1\")\n }\n}"}, {"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\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 division(n: u64) -> HashSet {\n let mut res = HashSet::new();\n\n if n % 2 == 0 {\n res.insert(2);\n res.insert(n / 2);\n }\n let mut i = 3;\n while i * i <= n {\n if n % i == 0 {\n res.insert(i);\n }\n i += 2;\n }\n res\n}\n\nfn main() {\n let n = readln!(u64);\n let divisions = division(n);\n\n if divisions.is_empty() {\n println!(\"{}\", n);\n } else if divisions.len() == 1 {\n println!(\"{}\", divisions.iter().next().unwrap());\n } else {\n println!(\"1\")\n }\n}"}, {"source_code": "#![allow(unused_imports)]\n#![allow(non_snake_case, unused)]\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::ops::*;\n\nmacro_rules! eprint {\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = write!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! eprintln {\n\t() => { eprintln!(\"\"); };\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = writeln!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! dbg {\n\t($v:expr) => {{\n\t\tlet val = $v;\n\t\teprintln!(\"[{}:{}] {} = {:?}\", file!(), line!(), stringify!($v), val);\n\t\tval\n\t}}\n}\n\nmacro_rules! mat {\n\t($($e:expr),*) => { Vec::from(vec![$($e),*]) };\n\t($($e:expr,)*) => { Vec::from(vec![$($e),*]) };\n\t($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };\n\t($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };\n}\n\nmacro_rules! ok {\n\t($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {\n\t\t$a$([$i])*.$f($($t),*)\n\t};\n\t($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {\n\t\tlet t = $e;\n\t\tok!($a$([$i])*.$f($($es),*)$(@$t)*@t)\n\t} };\n}\n\npub fn readln() -> String {\n\tlet mut line = String::new();\n\t::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!(\"{}\", e));\n\tline\n}\n\nmacro_rules! read {\n\t($($t:tt),*; $n:expr) => {{\n\t\tlet stdin = ::std::io::stdin();\n\t\tlet ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {\n\t\t\tlet line = line.unwrap();\n\t\t\tlet mut it = line.split_whitespace();\n\t\t\t_read!(it; $($t),*)\n\t\t}).collect::>();\n\t\tret\n\t}};\n\t($($t:tt),*) => {{\n\t\tlet line = readln();\n\t\tlet mut it = line.split_whitespace();\n\t\t_read!(it; $($t),*)\n\t}};\n}\n\nmacro_rules! _read {\n\t($it:ident; [char]) => {\n\t\t_read!($it; String).chars().collect::>()\n\t};\n\t($it:ident; [u8]) => {\n\t\tVec::from(_read!($it; String).into_bytes())\n\t};\n\t($it:ident; usize1) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1\n\t};\n\t($it:ident; [usize1]) => {\n\t\t$it.map(|s| s.parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1).collect::>()\n\t};\n\t($it:ident; [$t:ty]) => {\n\t\t$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))).collect::>()\n\t};\n\t($it:ident; $t:ty) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))\n\t};\n\t($it:ident; $($t:tt),+) => {\n\t\t($(_read!($it; $t)),*)\n\t};\n}\n\npub fn main() {\n\tlet _ = ::std::thread::Builder::new().name(\"run\".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();\n}\n\nconst MOD: u32 = 1_000_000_007;\nconst INF: i64 = std::i64::MAX;\n\npub trait SetMinMax {\n\tfn setmin(&mut self, v: Self) -> bool;\n\tfn setmax(&mut self, v: Self) -> bool;\n}\nimpl SetMinMax for T where T: PartialOrd {\n\tfn setmin(&mut self, v: T) -> bool {\n\t\t*self > v && { *self = v; true }\n\t}\n\tfn setmax(&mut self, v: T) -> bool {\n\t\t*self < v && { *self = v; true }\n\t}\n}\n\nuse std::cmp::Ordering;\n\n/// Equivalent to std::lowerbound and std::upperbound in c++\npub trait BinarySearch {\n fn lower_bound(&self, x: &T) -> usize;\n fn upper_bound(&self, x: &T) -> usize;\n}\n\nimpl BinarySearch for [T] {\n // 配列a内のv以上の最小のindex\n fn lower_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less => {\n low = mid + 1;\n }\n Ordering::Equal | Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n // 配列a内のvより大きいの最小のindex\n fn upper_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less | Ordering::Equal => {\n low = mid + 1;\n }\n Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n}\n\nfn swap(a: usize, b: usize, sv: &mut [char], tv: &mut [char]) {\n\tlet tmp = sv[a];\n\tsv[a] = tv[b];\n\ttv[b] = tmp;\n}\n\nfn solve() {\n\tlet n = read!(i64);\n\tlet mut sum = 0;\n\tlet mut v = vec![];\n\tfor i in 2..1000001 {\n\t\tif n%i==0 {\n\t\t\tsum+=1;\n\t\t\tv.push(i);\n\t\t}\n\t}\n\tif sum==1 {\n\t\tprintln!(\"{}\", n);\n\t\treturn;\n\t}\n\tlet mi = v[0];\n\tlet mut flag = true;\n\tfor &i in &v {\n\t\tif i%mi!=0 {flag=false;}\n\t}\n\tif !flag {println!(\"{}\", 1);}\n\telse{ println!(\"{}\", mi);}\n\n}\n\nfn run() {\n solve();\n}"}, {"source_code": "#![allow(unused_imports)]\n#![allow(non_snake_case, unused)]\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::ops::*;\n\nmacro_rules! eprint {\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = write!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! eprintln {\n\t() => { eprintln!(\"\"); };\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = writeln!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! dbg {\n\t($v:expr) => {{\n\t\tlet val = $v;\n\t\teprintln!(\"[{}:{}] {} = {:?}\", file!(), line!(), stringify!($v), val);\n\t\tval\n\t}}\n}\n\nmacro_rules! mat {\n\t($($e:expr),*) => { Vec::from(vec![$($e),*]) };\n\t($($e:expr,)*) => { Vec::from(vec![$($e),*]) };\n\t($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };\n\t($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };\n}\n\nmacro_rules! ok {\n\t($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {\n\t\t$a$([$i])*.$f($($t),*)\n\t};\n\t($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {\n\t\tlet t = $e;\n\t\tok!($a$([$i])*.$f($($es),*)$(@$t)*@t)\n\t} };\n}\n\npub fn readln() -> String {\n\tlet mut line = String::new();\n\t::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!(\"{}\", e));\n\tline\n}\n\nmacro_rules! read {\n\t($($t:tt),*; $n:expr) => {{\n\t\tlet stdin = ::std::io::stdin();\n\t\tlet ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {\n\t\t\tlet line = line.unwrap();\n\t\t\tlet mut it = line.split_whitespace();\n\t\t\t_read!(it; $($t),*)\n\t\t}).collect::>();\n\t\tret\n\t}};\n\t($($t:tt),*) => {{\n\t\tlet line = readln();\n\t\tlet mut it = line.split_whitespace();\n\t\t_read!(it; $($t),*)\n\t}};\n}\n\nmacro_rules! _read {\n\t($it:ident; [char]) => {\n\t\t_read!($it; String).chars().collect::>()\n\t};\n\t($it:ident; [u8]) => {\n\t\tVec::from(_read!($it; String).into_bytes())\n\t};\n\t($it:ident; usize1) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1\n\t};\n\t($it:ident; [usize1]) => {\n\t\t$it.map(|s| s.parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1).collect::>()\n\t};\n\t($it:ident; [$t:ty]) => {\n\t\t$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))).collect::>()\n\t};\n\t($it:ident; $t:ty) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))\n\t};\n\t($it:ident; $($t:tt),+) => {\n\t\t($(_read!($it; $t)),*)\n\t};\n}\n\npub fn main() {\n\tlet _ = ::std::thread::Builder::new().name(\"run\".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();\n}\n\nconst MOD: u32 = 1_000_000_007;\nconst INF: i64 = std::i64::MAX;\n\npub trait SetMinMax {\n\tfn setmin(&mut self, v: Self) -> bool;\n\tfn setmax(&mut self, v: Self) -> bool;\n}\nimpl SetMinMax for T where T: PartialOrd {\n\tfn setmin(&mut self, v: T) -> bool {\n\t\t*self > v && { *self = v; true }\n\t}\n\tfn setmax(&mut self, v: T) -> bool {\n\t\t*self < v && { *self = v; true }\n\t}\n}\n\nuse std::cmp::Ordering;\n\n/// Equivalent to std::lowerbound and std::upperbound in c++\npub trait BinarySearch {\n fn lower_bound(&self, x: &T) -> usize;\n fn upper_bound(&self, x: &T) -> usize;\n}\n\nimpl BinarySearch for [T] {\n // 配列a内のv以上の最小のindex\n fn lower_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less => {\n low = mid + 1;\n }\n Ordering::Equal | Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n // 配列a内のvより大きいの最小のindex\n fn upper_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less | Ordering::Equal => {\n low = mid + 1;\n }\n Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n}\n\nfn swap(a: usize, b: usize, sv: &mut [char], tv: &mut [char]) {\n\tlet tmp = sv[a];\n\tsv[a] = tv[b];\n\ttv[b] = tmp;\n}\n\nfn solve() {\n\tlet n = read!(i64);\n\tlet mut sum = 0;\n\tlet mut v = vec![];\n\tif n==1 {\n\t\tprintln!(\"{}\", 1);\n\t\treturn;\n\t}\n\tfor i in 2..((n as f64).sqrt() as i64+1) {\n\t\tif n%i==0 {\n\t\t\tsum+=2;\n\t\t\tv.push(i);\n\t\t\tv.push(n%i);\n\t\t}\n\t}\n\tif sum==0 {\n\t\tprintln!(\"{}\", n);\n\t\treturn;\n\t}\n\tlet mi = v[0];\n\tlet mut flag = true;\n\tfor &i in &v {\n\t\tif i%mi!=0 {flag=false;}\n\t}\n\tif !flag {println!(\"{}\", 1);}\n\telse{ println!(\"{}\", mi);}\n\n}\n\nfn run() {\n solve();\n}"}, {"source_code": "#![allow(unused_imports)]\n#![allow(non_snake_case, unused)]\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::ops::*;\n\nmacro_rules! eprint {\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = write!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! eprintln {\n\t() => { eprintln!(\"\"); };\n\t($($t:tt)*) => {{\n\t\tuse ::std::io::Write;\n\t\tlet _ = writeln!(::std::io::stderr(), $($t)*);\n\t}};\n}\nmacro_rules! dbg {\n\t($v:expr) => {{\n\t\tlet val = $v;\n\t\teprintln!(\"[{}:{}] {} = {:?}\", file!(), line!(), stringify!($v), val);\n\t\tval\n\t}}\n}\n\nmacro_rules! mat {\n\t($($e:expr),*) => { Vec::from(vec![$($e),*]) };\n\t($($e:expr,)*) => { Vec::from(vec![$($e),*]) };\n\t($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };\n\t($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };\n}\n\nmacro_rules! ok {\n\t($a:ident$([$i:expr])*.$f:ident()$(@$t:ident)*) => {\n\t\t$a$([$i])*.$f($($t),*)\n\t};\n\t($a:ident$([$i:expr])*.$f:ident($e:expr$(,$es:expr)*)$(@$t:ident)*) => { {\n\t\tlet t = $e;\n\t\tok!($a$([$i])*.$f($($es),*)$(@$t)*@t)\n\t} };\n}\n\npub fn readln() -> String {\n\tlet mut line = String::new();\n\t::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!(\"{}\", e));\n\tline\n}\n\nmacro_rules! read {\n\t($($t:tt),*; $n:expr) => {{\n\t\tlet stdin = ::std::io::stdin();\n\t\tlet ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {\n\t\t\tlet line = line.unwrap();\n\t\t\tlet mut it = line.split_whitespace();\n\t\t\t_read!(it; $($t),*)\n\t\t}).collect::>();\n\t\tret\n\t}};\n\t($($t:tt),*) => {{\n\t\tlet line = readln();\n\t\tlet mut it = line.split_whitespace();\n\t\t_read!(it; $($t),*)\n\t}};\n}\n\nmacro_rules! _read {\n\t($it:ident; [char]) => {\n\t\t_read!($it; String).chars().collect::>()\n\t};\n\t($it:ident; [u8]) => {\n\t\tVec::from(_read!($it; String).into_bytes())\n\t};\n\t($it:ident; usize1) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1\n\t};\n\t($it:ident; [usize1]) => {\n\t\t$it.map(|s| s.parse::().unwrap_or_else(|e| panic!(\"{}\", e)) - 1).collect::>()\n\t};\n\t($it:ident; [$t:ty]) => {\n\t\t$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))).collect::>()\n\t};\n\t($it:ident; $t:ty) => {\n\t\t$it.next().unwrap_or_else(|| panic!(\"input mismatch\")).parse::<$t>().unwrap_or_else(|e| panic!(\"{}\", e))\n\t};\n\t($it:ident; $($t:tt),+) => {\n\t\t($(_read!($it; $t)),*)\n\t};\n}\n\npub fn main() {\n\tlet _ = ::std::thread::Builder::new().name(\"run\".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();\n}\n\nconst MOD: u32 = 1_000_000_007;\nconst INF: i64 = std::i64::MAX;\n\npub trait SetMinMax {\n\tfn setmin(&mut self, v: Self) -> bool;\n\tfn setmax(&mut self, v: Self) -> bool;\n}\nimpl SetMinMax for T where T: PartialOrd {\n\tfn setmin(&mut self, v: T) -> bool {\n\t\t*self > v && { *self = v; true }\n\t}\n\tfn setmax(&mut self, v: T) -> bool {\n\t\t*self < v && { *self = v; true }\n\t}\n}\n\nuse std::cmp::Ordering;\n\n/// Equivalent to std::lowerbound and std::upperbound in c++\npub trait BinarySearch {\n fn lower_bound(&self, x: &T) -> usize;\n fn upper_bound(&self, x: &T) -> usize;\n}\n\nimpl BinarySearch for [T] {\n // 配列a内のv以上の最小のindex\n fn lower_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less => {\n low = mid + 1;\n }\n Ordering::Equal | Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n // 配列a内のvより大きいの最小のindex\n fn upper_bound(&self, x: &T) -> usize {\n let mut low = 0;\n let mut high = self.len();\n\n while low != high {\n let mid = (low + high) / 2;\n match self[mid].cmp(x) {\n Ordering::Less | Ordering::Equal => {\n low = mid + 1;\n }\n Ordering::Greater => {\n high = mid;\n }\n }\n }\n low\n }\n}\n\nfn swap(a: usize, b: usize, sv: &mut [char], tv: &mut [char]) {\n\tlet tmp = sv[a];\n\tsv[a] = tv[b];\n\ttv[b] = tmp;\n}\n\nfn solve() {\n\tlet n = read!(i64);\n\tlet mut sum = 0;\n\tlet mut v = vec![];\n\tif n==1 {\n\t\tprintln!(\"{}\", 1);\n\t\treturn;\n\t}\n\tfor i in 2..1000001 {\n\t\tif n%i==0 {\n\t\t\tsum+=1;\n\t\t\tv.push(i);\n\t\t}\n\t}\n\tif sum==1 {\n\t\tprintln!(\"{}\", n);\n\t\treturn;\n\t}\n\tlet mi = v[0];\n\tlet mut flag = true;\n\tfor &i in &v {\n\t\tif i%mi!=0 {flag=false;}\n\t}\n\tif !flag {println!(\"{}\", 1);}\n\telse{ println!(\"{}\", mi);}\n\n}\n\nfn run() {\n solve();\n}"}], "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\n#![allow(unused_labels)]\n\nuse std::cmp::*;\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\nuse std::io::*;\nuse std::str::FromStr;\nuse std::char::*;\nmacro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);}}\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 flag: bool,\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 flag: true,\n vc: vec![0;n],\n }\n }\n\n fn dfs(&mut self, crt: usize) {\n self.f[crt] = true;\n self.c = self.e[crt].len() as i64;\n if self.c != 2 {\n self.flag = false;\n }\n\n for i in 0..self.e[crt].len() {\n let v = self.e[crt][i];\n if self.f[v] { continue; }\n self.dfs(v);\n }\n }\n}\n\nfn binary_search(a: &Vec) -> usize {\n let mut left = -1;\n let mut right = a.len() as i64;\n\n while right - left > 1 {\n let mid:usize = ((right+left)/2) as usize;\n //debug!(left,mid,right);\n if is_ok(mid) { right = mid as i64; }\n else { left = mid as i64; }\n }\n right as usize\n}\n\nfn is_ok(key: usize) -> bool {\n true\n}\n\nfn neighbors(tree: &BTreeSet, val: usize) -> (Option<&usize>, Option<&usize>) {\n use std::ops::Bound::*;\n\n let mut before = tree.range((Unbounded, Excluded(val)));\n let mut after = tree.range((Excluded(val), Unbounded));\n\n (before.next_back(), after.next())\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\nconst MAX_A:i64 = 1e16 as i64;\n\nfn gcd(a:i64, b:i64) -> i64 {\n if b==0 {return a;}\n gcd(b, a%b)\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\n input! {\n n: usize,\n a: [i64;n]\n }\n\n let mut ans = 0;\n let i = 0;\n if (a[i]==1 && a[i+1]==2) || (a[i]==2 && a[i+1]==1) {\n ans += 3;\n }\n else if (a[i]==1 && a[i+1]==3) || (a[i]==3 && a[i+1]==1) {\n ans += 4;\n }\n else {\n puts!(\"Infinite\\n\");\n return;\n }\n\n for i in 1..n-1 {\n if a[i]==1 && a[i+1]==2 {\n if a[i-1]==3 { ans += 2; }\n else { ans += 3; }\n }\n else if a[i]==2 && a[i+1]==1 {\n ans += 3;\n }\n else if a[i]==1 && a[i+1]==3 {\n ans += 4;\n }\n else if a[i]==3 && a[i+1]==1 {\n ans += 4;\n }\n else {\n puts!(\"Infinite\\n\");\n return;\n }\n }\n puts!(\"Finite\\n\");\n puts!(\"{}\\n\", ans);\n\n}\n\n/*\n\n\n\n*/\n\n\n\n\n\n\n", "positive_code": [{"source_code": "// https://codeforces.com/contest/1156/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\nfn main() {\n input! {\n n: usize,\n a: [usize1; n]\n };\n\n let INF = 1000000000i64;\n let table = vec![\n vec![-INF, 3, 4],\n vec![3, -INF, -INF],\n vec![4, -INF, -INF],\n ];\n\n let mut points = 0i64;\n for i in 1..n {\n points += table[a[i-1]][a[i]];\n if i >= 2 && a[i-2] == 2 && a[i-1] == 0 && a[i] == 1 {\n points -= 1;\n }\n }\n if points <= -1 {\n println!(\"Infinite\");\n } else {\n println!(\"Finite\");\n println!(\"{}\", points);\n }\n}\n"}, {"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;\ntype I = usize;\n\nfn main() {\n input!{\n n: usize,\n aa: [usize; n],\n }\n\n let mut ans: u64 = 0;\n for i in 1..n {\n let a1 = aa[i-1];\n let a2 = aa[i];\n let mut a = [a1, a2];\n a.sort();\n\n if a[0] != 1 {\n return println!(\"{}\", \"Infinite\");\n }\n\n if a[1] == 2 {\n if a2 == 2 && i>=2 && aa[i-2] == 3 {\n ans += 2;\n } else {\n ans += 3;\n }\n } else {\n ans += 4;\n }\n }\n println!(\"{}\", \"Finite\");\n println!(\"{}\", ans);\n}\n"}, {"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;\ntype I = usize;\n\nfn main() {\n input!{\n n: usize,\n aa: [usize; n],\n }\n\n let mut ans: u64 = 0;\n for i in 1..n {\n let a1 = aa[i-1];\n let a2 = aa[i];\n let mut a = [a1, a2];\n a.sort();\n\n if a[0] != 1 {\n return println!(\"{}\", \"Infinite\");\n }\n\n if a[1] == 2 {\n if a2 == 2 && i>=2 && aa[i-2] == 3 {\n ans += 2;\n } else {\n ans += 3;\n }\n } else {\n ans += 4;\n }\n }\n println!(\"{}\", \"Finite\");\n println!(\"{}\", ans);\n}"}, {"source_code": "#![allow(dead_code, unused_imports, unused_macros)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn partial_sum(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + std::ops::Add + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = *state + x;\n Some(*state)\n })\n}\n\nfn partial_max(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + Ord + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = max(*state, x);\n Some(*state)\n })\n}\n\nfn partial_min(v: impl Iterator) -> impl Iterator {\n v.scan(std::u64::MAX, |state, x| {\n *state = min(*state, x);\n Some(*state)\n })\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != 0 {\n let old_m = a;\n a = b % a;\n b = old_m;\n }\n b\n}\n\n/// returns gcd, and pair (x, y), such that x * a + b * y == gcd\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if a == 0 {\n (b, 0, 1)\n } else {\n let (g, x, y) = egcd(b % a, a);\n (g, y - (b / a) * x, x)\n }\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n if n == 0 {\n return vec![0];\n } else if n == 1 {\n return vec![1];\n }\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nfn abs_diff(a: T, b: T) -> T\nwhere\n T: PartialOrd + std::ops::Sub,\n{\n if a > b {\n a - b\n } else {\n b - a\n }\n}\n\nstruct Permutations {\n inner: Vec,\n state: Vec,\n i: usize,\n start: bool,\n}\n\nimpl Permutations {\n fn new(inner: Vec) -> Self {\n Self {\n state: vec![0; inner.len()],\n i: 0,\n start: true,\n inner,\n }\n }\n}\n\n/*impl From for Permutations\nwhere\n X: IntoIterator,\n{\n fn from(f: X) -> Self {\n Self::new(f.into_iter().collect::>())\n }\n}*/\n\nimpl Iterator for Permutations\nwhere\n T: Clone,\n{\n type Item = Vec;\n fn next(&mut self) -> Option {\n if self.start {\n self.start = false;\n return Some(self.inner.clone());\n }\n while self.i < self.inner.len() {\n if self.state[self.i] < self.i {\n if self.i % 2 == 0 {\n self.inner.swap(0, self.i)\n } else {\n self.inner.swap(self.state[self.i], self.i)\n }\n self.state[self.i] += 1;\n self.i = 0;\n return Some(self.inner.clone());\n } else {\n self.state[self.i] = 0;\n self.i += 1;\n }\n }\n None\n }\n}\n\nuse std::cmp::{max, min, Ord, Ordering};\nuse std::collections::{BinaryHeap, VecDeque};\nuse std::mem::swap;\n\nmacro_rules! max_with {\n ($x: expr, $y: expr) => {\n $x = max($x, $y)\n };\n}\n\nmacro_rules! min_with {\n ($x: expr, $y: expr) => {\n $x = max($x, $y)\n };\n}\n\nfn is_prime(n: u64) -> bool {\n factorize(n).len() == 1\n}\n\nfn combination(n: u64, k: u64, m: u64) -> u64 {\n if n == 0 {\n return 1;\n }\n if k == 0 || k == n {\n return 1;\n }\n let new_k = if n - k < k { n - k } else { k };\n let mut res = 1;\n for i in ((n - new_k) + 1)..=n {\n res *= i;\n res %= m;\n }\n let mut den = 1;\n for i in 1..=(new_k) {\n den *= i;\n den %= m;\n }\n let (_one, inverse, _c) = egcd(den as i64, m as i64);\n let inverse = if inverse < 0 {\n m as i64 + inverse\n } else {\n inverse\n } as u64;\n //println!(\"inv: {} {}\", den, inverse);\n res *= inverse;\n res %= m;\n res\n}\n\nuse std::collections::HashSet;\nuse std::iter::FromIterator;\n\nfn main() -> Result<(), Box> {\n let _n = read_usize();\n let v = read_multiple::();\n let mut points = 0;\n let mut prev2 = 0;\n let mut prev = v[0];\n for a in v.into_iter().skip(1) {\n if prev == 1 {\n if a == 2 {\n points += 3\n } else {\n points += 4;\n }\n } else if prev == 2 {\n if a == 1 {\n points += 3\n } else {\n println!(\"Infinite\");\n return Ok(());\n }\n } else {\n //prv == 3\n if a == 1 {\n points += 4\n } else {\n println!(\"Infinite\");\n return Ok(());\n }\n }\n if prev2 == 3 && prev == 1 && a == 2 {\n points -= 1;\n }\n prev2 = prev;\n prev = a;\n }\n println!(\"Finite\");\n println!(\"{}\", points);\n Ok(())\n}\n"}, {"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::{stderr, stdin, stdout, BufWriter, StdoutLock, Write};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::{i64, u64, usize};\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 ) * } } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ 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 , [ $ t : tt ] ) => { { let len = read_value ! ( $ next , usize ) ; ( 0 .. len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( \"Parse error\" ) } ; }\n#[allow(dead_code)]\nstruct Writer {\n s: String,\n}\n#[allow(unused_imports)]\nuse std::fmt::Display;\n#[allow(dead_code)]\n#[doc = \" let mut writer = Writer::new();\"]\n#[doc = \" writer.writeln(hoge);\"]\n#[doc = \" writer.flush()\"]\nimpl Writer {\n #[allow(dead_code)]\n pub fn new() -> Writer {\n Writer { s: String::new() }\n }\n #[allow(dead_code)]\n pub fn flush(&mut self) {\n print!(\"{}\", self.s);\n self.s.clear();\n }\n pub fn write(&mut self, x: T) {\n self.s.push_str(&format!(\"{}\", x));\n }\n pub fn writeln(&mut self, x: T) {\n self.s.push_str(&format!(\"{}\", x));\n self.s.push('\\n');\n }\n #[allow(dead_code)]\n pub fn write_vec(&mut self, xs: &Vec) {\n if xs.len() == 0 {\n self.writeln(\"\");\n return;\n }\n self.write(&format!(\"{}\", xs[0]));\n for i in 1..xs.len() {\n self.write(&format!(\" {}\", xs[i]));\n }\n self.writeln(\"\");\n }\n}\n#[allow(unused_macros)]\nmacro_rules ! dbg { ( $ ( $ a : expr ) ,* ) => { writeln ! ( & mut stderr ( ) , concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) . unwrap ( ) ; } }\n#[allow(dead_code)]\nconst INF_U: u64 = 1_000_000_000_000_000;\n#[allow(dead_code)]\nconst INF_I: i64 = 1_000_000_000_000_000;\n#[allow(non_snake_case)]\n#[allow(dead_code)]\nfn main() {\n input! {\n n: usize,\n a: [usize; n]\n }\n let mut ans = 0;\n let mut flag = false;\n for i in 1..n {\n dbg!(ans);\n if a[i-1] == 1 {\n if a[i] == 2 {\n if flag { ans += 2; }\n else { ans += 3; }\n } else {\n ans += 4;\n }\n } else if a[i-1] == 2 {\n if a[i] == 1 {\n ans += 3;\n } else {\n println!(\"Infinite\");\n return;\n }\n } else {\n if a[i] == 1 {\n ans += 4;\n flag = true;\n continue;\n } else {\n println!(\"Infinite\");\n return;\n }\n }\n flag = false;\n }\n println!(\"Finite\");\n println!(\"{}\", ans);\n}"}, {"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,\n a: [i32; n],\n }\n let mut cnt = 0;\n for i in 0..n - 1 {\n if a[i] + a[i + 1] == 5 {\n puts!(\"Infinite\\n\");\n return;\n }\n cnt += a[i] + a[i + 1];\n }\n for i in 0..n - 2 {\n if a[i..i + 3] == [3, 1, 2] {\n cnt -= 1;\n }\n }\n puts!(\"Finite\\n{}\\n\", 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"}, {"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:usize,\n a:[usize;n]\n }\n let mut tot = 0;\n for i in 1..n {\n let x = i-1;\n let y = i;\n match (a[x],a[y]) {\n (1,2) | (2,1) => {\n if tot != -1 {\n tot += 3\n }\n },\n (2,3) | (3,2) => {\n tot = -1\n },\n (1,3) | (3,1) => {\n if tot != -1 {\n tot += 4\n }\n },\n _ => {\n\n }\n }\n }\n if tot == -1 {\n writeln!(out,\"Infinite\");\n return\n }\n for i in 2..n {\n match (a[i-2],a[i-1],a[i]) {\n (3,1,2) => {\n tot -= 1;\n },\n _ => {}\n }\n }\n writeln!(out,\"Finite\");\n writeln!(out,\"{}\",tot);\n}"}], "negative_code": [{"source_code": "// https://codeforces.com/contest/1156/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\nfn main() {\n input! {\n n: usize,\n a: [usize1; n]\n };\n\n let INF = 1000000000i64;\n let table = vec![\n vec![-INF, 3, 4],\n vec![3, -INF, -INF],\n vec![4, -INF, -INF],\n ];\n\n let mut points = 0i64;\n for i in 1..n {\n points += table[a[i-1]][a[i]];\n }\n if points <= -1 {\n println!(\"Infinite\");\n } else {\n println!(\"Finite\");\n println!(\"{}\", points);\n }\n}\n"}, {"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;\ntype I = usize;\n\nfn main() {\n input!{\n n: usize,\n aa: [usize; n],\n }\n\n let mut ans = 0;\n for i in 1..n {\n let a1 = aa[i-1];\n let a2 = aa[i];\n let mut a = [a1, a2];\n a.sort();\n\n if a == [2, 3] {\n println!(\"{}\", \"Infinite\");\n return;\n }\n\n if a == [1, 2] {\n ans += 3;\n } else {\n ans += 4;\n }\n }\n println!(\"{}\", \"Finite\");\n println!(\"{}\", ans);\n}\n"}, {"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;\ntype I = usize;\n\nfn main() {\n input!{\n n: usize,\n aa: [usize; n],\n }\n\n let mut ans: u64 = 0;\n for i in 1..n {\n let a1 = aa[i-1];\n let a2 = aa[i];\n let mut a = [a1, a2];\n a.sort();\n\n if a[0] != 1 {\n return println!(\"{}\", \"Infinite\");\n }\n\n if a[1] == 2 {\n ans += 3;\n } else {\n ans += 4;\n }\n }\n println!(\"{}\", \"Finite\");\n println!(\"{}\", ans);\n}\n"}, {"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;\ntype I = usize;\n\nfn main() {\n input!{\n n: usize,\n aa: [usize; n],\n }\n\n let mut ans = 0;\n for i in 1..n {\n let a1 = aa[i-1];\n let a2 = aa[i];\n let mut a = [a1, a2];\n a.sort();\n\n if a[0] != 1 {\n return println!(\"{}\", \"Infinite\");\n }\n\n if a[1] == 2 {\n ans += 3;\n } else {\n ans += 4;\n }\n }\n println!(\"{}\", \"Finite\");\n println!(\"{}\", ans);\n}\n"}, {"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;\ntype I = usize;\n\nfn f(i: u64) -> u64 {\n let ss = (i+1).to_string();\n let ss: Vec = ss.chars().collect();\n let mut index = ss.len();\n for i in (0..ss.len()).rev() {\n if ss[i] == '0' {\n index = i;\n } else {\n break;\n }\n }\n let ret = &ss[0..index];\n let ret: String = ret.iter().collect();\n return ret.parse().unwrap();\n}\n\nfn main() {\n input!{\n mut n: u64,\n }\n let mut seen = std::collections::HashMap::new();\n\n let mut ans = 0;\n while !seen.contains_key(&n) {\n ans += 1;\n seen.insert(n, true);\n n = f(n);\n }\n println!(\"{}\", ans);\n}\n"}, {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\n#![allow(unused_labels)]\n\nuse std::cmp::*;\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\nuse std::io::*;\nuse std::str::FromStr;\nuse std::char::*;\nmacro_rules! debug {($($a:expr),*) => {eprintln!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);}}\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 flag: bool,\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 flag: true,\n vc: vec![0;n],\n }\n }\n\n fn dfs(&mut self, crt: usize) {\n self.f[crt] = true;\n self.c = self.e[crt].len() as i64;\n if self.c != 2 {\n self.flag = false;\n }\n\n for i in 0..self.e[crt].len() {\n let v = self.e[crt][i];\n if self.f[v] { continue; }\n self.dfs(v);\n }\n }\n}\n\nfn binary_search(a: &Vec) -> usize {\n let mut left = -1;\n let mut right = a.len() as i64;\n\n while right - left > 1 {\n let mid:usize = ((right+left)/2) as usize;\n //debug!(left,mid,right);\n if is_ok(mid) { right = mid as i64; }\n else { left = mid as i64; }\n }\n right as usize\n}\n\nfn is_ok(key: usize) -> bool {\n true\n}\n\nfn neighbors(tree: &BTreeSet, val: usize) -> (Option<&usize>, Option<&usize>) {\n use std::ops::Bound::*;\n\n let mut before = tree.range((Unbounded, Excluded(val)));\n let mut after = tree.range((Excluded(val), Unbounded));\n\n (before.next_back(), after.next())\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\nconst MAX_A:i64 = 1e16 as i64;\n\nfn gcd(a:i64, b:i64) -> i64 {\n if b==0 {return a;}\n gcd(b, a%b)\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\n input! {\n n: usize,\n a: [i64;n]\n }\n\n let mut ans = 0;\n for i in 0..n-1 {\n if (a[i]==1 && a[i+1]==2) || (a[i]==2 && a[i+1]==1) {\n ans += 3;\n }\n else if (a[i]==1 && a[i+1]==3) || (a[i]==3 && a[i+1]==1) {\n ans += 4;\n }\n else {\n puts!(\"Infinite\\n\");\n return;\n }\n }\n puts!(\"Finite\\n\");\n puts!(\"{}\\n\", ans);\n\n}\n\n/*\n\n\n\n*/\n\n\n\n\n\n\n"}, {"source_code": "#![allow(dead_code, unused_imports, unused_macros)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn partial_sum(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + std::ops::Add + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = *state + x;\n Some(*state)\n })\n}\n\nfn partial_max(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + Ord + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = max(*state, x);\n Some(*state)\n })\n}\n\nfn partial_min(v: impl Iterator) -> impl Iterator {\n v.scan(std::u64::MAX, |state, x| {\n *state = min(*state, x);\n Some(*state)\n })\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != 0 {\n let old_m = a;\n a = b % a;\n b = old_m;\n }\n b\n}\n\n/// returns gcd, and pair (x, y), such that x * a + b * y == gcd\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if a == 0 {\n (b, 0, 1)\n } else {\n let (g, x, y) = egcd(b % a, a);\n (g, y - (b / a) * x, x)\n }\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n if n == 0 {\n return vec![0];\n } else if n == 1 {\n return vec![1];\n }\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nfn abs_diff(a: T, b: T) -> T\nwhere\n T: PartialOrd + std::ops::Sub,\n{\n if a > b {\n a - b\n } else {\n b - a\n }\n}\n\nstruct Permutations {\n inner: Vec,\n state: Vec,\n i: usize,\n start: bool,\n}\n\nimpl Permutations {\n fn new(inner: Vec) -> Self {\n Self {\n state: vec![0; inner.len()],\n i: 0,\n start: true,\n inner,\n }\n }\n}\n\n/*impl From for Permutations\nwhere\n X: IntoIterator,\n{\n fn from(f: X) -> Self {\n Self::new(f.into_iter().collect::>())\n }\n}*/\n\nimpl Iterator for Permutations\nwhere\n T: Clone,\n{\n type Item = Vec;\n fn next(&mut self) -> Option {\n if self.start {\n self.start = false;\n return Some(self.inner.clone());\n }\n while self.i < self.inner.len() {\n if self.state[self.i] < self.i {\n if self.i % 2 == 0 {\n self.inner.swap(0, self.i)\n } else {\n self.inner.swap(self.state[self.i], self.i)\n }\n self.state[self.i] += 1;\n self.i = 0;\n return Some(self.inner.clone());\n } else {\n self.state[self.i] = 0;\n self.i += 1;\n }\n }\n None\n }\n}\n\nuse std::cmp::{max, min, Ord, Ordering};\nuse std::collections::{BinaryHeap, VecDeque};\nuse std::mem::swap;\n\nmacro_rules! max_with {\n ($x: expr, $y: expr) => {\n $x = max($x, $y)\n };\n}\n\nmacro_rules! min_with {\n ($x: expr, $y: expr) => {\n $x = max($x, $y)\n };\n}\n\nfn is_prime(n: u64) -> bool {\n factorize(n).len() == 1\n}\n\nfn combination(n: u64, k: u64, m: u64) -> u64 {\n if n == 0 {\n return 1;\n }\n if k == 0 || k == n {\n return 1;\n }\n let new_k = if n - k < k { n - k } else { k };\n let mut res = 1;\n for i in ((n - new_k) + 1)..=n {\n res *= i;\n res %= m;\n }\n let mut den = 1;\n for i in 1..=(new_k) {\n den *= i;\n den %= m;\n }\n let (_one, inverse, _c) = egcd(den as i64, m as i64);\n let inverse = if inverse < 0 {\n m as i64 + inverse\n } else {\n inverse\n } as u64;\n //println!(\"inv: {} {}\", den, inverse);\n res *= inverse;\n res %= m;\n res\n}\n\nuse std::collections::HashSet;\nuse std::iter::FromIterator;\n\nfn main() -> Result<(), Box> {\n let _n = read_usize();\n let v = read_multiple::();\n let mut points = 0;\n let mut prev = v[0];\n for a in v.into_iter().skip(1) {\n if prev == 1 {\n if a == 2 {\n points += 3\n } else {\n points += 4;\n }\n } else if prev == 2 {\n if a == 1 {\n points += 3\n } else {\n println!(\"Infinite\");\n return Ok(());\n }\n } else {\n //prv == 3\n if a == 1 {\n points += 4\n } else {\n println!(\"Infinite\");\n return Ok(());\n }\n }\n prev = a;\n }\n println!(\"Finite\");\n println!(\"{}\", points);\n Ok(())\n}\n"}, {"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::{stderr, stdin, stdout, BufWriter, StdoutLock, Write};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n#[allow(unused_imports)]\nuse std::{i64, u64, usize};\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 ) * } } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ 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 , [ $ t : tt ] ) => { { let len = read_value ! ( $ next , usize ) ; ( 0 .. len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , bytes ) => { read_value ! ( $ next , String ) . into_bytes ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( \"Parse error\" ) } ; }\n#[allow(dead_code)]\nstruct Writer {\n s: String,\n}\n#[allow(unused_imports)]\nuse std::fmt::Display;\n#[allow(dead_code)]\n#[doc = \" let mut writer = Writer::new();\"]\n#[doc = \" writer.writeln(hoge);\"]\n#[doc = \" writer.flush()\"]\nimpl Writer {\n #[allow(dead_code)]\n pub fn new() -> Writer {\n Writer { s: String::new() }\n }\n #[allow(dead_code)]\n pub fn flush(&mut self) {\n print!(\"{}\", self.s);\n self.s.clear();\n }\n pub fn write(&mut self, x: T) {\n self.s.push_str(&format!(\"{}\", x));\n }\n pub fn writeln(&mut self, x: T) {\n self.s.push_str(&format!(\"{}\", x));\n self.s.push('\\n');\n }\n #[allow(dead_code)]\n pub fn write_vec(&mut self, xs: &Vec) {\n if xs.len() == 0 {\n self.writeln(\"\");\n return;\n }\n self.write(&format!(\"{}\", xs[0]));\n for i in 1..xs.len() {\n self.write(&format!(\" {}\", xs[i]));\n }\n self.writeln(\"\");\n }\n}\n#[allow(unused_macros)]\nmacro_rules ! dbg { ( $ ( $ a : expr ) ,* ) => { writeln ! ( & mut stderr ( ) , concat ! ( $ ( stringify ! ( $ a ) , \" = {:?}, \" ) ,* ) , $ ( $ a ) ,* ) . unwrap ( ) ; } }\n#[allow(dead_code)]\nconst INF_U: u64 = 1_000_000_000_000_000;\n#[allow(dead_code)]\nconst INF_I: i64 = 1_000_000_000_000_000;\n#[allow(non_snake_case)]\n#[allow(dead_code)]\nfn main() {\n input! {\n n: usize,\n a: [usize; n]\n }\n let mut ans = 0;\n for i in 1..n {\n if a[i-1] == 1 {\n if a[i] == 2 {\n ans += 3;\n } else {\n ans += 4;\n }\n } else if a[i-1] == 2 {\n if a[i] == 1 {\n ans += 3;\n } else {\n println!(\"Infinite\");\n return;\n }\n } else {\n if a[i] == 1 {\n ans += 4;\n } else {\n println!(\"Infinite\");\n return;\n }\n }\n }\n println!(\"Finite\");\n println!(\"{}\", ans);\n}"}, {"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:usize,\n a:[usize;n]\n }\n let mut tot = 0;\n for i in 1..n {\n let x = i-1;\n let y = i;\n match (a[x],a[y]) {\n (1,2) | (2,1) => {\n if tot != -1 {\n tot += 3\n }\n },\n (2,3) | (3,2) => {\n tot = -1\n },\n (1,3) | (3,1) => {\n if tot != -1 {\n tot += 4\n }\n },\n (_,_) => {\n\n }\n }\n }\n if tot == -1 {\n writeln!(out,\"Infinite\");\n } else {\n writeln!(out,\"Finite\");\n writeln!(out,\"{}\",tot);\n }\n}"}], "src_uid": "6c8f028f655cc77b05ed89a668273702"} {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n let mut s = s.split_whitespace();\n let x: i32 = s.next().unwrap().parse().unwrap();\n let y: i32 = s.next().unwrap().parse().unwrap();\n let z: i32 = s.next().unwrap().parse().unwrap();\n let t1: i32 = s.next().unwrap().parse().unwrap();\n let t2: i32 = s.next().unwrap().parse().unwrap();\n let t3: i32 = s.next().unwrap().parse().unwrap();\n if (x - y).abs() * t1 < ((x - z).abs() + (x - y).abs()) * t2 + 3 * t3 {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n }\n}\n", "positive_code": [{"source_code": "fn read()->Vec{\n let mut line=String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|x|x.parse::().unwrap()).collect()\n}\nuse std::i32;\nfn main(){\n let vec=read();\n let stairs=i32::abs(vec[0]-vec[1])*vec[3];\n let lift=i32::abs(vec[0]-vec[1])*vec[4]+3*vec[5]+i32::abs(vec[0]-vec[2])*vec[4];\n if lift<=stairs{\n println!(\"YES\");\n }\n else{\n println!(\"NO\");\n }\n}"}], "negative_code": [{"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n let mut s = s.split_whitespace();\n let x: i32 = s.next().unwrap().parse().unwrap();\n let y: i32 = s.next().unwrap().parse().unwrap();\n let z: i32 = s.next().unwrap().parse().unwrap();\n let t1: i32 = s.next().unwrap().parse().unwrap();\n let t2: i32 = s.next().unwrap().parse().unwrap();\n let t3: i32 = s.next().unwrap().parse().unwrap();\n if (x - y).abs() * t1 < ((x - z).abs() + (x - y).abs()) * t2 + 2 * t3 {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n }\n}\n"}], "src_uid": "05cffd59b28b9e026ca3203718b2e6ca"} {"source_code": "use std::io;\n\nfn bs(f: F, mut mi: i64, mut ma: i64) -> i64\nwhere\n F: Fn(i64) -> bool,\n{\n let mut mm = 0;\n while mi < ma {\n mm = (mi + ma) / 2;\n if f(mm) {\n mi = mm + 1;\n } else {\n ma = mm;\n }\n }\n if f(mm) {\n mm + 1\n } else {\n mm\n }\n}\n\n#[allow(dead_code)]\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!(i64);\n let k = read!(i64);\n\n let f = |i| {\n let mut u: i64 = 0;\n let mut kk = 1;\n while kk <= i {\n u += i / kk;\n kk *= k;\n }\n u < n\n };\n\n let r = bs(f, 0, n);\n rr.push(format!(\"{}\", r));\n }\n\n rr\n}\n\n#[allow(dead_code)]\nfn main() {\n let output = solve();\n println!(\"{}\", output.join(\"\\n\"));\n}\n", "positive_code": [{"source_code": "fn is_sufficient(v: u64, n: u64, k: u64) -> bool {\n let summand_count = ((v as f64).log(k as f64).trunc() + 1_f64) as usize;\n // dbg!(summand_count);\n let sum: u64 = (0..summand_count).map(|x| v / k.checked_pow(x as u32).unwrap()).sum();\n // dbg!(sum);\n sum >= n\n}\n\nfn solve(n: u64, k: u64) -> u64 {\n let mut l: u64 = 1;\n let mut r: u64 = n + 1;\n while r - l > 2 {\n let m = l + (r - l) / 2;\n // dbg!(l, m, r);\n if is_sufficient(m, n, k) {\n // dbg!(\"YES\");\n r = m + 1;\n } else {\n // dbg!(\"NO\");\n l = m;\n }\n }\n // dbg!(is_sufficient(4, n, k));\n if is_sufficient(l, n, k) {l} else {l + 1}\n}\n\nfn main() {\n let (n, k) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut n_k = buf.trim().split_whitespace().map(|x| x.parse::().unwrap());\n let n = n_k.next().unwrap();\n let k = n_k.next().unwrap();\n (n, k)\n };\n\n println!(\"{}\", solve(n, k));\n}\n"}], "negative_code": [], "src_uid": "41dfc86d341082dd96e089ac5433dc04"} {"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 n = read!(inf,usize) * 2;\n\tlet mut w = vec![0usize; n];\n\tfor i in 0..n {\n\t\tw[i] = read!(inf,usize);\n\t}\n\tw.sort();\n\tlet mut ans = MOD;\n\tfor i in 0..n {\n\t\tfor j in i + 1..n {\n\t\t\tlet mut v = Vec::new();\n\t\t\tfor k in 0..n {\n\t\t\t\tif k != i && k != j {\n\t\t\t\t\tv.push(w[k]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet mut pos = 0;\n\t\t\tlet mut p = 0;\n\t\t\twhile pos < v.len() {\n\t\t\t\tp += v[pos + 1] - v[pos];\n\t\t\t\tpos += 2;\n\t\t\t}\n\t\t\tans = min(ans, p);\n\t\t}\n\t}\n\twriteln!(ouf, \"{}\", ans);\n}", "positive_code": [{"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\n where 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 mut w: Vec = get_vec();\n\n w.sort();\n\n let mut ans = None;\n\n for i in 0..2 * n {\n for j in i + 1..2 * n {\n let mut v = w.clone();\n v.remove(j);\n v.remove(i);\n let cur = v.into_iter().fold((0, false), |acc, x| {\n (if acc.1 {\n acc.0 + x\n } else {\n acc.0 - x\n },\n !acc.1)\n }).0;\n\n match ans {\n Some(x) if x <= cur => (),\n _ => ans = Some(cur),\n };\n }\n }\n\n println!(\"{}\", ans.unwrap());\n}\n"}], "negative_code": [{"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 n = read!(inf,usize);\n\tlet mut w = vec![0usize; 2 * n];\n\tfor i in 0..2 * n {\n\t\tw[i] = read!(inf,usize);\n\t}\n\tw.sort();\n\tlet mut ans = MOD;\n\tfor i in 0..3 {\n\t\tlet mut pos = i;\n\t\tlet mut p = 0;\n\t\twhile pos < 2 * n - 2 + i {\n\t\t\tp += w[pos + 1] - w[pos];\n\t\t\tpos += 2;\n\t\t}\n\t\tans = min(ans, p);\n\t}\n\twriteln!(ouf, \"{}\", ans);\n}"}, {"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\n where 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 mut w: Vec = get_vec();\n\n w.sort();\n\n let ans = min(w[2 * n - 3] - w[0], w[2 * n - 2] - w[1]);\n let ans = min(ans, w[2 * n - 1] - w[2]);\n\n println!(\"{}\", ans);\n}\n"}, {"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\n where 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 mut w: Vec = get_vec();\n\n w.sort();\n\n let ans = (0..3).map(|i| {\n w.iter().cloned().skip(i).take(2 * (n - 1)).fold((0, false), |acc, x| {\n (if acc.1 {\n acc.0 + x\n } else {\n acc.0 - x\n }, !acc.1)\n }).0\n }).min().unwrap();\n\n println!(\"{}\", ans);\n}\n"}], "src_uid": "76659c0b7134416452585c391daadb16"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap};\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 seq: Vec = util::line().chars().collect();\n\n let l = seq.iter().filter(|&&c| c == 'L').count();\n let r = seq.iter().filter(|&&c| c == 'R').count();\n let u = seq.iter().filter(|&&c| c == 'U').count();\n let d = seq.iter().filter(|&&c| c == 'D').count();\n\n println!(\"{}\", 2 * min(l, r) + 2 * min(u, d));\n}\n", "positive_code": [{"source_code": "use std::collections::HashMap;\n\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\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\nfn main() {\n input! {\n _n: usize,\n commands: chars,\n }\n\n let mut num_command = HashMap::new();\n\n commands\n .iter()\n .for_each(|x| *num_command.entry(x).or_insert(0) += 1);\n\n let num_l = *num_command.get(&'L').unwrap_or(&0);\n let num_r = *num_command.get(&'R').unwrap_or(&0);\n let num_u = *num_command.get(&'U').unwrap_or(&0);\n let num_d = *num_command.get(&'D').unwrap_or(&0);\n\n println!(\n \"{}\",\n std::cmp::min(num_l * 2, num_r * 2) + std::cmp::min(num_u * 2, num_d * 2)\n );\n}\n"}, {"source_code": "\nfn main() {\n let mut ri = ReadIn::new();\n let n = ri.int();\n ri.read_line();\n let s = ri.0;\n let mut c1 = 0;\n let mut c2 = 0;\n for c in s.chars() {\n if c == 'L' {\n c1 -= 1;\n }\n if c == 'R' {\n c1 += 1;\n }\n if c == 'U' {\n c2 -= 1;\n }\n if c == 'D' {\n c2 += 1;\n }\n }\n if c1 < 0 {\n c1 = -c1;\n }\n if c2 < 0 {\n c2 = -c2;\n }\n println!(\"{}\", n - c1 - c2);\n}\n\nuse std::iter::Map;\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 {\n ReadIn(String::new())\n }\n fn read_i32(s: &str) -> i32 {\n s.parse().unwrap()\n }\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 int(&mut self) -> i32 {\n self.ints().next().unwrap()\n }\n pub fn int2(&mut self) -> (i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap())\n }\n}\n"}, {"source_code": "use std::cmp::min;\nuse std::io::stdin;\nfn main() {\n let mut _text = String::new();\n stdin().read_line(&mut _text).unwrap();\n let (uc, dc, rc, lc) = command_counter(parse());\n let counter = min(uc, dc) * 2 + min(lc, rc) * 2;\n println!(\"{}\", counter)\n}\n#[derive(Debug, Copy, Clone)]\nenum Command {\n U,\n D,\n L,\n R,\n}\n\nfn parse() -> Vec {\n let mut text = String::new();\n stdin().read_line(&mut text).unwrap();\n let fu = |e: char| -> Command {\n match e {\n 'U' => Command::U,\n 'D' => Command::D,\n 'L' => Command::L,\n _ => Command::R,\n }\n };\n let text: Vec = text.trim().chars().map(fu).collect();\n text\n}\nfn command_counter(arr: Vec) -> (usize, usize, usize, usize) {\n let mut uc = 0;\n let mut dc = 0;\n let mut lc = 0;\n let mut rc = 0;\n for i in arr {\n match i {\n Command::U => uc += 1,\n Command::D => dc += 1,\n Command::L => lc += 1,\n Command::R => rc += 1,\n }\n }\n (uc, dc, rc, lc)\n}\n"}, {"source_code": "use std::cmp::min;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_t(stdin : &Stdin) -> T {\n let mut line = String::new();\n read_line(stdin, &mut line);\n parse_t(&line)\n}\n\nfn max_moves(moves : &str) -> usize {\n let lrud = \"LRUD\".as_bytes();\n let left = lrud[0];\n let right = lrud[1];\n let up = lrud[2];\n let down = lrud[3];\n let mut num_left = 0;\n let mut num_right = 0;\n let mut num_up = 0;\n let mut num_down = 0;\n for &b in moves.as_bytes().iter() {\n if b == left {\n num_left = num_left + 1;\n } else if b == right {\n num_right = num_right + 1;\n } else if b == up {\n num_up = num_up + 1;\n } else if b == down {\n num_down = num_down + 1;\n } else {\n panic!(\"Unknown move!\");\n }\n }\n let x = min(num_left, num_right);\n let y = min(num_up, num_down);\n x + x + y + y\n}\n\nfn main() {\n let stdin = io::stdin();\n let _ : usize = read_t(&stdin);\n let mut moves = String::new();\n read_line(&stdin, &mut moves);\n let moves = moves.trim();\n let x = max_moves(moves);\n println!(\"{}\", x);\n}\n"}], "negative_code": [{"source_code": "use std::io::stdin;\nfn main() {\n let mut _text = String::new();\n stdin().read_line(&mut _text).unwrap();\n let commands = parse();\n let mut robot = Robot::new();\n let mut counter = 0;\n let mut results = vec!(0);\n for i in commands {\n robot.obey(i);\n counter +=1;\n if robot.x ==0 && robot.y ==0 {\n results.push(counter); \n }\n }\n println!(\"{}\",results[results.len()-1])\n \n}\nenum Command {\n U,\n D,\n L,\n R,\n}\nstruct Robot {\n x: usize,\n y: usize,\n}\nimpl Robot {\n fn new() -> Robot {\n Robot { x: 0, y: 0 }\n }\n fn obey(&mut self, c: Command) {\n match c {\n Command::U => {\n self.y += 1;\n }\n Command::D => {\n self.y -= 1;\n }\n Command::L => {\n self.x -= 1;\n }\n Command::R => {\n self.x += 1;\n }\n };\n }\n}\n\nfn parse() -> Vec {\n let mut text = String::new();\n stdin().read_line(&mut text).unwrap();\n let fu = |e: char| -> Command {\n match e {\n 'U' => Command::U,\n 'D' => Command::D,\n 'L' => Command::L,\n _ => Command::R,\n }\n };\n let text: Vec = text.trim().chars().map(fu).collect();\n text\n}\n"}], "src_uid": "b9fa2bb8001bd064ede531a5281cfd8a"} {"source_code": "use std::io::stdin;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n stdin().read_line(&mut a).unwrap();\n stdin().read_line(&mut b).unwrap();\n let a: Vec = a.trim().chars().collect();\n let b: Vec = b.trim().chars().collect();\n\n let mut answer = String::new();\n\n for i in 0..a.len() {\n if a[i] != b[i] {\n answer.push_str(\"1\");\n } else {\n answer.push_str(\"0\");\n }\n }\n\n println!(\"{}\", answer);\n}\n", "positive_code": [{"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($($n:expr, $T:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n ($({let mut v = Vec::new(); v.reserve(($n) as usize);\n for _ in 0..$n { let t = s.next(); if t == None { break; }\n v.push(t.unwrap().parse::<$T>().unwrap()); } v }),+)\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n scan!(String).chars().zip(scan!(String).chars()).map(|(x, y)| if x == y { 0 } else { 1 }).for_each(|x| print!(\"{}\", x));\n}\n"}, {"source_code": "fn 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 let a = input();\n let b = input();\n let res = a\n .chars()\n .zip(b.chars())\n .map(|(a, b)| if a == b { '0' } else { '1' })\n .collect::();\n println!(\"{}\", res)\n}"}, {"source_code": "//spnauti-rust\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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 input.ab().into_iter().zip(input.ab().into_iter()).for_each(|(a,b)| {\n print!(\"{}\", if a != b {1} else {0})\n });\n}\n\n"}, {"source_code": "fn main() {\n let a = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().to_string()\n };\n let b = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().to_string()\n };\n\n let ret: String = a.chars()\n .zip(b.chars())\n .map(|(x, y)| if x == y { '0' } else { '1' })\n .collect();\n println!(\"{}\", ret);\n}\n"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut iterator = stdin.lock().lines();\n let first = iterator.next().unwrap().unwrap();\n let second = iterator.next().unwrap().unwrap();\n\n let first_vec: Vec = first.chars().collect();\n let second_vec: Vec = second.chars().collect();\n\n let mut result = Vec::new();\n\n for i in 0..first_vec.len() {\n if first_vec[i] != second_vec[i] {\n result.push(\"1\");\n } else {\n result.push(\"0\");\n }\n }\n\n println!(\"{}\", result.join(\"\"));\n}"}, {"source_code": "use std::io::stdin;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n stdin().read_line(&mut a).unwrap();\n stdin().read_line(&mut b).unwrap();\n let a: Vec = a.trim().chars().collect();\n let b: Vec = b.trim().chars().collect();\n\n let mut answer = String::new();\n\n for i in 0..a.len() {\n if a[i] != b[i] {\n answer.push_str(\"1\");\n } else {\n answer.push_str(\"0\");\n }\n }\n\n println!(\"{}\", answer); //Hola\n}\n"}, {"source_code": "use std::io;\n\nfn read_line() -> String {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n}\n\nfn main() {\n let l1 = read_line();\n let l2 = read_line();\n let ans = l1.chars().zip(l2.chars()).map(|(c1, c2)| if c1 == c2 { '0' } else { '1' }).collect::();\n println!(\"{}\", ans);\n}\n"}, {"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 bits(i: impl Iterator) -> impl Iterator {\n i.map(|x| x == '0')\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 input1: String = read(sin);\n let input2: String = read(sin);\n\n let ans: String = bits(input1.as_str().chars())\n .zip(bits(input2.as_str().chars()))\n .map(|x| x.0 ^ x.1)\n .map(|x| if x { '1' } else { '0' })\n .collect();\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/61/A\nuse std::io;\n\nfn main() {\n let mut a = String::new();\n\n io::stdin()\n .read_line(&mut a)\n .unwrap();\n\n let a = a.trim();\n\n let a: Vec = a.chars().collect();\n\n let mut b = String::new();\n\n io::stdin()\n .read_line(&mut b)\n .unwrap();\n\n let b = b.trim();\n\n let b: Vec = b.chars().collect();\n\n let mut answer = String::from(\"\");\n\n for i in 0..a.len() {\n if a[i] == b[i] {\n answer.push_str(\"0\");\n } else {\n answer.push_str(\"1\");\n }\n }\n println!(\"{}\", answer);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/61/A\n// implementation, simulation\nuse std::io;\n\nfn main() {\n let mut a = String::new();\n\n io::stdin()\n .read_line(&mut a)\n .unwrap();\n\n let a = a.trim();\n\n let mut b = String::new();\n\n io::stdin()\n .read_line(&mut b)\n .unwrap();\n\n let b = b.trim();\n\n let mut iter = b.chars();\n\n let mut answer = String::from(\"\");\n\n for ch in a.chars() {\n if ch == iter.next().unwrap() {\n answer.push_str(\"0\");\n } else {\n answer.push_str(\"1\");\n }\n }\n\n println!(\"{}\", answer);\n}\n\n"}, {"source_code": "use std::io::{self, Read};\n\nfn get_input() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Failed\");\n buffer\n}\n\nfn main() -> io::Result<()> {\n let input1 = get_input().trim().to_string();\n let input2 = get_input().trim().to_string();\n\n for i in 0..input1.len() {\n let c1 = input1.chars().nth(i);\n let c2 = input2.chars().nth(i);\n if c1 == c2 {\n print!(\"{}\", 0);\n } else {\n print!(\"{}\", 1);\n }\n }\n print!(\"\\n\");\n\n Ok(())\n}\n"}, {"source_code": "use std::io::{self, prelude::*};\n\n\n#[allow(unused_must_use)]\nfn solve(mut scan: Scanner, mut w: W) {\n let a: Vec = scan.token::().chars().collect();\n let b: Vec = scan.token::().chars().collect();\n\n let mut c: Vec = Vec::new();\n\n for (i, _) in a.iter().enumerate() {\n if a[i] == b[i] {\n c.push('0');\n } else {\n c.push('1');\n }\n }\n\n let ans: String = c.into_iter().collect();\n \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"}, {"source_code": "use std::io;\n\nfn main() {\n let mut s = vec![String::new(), String::new()];\n for i in 0..2 {\n io::stdin().read_line(&mut s[i as usize]).unwrap();\n s[i as usize] = s[i as usize].trim().to_string(); \n }\n for i in 0..s[0].len() {\n if s[0].chars().nth(i) != s[1].chars().nth(i) {\n print!(\"1\");\n } else {\n print!(\"0\");\n }\n }\n}"}, {"source_code": "\n#![allow(unused_imports)]\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::BufReader;\nuse std::str::FromStr;\n\nfn main() {\n let mut first = String::new();\n let mut second = String::new();\n io::stdin().read_line(&mut first).unwrap();\n io::stdin().read_line(&mut second).unwrap();\n let fir: Vec = first.chars().filter(|c| c.is_digit(2)).collect();\n let sec: Vec = second.chars().filter(|c| c.is_digit(2)).collect();\n let mut out = vec!['_'; fir.len()];\n\n for i in 0..fir.len() {\n if fir[i] == sec[i] {\n out[i] = '0';\n } else {\n out[i] = '1';\n }\n }\n\n println!(\"{}\", out.iter().collect::());\n}\n\n"}, {"source_code": "use std::str::FromStr;\nuse std::fmt::Debug;\n\nfn main() {\n let num_1 = read_line().to_vec_chars();\n let num_2 = read_line().to_vec_chars();\n let mut s = String::with_capacity(num_1.len());\n \n for i in 0..num_1.len() {\n if num_1[i] == num_2[i] {\n s.push('0')\n } else {\n s.push('1')\n }\n }\n println!(\"{}\", s);\n}\n\nfn read_line() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Ошибка чтения\");\n\n buffer.trim().to_string()\n}\n\ntrait ParseStr {\n fn to_vec(&self, separator: &str) -> Vec\n where\n T: FromStr,\n ::Err: std::fmt::Debug;\n\n fn to_vec_chars(&self) -> Vec;\n\n fn to(&self) -> T\n where\n T: FromStr + Copy,\n ::Err: Debug;\n}\n\nimpl ParseStr for String {\n \n fn to_vec(&self, separator: &str) -> Vec\n where\n T: FromStr,\n ::Err: Debug,\n {\n self.split(separator).map(|c| c.parse::().expect(\"Ошибка преобразования\")).collect()\n }\n\n fn to_vec_chars(&self) -> Vec {\n self.chars().collect()\n }\n\n fn to(&self) -> T\n where\n T: FromStr + Copy,\n ::Err: Debug,\n {\n ParseStr::to_vec::(self, \" \")[0]\n }\n}"}, {"source_code": "fn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn main() {\n let (length, a): (usize, u128) = {\n let s: String = read_str();\n (s.len(), u128::from_str_radix(&s[..], 2).expect(\"Error\"))\n };\n let b: u128 = {\n let s: String = read_str();\n u128::from_str_radix(&s[..], 2).expect(\"Error\")\n };\n\n print!(\"{:01$b}\", a ^ b, length);\n}"}, {"source_code": "use 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 print_result(s_1 : &String, s_2 : &String) {\n let pair_iter = s_1.trim().chars().zip(s_2.trim().chars());\n for (a, b) in pair_iter {\n if a == b {\n print!(\"0\");\n } else {\n print!(\"1\");\n }\n }\n println!();\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut s_1 = String::new();\n let mut s_2 = String::new();\n read_line(&stdin, &mut s_1);\n read_line(&stdin, &mut s_2);\n print_result(&s_1, &s_2);\n}\n"}, {"source_code": "fn main() {\n let s: Vec = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim_end().chars().collect()\n };\n let t: Vec = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim_end().chars().collect()\n };\n\n let n = s.len();\n let mut ans = String::new();\n\n for i in 0..n {\n ans.push(if s.get(i) != t.get(i) { '1' } else { '0' });\n }\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "fn main() {\n let mut a = String::new();\n std::io::stdin().read_line(&mut a).unwrap();\n let mut b = String::new();\n std::io::stdin().read_line(&mut b).unwrap();\n\n for i in 0..a.trim().len() {\n if a.as_bytes()[i] != b.as_bytes()[i] {\n print!(\"1\");\n }\n else {\n print!(\"0\");\n }\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut string1 = String::new();\n\tio::stdin().read_line(&mut string1).unwrap();\n\tlet string1 = string1.trim();\n\n\tlet mut string2 = String::new();\n\tio::stdin().read_line(&mut string2).unwrap();\n\tlet string2 = string2.trim();\n\n\tfor i in 0..string1.len() {\n\t\tif string1.chars().nth(i) != string2.chars().nth(i) {\n\t\t\tprint!(\"1\");\n\t\t} else {\n\t\t\tprint!(\"0\");\n\t\t}\n\t}\n\tprintln!();\n}\n"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut input1 = String::new();\n let mut input2 = String::new();\n\n stdin.lock().read_line(&mut input1).unwrap();\n stdin.lock().read_line(&mut input2).unwrap();\n\n for (i, j) in input1.trim().chars().zip(input2.trim().chars()) {\n if i == j {\n print!(\"0\");\n } else {\n print!(\"1\");\n }\n }\n println!();\n}\n"}, {"source_code": "use std::io;\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 main() {\n let s = read_line();\n let t = read_line();\n\n for (ps, pt) in s.chars().zip(t.chars()) {\n if ps == pt {\n print!(\"0\");\n } else {\n print!(\"1\");\n }\n \n }\n \n}"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\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 out = &mut BufWriter::new(stdout());\n\n\tlet a = scan.next::();\n\tlet b = scan.next::();\n let ab = a.as_bytes();\n let bb = b.as_bytes();\n\n for i in 0..ab.len() {\n write!(out, \"{}\", ab[i] ^ bb[i]).expect(\"fail\");\n }\n\n writeln!(out, \"\").expect(\"fail\");\n}\n"}], "negative_code": [{"source_code": "fn main() {\n let a = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().to_string()\n };\n let b = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().to_string()\n };\n let x = i32::from_str_radix(&a, 2).unwrap();\n let y = i32::from_str_radix(&b, 2).unwrap();\n let z = x ^ y;\n \n println!(\"{}\", format!(\"{:b}\", z));\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n stdin().read_line(&mut a).unwrap();\n stdin().read_line(&mut b).unwrap();\n let a: Vec = a.chars().collect();\n let b: Vec = b.chars().collect();\n\n let mut answer = String::new();\n\n for i in 0..a.len() {\n if a[i] != b[i] {\n answer.push_str(\"1\");\n } else {\n answer.push_str(\"0\");\n }\n }\n\n println!(\"{}\", answer);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut string1 = String::new();\n\tio::stdin().read_line(&mut string1).unwrap();\n\n\tlet mut string2 = String::new();\n\tio::stdin().read_line(&mut string2).unwrap();\n\n\tfor i in 0..(string1.len()-1) {\n\t\tif string1.chars().nth(i) == string2.chars().nth(i) {\n\t\t\tprint!(\"0\");\n\t\t} else {\n\t\t\tprint!(\"1\");\n\t\t}\n\t}\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut string1 = String::new();\n\tio::stdin().read_line(&mut string1).unwrap();\n\n\tlet mut string2 = String::new();\n\tio::stdin().read_line(&mut string2).unwrap();\n\n\tfor i in 0..(string1.len()-1) {\n\t\tif string1.chars().nth(i) == string2.chars().nth(i) {\n\t\t\tprint!(\"0\");\n\t\t} else {\n\t\t\tprint!(\"1\");\n\t\t}\n\t}\n\tprintln!();\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut string1 = String::new();\n\tio::stdin().read_line(&mut string1).unwrap();\n\n\tlet mut string2 = String::new();\n\tio::stdin().read_line(&mut string2).unwrap();\n\n\tfor i in 0..string1.len()-1 {\n\t\tif string1.chars().nth(i) == string2.chars().nth(i) {\n\t\t\tprint!(\"0\");\n\t\t} else {\n\t\t\tprint!(\"1\");\n\t\t}\n\t}\n\tprintln!();\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut string1 = String::new();\n\tio::stdin().read_line(&mut string1).unwrap();\n\n\tlet mut string2 = String::new();\n\tio::stdin().read_line(&mut string2).unwrap();\n\n\tfor i in 0..string1.len()-1 {\n\t\tif string1.chars().nth(i) != string2.chars().nth(i) {\n\t\t\tprint!(\"1\");\n\t\t} else {\n\t\t\tprint!(\"0\");\n\t\t}\n\t}\n\tprintln!();\n}\n"}], "src_uid": "3714b7596a6b48ca5b7a346f60d90549"} {"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 n: usize = sc.ne();\n for _ in 0..n + 1 {\n let _: String = sc.ne();\n }\n println!(\"{}\",\n match n & 1 {\n 1 => \"contest\",\n _ => \"home\",\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", "positive_code": [{"source_code": "use std::collections::HashMap;\nuse std::io::{self};\nuse std::str::FromStr;\nuse std::process;\n\nfn main() {\n let mut buffer = String::new();\n let mut nbuff = String::new();\n let mut flights: HashMap<&str, i8> = HashMap::new();\n let stdin = io::stdin();\n\n stdin.read_line(&mut buffer).expect(\"Cannot_read_data1!!!\");\n stdin.read_line(&mut buffer).expect(\"Cannot_read_dat2!!!\");\n let lines: Vec<&str> = buffer.trim().split(\"\\n\").collect();\n\n let n: i8 = FromStr::from_str(lines[0].trim()).unwrap();\n\n let home = lines[1];\n let mut home_vec: Vec<&str> = vec![];\n\n for _ in 0..n {\n stdin.read_line(&mut nbuff).expect(\"Cannot_read_dat3!!!\");\n }\n\n let nlines: Vec<&str> = nbuff.trim().split(\"\\n\").collect();\n\n for x in &nlines {\n let points: Vec<&str> = x.trim().split(\"->\").collect();\n\n if *points[0] == *home {\n home_vec.push(points[1]);\n } else {\n if flights.contains_key(points[0]) {\n if let Some(y) = flights.get_mut(points[0]) {\n *y += 1;\n }\n } else {\n flights.insert(points[0], 1);\n }\n }\n }\n\n let mut result = \"home\";\n\n for x in &home_vec {\n if !flights.contains_key(x) {\n result = \"contest\";\n break;\n } else {\n if let Some(y) = flights.get_mut(x) {\n if *y == 0 {\n result = \"contest\";\n break;\n }\n *y -= 1;\n }\n }\n }\n\n println!(\"{}\", result);\n process::exit(0);\n\n}\n"}], "negative_code": [], "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"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 let sol = if n % 2 == 1 {\n 0\n } else {\n (n - 2) / 4\n };\n println!(\"{}\", sol);\n}\n\n", "positive_code": [{"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 = 100006;\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:i64};\n if n%2 != 0 {\n println!(\"0\");\n return();\n }\n println!(\"{}\", (n/2-1)/2);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "use std::io;\n\nmacro_rules! parse_line {\n ($($t: ty),+) => ({\n let mut a_str = String::new();\n io::stdin().read_line(&mut a_str).unwrap();\n let mut a_iter = a_str.split_whitespace();\n (\n $(\n a_iter.next().unwrap().parse::<$t>().unwrap(),\n )+\n )\n })\n}\n\nfn main() {\n let (mut n,) = parse_line!(u32);\n if n % 2 != 0 {\n println!(\"{}\", 0);\n return;\n }\n n /= 2;\n println!(\"{}\", n / 2 - ((n % 2) ^ 1));\n}\n"}], "negative_code": [], "src_uid": "32b59d23f71800bc29da74a3fe2e2b37"} {"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 n = read!(inf,i32);\n\tlet mut s = (n as f64).sqrt() as i32;\n\tif s * s < n {\n\t\ts += 1;\n\t}\n\n\twriteln!(ouf, \"{}\", 2 * (s + ((n + s - 1) / s)));\n}", "positive_code": [{"source_code": "fn main() {\n let mut sc = new(std::io::stdin());\n let n: usize = sc.next();\n let mut res = 1_000_000_000;\n for h in 1..(n + 1) {\n let w = (n + h - 1) / h;\n\n if (h + w) * 2 < res {\n res = (h + w) * 2;\n }\n }\n println!(\"{}\", res);\n}\n\nuse std::io;\nuse std::io::BufRead;\n\npub struct Scanner {\n br: io::BufReader,\n // Read tokens are stored in reversed order per line.\n buf: Vec,\n}\n\npub fn new(r: R) -> Scanner {\n Scanner::new(r)\n}\n\nimpl Scanner {\n #[inline]\n fn new(r: R) -> Scanner {\n Scanner {\n br: io::BufReader::new(r),\n buf: vec![],\n }\n }\n #[inline]\n pub fn next(&mut self) -> T\n where T: std::str::FromStr,\n T::Err: std::fmt::Debug\n {\n self.next_string().map(|s| s.parse::().expect(\"Parse failed: \")).unwrap()\n }\n fn next_string(&mut self) -> Option {\n self.buf.pop().or_else(|| match self.update() {\n true => self.next_string(),\n false => None,\n })\n }\n #[inline]\n fn update(&mut self) -> bool {\n let mut s = String::new();\n let res = self.br.read_line(&mut s);\n match res.expect(\"I/O error.\") {\n 0 => false,\n _ => {\n self.buf = s.split_whitespace().map(|x| x.to_string()).rev().collect();\n true\n }\n }\n }\n}\n"}, {"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 main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let n = scan!(s, usize);\n let max_n = 1000000;\n let mut squares = vec![2*max_n; 2001];\n squares[0] = 0;\n\n let mut i = 1;\n while i*i <= max_n {\n squares[i] = i*i;\n i += 1;\n }\n\n while squares[i] > n {\n i -= 1;\n }\n\n let mut result = 4*i;\n let diff = n - squares[i];\n if diff > 0 {\n if diff > i {\n result += 4;\n } else {\n result += 2; \n }\n }\n \n\n println!(\"{}\", result);\n}"}], "negative_code": [], "src_uid": "414cc57550e31d98c1a6a56be6722a12"} {"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: usize,\n A: [i64; N]\n }\n\n let mut ans = 0;\n\n for i in 0..N {\n for j in i..N{\n let mut cnt = 0;\n for x in 0..N{\n if (x < i || j < x) && A[x]==1 {\n cnt += 1;\n } else if i <= x && x <= j && A[x]==0 {\n cnt += 1;\n }\n }\n ans = max(ans,cnt);\n }\n }\n\n println!(\"{}\", ans);\n}", "positive_code": [{"source_code": "use std::io::{stdin, BufRead};\n\nfn get_max_delta(values: &Vec) -> Option<(T, usize, usize)>\nwhere\n T: Ord,\n T: Copy,\n T: std::ops::Sub,\n{\n if values.len() <= 1 {\n return None;\n }\n\n let mut min_positions: Vec = Vec::new();\n let mut max_positions: Vec = Vec::new();\n\n min_positions.push(0);\n max_positions.push(1);\n\n for i in 1..(values.len() - 1) {\n let value = values[i];\n let prev_value = values[i - 1];\n let next_value = values[i + 1];\n\n if (value >= prev_value) && (value >= next_value) {\n max_positions.push(i);\n }\n if (value <= prev_value) && (value <= next_value) {\n min_positions.push(i);\n }\n }\n\n min_positions.push(values.len() - 1);\n if values.len() > 2 {\n max_positions.push(values.len() - 1);\n }\n\n let mut max_delta: Option<(T, usize, usize)> = None;\n let mut max_position_index: usize = 0;\n\n for i in 0..min_positions.len() {\n let min_position = min_positions[i];\n let min_position_value = values[min_position];\n while max_positions[max_position_index] <= min_positions[i] {\n max_position_index += 1;\n if max_position_index >= max_positions.len() {\n break;\n }\n }\n if max_position_index >= max_positions.len() {\n break;\n }\n for j in max_position_index..max_positions.len() {\n let max_position = max_positions[j];\n let max_position_value = values[max_position];\n let delta_value = max_position_value - min_position_value;\n if let Some((max_delta_value, _max_delta_start, _max_delta_end)) = max_delta {\n if delta_value > max_delta_value {\n max_delta = Some((delta_value, min_position, max_position));\n }\n } else {\n max_delta = Some((delta_value, min_position, max_position));\n }\n }\n }\n\n return max_delta;\n}\n\nfn get_best_score(values: &Vec) -> usize {\n let mut switch_scores: Vec = Vec::with_capacity(values.len() + 1);\n switch_scores.push(0);\n let mut current_switch_score: isize = 0;\n let mut base_score: usize = 0;\n for &value in values {\n if value == 0 {\n current_switch_score += 1;\n } else {\n current_switch_score -= 1;\n base_score += 1;\n }\n switch_scores.push(current_switch_score);\n }\n\n let (max_switch_score, _, _) = get_max_delta(&switch_scores).unwrap();\n\n return ((base_score as isize) + max_switch_score) as usize;\n}\n\n#[cfg(test)]\nmod tests {\n use super::{get_best_score, get_max_delta};\n\n #[test]\n fn test_get_best_score_1() {\n assert_eq!(get_best_score(&vec![1, 0, 0, 1, 0]), 4);\n }\n #[test]\n fn test_get_best_score_2() {\n assert_eq!(get_best_score(&vec![1, 0, 0, 1]), 4);\n }\n #[test]\n fn test_get_best_score_3() {\n assert_eq!(get_best_score(&vec![1, 0, 1, 0, 1, 0]), 4);\n }\n #[test]\n fn test_get_best_score_4() {\n assert_eq!(get_best_score(&vec![1]), 0);\n }\n #[test]\n fn test_get_best_score_5() {\n assert_eq!(get_best_score(&vec![0]), 1);\n }\n\n fn do_test_max_delta(values: &Vec) {\n if values.len() <= 1 {\n assert_eq!(get_max_delta(values), None);\n return;\n }\n\n let mut max_delta: Option = None;\n for i in 0..values.len() {\n for j in (i + 1)..values.len() {\n let delta: i32 = values[j] - values[i];\n if let Some(max_delta_value) = max_delta {\n if delta > max_delta_value {\n max_delta = Some(delta);\n }\n } else {\n max_delta = Some(delta);\n }\n }\n }\n\n let (result_max_delta, result_start, result_end) = get_max_delta(values).unwrap();\n assert_eq!(result_max_delta, max_delta.unwrap());\n assert_eq!(\n values[result_end] - values[result_start],\n max_delta.unwrap()\n );\n }\n\n #[test]\n fn test_get_max_delta_1() {\n do_test_max_delta(&vec![1, 2, 7, 19, 20, 3, 0, -4, 4]);\n }\n #[test]\n fn test_get_max_delta_2() {\n do_test_max_delta(&vec![0, 0, 0, 3]);\n }\n #[test]\n fn test_get_max_delta_3() {\n do_test_max_delta(&vec![1]);\n }\n #[test]\n fn test_get_max_delta_4() {\n do_test_max_delta(&vec![0, -1, -2, -3]);\n }\n}\n\nfn main() {\n let stdin = stdin();\n let mut stdin_lock = stdin.lock();\n\n {\n let mut skip_buffer = String::new();\n stdin_lock.read_line(&mut skip_buffer).unwrap();\n }\n let mut string_buffer = String::new();\n stdin_lock.read_line(&mut string_buffer).unwrap();\n let values: Vec = string_buffer\n .trim()\n .split_whitespace()\n .map(|s| s.parse::().unwrap())\n .collect();\n\n let best_score: usize = get_best_score(&values);\n println!(\"{}\", best_score);\n}\n"}, {"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 n = input.i();\n let mut sum = 0;\n let mut max = 0;\n let mut sol = -1;\n for _ in 0..n {\n sum += input.i() * 2 - 1;\n a!(>,sol,max-sum);\n a!(>,max,sum);\n }\n let sum = (sum + n) / 2;\n let sol = sol + sum;\n println!(\"{}\", sol);\n}\n\n"}, {"source_code": "// 2018-10-12 13:59\nfn main() {\n let _ = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n };\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim()\n .split(\" \")\n .map(|s| s.parse::().unwrap())\n .collect()\n };\n\n let n = v.len();\n let orig = v.iter().filter(|&x| *x == 1).count() as i32;\n\n let mut dp = vec![vec![0; n + 1]; n + 1];\n let mut inc = -1;\n for i in 0..n {\n for j in i + 1..n + 1 {\n dp[i][j] = {\n if v[j - 1] == 0 {\n dp[i][j - 1] + 1\n } else {\n dp[i][j - 1]\n }\n };\n inc = std::cmp::max(inc, dp[i][j] * 2 - (j - i) as i32);\n }\n }\n println!(\"{:?}\", inc + orig);\n}\n"}, {"source_code": "// 2018-10-12 13:59\nfn main() {\n let _ = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n };\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim()\n .split(\" \")\n .map(|s| s.parse::().unwrap())\n .collect()\n };\n\n let n = v.len();\n let orig = v.iter().filter(|&x| *x == 1).count() as i32;\n\n let mut inc = -1;\n\n for i in 0..n {\n let mut prev = 0;\n for j in i + 1..n + 1 {\n if v[j - 1] == 0 {\n prev += 1\n }\n inc = std::cmp::max(inc, prev * 2 - (j - i) as i32);\n }\n }\n println!(\"{:?}\", inc + orig);\n}\n"}, {"source_code": "fn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n : usize = s.trim().parse().unwrap();\n s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let ints:Vec = s.split_whitespace().map(|x| x.parse().unwrap()).collect();\n let mut max = 0;\n let mut onesum = vec![];\n let mut onerevsum = vec![];\n let mut sum = 0;\n let mut revsum = 0;\n\n for i in 0..n {\n onesum.push(sum);\n onerevsum.insert(0,revsum);\n sum+=ints[i];\n revsum+=ints[n-i-1];\n }\n \n for i in 0..n {\n for j in i..n {\n max = std::cmp::max(max, ints[i..=j].iter().fold(0, |acc, x| acc+(1-x)) + onesum[i] + onerevsum[j]);\n }\n }\n println!(\"{}\",max);\n}\n \n\n\n"}, {"source_code": "fn main() {\n inputv! {\n n:usize,\n }\n let a = input_vector::();\n let mut ans = 0;\n let one_count = a.iter().filter(|&&q| q == 1).count();\n for i in 0..n {\n for j in i + 1..=n {\n let zero = a[i..j].iter().filter(|&&q| q == 0).count();\n let one = j - i - zero;\n ans = std::cmp::max(ans, one_count + zero - one);\n }\n }\n println!(\"{}\", ans);\n}\n\n//https://github.com/manta1130/competitive-template-rs\n\nuse input::*;\n\npub mod input {\n use std::cell::RefCell;\n use std::io;\n pub const SPLIT_DELIMITER: char = ' ';\n pub use std::io::prelude::*;\n\n #[macro_export]\n thread_local! {\n pub static INPUT_BUFFER:RefCell>=RefCell::new(std::collections::VecDeque::new());\n }\n\n #[macro_export]\n macro_rules! input_internal {\n ($x:ident : $t:ty) => {\n INPUT_BUFFER.with(|p| {\n if p.borrow().len() == 0 {\n let temp_str = input_line_str();\n let mut split_result_iter = temp_str\n .split(SPLIT_DELIMITER)\n .map(|q| q.to_string())\n .collect::>();\n p.borrow_mut().append(&mut split_result_iter)\n }\n });\n let mut buf_split_result = String::new();\n INPUT_BUFFER.with(|p| buf_split_result = p.borrow_mut().pop_front().unwrap());\n let $x: $t = buf_split_result.parse().unwrap();\n };\n (mut $x:ident : $t:ty) => {\n INPUT_BUFFER.with(|p| {\n if p.borrow().len() == 0 {\n let temp_str = input_line_str();\n let mut split_result_iter = temp_str\n .split(SPLIT_DELIMITER)\n .map(|q| q.to_string())\n .collect::>();\n p.borrow_mut().append(&mut split_result_iter)\n }\n });\n let mut buf_split_result = String::new();\n INPUT_BUFFER.with(|p| buf_split_result = p.borrow_mut().pop_front().unwrap());\n let mut $x: $t = buf_split_result.parse().unwrap();\n };\n }\n\n #[macro_export]\n macro_rules! inputv {\n ($i:ident : $t:ty) => {\n input_internal!{$i : $t}\n };\n (mut $i:ident : $t:ty) => {\n input_internal!{mut $i : $t}\n };\n ($i:ident : $t:ty $(,)*) => {\n input_internal!{$i : $t}\n };\n (mut $i:ident : $t:ty $(,)*) => {\n input_internal!{mut $i : $t}\n };\n (mut $i:ident : $t:ty,$($q:tt)*) => {\n input_internal!{mut $i : $t}\n inputv!{$($q)*}\n };\n ($i:ident : $t:ty,$($q:tt)*) => {\n input_internal!{$i : $t}\n inputv!{$($q)*}\n };\n}\n\n pub fn input_all() {\n INPUT_BUFFER.with(|p| {\n if p.borrow().len() == 0 {\n let mut temp_str = String::new();\n std::io::stdin().read_to_string(&mut temp_str).unwrap();\n let mut split_result_iter = temp_str\n .split_whitespace()\n .map(|q| q.to_string())\n .collect::>();\n p.borrow_mut().append(&mut split_result_iter)\n }\n });\n }\n\n pub fn input_line_str() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n }\n\n #[allow(clippy::match_wild_err_arm)]\n pub fn input_vector() -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v: Vec = Vec::new();\n\n let s = input_line_str();\n let split_result = s.split(SPLIT_DELIMITER);\n for z in split_result {\n let buf = match z.parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\",),\n };\n v.push(buf);\n }\n v\n }\n\n #[allow(clippy::match_wild_err_arm)]\n pub fn input_vector_row(n: usize) -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v = Vec::with_capacity(n);\n for _ in 0..n {\n let buf = match input_line_str().parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\",),\n };\n v.push(buf);\n }\n v\n }\n\n pub trait ToCharVec {\n fn to_charvec(&self) -> Vec;\n }\n\n impl ToCharVec for String {\n fn to_charvec(&self) -> Vec {\n self.to_string().chars().collect::>()\n }\n }\n}\n"}, {"source_code": "macro_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\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\nfn num_of_1_before(i: &Vec, idx: usize) -> u32 {\n i.iter().take(idx).sum()\n}\n\nfn num_of_1_after(i: &Vec, idx: usize) -> u32 {\n i.iter().skip(idx + 1).sum()\n}\n\nfn max_num_of_1_flipped_after(i: &Vec, idx: usize) -> u32 {\n if 1 == *i.iter().nth(idx).unwrap() {\n return 0;\n }\n let targets = i.iter().skip(idx);\n let mut current_score = 0;\n let mut scores = Vec::new();\n for (local_index, value) in targets.enumerate() {\n if *value == 0 {\n current_score = current_score + 1;\n }\n scores.push(current_score + num_of_1_after(i, idx + local_index));\n }\n scores.into_iter().max().unwrap_or(0)\n}\n\nfn max_score(i: &Vec, idx: usize) -> u32 {\n num_of_1_before(i, idx) + max_num_of_1_flipped_after(i, idx)\n}\n\nfn main() {\n input! {\n n: usize,\n a: [u32; n],\n }\n\n let v = Vec::from(a);\n\n println!(\n \"{}\",\n (0..n).map(|idx| max_score(&v, idx)).max().unwrap_or(0)\n );\n}\n"}, {"source_code": "use std::io;\nuse std::cmp;\n\nfn read_line() -> String {\n let mut line = String::new();\n match io::stdin().read_line(&mut line) {\n Ok(_) => line.trim().to_string(),\n _ => panic!(\"QQ\"),\n }\n}\n\nfn main() {\n read_line();\n\n let mut cnt: i32 = 0;\n let mut min: i32 = 0;\n let mut cur: i32 = 0;\n let mut ans: i32 = -1;\n for x in read_line().split_whitespace().map(|x| x.parse::().unwrap()) {\n cnt += x;\n cur += if x == 1 { -1 } else { 1 };\n ans = cmp::max(ans, cur - min);\n min = cmp::min(min, cur);\n }\n\n println!(\"{}\", ans + cnt);\n}\n"}, {"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 fn next_n(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next::()).collect()\n }\n\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: usize = scan.next();\n let arr: Vec = scan.next_n(n);\n let allones: usize = arr.iter().filter(|&&x| x==1).count();\n let total: isize = arr.iter().sum();\n // convert to an array in which Kadane can be used\n let arr2: Vec = arr.into_iter().map(|x| if x==1 { -1 } else { 1 }).collect();\n let mut cnt: isize = 0;\n let mut maxcnt: isize = 0;\n if allones == n {\n println!(\"{}\", total-1);\n return;\n }\n for i in 0..n {\n cnt += arr2[i];\n if cnt < 0 { cnt = 0; }\n maxcnt = maxcnt.max(cnt);\n }\n println!(\"{}\", total + maxcnt);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"source_code": "use std::cmp::max;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_t(stdin : &Stdin) -> T {\n let mut line = String::new();\n read_line(stdin, &mut line);\n parse_t(&line)\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn max_ones(xs : &Vec) -> i8 {\n let s = xs.iter().sum::();\n let mut ys = vec![];\n let one = 1;\n let minus_one = -1;\n for &x in xs.iter() {\n if x == 0 {\n ys.push(one);\n } else {\n ys.push(minus_one);\n }\n }\n let mut max_upto_i = ys[0];\n let mut max_ending_at_i = ys[0];\n for i in 1 .. ys.len() {\n let y = ys[i];\n max_ending_at_i = max(y, max_ending_at_i + y);\n max_upto_i = max(max_ending_at_i, max_upto_i);\n }\n s + max_upto_i\n}\n\nfn main() {\n let stdin = io::stdin();\n let _ : usize = read_t(&stdin);\n let mut xs = vec![]; \n read_ts(&stdin, &mut xs);\n let result = max_ones(&xs);\n println!(\"{}\", result);\n}\n"}, {"source_code": "use std::cmp::max;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_t(stdin : &Stdin) -> T {\n let mut line = String::new();\n read_line(stdin, &mut line);\n parse_t(&line)\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn max_ones(xs : &Vec) -> i8 {\n let mut ys = vec![];\n let one = 1;\n let minus_one = -1;\n let mut s = 0;\n for &x in xs.iter() {\n if x == 0 {\n ys.push(one);\n } else {\n ys.push(minus_one);\n s = s + one;\n }\n }\n let mut max_upto_i = ys[0];\n let mut max_ending_at_i = ys[0];\n for i in 1 .. ys.len() {\n let y = ys[i];\n max_ending_at_i = max(y, max_ending_at_i + y);\n max_upto_i = max(max_ending_at_i, max_upto_i);\n }\n s + max_upto_i\n}\n\nfn main() {\n let stdin = io::stdin();\n let _ : usize = read_t(&stdin);\n let mut xs = vec![]; \n read_ts(&stdin, &mut xs);\n let result = max_ones(&xs);\n println!(\"{}\", result);\n}\n"}, {"source_code": "use std::cmp::max;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_t(stdin : &Stdin) -> T {\n let mut line = String::new();\n read_line(stdin, &mut line);\n parse_t(&line)\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn max_ones(ys : &Vec) -> i8 {\n let one = 1;\n let minus_one = -1;\n let mut s = ys[0];\n let y_0 = if ys[0] == 0 { one } else { minus_one };\n let mut max_upto_i = y_0;\n let mut max_ending_at_i = y_0;\n for i in 1 .. ys.len() {\n let ys_i = ys[i];\n s = s + ys_i;\n let y = if ys_i == 0 { one } else { minus_one };\n max_ending_at_i = max(y, max_ending_at_i + y);\n max_upto_i = max(max_ending_at_i, max_upto_i);\n }\n s + max_upto_i\n}\n\nfn main() {\n let stdin = io::stdin();\n let _ : usize = read_t(&stdin);\n let mut xs = vec![]; \n read_ts(&stdin, &mut xs);\n let result = max_ones(&xs);\n println!(\"{}\", result);\n}\n"}, {"source_code": "fn solve() {\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 a: Vec = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.split_whitespace().map(|s| s.parse().unwrap()).collect()\n };\n\n let mut ans = 0;\n for i in 0..n {\n for j in i..n {\n let mut tmp = a.clone();\n for k in i..j + 1 {\n tmp[k] = 1 - tmp[k];\n }\n ans = ans.max(tmp.iter().sum());\n }\n }\n\n println!(\"{}\", ans);\n}\n\nfn main() {\n solve();\n}\n"}, {"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 s = vec![];\n for _ in 0..n {\n s.push(scan.token::());\n }\n let mut max: u8 = 0;\n\n for i in 0..n {\n for j in i..n {\n let mut curr = 0;\n for k in 0..n {\n curr += {\n if k < i {s[k]}\n else if k >= i && k <= j {1 - s[k]}\n else {s[k]}\n }\n }\n max = u8::max(curr, max);\n }\n }\n writeln!(out, \"{}\", max);\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"}, {"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\n\n#[derive(Copy, Clone, Debug)]\nstruct Pair {\n i : usize,\n cost : i64\n}\nimpl PartialOrd for Pair {\n fn partial_cmp(&self, other : &Pair) -> Option {\n Some(self.cost.cmp(&other.cost))\n }\n}\n\nimpl Ord for Pair {\n fn cmp(&self, other : &Pair) -> Ordering {\n self.partial_cmp(other).unwrap()\n }\n}\n\nimpl PartialEq for Pair {\n fn eq(&self, other : &Pair) -> bool {\n self.cost == other.cost\n }\n}\nimpl Eq for Pair {}\n\nfn main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let n = scan!(s, usize);\n let data : Vec<_> = scan_iter!(s, i64);\n let mut result = 0;\n\n for i in 0..n {\n for j in (i+1)..(n+1) {\n let mut count = 0;\n for k in 0..n {\n if k >= i && k <= j {\n count += 1 - data[k];\n } else {\n count += data[k];\n }\n }\n result = max(result, count);\n }\n }\n\n println!(\"{}\", result);\n}"}, {"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 = parse_input!(u64);\n let b = split_input!(u64);\n let mut best = 0;\n let mut cur = 0;\n let mut ones: u64 = b.iter().sum();\n if ones as usize == b.len() {\n ones -= 1;\n }\n for p in b.iter() {\n if *p == 0 {\n cur += 1;\n best = std::cmp::max(best, cur);\n } else if cur > 0 {\n cur -= 1;\n }\n }\n\n println!(\"{}\", ones + best);\n}\n"}], "negative_code": [{"source_code": "use std::io::{stdin, BufRead};\n\nfn get_max_delta(values: &Vec) -> Option<(T, usize, usize)>\nwhere\n T: Ord,\n T: Copy,\n T: std::ops::Sub,\n{\n if values.len() <= 1 {\n return None;\n }\n\n let mut min_positions: Vec = Vec::new();\n let mut max_positions: Vec = Vec::new();\n\n min_positions.push(0);\n max_positions.push(0);\n\n for i in 1..(values.len() - 1) {\n let value = values[i];\n let prev_value = values[i - 1];\n let next_value = values[i + 1];\n\n if (value >= prev_value) && (value >= next_value) {\n max_positions.push(i);\n }\n if (value <= prev_value) && (value <= next_value) {\n min_positions.push(i);\n }\n }\n\n min_positions.push(values.len() - 1);\n max_positions.push(values.len() - 1);\n\n let mut max_delta: Option<(T, usize, usize)> = None;\n let mut max_position_index: usize = 0;\n\n for i in 0..min_positions.len() {\n let min_position = min_positions[i];\n let min_position_value = values[min_position];\n while max_positions[max_position_index] <= min_positions[i] {\n max_position_index += 1;\n if max_position_index >= max_positions.len() {\n break;\n }\n }\n if max_position_index >= max_positions.len() {\n break;\n }\n for j in max_position_index..max_positions.len() {\n let max_position = max_positions[j];\n let max_position_value = values[max_position];\n let delta_value = max_position_value - min_position_value;\n if let Some((max_delta_value, _max_delta_start, _max_delta_end)) = max_delta {\n if delta_value > max_delta_value {\n max_delta = Some((delta_value, min_position, max_position));\n }\n } else {\n max_delta = Some((delta_value, min_position, max_position));\n }\n }\n }\n\n return max_delta;\n}\n\nfn get_best_score(values: &Vec) -> usize {\n let mut switch_scores: Vec = Vec::with_capacity(values.len() + 1);\n switch_scores.push(0);\n let mut current_switch_score: isize = 0;\n let mut base_score: usize = 0;\n for &value in values {\n if value == 0 {\n current_switch_score += 1;\n } else {\n current_switch_score -= 1;\n base_score += 1;\n }\n switch_scores.push(current_switch_score);\n }\n\n let (max_switch_score, _, _) = get_max_delta(&switch_scores).unwrap();\n\n return ((base_score as isize) + max_switch_score) as usize;\n}\n\n#[cfg(test)]\nmod tests {\n use super::{get_best_score, get_max_delta};\n\n #[test]\n fn test_get_best_score_1() {\n assert_eq!(get_best_score(&vec![1, 0, 0, 1, 0]), 4);\n }\n #[test]\n fn test_get_best_score_2() {\n assert_eq!(get_best_score(&vec![1, 0, 0, 1]), 4);\n }\n #[test]\n fn test_get_best_score_3() {\n assert_eq!(get_best_score(&vec![1, 0, 1, 0, 1, 0]), 4);\n }\n #[test]\n fn test_get_best_score_4() {\n assert_eq!(get_best_score(&vec![1]), 0);\n }\n #[test]\n fn test_get_best_score_5() {\n assert_eq!(get_best_score(&vec![0]), 1);\n }\n\n fn do_test_max_delta(values: &Vec) {\n if values.len() <= 1 {\n assert_eq!(get_max_delta(values), None);\n return;\n }\n\n let mut max_delta: i32 = 0;\n for i in 0..values.len() {\n for j in (i + 1)..values.len() {\n let delta: i32 = values[j] - values[i];\n if delta > max_delta {\n max_delta = delta;\n }\n }\n }\n\n let (result_max_delta, result_start, result_end) = get_max_delta(values).unwrap();\n assert_eq!(result_max_delta, max_delta);\n assert_eq!(values[result_end] - values[result_start], max_delta);\n }\n\n #[test]\n fn test_get_max_delta_1() {\n do_test_max_delta(&vec![1, 2, 7, 19, 20, 3, 0, -4, 4]);\n }\n #[test]\n fn test_get_max_delta_2() {\n do_test_max_delta(&vec![0, 0, 0, 3]);\n }\n #[test]\n fn test_get_max_delta_3() {\n do_test_max_delta(&vec![1]);\n }\n}\n\nfn main() {\n let stdin = stdin();\n let mut stdin_lock = stdin.lock();\n\n {\n let mut skip_buffer = String::new();\n stdin_lock.read_line(&mut skip_buffer).unwrap();\n }\n let mut string_buffer = String::new();\n stdin_lock.read_line(&mut string_buffer).unwrap();\n let values: Vec = string_buffer\n .trim()\n .split_whitespace()\n .map(|s| s.parse::().unwrap())\n .collect();\n\n let best_score: usize = get_best_score(&values);\n println!(\"{}\", best_score);\n}\n"}, {"source_code": "// 2018-10-12 13:59\nfn main() {\n let _ = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n };\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim()\n .split(\" \")\n .map(|s| s.parse::().unwrap())\n .collect()\n };\n\n let n = v.len();\n let orig = v.iter().filter(|&x| *x == 1).count() as i32;\n\n let mut dp = vec![vec![0; n + 1]; n + 1];\n let mut inc = 0;\n for i in 0..n {\n for j in i + 1..n + 1 {\n dp[i][j] = {\n if v[j - 1] == 0 {\n dp[i][j - 1] + 1\n } else {\n dp[i][j - 1]\n }\n };\n inc = std::cmp::max(inc, dp[i][j] * 2 - (j - i) as i32);\n }\n }\n if inc == 0 {\n println!(\"{:?}\", 0);\n } else {\n println!(\"{:?}\", inc + orig);\n }\n}\n"}, {"source_code": "// 2018-10-12 13:59\nfn main() {\n let _ = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().to_string()\n };\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim()\n .split(\" \")\n .map(|s| s.parse::().unwrap())\n .collect()\n };\n\n let n = v.len();\n let orig = v.iter().filter(|&x| *x == 1).count() as i32;\n\n let mut dp = vec![vec![0; n + 1]; n + 1];\n let mut inc = 0;\n for i in 0..n {\n for j in i + 1..n + 1 {\n dp[i][j] = {\n if v[j - 1] == 0 {\n dp[i][j - 1] + 1\n } else {\n dp[i][j - 1]\n }\n };\n inc = std::cmp::max(inc, dp[i][j] * 2 - (j - i) as i32);\n }\n }\n println!(\"{:?}\", inc + orig);\n}\n"}, {"source_code": "fn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n : usize = s.trim().parse().unwrap();\n s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let ints:Vec = s.split_whitespace().map(|x| x.parse().unwrap()).collect();\n let mut onesum : Vec = vec![0];\n let mut onerevsum : Vec = vec![0];\n let mut sum = 0;\n let mut revsum = 0;\n let mut newints : Vec = vec![ints[0]];\n let mut newintscount : Vec = vec![if ints[0]==0 {1} else {0}];\n let mut lastnum=ints[0];\n\n for i in 0..n {\n *onesum.last_mut().unwrap() = sum;\n *onerevsum.first_mut().unwrap() = revsum;\n sum+=ints[i];\n revsum+=ints[n-i-1];\n if ints[i] == lastnum {\n *(newintscount.last_mut().unwrap())+=if ints[i]==0 {1} else{0};\n } else {\n onesum.push(0);\n onerevsum.insert(0,0);\n newints.push(ints[i]);\n newintscount.push(if ints[i]==0 {1} else {0});\n }\n lastnum = ints[i];\n }\n *onesum.last_mut().unwrap() = sum;\n *onerevsum.first_mut().unwrap() = revsum;\n\n// println!(\"{:?}\",newints);\n// println!(\"{:?}\",newintscount);\n// println!(\"{:?}\",onesum);\n// println!(\"{:?}\",onerevsum);\n\n let mut max = 0;\n\n for i in 0..(newints.len()) {\n for j in i..(newints.len()) {\n if newints[i] == 0 && newints[j] == 0 {\n let subsum = &newintscount[i..=j].iter().fold(0, |acc, x| acc+x) + onesum[i] + onerevsum[j];\n// println!(\"slice={:?} sum={}\",&newints[i..=j],subsum); \n max = std::cmp::max(max, subsum);\n }\n }\n }\n println!(\"{}\",max);\n\n}\n \n\n\n"}, {"source_code": "fn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n : usize = s.trim().parse().unwrap();\n s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let ints:Vec = s.split_whitespace().map(|x| x.parse().unwrap()).collect();\n let mut onesum : Vec = vec![0];\n let mut onerevsum : Vec = vec![0];\n let mut sum = 0;\n let mut revsum = 0;\n let mut newints : Vec = vec![ints[0]];\n let mut newintscount : Vec = vec![0];\n let mut lastnum=ints[0];\n\n for i in 0..n {\n *onesum.last_mut().unwrap() = sum;\n *onerevsum.first_mut().unwrap() = revsum;\n sum+=ints[i];\n revsum+=ints[n-i-1];\n if ints[i] == lastnum {\n *(newintscount.last_mut().unwrap())+=if ints[i]==0 {1} else{0};\n } else {\n onesum.push(0);\n onerevsum.insert(0,0);\n newints.push(ints[i]);\n newintscount.push(if ints[i]==0 {1} else {0});\n }\n lastnum = ints[i];\n }\n *onesum.last_mut().unwrap() = sum;\n *onerevsum.first_mut().unwrap() = revsum;\n\n// println!(\"{:?}\",newints);\n// println!(\"{:?}\",newintscount);\n// println!(\"{:?}\",onesum);\n// println!(\"{:?}\",onerevsum);\n\n let mut max = 0;\n\n for i in 0..(newints.len()) {\n for j in i..(newints.len()) {\n if newints[i] == 0 && newints[j] == 0 {\n let subsum = &newintscount[i..=j].iter().fold(0, |acc, x| acc+x) + onesum[i] + onerevsum[j];\n// println!(\"slice={:?} sum={}\",&newints[i..=j],subsum); \n max = std::cmp::max(max, subsum);\n }\n }\n }\n println!(\"{}\",max);\n\n}\n \n\n\n"}, {"source_code": "fn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n : usize = s.trim().parse().unwrap();\n s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let ints:Vec = s.split_whitespace().map(|x| x.parse().unwrap()).collect();\n let mut onesum : Vec = vec![0];\n let mut onerevsum : Vec = vec![0];\n let mut sum = 0;\n let mut revsum = 0;\n let mut newints : Vec = vec![ints[0]];\n let mut newintscount : Vec = vec![0];\n let mut lastnum=ints[0];\n\n for i in 0..n {\n *onesum.last_mut().unwrap() = sum;\n *onerevsum.first_mut().unwrap() = revsum;\n sum+=ints[i];\n revsum+=ints[n-i-1];\n if ints[i] == lastnum {\n *(newintscount.last_mut().unwrap())+=if ints[i]==0 {1} else{0};\n } else {\n onesum.push(0);\n onerevsum.insert(0,0);\n newints.push(ints[i]);\n newintscount.push(if ints[i]==0 {1} else {0});\n }\n lastnum = ints[i];\n }\n *onesum.last_mut().unwrap() = sum;\n *onerevsum.first_mut().unwrap() = revsum;\n\n// println!(\"{:?}\",newints);\n// println!(\"{:?}\",newintscount);\n// println!(\"{:?}\",onesum);\n// println!(\"{:?}\",onerevsum);\n\n if newints.len()==1 {\n if newints[0] == 1 {\n println!(\"{}\",n-1);\n } else {\n println!(\"{}\", n);\n }\n } else {\n let mut max = 0;\n\n for i in 0..(newints.len()) {\n for j in i..(newints.len()) {\n if newints[i] == 0 && newints[j] == 0 {\n let subsum = &newintscount[i..=j].iter().fold(0, |acc, x| acc+x) + onesum[i] + onerevsum[j];\n// println!(\"slice={:?} sum={}\",&newints[i..=j],subsum); \n max = std::cmp::max(max, subsum);\n }\n }\n }\n println!(\"{}\",max);\n }\n}\n \n\n\n"}, {"source_code": "macro_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\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\nstruct State(u32, u32);\n\nfn main() {\n input! {\n n: usize,\n a: [u8; n],\n }\n\n let mut state = State(0, 0);\n let num_of_1 = a.iter().filter(|x| **x == 1).count();\n\n for x in a {\n state = if x == 1 {\n State(std::cmp::max(state.0, state.1), 0)\n } else {\n State(state.0, state.1 + 1)\n };\n }\n println!(\"{}\", num_of_1 as u32 + state.0);\n}\n"}, {"source_code": "macro_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\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\nstruct State(u32, u32);\n\nfn main() {\n input! {\n n: usize,\n a: [u8; n],\n }\n\n let mut state = State(0, 0);\n let num_of_1 = a.iter().filter(|x| **x == 1).count();\n\n for x in a {\n state = if x == 1 {\n State(std::cmp::max(state.0, state.1), 0)\n } else {\n State(state.0, state.1 + 1)\n };\n }\n\n state = if state.1 != 0 {\n State(std::cmp::max(state.0, state.1), 0)\n } else {\n state\n };\n\n if state.0 == 0 {\n println!(\"{}\", n - 1);\n } else {\n println!(\"{}\", num_of_1 as u32 + state.0);\n }\n}\n"}, {"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 fn next_n(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next::()).collect()\n }\n\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let n: usize = scan.next();\n let arr: Vec = scan.next_n(n);\n let total: isize = arr.iter().sum();\n // convert to an array in which Kadane can be used\n let arr2: Vec = arr.into_iter().map(|x| if x==1 { -1 } else { 1 }).collect();\n let mut cnt: isize = 0;\n let mut maxcnt: isize = 0;\n for i in 0..n {\n cnt += arr2[i];\n if cnt < 0 { cnt = 0; }\n maxcnt = maxcnt.max(cnt);\n }\n println!(\"{}\", total + maxcnt);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"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\n\n#[derive(Copy, Clone, Debug)]\nstruct Pair {\n i : usize,\n cost : i64\n}\nimpl PartialOrd for Pair {\n fn partial_cmp(&self, other : &Pair) -> Option {\n Some(self.cost.cmp(&other.cost))\n }\n}\n\nimpl Ord for Pair {\n fn cmp(&self, other : &Pair) -> Ordering {\n self.partial_cmp(other).unwrap()\n }\n}\n\nimpl PartialEq for Pair {\n fn eq(&self, other : &Pair) -> bool {\n self.cost == other.cost\n }\n}\nimpl Eq for Pair {}\n\nfn main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let _ = scan!(s, usize);\n let mut data : Vec<_> = scan_iter!(s, i64);\n let mut i = 0;\n let mut j = data.len() - 1;\n\n while i < data.len() && data[i] == 1 {\n i += 1;\n }\n while j > 0 && data[j] == 1 {\n j -= 1;\n }\n\n for k in i..(j+1) {\n data[k] = 1 - data[k];\n }\n let result = data.iter().fold(0, |c, x| c + x);\n \n\n println!(\"{}\", result);\n}"}, {"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\n\n#[derive(Copy, Clone, Debug)]\nstruct Pair {\n i : usize,\n cost : i64\n}\nimpl PartialOrd for Pair {\n fn partial_cmp(&self, other : &Pair) -> Option {\n Some(self.cost.cmp(&other.cost))\n }\n}\n\nimpl Ord for Pair {\n fn cmp(&self, other : &Pair) -> Ordering {\n self.partial_cmp(other).unwrap()\n }\n}\n\nimpl PartialEq for Pair {\n fn eq(&self, other : &Pair) -> bool {\n self.cost == other.cost\n }\n}\nimpl Eq for Pair {}\n\nfn main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let _ = scan!(s, usize);\n let mut data : Vec<_> = scan_iter!(s, i64);\n let mut i = 0;\n let mut j = data.len() - 1;\n\n while i < data.len() - 1 && data[i] == 1 {\n i += 1;\n }\n while j > 0 && data[j] == 1 {\n j -= 1;\n }\n\n if i > j {\n i = 0; j = 0;\n }\n\n for k in i..(j+1) {\n data[k] = 1 - data[k];\n }\n let result = data.iter().fold(0, |c, x| c + x);\n \n\n println!(\"{}\", result);\n}"}, {"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 = parse_input!(u64);\n let b = split_input!(u64);\n let mut best = 0;\n let mut cur = 0;\n let ones: u64 = b.iter().sum();\n for p in b.iter() {\n if *p == 0 {\n cur += 1;\n best = std::cmp::max(best, cur);\n } else if cur > 0 {\n cur -= 1;\n }\n }\n\n println!(\"{}\", ones + best);\n}\n"}], "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"source_code": "fn main() {\n let mut line1 = String::new();\n let mut line2 = String::new();\n std::io::stdin().read_line(&mut line1).unwrap();\n std::io::stdin().read_line(&mut line2).unwrap();\n let rev = line2.chars().rev().collect::();\n println!(\"{}\", if rev.trim() == line1.trim() { \"YES\" } else { \"NO\"});\n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn main() {\n let mut first_input = String::new();\n io::stdin().read_line(&mut first_input);\n\n let mut second_input = String::new();\n io::stdin().read_line(&mut second_input);\n\n first_input = first_input.trim().parse().unwrap();\n second_input = second_input.trim().parse().unwrap();\n\n let second_input: String = second_input.chars().rev().collect();\n\n if first_input.eq(&second_input) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut buf1 = String::new();\n io::stdin().read_line(&mut buf1).unwrap();\n let buf1_rev = buf1.trim().chars().rev().collect::();\n\n let mut buf2 = String::new();\n io::stdin().read_line(&mut buf2).unwrap();\n if buf2.trim() == buf1_rev {\n println!(\"YES\");\n return;\n }\n println!(\"NO\");\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n\n let mut t = String::new();\n io::stdin().read_line(&mut t).unwrap();\n let t: String = t.chars().rev().collect();\n\n if s.trim() == t.trim() {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "use std::io;\n\nfn read_line() -> String {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n line\n}\n\nfn main() {\n\n let line1 = read_line();\n let line2 = read_line();\n let correct = line1.len() == line2.len() && line1.trim().chars().rev().zip(line2.trim().chars()).all(|(a, b)| a == b);\n\n print!(\"{}\", if correct { \"YES\" } else { \"NO\" });\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let mut from: String = read(sin);\n let mut to: String = read(sin);\n\n let mut from = from.as_str().chars().rev();\n let mut to = to.as_str().chars();\n\n if from.zip(to).map(|x| x.0 != x.1).filter(|x| *x).count() == 0 {\n println!(\"YES\")\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "fn main(){\n let mut line=String::new();\n let mut translated=String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line=line.trim().chars().rev().collect();\n std::io::stdin().read_line(&mut translated).unwrap();\n print!(\"{}\",if translated.trim()==line{\"YES\"}else{\"NO\"});\n}"}, {"source_code": "fn main() {\n let word = get_input();\n let their_rev = get_input();\n let is_correct = their_rev == word.chars().rev().collect::();\n println!(\"{}\", if is_correct { \"YES\" } else { \"NO\" });\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"}, {"source_code": "// https://codeforces.com/problemset/problem/41/A\nuse std::io;\n\nfn main() {\n let mut s = String::new();\n\n io::stdin()\n .read_line(&mut s)\n .unwrap();\n\n let s: String = s.trim().chars().rev().collect();\n\n let mut t = String::new();\n\n io::stdin()\n .read_line(&mut t)\n .unwrap();\n\n let t = t.trim();\n\n if s == t {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n}\n"}, {"source_code": "use std::io::{self, Read};\n\nfn get_input() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Failed\");\n buffer\n}\n\nfn main() -> io::Result<()> {\n let mut input = get_input().trim().to_string();\n\n let mut input2 = get_input().trim().to_string();\n\n let res: String = input.chars().rev().collect();\n\n if input2 == res {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n Ok(())\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut s1 = String::new();\n let mut s2 = String::new();\n io::stdin().read_line(&mut s1).unwrap();\n io::stdin().read_line(&mut s2).unwrap();\n s1 = s1.trim().to_string();\n s2 = s2.trim().to_string();\n let n = s1.len();\n let mut flag = true;\n for i in 0..n {\n let c1 = s1.chars().nth(i);\n let c2 = s2.chars().nth(n-1-i);\n if c1 != c2 {\n flag = false;\n }\n }\n if flag {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}"}, {"source_code": "fn main() {\n let first_string = read_line();\n let second_string = read_line();\n\n if second_string == first_string.chars().rev().collect::() {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n}\n\nfn read_line() -> String {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).expect(\"Ошибка чтения\");\n\n input.trim().to_string()\n}"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn main() {\n let (s, t): (String, String) = (read_str(), read_str());\n if s.chars().rev().collect::() == t { println!(\"YES\"); }\n else { println!(\"NO\"); }\n}"}, {"source_code": "// http://codeforces.com/problemset/problem/41/A\n\nuse std::io::{Read, Write, stdin, stdout};\n\npub struct Scanner {\n pub buffer: Vec,\n pub reader: U,\n}\nimpl Scanner {\n pub fn next_line(&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 if self.buffer.is_empty() {\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 self.buffer\n .pop()\n .unwrap()\n .parse()\n .ok()\n .expect(\"Failed parse\")\n }\n\n pub fn new(reader: U) -> Self {\n Scanner {\n buffer: vec![],\n reader,\n }\n }\n}\n\npub fn solution_of_p41a(input: &mut dyn Read, out: &mut dyn Write) {\n let mut scanner = Scanner::new(input);\n let s1 = scanner.next_line::();\n let s2 = scanner.next_line::();\n\n if is_translation(s1, s2) {\n write!(out, \"YES\").ok();\n } else {\n write!(out, \"NO\").ok();\n }\n}\n\nfn is_translation(s1: String, s2: String) -> bool {\n if s1.len() != s2.len() {\n return false;\n }\n let l = s1.len();\n for i in 0..l {\n if s1[i..=i] != s2[l - i - 1..=l - i - 1] {\n return false;\n }\n }\n true\n}\n\nfn main() {\n solution_of_p41a(&mut stdin(), &mut stdout());\n}\n"}, {"source_code": "use 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 main() {\n let stdin = io::stdin();\n let mut s = String::new();\n let mut t = String::new();\n read_line(&stdin, &mut s);\n read_line(&stdin, &mut t);\n let mut c_s = s.trim().chars();\n let mut c_t = t.trim().chars();\n let mut is_translation = false;\n loop {\n let x_s = c_s.next();\n let x_t = c_t.next_back();\n if x_s.is_none() && x_t.is_none() {\n is_translation = true;\n break;\n } else if x_s.is_some() && x_t.is_some() {\n let u_x_s = x_s.unwrap();\n let u_x_t = x_t.unwrap();\n if u_x_s == u_x_t {\n // Do nothing ...\n } else {\n break;\n }\n } else {\n break;\n }\n }\n if is_translation {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "macro_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 ($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\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\nfn main() {\n input! {\n s : String,\n t : String,\n };\n let s: Vec = s.chars().collect();\n let t: Vec = t.chars().rev().collect();\n let n = s.len();\n for i in 0..n {\n if s.get(i) != t.get(i) {\n println!(\"NO\");\n return;\n }\n }\n println!(\"YES\");\n}\n"}, {"source_code": "fn readln() -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n\n line\n}\n\n\nfn main() {\n let s = readln();\n let t = readln();\n\n let s = String::from(s.trim());\n let t:String = String::from(t.trim()).chars().rev().collect();\n\n println!(\"{}\", if s == t {\"YES\"} else {\"NO\"});\n}"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut word = String::new();\n\tio::stdin().read_line(&mut word).unwrap();\n\tlet word = word.trim();\n\t\n\tlet mut translation = String::new();\n\tio::stdin().read_line(&mut translation).unwrap();\n\tlet translation = translation.trim();\n\n\tif translation == word.chars().rev().collect::() {\n\t\tprintln!(\"YES\");\n\t} else {\n\t\tprintln!(\"NO\");\n\t}\n}\n"}, {"source_code": "#![allow(non_snake_case, unused_imports)]\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::{HashSet,HashMap,VecDeque,BinaryHeap};\n\n// Functions\n\n// Main\nfn main(){\n\n input!{\n S: chars,\n T: chars\n }\n\n let mut ans = \"YES\";\n for i in 0..S.len(){\n if S[i] != T[T.len()-1-i]{\n ans = \"NO\";\n break;\n }\n }\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut first = String::new();\n io::stdin().read_line(&mut first).unwrap();\n first = first.trim().to_string();\n let mut second = String::new();\n io::stdin().read_line(&mut second).unwrap();\n second = second.trim().chars().rev().collect();\n\n if first.contains(&second) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "use std::io;\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\n\nfn main() {\n let s = read_line();\n let t = read_line().chars().rev().collect::();\n\n if s == t {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n \n}"}, {"source_code": "use 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 out = &mut BufWriter::new(stdout());\n\n\tlet a = scan.next::();\n\tlet b = scan.next::();\n let c = a.chars().rev().collect::();\n\n writeln!(out, \"{}\", if b == c { \"YES\" } else { \"NO\" }).expect(\"fail\");\n}\n"}, {"source_code": "fn main() {\n // The input text need to be translated\n let mut s = String::new();\n let mut t = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n std::io::stdin().read_line(&mut t).unwrap();\n\n let vs: Vec = s.trim().chars().collect();\n let vt: Vec = t.trim().chars().collect();\n\n let mut b: bool = true;\n if vs.len() != vt.len() {\n b = false;\n } else {\n // Check duplicate characters\n let mut p: usize = 0;\n let mut q: usize = vt.len() - 1;\n loop {\n if vs[p] != vt[q] {\n b = false;\n break;\n }\n\n if p >= vs.len() || q <= 0 {\n break;\n }\n\n p += 1;\n q -= 1;\n }\n }\n\n // Display the result\n if b {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "//! http://codeforces.com/contest/41/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!(s: String);\n scanln!(t: String);\n let v: String = t.chars().rev().collect();\n println!(\"{}\",\n if &s == &v {\n \"YES\"\n } else {\n \"NO\"\n }\n );\n}\n"}, {"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] fn strarr() -> Vec {\n let mut inp = String::new();\n stdin().read_line(&mut inp).ok();\n inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).map(|x| x.to_string()).collect() }\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let s = strarr(); let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec) -> T\n where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut s = strarr(); let mut v = Vec::new();\n for i in 0..$n { v.push(s[i as usize].parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\n\nfn main()\n{\n let s = scan!(String);\n let t = scan!(String);\n println!(\"{}\", if s.chars().rev().collect::>() == t.chars().collect::>() { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "use std::io::{self, Write};\n\nfn main() {\n let mut s = String::new();\n let mut t = String::new();\n\n io::stdin().read_line(&mut s).expect(\"failed to read\");\n io::stdin().read_line(&mut t).expect(\"failed to read\");\n\n s = s.trim().to_string();\n t = t.trim().to_string();\n\n if s.len() != t.len() {\n print!(\"NO\");\n io::stdout().flush().expect(\"failed to flush\");\n return;\n }\n for i in 0..(s.len()) {\n let char_s = &s[i..(i + 1)];\n let char_t = &t[(t.len() - i - 1)..(t.len() - i)];\n if char_s != char_t {\n print!(\"NO\");\n io::stdout().flush().expect(\"failed to flush\");\n return;\n }\n }\n\n print!(\"YES\");\n io::stdout().flush().expect(\"failed to flush\");\n}\n"}, {"source_code": "use std::io;\n\nfn input() -> String {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n}\n\nfn main() {\n let (t, s) = (input(), input());\n if t == s.chars().rev().collect::() {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}"}, {"source_code": "//spnauti-rust\n#[allow(unused_imports)]\nuse std::io::{self,Read};\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n if input.s() == input.s().chars().rev().collect::() {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n\n"}, {"source_code": "fn main() {\n let mut s1 = String::new();\n std::io::stdin().read_line(&mut s1);\n let s1 = s1.trim();\n\n let mut s2 = String::new();\n std::io::stdin().read_line(&mut s2);\n let s2 = s2.trim();\n\n let s1_reversed: String = s1.chars().rev().collect();\n if s1_reversed.eq(s2) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}], "negative_code": [{"source_code": "use std::io;\n\nfn main() {\n\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n\n let vector: Vec<&str> = input.split(\"\\n\").collect();\n let second_vector: String = vector[1].chars().rev().collect();\n\n if vector[0].to_string().eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n\n let vector: Vec<&str> = input.split(\"\\r\\n\").collect();\n let first_vector = vector[0].to_string();\n let second_vector: String = vector[1].trim().chars().rev().collect();\n\n //println!(\"{:?}\", vector);\n\n if first_vector.eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut x = String::new();\n\n io::stdin().read_line(&mut x).expect(\"error\");\n\n if x.len() <= 100 && !x.contains(\" \") {\n let v: Vec<&str> = x.split(\"\\n\").collect();\n\n let mut z: String = String::from(\"\");\n let mut index = 0;\n let mut a: &str = \"\";\n\n for y in v {\n if index == 0 {\n z = y.chars().rev().collect();\n index += 1;\n } else {\n a = y;\n }\n }\n\n if !z.eq_ignore_ascii_case(a) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n\n let vector: Vec<&str> = input.split(\"\\r\").collect();\n let first_vector = vector[0].to_string();\n let second_vector: String = vector[1].trim_start().chars().rev().collect();\n\n if first_vector.eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut x = String::new();\n\n io::stdin().read_line(&mut x).expect(\"error\");\n\n if x.len() <= 100 && !x.contains(\" \") {\n let v: Vec<&str> = x.split(\"\\n\").collect();\n\n let mut z: String = String::from(\"\");\n let mut index = 0;\n let mut a: &str = \"\";\n\n for y in v {\n if index == 0 {\n z = y.chars().rev().collect();\n index += 1;\n } else {\n a = y;\n }\n }\n\n let g = z.as_str();\n\n if !z.eq_ignore_ascii_case(a) && g.eq_ignore_ascii_case(a) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut string = String::new();\n io::stdin().read_line(&mut string);\n\n let vector: Vec<&str> = string.split(\"\\n\").collect();\n let second_vector: String = vector[1].chars().rev().collect();\n\n if vector[0].to_string().eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO {} - {}\", vector[0], second_vector);\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut string = String::new();\n io::stdin().read_line(&mut string);\n\n let vector: Vec<&str> = string.split(\"\\n\").collect();\n let second_vector: String = vector[1].chars().rev().collect();\n\n if vector[0].to_string().eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n\n let vector: Vec<&str> = input.split(\"\\n\").collect();\n let second_vector: String = vector[1].trim().chars().rev().collect();\n\n if vector[0].trim().to_string().eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut string = String::new();\n io::stdin().read_line(&mut string);\n\n let vector: Vec<&str> = string.split(\"\\n\").collect();\n\n if vector[1].chars().eq(vector[0].chars().rev()) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n\n let vector: Vec<&str> = input.split(\"\\n\").collect();\n let first_vector = vector[0].to_string();\n let second_vector: String = vector[1].trim().chars().rev().collect();\n\n if first_vector.eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n println!(\"{:?}\", vector);\n\n println!(\"1. {}\", first_vector);\n println!(\"2. {}\", second_vector);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut string = String::new();\n io::stdin().read_line(&mut string);\n\n let vector: Vec<&str> = string.split(\"\\n\").collect();\n let second_vector: String = vector[1].chars().rev().collect();\n\n if vector[0].to_string().eq(&second_vector) {\n println!(\"YES\");\n } else {\n println!(\"NO {} - {}\", vector[0], vector[1]);\n }\n\n println!(\"{:?}\", vector);\n}\n"}], "src_uid": "35a4be326690b58bf9add547fb63a5a5"} {"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 mut input = input.trim().split(' ');\n let mut shoes = [i32::default();2];\n shoes[0] = input.next().unwrap().parse::().unwrap();\n shoes[1] = input.next().unwrap().parse::().unwrap();\n\n if shoes[0] > shoes[1] {\n shoes.swap(0, 1);\n }\n\n let fashion = shoes[0];\n let normal = (shoes[1] - fashion) / 2;\n\n println!(\"{} {}\", fashion, normal);\n\n\n}", "positive_code": [{"source_code": "use std::cmp::{max, min};\nuse std::io::stdin;\n\npub fn main() {\n let (red, blue) = {\n let mut buf = String::new();\n stdin().read_line(&mut buf).unwrap();\n let a: Vec = buf\n .trim()\n .split_ascii_whitespace()\n .map(|c| c.parse().unwrap())\n .collect();\n (a[0], a[1])\n };\n let hip_pairs = min(red, blue);\n let normal_pairs = (max(red, blue) - hip_pairs) / 2;\n println!(\"{} {}\", hip_pairs, normal_pairs);\n}\n"}, {"source_code": "fn input_pair() -> Vec {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().split_whitespace().map(|elem| elem.parse().unwrap()).collect()\n}\n\nfn main() {\n let input = input_pair();\n let (r, b) = (input[0], input[1]);\n let s = r.min(b);\n let l = (r.max(b) - s) / 2;\n println!(\"{} {}\", s, l);\n}"}, {"source_code": "type Pair = (u8, u8);\nfn input_pair() -> Pair {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let buf: Vec = buf.trim().split_whitespace().map(|elem| elem.parse().unwrap()).collect();\n (buf[0], buf[1])\n}\n\nfn main() {\n let (r, b) = input_pair();\n println!(\"{} {}\", r.min(b), (r.max(b) - r.min(b)) / 2);\n}"}, {"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 a = input.i();\n let b = input.i();\n let min = std::cmp::min(a, b);\n println!(\"{} {}\", min, (a + b - 2 * min) / 2);\n}\n\n"}, {"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 println!(\"{} {}\",std::cmp::min(a,b),(a+b-std::cmp::min(a,b)*2)/2);\n}\n"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut iterator = stdin.lock().lines();\n let line: String;\n let numbers: Vec;\n let (min, max): (i32, i32);\n\n line = iterator.next().unwrap().unwrap();\n numbers = line\n .split_whitespace()\n .map(|n| n.parse().unwrap())\n .collect();\n \n match numbers.iter().min() {\n Some(number) => min = *number,\n None => min = 0,\n }\n match numbers.iter().max() {\n Some(number) => max = *number,\n None => max = 0,\n }\n\n println!(\"{} {}\", min, (max-min)/2);\n}"}, {"source_code": "use std::io::stdin;\nfn main() {\n\tlet mut s = String::new();\n\tstdin().read_line(&mut s).unwrap();\n\tlet a: Vec = s\n\t\t.split_whitespace()\n\t\t.map(|x| x.parse().unwrap())\n\t\t.collect();\n\tprintln!(\"{} {}\", std::cmp::min(a[0], a[1]), (a[0] - a[1]).abs()/2)\n}\n"}, {"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\n let (a, b) = R!(usize, usize);\n\n println!(\"{} {}\", cmp::min(a, b), (cmp::max(a, b) - cmp::min(a, b)) / 2);\n\n}\n"}, {"source_code": "use std::error::Error;\nuse std::io;\n\nfn get_line() -> io::Result {\n\tlet mut buffer = String::new();\n\tio::stdin().read_line(&mut buffer)?;\n\tOk(buffer)\n}\n\nfn main() -> Result<(), Box> {\n\tlet input = get_line()?\n\t\t.split_whitespace()\n\t\t.map(|s| s.parse::())\n\t\t.collect::, _>>()?;\n\tlet diff = input[0].min(input[1]);\n\tlet same = (input[0].max(input[1]) - diff) / 2;\n\tprint!(\"{} {}\", diff, same);\n\tOk(())\n}\n"}, {"source_code": "macro_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\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\nfn main() {\n input! {\n red_socks: u32,\n blue_socks: u32,\n }\n\n let x = std::cmp::min(red_socks, blue_socks);\n let y = ((red_socks - x) + (blue_socks - x)) / 2;\n\n println!(\"{} {}\", x, y)\n}\n"}, {"source_code": "use std::io;\nuse std::io::BufRead;\nuse std::cmp;\n\nfn main() {\n let reader = io::stdin();\n\n let parts:Vec = \n reader.lock()\n .lines().next().unwrap().unwrap()\n .split_whitespace()\n .filter(|s| !s.is_empty())\n .map(|s| s.parse::().unwrap())\n .collect();\n \n let a:i8 = parts[0];\n let b:i8 = parts[1];\n\n println!(\"{} {}\", cmp::min(a, b), (a-b).abs() / 2 );\n\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/581/A\nuse std::io;\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 a = words[0];\n let b = words[1];\n\n println!(\"{} {}\", std::cmp::min(a,b), i64::abs((a-b)/2));\n}\n\n"}, {"source_code": "use std::io;\nuse std::cmp;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n let arr : Vec = s.split_whitespace().map(|s| s.parse().unwrap()).collect();\n let (a, b, x) = (arr[0], arr[1], cmp::min(arr[0], arr[1]));\n println!(\"{} {}\", x, (a + b - 2 * x) / 2);\n}"}, {"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 a: usize = scan.next();\n let b: usize = scan.next();\n let result1 = a.min(b);\n let result2 = (a.max(b) - result1) / 2;\n println!(\"{} {}\", result1, result2);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"source_code": "use std::io;\nuse std::cmp;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s)\n .expect(\"failed to read l2\");\n\n let values = s\n .split_whitespace()\n .map(|x| x.parse::())\n .collect::, _>>()\n .unwrap();\n\n assert!(values.len() == 2);\n let a = values[0];\n let b = values[1];\n\n let min = cmp::min(a,b);\n let rest_same_color_pairs = (cmp::max(a,b) - min) / 2;\n\n println!(\"{} {}\", min, rest_same_color_pairs);\n}\n"}, {"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 read_line_pair() -> (i64, i64) {\n let vec = read_line_vec();\n return (vec[0], vec[1]);\n}\n\nfn main() {\n \n let (a, b) = read_line_pair();\n\n let p1 = std::cmp::min(a, b);\n let p2 = ((a + b) - p1 - p1) / 2;\n\n println!(\"{} {}\", p1, p2);\n\n}"}], "negative_code": [], "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"source_code": "use std::fmt::Debug;\nuse std::io::stdin;\nuse std::str::FromStr;\n\nfn read_line() -> String {\n let mut buf = String::new();\n stdin().read_line(&mut buf).expect(\"Failed to read a line\");\n buf\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_line().trim().parse::().unwrap()\n}\n\nfn read_vector() -> Vec\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_line().trim().split_whitespace().map(|x| x.parse::().unwrap()).collect()\n}\n\nfn calculate_min_max_pairs(n: u64, m: u64) -> (u64, u64) {\n let get_pair_count = |x| x * (x - 1) / 2;\n let max_count = get_pair_count(n - m + 1);\n let (d, r) = (n / m, n % m);\n let min_count = (m - r) * get_pair_count(d) + r * get_pair_count(d + 1);\n (min_count, max_count)\n}\n\nfn main() {\n let (n, m) = {\n let v = read_vector::();\n (v[0], v[1])\n };\n let result = calculate_min_max_pairs(n, m);\n println!(\"{} {}\", result.0, result.1);\n}\n", "positive_code": [{"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 let mut bout = BufWriter::new(stdout());\n\n let f = |n,x| x * n * (n - 1) / 2;\n let n: i64 = input.p();\n let m: i64 = input.p();\n let r = n % m;\n writeln!(bout, \"{} {}\", f(n/m, m-r) + f(n/m+1, r), f(n-m+1, 1)).ok();\n}\n\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min};\n#[allow(unused_imports)]\nuse std::collections::HashMap;\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 foo(x : i32) -> i64 {\n let x : i64 = x as i64;\n return (x*(x-1))/2;\n}\n\nfn main() {\n let (n,m) = readln!(i32,i32);\n let a1 = foo(n-m+1);\n let r = n%m;\n let q = n/m;\n let a2 = r as i64*foo(q+1) + (m-r) as i64 *foo(q);\n println!(\"{} {}\",a2,a1);\n}\n"}, {"source_code": "\nfn c2 (x:i64) -> i64 { let y=x as i64; y * (y-1)/2 }\n\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let mut ints = s.split_whitespace().map(|x| x.parse::().unwrap());\n let n = ints.next().unwrap();\n let t = ints.next().unwrap();\n if n == t {\n println!(\"0 0\");\n } else {\n let max = c2(n - t + 1);\n let a = n/t;\n let b = n%t;\n let min = b*c2(a+1)+(t-b)*c2(a);\n println!(\"{} {}\",min, max);\n }\n\n}"}, {"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: u64 = scan.next();\n let m: u64 = scan.next();\n let maxcalc = (n-m+1) * (n-m) / 2;\n let minval1 = n/m + 1;\n let minval2 = n/m;\n let minn1 = n%m;\n let minn2 = m - minn1;\n let mincalc = (minval1*(minval1-1)/2)*minn1 \n + (minval2*(minval2-1)/2)*minn2;\n println!(\"{} {}\", mincalc, maxcalc);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"source_code": "fn solve() {\n let (n, m): (i64, i64) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut ws = buf.split_whitespace();\n let n = ws.next().unwrap().parse().unwrap();\n let m = ws.next().unwrap().parse().unwrap();\n (n, m)\n };\n\n let min = {\n let a = n / m;\n let b = n - a * m;\n (a + 1) * a / 2 * b + a * (a - 1) / 2 * (m - b)\n };\n\n let max = {\n let t = n - (m - 1);\n t * (t - 1) / 2\n };\n\n println!(\"{} {}\", min, max);\n}\n\nfn main() {\n // let t: u32 = {\n // let mut buf = String::new();\n // std::io::stdin().read_line(&mut buf).unwrap();\n // buf.trim_end().parse().unwrap()\n // };\n\n // for _ in 0..t {}\n solve();\n}\n"}], "negative_code": [{"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: u64 = scan.next();\n let m: u64 = scan.next();\n if n == m {\n println!(\"{} {}\", m, m);\n return;\n }\n let maxcalc = (n-m+1) * (n-m) / 2;\n let minval1 = n/m + 1;\n let minval2 = n/m;\n let minn1 = n%m;\n let minn2 = m - minn1;\n let mincalc = (minval1*(minval1-1)/2)*minn1 \n + (minval2*(minval2-1)/2)*minn2;\n println!(\"{} {}\", mincalc, maxcalc);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}], "src_uid": "a081d400a5ce22899b91df38ba98eecc"} {"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/// 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 self.x.fmt(f)\n }\n }\n impl From for ModInt {\n fn from(x: i64) -> Self { Self::new(x) }\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, verified as NTT only)\n/// R: Ring + Copy\n/// Verified by: https://codeforces.com/contest/1096/submission/47672373\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 { f.swap(i, j); }\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 base = zetapow.pop().unwrap();\n let mut r = 0;\n while r < n {\n let mut w = one;\n for s in r .. r + m {\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 += 2 * m;\n }\n m *= 2;\n }\n }\n}\n\nuse fft::*;\n\n// Depends on ModInt.rs\nfn fact_init(w: usize) -> (Vec, Vec) {\n let mut fac = vec![ModInt::new(1); w];\n let mut invfac = vec![0.into(); w];\n for i in 1 .. w {\n fac[i] = fac[i - 1] * i as i64;\n }\n invfac[w - 1] = fac[w - 1].inv();\n for i in (0 .. w - 1).rev() {\n invfac[i] = invfac[i + 1] * (i as i64 + 1);\n }\n (fac, invfac)\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 l: i64,\n }\n const N: usize = 4096;\n let (fac, invfac) = fact_init(N);\n\n let mut p = vec![ModInt::new(0); N];\n let mut q = vec![ModInt::new(0); N];\n p[1] = ModInt::new(2);\n p[2] = -ModInt::new(2);\n q[0] = ModInt::new(1);\n q[1] = -ModInt::new(2);\n q[2] = ModInt::new(2);\n\n let zeta = ModInt::new(3).pow((MOD - 1) / N as i64);\n transform(&mut p, zeta, ModInt::new(1));\n transform(&mut q, zeta, ModInt::new(1));\n\n let mut ans = vec![ModInt::new(0); N];\n let mut coef = vec![ModInt::new(0); N];\n for i in k..n + 1 {\n coef[i] = fac[n] * invfac[n - i] * invfac[i];\n }\n for j in 0..N {\n let mut pp = p[j].pow(k as i64);\n let mut qp = q[j].pow((n - k) as i64);\n let mut qinv = q[j].inv();\n for i in k..n + 1 {\n let coef = coef[i];\n ans[j] += pp * qp * coef;\n pp *= p[j];\n qp *= qinv;\n }\n }\n transform(&mut ans, zeta.inv(), ModInt::new(1));\n // eprintln!(\"ans = {:?}\", &ans[0..10]);\n let mut tot = ModInt::new(0);\n for i in 0..2 * n + 1 {\n tot += ans[i] * ModInt::new((i + 1) as i64).inv();\n }\n tot *= ModInt::new(N as i64).inv();\n puts!(\"{}\\n\", tot * l);\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", "positive_code": [{"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\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 pub fn comb(n: u32, k: u32) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n let k = std::cmp::min(k, n - k);\n let mut nu = ModInt::one();\n let mut de = ModInt::one();\n for i in 0..k {\n nu *= ModInt(n - i);\n de *= ModInt(i + 1);\n }\n nu * de.inv()\n }\n}\n\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 ModInt ----------\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 k: usize = it.next().unwrap().parse().unwrap();\n let l: u32 = it.next().unwrap().parse().unwrap();\n let pc = Precalc::new(2 * n + 1);\n let mut dp = vec![ModInt::zero(); 2 * n + 1];\n dp[0] = ModInt::one();\n for i in 0..n {\n for j in (0..=(2 * i)).rev() {\n let p = dp[j];\n dp[j + 2] -= ModInt(2) * p;\n dp[j + 1] += ModInt(2) * p;\n dp[j] = ModInt(0);\n }\n }\n let mut ans = ModInt::zero();\n for i in (k..=n).rev() {\n let mut eval = ModInt::zero();\n for j in 0..=(2 * n) {\n eval += dp[j] * pc.inv(j + 1)\n }\n ans += pc.comb(n, i) * eval;\n let f = ModInt(2).inv();\n let mut next = vec![ModInt::zero(); 2 * n + 1];\n for j in (2..=(2 * n)).rev() {\n let v = dp[j];\n dp[j - 1] += v;\n next[j - 2] = -v * f;\n }\n dp = next;\n for j in (0..=(2 * (n - 1))).rev() {\n let v = dp[j];\n dp[j + 2] += ModInt(2) * v;\n dp[j + 1] -= ModInt(2) * v;\n }\n }\n ans *= ModInt(l);\n println!(\"{}\", ans.0);\n}\n\nfn main() {\n run();\n}\n"}], "negative_code": [], "src_uid": "c9e79e83928d5d034123ebc3b2f5e064"} {"source_code": "use std::io;\n\nfn main() {\n let n: usize = {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input.trim().parse().unwrap()\n };\n\n let a: Vec = {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input.split_whitespace().map(|k| k.parse().unwrap()).collect()\n };\n\n let ans = n % 2 == 1 && a.first().unwrap() % 2 == 1 && a.last().unwrap() % 2 == 1;\n\n if ans {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n}\n", "positive_code": [{"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 let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line_to_vec: failed at `handle.read_line`.\");\n \n for s in buffer.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\ntrait Ext {\n fn is_odd(&self) -> bool;\n fn is_even(&self) -> bool;\n}\n\nimpl Ext for i32 {\n #[inline]\n fn is_odd(&self) -> bool {\n self % 2 != 0\n }\n\n #[inline]\n fn is_even(&self) -> bool {\n self % 2 == 0\n }\n}\n\nfn main() {\n let (n,) = scan_line!(usize);\n let array = scan_line_to_vec!(i32);\n\n let mut result = true;\n result &= array[0].is_odd();\n result &= array[n - 1].is_odd();\n result &= (array.len() as i32).is_odd();\n\n\n if result {\n println!(\"YES\")\n } else {\n println!(\"NO\")\n }\n}"}], "negative_code": [{"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 let mut buffer = String::new();\n handle.read_line(&mut buffer)\n .expect(\"scan_line_to_vec: failed at `handle.read_line`.\");\n \n for s in buffer.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\ntrait Ext {\n fn is_odd(&self) -> bool;\n fn is_even(&self) -> bool;\n}\n\nimpl Ext for i32 {\n #[inline]\n fn is_odd(&self) -> bool {\n self % 2 != 0\n }\n\n #[inline]\n fn is_even(&self) -> bool {\n self % 2 == 0\n }\n}\n\nfn main() {\n let (n,) = scan_line!(usize);\n let array = scan_line_to_vec!(i32);\n\n let mut result = true;\n\n let mut i = 0;\n let mut segment_count = 0;\n let mut count_evens = 0;\n\n while i < (n - 1) {\n if array[i].is_odd() && array[i+1].is_odd() {\n segment_count += 1;\n } else if array[i].is_odd() && array[i+1].is_even() {\n count_evens += 1;\n } else if array[i].is_even() && array[i+1].is_even() {\n count_evens += 1;\n } else if array[i].is_even() && array[i+1].is_odd() {\n if count_evens.is_odd() {\n count_evens = 0;\n segment_count += 1;\n i += 1;\n } else {\n result = false;\n break;\n }\n }\n i += 1;\n }\n\n if i == n - 1 && array[n - 1].is_odd() {\n segment_count += 1;\n } else if i == n - 1 {\n result = false;\n }\n\n if segment_count.is_even() {\n result = false;\n }\n\n if result {\n println!(\"YES\")\n } else {\n println!(\"NO\")\n }\n}"}], "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"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 s = \"aeiou13579\";\n let sol = input.sl().chars().filter(|&c| s.chars().any(|a| a == c)).count();\n println!(\"{}\", sol);\n}\n\n", "positive_code": [{"source_code": "use std::io::Read;\n\nfn main() {\n let stdin = std::io::stdin();\n let x = stdin.bytes().map(|c| {\n let c = c.unwrap();\n c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' || (c >= b'0' && c <= b'9' && (c - b'0') % 2 == 1)\n }).filter(|&x| x).count();\n println!(\"{}\", x);\n}\n"}, {"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 is_vowel(z: char)->bool {\n let s = \"aeoiu\";\n return s.chars().any(|x|x==z);\n}\n\nfn is_odd(z: char)->bool {\n let s = \"13579\";\n return s.chars().any(|x|x==z);\n}\n\nfn main() {\nlet s = readln!();\nprintln!(\"{}\",s.chars().filter(|&x| is_vowel(x) || is_odd(x)).count());\n}\n"}, {"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 is_vowel(ch: char) -> bool {\n return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let mut result = 0usize;\n for ch in scan.next::().chars() {\n if is_vowel(ch) || ch.to_digit(10).unwrap_or(2) % 2 == 1 {\n result += 1;\n }\n }\n println!(\"{}\", result);\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"}, {"source_code": "fn read_line() -> Option {\n let stdin = std::io::stdin();\n let mut line = String::new();\n if stdin.read_line(&mut line).unwrap_or(0) > 0 {\n Some(line.trim().into())\n } else {\n None\n }\n}\n\nfn main() {\n fn should_flip(c: char) -> bool {\n (\n (c.is_digit(10) && (c as u8 - '0' as u8) % 2 == 1) ||\n (['a', 'e', 'i', 'o', 'u'].iter().find(|&&a| a == c).is_some())\n )\n }\n let flips = read_line()\n .expect(\"should have line\")\n .chars()\n .fold(0, |acc, c| if should_flip(c) { acc + 1 } else { acc });\n println!(\"{}\", flips);\n}\n"}, {"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\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 s: chars,\n }\n let c = s.iter().filter(|&&c| {\n if c <= '9' {\n (c as u8 - b'0') % 2 == 1\n } else {\n ['a', 'e', 'i', 'o', 'u'].iter().find(|&&x| x == c).is_some()\n }\n }).count();\n puts!(\"{}\\n\", c);\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"}], "negative_code": [{"source_code": "fn read_line() -> Option {\n let stdin = std::io::stdin();\n let mut line = String::new();\n if stdin.read_line(&mut line).unwrap_or(0) > 0 {\n Some(line.trim().into())\n } else {\n None\n }\n}\n\nfn main() {\n fn should_flip(c: char) -> bool {\n (\n (c.is_digit(10) && (c as u8 - '0' as u8) % 2 == 0) ||\n (['a', 'e', 'i', 'o', 'u'].iter().find(|&&a| a == c).is_some())\n )\n }\n let flips = read_line()\n .expect(\"should have line\")\n .chars()\n .fold(0, |acc, c| if should_flip(c) { acc + 1 } else { acc });\n println!(\"{}\", flips);\n}\n"}], "src_uid": "b4af2b8a7e9844bf58ad3410c2cb5223"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::collections::HashSet;\n\nstruct Reader {}\n\nimpl Reader {\n #[allow(unused)]\n fn read_string() -> String {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n string.trim().to_string()\n }\n\n #[allow(unused)]\n fn read_tokens() -> Vec:: {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n let mut v = Vec::new();\n for value in string.split_whitespace() {\n v.push(value.to_string());\n }\n v\n }\n}\n\n//mod math;\n\npub fn generate_simple_numbers(max_value: u64) -> Vec {\n let mut src = vec![true; max_value as usize + 1];\n let mut dst = Vec::new();\n\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n let mut ind = i * i;\n while ind <= max_value as usize {\n src[ind] = false;\n ind += i;\n }\n dst.push(i as u64);\n }\n }\n dst\n}\n\nfn main() {\n let n = Reader::read_string().parse::().unwrap();\n let simple_numbers = generate_simple_numbers(3000);\n let mut ans = 0_u64;\n for i in 1..=n {\n let mut number = i as u64;\n let mut map = std::collections::BTreeSet::::new();\n for value in simple_numbers.iter() {\n if *value > number {\n break;\n }\n while number % *value == 0 {\n map.insert(*value);\n number /= *value;\n }\n }\n if map.len() == 2 {\n ans += 1;\n }\n }\n println!(\"{}\", ans);\n}", "positive_code": [{"source_code": "fn sieve_of_eratosthene(n: usize) -> Vec {\n let mut is_prime = vec![true; std::cmp::max(n, 2)];\n\n is_prime[0] = false;\n is_prime[1] = false;\n \n\n let mut i = 2;\n loop {\n while i < n && !is_prime[i] {\n i += 1;\n }\n\n let cur_prime = i;\n\n let mut q = 2;\n while q * cur_prime < n {\n is_prime[q * cur_prime] = false;\n q += 1;\n }\n\n i += 1;\n if i >= n {\n return is_prime;\n }\n }\n}\n\nfn primes(is_prime: &Vec) -> Vec {\n let mut primes = Vec::new();\n for i in 0..is_prime.len() {\n if is_prime[i] {\n primes.push(i);\n }\n }\n \n primes\n}\n\nfn is_number_good(prime: &Vec, n: usize) -> bool {\n let mut firstmult = 0;\n\n for i in 0..prime.len() {\n if n % prime[i] == 0 {\n firstmult = prime[i];\n break;\n }\n }\n\n let mut secmult = 0;\n for i in 0..prime.len() {\n if n % prime[i] == 0 && prime[i] != firstmult {\n secmult = prime[i];\n break;\n }\n }\n\n if secmult == 0 {\n return false;\n }\n\n for i in 0..prime.len() {\n if n % prime[i] == 0 && prime[i] != firstmult && prime[i] != secmult {\n return false\n }\n }\n\n true\n}\nfn main() {\n let mut str = String::new();\n\n std::io::stdin().read_line(&mut str).unwrap();\n\n let n = str.trim().parse::().unwrap();\n\n let is_prime = sieve_of_eratosthene(n);\n\n let mut c = 0;\n for i in 2..=n {\n if is_number_good(&primes(&is_prime), i) {\n c += 1;\n }\n }\n\n println!(\"{}\", c);\n}\n\n"}, {"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 count_prime_factors(n: i32) -> i32 {\n let mut count = 0;\n let mut factor = 2;\n let mut n = n;\n while factor * factor <= n {\n let mut expo = 0;\n while n % factor == 0 {\n n /= factor;\n expo += 1;\n }\n if expo >= 1 {\n count += 1;\n }\n factor += 1;\n }\n if n > 1 {\n count += 1;\n }\n count\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let n: i32 = scan.token();\n let mut ans = 0;\n for i in 1..=n {\n let count = count_prime_factors(i);\n if count == 2 {\n ans += 1;\n }\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"}, {"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.u();\n let mut p = vec![0; n + 1];\n let mut sol = 0;\n for i in 2..=n {\n if p[i] == 0 {\n let mut j = i;\n while j <= n {\n p[j] += 1;\n j += i;\n }\n } else if p[i] == 2 {\n sol += 1;\n }\n }\n println!(\"{}\", sol);\n}\n\n"}, {"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 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 n: usize = scan.next();\n let mut count = [0; 3001];\n let mut result = 0usize;\n let mut i = 2usize;\n while i <= n {\n if count[i] == 0 {\n let mut j = 2;\n while i * j <= n {\n count[i * j] += 1;\n j += 1;\n }\n }\n i += 1;\n }\n for i in 2..=n {\n if count[i] == 2 {\n result += 1;\n }\n }\n println!(\"{}\", result);\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"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::collections::HashSet;\n\nstruct Reader {}\n\nimpl Reader {\n #[allow(unused)]\n fn read_string() -> String {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n string.trim().to_string()\n }\n\n #[allow(unused)]\n fn read_tokens() -> Vec:: {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n let mut v = Vec::new();\n for value in string.split_whitespace() {\n v.push(value.to_string());\n }\n v\n }\n}\n\n//mod math;\n\nfn generate_simple_numbers(max_value: i64) -> Vec {\n let mut src = vec![true; max_value as usize + 1];\n let mut dst = Vec::new();\n\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n let mut ind = i * i;\n while ind <= max_value as usize {\n src[ind] = false;\n ind += i;\n }\n }\n }\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n dst.push(i as i64);\n }\n }\n dst\n}\n\n\nfn main() {\n\n let n = Reader::read_string().parse::().unwrap();\n let simple_numbers = generate_simple_numbers(3000);\n let mut ans = 0_i64;\n for i in 1..=n {\n let mut number = i;\n let mut map = std::collections::BTreeSet::::new();\n for value in simple_numbers.iter() {\n if *value > number {\n break;\n }\n while number % *value == 0 {\n map.insert(*value);\n number /= *value;\n }\n }\n if map.len() == 2 {\n ans += 1;\n }\n }\n println!(\"{}\", ans);\n}"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::collections::HashSet;\n\nstruct Reader {}\n\nimpl Reader {\n #[allow(unused)]\n fn read_string() -> String {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n string.trim().to_string()\n }\n\n #[allow(unused)]\n fn read_tokens() -> Vec:: {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n let mut v = Vec::new();\n for value in string.split_whitespace() {\n v.push(value.to_string());\n }\n v\n }\n}\n\n//mod math;\n\nfn generate_simple_numbers(max_value: i64) -> Vec {\n let mut src = vec![true; max_value as usize + 1];\n let mut dst = Vec::new();\n\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n let mut ind = i * i;\n while ind <= max_value as usize {\n src[ind] = false;\n ind += i;\n }\n }\n }\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n dst.push(i as i64);\n }\n }\n dst\n}\n\n\nfn main() {\n\n let n = Reader::read_string().parse::().unwrap();\n let simple_numbers = generate_simple_numbers(3000);\n let mut ans = 0_i64;\n for i in 1..=n {\n let mut number = i;\n let mut map = std::collections::HashMap::::new();\n for value in simple_numbers.iter() {\n if *value > number {\n break;\n }\n while number % *value == 0 {\n map.insert(*value, 1);\n number /= *value;\n }\n }\n if map.len() == 2 {\n ans += 1;\n }\n }\n println!(\"{}\", ans);\n}"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::collections::HashSet;\n\nstruct Reader {}\n\nimpl Reader {\n #[allow(unused)]\n fn read_string() -> String {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n string.trim().to_string()\n }\n\n #[allow(unused)]\n fn read_tokens() -> Vec:: {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string).unwrap();\n let mut v = Vec::new();\n for value in string.split_whitespace() {\n v.push(value.to_string());\n }\n v\n }\n}\n\n//mod math;\n\nfn generate_simple_numbers(max_value: i64) -> Vec {\n let mut src = vec![true; max_value as usize + 1];\n let mut dst = Vec::new();\n\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n let mut ind = i * i;\n while ind <= max_value as usize {\n src[ind] = false;\n ind += i;\n }\n }\n }\n for i in 2 .. max_value as usize + 1 {\n if src[i] {\n dst.push(i as i64);\n }\n }\n dst\n}\n\n\nfn main() {\n\n let n = Reader::read_string().parse::().unwrap();\n let simple_numbers = generate_simple_numbers(3000);\n let mut ans = 0_i64;\n for i in 1..=n {\n let mut number = i;\n let mut map = std::collections::HashMap::::new();\n for value in simple_numbers.iter() {\n while number % *value == 0 {\n map.insert(*value, 1);\n number /= *value;\n }\n }\n if map.len() == 2 {\n ans += 1;\n }\n }\n println!(\"{}\", ans);\n}"}], "negative_code": [{"source_code": "fn sieve_of_eratosthene(n: usize) -> Vec {\n let mut is_prime = vec![true; std::cmp::max(n, 2)];\n\n is_prime[0] = false;\n is_prime[1] = false;\n \n\n let mut i = 2;\n loop {\n while i < n && !is_prime[i] {\n i += 1;\n }\n\n let cur_prime = i;\n\n let mut q = 2;\n while q * cur_prime < n {\n is_prime[q * cur_prime] = false;\n q += 1;\n }\n\n i += 1;\n if i >= n {\n return is_prime;\n }\n }\n}\n\nfn primes(is_prime: &Vec) -> Vec {\n let mut primes = Vec::new();\n for i in 0..is_prime.len() {\n if is_prime[i] {\n primes.push(i);\n }\n }\n \n primes\n}\n\nfn is_number_good(prime: &Vec, n: usize) -> bool {\n let mut firstmultiplier = 0;\n\n for i in 0..prime.len() {\n if n % prime[i] == 0 {\n firstmultiplier = prime[i];\n }\n }\n\n for i in 0..prime.len() {\n if n % prime[i] == 0 && prime[i] != firstmultiplier {\n return true;\n }\n }\n\n false\n}\n\nfn main() {\n let mut str = String::new();\n\n std::io::stdin().read_line(&mut str).unwrap();\n\n let n = str.trim().parse::().unwrap();\n\n let is_prime = sieve_of_eratosthene(n);\n\n let mut c = 0;\n for i in 2..n {\n if is_number_good(&primes(&is_prime), i) {\n c += 1;\n }\n }\n\n println!(\"{}\", c);\n}\n\n"}, {"source_code": "fn sieve_of_eratosthene(n: usize) -> Vec {\n let mut is_prime = vec![true; std::cmp::max(n, 2)];\n\n is_prime[0] = false;\n is_prime[1] = false;\n \n\n let mut i = 2;\n loop {\n while i < n && !is_prime[i] {\n i += 1;\n }\n\n let cur_prime = i;\n\n let mut q = 2;\n while q * cur_prime < n {\n is_prime[q * cur_prime] = false;\n q += 1;\n }\n\n i += 1;\n if i >= n {\n return is_prime;\n }\n }\n}\n\nfn primes(is_prime: &Vec) -> Vec {\n let mut primes = Vec::new();\n for i in 0..is_prime.len() {\n if is_prime[i] {\n primes.push(i);\n }\n }\n \n primes\n}\n\nfn is_number_good(prime: &Vec, n: usize) -> bool {\n let mut firstmultiplier = 0;\n\n for i in 0..prime.len() {\n if n % prime[i] == 0 {\n firstmultiplier = prime[i];\n }\n }\n\n for i in 0..prime.len() {\n if n % prime[i] == 0 && prime[i] != firstmultiplier {\n return true;\n }\n }\n\n false\n}\n\nfn main() {\n let mut str = String::new();\n\n std::io::stdin().read_line(&mut str).unwrap();\n\n let n = str.trim().parse::().unwrap();\n\n let is_prime = sieve_of_eratosthene(n);\n\n let mut c = 0;\n for i in 2..=n {\n if is_number_good(&primes(&is_prime), i) {\n c += 1;\n }\n }\n\n println!(\"{}\", c);\n}\n\n"}], "src_uid": "356666366625bc5358bc8b97c8d67bd5"} {"source_code": "use std::io;\n\nstruct Prime {\n a: Vec,\n al: usize,\n t: Vec,\n}\n\n#[allow(dead_code)]\nimpl Prime {\n fn new(n: usize) -> Self {\n let mut t = vec![2; 1];\n let s = (n as f64).sqrt().round() as usize + 3;\n let mut a = vec![true; s];\n a[0] = false;\n a[1] = false;\n for i in (4..s).step_by(2) {\n a[i] = false;\n }\n for i in (3..s).step_by(2) {\n if !a[i] {\n continue;\n }\n t.push(i);\n if i * i < s {\n for j in ((i * i)..s).step_by(i * 2) {\n a[j] = false;\n }\n }\n }\n let al = a.len();\n Prime { a, al, t }\n }\n\n fn is_prime(&self, x: usize) -> bool {\n if x < self.al {\n return self.a[x];\n }\n\n for c in self.t.iter() {\n if x % c == 0 {\n return false;\n }\n }\n\n true\n }\n}\n\n#[allow(dead_code)]\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\n let mut r = 3;\n if n > 3 && n % 2 == 0 {\n r = 2;\n } else {\n let pr = Prime::new(n);\n if pr.is_prime(n) {\n r = 1;\n } else if pr.is_prime(n - 2) {\n r = 2;\n }\n }\n\n rr.push(format!(\"{}\", r));\n }\n\n rr\n}\n\n#[allow(dead_code)]\nfn main() {\n let output = solve();\n println!(\"{}\", output.join(\"\\n\"));\n}\n", "positive_code": [{"source_code": "//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\n//\n\nfn is_prime(n: u64) -> bool {\n if n <= 1 {\n return false;\n }\n for k in (2..).take_while(|k| k * k <= n) {\n if n % k == 0 {\n return false;\n }\n }\n true\n}\n\nfn run() {\n input! {\n n: u64,\n }\n let ans = if is_prime(n) {\n 1\n } else if n % 2 == 0 {\n 2\n } else if is_prime(n - 2) {\n 2\n } else {\n 3\n };\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"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 n: i64 = sc.ne();\n let ans = if is_prime(n) {\n 1\n } else if n & 1 == 0 || is_prime(n - 2) {\n 2\n } else {\n 3\n };\n println!(\"{}\", ans);\n}\n\nfn is_prime(x: i64) -> bool {\n let mut y = 2;\n while y * y <= x {\n if x % y == 0 {\n return false;\n }\n y += 1;\n }\n x != 1\n}\nconst DEFAULT_STACK: usize = 16 * 1024 * 1024;\nfn main() {\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"}], "negative_code": [{"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 n: i64 = sc.ne();\n let ans = if is_prime(n) {\n 1\n } else if n & 1 == 1 {\n 3\n } else {\n 2\n };\n println!(\"{}\", ans);\n}\n\nfn is_prime(x: i64) -> bool {\n let mut y = 2;\n while y * y <= x {\n if x % y == 0 {\n return false;\n }\n y += 1;\n }\n x != 1\n}\nconst DEFAULT_STACK: usize = 16 * 1024 * 1024;\nfn main() {\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"}, {"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 n: i64 = sc.ne();\n fn solve(n: i64) -> i64 {\n if is_prime(n) {\n return 1;\n }\n let mut x = n - 2;\n while is_prime(x) == false {\n x -= 1;\n }\n 1 + solve(n - x)\n }\n println!(\"{}\", solve(n));\n}\n\nfn is_prime(x: i64) -> bool {\n let mut y = 2;\n while y * y <= x {\n if x % y == 0 {\n return false;\n }\n y += 1;\n }\n x != 1\n}\nconst DEFAULT_STACK: usize = 16 * 1024 * 1024;\nfn main() {\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": "684ce84149d6a5f4776ecd1ea6cb455b"} {"source_code": "use std::io;\nuse std::cmp::Ordering;\n\nfn read_int_line () -> i32 {\n let mut num = String::new();\n io::stdin().read_line(&mut num)\n .expect(\"Failed to read line\");\n \n num.trim().parse()\n .expect(\"Not an integer\")\n}\n\nfn main() {\n\n let num = read_int_line();\n\n let mut a: i32 = -1;\n let mut b: i32 = -1;\n\n let mut an: i32 = 0;\n let mut bn: i32 = 0;\n\n let mut foo: bool = true;\n\n for i in (0..num).rev(){\n let temp = read_int_line();\n match temp.cmp(&a) {\n Ordering::Equal => an += 1,\n _ => match temp.cmp(&b) {\n Ordering::Equal => bn += 1,\n _ => match b.cmp(&(-1)) {\n Ordering::Equal => b = temp, \n _ => match a.cmp(&-1) {\n Ordering::Equal => a = temp,\n _ => { println!(\"NO\"); foo = false; break; } ,\n }\n },\n },\n }\n }\n\n if foo {\n match a.cmp(&b) {\n Ordering::Equal => println!(\"NO\"),\n _ => match an.cmp(&bn) {\n Ordering::Equal => {println!(\"YES\"); println!(\"{} {}\", a, b);},\n _ => println!(\"NO\"),\n },\n }\n }\n}\n", "positive_code": [{"source_code": "use std::io;\nuse std::cmp::Ordering;\n\nfn read_int_line () -> i32 {\n let mut num = String::new();\n io::stdin().read_line(&mut num)\n .expect(\"Failed to read line\");\n \n num.trim().parse()\n .expect(\"Not an integer\")\n}\n\nfn main() {\n\n let num = read_int_line();\n\n let mut a: i32 = -1;\n let mut b: i32 = -1;\n\n let mut an: i32 = 0;\n let mut bn: i32 = 0;\n\n let mut foo: bool = true;\n\n for i in (0..num).rev(){\n let temp = read_int_line();\n if !foo {\n\n }\n else if a == temp {\n an += 1;\n }\n else if b == temp {\n bn += 1;\n } \n else if b == -1 {\n b = temp;\n }\n else if a == -1 {\n a = temp;\n }\n else {\n foo = false; \n }\n }\n\n if foo {\n match a.cmp(&b) {\n Ordering::Equal => println!(\"NO\"),\n _ => match an.cmp(&bn) {\n Ordering::Equal => {println!(\"YES\"); println!(\"{} {}\", a, b);},\n _ => println!(\"NO\"),\n },\n }\n }\n else {\n println!(\"NO\"); \n }\n}\n"}, {"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 mut set = vec![0; 100];\n\n for s in BufReader::new(io::stdin()).lines() {\n let s = s.unwrap();\n let a: usize = s.trim().parse::().unwrap() - 1;\n set[a] += 1;\n }\n\n let ans = set.iter().filter(|&&x| x != 0).count() == 2\n && {\n let mut it = set.iter().filter(|&&x| x != 0);\n it.next().unwrap() == it.next().unwrap()\n };\n\n if ans {\n println!(\"YES\");\n for (i, _) in set.iter().enumerate().filter(|&(_, &x)| x != 0) {\n print!(\"{} \", i + 1);\n }\n println!(\"\");\n } else {\n println!(\"NO\");\n }\n}\n"}], "negative_code": [], "src_uid": "2860b4fb22402ea9574c2f9e403d63d8"} {"source_code": "use std::io;\n\nfn main() {\n let (mut cnt1, mut cnt2);\n\n cnt1 = 0;\n cnt2 = 0;\n\n let mut s = String::new();\n io::stdin().read_line(&mut s).expect(\"Failed to read line\");\n\n let n: usize = s.trim().parse().unwrap();\n\n s = String::new();\n io::stdin().read_line(&mut s).expect(\"Failed to read line\");\n let a = s\n .split_whitespace()\n .map(|x| x.parse::())\n .collect::, _>>()\n .unwrap();\n\n s = String::new();\n io::stdin().read_line(&mut s).expect(\"Failed to read line\");\n let b = s\n .split_whitespace()\n .map(|x| x.parse::())\n .collect::, _>>()\n .unwrap();\n \n for i in 0usize..n {\n if a[i] == 1 && b[i] == 0 {\n cnt1 = cnt1 + 1;\n } else if a[i] == 0 && b[i] == 1 {\n cnt2 = cnt2 + 1;\n }\n }\n\n if cnt1 == 0 {\n println!(\"-1\");\n } else {\n println!(\"{}\", cnt2 / cnt1 + 1);\n }\n}\n", "positive_code": [{"source_code": "fn get_input() -> String {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).unwrap();\n buffer\n}\n\nfn main() {\n let _n = get_input().trim().parse::().unwrap();\n let ra: Vec = get_input().trim().split(' ').map(|x| x.parse::().unwrap()).collect();\n let rb: Vec = get_input().trim().split(' ').map(|x| x.parse::().unwrap()).collect();\n let mut badv = 0;\n let mut rchn = 0;\n for (rv, bv) in ra.iter().zip(rb) {\n if *rv == 0 && bv == 1 {\n badv += 1;\n } else if *rv == 1 && bv == 0 {\n rchn += 1;\n }\n }\n\n if rchn == 0 {\n println!(\"{}\", -1);\n } else if badv == 0 {\n println!(\"{}\", 1);\n } else {\n let rwin = badv + 1;\n if rwin % rchn != 0 {\n println!(\"{}\", 1 + (rwin / rchn));\n } else {\n println!(\"{}\", rwin / rchn);\n }\n }\n}\n"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut lines = stdin.lock().lines();\n let _ = lines.next().unwrap().unwrap().parse::().unwrap();\n let a: Vec = lines.next().unwrap().unwrap().split(\" \").map(|s| s.parse::().unwrap()).collect();\n let b: Vec = lines.next().unwrap().unwrap().split(\" \").map(|s| s.parse::().unwrap()).collect();\n println!(\"{}\", solve(a, b).unwrap_or(-1));\n}\n\npub fn solve( a: Vec, b: Vec) -> Option {\n let b_score = a.iter().zip(b.iter()).fold(0, |mut acc, (x,y)| {\n if x < y {\n acc += 1;\n }\n acc\n });\n let outperform = a.iter().zip(b.iter()).fold(0, |mut acc, (x,y)| {\n if x > y {\n acc += 1;\n }\n acc\n });\n match outperform {\n 0 => None,\n r => Some(b_score / outperform + 1),\n }\n}"}, {"source_code": "struct Scanner {\n buffer : std::collections::VecDeque\n }\n\n impl Scanner {\n\n fn new() -> Scanner {\n Scanner {\n buffer: std::collections::VecDeque::new()\n }\n }\n\n fn next(&mut self) -> T {\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 let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n\n}\n\nfn main() {\n let mut scanner = Scanner::new();\n let n : usize = scanner.next();\n let mut r: Vec = Vec::new();\n let (mut r_win, mut b_win) = (0, 0);\n for _ in 0..n {\n let num : i32 = scanner.next();\n r.push(num);\n }\n for i in 0..n {\n let num : i32 = scanner.next();\n if num > r[i] {\n b_win += 1;\n } else if num < r[i] {\n r_win += 1;\n }\n }\n if r_win == 0 {\n println!(\"-1\");\n } else {\n println!(\"{}\", b_win / r_win + 1);\n }\n}"}, {"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#[macro_export]\nmacro_rules ! cfor { ( ; $ ( $ rest : tt ) * ) => { cfor ! ( ( ) ; $ ( $ rest ) * ) } ; ( $ ( $ init : stmt ) ,+; ; $ ( $ rest : tt ) * ) => { cfor ! ( $ ( $ init ) ,+; ! false ; $ ( $ rest ) * ) } ; ( $ ( $ init : stmt ) ,+; $ cond : expr ; ; $ body : block ) => { cfor ! { $ ( $ init ) ,+; $ cond ; ( ) ; $ body } } ; ( $ ( $ init : stmt ) ,+; $ cond : expr ; $ ( $ step : expr ) ,+; $ body : block ) => { { $ ( $ init ; ) + while $ cond { let mut _first = true ; let mut _continue = false ; loop { if ! _first { _continue = true ; break } _first = false ; $ body } if ! _continue { break } $ ( $ step ; ) + } } } ; }\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:usize,\n a:[u8;n],\n b:[u8;n],\n }\n let mut acnt = 0;\n let mut btot = 0;\n for i in 0..n {\n if a[i] == b[i] {\n } else {\n if a[i] == 1 {\n acnt += 1;\n } else {\n btot += 1;\n }\n }\n }\n if acnt == 0 {\n writeln!(out,\"-1\");\n return\n }\n let ars = ArithSeq::new(0,acnt);\n let nxt = ars.next(btot+1);\n writeln!(out,\"{}\",nxt/acnt);\n}\nstruct ArithSeq {\n a: i64,\n b: i64,\n}\nimpl ArithSeq {\n pub fn new(a: i64, b: i64) -> ArithSeq {\n assert!(b > 0);\n ArithSeq { a: a, b: b }\n }\n #[doc = \"a+bi >= x\"]\n pub fn next(&self, x: i64) -> i64 {\n if x >= self.a {\n let d = x - self.a;\n let i = (d - 1 + self.b) / self.b;\n self.a + self.b * i\n } else {\n let d = self.a - x;\n let i = d / self.b;\n self.a - self.b * i\n }\n }\n #[doc = \"a+bi <= x\"]\n pub fn prev(&self, x: i64) -> i64 {\n let next = self.next(x);\n if next == x {\n x\n } else {\n next - self.b\n }\n }\n #[doc = \"[a+bi, n] <= [l, u]\"]\n pub fn range(&self, l: i64, u: i64) -> Option<(i64, i64)> {\n if l > u {\n return None;\n }\n let x = self.next(l);\n let y = self.prev(u);\n if x > y {\n return None;\n }\n assert!(x <= y);\n if l <= x && x <= u {\n let cnt = (y - x) / self.b;\n Some((x, cnt + 1))\n } else {\n None\n }\n }\n}"}, {"source_code": "use std::io::stdin;\n\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}\nfn main() {\n let mut scan = Scanner::default();\n let responses = scan.next::();\n let mut robo_coder_s = String::new();\n stdin().read_line(&mut robo_coder_s).expect(\"Failed read\");\n let robo_coder = robo_coder_s.split_whitespace().collect::>();\n let mut bionic_solver_s = String::new();\n stdin()\n .read_line(&mut bionic_solver_s)\n .expect(\"Failed read\");\n let bionic_solver = bionic_solver_s.split_whitespace().collect::>();\n\n let mut only_robo_coder_wins = 0.0;\n let mut only_bionic_solver_wins = 0.0;\n for response in 0..responses {\n match (robo_coder[response], bionic_solver[response]) {\n (\"1\", \"0\") => only_robo_coder_wins += 1.0,\n (\"0\", \"1\") => only_bionic_solver_wins += 1.0,\n _ => (),\n }\n }\n let robo_code_minimum_points: f64 = if only_robo_coder_wins == 0.0 {\n -1.0\n } else {\n (only_bionic_solver_wins + 1.0) / only_robo_coder_wins\n };\n println!(\"{}\", robo_code_minimum_points.ceil() as i32);\n}\n"}, {"source_code": "use std::io::stdin;\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 = scan.next::();\n let mut a = Vec::with_capacity(n);\n for _ in 0..n {\n a.push(scan.next::());\n }\n let mut b = Vec::with_capacity(n);\n for _ in 0..n {\n b.push(scan.next::());\n }\n let mut num_a = 0;\n let mut num_b = 0;\n for i in 0..n {\n if b[i] == 0 && a[i] == 1 {\n num_a += 1;\n } else if b[i] == 1 && a[i] == 0 {\n num_b += 1;\n }\n }\n let mut ans;\n if num_a == 0 {\n ans = -1;\n } else {\n ans = 1;\n while num_a * ans <= num_b {\n ans += 1;\n }\n }\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io::stdin;\n\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 main() {\n let mut scan = Scanner::default();\n let n = scan.next::();\n let mut a = vec![0; n];\n for i in 0..n {\n a[i] = scan.next::();\n }\n let mut b = vec![0; n];\n for i in 0..n {\n b[i] = scan.next::();\n }\n let mut num_a = 0;\n let mut num_b = 0;\n for i in 0..n {\n if a[i] == 1 && b[i] == 0 {\n num_a += 1;\n } else if a[i] == 0 && b[i] == 1 {\n num_b += 1;\n }\n }\n let ans = {\n if num_a == 0 {\n -1\n } else {\n let mut x = 1;\n while num_a * x <= num_b {\n x += 1;\n }\n x\n }\n };\n println!(\"{}\", ans);\n}\n"}], "negative_code": [], "src_uid": "b62338bff0cbb4df4e5e27e1a3ffaa07"} {"source_code": "use std::cmp::{max, min};\nuse std::io::stdin;\nfn main() {\n let mut text = String::new();\n stdin().read_line(&mut text).unwrap();\n text.clear();\n stdin().read_line(&mut text).unwrap();\n let text: Vec = text\n .trim()\n .split_whitespace()\n .map(|e| e.parse().unwrap())\n .collect();\n let mut v: Vec = vec![];\n for x in 1..(text.len() + 1) {\n let mut value = 0;\n for a in 1..(text.len() + 1) {\n value += (abs(x, a) + abs(1, a) + abs(1, x)) * text[a - 1] * 2\n }\n v.push(value)\n }\n v.sort();\n\n println!(\"{}\", v[0]);\n}\nfn abs(a: usize, b: usize) -> usize {\n max(a, b) - min(a, b)\n}\n", "positive_code": [{"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 println!(concat!($(stringify!($a), \"={:?} \"),*), $($a),*);\n }\n}\n\n#[allow(unused_imports)]\nuse std::cmp::{min, max};\n\nfn main() {\n input!{\n n: usize,\n aa: [i64; n],\n }\n let mut ans: i64 = 1 << 32;\n for i in 0i64..n as i64 {\n let mut cost = 0;\n for j in 0i64..n as i64 {\n cost += ((j-i).abs() + j + i) * 2 * aa[j as usize] as i64;\n }\n ans = min(cost, ans);\n }\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\n\n\nfn main() {\n let n = read_one::();\n let an = read::();\n let mut ans = 0;\n\n for i in 0..n {\n ans += an[i] * i * 4;\n }\n println!(\"{}\", ans);\n}\n\n\n#[allow(dead_code)]\nfn read() -> Vec\nwhere T:\n std::str::FromStr,\n T::Err: std::fmt::Debug {\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.split_whitespace()\n .map(|s| s.trim().parse().unwrap())\n .collect()\n}\n\n#[allow(dead_code)]\nfn read_one() -> T\nwhere T:\n std::str::FromStr,\n T::Err: std::fmt::Debug {\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n}"}], "negative_code": [{"source_code": "use std::io;\nuse std::cmp;\n\n\nfn main() {\n let n = read_one::();\n let an = read::();\n let mut ans = 100_000_000;\n\n for i in 0..n { // i + 1 : x_th\n let mut tmp = 0;\n for j in 0..n { // a_th\n tmp += (an[j] as isize) * ((i as isize - j as isize).abs()) * 2; // x -> a\n tmp += (an[j] * j * 2) as isize; // a -> ground\n tmp += (2 * i) as isize; // g -> x\n }\n ans = cmp::min(ans, tmp);\n }\n println!(\"{}\", ans);\n}\n\n\n#[allow(dead_code)]\nfn read() -> Vec\nwhere T:\n std::str::FromStr,\n T::Err: std::fmt::Debug {\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.split_whitespace()\n .map(|s| s.trim().parse().unwrap())\n .collect()\n}\n\n#[allow(dead_code)]\nfn read_one() -> T\nwhere T:\n std::str::FromStr,\n T::Err: std::fmt::Debug {\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n}"}], "src_uid": "a5002ddf9e792cb4b4685e630f1e1b8f"} {"source_code": "use std::io;\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 digits(mut n: u64) -> u64 {\n let mut count = 0u64;\n while n > 0 {\n count += 1;\n n /= 10;\n }\n return count;\n}\n\nfn main() {\n let n: u64 = read_line().parse().unwrap();\n \n let d = digits(n);\n let mut nums_counted = 0u64;\n let mut nines = 9u64;\n let mut res = 0u64;\n for i in 1 .. d {\n let cur_len = nines - nums_counted;\n nines = nines * 10 + 9;\n res += cur_len * i;\n nums_counted += cur_len;\n }\n \n let cur_len = n - nums_counted;\n res += cur_len * d;\n \n println!(\"{}\", res);\n}\n", "positive_code": [{"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! 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}\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 std::iter::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\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 sol = n * 0;\n let mut d = 1;\n let mut x = 1;\n loop {\n let xx = x * 10;\n if n < xx {\n sol += (n - x + 1) * d;\n break;\n } else {\n sol += (xx - x) * d;\n x = xx;\n d += 1;\n }\n }\n println!(\"{}\", sol);\n}\n\n"}], "negative_code": [], "src_uid": "4e652ccb40632bf4b9dd95b9f8ae1ec9"} {"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!(l,r: i64 = input.p());\n if l == r {\n println!(\"0\");\n } else {\n let mut x = l ^ r;\n for i in 0..=5 {\n x |= x >> (1 << i);\n }\n println!(\"{}\", x);\n }\n}\n\n", "positive_code": [{"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 (l, r) = parse_line!(u64, u64);\n let mut bit = 1u64 << 63;\n while bit != 0 && l & bit == r & bit {\n bit >>= 1;\n }\n if bit == 0 {\n writeln!(writer, \"0\").unwrap();\n }else{\n writeln!(writer, \"{}\", bit | (bit - 1)).unwrap();\n }\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"}], "negative_code": [], "src_uid": "d90e99d539b16590c17328d79a5921e0"} {"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 resolve(hy: i64, ay: i64, dy: i64, hm: i64, am: i64, dm: i64) -> bool {\n let ay = ay - dm;\n let am = am - dy;\n if ay <= 0 {\n return false;\n }\n if am <= 0 {\n return true;\n }\n let yt = (hy - 1) / am;\n let mt = (hm - 1) / ay;\n yt > mt\n}\n\nfn solve() {\n let (hy, ay, dy) = parse_line!(i64, i64, i64);\n let (hm, am, dm) = parse_line!(i64, i64, i64);\n let (h, a, d) = parse_line!(i64, i64, i64);\n let mut ans = std::i64::MAX;\n for aadd in 0..500 {\n for dadd in 0..500 {\n let ay = ay + aadd;\n let dy = dy + dadd;\n let mut l: i64 = -1;\n let mut r: i64 = 100001;\n while r - l > 1 {\n let m = (l + r) / 2;\n let hy = hy + m;\n if resolve(hy, ay, dy, hm, am, dm) {\n r = m;\n }else{\n l = m;\n }\n }\n let cost = aadd * a + dadd * d + r * h;\n ans = std::cmp::min(ans, cost);\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n", "positive_code": [{"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 resolve(hy: i64, ay: i64, dy: i64, hm: i64, am: i64, dm: i64) -> bool {\n let ay = ay - dm;\n let am = am - dy;\n if ay <= 0 {\n return false;\n }\n if am <= 0 {\n return true;\n }\n let yt = (hy - 1) / am;\n let mt = (hm - 1) / ay;\n yt > mt\n}\n\nfn solve() {\n let (hy, ay, dy) = parse_line!(i64, i64, i64);\n let (hm, am, dm) = parse_line!(i64, i64, i64);\n let (h, a, d) = parse_line!(i64, i64, i64);\n let mut ans = std::i64::MAX;\n for aadd in 0..200 {\n for dadd in 0..100 {\n let ay = ay + aadd;\n let dy = dy + dadd;\n let mut l: i64 = -1;\n let mut r: i64 = 10001;\n if !resolve(hy + r, ay, dy, hm, am, dm) {\n continue;\n }\n while r - l > 1 {\n let m = (l + r) / 2;\n let hy = hy + m;\n if resolve(hy, ay, dy, hm, am, dm) {\n r = m;\n }else{\n l = m;\n }\n }\n let cost = aadd * a + dadd * d + r * h;\n if cost < ans {\n ans = cost;\n }\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n"}, {"source_code": "// ---------- 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 std::cmp::*;\n\nfn run() {\n input! {\n yang: (i64, i64, i64),\n mons: (i64, i64, i64),\n h: i64,\n a: i64,\n d: i64,\n }\n let win = |h: i64, a: i64, b: i64| -> bool {\n let yang = (yang.0 + h, yang.1 + a, yang.2 + b);\n let x = max(yang.1 - mons.2, 0);\n if x <= 0 {\n return false;\n }\n let y = max(mons.1 - yang.2, 0);\n if y <= 0 {\n return true;\n }\n let a = (yang.0 + y - 1) / y;\n let b = (mons.0 + x - 1) / x;\n a > b\n };\n // DEFを100, ATK を100買えば勝てる、これ以下\n let mut ans = 100 * a + 100 * d;\n for i in 0..=21000 {\n if i * h > ans {\n break;\n }\n for j in 0..=200 {\n if j * a > ans - i * h {\n break;\n }\n for k in 0..=200 {\n if win(i, j, k) {\n ans = min(ans, i * h + j * a + k * d);\n }\n }\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}], "negative_code": [{"source_code": "// ---------- 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 std::cmp::*;\n\nfn run() {\n input! {\n yang: (i64, i64, i64),\n mons: (i64, i64, i64),\n h: i64,\n a: i64,\n d: i64,\n }\n let win = |h: i64, a: i64, b: i64| -> bool {\n let yang = (yang.0 + h, yang.1 + a, yang.2 + b);\n let x = max(yang.1 - mons.2, 0);\n if x <= 0 {\n return false;\n }\n let y = max(mons.1 - yang.2, 0);\n if y <= 0 {\n return true;\n }\n let a = (yang.0 + y - 1) / y;\n let b = (mons.0 + x - 1) / x;\n a > b\n };\n // DEFを100, ATK を100買えば勝てる、これ以下\n let mut ans = 100 * a + 100 * d;\n for i in 0..=10000 {\n if i * h > ans {\n break;\n }\n for j in 0..=100 {\n if j * a > ans - i * h {\n break;\n }\n for k in 0..=100 {\n if win(i, j, k) {\n ans = min(ans, i * h + j * a + k * d);\n }\n }\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"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 resolve(hy: i64, ay: i64, dy: i64, hm: i64, am: i64, dm: i64) -> bool {\n let ay = std::cmp::max(0, ay - dm);\n let am = std::cmp::max(0, am - dy);\n if ay == 0 {\n return false;\n }\n if am == 0 {\n return true;\n }\n let yt = (hy - 1) / am + 1;\n let mt = (hm - 1) / ay + 1;\n yt > mt\n}\n\nfn solve() {\n let (hy, ay, dy) = parse_line!(i64, i64, i64);\n let (hm, am, dm) = parse_line!(i64, i64, i64);\n let (h, a, d) = parse_line!(i64, i64, i64);\n let mut ans = std::i64::MAX;\n for aadd in 0..200 {\n for dadd in 0..100 {\n let ay = ay + aadd;\n let dy = dy + dadd;\n let mut l: i64 = -1;\n let mut r: i64 = 10001;\n while r - l > 1 {\n let m = (l + r) / 2;\n let hy = hy + m;\n if resolve(hy, ay, dy, hm, am, dm) {\n r = m;\n }else{\n l = m;\n }\n }\n let cost = aadd * a + dadd * d + r * h;\n ans = std::cmp::min(ans, cost);\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n"}], "src_uid": "bf8a133154745e64a547de6f31ddc884"} {"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 b(n: u32) -> bool {\n let mut sum = 0;\n let mut k = n;\n while k > 0 {\n sum += k % 10;\n k /= 10;\n }\n return sum == 10;\n}\n\nfn main() {\n let mut k: u32 = read_line().parse().unwrap();\n let mut i = 0u32;\n while k > 0 {\n i += 1;\n if b(i) {\n k -= 1;\n }\n }\n\n println!(\"{}\", i);\n \n\n}\n", "positive_code": [{"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 digit_sum(n: u32) -> u32 {\n let mut ans = 0;\n let mut n = n;\n while n > 0 {\n ans += n % 10;\n n /= 10;\n }\n ans\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n\n let mut k: usize = scan.token();\n let mut num = 0;\n while k > 0 {\n num += 1;\n if digit_sum(num) == 10 {\n k -= 1;\n }\n }\n writeln!(out, \"{}\", num).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"}, {"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 k = input.u();\n let sol = (1..).filter(|&a| {\n let mut b = a;\n let mut s = 0;\n while b > 0 {\n s += b % 10;\n b /= 10;\n }\n s == 10\n }).nth(k - 1).unwrap();\n println!(\"{}\", sol);\n}\n\n"}, {"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\n\n\nfn main() {\n let cin = stdin();\n let cin = cin.lock();\n let mut sc = Scanner::new(cin);\n\n let k: usize = sc.read();\n let mut cnt = 0;\n for i in 0..1000_000_00 {\n let mut sum = 0;\n let mut x = i;\n while x > 0 {\n sum += x % 10;\n x /= 10;\n }\n if sum == 10 {\n cnt += 1;\n }\n\n if cnt == k {\n println!(\"{}\", i);\n break;\n }\n }\n}"}, {"source_code": "#![allow(unused_imports, unused_macros, dead_code)]\nuse std::f64::*;\nuse std::cmp::*;\nuse std::collections::*;\n\nmacro_rules! dump{\n ($($a:expr),*) => {\n println!(concat!($(stringify!($a), \" = {:?}, \"),*), $($a),*);\n }\n}\n\nconst INF: i64 = 0x3f3f3f3f3f3f3f3f;\nconst MOD: i64 = 1000000007;\nconst NOTHING: usize = std::usize::MAX;\nconst DX: [usize; 4] = [1, 0, std::usize::MAX, 0];\nconst DY: [usize; 4] = [0, 1, 0, std::usize::MAX];\n\nfn main() {\n let mut k: u64 = readln();\n let mut i = 0;\n while k > 0 {\n i += 1;\n let mut x = i;\n let mut s = 0;\n while x > 0 {\n s += x % 10;\n x /= 10;\n }\n if s == 10 {\n k -= 1;\n }\n }\n println!(\"{}\", i);\n}\n\ntrait Read {\n fn read(s: &str) -> Self;\n}\n\nfn readln() -> T {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n T::read(buf.trim_right())\n}\n\nmacro_rules! read_impl{\n ($($t:ty)*) => ($(\n impl Read for $t {\n fn read(s: &str) -> $t{\n s.parse().unwrap()\n }\n }\n )*)\n}\nread_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }\n\nimpl Read for String {\n fn read(s: &str) -> Self {\n s.to_string()\n }\n}\n\nimpl Read for Vec {\n fn read(s: &str) -> Self {\n s.chars().collect()\n }\n}\n\nimpl Read for Vec {\n fn read(s: &str) -> Self {\n s.split_whitespace().map(T::read).collect()\n }\n}\n\nimpl Read for (A, B) {\n fn read(s: &str) -> Self {\n let tokens: Vec<_> = s.split_whitespace().collect();\n (A::read(tokens[0]), B::read(tokens[1]))\n }\n}\n\nimpl Read for (A, B, C) {\n fn read(s: &str) -> Self {\n let tokens: Vec<_> = s.split_whitespace().collect();\n (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))\n }\n}\n\nimpl Read for (A, B, C, D) {\n fn read(s: &str) -> Self {\n let tokens: Vec<_> = s.split_whitespace().collect();\n (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]), D::read(tokens[3]))\n }\n}\n"}, {"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 good(mut a: u32) -> bool {\n let mut sum = 0;\n while a != 0 {\n sum += a % 10;\n a /= 10;\n }\n return sum == 10;\n}\n\nfn solve(writer: &mut std::io::BufWriter) {\n let mut k = parse_line!(usize);\n let mut result = 0;\n while k > 0 {\n result += 1;\n if good(result) {\n k -= 1;\n }\n }\n writeln!(writer, \"{}\", result).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"}, {"source_code": "fn read_line() -> Option {\n let stdin = std::io::stdin();\n let mut line = String::new();\n if stdin.read_line(&mut line).unwrap_or(0) > 0 {\n Some(line.trim().into())\n } else {\n None\n }\n}\n\nfn main() {\n let n: i32 = read_line().unwrap().parse().unwrap();\n fn sum_digits(mut n: i64) -> i32 {\n let mut sum = 0;\n while n > 0 {\n sum += (n % 10) as i32;\n n /= 10;\n }\n sum\n }\n let mut a = 19;\n let mut m = 0;\n loop {\n let sum = sum_digits(a);\n if sum == 10 {\n m += 1;\n if m == n {\n println!(\"{}\", a);\n break;\n }\n }\n if sum >= 10 {\n a += 10 - a % 10;\n } else {\n a += 1;\n }\n }\n}\n"}], "negative_code": [], "src_uid": "0a98a6a15e553ce11cb468d3330fc86a"} {"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 = input.u();\n let mut a = vec![0; 3];\n for i in 0..n {\n a[i % 3] += input.i();\n }\n let max = a.iter().max().unwrap();\n for (x,y) in vec![\"chest\",\"biceps\",\"back\"].into_iter().zip(a.iter()) {\n if max == y {\n println!(\"{}\", x);\n }\n }\n}\n\n", "positive_code": [{"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 mut cnt = [0usize; 3];\n let ex_msg = [\"chest\", \"biceps\", \"back\"];\n let mut maxa = 0usize;\n let mut maxi = 0usize;\n for i in 0..n {\n let a: usize = scan.next();\n let exi = i % 3;\n cnt[exi] += a;\n if cnt[exi] > maxa {\n maxa = cnt[exi];\n maxi = exi;\n }\n }\n println!(\"{}\", ex_msg[maxi]);\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"}, {"source_code": "fn input_count() -> [u8; 3] {\n let mut buf = String::new();\n let mut body = [0; 3];\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim()\n .split_whitespace()\n .map(|elem| elem.parse::().unwrap())\n .zip(0..)\n .for_each(|(a_i, i)| body[i % 3] += a_i);\n body\n}\n\nfn main() {\n {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n }\n println!(\n \"{}\",\n input_count()\n .iter()\n .zip([\"chest\", \"biceps\", \"back\"].iter())\n .max()\n .unwrap()\n .1\n );\n}"}], "negative_code": [], "src_uid": "579021de624c072f5e0393aae762117e"} {"source_code": "fn dir(c: char) -> i32 {\n match c {\n 'v' => 0,\n '<' => 1,\n '^' => 2,\n '>' => 3,\n _ => panic!(\"Invalid character\"),\n }\n}\n\nfn modu(a: i32) -> i32 {\n if a < 0 {\n a % 4 + 4\n } else {\n a % 4\n }\n}\n\nfn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut iter = input.chars();\n\n let start = iter.next().unwrap();\n iter.next().unwrap();\n let end = iter.next().unwrap();\n\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n\n let n = it.next().unwrap();\n\n if n % 2 == 0 {\n println!(\"undefined\");\n } else if n % 4 == modu(dir(end) - dir(start)) {\n println!(\"cw\");\n } else {\n println!(\"ccw\");\n }\n}\n", "positive_code": [{"source_code": "fn read_line() -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\n \"Could not read line\",\n );\n String::from(&line[..line.len() - 1])\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(\n &format!(concat!(\"Could not parse {} into \", stringify!($t)), token))\n }).collect::>()\n }};\n ($($t: ty),*) => {{\n let line = read_line();\n let mut iter = line.split_whitespace();\n let result = ($({\n let token = iter.next().expect(\"Not enough tokens\");\n <$t as std::str::FromStr>::from_str(token).expect(\n &format!(concat!(\"Could not parse {} into \", stringify!($t)), token))\n }),*);\n if let Some(token) = iter.next() {\n panic!(\"Unexpected token {}\", token);\n }\n result\n }};\n}\n\nfn main() {\n let (s, f) = read_line!(String, String);\n let s = s.chars().nth(0).unwrap();\n let f = f.chars().nth(0).unwrap();\n let time = read_line!(usize);\n let all = ['v', '<', '^', '>'];\n let s = all.iter().enumerate().find(|x| *x.1 == s).unwrap().0;\n let f = all.iter().enumerate().find(|x| *x.1 == f).unwrap().0;\n let canCw = (s + time) % 4 == f;\n let canCcw = s == (f + time) % 4;\n println!(\n \"{}\",\n match (canCw, canCcw) {\n (false, false) => panic!(\"impossible\"),\n (true, false) => \"cw\",\n (false, true) => \"ccw\",\n (true, true) => \"undefined\",\n }\n );\n}"}, {"source_code": "fn read_line() -> 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\nfn spinner_position(c: char) -> i32 {\n match c {\n '^' => 0,\n '>' => 1,\n 'v' => 2,\n '<' => 3,\n _ => -1,\n }\n}\n\nfn main() {\n let (s, t) = read_line!(String, String);\n let n = read_line!(i32) % 4;\n let x = spinner_position(s.chars().nth(0).expect(\"\"));\n let y = spinner_position(t.chars().nth(0).expect(\"\"));\n let d = (y - x + 4) % 4;\n if n % 2 == 0 {\n println!(\"undefined\");\n } else if d == n {\n println!(\"cw\");\n } else if d == 4 - n {\n println!(\"ccw\");\n }\n}\n"}, {"source_code": "#[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!(f32);\nimpl_scan_single!(f64);\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 modu(x: i32, y: i32) -> i32 {\n let res = x % y;\n if res < 0 { res + y } else { res }\n}\n\nfn main() {\n scanln!(start: String, end: String);\n scanln!(rotations: i32);\n let start = match &start as &str {\n \"^\" => 0i32,\n \">\" => 1i32,\n \"v\" => 2i32,\n \"<\" => 3i32,\n _ => unreachable!()\n };\n let end = match &end as &str {\n \"^\" => 0i32,\n \">\" => 1i32,\n \"v\" => 2i32,\n \"<\" => 3i32,\n _ => unreachable!()\n };\n let cw = modu(start + (rotations % 4), 4);\n let ccw = modu(start - (rotations % 4), 4);\n if cw == end && ccw == end {\n println!(\"undefined\");\n } else if cw == end {\n println!(\"cw\");\n } else if ccw == end {\n println!(\"ccw\");\n } else {\n println!(\"undefined\");\n }\n}\n"}, {"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 read_int() -> u64 {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).expect(\"Failed\");\n let x = input.trim().parse::().unwrap();\n input.clear();\n x\n}\n\nfn main(){\n let s = read_string();\n let vec: Vec<&str> = s.split(\"\").collect();\n let start_pos_as_char = vec[1].chars().next().unwrap() as u8;\n let end_pos_as_char = vec[3].chars().next().unwrap() as u8;\n let x = read_int();\n let cases = vec![118, 60, 94, 62]; // down left up right\n let sp = cases.iter().position(|&r| r == start_pos_as_char).unwrap();\n let ep = cases.iter().position(|&r| r == end_pos_as_char).unwrap();\n let is_even = ((x % 2) + 2) % 2;\n let result = (((x+sp as u64) % 4) + 4) % 4;\n if is_even == 0{\n println!(\"undefined\");\n } else if (sp < 4) && (cases[result as usize] == end_pos_as_char) || (cases[result as usize] == end_pos_as_char) && (ep == 4){\n println!(\"cw\");\n } else {\n println!(\"ccw\");\n }\n\n}"}], "negative_code": [{"source_code": "fn dir(c: char) -> i32 {\n match c {\n 'v' => 0,\n '<' => 1,\n '^' => 2,\n '>' => 3,\n _ => panic!(\"Invalid character\"),\n }\n}\n\nfn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut iter = input.chars();\n\n let start = iter.next().unwrap();\n iter.next().unwrap();\n let end = iter.next().unwrap();\n\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n\n let n = it.next().unwrap();\n\n if n % 2 == 0 {\n println!(\"undefined\");\n } else if n % 4 == (dir(end) - dir(start)) % 4 {\n println!(\"cw\");\n } else {\n println!(\"ccw\");\n }\n}\n"}], "src_uid": "fb99ef80fd21f98674fe85d80a2e5298"} {"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 mut x: i32 = scan.token();\n let m: i32 = scan.token();\n\n x %= m;\n\n let mut seen = vec![false; m as usize];\n\n while x > 0 && !seen[x as usize] {\n seen[x as usize] = true;\n x += x;\n if x >= m {\n x -= m;\n }\n }\n\n writeln!(out, \"{}\", match x {\n 0 => \"Yes\",\n _ => \"No\",\n })?;\n\n Ok(())\n}\n", "positive_code": [{"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 mut x: u32 = scan.token();\n let mut m: u32 = scan.token();\n\n x >>= x.trailing_zeros();\n m >>= m.trailing_zeros();\n\n writeln!(out, \"{}\", if x % m == 0 { \"Yes\" } else { \"No\" })?;\n\n Ok(())\n}\n"}, {"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 mut x: i32 = scan.token();\n let mut m: i32 = scan.token();\n\n while m % 2 == 0 {\n m /= 2;\n }\n while x % 2 == 0 {\n x /= 2;\n }\n\n writeln!(out, \"{}\", if x % m == 0 { \"Yes\" } else { \"No\" })?;\n\n Ok(())\n}\n"}], "negative_code": [], "src_uid": "f726133018e2149ec57e113860ec498a"} {"source_code": "\nfn factorial(x: usize) -> usize {\n let mut result: usize = 1;\n for i in 1..=x {\n result *= i;\n }\n result\n}\n\nstruct 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 a: usize = scan.next();\n let b: usize = scan.next();\n println!(\"{}\", factorial(a.min(b)));\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "positive_code": [{"source_code": "use std::cmp::min;\nuse std::io;\n\nfn factorial(n: u32) -> u32 {\n (1..=n).fold(1, |acc, x| acc * x)\n}\n\nfn main() {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n let numbers: Vec = line\n .split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect();\n let a = numbers[0];\n let b = numbers[1];\n let ans = factorial(min(a, b));\n println!(\"{}\", ans);\n}\n"}, {"source_code": "fn fact(n: u32) -> u32 {\n if n == 1 {\n 1\n } else {\n n * fact(n - 1)\n }\n}\n\nfn main() {\n let (a, b) = {\n let mut buf = String::with_capacity(3);\n std::io::stdin().read_line(&mut buf).unwrap();\n let nums: Vec = buf\n .trim()\n .split_whitespace()\n .map(|a| a.parse().unwrap())\n .collect();\n (nums[0], nums[1])\n };\n\n print!(\"{}\", fact(a.min(b)));\n}"}, {"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 println!(\"{}\", (1..1 + (input.i().min(input.i()) as i64))\n .product::());\n}\n\n"}, {"source_code": "use std::io;\nuse std::str::{FromStr, SplitWhitespace};\nuse std::fmt::Debug;\nuse std::iter::Map;\nuse std::cmp::min;\n\nfn main() {\n let (a,b) = Input::line().pair();\n let res = (1..min::(a,b) + 1).fold(1, |ref x, i| x * i) ;\n println!(\"{}\", res);\n\n}\n\npub trait UParse: FromStr {\n fn uparse(&str) -> Self;\n}\nimpl UParse for T\nwhere\n T: FromStr,\n T::Err: Debug,\n{\n fn uparse(str: &str) -> Self {\n str.trim().parse().unwrap()\n }\n}\n\npub struct Input(String);\nimpl Input {\n pub fn line() -> Input {\n let mut str = String::new();\n io::stdin().read_line(&mut str).unwrap();\n Input(str)\n }\n\n fn trim_parse(s: &str) -> T {\n UParse::uparse(s)\n }\n\n pub fn iter(&self) -> Map T> {\n self.0.split_whitespace().map(Input::trim_parse)\n }\n\n pub fn single(&self) -> T {\n Input::trim_parse(self.0.as_ref())\n }\n\n pub fn pair(&self) -> (A, B) {\n let mut it = self.0.split_whitespace();\n let a = Input::trim_parse(it.next().unwrap());\n let b = Input::trim_parse(it.next().unwrap());\n (a, b)\n }\n\n pub fn triple(&self) -> (A, B, C) {\n let mut it = self.0.split_whitespace();\n let a = Input::trim_parse(it.next().unwrap());\n let b = Input::trim_parse(it.next().unwrap());\n let c = Input::trim_parse(it.next().unwrap());\n (a, b, c)\n }\n\n pub fn quadruple(&self) -> (A, B, C, D) {\n let mut it = self.0.split_whitespace();\n let a = Input::trim_parse(it.next().unwrap());\n let b = Input::trim_parse(it.next().unwrap());\n let c = Input::trim_parse(it.next().unwrap());\n let d = Input::trim_parse(it.next().unwrap());\n (a, b, c, d)\n }\n}\n"}, {"source_code": "use std::io;\nuse std::str::{FromStr, SplitWhitespace};\nuse std::fmt::Debug;\nuse std::iter::Map;\nuse std::cmp::min;\n\nfn main() {\n let (a,b) = Input::line().pair();\n let res = (1..min::(a,b) + 1).fold(1, |ref x, i| x * i) ;\n println!(\"{}\", res);\n\n}\n\npub trait UParse: FromStr {\n fn uparse(&str) -> Self;\n}\nimpl UParse for T\nwhere\n T: FromStr,\n T::Err: Debug,\n{\n fn uparse(str: &str) -> Self {\n str.trim().parse().unwrap()\n }\n}\n\npub struct Input(String);\nimpl Input {\n pub fn line() -> Input {\n let mut str = String::new();\n io::stdin().read_line(&mut str).unwrap();\n Input(str)\n }\n\n fn trim_parse(s: &str) -> T {\n UParse::uparse(s)\n }\n\n pub fn iter(&self) -> Map T> {\n self.0.split_whitespace().map(Input::trim_parse)\n }\n\n pub fn single(&self) -> T {\n Input::trim_parse(self.0.as_ref())\n }\n\n pub fn pair(&self) -> (A, B) {\n let mut it = self.0.split_whitespace();\n let a = Input::trim_parse(it.next().unwrap());\n let b = Input::trim_parse(it.next().unwrap());\n (a, b)\n }\n\n pub fn triple(&self) -> (A, B, C) {\n let mut it = self.0.split_whitespace();\n let a = Input::trim_parse(it.next().unwrap());\n let b = Input::trim_parse(it.next().unwrap());\n let c = Input::trim_parse(it.next().unwrap());\n (a, b, c)\n }\n\n pub fn quadruple(&self) -> (A, B, C, D) {\n let mut it = self.0.split_whitespace();\n let a = Input::trim_parse(it.next().unwrap());\n let b = Input::trim_parse(it.next().unwrap());\n let c = Input::trim_parse(it.next().unwrap());\n let d = Input::trim_parse(it.next().unwrap());\n (a, b, c, d)\n }\n}\n"}, {"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 (x,y) = readln!(i64,i64);\n let p = (1..=min(x,y)).product::();\n println!(\"{}\",p);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn read_n() -> (u32, u32) {\n let mut buffer = String::new();\n stdin().read_line(&mut buffer).unwrap();\n let snums: Vec<&str> = buffer.trim().split(\" \").collect();\n (snums[0].parse::().unwrap(), snums[1].parse::().unwrap())\n}\n\nfn factorial(x: u32) -> u32 {\n let mut n: u32 = 1;\n for i in 2..x+1 {\n n *= i;\n }\n n\n}\n\n\nfn main() {\n let (a, b) = read_n();\n if a < b {\n println!(\"{}\", factorial(a));\n } else {\n println!(\"{}\", factorial(b));\n }\n}"}, {"source_code": "fn factorial(n: i32) -> i32 {\n if n == 0 {\n 1\n } else {\n n * factorial(n - 1)\n }\n}\n\nuse std::cmp;\nuse std::io;\n\nfn main() {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input).unwrap();\n\n let mut iter = input.split_whitespace().map(|p| p.parse::().unwrap());\n\n let a = iter.next().unwrap();\n let b = iter.next().unwrap();\n\n let c = cmp::min(a, b);\n println!(\"{}\", factorial(c));\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::io;\nuse std::cmp::{min, max};\nuse std::mem;\nuse std::str::FromStr;\nuse std::cmp::Ordering;\nuse std::collections::BinaryHeap;\n\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Scanner {\n Scanner {\n reader: reader,\n buffer: Vec::new(),\n }\n }\n\n /// Use \"turbofish\" syntax next::() to select data type of next token.\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n\n pub fn next_vec(&mut self, len: usize) -> Vec\n where\n T::Err: ::std::fmt::Debug,\n {\n (0..len).map(|_| self.next::()).collect::>()\n }\n}\n\nfn main1() {\n let stdin = io::stdin();\n let mut input = Scanner::new(stdin.lock());\n let a: i64 = input.next();\n let b: i64 = input.next();\n let n = min(a, b);\n let answer = (1..(n + 1)).fold(1i64, |mul, x| mul * x);\n println!(\"{}\", answer);\n\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}\n"}, {"source_code": "use std::io::{self, BufRead};\n\nfn factorial(x: i32) -> i32 {\n if x < 2 {\n return 1;\n } else {\n return x * factorial(x - 1);\n }\n}\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 mut min= numbers[0];\n if numbers[1] < min {\n min = numbers[1];\n }\n\n println!(\"{}\", factorial(min));\n}\n"}, {"source_code": "fn main() {\n use std::io;\n use std::cmp;\n\n fn factorial(n: usize) -> usize {\n let mut result = 1;\n for i in 2..(n+1) {\n result *= i;\n }\n result\n }\n\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n let mut ns = line.split(\" \").map(|str| str.trim().parse::().unwrap());\n let a = ns.next().unwrap();\n let b = ns.next().unwrap();\n\n println!(\"{}\", factorial(cmp::min(a, b)));\n}\n"}], "negative_code": [{"source_code": "use std::cmp::min;\nuse std::io;\n\nfn factorial(n: u32) -> u32 {\n (1..=n).fold(1, |acc, x| acc * x)\n}\n\nfn main() {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n let numbers: Vec = line\n .split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect();\n let a = numbers[0];\n let b = numbers[1];\n let ans = min(factorial(a), factorial(b));\n println!(\"{}\", ans);\n}\n"}, {"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 println!(\"{}\", (1..(input.i().min(input.i()) as i64))\n .product::());\n}\n\n"}], "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"source_code": "use std::io;\n\n\nfn main() {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n let nkx : Vec = line.trim().split(\" \").map(|x| x.parse::().unwrap()).collect();\n let (n, k, x) : (usize, usize, usize) = (nkx[0], nkx[1], nkx[2]);\n\n line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n let my_deeds : Vec = line.trim().split(\" \").map(|x| x.parse::().unwrap()).collect();\n\n let mut min_cost = 0;\n for i in 1..(n + 1) {\n if i <= k {\n min_cost += x;\n } else {\n min_cost += my_deeds[((n - i) as usize)];\n }\n }\n\n print!(\"{}\", min_cost);\n}\n", "positive_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet};\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n\n #[allow(dead_code)]\n pub fn get3() -> (S, T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {:?}\", stringify!($x), $x)\n }\n}\n\nfn main() {\n let (n, k, x): (usize, usize, usize) = util::get3();\n let a: Vec = util::gets();\n\n println!(\"{}\", a[..n - k].iter().sum::() + k * x);\n}\n"}, {"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 (n, k, x): (usize, usize, usize) = {\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 a: Vec = get_vec();\n\n let ans = &a[..a.len() - k].iter().cloned().sum::() + k * x;\n\n println!(\"{}\", ans);\n}\n"}], "negative_code": [], "src_uid": "92a233f8d9c73d9f33e4e6116b7d0a96"} {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 && m != 1 {\n println!(\"-1 -1\");\n return;\n }\n\n if s == 0 && m == 1 {\n println!(\"0 0\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n println!(\"-1 -1\");\n return;\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n }\n\n for ch in chars {\n minima.push(ch);\n }\n\n if maxima == \"-1\" {\n minima = String::from(\"-1\");\n }\n\n println!(\"{} {}\", minima, maxima);\n}\n\n", "positive_code": [{"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] use std::thread::*;\n#[allow(unused)] use std::ops::*;\n#[allow(unused)] use std::marker::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($($n:expr, $T:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n ($({let mut v = Vec::new(); v.reserve(($n) as usize);\n for _ in 0..$n { let t = s.next(); if t == None { break; }\n v.push(t.unwrap().parse::<$T>().unwrap()); } v }),+)\n }}; }\n///////////////////////////////////////////////////////////////////////////////\n\n\n\nfn main()\n{\n let (n, mut s) = scan!(usize, u64);\n if n == 1 && s == 0 { println!(\"0 0\"); return; }\n if (9 * n as u64) < s || s < 1 { println!(\"-1 -1\"); return; }\n let mut a = vec![0; n];\n for i in 0..n { a[i] += min(s, 9); s -= min(s, 9); }\n let mut b = a.iter().rev().map(|&x| x).collect::>();\n if b[0] == 0 { for i in 0..n { if b[i] > 0 { b[i] -= 1; b[0] += 1; break; } } }\n for i in 0..n { print!(\"{}\", b[i]); } print!(\" \");\n for i in 0..n { print!(\"{}\", a[i]); } println!();\n}\n"}, {"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 m: isize = scan.next();\n let s: isize = scan.next();\n let nnines = s / 9;\n let last = s % 9;\n if nnines > m || nnines == m && last != 0 || m>1 && s == 0 {\n println!(\"-1 -1\");\n } else if m == 1 && s == 0 {\n println!(\"0 0\");\n } else if m == 1 {\n println!(\"{} {}\", s, s);\n } else if nnines == m {\n let sol = format!(\"{}\", \"9\".repeat(nnines as usize));\n println!(\"{} {}\", sol, sol);\n } else {\n let mut result = String::new();\n let mut s1 = s;\n for i in 1..=m {\n for d in 0..=9 {\n if i==1 && d==0 { continue; }\n if s1-d <= 9*(m-i) && s1-d >= 0 {\n result = format!(\"{}{}\", result, d);\n s1 -= d;\n break;\n }\n }\n }\n print!(\"{}\", result);\n result.clear();\n s1 = s;\n for i in 1..=m {\n for d in (0..=9).rev() {\n if s1-d <= 9*(m-i) && s1-d >= 0 {\n result = format!(\"{}{}\", result, d);\n s1 -= d;\n break;\n }\n }\n }\n println!(\" {}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n\n"}, {"source_code": "use std::io;\n\n\nfn read_line(buf: &mut String) {\n buf.clear();\n match io::stdin().read_line(buf) {\n Err(error) => println!(\"error! {}\",error),\n _ => {}\n }\n}\n\nfn is_valid(m: i32, n: i32) -> bool {\n if n==0 || n>9*m {\n return false;\n }\n return true;\n}\nfn get_max(m:i32,n:i32) {\n let mut max = Vec::::new();\n max.reserve(m as usize);\n for _ in 0..m {\n max.push(0);\n }\n let mut n_copy = n;\n for index in 0..m {\n if n_copy > 9 {\n max[index as usize]+=9;\n n_copy -= 9;\n }\n else {\n max[index as usize]+= n_copy as u8;\n break;\n }\n }\n print!(\" \");\n for x in max {\n print!(\"{}\",x);\n }\n println!(\"\");\n\n}\nfn get_min(m:i32, n:i32) {\n let mut min = Vec::::new();\n min.reserve(m as usize);\n min.push(1);\n for _ in 1..m {\n min.push(0);\n }\n let mut n_copy = n-1;\n for index in (0..(m)).rev() {\n if n_copy > 9 {\n min[index as usize]+=9;\n n_copy -= 9;\n }\n else {\n min[index as usize]+= n_copy as u8;\n break;\n }\n }\n for x in min {\n print!(\"{}\",x);\n }\n\n}\n\nfn main() {\n let mut buf : String = String::new();\n read_line(&mut buf);\n let mut string_iter = buf.trim().split_whitespace();\n let m = string_iter.next().unwrap().parse::().unwrap();\n let n = string_iter.next().unwrap().parse::().unwrap();\n\n if !is_valid(m,n) {\n if m==1 && n==0 {\n println!(\"0 0\");\n }\n else{\n println!(\"-1 -1\");\n }\n }\n else {\n get_min(m,n);\n get_max(m,n);\n }\n}\n"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn max_num_with_m_digits_and_digit_sum(m : usize, s : usize, max_num : &mut Vec) {\n if (m * 9) < s {\n // Do nothing ...\n } else {\n if s == 0 {\n if m == 1 {\n max_num.push(0);\n } else {\n // Do nothing ...\n }\n } else {\n let mut cur_sum = 0;\n for _ in 0 .. m {\n let diff = s - cur_sum; \n if diff >= 9 {\n max_num.push(9);\n cur_sum = cur_sum + 9;\n } else {\n max_num.push(diff as u8);\n cur_sum = cur_sum + diff;\n }\n }\n }\n }\n}\n\nfn min_num_with_m_digits_and_digit_sum(m : usize, max_num : &mut Vec) {\n if max_num.is_empty() {\n // Do nothing ...\n } else {\n max_num.reverse();\n if max_num[0] == 0 {\n if m == 1 {\n // Do nothing ...\n } else {\n max_num[0] = 1;\n for i in 1 .. m {\n if max_num[i] == 0 {\n // Do nothing ...\n } else {\n max_num[i] = max_num[i] - 1;\n break;\n }\n }\n }\n }\n }\n}\n\nfn print_vec(v : &Vec) {\n for &x in v.iter() {\n print!(\"{}\", x);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut m_s = vec![];\n read_ts(&stdin, &mut m_s);\n let m = m_s[0];\n let s = m_s[1];\n let mut max_num = vec![];\n max_num_with_m_digits_and_digit_sum(m, s, &mut max_num);\n if max_num.is_empty() {\n println!(\"-1 -1\");\n } else {\n let mut max_num_copy = max_num.to_vec();\n min_num_with_m_digits_and_digit_sum(m, &mut max_num_copy);\n print_vec(&max_num_copy);\n print!(\" \");\n print_vec(&max_num);\n println!();\n }\n}"}, {"source_code": "fn find_min(m: usize, s: usize) -> String {\n let mut num = vec![0; m];\n num[0] = 1;\n let mut i = m - 1;\n let mut sum = 1;\n\n while sum + 9 < s {\n num[i] = 9;\n i -= 1;\n sum += 9;\n }\n\n num[i] += (s - sum) as u8;\n vec_to_num(&num)\n}\n\nfn find_max(m: usize, s: usize) -> String {\n let mut num = vec![9; m];\n let mut i = m - 1;\n let mut sum = 9 * m;\n\n while sum - 9 > s {\n num[i] = 0;\n i -= 1;\n sum -= 9;\n }\n\n num[i] -= (sum - s) as u8;\n vec_to_num(&num)\n}\n\nfn vec_to_num(v: &Vec) -> String {\n v.into_iter()\n .map(|digit| (digit + 48) as char)\n .collect::()\n}\n\nfn main() {\n let (m, s) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n if m == 1 && s == 0 {\n println!(\"0 0\");\n } else if s < 1 || s > 9 * m {\n println!(\"-1 -1\");\n } else {\n println!(\"{} {}\", find_min(m, s), find_max(m, s))\n }\n}"}, {"source_code": "fn solve() {\n let (m, s): (i32, i32) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut ws = buf.split_whitespace();\n let m = ws.next().unwrap().parse().unwrap();\n let s = ws.next().unwrap().parse().unwrap();\n (m, s)\n };\n\n if s == 0 {\n match m {\n 1 => println!(\"0 0\"),\n _ => println!(\"-1 -1\"),\n }\n return;\n }\n if s > 9 * m {\n println!(\"-1 -1\");\n return;\n }\n\n let check = |m: i32, s: i32| (s >= 0) && s <= 9 * m;\n\n let mut min = String::new();\n let mut sum = s;\n for i in 0..m {\n for d in 0..10 {\n if (i > 0 || d > 0 || (m == 1 && d == 0)) && check(m - i - 1, sum - d) {\n sum -= d;\n min.push_str(&d.to_string());\n break;\n }\n }\n }\n\n let mut max = String::new();\n sum = s;\n for i in 0..m {\n for d in (0..10).rev() {\n if (i > 0 || d > 0 || (m == 1 && d == 0)) && check(m - i - 1, sum - d) {\n sum -= d;\n max.push_str(&d.to_string());\n break;\n }\n }\n }\n\n println!(\"{} {}\", min, max);\n}\n\nfn main() {\n // let t: u32 = {\n // let mut buf = String::new();\n // std::io::stdin().read_line(&mut buf).unwrap();\n // buf.trim_end().parse().unwrap()\n // };\n\n // for _ in 0..t {}\n solve();\n}\n"}, {"source_code": "fn get_max_digits(length: usize, sum: u32) -> Option> {\n if length == 0 {\n return None;\n }\n if (sum == 0) && (length > 1) {\n return None;\n }\n if sum == 0 {\n return Some(vec![0]);\n }\n let mut result: Vec = Vec::with_capacity(length);\n let mut rest_sum: u32 = sum;\n let first_digit: u32;\n if rest_sum > 9 {\n first_digit = 9;\n } else {\n first_digit = rest_sum;\n }\n result.push(first_digit);\n rest_sum -= first_digit;\n\n for _ in 1..length {\n let digit: u32;\n if rest_sum > 9 {\n digit = 9;\n } else {\n digit = rest_sum;\n }\n result.push(digit);\n rest_sum -= digit;\n }\n\n if rest_sum == 0 {\n return Some(result);\n } else {\n return None;\n }\n}\n\nfn get_min_digits(length: usize, sum: u32) -> Option> {\n if (sum == 0) && (length > 1) {\n return None;\n }\n if sum == 0 {\n return Some(vec![0]);\n }\n let mut result: Vec = Vec::with_capacity(length);\n let mut rest_sum: u32 = sum - 1;\n\n for _ in 1..length {\n let digit: u32;\n if rest_sum > 9 {\n digit = 9;\n } else {\n digit = rest_sum;\n }\n result.push(digit);\n rest_sum -= digit;\n }\n\n if rest_sum >= 9 {\n return None;\n }\n\n let last_digit: u32 = rest_sum + 1;\n result.push(last_digit);\n\n result.reverse();\n return Some(result);\n}\n\n#[cfg(test)]\nmod tests {\n use super::{get_max_digits, get_min_digits};\n\n #[test]\n fn test1() {\n assert_eq!(get_max_digits(2, 15), Some(vec![9, 6]));\n assert_eq!(get_min_digits(2, 15), Some(vec![6, 9]));\n }\n #[test]\n fn test2() {\n assert_eq!(get_max_digits(3, 0), None);\n assert_eq!(get_min_digits(3, 0), None);\n }\n #[test]\n fn test3() {\n assert_eq!(get_max_digits(1, 0), Some(vec![0]));\n assert_eq!(get_min_digits(1, 0), Some(vec![0]));\n }\n #[test]\n fn test4() {\n assert_eq!(get_max_digits(1, 9), Some(vec![9]));\n assert_eq!(get_min_digits(1, 9), Some(vec![9]));\n }\n #[test]\n fn test5() {\n assert_eq!(get_max_digits(2, 12), Some(vec![9, 3]));\n assert_eq!(get_min_digits(2, 12), Some(vec![3, 9]));\n }\n}\n\nuse std::io::{stdin, stdout, BufRead, Write};\n\nfn main() {\n let stdin = stdin();\n let mut stdin_lock = stdin.lock();\n\n let stdout = stdout();\n let mut stdout_lock = stdout.lock();\n\n let mut input_str: String = String::new();\n stdin_lock.read_line(&mut input_str).unwrap();\n let mut input_tokens = input_str.trim().split_whitespace();\n let length: usize = input_tokens.next().unwrap().parse().unwrap();\n let sum: u32 = input_tokens.next().unwrap().parse().unwrap();\n\n if let Some(min_digits_array) = get_min_digits(length, sum) {\n for digit in min_digits_array {\n write!(stdout_lock, \"{}\", digit).unwrap();\n }\n } else {\n write!(stdout_lock, \"-1\").unwrap();\n }\n\n write!(stdout_lock, \" \").unwrap();\n\n if let Some(max_digits_array) = get_max_digits(length, sum) {\n for digit in max_digits_array {\n write!(stdout_lock, \"{}\", digit).unwrap();\n }\n } else {\n write!(stdout_lock, \"-1\").unwrap();\n }\n\n writeln!(stdout_lock, \"\").unwrap();\n}\n"}, {"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 n = input.i();\n let s = input.i();\n if (s == 0 && n > 1) || n * 9 < s {\n println!(\"-1 -1\");\n } else if n == 1 {\n println!(\"{} {}\", s, s);\n } else {\n let ok = |i,d,t| {\n if i == n - 1 && d == 0 { return false; }\n let t1 = t - d;\n t1 >= 0 && t1 <= 9 * i\n };\n (0..n).rev().fold(s, |t,i| {\n let d = (0..10).filter(|&d| ok(i,d,t)).min().unwrap();\n print!(\"{}\", d);\n t - d\n });\n print!(\" \");\n (0..n).rev().fold(s, |t,i| {\n let d = (0..10).filter(|&d| ok(i,d,t)).max().unwrap();\n print!(\"{}\", d);\n t - d\n });\n println!(\"\");\n }\n}\n\n"}, {"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 (n,m) = readln!(i32,i32);\n if n==1 && m==0 {\n println!(\"0 0\");\n return;\n }\n if (9*n < m || m==0) {\n println!(\"-1 -1\");\n return;\n }\n let mut m1 = m;\n if (9*(n-1) >= m) {\n m1 -= 1;\n }\n\n let mut l = String::from(\"\");\n let mut used = 0;\n for i in 0..n {\n let mut touse = 0;\n if i == n-1 {\n touse = m-used;\n } else {\n touse = std::cmp::min(m1-used,9);\n }\n l.push((('0' as u8) + (touse as u8)) as char);\n used += touse;\n }\n\n let mut r = String::from(\"\");\n let mut used = 0;\n for i in 0..n {\n let touse = std::cmp::min(m-used,9);\n r.push((('0' as u8) + (touse as u8)) as char);\n used += touse;\n }\n println!(\"{} {}\",l.chars().rev().collect::(),r);\n}\n"}, {"source_code": "use std::io;\nuse std::cmp;\nuse std::process;\nfn main()\n{\n let mut s=String::new();\n io::stdin().read_line(&mut s).expect(\"read error\");\n let vec=s.split_whitespace()\n .map(|x|\n x.parse::().expect(\"parse error\"))\n .collect::>();\n if (vec[0]>1 && vec[1]<1) || (vec[0]*90\n {\n n1=n1-1;\n let x:i64=cmp::min(9,n2);\n n2-=x;\n ans1+=&x.to_string();\n }\n n1=vec[0];\n n2=vec[1];\n while n1>0{\n n1=n1-1;\n let mut x:i64=0;\n if n1==vec[0]-1{\n x=cmp::min(1,n2);\n }\n x=cmp::max(x,n2-9*n1);\n n2-=x;\n ans2+=&x.to_string();\n }\n println!(\"{} {}\",ans2,ans1);\n}"}, {"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\n\nfn main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let (m, s) = scan!(s, usize, i64);\n let mut smallest = vec![0; m];\n let mut largest = vec![0; m];\n let lower_bound = if m == 1 { 0 } else { 1 };\n let upper_bound = (9*m).num();\n\n if s >= lower_bound && s <= upper_bound {\n let mut temp = s;\n for i in 0..m {\n if temp > 9 {\n largest[i] = 9;\n temp -= 9;\n } else {\n largest[i] = temp;\n break;\n }\n }\n\n temp = s;\n for i in (0..m).rev() {\n if temp > 9 {\n smallest[i] = 9;\n temp -= 9;\n } else {\n smallest[i] = temp - 1;\n smallest[0] += 1;\n break;\n }\n }\n\n let mut flag = false;\n for i in 0..m {\n if smallest[i] != 0 || flag {\n flag = true;\n print!(\"{}\", smallest[i]);\n } \n }\n if !flag {\n print!(\"0\");\n }\n print!(\" \");\n\n flag = false;\n for i in 0..m {\n if largest[i] != 0 || flag {\n flag = true;\n print!(\"{}\", largest[i]);\n }\n }\n if !flag {\n print!(\"0\");\n }\n } else {\n println!(\"-1 -1\");\n }\n}"}, {"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 build_max(m: usize, s: usize) -> String {\n if m * 9 < s {\n return \"-1\".to_string();\n } else if s == 0 {\n if m == 1 {\n return \"0\".to_string();\n } else {\n return \"-1\".to_string();\n }\n } else {\n let mut ns = 0;\n let mut ans = String::new();\n for _ in 0..m {\n let d = cmp::min(9, s - ns);\n ans += &d.to_string();\n ns += d;\n }\n return ans;\n }\n}\n\nfn build_min(m: usize, s: usize) -> String {\n if m * 9 < s {\n return \"-1\".to_string();\n } else if s == 0 {\n if m == 1 {\n return \"0\".to_string();\n } else {\n return \"-1\".to_string();\n }\n } else {\n let mut ns = 0;\n let mut ans = String::new();\n for _ in 0..(m-1) {\n let d = cmp::min(9, s - ns - 1);\n ans += &d.to_string();\n ns += d;\n }\n ans += &(s - ns).to_string();\n return ans.chars().rev().collect::();\n }\n}\n\nfn main() {\n let (m, s) = R!(usize, usize);\n println!(\"{} {}\", build_min(m, s), build_max(m, s));\n}\n"}, {"source_code": "fn main() -> Result<(), Box> {\n let data = read_input();\n let (len, sum) = (data[0], data[1]);\n\n if 9 * len < sum {\n println!(\"-1 -1\");\n return Ok(());\n }\n\n if sum == 0 {\n if len > 1 {\n println!(\"-1 -1\");\n } else {\n println!(\"0 0\");\n }\n return Ok(());\n }\n\n if sum == 1 {\n let mut ans = String::with_capacity(len);\n ans.push('1');\n \n for _ in 1..len {\n ans.push('0');\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n if (sum >= 1 && sum <= 9) && (len == 1) {\n println!(\"{} {}\", sum, sum);\n return Ok(());\n }\n\n if sum % 9 == 0 && sum / 9 == len {\n let mut ans = String::with_capacity(len);\n for _ in 0..len {\n ans.push('9')\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n let mut digits = vec![0; len];\n let mut max_digits = vec![0; len];\n \n let nines = sum / 9;\n let rem = sum % 9;\n\n let start = len - nines;\n for i in (start..len).rev() {\n digits[i] = 9;\n }\n\n if len - nines > 1 {\n if rem > 0 {\n digits[start - 1] = rem - 1;\n digits[0] = 1;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n } else {\n if rem > 0 {\n digits[0] = rem;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n }\n\n for i in 0..nines {\n max_digits[i] = 9;\n }\n if rem != 0 {\n max_digits[nines] = rem;\n }\n\n for d in digits {\n print!(\"{}\", d);\n }\n print!(\" \");\n\n for d in max_digits {\n print!(\"{}\", d);\n }\n println!();\n\n Ok(())\n}\n\nfn read_input() -> Vec {\n let mut buffer = String::new();\n\n std::io::stdin()\n .read_line(&mut buffer)\n .expect(\"Failed to get input\");\n\n buffer\n .trim()\n .split_whitespace()\n .map(|x| x.parse().expect(\"Failed to parse number\"))\n .collect()\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 && m != 1 {\n println!(\"-1 -1\");\n return;\n }\n\n if s == 0 && m == 1 {\n println!(\"0 0\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n println!(\"-1 -1\");\n return;\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n }\n\n for ch in chars {\n minima.push(ch);\n }\n\n println!(\"{} {}\", minima, maxima);\n}\n\n"}], "negative_code": [{"source_code": "fn find_min(m: usize, s: usize) -> String {\n let mut num = vec![0; m];\n num[0] = 1;\n let mut i = m - 1;\n let mut sum = 1;\n\n while sum + 9 < s {\n num[i] = 9;\n i -= 1;\n sum += 9;\n }\n\n num[i] += (s - sum) as u8;\n vec_to_num(&num)\n}\n\nfn find_max(m: usize, s: usize) -> String {\n let mut num = vec![9; m];\n let mut i = m - 1;\n let mut sum = 9 * m;\n\n while sum - 9 > s {\n num[i] = 0;\n i -= 1;\n sum -= 9;\n }\n\n num[i] -= (sum - s) as u8;\n vec_to_num(&num)\n}\n\nfn vec_to_num(v: &Vec) -> String {\n v.into_iter()\n .map(|digit| (digit + 48) as char)\n .collect::()\n}\n\nfn main() {\n let (m, s) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n if s < 1 || s > 9 * m {\n println!(\"-1 -1\");\n } else if m == 1 && s == 0 {\n println!(\"0 0\");\n } else {\n println!(\"{} {}\", find_min(m, s), find_max(m, s))\n }\n}"}, {"source_code": "fn find_min(m: usize, s: usize) -> String {\n let mut num = vec![0; m];\n num[0] = 1;\n let mut i = m - 1;\n let mut sum = 1;\n\n while sum + 9 < s {\n num[i] = 9;\n i -= 1;\n sum += 9;\n }\n\n num[i] += (s - sum) as u8;\n vec_to_num(&num)\n}\n\nfn find_max(m: usize, s: usize) -> String {\n let mut num = vec![9; m];\n let mut i = m - 1;\n let mut sum = 9 * m;\n\n while sum - 9 > s {\n num[i] = 0;\n i -= 1;\n sum -= 9;\n }\n\n num[i] -= (sum - s) as u8;\n vec_to_num(&num)\n}\n\nfn vec_to_num(v: &Vec) -> String {\n v.into_iter()\n .map(|digit| (digit + 48) as char)\n .collect::()\n}\n\nfn main() {\n let (m, s) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n if s < 1 || s > 9 * m {\n println!(\"-1 -1\");\n } else if s == 1 && m == 0 {\n println!(\"0 0\");\n } else {\n println!(\"{} {}\", find_min(m, s), find_max(m, s))\n }\n}"}, {"source_code": "fn find_min(m: usize, s: usize) -> String {\n let mut num = vec![0; m];\n num[0] = 1;\n let mut i = m - 1;\n let mut sum = 1;\n\n while sum + 9 < s {\n num[i] = 9;\n i -= 1;\n sum += 9;\n }\n\n num[i] += (s - sum) as u8;\n vec_to_num(&num)\n}\n\nfn find_max(m: usize, s: usize) -> String {\n let mut num = vec![9; m];\n let mut i = m - 1;\n let mut sum = 9 * m;\n\n while sum - 9 > s {\n num[i] = 0;\n i -= 1;\n sum -= 9;\n }\n\n num[i] -= (sum - s) as u8;\n vec_to_num(&num)\n}\n\nfn vec_to_num(v: &Vec) -> String {\n v.into_iter()\n .map(|digit| (digit + 48) as char)\n .collect::()\n}\n\nfn main() {\n let (m, s) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n if s < 1 || s > 9 * m {\n println!(\"-1 -1\");\n } else {\n println!(\"{} {}\", find_min(m, s), find_max(m, s))\n }\n}"}, {"source_code": "fn find_min(m: usize, s: usize) -> String {\n let mut num = vec![0; m];\n num[0] = 1;\n let mut i = m - 1;\n let mut sum = 1;\n\n while sum + 9 < s {\n num[i] = 9;\n i -= 1;\n sum += 9;\n }\n\n num[i] += (s - sum) as u8;\n vec_to_num(&num)\n}\n\nfn find_max(m: usize, s: usize) -> String {\n let mut num = vec![9; m];\n let mut i = m - 1;\n let mut sum = 9 * m;\n\n while sum - 9 > s {\n num[i] = 0;\n i -= 1;\n sum -= 9;\n }\n\n num[i] -= (sum - s) as u8;\n vec_to_num(&num)\n}\n\nfn vec_to_num(v: &Vec) -> String {\n v.into_iter()\n .map(|digit| (digit + 48) as char)\n .collect::()\n}\n\nfn main() {\n let (m, s) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n if s < 2 || s > 9 * m {\n println!(\"-1 -1\");\n } else {\n println!(\"{} {}\", find_min(m, s), find_max(m, s))\n }\n}"}, {"source_code": "fn find_min(m: usize, s: usize) -> String {\n let mut num = vec![0; m];\n num[0] = 1;\n let mut i = m - 1;\n let mut sum = 1;\n\n while sum + 9 < s {\n num[i] = 9;\n i -= 1;\n sum += 9;\n }\n\n num[i] = (s - sum) as u8;\n vec_to_num(&num)\n}\n\nfn find_max(m: usize, s: usize) -> String {\n let mut num = vec![9; m];\n let mut i = m - 1;\n let mut sum = 9 * m;\n\n while sum - 9 > s {\n num[i] = 0;\n i -= 1;\n sum -= 9;\n }\n\n num[i] -= (sum - s) as u8;\n vec_to_num(&num)\n}\n\nfn vec_to_num(v: &Vec) -> String {\n v.into_iter()\n .map(|digit| (digit + 48) as char)\n .collect::()\n}\n\nfn main() {\n let (m, s) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let temp: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (temp[0], temp[1])\n };\n\n if s < 2 || s > 9 * m {\n println!(\"-1 -1\");\n } else {\n println!(\"{} {}\", find_min(m, s), find_max(m, s))\n }\n}"}, {"source_code": "fn get_max_digits(length: usize, sum: u32) -> Option> {\n if length == 0 {\n return None;\n }\n if (sum == 0) && (length > 1) {\n return None;\n }\n if sum == 0 {\n return Some(vec![0]);\n }\n let mut result: Vec = Vec::with_capacity(length);\n let mut rest_sum: u32 = sum;\n let first_digit: u32;\n if rest_sum > 9 {\n first_digit = 9;\n } else {\n first_digit = rest_sum;\n }\n result.push(first_digit);\n rest_sum -= first_digit;\n\n for _ in 1..length {\n let digit: u32;\n if rest_sum > 9 {\n digit = 9;\n } else {\n digit = rest_sum;\n }\n result.push(digit);\n rest_sum -= digit;\n }\n\n if rest_sum == 0 {\n return Some(result);\n } else {\n return None;\n }\n}\n\nfn get_min_digits(length: usize, sum: u32) -> Option> {\n if (sum == 0) && (length > 1) {\n return None;\n }\n if sum == 0 {\n return Some(vec![0]);\n }\n let mut result: Vec = Vec::with_capacity(length);\n let mut rest_sum: u32 = sum - 1;\n\n for _ in 1..length {\n let digit: u32;\n if rest_sum > 9 {\n digit = 9;\n } else {\n digit = rest_sum;\n }\n result.push(digit);\n rest_sum -= digit;\n }\n\n if rest_sum >= 9 {\n return None;\n }\n\n let last_digit: u32 = rest_sum + 1;\n result.push(last_digit);\n\n result.reverse();\n return Some(result);\n}\n\n#[cfg(test)]\nmod tests {\n use super::{get_max_digits, get_min_digits};\n\n #[test]\n fn test1() {\n assert_eq!(get_max_digits(2, 15), Some(vec![9, 6]));\n assert_eq!(get_min_digits(2, 15), Some(vec![6, 9]));\n }\n #[test]\n fn test2() {\n assert_eq!(get_max_digits(3, 0), None);\n assert_eq!(get_min_digits(3, 0), None);\n }\n #[test]\n fn test3() {\n assert_eq!(get_max_digits(1, 0), Some(vec![0]));\n assert_eq!(get_min_digits(1, 0), Some(vec![0]));\n }\n #[test]\n fn test4() {\n assert_eq!(get_max_digits(1, 9), Some(vec![9]));\n assert_eq!(get_min_digits(1, 9), Some(vec![9]));\n }\n #[test]\n fn test5() {\n assert_eq!(get_max_digits(2, 12), Some(vec![9, 3]));\n assert_eq!(get_min_digits(2, 12), Some(vec![3, 9]));\n }\n}\n\nuse std::io::{stdin, stdout, BufRead, Write};\n\nfn main() {\n let stdin = stdin();\n let mut stdin_lock = stdin.lock();\n\n let stdout = stdout();\n let mut stdout_lock = stdout.lock();\n\n let mut input_str: String = String::new();\n stdin_lock.read_line(&mut input_str).unwrap();\n let mut input_tokens = input_str.trim().split_whitespace();\n let length: usize = input_tokens.next().unwrap().parse().unwrap();\n let sum: u32 = input_tokens.next().unwrap().parse().unwrap();\n\n if let Some(max_digits_array) = get_max_digits(length, sum) {\n for digit in max_digits_array {\n write!(stdout_lock, \"{}\", digit).unwrap();\n }\n } else {\n write!(stdout_lock, \"-1\").unwrap();\n }\n write!(stdout_lock, \" \").unwrap();\n\n if let Some(min_digits_array) = get_min_digits(length, sum) {\n for digit in min_digits_array {\n write!(stdout_lock, \"{}\", digit).unwrap();\n }\n } else {\n write!(stdout_lock, \"-1\").unwrap();\n }\n\n writeln!(stdout_lock, \"\").unwrap();\n}\n"}, {"source_code": "fn get_max_digits(length: usize, sum: u32) -> Option> {\n if length == 0 {\n return None;\n }\n if (sum == 0) && (length > 1) {\n return None;\n }\n if sum == 0 {\n return Some(vec![0]);\n }\n let mut result: Vec = Vec::with_capacity(length);\n let mut rest_sum: u32 = sum;\n let first_digit: u32;\n if rest_sum > 9 {\n first_digit = 9;\n } else {\n first_digit = rest_sum;\n }\n result.push(first_digit);\n rest_sum -= first_digit;\n\n for _ in 1..length {\n let digit: u32;\n if rest_sum > 9 {\n digit = 9;\n } else {\n digit = rest_sum;\n }\n result.push(digit);\n rest_sum -= digit;\n }\n\n if rest_sum == 0 {\n return Some(result);\n } else {\n return None;\n }\n}\n\nfn get_min_digits(length: usize, sum: u32) -> Option> {\n if (sum == 0) && (length > 1) {\n return None;\n }\n if sum == 0 {\n return Some(vec![0]);\n }\n let mut result: Vec = Vec::with_capacity(length);\n let mut rest_sum: u32 = sum - 1;\n\n for _ in 1..length {\n let digit: u32;\n if rest_sum > 9 {\n digit = 9;\n } else {\n digit = rest_sum;\n }\n result.push(digit);\n rest_sum -= digit;\n }\n\n if rest_sum >= 9 {\n return None;\n }\n\n let last_digit: u32 = rest_sum + 1;\n result.push(last_digit);\n\n result.reverse();\n return Some(result);\n}\n\n#[cfg(test)]\nmod tests {\n use super::{get_max_digits, get_min_digits};\n\n #[test]\n fn test1() {\n assert_eq!(get_max_digits(2, 15), Some(vec![9, 6]));\n assert_eq!(get_min_digits(2, 15), Some(vec![6, 9]));\n }\n #[test]\n fn test2() {\n assert_eq!(get_max_digits(3, 0), None);\n assert_eq!(get_min_digits(3, 0), None);\n }\n #[test]\n fn test3() {\n assert_eq!(get_max_digits(1, 0), Some(vec![0]));\n assert_eq!(get_min_digits(1, 0), Some(vec![0]));\n }\n #[test]\n fn test4() {\n assert_eq!(get_max_digits(1, 9), Some(vec![9]));\n assert_eq!(get_min_digits(1, 9), Some(vec![9]));\n }\n #[test]\n fn test5() {\n assert_eq!(get_max_digits(2, 12), Some(vec![9, 3]));\n assert_eq!(get_min_digits(2, 12), Some(vec![3, 9]));\n }\n}\n\nuse std::io::{stdin, stdout, BufRead, Write};\n\nfn main() {\n let stdin = stdin();\n let mut stdin_lock = stdin.lock();\n\n let stdout = stdout();\n let mut stdout_lock = stdout.lock();\n\n let mut input_str: String = String::new();\n stdin_lock.read_line(&mut input_str).unwrap();\n let mut input_tokens = input_str.trim().split_whitespace();\n let length: usize = input_tokens.next().unwrap().parse().unwrap();\n let sum: u32 = input_tokens.next().unwrap().parse().unwrap();\n\n if let Some(min_digits_array) = get_min_digits(length, sum) {\n for digit in min_digits_array {\n write!(stdout_lock, \"{}\", digit).unwrap();\n }\n } else {\n write!(stdout_lock, \"-1\").unwrap();\n }\n\n if let Some(max_digits_array) = get_max_digits(length, sum) {\n for digit in max_digits_array {\n write!(stdout_lock, \"{}\", digit).unwrap();\n }\n } else {\n write!(stdout_lock, \"-1\").unwrap();\n }\n write!(stdout_lock, \" \").unwrap();\n\n writeln!(stdout_lock, \"\").unwrap();\n}\n"}, {"source_code": "use std::io;\nuse std::cmp;\nuse std::process;\nfn main()\n{\n let mut s=String::new();\n io::stdin().read_line(&mut s).expect(\"read error\");\n let vec=s.split_whitespace()\n .map(|x|\n x.parse::().expect(\"parse error\"))\n .collect::>();\n if (vec[0]>1 && vec[1]<1) || (vec[0]*90\n {\n n1=n1-1;\n let x:i64=cmp::min(9,n2);\n n2-=x;\n ans1+=&x.to_string();\n }\n n1=vec[0];\n n2=vec[1];\n while n1>0{\n n1=n1-1;\n let mut x:i64=0;\n if n1==vec[0]-1{\n x=1;\n }\n x=cmp::max(x,n2-9*n1);\n n2-=x;\n ans2+=&x.to_string();\n }\n println!(\"{} {}\",ans2,ans1);\n}"}, {"source_code": "use std::io;\nuse std::cmp;\nuse std::process;\nfn main()\n{\n let mut s=String::new();\n io::stdin().read_line(&mut s).expect(\"read error\");\n let mut vec=s.split_whitespace()\n .map(|x|\n x.parse::().expect(\"parse error\"))\n .collect::>();\n if (vec[0]>1 && vec[1]<2) || (vec[0]*90\n {\n vec[0]=vec[0]-1;\n if vec[0]==0{\n ans=ans+&vec[1].to_string();\n }\n else{\n let x: i64=cmp::min(9,vec[1]-1);\n ans=ans+&x.to_string();\n vec[1]=vec[1]-x;\n }\n }\n println!(\"{} {}\",ans.chars().rev().collect::(),ans);\n}"}, {"source_code": "use std::io;\nuse std::cmp;\nuse std::process;\nfn main()\n{\n let mut s=String::new();\n io::stdin().read_line(&mut s).expect(\"read error\");\n let mut vec=s.split_whitespace()\n .map(|x|\n x.parse::().expect(\"parse error\"))\n .collect::>();\n if (vec[0]>1 && vec[1]<1) || (vec[0]*90\n {\n vec[0]=vec[0]-1;\n ans+=\"0\";\n } \n println!(\"{} {}\",ans, ans);\n process::exit(0);\n }\n while vec[0]>0\n {\n vec[0]=vec[0]-1;\n if vec[0]==0{\n ans=ans+&vec[1].to_string();\n }\n else{\n let x: i64=cmp::min(9,vec[1]-1);\n ans=ans+&x.to_string();\n vec[1]=vec[1]-x;\n }\n }\n println!(\"{} {}\",ans.chars().rev().collect::(),ans);\n}"}, {"source_code": "fn main() -> Result<(), Box> {\n let data = read_input();\n let (len, sum) = (data[0], data[1]);\n\n if sum == 0 || (sum == 1 && len > 1) || 9 * len < sum {\n println!(\"-1 -1\");\n return Ok(());\n }\n\n if (sum >= 1 && sum <= 9) && (len == 1) {\n println!(\"{} {}\", sum, sum);\n return Ok(());\n }\n\n if sum % 9 == 0 && sum / 9 == len {\n let mut ans = String::with_capacity(len);\n for _ in 0..len {\n ans.push('9')\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n let mut digits = vec![0; len];\n\n let nines = sum / 9;\n let rem = sum % 9;\n\n let start = len - 1 - nines;\n for i in (start..len).rev() {\n digits[i] = 9;\n }\n\n if len - nines > 1 {\n if rem > 0 {\n digits[start - 1] = rem - 1;\n digits[0] = 1;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n } else {\n if rem > 0 {\n digits[0] = rem;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n }\n \n for d in digits.iter() {\n print!(\"{}\", d);\n }\n print!(\" \");\n \n for d in digits.iter().rev() {\n print!(\"{}\", d);\n }\n println!();\n \n Ok(())\n}\n\nfn read_input() -> Vec {\n let mut buffer = String::new();\n\n std::io::stdin()\n .read_line(&mut buffer)\n .expect(\"Failed to get input\");\n\n buffer\n .trim()\n .split_whitespace()\n .map(|x| x.parse().expect(\"Failed to parse number\"))\n .collect()\n}\n"}, {"source_code": "fn main() -> Result<(), Box> {\n let data = read_input();\n let (len, sum) = (data[0], data[1]);\n\n if sum == 0 || 9 * len < sum {\n println!(\"-1 -1\");\n return Ok(());\n }\n\n if sum == 1 {\n let mut ans = String::with_capacity(len);\n ans.push('1');\n \n for _ in 1..len {\n ans.push('0');\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n if (sum >= 1 && sum <= 9) && (len == 1) {\n println!(\"{} {}\", sum, sum);\n return Ok(());\n }\n\n if sum % 9 == 0 && sum / 9 == len {\n let mut ans = String::with_capacity(len);\n for _ in 0..len {\n ans.push('9')\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n let mut digits = vec![0; len];\n\n let nines = sum / 9;\n let rem = sum % 9;\n\n let start = len - 1 - nines;\n for i in (start..len).rev() {\n digits[i] = 9;\n }\n\n if len - nines > 1 {\n if rem > 0 {\n digits[start - 1] = rem - 1;\n digits[0] = 1;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n } else {\n if rem > 0 {\n digits[0] = rem;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n }\n\n for d in digits.iter() {\n print!(\"{}\", d);\n }\n print!(\" \");\n\n for d in digits.iter().rev() {\n print!(\"{}\", d);\n }\n println!();\n\n Ok(())\n}\n\nfn read_input() -> Vec {\n let mut buffer = String::new();\n\n std::io::stdin()\n .read_line(&mut buffer)\n .expect(\"Failed to get input\");\n\n buffer\n .trim()\n .split_whitespace()\n .map(|x| x.parse().expect(\"Failed to parse number\"))\n .collect()\n}\n"}, {"source_code": "fn main() -> Result<(), Box> {\n let data = read_input();\n let (len, sum) = (data[0], data[1]);\n\n if 9 * len < sum {\n println!(\"-1 -1\");\n return Ok(());\n }\n\n if sum == 0 {\n println!(\"0 0\");\n return Ok(());\n }\n\n if sum == 1 {\n let mut ans = String::with_capacity(len);\n ans.push('1');\n \n for _ in 1..len {\n ans.push('0');\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n if (sum >= 1 && sum <= 9) && (len == 1) {\n println!(\"{} {}\", sum, sum);\n return Ok(());\n }\n\n if sum % 9 == 0 && sum / 9 == len {\n let mut ans = String::with_capacity(len);\n for _ in 0..len {\n ans.push('9')\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n let mut digits = vec![0; len];\n let mut max_digits = vec![0; len];\n \n let nines = sum / 9;\n let rem = sum % 9;\n\n let start = len - nines;\n for i in (start..len).rev() {\n digits[i] = 9;\n }\n\n if len - nines > 1 {\n if rem > 0 {\n digits[start - 1] = rem - 1;\n digits[0] = 1;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n } else {\n if rem > 0 {\n digits[0] = rem;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n }\n\n for i in 0..nines {\n max_digits[i] = 9;\n }\n if rem != 0 {\n max_digits[nines] = rem;\n }\n\n for d in digits {\n print!(\"{}\", d);\n }\n print!(\" \");\n\n for d in max_digits {\n print!(\"{}\", d);\n }\n println!();\n\n Ok(())\n}\n\nfn read_input() -> Vec {\n let mut buffer = String::new();\n\n std::io::stdin()\n .read_line(&mut buffer)\n .expect(\"Failed to get input\");\n\n buffer\n .trim()\n .split_whitespace()\n .map(|x| x.parse().expect(\"Failed to parse number\"))\n .collect()\n}\n"}, {"source_code": "fn main() -> Result<(), Box> {\n let data = read_input();\n let (len, sum) = (data[0], data[1]);\n\n if sum == 0 || 9 * len < sum {\n println!(\"-1 -1\");\n return Ok(());\n }\n\n if sum == 1 {\n let mut ans = String::with_capacity(len);\n ans.push('1');\n \n for _ in 1..len {\n ans.push('0');\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n if (sum >= 1 && sum <= 9) && (len == 1) {\n println!(\"{} {}\", sum, sum);\n return Ok(());\n }\n\n if sum % 9 == 0 && sum / 9 == len {\n let mut ans = String::with_capacity(len);\n for _ in 0..len {\n ans.push('9')\n }\n println!(\"{} {}\", ans, ans);\n return Ok(());\n }\n\n let mut digits = vec![0; len];\n let mut max_digits = vec![0; len];\n \n let nines = sum / 9;\n let rem = sum % 9;\n\n let start = len - nines;\n for i in (start..len).rev() {\n digits[i] = 9;\n }\n\n if len - nines > 1 {\n if rem > 0 {\n digits[start - 1] = rem - 1;\n digits[0] = 1;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n } else {\n if rem > 0 {\n digits[0] = rem;\n } else {\n digits[start] -= 1;\n digits[0] = 1;\n }\n }\n\n for i in 0..nines {\n max_digits[i] = 9;\n }\n if rem != 0 {\n max_digits[nines] = rem;\n }\n\n for d in digits {\n print!(\"{}\", d);\n }\n print!(\" \");\n\n for d in max_digits {\n print!(\"{}\", d);\n }\n println!();\n\n Ok(())\n}\n\nfn read_input() -> Vec {\n let mut buffer = String::new();\n\n std::io::stdin()\n .read_line(&mut buffer)\n .expect(\"Failed to get input\");\n\n buffer\n .trim()\n .split_whitespace()\n .map(|x| x.parse().expect(\"Failed to parse number\"))\n .collect()\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 {\n println!(\"-1 -1\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n maxima = String::from(\"-1\");\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n }\n\n \n\n for ch in chars {\n minima.push(ch);\n }\n\n println!(\"{} {}\", minima, maxima);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 {\n println!(\"-1 -1\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n maxima = String::from(\"-1\");\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n }\n\n for ch in chars {\n minima.push(ch);\n }\n\n if maxima == \"-1\" {\n minima = String::from(\"-1\");\n }\n\n println!(\"{} {}\", minima, maxima);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 && m != 1 {\n println!(\"-1 -1\");\n return;\n }\n\n if s == 0 && m == 1 {\n println!(\"0 0\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n maxima = String::from(\"-1\");\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n }\n\n for ch in chars {\n minima.push(ch);\n }\n\n if maxima == \"-1\" {\n minima = String::from(\"-1\");\n }\n\n println!(\"{} {}\", minima, maxima);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 {\n println!(\"-1 -1\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n maxima = String::from(\"-1\");\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n }\n\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n\n for ch in chars {\n minima.push(ch);\n }\n\n println!(\"{} {}\", maxima, minima);\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/489/C\nuse std::io;\nuse std::char;\n\nfn reverse(cadena: &String) -> String {\n let mut ans = String::from(\"\");\n for ch in cadena.chars().rev() {\n ans.push(ch);\n }\n ans\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 m = words[0] as usize;\n let mut s = words[1];\n let mut _t = words[1];\n\n if s == 0 {\n println!(\"-1 -1\");\n return;\n }\n\n // lets construct maxima\n let mut maxima = String::from(\"\");\n\n while s > 0 {\n if s >= 9 {\n maxima = format!(\"9{}\", maxima);\n s -= 9;\n } else {\n maxima = format!(\"{}{}\", maxima, s);\n s -= s;\n }\n }\n \n if maxima.len() > m {\n maxima = String::from(\"-1\");\n }\n\n while maxima.len() < m {\n maxima = format!(\"{}0\", maxima);\n }\n\n // lets construct minima\n let mut chars: Vec = reverse(&maxima).chars().collect();\n let mut minima = String::from(\"\");\n\n if chars[0] == '0' {\n chars[0] = '1';\n for i in 1..chars.len() {\n if chars[i] != '0' {\n chars[i] = char::from_digit(chars[i].to_digit(10).unwrap()-1,10).unwrap();\n break;\n }\n }\n }\n\n \n\n for ch in chars {\n minima.push(ch);\n }\n\n println!(\"{} {}\", maxima, minima);\n}\n\n"}, {"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 m: isize = scan.next();\n let s: isize = scan.next();\n let nnines = s / 9;\n let last = s % 9;\n if nnines > m {\n println!(\"-1 -1\");\n } else {\n let sol_max = format!(\"{}{}{}\", \"9\".repeat(nnines as usize), last,\n \"0\".repeat((m -nnines -1).max(0) as usize));\n let mut sol_min: String = String::new();\n if nnines == 0 {\n sol_min = format!(\"1{}{}\",\"0\".repeat((m -2).max(0) as usize ), last-1);\n } else {\n if last == 0 {\n sol_min = format!(\"1{}8{}\", \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat((nnines -1).max(0) as usize));\n } else {\n sol_min = format!(\"{}{}{}\", last, \n \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat(nnines as usize));\n }\n }\n println!(\"{} {}\", sol_min, sol_max);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n\n"}, {"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 m: isize = scan.next();\n let s: isize = scan.next();\n let nnines = s / 9;\n let last = s % 9;\n if nnines > m || m>1 && s == 0 {\n println!(\"-1 -1\");\n } else if m == 1 && s == 0 {\n println!(\"0 0\");\n } else {\n let sol_max = format!(\"{}{}{}\", \"9\".repeat(nnines as usize), last,\n \"0\".repeat((m -nnines -1).max(0) as usize));\n let mut sol_min: String = String::new();\n if nnines == 0 {\n sol_min = format!(\"1{}{}\",\"0\".repeat((m -2).max(0) as usize ), last-1);\n } else {\n if last == 0 {\n sol_min = format!(\"1{}8{}\", \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat((nnines -1).max(0) as usize));\n } else {\n sol_min = format!(\"{}{}{}\", last, \n \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat(nnines as usize));\n }\n }\n println!(\"{} {}\", sol_min, sol_max);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n\n"}, {"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 m: isize = scan.next();\n let s: isize = scan.next();\n let nnines = s / 9;\n let last = s % 9;\n if nnines > m || nnines == m && last != 0 || m>1 && s == 0 {\n println!(\"-1 -1\");\n } else if m == 1 && s == 0 {\n println!(\"0 0\");\n } else if m == 1 {\n println!(\"{} {}\", s, s);\n } else {\n let sol_max = format!(\"{}{}{}\", \"9\".repeat(nnines as usize), last,\n \"0\".repeat((m -nnines -1).max(0) as usize));\n let mut sol_min: String = String::new();\n if nnines == 0 {\n sol_min = format!(\"1{}{}\",\"0\".repeat((m -2).max(0) as usize ), last-1);\n } else {\n if last == 0 && m>1 {\n sol_min = format!(\"1{}8{}\", \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat((nnines -1).max(0) as usize));\n } else {\n sol_min = format!(\"{}{}{}\", last, \n \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat(nnines as usize));\n }\n }\n println!(\"{} {}\", sol_min, sol_max);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n\n"}, {"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 m: isize = scan.next();\n let s: isize = scan.next();\n let nnines = s / 9;\n let last = s % 9;\n if nnines > m || nnines == m && last != 0 || m>1 && s == 0 {\n println!(\"-1 -1\");\n } else if m == 1 && s == 0 {\n println!(\"0 0\");\n } else if m == 1 {\n println!(\"{} {}\", s, s);\n } else if nnines == m {\n let sol = format!(\"{}\", \"9\".repeat(nnines as usize));\n println!(\"{} {}\", sol, sol);\n } else {\n let sol_max = format!(\"{}{}{}\", \"9\".repeat(nnines as usize), last,\n \"0\".repeat((m -nnines -1).max(0) as usize));\n let mut sol_min: String = String::new();\n if nnines == 0 {\n sol_min = format!(\"1{}{}\",\"0\".repeat((m - 2).max(0) as usize ), last-1);\n } else {\n if last == 0 {\n sol_min = format!(\"1{}8{}\", \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat((nnines -1).max(0) as usize));\n } else {\n sol_min = format!(\"{}{}{}\", last, \n \"0\".repeat((m -nnines -1).max(0) as usize),\n \"9\".repeat(nnines as usize));\n }\n }\n println!(\"{} {}\", sol_min, sol_max);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n\n"}, {"source_code": "use std::io;\n\n\nfn read_line(buf: &mut String) {\n buf.clear();\n match io::stdin().read_line(buf) {\n Err(error) => println!(\"error! {}\",error),\n _ => {}\n }\n}\n\nfn is_valid(m: i32, n: i32) -> bool {\n if n==0 || n>9*m {\n return false;\n }\n return true;\n}\nfn get_max(m:i32,n:i32) {\n let mut max = Vec::::new();\n max.reserve(m as usize);\n for _ in 0..m {\n max.push(0);\n }\n let mut n_copy = n;\n for index in 0..m {\n if n_copy > 9 {\n max[index as usize]+=9;\n n_copy -= 9;\n }\n else {\n max[index as usize]+= n_copy as u8;\n break;\n }\n }\n print!(\" \");\n for x in max {\n print!(\"{}\",x);\n }\n println!(\"\");\n\n}\nfn get_min(m:i32, n:i32) {\n let mut min = Vec::::new();\n min.reserve(m as usize);\n min.push(1);\n for _ in 1..m {\n min.push(0);\n }\n let mut n_copy = n-1;\n for index in (0..(m)).rev() {\n if n_copy > 9 {\n min[index as usize]+=9;\n n_copy -= 9;\n }\n else {\n min[index as usize]+= n_copy as u8;\n break;\n }\n }\n for x in min {\n print!(\"{}\",x);\n }\n\n}\n\nfn main() {\n let mut buf : String = String::new();\n read_line(&mut buf);\n let mut string_iter = buf.trim().split_whitespace();\n let m = string_iter.next().unwrap().parse::().unwrap();\n let n = string_iter.next().unwrap().parse::().unwrap();\n\n if !is_valid(m,n) {\n println!{\"-1 -1\"};\n }\n else {\n get_min(m,n);\n get_max(m,n);\n }\n}\n"}, {"source_code": "use std::io;\n\n\nfn read_line(buf: &mut String) {\n buf.clear();\n match io::stdin().read_line(buf) {\n Err(error) => println!(\"error! {}\",error),\n _ => {}\n }\n}\n\nfn is_valid(m: i32, n: i32) -> bool {\n if n==0 || n>9*m {\n return false;\n }\n return true;\n}\nfn get_max(m:i32,n:i32) {\n let mut max = Vec::::new();\n max.reserve(m as usize);\n for _ in 0..m {\n max.push(0);\n }\n let mut n_copy = n;\n for index in 0..m {\n if n_copy > 9 {\n max[index as usize]+=9;\n n_copy -= 9;\n }\n else {\n max[index as usize]+= n_copy as u8;\n break;\n }\n }\n print!(\" \");\n for x in max {\n print!(\"{}\",x);\n }\n println!(\"\");\n\n}\nfn get_min(m:i32, n:i32) {\n let mut min = Vec::::new();\n min.reserve(m as usize);\n min.push(1);\n for _ in 1..m {\n min.push(0);\n }\n let mut n_copy = n-1;\n for index in (0..(m)).rev() {\n if n_copy > 9 {\n min[index as usize]+=9;\n n_copy -= 9;\n }\n else {\n min[index as usize]+= n_copy as u8;\n break;\n }\n }\n for x in min {\n print!(\"{}\",x);\n }\n\n}\n\nfn main() {\n let mut buf : String = String::new();\n read_line(&mut buf);\n let mut string_iter = buf.trim().split_whitespace();\n let m = string_iter.next().unwrap().parse::().unwrap();\n let n = string_iter.next().unwrap().parse::().unwrap();\n\n if !is_valid(m,n) {\n if m==0 {\n println!(\"0 0\");\n }\n else{\n println!(\"-1 -1\");\n }\n }\n else {\n get_min(m,n);\n get_max(m,n);\n }\n}\n"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn max_num_with_m_digits_and_digit_sum(m : usize, s : usize, max_num : &mut Vec) {\n if s == 0 {\n if m == 1 {\n max_num.push(0);\n } else {\n // Do nothing ...\n }\n } else {\n let mut cur_sum = 0;\n for _ in 0 .. m {\n let diff = s - cur_sum; \n if diff >= 9 {\n max_num.push(9);\n cur_sum = cur_sum + 9;\n } else {\n max_num.push(diff as u8);\n cur_sum = cur_sum + diff;\n }\n }\n }\n}\n\nfn min_num_with_m_digits_and_digit_sum(m : usize, max_num : &mut Vec) {\n if max_num.is_empty() {\n // Do nothing ...\n } else {\n max_num.reverse();\n if max_num[0] == 0 {\n if m == 1 {\n // Do nothing ...\n } else {\n max_num[0] = 1;\n for i in 1 .. m {\n if max_num[i] == 0 {\n // Do nothing ...\n } else {\n max_num[i] = max_num[i] - 1;\n break;\n }\n }\n }\n }\n }\n}\n\nfn print_vec(v : &Vec) {\n for &x in v.iter() {\n print!(\"{}\", x);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut m_s = vec![];\n read_ts(&stdin, &mut m_s);\n let m = m_s[0];\n let s = m_s[1];\n let mut max_num = vec![];\n max_num_with_m_digits_and_digit_sum(m, s, &mut max_num);\n if max_num.is_empty() {\n println!(\"-1 -1\");\n } else {\n print_vec(&max_num);\n print!(\" \");\n min_num_with_m_digits_and_digit_sum(m, &mut max_num);\n print_vec(&max_num);\n println!();\n }\n}"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn max_num_with_m_digits_and_digit_sum(m : usize, s : usize, max_num : &mut Vec) {\n if s == 0 {\n if m == 1 {\n max_num.push(0);\n } else {\n // Do nothing ...\n }\n } else {\n let mut cur_sum = 0;\n for _ in 0 .. m {\n let diff = s - cur_sum; \n if diff >= 9 {\n max_num.push(9);\n cur_sum = cur_sum + 9;\n } else {\n max_num.push(diff as u8);\n cur_sum = cur_sum + diff;\n }\n }\n }\n}\n\nfn min_num_with_m_digits_and_digit_sum(m : usize, max_num : &mut Vec) {\n if max_num.is_empty() {\n // Do nothing ...\n } else {\n max_num.reverse();\n if max_num[0] == 0 {\n if m == 1 {\n // Do nothing ...\n } else {\n max_num[0] = 1;\n for i in 1 .. m {\n if max_num[i] == 0 {\n // Do nothing ...\n } else {\n max_num[i] = max_num[i] - 1;\n break;\n }\n }\n }\n }\n }\n}\n\nfn print_vec(v : &Vec) {\n for &x in v.iter() {\n print!(\"{}\", x);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut m_s = vec![];\n read_ts(&stdin, &mut m_s);\n let m = m_s[0];\n let s = m_s[1];\n let mut max_num = vec![];\n max_num_with_m_digits_and_digit_sum(m, s, &mut max_num);\n if max_num.is_empty() {\n println!(\"-1 -1\");\n } else {\n let mut max_num_copy = max_num.to_vec();\n min_num_with_m_digits_and_digit_sum(m, &mut max_num_copy);\n print_vec(&max_num_copy);\n print!(\" \");\n print_vec(&max_num);\n println!();\n }\n}"}, {"source_code": "fn solve() {\n let (m, s): (i32, i32) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut ws = buf.split_whitespace();\n let m = ws.next().unwrap().parse().unwrap();\n let s = ws.next().unwrap().parse().unwrap();\n (m, s)\n };\n\n let check = |m: i32, s: i32| (s >= 0) && s <= 9 * m;\n\n let mut ans = String::new();\n let mut sum = s;\n for i in 0..m {\n for d in 0..10 {\n if (i > 0 || d > 0 || (m == 1 && d == 0)) && check(m - i - 1, sum - d) {\n sum -= d;\n ans.push_str(&d.to_string());\n break;\n }\n }\n }\n\n ans.push(' ');\n sum = s;\n for i in 0..m {\n for d in (0..10).rev() {\n if (i > 0 || d > 0 || (m == 1 && d == 0)) && check(m - i - 1, sum - d) {\n sum -= d;\n ans.push_str(&d.to_string());\n break;\n }\n }\n }\n\n if ans.chars().next().unwrap() == '0' {\n println!(\"-1 -1\");\n return;\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n // let t: u32 = {\n // let mut buf = String::new();\n // std::io::stdin().read_line(&mut buf).unwrap();\n // buf.trim_end().parse().unwrap()\n // };\n\n // for _ in 0..t {}\n solve();\n}\n"}, {"source_code": "fn solve() {\n let (m, s): (i32, i32) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut ws = buf.split_whitespace();\n let m = ws.next().unwrap().parse().unwrap();\n let s = ws.next().unwrap().parse().unwrap();\n (m, s)\n };\n\n let check = |m: i32, s: i32| (s >= 0) && s <= 9 * m;\n\n let mut ans = String::new();\n let mut sum = s;\n for i in 0..m {\n for d in 0..10 {\n if (i > 0 || d > 0 || (m == 1 && d == 0)) && check(m - i - 1, sum - d) {\n sum -= d;\n ans.push_str(&d.to_string());\n break;\n }\n }\n }\n\n ans.push(' ');\n sum = s;\n for i in 0..m {\n for d in (0..10).rev() {\n if (i > 0 || d > 0 || (m == 1 && d == 0)) && check(m - i - 1, sum - d) {\n sum -= d;\n ans.push_str(&d.to_string());\n break;\n }\n }\n }\n\n match ans.chars().next().unwrap() {\n '0' => println!(\"-1 -1\"),\n ' ' => println!(\"-1 -1\"),\n _ => println!(\"{}\", ans),\n }\n}\n\nfn main() {\n // let t: u32 = {\n // let mut buf = String::new();\n // std::io::stdin().read_line(&mut buf).unwrap();\n // buf.trim_end().parse().unwrap()\n // };\n\n // for _ in 0..t {}\n solve();\n}\n"}, {"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\n\nfn main() {\n let stdin = stdin();\n let mut s = stdin.lock();\n let (m, s) = scan!(s, usize, i64);\n let mut smallest = vec![0; m];\n let mut largest = vec![0; m];\n let lower_bound = if m == 1 { 0 } else { 1 };\n let upper_bound = (9*m).num();\n\n if s >= lower_bound && s <= upper_bound {\n let mut temp = s;\n for i in 0..m {\n if temp > 9 {\n largest[i] = 9;\n temp -= 9;\n } else {\n largest[i] = temp;\n break;\n }\n }\n\n temp = s;\n for i in (0..m).rev() {\n if temp > 9 {\n smallest[i] = 9;\n temp -= 9;\n } else {\n smallest[i] = temp;\n break;\n }\n }\n\n let mut flag = false;\n for i in 0..m {\n if smallest[i] != 0 || flag {\n flag = true;\n print!(\"{}\", smallest[i]);\n } \n }\n if !flag {\n print!(\"0\");\n }\n print!(\" \");\n\n flag = false;\n for i in 0..m {\n if largest[i] != 0 || flag {\n flag = true;\n print!(\"{}\", largest[i]);\n }\n }\n if !flag {\n print!(\"0\");\n }\n } else {\n println!(\"-1 -1\");\n }\n}"}], "src_uid": "75d062cece5a2402920d6706c655cad7"} {"source_code": "use std::io::{self, Read};\nuse std::collections::BTreeSet;\n\nfn main() -> () {\n let mut buffer = String::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n\n handle.read_to_string(&mut buffer).unwrap();\n\n let mut arr = buffer.split_whitespace().take(1).map(|x| x.parse::().unwrap() ).collect::>();\n let n = arr[0] as usize;\n let mut num = buffer.split_whitespace().skip(1).take(1).next().unwrap();\n let mut b = vec![];\n for i in num.chars() {\n let digit = i as u32 - '0' as u32;\n b.push(digit);\n }\n let s : u32 = b.iter().sum();\n\n if s == 0 {\n println!(\"YES\");\n return\n }\n \n 'outer: for i in 1..s+1 {\n if s % i == 0 {\n let ss = s / i;\n let mut segsum = 0;\n let mut count_seg = 0;\n for j in 0..n {\n segsum += b[j];\n if segsum == ss {\n segsum = 0;\n count_seg += 1;\n } else if segsum > ss {\n continue 'outer;\n }\n }\n if count_seg > 1 {\n println!(\"YES\");\n return\n }\n }\n }\n\n println!(\"NO\");\n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn main() {\n let mut input_text = String::new();\n io::stdin()\n .read_line(&mut input_text)\n .expect(\"failed to read from stdin\");\n\n let trimmed = input_text.trim();\n let mut no_of_digits: u32 = 0;\n match trimmed.parse::() {\n Ok(i) => no_of_digits = i,\n Err(..) => println!(\"this was not an integer: {}\", trimmed),\n };\n\n let mut input_digits = String::new();\n \tio::stdin()\n .read_line(&mut input_digits)\n .expect(\"failed to read from stdin\");\n let digits = input_digits.trim();\n\n \tlet mut answer : bool = false;\n \tlet total_sum: u32 = digits.chars().map(|x| x.to_digit(10).unwrap()).sum();\n for i in 1..total_sum {\n let mut sum: u32 = 0;\n \tfor c in digits.chars() {\n\t\t\tlet current_digit = c.to_digit(10).unwrap();\n\t\t\tsum += current_digit;\n\t\t\tif sum == i {\n\t\t\t\tsum = 0;\n\t\t\t}\n \t}\n \tif sum == 0 {\n \t\tanswer = true;\n \t}\n }\n if answer || total_sum == 0 {\n \tprintln!(\"YES\");\n } else {\n \tprintln!(\"NO\");\n }\n}"}, {"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 can_be_splitted(slice : &[i32], sum : i32) -> bool {\n let mut curr_sum = 0;\n let mut index = 0;\n let mut at_least_one = false;\n loop {\n if index >= slice.len() {\n return at_least_one && curr_sum == 0;\n }\n\n curr_sum += slice[index];\n if curr_sum == sum {\n curr_sum = 0;\n at_least_one = true;\n } else if curr_sum > sum {\n return false;\n }\n index += 1;\n }\n\n true\n}\n\nfn solve(length : usize, digits : Vec) -> (bool, i32) {\n let mut curr_sum = 0;\n for index in 0..(length - 1) {\n curr_sum += digits[index];\n if can_be_splitted(&digits[(index + 1)..], curr_sum) {\n return (true, curr_sum);\n }\n }\n (false, 0)\n}\n\nfn main() {\n let length = readln!(usize);\n \n let digits = readln!();\n let digits : Vec = digits.chars().map(|ch| ch.to_digit(10).unwrap() as i32).collect();\n\n let (result, sum) = solve(length, digits);\n\n println!(\"{}\", if result { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "use std::io;\nuse std::slice::Iter;\nuse std::iter::Peekable;\n\nfn check_step(iter : &mut Peekable>, check_sum : u64) -> Option {\n if iter.len() == 0 { return None }\n let mut sum = 0;\n while let Some(x) = iter.next() {\n sum += x;\n if sum == check_sum {\n while iter.peek().map(|x| **x == 0).unwrap_or(false) {\n iter.next();\n }\n return Some(true)\n }\n }\n Some(false)\n}\n\nfn check(iter : Iter, check_sum : u64) -> bool {\n if iter.len() == 0 { return false }\n let mut iter = iter.peekable();\n while let Some(flag) = check_step(&mut iter, check_sum) {\n if !flag { \n return false \n }\n }\n true\n}\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n if check(iter.clone(), sum) {\n println!(\"YES\");\n return\n }\n }\n }\n println!(\"NO\");\n}"}], "negative_code": [{"source_code": "use std::io::{self, Read};\nuse std::collections::BTreeSet;\n\nfn main() -> () {\n let mut buffer = String::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n\n handle.read_to_string(&mut buffer).unwrap();\n\n let mut arr = buffer.split_whitespace().take(1).map(|x| x.parse::().unwrap() ).collect::>();\n let n = arr[0] as usize;\n let mut num = buffer.split_whitespace().skip(1).take(1).next().unwrap();\n let mut b = vec![];\n for i in num.chars() {\n let digit = i as u32 - '0' as u32;\n b.push(digit);\n }\n let s : u32 = b.iter().sum();\n \n 'outer: for i in 1..s+1 {\n if s % i == 0 {\n let ss = s / i;\n let mut segsum = 0;\n let mut count_seg = 0;\n for j in 0..n {\n segsum += b[j];\n if segsum == ss {\n segsum = 0;\n count_seg += 1;\n } else if segsum > ss {\n continue 'outer;\n }\n }\n if count_seg > 1 {\n println!(\"YES\");\n return\n }\n }\n }\n\n println!(\"NO\");\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input_text = String::new();\n io::stdin()\n .read_line(&mut input_text)\n .expect(\"failed to read from stdin\");\n\n let trimmed = input_text.trim();\n let mut no_of_digits: u32 = 0;\n match trimmed.parse::() {\n Ok(i) => no_of_digits = i,\n Err(..) => println!(\"this was not an integer: {}\", trimmed),\n };\n\n let mut input_digits = String::new();\n \tio::stdin()\n .read_line(&mut input_digits)\n .expect(\"failed to read from stdin\");\n let digits = input_digits.trim();\n\n \tlet mut answer : bool = false;\n \tlet total_sum: u32 = digits.chars().map(|x| x.to_digit(10).unwrap()).sum();\n for i in 1..total_sum {\n let mut sum: u32 = 0;\n \tfor c in digits.chars() {\n\t\t\tlet current_digit = c.to_digit(10).unwrap();\n\t\t\tsum += current_digit;\n\t\t\tif sum == i {\n\t\t\t\tsum = 0;\n\t\t\t}\n \t}\n \tif sum == 0 {\n \t\tanswer = true;\n \t}\n }\n if answer {\n \tprintln!(\"YES\");\n } else {\n \tprintln!(\"NO\");\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input_text = String::new();\n io::stdin()\n .read_line(&mut input_text)\n .expect(\"failed to read from stdin\");\n\n let trimmed = input_text.trim();\n let mut no_of_digits: u32 = 0;\n match trimmed.parse::() {\n Ok(i) => no_of_digits = i,\n Err(..) => println!(\"this was not an integer: {}\", trimmed),\n };\n\n let mut input_digits = String::new();\n \tio::stdin()\n .read_line(&mut input_digits)\n .expect(\"failed to read from stdin\");\n let digits = input_digits.trim();\n\n \tlet mut answer : bool = false;\n for i in 1..901 {\n let mut sum: u32 = 0;\n \tfor c in digits.chars() {\n\t\t\tlet current_digit = c.to_digit(10).unwrap();\n\t\t\tsum += current_digit;\n\t\t\tif sum == i {\n\t\t\t\tsum = 0;\n\t\t\t}\n \t}\n \tif sum == 0 {\n \t\tanswer = true;\n \t}\n }\n if answer {\n \tprintln!(\"YES\");\n } else {\n \tprintln!(\"NO\");\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input_text = String::new();\n io::stdin()\n .read_line(&mut input_text)\n .expect(\"failed to read from stdin\");\n\n let trimmed = input_text.trim();\n let mut no_of_digits: u32 = 0;\n match trimmed.parse::() {\n Ok(i) => no_of_digits = i,\n Err(..) => println!(\"this was not an integer: {}\", trimmed),\n };\n\n let mut input_digits = String::new();\n \tio::stdin()\n .read_line(&mut input_digits)\n .expect(\"failed to read from stdin\");\n let digits = input_digits.trim();\n\n \tlet mut answer : bool = false;\n \tlet total_sum: u32 = digits.chars().map(|x| x.to_digit(10).unwrap()).sum();\n for i in 0..total_sum {\n let mut sum: u32 = 0;\n \tfor c in digits.chars() {\n\t\t\tlet current_digit = c.to_digit(10).unwrap();\n\t\t\tsum += current_digit;\n\t\t\tif sum == i {\n\t\t\t\tsum = 0;\n\t\t\t}\n \t}\n \tif sum == 0 {\n \t\tanswer = true;\n \t}\n }\n if answer {\n \tprintln!(\"YES\");\n } else {\n \tprintln!(\"NO\");\n }\n}"}, {"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 can_be_splitted(slice : &[i32], sum : i32) -> bool {\n let mut curr_sum = 0;\n let mut index = 0;\n let mut at_least_one = false;\n loop {\n if index >= slice.len() {\n return at_least_one;\n }\n\n curr_sum += slice[index];\n if curr_sum == sum {\n curr_sum = 0;\n at_least_one = true;\n } else if curr_sum > sum {\n return false;\n }\n index += 1;\n }\n\n true\n}\n\nfn solve(length : usize, digits : Vec) -> (bool, i32) {\n let mut curr_sum = 0;\n for index in 0..(length - 1) {\n curr_sum += digits[index];\n if can_be_splitted(&digits[(index + 1)..], curr_sum) {\n return (true, curr_sum);\n }\n }\n (false, 0)\n}\n\nfn main() {\n let length = readln!(usize);\n \n let digits = readln!();\n let digits : Vec = digits.chars().map(|ch| ch.to_digit(10).unwrap() as i32).collect();\n\n let (result, sum) = solve(length, digits);\n\n println!(\"{}\", if result { \"YES\" } else { \"NO\" });\n}\n"}, {"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 can_be_splitted(slice : &[i32], sum : i32) -> bool {\n let mut curr_sum = 0;\n let mut index = 0;\n loop {\n if index >= slice.len() {\n return curr_sum == 0;\n }\n\n curr_sum += slice[index];\n if curr_sum == sum {\n curr_sum = 0;\n } else if curr_sum > sum {\n return false;\n }\n index += 1;\n }\n\n true\n}\n\nfn solve(length : usize, digits : Vec) -> (bool, i32) {\n let mut curr_sum = 0;\n for index in 0..(length - 1) {\n curr_sum += digits[index];\n if can_be_splitted(&digits[(index + 1)..], curr_sum) {\n return (true, curr_sum);\n }\n }\n (false, 0)\n}\n\nfn main() {\n let length = readln!(usize);\n \n let digits = readln!();\n let digits : Vec = digits.chars().map(|ch| ch.to_digit(10).unwrap() as i32).collect();\n\n let (result, sum) = solve(length, digits);\n\n println!(\"{}\", if result { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "use std::io;\nuse std::slice::Iter;\n\nfn check(mut iter : Iter, check_sum : u64) -> bool {\n let mut did_something = false;\n let mut sum = 0;\n while let Some(x) = iter.next() {\n sum += x;\n did_something = true;\n if sum == check_sum {\n sum = 0;\n }\n }\n if sum == 0 && did_something {\n true\n } else {\n false\n }\n}\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n if check(iter.clone(), sum) {\n println!(\"YES\");\n return\n }\n }\n }\n println!(\"NO\");\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n {\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n let mut exhausted = true;\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n exhausted = false;\n break\n }\n }\n if exhausted {\n println!(\"TRUE\");\n }\n }\n let mut sum2 = 0;\n while let Some(x) = iter.next() {\n sum2 += x;\n if sum2 == sum {\n sum2 = 0;\n }\n }\n if sum2 == 0 {\n println!(\"YES\")\n } else {\n println!(\"NO\")\n }\n}"}, {"source_code": "use std::io;\nuse std::slice::Iter;\n\nfn check(mut iter : Iter, check_sum : u64) -> bool {\n let mut sum = 0;\n while let Some(x) = iter.next() {\n sum += x;\n if sum == check_sum {\n sum = 0;\n }\n }\n if sum == 0 {\n true\n } else {\n false\n }\n}\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n if check(iter.clone(), sum) {\n println!(\"YES\");\n return\n }\n }\n }\n println!(\"NO\");\n}"}, {"source_code": "use std::io;\nuse std::slice::Iter;\n\nfn check_step(iter : &mut Iter, check_sum : u64) -> Option {\n if iter.as_slice().len() == 0 { return None }\n let mut iter = iter.peekable();\n let mut sum = 0;\n while let Some(x) = iter.next() {\n sum += x;\n if sum == check_sum {\n while iter.peek().map(|x| **x == 0).unwrap_or(false) {\n iter.next();\n }\n return Some(true)\n }\n }\n Some(false)\n}\n\nfn check(mut iter : Iter, check_sum : u64) -> bool {\n if iter.as_slice().len() == 0 { return false }\n while let Some(flag) = check_step(&mut iter, check_sum) {\n if !flag { \n return false \n }\n }\n true\n}\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n if check(iter.clone(), sum) {\n println!(\"YES\");\n return\n }\n }\n }\n println!(\"NO\");\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n {\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n let mut exhausted = true;\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n exhausted = false;\n break\n }\n }\n if exhausted {\n println!(\"NO\");\n }\n }\n let mut sum2 = 0;\n while let Some(x) = iter.next() {\n sum2 += x;\n if sum2 == sum {\n sum2 = 0;\n }\n }\n if sum2 == 0 {\n println!(\"YES\")\n } else {\n println!(\"NO\")\n }\n}"}, {"source_code": "use std::io;\nuse std::slice::Iter;\n\nfn check_step(iter : &mut Iter, check_sum : u64) -> Option {\n if iter.as_slice().len() == 0 { return None }\n let mut sum = 0;\n while let Some(x) = iter.next() {\n sum += x;\n if sum == check_sum {\n return Some(true)\n }\n }\n Some(false)\n}\n\nfn check(mut iter : Iter, check_sum : u64) -> bool {\n if iter.as_slice().len() == 0 { return false }\n while let Some(flag) = check_step(&mut iter, check_sum) {\n if !flag { \n return false \n }\n }\n true\n}\n\nfn main() {\n let n = {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n buffer.trim().parse().unwrap()\n };\n let nums : Vec = {\n let mut buffer = String::with_capacity(n);\n let mut char_str = String::from(\"0\");\n io::stdin().read_line(&mut buffer).unwrap();\n buffer\n .trim()\n .chars()\n .map(|x| {\n char_str.pop();\n char_str.push(x);\n char_str.trim().parse().unwrap()\n })\n .collect()\n };\n let mut iter = nums.iter();\n let mut sum = 0;\n let mut sum_rest : u64 = nums.iter().fold(0, |acc, x| acc + x);\n while let Some(x) = iter.next() {\n sum_rest -= x;\n sum += x;\n if sum_rest.checked_rem(sum).map(|x| x == 0).unwrap_or_else(|| sum == sum_rest) {\n if check(iter.clone(), sum) {\n println!(\"YES\");\n return\n }\n }\n }\n println!(\"NO\");\n}"}], "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"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 sort_str(s: String) -> Vec {\n let mut s: Vec = s.chars().collect();\n s.sort_unstable();\n s\n}\n\nfn solve(n: u32) -> &'static str {\n if n == 1 {\n \"Yes\"\n } else {\n let doggos = raw_input();\n let doggos = sort_str(doggos);\n\n let mut doggos_without_doubles = doggos.clone();\n doggos_without_doubles.dedup();\n\n if doggos != doggos_without_doubles {\n \"Yes\"\n } else {\n \"No\"\n }\n }\n}\n\nfn main() {\n let n: u32 = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n };\n println!(\"{}\", solve(n));\n}", "positive_code": [{"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 sort_str(s: String) -> Vec {\n let mut s: Vec = s.chars().collect();\n s.sort_unstable();\n s\n}\n\nfn solve(n: u32) -> &'static str {\n if n == 1 {\n return \"Yes\";\n } else {\n let doggos = raw_input();\n let doggos = sort_str(doggos);\n\n for i in 1..doggos.len() {\n if doggos[i] == doggos[i - 1] {\n return \"Yes\";\n }\n }\n }\n \"No\"\n}\n\nfn main() {\n let n: u32 = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n };\n println!(\"{}\", solve(n));\n}"}, {"source_code": "use std::io::*;\nuse std::str::FromStr;\n\n#[allow(dead_code)]\nfn get_line() -> String {\n let stdin = stdin();\n let mut line = String::new();\n stdin.lock().read_line(&mut line).expect(\"io error.\");\n line.trim().to_string()\n}\n\n#[allow(dead_code)]\nfn get_word() -> T {\n (&get_line()).parse().ok().expect(\"parse error.\")\n}\n\n#[allow(dead_code)]\nfn get_vec() -> Vec {\n (&get_line()).split(' ').map(|x| x.parse().ok().expect(\"parse error.\")).collect()\n}\n\nfn main() {\n let n = get_word::();\n let s = get_line();\n\n if n == 1 {\n println!(\"Yes\");\n return;\n }\n\n let mut cnt = [0u64; 26];\n for c in s.chars() {\n cnt[((c as u8) - ('a' as u8)) as usize] += 1;\n }\n\n for k in cnt.iter() {\n if *k > 1 {\n println!(\"Yes\");\n return;\n }\n }\n\n println!(\"No\");\n}\n"}, {"source_code": "fn read_string() -> String {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string)\n .ok()\n .expect(\"Ошибка чтения ввода\");\n return string;\n}\n\nfn main() {\n let n: i32 = read_string().trim().parse().unwrap();\n if n == 1 {\n println!(\"{}\", \"Yes\")\n }else {\n let text = read_string();\n let mut counter = [0; 26];\n let mut res = false;\n for ch in text.trim().chars() {\n let value: u32 = ch as u32 - 'a' as u32;\n counter[value as usize] += 1;\n if counter[value as usize] > 1 {\n res = true;\n }\n }\n if res{\n println!(\"{}\", \"Yes\")\n }else {\n println!(\"{}\", \"No\")\n }\n }\n}"}], "negative_code": [{"source_code": "use std::io::*;\nuse std::str::FromStr;\n\n#[allow(dead_code)]\nfn get_line() -> String {\n let stdin = stdin();\n let mut line = String::new();\n stdin.lock().read_line(&mut line).expect(\"io error.\");\n line.trim().to_string()\n}\n\n#[allow(dead_code)]\nfn get_word() -> T {\n (&get_line()).parse().ok().expect(\"parse error.\")\n}\n\n#[allow(dead_code)]\nfn get_vec() -> Vec {\n (&get_line()).split(' ').map(|x| x.parse().ok().expect(\"parse error.\")).collect()\n}\n\nfn main() {\n let _ = get_word::();\n let s = get_line();\n\n let mut cnt = [0u64; 26];\n for c in s.chars() {\n cnt[((c as u8) - ('a' as u8)) as usize] += 1;\n }\n\n for k in cnt.iter() {\n if *k > 1 {\n println!(\"Yes\");\n return;\n }\n }\n\n println!(\"No\");\n}\n"}, {"source_code": "fn read_string() -> String {\n let mut string: String = String::new();\n std::io::stdin().read_line(&mut string)\n .ok()\n .expect(\"Ошибка чтения ввода\");\n return string;\n}\n\nfn main() {\n read_string();\n let text = read_string();\n let mut counter = [0; 26];\n let mut res = false;\n for ch in text.trim().chars() {\n let value: u32 = ch as u32 - 'a' as u32;\n counter[value as usize] += 1;\n if counter[value as usize] > 1 {\n res = true;\n }\n }\n if res {\n println!(\"{}\", \"Yes\")\n }else {\n println!(\"{}\", \"No\")\n }\n}"}], "src_uid": "6b22e93f7e429693dcfe3c099346dcda"} {"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(solve)?\n .join()\n .unwrap();\n Ok(())\n}\n\nfn solve() {\n let stdin = io::stdin();\n let mut kin = KInput::new(stdin.lock());\n let stdout = io::stdout();\n let mut out = io::BufWriter::new(stdout.lock());\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 (n, k): (i64, i64) = kin.input();\n if k >= n {\n outputln!(\"0\");\n return;\n }\n const MOD: i64 = 998244353;\n let c = Combination::new(n as usize, MOD);\n if k == 0 {\n outputln!(\"{}\", c.fact(n));\n return;\n }\n let mut ans = 0;\n let mut sign = 1;\n for i in (1..=n - k).rev() {\n ans += MOD + sign * (c.pow(i, n) * c.comb(n - k, i) % MOD);\n sign = -sign;\n }\n ans %= MOD;\n ans = ans * c.comb(n, n - k) % MOD * 2 % MOD;\n outputln!(\"{}\", ans);\n}\npub fn mod_pow(mut a: i64, mut b: i64, m: i64) -> i64 {\n let mut y = 1;\n while b > 0 {\n if b & 1 == 1 {\n y = y * a % m;\n }\n a = a * a % m;\n b >>= 1;\n }\n y\n}\npub fn mod_inv(x: i64, m: i64) -> i64 {\n mod_pow(x, m - 2, m)\n}\npub struct Combination {\n m: i64,\n fact: Vec,\n}\nimpl Combination {\n pub fn new(size: usize, m: i64) -> Self {\n let mut comb = Self {\n m,\n fact: Vec::new(),\n };\n comb.resize(size);\n comb\n }\n pub fn resize(&mut self, size: usize) {\n let old_len = self.fact.len();\n self.fact.resize(size + 1, 0);\n for i in old_len..=size {\n self.fact[i] = if i == 0 {\n 1\n } else {\n i as i64 * self.fact[i - 1] % self.m\n };\n }\n }\n pub fn fact(&self, x: i64) -> i64 {\n self.fact[x as usize]\n }\n pub fn perm(&self, a: i64, b: i64) -> i64 {\n if a >= b {\n self.fact(a) * self.inv(self.fact(a - b)) % self.m\n } else {\n 0\n }\n }\n pub fn comb(&self, a: i64, b: i64) -> i64 {\n if a >= b {\n self.fact(a) * self.inv(self.fact(b) * self.fact(a - b) % self.m) % self.m\n } else {\n 0\n }\n }\n pub fn pow(&self, a: i64, b: i64) -> i64 {\n mod_pow(a, b, self.m)\n }\n pub fn inv(&self, x: i64) -> i64 {\n self.pow(x, self.m - 2)\n }\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 }\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}\n", "positive_code": [{"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 より\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 n: usize,\n m: u64,\n }\n if m > n as u64 - 1 {\n println!(\"0\");\n return;\n }\n let m = m as usize;\n let pc = Precalc::new(n + m);\n if m == 0 {\n println!(\"{}\", pc.fact(n));\n return;\n }\n let mut ans = ModInt::zero();\n let mut sign = ModInt::one();\n for i in (1..=(n - m)).rev() {\n ans += sign * pc.comb(n - m, i) * ModInt::from(i).pow(n as u32);\n sign = -sign;\n }\n ans *= pc.comb(n, n - m) * ModInt(2);\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"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 より\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}\nfn run() {\n input! {\n n: usize,\n m: u64,\n }\n if m > n as u64 - 1 {\n println!(\"0\");\n return;\n }\n let m = m as usize;\n let pc = Precalc::new(n + m);\n if m == 0 {\n println!(\"{}\", pc.fact(n));\n return;\n }\n let mut ans = ModInt::zero();\n let mut sign = ModInt::one();\n for i in (1..=(n - m)).rev() {\n ans += sign * pc.comb(n - m, i) * ModInt::from(i).pow(n as u32);\n sign = -sign;\n }\n ans *= pc.comb(n, n - m) * ModInt(2);\n println!(\"{}\", ans);\n}\nfn main() {\n run();\n}"}, {"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\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 = 998_244_353;\ndefine_mod!(P, MOD);\ntype ModInt = mod_int::ModInt

;\n\n// Depends on ModInt.rs\nfn fact_init(w: usize) -> (Vec, Vec) {\n let mut fac = vec![ModInt::new(1); w];\n let mut invfac = vec![0.into(); w];\n for i in 1 .. w {\n fac[i] = fac[i - 1] * i as i64;\n }\n invfac[w - 1] = fac[w - 1].inv();\n for i in (0 .. w - 1).rev() {\n invfac[i] = invfac[i + 1] * (i as i64 + 1);\n }\n (fac, invfac)\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: usize, k: i64);\n let (fac, invfac) = fact_init(n + 1);\n if k > n as i64 - 1 {\n puts!(\"0\\n\");\n return;\n }\n let k = k as usize;\n if k == 0 {\n puts!(\"{}\\n\", fac[n]);\n return;\n }\n let mut inex = ModInt::new(0);\n // Sur(n, n - k)\n for i in 0..n - k + 1 {\n let sgn = if (n - k + i) % 2 == 0 { 1 } else { MOD - 1 };\n let tmp = ModInt::new(i as i64).pow(n as i64);\n inex += tmp * sgn * fac[n - k] * invfac[i] * invfac[n - k - i];\n }\n puts!(\"{}\\n\", inex * fac[n] * invfac[n - k] * invfac[k] * 2);\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"}], "negative_code": [], "src_uid": "6c1a9aaa7bdd7de97220b8c6d35740cc"} {"source_code": "// ---------- begin chmin, chmax ----------\r\npub trait ChangeMinMax {\r\n fn chmin(&mut self, x: Self) -> bool;\r\n fn chmax(&mut self, x: Self) -> bool;\r\n}\r\n\r\nimpl ChangeMinMax for T {\r\n fn chmin(&mut self, x: Self) -> bool {\r\n *self > x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n fn chmax(&mut self, x: Self) -> bool {\r\n *self < x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n}\r\n// ---------- end chmin, chmax ----------\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\nuse std::collections::*;\r\nuse std::io::Write;\r\n\r\ntype Map = BTreeMap;\r\n\r\n// 下の桁からdpっぽく?\r\n// +がいくつ、-がいくつ、暫定carryがいくつ\r\n// この時1を幾つで合わせられるか的な\r\n// MLE\r\n// なんか状態多いっぽいが\r\n//\r\n//\r\n\r\nconst INF: i32 = 100000;\r\n\r\nfn run() {\r\n input!(s: bytes);\r\n let m = 300;\r\n let geta = m / 9 + 1;\r\n let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n dp[geta] = vec![vec![0; m + 1]; m + 1];\r\n for &s in s.iter().rev() {\r\n let s = (s - b'0') as i32;\r\n let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n if *dp == INF {\r\n continue;\r\n }\r\n let carry = carry as i32 - geta as i32;\r\n let d = add as i32 - sub as i32 + carry;\r\n if d.rem_euclid(10) != s {\r\n continue;\r\n }\r\n let carry = (d.div_euclid(10) + geta as i32) as usize;\r\n next[carry][add][sub].chmin(*dp + (add + sub) as i32);\r\n }\r\n }\r\n }\r\n dp = next;\r\n for dp in dp.iter_mut() {\r\n for i in (0..m).rev() {\r\n for j in (0..m).rev() {\r\n dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);\r\n }\r\n }\r\n }\r\n }\r\n let mut ans = INF;\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n let carry = carry as i32 - geta as i32;\r\n let add = add as i32;\r\n let sub = sub as i32;\r\n let mut v = *dp;\r\n if carry == 0 {\r\n } else if carry > 0 && sub >= carry {\r\n v += carry;\r\n } else if carry < 0 && add >= -carry {\r\n v += -carry;\r\n } else {\r\n v += INF;\r\n }\r\n ans.chmin(v);\r\n }\r\n }\r\n }\r\n println!(\"{}\", ans);\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n", "positive_code": [{"source_code": "// ---------- begin chmin, chmax ----------\r\npub trait ChangeMinMax {\r\n fn chmin(&mut self, x: Self) -> bool;\r\n fn chmax(&mut self, x: Self) -> bool;\r\n}\r\n\r\nimpl ChangeMinMax for T {\r\n fn chmin(&mut self, x: Self) -> bool {\r\n *self > x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n fn chmax(&mut self, x: Self) -> bool {\r\n *self < x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n}\r\n// ---------- end chmin, chmax ----------\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\nuse std::collections::*;\r\nuse std::io::Write;\r\n\r\ntype Map = BTreeMap;\r\n\r\n// 下の桁からdpっぽく?\r\n// +がいくつ、-がいくつ、暫定carryがいくつ\r\n// この時1を幾つで合わせられるか的な\r\n// MLE\r\n// なんか状態多いっぽいが\r\n//\r\n//\r\n\r\nconst INF: i32 = 100000;\r\n\r\nfn run() {\r\n input!(s: bytes);\r\n let m = 200;\r\n let geta = m / 9 + 1;\r\n let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n dp[geta] = vec![vec![0; m + 1]; m + 1];\r\n for &s in s.iter().rev() {\r\n let s = (s - b'0') as i32;\r\n let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n if *dp == INF {\r\n continue;\r\n }\r\n let carry = carry as i32 - geta as i32;\r\n let d = add as i32 - sub as i32 + carry;\r\n if d.rem_euclid(10) != s {\r\n continue;\r\n }\r\n let carry = (d.div_euclid(10) + geta as i32) as usize;\r\n next[carry][add][sub].chmin(*dp + (add + sub) as i32);\r\n }\r\n }\r\n }\r\n dp = next;\r\n for dp in dp.iter_mut() {\r\n for i in (0..m).rev() {\r\n for j in (0..m).rev() {\r\n dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);\r\n }\r\n }\r\n }\r\n }\r\n let mut ans = INF;\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n let carry = carry as i32 - geta as i32;\r\n let add = add as i32;\r\n let sub = sub as i32;\r\n let mut v = *dp;\r\n if carry == 0 {\r\n } else if carry > 0 && sub >= carry {\r\n v += carry;\r\n } else if carry < 0 && add >= -carry {\r\n v += -carry;\r\n } else {\r\n v += INF;\r\n }\r\n ans.chmin(v);\r\n }\r\n }\r\n }\r\n println!(\"{}\", ans);\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"source_code": "#[allow(unused_imports)]\r\nuse std::cmp::*;\r\n#[allow(unused_imports)]\r\nuse std::collections::*;\r\n#[allow(unused_imports)]\r\nuse std::io;\r\n#[allow(unused_imports)]\r\nuse std::iter::*;\r\n#[allow(unused_imports)]\r\nuse std::mem::*;\r\n#[allow(unused_imports)]\r\nuse std::str::*;\r\n#[allow(unused_imports)]\r\nuse std::usize;\r\n\r\n// vec with some initial value\r\n#[allow(unused_macros)]\r\nmacro_rules! vvec {\r\n ($($x:expr),+; $y:expr; $n:expr) => {{\r\n let mut v = vec![$y; $n];\r\n\r\n let mut it = v.iter_mut();\r\n $(\r\n *it.next().unwrap() = $x;\r\n )+\r\n\r\n v\r\n }}\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! it {\r\n ($x:expr) => {\r\n once($x)\r\n };\r\n ($first:expr,$($x:expr),+) => {\r\n chain(\r\n once($first),\r\n it!($($x),+)\r\n )\r\n }\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! pushed {\r\n ($c:expr, $x:expr) => {{\r\n let mut c = $c;\r\n c.push($x);\r\n c\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! inserted {\r\n ($c:expr, $($x:expr),*) => {{\r\n let mut c = $c;\r\n c.insert($($x),*);\r\n c\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_tuple {\r\n ($($t:ty),+) => {{\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n\r\n let mut it = line.trim()\r\n .split_whitespace();\r\n\r\n ($(\r\n it.next().unwrap().parse::<$t>().ok().unwrap()\r\n ),+)\r\n }}\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read() -> T {\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n line.trim().to_string().parse().ok().unwrap()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_str() -> Vec {\r\n read::().chars().collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_row() -> Vec {\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n\r\n line.trim()\r\n .split_whitespace()\r\n .map(|s| s.parse().ok().unwrap())\r\n .collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_col(n: usize) -> Vec {\r\n (0..n).map(|_| read()).collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_mat(n: usize) -> Vec> {\r\n (0..n).map(|_| read_row()).collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_vec R>(n: usize, mut f: F) -> Vec {\r\n (0..n).map(|_| f()).collect()\r\n}\r\n\r\ntrait IterCopyExt<'a, T>: IntoIterator + Sized\r\nwhere\r\n T: 'a + Copy,\r\n{\r\n fn citer(self) -> std::iter::Copied {\r\n self.into_iter().copied()\r\n }\r\n}\r\n\r\nimpl<'a, T, I> IterCopyExt<'a, T> for I\r\nwhere\r\n I: IntoIterator,\r\n T: 'a + Copy,\r\n{\r\n}\r\n\r\nconst B: i32 = 250;\r\nconst C: i32 = 25;\r\n\r\nfn main() {\r\n let n = read::()\r\n .chars()\r\n .map(|c| c.to_digit(10).unwrap() as i32)\r\n .collect::>();\r\n\r\n let dp = n.citer().fold(\r\n (-C..=C)\r\n .map(|t| {\r\n (0..B)\r\n .map(|i| {\r\n if i < t {\r\n vec![i32::MAX; B as usize]\r\n } else {\r\n vec![t; B as usize]\r\n }\r\n })\r\n .collect::>()\r\n })\r\n .collect::>(),\r\n |prev, d| {\r\n // eprintln!(\"{:?}\", prev);\r\n (-C..=C)\r\n .map(|t| {\r\n let d = d + t;\r\n let mut dp = (0..B)\r\n .map(|i| {\r\n let mut v = vec![i32::MAX; B as usize];\r\n\r\n (-C..=C).for_each(|c| {\r\n if i + 10 * c >= d && i + 10 * c < B + d {\r\n let j = i + 10 * c - d;\r\n v[j as usize] = prev[(c + C) as usize][i as usize][j as usize]\r\n .saturating_add(i + j);\r\n }\r\n });\r\n\r\n v\r\n })\r\n .collect::>();\r\n for i in 0..B {\r\n for j in 0..B {\r\n if i > 0 {\r\n dp[i as usize][j as usize] =\r\n min(dp[i as usize][j as usize], dp[i as usize - 1][j as usize]);\r\n }\r\n if j > 0 {\r\n dp[i as usize][j as usize] =\r\n min(dp[i as usize][j as usize], dp[i as usize][j as usize - 1]);\r\n }\r\n }\r\n }\r\n dp\r\n })\r\n .collect::>()\r\n },\r\n );\r\n let ans = dp[0 + C as usize][B as usize - 1][B as usize - 1];\r\n println!(\"{}\", ans);\r\n}\r\n"}], "negative_code": [{"source_code": "// ---------- begin chmin, chmax ----------\r\npub trait ChangeMinMax {\r\n fn chmin(&mut self, x: Self) -> bool;\r\n fn chmax(&mut self, x: Self) -> bool;\r\n}\r\n\r\nimpl ChangeMinMax for T {\r\n fn chmin(&mut self, x: Self) -> bool {\r\n *self > x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n fn chmax(&mut self, x: Self) -> bool {\r\n *self < x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n}\r\n// ---------- end chmin, chmax ----------\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\nuse std::collections::*;\r\nuse std::io::Write;\r\n\r\ntype Map = BTreeMap;\r\n\r\n// 下の桁からdpっぽく?\r\n// +がいくつ、-がいくつ、暫定carryがいくつ\r\n// この時1を幾つで合わせられるか的な\r\n// MLE\r\n// なんか状態多いっぽいが\r\n//\r\n//\r\n\r\nconst INF: i32 = 100000;\r\n\r\nfn dfs(\r\n pos: usize,\r\n add: i32,\r\n sub: i32,\r\n carry: i32,\r\n s: &[i32],\r\n dp: &mut Map<(usize, i32, i32, i32), i32>,\r\n) -> i32 {\r\n if let Some(&v) = dp.get(&(pos, add, sub, carry)) {\r\n return v;\r\n }\r\n if pos == 0 {\r\n return if carry == 0 {\r\n 0\r\n } else if carry > 0 && sub >= carry {\r\n carry\r\n } else if carry < 0 && add >= -carry {\r\n -carry\r\n } else {\r\n INF\r\n };\r\n }\r\n let mut ans = INF;\r\n if add > 0 {\r\n ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));\r\n }\r\n if sub > 0 {\r\n ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));\r\n }\r\n let d = add - sub + carry;\r\n if d.rem_euclid(10) == s[pos - 1] {\r\n let carry = d.div_euclid(10);\r\n ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);\r\n }\r\n dp.insert((pos, add, sub, carry), ans);\r\n ans\r\n}\r\n\r\nfn run() {\r\n input!(s: bytes);\r\n let m = 150;\r\n let geta = m / 10 + 2;\r\n let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n dp[geta] = vec![vec![0; m + 1]; m + 1];\r\n for &s in s.iter().rev() {\r\n let s = (s - b'0') as i32;\r\n let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n if *dp == INF {\r\n continue;\r\n }\r\n let carry = carry as i32 - geta as i32;\r\n let d = add as i32 - sub as i32 + carry;\r\n if d.rem_euclid(10) != s {\r\n continue;\r\n }\r\n let carry = (d.div_euclid(10) + geta as i32) as usize;\r\n next[carry][add][sub].chmin(*dp + (add + sub) as i32);\r\n }\r\n }\r\n }\r\n dp = next;\r\n for dp in dp.iter_mut() {\r\n for i in (0..m).rev() {\r\n for j in (0..m).rev() {\r\n dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);\r\n }\r\n }\r\n }\r\n }\r\n let mut ans = INF;\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n let carry = carry as i32 - geta as i32;\r\n let add = add as i32;\r\n let sub = sub as i32;\r\n let mut v = *dp;\r\n if carry == 0 {\r\n } else if carry > 0 && sub >= carry {\r\n v += carry;\r\n } else if carry < 0 && add >= -carry {\r\n v += -carry;\r\n } else {\r\n v += INF;\r\n }\r\n ans.chmin(v);\r\n }\r\n }\r\n }\r\n println!(\"{}\", ans);\r\n /*\r\n let s = s.into_iter().map(|s| (s - b'0') as i32).collect::>();\r\n let mut map = Map::new();\r\n let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);\r\n println!(\"{}\", ans);\r\n */\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"source_code": "// ---------- begin chmin, chmax ----------\r\npub trait ChangeMinMax {\r\n fn chmin(&mut self, x: Self) -> bool;\r\n fn chmax(&mut self, x: Self) -> bool;\r\n}\r\n\r\nimpl ChangeMinMax for T {\r\n fn chmin(&mut self, x: Self) -> bool {\r\n *self > x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n fn chmax(&mut self, x: Self) -> bool {\r\n *self < x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n}\r\n// ---------- end chmin, chmax ----------\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\nuse std::collections::*;\r\nuse std::io::Write;\r\n\r\ntype Map = BTreeMap;\r\n\r\n// 下の桁からdpっぽく?\r\n// +がいくつ、-がいくつ、暫定carryがいくつ\r\n// この時1を幾つで合わせられるか的な\r\n// MLE\r\n// なんか状態多いっぽいが\r\n//\r\n//\r\n\r\nconst INF: i32 = 100000;\r\n\r\nfn dfs(\r\n pos: usize,\r\n add: i32,\r\n sub: i32,\r\n carry: i32,\r\n s: &[i32],\r\n dp: &mut Map<(usize, i32, i32, i32), i32>,\r\n) -> i32 {\r\n if let Some(&v) = dp.get(&(pos, add, sub, carry)) {\r\n return v;\r\n }\r\n if pos == 0 {\r\n return if carry == 0 {\r\n 0\r\n } else if carry > 0 && sub >= carry {\r\n carry\r\n } else if carry < 0 && add >= -carry {\r\n -carry\r\n } else {\r\n INF\r\n };\r\n }\r\n let mut ans = INF;\r\n if add > 0 {\r\n ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));\r\n }\r\n if sub > 0 {\r\n ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));\r\n }\r\n let d = add - sub + carry;\r\n if d.rem_euclid(10) == s[pos - 1] {\r\n let carry = d.div_euclid(10);\r\n ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);\r\n }\r\n dp.insert((pos, add, sub, carry), ans);\r\n ans\r\n}\r\n\r\nfn run() {\r\n input!(s: bytes);\r\n let m = 100;\r\n let geta = 11;\r\n let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n dp[geta] = vec![vec![0; m + 1]; m + 1];\r\n for &s in s.iter().rev() {\r\n let s = (s - b'0') as i32;\r\n let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n if *dp == INF {\r\n continue;\r\n }\r\n let carry = carry as i32 - geta as i32;\r\n let d = add as i32 - sub as i32 + carry;\r\n if d.rem_euclid(10) != s {\r\n continue;\r\n }\r\n let carry = (d.div_euclid(10) + geta as i32) as usize;\r\n next[carry][add][sub].chmin(*dp + (add + sub) as i32);\r\n }\r\n }\r\n }\r\n dp = next;\r\n for dp in dp.iter_mut() {\r\n for i in (0..m).rev() {\r\n for j in (0..m).rev() {\r\n dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);\r\n }\r\n }\r\n }\r\n }\r\n let mut ans = INF;\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n let carry = carry as i32 - geta as i32;\r\n let add = add as i32;\r\n let sub = sub as i32;\r\n let mut v = *dp;\r\n if carry == 0 {\r\n } else if carry > 0 && sub >= carry {\r\n v += carry;\r\n } else if carry < 0 && add >= -carry {\r\n v += -carry;\r\n } else {\r\n v += INF;\r\n }\r\n ans.chmin(v);\r\n }\r\n }\r\n }\r\n println!(\"{}\", ans);\r\n /*\r\n let s = s.into_iter().map(|s| (s - b'0') as i32).collect::>();\r\n let mut map = Map::new();\r\n let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);\r\n println!(\"{}\", ans);\r\n */\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"source_code": "// ---------- begin chmin, chmax ----------\r\npub trait ChangeMinMax {\r\n fn chmin(&mut self, x: Self) -> bool;\r\n fn chmax(&mut self, x: Self) -> bool;\r\n}\r\n\r\nimpl ChangeMinMax for T {\r\n fn chmin(&mut self, x: Self) -> bool {\r\n *self > x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n fn chmax(&mut self, x: Self) -> bool {\r\n *self < x && {\r\n *self = x;\r\n true\r\n }\r\n }\r\n}\r\n// ---------- end chmin, chmax ----------\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\nuse std::collections::*;\r\nuse std::io::Write;\r\n\r\ntype Map = BTreeMap;\r\n\r\n// 下の桁からdpっぽく?\r\n// +がいくつ、-がいくつ、暫定carryがいくつ\r\n// この時1を幾つで合わせられるか的な\r\n// MLE\r\n// なんか状態多いっぽいが\r\n//\r\n//\r\n\r\nconst INF: i32 = 100000;\r\n\r\nfn dfs(\r\n pos: usize,\r\n add: i32,\r\n sub: i32,\r\n carry: i32,\r\n s: &[i32],\r\n dp: &mut Map<(usize, i32, i32, i32), i32>,\r\n) -> i32 {\r\n if let Some(&v) = dp.get(&(pos, add, sub, carry)) {\r\n return v;\r\n }\r\n if pos == 0 {\r\n return if carry == 0 {\r\n 0\r\n } else if carry > 0 && sub >= carry {\r\n carry\r\n } else if carry < 0 && add >= -carry {\r\n -carry\r\n } else {\r\n INF\r\n };\r\n }\r\n let mut ans = INF;\r\n if add > 0 {\r\n ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));\r\n }\r\n if sub > 0 {\r\n ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));\r\n }\r\n let d = add - sub + carry;\r\n if d.rem_euclid(10) == s[pos - 1] {\r\n let carry = d.div_euclid(10);\r\n ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);\r\n }\r\n dp.insert((pos, add, sub, carry), ans);\r\n ans\r\n}\r\n\r\nfn run() {\r\n input!(s: bytes);\r\n let m = 100;\r\n let geta = 11;\r\n let mut dp = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n dp[geta] = vec![vec![0; m + 1]; m + 1];\r\n for &s in s.iter().rev() {\r\n let s = (s - b'0') as i32;\r\n let mut next = vec![vec![vec![INF; m + 1]; m + 1]; 2 * geta + 1];\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n if *dp == INF {\r\n continue;\r\n }\r\n let carry = carry as i32 - geta as i32;\r\n let d = add as i32 - sub as i32 + carry;\r\n if d.rem_euclid(10) != s {\r\n continue;\r\n }\r\n let carry = (d.div_euclid(10) + geta as i32) as usize;\r\n next[carry][add][sub].chmin(*dp + (add + sub) as i32);\r\n }\r\n }\r\n }\r\n dp = next;\r\n for dp in dp.iter_mut() {\r\n for i in (0..m).rev() {\r\n for j in (0..m).rev() {\r\n dp[i][j] = dp[i][j].min(dp[i + 1][j]).min(dp[i][j + 1]);\r\n }\r\n }\r\n }\r\n }\r\n let mut ans = INF;\r\n for (carry, dp) in dp.iter().enumerate() {\r\n for (add, dp) in dp.iter().enumerate() {\r\n for (sub, dp) in dp.iter().enumerate() {\r\n let carry = carry as i32 - geta as i32;\r\n let add = add as i32;\r\n let sub = sub as i32;\r\n let mut v = *dp;\r\n if carry == 0 {\r\n } else if carry > 0 && sub >= carry {\r\n v += carry;\r\n } else if carry < 0 && add >= -carry {\r\n v += carry;\r\n } else {\r\n v += INF;\r\n }\r\n ans.chmin(v);\r\n }\r\n }\r\n }\r\n println!(\"{}\", ans);\r\n /*\r\n let s = s.into_iter().map(|s| (s - b'0') as i32).collect::>();\r\n let mut map = Map::new();\r\n let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);\r\n println!(\"{}\", ans);\r\n */\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"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::collections::*;\r\nuse std::io::Write;\r\n\r\ntype Map = HashMap;\r\n\r\n// 下の桁からdpっぽく?\r\n// +がいくつ、-がいくつ、暫定carryがいくつ\r\n// この時1を幾つで合わせられるか的な\r\n\r\nconst INF: i32 = 100000;\r\n\r\nfn dfs(\r\n pos: usize,\r\n add: i32,\r\n sub: i32,\r\n carry: i32,\r\n s: &[i32],\r\n dp: &mut Map<(usize, i32, i32, i32), i32>,\r\n) -> i32 {\r\n if let Some(&v) = dp.get(&(pos, add, sub, carry)) {\r\n return v;\r\n }\r\n if pos == 0 {\r\n return if carry == 0 {\r\n 0\r\n } else if carry > 0 && sub >= carry {\r\n carry\r\n } else if carry < 0 && add >= -carry {\r\n carry\r\n } else {\r\n INF\r\n };\r\n }\r\n let mut ans = INF;\r\n if add > 0 {\r\n ans = ans.min(dfs(pos, add - 1, sub, carry, s, dp));\r\n }\r\n if sub > 0 {\r\n ans = ans.min(dfs(pos, add, sub - 1, carry, s, dp));\r\n }\r\n let d = add - sub + carry;\r\n if d.rem_euclid(10) == s[pos - 1] {\r\n let carry = d.div_euclid(10);\r\n ans = ans.min(dfs(pos - 1, add, sub, carry, s, dp) + add + sub);\r\n }\r\n dp.insert((pos, add, sub, carry), ans);\r\n ans\r\n}\r\n\r\nfn run() {\r\n input!(s: bytes);\r\n let s = s.into_iter().map(|s| (s - b'0') as i32).collect::>();\r\n let mut map = Map::new();\r\n let ans = dfs(s.len(), 100, 100, 0, &s, &mut map);\r\n println!(\"{}\", ans);\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"source_code": "#[allow(unused_imports)]\r\nuse std::cmp::*;\r\n#[allow(unused_imports)]\r\nuse std::collections::*;\r\n#[allow(unused_imports)]\r\nuse std::io;\r\n#[allow(unused_imports)]\r\nuse std::iter::*;\r\n#[allow(unused_imports)]\r\nuse std::mem::*;\r\n#[allow(unused_imports)]\r\nuse std::str::*;\r\n#[allow(unused_imports)]\r\nuse std::usize;\r\n\r\n// vec with some initial value\r\n#[allow(unused_macros)]\r\nmacro_rules! vvec {\r\n ($($x:expr),+; $y:expr; $n:expr) => {{\r\n let mut v = vec![$y; $n];\r\n\r\n let mut it = v.iter_mut();\r\n $(\r\n *it.next().unwrap() = $x;\r\n )+\r\n\r\n v\r\n }}\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! it {\r\n ($x:expr) => {\r\n once($x)\r\n };\r\n ($first:expr,$($x:expr),+) => {\r\n chain(\r\n once($first),\r\n it!($($x),+)\r\n )\r\n }\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! pushed {\r\n ($c:expr, $x:expr) => {{\r\n let mut c = $c;\r\n c.push($x);\r\n c\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! inserted {\r\n ($c:expr, $($x:expr),*) => {{\r\n let mut c = $c;\r\n c.insert($($x),*);\r\n c\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_tuple {\r\n ($($t:ty),+) => {{\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n\r\n let mut it = line.trim()\r\n .split_whitespace();\r\n\r\n ($(\r\n it.next().unwrap().parse::<$t>().ok().unwrap()\r\n ),+)\r\n }}\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read() -> T {\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n line.trim().to_string().parse().ok().unwrap()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_str() -> Vec {\r\n read::().chars().collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_row() -> Vec {\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n\r\n line.trim()\r\n .split_whitespace()\r\n .map(|s| s.parse().ok().unwrap())\r\n .collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_col(n: usize) -> Vec {\r\n (0..n).map(|_| read()).collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_mat(n: usize) -> Vec> {\r\n (0..n).map(|_| read_row()).collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_vec R>(n: usize, mut f: F) -> Vec {\r\n (0..n).map(|_| f()).collect()\r\n}\r\n\r\ntrait IterCopyExt<'a, T>: IntoIterator + Sized\r\nwhere\r\n T: 'a + Copy,\r\n{\r\n fn citer(self) -> std::iter::Copied {\r\n self.into_iter().copied()\r\n }\r\n}\r\n\r\nimpl<'a, T, I> IterCopyExt<'a, T> for I\r\nwhere\r\n I: IntoIterator,\r\n T: 'a + Copy,\r\n{\r\n}\r\n\r\n// const B: usize = 500;\r\nconst B: usize = 22;\r\nconst C: usize = 5;\r\n\r\n// fn solve(\r\n// n: &[usize],\r\n// carry: usize,\r\n// plus_max: usize,\r\n// minus_max: usize,\r\n// memo: &mut Vec>>>>>,\r\n// ) -> Option<(usize, usize, usize)> {\r\n// if let Some(ret) = memo[n.len()][carry][plus_max][minus_max] {\r\n// return ret;\r\n// }\r\n\r\n// let ret = if plus_max >= B || minus_max >= B {\r\n// None\r\n// } else if n.is_empty() {\r\n// if plus_max >= carry {\r\n// Some((carry, carry, 0))\r\n// } else {\r\n// None\r\n// }\r\n// } else {\r\n// let d = *n.last().unwrap() + carry;\r\n\r\n// (0..=C)\r\n// .filter_map(|c| {\r\n// // make -c*10 + d\r\n// if plus_max + 10 * c < d || minus_max + d < 10 * c {\r\n// None\r\n// } else {\r\n// solve(\r\n// &n[0..n.len() - 1],\r\n// c,\r\n// min(plus_max, minus_max + d - 10 * c),\r\n// min(minus_max, plus_max + 10 * c - d),\r\n// memo,\r\n// )\r\n// .map(|t| {\r\n// let x = if t.2 + d >= 10 * c {\r\n// max(t.1, t.2 + d - 10 * c)\r\n// } else {\r\n// t.1\r\n// };\r\n// let y = if t.1 + 10 * c >= d {\r\n// max(t.1 + 10 * c - d, t.2)\r\n// } else {\r\n// t.2\r\n// };\r\n// (t.0 + x + y, x, y)\r\n// })\r\n// }\r\n// })\r\n// .min()\r\n// };\r\n\r\n// // eprintln!(\"{} {} {} {} {:?}\", n.len(), carry, plus_max, minus_max, ret);\r\n// memo[n.len()][carry][plus_max][minus_max] = Some(ret);\r\n\r\n// ret\r\n// }\r\n\r\nfn main() {\r\n let n = read::()\r\n .chars()\r\n .map(|c| c.to_digit(10).unwrap() as usize)\r\n .collect::>();\r\n\r\n let dp = n.citer().fold(\r\n (0..=C)\r\n .map(|t| {\r\n (0..B)\r\n .map(|i| {\r\n if i < t {\r\n vec![usize::MAX; B]\r\n } else {\r\n vec![t; B]\r\n }\r\n })\r\n .collect::>()\r\n })\r\n .collect::>(),\r\n |prev, d| {\r\n // eprintln!(\"{:?}\", prev);\r\n (0..=C)\r\n .map(|t| {\r\n let d = d + t;\r\n let mut dp = (0..B)\r\n .map(|i| {\r\n let mut v = vec![usize::MAX; B];\r\n\r\n (0..=C).for_each(|c| {\r\n if i + 10 * c >= d && i + 10 * c < B + d {\r\n let j = i + 10 * c - d;\r\n v[j] = prev[c][i][j].saturating_add(i + j);\r\n }\r\n });\r\n\r\n v\r\n })\r\n .collect::>();\r\n for i in 0..B {\r\n for j in 0..B {\r\n if i > 0 {\r\n dp[i][j] = min(dp[i][j], dp[i - 1][j]);\r\n }\r\n if j > 0 {\r\n dp[i][j] = min(dp[i][j], dp[i][j - 1]);\r\n }\r\n }\r\n }\r\n dp\r\n })\r\n .collect::>()\r\n },\r\n );\r\n let ans = dp[0][B - 1][B - 1];\r\n println!(\"{}\", ans);\r\n\r\n // let mut memo = vec![vec![vec![vec![None; B]; B]; C + 1]; n.len() + 1];\r\n // let ans2 = (0..B)\r\n // .filter_map(|i| (0..B).filter_map(|j| solve(&n, 0, i, j, &mut memo)).min())\r\n // .min()\r\n // .unwrap()\r\n // .0;\r\n // println!(\"{}\", ans2);\r\n}\r\n"}, {"source_code": "#[allow(unused_imports)]\r\nuse std::cmp::*;\r\n#[allow(unused_imports)]\r\nuse std::collections::*;\r\n#[allow(unused_imports)]\r\nuse std::io;\r\n#[allow(unused_imports)]\r\nuse std::iter::*;\r\n#[allow(unused_imports)]\r\nuse std::mem::*;\r\n#[allow(unused_imports)]\r\nuse std::str::*;\r\n#[allow(unused_imports)]\r\nuse std::usize;\r\n\r\n// vec with some initial value\r\n#[allow(unused_macros)]\r\nmacro_rules! vvec {\r\n ($($x:expr),+; $y:expr; $n:expr) => {{\r\n let mut v = vec![$y; $n];\r\n\r\n let mut it = v.iter_mut();\r\n $(\r\n *it.next().unwrap() = $x;\r\n )+\r\n\r\n v\r\n }}\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! it {\r\n ($x:expr) => {\r\n once($x)\r\n };\r\n ($first:expr,$($x:expr),+) => {\r\n chain(\r\n once($first),\r\n it!($($x),+)\r\n )\r\n }\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! pushed {\r\n ($c:expr, $x:expr) => {{\r\n let mut c = $c;\r\n c.push($x);\r\n c\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! inserted {\r\n ($c:expr, $($x:expr),*) => {{\r\n let mut c = $c;\r\n c.insert($($x),*);\r\n c\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_tuple {\r\n ($($t:ty),+) => {{\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n\r\n let mut it = line.trim()\r\n .split_whitespace();\r\n\r\n ($(\r\n it.next().unwrap().parse::<$t>().ok().unwrap()\r\n ),+)\r\n }}\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read() -> T {\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n line.trim().to_string().parse().ok().unwrap()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_str() -> Vec {\r\n read::().chars().collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_row() -> Vec {\r\n let mut line = String::new();\r\n io::stdin().read_line(&mut line).unwrap();\r\n\r\n line.trim()\r\n .split_whitespace()\r\n .map(|s| s.parse().ok().unwrap())\r\n .collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_col(n: usize) -> Vec {\r\n (0..n).map(|_| read()).collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_mat(n: usize) -> Vec> {\r\n (0..n).map(|_| read_row()).collect()\r\n}\r\n\r\n#[allow(dead_code)]\r\nfn read_vec R>(n: usize, mut f: F) -> Vec {\r\n (0..n).map(|_| f()).collect()\r\n}\r\n\r\ntrait IterCopyExt<'a, T>: IntoIterator + Sized\r\nwhere\r\n T: 'a + Copy,\r\n{\r\n fn citer(self) -> std::iter::Copied {\r\n self.into_iter().copied()\r\n }\r\n}\r\n\r\nimpl<'a, T, I> IterCopyExt<'a, T> for I\r\nwhere\r\n I: IntoIterator,\r\n T: 'a + Copy,\r\n{\r\n}\r\n\r\nfn main() {\r\n let n = read::()\r\n .chars()\r\n .map(|c| c.to_digit(10).unwrap() as usize)\r\n .collect::>();\r\n\r\n const B: usize = 500;\r\n\r\n let dp = n.citer().fold(\r\n vec![\r\n vec![vec![0usize; B]; B],\r\n vvec![vec![usize::MAX; B]; vec![1usize; B]; B],\r\n ],\r\n |prev, d| {\r\n // eprintln!(\"{:?}\", prev);\r\n (0..2)\r\n .map(|t| {\r\n let d = d + t;\r\n let mut dp = (0..B)\r\n .map(|i| {\r\n let mut v = vec![usize::MAX; B];\r\n\r\n if i >= d {\r\n v[i - d] = prev[0][i][i - d].saturating_add(i + (i - d));\r\n }\r\n\r\n if i + 10 >= d && i + 10 - d < B {\r\n v[i + 10 - d] =\r\n prev[1][i][i + 10 - d].saturating_add(i + (i + 10 - d))\r\n }\r\n\r\n v\r\n })\r\n .collect::>();\r\n for i in 0..B {\r\n for j in 0..B {\r\n if i > 0 {\r\n dp[i][j] = min(dp[i][j], dp[i - 1][j]);\r\n }\r\n if j > 0 {\r\n dp[i][j] = min(dp[i][j], dp[i][j - 1]);\r\n }\r\n }\r\n }\r\n dp\r\n })\r\n .collect::>()\r\n },\r\n );\r\n let ans = dp[0][B - 1][B - 1];\r\n println!(\"{}\", ans);\r\n}\r\n"}], "src_uid": "1961e7c9120ff652b15cad5dd5ca0907"} {"source_code": "type Res = u64;\nconst MAX_INP: Res = 1_000_000_000_000;\nconst STEP_SIZE: Res = 1000000000;\n\nfn main() {\n/*\n print!(\"let lookup = [\");\n let mut i = STEP_SIZE;\n let mut result = ('_', 1, 1);\n print!(\"(1,1),\");\n while i <= MAX_INP {\n result = solve_internal(i, result.1, result.2);\n print!(\"({},{}),\", result.1, result.2);\n i += STEP_SIZE;\n }\n println!(\"];\");\n*/\n\n\n let k = {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n input.trim().parse::().unwrap()\n };\n assert!((1 <= k) && (k <= MAX_INP), \"K out of input range. 1<= k <= 10^12\");\n let result = solve(k);\n println!(\"{}\", result);\n}\n\nfn int_len_(inp: Res) -> Res {\n if inp == 0 {\n return 1;\n }\n\n let mut res = 0;\n let mut temp = 1;\n while temp <= inp {\n res += 1;\n temp *= 10\n }\n res\n}\n\nfn int_len(inp: Res) -> Res {\n //debug_assert!(0 <= inp);\n //debug_assert!(inp <= MAX_INP);\n match inp {\n 1000000000000..=9999999999999 => 13,\n 100000000000..=999999999999 => 12,\n 10000000000..=99999999999 => 11,\n 1000000000..=9999999999 => 10,\n 100000000..=999999999 => 9,\n 10000000..=99999999 => 8,\n 1000000..=9999999 => 7,\n 100000..=999999 => 6,\n 10000..=99999 => 5,\n 1000..=9999 => 4,\n 100..=999 => 3,\n 10..=99 => 2,\n 0..=9 => 1,\n _ => unreachable!()\n }\n}\n\nfn solve(k: Res) -> char {\n let lookup = [(1,1),(1000000008,123456790),(2000000007,234567901),(3000000006,345679012),(4000000005,456790123),(5000000004,567901234),(6000000003,679012345),(7000000002,790123456),(8000000001,901234567),(9000000009,1011111111),(10000000009,1111111111),(11000000009,1211111111),(12000000009,1311111111),(13000000009,1411111111),(14000000009,1511111111),(15000000009,1611111111),(16000000009,1711111111),(17000000009,1811111111),(18000000009,1911111111),(19000000009,2011111111),(20000000009,2111111111),(21000000009,2211111111),(22000000009,2311111111),(23000000009,2411111111),(24000000009,2511111111),(25000000009,2611111111),(26000000009,2711111111),(27000000009,2811111111),(28000000009,2911111111),(29000000009,3011111111),(30000000009,3111111111),(31000000009,3211111111),(32000000009,3311111111),(33000000009,3411111111),(34000000009,3511111111),(35000000009,3611111111),(36000000009,3711111111),(37000000009,3811111111),(38000000009,3911111111),(39000000009,4011111111),(40000000009,4111111111),(41000000009,4211111111),(42000000009,4311111111),(43000000009,4411111111),(44000000009,4511111111),(45000000009,4611111111),(46000000009,4711111111),(47000000009,4811111111),(48000000009,4911111111),(49000000009,5011111111),(50000000009,5111111111),(51000000009,5211111111),(52000000009,5311111111),(53000000009,5411111111),(54000000009,5511111111),(55000000009,5611111111),(56000000009,5711111111),(57000000009,5811111111),(58000000009,5911111111),(59000000009,6011111111),(60000000009,6111111111),(61000000009,6211111111),(62000000009,6311111111),(63000000009,6411111111),(64000000009,6511111111),(65000000009,6611111111),(66000000009,6711111111),(67000000009,6811111111),(68000000009,6911111111),(69000000009,7011111111),(70000000009,7111111111),(71000000009,7211111111),(72000000009,7311111111),(73000000009,7411111111),(74000000009,7511111111),(75000000009,7611111111),(76000000009,7711111111),(77000000009,7811111111),(78000000009,7911111111),(79000000009,8011111111),(80000000009,8111111111),(81000000009,8211111111),(82000000009,8311111111),(83000000009,8411111111),(84000000009,8511111111),(85000000009,8611111111),(86000000009,8711111111),(87000000009,8811111111),(88000000009,8911111111),(89000000009,9011111111),(90000000009,9111111111),(91000000009,9211111111),(92000000009,9311111111),(93000000009,9411111111),(94000000009,9511111111),(95000000009,9611111111),(96000000009,9711111111),(97000000009,9811111111),(98000000009,9911111111),(99000000010,10010101010),(100000000000,10101010100),(101000000001,10191919191),(102000000002,10282828282),(103000000003,10373737373),(104000000004,10464646464),(105000000005,10555555555),(106000000006,10646464646),(107000000007,10737373737),(108000000008,10828282828),(109000000009,10919191919),(110000000010,11010101010),(111000000000,11101010100),(112000000001,11191919191),(113000000002,11282828282),(114000000003,11373737373),(115000000004,11464646464),(116000000005,11555555555),(117000000006,11646464646),(118000000007,11737373737),(119000000008,11828282828),(120000000009,11919191919),(121000000010,12010101010),(122000000000,12101010100),(123000000001,12191919191),(124000000002,12282828282),(125000000003,12373737373),(126000000004,12464646464),(127000000005,12555555555),(128000000006,12646464646),(129000000007,12737373737),(130000000008,12828282828),(131000000009,12919191919),(132000000010,13010101010),(133000000000,13101010100),(134000000001,13191919191),(135000000002,13282828282),(136000000003,13373737373),(137000000004,13464646464),(138000000005,13555555555),(139000000006,13646464646),(140000000007,13737373737),(141000000008,13828282828),(142000000009,13919191919),(143000000010,14010101010),(144000000000,14101010100),(145000000001,14191919191),(146000000002,14282828282),(147000000003,14373737373),(148000000004,14464646464),(149000000005,14555555555),(150000000006,14646464646),(151000000007,14737373737),(152000000008,14828282828),(153000000009,14919191919),(154000000010,15010101010),(155000000000,15101010100),(156000000001,15191919191),(157000000002,15282828282),(158000000003,15373737373),(159000000004,15464646464),(160000000005,15555555555),(161000000006,15646464646),(162000000007,15737373737),(163000000008,15828282828),(164000000009,15919191919),(165000000010,16010101010),(166000000000,16101010100),(167000000001,16191919191),(168000000002,16282828282),(169000000003,16373737373),(170000000004,16464646464),(171000000005,16555555555),(172000000006,16646464646),(173000000007,16737373737),(174000000008,16828282828),(175000000009,16919191919),(176000000010,17010101010),(177000000000,17101010100),(178000000001,17191919191),(179000000002,17282828282),(180000000003,17373737373),(181000000004,17464646464),(182000000005,17555555555),(183000000006,17646464646),(184000000007,17737373737),(185000000008,17828282828),(186000000009,17919191919),(187000000010,18010101010),(188000000000,18101010100),(189000000001,18191919191),(190000000002,18282828282),(191000000003,18373737373),(192000000004,18464646464),(193000000005,18555555555),(194000000006,18646464646),(195000000007,18737373737),(196000000008,18828282828),(197000000009,18919191919),(198000000010,19010101010),(199000000000,19101010100),(200000000001,19191919191),(201000000002,19282828282),(202000000003,19373737373),(203000000004,19464646464),(204000000005,19555555555),(205000000006,19646464646),(206000000007,19737373737),(207000000008,19828282828),(208000000009,19919191919),(209000000010,20010101010),(210000000000,20101010100),(211000000001,20191919191),(212000000002,20282828282),(213000000003,20373737373),(214000000004,20464646464),(215000000005,20555555555),(216000000006,20646464646),(217000000007,20737373737),(218000000008,20828282828),(219000000009,20919191919),(220000000010,21010101010),(221000000000,21101010100),(222000000001,21191919191),(223000000002,21282828282),(224000000003,21373737373),(225000000004,21464646464),(226000000005,21555555555),(227000000006,21646464646),(228000000007,21737373737),(229000000008,21828282828),(230000000009,21919191919),(231000000010,22010101010),(232000000000,22101010100),(233000000001,22191919191),(234000000002,22282828282),(235000000003,22373737373),(236000000004,22464646464),(237000000005,22555555555),(238000000006,22646464646),(239000000007,22737373737),(240000000008,22828282828),(241000000009,22919191919),(242000000010,23010101010),(243000000000,23101010100),(244000000001,23191919191),(245000000002,23282828282),(246000000003,23373737373),(247000000004,23464646464),(248000000005,23555555555),(249000000006,23646464646),(250000000007,23737373737),(251000000008,23828282828),(252000000009,23919191919),(253000000010,24010101010),(254000000000,24101010100),(255000000001,24191919191),(256000000002,24282828282),(257000000003,24373737373),(258000000004,24464646464),(259000000005,24555555555),(260000000006,24646464646),(261000000007,24737373737),(262000000008,24828282828),(263000000009,24919191919),(264000000010,25010101010),(265000000000,25101010100),(266000000001,25191919191),(267000000002,25282828282),(268000000003,25373737373),(269000000004,25464646464),(270000000005,25555555555),(271000000006,25646464646),(272000000007,25737373737),(273000000008,25828282828),(274000000009,25919191919),(275000000010,26010101010),(276000000000,26101010100),(277000000001,26191919191),(278000000002,26282828282),(279000000003,26373737373),(280000000004,26464646464),(281000000005,26555555555),(282000000006,26646464646),(283000000007,26737373737),(284000000008,26828282828),(285000000009,26919191919),(286000000010,27010101010),(287000000000,27101010100),(288000000001,27191919191),(289000000002,27282828282),(290000000003,27373737373),(291000000004,27464646464),(292000000005,27555555555),(293000000006,27646464646),(294000000007,27737373737),(295000000008,27828282828),(296000000009,27919191919),(297000000010,28010101010),(298000000000,28101010100),(299000000001,28191919191),(300000000002,28282828282),(301000000003,28373737373),(302000000004,28464646464),(303000000005,28555555555),(304000000006,28646464646),(305000000007,28737373737),(306000000008,28828282828),(307000000009,28919191919),(308000000010,29010101010),(309000000000,29101010100),(310000000001,29191919191),(311000000002,29282828282),(312000000003,29373737373),(313000000004,29464646464),(314000000005,29555555555),(315000000006,29646464646),(316000000007,29737373737),(317000000008,29828282828),(318000000009,29919191919),(319000000010,30010101010),(320000000000,30101010100),(321000000001,30191919191),(322000000002,30282828282),(323000000003,30373737373),(324000000004,30464646464),(325000000005,30555555555),(326000000006,30646464646),(327000000007,30737373737),(328000000008,30828282828),(329000000009,30919191919),(330000000010,31010101010),(331000000000,31101010100),(332000000001,31191919191),(333000000002,31282828282),(334000000003,31373737373),(335000000004,31464646464),(336000000005,31555555555),(337000000006,31646464646),(338000000007,31737373737),(339000000008,31828282828),(340000000009,31919191919),(341000000010,32010101010),(342000000000,32101010100),(343000000001,32191919191),(344000000002,32282828282),(345000000003,32373737373),(346000000004,32464646464),(347000000005,32555555555),(348000000006,32646464646),(349000000007,32737373737),(350000000008,32828282828),(351000000009,32919191919),(352000000010,33010101010),(353000000000,33101010100),(354000000001,33191919191),(355000000002,33282828282),(356000000003,33373737373),(357000000004,33464646464),(358000000005,33555555555),(359000000006,33646464646),(360000000007,33737373737),(361000000008,33828282828),(362000000009,33919191919),(363000000010,34010101010),(364000000000,34101010100),(365000000001,34191919191),(366000000002,34282828282),(367000000003,34373737373),(368000000004,34464646464),(369000000005,34555555555),(370000000006,34646464646),(371000000007,34737373737),(372000000008,34828282828),(373000000009,34919191919),(374000000010,35010101010),(375000000000,35101010100),(376000000001,35191919191),(377000000002,35282828282),(378000000003,35373737373),(379000000004,35464646464),(380000000005,35555555555),(381000000006,35646464646),(382000000007,35737373737),(383000000008,35828282828),(384000000009,35919191919),(385000000010,36010101010),(386000000000,36101010100),(387000000001,36191919191),(388000000002,36282828282),(389000000003,36373737373),(390000000004,36464646464),(391000000005,36555555555),(392000000006,36646464646),(393000000007,36737373737),(394000000008,36828282828),(395000000009,36919191919),(396000000010,37010101010),(397000000000,37101010100),(398000000001,37191919191),(399000000002,37282828282),(400000000003,37373737373),(401000000004,37464646464),(402000000005,37555555555),(403000000006,37646464646),(404000000007,37737373737),(405000000008,37828282828),(406000000009,37919191919),(407000000010,38010101010),(408000000000,38101010100),(409000000001,38191919191),(410000000002,38282828282),(411000000003,38373737373),(412000000004,38464646464),(413000000005,38555555555),(414000000006,38646464646),(415000000007,38737373737),(416000000008,38828282828),(417000000009,38919191919),(418000000010,39010101010),(419000000000,39101010100),(420000000001,39191919191),(421000000002,39282828282),(422000000003,39373737373),(423000000004,39464646464),(424000000005,39555555555),(425000000006,39646464646),(426000000007,39737373737),(427000000008,39828282828),(428000000009,39919191919),(429000000010,40010101010),(430000000000,40101010100),(431000000001,40191919191),(432000000002,40282828282),(433000000003,40373737373),(434000000004,40464646464),(435000000005,40555555555),(436000000006,40646464646),(437000000007,40737373737),(438000000008,40828282828),(439000000009,40919191919),(440000000010,41010101010),(441000000000,41101010100),(442000000001,41191919191),(443000000002,41282828282),(444000000003,41373737373),(445000000004,41464646464),(446000000005,41555555555),(447000000006,41646464646),(448000000007,41737373737),(449000000008,41828282828),(450000000009,41919191919),(451000000010,42010101010),(452000000000,42101010100),(453000000001,42191919191),(454000000002,42282828282),(455000000003,42373737373),(456000000004,42464646464),(457000000005,42555555555),(458000000006,42646464646),(459000000007,42737373737),(460000000008,42828282828),(461000000009,42919191919),(462000000010,43010101010),(463000000000,43101010100),(464000000001,43191919191),(465000000002,43282828282),(466000000003,43373737373),(467000000004,43464646464),(468000000005,43555555555),(469000000006,43646464646),(470000000007,43737373737),(471000000008,43828282828),(472000000009,43919191919),(473000000010,44010101010),(474000000000,44101010100),(475000000001,44191919191),(476000000002,44282828282),(477000000003,44373737373),(478000000004,44464646464),(479000000005,44555555555),(480000000006,44646464646),(481000000007,44737373737),(482000000008,44828282828),(483000000009,44919191919),(484000000010,45010101010),(485000000000,45101010100),(486000000001,45191919191),(487000000002,45282828282),(488000000003,45373737373),(489000000004,45464646464),(490000000005,45555555555),(491000000006,45646464646),(492000000007,45737373737),(493000000008,45828282828),(494000000009,45919191919),(495000000010,46010101010),(496000000000,46101010100),(497000000001,46191919191),(498000000002,46282828282),(499000000003,46373737373),(500000000004,46464646464),(501000000005,46555555555),(502000000006,46646464646),(503000000007,46737373737),(504000000008,46828282828),(505000000009,46919191919),(506000000010,47010101010),(507000000000,47101010100),(508000000001,47191919191),(509000000002,47282828282),(510000000003,47373737373),(511000000004,47464646464),(512000000005,47555555555),(513000000006,47646464646),(514000000007,47737373737),(515000000008,47828282828),(516000000009,47919191919),(517000000010,48010101010),(518000000000,48101010100),(519000000001,48191919191),(520000000002,48282828282),(521000000003,48373737373),(522000000004,48464646464),(523000000005,48555555555),(524000000006,48646464646),(525000000007,48737373737),(526000000008,48828282828),(527000000009,48919191919),(528000000010,49010101010),(529000000000,49101010100),(530000000001,49191919191),(531000000002,49282828282),(532000000003,49373737373),(533000000004,49464646464),(534000000005,49555555555),(535000000006,49646464646),(536000000007,49737373737),(537000000008,49828282828),(538000000009,49919191919),(539000000010,50010101010),(540000000000,50101010100),(541000000001,50191919191),(542000000002,50282828282),(543000000003,50373737373),(544000000004,50464646464),(545000000005,50555555555),(546000000006,50646464646),(547000000007,50737373737),(548000000008,50828282828),(549000000009,50919191919),(550000000010,51010101010),(551000000000,51101010100),(552000000001,51191919191),(553000000002,51282828282),(554000000003,51373737373),(555000000004,51464646464),(556000000005,51555555555),(557000000006,51646464646),(558000000007,51737373737),(559000000008,51828282828),(560000000009,51919191919),(561000000010,52010101010),(562000000000,52101010100),(563000000001,52191919191),(564000000002,52282828282),(565000000003,52373737373),(566000000004,52464646464),(567000000005,52555555555),(568000000006,52646464646),(569000000007,52737373737),(570000000008,52828282828),(571000000009,52919191919),(572000000010,53010101010),(573000000000,53101010100),(574000000001,53191919191),(575000000002,53282828282),(576000000003,53373737373),(577000000004,53464646464),(578000000005,53555555555),(579000000006,53646464646),(580000000007,53737373737),(581000000008,53828282828),(582000000009,53919191919),(583000000010,54010101010),(584000000000,54101010100),(585000000001,54191919191),(586000000002,54282828282),(587000000003,54373737373),(588000000004,54464646464),(589000000005,54555555555),(590000000006,54646464646),(591000000007,54737373737),(592000000008,54828282828),(593000000009,54919191919),(594000000010,55010101010),(595000000000,55101010100),(596000000001,55191919191),(597000000002,55282828282),(598000000003,55373737373),(599000000004,55464646464),(600000000005,55555555555),(601000000006,55646464646),(602000000007,55737373737),(603000000008,55828282828),(604000000009,55919191919),(605000000010,56010101010),(606000000000,56101010100),(607000000001,56191919191),(608000000002,56282828282),(609000000003,56373737373),(610000000004,56464646464),(611000000005,56555555555),(612000000006,56646464646),(613000000007,56737373737),(614000000008,56828282828),(615000000009,56919191919),(616000000010,57010101010),(617000000000,57101010100),(618000000001,57191919191),(619000000002,57282828282),(620000000003,57373737373),(621000000004,57464646464),(622000000005,57555555555),(623000000006,57646464646),(624000000007,57737373737),(625000000008,57828282828),(626000000009,57919191919),(627000000010,58010101010),(628000000000,58101010100),(629000000001,58191919191),(630000000002,58282828282),(631000000003,58373737373),(632000000004,58464646464),(633000000005,58555555555),(634000000006,58646464646),(635000000007,58737373737),(636000000008,58828282828),(637000000009,58919191919),(638000000010,59010101010),(639000000000,59101010100),(640000000001,59191919191),(641000000002,59282828282),(642000000003,59373737373),(643000000004,59464646464),(644000000005,59555555555),(645000000006,59646464646),(646000000007,59737373737),(647000000008,59828282828),(648000000009,59919191919),(649000000010,60010101010),(650000000000,60101010100),(651000000001,60191919191),(652000000002,60282828282),(653000000003,60373737373),(654000000004,60464646464),(655000000005,60555555555),(656000000006,60646464646),(657000000007,60737373737),(658000000008,60828282828),(659000000009,60919191919),(660000000010,61010101010),(661000000000,61101010100),(662000000001,61191919191),(663000000002,61282828282),(664000000003,61373737373),(665000000004,61464646464),(666000000005,61555555555),(667000000006,61646464646),(668000000007,61737373737),(669000000008,61828282828),(670000000009,61919191919),(671000000010,62010101010),(672000000000,62101010100),(673000000001,62191919191),(674000000002,62282828282),(675000000003,62373737373),(676000000004,62464646464),(677000000005,62555555555),(678000000006,62646464646),(679000000007,62737373737),(680000000008,62828282828),(681000000009,62919191919),(682000000010,63010101010),(683000000000,63101010100),(684000000001,63191919191),(685000000002,63282828282),(686000000003,63373737373),(687000000004,63464646464),(688000000005,63555555555),(689000000006,63646464646),(690000000007,63737373737),(691000000008,63828282828),(692000000009,63919191919),(693000000010,64010101010),(694000000000,64101010100),(695000000001,64191919191),(696000000002,64282828282),(697000000003,64373737373),(698000000004,64464646464),(699000000005,64555555555),(700000000006,64646464646),(701000000007,64737373737),(702000000008,64828282828),(703000000009,64919191919),(704000000010,65010101010),(705000000000,65101010100),(706000000001,65191919191),(707000000002,65282828282),(708000000003,65373737373),(709000000004,65464646464),(710000000005,65555555555),(711000000006,65646464646),(712000000007,65737373737),(713000000008,65828282828),(714000000009,65919191919),(715000000010,66010101010),(716000000000,66101010100),(717000000001,66191919191),(718000000002,66282828282),(719000000003,66373737373),(720000000004,66464646464),(721000000005,66555555555),(722000000006,66646464646),(723000000007,66737373737),(724000000008,66828282828),(725000000009,66919191919),(726000000010,67010101010),(727000000000,67101010100),(728000000001,67191919191),(729000000002,67282828282),(730000000003,67373737373),(731000000004,67464646464),(732000000005,67555555555),(733000000006,67646464646),(734000000007,67737373737),(735000000008,67828282828),(736000000009,67919191919),(737000000010,68010101010),(738000000000,68101010100),(739000000001,68191919191),(740000000002,68282828282),(741000000003,68373737373),(742000000004,68464646464),(743000000005,68555555555),(744000000006,68646464646),(745000000007,68737373737),(746000000008,68828282828),(747000000009,68919191919),(748000000010,69010101010),(749000000000,69101010100),(750000000001,69191919191),(751000000002,69282828282),(752000000003,69373737373),(753000000004,69464646464),(754000000005,69555555555),(755000000006,69646464646),(756000000007,69737373737),(757000000008,69828282828),(758000000009,69919191919),(759000000010,70010101010),(760000000000,70101010100),(761000000001,70191919191),(762000000002,70282828282),(763000000003,70373737373),(764000000004,70464646464),(765000000005,70555555555),(766000000006,70646464646),(767000000007,70737373737),(768000000008,70828282828),(769000000009,70919191919),(770000000010,71010101010),(771000000000,71101010100),(772000000001,71191919191),(773000000002,71282828282),(774000000003,71373737373),(775000000004,71464646464),(776000000005,71555555555),(777000000006,71646464646),(778000000007,71737373737),(779000000008,71828282828),(780000000009,71919191919),(781000000010,72010101010),(782000000000,72101010100),(783000000001,72191919191),(784000000002,72282828282),(785000000003,72373737373),(786000000004,72464646464),(787000000005,72555555555),(788000000006,72646464646),(789000000007,72737373737),(790000000008,72828282828),(791000000009,72919191919),(792000000010,73010101010),(793000000000,73101010100),(794000000001,73191919191),(795000000002,73282828282),(796000000003,73373737373),(797000000004,73464646464),(798000000005,73555555555),(799000000006,73646464646),(800000000007,73737373737),(801000000008,73828282828),(802000000009,73919191919),(803000000010,74010101010),(804000000000,74101010100),(805000000001,74191919191),(806000000002,74282828282),(807000000003,74373737373),(808000000004,74464646464),(809000000005,74555555555),(810000000006,74646464646),(811000000007,74737373737),(812000000008,74828282828),(813000000009,74919191919),(814000000010,75010101010),(815000000000,75101010100),(816000000001,75191919191),(817000000002,75282828282),(818000000003,75373737373),(819000000004,75464646464),(820000000005,75555555555),(821000000006,75646464646),(822000000007,75737373737),(823000000008,75828282828),(824000000009,75919191919),(825000000010,76010101010),(826000000000,76101010100),(827000000001,76191919191),(828000000002,76282828282),(829000000003,76373737373),(830000000004,76464646464),(831000000005,76555555555),(832000000006,76646464646),(833000000007,76737373737),(834000000008,76828282828),(835000000009,76919191919),(836000000010,77010101010),(837000000000,77101010100),(838000000001,77191919191),(839000000002,77282828282),(840000000003,77373737373),(841000000004,77464646464),(842000000005,77555555555),(843000000006,77646464646),(844000000007,77737373737),(845000000008,77828282828),(846000000009,77919191919),(847000000010,78010101010),(848000000000,78101010100),(849000000001,78191919191),(850000000002,78282828282),(851000000003,78373737373),(852000000004,78464646464),(853000000005,78555555555),(854000000006,78646464646),(855000000007,78737373737),(856000000008,78828282828),(857000000009,78919191919),(858000000010,79010101010),(859000000000,79101010100),(860000000001,79191919191),(861000000002,79282828282),(862000000003,79373737373),(863000000004,79464646464),(864000000005,79555555555),(865000000006,79646464646),(866000000007,79737373737),(867000000008,79828282828),(868000000009,79919191919),(869000000010,80010101010),(870000000000,80101010100),(871000000001,80191919191),(872000000002,80282828282),(873000000003,80373737373),(874000000004,80464646464),(875000000005,80555555555),(876000000006,80646464646),(877000000007,80737373737),(878000000008,80828282828),(879000000009,80919191919),(880000000010,81010101010),(881000000000,81101010100),(882000000001,81191919191),(883000000002,81282828282),(884000000003,81373737373),(885000000004,81464646464),(886000000005,81555555555),(887000000006,81646464646),(888000000007,81737373737),(889000000008,81828282828),(890000000009,81919191919),(891000000010,82010101010),(892000000000,82101010100),(893000000001,82191919191),(894000000002,82282828282),(895000000003,82373737373),(896000000004,82464646464),(897000000005,82555555555),(898000000006,82646464646),(899000000007,82737373737),(900000000008,82828282828),(901000000009,82919191919),(902000000010,83010101010),(903000000000,83101010100),(904000000001,83191919191),(905000000002,83282828282),(906000000003,83373737373),(907000000004,83464646464),(908000000005,83555555555),(909000000006,83646464646),(910000000007,83737373737),(911000000008,83828282828),(912000000009,83919191919),(913000000010,84010101010),(914000000000,84101010100),(915000000001,84191919191),(916000000002,84282828282),(917000000003,84373737373),(918000000004,84464646464),(919000000005,84555555555),(920000000006,84646464646),(921000000007,84737373737),(922000000008,84828282828),(923000000009,84919191919),(924000000010,85010101010),(925000000000,85101010100),(926000000001,85191919191),(927000000002,85282828282),(928000000003,85373737373),(929000000004,85464646464),(930000000005,85555555555),(931000000006,85646464646),(932000000007,85737373737),(933000000008,85828282828),(934000000009,85919191919),(935000000010,86010101010),(936000000000,86101010100),(937000000001,86191919191),(938000000002,86282828282),(939000000003,86373737373),(940000000004,86464646464),(941000000005,86555555555),(942000000006,86646464646),(943000000007,86737373737),(944000000008,86828282828),(945000000009,86919191919),(946000000010,87010101010),(947000000000,87101010100),(948000000001,87191919191),(949000000002,87282828282),(950000000003,87373737373),(951000000004,87464646464),(952000000005,87555555555),(953000000006,87646464646),(954000000007,87737373737),(955000000008,87828282828),(956000000009,87919191919),(957000000010,88010101010),(958000000000,88101010100),(959000000001,88191919191),(960000000002,88282828282),(961000000003,88373737373),(962000000004,88464646464),(963000000005,88555555555),(964000000006,88646464646),(965000000007,88737373737),(966000000008,88828282828),(967000000009,88919191919),(968000000010,89010101010),(969000000000,89101010100),(970000000001,89191919191),(971000000002,89282828282),(972000000003,89373737373),(973000000004,89464646464),(974000000005,89555555555),(975000000006,89646464646),(976000000007,89737373737),(977000000008,89828282828),(978000000009,89919191919),(979000000010,90010101010),(980000000000,90101010100),(981000000001,90191919191),(982000000002,90282828282),(983000000003,90373737373),(984000000004,90464646464),(985000000005,90555555555),(986000000006,90646464646),(987000000007,90737373737),(988000000008,90828282828),(989000000009,90919191919),(990000000010,91010101010),(991000000000,91101010100),(992000000001,91191919191),(993000000002,91282828282),(994000000003,91373737373),(995000000004,91464646464),(996000000005,91555555555),(997000000006,91646464646),(998000000007,91737373737),(999000000008,91828282828),(1000000000009,91919191919),];\n\n let idx = k / STEP_SIZE;\n let starts = lookup[idx as usize];\n let result = solve_internal(k, starts.0, starts.1);\n result.0\n}\n\nfn solve_internal(k: Res, n: Res, d: Res) -> (char, Res, Res) {\n // counter for digits\n let mut n: Res = n;//1;\n // Potential number of the digit we search\n let mut d: Res = d;//1;\n while n u64 {\n let mut num_digits = 1;\n\n while k > digit_length(num_digits) {\n k -= digit_length(num_digits);\n num_digits += 1;\n }\n\n\n let a = if k % num_digits == 0 {\n (k / num_digits) - 1\n } else {\n (k / num_digits)\n };\n\n k -= a * num_digits;\n\n nth_digit(a + int_pow(10, num_digits - 1), num_digits, k)\n}\n\nfn nth_digit(num: u64, digits: u64, n: u64) -> u64{\n let a = int_pow(10, digits - n);\n\n (num / a) % 10\n}\n\nfn digit_length(digit: u64) -> u64 {\n digit * 9 * int_pow(10, digit-1)\n}\n\nfn int_pow(a: u64, b: u64) -> u64 {\n let mut rv = 1;\n\n for _ in 0..b {\n rv *= a;\n }\n\n rv\n}\n"}, {"source_code": "use std::error::Error;\nuse std::io::stdin;\n\n\nstruct Digits {\n number: u64,\n divisor: u64,\n}\n\nimpl Digits {\n fn new(number: u64) -> Self {\n let mut divisor = 1;\n while number >= divisor * 10 {\n divisor *= 10;\n }\n\n Digits {\n number,\n divisor,\n }\n }\n\n fn reset(&mut self, number: u64){\n let mut divisor = 1;\n while number >= divisor * 10 {\n divisor *= 10;\n }\n self.divisor = divisor;\n self.number = number;\n\n }\n}\n\nimpl Iterator for Digits {\n type Item = u64;\n\n fn next(&mut self) -> Option {\n if self.divisor == 0 {\n None\n } else {\n let v = Some(self.number / self.divisor);\n self.number %= self.divisor;\n self.divisor /= 10;\n v\n }\n\n }\n}\n\nstruct InfinityCounter{\n num: Digits,\n current: u64,\n}\nimpl InfinityCounter{\n pub fn new() -> Self{\n Self{\n current: 0,\n num: Digits::new(1),\n }\n }\n}\n\n\nimpl Iterator for InfinityCounter{\n type Item = u64;\n\n fn next(&mut self) -> Option {\n let next = self.num.next();\n if next.is_none() {\n self.current += 1;\n self.num.reset(self.current);\n return self.num.next();\n }\n next\n }\n}\n\nfn main() -> Result<(), Box> {\n let mut input = String::new();\n stdin().read_line(&mut input)?;\n let number: usize = input.trim().parse()?;\n let mut counter = InfinityCounter::new();\n if let Some(x) = counter.nth(number){\n println!(\"{}\", x);\n }\n Ok(())\n}\n"}, {"source_code": "const SEQ: &str = \"01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277\";\n\nfn user_input(mut r: R) -> usize {\n let mut input = String::new();\n r.read_to_string(&mut input).unwrap();\n input.split_whitespace().nth(0).unwrap().parse::().unwrap()\n}\n\nfn main() {\n let idx = user_input(std::io::stdin());\n println!(\"{}\", SEQ.chars().nth(idx).unwrap());\n}"}, {"source_code": "pub fn get_digits_len(mut k: usize) -> usize {\n let mut n: usize = 1;\n \n loop {\n k /= 10;\n\n if k > 0 {\n n+=1;\n }else{\n break n;\n }\n }\n}\n\npub fn get_nth_right_digit(n: usize, k: usize) -> usize {\n \n (k/usize::pow(10, n as u32)) % 10\n}\n\npub fn get_kth(mut k: usize) -> usize {\n let mut x: usize = 1;\n\n 'outer: loop {\n let n = get_digits_len(x);\n\n if n > k {\n break get_nth_right_digit(n-k, x);\n } else if (k - n) == 0 {\n break get_nth_right_digit(0, x);\n } else {\n k -= n;\n }\n\n x += 1;\n }\n}\n\nuse std::{io, io::BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let locked_stdin = stdin.lock();\n println!(\"{}\", locked_stdin.lines().take(1).map(|l| str::parse::(&l.unwrap()).unwrap()).map(|k| get_kth(k)).last().unwrap())\n}"}, {"source_code": "use std::io::{self, BufRead};\n\nfn it() -> impl Iterator {\n (0..).flat_map(|i| i.to_string().chars().collect::>())\n}\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock().lines().next().expect(\"input\").expect(\"UTF-8\");\n let index: usize = line.parse().expect(\"Numeric value\");\n\n println!(\"{}\", it().skip(index).next().unwrap());\n}\n\n#[test]\nfn vectors() {\n let in_out = [(7, '7'), (21, '5')];\n\n for (i, o) in &in_out {\n assert_eq!(it().skip(*i).next().unwrap(), *o);\n }\n}\n"}, {"source_code": "fn main() {\n /*\n let mut seq = String::with_capacity(10050);\n let mut stat: u32 = 0;\n while seq.len() < 10000 {\n stat += 1;\n seq.push_str(&format!(\"{}\", stat));\n }\n print!(\"let seq = [\");\n for c in seq.chars() {\n print!(\"{},\",c);\n }\n println!(\"];\");\n */\n let seq = [1,2,3,4,5,6,7,8,9,1,0,1,1,1,2,1,3,1,4,1,5,1,6,1,7,1,8,1,9,2,0,2,1,2,2,2,3,2,4,2,5,2,6,2,7,2,8,2,9,3,0,3,1,3,2,3,3,3,4,3,5,3,6,3,7,3,8,3,9,4,0,4,1,4,2,4,3,4,4,4,5,4,6,4,7,4,8,4,9,5,0,5,1,5,2,5,3,5,4,5,5,5,6,5,7,5,8,5,9,6,0,6,1,6,2,6,3,6,4,6,5,6,6,6,7,6,8,6,9,7,0,7,1,7,2,7,3,7,4,7,5,7,6,7,7,7,8,7,9,8,0,8,1,8,2,8,3,8,4,8,5,8,6,8,7,8,8,8,9,9,0,9,1,9,2,9,3,9,4,9,5,9,6,9,7,9,8,9,9,1,0,0,1,0,1,1,0,2,1,0,3,1,0,4,1,0,5,1,0,6,1,0,7,1,0,8,1,0,9,1,1,0,1,1,1,1,1,2,1,1,3,1,1,4,1,1,5,1,1,6,1,1,7,1,1,8,1,1,9,1,2,0,1,2,1,1,2,2,1,2,3,1,2,4,1,2,5,1,2,6,1,2,7,1,2,8,1,2,9,1,3,0,1,3,1,1,3,2,1,3,3,1,3,4,1,3,5,1,3,6,1,3,7,1,3,8,1,3,9,1,4,0,1,4,1,1,4,2,1,4,3,1,4,4,1,4,5,1,4,6,1,4,7,1,4,8,1,4,9,1,5,0,1,5,1,1,5,2,1,5,3,1,5,4,1,5,5,1,5,6,1,5,7,1,5,8,1,5,9,1,6,0,1,6,1,1,6,2,1,6,3,1,6,4,1,6,5,1,6,6,1,6,7,1,6,8,1,6,9,1,7,0,1,7,1,1,7,2,1,7,3,1,7,4,1,7,5,1,7,6,1,7,7,1,7,8,1,7,9,1,8,0,1,8,1,1,8,2,1,8,3,1,8,4,1,8,5,1,8,6,1,8,7,1,8,8,1,8,9,1,9,0,1,9,1,1,9,2,1,9,3,1,9,4,1,9,5,1,9,6,1,9,7,1,9,8,1,9,9,2,0,0,2,0,1,2,0,2,2,0,3,2,0,4,2,0,5,2,0,6,2,0,7,2,0,8,2,0,9,2,1,0,2,1,1,2,1,2,2,1,3,2,1,4,2,1,5,2,1,6,2,1,7,2,1,8,2,1,9,2,2,0,2,2,1,2,2,2,2,2,3,2,2,4,2,2,5,2,2,6,2,2,7,2,2,8,2,2,9,2,3,0,2,3,1,2,3,2,2,3,3,2,3,4,2,3,5,2,3,6,2,3,7,2,3,8,2,3,9,2,4,0,2,4,1,2,4,2,2,4,3,2,4,4,2,4,5,2,4,6,2,4,7,2,4,8,2,4,9,2,5,0,2,5,1,2,5,2,2,5,3,2,5,4,2,5,5,2,5,6,2,5,7,2,5,8,2,5,9,2,6,0,2,6,1,2,6,2,2,6,3,2,6,4,2,6,5,2,6,6,2,6,7,2,6,8,2,6,9,2,7,0,2,7,1,2,7,2,2,7,3,2,7,4,2,7,5,2,7,6,2,7,7,2,7,8,2,7,9,2,8,0,2,8,1,2,8,2,2,8,3,2,8,4,2,8,5,2,8,6,2,8,7,2,8,8,2,8,9,2,9,0,2,9,1,2,9,2,2,9,3,2,9,4,2,9,5,2,9,6,2,9,7,2,9,8,2,9,9,3,0,0,3,0,1,3,0,2,3,0,3,3,0,4,3,0,5,3,0,6,3,0,7,3,0,8,3,0,9,3,1,0,3,1,1,3,1,2,3,1,3,3,1,4,3,1,5,3,1,6,3,1,7,3,1,8,3,1,9,3,2,0,3,2,1,3,2,2,3,2,3,3,2,4,3,2,5,3,2,6,3,2,7,3,2,8,3,2,9,3,3,0,3,3,1,3,3,2,3,3,3,3,3,4,3,3,5,3,3,6,3,3,7,3,3,8,3,3,9,3,4,0,3,4,1,3,4,2,3,4,3,3,4,4,3,4,5,3,4,6,3,4,7,3,4,8,3,4,9,3,5,0,3,5,1,3,5,2,3,5,3,3,5,4,3,5,5,3,5,6,3,5,7,3,5,8,3,5,9,3,6,0,3,6,1,3,6,2,3,6,3,3,6,4,3,6,5,3,6,6,3,6,7,3,6,8,3,6,9,3,7,0,3,7,1,3,7,2,3,7,3,3,7,4,3,7,5,3,7,6,3,7,7,3,7,8,3,7,9,3,8,0,3,8,1,3,8,2,3,8,3,3,8,4,3,8,5,3,8,6,3,8,7,3,8,8,3,8,9,3,9,0,3,9,1,3,9,2,3,9,3,3,9,4,3,9,5,3,9,6,3,9,7,3,9,8,3,9,9,4,0,0,4,0,1,4,0,2,4,0,3,4,0,4,4,0,5,4,0,6,4,0,7,4,0,8,4,0,9,4,1,0,4,1,1,4,1,2,4,1,3,4,1,4,4,1,5,4,1,6,4,1,7,4,1,8,4,1,9,4,2,0,4,2,1,4,2,2,4,2,3,4,2,4,4,2,5,4,2,6,4,2,7,4,2,8,4,2,9,4,3,0,4,3,1,4,3,2,4,3,3,4,3,4,4,3,5,4,3,6,4,3,7,4,3,8,4,3,9,4,4,0,4,4,1,4,4,2,4,4,3,4,4,4,4,4,5,4,4,6,4,4,7,4,4,8,4,4,9,4,5,0,4,5,1,4,5,2,4,5,3,4,5,4,4,5,5,4,5,6,4,5,7,4,5,8,4,5,9,4,6,0,4,6,1,4,6,2,4,6,3,4,6,4,4,6,5,4,6,6,4,6,7,4,6,8,4,6,9,4,7,0,4,7,1,4,7,2,4,7,3,4,7,4,4,7,5,4,7,6,4,7,7,4,7,8,4,7,9,4,8,0,4,8,1,4,8,2,4,8,3,4,8,4,4,8,5,4,8,6,4,8,7,4,8,8,4,8,9,4,9,0,4,9,1,4,9,2,4,9,3,4,9,4,4,9,5,4,9,6,4,9,7,4,9,8,4,9,9,5,0,0,5,0,1,5,0,2,5,0,3,5,0,4,5,0,5,5,0,6,5,0,7,5,0,8,5,0,9,5,1,0,5,1,1,5,1,2,5,1,3,5,1,4,5,1,5,5,1,6,5,1,7,5,1,8,5,1,9,5,2,0,5,2,1,5,2,2,5,2,3,5,2,4,5,2,5,5,2,6,5,2,7,5,2,8,5,2,9,5,3,0,5,3,1,5,3,2,5,3,3,5,3,4,5,3,5,5,3,6,5,3,7,5,3,8,5,3,9,5,4,0,5,4,1,5,4,2,5,4,3,5,4,4,5,4,5,5,4,6,5,4,7,5,4,8,5,4,9,5,5,0,5,5,1,5,5,2,5,5,3,5,5,4,5,5,5,5,5,6,5,5,7,5,5,8,5,5,9,5,6,0,5,6,1,5,6,2,5,6,3,5,6,4,5,6,5,5,6,6,5,6,7,5,6,8,5,6,9,5,7,0,5,7,1,5,7,2,5,7,3,5,7,4,5,7,5,5,7,6,5,7,7,5,7,8,5,7,9,5,8,0,5,8,1,5,8,2,5,8,3,5,8,4,5,8,5,5,8,6,5,8,7,5,8,8,5,8,9,5,9,0,5,9,1,5,9,2,5,9,3,5,9,4,5,9,5,5,9,6,5,9,7,5,9,8,5,9,9,6,0,0,6,0,1,6,0,2,6,0,3,6,0,4,6,0,5,6,0,6,6,0,7,6,0,8,6,0,9,6,1,0,6,1,1,6,1,2,6,1,3,6,1,4,6,1,5,6,1,6,6,1,7,6,1,8,6,1,9,6,2,0,6,2,1,6,2,2,6,2,3,6,2,4,6,2,5,6,2,6,6,2,7,6,2,8,6,2,9,6,3,0,6,3,1,6,3,2,6,3,3,6,3,4,6,3,5,6,3,6,6,3,7,6,3,8,6,3,9,6,4,0,6,4,1,6,4,2,6,4,3,6,4,4,6,4,5,6,4,6,6,4,7,6,4,8,6,4,9,6,5,0,6,5,1,6,5,2,6,5,3,6,5,4,6,5,5,6,5,6,6,5,7,6,5,8,6,5,9,6,6,0,6,6,1,6,6,2,6,6,3,6,6,4,6,6,5,6,6,6,6,6,7,6,6,8,6,6,9,6,7,0,6,7,1,6,7,2,6,7,3,6,7,4,6,7,5,6,7,6,6,7,7,6,7,8,6,7,9,6,8,0,6,8,1,6,8,2,6,8,3,6,8,4,6,8,5,6,8,6,6,8,7,6,8,8,6,8,9,6,9,0,6,9,1,6,9,2,6,9,3,6,9,4,6,9,5,6,9,6,6,9,7,6,9,8,6,9,9,7,0,0,7,0,1,7,0,2,7,0,3,7,0,4,7,0,5,7,0,6,7,0,7,7,0,8,7,0,9,7,1,0,7,1,1,7,1,2,7,1,3,7,1,4,7,1,5,7,1,6,7,1,7,7,1,8,7,1,9,7,2,0,7,2,1,7,2,2,7,2,3,7,2,4,7,2,5,7,2,6,7,2,7,7,2,8,7,2,9,7,3,0,7,3,1,7,3,2,7,3,3,7,3,4,7,3,5,7,3,6,7,3,7,7,3,8,7,3,9,7,4,0,7,4,1,7,4,2,7,4,3,7,4,4,7,4,5,7,4,6,7,4,7,7,4,8,7,4,9,7,5,0,7,5,1,7,5,2,7,5,3,7,5,4,7,5,5,7,5,6,7,5,7,7,5,8,7,5,9,7,6,0,7,6,1,7,6,2,7,6,3,7,6,4,7,6,5,7,6,6,7,6,7,7,6,8,7,6,9,7,7,0,7,7,1,7,7,2,7,7,3,7,7,4,7,7,5,7,7,6,7,7,7,7,7,8,7,7,9,7,8,0,7,8,1,7,8,2,7,8,3,7,8,4,7,8,5,7,8,6,7,8,7,7,8,8,7,8,9,7,9,0,7,9,1,7,9,2,7,9,3,7,9,4,7,9,5,7,9,6,7,9,7,7,9,8,7,9,9,8,0,0,8,0,1,8,0,2,8,0,3,8,0,4,8,0,5,8,0,6,8,0,7,8,0,8,8,0,9,8,1,0,8,1,1,8,1,2,8,1,3,8,1,4,8,1,5,8,1,6,8,1,7,8,1,8,8,1,9,8,2,0,8,2,1,8,2,2,8,2,3,8,2,4,8,2,5,8,2,6,8,2,7,8,2,8,8,2,9,8,3,0,8,3,1,8,3,2,8,3,3,8,3,4,8,3,5,8,3,6,8,3,7,8,3,8,8,3,9,8,4,0,8,4,1,8,4,2,8,4,3,8,4,4,8,4,5,8,4,6,8,4,7,8,4,8,8,4,9,8,5,0,8,5,1,8,5,2,8,5,3,8,5,4,8,5,5,8,5,6,8,5,7,8,5,8,8,5,9,8,6,0,8,6,1,8,6,2,8,6,3,8,6,4,8,6,5,8,6,6,8,6,7,8,6,8,8,6,9,8,7,0,8,7,1,8,7,2,8,7,3,8,7,4,8,7,5,8,7,6,8,7,7,8,7,8,8,7,9,8,8,0,8,8,1,8,8,2,8,8,3,8,8,4,8,8,5,8,8,6,8,8,7,8,8,8,8,8,9,8,9,0,8,9,1,8,9,2,8,9,3,8,9,4,8,9,5,8,9,6,8,9,7,8,9,8,8,9,9,9,0,0,9,0,1,9,0,2,9,0,3,9,0,4,9,0,5,9,0,6,9,0,7,9,0,8,9,0,9,9,1,0,9,1,1,9,1,2,9,1,3,9,1,4,9,1,5,9,1,6,9,1,7,9,1,8,9,1,9,9,2,0,9,2,1,9,2,2,9,2,3,9,2,4,9,2,5,9,2,6,9,2,7,9,2,8,9,2,9,9,3,0,9,3,1,9,3,2,9,3,3,9,3,4,9,3,5,9,3,6,9,3,7,9,3,8,9,3,9,9,4,0,9,4,1,9,4,2,9,4,3,9,4,4,9,4,5,9,4,6,9,4,7,9,4,8,9,4,9,9,5,0,9,5,1,9,5,2,9,5,3,9,5,4,9,5,5,9,5,6,9,5,7,9,5,8,9,5,9,9,6,0,9,6,1,9,6,2,9,6,3,9,6,4,9,6,5,9,6,6,9,6,7,9,6,8,9,6,9,9,7,0,9,7,1,9,7,2,9,7,3,9,7,4,9,7,5,9,7,6,9,7,7,9,7,8,9,7,9,9,8,0,9,8,1,9,8,2,9,8,3,9,8,4,9,8,5,9,8,6,9,8,7,9,8,8,9,8,9,9,9,0,9,9,1,9,9,2,9,9,3,9,9,4,9,9,5,9,9,6,9,9,7,9,9,8,9,9,9,1,0,0,0,1,0,0,1,1,0,0,2,1,0,0,3,1,0,0,4,1,0,0,5,1,0,0,6,1,0,0,7,1,0,0,8,1,0,0,9,1,0,1,0,1,0,1,1,1,0,1,2,1,0,1,3,1,0,1,4,1,0,1,5,1,0,1,6,1,0,1,7,1,0,1,8,1,0,1,9,1,0,2,0,1,0,2,1,1,0,2,2,1,0,2,3,1,0,2,4,1,0,2,5,1,0,2,6,1,0,2,7,1,0,2,8,1,0,2,9,1,0,3,0,1,0,3,1,1,0,3,2,1,0,3,3,1,0,3,4,1,0,3,5,1,0,3,6,1,0,3,7,1,0,3,8,1,0,3,9,1,0,4,0,1,0,4,1,1,0,4,2,1,0,4,3,1,0,4,4,1,0,4,5,1,0,4,6,1,0,4,7,1,0,4,8,1,0,4,9,1,0,5,0,1,0,5,1,1,0,5,2,1,0,5,3,1,0,5,4,1,0,5,5,1,0,5,6,1,0,5,7,1,0,5,8,1,0,5,9,1,0,6,0,1,0,6,1,1,0,6,2,1,0,6,3,1,0,6,4,1,0,6,5,1,0,6,6,1,0,6,7,1,0,6,8,1,0,6,9,1,0,7,0,1,0,7,1,1,0,7,2,1,0,7,3,1,0,7,4,1,0,7,5,1,0,7,6,1,0,7,7,1,0,7,8,1,0,7,9,1,0,8,0,1,0,8,1,1,0,8,2,1,0,8,3,1,0,8,4,1,0,8,5,1,0,8,6,1,0,8,7,1,0,8,8,1,0,8,9,1,0,9,0,1,0,9,1,1,0,9,2,1,0,9,3,1,0,9,4,1,0,9,5,1,0,9,6,1,0,9,7,1,0,9,8,1,0,9,9,1,1,0,0,1,1,0,1,1,1,0,2,1,1,0,3,1,1,0,4,1,1,0,5,1,1,0,6,1,1,0,7,1,1,0,8,1,1,0,9,1,1,1,0,1,1,1,1,1,1,1,2,1,1,1,3,1,1,1,4,1,1,1,5,1,1,1,6,1,1,1,7,1,1,1,8,1,1,1,9,1,1,2,0,1,1,2,1,1,1,2,2,1,1,2,3,1,1,2,4,1,1,2,5,1,1,2,6,1,1,2,7,1,1,2,8,1,1,2,9,1,1,3,0,1,1,3,1,1,1,3,2,1,1,3,3,1,1,3,4,1,1,3,5,1,1,3,6,1,1,3,7,1,1,3,8,1,1,3,9,1,1,4,0,1,1,4,1,1,1,4,2,1,1,4,3,1,1,4,4,1,1,4,5,1,1,4,6,1,1,4,7,1,1,4,8,1,1,4,9,1,1,5,0,1,1,5,1,1,1,5,2,1,1,5,3,1,1,5,4,1,1,5,5,1,1,5,6,1,1,5,7,1,1,5,8,1,1,5,9,1,1,6,0,1,1,6,1,1,1,6,2,1,1,6,3,1,1,6,4,1,1,6,5,1,1,6,6,1,1,6,7,1,1,6,8,1,1,6,9,1,1,7,0,1,1,7,1,1,1,7,2,1,1,7,3,1,1,7,4,1,1,7,5,1,1,7,6,1,1,7,7,1,1,7,8,1,1,7,9,1,1,8,0,1,1,8,1,1,1,8,2,1,1,8,3,1,1,8,4,1,1,8,5,1,1,8,6,1,1,8,7,1,1,8,8,1,1,8,9,1,1,9,0,1,1,9,1,1,1,9,2,1,1,9,3,1,1,9,4,1,1,9,5,1,1,9,6,1,1,9,7,1,1,9,8,1,1,9,9,1,2,0,0,1,2,0,1,1,2,0,2,1,2,0,3,1,2,0,4,1,2,0,5,1,2,0,6,1,2,0,7,1,2,0,8,1,2,0,9,1,2,1,0,1,2,1,1,1,2,1,2,1,2,1,3,1,2,1,4,1,2,1,5,1,2,1,6,1,2,1,7,1,2,1,8,1,2,1,9,1,2,2,0,1,2,2,1,1,2,2,2,1,2,2,3,1,2,2,4,1,2,2,5,1,2,2,6,1,2,2,7,1,2,2,8,1,2,2,9,1,2,3,0,1,2,3,1,1,2,3,2,1,2,3,3,1,2,3,4,1,2,3,5,1,2,3,6,1,2,3,7,1,2,3,8,1,2,3,9,1,2,4,0,1,2,4,1,1,2,4,2,1,2,4,3,1,2,4,4,1,2,4,5,1,2,4,6,1,2,4,7,1,2,4,8,1,2,4,9,1,2,5,0,1,2,5,1,1,2,5,2,1,2,5,3,1,2,5,4,1,2,5,5,1,2,5,6,1,2,5,7,1,2,5,8,1,2,5,9,1,2,6,0,1,2,6,1,1,2,6,2,1,2,6,3,1,2,6,4,1,2,6,5,1,2,6,6,1,2,6,7,1,2,6,8,1,2,6,9,1,2,7,0,1,2,7,1,1,2,7,2,1,2,7,3,1,2,7,4,1,2,7,5,1,2,7,6,1,2,7,7,1,2,7,8,1,2,7,9,1,2,8,0,1,2,8,1,1,2,8,2,1,2,8,3,1,2,8,4,1,2,8,5,1,2,8,6,1,2,8,7,1,2,8,8,1,2,8,9,1,2,9,0,1,2,9,1,1,2,9,2,1,2,9,3,1,2,9,4,1,2,9,5,1,2,9,6,1,2,9,7,1,2,9,8,1,2,9,9,1,3,0,0,1,3,0,1,1,3,0,2,1,3,0,3,1,3,0,4,1,3,0,5,1,3,0,6,1,3,0,7,1,3,0,8,1,3,0,9,1,3,1,0,1,3,1,1,1,3,1,2,1,3,1,3,1,3,1,4,1,3,1,5,1,3,1,6,1,3,1,7,1,3,1,8,1,3,1,9,1,3,2,0,1,3,2,1,1,3,2,2,1,3,2,3,1,3,2,4,1,3,2,5,1,3,2,6,1,3,2,7,1,3,2,8,1,3,2,9,1,3,3,0,1,3,3,1,1,3,3,2,1,3,3,3,1,3,3,4,1,3,3,5,1,3,3,6,1,3,3,7,1,3,3,8,1,3,3,9,1,3,4,0,1,3,4,1,1,3,4,2,1,3,4,3,1,3,4,4,1,3,4,5,1,3,4,6,1,3,4,7,1,3,4,8,1,3,4,9,1,3,5,0,1,3,5,1,1,3,5,2,1,3,5,3,1,3,5,4,1,3,5,5,1,3,5,6,1,3,5,7,1,3,5,8,1,3,5,9,1,3,6,0,1,3,6,1,1,3,6,2,1,3,6,3,1,3,6,4,1,3,6,5,1,3,6,6,1,3,6,7,1,3,6,8,1,3,6,9,1,3,7,0,1,3,7,1,1,3,7,2,1,3,7,3,1,3,7,4,1,3,7,5,1,3,7,6,1,3,7,7,1,3,7,8,1,3,7,9,1,3,8,0,1,3,8,1,1,3,8,2,1,3,8,3,1,3,8,4,1,3,8,5,1,3,8,6,1,3,8,7,1,3,8,8,1,3,8,9,1,3,9,0,1,3,9,1,1,3,9,2,1,3,9,3,1,3,9,4,1,3,9,5,1,3,9,6,1,3,9,7,1,3,9,8,1,3,9,9,1,4,0,0,1,4,0,1,1,4,0,2,1,4,0,3,1,4,0,4,1,4,0,5,1,4,0,6,1,4,0,7,1,4,0,8,1,4,0,9,1,4,1,0,1,4,1,1,1,4,1,2,1,4,1,3,1,4,1,4,1,4,1,5,1,4,1,6,1,4,1,7,1,4,1,8,1,4,1,9,1,4,2,0,1,4,2,1,1,4,2,2,1,4,2,3,1,4,2,4,1,4,2,5,1,4,2,6,1,4,2,7,1,4,2,8,1,4,2,9,1,4,3,0,1,4,3,1,1,4,3,2,1,4,3,3,1,4,3,4,1,4,3,5,1,4,3,6,1,4,3,7,1,4,3,8,1,4,3,9,1,4,4,0,1,4,4,1,1,4,4,2,1,4,4,3,1,4,4,4,1,4,4,5,1,4,4,6,1,4,4,7,1,4,4,8,1,4,4,9,1,4,5,0,1,4,5,1,1,4,5,2,1,4,5,3,1,4,5,4,1,4,5,5,1,4,5,6,1,4,5,7,1,4,5,8,1,4,5,9,1,4,6,0,1,4,6,1,1,4,6,2,1,4,6,3,1,4,6,4,1,4,6,5,1,4,6,6,1,4,6,7,1,4,6,8,1,4,6,9,1,4,7,0,1,4,7,1,1,4,7,2,1,4,7,3,1,4,7,4,1,4,7,5,1,4,7,6,1,4,7,7,1,4,7,8,1,4,7,9,1,4,8,0,1,4,8,1,1,4,8,2,1,4,8,3,1,4,8,4,1,4,8,5,1,4,8,6,1,4,8,7,1,4,8,8,1,4,8,9,1,4,9,0,1,4,9,1,1,4,9,2,1,4,9,3,1,4,9,4,1,4,9,5,1,4,9,6,1,4,9,7,1,4,9,8,1,4,9,9,1,5,0,0,1,5,0,1,1,5,0,2,1,5,0,3,1,5,0,4,1,5,0,5,1,5,0,6,1,5,0,7,1,5,0,8,1,5,0,9,1,5,1,0,1,5,1,1,1,5,1,2,1,5,1,3,1,5,1,4,1,5,1,5,1,5,1,6,1,5,1,7,1,5,1,8,1,5,1,9,1,5,2,0,1,5,2,1,1,5,2,2,1,5,2,3,1,5,2,4,1,5,2,5,1,5,2,6,1,5,2,7,1,5,2,8,1,5,2,9,1,5,3,0,1,5,3,1,1,5,3,2,1,5,3,3,1,5,3,4,1,5,3,5,1,5,3,6,1,5,3,7,1,5,3,8,1,5,3,9,1,5,4,0,1,5,4,1,1,5,4,2,1,5,4,3,1,5,4,4,1,5,4,5,1,5,4,6,1,5,4,7,1,5,4,8,1,5,4,9,1,5,5,0,1,5,5,1,1,5,5,2,1,5,5,3,1,5,5,4,1,5,5,5,1,5,5,6,1,5,5,7,1,5,5,8,1,5,5,9,1,5,6,0,1,5,6,1,1,5,6,2,1,5,6,3,1,5,6,4,1,5,6,5,1,5,6,6,1,5,6,7,1,5,6,8,1,5,6,9,1,5,7,0,1,5,7,1,1,5,7,2,1,5,7,3,1,5,7,4,1,5,7,5,1,5,7,6,1,5,7,7,1,5,7,8,1,5,7,9,1,5,8,0,1,5,8,1,1,5,8,2,1,5,8,3,1,5,8,4,1,5,8,5,1,5,8,6,1,5,8,7,1,5,8,8,1,5,8,9,1,5,9,0,1,5,9,1,1,5,9,2,1,5,9,3,1,5,9,4,1,5,9,5,1,5,9,6,1,5,9,7,1,5,9,8,1,5,9,9,1,6,0,0,1,6,0,1,1,6,0,2,1,6,0,3,1,6,0,4,1,6,0,5,1,6,0,6,1,6,0,7,1,6,0,8,1,6,0,9,1,6,1,0,1,6,1,1,1,6,1,2,1,6,1,3,1,6,1,4,1,6,1,5,1,6,1,6,1,6,1,7,1,6,1,8,1,6,1,9,1,6,2,0,1,6,2,1,1,6,2,2,1,6,2,3,1,6,2,4,1,6,2,5,1,6,2,6,1,6,2,7,1,6,2,8,1,6,2,9,1,6,3,0,1,6,3,1,1,6,3,2,1,6,3,3,1,6,3,4,1,6,3,5,1,6,3,6,1,6,3,7,1,6,3,8,1,6,3,9,1,6,4,0,1,6,4,1,1,6,4,2,1,6,4,3,1,6,4,4,1,6,4,5,1,6,4,6,1,6,4,7,1,6,4,8,1,6,4,9,1,6,5,0,1,6,5,1,1,6,5,2,1,6,5,3,1,6,5,4,1,6,5,5,1,6,5,6,1,6,5,7,1,6,5,8,1,6,5,9,1,6,6,0,1,6,6,1,1,6,6,2,1,6,6,3,1,6,6,4,1,6,6,5,1,6,6,6,1,6,6,7,1,6,6,8,1,6,6,9,1,6,7,0,1,6,7,1,1,6,7,2,1,6,7,3,1,6,7,4,1,6,7,5,1,6,7,6,1,6,7,7,1,6,7,8,1,6,7,9,1,6,8,0,1,6,8,1,1,6,8,2,1,6,8,3,1,6,8,4,1,6,8,5,1,6,8,6,1,6,8,7,1,6,8,8,1,6,8,9,1,6,9,0,1,6,9,1,1,6,9,2,1,6,9,3,1,6,9,4,1,6,9,5,1,6,9,6,1,6,9,7,1,6,9,8,1,6,9,9,1,7,0,0,1,7,0,1,1,7,0,2,1,7,0,3,1,7,0,4,1,7,0,5,1,7,0,6,1,7,0,7,1,7,0,8,1,7,0,9,1,7,1,0,1,7,1,1,1,7,1,2,1,7,1,3,1,7,1,4,1,7,1,5,1,7,1,6,1,7,1,7,1,7,1,8,1,7,1,9,1,7,2,0,1,7,2,1,1,7,2,2,1,7,2,3,1,7,2,4,1,7,2,5,1,7,2,6,1,7,2,7,1,7,2,8,1,7,2,9,1,7,3,0,1,7,3,1,1,7,3,2,1,7,3,3,1,7,3,4,1,7,3,5,1,7,3,6,1,7,3,7,1,7,3,8,1,7,3,9,1,7,4,0,1,7,4,1,1,7,4,2,1,7,4,3,1,7,4,4,1,7,4,5,1,7,4,6,1,7,4,7,1,7,4,8,1,7,4,9,1,7,5,0,1,7,5,1,1,7,5,2,1,7,5,3,1,7,5,4,1,7,5,5,1,7,5,6,1,7,5,7,1,7,5,8,1,7,5,9,1,7,6,0,1,7,6,1,1,7,6,2,1,7,6,3,1,7,6,4,1,7,6,5,1,7,6,6,1,7,6,7,1,7,6,8,1,7,6,9,1,7,7,0,1,7,7,1,1,7,7,2,1,7,7,3,1,7,7,4,1,7,7,5,1,7,7,6,1,7,7,7,1,7,7,8,1,7,7,9,1,7,8,0,1,7,8,1,1,7,8,2,1,7,8,3,1,7,8,4,1,7,8,5,1,7,8,6,1,7,8,7,1,7,8,8,1,7,8,9,1,7,9,0,1,7,9,1,1,7,9,2,1,7,9,3,1,7,9,4,1,7,9,5,1,7,9,6,1,7,9,7,1,7,9,8,1,7,9,9,1,8,0,0,1,8,0,1,1,8,0,2,1,8,0,3,1,8,0,4,1,8,0,5,1,8,0,6,1,8,0,7,1,8,0,8,1,8,0,9,1,8,1,0,1,8,1,1,1,8,1,2,1,8,1,3,1,8,1,4,1,8,1,5,1,8,1,6,1,8,1,7,1,8,1,8,1,8,1,9,1,8,2,0,1,8,2,1,1,8,2,2,1,8,2,3,1,8,2,4,1,8,2,5,1,8,2,6,1,8,2,7,1,8,2,8,1,8,2,9,1,8,3,0,1,8,3,1,1,8,3,2,1,8,3,3,1,8,3,4,1,8,3,5,1,8,3,6,1,8,3,7,1,8,3,8,1,8,3,9,1,8,4,0,1,8,4,1,1,8,4,2,1,8,4,3,1,8,4,4,1,8,4,5,1,8,4,6,1,8,4,7,1,8,4,8,1,8,4,9,1,8,5,0,1,8,5,1,1,8,5,2,1,8,5,3,1,8,5,4,1,8,5,5,1,8,5,6,1,8,5,7,1,8,5,8,1,8,5,9,1,8,6,0,1,8,6,1,1,8,6,2,1,8,6,3,1,8,6,4,1,8,6,5,1,8,6,6,1,8,6,7,1,8,6,8,1,8,6,9,1,8,7,0,1,8,7,1,1,8,7,2,1,8,7,3,1,8,7,4,1,8,7,5,1,8,7,6,1,8,7,7,1,8,7,8,1,8,7,9,1,8,8,0,1,8,8,1,1,8,8,2,1,8,8,3,1,8,8,4,1,8,8,5,1,8,8,6,1,8,8,7,1,8,8,8,1,8,8,9,1,8,9,0,1,8,9,1,1,8,9,2,1,8,9,3,1,8,9,4,1,8,9,5,1,8,9,6,1,8,9,7,1,8,9,8,1,8,9,9,1,9,0,0,1,9,0,1,1,9,0,2,1,9,0,3,1,9,0,4,1,9,0,5,1,9,0,6,1,9,0,7,1,9,0,8,1,9,0,9,1,9,1,0,1,9,1,1,1,9,1,2,1,9,1,3,1,9,1,4,1,9,1,5,1,9,1,6,1,9,1,7,1,9,1,8,1,9,1,9,1,9,2,0,1,9,2,1,1,9,2,2,1,9,2,3,1,9,2,4,1,9,2,5,1,9,2,6,1,9,2,7,1,9,2,8,1,9,2,9,1,9,3,0,1,9,3,1,1,9,3,2,1,9,3,3,1,9,3,4,1,9,3,5,1,9,3,6,1,9,3,7,1,9,3,8,1,9,3,9,1,9,4,0,1,9,4,1,1,9,4,2,1,9,4,3,1,9,4,4,1,9,4,5,1,9,4,6,1,9,4,7,1,9,4,8,1,9,4,9,1,9,5,0,1,9,5,1,1,9,5,2,1,9,5,3,1,9,5,4,1,9,5,5,1,9,5,6,1,9,5,7,1,9,5,8,1,9,5,9,1,9,6,0,1,9,6,1,1,9,6,2,1,9,6,3,1,9,6,4,1,9,6,5,1,9,6,6,1,9,6,7,1,9,6,8,1,9,6,9,1,9,7,0,1,9,7,1,1,9,7,2,1,9,7,3,1,9,7,4,1,9,7,5,1,9,7,6,1,9,7,7,1,9,7,8,1,9,7,9,1,9,8,0,1,9,8,1,1,9,8,2,1,9,8,3,1,9,8,4,1,9,8,5,1,9,8,6,1,9,8,7,1,9,8,8,1,9,8,9,1,9,9,0,1,9,9,1,1,9,9,2,1,9,9,3,1,9,9,4,1,9,9,5,1,9,9,6,1,9,9,7,1,9,9,8,1,9,9,9,2,0,0,0,2,0,0,1,2,0,0,2,2,0,0,3,2,0,0,4,2,0,0,5,2,0,0,6,2,0,0,7,2,0,0,8,2,0,0,9,2,0,1,0,2,0,1,1,2,0,1,2,2,0,1,3,2,0,1,4,2,0,1,5,2,0,1,6,2,0,1,7,2,0,1,8,2,0,1,9,2,0,2,0,2,0,2,1,2,0,2,2,2,0,2,3,2,0,2,4,2,0,2,5,2,0,2,6,2,0,2,7,2,0,2,8,2,0,2,9,2,0,3,0,2,0,3,1,2,0,3,2,2,0,3,3,2,0,3,4,2,0,3,5,2,0,3,6,2,0,3,7,2,0,3,8,2,0,3,9,2,0,4,0,2,0,4,1,2,0,4,2,2,0,4,3,2,0,4,4,2,0,4,5,2,0,4,6,2,0,4,7,2,0,4,8,2,0,4,9,2,0,5,0,2,0,5,1,2,0,5,2,2,0,5,3,2,0,5,4,2,0,5,5,2,0,5,6,2,0,5,7,2,0,5,8,2,0,5,9,2,0,6,0,2,0,6,1,2,0,6,2,2,0,6,3,2,0,6,4,2,0,6,5,2,0,6,6,2,0,6,7,2,0,6,8,2,0,6,9,2,0,7,0,2,0,7,1,2,0,7,2,2,0,7,3,2,0,7,4,2,0,7,5,2,0,7,6,2,0,7,7,2,0,7,8,2,0,7,9,2,0,8,0,2,0,8,1,2,0,8,2,2,0,8,3,2,0,8,4,2,0,8,5,2,0,8,6,2,0,8,7,2,0,8,8,2,0,8,9,2,0,9,0,2,0,9,1,2,0,9,2,2,0,9,3,2,0,9,4,2,0,9,5,2,0,9,6,2,0,9,7,2,0,9,8,2,0,9,9,2,1,0,0,2,1,0,1,2,1,0,2,2,1,0,3,2,1,0,4,2,1,0,5,2,1,0,6,2,1,0,7,2,1,0,8,2,1,0,9,2,1,1,0,2,1,1,1,2,1,1,2,2,1,1,3,2,1,1,4,2,1,1,5,2,1,1,6,2,1,1,7,2,1,1,8,2,1,1,9,2,1,2,0,2,1,2,1,2,1,2,2,2,1,2,3,2,1,2,4,2,1,2,5,2,1,2,6,2,1,2,7,2,1,2,8,2,1,2,9,2,1,3,0,2,1,3,1,2,1,3,2,2,1,3,3,2,1,3,4,2,1,3,5,2,1,3,6,2,1,3,7,2,1,3,8,2,1,3,9,2,1,4,0,2,1,4,1,2,1,4,2,2,1,4,3,2,1,4,4,2,1,4,5,2,1,4,6,2,1,4,7,2,1,4,8,2,1,4,9,2,1,5,0,2,1,5,1,2,1,5,2,2,1,5,3,2,1,5,4,2,1,5,5,2,1,5,6,2,1,5,7,2,1,5,8,2,1,5,9,2,1,6,0,2,1,6,1,2,1,6,2,2,1,6,3,2,1,6,4,2,1,6,5,2,1,6,6,2,1,6,7,2,1,6,8,2,1,6,9,2,1,7,0,2,1,7,1,2,1,7,2,2,1,7,3,2,1,7,4,2,1,7,5,2,1,7,6,2,1,7,7,2,1,7,8,2,1,7,9,2,1,8,0,2,1,8,1,2,1,8,2,2,1,8,3,2,1,8,4,2,1,8,5,2,1,8,6,2,1,8,7,2,1,8,8,2,1,8,9,2,1,9,0,2,1,9,1,2,1,9,2,2,1,9,3,2,1,9,4,2,1,9,5,2,1,9,6,2,1,9,7,2,1,9,8,2,1,9,9,2,2,0,0,2,2,0,1,2,2,0,2,2,2,0,3,2,2,0,4,2,2,0,5,2,2,0,6,2,2,0,7,2,2,0,8,2,2,0,9,2,2,1,0,2,2,1,1,2,2,1,2,2,2,1,3,2,2,1,4,2,2,1,5,2,2,1,6,2,2,1,7,2,2,1,8,2,2,1,9,2,2,2,0,2,2,2,1,2,2,2,2,2,2,2,3,2,2,2,4,2,2,2,5,2,2,2,6,2,2,2,7,2,2,2,8,2,2,2,9,2,2,3,0,2,2,3,1,2,2,3,2,2,2,3,3,2,2,3,4,2,2,3,5,2,2,3,6,2,2,3,7,2,2,3,8,2,2,3,9,2,2,4,0,2,2,4,1,2,2,4,2,2,2,4,3,2,2,4,4,2,2,4,5,2,2,4,6,2,2,4,7,2,2,4,8,2,2,4,9,2,2,5,0,2,2,5,1,2,2,5,2,2,2,5,3,2,2,5,4,2,2,5,5,2,2,5,6,2,2,5,7,2,2,5,8,2,2,5,9,2,2,6,0,2,2,6,1,2,2,6,2,2,2,6,3,2,2,6,4,2,2,6,5,2,2,6,6,2,2,6,7,2,2,6,8,2,2,6,9,2,2,7,0,2,2,7,1,2,2,7,2,2,2,7,3,2,2,7,4,2,2,7,5,2,2,7,6,2,2,7,7,2,2,7,8,2,2,7,9,2,2,8,0,2,2,8,1,2,2,8,2,2,2,8,3,2,2,8,4,2,2,8,5,2,2,8,6,2,2,8,7,2,2,8,8,2,2,8,9,2,2,9,0,2,2,9,1,2,2,9,2,2,2,9,3,2,2,9,4,2,2,9,5,2,2,9,6,2,2,9,7,2,2,9,8,2,2,9,9,2,3,0,0,2,3,0,1,2,3,0,2,2,3,0,3,2,3,0,4,2,3,0,5,2,3,0,6,2,3,0,7,2,3,0,8,2,3,0,9,2,3,1,0,2,3,1,1,2,3,1,2,2,3,1,3,2,3,1,4,2,3,1,5,2,3,1,6,2,3,1,7,2,3,1,8,2,3,1,9,2,3,2,0,2,3,2,1,2,3,2,2,2,3,2,3,2,3,2,4,2,3,2,5,2,3,2,6,2,3,2,7,2,3,2,8,2,3,2,9,2,3,3,0,2,3,3,1,2,3,3,2,2,3,3,3,2,3,3,4,2,3,3,5,2,3,3,6,2,3,3,7,2,3,3,8,2,3,3,9,2,3,4,0,2,3,4,1,2,3,4,2,2,3,4,3,2,3,4,4,2,3,4,5,2,3,4,6,2,3,4,7,2,3,4,8,2,3,4,9,2,3,5,0,2,3,5,1,2,3,5,2,2,3,5,3,2,3,5,4,2,3,5,5,2,3,5,6,2,3,5,7,2,3,5,8,2,3,5,9,2,3,6,0,2,3,6,1,2,3,6,2,2,3,6,3,2,3,6,4,2,3,6,5,2,3,6,6,2,3,6,7,2,3,6,8,2,3,6,9,2,3,7,0,2,3,7,1,2,3,7,2,2,3,7,3,2,3,7,4,2,3,7,5,2,3,7,6,2,3,7,7,2,3,7,8,2,3,7,9,2,3,8,0,2,3,8,1,2,3,8,2,2,3,8,3,2,3,8,4,2,3,8,5,2,3,8,6,2,3,8,7,2,3,8,8,2,3,8,9,2,3,9,0,2,3,9,1,2,3,9,2,2,3,9,3,2,3,9,4,2,3,9,5,2,3,9,6,2,3,9,7,2,3,9,8,2,3,9,9,2,4,0,0,2,4,0,1,2,4,0,2,2,4,0,3,2,4,0,4,2,4,0,5,2,4,0,6,2,4,0,7,2,4,0,8,2,4,0,9,2,4,1,0,2,4,1,1,2,4,1,2,2,4,1,3,2,4,1,4,2,4,1,5,2,4,1,6,2,4,1,7,2,4,1,8,2,4,1,9,2,4,2,0,2,4,2,1,2,4,2,2,2,4,2,3,2,4,2,4,2,4,2,5,2,4,2,6,2,4,2,7,2,4,2,8,2,4,2,9,2,4,3,0,2,4,3,1,2,4,3,2,2,4,3,3,2,4,3,4,2,4,3,5,2,4,3,6,2,4,3,7,2,4,3,8,2,4,3,9,2,4,4,0,2,4,4,1,2,4,4,2,2,4,4,3,2,4,4,4,2,4,4,5,2,4,4,6,2,4,4,7,2,4,4,8,2,4,4,9,2,4,5,0,2,4,5,1,2,4,5,2,2,4,5,3,2,4,5,4,2,4,5,5,2,4,5,6,2,4,5,7,2,4,5,8,2,4,5,9,2,4,6,0,2,4,6,1,2,4,6,2,2,4,6,3,2,4,6,4,2,4,6,5,2,4,6,6,2,4,6,7,2,4,6,8,2,4,6,9,2,4,7,0,2,4,7,1,2,4,7,2,2,4,7,3,2,4,7,4,2,4,7,5,2,4,7,6,2,4,7,7,2,4,7,8,2,4,7,9,2,4,8,0,2,4,8,1,2,4,8,2,2,4,8,3,2,4,8,4,2,4,8,5,2,4,8,6,2,4,8,7,2,4,8,8,2,4,8,9,2,4,9,0,2,4,9,1,2,4,9,2,2,4,9,3,2,4,9,4,2,4,9,5,2,4,9,6,2,4,9,7,2,4,9,8,2,4,9,9,2,5,0,0,2,5,0,1,2,5,0,2,2,5,0,3,2,5,0,4,2,5,0,5,2,5,0,6,2,5,0,7,2,5,0,8,2,5,0,9,2,5,1,0,2,5,1,1,2,5,1,2,2,5,1,3,2,5,1,4,2,5,1,5,2,5,1,6,2,5,1,7,2,5,1,8,2,5,1,9,2,5,2,0,2,5,2,1,2,5,2,2,2,5,2,3,2,5,2,4,2,5,2,5,2,5,2,6,2,5,2,7,2,5,2,8,2,5,2,9,2,5,3,0,2,5,3,1,2,5,3,2,2,5,3,3,2,5,3,4,2,5,3,5,2,5,3,6,2,5,3,7,2,5,3,8,2,5,3,9,2,5,4,0,2,5,4,1,2,5,4,2,2,5,4,3,2,5,4,4,2,5,4,5,2,5,4,6,2,5,4,7,2,5,4,8,2,5,4,9,2,5,5,0,2,5,5,1,2,5,5,2,2,5,5,3,2,5,5,4,2,5,5,5,2,5,5,6,2,5,5,7,2,5,5,8,2,5,5,9,2,5,6,0,2,5,6,1,2,5,6,2,2,5,6,3,2,5,6,4,2,5,6,5,2,5,6,6,2,5,6,7,2,5,6,8,2,5,6,9,2,5,7,0,2,5,7,1,2,5,7,2,2,5,7,3,2,5,7,4,2,5,7,5,2,5,7,6,2,5,7,7,2,5,7,8,2,5,7,9,2,5,8,0,2,5,8,1,2,5,8,2,2,5,8,3,2,5,8,4,2,5,8,5,2,5,8,6,2,5,8,7,2,5,8,8,2,5,8,9,2,5,9,0,2,5,9,1,2,5,9,2,2,5,9,3,2,5,9,4,2,5,9,5,2,5,9,6,2,5,9,7,2,5,9,8,2,5,9,9,2,6,0,0,2,6,0,1,2,6,0,2,2,6,0,3,2,6,0,4,2,6,0,5,2,6,0,6,2,6,0,7,2,6,0,8,2,6,0,9,2,6,1,0,2,6,1,1,2,6,1,2,2,6,1,3,2,6,1,4,2,6,1,5,2,6,1,6,2,6,1,7,2,6,1,8,2,6,1,9,2,6,2,0,2,6,2,1,2,6,2,2,2,6,2,3,2,6,2,4,2,6,2,5,2,6,2,6,2,6,2,7,2,6,2,8,2,6,2,9,2,6,3,0,2,6,3,1,2,6,3,2,2,6,3,3,2,6,3,4,2,6,3,5,2,6,3,6,2,6,3,7,2,6,3,8,2,6,3,9,2,6,4,0,2,6,4,1,2,6,4,2,2,6,4,3,2,6,4,4,2,6,4,5,2,6,4,6,2,6,4,7,2,6,4,8,2,6,4,9,2,6,5,0,2,6,5,1,2,6,5,2,2,6,5,3,2,6,5,4,2,6,5,5,2,6,5,6,2,6,5,7,2,6,5,8,2,6,5,9,2,6,6,0,2,6,6,1,2,6,6,2,2,6,6,3,2,6,6,4,2,6,6,5,2,6,6,6,2,6,6,7,2,6,6,8,2,6,6,9,2,6,7,0,2,6,7,1,2,6,7,2,2,6,7,3,2,6,7,4,2,6,7,5,2,6,7,6,2,6,7,7,2,6,7,8,2,6,7,9,2,6,8,0,2,6,8,1,2,6,8,2,2,6,8,3,2,6,8,4,2,6,8,5,2,6,8,6,2,6,8,7,2,6,8,8,2,6,8,9,2,6,9,0,2,6,9,1,2,6,9,2,2,6,9,3,2,6,9,4,2,6,9,5,2,6,9,6,2,6,9,7,2,6,9,8,2,6,9,9,2,7,0,0,2,7,0,1,2,7,0,2,2,7,0,3,2,7,0,4,2,7,0,5,2,7,0,6,2,7,0,7,2,7,0,8,2,7,0,9,2,7,1,0,2,7,1,1,2,7,1,2,2,7,1,3,2,7,1,4,2,7,1,5,2,7,1,6,2,7,1,7,2,7,1,8,2,7,1,9,2,7,2,0,2,7,2,1,2,7,2,2,2,7,2,3,2,7,2,4,2,7,2,5,2,7,2,6,2,7,2,7,2,7,2,8,2,7,2,9,2,7,3,0,2,7,3,1,2,7,3,2,2,7,3,3,2,7,3,4,2,7,3,5,2,7,3,6,2,7,3,7,2,7,3,8,2,7,3,9,2,7,4,0,2,7,4,1,2,7,4,2,2,7,4,3,2,7,4,4,2,7,4,5,2,7,4,6,2,7,4,7,2,7,4,8,2,7,4,9,2,7,5,0,2,7,5,1,2,7,5,2,2,7,5,3,2,7,5,4,2,7,5,5,2,7,5,6,2,7,5,7,2,7,5,8,2,7,5,9,2,7,6,0,2,7,6,1,2,7,6,2,2,7,6,3,2,7,6,4,2,7,6,5,2,7,6,6,2,7,6,7,2,7,6,8,2,7,6,9,2,7,7,0,2,7,7,1,2,7,7,2,2,7,7,3,2,7,7,4,2,7,7,5,2,7,7,6,2,7,7,7,];\n\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n let input = input.trim().parse::().unwrap();\n println!(\"{}\", seq[input-1]);\n}\n"}, {"source_code": "type Res = u64;\n\nfn main() {\n let k = {\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n input.trim().parse::().unwrap()\n };\n\n let result = solve(k);\n\n println!(\"{}\", result);\n\n}\n\nfn int_len(inp: Res) -> Res {\n if inp == 0 {\n return 1;\n }\n\n let mut res = 0;\n let mut temp = 1;\n while temp <= inp {\n res += 1;\n temp *= 10\n }\n res\n}\n\nfn solve(k: Res) -> char {\n // counter for digits\n let mut n: Res = 1;\n // Potential number of the digit we search\n let mut d: Res = 1;\n while n().unwrap()\n };\n assert!((1 <= k) && (k <= MAX_INP), \"K out of input range. 1<= k <= 10^12\");\n let result = solve(k);\n println!(\"{}\", result);\n}\n\nfn int_len_(inp: Res) -> Res {\n if inp == 0 {\n return 1;\n }\n\n let mut res = 0;\n let mut temp = 1;\n while temp <= inp {\n res += 1;\n temp *= 10\n }\n res\n}\n\nfn int_len(inp: Res) -> Res {\n //debug_assert!(0 <= inp);\n //debug_assert!(inp <= MAX_INP);\n match inp {\n 1000000000000..=9999999999999 => 13,\n 100000000000..=999999999999 => 12,\n 10000000000..=99999999999 => 11,\n 1000000000..=9999999999 => 10,\n 100000000..=999999999 => 9,\n 10000000..=99999999 => 8,\n 1000000..=9999999 => 7,\n 100000..=999999 => 6,\n 10000..=99999 => 5,\n 1000..=9999 => 4,\n 100..=999 => 3,\n 10..=99 => 2,\n 0..=9 => 1,\n _ => unreachable!()\n }\n}\n\nfn solve(k: Res) -> char {\n let lookup = [(1,1),(1000000008,123456790),(2000000007,234567901),(3000000006,345679012),(4000000005,456790123),(5000000004,567901234),(6000000003,679012345),(7000000002,790123456),(8000000001,901234567),(9000000009,1011111111),(10000000009,1111111111),(11000000009,1211111111),(12000000009,1311111111),(13000000009,1411111111),(14000000009,1511111111),(15000000009,1611111111),(16000000009,1711111111),(17000000009,1811111111),(18000000009,1911111111),(19000000009,2011111111),(20000000009,2111111111),(21000000009,2211111111),(22000000009,2311111111),(23000000009,2411111111),(24000000009,2511111111),(25000000009,2611111111),(26000000009,2711111111),(27000000009,2811111111),(28000000009,2911111111),(29000000009,3011111111),(30000000009,3111111111),(31000000009,3211111111),(32000000009,3311111111),(33000000009,3411111111),(34000000009,3511111111),(35000000009,3611111111),(36000000009,3711111111),(37000000009,3811111111),(38000000009,3911111111),(39000000009,4011111111),(40000000009,4111111111),(41000000009,4211111111),(42000000009,4311111111),(43000000009,4411111111),(44000000009,4511111111),(45000000009,4611111111),(46000000009,4711111111),(47000000009,4811111111),(48000000009,4911111111),(49000000009,5011111111),(50000000009,5111111111),(51000000009,5211111111),(52000000009,5311111111),(53000000009,5411111111),(54000000009,5511111111),(55000000009,5611111111),(56000000009,5711111111),(57000000009,5811111111),(58000000009,5911111111),(59000000009,6011111111),(60000000009,6111111111),(61000000009,6211111111),(62000000009,6311111111),(63000000009,6411111111),(64000000009,6511111111),(65000000009,6611111111),(66000000009,6711111111),(67000000009,6811111111),(68000000009,6911111111),(69000000009,7011111111),(70000000009,7111111111),(71000000009,7211111111),(72000000009,7311111111),(73000000009,7411111111),(74000000009,7511111111),(75000000009,7611111111),(76000000009,7711111111),(77000000009,7811111111),(78000000009,7911111111),(79000000009,8011111111),(80000000009,8111111111),(81000000009,8211111111),(82000000009,8311111111),(83000000009,8411111111),(84000000009,8511111111),(85000000009,8611111111),(86000000009,8711111111),(87000000009,8811111111),(88000000009,8911111111),(89000000009,9011111111),(90000000009,9111111111),(91000000009,9211111111),(92000000009,9311111111),(93000000009,9411111111),(94000000009,9511111111),(95000000009,9611111111),(96000000009,9711111111),(97000000009,9811111111),(98000000009,9911111111),(99000000010,10010101010),(100000000000,10101010100),(101000000001,10191919191),(102000000002,10282828282),(103000000003,10373737373),(104000000004,10464646464),(105000000005,10555555555),(106000000006,10646464646),(107000000007,10737373737),(108000000008,10828282828),(109000000009,10919191919),(110000000010,11010101010),(111000000000,11101010100),(112000000001,11191919191),(113000000002,11282828282),(114000000003,11373737373),(115000000004,11464646464),(116000000005,11555555555),(117000000006,11646464646),(118000000007,11737373737),(119000000008,11828282828),(120000000009,11919191919),(121000000010,12010101010),(122000000000,12101010100),(123000000001,12191919191),(124000000002,12282828282),(125000000003,12373737373),(126000000004,12464646464),(127000000005,12555555555),(128000000006,12646464646),(129000000007,12737373737),(130000000008,12828282828),(131000000009,12919191919),(132000000010,13010101010),(133000000000,13101010100),(134000000001,13191919191),(135000000002,13282828282),(136000000003,13373737373),(137000000004,13464646464),(138000000005,13555555555),(139000000006,13646464646),(140000000007,13737373737),(141000000008,13828282828),(142000000009,13919191919),(143000000010,14010101010),(144000000000,14101010100),(145000000001,14191919191),(146000000002,14282828282),(147000000003,14373737373),(148000000004,14464646464),(149000000005,14555555555),(150000000006,14646464646),(151000000007,14737373737),(152000000008,14828282828),(153000000009,14919191919),(154000000010,15010101010),(155000000000,15101010100),(156000000001,15191919191),(157000000002,15282828282),(158000000003,15373737373),(159000000004,15464646464),(160000000005,15555555555),(161000000006,15646464646),(162000000007,15737373737),(163000000008,15828282828),(164000000009,15919191919),(165000000010,16010101010),(166000000000,16101010100),(167000000001,16191919191),(168000000002,16282828282),(169000000003,16373737373),(170000000004,16464646464),(171000000005,16555555555),(172000000006,16646464646),(173000000007,16737373737),(174000000008,16828282828),(175000000009,16919191919),(176000000010,17010101010),(177000000000,17101010100),(178000000001,17191919191),(179000000002,17282828282),(180000000003,17373737373),(181000000004,17464646464),(182000000005,17555555555),(183000000006,17646464646),(184000000007,17737373737),(185000000008,17828282828),(186000000009,17919191919),(187000000010,18010101010),(188000000000,18101010100),(189000000001,18191919191),(190000000002,18282828282),(191000000003,18373737373),(192000000004,18464646464),(193000000005,18555555555),(194000000006,18646464646),(195000000007,18737373737),(196000000008,18828282828),(197000000009,18919191919),(198000000010,19010101010),(199000000000,19101010100),(200000000001,19191919191),(201000000002,19282828282),(202000000003,19373737373),(203000000004,19464646464),(204000000005,19555555555),(205000000006,19646464646),(206000000007,19737373737),(207000000008,19828282828),(208000000009,19919191919),(209000000010,20010101010),(210000000000,20101010100),(211000000001,20191919191),(212000000002,20282828282),(213000000003,20373737373),(214000000004,20464646464),(215000000005,20555555555),(216000000006,20646464646),(217000000007,20737373737),(218000000008,20828282828),(219000000009,20919191919),(220000000010,21010101010),(221000000000,21101010100),(222000000001,21191919191),(223000000002,21282828282),(224000000003,21373737373),(225000000004,21464646464),(226000000005,21555555555),(227000000006,21646464646),(228000000007,21737373737),(229000000008,21828282828),(230000000009,21919191919),(231000000010,22010101010),(232000000000,22101010100),(233000000001,22191919191),(234000000002,22282828282),(235000000003,22373737373),(236000000004,22464646464),(237000000005,22555555555),(238000000006,22646464646),(239000000007,22737373737),(240000000008,22828282828),(241000000009,22919191919),(242000000010,23010101010),(243000000000,23101010100),(244000000001,23191919191),(245000000002,23282828282),(246000000003,23373737373),(247000000004,23464646464),(248000000005,23555555555),(249000000006,23646464646),(250000000007,23737373737),(251000000008,23828282828),(252000000009,23919191919),(253000000010,24010101010),(254000000000,24101010100),(255000000001,24191919191),(256000000002,24282828282),(257000000003,24373737373),(258000000004,24464646464),(259000000005,24555555555),(260000000006,24646464646),(261000000007,24737373737),(262000000008,24828282828),(263000000009,24919191919),(264000000010,25010101010),(265000000000,25101010100),(266000000001,25191919191),(267000000002,25282828282),(268000000003,25373737373),(269000000004,25464646464),(270000000005,25555555555),(271000000006,25646464646),(272000000007,25737373737),(273000000008,25828282828),(274000000009,25919191919),(275000000010,26010101010),(276000000000,26101010100),(277000000001,26191919191),(278000000002,26282828282),(279000000003,26373737373),(280000000004,26464646464),(281000000005,26555555555),(282000000006,26646464646),(283000000007,26737373737),(284000000008,26828282828),(285000000009,26919191919),(286000000010,27010101010),(287000000000,27101010100),(288000000001,27191919191),(289000000002,27282828282),(290000000003,27373737373),(291000000004,27464646464),(292000000005,27555555555),(293000000006,27646464646),(294000000007,27737373737),(295000000008,27828282828),(296000000009,27919191919),(297000000010,28010101010),(298000000000,28101010100),(299000000001,28191919191),(300000000002,28282828282),(301000000003,28373737373),(302000000004,28464646464),(303000000005,28555555555),(304000000006,28646464646),(305000000007,28737373737),(306000000008,28828282828),(307000000009,28919191919),(308000000010,29010101010),(309000000000,29101010100),(310000000001,29191919191),(311000000002,29282828282),(312000000003,29373737373),(313000000004,29464646464),(314000000005,29555555555),(315000000006,29646464646),(316000000007,29737373737),(317000000008,29828282828),(318000000009,29919191919),(319000000010,30010101010),(320000000000,30101010100),(321000000001,30191919191),(322000000002,30282828282),(323000000003,30373737373),(324000000004,30464646464),(325000000005,30555555555),(326000000006,30646464646),(327000000007,30737373737),(328000000008,30828282828),(329000000009,30919191919),(330000000010,31010101010),(331000000000,31101010100),(332000000001,31191919191),(333000000002,31282828282),(334000000003,31373737373),(335000000004,31464646464),(336000000005,31555555555),(337000000006,31646464646),(338000000007,31737373737),(339000000008,31828282828),(340000000009,31919191919),(341000000010,32010101010),(342000000000,32101010100),(343000000001,32191919191),(344000000002,32282828282),(345000000003,32373737373),(346000000004,32464646464),(347000000005,32555555555),(348000000006,32646464646),(349000000007,32737373737),(350000000008,32828282828),(351000000009,32919191919),(352000000010,33010101010),(353000000000,33101010100),(354000000001,33191919191),(355000000002,33282828282),(356000000003,33373737373),(357000000004,33464646464),(358000000005,33555555555),(359000000006,33646464646),(360000000007,33737373737),(361000000008,33828282828),(362000000009,33919191919),(363000000010,34010101010),(364000000000,34101010100),(365000000001,34191919191),(366000000002,34282828282),(367000000003,34373737373),(368000000004,34464646464),(369000000005,34555555555),(370000000006,34646464646),(371000000007,34737373737),(372000000008,34828282828),(373000000009,34919191919),(374000000010,35010101010),(375000000000,35101010100),(376000000001,35191919191),(377000000002,35282828282),(378000000003,35373737373),(379000000004,35464646464),(380000000005,35555555555),(381000000006,35646464646),(382000000007,35737373737),(383000000008,35828282828),(384000000009,35919191919),(385000000010,36010101010),(386000000000,36101010100),(387000000001,36191919191),(388000000002,36282828282),(389000000003,36373737373),(390000000004,36464646464),(391000000005,36555555555),(392000000006,36646464646),(393000000007,36737373737),(394000000008,36828282828),(395000000009,36919191919),(396000000010,37010101010),(397000000000,37101010100),(398000000001,37191919191),(399000000002,37282828282),(400000000003,37373737373),(401000000004,37464646464),(402000000005,37555555555),(403000000006,37646464646),(404000000007,37737373737),(405000000008,37828282828),(406000000009,37919191919),(407000000010,38010101010),(408000000000,38101010100),(409000000001,38191919191),(410000000002,38282828282),(411000000003,38373737373),(412000000004,38464646464),(413000000005,38555555555),(414000000006,38646464646),(415000000007,38737373737),(416000000008,38828282828),(417000000009,38919191919),(418000000010,39010101010),(419000000000,39101010100),(420000000001,39191919191),(421000000002,39282828282),(422000000003,39373737373),(423000000004,39464646464),(424000000005,39555555555),(425000000006,39646464646),(426000000007,39737373737),(427000000008,39828282828),(428000000009,39919191919),(429000000010,40010101010),(430000000000,40101010100),(431000000001,40191919191),(432000000002,40282828282),(433000000003,40373737373),(434000000004,40464646464),(435000000005,40555555555),(436000000006,40646464646),(437000000007,40737373737),(438000000008,40828282828),(439000000009,40919191919),(440000000010,41010101010),(441000000000,41101010100),(442000000001,41191919191),(443000000002,41282828282),(444000000003,41373737373),(445000000004,41464646464),(446000000005,41555555555),(447000000006,41646464646),(448000000007,41737373737),(449000000008,41828282828),(450000000009,41919191919),(451000000010,42010101010),(452000000000,42101010100),(453000000001,42191919191),(454000000002,42282828282),(455000000003,42373737373),(456000000004,42464646464),(457000000005,42555555555),(458000000006,42646464646),(459000000007,42737373737),(460000000008,42828282828),(461000000009,42919191919),(462000000010,43010101010),(463000000000,43101010100),(464000000001,43191919191),(465000000002,43282828282),(466000000003,43373737373),(467000000004,43464646464),(468000000005,43555555555),(469000000006,43646464646),(470000000007,43737373737),(471000000008,43828282828),(472000000009,43919191919),(473000000010,44010101010),(474000000000,44101010100),(475000000001,44191919191),(476000000002,44282828282),(477000000003,44373737373),(478000000004,44464646464),(479000000005,44555555555),(480000000006,44646464646),(481000000007,44737373737),(482000000008,44828282828),(483000000009,44919191919),(484000000010,45010101010),(485000000000,45101010100),(486000000001,45191919191),(487000000002,45282828282),(488000000003,45373737373),(489000000004,45464646464),(490000000005,45555555555),(491000000006,45646464646),(492000000007,45737373737),(493000000008,45828282828),(494000000009,45919191919),(495000000010,46010101010),(496000000000,46101010100),(497000000001,46191919191),(498000000002,46282828282),(499000000003,46373737373),(500000000004,46464646464),(501000000005,46555555555),(502000000006,46646464646),(503000000007,46737373737),(504000000008,46828282828),(505000000009,46919191919),(506000000010,47010101010),(507000000000,47101010100),(508000000001,47191919191),(509000000002,47282828282),(510000000003,47373737373),(511000000004,47464646464),(512000000005,47555555555),(513000000006,47646464646),(514000000007,47737373737),(515000000008,47828282828),(516000000009,47919191919),(517000000010,48010101010),(518000000000,48101010100),(519000000001,48191919191),(520000000002,48282828282),(521000000003,48373737373),(522000000004,48464646464),(523000000005,48555555555),(524000000006,48646464646),(525000000007,48737373737),(526000000008,48828282828),(527000000009,48919191919),(528000000010,49010101010),(529000000000,49101010100),(530000000001,49191919191),(531000000002,49282828282),(532000000003,49373737373),(533000000004,49464646464),(534000000005,49555555555),(535000000006,49646464646),(536000000007,49737373737),(537000000008,49828282828),(538000000009,49919191919),(539000000010,50010101010),(540000000000,50101010100),(541000000001,50191919191),(542000000002,50282828282),(543000000003,50373737373),(544000000004,50464646464),(545000000005,50555555555),(546000000006,50646464646),(547000000007,50737373737),(548000000008,50828282828),(549000000009,50919191919),(550000000010,51010101010),(551000000000,51101010100),(552000000001,51191919191),(553000000002,51282828282),(554000000003,51373737373),(555000000004,51464646464),(556000000005,51555555555),(557000000006,51646464646),(558000000007,51737373737),(559000000008,51828282828),(560000000009,51919191919),(561000000010,52010101010),(562000000000,52101010100),(563000000001,52191919191),(564000000002,52282828282),(565000000003,52373737373),(566000000004,52464646464),(567000000005,52555555555),(568000000006,52646464646),(569000000007,52737373737),(570000000008,52828282828),(571000000009,52919191919),(572000000010,53010101010),(573000000000,53101010100),(574000000001,53191919191),(575000000002,53282828282),(576000000003,53373737373),(577000000004,53464646464),(578000000005,53555555555),(579000000006,53646464646),(580000000007,53737373737),(581000000008,53828282828),(582000000009,53919191919),(583000000010,54010101010),(584000000000,54101010100),(585000000001,54191919191),(586000000002,54282828282),(587000000003,54373737373),(588000000004,54464646464),(589000000005,54555555555),(590000000006,54646464646),(591000000007,54737373737),(592000000008,54828282828),(593000000009,54919191919),(594000000010,55010101010),(595000000000,55101010100),(596000000001,55191919191),(597000000002,55282828282),(598000000003,55373737373),(599000000004,55464646464),(600000000005,55555555555),(601000000006,55646464646),(602000000007,55737373737),(603000000008,55828282828),(604000000009,55919191919),(605000000010,56010101010),(606000000000,56101010100),(607000000001,56191919191),(608000000002,56282828282),(609000000003,56373737373),(610000000004,56464646464),(611000000005,56555555555),(612000000006,56646464646),(613000000007,56737373737),(614000000008,56828282828),(615000000009,56919191919),(616000000010,57010101010),(617000000000,57101010100),(618000000001,57191919191),(619000000002,57282828282),(620000000003,57373737373),(621000000004,57464646464),(622000000005,57555555555),(623000000006,57646464646),(624000000007,57737373737),(625000000008,57828282828),(626000000009,57919191919),(627000000010,58010101010),(628000000000,58101010100),(629000000001,58191919191),(630000000002,58282828282),(631000000003,58373737373),(632000000004,58464646464),(633000000005,58555555555),(634000000006,58646464646),(635000000007,58737373737),(636000000008,58828282828),(637000000009,58919191919),(638000000010,59010101010),(639000000000,59101010100),(640000000001,59191919191),(641000000002,59282828282),(642000000003,59373737373),(643000000004,59464646464),(644000000005,59555555555),(645000000006,59646464646),(646000000007,59737373737),(647000000008,59828282828),(648000000009,59919191919),(649000000010,60010101010),(650000000000,60101010100),(651000000001,60191919191),(652000000002,60282828282),(653000000003,60373737373),(654000000004,60464646464),(655000000005,60555555555),(656000000006,60646464646),(657000000007,60737373737),(658000000008,60828282828),(659000000009,60919191919),(660000000010,61010101010),(661000000000,61101010100),(662000000001,61191919191),(663000000002,61282828282),(664000000003,61373737373),(665000000004,61464646464),(666000000005,61555555555),(667000000006,61646464646),(668000000007,61737373737),(669000000008,61828282828),(670000000009,61919191919),(671000000010,62010101010),(672000000000,62101010100),(673000000001,62191919191),(674000000002,62282828282),(675000000003,62373737373),(676000000004,62464646464),(677000000005,62555555555),(678000000006,62646464646),(679000000007,62737373737),(680000000008,62828282828),(681000000009,62919191919),(682000000010,63010101010),(683000000000,63101010100),(684000000001,63191919191),(685000000002,63282828282),(686000000003,63373737373),(687000000004,63464646464),(688000000005,63555555555),(689000000006,63646464646),(690000000007,63737373737),(691000000008,63828282828),(692000000009,63919191919),(693000000010,64010101010),(694000000000,64101010100),(695000000001,64191919191),(696000000002,64282828282),(697000000003,64373737373),(698000000004,64464646464),(699000000005,64555555555),(700000000006,64646464646),(701000000007,64737373737),(702000000008,64828282828),(703000000009,64919191919),(704000000010,65010101010),(705000000000,65101010100),(706000000001,65191919191),(707000000002,65282828282),(708000000003,65373737373),(709000000004,65464646464),(710000000005,65555555555),(711000000006,65646464646),(712000000007,65737373737),(713000000008,65828282828),(714000000009,65919191919),(715000000010,66010101010),(716000000000,66101010100),(717000000001,66191919191),(718000000002,66282828282),(719000000003,66373737373),(720000000004,66464646464),(721000000005,66555555555),(722000000006,66646464646),(723000000007,66737373737),(724000000008,66828282828),(725000000009,66919191919),(726000000010,67010101010),(727000000000,67101010100),(728000000001,67191919191),(729000000002,67282828282),(730000000003,67373737373),(731000000004,67464646464),(732000000005,67555555555),(733000000006,67646464646),(734000000007,67737373737),(735000000008,67828282828),(736000000009,67919191919),(737000000010,68010101010),(738000000000,68101010100),(739000000001,68191919191),(740000000002,68282828282),(741000000003,68373737373),(742000000004,68464646464),(743000000005,68555555555),(744000000006,68646464646),(745000000007,68737373737),(746000000008,68828282828),(747000000009,68919191919),(748000000010,69010101010),(749000000000,69101010100),(750000000001,69191919191),(751000000002,69282828282),(752000000003,69373737373),(753000000004,69464646464),(754000000005,69555555555),(755000000006,69646464646),(756000000007,69737373737),(757000000008,69828282828),(758000000009,69919191919),(759000000010,70010101010),(760000000000,70101010100),(761000000001,70191919191),(762000000002,70282828282),(763000000003,70373737373),(764000000004,70464646464),(765000000005,70555555555),(766000000006,70646464646),(767000000007,70737373737),(768000000008,70828282828),(769000000009,70919191919),(770000000010,71010101010),(771000000000,71101010100),(772000000001,71191919191),(773000000002,71282828282),(774000000003,71373737373),(775000000004,71464646464),(776000000005,71555555555),(777000000006,71646464646),(778000000007,71737373737),(779000000008,71828282828),(780000000009,71919191919),(781000000010,72010101010),(782000000000,72101010100),(783000000001,72191919191),(784000000002,72282828282),(785000000003,72373737373),(786000000004,72464646464),(787000000005,72555555555),(788000000006,72646464646),(789000000007,72737373737),(790000000008,72828282828),(791000000009,72919191919),(792000000010,73010101010),(793000000000,73101010100),(794000000001,73191919191),(795000000002,73282828282),(796000000003,73373737373),(797000000004,73464646464),(798000000005,73555555555),(799000000006,73646464646),(800000000007,73737373737),(801000000008,73828282828),(802000000009,73919191919),(803000000010,74010101010),(804000000000,74101010100),(805000000001,74191919191),(806000000002,74282828282),(807000000003,74373737373),(808000000004,74464646464),(809000000005,74555555555),(810000000006,74646464646),(811000000007,74737373737),(812000000008,74828282828),(813000000009,74919191919),(814000000010,75010101010),(815000000000,75101010100),(816000000001,75191919191),(817000000002,75282828282),(818000000003,75373737373),(819000000004,75464646464),(820000000005,75555555555),(821000000006,75646464646),(822000000007,75737373737),(823000000008,75828282828),(824000000009,75919191919),(825000000010,76010101010),(826000000000,76101010100),(827000000001,76191919191),(828000000002,76282828282),(829000000003,76373737373),(830000000004,76464646464),(831000000005,76555555555),(832000000006,76646464646),(833000000007,76737373737),(834000000008,76828282828),(835000000009,76919191919),(836000000010,77010101010),(837000000000,77101010100),(838000000001,77191919191),(839000000002,77282828282),(840000000003,77373737373),(841000000004,77464646464),(842000000005,77555555555),(843000000006,77646464646),(844000000007,77737373737),(845000000008,77828282828),(846000000009,77919191919),(847000000010,78010101010),(848000000000,78101010100),(849000000001,78191919191),(850000000002,78282828282),(851000000003,78373737373),(852000000004,78464646464),(853000000005,78555555555),(854000000006,78646464646),(855000000007,78737373737),(856000000008,78828282828),(857000000009,78919191919),(858000000010,79010101010),(859000000000,79101010100),(860000000001,79191919191),(861000000002,79282828282),(862000000003,79373737373),(863000000004,79464646464),(864000000005,79555555555),(865000000006,79646464646),(866000000007,79737373737),(867000000008,79828282828),(868000000009,79919191919),(869000000010,80010101010),(870000000000,80101010100),(871000000001,80191919191),(872000000002,80282828282),(873000000003,80373737373),(874000000004,80464646464),(875000000005,80555555555),(876000000006,80646464646),(877000000007,80737373737),(878000000008,80828282828),(879000000009,80919191919),(880000000010,81010101010),(881000000000,81101010100),(882000000001,81191919191),(883000000002,81282828282),(884000000003,81373737373),(885000000004,81464646464),(886000000005,81555555555),(887000000006,81646464646),(888000000007,81737373737),(889000000008,81828282828),(890000000009,81919191919),(891000000010,82010101010),(892000000000,82101010100),(893000000001,82191919191),(894000000002,82282828282),(895000000003,82373737373),(896000000004,82464646464),(897000000005,82555555555),(898000000006,82646464646),(899000000007,82737373737),(900000000008,82828282828),(901000000009,82919191919),(902000000010,83010101010),(903000000000,83101010100),(904000000001,83191919191),(905000000002,83282828282),(906000000003,83373737373),(907000000004,83464646464),(908000000005,83555555555),(909000000006,83646464646),(910000000007,83737373737),(911000000008,83828282828),(912000000009,83919191919),(913000000010,84010101010),(914000000000,84101010100),(915000000001,84191919191),(916000000002,84282828282),(917000000003,84373737373),(918000000004,84464646464),(919000000005,84555555555),(920000000006,84646464646),(921000000007,84737373737),(922000000008,84828282828),(923000000009,84919191919),(924000000010,85010101010),(925000000000,85101010100),(926000000001,85191919191),(927000000002,85282828282),(928000000003,85373737373),(929000000004,85464646464),(930000000005,85555555555),(931000000006,85646464646),(932000000007,85737373737),(933000000008,85828282828),(934000000009,85919191919),(935000000010,86010101010),(936000000000,86101010100),(937000000001,86191919191),(938000000002,86282828282),(939000000003,86373737373),(940000000004,86464646464),(941000000005,86555555555),(942000000006,86646464646),(943000000007,86737373737),(944000000008,86828282828),(945000000009,86919191919),(946000000010,87010101010),(947000000000,87101010100),(948000000001,87191919191),(949000000002,87282828282),(950000000003,87373737373),(951000000004,87464646464),(952000000005,87555555555),(953000000006,87646464646),(954000000007,87737373737),(955000000008,87828282828),(956000000009,87919191919),(957000000010,88010101010),(958000000000,88101010100),(959000000001,88191919191),(960000000002,88282828282),(961000000003,88373737373),(962000000004,88464646464),(963000000005,88555555555),(964000000006,88646464646),(965000000007,88737373737),(966000000008,88828282828),(967000000009,88919191919),(968000000010,89010101010),(969000000000,89101010100),(970000000001,89191919191),(971000000002,89282828282),(972000000003,89373737373),(973000000004,89464646464),(974000000005,89555555555),(975000000006,89646464646),(976000000007,89737373737),(977000000008,89828282828),(978000000009,89919191919),(979000000010,90010101010),(980000000000,90101010100),(981000000001,90191919191),(982000000002,90282828282),(983000000003,90373737373),(984000000004,90464646464),(985000000005,90555555555),(986000000006,90646464646),(987000000007,90737373737),(988000000008,90828282828),(989000000009,90919191919),(990000000010,91010101010),(991000000000,91101010100),(992000000001,91191919191),(993000000002,91282828282),(994000000003,91373737373),(995000000004,91464646464),(996000000005,91555555555),(997000000006,91646464646),(998000000007,91737373737),(999000000008,91828282828),(1000000000009,91919191919),];\n\n let idx = k / STEP_SIZE;\n let starts = lookup[idx as usize];\n let result = solve_internal(k, starts.0, starts.1);\n result.0\n}\n\nfn solve_internal(k: Res, n: Res, d: Res) -> (char, Res, Res) {\n // counter for digits\n let mut n: Res = n;//1;\n // Potential number of the digit we search\n let mut d: Res = d;//1;\n while n().unwrap();\n println!(\"{}\", seq.chars().nth(input-1).unwrap());\n}\n"}, {"source_code": "use std::io::*;\n\nfn main() {\n let stdin = stdin();\n\n let k: usize = {\n let mut buffer_string = String::new();\n stdin\n .read_line(&mut buffer_string)\n .expect(\"could not read line\");\n buffer_string.trim().parse().unwrap()\n };\n\n let mut digits = 0;\n for n in (1..).map(|m| m.to_string()) {\n let digits_in_n = n.len();\n if digits + digits_in_n < k {\n digits += digits_in_n;\n } else {\n let index_in_n = k - digits - 1;\n println!(\"{}\", n.chars().nth(index_in_n).unwrap());\n return;\n }\n }\n}\n"}, {"source_code": "use std::io::{self, BufRead};\nuse std::collections::VecDeque;\n\nstruct DigitSequenceIterator {\n inner: u64,\n state: VecDeque,\n}\n\nimpl Iterator for DigitSequenceIterator {\n type Item = char;\n\n fn next(&mut self) -> Option {\n if self.state.len() == 0 {\n self.state.extend(self.inner.to_string().chars());;\n\n self.inner += 1;\n }\n\n self.state.pop_front()\n }\n}\n\nimpl DigitSequenceIterator {\n pub fn new() -> Self {\n DigitSequenceIterator {\n inner: 0,\n state: VecDeque::new(),\n }\n }\n\n pub fn skip(mut to_skip: u64) -> impl Iterator {\n let mut inner = 0;\n\n if to_skip >= 10 {\n inner = 10;\n to_skip -= 10;\n }\n\n let mut can_jump = 90;\n let mut i = 2;\n while to_skip > can_jump * i {\n to_skip -= can_jump * i;\n inner *= 10;\n\n can_jump *= 10;\n i += 1;\n }\n\n // Now, all numbers between inner and the end are `i` wide.\n // So, to_skip/i is the amount of numbers we can still skip.\n if i > 2 {\n inner += to_skip/i;\n to_skip = to_skip % i;\n }\n\n DigitSequenceIterator {\n inner,\n state: VecDeque::new(),\n }.skip(to_skip as usize)\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock().lines().next().expect(\"input\").expect(\"UTF-8\");\n let index: u64 = line.parse().expect(\"Numeric value\");\n\n println!(\"{}\", DigitSequenceIterator::skip(index).next().unwrap());\n}\n\n#[test]\nfn vectors() {\n let in_out = [(7, '7'), (21, '5'), (188, '9'), (192, '0'), (417, '5')];\n\n for (i, o) in &in_out {\n let test = DigitSequenceIterator::skip(*i).next().unwrap();\n assert_eq!(test, *o,\n \"{}th should be {}, but got {}\", i, *o, test);\n }\n}\n"}], "negative_code": [{"source_code": "use std::io::{self, BufRead};\nuse std::collections::VecDeque;\n\nstruct DigitSequenceIterator {\n inner: usize,\n state: VecDeque,\n}\n\nimpl Iterator for DigitSequenceIterator {\n type Item = char;\n\n fn next(&mut self) -> Option {\n if self.state.len() == 0 {\n self.state.extend(self.inner.to_string().chars());;\n\n self.inner += 1;\n }\n\n self.state.pop_front()\n }\n}\n\nimpl DigitSequenceIterator {\n pub fn new() -> Self {\n DigitSequenceIterator {\n inner: 0,\n state: VecDeque::new(),\n }\n }\n\n pub fn skip(mut to_skip: usize) -> impl Iterator {\n let mut inner = 0;\n\n if to_skip >= 10 {\n inner = 10;\n to_skip -= 10;\n }\n\n let mut can_jump = 90;\n while to_skip > can_jump {\n to_skip -= can_jump;\n inner *= 10;\n\n can_jump *= 10;\n }\n\n DigitSequenceIterator {\n inner,\n state: VecDeque::new(),\n }.skip(to_skip)\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock().lines().next().expect(\"input\").expect(\"UTF-8\");\n let index: usize = line.parse().expect(\"Numeric value\");\n\n println!(\"{}\", DigitSequenceIterator::skip(index).next().unwrap());\n}\n\n#[test]\nfn vectors() {\n let in_out = [(7, '7'), (21, '5'), (192, '0'), (417, '5')];\n\n for (i, o) in &in_out {\n let test = DigitSequenceIterator::skip(*i).next().unwrap();\n assert_eq!(test, *o,\n \"{}th should be {}, but got {}\", i, *o, test);\n }\n}\n"}], "src_uid": "1503d761dd4e129fb7c423da390544ff"} {"source_code": "fn main() {\r\n use std::io::Read;\r\n let mut buf = String::new();\r\n std::io::stdin().read_to_string(&mut buf).unwrap();\r\n let mut itr = buf.split_whitespace();\r\n\r\n use std::io::Write;\r\n let out = std::io::stdout();\r\n let mut out = std::io::BufWriter::new(out.lock());\r\n\r\n macro_rules! print {\r\n ($($T:expr),*) => {\r\n write!(out, $($T),*).unwrap()\r\n };\r\n }\r\n\r\n macro_rules! scan {\r\n (bytes) => {\r\n scan!(String).bytes().collect::>()\r\n };\r\n (chars) => {\r\n scan!(String).chars().collect::>()\r\n };\r\n ([$T:tt; $n:expr]) => {\r\n (0..$n).map(|_| scan!($T)).collect::>()\r\n };\r\n (($($T:tt),*)) => {\r\n ($(scan!($T)),*)\r\n };\r\n ($T:ty) => {\r\n itr.next().unwrap().parse::<$T>().unwrap()\r\n };\r\n ($($T:tt),*) => {\r\n ($(scan!($T)),*)\r\n };\r\n }\r\n\r\n let t: usize = 1; //scan!(usize);\r\n for _ in 1..=t {\r\n let n = scan!(usize);\r\n let mut a = vec![0; n + 1];\r\n\r\n let mut sum = 0;\r\n for i in 1..=n {\r\n a[i] = scan!(usize);\r\n sum += a[i];\r\n }\r\n\r\n if sum % 2 != 0 {\r\n print!(\"0\");\r\n } else {\r\n let mut dp = vec![vec![false; sum + 1]; n + 1];\r\n dp[0][0] = true;\r\n\r\n for i in 1..=n {\r\n for s in 0..=sum {\r\n if a[i] + s <= sum {\r\n dp[i][s + a[i]] |= dp[i - 1][s];\r\n }\r\n dp[i][s] |= dp[i - 1][s];\r\n }\r\n }\r\n\r\n if dp[n][sum / 2] {\r\n print!(\"1\\n\");\r\n let mut min_idx = 0;\r\n let mut min_cnt = 31;\r\n for i in 1..=n {\r\n let mut cnt = 0;\r\n let mut a = a[i];\r\n while a % 2 == 0 {\r\n cnt += 1;\r\n a /= 2;\r\n }\r\n if min_cnt > cnt {\r\n min_cnt = cnt;\r\n min_idx = i;\r\n }\r\n }\r\n\r\n print!(\"{}\", min_idx);\r\n } else {\r\n print!(\"0\");\r\n }\r\n }\r\n print!(\"\\n\");\r\n }\r\n}\r\n", "positive_code": [{"source_code": "cp! {\nkind = single;\ninput {\n n: u,\n a: [u; n],\n}\n\nsolve {\n fn check(a: &[u], h: &mut m<(u, i), bool>, i: u, sum: i) -> bool {\n if let Some(val) = h.get(&(i, sum)) {\n return *val;\n }\n let val = {\n if sum < 0 {\n return false;\n }\n if sum == 0 {\n return true;\n }\n if i == a.len() {\n return false;\n }\n check(a, h, i + 1, sum - a[i] as i) || check(a, h, i + 1, sum as i)\n };\n h.insert((i, sum), val);\n val\n }\n\n let mut c = m::new();\n let sum = a.iter().sum::();\n if sum & 1 == 1 || !check(&a, &mut c, 0, sum as i / 2)\n {\n ans!(0);\n }\n\n loop {\n for (i, x) in a.iter_mut().enumerate() {\n if *x & 1 == 1 {\n outln!(1);\n ans!(i + 1);\n }\n *x /= 2;\n }\n }\n}\n}\n\n#[cfg(not(ONLINE_JUDGE))]\n#[macro_use]\nextern crate cp;\n\n#[cfg(not(ONLINE_JUDGE))]\nuse cp::*;\n// =================================================================================\n// =================================================================================\n\n// LIBRARY CODE BEGINS HERE\n// TAKEN FROM https://github.com/EbTech/rust-algorithms\n// YOU CAN JUST RUN rustfmt TO GET READABLE CODE\n\n// =================================================================================\n// =================================================================================\npub use std::cmp::*; pub use std::collections::*; use std::hash::Hash; pub use std::io::*; pub use std::mem::*; pub use std::str::FromStr; pub type i = i64; pub type u = usize; pub type v = Vec; pub type vi = v; pub type ii = (i, i); pub type uu = (u, u); pub type vu = v; pub type vii = v; pub type vuu = v; pub type s = String; pub type m = HashMap; use std::{ fmt::Display, intrinsics::transmute, io::{self, StdinLock}, mem::MaybeUninit, }; pub mod algo { pub mod caching { use std::collections::{hash_map::Entry, HashMap}; pub struct Cacher where U: std::cmp::Eq + std::hash::Hash + Copy, V: Copy, { values: HashMap, } impl Cacher where U: std::cmp::Eq + std::hash::Hash + Copy, V: Copy, { pub fn new() -> Cacher { Cacher { values: HashMap::new(), } } pub fn call(&mut self, arg: U, calc: impl Fn(U) -> V) -> V { if let Some(v) = self.values.get(&arg) { return *v; } let val = calc(arg); self.values.insert(arg, val); val } } } pub mod graph { pub mod connectivity { use super::Graph; struct ConnectivityData { time: usize, vis: Box<[usize]>, low: Box<[usize]>, v_stack: Vec, e_stack: Vec, } impl ConnectivityData { fn new(num_v: usize) -> Self { Self { time: 0, vis: vec![0; num_v].into_boxed_slice(), low: vec![0; num_v].into_boxed_slice(), v_stack: vec![], e_stack: vec![], } } fn visit(&mut self, u: usize) { self.time += 1; self.vis[u] = self.time; self.low[u] = self.time; self.v_stack.push(u); } fn lower(&mut self, u: usize, val: usize) { if self.low[u] > val { self.low[u] = val } } } pub struct ConnectivityGraph<'a> { pub graph: &'a Graph, pub cc: Vec, pub vcc: Vec, pub num_cc: usize, pub num_vcc: usize, } impl<'a> ConnectivityGraph<'a> { pub fn new(graph: &'a Graph, is_directed: bool) -> Self { let mut connect = Self { graph, cc: vec![0; graph.num_v()], vcc: vec![0; graph.num_e()], num_cc: 0, num_vcc: 0, }; let mut data = ConnectivityData::new(graph.num_v()); for u in 0..graph.num_v() { if data.vis[u] == 0 { if is_directed { connect.scc(&mut data, u); } else { connect.bcc(&mut data, u, graph.num_e() + 1); } } } connect } fn scc(&mut self, data: &mut ConnectivityData, u: usize) { data.visit(u); for (_, v) in self.graph.adj_list(u) { if data.vis[v] == 0 { self.scc(data, v); } if self.cc[v] == 0 { data.lower(u, data.low[v]); } } if data.vis[u] == data.low[u] { self.num_cc += 1; while let Some(v) = data.v_stack.pop() { self.cc[v] = self.num_cc; if v == u { break; } } } } pub fn two_sat_assign(&self) -> Option> { (0..self.graph.num_v() / 2) .map(|i| { let scc_true = self.cc[2 * i]; let scc_false = self.cc[2 * i + 1]; if scc_true == scc_false { None } else { Some(scc_true < scc_false) } }) .collect() } pub fn topological_sort(&self) -> Vec { let mut vertices = (0..self.graph.num_v()).collect::>(); vertices.sort_unstable_by_key(|&u| self.num_cc - self.cc[u]); vertices } fn bcc(&mut self, data: &mut ConnectivityData, u: usize, par: usize) { data.visit(u); for (e, v) in self.graph.adj_list(u) { if data.vis[v] == 0 { data.e_stack.push(e); self.bcc(data, v, e); data.lower(u, data.low[v]); if data.vis[u] <= data.low[v] { self.num_vcc += 1; while let Some(top_e) = data.e_stack.pop() { self.vcc[top_e] = self.num_vcc; self.vcc[top_e ^ 1] = self.num_vcc; if e ^ top_e <= 1 { break; } } } } else if data.vis[v] < data.vis[u] && e ^ par != 1 { data.lower(u, data.vis[v]); data.e_stack.push(e); } else if v == u { self.num_vcc += 1; self.vcc[e] = self.num_vcc; self.vcc[e ^ 1] = self.num_vcc; } } if data.vis[u] == data.low[u] { self.num_cc += 1; while let Some(v) = data.v_stack.pop() { self.cc[v] = self.num_cc; if v == u { break; } } } } pub fn is_cut_vertex(&self, u: usize) -> bool { if let Some(first_e) = self.graph.first[u] { self.graph .adj_list(u) .any(|(e, _)| self.vcc[first_e] != self.vcc[e]) } else { false } } pub fn is_cut_edge(&self, e: usize) -> bool { let u = self.graph.endp[e ^ 1]; let v = self.graph.endp[e]; self.cc[u] != self.cc[v] } } } pub mod flow { use super::{AdjListIterator, Graph}; pub struct FlowGraph { pub graph: Graph, pub cap: Vec, pub cost: Vec, } impl FlowGraph { const INF: i64 = i64::MAX; pub fn new(vmax: usize, emax_hint: usize) -> Self { Self { graph: Graph::new(vmax, 2 * emax_hint), cap: Vec::with_capacity(2 * emax_hint), cost: Vec::with_capacity(2 * emax_hint), } } pub fn add_edge(&mut self, u: usize, v: usize, cap: i64, rcap: i64, cost: i64) { self.cap.push(cap); self.cap.push(rcap); self.cost.push(cost); self.cost.push(-cost); self.graph.add_undirected_edge(u, v); } pub fn dinic(&self, s: usize, t: usize) -> (i64, Vec) { let mut flow = vec![0; self.graph.num_e()]; let mut max_flow = 0; loop { let dist = self.dinic_search(s, &flow); if dist[t] == Self::INF { break; } let mut adj_iters = (0..self.graph.num_v()) .map(|u| self.graph.adj_list(u).peekable()) .collect::>(); max_flow += self.dinic_augment(s, t, Self::INF, &dist, &mut adj_iters, &mut flow); } (max_flow, flow) } fn dinic_search(&self, s: usize, flow: &[i64]) -> Vec { let mut dist = vec![Self::INF; self.graph.num_v()]; let mut q = ::std::collections::VecDeque::new(); dist[s] = 0; q.push_back(s); while let Some(u) = q.pop_front() { for (e, v) in self.graph.adj_list(u) { if dist[v] == Self::INF && flow[e] < self.cap[e] { dist[v] = dist[u] + 1; q.push_back(v); } } } dist } fn dinic_augment( &self, u: usize, t: usize, f: i64, dist: &[i64], adj: &mut [::std::iter::Peekable], flow: &mut [i64], ) -> i64 { if u == t { return f; } let mut df = 0; while let Some(&(e, v)) = adj[u].peek() { let rem_cap = (self.cap[e] - flow[e]).min(f - df); if rem_cap > 0 && dist[v] == dist[u] + 1 { let cf = self.dinic_augment(v, t, rem_cap, dist, adj, flow); flow[e] += cf; flow[e ^ 1] -= cf; df += cf; if df == f { break; } } adj[u].next(); } df } pub fn min_cut(&self, dist: &[i64]) -> Vec { (0..self.graph.num_e()) .filter(|&e| { let u = self.graph.endp[e ^ 1]; let v = self.graph.endp[e]; dist[u] < Self::INF && dist[v] == Self::INF }) .collect() } pub fn mcf(&self, s: usize, t: usize) -> (i64, i64, Vec) { let mut pot = vec![0; self.graph.num_v()]; for _ in 1..self.graph.num_v() { for e in 0..self.graph.num_e() { if self.cap[e] > 0 { let u = self.graph.endp[e ^ 1]; let v = self.graph.endp[e]; pot[v] = pot[v].min(pot[u] + self.cost[e]); } } } let mut flow = vec![0; self.graph.num_e()]; let (mut min_cost, mut max_flow) = (0, 0); loop { let par = self.mcf_search(s, &flow, &mut pot); if par[t] == None { break; } let (dc, df) = self.mcf_augment(t, &par, &mut flow); min_cost += dc; max_flow += df; } (min_cost, max_flow, flow) } fn mcf_search( &self, s: usize, flow: &[i64], pot: &mut [i64], ) -> Vec> { let mut vis = vec![false; self.graph.num_v()]; let mut dist = vec![Self::INF; self.graph.num_v()]; let mut par = vec![None; self.graph.num_v()]; dist[s] = 0; while let Some(u) = (0..self.graph.num_v()) .filter(|&u| !vis[u] && dist[u] < Self::INF) .min_by_key(|&u| dist[u] - pot[u]) { vis[u] = true; pot[u] = dist[u]; for (e, v) in self.graph.adj_list(u) { if dist[v] > dist[u] + self.cost[e] && flow[e] < self.cap[e] { dist[v] = dist[u] + self.cost[e]; par[v] = Some(e); } } } par } fn mcf_augment( &self, t: usize, par: &[Option], flow: &mut [i64], ) -> (i64, i64) { let (mut dc, mut df) = (0, Self::INF); let mut u = t; while let Some(e) = par[u] { df = df.min(self.cap[e] - flow[e]); u = self.graph.endp[e ^ 1]; } u = t; while let Some(e) = par[u] { flow[e] += df; flow[e ^ 1] -= df; dc += df * self.cost[e]; u = self.graph.endp[e ^ 1]; } (dc, df) } } } pub mod util { use super::AdjListIterator; use super::{DisjointSets, Graph}; use std::cmp::Reverse; impl Graph { pub fn euler_path(&self, u: usize) -> Vec { let mut adj_iters = (0..self.num_v()) .map(|u| self.adj_list(u)) .collect::>(); let mut edges = Vec::with_capacity(self.num_e()); self.euler_recurse(u, &mut adj_iters, &mut edges); edges.reverse(); edges } fn euler_recurse( &self, u: usize, adj: &mut [AdjListIterator], edges: &mut Vec, ) { while let Some((e, v)) = adj[u].next() { self.euler_recurse(v, adj, edges); edges.push(e); } } pub fn min_spanning_tree(&self, weights: &[i64]) -> Vec { assert_eq!(self.num_e(), 2 * weights.len()); let mut edges = (0..weights.len()).collect::>(); edges.sort_unstable_by_key(|&e| weights[e]); let mut components = DisjointSets::new(self.num_v()); edges .into_iter() .filter(|&e| components.merge(self.endp[2 * e], self.endp[2 * e + 1])) .collect() } pub fn dijkstra(&self, weights: &[u64], u: usize) -> Vec { assert_eq!(self.num_e(), weights.len()); let mut dist = vec![u64::max_value(); weights.len()]; let mut heap = std::collections::BinaryHeap::new(); dist[u] = 0; heap.push((Reverse(0), 0)); while let Some((Reverse(dist_u), u)) = heap.pop() { if dist[u] == dist_u { for (e, v) in self.adj_list(u) { let dist_v = dist_u + weights[e]; if dist[v] > dist_v { dist[v] = dist_v; heap.push((Reverse(dist_v), v)); } } } } dist } pub fn dfs(&self, root: usize) -> DfsIterator { let mut visited = vec![false; self.num_v()]; visited[root] = true; let adj_iters = (0..self.num_v()) .map(|u| self.adj_list(u)) .collect::>(); DfsIterator { visited, stack: vec![root], adj_iters, } } } pub struct DfsIterator<'a> { visited: Vec, stack: Vec, adj_iters: Vec>, } impl<'a> Iterator for DfsIterator<'a> { type Item = (usize, usize); fn next(&mut self) -> Option { loop { let &u = self.stack.last()?; while let Some((e, v)) = self.adj_iters[u].next() { if !self.visited[v] { self.visited[v] = true; self.stack.push(v); return Some((e, v)); } } self.stack.pop(); } } } } pub struct DisjointSets { parent: Vec, } impl DisjointSets { pub fn new(size: usize) -> Self { Self { parent: (0..size).collect(), } } pub fn find(&mut self, u: usize) -> usize { let pu = self.parent[u]; if pu != u { self.parent[u] = self.find(pu); } self.parent[u] } pub fn merge(&mut self, u: usize, v: usize) -> bool { let (pu, pv) = (self.find(u), self.find(v)); self.parent[pu] = pv; pu != pv } } pub struct Graph { first: Vec>, next: Vec>, endp: Vec, } impl Graph { pub fn new(vmax: usize, emax_hint: usize) -> Self { Self { first: vec![None; vmax], next: Vec::with_capacity(emax_hint), endp: Vec::with_capacity(emax_hint), } } pub fn num_v(&self) -> usize { self.first.len() } pub fn num_e(&self) -> usize { self.endp.len() } pub fn add_edge(&mut self, u: usize, v: usize) { self.next.push(self.first[u]); self.first[u] = Some(self.num_e()); self.endp.push(v); } pub fn add_undirected_edge(&mut self, u: usize, v: usize) { self.add_edge(u, v); self.add_edge(v, u); } pub fn add_two_sat_clause(&mut self, u: usize, v: usize) { self.add_edge(u ^ 1, v); self.add_edge(v ^ 1, u); } pub fn adj_list(&self, u: usize) -> AdjListIterator { AdjListIterator { graph: self, next_e: self.first[u], } } } pub struct AdjListIterator<'a> { graph: &'a Graph, next_e: Option, } impl<'a> Iterator for AdjListIterator<'a> { type Item = (usize, usize); fn next(&mut self) -> Option { self.next_e.map(|e| { let v = self.graph.endp[e]; self.next_e = self.graph.next[e]; (e, v) }) } } } pub mod math { pub mod fft { use super::num::{CommonField, Complex, PI}; use std::ops::{Add, Div, Mul, Neg, Sub}; struct BitRevIterator { a: usize, n: usize, } impl BitRevIterator { fn new(n: usize) -> Self { assert!(n.is_power_of_two()); Self { a: 2 * n - 1, n } } } impl Iterator for BitRevIterator { type Item = usize; fn next(&mut self) -> Option { if self.a == 2 * self.n - 2 { return None; } let mut mask = self.n; while self.a & mask > 0 { self.a ^= mask; mask /= 2; } self.a |= mask; Some(self.a / 2) } } #[allow(clippy::upper_case_acronyms)] pub trait FFT: Sized + Copy { type F: Sized + Copy + From + Neg + Add + Div + Mul + Sub; const ZERO: Self; fn get_roots(n: usize, inverse: bool) -> Vec; fn get_factor(n: usize, inverse: bool) -> Self::F; fn extract(f: Self::F) -> Self; } impl FFT for f64 { type F = Complex; const ZERO: f64 = 0.0; fn get_roots(n: usize, inverse: bool) -> Vec { let step = if inverse { -2.0 } else { 2.0 } * PI / n as f64; (0..n / 2) .map(|i| Complex::from_polar(1.0, step * i as f64)) .collect() } fn get_factor(n: usize, inverse: bool) -> Self::F { Self::F::from(if inverse { (n as f64).recip() } else { 1.0 }) } fn extract(f: Self::F) -> f64 { f.real } } impl FFT for i64 { type F = CommonField; const ZERO: Self = 0; fn get_roots(n: usize, inverse: bool) -> Vec { assert!(n <= 1 << 23); let mut prim_root = Self::F::from(15_311_432); if inverse { prim_root = prim_root.recip(); } for _ in (0..).take_while(|&i| n < 1 << (23 - i)) { prim_root = prim_root * prim_root; } let mut roots = Vec::with_capacity(n / 2); let mut root = Self::F::from(1); for _ in 0..roots.capacity() { roots.push(root); root = root * prim_root; } roots } fn get_factor(n: usize, inverse: bool) -> Self::F { Self::F::from(if inverse { n as Self } else { 1 }).recip() } fn extract(f: Self::F) -> Self { f.val } } pub fn fft(v: &[T::F], inverse: bool) -> Vec { let n = v.len(); assert!(n.is_power_of_two()); let factor = T::get_factor(n, inverse); let roots_of_unity = T::get_roots(n, inverse); let mut dft = BitRevIterator::new(n) .map(|i| v[i] * factor) .collect::>(); for m in (0..).map(|s| 1 << s).take_while(|&m| m < n) { for k in (0..n).step_by(2 * m) { for j in 0..m { let u = dft[k + j]; let t = dft[k + j + m] * roots_of_unity[n / 2 / m * j]; dft[k + j] = u + t; dft[k + j + m] = u - t; } } } dft } pub fn dft_from_reals(v: &[T], desired_len: usize) -> Vec { assert!(v.len() <= desired_len); let complex_v = v .iter() .cloned() .chain(std::iter::repeat(T::ZERO)) .take(desired_len.next_power_of_two()) .map(T::F::from) .collect::>(); fft::(&complex_v, false) } pub fn idft_to_reals(dft_v: &[T::F], desired_len: usize) -> Vec { assert!(dft_v.len() >= desired_len); let complex_v = fft::(dft_v, true); complex_v .into_iter() .take(desired_len) .map(T::extract) .collect() } pub fn convolution(a: &[T], b: &[T]) -> Vec { let len_c = a.len() + b.len() - 1; let dft_a = dft_from_reals(a, len_c).into_iter(); let dft_b = dft_from_reals(b, len_c).into_iter(); let dft_c = dft_a.zip(dft_b).map(|(a, b)| a * b).collect::>(); idft_to_reals(&dft_c, len_c) } } pub mod num { pub use std::f64::consts::PI; use std::ops::{Add, Div, Index, IndexMut, Mul, Neg, Sub}; pub fn fast_gcd(mut a: i64, mut b: i64) -> i64 { while b != 0 { a %= b; std::mem::swap(&mut a, &mut b); } a.abs() } #[derive(Clone, Copy, Eq, PartialEq, Debug, Hash)] pub struct Rational { pub num: i64, pub den: i64, } impl Rational { pub fn new(num: i64, den: i64) -> Self { let g = fast_gcd(num, den) * den.signum(); Self { num: num / g, den: den / g, } } pub fn abs(self) -> Self { Self { num: self.num.abs(), den: self.den, } } pub fn recip(self) -> Self { let g = self.num.signum(); Self { num: self.den / g, den: self.num / g, } } } impl From for Rational { fn from(num: i64) -> Self { Self { num, den: 1 } } } impl Neg for Rational { type Output = Self; fn neg(self) -> Self { Self { num: -self.num, den: self.den, } } } #[allow(clippy::suspicious_arithmetic_impl)] impl Add for Rational { type Output = Self; fn add(self, other: Self) -> Self { Self::new( self.num * other.den + self.den * other.num, self.den * other.den, ) } } #[allow(clippy::suspicious_arithmetic_impl)] impl Sub for Rational { type Output = Self; fn sub(self, other: Self) -> Self { Self::new( self.num * other.den - self.den * other.num, self.den * other.den, ) } } impl Mul for Rational { type Output = Self; fn mul(self, other: Self) -> Self { Self::new(self.num * other.num, self.den * other.den) } } #[allow(clippy::suspicious_arithmetic_impl)] impl Div for Rational { type Output = Self; fn div(self, other: Self) -> Self { self * other.recip() } } impl Ord for Rational { fn cmp(&self, other: &Self) -> std::cmp::Ordering { (self.num * other.den).cmp(&(self.den * other.num)) } } impl PartialOrd for Rational { fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } #[derive(Clone, Copy, PartialEq, Debug)] pub struct Complex { pub real: f64, pub imag: f64, } impl Complex { pub fn new(real: f64, imag: f64) -> Self { Self { real, imag } } pub fn from_polar(r: f64, th: f64) -> Self { Self::new(r * th.cos(), r * th.sin()) } pub fn abs_square(self) -> f64 { self.real * self.real + self.imag * self.imag } pub fn argument(self) -> f64 { self.imag.atan2(self.real) } pub fn conjugate(self) -> Self { Self::new(self.real, -self.imag) } pub fn recip(self) -> Self { let denom = self.abs_square(); Self::new(self.real / denom, -self.imag / denom) } } impl From for Complex { fn from(real: f64) -> Self { Self::new(real, 0.0) } } impl Neg for Complex { type Output = Self; fn neg(self) -> Self { Self::new(-self.real, -self.imag) } } impl Add for Complex { type Output = Self; fn add(self, other: Self) -> Self { Self::new(self.real + other.real, self.imag + other.imag) } } impl Sub for Complex { type Output = Self; fn sub(self, other: Self) -> Self { Self::new(self.real - other.real, self.imag - other.imag) } } impl Mul for Complex { type Output = Self; fn mul(self, other: Self) -> Self { let real = self.real * other.real - self.imag * other.imag; let imag = self.imag * other.real + self.real * other.imag; Self::new(real, imag) } } #[allow(clippy::suspicious_arithmetic_impl)] impl Div for Complex { type Output = Self; fn div(self, other: Self) -> Self { self * other.recip() } } #[derive(Clone, Copy, Eq, PartialEq, Debug, Hash)] pub struct Modulo { pub val: i64, } impl Modulo { pub fn pow(mut self, mut n: u64) -> Self { let mut result = Self::from_small(1); while n > 0 { if n % 2 == 1 { result = result * self; } self = self * self; n /= 2; } result } pub fn vec_of_recips(n: i64) -> Vec { let mut recips = vec![Self::from(0), Self::from(1)]; for i in 2..=n { let (md, dv) = (M % i, M / i); recips.push(recips[md as usize] * Self::from_small(-dv)); } recips } pub fn recip(self) -> Self { self.pow(M as u64 - 2) } fn from_small(s: i64) -> Self { let val = if s < 0 { s + M } else { s }; Self { val } } } impl From for Modulo { fn from(val: i64) -> Self { Self::from_small(val % M) } } impl Neg for Modulo { type Output = Self; fn neg(self) -> Self { Self::from_small(-self.val) } } impl Add for Modulo { type Output = Self; fn add(self, other: Self) -> Self { Self::from_small(self.val + other.val - M) } } impl Sub for Modulo { type Output = Self; fn sub(self, other: Self) -> Self { Self::from_small(self.val - other.val) } } impl Mul for Modulo { type Output = Self; fn mul(self, other: Self) -> Self { Self::from(self.val * other.val) } } #[allow(clippy::suspicious_arithmetic_impl)] impl Div for Modulo { type Output = Self; fn div(self, other: Self) -> Self { self * other.recip() } } pub const COMMON_PRIME: i64 = 998_244_353; pub type CommonField = Modulo; #[derive(Clone, PartialEq, Debug)] pub struct Matrix { cols: usize, inner: Box<[f64]>, } impl Matrix { pub fn zero(rows: usize, cols: usize) -> Self { let inner = vec![0.0; rows * cols].into_boxed_slice(); Self { cols, inner } } pub fn one(cols: usize) -> Self { let mut matrix = Self::zero(cols, cols); for i in 0..cols { matrix[i][i] = 1.0; } matrix } pub fn vector(vec: &[f64], as_row: bool) -> Self { let cols = if as_row { vec.len() } else { 1 }; let inner = vec.to_vec().into_boxed_slice(); Self { cols, inner } } pub fn pow(&self, mut n: u64) -> Self { let mut base = self.clone(); let mut result = Self::one(self.cols); while n > 0 { if n % 2 == 1 { result = &result * &base; } base = &base * &base; n /= 2; } result } pub fn rows(&self) -> usize { self.inner.len() / self.cols } pub fn transpose(&self) -> Self { let mut matrix = Matrix::zero(self.cols, self.rows()); for i in 0..self.rows() { for j in 0..self.cols { matrix[j][i] = self[i][j]; } } matrix } pub fn recip(&self) -> Self { unimplemented!(); } } impl Index for Matrix { type Output = [f64]; fn index(&self, row: usize) -> &Self::Output { let start = self.cols * row; &self.inner[start..start + self.cols] } } impl IndexMut for Matrix { fn index_mut(&mut self, row: usize) -> &mut Self::Output { let start = self.cols * row; &mut self.inner[start..start + self.cols] } } impl Neg for &Matrix { type Output = Matrix; fn neg(self) -> Matrix { let inner = self.inner.iter().map(|&v| -v).collect(); Matrix { cols: self.cols, inner, } } } impl Add for &Matrix { type Output = Matrix; fn add(self, other: Self) -> Matrix { let self_iter = self.inner.iter(); let inner = self_iter .zip(other.inner.iter()) .map(|(&u, &v)| u + v) .collect(); Matrix { cols: self.cols, inner, } } } impl Sub for &Matrix { type Output = Matrix; fn sub(self, other: Self) -> Matrix { let self_iter = self.inner.iter(); let inner = self_iter .zip(other.inner.iter()) .map(|(&u, &v)| u - v) .collect(); Matrix { cols: self.cols, inner, } } } impl Mul for &Matrix { type Output = Matrix; fn mul(self, scalar: f64) -> Matrix { let inner = self.inner.iter().map(|&v| v * scalar).collect(); Matrix { cols: self.cols, inner, } } } impl Mul for &Matrix { type Output = Matrix; fn mul(self, other: Self) -> Matrix { assert_eq!(self.cols, other.rows()); let mut matrix = Matrix::zero(self.rows(), other.cols); for i in 0..self.rows() { for k in 0..self.cols { for j in 0..other.cols { matrix[i][j] += self[i][k] * other[k][j]; } } } matrix } } } pub fn extended_gcd(a: i64, b: i64) -> (i64, i64, i64) { if b == 0 { (a.abs(), a.signum(), 0) } else { let (d, coef_b, coef_a) = extended_gcd(b, a % b); (d, coef_a, coef_b - coef_a * (a / b)) } } pub fn canon_egcd(a: i64, b: i64, c: i64) -> Option<(i64, i64, i64)> { let (d, _, coef_b_init) = extended_gcd(a, b); if c % d == 0 { let a_d = (a / d).abs(); let coef_b = (coef_b_init * (c / d) % a_d + a_d) % a_d; let coef_a = (c - b * coef_b) / a; Some((d, coef_a, coef_b)) } else { None } } fn pos_mod(n: i64, m: i64) -> i64 { if n < 0 { n + m } else { n } } fn mod_mul(a: i64, b: i64, m: i64) -> i64 { pos_mod((a as i128 * b as i128 % m as i128) as i64, m) } fn mod_exp(mut base: i64, mut exp: u64, m: i64) -> i64 { assert!(m >= 1); let mut ans = 1 % m; base %= m; while exp > 0 { if exp % 2 == 1 { ans = mod_mul(ans, base, m); } base = mod_mul(base, base, m); exp /= 2; } pos_mod(ans, m) } fn is_strong_probable_prime(n: i64, exp: u64, r: i64, a: i64) -> bool { let mut x = mod_exp(a, exp, n); if x == 1 || x == n - 1 { return true; } for _ in 1..r { x = mod_mul(x, x, n); if x == n - 1 { return true; } } false } pub fn is_prime(n: i64) -> bool { const BASES: [i64; 12] = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]; assert!(n >= 0); match n { 0 | 1 => false, 2 | 3 => true, _ if n % 2 == 0 => false, _ => { let r = (n - 1).trailing_zeros() as i64; let exp = (n - 1) as u64 >> r; BASES .iter() .all(|&base| base > n - 2 || is_strong_probable_prime(n, exp, r, base)) } } } fn pollard_rho(n: i64) -> i64 { for a in 1..n { let f = |x| pos_mod(mod_mul(x, x, n) + a, n); let mut x = 2; let mut y = 2; loop { x = f(x); y = f(f(y)); let div = num::fast_gcd(x - y, n); if div == n { break; } else if div > 1 { return div; } } } panic!(\"No divisor found!\"); } pub fn factorize(n: i64) -> Vec { assert!(n >= 1); let r = n.trailing_zeros() as usize; let mut factors = vec![2; r]; let mut stack = match n >> r { 1 => vec![], x => vec![x], }; while let Some(top) = stack.pop() { if is_prime(top) { factors.push(top); } else { let div = pollard_rho(top); stack.push(div); stack.push(top / div); } } factors.sort_unstable(); factors } } pub mod order { pub fn asserting_cmp(a: &T, b: &T) -> std::cmp::Ordering { a.partial_cmp(b).expect(\"Comparing incomparable elements\") } pub fn slice_lower_bound(slice: &[T], key: &T) -> usize { slice .binary_search_by(|x| asserting_cmp(x, key).then(std::cmp::Ordering::Greater)) .unwrap_err() } pub fn slice_upper_bound(slice: &[T], key: &T) -> usize { slice .binary_search_by(|x| asserting_cmp(x, key).then(std::cmp::Ordering::Less)) .unwrap_err() } pub fn merge_sorted( i1: impl IntoIterator, i2: impl IntoIterator, ) -> Vec { let mut i1 = i1.into_iter().peekable(); let mut i2 = i2.into_iter().peekable(); let mut merged = Vec::with_capacity(i1.size_hint().0 + i2.size_hint().0); while let (Some(a), Some(b)) = (i1.peek(), i2.peek()) { merged.push(if a <= b { i1.next() } else { i2.next() }.unwrap()); } merged.extend(i1.chain(i2)); merged } pub fn merge_sort(mut v: Vec) -> Vec { if v.len() < 2 { v } else { let v2 = v.split_off(v.len() / 2); merge_sorted(merge_sort(v), merge_sort(v2)) } } pub struct SparseIndex { coords: Vec, } impl SparseIndex { pub fn new(mut coords: Vec) -> Self { coords.sort_unstable(); coords.dedup(); Self { coords } } pub fn compress(&self, q: i64) -> Result { self.coords.binary_search(&q) } } #[derive(Default)] pub struct PiecewiseLinearConvexFn { recent_lines: Vec<(f64, f64)>, sorted_lines: Vec<(f64, f64)>, intersections: Vec, amortized_work: usize, } impl PiecewiseLinearConvexFn { pub fn max_with(&mut self, new_m: f64, new_b: f64) { self.recent_lines.push((new_m, new_b)); } fn max_with_sorted(&mut self, new_m: f64, new_b: f64) { while let Some(&(last_m, last_b)) = self.sorted_lines.last() { if (new_m - last_m).abs() > 1e-9 { let intersect = (new_b - last_b) / (last_m - new_m); if self.intersections.last() < Some(&intersect) { self.intersections.push(intersect); break; } } self.intersections.pop(); self.sorted_lines.pop(); } self.sorted_lines.push((new_m, new_b)); } fn eval_unoptimized(&self, x: f64) -> f64 { let idx = slice_lower_bound(&self.intersections, &x); self.recent_lines .iter() .chain(self.sorted_lines.get(idx)) .map(|&(m, b)| m * x + b) .max_by(asserting_cmp) .unwrap_or(-1e18) } pub fn evaluate(&mut self, x: f64) -> f64 { self.amortized_work += self.recent_lines.len(); if self.amortized_work > self.sorted_lines.len() { self.amortized_work = 0; self.recent_lines.sort_unstable_by(asserting_cmp); self.intersections.clear(); let all_lines = merge_sorted(self.recent_lines.drain(..), self.sorted_lines.drain(..)); for (new_m, new_b) in all_lines { self.max_with_sorted(new_m, new_b); } } self.eval_unoptimized(x) } } } pub mod range_query { pub mod dynamic_arq { use super::ArqSpec; pub struct DynamicArqNode { val: T::S, app: Option, down: (usize, usize), } impl Clone for DynamicArqNode { fn clone(&self) -> Self { Self { val: self.val.clone(), app: self.app.clone(), down: self.down, } } } impl Default for DynamicArqNode { fn default() -> Self { Self { val: T::identity(), app: None, down: (usize::max_value(), usize::max_value()), } } } impl DynamicArqNode { fn apply(&mut self, f: &T::F, size: i64) { self.val = T::apply(f, &self.val, size); if size > 1 { let h = match self.app { Some(ref g) => T::compose(f, g), None => f.clone(), }; self.app = Some(h); } } } pub type ArqView = (usize, i64); pub struct DynamicArq { nodes: Vec>, is_persistent: bool, } impl DynamicArq { pub fn new(is_persistent: bool) -> Self { Self { nodes: vec![], is_persistent, } } pub fn build_from_identity(&mut self, size: i64) -> ArqView { self.nodes.push(DynamicArqNode::default()); (self.nodes.len() - 1, size) } pub fn build_from_slice(&mut self, init_val: &[T::S]) -> ArqView { if init_val.len() == 1 { let root = DynamicArqNode { val: init_val[0].clone(), ..Default::default() }; self.nodes.push(root); (self.nodes.len() - 1, 1) } else { let ls = init_val.len() / 2; let (l_init, r_init) = init_val.split_at(ls); let l_view = self.build_from_slice(l_init); let r_view = self.build_from_slice(r_init); self.merge_equal_sized(l_view, r_view) } } pub fn merge_equal_sized( &mut self, (lp, ls): ArqView, (rp, rs): ArqView, ) -> ArqView { assert!(ls == rs || ls + 1 == rs); let p = self.nodes.len(); let root = DynamicArqNode { down: (lp, rp), ..Default::default() }; self.nodes.push(root); self.pull(p); (p, ls + rs) } pub fn push(&mut self, (p, s): ArqView) -> (ArqView, ArqView) { if self.nodes[p].down.0 == usize::max_value() { self.nodes.push(DynamicArqNode::default()); self.nodes.push(DynamicArqNode::default()); self.nodes[p].down = (self.nodes.len() - 2, self.nodes.len() - 1) }; let (lp, rp) = self.nodes[p].down; let ls = s / 2; if let Some(ref f) = self.nodes[p].app.take() { self.nodes[lp].apply(f, ls); self.nodes[rp].apply(f, s - ls); } ((lp, ls), (rp, s - ls)) } pub fn pull(&mut self, p: usize) { let (lp, rp) = self.nodes[p].down; let left_val = &self.nodes[lp].val; let right_val = &self.nodes[rp].val; self.nodes[p].val = T::op(left_val, right_val); } fn clone_node(&mut self, p_orig: usize) -> usize { if self.is_persistent { let node = self.nodes[p_orig].clone(); self.nodes.push(node); self.nodes.len() - 1 } else { p_orig } } pub fn update(&mut self, view: ArqView, l: i64, r: i64, f: &T::F) -> ArqView { let (p_orig, s) = view; if r < 0 || s - 1 < l { view } else if l <= 0 && s - 1 <= r { let p_clone = self.clone_node(p_orig); self.nodes[p_clone].apply(f, s); (p_clone, s) } else { let (l_view, r_view) = self.push(view); let ls = l_view.1; let p_clone = self.clone_node(p_orig); let lp_clone = self.update(l_view, l, r, f).0; let rp_clone = self.update(r_view, l - ls, r - ls, f).0; self.nodes[p_clone].down = (lp_clone, rp_clone); self.pull(p_clone); (p_clone, s) } } pub fn query(&mut self, view: ArqView, l: i64, r: i64) -> T::S { let (p, s) = view; if r < 0 || s - 1 < l { T::identity() } else if l <= 0 && s - 1 <= r { self.nodes[p].val.clone() } else { let (l_view, r_view) = self.push(view); let ls = l_view.1; let l_agg = self.query(l_view, l, r); let r_agg = self.query(r_view, l - ls, r - ls); T::op(&l_agg, &r_agg) } } } pub fn first_negative( arq: &mut DynamicArq, view: ArqView, ) -> Option { let (p, s) = view; if s == 1 { Some(0).filter(|_| arq.nodes[p].val < 0) } else { let (l_view, r_view) = arq.push(view); let (lp, ls) = l_view; if arq.nodes[lp].val < 0 { first_negative(arq, l_view) } else { first_negative(arq, r_view).map(|x| ls + x) } } } } pub mod specs { pub trait ArqSpec { type S: Clone; type F: Clone; fn op(a: &Self::S, b: &Self::S) -> Self::S; fn identity() -> Self::S; fn compose(f: &Self::F, g: &Self::F) -> Self::F; fn apply(f: &Self::F, a: &Self::S, size: i64) -> Self::S; } pub enum AssignMin {} impl ArqSpec for AssignMin { type S = i64; type F = i64; fn op(&a: &Self::S, &b: &Self::S) -> Self::S { a.min(b) } fn identity() -> Self::S { i64::max_value() } fn compose(&f: &Self::F, _: &Self::F) -> Self::F { f } fn apply(&f: &Self::F, _: &Self::S, _: i64) -> Self::S { f } } pub enum AssignSum {} impl ArqSpec for AssignSum { type S = i64; type F = i64; fn op(&a: &Self::S, &b: &Self::S) -> Self::S { a + b } fn identity() -> Self::S { 0 } fn compose(&f: &Self::F, _: &Self::F) -> Self::F { f } fn apply(&f: &Self::F, _: &Self::S, size: i64) -> Self::S { f * size } } pub enum SupplyDemand {} impl ArqSpec for SupplyDemand { type S = (i64, i64, i64); type F = (i64, i64); fn op((p1, o1, s1): &Self::S, (p2, o2, s2): &Self::S) -> Self::S { let extra = (p1 - s1).min(o2 - s2); (p1 + p2, o1 + o2, s1 + s2 + extra) } fn identity() -> Self::S { (0, 0, 0) } fn compose(_: &Self::F, _: &Self::F) -> Self::F { unimplemented!() } fn apply(&(p_add, o_add): &Self::F, &(p, o, _): &Self::S, s: i64) -> Self::S { assert_eq!(s, 1); let p = p + p_add; let o = o + o_add; (p, o, p.min(o)) } } } pub mod sqrt_decomp { pub trait MoState { type Q; type A; const L_R_RATIO: f64 = 1.0; fn query(&self, q: &Self::Q) -> Self::A; fn insert_left(&mut self, pos: usize); fn remove_left(&mut self, pos: usize); fn insert_right(&mut self, pos: usize) { self.insert_left(pos); } fn remove_right(&mut self, pos: usize) { self.remove_left(pos); } fn process(&mut self, queries: &[(usize, usize, Self::Q)]) -> Vec { let q = queries.len(); let mut q_positions: Vec = (0..q).collect(); if let Some(max_r) = queries.iter().map(|&(_, r, _)| r).max() { let q_adjusted = q as f64 * Self::L_R_RATIO; let bucket_width = 1 + max_r / q_adjusted.sqrt() as usize; q_positions.sort_unstable_by_key(|&i| { let (l, mut r) = (queries[i].0, queries[i].1); let bucket = l / bucket_width; if bucket % 2 != 0 { r = max_r - r; } (bucket, r) }); } let (mut cur_l, mut cur_r) = (1, 0); let mut answers = Vec::with_capacity(queries.len()); for i in q_positions { let (l, r, ref q) = queries[i]; while cur_l > l { cur_l -= 1; self.insert_left(cur_l); } while cur_r < r { cur_r += 1; self.insert_right(cur_r); } while cur_l < l { self.remove_left(cur_l); cur_l += 1; } while cur_r > r { self.remove_right(cur_r); cur_r -= 1; } answers.push((i, self.query(q))); } answers.sort_unstable_by_key(|&(i, _)| i); answers.into_iter().map(|(_, ans)| ans).collect() } } pub struct DistinctVals { vals: Vec, counts: Vec, distinct: usize, } impl DistinctVals { pub fn new(vals: Vec) -> Self { let &max_val = vals.iter().max().unwrap_or(&0); Self { vals, counts: vec![0; max_val + 1], distinct: 0, } } } impl MoState for DistinctVals { type Q = (); type A = usize; fn query(&self, _: &Self::Q) -> Self::A { self.distinct } fn insert_left(&mut self, pos: usize) { let v = self.vals[pos]; if self.counts[v] == 0 { self.distinct += 1; } self.counts[v] += 1; } fn remove_left(&mut self, pos: usize) { let v = self.vals[pos]; self.counts[v] -= 1; if self.counts[v] == 0 { self.distinct -= 1; } } } } pub mod static_arq { use super::ArqSpec; pub struct StaticArq { val: Vec, app: Vec>, } impl StaticArq { pub fn new(init_val: &[T::S]) -> Self { let size = init_val.len(); let mut val = vec![T::identity(); size]; val.extend_from_slice(init_val); let app = vec![None; size]; let mut arq = Self { val, app }; for p in (0..size).rev() { arq.pull(p); } arq } fn apply(&mut self, p: usize, f: &T::F, s: i64) { self.val[p] = T::apply(f, &self.val[p], s); if let Some(lazy) = self.app.get_mut(p) { let h = match *lazy { Some(ref g) => T::compose(f, g), None => f.clone(), }; *lazy = Some(h); } } fn push(&mut self, p: usize) { if let Some(ref f) = self.app[p].take() { let s = ((self.app.len() + p - 1) / p / 2).next_power_of_two() as i64; self.apply(p << 1, f, s); self.apply(p << 1 | 1, f, s); } } fn pull(&mut self, p: usize) { self.val[p] = T::op(&self.val[p << 1], &self.val[p << 1 | 1]); } fn push_to(&mut self, p: usize) { let one_plus_floor_log_p = (p + 1).next_power_of_two().trailing_zeros(); for i in (1..one_plus_floor_log_p).rev() { self.push(p >> i); } } fn pull_from(&mut self, mut p: usize) { while p > 1 { p >>= 1; self.pull(p); } } pub fn update(&mut self, mut l: usize, mut r: usize, f: &T::F) { l += self.app.len(); r += self.app.len(); if l < r { self.push_to(l); } self.push_to(r); let (mut l0, mut r0, mut s) = (1, 1, 1); while l <= r { if l & 1 == 1 { self.apply(l, f, s); l0 = l0.max(l); l += 1; } if r & 1 == 0 { self.apply(r, f, s); r0 = r0.max(r); r -= 1; } l >>= 1; r >>= 1; s <<= 1; } self.pull_from(l0); self.pull_from(r0); } pub fn query(&mut self, mut l: usize, mut r: usize) -> T::S { l += self.app.len(); r += self.app.len(); if l < r { self.push_to(l); } self.push_to(r); let (mut l_agg, mut r_agg) = (T::identity(), T::identity()); while l <= r { if l & 1 == 1 { l_agg = T::op(&l_agg, &self.val[l]); l += 1; } if r & 1 == 0 { r_agg = T::op(&self.val[r], &r_agg); r -= 1; } l >>= 1; r >>= 1; } T::op(&l_agg, &r_agg) } } pub fn first_negative(arq: &mut StaticArq) -> Option { assert!(arq.app.len().is_power_of_two()); let mut p = 1; if arq.val[p] >= 0 { None } else { while p < arq.app.len() { arq.push(p); p <<= 1; if arq.val[p] >= 0 { p |= 1; } } Some(p - arq.app.len()) } } } pub use self::dynamic_arq::{ArqView, DynamicArq}; pub use self::specs::ArqSpec; pub use self::static_arq::StaticArq; } pub mod rng { pub type SmallRng = Xoshiro256PlusPlus; #[derive(Debug, Clone, PartialEq, Eq)] pub struct Xoshiro256PlusPlus { s: [u64; 4], } impl Xoshiro256PlusPlus { pub fn new(mut state: u64) -> Self { const PHI: u64 = 0x9e3779b97f4a7c15; let mut seed = <[u64; 4]>::default(); for chunk in &mut seed { state = state.wrapping_add(PHI); let mut z = state; z = (z ^ (z >> 30)).wrapping_mul(0xbf58476d1ce4e5b9); z = (z ^ (z >> 27)).wrapping_mul(0x94d049bb133111eb); z = z ^ (z >> 31); *chunk = z; } Self { s: seed } } #[inline] pub fn next_u32(&mut self) -> u32 { (self.next_u64() >> 32) as u32 } #[inline] pub fn next_u64(&mut self) -> u64 { let result_plusplus = self.s[0] .wrapping_add(self.s[3]) .rotate_left(23) .wrapping_add(self.s[0]); let t = self.s[1] << 17; self.s[2] ^= self.s[0]; self.s[3] ^= self.s[1]; self.s[1] ^= self.s[2]; self.s[0] ^= self.s[3]; self.s[2] ^= t; self.s[3] = self.s[3].rotate_left(45); result_plusplus } } } pub mod scanner { use std::io; use std::str; pub struct Scanner { reader: R, buffer: Vec, } impl Scanner { pub fn new(reader: R) -> Self { Self { reader, buffer: vec![], } } pub fn token(&mut self) -> T { loop { if let Some(token) = self.buffer.pop() { return token.parse().ok().expect(\"Failed parse\"); } let mut input = String::new(); self.reader.read_line(&mut input).expect(\"Failed read\"); self.buffer = input.split_whitespace().rev().map(String::from).collect(); } } } pub struct UnsafeScanner { reader: R, buf_str: Vec, buf_iter: str::SplitAsciiWhitespace<'static>, } impl UnsafeScanner { pub fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: \"\".split_ascii_whitespace(), } } pub fn token(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect(\"Failed parse\"); } self.buf_str.clear(); self.reader .read_until(b'\\n', &mut self.buf_str) .expect(\"Failed read\"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_ascii_whitespace()) } } } } pub fn scanner_from_file(filename: &str) -> Scanner> { let file = std::fs::File::open(filename).expect(\"Input file not found\"); Scanner::new(io::BufReader::new(file)) } pub fn writer_to_file(filename: &str) -> io::BufWriter { let file = std::fs::File::create(filename).expect(\"Output file not found\"); io::BufWriter::new(file) } } pub mod printer {} pub mod string_proc { use std::cmp::{max, min}; use std::collections::{hash_map::Entry, HashMap, VecDeque}; pub struct Trie { links: Vec>, } impl Default for Trie { fn default() -> Self { Self { links: vec![HashMap::new()], } } } impl Trie { pub fn insert(&mut self, word: impl IntoIterator) -> usize { let mut node = 0; for ch in word { let len = self.links.len(); node = match self.links[node].entry(ch) { Entry::Occupied(entry) => *entry.get(), Entry::Vacant(entry) => { entry.insert(len); self.links.push(HashMap::new()); len } } } node } pub fn get(&self, word: impl IntoIterator) -> Option { let mut node = 0; for ch in word { node = *self.links[node].get(&ch)?; } Some(node) } } pub struct Matcher<'a, C: Eq> { pub pattern: &'a [C], pub fail: Vec, } impl<'a, C: Eq> Matcher<'a, C> { pub fn new(pattern: &'a [C]) -> Self { let mut fail = Vec::with_capacity(pattern.len()); fail.push(0); let mut len = 0; for ch in &pattern[1..] { while len > 0 && pattern[len] != *ch { len = fail[len - 1]; } if pattern[len] == *ch { len += 1; } fail.push(len); } Self { pattern, fail } } pub fn kmp_match(&self, text: impl IntoIterator) -> Vec { let mut len = 0; text.into_iter() .map(|ch| { if len == self.pattern.len() { len = self.fail[len - 1]; } while len > 0 && self.pattern[len] != ch { len = self.fail[len - 1]; } if self.pattern[len] == ch { len += 1; } len }) .collect() } } pub struct MultiMatcher { pub trie: Trie, pub pat_id: Vec>, pub fail: Vec, pub fast: Vec, } impl MultiMatcher { fn next(trie: &Trie, fail: &[usize], mut node: usize, ch: &C) -> usize { loop { if let Some(&child) = trie.links[node].get(ch) { return child; } else if node == 0 { return 0; } node = fail[node]; } } pub fn new(patterns: impl IntoIterator>) -> Self { let mut trie = Trie::default(); let pat_nodes: Vec = patterns.into_iter().map(|pat| trie.insert(pat)).collect(); let mut pat_id = vec![None; trie.links.len()]; for (i, node) in pat_nodes.into_iter().enumerate() { pat_id[node] = Some(i); } let mut fail = vec![0; trie.links.len()]; let mut fast = vec![0; trie.links.len()]; let mut q: VecDeque = trie.links[0].values().cloned().collect(); while let Some(node) = q.pop_front() { for (ch, &child) in &trie.links[node] { let nx = Self::next(&trie, &fail, fail[node], &ch); fail[child] = nx; fast[child] = if pat_id[nx].is_some() { nx } else { fast[nx] }; q.push_back(child); } } Self { trie, pat_id, fail, fast, } } pub fn ac_match(&self, text: impl IntoIterator) -> Vec { let mut node = 0; text.into_iter() .map(|ch| { node = Self::next(&self.trie, &self.fail, node, &ch); node }) .collect() } pub fn get_end_pos_and_pat_id(&self, match_nodes: &[usize]) -> Vec<(usize, usize)> { let mut res = vec![]; for (text_pos, &(mut node)) in match_nodes.iter().enumerate() { while node != 0 { if let Some(id) = self.pat_id[node] { res.push((text_pos + 1, id)); } node = self.fast[node]; } } res } } pub struct SuffixArray { pub sfx: Vec, pub rank: Vec>, } impl SuffixArray { fn counting_sort( vals: impl Iterator + Clone, val_to_key: &[usize], max_key: usize, ) -> Vec { let mut counts = vec![0; max_key]; for v in vals.clone() { counts[val_to_key[v]] += 1; } let mut total = 0; for c in counts.iter_mut() { total += *c; *c = total - *c; } let mut result = vec![0; total]; for v in vals { let c = &mut counts[val_to_key[v]]; result[*c] = v; *c += 1; } result } pub fn new(text: impl IntoIterator) -> Self { let init_rank = text.into_iter().map(|ch| ch as usize).collect::>(); let n = init_rank.len(); let mut sfx = Self::counting_sort(0..n, &init_rank, 256); let mut rank = vec![init_rank]; for skip in (0..).map(|i| 1 << i).take_while(|&skip| skip < n) { let prev_rank = rank.last().unwrap(); let mut cur_rank = prev_rank.clone(); let pos = (n - skip..n).chain(sfx.into_iter().filter_map(|p| p.checked_sub(skip))); sfx = Self::counting_sort(pos, &prev_rank, max(n, 256)); let mut prev = sfx[0]; cur_rank[prev] = 0; for &cur in sfx.iter().skip(1) { if max(prev, cur) + skip < n && prev_rank[prev] == prev_rank[cur] && prev_rank[prev + skip] == prev_rank[cur + skip] { cur_rank[cur] = cur_rank[prev]; } else { cur_rank[cur] = cur_rank[prev] + 1; } prev = cur; } rank.push(cur_rank); } Self { sfx, rank } } pub fn longest_common_prefix(&self, mut i: usize, mut j: usize) -> usize { let mut len = 0; for (k, rank) in self.rank.iter().enumerate().rev() { if rank[i] == rank[j] { i += 1 << k; j += 1 << k; len += 1 << k; if max(i, j) >= self.sfx.len() { break; } } } len } } pub fn palindromes(text: &[impl Eq]) -> Vec { let mut pal = Vec::with_capacity(2 * text.len() - 1); pal.push(1); while pal.len() < pal.capacity() { let i = pal.len() - 1; let max_len = min(i + 1, pal.capacity() - i); while pal[i] < max_len && text[(i - pal[i] - 1) / 2] == text[(i + pal[i] + 1) / 2] { pal[i] += 2; } if let Some(a) = 1usize.checked_sub(pal[i]) { pal.push(a); } else { for d in 1.. { let (a, b) = (pal[i - d], pal[i] - d); if a < b { pal.push(a); } else { pal.push(b); break; } } } } pal } pub fn z_algorithm(text: &[impl Eq]) -> Vec { let n = text.len(); let (mut l, mut r) = (1, 1); let mut z = Vec::with_capacity(n); z.push(n); for i in 1..n { if r > i + z[i - l] { z.push(z[i - l]); } else { l = i; while r < i || (r < n && text[r - i] == text[r]) { r += 1; } z.push(r - i); } } z } } } use algo::scanner::UnsafeScanner; static mut SCANNER: MaybeUninit> = MaybeUninit::uninit(); static mut WRITER: MaybeUninit> = MaybeUninit::uninit(); pub const YES: &str = \"YES\"; pub const NO: &str = \"NO\"; pub fn init() { unsafe { let scanner = UnsafeScanner::new(transmute::>( io::stdin().lock(), )); SCANNER.as_mut_ptr().write(scanner); let writer = io::BufWriter::new(transmute::>( io::stdout().lock(), )); WRITER.as_mut_ptr().write(writer); } } #[cfg(generator)] pub fn r< T: rand::distributions::uniform::SampleUniform, R: rand::distributions::uniform::SampleRange, >( r: R, ) -> T { use rand::Rng; rand::thread_rng().gen_range(r) } #[inline(always)] pub fn __scanner() -> &'static mut UnsafeScanner> { unsafe { &mut *SCANNER.as_mut_ptr() } } #[inline(always)] pub fn __writer() -> &'static mut io::BufWriter> { unsafe { &mut *WRITER.as_mut_ptr() } } pub fn flush() { __writer().flush().unwrap(); } #[macro_export] macro_rules! main { (multi) => { fn main() { $crate::init(); input!(t: usize); for _ in 0..t { solve(); } $crate::flush(); } }; (multi , intr) => { fn main() { $crate::init(); input!(t: usize); for _ in 0..t { solve(); $crate::flush(); } } }; () => { fn main() { $crate::init(); solve(); $crate::flush(); } }; } #[macro_export] macro_rules! flush { () => { $crate::flush(); }; } #[macro_export] macro_rules ! input { ($ ($ r : tt) *) => { let sc = $ crate :: __scanner () ; input_inner ! { sc , $ ($ r) * } } ; } #[macro_export] macro_rules ! input_inner { ($ sc : expr) => { } ; ($ sc : expr ,) => { } ; ($ sc : expr , $ var : ident : $ t : tt $ ($ r : tt) *) => { # [allow (unused_mut)] let mut $ var = read_value ! ($ sc , $ t) ; input_inner ! { $ sc $ ($ r) * } } ; } #[macro_export] macro_rules ! read_value { ($ sc : expr , ($ ($ t : tt) ,*)) => { ($ (read_value ! ($ sc , $ t)) ,*) } ; ($ sc : expr , [$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | read_value ! ($ sc , $ t)) . collect ::< Vec < _ >> () } ; ($ sc : expr , c) => { read_value ! ($ sc , String) . chars () . collect ::< Vec < char >> () } ; ($ sc : expr , b) => { read_value ! ($ sc , String) . into_bytes () } ; ($ sc : expr , u1) => { read_value ! ($ sc , usize) - 1 } ; ($ sc : expr , $ t : ty) => { $ sc . token ::<$ t > () } ; } #[macro_export] macro_rules ! println { ($ ($ args : tt) *) => { { use std :: io :: Write ; writeln ! ($ crate :: __writer () , $ ($ args) *) . unwrap () } } ; } #[macro_export] macro_rules ! print { ($ ($ args : tt) *) => { { use std :: io :: Write ; write ! ($ crate :: __writer () , $ ($ args) *) . unwrap () } } ; } #[macro_export] macro_rules ! out { () => { } ; ($ e : expr) => { print ! (\"{}\" , $ e) ; } ; ($ e : expr , $ ($ es : expr) ,*) => { out ! ($ e) ; out ! (\" \") ; out ! ($ ($ es) ,*) ; } ; } #[macro_export] macro_rules ! outln { ($ ($ args : tt) *) => { { out ! ($ ($ args) *) ; println ! () ; } } ; } pub fn out_spaced(it: impl IntoIterator) { let mut first = true; for v in it { if !first { print!(\" {}\", v); } else { print!(\"{}\", v); first = false; } } } pub fn out_lined(it: impl IntoIterator) { let mut first = true; for v in it { if !first { print!(\"\\n{}\", v); } else { print!(\"{}\", v); first = false; } } } pub fn yn(yes: bool) -> &'static str { if yes { \"YES\" } else { \"NO\" } } #[macro_export] macro_rules ! ans { ($ ($ args : tt) *) => { output ! ($ ($ args) *;) ; return ; } ; } #[macro_export] macro_rules ! output { (; $ ($ r : tt) *) => { println ! () ; output ! ($ ($ r) *) ; } ; ($ x : expr ,* $ ($ r : tt) *) => { $ crate :: out_spaced ($ x) ; output ! ($ ($ r) *) ; } ; ($ x : expr ;* $ ($ r : tt) *) => { $ crate :: out_lined ($ x) ; output ! ($ ($ r) *) ; } ; ($ x : expr , $ ($ r : tt) *) => { out ! ($ x) ; print ! (\" \") ; output ! ($ ($ r) *) ; } ; ($ x : expr ; $ ($ r : tt) *) => { out ! ($ x) ; println ! () ; output ! ($ ($ r) *) ; } ; ($ x : expr) => { print ! (\"{}\" , $ x) ; } ; () => { } ; } #[macro_export] macro_rules ! cmp_go { (@ go $ a : ident , $ b : ident , .$ x : tt , $ ($ tt : tt) *) => { match ($ a .$ x) . cmp (& ($ b .$ x)) { std :: cmp :: Ordering :: Equal => cmp_go ! (@ go $ a , $ b , $ ($ tt) *) , ordering => ordering } } ; (@ go $ a : ident , $ b : ident , .$ x : tt) => { cmp_go ! (@ go $ a , $ b , .$ x ,) } ; (@ go $ a : ident , $ b : ident , $ x : expr ,) => { cmp_go ! (@ go $ a , $ b , $ x ,) } ; (@ go $ a : ident , $ b : ident , $ x : expr , $ ($ tt : tt) *) => { match $ x { mut x => match (x ($ a)) . cmp (& (x (&$ b))) { std :: cmp :: Ordering :: Equal => cmp_go ! (@ go $ a , $ b , $ ($ tt) *) , ordering => ordering } } } ; (@ go $ a : ident , $ b : ident , $ x : tt , $ ($ tt : tt) *) => { match ($ x ($ a)) . cmp (& ($ x (&$ b))) { std :: cmp :: Ordering :: Equal => cmp_go ! (@ go $ a , $ b , $ ($ tt) *) , ordering => ordering } } ; (@ go $ a : ident , $ b : ident ,) => { std :: cmp :: Ordering :: Equal } ; } #[macro_export(local_inner_macros)] macro_rules ! cmp { ($ ($ tt : tt) *) => { | a , b | { cmp_go ! (@ go a , b , $ ($ tt) *) } } ; } pub trait IExt { fn i(self) -> i64; } impl IExt for usize { fn i(self) -> i64 { self as i64 } } pub trait UExt { fn u(self) -> usize; } impl UExt for usize { fn u(self) -> usize { self } } impl UExt for i64 { fn u(self) -> usize { self as usize } } impl UExt for i32 { fn u(self) -> usize { self as usize } } pub fn freq_map(v: &[t]) -> m { let mut m = m::new(); for x in v { *m.entry(*x).or_default() += 1; } m } #[macro_export] macro_rules ! query { ($ ($ name : ident ($ ($ arg : ident) ,*) : $ ret : ty = $ query : expr ;) *) => { $ (pub fn $ name ($ ($ arg : impl :: std :: fmt :: Display) ,*) -> $ ret { println ! ($ query , $ ($ arg) ,*) ; $ crate :: flush () ; input ! (v : $ ret) ; v }) * } ; } #[macro_export] macro_rules! rand { ($ ($ name : ident = $ value : expr ;) *) => {}; } #[macro_export] macro_rules ! cp { ($ (kind = multi ;) ? input { $ ($ input : tt) * } $ (rand { $ ($ rand : tt) * }) ? $ (query { $ ($ query : tt) * }) ? $ (pre { $ ($ pre : tt) * }) ? $ (naive { $ ($ naive : tt) * }) ? solve $ solve : expr) => { $ (__random ! { $ ($ rand) * }) ? $ (query ! { $ ($ query) * }) ? # [cfg (not (generator))] fn main () { $ crate :: init () ; $ ($ ($ pre) *) ? input ! (t : usize) ; for _ in 0 .. t { input ! { $ ($ input) * } (|| { # [cfg (naive)] { $ ($ ($ naive) *) ? } # [cfg (not (naive))] { $ solve } }) () ; $ crate :: flush () ; } } # [cfg (generator)] fn main () { $ crate :: init () ; println ! (\"{}\" , 1) ; __generate_input ! { $ ($ input) * } $ crate :: flush () ; } } ; (kind = single ; input { $ ($ input : tt) * } $ (rand { $ ($ rand : tt) * }) ? $ (query { $ ($ query : tt) * }) ? $ (pre { $ ($ pre : tt) * }) ? $ (naive { $ ($ naive : tt) * }) ? solve { $ ($ solve : tt) * }) => { $ (__random ! { $ ($ rand) * }) ? $ (query ! { $ ($ query) * }) ? # [cfg (not (generator))] fn main () { $ crate :: init () ; $ ($ ($ pre) *) ? input ! { $ ($ input) * } (|| { # [cfg (naive)] { $ ($ ($ naive) *) ? } # [cfg (not (naive))] { $ ($ solve) * } }) () ; $ crate :: flush () ; } # [cfg (generator)] fn main () { $ crate :: init () ; __generate_input ! { $ ($ input) * } $ crate :: flush () ; } } ; } #[macro_export] macro_rules ! __random { ($ ($ name : ident = $ value : expr ;) *) => { macro_rules ! __get_random_value { $ (($ name) => { $ value } ;) * } } } #[macro_export] macro_rules ! __generate_input { ($ ($ name : ident : $ ty : tt) ,* $ (,) ?) => { $ (__generate_value ! { $ name : $ ty }) * } } #[macro_export] macro_rules! __print_value { ($ name : ident : ($ a : ty , $ b : ty)) => { println!(\"{} {}\", $name.0, $name.1); }; ($ name : ident : ($ a : ty , $ b : ty , $ c : ty)) => { println!(\"{} {} {}\", $name.0, $name.1, $name.2); }; ($ name : ident : ($ a : ty , $ b : ty , $ c : ty , $ d : ty)) => { println!(\"{} {} {} {}\", $name.0, $name.1, $name.2, $name.3); }; ($ name : ident : $ ty : ty) => { println!(\"{}\", $name); }; } #[macro_export] macro_rules! __generate_value { ($ var : ident : [$ t : tt ; $ len : expr]) => { for _ in 0..$len { __generate_value!($var: $t); } }; ($ var : ident : $ t : tt) => { let $var: $t = __get_random_value!($var); __print_value!($var: $t); }; } #[macro_export] macro_rules! dp { ($ t : block) => { macro_rules! solve { () => { $t }; } }; } pub fn yc R>(f: &F) -> impl Fn(T) -> R + '_ { move |x| f(f, x) } #[macro_export] macro_rules ! yc { ($ this : ident = |$ ($ arg : ident : $ ($ ty : ty) ?) ,*| $ (-> $ ret : ty) ? $ body : block) => { let $ this = $ crate :: yc (|$ this , $ ($ arg : $ ($ ty) ?) ,*| $ (-> $ ret) ? $ body) ; } ; } \n"}, {"source_code": "use std::{io, usize};\r\n\r\n#[allow(dead_code)]\r\nfn gets() -> String {\r\n let mut s = String::new();\r\n io::stdin().read_line(&mut s).unwrap();\r\n s.trim().to_string()\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_vec {\r\n ($ty:ty) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n let mut v = Vec::new();\r\n while let Some(value) = it.next() {\r\n v.push(value.parse::<$ty>().unwrap());\r\n }\r\n v\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read {\r\n ( $ty:ty) => {\r\n gets().split_whitespace().next().unwrap().parse::<$ty>().unwrap()\r\n };\r\n ( $($ty:ty),* ) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )\r\n }};\r\n ( $( $ty:ty ),+ ,) => {\r\n\t\tread![ $( $ty ),* ]\r\n };\r\n}\r\nuse std::collections::BTreeSet;\r\nfn main() {\r\n let _ = read!(usize);\r\n let mut a = read_vec!(i32);\r\n let mut set = BTreeSet::new();\r\n set.insert(0);\r\n for x in &a {\r\n let mut tmp = BTreeSet::new();\r\n for y in set.iter() {\r\n tmp.insert(y + x);\r\n }\r\n for y in tmp.iter() {\r\n set.insert(*y);\r\n }\r\n }\r\n let mut sum = 0;\r\n for x in &a {\r\n sum += x;\r\n }\r\n if sum % 2 == 0 && set.contains(&(sum / 2)) {\r\n println!(\"1\");\r\n loop {\r\n match a.iter().position(|a| a % 2 != 0) {\r\n Some(ans) => {\r\n println!(\"{}\", ans + 1);\r\n break;\r\n }\r\n None => {\r\n for i in 0..a.len() {\r\n a[i] /= 2;\r\n }\r\n }\r\n }\r\n }\r\n } else {\r\n println!(\"0\");\r\n }\r\n}\r\n"}, {"source_code": "// codesnip-guard: main\nfn main() {\n #![allow(unused_imports, unused_macros)]\n prepare_io!(_in_buf, scanner, _out);\n macro_rules ! print { ($ ($ arg : tt) *) => (:: std :: write ! (_out , $ ($ arg) *) . expect (\"io error\")) }\n macro_rules ! println { ($ ($ arg : tt) *) => (:: std :: writeln ! (_out , $ ($ arg) *) . expect (\"io error\")) }\n scan!(scanner, n, a: [usize; n]);\n let s: usize = a.iter().cloned().sum();\n if s % 2 == 0 {\n let mut dp = vec![false; 2001 * n];\n dp[0] = true;\n for a in a.iter().cloned() {\n for i in (0..dp.len().saturating_sub(a + 1)).rev() {\n dp[i + a] |= dp[i];\n }\n }\n if dp[s / 2] {\n println!(\"{}\", 1);\n let i = (0..n).min_by_key(|&i| a[i].trailing_zeros()).unwrap();\n println!(\"{}\", i + 1);\n } else {\n println!(\"{}\", 0);\n }\n } else {\n println!(\"{}\", 0);\n }\n}\n#[macro_export]\nmacro_rules! prepare_io {\n ($ in_buf : ident , $ scanner : ident , $ out : ident) => {\n use std::io::{stdout, BufWriter, Write as _};\n let $in_buf = read_stdin_all_unchecked();\n let mut $scanner = Scanner::new(&$in_buf);\n let $out = stdout();\n let mut $out = BufWriter::new($out.lock());\n };\n}\n// codesnip-guard: _echo\npub fn echo(\n mut writer: impl std::io::Write,\n iter: impl IntoIterator,\n sep: impl std::fmt::Display,\n) -> std::io::Result<()> {\n let mut iter = iter.into_iter();\n if let Some(item) = iter.next() {\n write!(writer, \"{}\", item)?;\n }\n for item in iter {\n write!(writer, \"{}{}\", sep, item)?;\n }\n writeln!(writer)\n}\n// codesnip-guard: scanner\npub fn read_stdin_all_unchecked() -> String {\n use std::io::Read as _;\n let mut buf = Vec::new();\n std::io::stdin().read_to_end(&mut buf).expect(\"io error\");\n unsafe { String::from_utf8_unchecked(buf) }\n}\npub fn read_stdin_line() -> String {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).expect(\"io error\");\n s\n}\npub trait IterScan: Sized {\n type Output;\n fn scan<'a, I: Iterator>(iter: &mut I) -> Option;\n}\npub trait MarkedIterScan: Sized {\n type Output;\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option;\n}\n#[derive(Clone, Debug)]\npub struct Scanner<'a> {\n iter: std::str::SplitAsciiWhitespace<'a>,\n}\nmod scanner_impls {\n use super::*;\n impl<'a> Scanner<'a> {\n #[inline]\n pub fn new(s: &'a str) -> Self {\n let iter = s.split_ascii_whitespace();\n Self { iter }\n }\n #[inline]\n pub fn scan(&mut self) -> ::Output {\n ::scan(&mut self.iter).expect(\"scan error\")\n }\n #[inline]\n pub fn mscan(&mut self, marker: T) -> ::Output {\n marker.mscan(&mut self.iter).expect(\"scan error\")\n }\n #[inline]\n pub fn scan_vec(&mut self, size: usize) -> Vec<::Output> {\n (0..size)\n .map(|_| ::scan(&mut self.iter).expect(\"scan error\"))\n .collect()\n }\n #[inline]\n pub fn iter<'b, T: IterScan>(&'b mut self) -> ScannerIter<'a, 'b, T> {\n ScannerIter {\n inner: self,\n _marker: std::marker::PhantomData,\n }\n }\n }\n macro_rules ! iter_scan_impls { ($ ($ t : ty) *) => { $ (impl IterScan for $ t { type Output = Self ; # [inline] fn scan <'a , I : Iterator < Item = &'a str >> (iter : & mut I) -> Option < Self > { iter . next () ?. parse ::<$ t > () . ok () } }) * } ; }\n iter_scan_impls ! (char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String);\n macro_rules ! iter_scan_tuple_impl { ($ ($ T : ident) *) => { impl <$ ($ T : IterScan) ,*> IterScan for ($ ($ T ,) *) { type Output = ($ (<$ T as IterScan >:: Output ,) *) ; # [inline] fn scan <'a , It : Iterator < Item = &'a str >> (_iter : & mut It) -> Option < Self :: Output > { Some (($ (<$ T as IterScan >:: scan (_iter) ?,) *)) } } } ; }\n iter_scan_tuple_impl!();\n iter_scan_tuple_impl!(A);\n iter_scan_tuple_impl ! (A B);\n iter_scan_tuple_impl ! (A B C);\n iter_scan_tuple_impl ! (A B C D);\n iter_scan_tuple_impl ! (A B C D E);\n iter_scan_tuple_impl ! (A B C D E F);\n iter_scan_tuple_impl ! (A B C D E F G);\n iter_scan_tuple_impl ! (A B C D E F G H);\n iter_scan_tuple_impl ! (A B C D E F G H I);\n iter_scan_tuple_impl ! (A B C D E F G H I J);\n iter_scan_tuple_impl ! (A B C D E F G H I J K);\n pub struct ScannerIter<'a, 'b, T> {\n inner: &'b mut Scanner<'a>,\n _marker: std::marker::PhantomData T>,\n }\n impl<'a, 'b, T: IterScan> Iterator for ScannerIter<'a, 'b, T> {\n type Item = ::Output;\n #[inline]\n fn next(&mut self) -> Option {\n ::scan(&mut self.inner.iter)\n }\n }\n}\n#[derive(Debug, Copy, Clone)]\npub struct Usize1;\n#[derive(Debug, Copy, Clone)]\npub struct CharWithBase(pub char);\n#[derive(Debug, Copy, Clone)]\npub struct Chars;\n#[derive(Debug, Copy, Clone)]\npub struct CharsWithBase(pub char);\n#[derive(Debug, Copy, Clone)]\npub struct Collect::Output>> {\n size: usize,\n _marker: std::marker::PhantomData (T, B)>,\n}\nmod marker_impls {\n use super::*;\n use std::{iter::FromIterator, marker::PhantomData};\n impl IterScan for Usize1 {\n type Output = usize;\n #[inline]\n fn scan<'a, I: Iterator>(iter: &mut I) -> Option {\n ::scan(iter)?.checked_sub(1)\n }\n }\n impl MarkedIterScan for CharWithBase {\n type Output = usize;\n #[inline]\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option {\n Some((::scan(iter)? as u8 - self.0 as u8) as usize)\n }\n }\n impl IterScan for Chars {\n type Output = Vec;\n #[inline]\n fn scan<'a, I: Iterator>(iter: &mut I) -> Option {\n Some(iter.next()?.chars().collect())\n }\n }\n impl MarkedIterScan for CharsWithBase {\n type Output = Vec;\n #[inline]\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option {\n Some(\n iter.next()?\n .chars()\n .map(|c| (c as u8 - self.0 as u8) as usize)\n .collect(),\n )\n }\n }\n impl::Output>> Collect {\n pub fn new(size: usize) -> Self {\n Self {\n size,\n _marker: PhantomData,\n }\n }\n }\n impl::Output>> MarkedIterScan for Collect {\n type Output = B;\n #[inline]\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option {\n Some(\n (0..self.size)\n .map(|_| ::scan(iter).expect(\"scan error\"))\n .collect::(),\n )\n }\n }\n}\n#[macro_export]\nmacro_rules ! scan_value { ($ scanner : expr , ($ ($ t : tt) ,*)) => { ($ ($ crate :: scan_value ! ($ scanner , $ t)) ,*) } ; ($ scanner : expr , [$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | $ crate :: scan_value ! ($ scanner , $ t)) . collect ::< Vec < _ >> () } ; ($ scanner : expr , [$ t : ty ; $ len : expr]) => { $ scanner . scan_vec ::<$ t > ($ len) } ; ($ scanner : expr , [$ t : ty]) => { $ scanner . iter ::<$ t > () } ; ($ scanner : expr , { $ e : expr }) => { $ scanner . mscan ($ e) } ; ($ scanner : expr , $ t : ty) => { $ scanner . scan ::<$ t > () } ; }\n#[macro_export]\nmacro_rules ! scan { ($ scanner : expr) => { } ; ($ scanner : expr ,) => { } ; ($ scanner : expr , mut $ var : tt : $ t : tt) => { let mut $ var = $ crate :: scan_value ! ($ scanner , $ t) ; } ; ($ scanner : expr , $ var : tt : $ t : tt) => { let $ var = $ crate :: scan_value ! ($ scanner , $ t) ; } ; ($ scanner : expr , mut $ var : tt : $ t : tt , $ ($ rest : tt) *) => { let mut $ var = $ crate :: scan_value ! ($ scanner , $ t) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , $ var : tt : $ t : tt , $ ($ rest : tt) *) => { let $ var = $ crate :: scan_value ! ($ scanner , $ t) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , mut $ var : tt) => { let mut $ var = $ crate :: scan_value ! ($ scanner , usize) ; } ; ($ scanner : expr , $ var : tt) => { let $ var = $ crate :: scan_value ! ($ scanner , usize) ; } ; ($ scanner : expr , mut $ var : tt , $ ($ rest : tt) *) => { let mut $ var = $ crate :: scan_value ! ($ scanner , usize) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , $ var : tt , $ ($ rest : tt) *) => { let $ var = $ crate :: scan_value ! ($ scanner , usize) ; scan ! ($ scanner , $ ($ rest) *) } ; }\n"}, {"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\nfn run() {\r\n input! {\r\n n: usize,\r\n a: [usize; n],\r\n }\r\n let s = a.iter().sum::();\r\n let mut dp = vec![0; s + 1];\r\n dp[0] = 1u32;\r\n for &a in a.iter() {\r\n for i in (a..=s).rev() {\r\n dp[i] = dp[i].saturating_add(dp[i - a]);\r\n }\r\n }\r\n if s % 2 == 1 || dp[s / 2] == 0 {\r\n println!(\"0\");\r\n return;\r\n }\r\n for d in 0.. {\r\n let d = 2usize.pow(d);\r\n if let Some(x) = a.iter().position(|a| *a / d % 2 == 1) {\r\n println!(\"1\\n{}\", x + 1);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"source_code": "//spnauti-rusT {{{\n#[allow(unused_imports)]use std::{io::*,collections::*,fmt::Debug,str::{self,*},cmp::Ordering,ops::{self,*},iter::{self,*}};\n#[allow(unused_macros)]macro_rules!min{($x:expr,$y:expr)=>{let b=$y;let a=&mut$x;if b<*a{*a=b;true}else{false}};}\n#[allow(unused_macros)]macro_rules!max{($x:expr,$y:expr)=>{let b=$y;let a=&mut$x;if b>*a{*a=b;true}else{false}};}\n#[allow(unused_macros)]macro_rules!l{\n\t($($v:ident),+:$t:ty=$e:expr)=>{$(let$v:$t=$e;)+};(mut $($v:ident),+ =$e:expr)=>{$(let mut$v=$e;)+};\n\t(mut $($v:ident),+:$t:ty=$e:expr)=>{$(let mut$v:$t=$e;)+};($($v:ident),+ =$e:expr)=>{$(let$v=$e;)+};\n}#[allow(unused_macros)]macro_rules!v{([$d:expr]$($s:tt)+)=>{vec![v!($($s)+);$d]};\n\t([])=>{Vec::new()};([$e:expr])=>{Vec::with_capacity($e)};(=$e:expr)=>{$e};\n}#[allow(unused_macros)]macro_rules!rp{{[$c:expr]$($s:tt)+}=>(for _ in 0..$c{$($s)+})}\n#[allow(dead_code)]fn rio()->(Reader,BufWriter){(Reader::new(),BufWriter::new(stdout()))}\nstruct Reader{buf:Vec,pos:usize,q:StdinLock<'static>}//'\n#[allow(dead_code)]impl Reader{\n\tfn new()->Self{let r=unsafe{&*Box::into_raw(Box::new(stdin()))};Self{q:r.lock(),buf:v!([]),pos:0}}\n\tfn next_line(&mut self)->bool{self.buf.clear();self.pos=0;self.q.read_until(b'\\n',&mut self.buf).unwrap_or(0)>0}\n\tfn is_ws(c:u8)->bool{c==b' '||c==b'\\n'||c==b'\\r'||c==b'\\t'}\n\tfn byte(&mut self) -> Option {\n\t\tif self.pos==self.buf.len(){if!self.next_line(){return None;}}self.pos+=1;Some(self.buf[self.pos-1])\n\t}\n\tfn vb(&mut self)->Vec{\n\t\tlet mut s=v!([10]);let mut f=false;while let Some(c)=self.byte()\n\t\t{if!Self::is_ws(c){s.push(c);f=true;}else if f{break;}}s\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\trp!{[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\trp!{[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][]); rp!{[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][]);rp!{[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//----------}}}\n\nfn gcd(a: i32, b: i32) -> i32 {\n\tif b == 0 {a} else {gcd(b, a%b)}\n}\n\nfn main() {\n\tlet (mut rin,mut rout) = rio();\n\n\tlet n = rin.u();\n\tlet mut a = rin.vi(n);\n\tlet mut g = 0;\n\tfor &x in a.iter() {\n\t\tg = gcd(g, x);\n\t}\n\tfor x in a.iter_mut() {\n\t\t*x /= g;\n\t}\n\tlet sum: i32 = a.iter().sum();\n\tlet mut ans = None;\n\tif sum % 2 == 0 {\n\t\tlet s = (sum/2) as usize;\n\t\tlet mut dp = v!([s+1] = false);\n\t\tdp[0] = true;\n\t\tfor i in 0..n {\n\t\t\tlet b = a[i] as usize;\n\t\t\tfor j in (b..=s).rev() {\n\t\t\t\tdp[j] |= dp[j-b];\n\t\t\t}\n\t\t}\n\t\tif dp[s] {\n\t\t\tfor i in 0..n {\n\t\t\t\tif a[i] % 2 == 1 {\n\t\t\t\t\tans = Some(i+1);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif let Some(x) = ans {\n\t\twriteln!(rout, \"1\\n{}\", x).unwrap();\n\t} else {\n\t\twriteln!(rout, \"0\").unwrap();\n\t}\n}\n"}, {"source_code": "use std::io::{self, Write};\r\n\r\nfn main() {\r\n let (stdin, stdout) = (io::stdin(), io::stdout());\r\n let mut sc = cf_scanner::Scanner::new(stdin.lock());\r\n let mut out = io::BufWriter::new(stdout.lock());\r\n\r\n let n: usize = sc.next();\r\n let mut a: Vec = sc.next_vec(n);\r\n\r\n let mut can_reach: Vec = vec![false; n * 2000 + 10];\r\n can_reach[0] = true;\r\n for i in 0..n {\r\n for j in (0..can_reach.len()).rev() {\r\n if j < a[i] {\r\n continue;\r\n }\r\n can_reach[j] |= can_reach[j - a[i]];\r\n }\r\n }\r\n\r\n let s: usize = a.iter().sum();\r\n\r\n if s % 2 == 1 || !can_reach[s / 2] {\r\n writeln!(out, \"0\").unwrap();\r\n return;\r\n }\r\n\r\n let mut ans: usize = 0;\r\n let mut to_make: usize = 31;\r\n for i in 0..n {\r\n let mut c: usize = 0;\r\n while a[i] % 2 == 0 {\r\n c += 1;\r\n a[i] /= 2;\r\n }\r\n if c < to_make {\r\n to_make = c;\r\n ans = i;\r\n }\r\n }\r\n writeln!(out, \"1\\n{}\", ans + 1).unwrap();\r\n}\r\n\r\n#[allow(dead_code)]\r\nmod cf_scanner {\r\n use std::io;\r\n use std::str::{FromStr, SplitAsciiWhitespace};\r\n\r\n pub struct Scanner {\r\n reader: R,\r\n buf_str: Vec,\r\n buf_iter: SplitAsciiWhitespace<'static>,\r\n }\r\n\r\n impl Scanner {\r\n pub fn new(reader: R) -> Scanner {\r\n Scanner {\r\n reader,\r\n buf_str: Vec::new(),\r\n buf_iter: \"\".split_ascii_whitespace(),\r\n }\r\n }\r\n\r\n pub fn next(&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 = std::str::from_utf8_unchecked(&self.buf_str);\r\n std::mem::transmute(slice.split_ascii_whitespace())\r\n }\r\n }\r\n }\r\n\r\n pub fn next_vec(&mut self, n: usize) -> Vec {\r\n (0..n).map(|_| self.next()).collect()\r\n }\r\n }\r\n}\r\n"}, {"source_code": "#![allow(unused_imports, unused_macros)]\n\nuse kyoproio::*;\nuse std::{\n collections::*,\n io::{self, prelude::*},\n iter, mem,\n};\n\nfn run(mut kin: I, mut out: O) {\n let t: usize = 1; // kin.parse();\n for _ in 0..t {\n case(&mut kin, &mut out);\n }\n}\n\nfn case(mut kin: I, mut out: O) {\n let n: usize = kin.parse();\n let a: Vec = kin.collect(n);\n let sum: i32 = a.iter().sum();\n let mut s = vec![false; sum as usize + 1];\n s[0] = true;\n for &a in &a {\n let a = a as usize;\n for i in (0..s.len() - a).rev() {\n s[i + a] |= s[i];\n }\n }\n d!(s);\n if sum % 2 == 1 || !s[sum as usize / 2] {\n wln!(out, \"0\");\n return;\n }\n for k in 0.. {\n for (i, &a) in a.iter().enumerate() {\n if a & 1 << k != 0 {\n wln!(out, \"1\");\n wln!(out, \"{}\", i + 1);\n return;\n }\n }\n }\n}\n\n// -----------------------------------------------------------------------------\nfn main() -> io::Result<()> {\n std::thread::Builder::new()\n .stack_size(1 << 26)\n .spawn(|| {\n run(\n Scanner::new(io::stdin().lock()),\n io::BufWriter::new(io::stdout().lock()),\n )\n })?\n .join()\n .unwrap();\n Ok(())\n}\n\n#[macro_export]\nmacro_rules! w {\n ($($arg:tt)*) => { write!($($arg)*).unwrap(); }\n}\n#[macro_export]\nmacro_rules! wln {\n ($dst:expr $(, $($arg:tt)*)?) => {{\n writeln!($dst $(, $($arg)*)?).unwrap();\n #[cfg(debug_assertions)]\n $dst.flush().unwrap();\n }}\n}\n#[macro_export]\nmacro_rules! w_iter {\n ($dst:expr, $fmt:expr, $iter:expr, $delim:expr) => {{\n let mut first = true;\n for elem in $iter {\n if first {\n w!($dst, $fmt, elem);\n first = false;\n } else {\n w!($dst, concat!($delim, $fmt), elem);\n }\n }\n }};\n ($dst:expr, $fmt:expr, $iter:expr) => {\n w_iter!($dst, $fmt, $iter, \" \")\n };\n}\n#[macro_export]\nmacro_rules! w_iter_ln {\n ($dst:expr, $($t:tt)*) => {{\n w_iter!($dst, $($t)*);\n wln!($dst);\n }}\n}\n#[macro_export]\nmacro_rules! e {\n ($($t:tt)*) => {\n #[cfg(debug_assertions)]\n eprint!($($t)*)\n }\n}\n#[macro_export]\nmacro_rules! eln {\n ($($t:tt)*) => {\n #[cfg(debug_assertions)]\n eprintln!($($t)*)\n }\n}\n#[macro_export]\nmacro_rules! __tstr {\n ($h:expr $(, $t:expr)+) => { concat!(__tstr!($($t),+), \", \", __tstr!(@)) };\n ($h:expr) => { concat!(__tstr!(), \" \", __tstr!(@)) };\n () => { \"\\x1B[94m[{}:{}]\\x1B[0m\" };\n (@) => { \"\\x1B[1;92m{}\\x1B[0m = {:?}\" }\n}\n#[macro_export]\nmacro_rules! d {\n ($($a:expr),*) => { eln!(__tstr!($($a),*), file!(), line!(), $(stringify!($a), $a),*) };\n}\n\npub mod kyoproio {\n use std::{\n fmt::Display,\n io::{self, prelude::*},\n iter::FromIterator,\n marker::PhantomData,\n mem::{self, MaybeUninit},\n str,\n };\n\n pub trait Input {\n fn bytes(&mut self) -> &[u8];\n fn str(&mut self) -> &str {\n str::from_utf8(self.bytes()).unwrap()\n }\n fn parse(&mut self) -> T {\n T::parse(self)\n }\n fn parse_iter(&mut self) -> ParseIter {\n ParseIter(self, PhantomData)\n }\n fn collect>(&mut self, n: usize) -> B {\n self.parse_iter().take(n).collect()\n }\n fn map U, B: FromIterator>(&mut self, n: usize, f: F) -> B {\n self.parse_iter().take(n).map(f).collect()\n }\n }\n impl Input for &mut I {\n fn bytes(&mut self) -> &[u8] {\n (**self).bytes()\n }\n }\n pub struct Scanner {\n src: R,\n buf: Vec,\n pos: usize,\n len: usize,\n }\n impl Scanner {\n pub fn new(src: R) -> Self {\n Self {\n src,\n buf: vec![0; 1 << 16],\n pos: 0,\n len: 0,\n }\n }\n fn read(&mut self) -> usize {\n if self.pos > 0 {\n self.buf.copy_within(self.pos..self.len, 0);\n self.len -= self.pos;\n self.pos = 0;\n } else if self.len >= self.buf.len() {\n self.buf.resize(2 * self.buf.len(), 0);\n }\n let n = self.src.read(&mut self.buf[self.len..]).unwrap();\n self.len += n;\n assert!(self.len <= self.buf.len());\n n\n }\n }\n impl Input for Scanner {\n fn bytes(&mut self) -> &[u8] {\n loop {\n while let Some(d) = unsafe { self.buf.get_unchecked(self.pos..self.len) }\n .iter()\n .position(u8::is_ascii_whitespace)\n {\n let p = self.pos;\n self.pos += d + 1;\n if d > 0 {\n return unsafe { self.buf.get_unchecked(p..p + d) };\n }\n }\n if self.read() == 0 {\n let p = self.pos;\n self.pos = self.len;\n return unsafe { self.buf.get_unchecked(p..self.len) };\n }\n }\n }\n }\n pub struct ParseIter<'a, T, I: ?Sized>(&'a mut I, PhantomData<*const T>);\n impl<'a, T: Parse, I: Input + ?Sized> Iterator for ParseIter<'a, T, I> {\n type Item = T;\n fn next(&mut self) -> Option {\n Some(self.0.parse())\n }\n fn size_hint(&self) -> (usize, Option) {\n (!0, None)\n }\n }\n pub trait Parse: Sized {\n fn parse(src: &mut I) -> Self;\n }\n macro_rules! from_bytes {\n ($($T:ty)*) => {$(\n impl Parse for $T {\n fn parse(src: &mut I) -> Self {\n src.bytes().into()\n }\n }\n )*}\n }\n from_bytes!(Vec Box<[u8]>);\n macro_rules! from_str {\n ($($T:ty)*) => {$(\n impl Parse for $T {\n fn parse(src: &mut I) -> Self {\n src.str().parse::<$T>().unwrap()\n }\n }\n )*}\n }\n from_str!(String char bool f32 f64);\n macro_rules! int {\n ($($I:ty: $U:ty)*) => {$(\n impl Parse for $I {\n fn parse(src: &mut I) -> Self {\n let f = |s: &[u8]| s.iter().fold(0, |x, b| 10 * x + (b & 0xf) as $I);\n let s = src.bytes();\n if let Some((&b'-', t)) = s.split_first() { -f(t) } else { f(s) }\n }\n }\n impl Parse for $U {\n fn parse(src: &mut I) -> Self {\n src.bytes().iter().fold(0, |x, b| 10 * x + (b & 0xf) as $U)\n }\n }\n )*}\n }\n int!(isize:usize i8:u8 i16:u16 i32:u32 i64:u64 i128:u128);\n macro_rules! tuple {\n ($H:ident $($T:ident)*) => {\n impl<$H: Parse, $($T: Parse),*> Parse for ($H, $($T),*) {\n fn parse(src: &mut I) -> Self {\n ($H::parse(src), $($T::parse(src)),*)\n }\n }\n tuple!($($T)*);\n };\n () => {}\n }\n tuple!(A B C D E F G);\n macro_rules! array {\n ($($N:literal)*) => {$(\n impl Parse for [T; $N] {\n fn parse(src: &mut I) -> Self {\n unsafe {\n let mut arr: [MaybeUninit; $N] = MaybeUninit::uninit().assume_init();\n for elem in &mut arr {\n *elem = MaybeUninit::new(src.parse());\n }\n mem::transmute_copy(&arr)\n }\n }\n }\n )*}\n }\n array!(1 2 3 4 5 6 7 8);\n}\n"}, {"source_code": "#![allow(unused_imports)]\r\nuse std::cmp::*;\r\nuse std::collections::*;\r\nuse std::io::Write;\r\nuse std::ops::Bound::*;\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! debug {\r\n ($($e:expr),*) => {\r\n #[cfg(debug_assertions)]\r\n $({\r\n let (e, mut err) = (stringify!($e), std::io::stderr());\r\n writeln!(err, \"{} = {:?}\", e, $e).unwrap()\r\n })*\r\n };\r\n}\r\n\r\nfn main() {\r\n let n = read::();\r\n let mut a = read_vec::();\r\n while a.iter().all(|&x| x % 2 == 0) {\r\n a = a.iter().map(|&x| x / 2).collect::>();\r\n }\r\n\r\n if a.iter().sum::() % 2 == 1 {\r\n println!(\"0\");\r\n return;\r\n }\r\n let mut dp = vec![false; 2000 * n + 1];\r\n dp[0] = true;\r\n for i in 0..n {\r\n for next in (a[i]..dp.len()).rev() {\r\n dp[next] |= dp[next - a[i]];\r\n }\r\n }\r\n // debug!(dp);\r\n if !dp[a.iter().sum::() / 2] {\r\n println!(\"0\");\r\n return;\r\n }\r\n println!(\"1\");\r\n for i in 0..n {\r\n if a[i] % 2 == 1 {\r\n println!(\"{}\", i + 1);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfn read() -> T {\r\n let mut s = String::new();\r\n std::io::stdin().read_line(&mut s).ok();\r\n s.trim().parse().ok().unwrap()\r\n}\r\n\r\nfn read_vec() -> Vec {\r\n read::()\r\n .split_whitespace()\r\n .map(|e| e.parse().ok().unwrap())\r\n .collect()\r\n}\r\n"}, {"source_code": "use crate::lib::stdio::*;\nuse crate::lib::ds::idx::*;\n\nfn main() {\n prtln!(new cout);\n scan!(new cin, n: usize, a: [isize; n]);\n let ofs: isize = 101 * 2000;\n let mut dp = IdxInt(vec![false; ofs as usize * 2]);\n dp[ofs] = true;\n for i in 0..n {\n let mut dp2 = IdxInt(vec![false; ofs as usize * 2]);\n for s in 0..ofs * 2 {\n if s >= a[i] {\n dp2[s - a[i]] |= dp[s];\n }\n if s + a[i] < ofs * 2 {\n dp2[s + a[i]] |= dp[s];\n }\n }\n dp = dp2;\n }\n if !dp[ofs] {\n return prtln!(to cout, 0);\n }\n prtln!(to cout, 1);\n for d in 0.. {\n if let Some(i) = (0..n).filter(|&i| a[i] >> d & 1 != 0).next() {\n return prtln!(to cout, i + 1);\n }\n }\n}\n\n\npub mod lib {\n\npub mod ds {\n\npub mod idx {\n\nuse std::ops::{Deref, DerefMut, Index, IndexMut};\n\n#[derive(Debug, Clone)]\npub struct IdxInt(pub Vec);\n\nimpl Deref for IdxInt {\n type Target = Vec;\n fn deref(&self) -> &Self::Target {\n &self.0\n }\n}\n\nimpl DerefMut for IdxInt {\n fn deref_mut(&mut self) -> &mut Self::Target {\n &mut self.0\n }\n}\n\nmacro_rules! impl_index {\n ($($idx:ty),*) => { $(\n impl Index<$idx> for IdxInt {\n type Output = T;\n fn index(&self, index: $idx) -> &Self::Output {\n self.0.index(index as usize)\n }\n }\n impl IndexMut<$idx> for IdxInt {\n fn index_mut(&mut self, index: $idx) -> &mut Self::Output {\n self.0.index_mut(index as usize)\n }\n }\n )* }\n}\n\nimpl_index!(i32, i64, i128, isize, u32, u64, u128, usize);\n\n} // mod idx\n\n} // mod ds\n\npub mod stdio {\n\npub use crate::prtln;\npub use crate::scan;\npub use std::io::Write;\nuse std::io::{stdout, BufWriter, StdoutLock};\n\npub fn stdout_buf() -> BufWriter> {\n let out = Box::leak(Box::new(stdout()));\n BufWriter::new(out.lock())\n}\n\n#[macro_export]\nmacro_rules! prtln {\n (@ $dst:expr, iter=$v:expr) => { $crate::prtln!(@ $dst, iter=$v, sep=\" \"); };\n (@ $dst:expr, iter=$v:expr, sep=$sep:expr) => { {\n let mut iter = $v.into_iter();\n if let Some(expr) = iter.next() {\n std::write!($dst, \"{}\", expr).unwrap();\n for v in iter { std::write!($dst, \"{}{}\", $sep, v).unwrap(); }\n }\n $crate::prtln!(@ $dst, \"\");\n } };\n (@ $dst:expr, bytes=$v:expr) => {\n $crate::prtln!(@ $dst, std::str::from_utf8(&$v).unwrap());\n };\n (@ $dst:expr, YesNo=$v:expr) => { $crate::prtln!(@ $dst, if $v { \"Yes\" } else { \"No\" }); };\n (@ $dst:expr, YESNO=$v:expr) => { $crate::prtln!(@ $dst, if $v { \"YES\" } else { \"NO\" }); };\n (@ $dst:expr, $v:expr, no eol) => { std::write!($dst, \"{}\", $v).unwrap(); };\n (@ $dst:expr, $v:expr) => { std::writeln!($dst, \"{}\", $v).unwrap(); };\n (@ $dst:expr, $v:expr, $($t:tt)*) => { {\n std::write!($dst, \"{} \", $v).unwrap();\n $crate::prtln!(@ $dst, $($t)*);\n } };\n (new $var:ident $(,)?) => { let mut $var = stdout_buf(); };\n (new $var:ident, $($t:tt)*) => {\n $crate::prtln!(new $var);\n $crate::prtln!(to $var, $($t)*);\n };\n (to $var:ident, $($t:tt)*) => { {\n $crate::prtln!(@ $var, $($t)*);\n } };\n ($($t:tt)*) => { {\n $crate::prtln!(new __prtln, $($t)*);\n std::mem::drop(__prtln);\n } };\n}\n\n#[macro_export]\nmacro_rules! scan {\n (@ $iter:expr $(,)?) => {};\n (@ $iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {\n #[allow(non_snake_case)]\n let mut $var = $crate::scan_value!($iter.into_iter(), $t);\n $crate::scan!(@ $iter $($r)*)\n };\n (@ $iter:expr, $var:ident : $t:tt $($r:tt)*) => {\n #[allow(non_snake_case)]\n let $var = $crate::scan_value!($iter.into_iter(), $t);\n $crate::scan!(@ $iter $($r)*)\n };\n (@ $iter:expr, $pat:pat in $t:tt $($r:tt)*) => {\n let $pat = $crate::scan_value!($iter.into_iter(), $t);\n $crate::scan!(@ $iter $($r)*)\n };\n (from $s:expr, $($r:tt)*) => { $crate::scan!(@ $s, $($r)*); };\n (new $var:ident, $($r:tt)*) => {\n let mut __input = String::new();\n std::io::Read::read_to_string(&mut std::io::stdin(), &mut __input).unwrap();\n let $var = &mut __input.split_ascii_whitespace();\n $crate::scan!(@ $var, $($r)*);\n };\n ($($r:tt)*) => { $crate::scan!(new __scan, $($r)*); };\n}\n\n#[macro_export]\nmacro_rules! scan_value {\n ($iter:expr, ( $($t:tt),* )) => { ( $($crate::scan_value!($iter, $t)),* ) };\n ($iter:expr, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| $crate::scan_value!($iter, $t)).collect::>()\n };\n ($iter:expr, bytes) => { $iter.next().unwrap().as_bytes() };\n ($iter:expr, [u8]) => { $iter.next().unwrap().as_bytes().to_vec() };\n ($iter:expr, [char]) => { $iter.next().unwrap().chars().collect::>() };\n ($iter:expr, usize1) => { $crate::scan_value!($iter, usize) - 1 };\n (@graph $iter:expr, $n:expr, $m:expr) => { {\n let mut graph = vec![Vec::new(); $n];\n for _ in 0..$m {\n let (a, b) = $crate::scan_value!($iter, (usize1, usize1));\n graph[a].push(b);\n graph[b].push(a);\n }\n graph\n } };\n ($iter:expr, graph) => { {\n let (n, m) = $crate::scan_value!($iter, (usize, usize));\n $crate::scan_value!(@graph $iter, n, m)\n } };\n ($iter:expr, tree) => { {\n let n = $crate::scan_value!($iter, usize);\n $crate::scan_value!(@graph $iter, n, n - 1)\n } };\n ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().unwrap() };\n}\n\n} // mod stdio\n\n} // mod lib\n"}], "negative_code": [{"source_code": "use std::{io, usize};\r\n\r\n#[allow(dead_code)]\r\nfn gets() -> String {\r\n let mut s = String::new();\r\n io::stdin().read_line(&mut s).unwrap();\r\n s.trim().to_string()\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_vec {\r\n ($ty:ty) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n let mut v = Vec::new();\r\n while let Some(value) = it.next() {\r\n v.push(value.parse::<$ty>().unwrap());\r\n }\r\n v\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read {\r\n ( $ty:ty) => {\r\n gets().split_whitespace().next().unwrap().parse::<$ty>().unwrap()\r\n };\r\n ( $($ty:ty),* ) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )\r\n }};\r\n ( $( $ty:ty ),+ ,) => {\r\n\t\tread![ $( $ty ),* ]\r\n };\r\n}\r\nuse std::collections::BTreeSet;\r\nfn main() {\r\n let _ = read!(usize);\r\n let a = read_vec!(i32);\r\n let mut set = BTreeSet::new();\r\n set.insert(0);\r\n for x in &a {\r\n let mut tmp = BTreeSet::new();\r\n for y in set.iter() {\r\n tmp.insert(y + x);\r\n }\r\n for y in tmp.iter() {\r\n set.insert(*y);\r\n }\r\n }\r\n let mut sum = 0;\r\n for x in &a {\r\n sum += x;\r\n }\r\n if sum % 2 == 0 && set.contains(&(sum / 2)) {\r\n println!(\"1\");\r\n let mut ans = a[0];\r\n let mut ansidx = 0;\r\n for i in 0..a.len() {\r\n if ans > a[i] {\r\n ans = a[i];\r\n ansidx = i;\r\n }\r\n }\r\n println!(\"{}\", ansidx + 1);\r\n } else {\r\n println!(\"0\");\r\n }\r\n}\r\n"}, {"source_code": "use std::{io, usize};\r\n\r\n#[allow(dead_code)]\r\nfn gets() -> String {\r\n let mut s = String::new();\r\n io::stdin().read_line(&mut s).unwrap();\r\n s.trim().to_string()\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_vec {\r\n ($ty:ty) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n let mut v = Vec::new();\r\n while let Some(value) = it.next() {\r\n v.push(value.parse::<$ty>().unwrap());\r\n }\r\n v\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read {\r\n ( $ty:ty) => {\r\n gets().split_whitespace().next().unwrap().parse::<$ty>().unwrap()\r\n };\r\n ( $($ty:ty),* ) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )\r\n }};\r\n ( $( $ty:ty ),+ ,) => {\r\n\t\tread![ $( $ty ),* ]\r\n };\r\n}\r\nuse std::collections::BTreeSet;\r\nfn main() {\r\n let _ = read!(usize);\r\n let a = read_vec!(i32);\r\n let mut set = BTreeSet::new();\r\n set.insert(0);\r\n for x in &a {\r\n let mut tmp = BTreeSet::new();\r\n for y in set.iter() {\r\n tmp.insert(y + x);\r\n }\r\n for y in tmp.iter() {\r\n set.insert(*y);\r\n }\r\n }\r\n let mut sum = 0;\r\n for x in &a {\r\n sum += x;\r\n }\r\n if sum % 2 == 0 && set.contains(&(sum / 2)) {\r\n println!(\"1\");\r\n let mut ans = a[0];\r\n let mut ansidx = 0;\r\n for i in 0..a.len(){\r\n if ans > a[i] {\r\n ans = a[i];\r\n ansidx = i;\r\n }\r\n }\r\n println!(\"{}\", ansidx);\r\n } else {\r\n println!(\"0\");\r\n }\r\n}\r\n"}, {"source_code": "use std::{io, usize};\r\n\r\n#[allow(dead_code)]\r\nfn gets() -> String {\r\n let mut s = String::new();\r\n io::stdin().read_line(&mut s).unwrap();\r\n s.trim().to_string()\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read_vec {\r\n ($ty:ty) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n let mut v = Vec::new();\r\n while let Some(value) = it.next() {\r\n v.push(value.parse::<$ty>().unwrap());\r\n }\r\n v\r\n }};\r\n}\r\n\r\n#[allow(unused_macros)]\r\nmacro_rules! read {\r\n ( $ty:ty) => {\r\n gets().split_whitespace().next().unwrap().parse::<$ty>().unwrap()\r\n };\r\n ( $($ty:ty),* ) => {{\r\n let line = gets();\r\n let mut it = line.split_whitespace();\r\n ( $(it.next().unwrap().parse::<$ty>().unwrap(),)* )\r\n }};\r\n ( $( $ty:ty ),+ ,) => {\r\n\t\tread![ $( $ty ),* ]\r\n };\r\n}\r\nuse std::collections::BTreeSet;\r\nfn main() {\r\n let _ = read!(usize);\r\n let a = read_vec!(i32);\r\n let mut set = BTreeSet::new();\r\n set.insert(0);\r\n for x in &a {\r\n let mut tmp = BTreeSet::new();\r\n for y in set.iter() {\r\n tmp.insert(y + x);\r\n }\r\n for y in tmp.iter() {\r\n set.insert(*y);\r\n }\r\n }\r\n let mut sum = 0;\r\n for x in a {\r\n sum += x;\r\n }\r\n if sum % 2 == 0 && set.contains(&(sum / 2)) {\r\n println!(\"1\\n1\");\r\n } else {\r\n println!(\"0\");\r\n }\r\n}\r\n"}, {"source_code": "fn main() {\r\n use std::io::Read;\r\n let mut buf = String::new();\r\n std::io::stdin().read_to_string(&mut buf).unwrap();\r\n let mut itr = buf.split_whitespace();\r\n\r\n use std::io::Write;\r\n let out = std::io::stdout();\r\n let mut out = std::io::BufWriter::new(out.lock());\r\n\r\n macro_rules! print {\r\n ($($T:expr),*) => {\r\n write!(out, $($T),*).unwrap()\r\n };\r\n }\r\n\r\n macro_rules! scan {\r\n (bytes) => {\r\n scan!(String).bytes().collect::>()\r\n };\r\n (chars) => {\r\n scan!(String).chars().collect::>()\r\n };\r\n ([$T:tt; $n:expr]) => {\r\n (0..$n).map(|_| scan!($T)).collect::>()\r\n };\r\n (($($T:tt),*)) => {\r\n ($(scan!($T)),*)\r\n };\r\n ($T:ty) => {\r\n itr.next().unwrap().parse::<$T>().unwrap()\r\n };\r\n ($($T:tt),*) => {\r\n ($(scan!($T)),*)\r\n };\r\n }\r\n\r\n let t: usize = 1; //scan!(usize);\r\n for _ in 1..=t {\r\n let n = scan!(usize);\r\n let mut a = vec![0; n + 1];\r\n\r\n let mut sum = 0;\r\n for i in 1..=n {\r\n a[i] = scan!(usize);\r\n sum += a[i];\r\n }\r\n\r\n if sum % 2 != 0 {\r\n print!(\"0\");\r\n } else {\r\n let mut dp = vec![vec![false; sum + 1]; n + 1];\r\n dp[0][0] = true;\r\n\r\n for i in 1..=n {\r\n for s in 0..=sum {\r\n if a[i] + s <= sum {\r\n dp[i][s + a[i]] |= dp[i - 1][s];\r\n }\r\n dp[i][s] |= dp[i - 1][s];\r\n }\r\n }\r\n\r\n if dp[n][sum / 2] {\r\n print!(\"1\\n\");\r\n let mut min_idx = 0;\r\n let mut min_cnt = 31;\r\n for i in 1..=n {\r\n let mut cnt = 0;\r\n let mut a = a[i];\r\n while a > 1 {\r\n cnt += 1;\r\n a /= 2;\r\n }\r\n if min_cnt > cnt {\r\n min_cnt = cnt;\r\n min_idx = i;\r\n }\r\n }\r\n\r\n print!(\"{}\", min_idx);\r\n } else {\r\n print!(\"0\");\r\n }\r\n }\r\n print!(\"\\n\");\r\n }\r\n}\r\n"}, {"source_code": "// codesnip-guard: main\nfn main() {\n #![allow(unused_imports, unused_macros)]\n prepare_io!(_in_buf, scanner, _out);\n macro_rules ! print { ($ ($ arg : tt) *) => (:: std :: write ! (_out , $ ($ arg) *) . expect (\"io error\")) }\n macro_rules ! println { ($ ($ arg : tt) *) => (:: std :: writeln ! (_out , $ ($ arg) *) . expect (\"io error\")) }\n scan!(scanner, n, a: [u64; n]);\n let s: u64 = a.iter().cloned().sum();\n if s % 2 == 0 {\n println!(\"{}\", 1);\n let i = (0..n).min_by_key(|&i| a[i].trailing_zeros()).unwrap();\n println!(\"{}\", i + 1);\n } else {\n println!(\"{}\", 0);\n }\n}\n#[macro_export]\nmacro_rules! prepare_io {\n ($ in_buf : ident , $ scanner : ident , $ out : ident) => {\n use std::io::{stdout, BufWriter, Write as _};\n let $in_buf = read_stdin_all_unchecked();\n let mut $scanner = Scanner::new(&$in_buf);\n let $out = stdout();\n let mut $out = BufWriter::new($out.lock());\n };\n}\n// codesnip-guard: _echo\npub fn echo(\n mut writer: impl std::io::Write,\n iter: impl IntoIterator,\n sep: impl std::fmt::Display,\n) -> std::io::Result<()> {\n let mut iter = iter.into_iter();\n if let Some(item) = iter.next() {\n write!(writer, \"{}\", item)?;\n }\n for item in iter {\n write!(writer, \"{}{}\", sep, item)?;\n }\n writeln!(writer)\n}\n// codesnip-guard: scanner\npub fn read_stdin_all_unchecked() -> String {\n use std::io::Read as _;\n let mut buf = Vec::new();\n std::io::stdin().read_to_end(&mut buf).expect(\"io error\");\n unsafe { String::from_utf8_unchecked(buf) }\n}\npub fn read_stdin_line() -> String {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).expect(\"io error\");\n s\n}\npub trait IterScan: Sized {\n type Output;\n fn scan<'a, I: Iterator>(iter: &mut I) -> Option;\n}\npub trait MarkedIterScan: Sized {\n type Output;\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option;\n}\n#[derive(Clone, Debug)]\npub struct Scanner<'a> {\n iter: std::str::SplitAsciiWhitespace<'a>,\n}\nmod scanner_impls {\n use super::*;\n impl<'a> Scanner<'a> {\n #[inline]\n pub fn new(s: &'a str) -> Self {\n let iter = s.split_ascii_whitespace();\n Self { iter }\n }\n #[inline]\n pub fn scan(&mut self) -> ::Output {\n ::scan(&mut self.iter).expect(\"scan error\")\n }\n #[inline]\n pub fn mscan(&mut self, marker: T) -> ::Output {\n marker.mscan(&mut self.iter).expect(\"scan error\")\n }\n #[inline]\n pub fn scan_vec(&mut self, size: usize) -> Vec<::Output> {\n (0..size)\n .map(|_| ::scan(&mut self.iter).expect(\"scan error\"))\n .collect()\n }\n #[inline]\n pub fn iter<'b, T: IterScan>(&'b mut self) -> ScannerIter<'a, 'b, T> {\n ScannerIter {\n inner: self,\n _marker: std::marker::PhantomData,\n }\n }\n }\n macro_rules ! iter_scan_impls { ($ ($ t : ty) *) => { $ (impl IterScan for $ t { type Output = Self ; # [inline] fn scan <'a , I : Iterator < Item = &'a str >> (iter : & mut I) -> Option < Self > { iter . next () ?. parse ::<$ t > () . ok () } }) * } ; }\n iter_scan_impls ! (char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String);\n macro_rules ! iter_scan_tuple_impl { ($ ($ T : ident) *) => { impl <$ ($ T : IterScan) ,*> IterScan for ($ ($ T ,) *) { type Output = ($ (<$ T as IterScan >:: Output ,) *) ; # [inline] fn scan <'a , It : Iterator < Item = &'a str >> (_iter : & mut It) -> Option < Self :: Output > { Some (($ (<$ T as IterScan >:: scan (_iter) ?,) *)) } } } ; }\n iter_scan_tuple_impl!();\n iter_scan_tuple_impl!(A);\n iter_scan_tuple_impl ! (A B);\n iter_scan_tuple_impl ! (A B C);\n iter_scan_tuple_impl ! (A B C D);\n iter_scan_tuple_impl ! (A B C D E);\n iter_scan_tuple_impl ! (A B C D E F);\n iter_scan_tuple_impl ! (A B C D E F G);\n iter_scan_tuple_impl ! (A B C D E F G H);\n iter_scan_tuple_impl ! (A B C D E F G H I);\n iter_scan_tuple_impl ! (A B C D E F G H I J);\n iter_scan_tuple_impl ! (A B C D E F G H I J K);\n pub struct ScannerIter<'a, 'b, T> {\n inner: &'b mut Scanner<'a>,\n _marker: std::marker::PhantomData T>,\n }\n impl<'a, 'b, T: IterScan> Iterator for ScannerIter<'a, 'b, T> {\n type Item = ::Output;\n #[inline]\n fn next(&mut self) -> Option {\n ::scan(&mut self.inner.iter)\n }\n }\n}\n#[derive(Debug, Copy, Clone)]\npub struct Usize1;\n#[derive(Debug, Copy, Clone)]\npub struct CharWithBase(pub char);\n#[derive(Debug, Copy, Clone)]\npub struct Chars;\n#[derive(Debug, Copy, Clone)]\npub struct CharsWithBase(pub char);\n#[derive(Debug, Copy, Clone)]\npub struct Collect::Output>> {\n size: usize,\n _marker: std::marker::PhantomData (T, B)>,\n}\nmod marker_impls {\n use super::*;\n use std::{iter::FromIterator, marker::PhantomData};\n impl IterScan for Usize1 {\n type Output = usize;\n #[inline]\n fn scan<'a, I: Iterator>(iter: &mut I) -> Option {\n ::scan(iter)?.checked_sub(1)\n }\n }\n impl MarkedIterScan for CharWithBase {\n type Output = usize;\n #[inline]\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option {\n Some((::scan(iter)? as u8 - self.0 as u8) as usize)\n }\n }\n impl IterScan for Chars {\n type Output = Vec;\n #[inline]\n fn scan<'a, I: Iterator>(iter: &mut I) -> Option {\n Some(iter.next()?.chars().collect())\n }\n }\n impl MarkedIterScan for CharsWithBase {\n type Output = Vec;\n #[inline]\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option {\n Some(\n iter.next()?\n .chars()\n .map(|c| (c as u8 - self.0 as u8) as usize)\n .collect(),\n )\n }\n }\n impl::Output>> Collect {\n pub fn new(size: usize) -> Self {\n Self {\n size,\n _marker: PhantomData,\n }\n }\n }\n impl::Output>> MarkedIterScan for Collect {\n type Output = B;\n #[inline]\n fn mscan<'a, I: Iterator>(self, iter: &mut I) -> Option {\n Some(\n (0..self.size)\n .map(|_| ::scan(iter).expect(\"scan error\"))\n .collect::(),\n )\n }\n }\n}\n#[macro_export]\nmacro_rules ! scan_value { ($ scanner : expr , ($ ($ t : tt) ,*)) => { ($ ($ crate :: scan_value ! ($ scanner , $ t)) ,*) } ; ($ scanner : expr , [$ t : tt ; $ len : expr]) => { (0 ..$ len) . map (| _ | $ crate :: scan_value ! ($ scanner , $ t)) . collect ::< Vec < _ >> () } ; ($ scanner : expr , [$ t : ty ; $ len : expr]) => { $ scanner . scan_vec ::<$ t > ($ len) } ; ($ scanner : expr , [$ t : ty]) => { $ scanner . iter ::<$ t > () } ; ($ scanner : expr , { $ e : expr }) => { $ scanner . mscan ($ e) } ; ($ scanner : expr , $ t : ty) => { $ scanner . scan ::<$ t > () } ; }\n#[macro_export]\nmacro_rules ! scan { ($ scanner : expr) => { } ; ($ scanner : expr ,) => { } ; ($ scanner : expr , mut $ var : tt : $ t : tt) => { let mut $ var = $ crate :: scan_value ! ($ scanner , $ t) ; } ; ($ scanner : expr , $ var : tt : $ t : tt) => { let $ var = $ crate :: scan_value ! ($ scanner , $ t) ; } ; ($ scanner : expr , mut $ var : tt : $ t : tt , $ ($ rest : tt) *) => { let mut $ var = $ crate :: scan_value ! ($ scanner , $ t) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , $ var : tt : $ t : tt , $ ($ rest : tt) *) => { let $ var = $ crate :: scan_value ! ($ scanner , $ t) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , mut $ var : tt) => { let mut $ var = $ crate :: scan_value ! ($ scanner , usize) ; } ; ($ scanner : expr , $ var : tt) => { let $ var = $ crate :: scan_value ! ($ scanner , usize) ; } ; ($ scanner : expr , mut $ var : tt , $ ($ rest : tt) *) => { let mut $ var = $ crate :: scan_value ! ($ scanner , usize) ; scan ! ($ scanner , $ ($ rest) *) } ; ($ scanner : expr , $ var : tt , $ ($ rest : tt) *) => { let $ var = $ crate :: scan_value ! ($ scanner , usize) ; scan ! ($ scanner , $ ($ rest) *) } ; }\n"}, {"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\nfn run() {\r\n input! {\r\n n: usize,\r\n a: [u32; n],\r\n }\r\n let s = a.iter().sum::();\r\n if s % 2 == 1 {\r\n println!(\"0\");\r\n return;\r\n }\r\n for d in 0.. {\r\n let d = 2u32.pow(d);\r\n if let Some(x) = a.iter().position(|a| *a / d % 2 == 1) {\r\n println!(\"1\\n{}\", x + 1);\r\n return;\r\n }\r\n }\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}], "src_uid": "29063ad54712b4911c6bf871969ee147"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap};\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, k) = get!(u64, u64);\n\n let mut ans = 1;\n\n if k > 1 {\n for i in 2..k + 1 {\n let u = (n - i + 1..n + 1).fold(1, |a, b| a * b);\n let d = (1..i + 1).fold(1, |a, b| a * b);\n\n let c = u / d;\n\n ans += c * [1, 2, 9][(i - 2) as usize];\n }\n }\n\n println!(\"{}\", ans);\n}\n", "positive_code": [{"source_code": "fn main() {\n let v: Vec = vec![1,0,1,2,9];\n let mut ri = ReadIn::new();\n let tp = ri.int2();\n let mut ans:i64 = 1;\n for kk in 2..tp.1+1 {\n ans += cal(tp.0 as i64, kk as i64) * v[(kk as usize)] ;\n }\n println!(\"{}\", ans)\n}\n\nfn cal(n: i64, k: i64) -> i64{\n let mut up: i64 = 1;\n let mut down: i64 = 1;\n for kk in 0..k {\n up = up * (n - kk);\n down = down * (1 + kk);\n }\n up / down\n}\n\nuse std::iter::Map;\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 {\n ReadIn(String::new())\n }\n fn read_i32(s: &str) -> i32 {\n s.parse().unwrap()\n }\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 int(&mut self) -> i32 {\n self.ints().next().unwrap()\n }\n pub fn int2(&mut self) -> (i32, i32) {\n let mut it = self.ints();\n (it.next().unwrap(), it.next().unwrap())\n }\n}\n"}], "negative_code": [], "src_uid": "96d839dc2d038f8ae95fc47c217b2e2f"} {"source_code": "use std::io;\nuse std::str::FromStr;\n\nfn get_nums() -> (usize, usize, usize, usize) {\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| usize::from_str(s).unwrap())\n .collect::>();\n\n (v[0], v[1], v[2], v[3])\n}\n\nfn main() {\n let (a, b, c, d) = get_nums();\n\n let misha = std::cmp::max(3 * a / 10, a - a / 250 * c);\n let vasya = std::cmp::max(3 * b / 10, b - b / 250 * d);\n\n if misha > vasya {\n println!(\"Misha\");\n } else if misha < vasya {\n println!(\"Vasya\");\n } else {\n println!(\"Tie\");\n }\n}\n", "positive_code": [{"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 a = input.i();\n let b = input.i();\n let c = input.i();\n let d = input.i();\n println!(\"{}\", match ((a * 3 / 10).max(a - a/250 * c)).cmp(&(b * 3 / 10).max(b - b/250 * d)) {\n Greater => \"Misha\",\n Less => \"Vasya\",\n Equal => \"Tie\",\n });\n}\n\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min,Ordering};\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 solve(a: i64, t: i64) -> i64 {\n return max((a*3)/10,a-(a/250)*t);\n}\n\nfn main() {\n let (a,b,c,d) = readln!(i64,i64,i64,i64);\n let p1 = solve(a,c);\n let p2 = solve(b,d);\n println!(\"{}\",if p1 < p2 { \"Vasya\" } else if p1 > p2 { \"Misha\" } else { \"Tie\" });\n}\n"}, {"source_code": "use std::cmp::Ordering;\nuse std::io::{self, BufRead};\n\nfn score(p: i32, t: i32) -> i32 {\n std::cmp::max(3 * p / 10, p - p / 250 * t)\n}\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock().lines().next().unwrap().unwrap();\n let v: Vec<_> = line.split(\" \").map(|x| x.parse::().unwrap()).collect();\n let (a, b, c, d) = (v[0], v[1], v[2], v[3]);\n let misha = score(a,c);\n let vasya = score(b,d);\n match vasya.cmp(&misha) {\n Ordering::Greater => println!(\"Vasya\"),\n Ordering::Equal => println!(\"Tie\"),\n Ordering::Less => println!(\"Misha\"),\n }\n}"}], "negative_code": [{"source_code": "use std::io;\nuse std::str::FromStr;\n\nfn get_nums() -> (usize, usize, usize, usize) {\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| usize::from_str(s).unwrap())\n .collect::>();\n\n (v[0], v[1], v[2], v[3])\n}\n\nfn main() {\n let (a, b, c, d) = get_nums();\n\n let misha = std::cmp::max(3 * a / 10, a / 250 * c);\n let vasya = std::cmp::max(3 * b / 10, b / 250 * d);\n\n if misha > vasya {\n println!(\"Misha\");\n } else if misha < vasya {\n println!(\"Vasya\");\n } else {\n println!(\"Tie\");\n }\n}\n"}], "src_uid": "95b19d7569d6b70bd97d46a8541060d0"} {"source_code": "use std::collections::HashSet;\nuse 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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n let input: Vec = reads(sin);\n\n let mut set = HashSet::new();\n\n for c in input {\n set.insert(c);\n }\n\n println!(\"{}\", 4 - set.len());\n}\n", "positive_code": [{"source_code": "//! http://codeforces.com/contest/228/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 mut ns: Vec = buf.split(\" \")\n .map(|str| str.trim().parse::().unwrap())\n .collect();\n ns.sort();\n let mut last = 0;\n let mut shoes = 0;\n for n in ns {\n if n != last { shoes += 1; last = n; }\n }\n println!(\"{}\", 4 - shoes);\n}\n"}, {"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] use std::thread::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($($n:expr, $T:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n ($({let mut v = Vec::new(); v.reserve(($n) as usize);\n for _ in 0..$n { let t = s.next(); if t == None { break; }\n v.push(t.unwrap().parse::<$T>().unwrap()); } v }),+)\n }}; }\n///////////////////////////////////////////////////////////////////////////////\n\n\n\nfn main()\n{\n let mut a = arr!(4usize, i32);\n a.sort_by(|x, y| x.cmp(&y));\n println!(\"{}\", (1..4).filter(|&x| a[x] == a[x-1]).count());\n}\n"}, {"source_code": "fn input_split() -> Vec {\n let mut buf = String::with_capacity(7);\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 mut shoes = input_split();\n shoes.sort_unstable();\n shoes.dedup();\n println!(\"{}\", 4 - shoes.len());\n}"}, {"source_code": "//spnauti-rust\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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(4);\n a.sort();\n a.dedup();\n let sol = 4 - a.len();\n println!(\"{}\", sol);\n}\n\n"}, {"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 mut s: BTreeSet = BTreeSet::new();\n for i in 1..=4 {\n \ts.insert(scanner.next());\n }\n println![\"{}\", 4 - s.len()];\n}"}, {"source_code": "use std::io::{self, BufRead};\nuse std::collections::HashSet;\n\nfn main() {\n let stdin = io::stdin();\n let mut iterator = stdin.lock().lines();\n\n let line = iterator.next().unwrap().unwrap();\n let colors: Vec<&str> = line\n .split_whitespace()\n .collect();\n \n let unique: HashSet<_> = colors.iter().cloned().collect();\n \n let unique_count: i32 = unique.len() as i32;\n println!(\"{}\", (unique_count-4).abs());\n}"}, {"source_code": "use std::collections::HashSet;\nuse std::io::stdin;\n\nfn main() {\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n\n let line: Vec = line\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let mut lista_sin_repetidos = HashSet::new();\n\n for i in line {\n lista_sin_repetidos.insert(i);\n }\n\n println!(\"{}\", 4 - lista_sin_repetidos.len());\n}\n"}, {"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 mut ns = R!(usize, ...);\n ns.sort();\n ns.dedup();\n println!(\"{}\", 4 - ns.len());\n}\n"}, {"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::{stderr, stdin, BufRead, Write};\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(unused_macros)]\nmacro_rules! debug {\n ($($arg:expr),*) => {\n #[cfg(debug_assertions)]\n $(writeln!(stderr(), \"{} = {:?}\", stringify!($arg), $arg).unwrap());*\n };\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 input = rl();\n\n let mut s = HashSet::new();\n\n input\n .split(\" \")\n .for_each(|t| {\n s.insert(t);\n });\n\n println!(\"{}\", 4-s.len());\n\n\treturn;\n}\n"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\nuse std::collections::HashSet;\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 parse_t(s: &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin: &Stdin, ts: &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn read_i64(stdin: &Stdin) -> i64 {\n let mut line = String::new();\n read_line(&stdin, &mut line);\n match line.trim().parse() {\n Ok(i) => i,\n Err(e) => {\n panic!(\"Could not read i64!\");\n }\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut v:Vec= vec![];\n read_ts(&stdin, &mut v);\n let mut hs = HashSet::new();\n for i in v {\n hs.insert(i);\n }\n println!(\"{}\", 4 - hs.len());\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/228/A\nuse std::io;\nuse std::collections::HashSet;\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 mut horseshoes = HashSet::new();\n\n for item in words {\n horseshoes.insert(item);\n }\n\n println!(\"{}\", 4-horseshoes.len());\n\n}\n\n"}, {"source_code": "use std::io::{self, prelude::*};\n\n\n#[allow(unused_must_use)]\n#[allow(unused_assignments)]\n#[allow(unused_variables)]\nfn solve(mut scan: Scanner, mut w: W) {\n let mut input: Vec = scan.get_vector(4);\n\n input.sort();\n input.dedup();\n let ans: usize = 4 -input.len();\n\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#[allow(dead_code)]\nfn vector_to_str(vector: &Vec, separator: &str) -> String { \n use std::fmt::Write;\n let mut ans = String::new();\n for line in vector.iter() {\n write!(&mut ans, \"{}{}\", line.to_string(), separator).unwrap();\n }\n ans\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 pub fn get_vector(&mut self, n: usize) -> Vec {\n let mut ans: Vec = Vec::with_capacity(n);\n for _ in 0..n {\n ans.push(self.token::());\n }\n ans\n }\n}\n"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_hash() -> std::collections::HashSet {\n read_str()\n .split_whitespace()\n .map(|value| value.parse::().ok().expect(\"Error\"))\n .collect()\n}\n\nfn main() {\n let shoes: std::collections::HashSet = read_hash();\n print!(\"{}\", 4 - shoes.len());\n}"}, {"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 a: usize = scan.next();\n let b: usize = scan.next();\n let c: usize = scan.next();\n let d: usize = scan.next();\n let eq: [bool;3] = [a==b || a==c || a==d, b==c || b==d, c==d];\n let result: usize = eq.iter().map(|&x| (x as usize))\n .fold(0,|sum, x| sum+x);\n println!(\"{}\", result);\n}\n"}, {"source_code": "use std::collections::BTreeSet;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut cols : Vec = vec![];\n read_ts(&stdin, &mut cols);\n let mut distinct_cols = BTreeSet::new();\n for c in cols {\n distinct_cols.insert(c);\n }\n println!(\"{}\", 4 - distinct_cols.len());\n}\n"}, {"source_code": "use std::collections::HashSet;\n\nfn main() {\n let a: HashSet = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let ws = buf.split_whitespace();\n ws.map(|c| c.parse().unwrap()).collect()\n };\n\n println!(\"{}\", 4 - a.len());\n}\n"}, {"source_code": "fn readln() -> Vec {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect()\n}\nfn main() {\n let mut colors = readln();\n colors.sort();\n\n let mut ans = 0;\n\n for i in 1..4 {\n if colors[i - 1] == colors[i] {\n ans += 1;\n }\n }\n\n println!(\"{}\", ans);\n}"}, {"source_code": "fn main() {\n\tlet mut inp = String::new();\n\tstd::io::stdin().read_line(&mut inp).unwrap();\n\tlet inp: Vec = inp\n\t\t.split_whitespace()\n\t\t.map(|x| x.parse::().unwrap())\n\t\t.collect();\n\n\tlet mut exist: Vec = vec![];\n\tlet mut ans = 0;\n\tfor i in inp {\n\t\tif exist.contains(&i) {\n\t\t\tans += 1;\n\t\t} else {\n\t\t\texist.push(i);\n\t\t}\n\t}\n\tprintln!(\"{}\", ans);\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\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 out = &mut BufWriter::new(stdout());\n\n\tlet n = 4;\n let mut p = (0..n).map(|_| scan.next::()).collect::>();\n p.sort();\n p.dedup();\n\n writeln!(out, \"{}\", n - p.len()).expect(\"fail\");\n}\n"}], "negative_code": [], "src_uid": "38c4864937e57b35d3cce272f655e20f"} {"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\n\nfn read_line<'a>() -> Result> {\n let mut line = String::new();\n stdin().read_line(&mut line)?;\n\n Ok(line.trim().to_owned())\n}\n\nfn main() -> Result<(), Box> {\n let line = read_line()?;\n let mut nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap());\n\n let _ = nums.next().unwrap();\n let mut b = nums.next().unwrap();\n\n let line = read_line()?;\n\n let nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap())\n .collect::>();\n\n let evency = nums\n .iter()\n .map(|n| if n % 2 == 0 { 1 } else { -1 })\n .collect::>();\n\n let mut split_points = HashSet::new();\n let mut s = 0;\n\n for (i, e) in evency[..evency.len() - 1].iter().enumerate() {\n s += e;\n\n // println!(\"{}, {}, {}\", i, s, e);\n\n if s == 0 {\n split_points.insert(i);\n }\n }\n\n let mut diffs = nums\n .iter()\n .zip(&nums[1..])\n .map(|(&prev, &curr)| (curr - prev).abs())\n .enumerate()\n .collect::>();\n \n diffs.sort_unstable_by_key(|&(_, diff)| diff);\n\n // println!(\"diffs: {:?}\", diffs);\n // println!(\"split_points: {:?}\", split_points);\n\n let mut ans = 0;\n\n for (i, diff) in diffs {\n if split_points.contains(&i) && b >= diff {\n // println!(\"split at {}, price {}, current budget: {}\", i, diff, b);\n\n ans += 1;\n b -= diff;\n }\n }\n\n\n println!(\"{}\", ans);\n\n Ok(())\n}\n", "positive_code": [{"source_code": "use std::io::{self, Read};\nuse std::cmp::Ordering;\n\nfn cut( accum: &Vec<(i64,i64)>, nums: &Vec, s: usize, e: usize ) -> (i64,i64) {\n //println!(\"cut range: {},{}\", s,e);\n for idx in s..e {\n let b = ( accum[e-1].0 - accum[idx].0, accum[e-1].1 - accum[idx].1 );\n let a = if s > 0 {\n ( accum[idx].0 - accum[s-1].0, accum[idx].1 - accum[s-1].1 )\n } else {\n ( accum[idx].0, accum[idx].1 )\n };\n //println!(\"idx:{}, a: {:?}, b: {:?}\", idx, a, b );\n if b.0 == b.1 && b.0 != 0 && a.0 == a.1 && a.0 != 0 {\n //make a cut between (idx, idx+1)\n //println!(\"make a cut between {}, {}\", idx, idx+1 );\n return (idx as i64,idx as i64 + 1) \n }\n }\n return (-1,-1)\n}\n\nfn main() {\n\n use std::collections::{HashMap,HashSet, BinaryHeap};\n \n let mut buffer = String::new();\n let stdin = io::stdin();\n let mut handle = stdin.lock();\n\n handle.read_to_string(&mut buffer).unwrap();\n\n let input_strs = buffer.split_whitespace().map( |x| x.parse::().unwrap() ).collect::< Vec >();\n\n let n = *input_strs.iter().nth(0).unwrap();\n let b = *input_strs.iter().nth(1).unwrap();\n \n let nums = input_strs.iter().skip(2).cloned().collect::< Vec >();\n\n //println!( \"{:?}\", nums );\n\n\n let mut eo = nums.iter().map( |x| if *x % 2 == 0 { true } else { false } ).collect::>();\n\n let mut count_e = 0;\n let mut count_o = 0;\n let accum = eo.iter().enumerate().map(|(k,x)| {\n if *x == true { count_e += 1; } else { count_o += 1; }\n ( count_e, count_o )\n } ).collect::< Vec< (i64,i64) > >();\n \n //println!( \"{:?}\", accum );\n\n let mut cut_idxs = cut( &accum, &nums, 0, nums.len() );\n let mut accum_cost = 0;\n let mut num_cuts = 0;\n\n let mut possible_cuts = vec![];\n loop {\n if cut_idxs.0 == -1 || cut_idxs.1 == -1 {\n break;\n }\n let cost_cut = (nums[cut_idxs.0 as usize] - nums[cut_idxs.1 as usize]).abs();\n\n cut_idxs = cut( &accum, &nums, cut_idxs.1 as usize, nums.len() );\n possible_cuts.push( ( cost_cut, cut_idxs ) );\n }\n\n possible_cuts.sort();\n \n // println!( \"{:?}\", possible_cuts );\n\n for i in possible_cuts.iter() {\n if accum_cost + i.0 <= b {\n accum_cost += i.0;\n num_cuts += 1;\n } else {\n break;\n }\n }\n\n println!( \"{}\", num_cuts );\n}\n"}], "negative_code": [{"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\n\nfn read_line<'a>() -> Result> {\n let mut line = String::new();\n stdin().read_line(&mut line)?;\n\n Ok(line.trim().to_owned())\n}\n\nfn main() -> Result<(), Box> {\n let line = read_line()?;\n let mut nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap());\n\n let _ = nums.next().unwrap();\n let mut b = nums.next().unwrap();\n\n let line = read_line()?;\n\n let nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap())\n .collect::>();\n\n let evency = nums\n .iter()\n .map(|n| if n % 2 == 0 { 1 } else { -1 })\n .collect::>();\n\n let mut split_points = HashSet::new();\n let mut s = 0;\n\n for (i, e) in evency[..evency.len() - 1].iter().enumerate() {\n s += e;\n\n // println!(\"{}, {}, {}\", i, s, e);\n\n if s == 0 {\n split_points.insert(i);\n }\n }\n\n let mut diffs = nums\n .iter()\n .zip(&nums[1..])\n .map(|(&prev, &curr)| (prev - curr).abs())\n .enumerate()\n .collect::>();\n \n diffs.sort_unstable_by_key(|&(_, diff)| diff);\n\n // println!(\"diffs: {:?}\", diffs);\n // println!(\"split_points: {:?}\", split_points);\n\n let mut ans = 0;\n\n for (i, diff) in diffs {\n if split_points.contains(&(i + 1)) && b >= diff {\n ans += 1;\n b -= diff;\n }\n }\n\n println!(\"{}\", ans);\n\n Ok(())\n}\n"}, {"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\n\nfn read_line<'a>() -> Result> {\n let mut line = String::new();\n stdin().read_line(&mut line)?;\n\n Ok(line.trim().to_owned())\n}\n\nfn main() -> Result<(), Box> {\n let line = read_line()?;\n let mut nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap());\n\n let _ = nums.next().unwrap();\n let mut b = nums.next().unwrap();\n\n let line = read_line()?;\n\n let nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap())\n .collect::>();\n\n let evency = nums\n .iter()\n .map(|n| if n % 2 == 0 { 1 } else { -1 })\n .collect::>();\n\n let mut split_points = HashSet::new();\n let mut s = 0;\n\n for (i, e) in evency[..evency.len() - 1].iter().enumerate() {\n s += e;\n\n // println!(\"{}, {}, {}\", i, s, e);\n\n if s == 0 {\n split_points.insert(i);\n }\n }\n\n let mut diffs = nums\n .iter()\n .zip(&nums[1..])\n .map(|(&prev, &curr)| (prev - curr).abs())\n .enumerate()\n .collect::>();\n \n diffs.sort_unstable_by_key(|&(_, diff)| diff);\n\n // println!(\"diffs: {:?}\", diffs);\n // println!(\"split_points: {:?}\", split_points);\n\n let mut ans = 0;\n\n for (i, diff) in diffs {\n if split_points.contains(&(i + 1)) && b > diff {\n ans += 1;\n b -= diff;\n }\n }\n\n println!(\"{}\", ans);\n\n Ok(())\n}\n"}, {"source_code": "use std::io::stdin;\nuse std::collections::HashSet;\n\nfn read_line<'a>() -> Result> {\n let mut line = String::new();\n stdin().read_line(&mut line)?;\n\n Ok(line.trim().to_owned())\n}\n\nfn main() -> Result<(), Box> {\n let line = read_line()?;\n let mut nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap());\n\n let _ = nums.next().unwrap();\n let mut b = nums.next().unwrap();\n\n let line = read_line()?;\n\n let nums = line\n .split(' ')\n .map(|s| s.parse::().unwrap())\n .collect::>();\n\n let evency = nums\n .iter()\n .map(|n| if n % 2 == 0 { 1 } else { -1 })\n .collect::>();\n\n let mut split_points = HashSet::new();\n let mut s = 0;\n\n for (i, e) in evency[..evency.len() - 1].iter().enumerate() {\n s += e;\n\n // println!(\"{}, {}, {}\", i, s, e);\n\n if s == 0 {\n split_points.insert(i);\n }\n }\n\n let mut diffs = nums\n .iter()\n .zip(&nums[1..])\n .map(|(&prev, &curr)| (curr - prev).abs())\n .enumerate()\n .collect::>();\n \n diffs.sort_unstable_by_key(|&(_, diff)| diff);\n\n println!(\"diffs: {:?}\", diffs);\n println!(\"split_points: {:?}\", split_points);\n\n let mut ans = 0;\n\n for (i, diff) in diffs {\n if split_points.contains(&i) && b >= diff {\n println!(\"split at {}, price {}, current budget: {}\", i, diff, b);\n\n ans += 1;\n b -= diff;\n }\n }\n\n\n println!(\"{}\", ans);\n\n Ok(())\n}\n"}], "src_uid": "b3f8e769ee7719ea5c9f458428b16a4e"} {"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 n = a[0];\n let single = a[2];\n let group = a[3];\n let group_count = a[1];\n let mut best = single * n;\n best = std::cmp::min(best, ((n + (group_count - 1)) / group_count) * group);\n let other = n / group_count * group;\n let rem = n % group_count;\n best = std::cmp::min(other + rem * single, best);\n\n println!(\"{}\", best);\n}\n", "positive_code": [{"source_code": "use std::io::{self, prelude::*, Write};\nuse std::str;\nuse std::string::String;\nuse std::vec::Vec;\n\nuse std::cmp;\n\n#[allow(unused_must_use)]\nfn run(mut reader: Scanner, mut writer: W) {\n let total_number_of_trips: i32 = reader.next();\n let number_of_trips_with_special_ticket: i32 = reader.next();\n let one_trip_price: i32 = reader.next();\n let special_ticket_price: i32 = reader.next();\n\n let number_of_special_tickets_bought: i32 = total_number_of_trips / number_of_trips_with_special_ticket;\n let mut total_cost: i32 = number_of_special_tickets_bought * special_ticket_price;\n let remaining_trips_needed: i32 = total_number_of_trips % number_of_trips_with_special_ticket;\n if remaining_trips_needed > 0 {\n total_cost += cmp::min(remaining_trips_needed * one_trip_price, special_ticket_price);\n }\n\n total_cost = cmp::min(total_cost, total_number_of_trips * one_trip_price);\n\n writeln!(writer, \"{}\", total_cost);\n}\n\nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n\n let reader = Scanner::new(stdin.lock());\n let writer = io::BufWriter::new(stdout.lock());\n run(reader, writer);\n io::stdout().flush().unwrap();\n}\n\npub struct Scanner {\n reader: B,\n buffer_string: Vec,\n buffer_iterator: str::SplitWhitespace<'static>,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n return Self {\n reader,\n buffer_string: Vec::new(),\n buffer_iterator: \"\".split_whitespace()\n };\n }\n\n pub fn next(&mut self) -> T {\n loop {\n //if buffer already exists, just use existing buffer\n if let Some(token) = self.buffer_iterator.next() {\n return token.parse().ok().expect(\"Fail to parse token\");\n }\n\n //get new line\n self.buffer_string.clear();\n self.reader.read_until(b'\\n', &mut self.buffer_string).expect(\"Failed to read\");\n\n //split by white space\n self.buffer_iterator = unsafe {\n let slice = str::from_utf8_unchecked(&self.buffer_string);\n std::mem::transmute(slice.split_whitespace())\n };\n }\n }\n\n pub fn next_line(&mut self) -> String {\n //reset buffer\n self.buffer_iterator = \"\".split_whitespace();\n self.buffer_string.clear();\n\n let mut input: String = String::new();\n self.reader.read_line(&mut input).expect(\"Failed to read line\");\n return input.trim().to_string();\n }\n}"}, {"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 (n, m, a, b) = {\n let temp = input_split();\n (temp[0], temp[1], temp[2], temp[3])\n };\n\n if m * a > b {\n println!(\"{}\", (n / m) * b + b.min((n % m) * a));\n } else {\n println!(\"{}\", n * a);\n }\n}"}, {"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 n = input.i();\n let m = input.i();\n let a = input.i();\n let b = input.i();\n let p = n / m;\n let q = n % m;\n let val = [a*n, a*q+b*p, b*(p+1)];\n let sol = val.iter().min().unwrap();\n println!(\"{}\", sol);\n}\n\n"}, {"source_code": "// 2018-10-12 09:00\nfn main() {\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().split(\" \").map(|s| s.parse::().unwrap()).collect()\n };\n let (n, m, a, b) = (v[0], v[1], v[2], v[3]);\n\n if b / m >= a {\n println!(\"{:?}\", a * n);\n } else {\n if n % m * a > b {\n println!(\"{:?}\", (n as f32 / m as f32).ceil() as i32 * b); \n \n } else {\n println!(\"{:?}\", (n / m) * b + n % m * a);\n }\n\n }\n}\n"}, {"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 (n,m,a,b) = readln!(i32,i32,i32,i32);\n let r1 = n*a;\n let r2 = b*((n+m-1)/m);\n let r3 = b*(n/m) + a*(n%m);\n println!(\"{}\", std::cmp::min(r1,std::cmp::min(r2,r3)));\n}\n"}, {"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, m, a, b) = R!(usize, usize, usize, usize);\n println!(\"{}\", cmp::min(n*a, cmp::min((n%m)*a + (n/m)*b, (n+m-1)/m*b)));\n}\n"}, {"source_code": "use std::io;\nuse std::cmp::min;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n\n let x: Vec = s.trim()\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let n = x[0];\n let m = x[1];\n let a = x[2];\n let b = x[3];\n\n let ans =\n min( a*n,\n min( b*(n/m + 1),\n b*(n/m) + a*(n%m)\n ));\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\nuse std::cmp::min;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n\n let x: Vec = s.trim()\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let n = x[0];\n let m = x[1];\n let a = x[2];\n let b = x[3];\n\n if m * a <= b {\n println!(\"{}\", a*n);\n } else {\n if m > n { \n println!(\"{}\", min(b, a*n));\n } else {\n if a*(n%m) < b {\n println!(\"{}\", b*(n/m)+a*(n%m));\n } else {\n println!(\"{}\", b*(n/m+1));\n }\n }\n }\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let params: Vec = reads(sin);\n\n let n = params[0];\n let m = params[1];\n let a = params[2];\n let b = params[3];\n\n let ans = if a * m < b {\n n * a\n } else {\n let base = n / m;\n let remain = n % m;\n (base * b) + std::cmp::min(remain * a, b)\n };\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/466/A\nuse std::io;\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 m = words[1];\n let a = words[2];\n let b = words[3];\n\n let sale: f64 = b as f64/m as f64;\n\n if sale < a as f64 {\n let mut ans = (n as f64/m as f64).floor() as i64*b;\n let minima = std::cmp::min((n%m)*a, b);\n ans += minima;\n println!(\"{}\", ans);\n } else {\n println!(\"{}\", n*a);\n }\n}\n\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp;\n#[allow(unused_imports)]\nuse std::collections::BTreeSet;\n#[allow(unused_imports)]\nuse std::collections::HashSet;\nuse std::fs::File;\nuse std::io::Read;\n#[allow(unused_imports)]\nuse std::mem;\nuse std::fmt::Display;\n\n#[allow(dead_code)]\nfn pow_speedy_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\n#[allow(dead_code)]\nfn comb(n: usize, k: usize, m: i64, frac: &[i64], frac_inv: &[i64]) -> i64 {\n let mut ret = 1i64;\n if n < k {\n return 0;\n }\n ret *= frac[n] * frac_inv[n - k];\n ret %= m;\n ret *= frac_inv[k];\n ret %= m;\n ret\n}\n\n#[allow(dead_code)]\nfn show1dvec(v : &Vec) {\n let n = v.len();\n for i in 0..n - 1 {\n print!(\"{} \" , v[i]);\n }\n println!(\"{} \" , v[n - 1]);\n}\n\n\n#[derive(Debug)]\nstruct Piece {\n mark: char,\n y: i32,\n x: i32,\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\n let n: i32 = iter.next().unwrap().parse().unwrap();\n let m: i32 = iter.next().unwrap().parse().unwrap();\n let a: i32 = iter.next().unwrap().parse().unwrap();\n let b: i32 = iter.next().unwrap().parse().unwrap();\n\n println!(\"{}\", cmp::min(cmp::min(n * a, (n + m - 1) / m * b), (n % m) * a + (n / m) * b));\n\n // let n = iter.next().unwrap().parse().unwrap();\n\n // println!(\"{}\", n);\n // println!(\"{:?}\", cum_num);\n}\n"}, {"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 a: isize = scan.next();\n let b: isize = scan.next();\n if a*m <= b {\n println!(\"{}\", a*n);\n } else {\n let mut result = (n/m)*b;\n if b <= a*(n%m) { result += b; }\n else { result += (n%m)*a; }\n println!(\"{}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"source_code": "use std::cmp::min;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut n_m_a_b : Vec = vec![];\n read_ts(&stdin, &mut n_m_a_b);\n let n = n_m_a_b[0];\n let m = n_m_a_b[1];\n let a = n_m_a_b[2];\n let b = n_m_a_b[3];\n let cost_1 = n * a;\n let cost_2 = ((n / m) * b) + min((n % m) * a, b);\n let min_cost = min(cost_1, cost_2);\n println!(\"{}\", min_cost);\n}\n"}, {"source_code": "fn solve() {\n let (n, m, a, b) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let v: Vec = buf.split_whitespace().map(|x| x.parse().unwrap()).collect();\n (v[0], v[1], v[2], v[3])\n };\n\n let mut ans = 0;\n if b < m * a {\n let d = n / m;\n ans += d * b;\n if b < a * (n - d * m) {\n ans += b;\n } else {\n ans += (n - d * m) * a;\n }\n } else {\n ans += n * a;\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n // let t: u32 = {\n // let mut buf = String::new();\n // std::io::stdin().read_line(&mut buf).unwrap();\n // buf.trim_end().parse().unwrap()\n // };\n\n solve();\n // for _ in 0..t {}\n}\n"}, {"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 n = a[0];\n let single = a[2];\n let group = a[3];\n let group_count = a[1];\n let mut best = single * n;\n best = std::cmp::min(best, ((n + (group_count - 1)) / group_count) * group);\n\n let other = n / group_count * group;\n let rem = n % group_count;\n\n best = std::cmp::min(other + rem * single, best);\n best = std::cmp::min(other + group, best);\n\n println!(\"{}\", best);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn read_line() -> String {\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed to read line!\");\n input\n}\n\nfn main() {\n let input1 = read_line();\n let line1: Vec<&str> = input1.split(\" \").collect();\n let n = line1[0].trim().parse::().unwrap();\n let m = line1[1].trim().parse::().unwrap();\n let a = line1[2].trim().parse::().unwrap();\n let b = line1[3].trim().parse::().unwrap();\n\n let costs: i32;\n if b <= a {\n costs = f32::ceil(n as f32 / m as f32) as i32 * b;\n } else if b / m < a {\n if m > n {\n if n * a > b {\n costs = b;\n } else {\n costs = n * a;\n }\n } else {\n costs = (n % m) * a + f32::floor(n as f32 / m as f32) as i32 * b\n }\n } else {\n costs = n * a;\n }\n println!(\"{}\", costs);\n}\n"}], "negative_code": [{"source_code": "use std::io::{self, prelude::*, Write};\nuse std::str;\nuse std::string::String;\nuse std::vec::Vec;\n\nuse std::cmp;\n\n#[allow(unused_must_use)]\nfn run(mut reader: Scanner, mut writer: W) {\n let total_number_of_trips: i32 = reader.next();\n let number_of_trips_with_special_ticket: i32 = reader.next();\n let one_trip_price: i32 = reader.next();\n let special_ticket_price: i32 = reader.next();\n\n let number_of_special_tickets_bought: i32 = total_number_of_trips / number_of_trips_with_special_ticket;\n let mut total_cost: i32 = number_of_special_tickets_bought * special_ticket_price;\n let remaining_trips_needed: i32 = total_number_of_trips % number_of_trips_with_special_ticket;\n if remaining_trips_needed > 0 {\n total_cost += cmp::min(remaining_trips_needed * one_trip_price, special_ticket_price);\n }\n\n writeln!(writer, \"{}\", total_cost);\n}\n\nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n\n let reader = Scanner::new(stdin.lock());\n let writer = io::BufWriter::new(stdout.lock());\n run(reader, writer);\n io::stdout().flush().unwrap();\n}\n\npub struct Scanner {\n reader: B,\n buffer_string: Vec,\n buffer_iterator: str::SplitWhitespace<'static>,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n return Self {\n reader,\n buffer_string: Vec::new(),\n buffer_iterator: \"\".split_whitespace()\n };\n }\n\n pub fn next(&mut self) -> T {\n loop {\n //if buffer already exists, just use existing buffer\n if let Some(token) = self.buffer_iterator.next() {\n return token.parse().ok().expect(\"Fail to parse token\");\n }\n\n //get new line\n self.buffer_string.clear();\n self.reader.read_until(b'\\n', &mut self.buffer_string).expect(\"Failed to read\");\n\n //split by white space\n self.buffer_iterator = unsafe {\n let slice = str::from_utf8_unchecked(&self.buffer_string);\n std::mem::transmute(slice.split_whitespace())\n };\n }\n }\n\n pub fn next_line(&mut self) -> String {\n //reset buffer\n self.buffer_iterator = \"\".split_whitespace();\n self.buffer_string.clear();\n\n let mut input: String = String::new();\n self.reader.read_line(&mut input).expect(\"Failed to read line\");\n return input.trim().to_string();\n }\n}"}, {"source_code": "use std::io::{self, prelude::*, Write};\nuse std::str;\nuse std::string::String;\nuse std::vec::Vec;\n\n#[allow(unused_must_use)]\nfn run(mut reader: Scanner, mut writer: W) {\n let total_number_of_trips: i32 = reader.next();\n let number_of_trips_with_special_ticket: i32 = reader.next();\n let one_trip_price: i32 = reader.next();\n let special_ticket_price: i32 = reader.next();\n\n let number_of_special_tickets_bought: i32 = total_number_of_trips / number_of_trips_with_special_ticket;\n let mut total_cost: i32 = number_of_special_tickets_bought * special_ticket_price;\n let remaining_trips_needed: i32 = total_number_of_trips % number_of_trips_with_special_ticket;\n if remaining_trips_needed > 0 {\n total_cost += remaining_trips_needed * one_trip_price;\n }\n\n writeln!(writer, \"{}\", total_cost);\n}\n\nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n\n let reader = Scanner::new(stdin.lock());\n let writer = io::BufWriter::new(stdout.lock());\n run(reader, writer);\n io::stdout().flush().unwrap();\n}\n\npub struct Scanner {\n reader: B,\n buffer_string: Vec,\n buffer_iterator: str::SplitWhitespace<'static>,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n return Self {\n reader,\n buffer_string: Vec::new(),\n buffer_iterator: \"\".split_whitespace()\n };\n }\n\n pub fn next(&mut self) -> T {\n loop {\n //if buffer already exists, just use existing buffer\n if let Some(token) = self.buffer_iterator.next() {\n return token.parse().ok().expect(\"Fail to parse token\");\n }\n\n //get new line\n self.buffer_string.clear();\n self.reader.read_until(b'\\n', &mut self.buffer_string).expect(\"Failed to read\");\n\n //split by white space\n self.buffer_iterator = unsafe {\n let slice = str::from_utf8_unchecked(&self.buffer_string);\n std::mem::transmute(slice.split_whitespace())\n };\n }\n }\n\n pub fn next_line(&mut self) -> String {\n //reset buffer\n self.buffer_iterator = \"\".split_whitespace();\n self.buffer_string.clear();\n\n let mut input: String = String::new();\n self.reader.read_line(&mut input).expect(\"Failed to read line\");\n return input.trim().to_string();\n }\n}"}, {"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 (n, m, a, b) = {\n let temp = input_split();\n (temp[0], temp[1], temp[2], temp[3])\n };\n\n if m * a > b {\n println!(\"{}\", (n / m) * b + b.min((n % m) * a));\n } else {\n println!(\"{}\", n * a);\n }\n}"}, {"source_code": "// 2018-10-12 09:00\nfn main() {\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().split(\" \").map(|s| s.parse::().unwrap()).collect()\n };\n let (n, m, a, b) = (v[0], v[1], v[2], v[3]);\n\n if b / m >= a {\n println!(\"{:?}\", a * n);\n } else {\n println!(\"{:?}\", (n as f32 / m as f32).ceil() as i32 * b);\n }\n}\n"}, {"source_code": "// 2018-10-12 09:00\nfn main() {\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().split(\" \").map(|s| s.parse::().unwrap()).collect()\n };\n let (n, m, a, b) = (v[0], v[1], v[2], v[3]);\n \n if b / m >= a {\n println!(\"{:?}\", a * n);\n } else {\n println!(\"{:?}\", n / m * b + n % m * a);\n }\n}\n"}, {"source_code": "use std::io;\nuse std::cmp::min;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n\n let x: Vec = s.trim()\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let n = x[0];\n let m = x[1];\n let a = x[2];\n let b = x[3];\n\n if m * a <= b {\n println!(\"{}\", a*n);\n } else {\n if m > n { \n println!(\"{}\", min(b, a*n));\n } else {\n println!(\"{}\", b*(n/m)+a*(n%m));\n }\n }\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/466/A\nuse std::io;\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 m = words[1];\n let a = words[2];\n let b = words[3];\n\n let sale: f64 = b/m;\n\n if sale < a {\n println!(\"{}\", (n/m).floor()*b + (n%m)*a);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/466/A\nuse std::io;\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 m = words[1];\n let a = words[2];\n let b = words[3];\n\n let sale: f64 = b/m;\n\n if sale < a {\n println!(\"{}\", (n/m).floor()*b + (n%m)*a);\n } else {\n println!(\"{}\", n*a);\n }\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/466/A\nuse std::io;\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 m = words[1];\n let a = words[2];\n let b = words[3];\n\n let sale: f64 = b/m;\n\n if sale < a {\n println!(\"{}\", (n/m).floor()*b + (n%m)*a);\n } else {\n println!(\"{}\", a);\n }\n}\n\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp;\n#[allow(unused_imports)]\nuse std::collections::BTreeSet;\n#[allow(unused_imports)]\nuse std::collections::HashSet;\nuse std::fs::File;\nuse std::io::Read;\n#[allow(unused_imports)]\nuse std::mem;\nuse std::fmt::Display;\n\n#[allow(dead_code)]\nfn pow_speedy_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\n#[allow(dead_code)]\nfn comb(n: usize, k: usize, m: i64, frac: &[i64], frac_inv: &[i64]) -> i64 {\n let mut ret = 1i64;\n if n < k {\n return 0;\n }\n ret *= frac[n] * frac_inv[n - k];\n ret %= m;\n ret *= frac_inv[k];\n ret %= m;\n ret\n}\n\n#[allow(dead_code)]\nfn show1dvec(v : &Vec) {\n let n = v.len();\n for i in 0..n - 1 {\n print!(\"{} \" , v[i]);\n }\n println!(\"{} \" , v[n - 1]);\n}\n\n\n#[derive(Debug)]\nstruct Piece {\n mark: char,\n y: i32,\n x: i32,\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\n let n: i32 = iter.next().unwrap().parse().unwrap();\n let m: i32 = iter.next().unwrap().parse().unwrap();\n let a: i32 = iter.next().unwrap().parse().unwrap();\n let b: i32 = iter.next().unwrap().parse().unwrap();\n\n println!(\"{}\", cmp::min(n * a, (n % m) * a + (n / m) * b));\n\n // let n = iter.next().unwrap().parse().unwrap();\n\n // println!(\"{}\", n);\n // println!(\"{:?}\", cum_num);\n}\n"}, {"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 a: isize = scan.next();\n let b: isize = scan.next();\n if a*m <= b {\n println!(\"{}\", a*n);\n } else {\n let mut result = (n/m)*b;\n if b <= a*(n%m) { result += 1; }\n else { result += (n%m)*a; }\n println!(\"{}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"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 a: isize = scan.next();\n let b: isize = scan.next();\n if a*m <= b {\n println!(\"{}\", a*n);\n } else {\n let result = n/m*b + n%m*a;\n println!(\"{}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"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 a: isize = scan.next();\n let b: isize = scan.next();\n if a*m <= b {\n println!(\"{}\", a*n);\n } else {\n let result = (n/m)*b + (n%m)*a;\n println!(\"{}\", result);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}, {"source_code": "use std::cmp::min;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut n_m_a_b : Vec = vec![];\n read_ts(&stdin, &mut n_m_a_b);\n let n = n_m_a_b[0];\n let m = n_m_a_b[1];\n let a = n_m_a_b[2];\n let b = n_m_a_b[3];\n let cost_1 = n * a;\n let cost_2 = ((n / m) * b) + ((n % m) * a);\n let min_cost = min(cost_1, cost_2);\n println!(\"{}\", min_cost);\n}\n"}, {"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 n = a[0];\n let single = a[2];\n let group = a[3];\n let group_count = a[1];\n\n if (single * group_count) <= group {\n println!(\"{}\", single * n);\n } else if group < single {\n println!(\"{}\", (n + (group_count - 1)) / group_count * group);\n } else {\n println!(\"{}\", n / group_count * group + (n % group_count) * single);\n }\n}\n"}, {"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 n = a[0];\n let single = a[2];\n let group = a[3];\n let group_count = a[1];\n\n if (single * group_count) <= group {\n println!(\"{}\", single * n);\n } else {\n println!(\"{}\", n / group_count * group + (n % group_count) * single);\n }\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn read_line() -> String {\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed to read line!\");\n input\n}\n\nfn main() {\n let input1 = read_line();\n let line1: Vec<&str> = input1.split(\" \").collect();\n let n = line1[0].trim().parse::().unwrap();\n let m = line1[1].trim().parse::().unwrap();\n let a = line1[2].trim().parse::().unwrap();\n let b = line1[3].trim().parse::().unwrap();\n\n let costs: i32;\n if b / m < a {\n costs = (n % m) * a + f32::floor(n as f32 / m as f32) as i32 * b\n } else {\n costs = n * a;\n }\n println!(\"{}\", costs);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn read_line() -> String {\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed to read line!\");\n input\n}\n\nfn main() {\n let input1 = read_line();\n let line1: Vec<&str> = input1.split(\" \").collect();\n let n = line1[0].trim().parse::().unwrap();\n let m = line1[1].trim().parse::().unwrap();\n let a = line1[2].trim().parse::().unwrap();\n let b = line1[3].trim().parse::().unwrap();\n\n let costs: i32;\n if b <= a {\n costs = f32::ceil(n as f32 / m as f32) as i32 * b;\n } else if b / m < a {\n costs = (n % m) * a + f32::floor(n as f32 / m as f32) as i32 * b\n } else {\n costs = n * a;\n }\n println!(\"{}\", costs);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn read_line() -> String {\n let mut input = String::new();\n stdin().read_line(&mut input).expect(\"Failed to read line!\");\n input\n}\n\nfn main() {\n let input1 = read_line();\n let line1: Vec<&str> = input1.split(\" \").collect();\n let n = line1[0].trim().parse::().unwrap();\n let m = line1[1].trim().parse::().unwrap();\n let a = line1[2].trim().parse::().unwrap();\n let b = line1[3].trim().parse::().unwrap();\n\n let costs: i32;\n if b <= a {\n costs = f32::ceil(n as f32 / m as f32) as i32 * b;\n } else if b / m < a {\n if m > n {\n if n * a > m * b {\n costs = m * b;\n } else {\n costs = n * a;\n }\n } else {\n costs = (n % m) * a + f32::floor(n as f32 / m as f32) as i32 * b\n }\n } else {\n costs = n * a;\n }\n println!(\"{}\", costs);\n}\n"}], "src_uid": "faa343ad6028c5a069857a38fa19bb24"} {"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 println!(\"Karen\");\n}\n", "positive_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet};\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\nfn main() {\n let n: usize = util::get();\n let a: Vec = util::gets();\n let b: Vec = util::gets();\n\n let mut set = HashSet::new();\n for i in 0..n {\n set.insert(a[i]);\n set.insert(b[i]);\n }\n\n let mut cnt = 0;\n\n for i in 0..n {\n for k in 0..n {\n let xor = a[i] ^ b[k];\n if set.contains(&xor) {\n cnt += 1;\n }\n }\n }\n\n if cnt % 2 == 0 {\n println!(\"Karen\");\n } else {\n println!(\"Koyomi\");\n }\n\n}\n"}, {"source_code": "fn main() {\n println!(\"Karen\");\n}"}, {"source_code": "#![allow(dead_code, unused_imports)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn partial_sum(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + std::ops::Add + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = *state + x;\n Some(*state)\n })\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != 0 {\n let old_m = a;\n a = b % a;\n b = old_m;\n }\n b\n}\n\n/// returns gcd, and pair (x, y), such that x * a + b * y == gcd\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if a == 0 {\n (b, 0, 1)\n } else {\n let (g, x, y) = egcd(b % a, a);\n (g, y - (b / a) * x, x)\n }\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n if n == 0 {\n return vec![0];\n } else if n == 1 {\n return vec![1];\n }\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nfn abs_diff(a: T, b: T) -> T\nwhere\n T: PartialOrd + std::ops::Sub,\n{\n if a > b {\n a - b\n } else {\n b - a\n }\n}\n\nstruct Permutations {\n inner: Vec,\n state: Vec,\n i: usize,\n start: bool,\n}\n\nimpl Permutations {\n fn new(inner: Vec) -> Self {\n Self {\n state: vec![0; inner.len()],\n i: 0,\n start: true,\n inner,\n }\n }\n}\n\n/*impl From for Permutations\nwhere\n X: IntoIterator,\n{\n fn from(f: X) -> Self {\n Self::new(f.into_iter().collect::>())\n }\n}*/\n\nimpl Iterator for Permutations\nwhere\n T: Clone,\n{\n type Item = Vec;\n fn next(&mut self) -> Option {\n if self.start {\n self.start = false;\n return Some(self.inner.clone());\n }\n while self.i < self.inner.len() {\n if self.state[self.i] < self.i {\n if self.i % 2 == 0 {\n self.inner.swap(0, self.i)\n } else {\n self.inner.swap(self.state[self.i], self.i)\n }\n self.state[self.i] += 1;\n self.i = 0;\n return Some(self.inner.clone());\n } else {\n self.state[self.i] = 0;\n self.i += 1;\n }\n }\n None\n }\n}\n\nuse std::cmp::{max, min, Ord, Ordering};\nuse std::collections::{BinaryHeap, VecDeque};\nuse std::mem::swap;\n\n#[derive(Clone)]\nstruct Graph {\n nodes: usize,\n edges: Vec>,\n}\n\nimpl Graph {\n fn new(n: usize) -> Self {\n Self {\n nodes: n,\n edges: vec![Vec::new(); n + 1],\n }\n }\n\n fn add_edge(&mut self, x: usize, y: usize, cost: u64) {\n self.edges[x].push((y, cost));\n self.edges[y].push((x, cost));\n }\n\n fn dijkstra(&mut self, start: usize, end: usize) -> u64 {\n let mut dist = vec![None; self.nodes + 1];\n let mut prev = vec![None; self.nodes + 1];\n dist[start] = Some(0);\n let mut queue = (1..=self.nodes).collect::>();\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n while let Some(next_node) = queue.pop() {\n if next_node == end {\n return dist[next_node].unwrap();\n }\n for (neighbour, cost) in self.edges[next_node].iter() {\n let alt = dist[next_node].unwrap() + cost;\n if dist[*neighbour].is_none() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n } else {\n if alt < dist[*neighbour].unwrap() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n }\n }\n }\n //println!(\"{:?} {:?}\", dist, prev);\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n }\n 0\n }\n\n fn set_cost(&mut self, x: usize, y: usize, cost: u64) {\n for i in 0..self.edges[x].len() {\n if self.edges[x][i].0 == y {\n self.edges[x][i].1 = cost\n }\n }\n for i in 0..self.edges[y].len() {\n if self.edges[y][i].0 == x {\n self.edges[y][i].1 = cost\n }\n }\n }\n}\n\nconst MODULO: u64 = 1_000_000_007;\n\n#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]\nstruct BigPrimeRing {\n inner: u64,\n}\n\nimpl From for BigPrimeRing\nwhere\n T: Into,\n{\n fn from(n: T) -> Self {\n Self {\n inner: n.into() % MODULO,\n }\n }\n}\n\nimpl std::ops::Add for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn add(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner + rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::AddAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn add_assign(&mut self, rhs: T) {\n self.inner += rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl std::ops::Sub for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn sub(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner + MODULO - rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::SubAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn sub_assign(&mut self, rhs: T) {\n self.inner += MODULO;\n self.inner -= rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl std::ops::Mul for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn mul(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner * rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::MulAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn mul_assign(&mut self, rhs: T) {\n self.inner *= rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl BigPrimeRing {\n fn inverse(self) -> Self {\n if self.inner == 0 {\n return self;\n }\n let (_g, mut x, _y) = egcd(self.inner as i64, MODULO as i64);\n if x < 0 {\n x += MODULO as i64;\n }\n Self { inner: x as u64 }\n }\n}\n\nfn main() -> Result<(), Box> {\n println!(\"Karen\");\n Ok(())\n}\n"}, {"source_code": "// Basics\n\n#![allow(unused_imports)]\n\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}\n\nfn loads() -> 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: i32 = i.trim().parse().unwrap();\n data.push(el);\n }\n data\n}\n\nfn main() {\n let n = loads()[0] as usize;\n let a = load();\n let b = load();\n let mut s: HashSet<&i64> = HashSet::new();\n for i in 0..n {\n s.insert(&a[i]);\n s.insert(&b[i]);\n }\n let mut res = 0;\n for i in 0..n {\n for j in 0..n {\n let x: i64 = a[i] ^ a[j];\n if s.contains(&x) {\n res += 1;\n }\n }\n }\n println!(\"{}\", if res % 2 == 0 { \"Karen\" } else { \"Koyomi\" });\n}\n\n//\n//mod strings;\n//\n//fn main() {\n// strings_sample();\n//}\n"}], "negative_code": [{"source_code": "#![allow(dead_code, unused_imports)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn partial_sum(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + std::ops::Add + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = *state + x;\n Some(*state)\n })\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != 0 {\n let old_m = a;\n a = b % a;\n b = old_m;\n }\n b\n}\n\n/// returns gcd, and pair (x, y), such that x * a + b * y == gcd\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if a == 0 {\n (b, 0, 1)\n } else {\n let (g, x, y) = egcd(b % a, a);\n (g, y - (b / a) * x, x)\n }\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n if n == 0 {\n return vec![0];\n } else if n == 1 {\n return vec![1];\n }\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nfn abs_diff(a: T, b: T) -> T\nwhere\n T: PartialOrd + std::ops::Sub,\n{\n if a > b {\n a - b\n } else {\n b - a\n }\n}\n\nstruct Permutations {\n inner: Vec,\n state: Vec,\n i: usize,\n start: bool,\n}\n\nimpl Permutations {\n fn new(inner: Vec) -> Self {\n Self {\n state: vec![0; inner.len()],\n i: 0,\n start: true,\n inner,\n }\n }\n}\n\n/*impl From for Permutations\nwhere\n X: IntoIterator,\n{\n fn from(f: X) -> Self {\n Self::new(f.into_iter().collect::>())\n }\n}*/\n\nimpl Iterator for Permutations\nwhere\n T: Clone,\n{\n type Item = Vec;\n fn next(&mut self) -> Option {\n if self.start {\n self.start = false;\n return Some(self.inner.clone());\n }\n while self.i < self.inner.len() {\n if self.state[self.i] < self.i {\n if self.i % 2 == 0 {\n self.inner.swap(0, self.i)\n } else {\n self.inner.swap(self.state[self.i], self.i)\n }\n self.state[self.i] += 1;\n self.i = 0;\n return Some(self.inner.clone());\n } else {\n self.state[self.i] = 0;\n self.i += 1;\n }\n }\n None\n }\n}\n\nuse std::cmp::{max, min, Ord, Ordering};\nuse std::collections::{BinaryHeap, VecDeque};\nuse std::mem::swap;\n\n#[derive(Clone)]\nstruct Graph {\n nodes: usize,\n edges: Vec>,\n}\n\nimpl Graph {\n fn new(n: usize) -> Self {\n Self {\n nodes: n,\n edges: vec![Vec::new(); n + 1],\n }\n }\n\n fn add_edge(&mut self, x: usize, y: usize, cost: u64) {\n self.edges[x].push((y, cost));\n self.edges[y].push((x, cost));\n }\n\n fn dijkstra(&mut self, start: usize, end: usize) -> u64 {\n let mut dist = vec![None; self.nodes + 1];\n let mut prev = vec![None; self.nodes + 1];\n dist[start] = Some(0);\n let mut queue = (1..=self.nodes).collect::>();\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n while let Some(next_node) = queue.pop() {\n if next_node == end {\n return dist[next_node].unwrap();\n }\n for (neighbour, cost) in self.edges[next_node].iter() {\n let alt = dist[next_node].unwrap() + cost;\n if dist[*neighbour].is_none() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n } else {\n if alt < dist[*neighbour].unwrap() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n }\n }\n }\n //println!(\"{:?} {:?}\", dist, prev);\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n }\n 0\n }\n\n fn set_cost(&mut self, x: usize, y: usize, cost: u64) {\n for i in 0..self.edges[x].len() {\n if self.edges[x][i].0 == y {\n self.edges[x][i].1 = cost\n }\n }\n for i in 0..self.edges[y].len() {\n if self.edges[y][i].0 == x {\n self.edges[y][i].1 = cost\n }\n }\n }\n}\n\nconst MODULO: u64 = 1_000_000_007;\n\n#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]\nstruct BigPrimeRing {\n inner: u64,\n}\n\nimpl From for BigPrimeRing\nwhere\n T: Into,\n{\n fn from(n: T) -> Self {\n Self {\n inner: n.into() % MODULO,\n }\n }\n}\n\nimpl std::ops::Add for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn add(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner + rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::AddAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn add_assign(&mut self, rhs: T) {\n self.inner += rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl std::ops::Sub for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn sub(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner + MODULO - rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::SubAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn sub_assign(&mut self, rhs: T) {\n self.inner += MODULO;\n self.inner -= rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl std::ops::Mul for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn mul(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner * rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::MulAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn mul_assign(&mut self, rhs: T) {\n self.inner *= rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl BigPrimeRing {\n fn inverse(self) -> Self {\n if self.inner == 0 {\n return self;\n }\n let (_g, mut x, _y) = egcd(self.inner as i64, MODULO as i64);\n if x < 0 {\n x += MODULO as i64;\n }\n Self { inner: x as u64 }\n }\n}\n\nfn main() -> Result<(), Box> {\n let _n = read_usize();\n let a_vec = read_multiple::();\n let b_vec = read_multiple::();\n let mut count = 0;\n for (a, b) in a_vec.iter().zip(b_vec.iter()) {\n if a_vec.contains(&(a ^ b)) || b_vec.contains(&(a ^ b)) {\n count += 1;\n }\n }\n if count % 2 == 0 {\n println!(\"Karen\")\n } else {\n println!(\"Koyomi\")\n }\n Ok(())\n}\n"}], "src_uid": "1649d2592eadaa8f8d076eae2866cffc"} {"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 binary_search(s: &Vec, v:i64) -> usize {\n let mut left = 0;\n let mut right = s.len();\n\n while right-left > 1 {\n let mid = (right+left)/2;\n //debug!(left,mid,right,s[mid]);\n if s[mid] < v { left = mid; }\n else { right = mid; }\n }\n left\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let m:usize = read();\n let mut p:Vec<(usize,usize,i64,usize)> = (0..m).map(|i| (read::()-1,read::()-1,read(),i)).collect();\n\n let mut v = vec![];\n\n let mut f = vec![false;m];\n let mut c = vec![0;m];\n for i in 0..m { c[i] = p[i].2; }\n\n for i in 0..n {\n // examがあれば実行\n let mut idx = m;\n for j in 0..m {\n if p[j].1 == i {\n idx = j;\n }\n }\n if idx != m {\n if c[idx] == 0 {\n v.push(m+1);\n continue;\n } else {\n println!(\"-1\");\n return;\n }\n }\n // 可能なタスクの中で締め切りの近いものを求める\n let mut idx = m;\n let mut dead = n;\n for j in 0..m {\n if !f[j] && p[j].0 <= i && i < p[j].1 {\n if dead > p[j].1 {\n dead = p[j].1;\n idx = j;\n }\n }\n }\n\n // 可能なタスクがない場合は休む\n if idx == m {\n v.push(0);\n continue;\n }\n\n // タスクを実行\n v.push(idx+1);\n c[idx] -= 1;\n if c[idx] == 0 {\n f[idx] = true;\n }\n\n }\n\n for e in v {print!(\"{} \", e);} println!();\n\n //}\n}\n\n/*\n\n\n*/\n", "positive_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::*;\n#[allow(unused_imports)]\nuse std::collections::*;\nuse std::io::{Read, Write, BufWriter};\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/**\n * Dinic's algorithm for maximum flow problem.\n * Verified by: yukicoder No.177 (http://yukicoder.me/submissions/148371)\n * Min-cut (the second element of max_flow's returned values) is not verified.\n */\n\n#[derive(Clone)]\nstruct Edge {\n to: usize,\n cap: T,\n rev: usize, // rev is the position of the reverse edge in graph[to]\n}\n\nstruct Dinic {\n graph: Vec>>,\n iter: Vec,\n zero: T,\n}\n\nimpl Dinic\n where T: Clone,\n T: Copy,\n T: Ord,\n T: std::ops::AddAssign,\n T: std::ops::SubAssign,\n{\n fn bfs(&self, s: usize, level: &mut [Option]) {\n let n = level.len();\n for i in 0 .. n {\n level[i] = None;\n }\n let mut que = std::collections::VecDeque::new();\n level[s] = Some(0);\n que.push_back(s);\n while let Some(v) = que.pop_front() {\n for e in self.graph[v].iter() {\n\t if e.cap > self.zero && level[e.to] == None {\n\t level[e.to] = Some(level[v].unwrap() + 1);\n\t que.push_back(e.to);\n }\n }\n\t}\n }\n /* search augment path by dfs.\n * if f == None, f is treated as infinity.\n */\n fn dfs(&mut self, v: usize, t: usize, f: Option, level: &mut [Option]) -> T {\n if v == t {\n return f.unwrap();\n }\n while self.iter[v] < self.graph[v].len() {\n let i = self.iter[v];\n let e = self.graph[v][i].clone();\n if e.cap > self.zero && level[v] < level[e.to] {\n let newf = std::cmp::min(f.unwrap_or(e.cap), e.cap);\n let d = self.dfs(e.to, t, Some(newf), level);\n if d > self.zero {\n self.graph[v][i].cap -= d;\n self.graph[e.to][e.rev].cap += d;\n return d;\n }\n }\n self.iter[v] += 1;\n }\n self.zero\n }\n pub fn new(n: usize, zero: T) -> Self {\n Dinic {\n graph: vec![Vec::new(); n],\n iter: vec![0; n],\n zero: zero,\n }\n }\n pub fn add_edge(&mut self, from: usize, to: usize, cap: T) {\n let added_from = Edge { to: to, cap: cap,\n rev: self.graph[to].len() };\n let added_to = Edge { to: from, cap: self.zero,\n rev: self.graph[from].len() };\n self.graph[from].push(added_from);\n self.graph[to].push(added_to);\n }\n pub fn max_flow(&mut self, s: usize, t: usize) -> (T, Vec) {\n let mut flow = self.zero;\n let n = self.graph.len();\n let mut level = vec![None; n];\n loop {\n self.bfs(s, &mut level);\n if level[t] == None {\n let ret = (0 .. n).filter(|&i| level[i] == None)\n .collect();\n return (flow, ret);\n }\n self.iter.clear();\n self.iter.resize(n, 0);\n loop {\n let f = self.dfs(s, t, None, &mut level);\n if f <= self.zero { break; }\n flow += f;\n }\n }\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:expr) => (write!(out,$format).unwrap());\n ($format:expr, $($args:expr),+) => (write!(out,$format,$($args),*).unwrap())\n }\n let n = get();\n let m = get();\n let mut s = vec![0; n];\n let mut t = vec![0; n];\n let mut c = vec![0; n];\n let mut ex = vec![false; n];\n for i in 0 .. m {\n s[i] = get::() - 1;\n t[i] = get::() - 1;\n c[i] = get::();\n ex[t[i]] = true;\n }\n let mut din = Dinic::new(2 + n + m, 0);\n let mut expect = 0;\n for i in 0 .. n {\n din.add_edge(0, 2 + i, 1);\n }\n for i in 0 .. m {\n din.add_edge(2 + n + i, 1, c[i]);\n expect += c[i];\n }\n for i in 0 .. m {\n for j in s[i] .. t[i] {\n if !ex[j] {\n din.add_edge(2 + j, 2 + n + i, 1);\n }\n }\n }\n let (ans, _) = din.max_flow(0, 1);\n if ans != expect {\n puts!(\"-1\\n\");\n return;\n }\n let mut ans = vec![0; n];\n let graph = din.graph;\n for (i, g) in graph.into_iter().enumerate() {\n if i < 2 || i >= 2 + n { continue; }\n let v = i - 2;\n if ex[v] {\n ans[v] = m + 1;\n continue;\n }\n for Edge { to: to, cap: cap, rev: _ } in g {\n if to < 2 + n { continue; }\n let w = to - 2 - n;\n if cap == 0 {\n ans[v] = 1 + w;\n }\n }\n }\n for i in 0 .. n {\n puts!(\"{}{}\", ans[i], if i == n - 1 { \"\\n\" } else { \" \" });\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"}], "negative_code": [{"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 binary_search(s: &Vec, v:i64) -> usize {\n let mut left = 0;\n let mut right = s.len();\n\n while right-left > 1 {\n let mid = (right+left)/2;\n //debug!(left,mid,right,s[mid]);\n if s[mid] < v { left = mid; }\n else { right = mid; }\n }\n left\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let m:usize = read();\n let mut p:Vec<(usize,usize,i64,usize)> = (0..m).map(|i| (read::()-1,read::()-1,read(),i)).collect();\n\n p.sort_by(|a,b| a.0.cmp(&b.0));\n //debug!(p);\n\n let mut e = vec![m;n];\n let mut c = vec![0;m];\n for i in 0..m {\n e[p[i].1] = i;\n c[p[i].3] = p[i].2;\n }\n\n let mut idx = 0;\n let mut v = vec![];\n for i in 0..n {\n if e[i] != m {\n if c[e[i]] != 0 {\n println!(\"-1\");\n return;\n }\n v.push(m+1);\n }\n else if idx == m {\n v.push(0);\n }\n else if i >= p[idx].0 {\n v.push(p[idx].3+1);\n c[p[idx].3] -= 1;\n if c[p[idx].3] == 0 {\n idx += 1;\n }\n }\n else {\n v.push(0);\n }\n }\n //debug!(v);\n for e in v {print!(\"{} \", e);} println!();\n\n //}\n}\n\n/*\n\n\n*/\n"}], "src_uid": "02d8d403eb60ae77756ff96f71b662d3"} {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n\n #[allow(dead_code)]\n pub fn get3() -> (S, T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {:?}\", stringify!($x), $x)\n }\n}\n\nfn main() {\n let n: usize = util::get();\n let ss: Vec> = (0..n)\n .map(|_| {\n let mut v: Vec = util::gets();\n v.sort();\n v\n })\n .collect();\n\n let ans = (1..)\n .take_while(|&x| if x < 10 {\n ss.iter().any(|v| v.binary_search(&x).is_ok())\n } else if x < 100 {\n let a1 = x % 10;\n let a2 = x / 10;\n\n let h1 = (0..ss.len())\n .filter(|&i| ss[i].binary_search(&a1).is_ok())\n .collect::>();\n let h2 = (0..ss.len())\n .filter(|&i| ss[i].binary_search(&a2).is_ok())\n .collect::>();\n\n (h1.len() > 1 && h2.len() > 1) ||\n (h1.len() > 0 && h2.len() > 0 &&\n (h1.difference(&h2).count() != 0 || h2.difference(&h1).count() != 0))\n\n } else {\n let perm = vec![\n vec![0, 1, 2],\n vec![0, 2, 1],\n vec![1, 0, 2],\n vec![1, 2, 0],\n vec![2, 0, 1],\n vec![2, 1, 0],\n ];\n\n let a1 = x % 10;\n let a2 = x / 10 % 10;\n let a3 = x / 100;\n let a = vec![a1, a2, a3];\n\n if n < 3 {\n false\n } else {\n perm.iter().any(|p| {\n p.iter().zip(a.iter()).all(|(&i, &k)| {\n ss[i].binary_search(&k).is_ok()\n })\n })\n }\n\n })\n .last();\n\n if let Some(a) = ans {\n println!(\"{}\", a);\n } else {\n println!(\"0\");\n }\n\n}\n", "positive_code": [{"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 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 n: usize = get_line().trim().parse().unwrap();\n\n let cubes: Vec<_> = BufReader::new(io::stdin()).lines()\n .map(|s| {\n let s = s.unwrap();\n let mut cube = [false; 10];\n for s in s.split_whitespace() {\n let d = s.bytes().last().unwrap();\n let d = (d - b'0') as usize;\n cube[d] = true;\n }\n cube\n }).collect();\n\n let perms = match n {\n 3 => vec![\n vec![0, 1, 2],\n vec![0, 2, 1],\n vec![1, 0, 2],\n vec![1, 2, 0],\n vec![2, 0, 1],\n vec![2, 1, 0],\n ],\n 2 => vec![\n vec![0, 1],\n vec![1, 0],\n ],\n 1 => vec![vec![0]],\n _ => panic!(\"\"),\n };\n\n\n let fact = |n| {\n let mut ret_val = 1;\n for i in 0..n {\n ret_val *= i + 1;\n }\n ret_val\n };\n\n let check = |x| {\n let x = format!(\"{}\", x);\n for perm in perms.iter().take(fact(n)) {\n let p = x.bytes().map(|b| (b - b'0') as usize)\n .zip(perm.iter()).all(|(d, &i)| cubes[i][d]);\n if p {\n return true;\n }\n }\n false\n };\n\n for i in 1.. {\n if !check(i) {\n println!(\"{}\", i - 1);\n return;\n }\n }\n}\n"}, {"source_code": "fn read_line() -> String {\n let stdin = std::io::stdin();\n let mut line = String::new();\n stdin.read_line(&mut line).unwrap();\n String::from(line.trim())\n}\n\nmacro_rules! scan_line {\n ($($ty: ty),*) => {{\n let line = read_line();\n let mut tok = line.split_whitespace();\n ($(tok.next().unwrap().parse::<$ty>().unwrap()),*)\n }}\n}\n\nfn check(dice: &[[i32; 6]], digits: &[i32]) -> bool {\n if dice.len() < digits.len() {\n println!(\"a\");\n false\n } else if digits.len() == 0 {\n true\n } else {\n let mut leftover_dice: Vec<[i32; 6]> = dice[1..].iter().cloned().collect();\n let mut has_solution = false;\n for (i, &die) in dice.iter().enumerate() {\n if die.iter().any(|&a| a == digits[0]) && check(&leftover_dice, &digits[1..]) {\n has_solution = true;\n break;\n }\n if i < leftover_dice.len() {\n leftover_dice[i] = die;\n }\n }\n has_solution\n }\n}\n\nfn main() {\n let n = scan_line!(i32);\n let mut dice = Vec::new();\n for _ in 0..n {\n let (a, b, c, d, e, f) = scan_line!(i32, i32, i32, i32, i32, i32);\n dice.push([a, b, c, d, e, f]);\n }\n let mut max_valid = 0;\n for i in 1.. {\n let mut digits = Vec::new();\n let mut j = i;\n while j > 0 {\n digits.push(j % 10);\n j /= 10;\n }\n let is_valid = check(&dice, &digits);\n if is_valid {\n max_valid = i;\n } else {\n break;\n }\n }\n println!(\"{}\", max_valid);\n}\n"}, {"source_code": "use std::iter::*;\n\nfn main() {\n let mut inp = ReadIn::new();\n let n = inp.int() as usize;\n let dices: Vec> = repeat(()).take(n).map(|_| inp.intvec()).collect();\n let mut res = nums(&dices);\n res.sort();\n let cnt = res.iter().scan(0, |p, &el| {\n if *p + 1 >= el {\n *p = el;\n Some(el)\n } else { None }\n }\n ).last().unwrap();\n println!(\"{:?}\", cnt);\n}\n\nfn nums(digs: &Vec>) -> Vec {\n if digs.is_empty() { vec![0] } else {\n digs.iter()\n .enumerate()\n .flat_map(|(i, v)| {\n let mut v1 = digs.clone();\n v1.remove(i);\n nums(&v1)\n .into_iter()\n .flat_map(move |n| v\n .iter()\n .map(move |d| n * 10 + d)\n .chain(once(n)))\n })\n .collect()\n }\n}\n\n\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}"}, {"source_code": "use std::iter::*;\n\nfn main() {\n let mut inp = ReadIn::new();\n let n = inp.int() as usize;\n let dices: Vec> = repeat(()).take(n).map(|_| inp.intvec()).collect();\n let mut res: Vec = nums(dices).collect();\n res.sort();\n let cnt = res.iter().scan(0, |p, &el| {\n if *p + 1 >= el {\n *p = el;\n Some(el)\n } else { None }\n }\n ).last().unwrap();\n println!(\"{:?}\", cnt);\n}\n\nfn nums<'a>(digs: Vec>) -> Box + 'a> {\n if digs.is_empty() { Box::new(once(0)) } else {\n let d1 = digs.clone();\n Box::new(d1.into_iter()\n .enumerate()\n .flat_map(move |(i, v)| {\n let mut v1 = digs.clone();\n v1.remove(i);\n nums(v1)\n .into_iter()\n .flat_map(move |n|\n v.clone()\n .into_iter()\n .map(move |d| n * 10 + d)\n .chain(once(n)))\n }))\n }\n}\n\n\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}"}], "negative_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min, Ordering};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet, BinaryHeap};\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n\n #[allow(dead_code)]\n pub fn get3() -> (S, T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {:?}\", stringify!($x), $x)\n }\n}\n\nfn main() {\n let n: usize = util::get();\n let ss: Vec> = (0..n)\n .map(|_| {\n let mut v: Vec = util::gets();\n v.sort();\n v\n })\n .collect();\n\n let ans = (1..)\n .take_while(|&x| if x < 10 {\n ss.iter().any(|v| v.binary_search(&x).is_ok())\n } else if x < 100 {\n let a1 = x % 10;\n let a2 = x / 10;\n\n let h1 = (0..ss.len())\n .filter(|&i| ss[i].binary_search(&a1).is_ok())\n .collect::>();\n let h2 = (0..ss.len())\n .filter(|&i| ss[i].binary_search(&a2).is_ok())\n .collect::>();\n\n (h1.len() > 1 && h2.len() > 1) || h1.difference(&h2).count() != 0 ||\n h2.difference(&h1).count() != 0\n\n } else {\n let perm = vec![\n vec![0, 1, 2],\n vec![0, 2, 1],\n vec![1, 0, 2],\n vec![1, 2, 0],\n vec![2, 0, 1],\n vec![2, 1, 0],\n ];\n\n let a1 = x % 10;\n let a2 = x / 10 % 10;\n let a3 = x / 100;\n let a = vec![a1, a2, a3];\n\n if n < 3 {\n false\n } else {\n perm.iter().any(|p| {\n p.iter().zip(a.iter()).all(|(&i, &k)| {\n ss[i].binary_search(&k).is_ok()\n })\n })\n }\n\n })\n .last();\n\n if let Some(a) = ans {\n println!(\"{}\", a);\n } else {\n println!(\"0\");\n }\n\n}\n"}, {"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 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 n: usize = get_line().trim().parse().unwrap();\n\n let cubes: Vec<_> = BufReader::new(io::stdin()).lines()\n .map(|s| {\n let s = s.unwrap();\n let mut cube = [false; 10];\n for s in s.split_whitespace() {\n let d = s.bytes().last().unwrap();\n let d = (d - b'0') as usize;\n cube[d] = true;\n }\n cube\n }).collect();\n\n let perms = [\n [0, 1, 2],\n [0, 2, 1],\n [1, 0, 2],\n [1, 2, 0],\n [2, 0, 1],\n [2, 1, 0],\n ];\n\n let fact = |n| {\n let mut ret_val = 1;\n for i in 0..n {\n ret_val *= i + 1;\n }\n ret_val\n };\n\n let check = |x| {\n let x = format!(\"{}\", x);\n for perm in perms.iter().take(fact(n)) {\n let p = x.bytes().map(|b| (b - b'0') as usize)\n .zip(perm.iter()).all(|(d, &i)| cubes[i][d]);\n if p {\n return true;\n }\n }\n false\n };\n\n for i in 1.. {\n if !check(i) {\n println!(\"{}\", i - 1);\n return;\n }\n }\n}\n"}, {"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 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 n: usize = get_line().trim().parse().unwrap();\n\n let cubes: Vec<_> = (0..n).map(|_| {\n let v: Vec = get_vec();\n v\n }).collect();\n\n let mut digits = vec![0; 10];\n for cube in cubes {\n for x in cube {\n digits[x] += 1;\n }\n }\n\n let last1 = digits.iter().skip(1).position(|&x| x == 0);\n if let Some(i) = last1 {\n println!(\"{}\", i);\n return;\n }\n\n let first = digits.iter().skip(1).position(|&x| x < 2).unwrap() + 1;\n println!(\"{}\", first * 10 + first - 1);\n}\n"}, {"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 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 n: usize = get_line().trim().parse().unwrap();\n\n let cubes: Vec<_> = (0..n).map(|_| {\n let v: Vec = get_vec();\n v\n }).collect();\n\n let mut digits = vec![0; 10];\n for cube in cubes {\n for x in cube {\n digits[x] += 1;\n }\n }\n\n let last1 = digits.iter().rposition(|&x| x >= 1).unwrap();\n if last1 != 9 {\n println!(\"{}\", last1);\n return;\n }\n\n let first = digits.iter().skip(1).position(|&x| x < 2).unwrap() + 1;\n println!(\"{}\", first * 10 + first - 1);\n}\n"}], "src_uid": "20aa53bffdfd47b4e853091ee6b11a4b"} {"source_code": "fn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_vec() -> Vec {\n read_str().trim()\n .split_whitespace()\n .map(|value| value\n .parse::()\n .expect(\"Error\"))\n .collect()\n}\n\nfn main() {\n let mut total: u32 = 0;\n let (k, n, w): (u32, u32, u32) = {\n let values: Vec = read_vec();\n (values[0], values[1], values[2])\n };\n\n for index in 1..w + 1 {\n total += index * k;\n }\n\n if total >= n { total -= n; }\n else { total = 0; }\n\n println!(\"{}\", total);\n}", "positive_code": [{"source_code": "fn main() {\n let mut text = String::new();\n std::io::stdin().read_line(&mut text).expect(\"\");\n let it : Vec = text.trim().split_whitespace().map(|x| x.parse::().expect(\"\")).collect();\n let k = it[0];\n let n = it[1];\n let w = it[2];\n println!(\"{}\", std::cmp::max((w + 1) * w / 2 * k - n, 0));\n}\n"}, {"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] fn strarr() -> Vec {\n let mut inp = String::new();\n stdin().read_line(&mut inp).ok();\n inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).map(|x| x.to_string()).collect() }\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let s = strarr(); let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec) -> T\n where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut s = strarr(); let mut v = Vec::new();\n for i in 0..$n { v.push(s[i as usize].parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\n\nfn main()\n{\n let (k, n, w) = scan!(i64, i64, i64);\n let req = k * (w * (w + 1)) / 2 - n;\n println!(\"{}\", max(req, 0));\n}\n"}, {"source_code": "\nuse std::io;\nuse std::io::prelude::*;\nfn main() {\n let mut inputnum = String::new();\n io::stdin().read_line(&mut inputnum).expect(\"Error\");\n let mut result : Vec = inputnum.split_whitespace().map(|x| x.parse::().unwrap()).collect();\n let totalcost:i64= (result[0]*(result[2]*(result[2]+1)))/2;\n if totalcost-result[1]>0{\n println!(\"{}\",totalcost-result[1]);\n }\n else{\n println!(\"0\");\n }\n}\n"}, {"source_code": "\nuse std::io;\nuse std::io::prelude::*;\nfn main() {\n let mut inputnum = String::new();\n io::stdin().read_line(&mut inputnum).expect(\"Error\");\n let mut result : Vec = inputnum.split_whitespace().map(|x| x.parse::().unwrap()).collect();\n let totalcost:i64= (result[0]*(result[2]*(result[2]+1)))/2;\n let diff:i64= totalcost-result[1];\n if diff>0{\n println!(\"{}\",diff);\n }\n else{\n println!(\"0\");\n }\n}\n"}, {"source_code": "\nuse std::io;\nuse std::io::prelude::*;\nfn main() {\n let mut inputnum = String::new();\n io::stdin().read_line(&mut inputnum).expect(\"Error\");\n let result : Vec = inputnum.split_whitespace().map(|x| x.parse::().unwrap()).collect();\n let totalcost:i64= (result[0]*(result[2]*(result[2]+1)))/2;\n if totalcost>result[1]{\n println!(\"{}\",totalcost-result[1]);\n }\n else{\n println!(\"0\");\n }\n}\n"}, {"source_code": "fn main() {\n let (k, n, w) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let nums: Vec = buf\n .trim()\n .split_whitespace()\n .map(|a| a.parse().unwrap())\n .collect();\n (nums[0], nums[1], nums[2])\n };\n\n let total_price = (w * (w + 1) / 2) * k;\n if total_price <= n {\n print!(\"0\");\n } else {\n print!(\"{}\", total_price - n);\n }\n}"}, {"source_code": "//spnauti-rust\n#[allow(unused_imports)]\nuse std::io::{self,Read};\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n let k = input.i();\n let n = input.i();\n let w = input.i();\n let sol = std::cmp::max(0, k * w * (w + 1) / 2 - n);\n println!(\"{}\", sol);\n}\n\n"}, {"source_code": "fn main() {\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().split(\" \").map(|s| s.parse::().unwrap()).collect()\n };\n\n let (first, total, n) = (v[0], v[1], v[2]);\n println!(\"{:?}\",\n std::cmp::max((0..n).fold(0, |total, i| total + first * (i + 1)) - total,\n 0));\n\n}\n"}, {"source_code": "/*\n Brute force - http://codeforces.com/problemset/problem/271/A\n Completed: 2/7/20 16:30\n*/\n\nuse std::io;\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n\n let vector: Vec<&str> = input.trim().split(\" \").collect();\n\n let bananas = &vector[2].parse::().unwrap();\n let dollars = &vector[1].parse::().unwrap();\n let initial_cost = &vector[0].parse::().unwrap();\n let mut current_banana = 0;\n let mut final_cost = 0;\n let mut borrow;\n\n for _ in 0..*bananas {\n current_banana += 1;\n final_cost += initial_cost * current_banana;\n }\n\n borrow = *dollars - final_cost;\n\n if borrow < 0 {\n borrow = -borrow;\n println!(\"{}\", borrow);\n } else {\n println!(\"0\");\n }\n\n\n}"}, {"source_code": "fn read() -> String {\n let mut res = String::new();\n std::io::stdin().read_line(&mut res).expect(\"???\");\n res\n}\n\nfn parse_int(s: &str) -> usize {\n s.trim().parse().expect(\"???\")\n}\n\nfn parse_ints(s: &str) -> Vec {\n s.split_whitespace().map(parse_int).collect()\n}\n\nfn main() {\n let v = parse_ints(&read());\n let k = v[0];\n let n = v[1];\n let w = v[2];\n let cost = k * (w * (w + 1)) / 2;\n let borrow = std::cmp::max(cost as i32 - n as i32, 0);\n println!(\"{}\", borrow);\n}\n"}, {"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 (k, n, w) = (read_in[0], read_in[1], read_in[2]);\n let cost = w * (w + 1) / 2 * k;\n let ret: usize;\n if cost <= n {\n ret = 0;\n } else {\n ret = cost - n;\n }\n println!(\"{}\", ret);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n\n let knw = s.split_whitespace()\n .map(|x| x.parse::().unwrap())\n .collect::>();\n let needed = knw[2]*(knw[2] + 1)/2 * knw[0];\n\n if needed > knw[1] {\n println!(\"{}\", needed - knw[1]);\n } else {\n println!(\"0\");\n }\n}\n"}, {"source_code": "use std::io;\nuse std::cmp;\n\nfn read_line() -> String {\n let mut line = String::new();\n io::stdin().read_line(&mut line).unwrap();\n line\n}\n\nfn main() {\n\n let line = read_line();\n let mut vs = line.trim().split_whitespace().map(|s| s.parse::().unwrap());\n let k = vs.next().unwrap();\n let n = vs.next().unwrap();\n let w = vs.next().unwrap();\n\n // 1k, 2k, 3k, ... wk\n // (1+w)w/2*k\n\n let need = (1 + w) * w / 2 * k;\n println!(\"{}\", cmp::max(0, need - n));\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let input: Vec = reads(sin);\n\n let ic_banana = input[0];\n let cash = input[1];\n let wants = input[2];\n\n let total_cost = (1..wants + 1)\n .map(|x| x * ic_banana)\n .fold(0, |acc, x| acc + x);\n\n if cash < total_cost {\n println!(\"{}\", total_cost - cash);\n } else {\n println!(\"0\");\n }\n}\n"}, {"source_code": "use std::io;\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n // (unit_price, money, count)\n let v: Vec<_> = buf\n .trim()\n .split_whitespace()\n .map(|x| x.parse::().unwrap())\n .collect();\n let total_price = (v[2] + 1) * v[2] / 2 * v[0];\n if v[1] >= total_price {\n println!(\"{}\", 0);\n } else {\n println!(\"{}\", total_price - v[1]);\n }\n}\n"}, {"source_code": "fn read()->Vec{\n let mut line=String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|x|x.parse::().unwrap()).collect()\n}\nfn main(){\n let a=read();\n let money=(2*a[0]+a[0]*(a[2]-1))*a[2]/2;\n let owe=money-a[1];\n if owe>0{\n print!(\"{}\",owe)\n }\n else{print!(\"0\")}\n}"}, {"source_code": "use std::io::BufRead;\n\nfn main() {\n let i: Vec = std::io::stdin()\n .lock()\n .lines()\n .next()\n .expect(\"stdin not work\")\n .expect(\"stdin not work\")\n .trim()\n .split(' ')\n .map(|s| s.parse::().expect(\"not number\"))\n .collect();\n println!(\"{}\", std::cmp::max((1 + i[2])*i[2]*i[0]/2-i[1], 0));\n}"}, {"source_code": "use std::io;\n\nfn read() -> String{\n let mut input=String::new();\n io::stdin().read_line(&mut input).expect(\"unable to read\");\n input.trim().to_string()\n}\nfn main() {\n let inp=read();\n let list: Vec<_>=inp.split_whitespace().collect();\n let price=list[0].parse::().expect(\"Failed to parse\");\n let money=list[1].parse::().expect(\"Failed to parse\");\n let total=list[2].parse::().expect(\"Failed to parse\");\n let mut sum=0;\n for i in 1..total+1{\n sum+=price*i;\n }sum-=money;\n if sum>0{\n println!(\"{}\",sum);\n }else{\n println!(\"{}\",0)\n }\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input = String::new();\n\n io::stdin()\n .read_line(&mut input)\n .unwrap();\n\n let words: Vec =\n input\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let k = words[0];\n let n = words[1];\n let w = words[2];\n\n let mut total = 0;\n\n for i in 1..w+1 {\n total += i*k;\n }\n\n let borrow = total - n;\n\n let answer = std::cmp::max(0, borrow);\n\n println!(\"{}\", answer);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input = String::new();\n\n io::stdin()\n .read_line(&mut input)\n .unwrap();\n\n let words: Vec =\n input\n .split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n\n let k = words[0];\n let n = words[1];\n let w = words[2];\n\n let mut total = w*(w+1)/2*k;\n\n let borrow = total - n;\n\n let answer = std::cmp::max(0, borrow);\n\n println!(\"{}\", answer);\n}\n"}, {"source_code": "use std::io::stdin;\nfn main() {\n let (banana_price, dolar_amount, banana_wanted) = parse_param();\n let price_to_pay = fact_add(banana_wanted, banana_price);\n if price_to_pay > dolar_amount {\n println!(\"{}\", price_to_pay - dolar_amount)\n } else {\n println!(\"0\")\n }\n}\n\nfn parse_param() -> (usize, usize, usize) {\n let mut entry_text = String::new();\n stdin().read_line(&mut entry_text).expect(\"msg: &str\");\n let a: Vec<&str> = entry_text.trim().split_whitespace().collect();\n (\n a[0].parse().expect(\"\"),\n a[1].parse().expect(\"\"),\n a[2].parse().expect(\"\"),\n )\n}\nfn fact_add(x: usize, y: usize) -> usize {\n if x <= 1 {\n return y;\n }\n (x * y) + fact_add(x - 1, y)\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n let arr : Vec = s.split_whitespace().map(|s| s.parse().unwrap()).collect();\n let k = arr[0];\n let n = arr[1];\n let w = arr[2];\n let sum = (1 + w) * w / 2 * k;\n if sum > n {\n println!(\"{}\", sum - n);\n } else {\n println!(\"0\");\n }\n}"}, {"source_code": "use std::cmp;\n\nfn read_int_line() -> Vec {\n // Read vector of integers\n let cin = std::io::stdin();\n let mut line = String::new();\n cin.read_line(&mut line).unwrap();\n let values: Vec = line\n .split_whitespace()\n .map(|x| x.parse::().unwrap())\n .collect();\n values\n}\n\n\nfn main() {\n\tlet values: Vec = read_int_line();\n\tlet k: i64 = values[0];\n\tlet n: i64 = values[1];\n\tlet w: i64 = values[2];\n\n\tlet sum: i64 = w * (w + 1) / 2 * k;\n\tlet mut ans: i64 = sum - n;\n\n\tans = cmp::max(ans, 0);\n\tprint!(\"{}\", ans);\n}"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let vector:Vec = stdin.lock().lines().next().unwrap().unwrap().trim().split(' ').map(|s| s.parse().unwrap()).collect();\n let x = vector[0] * (( vector[2] * (vector[2] + 1) ) / 2 ) ;\n if vector[1] > x {\n println!(\"{}\", 0);\n } else {\n println!(\"{}\", x - vector[1]);\n }\n}"}, {"source_code": "fn main(){\n let mut a = Vec::with_capacity(3);\n let mut val = String::new();\n std::io::stdin().read_line(&mut val).unwrap();\n let val = val.trim().parse::().unwrap();\n for j in val.split_whitespace(){\n let k = j.trim().parse::().unwrap();\n a.push(k);\n }\n let mut ans : i32 = 0;\n for p in 1..a[2]+1{\n ans += a[0]*p;\n }\n let last = ans - a[1];\n if last > 0 {\n println!(\"{}\",last);\n }\n else{\n println!(\"0\");\n }\n}"}, {"source_code": "fn main() {\n let mut buffer = String::new();\n\n std::io::stdin().read_line(&mut buffer).unwrap();\n\n let n: Vec = buffer\n .trim().split(' ')\n .map(|s: &str| s.parse::().unwrap())\n .collect();\n\n let sum = (1..=n[2]).sum::() * n[0];\n\n if sum > n[1] {\n println!(\"{}\", sum - n[1])\n } else {\n println!(\"0\")\n }\n}"}, {"source_code": "fn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_vec() -> Vec {\n read_str().trim()\n .split_whitespace()\n .map(|value| value\n .parse::()\n .expect(\"Error\"))\n .collect()\n}\n\nfn main() {\n let (k, n, w): (u32, u32, u32) = {\n let values: Vec = read_vec();\n (values[0], values[1], values[2])\n };\n\n let mut total: u32 = (1 + w) * w * k / 2;\n if total >= n { total -= n; }\n else { total = 0; }\n\n println!(\"{}\", total);\n}"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_vec(split_char: char) -> Vec {\n read_str()\n .split(split_char)\n .map(|value| value.parse::().ok().expect(\"Error\"))\n .collect()\n}\n\nfn main() {\n let (k, n, w): (u32, u32, u32) = {\n let values: Vec = read_vec(' ');\n (values[0], values[1], values[2])\n };\n\n println!(\"{}\", ((1 + w) * w * k / 2).saturating_sub(n));\n}"}, {"source_code": "use std::io::{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}\n\npub fn solution_of_p546a(input: &mut Read, out: &mut Write) {\n let mut scanner = Scanner::new(input);\n let arr: Vec = scanner.next::().split(' ').map(|e| {\n e.parse::().unwrap()\n }).collect();\n let k = arr[0];\n let n = arr[1];\n let w = arr[2];\n let mut s = 0;\n for i in 1..=w {\n s += i * k;\n }\n if s > n {\n write!(out, \"{}\", s - n).ok();\n } else {\n write!(out, \"{}\", 0).ok();\n }\n}\n\nfn main() {\n solution_of_p546a(&mut stdin(), &mut stdout());\n}\n"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn sum_1_through_n(n : u64) -> u64 {\n // Do the division before the multiplication\n // so that the result does not overflow sooner.\n if (n % 2) == 0 {\n (n / 2) * (n + 1)\n } else {\n n * ((n + 1) / 2)\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut knw = vec![];\n read_ts(&stdin, &mut knw);\n let k = knw[0];\n let n = knw[1];\n let w = knw[2];\n let needed_amount = k * sum_1_through_n(w);\n if needed_amount > n {\n let x = needed_amount - n;\n println!(\"{}\", x);\n } else {\n println!(\"{}\", 0);\n }\n}\n"}, {"source_code": "use std::io;\nuse std::io::prelude::*;\nuse std::cmp;\nmacro_rules! scan {\n ( $( $x:ty ),+ ) => {{\n let mut s =String::new();\n io::stdin().read_line(& mut s);\n\n let mut iter = s.split_whitespace();\n ($(iter.next().and_then(|word| word.parse::<$x>().ok()).unwrap(),)*)\n }}\n}\n\n\n\nfn main(){\n\n\n\n let (k,n,w)= scan!(i64,i64,i64);\n\n\n let r =cmp::max(0i64, (w*(w+1))/2 *k -n);\n print!(\"{}\",r);\n\n}"}, {"source_code": "use std::io;\nuse std::io::prelude::*;\nuse std::cmp;\nmacro_rules! scan {\n ( $string:expr, $( $x:ty ),+ ) => {{\n let mut iter = $string.split_whitespace();\n ($(iter.next().and_then(|word| word.parse::<$x>().ok()).unwrap(),)*)\n }}\n}\n\n\n\nfn main(){\n\n let mut s= String::new();\n io::stdin().read_line(& mut s);\n\n let (k,n,w)= scan!(s,i64,i64,i64);\n\n\n let r =cmp::max(0i64, (w*(w+1))/2 *k -n);\n print!(\"{}\",r);\n\n}"}, {"source_code": "use std::io;\nuse std::io::prelude::*;\nuse std::cmp;\nmacro_rules! scan {\n ( $string:expr, $( $x:ty ),+ ) => {{\n let mut iter = $string.split_whitespace();\n ($(iter.next().and_then(|word| word.parse::<$x>().ok()).unwrap(),)*)\n }}\n}\n\n\n\nfn main(){\n\n let mut s= String::new();\n io::stdin().read_line(& mut s);\n\n let mut it= s.split_whitespace();\n let (k,n,w)= scan!(s,i64,i64,i64);\n\n\n let r =cmp::max(0i64, (w*(w+1))/2 *k -n);\n print!(\"{}\",r);\n\n}"}, {"source_code": "use std::io;\nuse std::io::prelude::*;\nuse std::cmp;\n\n\nfn main(){\n let mut s= String::new();\n io::stdin().read_line(& mut s);\n\n let mut it= s.split_whitespace();\n let k= it.next().unwrap().parse::().unwrap();\n let n=it.next().unwrap().parse::().unwrap();\n let w=it.next().unwrap().parse::().unwrap();\n let r =cmp::max(0i64, (w*(w+1))/2 *k -n);\n print!(\"{}\",r);\n\n}"}, {"source_code": "fn readln() -> Vec {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n\n line.split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect()\n}\n\nfn main() {\n let mut input = readln();\n\n let k = input[0];\n let n = input[1];\n let w = input[2];\n\n let mut ans = w * (w + 1) / 2 * k - n;\n if ans < 0 {\n ans = 0;\n }\n\n println!(\"{}\", ans);\n}"}, {"source_code": "fn readln() -> Vec {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n\n line.split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect()\n}\n\nfn main() {\n let mut input = readln();\n\n let k = input[0];\n let n = input[1];\n let w = input[2];\n\n println!(\"{}\", std::cmp::max(0, w * (w + 1) / 2 * k - n));\n}"}, {"source_code": "use std::io;\nuse std::string;\nuse std::cmp::*;\n\nfn main() {\n let mut line = String::new();\n io::stdin().read_line(&mut line).expect(\"Failed to read line\");\n\n let vec: Vec<&str> = line.split(\" \").collect();\n let a: i64 = vec[0].trim().parse().unwrap();\n let b: i64 = vec[1].trim().parse().unwrap();\n let c: i64 = vec[2].trim().parse().unwrap();\n println!(\"{}\", max(0,a*(c+1)*c/2-b));\n}\n"}, {"source_code": "use std::io::{self, Read};\n\nfn main() -> io::Result<()> {\n let mut input = String::new();\n io::stdin().read_to_string(&mut input)?;\n let mut ts = input.split_whitespace();\n let k : i64 = ts.next().expect(\"a\").parse().expect(\"b\");\n let n : i64 = ts.next().expect(\"c\").parse().expect(\"d\");\n let w : i64 = ts.next().expect(\"e\").parse().expect(\"f\");\n let a = (w * (w + 1) / 2 * k - n).max(0);\n println!(\"{}\", a);\n Ok(())\n}"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut inp = String::new();\n\tio::stdin().read_line(&mut inp).unwrap();\n\tlet inp = inp.trim();\n\tlet k: i32 = inp.split_whitespace().nth(0).unwrap().parse().unwrap();\n\tlet n: i32 = inp.split_whitespace().nth(1).unwrap().parse().unwrap();\n\tlet w: i32 = inp.split_whitespace().nth(2).unwrap().parse().unwrap();\n\tlet mut all_money = 0;\n\tfor i in 1..(w+1) {\n\t\tall_money += i*k;\n\t}\n\tif all_money - n <= 0 {\n\t\tprintln!(\"0\");\n\t} else {\n\t\tprintln!(\"{}\", all_money - n);\n\t}\n}\n"}, {"source_code": "fn main() {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n\n let mut numbers = buf.trim_end().split_whitespace();\n let first_banana_price = numbers.next().unwrap().parse::().unwrap();\n let money_amount = numbers.next().unwrap().parse::().unwrap();\n let number_of_bananas = numbers.next().unwrap().parse::().unwrap();\n\n let mut total_cost = 0;\n\n for index in 0..number_of_bananas {\n total_cost += (index + 1) * first_banana_price;\n }\n\n if total_cost <= money_amount {\n println!(\"{}\", 0);\n }\n else {\n println!(\"{}\", total_cost - money_amount);\n }\n}\n"}, {"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 k: u32 = iter.next().unwrap().parse().unwrap();\n let n: u32 = iter.next().unwrap().parse().unwrap();\n let w: u32 = iter.next().unwrap().parse().unwrap();\n\n let mut total_cost = 0;\n let mut output = 0;\n\n for i in 1..=w {\n total_cost += k * i;\n }\n\n if total_cost > n {\n output = total_cost - n;\n }\n\n println!(\"{}\", output);\n}\n\n\n"}, {"source_code": "use std::io;\nuse std::cmp;\n\n\nfn main() {\n let mut input_line = String::new();\n io::stdin().read_line(&mut input_line)\n .expect(\"Failed to read line\");\n\n let nums: Vec = input_line.trim().split(' ')\n .map(|s| s.parse::().expect(\"oops\"))\n .collect();\n \n let k = nums[0];\n let n = nums[1];\n let w = nums[2];\n\n let mut cost = 0;\n\n for i in 1..w + 1 {\n cost += k * i;\n }\n\n let b = cmp::max(cost - n, 0);\n\n println!(\"{}\", b);\n\n}"}, {"source_code": "use 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 out = &mut BufWriter::new(stdout());\n\n\tlet k = scan.next::();\n\tlet n = scan.next::();\n\tlet w = scan.next::();\n\n let sum: i64 = (1..w+1).map(|x| x * k).sum();\n let res = if n - sum > 0 { 0 } else { sum - n };\n\n writeln!(out, \"{}\", res).expect(\"fail\");\n}\n"}], "negative_code": [{"source_code": "fn main() {\n let v: Vec = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().split(\" \").map(|s| s.parse::().unwrap()).collect()\n };\n\n let (first, total, n) = (v[0], v[1], v[2]);\n println!(\"{:?}\",\n (0..n).fold(0, |total, i| total + first * (i + 1)) - total);\n}\n"}, {"source_code": "/*\n Brute force - http://codeforces.com/problemset/problem/271/A\n Completed: 2/7/20 16:30\n*/\n\nuse std::io;\n\nfn main() {\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n\n let vector: Vec<&str> = input.trim().split(\" \").collect();\n\n let bananas = &vector[2].parse::().unwrap();\n let dollars = &vector[1].parse::().unwrap();\n let initial_cost = &vector[0].parse::().unwrap();\n let mut current_banana = 0;\n let mut final_cost = 0;\n let mut borrow;\n\n for _ in 0..*bananas {\n current_banana += 1;\n final_cost += initial_cost * current_banana;\n }\n\n borrow = final_cost - *dollars;\n\n if borrow < 0 {\n borrow = -borrow;\n }\n\n println!(\"{}\", borrow);\n\n}"}, {"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 (k, n, w) = (read_in[0], read_in[1], read_in[2]);\n let ret = w * (w + 1) / 2 * k - n;\n println!(\"{}\", ret);\n}\n"}, {"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 (k, n, w) = (read_in[0], read_in[1], read_in[2]);\n let cost = w * (w + 1) / 2 * k;\n let ret: usize;\n if cost >= n {\n ret = 0;\n } else {\n ret = n - cost;\n }\n println!(\"{}\", ret);\n}\n"}, {"source_code": "fn read()->Vec{\n let mut line=String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|x|x.parse::().unwrap()).collect()\n}\nfn main(){\n let a=read();\n let money=(2*a[0]+a[0]*(a[2]-1))*a[2]/2;\n let owe=money-a[1];\n if owe>0{\n print!(\"{}\",owe)\n }\n else{print!(\"0\")}\n print!(\"{}\",money)\n}"}, {"source_code": "fn read()->Vec{\n let mut line=String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|x|x.parse::().unwrap()).collect()\n}\nfn main(){\n let a=read();\n let money=(2*a[0]+a[0]*(a[2]-1))/2*a[2];\n let owe=money-a[1];\n if owe>0{\n print!(\"{}\",owe)\n }\n else{print!(\"0\")}\n}"}, {"source_code": "use std::io;\n\nfn read() -> String{\n let mut input=String::new();\n io::stdin().read_line(&mut input).expect(\"unable to read\");\n input.trim().to_string()\n}\nfn main() {\n let inp=read();\n let list: Vec<_>=inp.split_whitespace().collect();\n let price=list[0].parse::().expect(\"Failed to parse\");\n let money=list[1].parse::().expect(\"Failed to parse\");\n let total=list[2].parse::().expect(\"Failed to parse\");\n let mut sum=0;\n for i in 1..total+1{\n sum+=price*i;\n }println!(\"{}\",sum-money);\n}\n"}, {"source_code": "use std::io::stdin;\nfn main() {\n let (banana_price, dolar_amount, banana_wanted) = parse_param();\n println!(\"{}\", fact_add(banana_wanted, banana_price) - dolar_amount)\n}\n\nfn parse_param() -> (usize, usize, usize) {\n let mut entry_text = String::new();\n stdin().read_line(&mut entry_text).expect(\"msg: &str\");\n let a: Vec<&str> = entry_text.trim().split_whitespace().collect();\n (\n a[0].parse().expect(\"\"),\n a[1].parse().expect(\"\"),\n a[2].parse().expect(\"\"),\n )\n}\nfn fact_add(x: usize, y: usize) -> usize {\n if x <= 1 {\n return y;\n }\n (x * y) + fact_add(x - 1, y)\n}\n"}, {"source_code": "fn read_int_line() -> Vec {\n // Read vector of integers\n let cin = std::io::stdin();\n let mut line = String::new();\n cin.read_line(&mut line).unwrap();\n let values: Vec = line\n .split_whitespace()\n .map(|x| x.parse::().unwrap())\n .collect();\n values\n}\n\n\nfn main() {\n\tlet values: Vec = read_int_line();\n\tlet k: i64 = values[0];\n\tlet n: i64 = values[1];\n\tlet w: i64 = values[2];\n\n\tlet sum: i64 = w * (w + 1) / 2 * k;\n\tlet ans: i64 = sum - n;\n\n\tprint!(\"{}\", ans);\n}"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let vector:Vec = stdin.lock().lines().next().unwrap().unwrap().trim().split(' ').map(|s| s.parse().unwrap()).collect();\n let mut sum = 0;\n for i in 1..(vector[2] + 1) {\n sum = sum + (i * vector[0]);\n }\n println!(\"{}\", sum - vector[1]);\n}"}, {"source_code": "fn main(){\n let mut a = Vec::with_capacity(3);\n let mut val = String::new();\n std::io::stdin().read_line(&mut val).unwrap();\n let val = val.trim().parse::().unwrap();\n for j in val.split_whitespace(){\n let k = j.trim().parse::().unwrap();\n a.push(k);\n }\n let mut ans : i32 = 0;\n for p in 1..a[2]+1{\n ans += a[0]*p;\n }\n let last = ans - a[1];\n println!(\"{}\",last);\n}"}, {"source_code": "use std::io;\nuse std::io::prelude::*;\n\n\nfn main(){\n let mut s= String::new();\n io::stdin().read_line(& mut s);\n\n let mut it= s.split_whitespace();\n let k= it.next().unwrap().parse::().unwrap();\n let n=it.next().unwrap().parse::().unwrap();\n let w=it.next().unwrap().parse::().unwrap();\n let r =(w*(w+1))/2 *k -n;\n print!(\"{}\",r);\n\n}"}, {"source_code": "use std::io;\nuse std::string;\nuse std::cmp::*;\n\nfn main() {\n let mut line = String::new();\n io::stdin().read_line(&mut line).expect(\"Failed to read line\");\n\n let vec: Vec<&str> = line.split(\" \").collect();\n let a: u64 = vec[0].trim().parse().unwrap();\n let b: u64 = vec[1].trim().parse().unwrap();\n let c: u64 = vec[2].trim().parse().unwrap();\n println!(\"{}\", max(0,a*(c+1)*c/2-b));\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut inp = String::new();\n\tio::stdin().read_line(&mut inp).unwrap();\n\tlet inp = inp.trim();\n\tlet k: i32 = inp.split_whitespace().nth(0).unwrap().parse().unwrap();\n\tlet n: i32 = inp.split_whitespace().nth(1).unwrap().parse().unwrap();\n\tlet w: i32 = inp.split_whitespace().nth(2).unwrap().parse().unwrap();\n\tlet mut all_money = 0;\n\tfor i in 1..(w+1) {\n\t\tall_money += i*k;\n\t}\n\tprintln!(\"{}\", all_money - n);\n}\n"}], "src_uid": "e87d9798107734a885fd8263e1431347"} {"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 main() {\n input! {\n s: chars,\n }\n if s.len() % 2 == 0 {\n let n = s.len();\n let m = s.len() / 2;\n let mut res = String::new();\n for i in (0..m).rev() {\n res.push(s[i]);\n res.push(s[n-i-1]);\n }\n println!(\"{}\", res);\n }\n else {\n let n = s.len();\n let m = s.len() / 2;\n let mut res = String::new();\n res.push(s[m]);\n for i in (0..m).rev() {\n res.push(s[n-i-1]);\n res.push(s[i]);\n }\n println!(\"{}\", res);\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\npub fn continuous_division(xs: &[T]) -> Vec<(T,usize)> {\n let mut res = vec![];\n let n = xs.len();\n for i in 0..n {\n if i == 0 || xs[i-1] != xs[i] {\n res.push((xs[i], 1));\n }\n else {\n let m = res.len();\n res[m-1].1 += 1;\n }\n }\n res\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", "positive_code": [{"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 message = readln!();\n let message = message.chars().collect::>();\n\n if message.len() % 2 == 0 {\n for index in 0..message.len() / 2 {\n print!(\"{}{}\", message[message.len() / 2 - 1 - index], message[message.len() / 2 + index]);\n }\n } else {\n print!(\"{}\", message[message.len() / 2]);\n for index in 0..message.len() / 2 {\n print!(\"{}{}\", message[message.len() / 2 + 1 + index], message[message.len() / 2 - 1 - index]);\n }\n }\n\n println!();\n}\n"}, {"source_code": "\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).ok();\n let s = s.trim();\n let mut i: usize = 0;\n let mut j: usize = s.len()-1;\n \n let mut r = String::new();\n let mut last = s.len() % 2 == 0;\n\n for _ in 0..s.len() {\n if last {\n let c = s.chars().nth(j).unwrap();\n r.push(c);\n j -= 1;\n } else {\n let c = s.chars().nth(i).unwrap();\n r.push(c);\n i += 1;\n }\n last = !last;\n }\n println!(\"{}\", r.chars().rev().collect::());\n}"}], "negative_code": [{"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 next_index(len: usize, curr: usize, go_left: bool) -> Option {\n if len % 2 == 0 {\n if go_left {\n if len >= curr + 1 {\n Some(len - curr - 1)\n } else {\n None\n }\n } else {\n if len >= curr + 2 {\n Some(len - curr - 2)\n } else {\n None\n }\n }\n } else {\n if go_left {\n if len >= curr + 1 {\n Some(len - curr - 1)\n } else {\n None\n }\n } else {\n if len >= curr && len - curr < len {\n Some(len - curr)\n } else {\n None\n }\n }\n }\n}\n\nfn main() {\n let message = readln!();\n let message = message.chars().collect::>();\n\n if message.len() == 1 {\n println!(\"z\");\n return;\n }\n\n let mut index = (message.len() - 1) / 2;\n let mut go_left = true;\n loop {\n print!(\"{}\", message[index]);\n\n match next_index(message.len(), index, go_left) {\n None => break,\n Some(new_index) => index = new_index\n };\n go_left = !go_left;\n }\n println!();\n}\n"}], "src_uid": "992ae43e66f1808f19c86b1def1f6b41"} {"source_code": "/// square root of an int\nfn sqrti(b: u64) -> u64 {\n let n = 2;\n if b < 2 {\n return b\n };\n let n1 = n - 1;\n let n2 = n;\n let n3 = n1;\n let mut c = 1;\n let mut d = (n3 + b) / n2;\n let mut e = (n3 * d + b / d.pow(n1 as u32)) / n2;\n while c != d && c != e {\n c = d;\n d = e;\n e = (n3 * e + b / e.pow(n1 as u32)) / n2;\n }\n if d < e { d }\n else { e }\n}\n\nuse std::ops::Range;\n\n/// iterator that returns `(w, h)` for rectangles of provided area\nstruct Rects {\n area: u64,\n w: u64,\n rw: Range,\n rh: Range,\n}\n\nimpl Rects {\n pub fn new(area: u64) -> Rects {\n let q = sqrti(area);\n Rects { area, rw: 1..q, rh: 1..area, w: q }\n }\n pub fn with_limits(area: u64, rw: Range, rh: Range) -> Rects {\n let q = sqrti(area);\n let maxw = q.min(area / rh.start).min(rw.end);\n let minw = (area / rh.end).max(rw.start);\n Rects { area, rw: minw..maxw, rh, w: maxw }\n }\n}\n\nimpl Iterator for Rects {\n type Item = (u64, u64);\n fn next(&mut self) -> Option<(u64, u64)> {\n while self.w >= self.rw.start {\n let w = self.w;\n self.w -= 1;\n let h = self.area / w;\n if h < self.rh.start || h > self.rh.end || h * w != self.area {\n continue;\n }\n return Some((w, h));\n }\n None\n }\n}\n\nfn solve(a: u64, b: u64) -> Option {\n if a < 1 || b < 1 {\n return None;\n }\n let area = a + b;\n Rects::new(area).flat_map(|(ow, oh)| {\n let perimeter = (ow + oh) * 2;\n Rects::with_limits(a, 1..ow, 1..oh)\n .chain(Rects::with_limits(b, 1..ow, 1..oh))\n .find(|&(iw, ih)| iw <= ow && ih <= oh)\n .and(Some(perimeter))\n }).next()\n}\n\nuse std::io::{stdin, BufRead};\nuse std::process::{exit};\nfn input() -> Result<(u64, u64), String> {\n let std = stdin();\n let mut row = String::new();\n std.lock().read_line(&mut row).map_err(|_|\"Cannot read stdin\")?;\n let words: Vec<&str> = row.trim().split(' ').collect();\n let a: u64 = words[0].parse().map_err(|_|\"Cannot parse input\")?;\n let b: u64 = words[1].parse().map_err(|_|\"Cannot parse input\")?;\n Ok((a, b))\n}\n\nfn main() {\n let rv = input().map(|(a,b)| solve(a, b));\n match rv {\n Ok(Some(perimeter)) => {\n println!(\"{}\", perimeter);\n }\n Ok(None) => {\n eprintln!(\"Error: solution not found\");\n exit(1);\n }\n Err(e) => {\n eprintln!(\"Error: {}\", e);\n exit(1);\n }\n }\n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let rin = buf.split_whitespace().map(|c| c.parse::().unwrap()).collect::>();\n let n = rin[0] + rin[1];\n\n let ret1 = factors(n, None);\n let x = ret1.last().unwrap();\n let ret3 = factors(rin[0], Some(*x));\n let ret4 = factors(rin[1], Some(*x));\n// println!(\"{:?} {:?}\", ret3, ret4);\n\n let mut p: Option = None;\n 'find: for i in ret1.iter().rev() {\n let x1 = i;\n let y1 = n / x1;\n for j in ret3.iter().rev() {\n let x2 = j;\n let y2 = rin[0] / x2;\n// println!(\"{} {}, {} {}\", x1, y1, x2, y2);\n if x2 <= x1 && y2 <= y1 {\n let _p = (x1 + y1) * 2;\n if p.is_none() || _p < p.unwrap() {\n p = Some(_p);\n }\n break;\n }\n }\n for j in ret4.iter().rev() {\n let x2 = j;\n let y2 = rin[1] / x2;\n// println!(\"{} {}, {} {}\", x1, y1, x2, y2);\n if x2 <= x1 && y2 <= y1 {\n let _p = (x1 + y1) * 2;\n if p.is_none() || _p < p.unwrap() {\n p = Some(_p);\n }\n break 'find;\n }\n }\n }\n println!(\"{}\", p.unwrap());\n}\n\nfn factors(n: u64, max: Option) -> Vec {\n let sqrt = (n as f64).sqrt() as u64;\n let mut ret = Vec::::new();\n for i in 1..=sqrt {\n match max {\n Some(x) if i > x => {\n// println!(\"{}, {}\", i, x);\n break;\n }\n _ => {}\n }\n if n % i == 0 {\n ret.push(i);\n }\n }\n// let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::>();\n return ret;\n}"}, {"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::{stderr, stdin, BufRead, Write};\nuse std::mem::{replace, swap};\nuse std::ops::*;\nuse std::rc::Rc;\n\n// -----------------------------------------------\n// Framework \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(unused_macros)]\nmacro_rules! debug {\n ($($arg:expr),*) => {\n #[cfg(debug_assertions)]\n $(writeln!(stderr(), \"{} = {:?}\", stringify!($arg), $arg).unwrap());*\n };\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\n#[derive(PartialEq, Eq, Clone, Debug)]\npub struct Rev(pub T);\n\nimpl PartialOrd for Rev {\n fn partial_cmp(&self, other: &Rev) -> Option {\n other.0.partial_cmp(&self.0)\n }\n}\n\nimpl Ord for Rev {\n fn cmp(&self, other: &Rev) -> Ordering {\n other.0.cmp(&self.0)\n }\n}\n\nfn divs(n: i64) -> Vec {\n let r = (n as f64).sqrt().ceil() as i64;\n\n let mut xs = vec![];\n\n for k in 1..r + 1 {\n if n % k == 0 {\n xs.push(k);\n }\n }\n\n xs\n}\n\nfn solve_core(a: i64, b: i64) -> i64 {\n let mut ts = divs(a);\n let ss = ts.iter().rev().map(|&t| a / t).vec();\n ts.extend(ss);\n\n let ys = divs(a + b);\n\n // debug!((a, b), ts, ys);\n\n let mut l = 0;\n let mut r = 0;\n let mut q: BinaryHeap<(Rev, usize)> = BinaryHeap::new();\n let mut mi = std::i64::MAX;\n\n for ti in 0..ts.len() {\n let t = ts[ti];\n\n while l < ys.len() && ys[l] < t {\n l += 1;\n }\n\n r = max(r, l);\n\n while r < ys.len() && (a + b) / ys[r] >= a / t {\n let y = ys[r];\n let x = (a + b) / y;\n q.push((Rev(2 * (y + x)), r));\n\n r += 1;\n }\n\n while let Some(&(_, yi)) = q.peek() {\n if l <= yi {\n break;\n }\n\n q.pop();\n }\n\n // debug!((ti, t, l, r));\n\n if let Some((Rev(p), _)) = q.pop() {\n // debug!(p);\n mi = min(mi, p);\n }\n }\n\n mi\n}\n\nfn solve(a: i64, b: i64) -> i64 {\n let mut mi = solve_core(a, b);\n if a != b {\n mi = min(mi, solve_core(b, a));\n }\n mi\n}\n\nfn main() {\n let (a, b) = read!(i64, i64);\n println!(\"{}\", solve(a, b))\n}\n"}], "negative_code": [{"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let rin = buf.split_whitespace().map(|c| c.parse::().unwrap()).collect::>();\n let n = rin[0] + rin[1];\n let m: u64;\n\n let ret1 = factors(n, None);\n let x = ret1.last().unwrap();\n let ret3 = factors(rin[0], Some(*x));\n let ret4 = factors(rin[1], Some(*x));\n// println!(\"{:?} {:?}\", ret3, ret4);\n\n let ret2 = if ret3.last().unwrap() > ret4.last().unwrap() {\n m = rin[0];\n ret3\n } else {\n m = rin[1];\n ret4\n };\n// println!(\"{:?}\", ret1);\n// println!(\"{:?}\", ret2);\n let mut p: u64 = 0;\n 'find: for i in ret1.iter().rev() {\n let x1 = i;\n let y1 = n / x1;\n for j in ret2.iter().rev() {\n let x2 = j;\n let y2 = m / x2;\n// println!(\"{} {}, {} {}\", x1, y1, x2, y2);\n if x2 <= x1 && y2 <= y1 {\n p = (x1 + y1) * 2;\n break 'find;\n }\n }\n }\n println!(\"{}\", p);\n}\n\nfn factors(n: u64, max: Option) -> Vec {\n let sqrt = (n as f64).sqrt() as u64;\n let mut ret = Vec::::new();\n for i in 1..=sqrt {\n match max {\n Some(x) if i > x => {\n// println!(\"{}, {}\", i, x);\n break;\n }\n _ => {}\n }\n if n % i == 0 {\n ret.push(i);\n }\n }\n// let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::>();\n return ret;\n}"}, {"source_code": "use std::io;\nuse std::cmp;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let rin = buf.split_whitespace().map(|c| c.parse::().unwrap()).collect::>();\n let n = rin[0] + rin[1];\n let m = cmp::min(rin[0], rin[1]);\n let ret1 = factors(n);\n let ret2 = factors(m);\n let mut p: u64 = 0;\n 'find: for i in ret1.iter() {\n let x1 = i;\n let y1 = n / x1;\n for j in ret2.iter() {\n let x2 = j;\n let y2 = m / x2;\n if x2 <= x1 && y2 <= y1 {\n p = (x1 + y1) * 2;\n break 'find;\n }\n }\n }\n println!(\"{}\", p);\n}\n\nfn factors(n: u64) -> Vec {\n let sqrt = (n as f64).sqrt() as u64;\n let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::>();\n return ret;\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let rin = buf.split_whitespace().map(|c| c.parse::().unwrap()).collect::>();\n let n = rin[0] + rin[1];\n let m: u64;\n\n let ret1 = factors(n);\n// println!(\"{:?}\", ret1);\n let ret3 = factors(rin[0]);\n let ret4 = factors(rin[1]);\n\n let ret2 = if ret3[0] > ret4[0] {\n m = rin[0];\n ret3\n } else {\n m = rin[1];\n ret4\n };\n// println!(\"{:?}\", ret2);\n let mut p: u64 = 0;\n 'find: for i in ret1.iter() {\n let x1 = i;\n let y1 = n / x1;\n for j in ret2.iter() {\n let x2 = j;\n let y2 = m / x2;\n// println!(\"{} {}, {} {}\", x1, y1, x2, y2);\n if x2 <= x1 && y2 <= y1 {\n p = (x1 + y1) * 2;\n break 'find;\n }\n }\n }\n println!(\"{}\", p);\n}\n\nfn factors(n: u64) -> Vec {\n let sqrt = (n as f64).sqrt() as u64;\n let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::>();\n return ret;\n}"}, {"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let rin = buf.split_whitespace().map(|c| c.parse::().unwrap()).collect::>();\n let n = rin[0] + rin[1];\n let m: u64;\n\n let ret1 = factors(n, None);\n let x = ret1.last().unwrap();\n let ret3 = factors(rin[0], Some(*x));\n let ret4 = factors(rin[1], Some(*x));\n// println!(\"{:?} {:?}\", ret3, ret4);\n\n let r3_last = *ret3.last().unwrap();\n let r4_last = *ret4.last().unwrap();\n let ret2 = if r3_last > r4_last {\n m = rin[0];\n ret3\n } else if r3_last < r4_last {\n m = rin[1];\n ret4\n } else if rin[0] < rin[1] {\n m = rin[0];\n ret3\n } else {\n m = rin[1];\n ret4\n };\n// println!(\"{:?}\", ret1);\n// println!(\"{:?}\", ret2);\n let mut p: u64 = 0;\n 'find: for i in ret1.iter().rev() {\n let x1 = i;\n let y1 = n / x1;\n for j in ret2.iter().rev() {\n let x2 = j;\n let y2 = m / x2;\n// println!(\"{} {}, {} {}\", x1, y1, x2, y2);\n if x2 <= x1 && y2 <= y1 {\n p = (x1 + y1) * 2;\n break 'find;\n }\n }\n }\n println!(\"{}\", p);\n}\n\nfn factors(n: u64, max: Option) -> Vec {\n let sqrt = (n as f64).sqrt() as u64;\n let mut ret = Vec::::new();\n for i in 1..=sqrt {\n match max {\n Some(x) if i > x => {\n// println!(\"{}, {}\", i, x);\n break;\n }\n _ => {}\n }\n if n % i == 0 {\n ret.push(i);\n }\n }\n// let ret = (1..=sqrt).rev().filter(|c| n % c == 0).collect::>();\n return ret;\n}"}], "src_uid": "7d0c5f77bca792b6ab4fd4088fe18ff1"} {"source_code": "\nuse std::io;\nuse std::io::BufRead;\n\nfn main() {\n let stdin = io::stdin();\n let mut lines = stdin.lock().lines();\n\n lines.next().unwrap().unwrap();\n\n let mut first_list = [false; 10];\n let mut second_list = [false; 10];\n\n lines.next().unwrap().unwrap().split(\" \")\n .map(|x| x.parse::().unwrap())\n .for_each(|x| first_list[x] = true);\n lines.next().unwrap().unwrap().split(\" \")\n .map(|x| x.parse::().unwrap())\n .for_each(|x| second_list[x] = true);\n\n let mut min_first = 10;\n let mut min_second = 10;\n\n for i in 1..10 {\n if first_list[i] && second_list[i] {\n println!(\"{}\", i);\n return;\n }\n if first_list[i] && min_first > i {\n min_first = i;\n }\n if second_list[i] && min_second > i {\n min_second = i;\n }\n }\n\n let result = if min_first > min_second {\n min_second * 10 + min_first\n } else {\n min_first * 10 + min_second\n };\n\n println!(\"{}\", result);\n\n}\n", "positive_code": [{"source_code": "use std::boxed::Box;\nuse std::cmp::*;\nuse std::io;\n\nstruct Rand {\n state: u64,\n}\n\nimpl Rand {\n pub fn new() -> Self {\n Rand { state: 13 }\n }\n\n pub fn rand(&mut self) -> u64 {\n self.state = ((self.state ^ 1000000007) * 10000009) % 1000000013;\n self.state\n }\n}\n\n#[derive(Clone)]\nstruct Node {\n pub key: T,\n pub weight: u64,\n pub left: Option>>,\n pub right: Option>>,\n}\n\nimpl Node {\n fn new(value: T, weight: u64) -> Self {\n Node {\n key: value,\n weight: weight,\n left: None,\n right: None,\n }\n }\n\n pub fn split(\n node: Option>>,\n key: &T,\n ) -> (Option>>, Option>>) {\n match node {\n None => (None, None),\n Some(mut node) => match node.key.cmp(key) {\n Ordering::Less => {\n let (l, r) = Self::split(node.right, key);\n node.right = l;\n (Some(node), r)\n }\n _ => {\n let (l, r) = Self::split(node.left, key);\n node.left = r;\n (l, Some(node))\n }\n },\n }\n }\n\n pub fn merge(left: Option>>, right: Option>>) -> Option>> {\n match (left, right) {\n (None, None) => None,\n (left, None) => left,\n (None, right) => right,\n (Some(mut left), Some(mut right)) => match left.weight.cmp(&right.weight) {\n Ordering::Less => {\n left.right = Self::merge(left.right, Some(right));\n Some(left)\n }\n _ => {\n right.left = Self::merge(Some(left), right.left);\n Some(right)\n }\n },\n }\n }\n\n fn find(node: &Option>>, key: &T) -> bool {\n match node {\n None => false,\n Some(node) => match node.key.cmp(key) {\n Ordering::Less => Self::find(&node.right, key),\n Ordering::Greater => Self::find(&node.left, key),\n Ordering::Equal => true,\n },\n }\n }\n\n fn less(node: &Box>) -> T {\n match node.left {\n None => node.key.clone(),\n Some(ref left) => Self::less(left),\n }\n }\n}\n\nstruct Treap {\n root: Option>>,\n}\n\nimpl Treap {\n pub fn insert(&mut self, key: T, weight: u64) {\n let (mut l, r) = Node::split(self.root.take(), &key);\n l = Node::merge(l, Some(Box::new(Node::new(key, weight))));\n self.root = Node::merge(l, r);\n }\n\n pub fn delete(&mut self, key: &T) {\n let (l, mut r) = Node::split(self.root.take(), key);\n r = match r {\n None => None,\n Some(node) => {\n if &node.key == key {\n Node::merge(node.left, node.right)\n } else {\n Some(node)\n }\n }\n };\n self.root = Node::merge(l, r);\n }\n\n pub fn find(&self, key: &T) -> bool {\n Node::find(&self.root, key)\n }\n\n pub fn less(&self) -> Option {\n match self.root {\n Some(ref root) => Some(Node::less(root)),\n _ => None,\n }\n }\n\n pub fn new() -> Self {\n Treap { root: None }\n }\n}\n\nfn main() {\n let mut buffer = String::new();\n let mut rand = Rand::new();\n io::stdin().read_line(&mut buffer);\n buffer = String::new();\n io::stdin().read_line(&mut buffer);\n buffer.retain(|s| s != '\\r' && s != '\\n');\n let a: Vec = buffer\n .split_whitespace()\n .map(|n| n.parse::().unwrap())\n .collect();\n\n buffer = String::new();\n io::stdin().read_line(&mut buffer);\n buffer.retain(|s| s != '\\r' && s != '\\n');\n let b: Vec = buffer\n .split_whitespace()\n .map(|n| n.parse::().unwrap())\n .collect();\n\n let mut t1 = Treap::new();\n let mut t2 = Treap::new();\n //println!(\"{:?} | {:?}\", &a, &b);\n for n in a {\n t1.insert(n, rand.rand() as u64);\n }\n let mut m3 = 99;\n for n in b {\n t2.insert(n, rand.rand() as u64);\n if t1.find(&n) {\n m3 = std::cmp::min(m3, n);\n }\n }\n let (m1, m2) = (t1.less().unwrap(), t2.less().unwrap());\n\n if m1 != m2 && m3 < 99 {\n println!(\"{}\", m3);\n } else {\n match m1.cmp(&m2) {\n Ordering::Less => println!(\"{}{}\", m1, m2),\n Ordering::Greater => println!(\"{}{}\", m2, m1),\n Ordering::Equal => println!(\"{}\", m2),\n }\n }\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet};\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n\n #[allow(dead_code)]\n pub fn get3() -> (S, T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {:?}\", stringify!($x), $x)\n }\n}\n\nfn main() {\n let (_n, _m): (usize, usize) = util::get2();\n let a: HashSet = util::gets().iter().cloned().collect();\n let b: HashSet = util::gets().iter().cloned().collect();\n\n for i in 1..100 {\n if i < 10 {\n if a.contains(&i) && b.contains(&i) {\n println!(\"{}\", i);\n return;\n }\n } else {\n if (a.contains(&(i / 10)) || a.contains(&(i % 10))) &&\n (b.contains(&(i / 10)) || b.contains(&(i % 10)))\n {\n println!(\"{}\", i);\n return;\n }\n }\n }\n}\n"}, {"source_code": "use std::io::{self, BufReader, Stdin};\nuse std::io::prelude::*;\nuse std::collections::BTreeSet;\nuse std::iter::Map;\nuse std::str::SplitWhitespace;\n\nfn main() {\n let mut reader = ReadIn::new();\n\n reader.read_line();\n let a: BTreeSet = reader.read_iter().collect();\n let b: BTreeSet = reader.read_iter().collect();\n let c: BTreeSet = a.intersection(&b).map(|&x| x).collect();\n let res = (if !c.is_empty() { c.iter().map(|&x| x).next() } else {\n a.iter().next().and_then(\n |&ax| b.iter().next().map(\n |&bx| if (ax < bx) { ax * 10 + bx } else { bx * 10 + ax }))\n }).unwrap();\n print!(\"{}\", res);\n}\n\nstruct ReadIn { reader: BufReader, buf: String }\n\nimpl ReadIn {\n fn new() -> ReadIn { ReadIn { reader: BufReader::new(io::stdin()), buf: String::new() } }\n fn read_i32(s: &str) -> i32 { s.parse().unwrap() }\n fn read_line(&mut self) {\n self.buf.clear();\n self.reader.read_line(&mut self.buf);\n }\n fn read_iter(&mut self) -> Map i32> {\n self.read_line();\n self.buf.split_whitespace().map(ReadIn::read_i32)\n }\n fn read_vec(&mut self) -> Vec {\n self.read_iter().collect()\n }\n}\n\n\n\n"}, {"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 (n, m) = {\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 )\n };\n\n let f_v: Vec = get_vec();\n let s_v: Vec = get_vec();\n\n let first_list = f_v.into_iter()\n .fold(vec![false; 9], |mut acc, d| {\n acc[d - 1] = true;\n acc\n });\n\n let second_list = s_v.into_iter()\n .fold(vec![false; 9], |mut acc, d| {\n acc[d - 1] = true;\n acc\n });\n\n if let Some(i) = (0..first_list.len()).filter(|&i| first_list[i] && second_list[i]).min() {\n println!(\"{}\", i + 1);\n } else {\n let f = first_list.into_iter().position(|p| p).unwrap() + 1;\n let s = second_list.into_iter().position(|p| p).unwrap() + 1;\n print!(\"{}\", min(f, s));\n println!(\"{}\", max(f, s));\n }\n}\n"}], "negative_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet};\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n\n #[allow(dead_code)]\n pub fn get3() -> (S, T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\n\n#[allow(unused_macros)]\nmacro_rules! debug {\n ($x: expr) => {\n println!(\"{}: {:?}\", stringify!($x), $x)\n }\n}\n\nfn main() {\n let (_n, _m): (usize, usize) = util::get2();\n let a: HashSet = util::gets().iter().cloned().collect();\n let b: HashSet = util::gets().iter().cloned().collect();\n\n for i in 1..99 {\n if i < 10 {\n if a.contains(&i) && b.contains(&i) {\n println!(\"{}\", i);\n return;\n }\n } else {\n if a.contains(&(i / 10)) && b.contains(&(i % 10)) {\n println!(\"{}\", i);\n return;\n }\n }\n }\n}\n"}, {"source_code": "use std::io::{self, BufReader, Stdin};\nuse std::io::prelude::*;\nuse std::collections::BTreeSet;\nuse std::iter::Map;\nuse std::str::SplitWhitespace;\n\nfn main() {\n let mut reader = ReadIn::new();\n\n reader.read_line();\n let a: BTreeSet = reader.read_iter().collect();\n let b: BTreeSet = reader.read_iter().collect();\n let c: BTreeSet = a.intersection(&b).map(|&x| x).collect();\n let res = (if !c.is_empty() { c.iter().map(|&x| x).next() } else {\n a.iter().next().and_then(\n |ax| b.iter().next().map(\n |bx| ax * 10 + bx))\n }).unwrap();\n print!(\"{}\", res);\n}\n\nstruct ReadIn { reader: BufReader, buf: String }\n\nimpl ReadIn {\n fn new() -> ReadIn { ReadIn { reader: BufReader::new(io::stdin()), buf: String::new() } }\n fn read_i32(s: &str) -> i32 { s.parse().unwrap() }\n fn read_line(&mut self) {\n self.buf.clear();\n self.reader.read_line(&mut self.buf);\n }\n fn read_iter(&mut self) -> Map i32> {\n self.read_line();\n self.buf.split_whitespace().map(ReadIn::read_i32)\n }\n fn read_vec(&mut self) -> Vec {\n self.read_iter().collect()\n }\n}\n\n\n\n"}], "src_uid": "3a0c1b6d710fd8f0b6daf420255d76ee"} {"source_code": "use std::io;\nuse std::str::Chars;\n\nfn main() {\n let mut counter = 0;\n let mut col_checked = false;\n\n for i in 0..8 {\n let mut input_text = String::new();\n io::stdin()\n .read_line(&mut input_text)\n .expect(\"failed to read from stdin\");\n\n let trimmed = input_text.trim();\n if (trimmed.eq(\"BBBBBBBB\")) {\n counter = counter + 1;\n continue;\n }\n\n if (col_checked) {\n continue;\n }\n\n col_checked = true;\n for j in 0..8 {\n let char_at = trimmed.as_bytes()[j];\n if ((char_at as char) == 'B') {\n counter = counter + 1;\n }\n }\n }\n\n println!(\"{}\", counter);\n}", "positive_code": [{"source_code": "use std::io::{self, BufRead};\n\nconst W: char = 'W';\nconst B: char = 'B';\n\nfn parse_problem(input: B) -> io::Result<[[u8; 8]; 8]> {\n let mut matrix = [[0; 8]; 8];\n for (i, maybe_line) in input.lines().enumerate().take(8) {\n let line = maybe_line?;\n for (j, c) in line.chars().enumerate().take(8) {\n match c {\n B => matrix[i][j] = 1,\n W => {},\n _ => return Err(io::Error::new(io::ErrorKind::InvalidInput,\n \"not a B or W\")),\n }\n }\n }\n Ok(matrix)\n}\n\nfn main() -> io::Result<()> {\n let board = parse_problem(io::stdin().lock())?;\n let mut r: u32 = 0;\n let mut c: u32 = 0;\n 'outer_row: for i in 0..8 {\n for j in 0..8 {\n if board[i][j] == 0 {\n continue 'outer_row;\n }\n }\n r += 1;\n }\n 'outer_col: for j in 0..8 {\n for i in 0..8 {\n if board[i][j] == 0 {\n continue 'outer_col;\n }\n }\n c += 1;\n }\n let result = if r < 8 && c < 8 { r + c } else { 8 };\n println!(\"{}\", result);\n Ok(())\n}\n\n"}, {"source_code": "macro_rules! scanln {\n () => ({\n let mut buffer = String::new();\n ::std::io::stdin().read_line(&mut buffer).expect(\"Unable to read line\");\n buffer\n });\n ($($t: ty),+) => ({\n scanln!($($t),+, |c: char| c.is_whitespace())\n });\n ($($t: ty),+, $sp: expr) => ({\n let mut buffer = scanln!();\n let mut iter = buffer.split($sp);\n ($(iter.next().unwrap().parse::<$t>().expect(\"Unable to parse token\")),+)\n });\n}\n\nfn main() {\n let mut board = Vec::new();\n let mut count = 0;\n let mut checked = false;\n for _ in 0..8 {\n let line = scanln!(String);\n let row: Vec = line.split(' ').flat_map(|s| s.chars()).collect();\n board.push(row);\n }\n for r in board {\n let blacks = r.iter().filter(|c| **c == 'B').count();\n count += if blacks == 8 {\n 1\n } else if blacks > 0 && !checked {\n checked = true;\n blacks\n } else {\n 0\n }\n }\n println!(\"{}\", count);\n}"}], "negative_code": [], "src_uid": "8b6ae2190413b23f47e2958a7d4e7bc0"} {"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 = 14;\n let mut xs = vec![];\n for _ in 0..n {\n let x = get!();\n xs.push(x);\n }\n let mut ans = 0;\n for i in 0..n {\n let x = xs[i];\n let d = x / 14;\n let r = (x % 14) as usize;\n xs[i] = 0;\n let mut tmp = 0;\n for j in 0..n {\n let mut e = xs[j] + d;\n if i < j && j <= i + r {\n e += 1;\n } else if i < j + 14 && j + 14 <= i + r {\n e += 1;\n }\n if e % 2 == 0 {\n tmp += e;\n }\n }\n ans = std::cmp::max(ans, tmp);\n xs[i] = x;\n }\n println!(\"{}\", ans);\n}", "positive_code": [{"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 a: Vec = input.split_whitespace().map(|x| x.parse().unwrap())\n .collect();\n\n let mut max_ans = 0;\n\n let modulo = |a, b| {\n if a < 0 {\n a % b + b\n } else {\n a % b\n }\n };\n let modsub = |a, b| {\n modulo(a - b, 14)\n };\n\n for (i, &ai) in a.iter().enumerate() {\n let q = ai / 14;\n let r = ai % 14;\n\n let mut ans = 0;\n let mut j = i + 1;\n for _ in 0..13 {\n let cnt = a[modulo(j, 14)] + q + if r < modsub(j, i) as i64 { 0 } else { 1 };\n if cnt % 2 == 0 {\n ans += cnt;\n }\n \n j += 1\n }\n\n if q % 2 == 0 {\n ans += q;\n }\n\n if max_ans < ans {\n max_ans = ans;\n }\n }\n\n println!(\"{}\", max_ans);\n}\n"}, {"source_code": "use std::io::*;\nuse std::str::FromStr;\n\nfn main() {\n let stdin = stdin();\n let mut sc = Scanner::new(stdin.lock());\n let mut a: [usize; 14] = [0; 14];\n for i in 0..14 {\n a[i] = sc.next::();\n }\n let mut max: u64 = 0;\n for i in 0..14 {\n if a[i] == 0 {\n continue;\n }\n let mut b: [usize; 14] = a.clone();\n b[i] = 0;\n for j in 0..14 {\n b[(i + j + 1) % 14] += a[i] / 14 + (if j < a[i] % 14 { 1 } else { 0 });\n }\n\n let mut sum: u64 = 0;\n for j in 0..14 {\n if b[j] % 2 == 0 {\n sum += b[j] as u64;\n }\n }\n max = std::cmp::max(max, sum);\n }\n println!(\"{}\", max);\n}\n\n// 基本的に 14 割った数足す\n\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n}\n"}], "negative_code": [{"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 a: Vec = input.split_whitespace().map(|x| x.parse().unwrap())\n .collect();\n\n let mut max_ans = 0;\n\n let modulo = |a, b| {\n if a < 0 {\n a % b + b\n } else {\n a % b\n }\n };\n let modsub = |a, b| {\n modulo(a - b, 14)\n };\n\n for (i, &ai) in a.iter().enumerate() {\n let q = ai / 14;\n let r = ai % 14;\n\n let mut ans = 0;\n let mut j = i + 1;\n for _ in 0..13 {\n let cnt = a[modulo(j, 14)] + q + if r < modsub(j, i) as i32 { 0 } else { 1 };\n if cnt % 2 == 0 {\n ans += cnt;\n }\n \n j += 1\n }\n\n if q % 2 == 0 {\n ans += q;\n }\n\n if max_ans < ans {\n max_ans = ans;\n }\n }\n\n println!(\"{}\", max_ans);\n}\n"}, {"source_code": "use std::io::*;\nuse std::str::FromStr;\n\nfn main() {\n let stdin = stdin();\n let mut sc = Scanner::new(stdin.lock());\n let mut a: [usize; 14] = [0; 14];\n for i in 0..14 {\n a[i] = sc.next::();\n }\n let mut max = 0;\n for i in 0..14 {\n if a[i] == 0 {\n continue;\n }\n let mut b: [usize; 14] = a.clone();\n b[i] = 0;\n for j in 0..14 {\n b[(i + j + 1) % 14] += a[i] / 14 + (if j < a[i] % 14 { 1 } else { 0 });\n }\n\n let mut sum = 0;\n for j in 0..14 {\n if b[j] % 2 == 0 {\n sum += b[j]\n }\n }\n max = std::cmp::max(max, sum);\n }\n println!(\"{}\", max);\n}\n\n// 基本的に 14 割った数足す\n\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n}\n"}], "src_uid": "1ac11153e35509e755ea15f1d57d156b"} {"source_code": "use std::io;\n\nfn main() {\n\n let mut str = String::new();\n\n io::stdin().read_line(&mut str).expect(\"You are failure\");\n\n let mut vals = [0; 2];\n\n let str = str.trim().split(\" \");\n\n let mut f = 0;\n for i in str{\n vals[f] = i.parse().expect(\"err\");\n f+=1;\n }\n\n let mut printable = true;\n\n if vals[1] == 0 || (vals[0]%2 == vals[1]%2) || (vals[1]==1 && vals[0] != 0) || vals[1] > vals[0] + 1{\n printable = false;\n }\n\n println!(\"{}\", if printable {\"YES\"} else {\"NO\"});\n\n}\n", "positive_code": [{"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 x = get!();\n let y = get!();\n \n if y == 0 || (y == 1 && x > 0) || x < y - 1 {\n println!(\"No\");\n return;\n }\n \n let d = x - (y - 1);\n \n if d % 2 != 0 {\n println!(\"No\");\n return;\n }\n \n println!(\"Yes\");\n \n}"}, {"source_code": "/*\n *\n * Author : fcbruce \n *\n * Time : Sat 10 Feb 2018 18:51:25\n *\n */\n\nfn check(copy: i32, origin: i32) -> bool {\n let y = origin - 1;\n let x = copy - y;\n\n return y == 0 && x == 0 || x >= 0 && y > 0 && x % 2 == 0;\n}\n\nfn main() {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).unwrap();\n\n let mut numbers = buffer.split_whitespace();\n\n\n let copy:i32 = numbers.next().unwrap().parse().unwrap();\n let origin:i32 = numbers.next().unwrap().parse().unwrap();\n\n if check(copy, origin) {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n\n}\n\n"}], "negative_code": [{"source_code": "/*\n *\n * Author : fcbruce \n *\n * Time : Sat 10 Feb 2018 18:51:25\n *\n */\n// n - c, m - o\n// \n// 6 3\n// \n// 2x + y = n\n// 1 + y = m\n// \n// y = 2\n\nfn check(copy: i32, origin: i32) -> bool {\n let y = origin - 1;\n let x = copy - y;\n\n return x >= 0 && y >= 0 && x % 2 == 0;\n}\n\nfn main() {\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).unwrap();\n\n let mut numbers = buffer.split_whitespace();\n\n\n let copy:i32 = numbers.next().unwrap().parse().unwrap();\n let origin:i32 = numbers.next().unwrap().parse().unwrap();\n\n if check(copy, origin) {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n\n}\n\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut str = String::new();\n\n io::stdin().read_line(&mut str).expect(\"You are failure\");\n\n let mut vals = [0; 2];\n\n let str = str.trim().split(\" \");\n\n let mut f = 0;\n for i in str{\n vals[f] = i.parse().expect(\"err\");\n f+=1;\n }\n\n let mut printable = true;\n\n if vals[1] == 0 || (vals[0]%2 == vals[1]%2) || (vals[1]==1 && vals[0] != 0) {\n printable = false;\n }\n\n println!(\"{}\", if printable {\"YES\"} else {\"NO\"});\n\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\n let mut str = String::new();\n\n io::stdin().read_line(&mut str).expect(\"You are failure\");\n\n let mut vals = [0; 2];\n\n let str = str.trim().split(\" \");\n\n let mut f = 0;\n for i in str{\n vals[f] = i.parse().expect(\"err\");\n f+=1;\n }\n\n let mut printable = true;\n\n if vals[1] == 0 || (vals[0]%2 == vals[1]%2) || (vals[1]==1 && vals[0] != 0) || vals[0] > vals[1] + 1{\n printable = false;\n }\n\n println!(\"{}\", if printable {\"YES\"} else {\"NO\"});\n\n}\n"}], "src_uid": "1527171297a0b9c5adf356a549f313b9"} {"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 s = input.sl();\n let mut a = std::collections::HashMap::::new();\n for i in 0..n-1 {\n let t = String::from(&s[i..i+2]);\n let k = 1 + if let Some(&k) = a.get(&t) { k } else { 0 };\n a.insert(t, k);\n }\n let best = a.values().max().unwrap();\n let sol = a.iter().filter(|&(_,k)| best == k).next().unwrap().0;\n println!(\"{}\", sol);\n}\n\n", "positive_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max,min,Ordering};\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 readln!();\n let s = readln!();\n let mut ss : Vec<(char,char)>= s.chars().zip(s.chars().skip(1)).collect();\n ss.sort();\n let gg = String::new();\n let mut res = (0,gg);\n let mut i = 0;\n while i < ss.len() {\n let fr = i;\n while i < ss.len() && ss[i] == ss[fr] {\n i+=1;\n }\n let mut z = String::new();\n z.push(ss[fr].0);\n z.push(ss[fr].1);\n if (i-fr,z.clone()) > res {\n res = (i-fr,z);\n }\n }\n println!(\"{}\",res.1);\n}\n"}, {"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 binary_search(s: &Vec, v:i64) -> usize {\n let mut left = 0;\n let mut right = s.len();\n\n while right-left > 1 {\n let mid = (right+left)/2;\n //debug!(left,mid,right,s[mid]);\n if s[mid] < v { left = mid; }\n else { right = mid; }\n }\n left\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let s:Vec = read::().chars().collect();\n\n let mut v:Vec<(String,i64)> = vec![];\n for i in 0..n-1 {\n let mut t = String::new();\n t.push(s[i]);\n t.push(s[i+1]);\n let mut f = false;\n for j in 0..v.len() {\n if t == v[j].0 {\n v[j].1 += 1;\n f = true;\n }\n }\n if !f {\n v.push((t,1));\n }\n }\n\n let mut t = String::new();\n let mut mx = 0;\n for i in 0..v.len() {\n if v[i].1 > mx {\n t = v[i].0.clone();\n mx = v[i].1;\n }\n }\n\n println!(\"{}\", t);\n\n\n //}\n}\n\n/*\n\n\n*/\n"}, {"source_code": "#[allow(dead_code)]\nuse std::cmp::min;\nuse std::collections::HashMap;\nuse std::io;\nuse std::str::FromStr;\nuse std::io::Read;\n\nstruct Input {\n tokens: as IntoIterator>::IntoIter,\n read_all: bool,\n}\n\nimpl Input {\n pub fn new(read_all: bool) -> Input {\n if read_all {\n let mut all = String::new();\n io::stdin().read_to_string(&mut all).unwrap();\n let tokens: Vec = all.split_whitespace().map(|s| s.to_string()).collect();\n Input {\n tokens: tokens.into_iter(),\n read_all: true,\n }\n } else {\n Input {\n tokens: vec!().into_iter(),\n read_all: false,\n }\n }\n }\n\n fn refresh_next_line(&mut self) {\n if self.read_all {\n panic!();\n }\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let tokens: Vec = buf.split_whitespace().map(|s| s.to_string()).collect();\n self.tokens = tokens.into_iter();\n }\n\n fn next_impl(&mut self) -> String {\n loop {\n if let Some(next) = self.tokens.next() {\n return next.to_string();\n }\n self.refresh_next_line();\n }\n }\n\n pub fn next(&mut self) -> T where ::Err: std::fmt::Debug {\n let next_str = self.next_impl();\n next_str.parse().unwrap()\n }\n\n pub fn next_vec(&mut self, len: usize) -> Vec where ::Err: std::fmt::Debug {\n (0..len).map(|_i| self.next()).collect()\n }\n\n pub fn next_vec_read_len(&mut self) -> Vec where ::Err: std::fmt::Debug {\n let len = self.next();\n self.next_vec(len)\n }\n}\n\nfn main() {\n let mut input = Input::new(false);\n let n: usize = input.next();\n let s: String = input.next();\n let mut two_grams = HashMap::new();\n for i in 0..(n - 1) {\n let two_gram = &s[i..i + 2];\n let mut counter = two_grams.entry(two_gram).or_insert(0);\n *counter += 1\n }\n let max_times = *two_grams.values().max().unwrap();\n for (key, val) in&two_grams {\n if *val == max_times {\n println!(\"{}\", key);\n return;\n }\n }\n}\n"}, {"source_code": "use std::collections::HashMap;\n\nstruct 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 input: Vec = scan.next::().chars().collect();\n let mut map: HashMap = HashMap::new();\n let mut res: String = String::new();\n let mut cnt = 0usize;\n for i in 0..input.len() - 1 {\n let current: String = input[i..=i + 1].iter().collect();\n map.entry(current.clone())\n .and_modify(|x| {\n *x += 1;\n })\n .or_insert(1);\n if map[¤t] > cnt {\n cnt = map[¤t];\n res = current.clone();\n }\n }\n println!(\"{}\", res);\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"}, {"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 s: Vec = parse_line!(String).bytes().collect();\n let mut counts = std::collections::HashMap::new();\n let mut best = 0;\n let mut result = Vec::new();\n for i in 1..n {\n let cnt = counts.entry(s[i - 1..=i].iter().copied().collect::>()).or_insert(0);\n *cnt += 1;\n if *cnt > best {\n best = *cnt;\n result = s[i - 1..=i].iter().copied().collect::>();\n }\n }\n writeln!(writer, \"{}\", String::from_utf8(result).unwrap()).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"}, {"source_code": "use std::io::*;\nuse std::str::FromStr;\nuse std::collections::HashMap;\n\nfn main() {\n let stdin = stdin();\n let mut sc = Scanner::new(stdin.lock());\n\n // let stdout = stdout();\n // let mut wr = BufWriter::new(stdout.lock());\n\n let n = sc.next::();\n let s = sc.next::();\n let mut h = HashMap::new();\n\n for i in 1..n {\n let v = h.entry(&s.as_str()[i - 1..i + 1]).or_insert(0);\n *v += 1;\n }\n\n let mut max = -1;\n let mut result: &str = \"\";\n for (k, v) in &h {\n if *v > max {\n max = *v;\n result = k;\n }\n }\n println!(\"{}\", result);\n}\n\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n}\n\n// pub trait BinarySearch {\n// fn lower_bound(&self, &T) -> usize;\n// fn upper_bound(&self, &T) -> usize;\n// }\n\n// impl BinarySearch for [T] {\n// fn lower_bound(&self, x: &T) -> usize {\n// let mut low = 0;\n// let mut high = self.len();\n\n// while low != high {\n// let mid = (low + high) / 2;\n// match self[mid].cmp(x) {\n// std::cmp::Ordering::Less => {\n// low = mid + 1;\n// }\n// std::cmp::Ordering::Equal | std::cmp::Ordering::Greater => {\n// high = mid;\n// }\n// }\n// }\n// low\n// }\n\n// fn upper_bound(&self, x: &T) -> usize {\n// let mut low = 0;\n// let mut high = self.len();\n\n// while low != high {\n// let mid = (low + high) / 2;\n// match self[mid].cmp(x) {\n// std::cmp::Ordering::Less | std::cmp::Ordering::Equal => {\n// low = mid + 1;\n// }\n// std::cmp::Ordering::Greater => {\n// high = mid;\n// }\n// }\n// }\n// low\n// }\n// }\n"}, {"source_code": "use std::io;\nuse std::collections::HashMap;\n\n\nfn main() {\n let n = read_one::();\n let s = read_one::()\n .chars()\n .collect::>();\n\n let mut hm = HashMap::new();\n\n for i in 0..n - 1 {\n *hm.entry(s[i..i + 2].iter().collect::()).or_insert(0) += 1;\n }\n\n let mut v: Vec<_> = hm.iter().collect();\n v.sort_by_key(|&(_, v)| v);\n v.reverse();\n println!(\"{}\", v[0].0);\n}\n\n\n#[allow(dead_code)]\nfn read() -> Vec\nwhere T:\nstd::str::FromStr,\nT::Err: std::fmt::Debug {\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.split_whitespace()\n .map(|s| s.trim().parse().unwrap())\n .collect()\n}\n\n#[allow(dead_code)]\nfn read_one() -> T\nwhere T:\nstd::str::FromStr,\nT::Err: std::fmt::Debug {\n\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n}"}, {"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 = input.u();\n let s = input.sl();\n let a = build_counting_hashmap((0..n-1).map(|i| String::from(&s[i..i+2])));\n let best = a.values().max().unwrap();\n let sol = a.iter().filter(|&(_,k)| best == k).next().unwrap().0;\n println!(\"{}\", sol);\n}\n\n"}], "negative_code": [], "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"source_code": "// ____ _ _ _ _\n// | _ \\ _ _ ___| |_ ___ _ __ | |_ ___ _ __ ___ _ __ | | __ _| |_ ___\n// | |_) | | | / __| __| / __| '_ \\ | __/ _ \\ '_ ` _ \\| '_ \\| |/ _` | __/ _ \\\n// | _ <| |_| \\__ \\ |_ | (__| |_) | | || __/ | | | | | |_) | | (_| | || __/\n// |_| \\_\\\\__,_|___/\\__| \\___| .__/___\\__\\___|_| |_| |_| .__/|_|\\__,_|\\__\\___|\n// |_| |_____| |_|\n\n//https://github.com/manta1130/Competitive_Programming_Template_Rust\n\n#[macro_use]\nmod input {\n\n use std;\n use std::io;\n\n const SPLIT_DELIMITER: char = ' ';\n\n #[macro_export]\n #[allow(unused_macros)]\n macro_rules! input {\n ( $($x:expr ),*) => {\n {\n let temp_str = input_line_str();\n let mut split_result_iter = temp_str.split_whitespace();\n $(\n let buf_split_result = split_result_iter.next();\n let buf_split_result = buf_split_result.unwrap();\n ($x) = buf_split_result.parse().unwrap();\n )*\n }\n };\n}\n\n #[allow(dead_code)]\n pub fn input_line_str() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn p(t: T)\n where\n T: std::fmt::Display,\n {\n println!(\"{}\", t);\n }\n\n #[allow(dead_code)]\n pub fn input_vector2d(line: usize) -> Vec>\n where\n T: std::str::FromStr,\n {\n let mut v: Vec> = Vec::new();\n\n for _ in 0..line {\n let vec_line = input_vector();\n v.push(vec_line);\n }\n v\n }\n\n #[allow(dead_code)]\n pub fn input_vector() -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v: Vec = Vec::new();\n\n let s = input_line_str();\n let split_result = s.split(SPLIT_DELIMITER);\n for z in split_result {\n let buf = match z.parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\"),\n };\n v.push(buf);\n }\n v\n }\n\n #[allow(dead_code)]\n pub fn input_vector_row(n: usize) -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v = Vec::with_capacity(n);\n for _ in 0..n {\n let buf = match input_line_str().parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\"),\n };\n v.push(buf);\n }\n v\n }\n\n pub trait ToCharVec {\n fn to_charvec(&self) -> Vec;\n }\n\n impl ToCharVec for String {\n fn to_charvec(&self) -> Vec {\n self.to_string().chars().collect::>()\n }\n }\n}\nuse input::*;\n\nfn main() {\n let (mut a, mut b): (u64, u64);\n input!(a, b);\n\n while !(a == 0) && !(b == 0) {\n if a >= 2 * b {\n let buf = a / (2 * b);\n a = a - 2 * b * buf;\n } else if b >= 2 * a {\n let buf = b / (2 * a);\n b = b - 2 * a * buf;\n } else {\n break;\n }\n }\n println!(\"{} {}\", a, b);\n}\n", "positive_code": [{"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 brute_force(a: i64, b: i64) -> (i64, i64) {\n let mut a = a;\n let mut b = b;\n while a > 0 && b > 0 {\n if a >= 2 * b {\n a = a % (2 * b);\n } else if b >= 2 * a {\n b = b % (2 * a);\n }\n else {\n return (a, b);\n }\n }\n (a, b)\n}\n\nfn solve(scan: &mut Scanner, out: &mut W) {\n let a: i64 = scan.token();\n let b: i64 = scan.token();\n let (a, b) = brute_force(a, b);\n writeln!(out, \"{} {}\", a, b).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"}, {"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\n\n\nfn main() {\n let mut printer = ContestPrinter::new();\n \n let (A, B) = readl!(i64, i64);\n let (mut a, mut b) = (A, B);\n loop {\n if (a == 0) | (b == 0) { break; }\n else if a >= (2*b) {\n let num = a / (2*b);\n a -= num * (2*b);\n } else if b >= (2*a) {\n let num = b / (2*a);\n b -= num * (2*a);\n } else {\n break;\n }\n }\n println!(\"{} {}\", a, b);\n}"}, {"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 }\n let mut a = get!();\n let mut b = get!();\n while a > 0 && b > 0 {\n if a >= 2 * b {\n let x = a / (2 * b);\n a -= 2 * b * x;\n } else if b >= 2 * a {\n let x = b / (2 * a);\n b -= 2 * a * x;\n } else {\n break;\n }\n }\n println!(\"{} {}\", a, b);\n}"}, {"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 a, mut b) = read!(inf,i64,i64);\n\twhile b > 0 && a > 0 {\n\t\tif a >= 2 * b {\n\t\t\ta %= 2 * b;\n\t\t} else if b >= 2 * a {\n\t\t\tb %= 2 * a;\n\t\t} else {\n\t\t\tbreak;\n\t\t}\n\t}\n\twriteln!(ouf, \"{} {}\", a, b);\n}"}, {"source_code": "use std::io;\n\nfn foo(a: u64, b:u64) -> (u64, u64) {\n if a == 0 || b == 0 {\n (a, b)\n } else if a >= 2*b {\n foo(a % (2*b), b)\n } else if b >= 2*a {\n foo(a, b % (2*a))\n } else {\n (a, b)\n }\n}\n\nfn main() {\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).unwrap();\n let data = buffer.split_whitespace()\n .map(|x| x.trim().parse::().unwrap())\n .collect::>();\n let (a,b) = foo(data[0], data[1]);\n println!(\"{} {}\", a, b);\n}\n"}, {"source_code": "//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, 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: u64,\n b: u64,\n }\n let mut a = a;\n let mut b = b;\n loop {\n if a == 0 || b == 0 {\n println!(\"{} {}\", a, b);\n return;\n } else if a >= 2 * b {\n a %= 2 * b;\n } else if b >= 2 * a {\n b %= 2 * a;\n } else {\n println!(\"{} {}\", a, b);\n return;\n }\n }\n}\n\nfn main() {\n run();\n}\n"}, {"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 mut a: u64 = it.next().unwrap().parse().unwrap();\n let mut b: u64 = it.next().unwrap().parse().unwrap();\n\n loop {\n if a == 0 || b == 0 {\n break;\n } else if 2 * b <= a {\n a %= 2 * b;\n } else if 2 * a <= b {\n b %= 2 * a;\n } else {\n break;\n }\n }\n\n println!(\"{} {}\", a, b);\n}\n"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn process(a : u64, b : u64) -> (u64, u64) {\n let mut m_a = a;\n let mut m_b = b;\n loop {\n if (m_a == 0) || (m_b == 0) {\n break;\n } else {\n let two_m_a = 2 * m_a;\n let two_m_b = 2 * m_b;\n if m_a >= two_m_b {\n m_a = m_a % two_m_b;\n } else if m_b >= two_m_a {\n m_b = m_b % two_m_a;\n } else {\n break;\n }\n }\n }\n (m_a, m_b)\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut a_b = vec![];\n read_ts(&stdin, &mut a_b);\n let (c, d) = process(a_b[0], a_b[1]);\n println!(\"{} {}\", c, d);\n}\n"}], "negative_code": [], "src_uid": "1f505e430eb930ea2b495ab531274114"} {"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 read_line_pair() -> (u64, u64) {\n let vec = read_line_vec();\n return (vec[0], vec[1]);\n}\n\nfn get_fixed_num(n: u32) -> u32 {\n let str: String = n.to_string().chars().filter(|c| *c != '0').collect();\n return str.parse().unwrap();\n}\n \nfn main() {\n let a: u32 = read_line().parse().unwrap();\n let b: u32 = read_line().parse().unwrap();\n \n let c = a + b;\n \n if get_fixed_num(a) + get_fixed_num(b) == get_fixed_num(c) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n\n // let a_line_fixed: String = a_line.chars().filter(|c| c == '0').collect();\n // let b_line_fixed: String = b_line.chars().filter(|c| c == '0').collect();\n \n // let a_fixed: u32 = a_line_fixed.parse();\n // let b_fixed: u32 = b_line_fixed.parse();\n \n // println!(\"{}\", get_fixed_num(203));\n \n}\n", "positive_code": [{"source_code": "#![allow(non_snake_case, unused_imports)]\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::{HashSet,HashMap,VecDeque,BinaryHeap};\n\n// Functions\nfn remove_zero(n: u64) -> u64{\n let mut ret = 0;\n let mut nz:Vec = Vec::new();\n for d in n.to_string().chars(){\n if d!='0'{\n nz.push(d as u64 -48);\n }\n }\n for d in nz{\n ret = ret*10 + d;\n }\n return ret;\n}\n\n// Main\nfn main(){\n input!{\n A: u64,\n B: u64\n }\n let na = remove_zero(A);\n let nb = remove_zero(B);\n let nc = remove_zero(A+B);\n println!(\"{}\", if na+nb==nc{\"YES\"}else{\"NO\"});\n}\n"}, {"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 = input.i());\n let c = a + b;\n let f = |x: i32| -> i32 {\n let mut d = 1_000_000_000;\n let mut res = 0;\n while d > 0 {\n let y = x / d % 10;\n if y > 0 {\n res = res * 10 + y;\n }\n d /= 10;\n }\n res\n };\n if f(a) + f(b) == f(c) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n\n"}, {"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 no_zeros(x: u64) -> u64 {\n let mut result = 0u64;\n let mut current = x;\n let mut current10 = 1;\n while current > 0 {\n let dig = current % 10;\n if dig != 0 {\n result += current10 * dig;\n current10 *= 10;\n }\n current /= 10;\n }\n result\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let a: u64 = scan.next();\n let b: u64 = scan.next();\n let c = a + b;\n println!(\n \"{}\",\n if no_zeros(a) + no_zeros(b) == no_zeros(c) {\n \"YES\"\n } else {\n \"NO\"\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"}], "negative_code": [], "src_uid": "ac6971f4feea0662d82da8e0862031ad"} {"source_code": "pub mod solution {\n\nuse std::cmp::min;\nuse crate::io::input::Input;\nuse crate::io::output::output;\nuse crate::{out, out_line};\n\nfn solve(input: &mut Input, _test_case: usize) {\n let (n, k) = input.read();\n let mut ans = 0;\n let mut fact = vec![0; n + 1];\n let mut inv = vec![0; n + 1];\n let mut invfact = vec![0; n + 1];\n inv[1] = 1;\n for i in 2..=n {\n inv[i] = mul(inv[(MOD % i as i32) as usize], MOD - MOD / i as i32);\n }\n fact[0] = 1;\n invfact[0] = 1;\n for i in 1..=n {\n fact[i] = mul(fact[i - 1], i as i32);\n invfact[i] = mul(invfact[i - 1], inv[i]);\n }\n for i in 0..=min(k, n) {\n add(&mut ans, c(n, i, &fact, &invfact));\n }\n out_line!(ans);\n}\n\nfn c(n: usize, k: usize, fact: &Vec, invfact: &Vec) -> i32 {\n mul(fact[n], mul(invfact[k], invfact[n - k]))\n}\n\nfn add(a: &mut i32, b: i32) {\n *a += b;\n if *a >= MOD {\n *a -= MOD;\n }\n}\n\nconst MOD: i32 = 1000000007;\n\nfn mul(a: i32, b: i32) -> i32 {\n (a as i64 * b as i64 % MOD as i64) as i32\n}\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_some()\n}\n\n\n}\npub mod io {\npub mod input {\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\nimpl<'s> Input<'s> {\n const DEFAULT_BUF_SIZE: usize = 4096;\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 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 fn read_char(&mut self) -> char {\n self.skip_whitespace();\n self.get().unwrap().into()\n }\n\n fn read_float(&mut self) -> f64 {\n self.read_string().parse().unwrap()\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\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_float()\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 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}\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", "positive_code": [{"source_code": "use std::{\n fmt::Display,\n io::{self, prelude::*, BufWriter, Stdout, StdoutLock},\n ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Sub, SubAssign},\n};\n\n#[allow(unused_imports)]\nuse crate::{\n binary_search::*, ext::*, input::*, math::*, precompute::*, random::*, ranges::*,\n recursive_function::*,\n};\n\n#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]\npub struct ModPrime {\n value: usize,\n}\nimpl ModPrime {\n pub fn new(value: usize) -> Self {\n Self::from(value)\n }\n\n pub fn value(&self) -> usize {\n self.value\n }\n}\nimpl From for ModPrime {\n fn from(value: usize) -> Self {\n Self { value: value % M }\n }\n}\nimpl Display for ModPrime {\n fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n self.value.fmt(f)\n }\n}\nimpl AddAssign for ModPrime {\n fn add_assign(&mut self, rhs: Self) {\n self.value = (self.value + rhs.value) % M;\n }\n}\nimpl SubAssign for ModPrime {\n fn sub_assign(&mut self, rhs: Self) {\n self.value = (self.value + M - rhs.value) % M;\n }\n}\nimpl MulAssign for ModPrime {\n fn mul_assign(&mut self, rhs: Self) {\n self.value = (self.value * rhs.value) % M;\n }\n}\nimpl DivAssign for ModPrime {\n fn div_assign(&mut self, rhs: Self) {\n self.value = (self.value * pow_mod(rhs.value, M - 2, M)) % M;\n }\n}\nimpl RemAssign for ModPrime {\n fn rem_assign(&mut self, rhs: Self) {\n self.value = self.value % rhs.value;\n }\n}\nimpl Add for ModPrime {\n type Output = Self;\n fn add(mut self, rhs: Self) -> Self::Output {\n self += rhs;\n self\n }\n}\nimpl Sub for ModPrime {\n type Output = Self;\n fn sub(mut self, rhs: Self) -> Self::Output {\n self -= rhs;\n self\n }\n}\nimpl Mul for ModPrime {\n type Output = Self;\n fn mul(mut self, rhs: Self) -> Self::Output {\n self *= rhs;\n self\n }\n}\nimpl Div for ModPrime {\n type Output = Self;\n fn div(mut self, rhs: Self) -> Self::Output {\n self /= rhs;\n self\n }\n}\nimpl Rem for ModPrime {\n type Output = Self;\n fn rem(mut self, rhs: Self) -> Self::Output {\n self %= rhs;\n self\n }\n}\n\n#[derive(Debug, Clone)]\npub struct CombinatoricsModPrime {\n inverses: Vec>,\n factorials: Vec>,\n factorial_inverses: Vec>,\n}\nimpl CombinatoricsModPrime {\n /// The caller is responsible of ensuring that M is a prime number\n pub fn precompute(max_value: usize) -> Self {\n let mut inverses = vec![1.into(); max_value + 1];\n let mut factorials = vec![1.into(); max_value + 1];\n let mut factorial_inverses = vec![1.into(); max_value + 1];\n for i in 2..=max_value {\n inverses[i] = ModPrime::new(M) - ModPrime::new(M / i) * inverses[M % i];\n factorials[i] = factorials[i - 1] * i.into();\n factorial_inverses[i] = factorial_inverses[i - 1] * inverses[i];\n }\n\n Self {\n inverses,\n factorials,\n factorial_inverses,\n }\n }\n\n pub fn inverse(&self, value: ModPrime) -> ModPrime {\n assert!(value.value != 0);\n self.inverses[value.value]\n }\n\n pub fn factorial(&self, value: ModPrime) -> ModPrime {\n self.factorials[value.value]\n }\n\n pub fn factorial_inverse(&self, value: ModPrime) -> ModPrime {\n self.factorial_inverses[value.value]\n }\n\n pub fn n_perm_k(&self, n: ModPrime, k: ModPrime) -> ModPrime {\n if k.value == 0 {\n 1.into()\n } else if n < k {\n 0.into()\n } else {\n self.factorials[n.value] * self.factorial_inverses[(n - k).value]\n }\n }\n\n pub fn n_choose_k(&self, n: ModPrime, k: ModPrime) -> ModPrime {\n if k.value == 0 || k == n {\n 1.into()\n } else if n < k {\n 0.into()\n } else {\n self.factorials[n.value]\n * self.factorial_inverses[k.value]\n * self.factorial_inverses[(n - k).value]\n }\n }\n\n pub fn inverse_usize(&self, value: usize) -> usize {\n self.inverse(value.into()).value\n }\n\n pub fn factorial_usize(&self, value: usize) -> usize {\n self.factorial(value.into()).value\n }\n\n pub fn factorial_inverse_usize(&self, value: usize) -> usize {\n self.factorial_inverse(value.into()).value\n }\n\n pub fn n_perm_k_usize(&self, n: usize, k: usize) -> usize {\n self.n_perm_k(n.into(), k.into()).value\n }\n\n pub fn n_choose_k_usize(&self, n: usize, k: usize) -> usize {\n self.n_choose_k(n.into(), k.into()).value\n }\n}\n\nconst MOD: usize = 1e9 as usize + 7;\n\nfn solve(read: &mut Scanner) {\n let (n, k) = (read.u(), read.u());\n let comb = CombinatoricsModPrime::::precompute(n);\n let mut total = ModPrime::new(0);\n for i in 0..=(k.min(n)) {\n total += comb.n_choose_k(n.into(), i.into());\n }\n outln!(\"{}\", total);\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut read = Scanner::new(stdin.lock());\n unsafe {\n OUTPUT.0 = Some(io::stdout());\n OUTPUT.1 = Some(BufWriter::new(OUTPUT.0.as_ref().unwrap_unchecked().lock()));\n }\n\n solve(&mut read);\n\n unsafe {\n OUTPUT.1.take();\n }\n}\n\nstatic mut OUTPUT: (Option, Option>>) = (None, None);\n#[macro_export]\nmacro_rules! out {\n ($($arg:tt)*) => {\n unsafe {\n write!(OUTPUT.1.as_mut().unwrap_unchecked(), $($arg)*).unwrap();\n }\n };\n}\n#[macro_export]\nmacro_rules! outln {\n ($($arg:tt)*) => {\n unsafe {\n writeln!(OUTPUT.1.as_mut().unwrap_unchecked(), $($arg)*).unwrap();\n }\n };\n}\n#[macro_export]\nmacro_rules! flush {\n () => {\n unsafe {\n OUTPUT.1.as_mut().unwrap_unchecked().flush().unwrap();\n }\n };\n}\n\n// Template -------------------------------------------------------------------\npub mod input {\n use std::{\n io::prelude::*,\n iter::{FromIterator, Peekable},\n mem,\n str::{self, FromStr, SplitWhitespace},\n };\n\n #[derive(Debug)]\n pub struct Scanner {\n eof: bool,\n reader: R,\n buf_str: Vec,\n buf_iter: Peekable>,\n }\n impl Scanner {\n pub fn new(reader: R) -> Self {\n Self {\n eof: false,\n reader,\n buf_str: vec![],\n buf_iter: \"\".split_whitespace().peekable(),\n }\n }\n pub fn eof(&self) -> bool {\n self.eof\n }\n\n pub fn n(&mut self) -> T {\n self.read_until_next_token();\n self.buf_iter\n .next()\n .expect(\"No token\")\n .parse()\n .ok()\n .expect(\"Failed parse\")\n }\n pub fn u(&mut self) -> usize {\n self.n::()\n }\n pub fn i(&mut self) -> i64 {\n self.n::()\n }\n pub fn f(&mut self) -> f64 {\n self.n::()\n }\n pub fn s(&mut self) -> String {\n self.n::()\n }\n #[allow(clippy::should_implement_trait)]\n pub fn next(&mut self) -> Option {\n Some(self.buf_iter.next()?.parse().ok().expect(\"Failed parse\"))\n }\n pub fn next_u(&mut self) -> Option {\n self.next::()\n }\n pub fn next_i(&mut self) -> Option {\n self.next::()\n }\n pub fn next_f(&mut self) -> Option {\n self.next::()\n }\n pub fn next_s(&mut self) -> Option {\n self.next::()\n }\n\n pub fn collection(&mut self) -> C\n where\n C: FromIterator,\n T: FromStr,\n {\n self.read_until_next_token();\n self.rest()\n }\n pub fn collection_n(&mut self, n: usize) -> C\n where\n C: FromIterator,\n T: FromStr,\n {\n (0..n).map(|_| self.n()).collect()\n }\n pub fn rest(&mut self) -> C\n where\n C: FromIterator,\n T: FromStr,\n {\n self.buf_iter\n .by_ref()\n .map(|v| v.parse().ok().expect(\"Failed parse\"))\n .collect()\n }\n\n pub fn current_line(&self) -> &[u8] {\n &self.buf_str\n }\n pub fn read_line(&mut self) {\n assert!(!self.eof, \"Tried to read after EOF\");\n\n self.buf_str.clear();\n self.reader\n .read_until(b'\\n', &mut self.buf_str)\n .expect(\"Failed read\");\n\n if !self.buf_str.is_empty() && self.buf_str.last().unwrap() == &b'\\n' {\n self.buf_str.pop();\n } else {\n self.eof = true;\n }\n\n self.buf_iter = unsafe {\n let slice = str::from_utf8_unchecked(&self.buf_str);\n mem::transmute(slice.split_whitespace().peekable())\n };\n }\n pub fn read_until_next_token(&mut self) {\n while !self.eof && self.buf_iter.peek().is_none() {\n self.read_line();\n }\n }\n }\n}\n\npub mod num_traits {\n use std::ops::{\n Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div,\n DivAssign, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,\n SubAssign,\n };\n\n pub trait FromU8: Copy {\n fn from_u8(val: u8) -> Self;\n }\n macro_rules! from_u8_impl {\n ($($t: ident)+) => {$(\n impl FromU8 for $t {\n fn from_u8(val: u8) -> Self {\n val as $t\n }\n }\n )+};\n }\n from_u8_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize f32 f64);\n\n pub trait ToF64: Copy {\n fn to_f64(self) -> f64;\n }\n macro_rules! to_f64_impl {\n ($($t: ident)+) => {$(\n impl ToF64 for $t {\n fn to_f64(self) -> f64 {\n self as f64\n }\n }\n )+};\n }\n to_f64_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize f32 f64);\n\n pub trait Number:\n FromU8\n + ToF64\n + PartialOrd\n + Add\n + Sub\n + Mul\n + Div\n + Rem\n + AddAssign\n + SubAssign\n + MulAssign\n + DivAssign\n + RemAssign\n {\n }\n macro_rules! number_impl {\n ($($t: ident)+) => {$(\n impl Number for $t {}\n )+};\n }\n number_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize f32 f64);\n\n pub trait Signed: Number + Neg {}\n macro_rules! signed_impl {\n ($($t: ident)+) => {$(\n impl Signed for $t {}\n )+};\n }\n signed_impl!(i128 i64 i32 i16 i8 isize f32 f64);\n\n pub trait Unsigned: Number {}\n macro_rules! unsigned_impl {\n ($($t: ident)+) => {$(\n impl Unsigned for $t {}\n )+};\n }\n unsigned_impl!(u128 u64 u32 u16 u8 usize);\n\n pub trait Integer:\n Number\n + Ord\n + BitOr\n + BitAnd\n + BitXor\n + Shl\n + Shr\n + BitOrAssign\n + BitAndAssign\n + BitXorAssign\n + ShlAssign\n + ShrAssign\n {\n }\n macro_rules! integer_impl {\n ($($t: ident)+) => {$(\n impl Integer for $t {}\n )+};\n }\n integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);\n\n pub trait Float: Number {}\n macro_rules! float_impl {\n ($($t: ident)+) => {$(\n impl Float for $t {}\n )+};\n }\n float_impl!(f32 f64);\n}\n\npub mod ranges {\n use std::ops::{Range, RangeInclusive};\n\n use crate::{math, num_traits::Integer};\n\n #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]\n pub struct DiscreteRange {\n pub start: T,\n pub end: T,\n }\n impl DiscreteRange {\n pub fn is_empty(&self) -> bool {\n self.start >= self.end\n }\n\n pub fn len(&self) -> T {\n if self.is_empty() {\n T::from_u8(0)\n } else {\n self.end - self.start\n }\n }\n\n pub fn contains(&self, x: T) -> bool {\n self.start <= x && self.end > x\n }\n\n pub fn is_singleton(&self) -> bool {\n self.start + T::from_u8(1) == self.end\n }\n\n pub fn is_splittable(&self) -> bool {\n self.start + T::from_u8(1) < self.end\n }\n\n pub fn is_disjoint(&self, other: Self) -> bool {\n self.is_empty()\n || other.is_empty()\n || self.start >= other.end\n || self.end <= other.start\n }\n\n pub fn is_subset(&self, other: Self) -> bool {\n self.is_empty()\n || (!other.is_empty() && self.start >= other.start && self.end <= other.end)\n }\n\n pub fn is_superset(&self, other: Self) -> bool {\n other.is_subset(*self)\n }\n\n pub fn midpoint(&self) -> Option {\n if self.is_empty() {\n None\n } else {\n Some(math::midpoint(self.start, self.end - T::from_u8(1)))\n }\n }\n\n pub fn split(&self) -> Option<(Self, Self)>\n where\n Self: Sized,\n {\n if self.is_splittable() {\n let mid_plus_one =\n T::from_u8(1) + math::midpoint(self.start, self.end - T::from_u8(1));\n Some((\n Self {\n start: self.start,\n end: mid_plus_one,\n },\n Self {\n start: mid_plus_one,\n end: self.end,\n },\n ))\n } else {\n None\n }\n }\n\n pub fn iter(&self) -> Range {\n self.start..self.end\n }\n }\n impl From> for DiscreteRange {\n fn from(range: Range) -> Self {\n Self {\n start: range.start,\n end: range.end,\n }\n }\n }\n impl From> for DiscreteRange {\n fn from(range: RangeInclusive) -> Self {\n Self {\n start: *range.start(),\n end: *range.end() + T::from_u8(1),\n }\n }\n }\n}\n\npub mod ext {\n use crate::num_traits::Float;\n\n #[allow(clippy::derive_partial_eq_without_eq)]\n #[derive(Debug, Clone, Copy, Default, PartialEq, PartialOrd, Hash)]\n pub struct OrdFloat(pub T);\n impl Eq for OrdFloat {}\n #[allow(clippy::derive_ord_xor_partial_ord)]\n impl Ord for OrdFloat {\n fn cmp(&self, other: &Self) -> std::cmp::Ordering {\n self.0.partial_cmp(&other.0).unwrap()\n }\n }\n}\n\npub mod math {\n use std::{mem, ops::RangeFrom};\n\n use crate::num_traits::{Integer, Number, Unsigned};\n\n /// Rounds towards a if the type is an integer\n /// Risks overflowing if a and b have different signs\n pub fn midpoint(a: T, b: T) -> T\n where\n T: Number,\n {\n a + (b - a) / T::from_u8(2)\n }\n\n pub fn gcd(mut a: T, mut b: T) -> T\n where\n T: Integer + Unsigned,\n {\n while b != T::from_u8(0) {\n a %= b;\n mem::swap(&mut a, &mut b);\n }\n a\n }\n\n pub fn lcm(a: T, b: T) -> T\n where\n T: Integer + Unsigned,\n {\n (a / gcd(a, b)) * b\n }\n\n pub fn pow_mod(b: T, e: T, modulo: T) -> T\n where\n T: Integer + Unsigned,\n {\n if e == T::from_u8(0) {\n T::from_u8(1) % modulo\n } else {\n let half = pow_mod(b, e / T::from_u8(2), modulo);\n let combined = (half * half) % modulo;\n if e % T::from_u8(2) == T::from_u8(1) {\n (combined * b) % modulo\n } else {\n combined\n }\n }\n }\n\n pub fn is_prime(n: T) -> bool\n where\n T: Integer + Unsigned,\n RangeFrom: Iterator,\n {\n if n < T::from_u8(2) {\n false\n } else {\n for x in (T::from_u8(2)..).take_while(|&x| x * x <= n) {\n if n % x == T::from_u8(0) {\n return false;\n }\n }\n true\n }\n }\n}\n\npub mod precompute {\n #[derive(Debug, Clone)]\n pub struct Logarithms {\n /// index.log2() rounded down\n log2: Vec,\n /// greatest power of 2 <= index\n previous_power_of_two: Vec,\n }\n impl Logarithms {\n pub fn precompute(max_value: usize) -> Self {\n let mut log2 = vec![0; max_value + 1];\n let mut previous_power_of_two = vec![1; max_value + 1];\n for i in 2..=max_value {\n log2[i] = log2[i / 2] + 1;\n previous_power_of_two[i] = 1 << log2[i];\n }\n Self {\n log2,\n previous_power_of_two,\n }\n }\n\n pub fn log2(&self, value: usize) -> usize {\n assert!(value != 0);\n self.log2[value]\n }\n\n pub fn previous_power_of_two(&self, value: usize) -> usize {\n assert!(value != 0);\n self.previous_power_of_two[value]\n }\n }\n}\n\npub mod binary_search {\n use crate::{math, num_traits::Integer, ranges::DiscreteRange};\n\n pub fn binary_search_first_true(range: DiscreteRange, mut p: impl FnMut(T) -> bool) -> T\n where\n T: Integer,\n {\n let mut low = range.start;\n let mut high = range.end;\n while low < high {\n let mid = math::midpoint(low, high);\n if p(mid) {\n high = mid;\n } else {\n low = mid + T::from_u8(1);\n }\n }\n high\n }\n\n pub fn partition_point(range: DiscreteRange, mut p: impl FnMut(T) -> bool) -> T\n where\n T: Integer,\n {\n binary_search_first_true(range, |i| !p(i))\n }\n}\n\npub mod random {\n use std::{num::Wrapping, time::SystemTime};\n\n /// Pcg32 from https://docs.rs/pcg_rand/0.13.0/src/pcg_rand/lib.rs.html#406\n #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]\n pub struct Random {\n state: u64,\n inc: u64,\n }\n impl Random {\n pub fn random_seed() -> Self {\n let time = SystemTime::now()\n .duration_since(std::time::UNIX_EPOCH)\n .expect(\"Duration since epoch failed\");\n Self {\n state: (time.as_nanos() as u32) as u64,\n inc: time.subsec_nanos() as u64,\n }\n }\n\n pub fn from_seed(seed: [u64; 2]) -> Self {\n Self {\n state: seed[0],\n inc: seed[1],\n }\n }\n\n pub fn next_u32(&mut self) -> u32 {\n let oldstate = Wrapping(self.state);\n self.state =\n (oldstate * Wrapping(6_364_136_223_846_793_005u64) + Wrapping(self.inc | 1)).0;\n let xorshifted: u32 = (((oldstate >> 18usize) ^ oldstate) >> 27usize).0 as u32;\n let rot: u32 = (oldstate >> 59usize).0 as u32;\n (xorshifted >> rot) | (xorshifted << ((-(rot as i32)) & 31))\n }\n }\n}\n\n#[allow(clippy::too_many_arguments)]\npub mod recursive_function {\n use std::marker::PhantomData;\n\n macro_rules! recursive_function {\n ($name: ident, $trait: ident, ($($type: ident $arg: ident,)*)) => {\n pub trait $trait<$($type, )*Output> {\n fn call(&mut self, $($arg: $type,)*) -> Output;\n }\n\n pub struct $name\n where\n F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,\n {\n f: std::cell::UnsafeCell,\n $($arg: PhantomData<$type>,\n )*\n phantom_output: PhantomData,\n }\n\n impl $name\n where\n F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,\n {\n pub fn new(f: F) -> Self {\n Self {\n f: std::cell::UnsafeCell::new(f),\n $($arg: Default::default(),\n )*\n phantom_output: Default::default(),\n }\n }\n }\n\n impl $trait<$($type, )*Output> for $name\n where\n F: FnMut(&mut dyn $trait<$($type, )*Output>, $($type, )*) -> Output,\n {\n fn call(&mut self, $($arg: $type,)*) -> Output {\n unsafe { (&mut *self.f.get())(self, $($arg, )*) }\n }\n }\n }\n }\n\n recursive_function!(RecursiveFunction0, Callable0, ());\n recursive_function!(RecursiveFunction, Callable, (Arg arg,));\n recursive_function!(RecursiveFunction2, Callable2, (Arg1 arg1, Arg2 arg2,));\n recursive_function!(RecursiveFunction3, Callable3, (Arg1 arg1, Arg2 arg2, Arg3 arg3,));\n recursive_function!(RecursiveFunction4, Callable4, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4,));\n recursive_function!(RecursiveFunction5, Callable5, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5,));\n recursive_function!(RecursiveFunction6, Callable6, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6,));\n recursive_function!(RecursiveFunction7, Callable7, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7,));\n recursive_function!(RecursiveFunction8, Callable8, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8,));\n recursive_function!(RecursiveFunction9, Callable9, (Arg1 arg1, Arg2 arg2, Arg3 arg3, Arg4 arg4, Arg5 arg5, Arg6 arg6, Arg7 arg7, Arg8 arg8, Arg9 arg9,));\n}\n"}, {"source_code": "use std::{\r\n io::{prelude::*, stdin, stdout, BufWriter},\r\n iter::once,\r\n};\r\n\r\nconst MOD: i64 = 1000000007;\r\n\r\nfn main() {\r\n let std_in = stdin();\r\n let mut input = Scanner::new(std_in.lock());\r\n\r\n let std_out = stdout();\r\n let mut output = BufWriter::new(std_out.lock());\r\n\r\n let (n, k): (i64, i64) = (input.token(), input.token());\r\n if k >= n {\r\n writeln!(output, \"{}\", bin_pow_m(2, n)).unwrap();\r\n } else {\r\n let fact: Vec = once(1)\r\n .chain((1..=n).scan(1i64, |state, x| {\r\n *state = mul_m(*state, x);\r\n Some(*state)\r\n }))\r\n .collect();\r\n let inv_fact: Vec = fact.iter().map(|&x| bin_pow_m(x, MOD - 2)).collect();\r\n\r\n let mut result = 0;\r\n for i in 0..=(k as usize) {\r\n result = add_m(result, mul_m(inv_fact[i], inv_fact[n as usize - i]));\r\n }\r\n result = mul_m(result, fact[n as usize]);\r\n writeln!(output, \"{}\", result).unwrap();\r\n }\r\n}\r\n\r\nfn add_m(x: i64, y: i64) -> i64 {\r\n let mut tmp = x + y;\r\n if tmp < 0 {\r\n tmp += MOD;\r\n }\r\n if tmp >= MOD {\r\n tmp -= MOD;\r\n }\r\n tmp\r\n}\r\n\r\nfn mul_m(x: i64, y: i64) -> i64 {\r\n (x * y) % MOD\r\n}\r\n\r\nfn bin_pow_m(mut a: i64, mut n: i64) -> i64 {\r\n let mut res = 1;\r\n while n != 0 {\r\n if (n & 1) != 0 {\r\n res = mul_m(res, a);\r\n }\r\n a = mul_m(a, a);\r\n n >>= 1;\r\n }\r\n res\r\n}\r\n\r\npub struct Scanner {\r\n reader: B,\r\n buf_str: Vec,\r\n buf_iter: std::str::SplitWhitespace<'static>,\r\n}\r\nimpl Scanner {\r\n pub fn new(reader: B) -> Self {\r\n Self {\r\n reader,\r\n buf_str: Vec::new(),\r\n buf_iter: \"\".split_whitespace(),\r\n }\r\n }\r\n pub fn token(&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 = std::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"}, {"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: i64 = sc.tok();\r\n let k: i64 = sc.tok();\r\n let mut cur = 1;\r\n let mut res = 1;\r\n for a in 1..=min(n, k) {\r\n cur = (cur * mod_inv(a, MOD)) % MOD;\r\n cur = (cur * (n - a + 1)) % MOD;\r\n res += cur;\r\n if res >= MOD {\r\n res -= MOD;\r\n }\r\n }\r\n writeln!(wr, \"{}\", res);\r\n}\r\n\r\n/// Returns x, y such that ax + by = gcd(a, b);\r\n/// Assumes a, b are >= 0\r\npub fn extended_euclid(a: i64, b: i64) -> (i64, i64, i64) {\r\n let (mut x1, mut y1, mut z1) = (1i64, 0i64, a);\r\n let (mut x2, mut y2, mut z2) = (0i64, 1i64, b);\r\n while z2 > 0 {\r\n let k = z1 / z2;\r\n let (x3, y3, z3) = (x1 - k * x2, y1 - k * y2, z1 - k * z2);\r\n (x1, y1, z1) = (x2, y2, z2);\r\n (x2, y2, z2) = (x3, y3, z3);\r\n }\r\n (x1, y1, z1)\r\n}\r\n\r\n/// Finds the inverse of a mod m.\r\n/// Assumes they are relatively prime and m > 0\r\npub fn mod_inv(mut a: i64, m: i64) -> i64 {\r\n a %= m;\r\n if a < 0 {\r\n a += m;\r\n }\r\n let res = extended_euclid(a, m).0 % m;\r\n if res < 0 {\r\n res + m\r\n } else {\r\n res\r\n }\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"}, {"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\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 fn mul(a: u32, b: u32) -> 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(M::mul(self.val, rhs.into().val))\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 fn mul(a: u32, b: u32) -> u32 { \n mul_mod_u32(a, b, Self::get_modulus())\n }\n }\n pub type $mint = ModIntBase<$name>;\n }\n }\n\n #[derive(Debug, Clone, Copy)]\n pub struct ModulusCalc {\n pub modulus: u32,\n pub inv: u64\n }\n \n macro_rules! dynamic_modulus {\n ($mint: ident, $name: ident, $modulus: ident) => {\n static $modulus: crate::Unsync> = crate::Unsync(Cell::new(ModulusCalc { modulus: 0, inv: 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().modulus }\n fn mul(a: u32, b: u32) -> u32 {\n let ModulusCalc { modulus, inv } = $modulus.0.get();\n let p = a as u64 * b as u64;\n let g = ((p as u128 * inv as u128) >> 64) as u64;\n let (r, c) = p.overflowing_sub(g * modulus as u64);\n if c { (r as u32).wrapping_add(modulus) } else { r as u32 }\n }\n }\n impl $name {\n pub fn set_modulus(val: u32) { \n let inv = (1u64.wrapping_neg() / val as u64).wrapping_add(1);\n $modulus.0.set(ModulusCalc { modulus: val, inv })\n }\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;\ntype 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\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 let mc = ModCombinatorics::new(n);\n\n let ans = (0..=min(n, k)).map(|i| mc.inv_factorial(i) * mc.inv_factorial(n-i)).sum::() * mc.factorial(n);\n println!(ans);\n }\n \n out_flush();\n}"}, {"source_code": "use std::{io::{BufRead, BufWriter, Write}, hash::Hash};\r\n#[allow(unused)]\r\nuse std::{{collections::*, mem::swap},cmp::Reverse};\r\n\r\nuse std::convert::TryInto;\r\n\r\npub struct Combi {\r\n fact: Vec,\r\n ifact: Vec,\r\n}\r\nimpl Combi {\r\n pub fn new(n:usize) -> Self{\r\n let mut fact = vec![0;n+1];\r\n fact[0]=1;\r\n for i in 0..n {\r\n fact[i+1] = fact[i]*(i+1)%MOD;\r\n }\r\n let mut ifact = vec![0;n+1];\r\n ifact[n] = Self::inv(fact[n]);\r\n for i in (0..n).rev() {\r\n ifact[i] = ifact[i+1]*(i+1)%MOD;\r\n }\r\n return Self { fact, ifact};\r\n }\r\n\r\n pub fn kperm>(&self,n:U,k:U) -> usize {\r\n let n = n.try_into().ok().expect(\"Unable to cast n to usize\");\r\n let k = k.try_into().ok().expect(\"Unable to cast k to usize\");\r\n if n < k {\r\n return 0;\r\n }\r\n return self.fact[n]*self.ifact[n-k]%MOD;\r\n }\r\n\r\n pub fn kcombi>(&self,n:U,k:U) -> usize {\r\n let n = n.try_into().ok().expect(\"Unable to cast n to usize\");\r\n let k = k.try_into().ok().expect(\"Unable to cast k to usize\");\r\n if n < k {\r\n return 0;\r\n }\r\n return self.fact[n]*self.ifact[k]%MOD*self.ifact[n-k]%MOD;\r\n }\r\n\r\n pub fn fact(&self) -> &Vec { &self.fact }\r\n pub fn ifact(&self) -> &Vec { &self.ifact }\r\n\r\n fn pow(val:usize, mut power: usize) -> usize {\r\n let mut square = val;\r\n let mut ret = 1;\r\n while 0 < power {\r\n if (power & 1) == 1{\r\n ret *= square;\r\n ret %= MOD;\r\n }\r\n square *= square;\r\n square %= MOD;\r\n power >>= 1;\r\n }\r\n return ret;\r\n }\r\n fn inv(val: usize) -> usize {\r\n return Self::pow(val, MOD - 2);\r\n }\r\n}\r\n\r\nimpl Default for Combi{\r\n fn default() -> Self {\r\n return Self::new(1_000_000);\r\n }\r\n}\r\n\r\n\r\nfn main() {\r\n let sin = std::io::stdin();\r\n let scan = &mut Scanner::new(sin.lock());\r\n let sout = std::io::stdout();\r\n let out = &mut BufWriter::new(sout.lock());\r\n solve_wrapper(scan, out, solve);\r\n}\r\n\r\n#[allow(unused)]\r\n#[macro_export]\r\nmacro_rules! logln {\r\n ($($arg:tt)*) => ({\r\n #[cfg(debug_assertions)]\r\n println!($($arg)*);\r\n })\r\n}\r\n\r\ntrait MapX {\r\n fn update_with V>(&mut self, key:K, get_new_value:F);\r\n}\r\nmacro_rules! update_with { () => {\r\n fn update_with V>(&mut self, key:K, get_new_value:F) {\r\n let v = self.entry(key).or_default();\r\n let nv = get_new_value(v);\r\n *v = nv;\r\n }\r\n} }\r\nimpl MapX for BTreeMap {\r\n update_with!();\r\n}\r\nimpl MapX for HashMap {\r\n update_with!();\r\n}\r\n\r\ntrait UsizeX {\r\n fn i64(self) -> i64;\r\n fn ssb(self,rhs:usize) -> usize;\r\n}\r\nimpl UsizeX for usize {\r\n fn i64(self) -> i64 { self as i64 }\r\n fn ssb(self,rhs:usize) -> usize { self.saturating_sub(rhs) }\r\n}\r\n\r\ntrait I64X {\r\n fn usize(self) -> usize; }\r\nimpl I64X for i64 {\r\n fn usize(self) -> usize { self as usize }\r\n}\r\n\r\npub struct Scanner {\r\n reader: R,\r\n buffer: Vec,\r\n}\r\nimpl Scanner {\r\n pub fn new(reader: R) -> Self {\r\n Self { reader, buffer: vec![] }\r\n }\r\n pub fn token(&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 self.reader.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 pub fn line(&mut self) -> Vec {\r\n if !self.buffer.is_empty() {\r\n panic!(\"Consume token buffer before read a line.\");\r\n }\r\n let mut input = String::new();\r\n self.reader.read_line(&mut input).expect(\"Failed read\");\r\n input.split_whitespace().map(|v| v.parse().ok().expect(\"Failed parse\")).collect()\r\n }\r\n pub fn line_withT>(&mut self, f: F) -> Vec {\r\n return self.line().iter().map(f).collect::>();\r\n }\r\n}\r\n\r\n#[cfg(test)]\r\nmod abc999x {\r\n use super::*;\r\n use std::io::Read;\r\n\r\n macro_rules! test_macro {\r\n ($name:ident,) => {\r\n #[test]\r\n fn $name() {\r\n let fn_name = stringify!($name);\r\n let test_no = fn_name.as_bytes().last().copied().unwrap() as char;\r\n let bname = env!(\"CARGO_BIN_NAME\");\r\n let fname = format!(\"src/contest/{}/in{}\",bname,test_no);\r\n let f = std::fs::File::open(fname);\r\n if f.is_err() {\r\n panic!(\"No input file\");\r\n }\r\n let mut f = f.unwrap();\r\n let mut inp = Vec::new();\r\n f.read_to_end(&mut inp).unwrap();\r\n let fname = format!(\"src/contest/{}/out{}\",bname,test_no);\r\n let f = std::fs::File::open(fname);\r\n let mut exp = Vec::new();\r\n if let Ok(mut f) = f {\r\n f.read_to_end(&mut exp).unwrap();\r\n }\r\n let exp = String::from_utf8_lossy(&exp);\r\n let out = &mut Vec::new();\r\n let scan = &mut Scanner::new(&*inp);\r\n solve_wrapper(scan, out, solve);\r\n let out = String::from_utf8_lossy(&out);\r\n assert_eq!(exp, out);\r\n }\r\n };\r\n ($name:ident, $($n:ident),*,) => {\r\n test_macro!($name,);\r\n test_macro!($($n),*,);\r\n };\r\n }\r\n\r\n test_macro!(\r\ntest1,\r\ntest2,\r\ntest3,\r\n);\r\n\r\n}\r\n\r\nfn solve_wrapper(scan: &mut Scanner, out: &mut W, mut solve: F)\r\n where B: BufRead, W: Write, F:FnMut(&mut Scanner, &mut W)\r\n {\r\n let t = 1;\r\n //let t = scan.token::();\r\n for _ in 0..t {\r\n solve(scan,out);\r\n }\r\n}\r\n\r\nconst MOD:usize = 1e9 as usize + 7;\r\n\r\nfn solve(scan: &mut Scanner, out: &mut impl Write) {\r\n let n = scan.token::();\r\n let k = scan.token::();\r\n let cmb = Combi::::new(n);\r\n cmb.kcombi(n,k);\r\n let mut ans = 0;\r\n for i in 0..(k.min(n)+1) {\r\n ans+=cmb.kcombi(n,i);\r\n ans%=MOD;\r\n }\r\n writeln!(out, \"{}\", ans).ok();\r\n}\r\n\r\n\r\n\r\n\r\n"}, {"source_code": "// ---------- begin scanner -----------\n#[allow(unused_imports)]\nuse std::io::{BufWriter, stdin, stdout, Read, Write, Stdout};\nuse std::str::FromStr;\n\npub struct Scanner<'a> {\n it: std::str::SplitWhitespace<'a>,\n}\n#[allow(dead_code)]\nimpl<'a> Scanner<'a> {\n pub fn new(s: &'a String) -> Scanner<'a> {\n Scanner {\n it: s.split_whitespace(),\n }\n }\n pub fn next(&mut self) -> T {\n self.it.next().expect(\"read EOF\").parse::().ok().expect(\"parse failed\")\n }\n pub fn next_n(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next()).collect()\n }\n pub fn next_n_index1(&mut self, n: usize) -> Vec {\n std::iter::once(T::default()).chain((0..n).map(|_| self.next())).collect()\n }\n pub fn next_chars(&mut self) -> Vec { self.it.next().unwrap().chars().collect() }\n pub fn next_bytes(&mut self) -> Vec { self.it.next().unwrap().bytes().collect() }\n pub fn next_digits(&mut self) -> Vec {\n self.it.next().unwrap().bytes().map(|c|c-C0).collect()\n }\n}\n// ---------- end scanner -------------\n\n\n// ---------- begin utils -------------\n#[allow(dead_code)]\nconst C0: u8 = '0' as u8;\n\n// ---------- end utils ---------------\n\n\n// ---------- begin debugger ----------\n#[cfg(feature = \"my_debug\")]\n#[macro_export]\nmacro_rules! debug {\n () => {\n eprintln!(\"[{}:{}]\", file!(), line!())\n };\n ($val:expr $(,)?) => {\n eprintln!(\"[{}:{}] {} = {:?}\", file!(), line!(), stringify!($val), &($val))\n };\n ($($val:expr),+ $(,)?) => {\n ($(debug!($val)),+,)\n };\n}\n\n#[cfg(not(feature = \"my_debug\"))]\n#[macro_export]\nmacro_rules! debug {\n ($( $args:expr ),*) => {}\n}\n// ---------- end debugger ------------\n\n\nfn main() {\n debug!(\"Ish: good luck and high rating!\");\n\n #[cfg(not(feature = \"my_debug\"))]\n let s = {\n let mut s = String::new();\n stdin().read_to_string(&mut s).unwrap();\n s\n };\n #[cfg(feature = \"my_debug\")]\n let s = std::fs::read_to_string(\"in.txt\").unwrap();\n\n let mut sc = Scanner::new(&s);\n let out = &mut BufWriter::new(stdout());\n\n // let cases: u32 = sc.next();\n let cases: u32 = 1;\n debug!(cases);\n for _case in 1..=cases { debug!(_case);\n run(&mut sc, out);\n }\n}\n\n\n/** Write your mind here.\n1234 -\n不妨假设都是左赢\n1\n1 3\n12 34\n3142\n\n1\n1 5\n1 3 5 7\n12 34 56 78\n\n\n1\n1 2\n1 3 2 4\n153\n\n1 一定不能和\n\n二分?\n1\n1 3\n1 2 3 4\n15 26 37 48\n\n\n1\n1 2\n1 3 2 5\n14 36 27 58\n\n简单的说,1 有被每个对手替换的风险。\n如果 k=1,答案就是 n+1,因为 1 可能被三个对手替换,从中选择最菜的。\n\n如果 k=2 呢, 可以替换两次。\n\n1~16, k=1, ans=5\nk=2, 可以换的就是\n\n1\n1 9\n1 5 9 d\n1 3 5 7 9 b d f\n1_ _+ _+ +8 _+ +c +e f0\n\n*可以换多少个\nk=0, 1\nk=1, n个, 4\nk=2,1+2+..+n-1, 7\nk=3, 1\n\n层\n0: n\n1: 1, 2, 3, 4, .., n-1\n2:\n\nn^2 做法有了,层数转移。\n\n原数组\n0 0 0 0 1 k=0, ans=1\n1 1 1 1 0 k=1, ans=4\n3 2 1 0 0 k=2, ans=7\n3 1 0 0 0 k=3, ans=8\n1 0 0 0 0 k=4, ans=8\n\nn=3\n\nans(n, k) = for i in 0..=k {\n C(n, i)\n}\n\n */\n\nstruct MathSolver {\n fac: Vec,\n}\nimpl MathSolver {\n const MOD: i64 = 1000000007;\n\n fn new(mx: usize) -> Self {\n let mut fac = vec![1i64; mx];\n for i in 1..mx {\n fac[i] = (fac[i-1] * i as i64) % Self::MOD;\n }\n Self { fac }\n }\n\n // solve ax+by=gcd(a,b)\n fn exgcd(a: i64, b: i64) -> (i64, i64) {\n if b == 0 {\n return (1, 0);\n }\n let (x, y) = Self::exgcd(b, a % b);\n (y, x - a / b * y)\n }\n\n fn normalize(a: i64) -> i64 {\n (a % Self::MOD + Self::MOD) % Self::MOD\n }\n\n // solve ax===1 (mod b)\n fn inv(&self, a: i64) -> i64{\n Self::normalize(Self::exgcd(a, Self::MOD).0)\n }\n\n fn c(&self, a: usize, b: usize) -> i64 {\n self.fac[a] * self.inv(self.fac[b] * self.fac[a-b] % Self::MOD) % Self::MOD\n }\n}\n\nfn run(sc: &mut Scanner, out: &mut BufWriter) {\n let n = sc.next::();\n let k = sc.next::();\n\n let solver = MathSolver::new(n+1);\n let mut ans = 0;\n for i in 0..=k.min(n) {\n ans += solver.c(n, i);\n ans %= 1_000_000_007;\n }\n\n\n // let ans = if arr == brr {\"YES\"} else {\"NO\"};\n\n // let ans = 1;\n // let mut ok = true;\n // let ans = if ok {\"Yes\"} else {\"No\"};\n writeln!(out, \"{ans}\").ok();\n // for ans in ans {\n // for num in ans { write!(out, \"{num}\").ok(); }\n // writeln!(out).ok();\n // }\n}\n"}, {"source_code": "type Mod = ModInt1000000007;\nfn main() {\n let stdout = std::io::stdout();\n let mut writer = std::io::BufWriter::new(stdout.lock());\n #[allow(unused_macros)] macro_rules! print { ($($tt:tt)*) => {{ use std::io::Write; std::write!(writer, $($tt)*).unwrap(); }}; }\n #[allow(unused_macros)] macro_rules! println { ($($tt:tt)*) => {{ use std::io::Write; std::writeln!(writer, $($tt)*).unwrap(); }}; }\n\n let mut precalc = Binom::::new();\n input! {\n n: usize,\n k: usize\n }\n let k = k.min(n);\n let mut ans = Mod::raw(0);\n for i in 0..=k {\n ans += precalc.binom(n, i);\n }\n println!(\"{}\", ans);\n}\n\nstruct Binom {\n len: usize,\n inv: Vec,\n fact: Vec,\n ifact: Vec,\n n: Option,\n nprod: Vec,\n m: Option,\n mprod_n: usize,\n mprod: T\n}\n\n#[allow(dead_code)]\nimpl Binom {\n pub fn new() -> Self {\n assert_eq!(std::mem::size_of::(), 8);\n\n Self {\n len: 1,\n inv: vec![0, 1],\n fact: vec![T::raw(1), T::raw(1)],\n ifact: vec![T::raw(1), T::raw(1)],\n n: None,\n nprod: vec![],\n m: None,\n mprod_n: 0,\n mprod: T::raw(0)\n }\n }\n\n fn ensure(&mut self, idx: usize) {\n if idx > self.len {\n self.inv.reserve(idx - self.len);\n self.fact.reserve(idx - self.len);\n self.ifact.reserve(idx - self.len);\n let m = T::modulus() as usize;\n for i in self.len+1..=idx {\n let inv_i = self.inv[m % i] * (m - m / i) % m;\n self.inv.push(inv_i);\n self.fact.push(self.fact[i - 1] * T::from(i));\n self.ifact.push(self.ifact[i - 1] * T::raw(inv_i as u32));\n }\n self.len = idx;\n }\n }\n\n pub fn binom(&mut self, n: usize, m: usize) -> T {\n if m > n {\n return T::raw(0)\n }\n if m == 0 || m == n {\n return T::raw(1)\n }\n self.ensure(n);\n self.fact[n] * self.ifact[m] * self.ifact[n - m]\n }\n\n pub fn binom_n(&mut self, n: usize, m: usize) -> T {\n if m > n {\n return T::raw(0)\n }\n if m == 0 || m == n {\n return T::raw(1)\n }\n if n >= T::modulus() as usize {\n return self.binom_n(n % T::modulus() as usize, m);\n }\n if self.n != Some(n) {\n self.n = Some(n);\n self.nprod = vec![T::from(n)];\n }\n for i in self.nprod.len()..m {\n self.nprod.push(self.nprod[i - 1] * T::from(n - i));\n }\n self.ensure(m);\n self.nprod[m - 1] * self.ifact[m]\n }\n\n pub fn binom_m(&mut self, n: usize, m: usize) -> T {\n if m > n {\n return T::raw(0)\n }\n if m == 0 || m == n {\n return T::raw(1)\n }\n if n >= T::modulus() as usize {\n return self.binom_m(n % T::modulus() as usize, m);\n }\n if self.m != Some(m) || self.mprod_n > n + m || self.mprod_n + m < n {\n self.m = Some(m);\n self.mprod_n = n;\n self.mprod = ((n-m+1)..=n).map(T::from).product::();\n } else {\n while self.mprod_n < n {\n self.mprod_n += 1;\n self.mprod *= T::from(self.mprod_n);\n self.mprod /= T::from(self.mprod_n - m);\n }\n while self.mprod_n > n {\n self.mprod /= T::from(self.mprod_n);\n self.mprod *= T::from(self.mprod_n - m);\n self.mprod_n -= 1;\n }\n }\n self.ensure(m);\n self.mprod * self.ifact[m]\n }\n\n}\n\n// input macro with modifications (to better align with proconio)\n// based on https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8\n\n#[macro_export]\nmacro_rules! input {\n (@lock_stdin $reader:ident) => {\n let stdin = std::io::stdin();\n let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));\n let mut $reader = move || -> String {\n unsafe {\n String::from_utf8_unchecked(\n bytes\n .by_ref()\n .map_while(Result::ok)\n .skip_while(|c| c.is_ascii_whitespace())\n .take_while(|c| !c.is_ascii_whitespace())\n .collect()\n )\n }\n };\n };\n\n (@inner $reader:ident) => {};\n (@inner $reader:ident, ) => {};\n\n (@inner $reader:ident, mut $var:ident : $t:tt $($r:tt)*) => {\n let mut $var = read_value!($reader, $t);\n input!{@inner $reader $($r)*}\n };\n\n (@inner $reader:ident, $var:ident : $t:tt $($r:tt)*) => {\n let $var = read_value!($reader, $t);\n input!{@inner $reader $($r)*}\n };\n\n (@inner $reader:ident $($r:tt)*) => {\n compile_error!(stringify!(unable to read $($r)*))\n };\n\n (line = $s:expr, $($r:tt)*) => {\n let mut iter = $s.split_ascii_whitespace();\n let mut next = || { iter.next().unwrap_or_default() };\n input!{@inner next, $($r)*}\n };\n (name = $reader:ident, $($r:tt)*) => {\n input!{@lock_stdin $reader};\n input!{@inner $reader, $($r)*}\n };\n (use $reader:ident, $($r:tt)*) => {\n input!{@inner $reader, $($r)*}\n };\n ($($r:tt)*) => {\n input!{@lock_stdin reader};\n input!{@inner reader, $($r)*};\n };\n}\n\n#[macro_export]\nmacro_rules! read_value {\n ($reader:ident, ( $($t:tt),* )) => {\n ( $(read_value!($reader, $t)),* )\n };\n\n ($reader:ident, [ $t:tt ]) => {{\n let len = read_value!($reader, usize);\n read_value!($reader, [ $t ; len])\n }};\n\n ($reader:ident, [ $t:tt ; $len:expr ]) => {\n (0..$len).map(|_| read_value!($reader, $t)).collect::>()\n };\n\n ($reader:ident, chars) => {\n read_value!($reader, String).chars().collect::>()\n };\n\n ($reader:ident, bytes) => {\n read_value!($reader, String).into_bytes()\n };\n\n ($reader:ident, usize1) => {\n read_value!($reader, usize) - 1\n };\n\n ($reader:ident, $t:tt) => {\n $reader().parse::<$t>().expect(stringify!(parse error($t)))\n };\n}\n\n//https://github.com/rust-lang-ja/ac-library-rs\n\npub mod internal_math {\n #![allow(dead_code)]\n use std::mem::swap;\n\n pub(crate) fn safe_mod(mut x: i64, m: i64) -> i64 {\n x %= m;\n if x < 0 {\n x += m;\n }\n x\n }\n\n pub(crate) struct Barrett {\n pub(crate) _m: u32,\n pub(crate) im: u64,\n }\n\n impl Barrett {\n pub(crate) fn new(m: u32) -> Barrett {\n Barrett {\n _m: m,\n im: (-1i64 as u64 / m as u64).wrapping_add(1),\n }\n }\n\n pub(crate) fn umod(&self) -> u32 {\n self._m\n }\n\n #[allow(clippy::many_single_char_names)]\n pub(crate) fn mul(&self, a: u32, b: u32) -> u32 {\n mul_mod(a, b, self._m, self.im)\n }\n }\n\n #[allow(clippy::many_single_char_names)]\n pub(crate) fn mul_mod(a: u32, b: u32, m: u32, im: u64) -> u32 {\n let mut z = a as u64;\n z *= b as u64;\n let x = (((z as u128) * (im as u128)) >> 64) as u64;\n let mut v = z.wrapping_sub(x.wrapping_mul(m as u64)) as u32;\n if m <= v {\n v = v.wrapping_add(m);\n }\n v\n }\n\n #[allow(clippy::many_single_char_names)]\n pub(crate) fn pow_mod(x: i64, mut n: i64, m: i32) -> i64 {\n if m == 1 {\n return 0;\n }\n let _m = m as u32;\n let mut r: u64 = 1;\n let mut y: u64 = safe_mod(x, m as i64) as u64;\n while n != 0 {\n if (n & 1) > 0 {\n r = (r * y) % (_m as u64);\n }\n y = (y * y) % (_m as u64);\n n >>= 1;\n }\n r as i64\n }\n\n pub(crate) fn is_prime(n: i32) -> bool {\n let n = n as i64;\n match n {\n _ if n <= 1 => return false,\n 2 | 7 | 61 => return true,\n _ if n % 2 == 0 => return false,\n _ => {}\n }\n let mut d = n - 1;\n while d % 2 == 0 {\n d /= 2;\n }\n for &a in &[2, 7, 61] {\n let mut t = d;\n let mut y = pow_mod(a, t, n as i32);\n while t != n - 1 && y != 1 && y != n - 1 {\n y = y * y % n;\n t <<= 1;\n }\n if y != n - 1 && t % 2 == 0 {\n return false;\n }\n }\n true\n }\n\n #[allow(clippy::many_single_char_names)]\n pub(crate) fn inv_gcd(a: i64, b: i64) -> (i64, i64) {\n let a = safe_mod(a, b);\n if a == 0 {\n return (b, 0);\n }\n\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; // |m1 * u| <= |m1| * s <= b\n\n swap(&mut s, &mut t);\n swap(&mut m0, &mut m1);\n }\n if m0 < 0 {\n m0 += b / s;\n }\n (s, m0)\n }\n\n pub(crate) fn primitive_root(m: i32) -> i32 {\n match m {\n 2 => return 1,\n 167_772_161 => return 3,\n 469_762_049 => return 3,\n 754_974_721 => return 11,\n 998_244_353 => return 3,\n _ => {}\n }\n\n let mut divs = [0; 20];\n divs[0] = 2;\n let mut cnt = 1;\n let mut x = (m - 1) / 2;\n while x % 2 == 0 {\n x /= 2;\n }\n for i in (3..std::i32::MAX).step_by(2) {\n if i as i64 * i as i64 > x as i64 {\n break;\n }\n if x % i == 0 {\n divs[cnt] = i;\n cnt += 1;\n while x % i == 0 {\n x /= i;\n }\n }\n }\n if x > 1 {\n divs[cnt] = x;\n cnt += 1;\n }\n let mut g = 2;\n loop {\n if (0..cnt).all(|i| pow_mod(g, ((m - 1) / divs[i]) as i64, m) != 1) {\n break g as i32;\n }\n g += 1;\n }\n }\n}\npub mod modint {\n\n use crate::internal_math;\n use std::{\n cell::RefCell,\n convert::{Infallible, TryInto as _},\n fmt,\n hash::{Hash, Hasher},\n iter::{Product, Sum},\n marker::PhantomData,\n ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign},\n str::FromStr,\n sync::atomic::{self, AtomicU32, AtomicU64},\n thread::LocalKey,\n };\n\n pub type ModInt1000000007 = StaticModInt;\n pub type ModInt998244353 = StaticModInt;\n pub type ModInt = DynamicModInt;\n\n #[derive(Copy, Clone, Eq, PartialEq)]\n #[repr(transparent)]\n pub struct StaticModInt {\n val: u32,\n phantom: PhantomData M>,\n }\n\n impl StaticModInt {\n #[inline(always)]\n pub fn modulus() -> u32 {\n M::VALUE\n }\n\n #[inline]\n pub fn new(val: T) -> Self {\n Self::raw(val.rem_euclid_u32(M::VALUE))\n }\n\n #[inline]\n pub fn raw(val: u32) -> Self {\n Self {\n val,\n phantom: PhantomData,\n }\n }\n\n #[inline]\n pub fn val(self) -> u32 {\n self.val\n }\n\n #[inline]\n pub fn pow(self, n: u64) -> Self {\n ::pow(self, n)\n }\n\n #[inline]\n pub fn inv(self) -> Self {\n if M::HINT_VALUE_IS_PRIME {\n if self.val() == 0 {\n panic!(\"attempt to divide by zero\");\n }\n debug_assert!(\n internal_math::is_prime(M::VALUE.try_into().unwrap()),\n \"{} is not a prime number\",\n M::VALUE,\n );\n self.pow((M::VALUE - 2).into())\n } else {\n Self::inv_for_non_prime_modulus(self)\n }\n }\n }\n\n impl ModIntBase for StaticModInt {\n #[inline(always)]\n fn modulus() -> u32 {\n Self::modulus()\n }\n\n #[inline]\n fn raw(val: u32) -> Self {\n Self::raw(val)\n }\n\n #[inline]\n fn val(self) -> u32 {\n self.val()\n }\n\n #[inline]\n fn inv(self) -> Self {\n self.inv()\n }\n }\n\n pub trait Modulus: 'static + Copy + Eq {\n const VALUE: u32;\n const HINT_VALUE_IS_PRIME: bool;\n\n fn butterfly_cache() -> &'static LocalKey>>>;\n }\n\n #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]\n pub enum Mod1000000007 {}\n\n impl Modulus for Mod1000000007 {\n const VALUE: u32 = 1_000_000_007;\n const HINT_VALUE_IS_PRIME: bool = true;\n\n fn butterfly_cache() -> &'static LocalKey>>> {\n thread_local! {\n static BUTTERFLY_CACHE: RefCell>> = RefCell::default();\n }\n &BUTTERFLY_CACHE\n }\n }\n\n #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]\n pub enum Mod998244353 {}\n\n impl Modulus for Mod998244353 {\n const VALUE: u32 = 998_244_353;\n const HINT_VALUE_IS_PRIME: bool = true;\n\n fn butterfly_cache() -> &'static LocalKey>>> {\n thread_local! {\n static BUTTERFLY_CACHE: RefCell>> = RefCell::default();\n }\n &BUTTERFLY_CACHE\n }\n }\n\n #[allow(dead_code)]\n pub struct ButterflyCache {\n pub(crate) sum_e: Vec>,\n pub(crate) sum_ie: Vec>,\n }\n\n #[derive(Copy, Clone, Eq, PartialEq)]\n #[repr(transparent)]\n pub struct DynamicModInt {\n val: u32,\n phantom: PhantomData I>,\n }\n\n impl DynamicModInt {\n #[inline]\n pub fn modulus() -> u32 {\n I::companion_barrett().umod()\n }\n\n #[inline]\n pub fn set_modulus(modulus: u32) {\n if modulus == 0 {\n panic!(\"the modulus must not be 0\");\n }\n I::companion_barrett().update(modulus);\n }\n\n #[inline]\n pub fn new(val: T) -> Self {\n ::new(val)\n }\n\n #[inline]\n pub fn raw(val: u32) -> Self {\n Self {\n val,\n phantom: PhantomData,\n }\n }\n\n #[inline]\n pub fn val(self) -> u32 {\n self.val\n }\n\n #[inline]\n pub fn pow(self, n: u64) -> Self {\n ::pow(self, n)\n }\n\n #[inline]\n pub fn inv(self) -> Self {\n Self::inv_for_non_prime_modulus(self)\n }\n }\n\n impl ModIntBase for DynamicModInt {\n #[inline]\n fn modulus() -> u32 {\n Self::modulus()\n }\n\n #[inline]\n fn raw(val: u32) -> Self {\n Self::raw(val)\n }\n\n #[inline]\n fn val(self) -> u32 {\n self.val()\n }\n\n #[inline]\n fn inv(self) -> Self {\n self.inv()\n }\n }\n\n pub trait Id: 'static + Copy + Eq {\n fn companion_barrett() -> &'static Barrett;\n }\n\n #[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]\n pub enum DefaultId {}\n\n impl Id for DefaultId {\n fn companion_barrett() -> &'static Barrett {\n static BARRETT: Barrett = Barrett::default();\n &BARRETT\n }\n }\n\n pub struct Barrett {\n m: AtomicU32,\n im: AtomicU64,\n }\n\n impl Barrett {\n #[inline]\n pub const fn new(m: u32) -> Self {\n Self {\n m: AtomicU32::new(m),\n im: AtomicU64::new((-1i64 as u64 / m as u64).wrapping_add(1)),\n }\n }\n\n #[inline]\n const fn default() -> Self {\n Self::new(998_244_353)\n }\n\n #[inline]\n fn update(&self, m: u32) {\n let im = (-1i64 as u64 / m as u64).wrapping_add(1);\n self.m.store(m, atomic::Ordering::SeqCst);\n self.im.store(im, atomic::Ordering::SeqCst);\n }\n\n #[inline]\n fn umod(&self) -> u32 {\n self.m.load(atomic::Ordering::SeqCst)\n }\n\n #[inline]\n fn mul(&self, a: u32, b: u32) -> u32 {\n let m = self.m.load(atomic::Ordering::SeqCst);\n let im = self.im.load(atomic::Ordering::SeqCst);\n internal_math::mul_mod(a, b, m, im)\n }\n }\n\n impl Default for Barrett {\n #[inline]\n fn default() -> Self {\n Self::default()\n }\n }\n\n pub trait ModIntBase:\n Default\n + FromStr\n + From\n + From\n + From\n + From\n + From\n + From\n + From\n + From\n + From\n + From\n + From\n + From\n + Copy\n + Eq\n + Hash\n + fmt::Display\n + fmt::Debug\n + Neg\n + Add\n + Sub\n + Mul\n + Div\n + AddAssign\n + SubAssign\n + MulAssign\n + DivAssign\n {\n fn modulus() -> u32;\n\n fn raw(val: u32) -> Self;\n\n fn val(self) -> u32;\n\n fn inv(self) -> Self;\n\n #[inline]\n fn new(val: T) -> Self {\n Self::raw(val.rem_euclid_u32(Self::modulus()))\n }\n\n #[inline]\n fn pow(self, mut n: u64) -> Self {\n let mut x = self;\n let mut r = Self::raw(1);\n while n > 0 {\n if n & 1 == 1 {\n r *= x;\n }\n x *= x;\n n >>= 1;\n }\n r\n }\n }\n\n pub trait RemEuclidU32 {\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\n trait InternalImplementations: ModIntBase {\n #[inline]\n fn inv_for_non_prime_modulus(this: Self) -> Self {\n let (gcd, x) = internal_math::inv_gcd(this.val().into(), Self::modulus().into());\n if gcd != 1 {\n panic!(\"the multiplicative inverse does not exist\");\n }\n Self::new(x)\n }\n\n #[inline]\n fn default_impl() -> Self {\n Self::raw(0)\n }\n\n #[inline]\n fn from_str_impl(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 #[inline]\n fn hash_impl(this: &Self, state: &mut impl Hasher) {\n this.val().hash(state)\n }\n\n #[inline]\n fn display_impl(this: &Self, f: &mut fmt::Formatter) -> fmt::Result {\n fmt::Display::fmt(&this.val(), f)\n }\n\n #[inline]\n fn debug_impl(this: &Self, f: &mut fmt::Formatter) -> fmt::Result {\n fmt::Debug::fmt(&this.val(), f)\n }\n\n #[inline]\n fn neg_impl(this: Self) -> Self {\n Self::sub_impl(Self::raw(0), this)\n }\n\n #[inline]\n fn add_impl(lhs: Self, rhs: Self) -> Self {\n let modulus = Self::modulus();\n let mut val = lhs.val() + rhs.val();\n if val >= modulus {\n val -= modulus;\n }\n Self::raw(val)\n }\n\n #[inline]\n fn sub_impl(lhs: Self, rhs: Self) -> Self {\n let modulus = Self::modulus();\n let mut val = lhs.val().wrapping_sub(rhs.val());\n if val >= modulus {\n val = val.wrapping_add(modulus)\n }\n Self::raw(val)\n }\n\n fn mul_impl(lhs: Self, rhs: Self) -> Self;\n\n #[inline]\n fn div_impl(lhs: Self, rhs: Self) -> Self {\n Self::mul_impl(lhs, rhs.inv())\n }\n }\n\n impl InternalImplementations for StaticModInt {\n #[inline]\n fn mul_impl(lhs: Self, rhs: Self) -> Self {\n Self::raw((u64::from(lhs.val()) * u64::from(rhs.val()) % u64::from(M::VALUE)) as u32)\n }\n }\n\n impl InternalImplementations for DynamicModInt {\n #[inline]\n fn mul_impl(lhs: Self, rhs: Self) -> Self {\n Self::raw(I::companion_barrett().mul(lhs.val, rhs.val))\n }\n }\n\n macro_rules! impl_basic_traits {\n () => {};\n (impl <$generic_param:ident : $generic_param_bound:tt> _ for $self:ty; $($rest:tt)*) => {\n impl <$generic_param: $generic_param_bound> Default for $self {\n #[inline]\n fn default() -> Self {\n Self::default_impl()\n }\n }\n\n impl <$generic_param: $generic_param_bound> FromStr for $self {\n type Err = Infallible;\n\n #[inline]\n fn from_str(s: &str) -> Result {\n Self::from_str_impl(s)\n }\n }\n\n impl<$generic_param: $generic_param_bound, V: RemEuclidU32> From for $self {\n #[inline]\n fn from(from: V) -> Self {\n Self::new(from)\n }\n }\n\n #[allow(clippy::derive_hash_xor_eq)]\n impl<$generic_param: $generic_param_bound> Hash for $self {\n #[inline]\n fn hash(&self, state: &mut H) {\n Self::hash_impl(self, state)\n }\n }\n\n impl<$generic_param: $generic_param_bound> fmt::Display for $self {\n #[inline]\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n Self::display_impl(self, f)\n }\n }\n\n impl<$generic_param: $generic_param_bound> fmt::Debug for $self {\n #[inline]\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n Self::debug_impl(self, f)\n }\n }\n\n impl<$generic_param: $generic_param_bound> Neg for $self {\n type Output = $self;\n\n #[inline]\n fn neg(self) -> $self {\n Self::neg_impl(self)\n }\n }\n\n impl<$generic_param: $generic_param_bound> Neg for &'_ $self {\n type Output = $self;\n\n #[inline]\n fn neg(self) -> $self {\n <$self>::neg_impl(*self)\n }\n }\n\n impl_basic_traits!($($rest)*);\n };\n}\n\n impl_basic_traits! {\n impl _ for StaticModInt ;\n impl _ for DynamicModInt;\n }\n\n macro_rules! impl_bin_ops {\n () => {};\n (for<$($generic_param:ident : $generic_param_bound:tt),*> <$lhs_ty:ty> ~ <$rhs_ty:ty> -> $output:ty { { $lhs_body:expr } ~ { $rhs_body:expr } } $($rest:tt)*) => {\n impl <$($generic_param: $generic_param_bound),*> Add<$rhs_ty> for $lhs_ty {\n type Output = $output;\n\n #[inline]\n fn add(self, rhs: $rhs_ty) -> $output {\n <$output>::add_impl(apply($lhs_body, self), apply($rhs_body, rhs))\n }\n }\n\n impl <$($generic_param: $generic_param_bound),*> Sub<$rhs_ty> for $lhs_ty {\n type Output = $output;\n\n #[inline]\n fn sub(self, rhs: $rhs_ty) -> $output {\n <$output>::sub_impl(apply($lhs_body, self), apply($rhs_body, rhs))\n }\n }\n\n impl <$($generic_param: $generic_param_bound),*> Mul<$rhs_ty> for $lhs_ty {\n type Output = $output;\n\n #[inline]\n fn mul(self, rhs: $rhs_ty) -> $output {\n <$output>::mul_impl(apply($lhs_body, self), apply($rhs_body, rhs))\n }\n }\n\n impl <$($generic_param: $generic_param_bound),*> Div<$rhs_ty> for $lhs_ty {\n type Output = $output;\n\n #[inline]\n fn div(self, rhs: $rhs_ty) -> $output {\n <$output>::div_impl(apply($lhs_body, self), apply($rhs_body, rhs))\n }\n }\n\n impl_bin_ops!($($rest)*);\n };\n}\n\n macro_rules! impl_assign_ops {\n () => {};\n (for<$($generic_param:ident : $generic_param_bound:tt),*> <$lhs_ty:ty> ~= <$rhs_ty:ty> { _ ~= { $rhs_body:expr } } $($rest:tt)*) => {\n impl <$($generic_param: $generic_param_bound),*> AddAssign<$rhs_ty> for $lhs_ty {\n #[inline]\n fn add_assign(&mut self, rhs: $rhs_ty) {\n *self = *self + apply($rhs_body, rhs);\n }\n }\n\n impl <$($generic_param: $generic_param_bound),*> SubAssign<$rhs_ty> for $lhs_ty {\n #[inline]\n fn sub_assign(&mut self, rhs: $rhs_ty) {\n *self = *self - apply($rhs_body, rhs);\n }\n }\n\n impl <$($generic_param: $generic_param_bound),*> MulAssign<$rhs_ty> for $lhs_ty {\n #[inline]\n fn mul_assign(&mut self, rhs: $rhs_ty) {\n *self = *self * apply($rhs_body, rhs);\n }\n }\n\n impl <$($generic_param: $generic_param_bound),*> DivAssign<$rhs_ty> for $lhs_ty {\n #[inline]\n fn div_assign(&mut self, rhs: $rhs_ty) {\n *self = *self / apply($rhs_body, rhs);\n }\n }\n\n impl_assign_ops!($($rest)*);\n };\n}\n\n #[inline]\n fn apply O, X, O>(f: F, x: X) -> O {\n f(x)\n }\n\n impl_bin_ops! {\n for > ~ > -> StaticModInt { { |x| x } ~ { |x| x } }\n for > ~ <&'_ StaticModInt > -> StaticModInt { { |x| x } ~ { |&x| x } }\n for <&'_ StaticModInt > ~ > -> StaticModInt { { |&x| x } ~ { |x| x } }\n for <&'_ StaticModInt > ~ <&'_ StaticModInt > -> StaticModInt { { |&x| x } ~ { |&x| x } }\n for > ~ > -> DynamicModInt { { |x| x } ~ { |x| x } }\n for > ~ <&'_ DynamicModInt> -> DynamicModInt { { |x| x } ~ { |&x| x } }\n for <&'_ DynamicModInt> ~ > -> DynamicModInt { { |&x| x } ~ { |x| x } }\n for <&'_ DynamicModInt> ~ <&'_ DynamicModInt> -> DynamicModInt { { |&x| x } ~ { |&x| x } }\n\n for > ~ -> StaticModInt { { |x| x } ~ { StaticModInt::::new } }\n for > ~ -> DynamicModInt { { |x| x } ~ { DynamicModInt::::new } }\n }\n\n impl_assign_ops! {\n for > ~= > { _ ~= { |x| x } }\n for > ~= <&'_ StaticModInt > { _ ~= { |&x| x } }\n for > ~= > { _ ~= { |x| x } }\n for > ~= <&'_ DynamicModInt> { _ ~= { |&x| x } }\n\n for > ~= { _ ~= { StaticModInt::::new } }\n for > ~= { _ ~= { DynamicModInt::::new } }\n }\n\n macro_rules! impl_folding {\n () => {};\n (impl<$generic_param:ident : $generic_param_bound:tt> $trait:ident<_> for $self:ty { fn $method:ident(_) -> _ { _($unit:expr, $op:expr) } } $($rest:tt)*) => {\n impl<$generic_param: $generic_param_bound> $trait for $self {\n #[inline]\n fn $method(iter: S) -> Self\n where\n S: Iterator,\n {\n iter.fold($unit, $op)\n }\n }\n\n impl<'a, $generic_param: $generic_param_bound> $trait<&'a Self> for $self {\n #[inline]\n fn $method(iter: S) -> Self\n where\n S: Iterator,\n {\n iter.fold($unit, $op)\n }\n }\n\n impl_folding!($($rest)*);\n };\n}\n\n impl_folding! {\n impl Sum<_> for StaticModInt { fn sum(_) -> _ { _(Self::raw(0), Add::add) } }\n impl Product<_> for StaticModInt { fn product(_) -> _ { _(Self::raw(1), Mul::mul) } }\n impl Sum<_> for DynamicModInt { fn sum(_) -> _ { _(Self::raw(0), Add::add) } }\n impl Product<_> for DynamicModInt { fn product(_) -> _ { _(Self::raw(1), Mul::mul) } }\n }\n}\nuse modint::*;\n\n"}, {"source_code": "#![allow(dead_code, unused_imports)]\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, } #[derive(Debug, Clone)] pub struct Format<'a> { separator: &'a str, ending: &'a str, } impl<'a> Format<'a> { pub fn separator(self, separator: &'a str) -> Self { Self { separator, ..self } } pub fn ending(self, ending: &'a str) -> Self { Self { ending, ..self } } } impl Default for Format<'_> { fn default() -> Self { Format { separator: \" \", ending: \"\\n\", } } } 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> { self.write_with(val, &Format::default()) } pub fn write_with>(&mut self, val: T, fmt: &Format) -> Result<(), IoError> { val.write_to(&mut self.writer, fmt) } pub fn flush(&mut self) -> Result<(), IoError> { self.writer.flush() } } pub trait Writable { fn write_to(self, w: &mut W, fmt: &Format) -> Result<(), IoError>;} #[non_exhaustive] pub struct Single;impl Writable for T { fn write_to(self, w: &mut W, fmt: &Format) -> Result<(), IoError> { write!(w, \"{}{}\", self, fmt.ending) } } #[non_exhaustive] pub struct Many;impl Writable for I where I: Iterator, I::Item: Display, { fn write_to(mut self, w: &mut W, fmt: &Format) -> Result<(), IoError> { if let Some(x) = self.next() { write!(w, \"{}\", x)?;} else { return Ok(());} for x in self { write!(w, \"{}{}\", fmt.separator, x)?;} write!(w, \"{}\", fmt.ending) } } #[non_exhaustive] pub struct Slice;impl Writable for &[T] { fn write_to(self, w: &mut W, fmt: &Format) -> Result<(), IoError> { self.iter().write_to(w, fmt) } } #[macro_export] macro_rules! out { ($writer:expr, $val:expr) => { $writer.write($val).expect(\"failed to write token\");};($writer:expr, $val:expr, $($builder_name:ident = $value:expr),+) => { let mut fmt = Format::default();$( fmt = fmt.$builder_name($value);)+ $writer.write_with($val, &fmt).expect(\"failed to write token\");};} }\n#[rustfmt::skip] mod scanner {use std::fmt::Debug;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, } pub trait Instructions { type Target;type Error;fn read_from(scanner: &mut Scanner) -> Result;} impl Instructions for T { type Target = T;type Error = ScanError;fn read_from(scanner: &mut Scanner) -> Result { scanner.read_token() } } #[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(), } } pub fn read_token(&mut self) -> Result> { debug_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 } } } pub fn read(&mut self) -> Result { T::read_from(self) } } #[macro_use] pub mod macros { use super::*;use std::fmt::{self, Debug};use std::io::Read;use std::marker::PhantomData;use std::num::NonZeroUsize;use std::str::FromStr;pub struct UsizeM1(());impl Instructions for UsizeM1 { type Target = usize;type Error = ScanError;fn read_from(scanner: &mut Scanner) -> Result { Ok(scanner.read_token::()?.get() - 1) } } pub struct LenArray(PhantomData);impl Instructions for LenArray { type Target = Vec;type Error = LenArrayScanError;fn read_from(scanner: &mut Scanner) -> Result { let len = scanner .read_token::() .map_err(LenArrayScanError::Len)?;let mut arr = Vec::with_capacity(len);for i in 0..len { let elem = scanner .read_token::() .map_err(|e| LenArrayScanError::Data(i, e))?;arr.push(elem);} Ok(arr) } } pub enum LenArrayScanError { Len(ScanError), Data(usize, ScanError), } impl Debug for LenArrayScanError where T: Debug + FromStr, T::Err: Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use self::LenArrayScanError::*;match self { Len(e) => f.debug_tuple(\"Len\").field(e).finish(), Data(i, e) => f.debug_tuple(\"Data\").field(i).field(e).finish(), } } } #[macro_export] macro_rules! scan { (@scan 1 $scan:expr, $type:ty) => { $scan .read::<$type>() .expect(concat!(\"failed to read token of type \", stringify!($type))) };(@scan 2 $scan:expr, $type:ty, $n:expr) => { (0..$n) .map(|_| scan!(@scan 1 $scan, $type)) .collect::>() };(@accum ($scan:expr) () -> ($($body:tt)*)) => { ($($body)*) };(@accum ($scan:expr) ($type:ty) -> ($($body:tt)*)) => { scan!(@accum ($scan) () -> ($($body)* scan!(@scan 1 $scan, $type))) };(@accum ($scan:expr) ($type:ty, $($next:tt)*) -> ($($body:tt)*)) => { scan!(@accum ($scan) ($($next)*) -> ($($body)* scan!(@scan 1 $scan, $type),)) };(@accum ($scan:expr) ($n:tt * $type:ty) -> ($($body:tt)*)) => { scan!(@accum ($scan) () -> ($($body)* scan!(@scan 2 $scan, $type, $n))) };(@accum ($scan:expr) ($n:tt * $type:ty, $($next:tt)*) -> ($($body:tt)*)) => { scan!(@accum ($scan) ($($next)*) -> ($($body)* scan!(@scan 2 $scan, $type, $n),)) };($scan:expr, $($arg:tt)+) => { scan!(@accum ($scan) ($($arg)+) -> ()) };} } }\n#[rustfmt::skip] mod util { use std::cmp::Reverse; 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;fn argmin(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) } fn argmin(self) -> Option { self.map(Reverse).argmax() } } pub trait Sorted { fn sorted(self) -> Self;} impl Sorted for Vec where T: Ord, { fn sorted(mut self) -> Self { self.sort();self } } pub trait SortedBy { fn sorted_by(self, f: F) -> Self where F: FnMut(&T) -> K, K: Ord;} impl SortedBy for Vec { fn sorted_by(mut self, f: F) -> Self where F: FnMut(&T) -> K, K: Ord, { self.sort_by_key(f);self } } pub trait Choose { fn choose(self, a: T, b: T) -> T;fn choose_by(self, a: impl FnOnce() -> T, b: impl FnOnce() -> T) -> T;} impl Choose for bool { fn choose(self, a: T, b: T) -> T { if self { a } else { b } } fn choose_by(self, a: impl FnOnce() -> T, b: impl FnOnce() -> T) -> T { if self { a() } else { b() } } } #[macro_export] macro_rules! p { ( $( $x:expr ),* ) => { #[cfg(any(debug_assertions, debug_print))] { dbg!( $( & $x, )* );} };} pub fn fix(f: &dyn Fn(&dyn Fn(A) -> R, A) -> R) -> impl Fn(A) -> R + '_ { move |arg| f(&fix(&f), arg) } pub trait Assign { fn assign(&mut self, val: T);} impl Assign for Option { fn assign(&mut self, val: T) { assert!(self.is_none(), \".assign() called on Some variant\");*self = Some(val);} } }\n#[rustfmt::skip] mod prefix_sum {use std::{ fmt::{self, Debug, Formatter}, marker::PhantomData, ops::{Add, Bound, Range, RangeBounds, Sub}, };#[derive(Clone)] pub struct PrefixOp { fwd: F, inv: Option, marker: PhantomData T>, } impl PrefixOp where F: Fn(&T, &T) -> T, { pub fn new(op: F) -> Self { PrefixOp { fwd: op, inv: None, marker: PhantomData, } } } impl PrefixOp where F: Fn(&T, &T) -> T, I: Fn(&T, &T) -> T, { pub fn new_invertible(op: F, inverse: I) -> Self { PrefixOp { fwd: op, inv: Some(inverse), marker: PhantomData, } } } impl PrefixOp where F: Fn(&T, &T) -> T, I: Clone, { pub fn build(&self, mut arr: Vec) -> PrefixArray { for i in 1..arr.len() { arr[i] = (self.fwd)(&arr[i - 1], &arr[i]);} PrefixArray { pref: arr, fwd: PhantomData, inv: self.inv.clone(), } } } #[derive(Clone)] pub struct PrefixArray { pref: Vec, fwd: PhantomData, inv: Option, } impl PrefixArray { pub fn len(&self) -> usize { self.pref.len() } pub fn is_empty(&self) -> bool { self.pref.is_empty() } #[track_caller] fn verify_range_bounds(&self, range: impl RangeBounds) -> Range { let start = match range.start_bound() { Bound::Unbounded => 0, Bound::Included(&x) => x, Bound::Excluded(&x) => x + 1, };let end = match range.end_bound() { Bound::Unbounded => self.len(), Bound::Included(&x) => x + 1, Bound::Excluded(&x) => x, };assert!( start < end, \"range inverted: start >= end ({} >= {})\", start, end );assert!( end <= self.len(), \"range out of bounds: end > len ({} > {})\", end, self.len() );Range { start, end } } #[track_caller] pub fn query_prefix(&self, range: impl RangeBounds) -> T where T: Clone, { let Range { start, end } = self.verify_range_bounds(range);assert!(start == 0, \"query start bound is non-zero: {} > 0\", start);self.pref[end - 1].clone() } } impl PrefixArray where I: Fn(&T, &T) -> T, { #[track_caller] pub fn query(&self, range: impl RangeBounds) -> T where T: Clone, { let Range { start, end } = self.verify_range_bounds(range);if start == 0 { self.pref[end - 1].clone() } else { (self .inv .as_ref() .expect(\"range query is not supported on non-invertible operation\"))( &self.pref[end - 1], &self.pref[start - 1], ) } } } impl Debug for PrefixOp where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct(\"PrefixOp\").finish_non_exhaustive() } } impl Debug for PrefixArray where T: Debug, { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct(\"PrefixArray\") .field(\"pref\", &self.pref) .finish_non_exhaustive() } } type NextFn = fn(&T, &T) -> T;pub struct PrefixSum(PhantomData);impl PrefixSum where T: Add + Sub + Clone, { pub fn op() -> PrefixOp, NextFn> { PrefixOp::new_invertible(|a, b| a.clone() + b.clone(), |b, a| b.clone() - a.clone()) } pub fn build(arr: Vec) -> PrefixArray, NextFn> { Self::op().build(arr) } } }\n#[rustfmt::skip] mod combinatorics {use crate::{num::Integer, number_theory::mod_mulinv};pub fn next_permutation(perm: &mut [T]) -> bool where T: Ord, { if perm.is_empty() { return false;} let i = match Iterator::zip(perm.iter(), perm[1..].iter()).rposition(|(x, y)| x < y) { None => { perm.reverse();return false;} Some(x) => x, };let j = perm .iter() .rposition(|x| &perm[i] < x) .expect(\"inconsistent Ord implementation\");perm.swap(i, j);perm[i + 1..].reverse();true } #[derive(Debug, Clone)] pub struct Factorials { m: N, fact: Vec, fact_inv: Vec, } impl Factorials where N: Integer + Clone, { #[inline] fn as_n(x: usize) -> N { N::from_usize(x).expect(\"inconsistent Integer implementation\") } #[inline] fn as_usize(x: &N) -> usize { N::as_usize(x).expect(\"inconsistent Integer implementation\") } #[track_caller] pub fn new(n: N, m: N) -> Self { let cap = n .as_usize() .and_then(|x| x.checked_add(1)) .expect(\"required capacity overflowed usize\");assert!(cap > 0, \"n must be non-negative\");let mut fact = Vec::with_capacity(cap);fact.push(N::one());let mut cur = N::one();for i in 1..cap { cur = (cur * Self::as_n(i)).imod(&m);fact.push(cur.clone());} let mut fact_inv = Vec::with_capacity(cap);let mut cur = mod_mulinv(fact[cap - 1].clone(), m.clone());for i in (0..cap).rev() { fact_inv.push(cur.clone());cur = (cur * Self::as_n(i)).imod(&m);} fact_inv.reverse();debug_assert_eq!(fact.len(), cap);debug_assert_eq!(fact_inv.len(), cap);Factorials { m, fact, fact_inv } } pub fn len(&self) -> usize { self.fact.len() } pub fn is_empty(&self) -> bool { false } pub fn n(&self) -> N { Self::as_n(self.fact.len() - 1) } #[track_caller] fn verify_n<'a>(&self, n: &'a N) -> &'a N { assert!( N::zero() <= *n && *n <= self.n(), \"n is outside precomputed range\" );n } #[track_caller] pub fn factorial(&self, n: &N) -> N { let n = self.verify_n(n);self.fact[Self::as_usize(n)].clone() } #[track_caller] pub fn factorial_inverse(&self, n: &N) -> N { let n = self.verify_n(n);self.fact_inv[Self::as_usize(n)].clone() } #[track_caller] pub fn choose(&self, n: N, k: N) -> N { self.verify_n(&n);assert!(k >= N::zero(), \"k is negative\");if k <= n { ((self.fact[Self::as_usize(&n)].clone() * self.fact_inv[Self::as_usize(&k)].clone()) .imod(&self.m) * self.fact_inv[Self::as_usize(&(n - k))].clone()) .imod(&self.m) } else { N::zero() } } } }\n#[rustfmt::skip] mod number_theory {use crate::num::Integer;use std::mem;pub fn gcd(mut a: N, mut b: N) -> N { while b != N::zero() { mem::swap(&mut a, &mut b);b = b.imod(&a);} a.iabs() } #[allow(clippy::many_single_char_names)] pub fn egcd(a: N, b: N) -> (N, N, N) { if b == N::zero() { ( a.iabs(), if a >= N::zero() { N::one() } else { N::zero() - N::one() }, N::zero(), ) } else { let (g, s, t) = egcd(b.clone(), a.imod(&b));(g, t.clone(), s - a.idiv(&b) * t) } } #[track_caller] pub fn mod_exp(a: N, mut b: N, m: N) -> N { let zero = N::zero();let one = N::one();let two = N::one() + N::one();assert!(m > zero, \"modulus must be positive\");if b < zero { return mod_exp(mod_mulinv(a, m.clone()), zero - b, m);} let mut x = N::one();let mut pwr = a;while b > N::zero() { if b.imod(&two) == one { x = (x * pwr.clone()).imod(&m);} pwr = (pwr.clone() * pwr).imod(&m);b = b.idiv(&two);} x } #[track_caller] pub fn mod_mulinv(a: N, m: N) -> N { let zero = N::zero();let one = N::one();assert!(m > zero, \"modulus must be positive\");let (g, s, _) = egcd(a, m.clone());assert!(g == one, \"multiplicative inverse does not exist\");s.imod(&m) } #[derive(Debug, Clone)] pub struct PrimeSieve { lowest_factor: Vec, primes: Vec, } impl PrimeSieve where N: Integer + Clone, { #[inline] fn as_n(x: usize) -> N { N::from_usize(x).expect(\"inconsistent Integer implementation\") } #[inline] fn as_usize(x: &N) -> usize { N::as_usize(x).expect(\"inconsistent Integer implementation\") } #[track_caller] pub fn new(n: N) -> Self { let cap = n .as_usize() .and_then(|x| x.checked_add(1)) .expect(\"capacity overflowed usize\");assert!(cap > 0, \"n must be non-negative\");let mut lowest_factor = vec![N::zero(); cap];let mut primes = vec![];for i in 2..cap { if lowest_factor[i] == N::zero() { lowest_factor[i] = Self::as_n(i);primes.push(Self::as_n(i));} let lowest_factor_i = lowest_factor[i].clone();for (p, p_usize) in primes .iter() .map(|p| (p, Self::as_usize(p))) .take_while(|(p, p_usize)| i * p_usize < cap && p <= &&lowest_factor_i) { lowest_factor[i * p_usize] = p.clone();} } PrimeSieve { lowest_factor, primes, } } pub fn len(&self) -> usize { self.lowest_factor.len() } pub fn is_empty(&self) -> bool { false } pub fn n(&self) -> N { Self::as_n(self.lowest_factor.len() - 1) } #[track_caller] pub fn is_prime(&self, x: &N) -> bool { assert!(*x >= N::zero(), \"x must be non-negative\");let n = self.n();if *x <= n { *x > N::zero() && self.lowest_factor[Self::as_usize(x)] == *x } else if *x <= n.clone() * n { for p in self.primes.iter() { if x.imod(p) == N::zero() { return false;} } true } else { panic!(\"unable to determine primality: x > n^2\");} } #[track_caller] pub fn lowest_factor(&self, x: &N) -> N { assert!(*x >= N::zero(), \"x must be non-negative\");let n = self.n();if *x <= n { self.lowest_factor[Self::as_usize(x)].clone() } else if *x <= n.clone() * n { for p in self .primes .iter() .take_while(|&p| p.clone() * p.clone() <= *x) { if x.imod(p) == N::zero() { return p.clone();} } x.clone() } else { panic!(\"unable to determine lowest factor: x > n^2\",) } } #[track_caller] pub fn factorize(&self, mut x: N) -> Vec { let n = self.n();assert!(x > N::zero(), \"cannot factorize non-positive numbers\");assert!(x <= n.clone() * n.clone(), \"unable to factorize: x > n^2\",);let mut factors = Vec::new();let x2 = x.clone();let mut primes = self .primes .iter() .take_while(|&p| p.clone() * p.clone() <= x2);while x > N::one() { if x <= n { let f = &self.lowest_factor[Self::as_usize(&x)];factors.push(f.clone());x = x.idiv(f);} else if let Some(p) = primes.next() { while x.imod(p) == N::zero() { factors.push(p.clone());x = x.idiv(p);} } else { factors.push(x);break;} } factors } } }\n#[rustfmt::skip] mod num {use std::convert::{TryFrom, TryInto};use std::ops::{Add, Div, Mul, Rem, Sub};pub trait Num: Ord + Add + Sub + Mul + Div + Rem + FromPrimitive + IntoPrimitive + Sized { fn zero() -> Self;fn one() -> Self;} pub trait FromPrimitive: Sized { fn from_u64(x: u64) -> Option;fn from_i64(x: i64) -> Option;fn from_usize(x: usize) -> Option { Self::from_u64(x as u64) } fn from_isize(x: isize) -> Option { Self::from_i64(x as i64) } } pub trait IntoPrimitive { fn as_u64(&self) -> Option;fn as_i64(&self) -> Option;fn as_usize(&self) -> Option { self.as_u64().and_then(|x| x.try_into().ok()) } fn as_isize(&self) -> Option { self.as_i64().and_then(|x| x.try_into().ok()) } } pub trait Integer: Num { fn idiv(&self, x: &Self) -> Self;fn imod(&self, x: &Self) -> Self;fn iabs(&self) -> Self;} macro_rules! generate_integer_impl_for_primitive { ($( ($ty:ty, $unsigned:tt) ),+) => { $( impl FromPrimitive for $ty { #[inline(always)] fn from_u64(x: u64) -> Option { <$ty>::try_from(x).ok() } #[inline(always)] fn from_i64(x: i64) -> Option { <$ty>::try_from(x).ok() } } impl IntoPrimitive for $ty { #[inline(always)] fn as_u64(&self) -> Option { u64::try_from(*self).ok() } #[inline(always)] fn as_i64(&self) -> Option { i64::try_from(*self).ok() } } impl Num for $ty { #[inline(always)] fn zero() -> Self { 0 } #[inline(always)] fn one() -> Self { 1 } } impl Integer for $ty { #[inline(always)] fn idiv(&self, x: &Self) -> Self { self.div_euclid(*x) } #[inline(always)] fn imod(&self, x: &Self) -> Self { self.rem_euclid(*x) } generate_iabs_impl!($unsigned);} )+ };} macro_rules! generate_iabs_impl { (true) => { #[inline(always)] fn iabs(&self) -> Self { *self } };(false) => { #[inline(always)] fn iabs(&self) -> Self { self.abs() } };} generate_integer_impl_for_primitive!( (u8, true), (u16, true), (u32, true), (u64, true), (u128, true), (usize, true), (i8, false), (i16, false), (i32, false), (i64, false), (i128, false), (isize, false) );}\n\nuse combinatorics::{next_permutation, Factorials};\nuse number_theory::{egcd, gcd, mod_exp, mod_mulinv, PrimeSieve};\nuse prefix_sum::{PrefixOp, PrefixSum};\nuse scanner::{\n macros::{LenArray, UsizeM1},\n Scanner,\n};\nuse util::{fix, Argmax, Assign, Choose, IntoVec, Sorted};\nuse writer::{Format, Writer};\n\nfn main() {\n let mut sc = Scanner::stdin();\n let mut wr = Writer::stdout();\n\n let (n, k) = scan!(sc, i64, i64);\n const MOD: i64 = 1_000_000_007;\n let fact = Factorials::new(n, MOD);\n let mut ans = 0;\n for i in 0..=i64::min(n, k) {\n ans = (ans + fact.choose(n, i)) % MOD;\n }\n out!(wr, ans);\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::{\n cmp,\n collections::{BinaryHeap, HashMap, HashSet, VecDeque},\n hash::Hash,\n io::{self, BufWriter, Read, StdoutLock, Write},\n str::Lines,\n};\n\nconst MODVAL: u64 = 1e9 as u64 + 7;\n\n#[allow(unused_mut, unused_variables)]\nfn main() -> io::Result<()> {\n let mut input = String::new();\n io::stdin().lock().read_to_string(&mut input).unwrap();\n let mut input = input.lines();\n\n let out = io::stdout();\n let mut out = BufWriter::new(out.lock());\n\n let line = next_line_as_u64_vec(&mut input);\n let n = line[0];\n let k = line[1];\n\n let mut m = 1;\n let fact = FactorialsMod::new(n as usize, MODVAL);\n for k in 1..=cmp::min(n, k) {\n m += bi_coefficient_mod(n, k, &fact, MODVAL);\n }\n writeln!(out, \"{}\", m % MODVAL)?;\n\n Ok(())\n}\n\n#[allow(dead_code)]\nfn bi_coefficient_mod(n: u64, k: u64, fact: &FactorialsMod, modval: u64) -> u64 {\n if n == k {\n return 1;\n }\n let mut res = fact.get(n as usize).unwrap();\n res *= mod_inverse(fact.get(k as usize).unwrap(), modval);\n res %= modval;\n res *= mod_inverse(fact.get((n - k) as usize).unwrap(), modval);\n res %= modval;\n res\n}\n\n#[allow(dead_code)]\nfn pow_mod(a: u64, b: u64, modval: u64) -> u64 {\n let mut a = a % modval;\n if a == 0 {\n return 0;\n }\n let mut b = b;\n let mut res = 1u64;\n while b > 0 {\n if b & 1 != 0 {\n res *= a;\n res %= modval;\n b -= 1;\n }\n a *= a;\n a %= modval;\n b >>= 1;\n }\n res\n}\n\n#[allow(dead_code)]\nfn mod_inverse(a: u64, modval: u64) -> u64 {\n pow_mod(a, modval - 2, modval)\n}\n\n#[derive(Debug, Clone)]\nstruct FactorialsMod {\n numbers: Vec,\n}\n\n#[allow(dead_code)]\nimpl FactorialsMod {\n fn new(n: usize, modval: u64) -> Self {\n let mut numbers = vec![0; n + 1];\n let mut fac = 1u64;\n for i in 1..=n {\n fac *= i as u64;\n fac %= modval;\n numbers[i] = fac;\n }\n FactorialsMod { numbers }\n }\n\n fn get(&self, n: usize) -> Option {\n self.numbers.get(n).map(|&x| x)\n }\n}\n\n#[allow(dead_code)]\nfn next_line(input: &mut Lines) -> String {\n input.next().unwrap().to_string()\n}\n\n#[allow(dead_code)]\nfn next_line_as_u64(input: &mut Lines) -> u64 {\n let s = input.next().unwrap();\n let n: u64 = s.parse().unwrap();\n n\n}\n\n#[allow(dead_code)]\nfn next_line_as_i64(input: &mut Lines) -> i64 {\n let s = input.next().unwrap();\n let n: i64 = s.parse().unwrap();\n n\n}\n\n#[allow(dead_code)]\nfn next_line_as_string_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a = s.split(\" \").collect::>();\n a.iter().map(|&s| s.to_string()).collect()\n}\n\n#[allow(dead_code)]\nfn next_line_as_char_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.chars().collect();\n a\n}\n\n#[allow(dead_code)]\nfn next_line_as_u64_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.split(\" \").map(|s| s.parse().unwrap()).collect();\n a\n}\n\n#[allow(dead_code)]\nfn next_line_as_i64_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.split(\" \").map(|s| s.parse().unwrap()).collect();\n a\n}\n\n#[allow(dead_code)]\nfn write_bool_answer(answer: bool, out: &mut BufWriter) {\n if answer {\n writeln!(out, \"yes\").unwrap();\n } else {\n writeln!(out, \"no\").unwrap();\n }\n}\n"}, {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::cell::RefCell;\nuse std::cmp::Ordering;\nuse std::collections::*;\nuse std::error::Error;\nuse std::fmt::write;\nuse std::hash::Hash;\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::StdinLock;\nuse std::io::StdoutLock;\nuse std::io::Write;\nuse std::io::{stdin, stdout, BufRead, BufWriter};\nuse std::ops::Add;\nuse std::thread::panicking;\n\nmacro_rules! fprintvec {\n ($dst:expr, $arg:expr) => {{\n writeln!(\n $dst,\n \"{}\",\n $arg.iter()\n .map(|x| format!(\"{} \", x))\n .collect::>()\n .join(\"\")\n )\n .ok();\n }};\n}\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 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_whitespace())\n }\n }\n }\n\n pub fn next_split(&mut self) -> Vec {\n loop {\n let mut v = Vec::new();\n while let Some(token) = self.buf_iter.next() {\n v.push(token.parse().ok().expect(\"Failed parse\"));\n }\n if v.len() > 0 {\n return v;\n }\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_whitespace())\n }\n }\n }\n}\n\nfn lcm(first: usize, second: usize) -> usize {\n first * second / gcd(first, second)\n}\n\nfn gcd(first: usize, second: usize) -> usize {\n let mut max = first;\n let mut min = second;\n if min > max {\n let val = max;\n max = min;\n min = val;\n }\n\n loop {\n let res = max % min;\n if res == 0 {\n return min;\n }\n\n max = min;\n min = res;\n }\n}\n\n//let fmc = ModMath::::new(CACHE_SIZE);\n//let fmc = ModMath::<1000000007>::new(100005);\n\n#[derive(Clone, Default, Debug)]\nstruct ModMath {\n fact: Vec,\n inv: Vec,\n fact_cache_size: i64,\n}\n\nimpl ModMath {\n fn new(fact_cache_size: usize) -> ModMath {\n let mut fmc = ModMath {\n ..Default::default()\n };\n fmc.fact.resize(fact_cache_size, 0);\n fmc.inv.resize(fact_cache_size, 0);\n fmc.fact[0] = 1;\n fmc.inv[0] = 1;\n fmc.fact_cache_size = fact_cache_size as i64; //set this after so the calculation doesn't return cached value\n for i in 1..fact_cache_size {\n fmc.fact[i] = fmc.mult_mod(fmc.fact[i - 1], i as i64);\n fmc.inv[i] = fmc.inv_mod(fmc.fact[i]);\n }\n fmc\n }\n\n fn factorial_mod(&self, n: i64) -> i64 {\n if n < self.fact_cache_size {\n return self.fact[n as usize];\n }\n let mut t = self.fact[self.fact_cache_size as usize - 1];\n for x in self.fact_cache_size..=n {\n t = (t * x) % MODVAL;\n }\n t\n }\n\n fn permutations_mod(&self, n: i64, r: i64) -> i64 {\n let a = self.factorial_mod(n);\n let b = self.inv_fact_mod(n - r);\n return self.mult_mod(a, b);\n }\n\n fn inv_fact_mod(&self, n: i64) -> i64 {\n if n < self.fact_cache_size {\n return self.inv[n as usize];\n }\n self.pow_mod(self.factorial_mod(n), MODVAL - 2)\n }\n\n fn inv_mod(&self, n: i64) -> i64 {\n self.pow_mod(n, MODVAL - 2)\n }\n\n fn combinations_mod(&self, n: i64, r: i64) -> i64 {\n let a = self.factorial_mod(n);\n let b = self.inv_fact_mod(r);\n let c = self.inv_fact_mod(n - r);\n return self.mult_mod(self.mult_mod(a, b), c);\n }\n\n fn pow_mod(&self, mut base: i64, mut pow: i64) -> i64 {\n if pow == 0 {\n return 1;\n }\n let mut result = 1;\n while pow > 0 {\n if pow & 1 == 1 {\n result = (result * base) % MODVAL;\n }\n pow /= 2;\n base = (base * base) % MODVAL;\n }\n result\n }\n\n fn mult_mod(&self, a: i64, b: i64) -> i64 {\n let a = a as i128;\n let b = b as i128;\n ((a * b) % MODVAL as i128) as i64\n }\n\n fn add_mod(&self, a: i64, b: i64) -> i64 {\n ((a % MODVAL) + (b % MODVAL)) % MODVAL\n }\n}\n\nfn main() -> Result<(), Box> {\n let stdout = io::stdout();\n let lock = stdout.lock();\n let stdin = io::stdin();\n let mut ow = io::BufWriter::new(lock);\n let mut scan = Scanner::new(stdin.lock());\n\n // let n_tests = scan.next::();\n let n_tests = 1;\n let fmc = ModMath::<1000000007>::new(100005);\n for t_num in 1..=n_tests {\n let n = scan.next::();\n let k = scan.next::();\n\n let mut start = 1;\n\n for i in 1..=(std::cmp::min(n, k)) {\n start = fmc.add_mod(start, fmc.combinations_mod(n as i64, i as i64));\n }\n\n writeln!(ow, \"{}\", start);\n }\n Ok(())\n}\n"}, {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::cell::RefCell;\nuse std::cmp::Ordering;\nuse std::collections::*;\nuse std::error::Error;\nuse std::fmt::write;\nuse std::hash::Hash;\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::StdinLock;\nuse std::io::StdoutLock;\nuse std::io::Write;\nuse std::io::{stdin, stdout, BufRead, BufWriter};\nuse std::ops::Add;\nuse std::thread::panicking;\n\nmacro_rules! fprintvec {\n ($dst:expr, $arg:expr) => {{\n writeln!(\n $dst,\n \"{}\",\n $arg.iter()\n .map(|x| format!(\"{} \", x))\n .collect::>()\n .join(\"\")\n )\n .ok();\n }};\n}\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 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_whitespace())\n }\n }\n }\n\n pub fn next_split(&mut self) -> Vec {\n loop {\n let mut v = Vec::new();\n while let Some(token) = self.buf_iter.next() {\n v.push(token.parse().ok().expect(\"Failed parse\"));\n }\n if v.len() > 0 {\n return v;\n }\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_whitespace())\n }\n }\n }\n}\n\nfn lcm(first: usize, second: usize) -> usize {\n first * second / gcd(first, second)\n}\n\nfn gcd(first: usize, second: usize) -> usize {\n let mut max = first;\n let mut min = second;\n if min > max {\n let val = max;\n max = min;\n min = val;\n }\n\n loop {\n let res = max % min;\n if res == 0 {\n return min;\n }\n\n max = min;\n min = res;\n }\n}\n#[derive(Clone, Default, Debug)]\nstruct FactModCache {\n fact: Vec,\n inv: Vec,\n n: i64,\n}\n\nimpl FactModCache {\n fn new(n: usize) -> FactModCache {\n let mut fmc = FactModCache {\n ..Default::default()\n };\n fmc.fact.resize(n, 0);\n fmc.inv.resize(n, 0);\n fmc.fact[0] = 1;\n fmc.inv[0] = 1;\n fmc.n = n as i64; //set this after so the calculation doesn't return cached value\n for i in 1..n {\n fmc.fact[i] = fmc.mult_mod(fmc.fact[i - 1], i as i64);\n fmc.inv[i] = fmc.inv_mod(fmc.fact[i]);\n }\n fmc\n }\n\n fn factorial_mod(&self, n: i64) -> i64 {\n if n < self.n {\n return self.fact[n as usize];\n }\n let mut t = self.fact[self.n as usize - 1];\n for x in self.n..=n {\n t = (t * x) % MODVAL;\n }\n t\n }\n\n fn permutations_mod(&self, n: i64, r: i64) -> i64 {\n let a = self.factorial_mod(n);\n let b = self.inv_fact_mod(n - r);\n return self.mult_mod(a, b);\n }\n\n fn inv_fact_mod(&self, n: i64) -> i64 {\n if n < self.n {\n return self.inv[n as usize];\n }\n self.pow_mod(self.factorial_mod(n), MODVAL - 2)\n }\n\n fn inv_mod(&self, n: i64) -> i64 {\n self.pow_mod(n, MODVAL - 2)\n }\n\n fn combinations_mod(&self, n: i64, r: i64) -> i64 {\n let a = self.factorial_mod(n);\n let b = self.inv_fact_mod(r);\n let c = self.inv_fact_mod(n - r);\n return self.mult_mod(self.mult_mod(a, b), c);\n }\n\n fn pow_mod(&self, mut base: i64, mut pow: i64) -> i64 {\n if pow == 0 {\n return 1;\n }\n let mut result = 1;\n while pow > 0 {\n if pow & 1 == 1 {\n result = (result * base) % MODVAL;\n }\n pow /= 2;\n base = (base * base) % MODVAL;\n }\n result\n }\n\n fn mult_mod(&self, a: i64, b: i64) -> i64 {\n let a = a as i128;\n let b = b as i128;\n ((a * b) % MODVAL as i128) as i64\n }\n\n fn add_mod(&self, a: i64, b: i64) -> i64 {\n ((a % MODVAL) + (b % MODVAL)) % MODVAL\n }\n}\n\nfn main() -> Result<(), Box> {\n let stdout = io::stdout();\n let lock = stdout.lock();\n let stdin = io::stdin();\n let mut ow = io::BufWriter::new(lock);\n let mut scan = Scanner::new(stdin.lock());\n\n // let n_tests = scan.next::();\n let n_tests = 1;\n let fmc = FactModCache::<1000000007>::new(1000005);\n for t_num in 1..=n_tests {\n let n = scan.next::();\n let k = scan.next::();\n\n let mut start = 1;\n\n for i in 1..=(std::cmp::min(n, k)) {\n start = fmc.add_mod(start, fmc.combinations_mod(n as i64, i as i64));\n }\n\n writeln!(ow, \"{}\", start);\n }\n Ok(())\n}\n"}, {"source_code": "// start of input macros\r\n\r\nmacro_rules! input {\r\n\t(source = $s:expr, $($r:tt)*) => {\r\n\t\tlet mut iter = $s.split_whitespace();\r\n\t\tinput_inner!{iter, $($r)*}\r\n\t};\r\n\t($($r:tt)*) => {\r\n\t\tlet s = {\r\n\t\t\tuse std::io::Read;\r\n\t\t\tlet mut s = String::new();\r\n\t\t\tstd::io::stdin().read_to_string(&mut s).unwrap();\r\n\t\t\ts\r\n\t\t};\r\n\t\tlet mut iter = s.split_whitespace();\r\n\t\tinput_inner!{iter, $($r)*}\r\n\t};\r\n}\r\n\r\nmacro_rules! input_inner {\r\n\t($iter:expr) => {};\r\n\t($iter:expr, ) => {};\r\n\r\n\t($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\r\n\t\tlet $var = read_value!($iter, $t);\r\n\t\tinput_inner!{$iter $($r)*}\r\n\t};\r\n}\r\n\r\nmacro_rules! read_value {\r\n\t($iter:expr, ( $($t:tt),* )) => {\r\n\t\t( $(read_value!($iter, $t)),* )\r\n\t};\r\n\r\n\t($iter:expr, [ $t:tt ; $len:expr ]) => {\r\n\t\t(0..$len).map(|_| read_value!($iter, $t)).collect::>()\r\n\t};\r\n\r\n\t($iter:expr, chars) => {\r\n\t\tread_value!($iter, String).chars().collect::>()\r\n\t};\r\n\r\n\t($iter:expr, usize1) => {\r\n\t\tread_value!($iter, usize) - 1\r\n\t};\r\n\r\n\t($iter:expr, $t:ty) => {\r\n\t\t$iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\r\n\t};\r\n}\r\n\r\n// end of input macros\r\n\r\nstruct Factorial {\r\n\tn: usize,\r\n\tm: i64,\r\n\tfactorial: Vec,\r\n\tinverse: Vec,\r\n\tinverse_factorial: Vec,\r\n}\r\n\r\nimpl Factorial {\r\n\tfn new(n: usize, m: i64) -> Factorial {\r\n\t\tlet mut factorial = vec![1; n + 1];\r\n\t\tlet mut inverse = vec![1; n + 1];\r\n\t\tlet mut inverse_factorial = vec![1; n + 1];\r\n\t\tfor i in 2..=n {\r\n\t\t\tfactorial[i] = (i as i64) * factorial[i - 1] % m;\r\n\t\t\tinverse[i] = ((m / (i as i64)) * -inverse[(m % (i as i64)) as usize] % m + m) % m;\r\n\t\t\tinverse_factorial[i] = inverse[i] * inverse_factorial[i - 1] % m;\r\n\t\t}\r\n\t\tFactorial {\r\n\t\t\tn,\r\n\t\t\tm,\r\n\t\t\tfactorial,\r\n\t\t\tinverse,\r\n\t\t\tinverse_factorial,\r\n\t\t}\r\n\t}\r\n\r\n\tfn c(&self, n: usize, k: usize) -> i64 {\r\n\t\tif n < k {\r\n\t\t\t0\r\n\t\t} else {\r\n\t\t\tassert!(k <= n && n <= self.n);\r\n\t\t\tself.factorial[n] * self.inverse_factorial[k] % self.m * self.inverse_factorial[n - k]\r\n\t\t\t\t% self.m\r\n\t\t}\r\n\t}\r\n\r\n\tfn catalan(&self, n: usize) -> i64 {\r\n\t\tassert!(2 * n <= self.n);\r\n\t\tself.c(2 * n, n) * self.inverse[n + 1] % self.m\r\n\t}\r\n}\r\n\r\n// start of solution\r\n\r\nconst MOD: i64 = 1_000_000_007;\r\n\r\nfn main() {\r\n\tinput! {\r\n\t n: usize, k: usize\r\n\t}\r\n\tlet data = Factorial::new(200_005, MOD);\r\n\tlet mut answer = 0;\r\n\tfor i in 0..=n.min(k) {\r\n\t answer = (answer + data.c(n, i)) % MOD;\r\n\t}\r\n\tprintln!(\"{}\", answer);\r\n}\r\n\r\n// end of solution"}, {"source_code": "pub mod solution {\n\nuse crate::io::input::Input;\nuse crate::io::output::output;\nuse crate::{out, out_line};\nuse std::cmp::min;\nuse crate::math::modular::factorial::Factorial;\nuse crate::math::modular::primitive::ModularType;\n\ntype Mod = ModularType<1000000007>;\n\nfn solve(input: &mut Input, _test_case: usize) {\n let (n, k) = input.read();\n let mut ans = Mod::from(0);\n let factorials = Factorial::new(n);\n for i in 0..=min(k, n) {\n ans += factorials.combinations(n, i);\n }\n out_line!(ans);\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_some()\n}\n\n}\npub mod io {\npub mod input {\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\nimpl<'s> Input<'s> {\n const DEFAULT_BUF_SIZE: usize = 4096;\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 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 fn read_char(&mut self) -> char {\n self.skip_whitespace();\n self.get().unwrap().into()\n }\n\n fn read_float(&mut self) -> f64 {\n self.read_string().parse().unwrap()\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\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_float()\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 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 modular {\npub mod factorial {\nuse crate::math::modular::inverse::compute_inverse_up_to;\nuse crate::math::modular::primitive::Modular;\n\npub struct Factorial {\n fact: Vec,\n inverse_fact: Vec,\n}\n\nimpl Factorial\nwhere\n Mod: Modular,\n{\n pub fn new(n: usize) -> Self {\n let mut fact = vec![0.into(); n + 1];\n let mut inverse_fact = vec![0.into(); n + 1];\n let inv = compute_inverse_up_to(n);\n fact[0] = 1.into();\n inverse_fact[0] = 1.into();\n for i in 1..=n {\n fact[i] = fact[i - 1] * i.into();\n inverse_fact[i] = inverse_fact[i - 1] * inv[i];\n }\n Self { fact, inverse_fact }\n }\n\n pub fn combinations(&self, n: usize, k: usize) -> Mod {\n if k > n {\n 0.into()\n } else {\n self.fact[n] * self.inverse_fact[n - k] * self.inverse_fact[k]\n }\n }\n}\n}\npub mod inverse {\nuse crate::math::modular::primitive::Modular;\n\npub fn compute_inverse_up_to(n: usize) -> Vec\nwhere\n Mod: Modular,\n{\n let mut inv: Vec = vec![0.into(); n + 1];\n inv[1] = 1.into();\n for i in 2..=n {\n inv[i] = inv[Mod::MODULO as usize % i] * (Mod::MODULO as usize / i).into();\n inv[i] = -inv[i];\n }\n inv\n}\n}\npub mod primitive {\nuse crate::io::output::{Output, Writable};\nuse std::ops::{Add, AddAssign, Mul, Neg};\n\n#[derive(Copy, Clone)]\npub struct ModularType(u32);\n\npub trait Modular:\n Add\n + AddAssign\n + Mul\n + Neg\n + From\n + From\n + From\n + Writable\n + Copy\n{\n const MODULO: u32;\n fn value(&self) -> u32;\n fn usize(&self) -> usize {\n self.value() as usize\n }\n}\n\nimpl Modular for ModularType {\n const MODULO: u32 = M;\n\n fn value(&self) -> u32 {\n self.0\n }\n}\n\nimpl Add for ModularType {\n type Output = ModularType;\n\n fn add(self, rhs: Self) -> Self::Output {\n let result = self.0 + rhs.0;\n ModularType(if result >= M { result - M } else { result })\n }\n}\n\nimpl AddAssign for ModularType {\n fn add_assign(&mut self, rhs: Self) {\n self.0 += rhs.0;\n if self.0 >= M {\n self.0 -= M;\n }\n }\n}\n\nimpl Mul for ModularType {\n type Output = ModularType;\n\n fn mul(self, rhs: Self) -> Self::Output {\n Self((self.0 as u64 * rhs.0 as u64 % M as u64) as u32)\n }\n}\n\nimpl Neg for ModularType {\n type Output = ModularType;\n\n fn neg(self) -> Self::Output {\n Self(if self.0 == 0 { 0 } else { M - self.0 })\n }\n}\n\nimpl From for ModularType {\n fn from(x: u32) -> Self {\n Self(x % M)\n }\n}\n\nimpl From for ModularType {\n fn from(x: i32) -> Self {\n Self(x.rem_euclid(M as i32) as u32)\n }\n}\n\nimpl From for ModularType {\n fn from(x: usize) -> Self {\n Self((x % M as usize) as u32)\n }\n}\n\nimpl Into for ModularType {\n fn into(self) -> usize {\n self.0 as usize\n }\n}\n\nimpl Writable for ModularType {\n fn write(&self, output: &mut Output) {\n self.0.write(output);\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"}], "negative_code": [{"source_code": "#[allow(unused_imports)]\nuse std::{\n cmp,\n collections::{BinaryHeap, HashMap, HashSet, VecDeque},\n hash::Hash,\n io::{self, BufWriter, Read, StdoutLock, Write},\n str::Lines,\n};\n\nconst MODVAL: u64 = 1e9 as u64 + 7;\n\n#[allow(unused_mut, unused_variables)]\nfn main() -> io::Result<()> {\n let mut input = String::new();\n io::stdin().lock().read_to_string(&mut input).unwrap();\n let mut input = input.lines();\n\n let out = io::stdout();\n let mut out = BufWriter::new(out.lock());\n\n let line = next_line_as_u64_vec(&mut input);\n let n = line[0];\n let k = line[1];\n\n let mut m = 1;\n for k in 1..=cmp::min(n, k) {\n m += bi_coefficient_mod(n, k, MODVAL);\n }\n writeln!(out, \"{}\", m)?;\n\n Ok(())\n}\n\n#[allow(dead_code)]\nfn bi_coefficient_mod(n: u64, k: u64, modval: u64) -> u64 {\n if n == k {\n return 1;\n }\n let fact = FactorialsMod::new(n as usize, modval);\n let tmp = fact.get(n as usize).unwrap();\n let tmp = (tmp * mod_inverse(fact.get(k as usize).unwrap(), modval)) % modval;\n let tmp = (tmp * mod_inverse(fact.get((n - k) as usize).unwrap(), modval)) % modval;\n tmp\n}\n\n#[allow(dead_code)]\nfn extended_euclidean(a: u64, b: u64) -> (u64, i64, i64) {\n fn rec(a: u64, b: u64, p: i64, q: i64, x: i64, y: i64) -> (u64, i64, i64) {\n if b == 0 {\n return (a, p, x);\n }\n let quot = (a / b) as i64;\n rec(b, a % b, q, p - quot * q, y, x - quot * y)\n }\n rec(a, b, 1, 0, 0, 1)\n}\n\n#[allow(dead_code)]\nfn mod_inverse(n: u64, modval: u64) -> u64 {\n let (a, b) = if n > modval { (n, modval) } else { (modval, n) };\n let (gcd, x, y) = extended_euclidean(a, b);\n assert!(gcd == 1, \"gcd({},{}) is not zero!\", a, modval);\n let m = modval as i64;\n let res = if n > modval {\n ((x % m + m) % m) as u64\n } else {\n ((y % m + m) % m) as u64\n };\n res\n}\n\n#[derive(Debug, Clone)]\nstruct FactorialsMod {\n numbers: Vec,\n current: usize,\n}\n\n#[allow(dead_code)]\nimpl FactorialsMod {\n fn new(n: usize, modval: u64) -> Self {\n let mut numbers = vec![0; n + 1];\n let mut fac = 1u64;\n for i in 1..=n {\n fac *= i as u64;\n fac %= modval;\n numbers[i] = fac;\n }\n let current = 0;\n FactorialsMod { numbers, current }\n }\n\n fn reset(&mut self) {\n self.current = 0;\n }\n\n fn get(&self, n: usize) -> Option {\n self.numbers.get(n).map(|&x| x)\n }\n}\n\nimpl Iterator for FactorialsMod {\n type Item = u64;\n fn next(&mut self) -> Option {\n if self.current == self.numbers.len() {\n return None;\n }\n self.current += 1;\n self.numbers.get(self.current).map(|n| *n)\n }\n}\n\n#[allow(dead_code)]\nfn next_line(input: &mut Lines) -> String {\n input.next().unwrap().to_string()\n}\n\n#[allow(dead_code)]\nfn next_line_as_u64(input: &mut Lines) -> u64 {\n let s = input.next().unwrap();\n let n: u64 = s.parse().unwrap();\n n\n}\n\n#[allow(dead_code)]\nfn next_line_as_i64(input: &mut Lines) -> i64 {\n let s = input.next().unwrap();\n let n: i64 = s.parse().unwrap();\n n\n}\n\n#[allow(dead_code)]\nfn next_line_as_string_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a = s.split(\" \").collect::>();\n a.iter().map(|&s| s.to_string()).collect()\n}\n\n#[allow(dead_code)]\nfn next_line_as_char_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.chars().collect();\n a\n}\n\n#[allow(dead_code)]\nfn next_line_as_u64_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.split(\" \").map(|s| s.parse().unwrap()).collect();\n a\n}\n\n#[allow(dead_code)]\nfn next_line_as_i64_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.split(\" \").map(|s| s.parse().unwrap()).collect();\n a\n}\n\n#[allow(dead_code)]\nfn write_bool_answer(answer: bool, out: &mut BufWriter) {\n if answer {\n writeln!(out, \"yes\").unwrap();\n } else {\n writeln!(out, \"no\").unwrap();\n }\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::{\n cmp,\n collections::{BinaryHeap, HashMap, HashSet, VecDeque},\n hash::Hash,\n io::{self, BufWriter, Read, StdoutLock, Write},\n str::Lines,\n};\n\n#[allow(unused_mut, unused_variables)]\nfn main() -> io::Result<()> {\n let mut input = String::new();\n io::stdin().lock().read_to_string(&mut input).unwrap();\n let mut input = input.lines();\n\n let out = io::stdout();\n let mut out = BufWriter::new(out.lock());\n\n let line = next_line_as_u64_vec(&mut input);\n let n = line[0] as u32;\n let k = line[1] as u32;\n\n let stop = cmp::min(n, k);\n let mut winner = 1u64;\n for i in 1..=stop {\n winner += 2u64.pow(n - i);\n }\n\n let answer = winner % (1_000_000_000 + 7);\n println!(\"{}\", answer);\n\n Ok(())\n}\n\n#[allow(dead_code)]\nfn next_line(input: &mut Lines) -> String {\n input.next().unwrap().to_string()\n}\n\n#[allow(dead_code)]\nfn next_line_as_u64(input: &mut Lines) -> u64 {\n let s = input.next().unwrap();\n let n: u64 = s.parse().unwrap();\n n\n}\n\n#[allow(dead_code)]\nfn next_line_as_i64(input: &mut Lines) -> i64 {\n let s = input.next().unwrap();\n let n: i64 = s.parse().unwrap();\n n\n}\n\n#[allow(dead_code)]\nfn next_line_as_string_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a = s.split(\" \").collect::>();\n a.iter().map(|&s| s.to_string()).collect()\n}\n\n#[allow(dead_code)]\nfn next_line_as_char_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.chars().collect();\n a\n}\n\n#[allow(dead_code)]\nfn next_line_as_u64_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.split(\" \").map(|s| s.parse().unwrap()).collect();\n a\n}\n\n#[allow(dead_code)]\nfn next_line_as_i64_vec(input: &mut Lines) -> Vec {\n let s = input.next().unwrap();\n let a: Vec = s.split(\" \").map(|s| s.parse().unwrap()).collect();\n a\n}\n\n#[allow(dead_code)]\nfn write_bool_answer(answer: bool, out: &mut BufWriter) {\n if answer {\n writeln!(out, \"yes\").unwrap();\n } else {\n writeln!(out, \"no\").unwrap();\n }\n}\n"}, {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::cell::RefCell;\nuse std::cmp::Ordering;\nuse std::collections::*;\nuse std::error::Error;\nuse std::fmt::write;\nuse std::hash::Hash;\nuse std::io;\nuse std::io::prelude::*;\nuse std::io::StdinLock;\nuse std::io::StdoutLock;\nuse std::io::Write;\nuse std::io::{stdin, stdout, BufRead, BufWriter};\nuse std::ops::Add;\nuse std::thread::panicking;\n\nmacro_rules! fprintvec {\n ($dst:expr, $arg:expr) => {{\n writeln!(\n $dst,\n \"{}\",\n $arg.iter()\n .map(|x| format!(\"{} \", x))\n .collect::>()\n .join(\"\")\n )\n .ok();\n }};\n}\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 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_whitespace())\n }\n }\n }\n\n pub fn next_split(&mut self) -> Vec {\n loop {\n let mut v = Vec::new();\n while let Some(token) = self.buf_iter.next() {\n v.push(token.parse().ok().expect(\"Failed parse\"));\n }\n if v.len() > 0 {\n return v;\n }\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_whitespace())\n }\n }\n }\n}\nfn lcm(first: usize, second: usize) -> usize {\n first * second / gcd(first, second)\n}\n\nfn gcd(first: usize, second: usize) -> usize {\n let mut max = first;\n let mut min = second;\n if min > max {\n let val = max;\n max = min;\n min = val;\n }\n\n loop {\n let res = max % min;\n if res == 0 {\n return min;\n }\n\n max = min;\n min = res;\n }\n}\nconst MOD_VAL: i64 = 1000000007;\nfn main() -> Result<(), Box> {\n let stdout = io::stdout();\n let lock = stdout.lock();\n let stdin = io::stdin();\n let mut ow = io::BufWriter::new(lock);\n let mut scan = Scanner::new(stdin.lock());\n\n // let n_tests = scan.next::();\n let n_tests = 1;\n for t_num in 1..=n_tests {\n let n = scan.next::();\n let k = scan.next::();\n\n let mut start = 1;\n let mut step = 1;\n let good;\n if n >= k {\n good = n - k;\n } else {\n good = 0;\n }\n for i in 0..good {\n step = (step * 2) % MOD_VAL;\n }\n for i in 0..k {\n start = ((start % MOD_VAL) + (step % MOD_VAL)) % MOD_VAL;\n step = (step * 2) % MOD_VAL;\n }\n writeln!(ow, \"{}\", start);\n }\n Ok(())\n}\n"}, {"source_code": "// start of input macros\r\n\r\nmacro_rules! input {\r\n\t(source = $s:expr, $($r:tt)*) => {\r\n\t\tlet mut iter = $s.split_whitespace();\r\n\t\tinput_inner!{iter, $($r)*}\r\n\t};\r\n\t($($r:tt)*) => {\r\n\t\tlet s = {\r\n\t\t\tuse std::io::Read;\r\n\t\t\tlet mut s = String::new();\r\n\t\t\tstd::io::stdin().read_to_string(&mut s).unwrap();\r\n\t\t\ts\r\n\t\t};\r\n\t\tlet mut iter = s.split_whitespace();\r\n\t\tinput_inner!{iter, $($r)*}\r\n\t};\r\n}\r\n\r\nmacro_rules! input_inner {\r\n\t($iter:expr) => {};\r\n\t($iter:expr, ) => {};\r\n\r\n\t($iter:expr, $var:ident : $t:tt $($r:tt)*) => {\r\n\t\tlet $var = read_value!($iter, $t);\r\n\t\tinput_inner!{$iter $($r)*}\r\n\t};\r\n}\r\n\r\nmacro_rules! read_value {\r\n\t($iter:expr, ( $($t:tt),* )) => {\r\n\t\t( $(read_value!($iter, $t)),* )\r\n\t};\r\n\r\n\t($iter:expr, [ $t:tt ; $len:expr ]) => {\r\n\t\t(0..$len).map(|_| read_value!($iter, $t)).collect::>()\r\n\t};\r\n\r\n\t($iter:expr, chars) => {\r\n\t\tread_value!($iter, String).chars().collect::>()\r\n\t};\r\n\r\n\t($iter:expr, usize1) => {\r\n\t\tread_value!($iter, usize) - 1\r\n\t};\r\n\r\n\t($iter:expr, $t:ty) => {\r\n\t\t$iter.next().unwrap().parse::<$t>().expect(\"Parse error\")\r\n\t};\r\n}\r\n\r\n// end of input macros\r\n\r\nstruct Factorial {\r\n\tn: usize,\r\n\tm: i64,\r\n\tfactorial: Vec,\r\n\tinverse: Vec,\r\n\tinverse_factorial: Vec,\r\n}\r\n\r\nimpl Factorial {\r\n\tfn new(n: usize, m: i64) -> Factorial {\r\n\t\tlet mut factorial = vec![1; n + 1];\r\n\t\tlet mut inverse = vec![1; n + 1];\r\n\t\tlet mut inverse_factorial = vec![1; n + 1];\r\n\t\tfor i in 2..=n {\r\n\t\t\tfactorial[i] = (i as i64) * factorial[i - 1] % m;\r\n\t\t\tinverse[i] = ((m / (i as i64)) * -inverse[(m % (i as i64)) as usize] % m + m) % m;\r\n\t\t\tinverse_factorial[i] = inverse[i] * inverse_factorial[i - 1] % m;\r\n\t\t}\r\n\t\tFactorial {\r\n\t\t\tn,\r\n\t\t\tm,\r\n\t\t\tfactorial,\r\n\t\t\tinverse,\r\n\t\t\tinverse_factorial,\r\n\t\t}\r\n\t}\r\n\r\n\tfn c(&self, n: usize, k: usize) -> i64 {\r\n\t\tif n < k {\r\n\t\t\t0\r\n\t\t} else {\r\n\t\t\tassert!(k <= n && n <= self.n);\r\n\t\t\tself.factorial[n] * self.inverse_factorial[k] % self.m * self.inverse_factorial[n - k]\r\n\t\t\t\t% self.m\r\n\t\t}\r\n\t}\r\n\r\n\tfn catalan(&self, n: usize) -> i64 {\r\n\t\tassert!(2 * n <= self.n);\r\n\t\tself.c(2 * n, n) * self.inverse[n + 1] % self.m\r\n\t}\r\n}\r\n\r\n// start of solution\r\n\r\nconst MOD: i64 = 998_244_353;\r\n\r\nfn main() {\r\n\tinput! {\r\n\t n: usize, k: usize\r\n\t}\r\n\tlet data = Factorial::new(200_005, MOD);\r\n\tlet mut answer = 0;\r\n\tfor i in 0..=n.min(k) {\r\n\t answer = (answer + data.c(n, i)) % MOD;\r\n\t}\r\n\tprintln!(\"{}\", answer);\r\n}\r\n\r\n// end of solution"}], "src_uid": "dc7b887afcc2e95c4e90619ceda63071"} {"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 d1: usize = scan.next();\n let d2: usize = scan.next();\n let d3: usize = scan.next();\n let result = (d1+d2+d3).min((d1+d2)*2).min(d1*2+d3*2).min(d3*2+d2*2);\n println!(\"{}\", result);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "positive_code": [{"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 (a, b, c) = R!(u32, u32, u32);\n let ans = cmp::min(cmp::min(2*(a+b), 2*(b+c)), cmp::min(2*(a+c), a+b+c));\n W!(ans);\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::io;\nuse std::cmp::{min, max};\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Scanner {\n Scanner {\n reader: reader,\n buffer: Vec::new(),\n }\n }\n\n /// Use \"turbofish\" syntax next::() to select data type of next token.\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n\n pub fn next_vec(&mut self, len: usize) -> Vec\n where\n T::Err: ::std::fmt::Debug,\n {\n (0..len).map(|_| self.next::()).collect::>()\n }\n}\n\nfn main1() {\n let stdin = io::stdin();\n let mut input = Scanner::new(stdin.lock());\n let d = input.next_vec::(3);\n println!(\"{}\", min(d[0] + d[1] + d[2], min(2 * (d[0] + d[1]), 2 * min(d[0], d[1]) + 2 * d[2])));\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}\n"}, {"source_code": "#![allow(unused_imports)]\n\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}\n\nfn main() {\n let s = load();\n let (a, b, c) = (s[0], s[1], s[2]);\n let mx = max(a, max(b, c));\n let sum = a + b + c;\n println!(\"{}\", min(sum, 2 * (sum - mx)));\n}\n// min, max\n// HashSet, insert, contains\n// HashMap, insert, get\n// Vec, len, sort\n// primitive retype: i as f64\n"}, {"source_code": "type Trio = (u32, u32, u32);\nfn input_trio() -> Trio {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let buf: Vec = buf\n .trim()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect();\n (buf[0], buf[1], buf[2])\n}\n\nfn main() {\n let (d1, d2, d3) = input_trio();\n print!(\n \"{}\",\n d1.min(d2) + d3.min(d1 + d2) + (d1.max(d2)).min(d1.min(d2) + d3)\n )\n}"}, {"source_code": "use std::cmp::min;\nfn main() {\n let mut reader = scanner::TokenReader::new();\n let (a, b, c) = (\n reader.next::(),\n reader.next::(),\n reader.next::(),\n );\n\n println!(\n \"{}\",\n min(a + b + c, min((a + b) * 2, min((b + c) * 2, (a + c) * 2)))\n );\n}\n\n// ---------- Begin Scanner ----------\n#[allow(dead_code)]\nmod scanner {\n use std::fmt::Debug;\n use std::str::FromStr;\n\n pub struct TokenReader {\n reader: std::io::Stdin,\n tokens: Vec,\n index: usize,\n }\n\n impl TokenReader {\n pub fn new() -> Self {\n Self {\n reader: std::io::stdin(),\n tokens: Vec::new(),\n index: 0,\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T: FromStr,\n T::Err: Debug,\n {\n if self.index >= self.tokens.len() {\n self.load_next_line();\n }\n self.index += 1;\n self.tokens[self.index - 1].parse().unwrap()\n }\n\n pub fn vector(&mut self) -> Vec\n where\n T: FromStr,\n T::Err: Debug,\n {\n if self.index >= self.tokens.len() {\n self.load_next_line();\n }\n self.index = self.tokens.len();\n self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()\n }\n\n pub fn load_next_line(&mut self) {\n let mut line = String::new();\n self.reader.read_line(&mut line).unwrap();\n\n self.tokens = line.split_whitespace().map(String::from).collect();\n self.index = 0;\n }\n }\n}\n// ---------- End Scanner ----------\n"}, {"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 a = input.i();\n let b = input.i();\n let c = input.i();\n let sol = a.min(b + c) + b.min(a + c) + c.min(a + b);\n println!(\"{}\", sol);\n}\n\n"}, {"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 a = readvec!(i32);\n println!(\"{}\",\n min(min(a[0]+a[2]+a[1],\n a[0]*2+a[1]*2),\n min(a[0]*2+a[2]*2,\n a[1]*2+a[2]*2)));\n}\n"}], "negative_code": [{"source_code": "#[allow(unused_imports)]\nuse std::io;\nuse std::cmp::{min, max};\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Scanner {\n Scanner {\n reader: reader,\n buffer: Vec::new(),\n }\n }\n\n /// Use \"turbofish\" syntax next::() to select data type of next token.\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n\n pub fn next_vec(&mut self, len: usize) -> Vec\n where\n T::Err: ::std::fmt::Debug,\n {\n (0..len).map(|_| self.next::()).collect::>()\n }\n}\n\nfn main1() {\n let stdin = io::stdin();\n let mut input = Scanner::new(stdin.lock());\n let d = input.next_vec::(3);\n println!(\"{}\", min(d[0] + d[1] + d[2], 2 * (d[0] + d[1])))\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}\n"}, {"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 fn next_n(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.next::()).collect()\n }\n\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let d1: usize = scan.next();\n let d2: usize = scan.next();\n let d3: usize = scan.next();\n let result = (d1+d2+d3).min((d1+d2)*2).min(d1*2+d3*2);\n println!(\"{}\", result);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n"}], "src_uid": "26cd7954a21866dbb2824d725473673e"} {"source_code": "//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\n//\n\nfn run() {\n input! {\n n: usize,\n p: [[i64; 5]; n],\n }\n if n > 100 {\n println!(\"0\");\n return;\n }\n let mut ans = vec![];\n for i in 0..n {\n let mut q = p.clone();\n let p = q.remove(i);\n for q in q.iter_mut() {\n for (q, p) in q.iter_mut().zip(p.iter()) {\n *q -= *p;\n }\n }\n let mut ok = true;\n for (i, a) in q.iter().enumerate() {\n for b in q.iter().take(i) {\n let mut sum = 0;\n for (a, b) in a.iter().zip(b.iter()) {\n sum += *a * *b;\n }\n if sum > 0 {\n ok = false;\n }\n }\n }\n if ok {\n ans.push(i + 1);\n }\n }\n println!(\"{}\", ans.len());\n for (i, a) in ans.iter().enumerate() {\n if i > 0 {\n print!(\" \");\n }\n print!(\"{}\", a);\n }\n println!();\n}\n\nfn main() {\n run();\n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn main() {\n let n: usize = {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input.trim().parse().unwrap()\n };\n\n let mut points = Vec::with_capacity(n);\n\n for _ in 0..n {\n let point: Vec = {\n let mut input = String::new();\n io::stdin().read_line(&mut input).unwrap();\n input.split_whitespace().map(|k| k.parse().unwrap()).collect()\n };\n points.push(point);\n }\n\n let mut is_good = vec![true; n];\n\n let test = |a: usize, b: usize, c: usize| {\n let mut res = 0i32;\n for i in 0..5 {\n res += (points[b][i] - points[a][i]) * (points[c][i] - points[a][i]);\n }\n res <= 0\n };\n\n for i in 0..n {\n if !is_good[i] {\n continue;\n }\n for j in 0..n {\n if j == i {\n continue;\n }\n for k in 0..n {\n if k == j || k == i {\n continue;\n }\n let good = test(i, j, k);\n if good {\n is_good[j] = false;\n is_good[k] = false;\n } else {\n is_good[i] = false;\n }\n }\n }\n }\n\n println!(\"{}\", is_good.iter().filter(|&&b| b).count());\n\n for i in 0..n {\n if is_good[i] {\n println!(\"{}\", i + 1);\n }\n }\n}\n"}, {"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\n#[derive(Debug, Copy, Clone, PartialEq, Eq)]\nstruct Point {\n x1: i64,\n x2: i64,\n x3: i64,\n x4: i64,\n x5: i64\n}\n\nimpl Point {\n fn vect(&self, a : &Point) -> Point {\n Point {\n x1: a.x1 - self.x1,\n x2: a.x2 - self.x2,\n x3: a.x3 - self.x3,\n x4: a.x4 - self.x4,\n x5: a.x5 - self.x5\n }\n }\n\n fn product(a : &Point, b : &Point) -> i64 {\n a.x1*b.x1 + a.x2*b.x2 + a.x3*b.x3 + a.x4*b.x4 + a.x5*b.x5\n }\n\n fn length(&self) -> f64 {\n (Point::product(self, self) as f64).sqrt()\n }\n\n fn angle(&self, a : &Point, b : &Point) -> f64 {\n let vect1 = self.vect(a);\n let vect2 = self.vect(b);\n let n = Point::product(&vect1, &vect2) as f64;\n let d = vect1.length() * vect2.length();\n (n / d).acos()\n }\n\n fn sq_dist(a : &Point, b : &Point) -> i64 {\n (a.x1 - b.x1)*(a.x1 - b.x1)\n + (a.x2 - b.x2)*(a.x2 - b.x2)\n + (a.x3 - b.x3)*(a.x3 - b.x3)\n + (a.x4 - b.x4)*(a.x4 - b.x4)\n + (a.x5 - b.x5)*(a.x5 - b.x5)\n }\n}\n\nfn main() {\n let (n,) = scan_line!(usize);\n let mut points = vec![];\n let mut kind = vec![];\n let ninety = std::f64::consts::PI / 2.0;\n\n for i in 0..n {\n let (a, b, c, d, e) = scan_line!(i64 i64 i64 i64 i64);\n points.push(Point {\n x1: a, x2: b, x3: c, x4: d, x5: e\n });\n kind.push(true);\n }\n\n for i in 0..n {\n let test = points[i];\n let init = (i+1) % n;\n let mut constraint1 = points[init];\n let mut constraint2 = points[init];\n for j in 0..n {\n if i == j || init == j { continue; }\n\n let ang1 = test.angle(&constraint1, &points[j]);\n let ang2 = test.angle(&constraint2, &points[j]);\n\n if ang1 < ninety || ang2 < ninety {\n kind[i] = false;\n break;\n } else {\n let dist1 = Point::sq_dist(&constraint1, &points[j]);\n let dist2 = Point::sq_dist(&constraint2, &points[j]);\n if dist1 < dist2 {\n constraint1 = points[j];\n } else {\n constraint2 = points[j];\n }\n }\n }\n }\n\n let good_count = kind.iter().map(|&x| if x { 1 } else { 0 }).fold(0, |acc, x| acc + x);\n println!(\"{}\", good_count);\n if good_count > 0 {\n for i in 0..n {\n if kind[i] {\n println!(\"{}\", i+1);\n }\n }\n }\n}\n"}], "negative_code": [{"source_code": "//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\n//\n\nfn run() {\n input! {\n n: usize,\n p: [[i64; 5]; n],\n }\n if n > 10 {\n println!(\"0\");\n return;\n }\n let mut ans = vec![];\n for i in 0..n {\n let mut q = p.clone();\n let p = q.remove(i);\n for q in q.iter_mut() {\n for (q, p) in q.iter_mut().zip(p.iter()) {\n *q -= *p;\n }\n }\n let mut ok = true;\n for (i, a) in q.iter().enumerate() {\n for b in q.iter().take(i) {\n let mut sum = 0;\n for (a, b) in a.iter().zip(b.iter()) {\n sum += *a * *b;\n }\n if sum > 0 {\n ok = false;\n }\n }\n }\n if ok {\n ans.push(i + 1);\n }\n }\n println!(\"{}\", ans.len());\n for (i, a) in ans.iter().enumerate() {\n if i > 0 {\n print!(\" \");\n }\n print!(\"{}\", a);\n }\n println!();\n}\n\nfn main() {\n run();\n}\n"}], "src_uid": "c1cfe1f67217afd4c3c30a6327e0add9"} {"source_code": "//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\n//\n\n// ---------- 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 if *self > x {\n *self = x;\n true\n } else {\n false\n }\n }\n fn chmax(&mut self, x: Self) -> bool {\n if *self < x {\n *self = x;\n true\n } else {\n false\n }\n }\n}\n// ---------- end chmin, chmax ----------\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, [i32; 2]); n],\n }\n let mut p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, [p.1[0], p.1[1]]))\n .collect::>();\n let mut need = [0; 2];\n for p in p.iter_mut() {\n let n = n as i32;\n for (need, v) in need.iter_mut().zip(p.1.iter_mut()) {\n *need += max(0, *v - n);\n v.chmin(n);\n }\n }\n let mut sum = vec![[0i32; 2]];\n for &(x, _) in p.iter() {\n for i in 0..sum.len() {\n let mut a = sum[i];\n a[x] += 1;\n sum.push(a);\n }\n }\n let inf = std::i32::MAX / 2;\n let mut dp = vec![vec![vec![inf; 1 << n]; n.pow(2) + 1]; 2];\n let abs = (need[1] - need[0]).abs() as usize;\n dp[(need[0] >= need[1]) as usize][min(n * n, abs)][0] = 0;\n for bit in 0..(1 << n) {\n let sum = sum[bit];\n for rem in 0..=n.pow(2) {\n for i in 0..2 {\n let v = dp[i][rem][bit];\n if v == inf {\n continue;\n }\n for (j, &(_, p)) in p.iter().enumerate() {\n let k = bit | (1 << j);\n if k == bit {\n continue;\n }\n let p = [max(0, p[0] - sum[0]), max(0, p[1] - sum[1])];\n if rem as i32 + p[i ^ 1] >= p[i] {\n let x = rem as i32 + p[i ^ 1] - p[i];\n let v = v + p[i ^ 1];\n dp[i][min(x as usize, n.pow(2))][k].chmin(v);\n } else {\n let x = p[i] - rem as i32 - p[i ^ 1];\n let v = v + p[i] - rem as i32;\n dp[i ^ 1][min(x as usize, n.pow(2))][k].chmin(v);\n }\n }\n }\n }\n }\n let add = need.iter().copied().max().unwrap() + n as i32;\n let ans = add + dp.into_iter().flatten().map(|dp| dp[(1 << n) - 1]).min().unwrap();\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n", "positive_code": [{"source_code": "//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\n//\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, i32, i32); n],\n }\n let p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, p.1, p.2))\n .collect::>();\n let mut sum = vec![([0, 0], 0, 0)];\n for &(x, y, z) in p.iter() {\n for i in 0..sum.len() {\n let (mut a, mut b, mut c) = sum[i];\n a[x] += 1;\n b += y;\n c += z;\n sum.push((a, b, c));\n }\n }\n let mut now = std::collections::BTreeMap::new();\n now.insert((0, 0, 0), 0);\n for _ in 0..n {\n let mut next = std::collections::BTreeMap::new();\n for ((bit, rem_a, rem_b), v) in now {\n assert!(rem_a == 0 || rem_b == 0);\n let (cnt, _, _) = sum[bit];\n for (i, &(_, a, b)) in p.iter().enumerate() {\n if bit >> i & 1 == 1 {\n continue;\n }\n let p = max(0, a - cnt[0]);\n let q = max(0, b - cnt[1]);\n let add = max(0, max(p - rem_a, q - rem_b));\n let v = v + add;\n let po = next.entry((bit | (1 << i), rem_a + add - p, rem_b + add - q)).or_insert(v);\n *po = std::cmp::min(*po, v);\n }\n }\n now = next;\n }\n let ans = now.into_iter().map(|(_, v)| v).min().unwrap() + n as i32;\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "//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\n//\n\n// ---------- 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 if *self > x {\n *self = x;\n true\n } else {\n false\n }\n }\n fn chmax(&mut self, x: Self) -> bool {\n if *self < x {\n *self = x;\n true\n } else {\n false\n }\n }\n}\n// ---------- end chmin, chmax ----------\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, [i32; 2]); n],\n }\n let mut p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, [p.1[0], p.1[1]]))\n .collect::>();\n let mut need = [0; 2];\n for p in p.iter_mut() {\n let n = n as i32;\n for (need, v) in need.iter_mut().zip(p.1.iter_mut()) {\n *need += max(0, *v - n + 1);\n v.chmin(n - 1);\n }\n }\n let mut sum = vec![[0i32; 2]];\n for &(x, _) in p.iter() {\n for i in 0..sum.len() {\n let mut a = sum[i];\n a[x] += 1;\n sum.push(a);\n }\n }\n let inf = std::i32::MAX / 2;\n let sup = (n - 1) * (n - 1);\n let mut dp = vec![vec![vec![inf; 1 << n]; sup + 1]; 2];\n let abs = (need[1] - need[0]).abs() as usize;\n dp[(need[0] >= need[1]) as usize][min(sup, abs)][0] = 0;\n for bit in 0..(1 << n) {\n let sum = sum[bit];\n for rem in 0..=sup {\n for i in 0..2 {\n let v = dp[i][rem][bit];\n if v == inf {\n continue;\n }\n for (j, &(_, p)) in p.iter().enumerate() {\n let k = bit | (1 << j);\n if k == bit {\n continue;\n }\n let p = [max(0, p[0] - sum[0]), max(0, p[1] - sum[1])];\n if rem as i32 + p[i ^ 1] >= p[i] {\n let x = rem as i32 + p[i ^ 1] - p[i];\n let v = v + p[i ^ 1];\n dp[i][min(x as usize, sup)][k].chmin(v);\n } else {\n let x = p[i] - rem as i32 - p[i ^ 1];\n let v = v + p[i] - rem as i32;\n dp[i ^ 1][min(x as usize, sup)][k].chmin(v);\n }\n }\n }\n }\n }\n let add = need.iter().copied().max().unwrap() + n as i32;\n let ans = add + dp.into_iter().flatten().map(|dp| dp[(1 << n) - 1]).min().unwrap();\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "use std::io::{self, Stdin};\nuse std::str::{self, FromStr};\nuse std::error::Error;\nuse std::cmp::*;\nuse std::thread;\nconst INF: i64 = 1i64 << 60;\nfn exec() {\n let mut sc = Scanner::new();\n let n: usize = sc.ne();\n let mut cards = Vec::new();\n for _ in 0..n {\n let c: String = sc.ne();\n let r: i64 = sc.ne();\n let b: i64 = sc.ne();\n let is_r = c == \"R\";\n cards.push((is_r, r, b));\n }\n let sn = 1 << n;\n let rn = n * (n + 1) / 2;\n let mut dp = vec![vec![-INF; rn]; sn];\n dp[0][0] = 0;\n for s in 0..sn {\n let mut rnum = 0;\n let mut bnum = 0;\n for i in 0..n {\n if (s >> i) & 1 == 0 {\n continue;\n }\n if cards[i].0 {\n rnum += 1;\n } else {\n bnum += 1;\n }\n }\n for i in 0..rn {\n // println!(\"{:b}, i: {}, {}\", s, i, dp[s][i]);\n if dp[s][i] == -INF {\n continue;\n }\n for j in 0..n {\n if (s >> j) & 1 == 1 {\n continue;\n }\n let ns = s | (1 << j);\n let ni = min(rnum, cards[j].1) as usize + i;\n dp[ns][ni] = max(dp[ns][ni], dp[s][i] + min(bnum, cards[j].2));\n }\n }\n }\n let rsum = cards.iter().fold(0, |acc, &t| acc + t.1);\n let bsum = cards.iter().fold(0, |acc, &t| acc + t.2);\n let mut ans = INF;\n for i in 0..rn {\n ans = min(ans, max(rsum - i as i64, bsum - dp[sn - 1][i]));\n // println!(\"{}\", ans);\n }\n println!(\"{}\", ans + n as i64);\n}\n\nconst DEFAULT_STACK: usize = 16 * 1024 * 1024;\nfn main() {\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(_) => {\n panic!(\"parse error: {:?}\",\n str::from_utf8(&self.buf[l..r]).unwrap())\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"}], "negative_code": [{"source_code": "//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\n//\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, i32, i32); n],\n }\n let p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, p.1, p.2))\n .collect::>();\n let mut sum = vec![([0, 0], 0, 0)];\n for &(x, y, z) in p.iter() {\n for i in 0..sum.len() {\n let (mut a, mut b, mut c) = sum[i];\n a[x] += 1;\n b += y;\n c += z;\n sum.push((a, b, c));\n }\n }\n let inf = std::i32::MAX / 2;\n let mut now = vec![(0, 0, 0, 0)];// bit, Rのヒット、Bのヒット、最小値\n for _ in 0..n {\n let mut next = std::collections::BTreeMap::new();\n for (bit, x, y, v) in now {\n// println!(\"{} {} {} {}\", bit, x, y, v);\n let rem_a = v - sum[bit].1 + x;\n let rem_b = v - sum[bit].2 + y;\n for (i, &(_, a, b)) in p.iter().enumerate() {\n if bit >> i & 1 == 1 {\n continue;\n }\n let mut x = x;\n let mut y = y;\n let mut add = 0;\n let mut p = max(0, a - rem_a);\n if p > 0 {\n x += std::cmp::min(p, sum[bit].0[0]);\n p -= sum[bit].0[0];\n }\n add = max(add, p);\n let mut p = max(0, b - rem_b);\n if p > 0 {\n y += std::cmp::min(p, sum[bit].0[1]);\n p -= sum[bit].0[1];\n }\n add = max(add, p);\n let v = v + add;\n let po = next.entry((bit | (1 << i), x, y)).or_insert(v);\n *po = std::cmp::min(*po, v);\n }\n }\n let mut a = vec![];\n for ((bit, x, y), v) in next {\n a.push((bit, x, y, v));\n }\n now = a;\n }\n let ans = now.into_iter().map(|p| p.3).min().unwrap() + n as i32;\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "//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\n//\n\n// ---------- 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 if *self > x {\n *self = x;\n true\n } else {\n false\n }\n }\n fn chmax(&mut self, x: Self) -> bool {\n if *self < x {\n *self = x;\n true\n } else {\n false\n }\n }\n}\n// ---------- end chmin, chmax ----------\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, i32, i32); n],\n }\n let mut p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, p.1, p.2))\n .collect::>();\n let mut add = 0;\n for p in p.iter_mut() {\n let n = n as i32;\n let mut v = 0;\n v.chmax(p.1 - n);\n v.chmax(p.2 - n);\n add += v;\n p.1.chmin(n);\n p.2.chmin(n);\n }\n let mut sum = vec![[0i32; 2]];\n for &(x, _, _) in p.iter() {\n for i in 0..sum.len() {\n let mut a = sum[i];\n a[x] += 1;\n sum.push(a);\n }\n }\n let inf = std::i32::MAX / 2;\n let mut dp_a = std::collections::BTreeMap::new();\n let mut dp_b = std::collections::BTreeMap::new();\n dp_a.insert((0, 0), 0);\n dp_b.insert((0, 0), 0);\n for _ in 0..n {\n let mut next_a = std::collections::BTreeMap::new();\n let mut next_b = std::collections::BTreeMap::new();\n for ((bit, rem), v) in dp_a {\n let sum = sum[bit];\n for (i, &(_, a, b)) in p.iter().enumerate() {\n if bit >> i & 1 == 1 {\n continue;\n }\n let k = bit | (1 << i);\n let a = max(0, a - sum[0]);\n let b = max(0, b - sum[1]);\n if rem + b >= a {\n let x = rem + b - a;\n let po = next_a.entry((k, x)).or_insert(inf);\n po.chmin(v + b);\n } else {\n let x = a - (rem + b);\n let po = next_b.entry((k, x)).or_insert(inf);\n po.chmin(v + b + x);\n }\n }\n }\n for ((bit, rem), v) in dp_b {\n let sum = sum[bit];\n for (i, &(_, a, b)) in p.iter().enumerate() {\n if bit >> i & 1 == 1 {\n continue;\n }\n let k = bit | (1 << i);\n let a = max(0, a - sum[0]);\n let b = max(0, b - sum[1]);\n if rem + a >= b {\n let x = rem + a - b;\n let po = next_b.entry((k, x)).or_insert(inf);\n po.chmin(v + a);\n } else {\n let x = b - (rem + a);\n let po = next_a.entry((k, x)).or_insert(inf);\n po.chmin(v + a + x);\n }\n }\n }\n dp_a = next_a;\n dp_b = next_b;\n }\n let ans = add + dp_a.values().chain(dp_b.values()).cloned().min().unwrap() + n as i32;\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "//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\n//\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, i32, i32); n],\n }\n let p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, p.1, p.2))\n .collect::>();\n let mut sum = vec![([0, 0], 0, 0)];\n for &(x, y, z) in p.iter() {\n for i in 0..sum.len() {\n let (mut a, mut b, mut c) = sum[i];\n a[x] += 1;\n b += y;\n c += z;\n sum.push((a, b, c));\n }\n }\n let inf = std::i32::MAX / 2;\n let mut dp = vec![vec![vec![inf; 1 << n]; n + 1]; n + 1];\n dp[0][0][0] = 0;\n for i in 0..=n {\n for j in 0..=n {\n for k in 0..(1 << n) {\n let v = dp[i][j][k];\n if v == inf {\n continue;\n }\n let rem = [v - sum[k].1, v - sum[k].2];\n for (l, p) in p.iter().enumerate() {\n if k >> l & 1 == 1 {\n continue;\n }\n let mut add = 0;\n add = max(add, p.1 - rem[0] - i as i32);\n add = max(add, p.2 - rem[1] - j as i32);\n let bit = k | (1 << l);\n if p.0 == 0 {\n dp[i + 1][j][bit] = std::cmp::min(dp[i + 1][j][bit], v + add);\n } else {\n dp[i][j + 1][bit] = std::cmp::min(dp[i][j + 1][bit], v + add);\n }\n }\n }\n }\n }\n let mut ans = inf;\n for dp in dp {\n for dp in dp {\n ans = std::cmp::min(ans, dp[(1 << n) - 1]);\n }\n }\n ans += n as i32;\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "//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\n//\n\nuse std::cmp::*;\n\nfn run() {\n input! {\n n: usize,\n p: [(chars, i32, i32); n],\n }\n let p = p\n .into_iter()\n .map(|p| ((p.0[0] == 'B') as usize, p.1, p.2))\n .collect::>();\n let mut sum = vec![([0, 0], 0, 0)];\n for &(x, y, z) in p.iter() {\n for i in 0..sum.len() {\n let (mut a, mut b, mut c) = sum[i];\n a[x] += 1;\n b += y;\n c += z;\n sum.push((a, b, c));\n }\n }\n let inf = std::i32::MAX / 2;\n let mut dp = vec![vec![vec![inf; 1 << n]; n + 1]; n + 1];\n dp[0][0][0] = 0;\n for i in 0..=n {\n for j in 0..=n {\n for k in 0..(1 << n) {\n let v = dp[i][j][k];\n if v == inf {\n continue;\n }\n let rem = [v - sum[k].0[0], v - sum[k].0[1]];\n for (l, p) in p.iter().enumerate() {\n if k >> l & 1 == 1 {\n continue;\n }\n let mut add = 0;\n add = max(add, p.1 - rem[0] - i as i32);\n add = max(add, p.2 - rem[1] - j as i32);\n let bit = k | (1 << l);\n if p.0 == 0 {\n dp[i + 1][j][bit] = std::cmp::min(dp[i + 1][j][bit], v + add);\n } else {\n dp[i][j + 1][bit] = std::cmp::min(dp[i][j + 1][bit], v + add);\n }\n }\n }\n }\n }\n let mut ans = inf;\n for dp in dp {\n for dp in dp {\n ans = std::cmp::min(ans, dp[(1 << n) - 1]);\n }\n }\n ans += n as i32;\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}], "src_uid": "25a77f2b7cb281ff3c7800a20b3e5969"} {"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 main() {\n input! {\n s: chars,\n ts: [chars; 5],\n }\n let mut res = false;\n for i in 0..5 {\n if s[0] == ts[i][0] || s[1] == ts[i][1] {\n res = true;\n }\n }\n println!(\"{}\", ite!(res, \"YES\", \"NO\"));\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", "positive_code": [{"source_code": "fn main() {\n let mut card_on_table = String::new();\n std::io::stdin().read_line(&mut card_on_table).expect(\"CARD_ON_TABLE::Read line failed!\");\n\n let mut cards_in_hand = String::new();\n std::io::stdin().read_line(&mut cards_in_hand).expect(\"CARDS_IN_HAND::Read line failed!\");\n\n let mut card = card_on_table.trim().chars();\n let suit = card.next().expect(\"SUIT::Not exist next char!\");\n let rank = card.next().expect(\"RANK::Not exist next char!\");\n\n let can_play = cards_in_hand.contains(suit) || cards_in_hand.contains(rank);\n\n match can_play {\n true => println!(\"YES\"),\n false => println!(\"NO\"),\n }\n}"}, {"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\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 card = readln!();\n let card: Vec = card.chars().collect();\n\n let cards = readvec!(String);\n let cards: Vec> = cards.iter().map(|c| c.chars().collect()).collect();\n let mut ans = false;\n for current_card in cards {\n if current_card[0] == card[0] || current_card[1] == card[1] {\n ans = true;\n }\n }\n\n println!(\"{}\", if ans { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "#[derive(Debug, Copy, Clone, PartialEq)]\nenum CardSuit {\n Diamonds,\n Clubs,\n Spades,\n Hearts,\n Unknown,\n}\n\nimpl<'a> From<&'a str> for CardSuit {\n fn from(input: &'a str) -> CardSuit {\n match input {\n \"D\" => CardSuit::Diamonds,\n \"C\" => CardSuit::Clubs,\n \"S\" => CardSuit::Spades,\n \"H\" => CardSuit::Hearts,\n _ => CardSuit::Unknown,\n }\n }\n}\n\n#[derive(Debug, Copy, Clone, PartialEq)]\nenum CardRank {\n Two,\n Three,\n Four,\n Five,\n Six,\n Seven,\n Eight,\n Nine,\n T,\n J,\n Q,\n K,\n A,\n Unknown,\n}\n\nimpl<'a> From<&'a str> for CardRank {\n fn from(input: &'a str) -> CardRank {\n match input {\n \"2\" => CardRank::Two,\n \"3\" => CardRank::Three,\n \"4\" => CardRank::Four,\n \"5\" => CardRank::Five,\n \"6\" => CardRank::Six,\n \"7\" => CardRank::Seven,\n \"8\" => CardRank::Eight,\n \"9\" => CardRank::Nine,\n \"T\" => CardRank::T,\n \"J\" => CardRank::J,\n \"Q\" => CardRank::Q,\n \"K\" => CardRank::K,\n \"A\" => CardRank::A,\n _ => CardRank::Unknown,\n }\n }\n}\n\n#[derive(Debug, Copy, Clone)]\nstruct Card {\n suit: CardSuit,\n rank: CardRank,\n}\n\nimpl Card {\n pub fn playable(&self, other: &Card) -> bool {\n self.rank == other.rank || self.suit == other.suit\n }\n}\n\nimpl<'a> From<&'a str> for Card {\n fn from(input: &'a str) -> Card {\n Card {\n suit: CardSuit::from(&input[1..2]),\n rank: CardRank::from(&input[0..1]),\n }\n }\n}\n\nfn main() -> std::io::Result<()> {\n let mut table_input = String::default();\n std::io::stdin().read_line(&mut table_input)?;\n let table_card = Card::from(table_input.as_str());\n // println!(\"Table card: {:?}\", table_card);\n\n let mut hand_input = String::default();\n std::io::stdin().read_line(&mut hand_input)?;\n let hand_cards = hand_input\n .split(\" \")\n .into_iter()\n .map(|x| Card::from(x))\n .collect::>();\n // println!(\"Hand cards: {:#?}\", hand_cards);\n\n let mut can_play = false;\n\n for card in &hand_cards {\n if card.playable(&table_card) {\n can_play = true;\n }\n }\n\n match can_play {\n true => println!(\"YES\"),\n false => println!(\"NO\"),\n }\n\n Ok(())\n}\n"}, {"source_code": "// First letter {2,3,4,5,6,7,8,9,T,J,Q,K,A}\n// second letter {D,C,S,H}\nuse std::io::stdin;\n\nfn main() {\n let mut table = String::new();\n let mut hand = String::new();\n let _ = stdin().read_line(&mut table);\n let _ = stdin().read_line(&mut hand);\n table = table.trim().to_string();\n hand = hand.trim().to_string();\n\n let mut response = \"NO\";\n for tab in table.chars() {\n for h in hand.chars() {\n if h == tab {\n response = \"YES\";\n break;\n }\n }\n }\n\n println!(\"{}\", response);\n\n // println!(\"The table is {}\", table);\n // println!(\"The hand is {}\", hand);\n}\n"}, {"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 s = input.s();\n println!(\"{}\", if (0..5).any(|_| {\n let t = input.s();\n s.bytes().zip(t.bytes()).any(|(a,b)| a == b)\n }) {\n \"YES\"\n } else {\n \"NO\"\n });\n}\n\n"}, {"source_code": "use std::io;\n\nfn can_play(table: &str, hand: Vec<&str>) -> &'static str {\n for card in hand.iter() {\n let mut table_chars = table.chars();\n let mut card_chars = card.chars();\n\n if table_chars.nth(0).unwrap() == card_chars.nth(0).unwrap()\n || table_chars.nth(0).unwrap() == card_chars.nth(0).unwrap()\n {\n return \"YES\";\n }\n }\n\n \"NO\"\n}\n\npub fn solution() -> io::Result<()> {\n let mut table = String::new();\n let mut hand = String::new();\n\n io::stdin().read_line(&mut table)?;\n io::stdin().read_line(&mut hand)?;\n let hand: Vec<&str> = hand.trim().split(\" \").collect();\n\n println!(\"{}\", can_play(&table, hand));\n Ok(())\n}\n\nfn main() {\n solution();\n}\n"}, {"source_code": "macro_rules! debug {\n ( $x:expr ) => {\n if cfg!(debug_assertions) {\n println!(\"{}:{} {} = {:?}\", line!(), column!(), stringify!($x), $x);\n }\n };\n}\n\nmacro_rules! array {\n ( $t:ty ; $size:expr ) => {\n [<$t>::default(); $size]\n };\n}\n\nmod my {\n pub mod io {\n use std::io::{BufRead, ErrorKind};\n\n pub fn read_word(r: &mut R, buf: &mut Vec)\n -> std::io::Result {\n let mut read = 0;\n loop {\n let (done, used) = {\n let available = match r.fill_buf() {\n Ok(n) => n,\n Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,\n Err(e) => return Err(e)\n };\n match available.iter().position(|&x| x == b'\\n' || x == b' ') {\n Some(i) => {\n buf.extend_from_slice(&available[..i]);\n (true, i + 1)\n }\n None => {\n buf.extend_from_slice(available);\n (false, available.len())\n }\n }\n };\n r.consume(used);\n read += used;\n if done || used == 0 {\n return Ok(read);\n }\n }\n }\n\n pub struct InputReader {\n reader: R,\n buf: Vec,\n }\n\n impl InputReader {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf: Vec::::new(),\n }\n }\n\n pub fn read_word(&mut self) {\n read_word(&mut self.reader, &mut self.buf);\n }\n \n pub fn read(&mut self) -> T\n where T: std::str::FromStr,\n T::Err: std::fmt::Debug\n {\n self.buf.clear();\n self.read_word();\n std::str::from_utf8(&self.buf).unwrap().trim().parse().unwrap()\n }\n }\n }\n}\n\nfn main() {\n let stdin = std::io::stdin();\n let mut stdin = my::io::InputReader::new(stdin.lock());\n\n let table: String;\n let mut hands = Vec::::new();\n\n table = stdin.read();\n for i in 0..5 {\n hands.push(stdin.read());\n }\n\n let mut result = false;\n for i in 0..5 {\n if table.bytes().zip(hands[i].bytes()).any(|(x, y)| x == y) {\n result = true;\n break;\n }\n }\n println!(\"{}\", if result { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let l1 = read_line();\n let l2 = read_line();\n\n let lb1 = l1.as_bytes();\n let r = l2.split(' ').any(|c| {\n let c = c.as_bytes();\n if c[0] == lb1[0] || c[1] == lb1[1] {\n true\n } else {\n false\n }\n });\n println!(\"{}\", match r {\n true => \"YES\",\n false => \"NO\"\n });\n}\n\nfn read_line() -> String {\n let mut line = String::new();\n\n io::stdin().read_line(&mut line).unwrap();\n let l1 = line.trim();\n l1.to_string()\n}\n"}, {"source_code": "use std::io::{BufReader, BufRead};\n\nfn main() -> Result<(), Box> {\n let mut lines = BufReader::new(std::io::stdin())\n .lines()\n .map(Result::unwrap);\n\n let hand = lines.next().unwrap();\n let rank = &hand[0..1];\n let suit = &hand[1..2];\n\n for card in lines.next().unwrap().split_whitespace().take(5) {\n if rank == &card[0..1] || suit == &card[1..2] {\n println!(\"YES\");\n return Ok(())\n }\n }\n\n println!(\"NO\");\n Ok(())\n}\n"}, {"source_code": "use std::io;\n\nfn get_line() -> io::Result {\n\tlet mut buffer = String::new();\n\tio::stdin().read_line(&mut buffer)?;\n\tOk(buffer)\n}\n\nfn main() {\n\tlet input = get_line().unwrap();\n\tlet card = input.trim().as_bytes();\n\tlet input = get_line().unwrap();\n\tlet hand: Vec<&[u8]> = input.split_whitespace().map(|s| s.as_bytes()).collect();\n\tlet mut play = \"NO\";\n\tfor i in 0..hand.len() {\n\t\tif card[0] == hand[i][0] || card[1] == hand[i][1] {\n\t\t\tplay = \"YES\";\n\t\t\tbreak;\n\t\t}\n\t}\n\tprint!(\"{}\", play);\n}\n"}, {"source_code": "fn main() {\n let mut card = String::new();\n std::io::stdin().read_line(&mut card)\n .expect(\"Error input\");\n let card_chars: Vec = card.chars().collect();\n let mut hand = String::new();\n std::io::stdin().read_line(&mut hand)\n .expect(\"Error input\");\n let hand_chars: Vec> = hand.split(' ').map(|s| s.chars().collect()).collect();\n\n for c in hand_chars {\n if c[0] == card_chars[0] || c[1] == card_chars[1] {\n println!(\"YES\");\n std::process::exit(0);\n }\n }\n println!(\"NO\");\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let card_on_desk = {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf\n };\n let cards = {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf\n };\n\n if cards.split_whitespace().any(|card| {\n card.as_bytes()[0] == card_on_desk.as_bytes()[0]\n || card.as_bytes()[1] == card_on_desk.as_bytes()[1]\n }) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let stdin = io::stdin();\n\n let card_on_desk = {\n let mut read_buf = String::new();\n stdin.read_line(&mut read_buf).unwrap();\n read_buf.trim().to_string()\n };\n\n let cards = {\n let mut read_buf = String::new();\n stdin.read_line(&mut read_buf).unwrap();\n read_buf\n };\n\n if cards.split_whitespace().any(|card| {\n card.as_bytes()[0] == card_on_desk.as_bytes()[0]\n || card.as_bytes()[1] == card_on_desk.as_bytes()[1]\n }) {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}\n"}, {"source_code": "fn main() {\n let mut cin = io::Input::new();\n\n let s= cin.next_ascii_string();\n\n for _ in 1..=5 {\n let t = cin.next_ascii_string();\n if s[0] == t[0] || s[1] == t[1] {\n println!(\"YES\");\n return;\n }\n }\n\n println!(\"NO\");\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"}, {"source_code": "#![allow(dead_code, unused_imports)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn partial_sum(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + std::ops::Add + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = *state + x;\n Some(*state)\n })\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != 0 {\n let old_m = a;\n a = b % a;\n b = old_m;\n }\n b\n}\n\n/// returns gcd, and pair (x, y), such that x * a + b * y == gcd\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if a == 0 {\n (b, 0, 1)\n } else {\n let (g, x, y) = egcd(b % a, a);\n (g, y - (b / a) * x, x)\n }\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n if n == 0 {\n return vec![0];\n } else if n == 1 {\n return vec![1];\n }\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nfn abs_diff(a: T, b: T) -> T\nwhere\n T: PartialOrd + std::ops::Sub,\n{\n if a > b {\n a - b\n } else {\n b - a\n }\n}\n\nstruct Permutations {\n inner: Vec,\n state: Vec,\n i: usize,\n start: bool,\n}\n\nimpl Permutations {\n fn new(inner: Vec) -> Self {\n Self {\n state: vec![0; inner.len()],\n i: 0,\n start: true,\n inner,\n }\n }\n}\n\n/*impl From for Permutations\nwhere\n X: IntoIterator,\n{\n fn from(f: X) -> Self {\n Self::new(f.into_iter().collect::>())\n }\n}*/\n\nimpl Iterator for Permutations\nwhere\n T: Clone,\n{\n type Item = Vec;\n fn next(&mut self) -> Option {\n if self.start {\n self.start = false;\n return Some(self.inner.clone());\n }\n while self.i < self.inner.len() {\n if self.state[self.i] < self.i {\n if self.i % 2 == 0 {\n self.inner.swap(0, self.i)\n } else {\n self.inner.swap(self.state[self.i], self.i)\n }\n self.state[self.i] += 1;\n self.i = 0;\n return Some(self.inner.clone());\n } else {\n self.state[self.i] = 0;\n self.i += 1;\n }\n }\n None\n }\n}\n\nuse std::cmp::{max, min, Ord, Ordering};\nuse std::collections::{BinaryHeap, VecDeque};\nuse std::mem::swap;\n\n#[derive(Clone)]\nstruct Graph {\n nodes: usize,\n edges: Vec>,\n}\n\nimpl Graph {\n fn new(n: usize) -> Self {\n Self {\n nodes: n,\n edges: vec![Vec::new(); n + 1],\n }\n }\n\n fn add_edge(&mut self, x: usize, y: usize, cost: u64) {\n self.edges[x].push((y, cost));\n self.edges[y].push((x, cost));\n }\n\n fn dijkstra(&mut self, start: usize, end: usize) -> u64 {\n let mut dist = vec![None; self.nodes + 1];\n let mut prev = vec![None; self.nodes + 1];\n dist[start] = Some(0);\n let mut queue = (1..=self.nodes).collect::>();\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n while let Some(next_node) = queue.pop() {\n if next_node == end {\n return dist[next_node].unwrap();\n }\n for (neighbour, cost) in self.edges[next_node].iter() {\n let alt = dist[next_node].unwrap() + cost;\n if dist[*neighbour].is_none() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n } else {\n if alt < dist[*neighbour].unwrap() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n }\n }\n }\n //println!(\"{:?} {:?}\", dist, prev);\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n }\n 0\n }\n\n fn set_cost(&mut self, x: usize, y: usize, cost: u64) {\n for i in 0..self.edges[x].len() {\n if self.edges[x][i].0 == y {\n self.edges[x][i].1 = cost\n }\n }\n for i in 0..self.edges[y].len() {\n if self.edges[y][i].0 == x {\n self.edges[y][i].1 = cost\n }\n }\n }\n}\n\nfn main() -> Result<(), Box> {\n let table = read_stdin();\n let hand = read_stdin();\n if hand.split(' ').any(|h| {\n h.chars().nth(0).unwrap() == table.chars().nth(0).unwrap()\n || h.chars().nth(1).unwrap() == table.chars().nth(1).unwrap()\n }) {\n println!(\"YES\")\n } else {\n println!(\"NO\")\n }\n Ok(())\n}\n"}, {"source_code": "use std::io;\nuse std::io::prelude::*;\n\nfn main() {\n\tlet stdin = io::stdin();\n\tlet desk_card = stdin.lock().lines().next().unwrap().unwrap();\n\tlet my_cards = stdin.lock().lines().next().unwrap().unwrap();\n\n\n\tlet mut card = String::new();\n\tlet mut status: bool = false;\n\n\tfor c in my_cards.chars() {\n\t\tif c != ' ' {\n\t\t\tcard.push(c);\n\t\t}\n\n\t\tif card.len() == 2 {\n\t\t\tif &desk_card[0..1] == &card[0..1] {\n\t\t\t\tstatus = true;\n\t\t\t}\n\t\t\tif &desk_card[1..2] == &card[1..2] {\n\t\t\t\tstatus = true;\n\t\t\t}\n\t\t\tcard.clear();\n\t\t}\n\n\t\tif status { \n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif status { \n\t\tprintln!(\"{}\", \"YES\");\n\t} else {\n\t\tprintln!(\"{}\", \"NO\");\n\t}\n}"}, {"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 x: chars,\n my_cards: [chars; 5],\n }\n let mut can = false;\n for card in my_cards {\n if card[0] == x[0] || card[1] == x[1] {\n can = true;\n break;\n }\n }\n if can {\n println!(\"YES\");\n } else {\n println!(\"NO\");\n }\n}"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut table = String::new();\n\tio::stdin().read_line(&mut table).expect(\"Time to panic\");\n\tlet table=table.trim();\n\tlet mut hand = String::new();\n\tio::stdin().read_line(&mut hand).expect(\"Time to panic\");\n\tlet hand = hand.trim().split(' ');\n\tlet mut possible = false;\n\tfor card in hand {\n\t\tlet card: Vec = card.chars().collect();\n\t\tlet table: Vec = table.chars().collect();\n\t\tif card[0] == table[0] || card[1] == table[1] {\n\t\t\tpossible = true;\n\t\t}\n\t}\n\tif possible {\n\t\tprintln!(\"YES\");\n\t} else {\n\t\tprintln!(\"NO\");\n\t}\n}\n"}, {"source_code": "use std::io::{self, BufRead, BufWriter, StdinLock, Write};\n\nfn main() {\n let (stdin, stdout) = (io::stdin(), io::stdout());\n let mut scan = stdin.lock();\n let mut out = BufWriter::new(stdout.lock());\n\n let table = scan.next();\n let hand = scan.next();\n\n writeln!(\n out,\n \"{}\",\n if {\n let bytes = table.as_bytes();\n hand.contains(bytes[0] as char) || hand.contains(bytes[1] as char)\n } {\n \"YES\"\n } else {\n \"NO\"\n }\n )\n .ok();\n}\n\ntrait Scan {\n fn next(&mut self) -> String;\n}\n\nimpl<'a> Scan for StdinLock<'a> {\n fn next(&mut self) -> String {\n let mut buf = String::with_capacity(15);\n self.read_line(&mut buf).unwrap();\n return buf;\n }\n}\n"}, {"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 mine = scan.next::();\n let mine = mine.as_bytes();\n let table: Vec = scan.next_n(5);\n let mut result = false;\n for card in table.into_iter() {\n let x = card.as_bytes();\n if x[0] == mine[0] || x[1] == mine[1] {\n result = true;\n break;\n }\n }\n println!(\"{}\", if result { \"YES\" } else { \"NO\" });\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"}, {"source_code": "use std::io::stdin;\n\nfn main()\n{\n //handle input / output\n let mut s = String::new();\n stdin().read_line(&mut s).unwrap();\n let card: Vec<_> = s.split_whitespace().collect();\n let card = card[0].clone().chars().collect::>();\n let mut s = String::new();\n stdin().read_line(&mut s).unwrap();\n let deck: Vec<_> = s.split_whitespace().collect();\n let deck = deck.iter().map( |c| c.chars().collect::>()).collect::>();\n\n for dc in deck {\n if dc[0] == card[0] || dc[1] == card[1] {\n println!(\"YES\");\n return;\n }\n }\n\n println!(\"NO\");\n}"}, {"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 a: Vec<_> = parse_line!(String).bytes().collect();\n let mut result = false;\n for s in parse_line!(String).split_whitespace() {\n for (j, c) in s.bytes().enumerate() {\n result |= c == a[j];\n }\n }\n if result {\n writeln!(writer, \"YES\").unwrap()\n }else{\n writeln!(writer, \"NO\").unwrap()\n }\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n let mut writer = std::io::BufWriter::new(std::io::stdout());\n for _ in 0..tests {\n solve(&mut writer);\n }\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\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 out = &mut BufWriter::new(stdout());\n\n let f = |s1:&str, s2:&str| s1.chars().nth(0) == s2.chars().nth(0) || s1.chars().nth(1) == s2.chars().nth(1);\n let s1: String = scan.next::();\n\n for _ in 0..5\n {\n let s2: String = scan.next::();\n if f(s1.as_ref(), s2.as_ref())\n {\n write!(out, \"YES\").ok();\n return;\n }\n }\n write!(out, \"NO\").ok();\n}"}, {"source_code": "use std::io;\n\nfn main() -> io::Result<()> {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)?;\n\n let table: Vec = input.trim().chars().collect();\n input.clear();\n\n io::stdin().read_line(&mut input)?;\n\n let hand :Vec> = input.trim().split(' ').map(|x| x.chars().collect()).collect();\n\n let mut yes = false;\n for i in 0..5 {\n if hand[i][0] == table[0] {\n yes = true;\n }\n if hand[i][1] == table[1] {\n yes = true;\n }\n }\n\n if yes {\n print!(\"YES\");\n } else {\n print!(\"NO\");\n }\n\n Ok(())\n}"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut table = String::new();\n let mut hand = String::new();\n\n stdin.lock().read_line(&mut table).unwrap();\n stdin.lock().read_line(&mut hand).unwrap();\n\n let table = table.as_bytes();\n let hand = hand.trim().split(\" \");\n for card in hand {\n let card = card.as_bytes();\n if card[0] == table[0] || card[1] == table[1] {\n println!(\"YES\");\n return;\n }\n }\n println!(\"NO\");\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut ti = String::new();\n io::stdin().read_line(&mut ti).unwrap();\n let mut hi = String::new();\n io::stdin().read_line(&mut hi).unwrap();\n\n\n let t = ti.as_bytes();\n let h: Vec<&str> = hi.split_terminator(\" \").collect();\n for i in 0..5 {\n let h = h[i].as_bytes();\n if (h[1] == t[1]) || (h[0] == t[0]) {\n println!(\"YES\");\n return;\n } \n }\n println!(\"NO\");\n}"}, {"source_code": "use std::io::stdin;\n\nfn main() {\n let mut input1 = String::new();\n stdin().read_line(&mut input1).unwrap();\n let mut input2 = String::new();\n stdin().read_line(&mut input2).unwrap();\n\n for x in input2.split_whitespace() {\n if x[0..1] == *input1[0..1].trim() || x[1..] == *input1[1..].trim() {\n println!(\"YES\");\n return;\n }\n }\n\n println!(\"NO\");\n}\n"}], "negative_code": [{"source_code": "fn main() {\n let str = \"010\";\n let trimmed = str.trim();\n let mut negative = false;\n let mut lookup = &trimmed[..];\n if trimmed.starts_with('-') {\n negative = true;\n lookup = &trimmed[1..];\n }\n if trimmed.starts_with('+') {\n negative = false;\n lookup = &trimmed[1..];\n }\n \n let digits = lookup.chars().take_while(|c| c.is_digit(10)).collect::>();\n let mut answer: i64 = 0;\n\n for d in digits.iter().map(|c| c.to_digit(10).unwrap()) {\n answer *= 10;\n\n answer += match negative {\n true => -1 * d as i64,\n false => d as i64,\n };\n\n if answer >= i32::max_value().into() {\n answer = i32::max_value() as i64;\n break;\n }\n if answer <= i32::min_value().into() {\n answer = i32::min_value() as i64;\n break;\n }\n }\n \n println!(\"{}\", answer);\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn main()\n{\n //handle input / output\n let mut s = String::new();\n stdin().read_line(&mut s).unwrap();\n let card: Vec<_> = s.split_whitespace().collect();\n let card = card[0].clone().chars().collect::>();\n let mut s = String::new();\n stdin().read_line(&mut s).unwrap();\n let deck: Vec<_> = s.split_whitespace().collect();\n let deck = deck.iter().map( |c| c.chars().collect::>()).collect::>();\n\n for dc in deck {\n if dc[0] == card[0] || dc[1] == card[1] {\n println!(\"YES\");\n return;\n }\n }\n\n println!(\"N\");\n}"}], "src_uid": "699444eb6366ad12bc77e7ac2602d74b"} {"source_code": "use std::io::{self, BufRead};\nuse std::fs;\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock()\n .lines()\n .next()\n .expect(\"there was no next line\")\n .expect(\"the line could not be read\");\n\n let numbers: Vec<_> = line.split(\" \").collect();\n let v: i32 = numbers[0].parse().unwrap();\n// let b: i32 = numbers[1].parse().unwrap();\n\n println!(\"{}\", if v == 2 {2} else {1});\n}\n\n//fn main() {\n// let mut line = String::new();\n// let stdin = io::stdin();\n// stdin.lock().read_line(&mut line).expect(\"Could not read line\");\n// println!(\"{}\", line)\n//}\n\n/*\nfn main() {\n let stdin = io::stdin();\n let lines: Vec = stdin.lock().lines().map(|x| x.unwrap()).collect();\n\n let line = &lines[0];\n\n// let data = fs::read_to_string(\"test\").expect(\"Unable to read file\");\n// println!(\"{}\", data);\n\n\n let numbers: Vec<_> = line.split(\" \").collect();\n let a: i32 = numbers[0].parse().unwrap();\n let b: i32 = numbers[1].parse().unwrap();\n\n println!(\"{}\", a + b);\n}\n\n*/", "positive_code": [{"source_code": "use std::cell::RefCell;\nuse std::io::{self, Read};\nuse std::iter::FromIterator;\n\n#[allow(dead_code)]\nstruct Source {\n chars: Box>,\n}\n\n#[allow(dead_code)]\nimpl Source {\n fn next_chr(&mut self) -> char {\n self.chars\n .by_ref()\n .skip_while(|c| char::is_whitespace(*c))\n .next()\n .expect(\"eof\")\n }\n\n fn next_str(&mut self) -> String {\n let it = self\n .chars\n .by_ref()\n .skip_while(|c| char::is_whitespace(*c))\n .take_while(|c| !char::is_whitespace(*c));\n let s = String::from_iter(it);\n if s.is_empty() {\n panic!(\"eof\")\n } else {\n s\n }\n }\n\n fn from_stdin() -> Self {\n let mut data = String::new();\n io::stdin().read_to_string(&mut data).expect(\"Input error\");\n Self::from_str(&data)\n }\n\n fn from_str(s: &str) -> Self {\n let data = String::from(s);\n let chars = data.chars().collect::>().into_iter();\n Source {\n chars: Box::new(chars),\n }\n }\n}\n\nthread_local!(static SRC: RefCell = RefCell::new(Source::from_stdin()));\n\n#[allow(unused_macros)]\nmacro_rules! input {\n ($($elem:tt)*) => {\n input_inner!(SRC, $($elem)*)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! input_inner {\n ($src:expr) => {};\n ($src:expr,) => {};\n ($src:expr, $var:ident : mut $ty:tt $($rest:tt)*) => {\n let mut $var = $src.with(|src| {\n let mut src = src.borrow_mut();\n parse!(src, $ty)\n });\n input_inner!($src $($rest)*)\n };\n ($src:expr, $var:ident : $ty:tt $($rest:tt)*) => {\n let $var = $src.with(|src| {\n let mut src = src.borrow_mut();\n parse!(src, $ty)\n });\n input_inner!($src $($rest)*)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! parse {\n ($src:expr, ( $($ty:tt),* )) => {\n ( $(parse!($src,$ty)),* )\n };\n ($src:expr, char) => {\n $src.next_chr()\n };\n ($src:expr, [ $ty:tt; $len:expr ]) => {\n (0..$len).map(|_| parse!($src,$ty)).collect::>()\n };\n ($src:expr, $ty:tt) => {\n parse_str!($src,$ty)\n };\n}\n\n#[allow(unused_macros)]\nmacro_rules! parse_str {\n ($src:expr, chars) => {\n $src.next_str().chars().collect::>()\n };\n ($src:expr, $ty:ty) => {\n $src.next_str().parse::<$ty>().expect(\"Parse error\")\n };\n}\n\nfn main() {\n input! { n: mut u32 }\n\n if n > 2 {\n println!(\"1\")\n } else {\n println!(\"{}\", n)\n }\n}"}, {"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 s: u32 = buffer.trim().parse().expect(\"invalid input\");\n\n println!(\"{}\", if s == 2 { 2 } else { 1 });\n}"}], "negative_code": [{"source_code": "use std::io::{self, BufRead};\nuse std::fs;\n\nfn main() {\n let stdin = io::stdin();\n let line = stdin.lock()\n .lines()\n .next()\n .expect(\"there was no next line\")\n .expect(\"the line could not be read\");\n\n let numbers: Vec<_> = line.split(\" \").collect();\n let v: i32 = numbers[0].parse().unwrap();\n// let b: i32 = numbers[1].parse().unwrap();\n\n println!(\"{}\", 1);\n}\n\n//fn main() {\n// let mut line = String::new();\n// let stdin = io::stdin();\n// stdin.lock().read_line(&mut line).expect(\"Could not read line\");\n// println!(\"{}\", line)\n//}\n\n/*\nfn main() {\n let stdin = io::stdin();\n let lines: Vec = stdin.lock().lines().map(|x| x.unwrap()).collect();\n\n let line = &lines[0];\n\n// let data = fs::read_to_string(\"test\").expect(\"Unable to read file\");\n// println!(\"{}\", data);\n\n\n let numbers: Vec<_> = line.split(\" \").collect();\n let a: i32 = numbers[0].parse().unwrap();\n let b: i32 = numbers[1].parse().unwrap();\n\n println!(\"{}\", a + b);\n}\n\n*/"}], "src_uid": "c30b372a9cc0df4948dca48ef4c5d80d"} {"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(s: String) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n s.split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn extended_euclid(a: i32, b: i32) -> (i32, i32, i32) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d, x, y) = extended_euclid(b, modulo(a, b));\n (d, y, x - a / b * y)\n }\n}\n\nfn modulo(a: i32, b: i32) -> i32 {\n let ret_val = a % b;\n if ret_val < 0 {\n ret_val + b\n } else {\n ret_val\n }\n}\n\nfn main() {\n let (a, b): (i32, i32) = {\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 )\n };\n \n let (c, d): (i32, i32) = {\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 )\n };\n\n let e = d - b;\n\n let (g, x, y) = extended_euclid(a, c);\n\n let ans = if e % g != 0 {\n -1\n } else {\n let x1 = x * e / g;\n let x2 = modulo(x1, c / g);\n\n let y1 = y * e / g;\n let y2 = modulo(-y1, a / g);\n\n max(b + x2 * a, d + y2 * c)\n };\n\n println!(\"{}\", ans);\n}\n", "positive_code": [{"source_code": "use std::io::{self, Read};\nuse std::cmp::min;\n\nfn read_line() -> Vec {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n return buf.trim().split(\" \")\n .map(|x| {x.parse::().unwrap() })\n .collect();\n}\n\nfn get_ans (a : i32, b : i32, c : i32, d : i32) -> i32{\n let ans = -1;\n \n for i in 0..101{\n for j in 0..101{\n if (a*i + b == c*j + d){\n return a*i + b;\n }\n }\n }\n \n return 0x3f3f3f3f;\n}\n\n\nfn main(){\n let mut line = read_line();\n let (a, b) = (line[0], line[1]);\n line = read_line();\n let (c, d) = (line[0], line[1]);\n \n let mut ans = 0x3f3f3f3f;\n\n ans = min (get_ans(c, d, a, b), get_ans(a, b, c, d));\n if (ans == 0x3f3f3f3f){\n println! (\"-1\");\n }\n else{\n println! (\"{}\", ans);\n }\n \n}\n"}, {"source_code": "fn gcd(mut x: usize, mut y: usize) -> usize {\n while y != 0 {\n let z = x%y;\n x = y;\n y = z;\n }\n x\n}\n\nfn lcm(x: usize, y: usize) -> usize {\n x * y / gcd(x, y)\n}\n\nfn main() {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n let mut line = line.split_whitespace();\n let a = line.next().unwrap().parse::().unwrap();\n let b = line.next().unwrap().parse::().unwrap();\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n let mut line = line.split_whitespace();\n let c = line.next().unwrap().parse::().unwrap();\n let d = line.next().unwrap().parse::().unwrap();\n\n let mut counter_one = 0;\n let mut counter_two = 0;\n let limit = lcm(a, c);\n loop {\n let (x, y) = (counter_one + b, counter_two + d);\n if x == y {\n println!(\"{}\", x);\n return;\n } else if x < y {\n counter_one += a;\n } else {\n counter_two += c;\n }\n if counter_one > limit && counter_two > limit {\n println!(\"-1\");\n return;\n }\n }\n}\n"}], "negative_code": [{"source_code": "use std::io::{self, Read};\n\nfn read_line() -> Vec {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n return buf.trim().split(\" \")\n .map(|x| {x.parse::().unwrap() })\n .collect();\n}\n\n\nfn main(){\n \n let mut line = read_line();\n let (a, b) = (line[0], line[1]);\n line = read_line();\n let (c, d) = (line[0], line[1]);\n \n let mut ans = -1;\n\n 'outer: for i in 1..101 {\n\n for j in 1..101 {\n if ((a*i + b) == (c*j + d)){\n ans = a*i + b;\n break 'outer;\n }\n }\n }\n\n println! (\"{}\", ans);\n}\n"}, {"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(s: String) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n s.split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn extended_euclid(a: i32, b: i32) -> (i32, i32, i32) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d, x, y) = extended_euclid(b, modulo(a, b));\n (d, y, x - a / b * y)\n }\n}\n\nfn modulo(a: i32, b: i32) -> i32 {\n let ret_val = a % b;\n if ret_val < 0 {\n ret_val + b\n } else {\n ret_val\n }\n}\n\nfn main() {\n let (a, b): (i32, i32) = {\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 )\n };\n \n let (c, d): (i32, i32) = {\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 )\n };\n\n let e = d - b;\n\n let (g, x, y) = extended_euclid(a, c);\n\n let ans = if e % g != 0 {\n -1\n } else {\n let x1 = x * e / g;\n let x2 = modulo(x1, c / g);\n b + x2 * a\n };\n\n println!(\"{}\", ans);\n}\n"}, {"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(s: String) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n s.split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn extended_euclid(a: i32, b: i32) -> (i32, i32, i32) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d, x, y) = extended_euclid(b, modulo(a, b));\n (d, y, x - a / b * y)\n }\n}\n\nfn modulo(a: i32, b: i32) -> i32 {\n if a < 0 {\n a % b + b\n } else {\n a % b\n }\n}\n\nfn main() {\n let (a, b): (i32, i32) = {\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 )\n };\n \n let (c, d): (i32, i32) = {\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 )\n };\n\n let e = d - b;\n\n let (g, x, y) = extended_euclid(a, c);\n\n let ans = if e % g != 0 {\n -1\n } else {\n let f = e / g;\n let x0 = x * f;\n let x1 = modulo(x0, c / g);\n a * x1 + b\n };\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\nuse std::str::FromStr;\n\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(s: String) -> Vec\n where T: FromStr,\n ::Err: std::fmt::Debug,\n{\n s.split_whitespace().map(|k| k.parse().unwrap()).collect()\n}\n\nfn extended_gcd(a: i32, b: i32) -> (i32, i32, i32) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d1, x1, y1) = extended_gcd(b, modulo(a, b));\n let (d, x, y) = (d1, y1, x1 - (a / b) * y1);\n (d, x, y)\n }\n}\n\nfn modulo(a: i32, b: i32) -> i32 {\n if a < 0 {\n a % b + b\n } else {\n a % b\n }\n}\n\nfn main() {\n let (a, b): (i32, i32) = {\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 )\n };\n\n let (c, d): (i32, i32) = {\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 )\n };\n\n let (g, x, y) = extended_gcd(a, c);\n\n let ans = if (b - d) % g == 0 {\n a * modulo(x * (d - b) / g, c) + b\n } else {\n -1\n };\n\n println!(\"{}\", ans);\n}\n"}], "src_uid": "158cb12d45f4ee3368b94b2b622693e7"} {"source_code": "#[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!(f32);\nimpl_scan_single!(f64);\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, guards: u32);\n scanln!(guests: String);\n let mut starts = vec![-1i32; 26];\n let mut ends = vec![-1i32; 26];\n for (i, &byte) in guests.as_bytes().iter().enumerate() {\n let idx = (byte - b'A') as usize;\n ends[idx] = i as i32;\n if starts[idx] == -1 { starts[idx] = i as i32; }\n }\n\n enum Event { Start(i32), End(i32) };\n let mut events: Vec = starts.into_iter().filter_map(|x| if x != -1 { Some(Event::Start(x)) } else { None })\n .chain(ends.into_iter().filter_map(|x| if x != -1 { Some(Event::End(x)) } else { None }))\n .collect();\n events.sort_by_key(|x| match *x {\n Event::Start(x) => x,\n Event::End(x) => x\n });\n let mut concurrent = 0;\n let mut max_concurrent = 0;\n for event in events {\n match event {\n Event::Start(_) => concurrent += 1,\n Event::End(_) => concurrent -= 1\n };\n max_concurrent = std::cmp::max(max_concurrent, concurrent);\n }\n println!(\"{}\", if max_concurrent > guards { \"YES\" } else { \"NO\" });\n}\n", "positive_code": [{"source_code": "fn read_line() -> String {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\n \"Could not read line\",\n );\n String::from(&line[..line.len() - 1])\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(\n &format!(concat!(\"Could not parse {} into \", stringify!($t)), token))\n }).collect::>()\n }};\n ($($t: ty),*) => {{\n let line = read_line();\n let mut iter = line.split_whitespace();\n let result = ($({\n let token = iter.next().expect(\"Not enough tokens\");\n <$t as std::str::FromStr>::from_str(token).expect(\n &format!(concat!(\"Could not parse {} into \", stringify!($t)), token))\n }),*);\n if let Some(token) = iter.next() {\n panic!(\"Unexpected token {}\", token);\n }\n result\n }};\n}\n\nfn main() {\n let (n, k) = read_line!(usize, usize);\n let s: Vec = read_line().chars().collect();\n let mut v = vec![0; s.len() + 1];\n for c in 'A' as u8..'Z' as u8 + 1 {\n let c = c as char;\n if let Some(i1) = s.iter().position(|x| *x == c) {\n let i2 = s.iter().rposition(|x| *x == c).unwrap() + 1;\n v[i1] += 1;\n v[i2] -= 1;\n }\n }\n let mut cur = 0;\n let mut ans = false;\n for &x in &v {\n cur += x;\n // println!(\"{}\", cur);\n if cur > k {\n ans = true;\n break;\n }\n }\n println!(\"{}\", if ans { \"YES\" } else { \"NO\" });\n}"}, {"source_code": "fn read_line() -> 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::collections::HashMap;\nuse std::collections::HashSet;\n\nfn main() {\n let (n, k) = read_line!(i32, usize);\n let s = read_line();\n let mut last_of: HashMap = HashMap::new();\n for (i, c) in s.chars().enumerate() {\n last_of.insert(c, i);\n }\n\n let mut ans = false;\n let mut open_doors = HashSet::new();\n for (i, c) in s.chars().enumerate() {\n open_doors.insert(c);\n if open_doors.len() > k {\n ans = true;\n }\n if last_of[&c] == i {\n open_doors.remove(&c);\n }\n }\n\n match ans {\n true => println!(\"YES\"),\n false => println!(\"NO\"),\n }\n}\n"}, {"source_code": "fn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n\n let (n, k) = (it.next().unwrap(), it.next().unwrap());\n \n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let input = input.trim();\n\n let mut last_poss = [0; 26];\n\n for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {\n last_poss[c as usize] = i;\n }\n\n let mut statuses = [0; 26];\n for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {\n statuses[c as usize] = 1;\n let cur_gc:usize = statuses.iter().fold(0, |acc, &x| acc + x);\n if cur_gc > k {\n println!(\"YES\");\n std::process::exit(0);\n }\n if i >= last_poss[c as usize] {\n statuses[c as usize] = 0;\n }\n }\n\n println!(\"NO\");\n}\n"}], "negative_code": [{"source_code": "#[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!(f32);\nimpl_scan_single!(f64);\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, guards: u32);\n scanln!(guests: String);\n let mut starts = vec![-1i32; 26];\n let mut ends = vec![-1i32; 26];\n for (i, &byte) in guests.as_bytes().iter().enumerate() {\n let idx = (byte - b'A') as usize;\n ends[idx] = i as i32;\n if starts[idx] == -1 { starts[idx] = i as i32; }\n }\n\n enum Event { Start(i32), End(i32) };\n let mut events: Vec = ends.into_iter().filter_map(|x| if x != -1 { Some(Event::End(x)) } else { None })\n .chain(starts.into_iter().filter_map(|x| if x != -1 { Some(Event::Start(x)) } else { None }))\n .collect();\n events.sort_by_key(|x| match *x {\n Event::Start(x) => x,\n Event::End(x) => x\n });\n let mut concurrent = 0;\n let mut max_concurrent = 0;\n for event in events {\n match event {\n Event::Start(_) => concurrent += 1,\n Event::End(_) => concurrent -= 1\n };\n max_concurrent = std::cmp::max(max_concurrent, concurrent);\n }\n println!(\"{}\", if max_concurrent > guards { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "#[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!(f32);\nimpl_scan_single!(f64);\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, guards: u32);\n scanln!(guests: String);\n let mut starts = vec![-1i32; 26];\n let mut ends = vec![-1i32; 26];\n for (i, &byte) in guests.as_bytes().iter().enumerate() {\n let idx = (byte - b'A') as usize;\n ends[idx] = i as i32;\n if starts[idx] == -1 { starts[idx] = i as i32; }\n }\n let mut max_overlaps = 0;\n for i in 0..26 {\n let here = starts[i];\n if here != -1 {\n let mut overlaps = 1;\n for j in 0..26 {\n if i != j && starts[j] != -1 {\n use std::mem;\n let (mut os, mut oe) = (starts[i], ends[i]);\n let (mut ts, mut te) = (starts[j], ends[j]);\n if os > ts {\n mem::swap(&mut os, &mut ts);\n mem::swap(&mut oe, &mut te);\n }\n if ts <= oe { overlaps += 1; }\n }\n }\n max_overlaps = std::cmp::max(max_overlaps, overlaps);\n }\n }\n println!(\"{}\", if max_overlaps > guards { \"YES\" } else { \"NO\" });\n}\n"}, {"source_code": "use std::collections::HashSet;\n\nfn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n\n let (n, k) = (it.next().unwrap(), it.next().unwrap());\n \n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let input = input.trim();\n\n let has_left: Vec<_> = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {\n state.insert(x.clone());\n Some(state.clone())\n }).collect();\n\n let has_right: Vec<_> = input.chars().rev().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {\n state.insert(x.clone());\n Some(state.clone())\n }).collect();\n\n let it = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap());\n let it = it.skip(1).take(n - 2).zip(has_left.iter().zip(&has_right));\n\n for (c, (left_set, right_set)) in it {\n let cur_gc = left_set.intersection(&right_set).filter(|&&x| x != c).count();\n if cur_gc >= k {\n println!(\"YES\");\n std::process::exit(0);\n }\n }\n println!(\"NO\");\n}\n"}, {"source_code": "fn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n\n let (n, k) = (it.next().unwrap(), it.next().unwrap());\n \n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let input = input.trim();\n\n let mut last_poss = [0; 26];\n\n for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {\n last_poss[c as usize] = i;\n }\n\n let mut statuses = [0; 26];\n for (i, c) in input.chars().map(|c| c.to_digit(36).unwrap() - 10).enumerate() {\n if i >= last_poss[c as usize] {\n statuses[c as usize] = 0;\n } else {\n statuses[c as usize] = 1;\n }\n let cur_gc:usize = statuses.iter().fold(0, |acc, &x| acc + x);\n if cur_gc > k {\n println!(\"YES\");\n std::process::exit(0);\n }\n }\n\n println!(\"NO\");\n}\n"}, {"source_code": "use std::collections::HashSet;\n\nfn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let mut it = input.split_whitespace().map(|x| x.parse::().unwrap());\n\n let (n, k) = (it.next().unwrap(), it.next().unwrap());\n \n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).unwrap();\n\n let input = input.trim();\n\n let has_left: Vec<_> = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {\n state.insert(x.clone());\n Some(state.clone())\n }).collect();\n\n let has_right: Vec<_> = input.chars().rev().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap()).scan(HashSet::new(), |state, x| {\n state.insert(x.clone());\n Some(state.clone())\n }).collect();\n\n let it = input.chars().map(|c| c.to_digit(36).unwrap() - 'A'.to_digit(36).unwrap());\n let it = it.skip(1).take(n - 2).zip(has_left.iter().zip(&has_right));\n\n println!(\"{:?}\\n{:?}\", has_left, has_right);\n\n for (c, (left_set, right_set)) in it {\n let cur_gc = left_set.intersection(&right_set).filter(|&&x| x != c).count();\n if cur_gc >= k {\n println!(\"YES\");\n std::process::exit(0);\n }\n }\n println!(\"NO\");\n}\n"}], "src_uid": "216323563f5b2dd63edc30cb9b4849a5"} {"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 bi(x: i64, n: i64, l0: i64, r0: i64) -> i64 {\n let mut left = l0;\n let mut right = r0;\n\n while right - left > 1 {\n let y = (left + right) / 2;\n if x * x + y * y <= n * n {\n left = y;\n } else {\n right = y;\n }\n }\n return left;\n}\n\nfn main() {\n let mut sc = Scanner::new();\n\n let n: i64 = sc.cin();\n\n if n == 0 {\n println!(\"1\");\n return;\n }\n\n let mut a = 0;\n let mut b = 0;\n\n let mut l0 = 0;\n let mut r0 = n + 1;\n for x in 0..n {\n let y = bi(x, n, l0, r0);\n l0 = max(0, y - 10);\n r0 = min(y + 10, n + 1);\n // trace!((x, y));\n if x < y {\n a += 1;\n } else if x == y {\n b += 1;\n break;\n } else {\n break;\n }\n }\n let ans = 4 * (a * 2 - 1 + b);\n println!(\"{}\", ans);\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", "positive_code": [{"source_code": "#![allow(unused_imports)]\nuse std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\nuse std::cmp::Ordering::{*};\n\n// I have no idea what I'm doing\n\nuse std::f64::consts::{PI};\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: i64 = scan.token();\n\n if n == 0 {\n return writeln!(out, \"1\");\n }\n\n let is_in = |i, j| i*i + j*j <= n*n;\n // Uncomment for a cool circle in your screen\n // for i in -n..=n {\n // for j in -n..=n {\n // write!(out, \"{}\", if is_in(i.abs(), j.abs()) { '+' }\n // else { '-' })?;\n // write!(out, \" \")?;\n // }\n // writeln!(out)?;\n // }\n\n let mut ans = 0;\n let mut y = n;\n for x in 0..=n {\n if is_in(x, y) {\n ans += 1;\n }\n while !is_in(x, y) {\n y -= 1;\n ans += 1;\n }\n }\n\n writeln!(out, \"{}\", (ans - 1) * 4)?;\n\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"}], "negative_code": [{"source_code": "#![allow(unused_imports)]\nuse std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\nuse std::cmp::Ordering::{*};\n\n// I have no idea what I'm doing\n\nuse std::f64::consts::{PI};\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: i64 = scan.token();\n\n let is_in = |i, j| i*i + j*j <= n*n;\n // Uncomment for a cool circle in your screen\n // for i in -n..=n {\n // for j in -n..=n {\n // write!(out, \"{}\", if is_in(i.abs(), j.abs()) { '+' }\n // else { '-' })?;\n // write!(out, \" \")?;\n // }\n // writeln!(out)?;\n // }\n\n let mut ans = 0;\n let mut y = n;\n for x in 0..=n {\n if is_in(x, y) {\n ans += 1;\n }\n while !is_in(x, y) {\n y -= 1;\n ans += 1;\n }\n }\n\n writeln!(out, \"{}\", (ans - 1) * 4)?;\n\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"}, {"source_code": "#![allow(unused_imports)]\nuse std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\nuse std::cmp::Ordering::{*};\n\n// I have no idea what I'm doing\n\nuse std::f64::consts::{PI};\n\nfn brute(n: i32) -> i32 {\n let mut ans = 0;\n let is_in = |i, j| i*i + j*j <= n*n;\n for i in -n..=n {\n for j in -n..=n {\n let (i, j) = (i.abs(), j.abs());\n if is_in(i, j) && (!is_in(i+1, j) || !is_in(i, j+1) || !is_in(i-1, j) || !is_in(i, j-1)) {\n ans += 1;\n }\n }\n }\n ans\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: i32 = scan.token();\n\n // I wonder if this works\n writeln!(out, \"{}\", if n <= 2500 { brute(n) as i64 }\n else { (2.0 * PI * f64::from(n)).round() as i64 })?;\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"}, {"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 bi(x: i32, n: i32) -> i32 {\n let mut left = 0; // in\n let mut right = n + 1; // out\n for _ in 0..100 {\n let y = (left + right) / 2;\n if x * x + y * y <= n * n {\n left = y;\n } else {\n right = y;\n }\n }\n return left;\n}\n\nfn main() {\n let mut sc = Scanner::new();\n\n let n: i32 = sc.cin();\n\n let mut a = 0;\n let mut b = 0;\n for x in 0..n {\n let y = bi(x, n);\n // trace!((x, y));\n if x < y {\n a += 1;\n } else if x == y {\n b += 1;\n break;\n } else {\n break;\n }\n }\n let ans = 4 * (a * 2 - 1 + b);\n println!(\"{}\", ans);\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"}, {"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 bi(x: i64, n: i64, l0: i64, r0: i64) -> i64 {\n let mut left = l0;\n let mut right = r0;\n\n while right - left > 1 {\n let y = (left + right) / 2;\n if x * x + y * y <= n * n {\n left = y;\n } else {\n right = y;\n }\n }\n return left;\n}\n\nfn main() {\n let mut sc = Scanner::new();\n\n let n: i64 = sc.cin();\n\n if n == 0 {\n println!(\"1\");\n return;\n }\n\n let mut a = 0;\n let mut b = 0;\n\n let mut l0 = 0;\n let mut r0 = n + 1;\n for x in 0..n {\n let y = bi(x, n, l0, r0);\n l0 = y - 10;\n r0 = y + 10;\n // trace!((x, y));\n if x < y {\n a += 1;\n } else if x == y {\n b += 1;\n break;\n } else {\n break;\n }\n }\n let ans = 4 * (a * 2 - 1 + b);\n println!(\"{}\", ans);\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"}, {"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 bi(x: i32, n: i32) -> i32 {\n let mut left = 0; // in\n let mut right = n + 1; // out\n for _ in 0..100 {\n let y = (left + right) / 2;\n if x * x + y * y <= n * n {\n left = y;\n } else {\n right = y;\n }\n }\n return left;\n}\n\nfn main() {\n let mut sc = Scanner::new();\n\n let n: i32 = sc.cin();\n\n if n == 0 {\n println!(\"1\");\n return;\n }\n\n let mut a = 0;\n let mut b = 0;\n for x in 0..n {\n let y = bi(x, n);\n // trace!((x, y));\n if x < y {\n a += 1;\n } else if x == y {\n b += 1;\n break;\n } else {\n break;\n }\n }\n let ans = 4 * (a * 2 - 1 + b);\n println!(\"{}\", ans);\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": "d87ce09acb8401e910ca6ef3529566f4"} {"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 (a, b, c): (f64, f64, f64) = (scanner.next(), scanner.next(), scanner.next());\n let tot = (a*b*c).sqrt();\n println![\"{}\", 4.0*(tot/a + tot/b + tot/c)];\n}", "positive_code": [{"source_code": "\nfn main() {\n let areas: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n \n let a = (areas[0] * areas[1] / areas[2]).sqrt();\n let b = (areas[0] * areas[2] / areas[1]).sqrt();\n let c = (areas[2] * areas[1] / areas[0]).sqrt();\n let res = 4 * (a+b+c) as u32;\n\n println!(\"{}\", res);\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"}], "negative_code": [{"source_code": "\nfn main() {\n let areas: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let sum: u32 = areas.iter().sum();\n let result = 4 * sum;\n\n println!(\"{}\", result);\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"}], "src_uid": "c0a3290be3b87f3a232ec19d4639fefc"} {"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 calc_depth(d: &Vec, p: &Vec, ki: usize, ni: usize) -> i64 {\n d[ni - 1] + p[ki]\n}\n\nfn solve() -> bool {\n let v = read_vec::();\n let (n, k, l) = (v[0], v[1], v[2] as i64);\n let d = read_vec::();\n let p = (0..2 * k)\n .map(|x| if x <= k { x as i64 } else { (2 * k - x) as i64 })\n .collect::>();\n\n let mut dp = vec![vec![false; 2 * k]; n + 1];\n for ki in 0..2 * k {\n dp[0][ki] = true;\n }\n\n for ni in 1..n + 1 {\n for ki in 0..2 * k {\n let next_k = (ki + 1) % (2 * k);\n if dp[ni - 1][ki] && calc_depth(&d, &p, next_k, ni) <= l {\n dp[ni][next_k] = true;\n }\n }\n for ki in 0..2 * k {\n let next_k = (ki + 1) % (2 * k);\n if dp[ni][ki] && calc_depth(&d, &p, next_k, ni) <= l {\n dp[ni][next_k] = true;\n }\n }\n }\n\n dp[n].iter().any(|&x| x)\n}\n\nfn main() {\n let n = read::();\n for i in 0..n {\n if solve() {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n }\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", "positive_code": [{"source_code": "use std::fmt::Debug;\nuse std::str::FromStr;\n\npub struct TokenReader {\n reader: std::io::Stdin,\n tokens: Vec,\n index: usize,\n}\n\nimpl TokenReader {\n pub fn new() -> Self {\n Self {\n reader: std::io::stdin(),\n tokens: Vec::new(),\n index: 0,\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T: FromStr,\n T::Err: Debug,\n {\n if self.index >= self.tokens.len() {\n self.load_next_line();\n }\n self.index += 1;\n self.tokens[self.index - 1].parse().unwrap()\n }\n\n pub fn vector(&mut self) -> Vec\n where\n T: FromStr,\n T::Err: Debug,\n {\n if self.index >= self.tokens.len() {\n self.load_next_line();\n }\n self.index = self.tokens.len();\n self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()\n }\n\n pub fn load_next_line(&mut self) {\n let mut line = String::new();\n self.reader.read_line(&mut line).unwrap();\n\n self.tokens = line\n .split_whitespace()\n .map(String::from)\n .collect();\n self.index = 0;\n }\n}\n\nfn tide(k: usize, time: usize) -> usize {\n let time = time % (2 * k);\n if time <= k {\n time\n } else {\n 2 * k - time\n }\n}\n\nfn depth(k: usize, depths: &Vec, time: usize, index: usize) -> usize {\n depths[index] + tide(k, time)\n}\n\nfn prev_time(k: usize, time: usize) -> usize {\n if time == 0 {\n 2 * k - 1\n } else {\n time - 1\n }\n}\n\nfn possible(k: usize, l: usize, depths: &Vec) -> bool {\n let mut dp = vec![vec![false; 2 * k]; depths.len()];\n for i in 0..2 * k {\n if depth(k, depths, i, 0) <= l {\n dp[0][i] = true;\n }\n }\n\n for i in 1..depths.len() {\n for t in 0..2 * k {\n let p = prev_time(k, t);\n let d = depth(k, depths, t, i);\n\n if d > l {\n continue;\n } else if dp[i - 1][p] {\n dp[i][t] = true;\n } else if dp[i][p] {\n dp[i][t] = true;\n }\n }\n }\n dp[depths.len() - 1].iter().any(|&b| b)\n}\n\nfn main() {\n let mut reader = TokenReader::new();\n let tests = reader.next();\n\n for _ in 0..tests {\n let _ = reader.next::();\n let k = reader.next();\n let l = reader.next();\n let depths = reader.vector();\n\n let res = possible(k, l, &depths);\n println!(\"{}\", if res { \"Yes\" } else { \"No\" });\n }\n}\n"}, {"source_code": "#![allow(dead_code)]\n#![allow(unused_imports)]\n\nuse std::cmp::*;\nuse std::collections::*;\nuse std::io;\nuse std::ops::{self, Range};\nuse std::str::FromStr;\n\n#[derive(Clone, Debug, Default)]\nstruct ProblemState {\n}\n\nimpl Problem {\n fn solve(&mut self) {\n let n: usize = self.scan();\n let k: usize = self.scan();\n let l: usize = self.scan();\n let d: Vec = self.scan_vec(n);\n\n let mut x = vec![vec![0; 2 * k]; n];\n let mut p = vec![0; 2 * k];\n\n for i in 0..k {\n p[i] = i;\n p[2 * k - i - 1] = i + 1;\n }\n\n for i in 0..n {\n for j in 0..2 * k {\n if d[i] + p[j] <= l {\n if i == 0 {\n x[i][j] = 1;\n } else {\n x[i][j] |= x[i - 1][(j - 1 + 2 * k) % (2 * k)];\n x[i][j] |= x[i][(j - 1 + 2 * k) % (2 * k)];\n }\n }\n }\n }\n\n if x[n - 1].iter().any(|x_i| *x_i == 1) {\n println!(\"Yes\");\n } else {\n println!(\"No\");\n }\n\n// eprintln!(\"{:?}\", x[n - 1]);\n }\n}\n\nfn main() {\n Problem::new().solve_cases();\n}\n\nstruct Problem {\n input_state: InputState,\n problem_state: ProblemState,\n}\n\nstruct InputState {\n stdin: io::Stdin,\n buffer: String,\n tokens: VecDeque,\n}\n\nimpl Problem {\n fn new() -> Self {\n Self {\n input_state: InputState {\n stdin: io::stdin(),\n buffer: String::new(),\n tokens: VecDeque::new(),\n },\n problem_state: Default::default(),\n }\n }\n\n fn solve_cases(&mut self) {\n for _ in 0usize..self.scan() {\n self.solve()\n }\n }\n\n fn scan(&mut self) -> T {\n while self.input_state.tokens.is_empty() {\n self.input_state.stdin.read_line(&mut self.input_state.buffer).unwrap();\n\n for token in self.input_state.buffer.split_ascii_whitespace() {\n self.input_state.tokens.push_back(token.to_string());\n }\n\n self.input_state.buffer.clear();\n }\n\n self.input_state.tokens.pop_front().unwrap().parse().ok().unwrap()\n }\n\n fn scan_vec(&mut self, n: usize) -> Vec {\n (0..n).into_iter().map(|_| self.scan()).collect()\n }\n\n fn scan_line(&mut self) -> String {\n let mut line = String::new();\n self.input_state.stdin.read_line(&mut line).unwrap();\n while line.ends_with('\\n') || line.ends_with('\\r') { line.pop(); }\n line\n }\n\n fn scan_line_vec(&mut self, n: usize) -> Vec {\n (0..n).into_iter().map(|_| self.scan_line()).collect()\n }\n}\n\nimpl ops::Deref for Problem {\n type Target = ProblemState;\n\n fn deref(&self) -> &ProblemState {\n &self.problem_state\n }\n}\n\nimpl ops::DerefMut for Problem {\n fn deref_mut(&mut self) -> &mut ProblemState {\n &mut self.problem_state\n }\n}\n"}, {"source_code": "use std::collections::HashSet;\n\nstruct DFS {\n n: usize, k: usize, l: usize,\n d: Vec,\n p: Vec,\n set: HashSet<(usize, usize)>,\n}\n\nimpl DFS {\n fn new() -> DFS {\n let (n, k, l): (usize, usize, usize) = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut iter = buf.split_whitespace();\n (\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n };\n let d: Vec = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let iter = buf.split_whitespace();\n iter.map(|x| x.parse().unwrap()).collect()\n };\n let p: Vec = (0..k).chain((1..=k).rev()).collect();\n DFS { n, k, l, d, p, set: HashSet::new() } \n }\n\n fn search(&mut self, x: usize, t: usize) -> bool {\n if x == self.n + 1 {\n true\n } else if x > 0 && self.d[x - 1] + self.p[t] > self.l {\n false\n } else if self.set.contains(&(x, t)) {\n false\n } else {\n self.set.insert((x, t));\n let nt = (t + 1) % (self.k * 2);\n self.search(x, nt) || self.search(x + 1, nt) \n }\n }\n}\n\nfn main() {\n let t: usize = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim_end().parse().unwrap()\n };\n for _ in 0..t {\n let mut dfs = DFS::new();\n println!(\"{}\", if dfs.search(0, 0) { \"Yes\" } else { \"No\" });\n }\n}"}, {"source_code": "#![allow(dead_code, unused_imports)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(a: u64, b: u64) -> u64 {\n let mut a = a;\n let mut b = b;\n while a != b {\n if a > b {\n a = a - b\n } else {\n b = b - a\n }\n }\n a\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nuse std::cmp::{max, min};\nuse std::collections::VecDeque;\n\nfn first_factor(n: u32) -> u32 {\n if n % 2 == 0 {\n return 2;\n }\n if n % 3 == 0 {\n return 3;\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n if n % (f - 1) == 0 {\n return f - 1;\n }\n if n % (f + 1) == 0 {\n return f + 1;\n }\n f += 6;\n }\n return n;\n}\n\nfn found(d: Vec, k: u16, limit: u16) -> bool {\n if d.is_empty() {\n return true;\n }\n let p = (0..k).chain((1..k + 1).rev()).collect::>();\n for start in 0..p.len() {\n if d.iter()\n .enumerate()\n .map(|(i, di)| di + p[(i + start) % p.len()])\n .all(|di| di <= limit)\n {\n return true;\n }\n }\n false\n}\n\nfn main() -> Result<(), Box> {\n for _ in 0..read_usize() {\n let (_n, k, l) = read_3::();\n let d = read_multiple();\n let mut dead = false;\n let mut gap = Vec::new();\n for di in d {\n if k + di <= l {\n if !found(gap, k, l) {\n dead = true\n }\n gap = Vec::new();\n } else {\n gap.push(di)\n }\n }\n if !found(gap, k, l) {\n dead = true\n }\n if dead {\n println!(\"No\")\n } else {\n println!(\"Yes\")\n }\n }\n Ok(())\n}\n"}, {"source_code": "#![allow(dead_code)]\n#![allow(unused)]\n#![allow(unused_imports)]\n#![allow(non_snake_case)]\n\nuse std::collections::{HashSet, HashMap};\nuse std::cmp::{min,max,Reverse};\nuse std::io::{self, prelude::*};\nuse std::{str, iter};\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 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 = str::from_utf8_unchecked(&self.buf_str);\n std::mem::transmute(slice.split_whitespace())\n }\n }\n }\n}\n\nconst MAX : usize = 444;\n\nfn solve(scan: &mut Scanner, w: &mut W) {\n let N : usize = scan.token();\n let K : usize = scan.token();\n let L : i64 = scan.token();\n let d : Vec = iter::repeat_with(|| scan.token()).take(N).collect();\n let p : Vec = (0..K).chain((1..K+1).rev()).cycle().take(4*K).map(|x| x as i64).collect();\n\n let mut dp = [[false; MAX]; MAX];\n dp[N] = [true; MAX];\n\n for i in (0..N).rev() {\n for j in (0..4*K).rev() {\n dp[i][j] = (d[i] + p[j] <= L) && (dp[i][j+1] || dp[i+1][(j+1)%(2*K)]);\n }\n }\n // for i in (0..N).rev() {\n // println!(\"{}, {:?}\",i,&dp[i][0..2*K]);\n // }\n\n\n writeln!(w, \"{}\", if dp[0].iter().any(|&x|x) {\"Yes\"} else {\"No\"});\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 for _ in 0..scan.token::() {\n solve(&mut scan, &mut out);\n }\n}\n"}, {"source_code": "#![allow(unused_imports)]\n#![allow(dead_code)]\n\nuse std::cmp::{max, min};\nuse std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};\nuse std::io::{stdin, stdout, BufWriter, Write};\nuse std::mem::swap;\n\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().unwrap();\n }\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nconst T: usize = 20;\n\nfn solve_case(scan: &mut Scanner, out: &mut BufWriter) {\n let n: usize = scan.next();\n let k: usize = scan.next();\n let l: usize = scan.next();\n let d: Vec = (0..n).map(|_| scan.next()).collect();\n let mut g: Vec> = vec![vec![false; 2 * k]; n + 2];\n let mut dt: Vec = vec![0; 2 * k];\n for i in 0..k {\n dt[i + 1] = dt[i] + 1;\n }\n for i in k + 1..2*k {\n dt[i] = dt[i - 1] - 1;\n }\n g[0][0] = true;\n let mut q: VecDeque = VecDeque::new();\n q.push_back(0);\n q.push_back(0);\n while !q.is_empty() {\n let pos = q.pop_front().unwrap();\n let time = q.pop_front().unwrap();\n let nxt_time = (time + 1) % dt.len();\n if pos == n+1 {\n writeln!(out, \"Yes\").unwrap();\n return;\n }\n if (pos == 0 || d[pos-1] + dt[nxt_time] <= l) && !g[pos][nxt_time] {\n g[pos][nxt_time] = true;\n q.push_back(pos);\n q.push_back(nxt_time);\n }\n if (pos == n || d[pos] + dt[nxt_time] <= l) && !g[pos+1][nxt_time] {\n g[pos+1][nxt_time] = true;\n q.push_back(pos+1);\n q.push_back(nxt_time);\n }\n }\n writeln!(out, \"No\").unwrap();\n}\n\nfn solve(scan: &mut Scanner, out: &mut BufWriter) {\n let t: usize = scan.next();\n for _ in 0..t {\n solve_case(scan, out);\n }\n}\n\nfn main() {\n std::thread::Builder::new()\n .name(\"solver_thread\".into())\n .stack_size(1024 * 1024 * 1024)\n .spawn(|| {\n let mut scan = Scanner::default();\n let out = stdout();\n let mut out = BufWriter::new(out.lock());\n solve(&mut scan, &mut out);\n })\n .unwrap()\n .join()\n .unwrap();\n}\n"}, {"source_code": "#![allow(dead_code, unused_macros, unused_imports)]\nuse std::collections::*;\nuse std::io;\nuse std::io::Write;\nmacro_rules! fprintln {\n ($dst:expr) => (\n $dst.write(\"\\n\".as_bytes()).unwrap();\n );\n ($dst:expr, $($arg:tt)*) => ( {\n $dst.write_fmt(format_args!($($arg)*)).unwrap();\n $dst.write(\"\\n\".as_bytes()).unwrap();\n }\n );\n}\n\nmacro_rules! fprintvec {\n ($dst:expr, $arg:expr) => {{\n fprintln!(\n $dst,\n \"{}\",\n $arg.iter()\n .map(|x| format!(\"{}\", x))\n .collect::>()\n .join(\" \")\n );\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 input_line\n .trim_end_matches(\"\\n\")\n .trim_end_matches(\"\\r\")\n .parse::<$t>()\n .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 depth(t: i64, k: i64, start: i64) -> i64 {\n let v;\n let t = t % (2 * k);\n if t <= k {\n v = t;\n } else {\n v = k - (t - k);\n }\n v + start\n}\n\nfn slow(depths: &Vec, k: i64, l: i64) -> bool {\n let mut valid = (0..=2 * k).collect::>();\n for p in depths.iter() {\n let mut next = HashSet::new();\n for z in valid.iter() {\n for x in 1..=(2 * k) {\n if depth(z + x, k, *p) <= l {\n next.insert((z + x) % (2 * k));\n } else {\n break;\n }\n }\n }\n valid = next;\n }\n valid.len() > 0\n}\n\nfn main() {\n let stdout = io::stdout();\n let lock = stdout.lock();\n let mut w = io::BufWriter::new(lock);\n let num_tests = parse_input!(usize);\n // let num_tests = 1;\n for _ in 0..num_tests {\n let limits = split_input!(i64);\n let n = limits[0];\n let k = limits[1];\n let l = limits[2];\n let vals = split_input!(i64);\n let mut start = -k;\n let mut valid = true;\n // for (p, &d) in vals.iter().enumerate() {\n // if d > l {\n // valid = false;\n // break;\n // }\n // if d + k <= l {\n // start = -k;\n // } else {\n // let nt = start + 1;\n // let bad = (l - d) + 1;\n // let good = -bad;\n // if nt >= bad {\n // valid = false;\n // break;\n // }\n // start = std::cmp::max(nt, good);\n // }\n // dbg!(start);\n // }\n valid = slow(&vals, k, l);\n if valid {\n fprintln!(w, \"YES\");\n } else {\n fprintln!(w, \"NO\");\n }\n }\n}\n"}], "negative_code": [], "src_uid": "4941b0a365f86b2e2cf686cdf5d532f8"} {"source_code": "fn read_line() -> String {\n let stdin = std::io::stdin();\n let mut line = String::new();\n stdin.read_line(&mut line).unwrap();\n String::from(line.trim())\n}\n\nmacro_rules! scan_line {\n ($($ty: ty),*) => {{\n let line = read_line();\n let mut tok = line.split_whitespace();\n ($(tok.next().unwrap().parse::<$ty>().unwrap()),*)\n }}\n}\n\nfn main() {\n let (a, b) = scan_line!(u64, u64);\n let mut acc = 1;\n for i in (a + 1)..(b + 1) {\n acc = (acc * i % 10) % 10;\n if acc == 0 {\n break;\n }\n }\n println!(\"{}\", acc);\n}\n", "positive_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\n#[allow(unused_imports)]\nuse std::collections::{HashMap, HashSet};\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 get() -> T\n where\n ::Err: Debug,\n {\n let mut line: String = String::new();\n stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\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 #[allow(dead_code)]\n pub fn get2() -> (T, U)\n where\n ::Err: Debug,\n ::Err: Debug,\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().unwrap(),\n iter.next().unwrap().parse().unwrap(),\n )\n }\n}\n\nfn main() {\n let (a, b): (u64, u64) = util::get2();\n\n let mut f = 1;\n\n for x in a + 1..b + 1 {\n f = (f * (x % 10)) % 10;\n if f == 0 {\n break;\n }\n }\n\n println!(\"{}\", f);\n}\n"}, {"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 (a, b): (u64, u64) = {\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 )\n };\n\n let ans = if b - a < 10 {\n (a..b).fold(1, |acc, k| ((k + 1) * acc) % 10)\n } else {\n 0\n };\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "#![allow(dead_code, unused_imports)]\n\nuse std::fmt::Debug;\nuse std::str::FromStr;\n\nfn read_stdin() -> String {\n let mut s = String::new();\n std::io::stdin()\n .read_line(&mut s)\n .expect(\"cannot read stdin\");\n s.trim().to_string()\n}\n\nfn read() -> T\nwhere\n T: FromStr,\n ::Err: Debug,\n{\n read_stdin().parse::().unwrap()\n}\n\nfn read_usize() -> usize {\n read::()\n}\n\nfn read_2() -> (A, B)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n (a, b)\n}\n\nfn read_3() -> (A, B, C)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n (a, b, c)\n}\n\nfn read_4() -> (A, B, C, D)\nwhere\n A: FromStr,\n ::Err: Debug,\n B: FromStr,\n ::Err: Debug,\n C: FromStr,\n ::Err: Debug,\n D: FromStr,\n ::Err: Debug,\n{\n let s = read_stdin();\n let mut s = s.split_whitespace();\n let a = s.next().unwrap().parse::().unwrap();\n let b = s.next().unwrap().parse::().unwrap();\n let c = s.next().unwrap().parse::().unwrap();\n let d = s.next().unwrap().parse::().unwrap();\n (a, b, c, d)\n}\n\nfn read_multiple() -> Vec\nwhere\n ::Err: Debug,\n{\n read_stdin()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"cannot parse stdin\"))\n .collect()\n}\n\n/// NOTE: sort iter beforehand if required\nfn count(iter: &mut impl Iterator) -> Vec<(T, usize)>\nwhere\n T: std::cmp::Ord,\n{\n let iter = iter.collect::>();\n //iter.sort();\n let (mut v, o, c) =\n iter.into_iter()\n .fold((Vec::new(), None, 0), |(mut v, last, count), item| {\n if let Some(o) = last {\n if item == o {\n (v, Some(o), count + 1)\n } else {\n v.push((o, count));\n (v, Some(item), 1)\n }\n } else {\n (v, Some(item), 1)\n }\n });\n if let Some(i) = o {\n v.push((i, c));\n }\n v\n}\n\nfn partial_sum(v: impl Iterator) -> impl Iterator\nwhere\n T: Default + std::ops::Add + Copy,\n{\n v.scan(T::default(), |state, x| {\n *state = *state + x;\n Some(*state)\n })\n}\n\nfn max_subarray(v: impl Iterator) -> (i64, (usize, usize)) {\n //assert!(v.len() > 0);\n let mut best_sum = 0;\n let (mut best_start, mut best_end) = (0, 0);\n let mut current_sum = 0;\n let mut current_start = 0;\n for (end, val) in v.enumerate() {\n if current_sum <= 0 {\n current_start = end;\n current_sum = val;\n } else {\n current_sum += val;\n }\n if current_sum > best_sum {\n best_sum = current_sum;\n best_start = current_start;\n best_end = end + 1;\n }\n }\n (best_sum, (best_start, best_end))\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != 0 {\n let old_m = a;\n a = b % a;\n b = old_m;\n }\n b\n}\n\n/// returns gcd, and pair (x, y), such that x * a + b * y == gcd\nfn egcd(a: i64, b: i64) -> (i64, i64, i64) {\n if a == 0 {\n (b, 0, 1)\n } else {\n let (g, x, y) = egcd(b % a, a);\n (g, y - (b / a) * x, x)\n }\n}\n\nfn factorize(mut n: u64) -> Vec {\n if n <= 3 {\n return vec![n];\n }\n let mut v = Vec::new();\n while n % 2 == 0 {\n n /= 2;\n v.push(2);\n }\n while n % 3 == 0 {\n n /= 3;\n v.push(3);\n }\n let mut f = 6;\n while (f - 1) * (f - 1) <= n {\n while n % (f - 1) == 0 {\n n /= f - 1;\n v.push(f - 1);\n }\n while n % (f + 1) == 0 {\n n /= f + 1;\n v.push(f + 1);\n }\n f += 6;\n }\n if n > 1 {\n v.push(n);\n }\n v\n}\n\nfn compact_factors(n: u64) -> Vec<(u64, usize)> {\n count(&mut factorize(n).into_iter())\n}\n\nfn all_factors(n: u64) -> Vec {\n if n == 0 {\n return vec![0];\n } else if n == 1 {\n return vec![1];\n }\n let factors = compact_factors(n);\n let mut v = vec![1];\n for (fac, num) in factors {\n let ori = v.clone();\n for i in 1..num + 1 {\n v.append(\n &mut ori\n .clone()\n .into_iter()\n .map(|f| f * fac.pow(i as u32))\n .collect::>(),\n )\n }\n }\n v.sort();\n v\n}\n\nfn abs_diff(a: T, b: T) -> T\nwhere\n T: PartialOrd + std::ops::Sub,\n{\n if a > b {\n a - b\n } else {\n b - a\n }\n}\n\nstruct Permutations {\n inner: Vec,\n state: Vec,\n i: usize,\n start: bool,\n}\n\nimpl Permutations {\n fn new(inner: Vec) -> Self {\n Self {\n state: vec![0; inner.len()],\n i: 0,\n start: true,\n inner,\n }\n }\n}\n\n/*impl From for Permutations\nwhere\n X: IntoIterator,\n{\n fn from(f: X) -> Self {\n Self::new(f.into_iter().collect::>())\n }\n}*/\n\nimpl Iterator for Permutations\nwhere\n T: Clone,\n{\n type Item = Vec;\n fn next(&mut self) -> Option {\n if self.start {\n self.start = false;\n return Some(self.inner.clone());\n }\n while self.i < self.inner.len() {\n if self.state[self.i] < self.i {\n if self.i % 2 == 0 {\n self.inner.swap(0, self.i)\n } else {\n self.inner.swap(self.state[self.i], self.i)\n }\n self.state[self.i] += 1;\n self.i = 0;\n return Some(self.inner.clone());\n } else {\n self.state[self.i] = 0;\n self.i += 1;\n }\n }\n None\n }\n}\n\nuse std::cmp::{max, min, Ord, Ordering};\nuse std::collections::{BinaryHeap, VecDeque};\nuse std::mem::swap;\n\n#[derive(Clone)]\nstruct Graph {\n nodes: usize,\n edges: Vec>,\n}\n\nimpl Graph {\n fn new(n: usize) -> Self {\n Self {\n nodes: n,\n edges: vec![Vec::new(); n + 1],\n }\n }\n\n fn add_edge(&mut self, x: usize, y: usize, cost: u64) {\n self.edges[x].push((y, cost));\n self.edges[y].push((x, cost));\n }\n\n fn dijkstra(&mut self, start: usize, end: usize) -> u64 {\n let mut dist = vec![None; self.nodes + 1];\n let mut prev = vec![None; self.nodes + 1];\n dist[start] = Some(0);\n let mut queue = (1..=self.nodes).collect::>();\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n while let Some(next_node) = queue.pop() {\n if next_node == end {\n return dist[next_node].unwrap();\n }\n for (neighbour, cost) in self.edges[next_node].iter() {\n let alt = dist[next_node].unwrap() + cost;\n if dist[*neighbour].is_none() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n } else {\n if alt < dist[*neighbour].unwrap() {\n dist[*neighbour] = Some(alt);\n prev[*neighbour] = Some(next_node);\n }\n }\n }\n //println!(\"{:?} {:?}\", dist, prev);\n queue.sort_unstable_by_key(|node| dist[*node].unwrap_or(std::u64::MAX));\n queue.reverse();\n }\n 0\n }\n\n fn set_cost(&mut self, x: usize, y: usize, cost: u64) {\n for i in 0..self.edges[x].len() {\n if self.edges[x][i].0 == y {\n self.edges[x][i].1 = cost\n }\n }\n for i in 0..self.edges[y].len() {\n if self.edges[y][i].0 == x {\n self.edges[y][i].1 = cost\n }\n }\n }\n}\n\nconst MODULO: u64 = 1_000_000_007;\n\n#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]\nstruct BigPrimeRing {\n inner: u64,\n}\n\nimpl From for BigPrimeRing\nwhere\n T: Into,\n{\n fn from(n: T) -> Self {\n Self {\n inner: n.into() % MODULO,\n }\n }\n}\n\nimpl std::ops::Add for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn add(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner + rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::AddAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn add_assign(&mut self, rhs: T) {\n self.inner += rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl std::ops::Sub for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn sub(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner + MODULO - rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::SubAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn sub_assign(&mut self, rhs: T) {\n self.inner += MODULO;\n self.inner -= rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl std::ops::Mul for BigPrimeRing\nwhere\n T: Into,\n{\n type Output = BigPrimeRing;\n fn mul(self, rhs: T) -> Self::Output {\n Self {\n inner: (self.inner * rhs.into().inner) % MODULO,\n }\n }\n}\n\nimpl std::ops::MulAssign for BigPrimeRing\nwhere\n T: Into,\n{\n fn mul_assign(&mut self, rhs: T) {\n self.inner *= rhs.into().inner;\n self.inner %= MODULO;\n }\n}\n\nimpl BigPrimeRing {\n fn inverse(self) -> Self {\n if self.inner == 0 {\n return self;\n }\n let (_g, mut x, _y) = egcd(self.inner as i64, MODULO as i64);\n if x < 0 {\n x += MODULO as i64;\n }\n Self { inner: x as u64 }\n }\n}\n\nfn main() -> Result<(), Box> {\n let (a, b) = read_2::();\n let mut res = 1;\n 'lop: for i in (a + 1)..=b {\n res *= i;\n res %= 10;\n if res == 0 {\n break 'lop;\n }\n }\n println!(\"{}\", res);\n Ok(())\n}\n"}, {"source_code": "// Basics\n\n#![allow(unused_imports)]\n\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}\n\nfn main() {\n let w = load();\n let (a, b) = (w[0], w[1]);\n if b - a >= 10 {\n println!(\"0\");\n } else {\n let mut end = 1;\n for i in (a + 1)..(b + 1) {\n end *= i % 10;\n }\n println!(\"{}\", (end % 10));\n }\n}\n\n//\n//mod strings;\n//\n//fn main() {\n// strings_sample();\n//}\n"}], "negative_code": [{"source_code": "// Basics\n\n#![allow(unused_imports)]\n\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: i32 = i.trim().parse().unwrap();\n data.push(el);\n }\n data\n}\n\nfn main() {\n let w = load();\n let (a, b) = (w[0], w[1]);\n if b - a >= 10 {\n println!(\"0\");\n } else {\n let mut end = 1;\n for i in (a + 1)..(b + 1) {\n end *= i;\n }\n println!(\"{}\", (end % 10));\n }\n}\n\n//\n//mod strings;\n//\n//fn main() {\n// strings_sample();\n//}\n"}], "src_uid": "2ed5a7a6176ed9b0bda1de21aad13d60"} {"source_code": "// https://codeforces.com/contest/1271/problem/A\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 main() {\n input! {\n a: i64, b: i64, c: i64, d: i64,\n t1: i64, t2: i64\n };\n\n let mut best = 0;\n for i in 0..d+1 {\n best = max(best, t1*min(a, i)+t2*(min(min(b,c),d-i)));\n }\n\n println!(\"{}\", best);\n}\n", "positive_code": [{"source_code": "use std::io::stdin;\nuse std::cmp::max;\nuse std::cmp::min;\n\nfn main() {\n let mut str = String::new();\n let _ = stdin().read_line(&mut str).unwrap();\n let mut a: i64 = str.trim().parse().unwrap();\n str.clear();\n let _ = stdin().read_line(&mut str).unwrap();\n let mut b: i64 = str.trim().parse().unwrap();\n str.clear();\n let _ = stdin().read_line(&mut str).unwrap();\n let mut c: i64 = str.trim().parse().unwrap();\n str.clear();\n let _ = stdin().read_line(&mut str).unwrap();\n let mut d: i64 = str.trim().parse().unwrap();\n str.clear();\n let _ = stdin().read_line(&mut str).unwrap();\n let mut e: i64 = str.trim().parse().unwrap();\n str.clear();\n let _ = stdin().read_line(&mut str).unwrap();\n let mut f: i64 = str.trim().parse().unwrap();\n str.clear();\n b = min (b, c);\n if e > f {\n println!(\"{}\", min(d, a) * e + min(d - min(d,a) ,b) * f);\n }\n else {\n println!(\"{}\", min(d, b) * f + min(d - min(d,b) ,a) * e);\n }\n \n}\n"}, {"source_code": "//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, 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::*;\n\nfn run() {\n input! {\n a: i32,\n b: i32,\n c: i32,\n d: i32,\n e: i32,\n f: i32,\n }\n let mut ans = 0;\n for x in 0..=min(a, d) {\n let mut val = 0;\n val += e * x;\n val += f * min(b, min(c, d - x));\n ans = max(ans, val);\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"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#[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#[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 let out = stdout();\n let mut out = BufWriter::new(out.lock());\n\n input!{\n a:usize,\n b:usize,\n c:usize,\n d:usize,\n e:usize,\n f:usize,\n }\n\n let mut maxcost = 0;\n for i in 0..d+1 {\n let mut cost = 0;\n if a < i {\n continue;\n }\n cost += e*i;\n\n let rest = d-i;\n let mut j = min(min(b,c),rest);\n\n cost += f*j;\n\n chmax!(maxcost, cost);\n }\n println!(\"{}\", maxcost);\n}"}, {"source_code": "\nfn read_u32() -> u32 {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n line.trim().parse().unwrap()\n}\n\nfn convert_a(a: &mut u32, d: &mut u32, cost: u32) -> u32 {\n\n let a_amount = *a.min(d);\n *a -= a_amount;\n *d -= a_amount;\n\n a_amount * cost\n}\n\nfn convert_b(b: &mut u32, c: &mut u32, d: &mut u32, cost: u32) -> u32 {\n\n let b_amount = *b.min(c).min(d);\n *b -= b_amount;\n *c -= b_amount;\n *d -= b_amount;\n\n b_amount * cost\n}\n\nfn main() {\n let mut a = read_u32();\n let mut b = read_u32();\n let mut c = read_u32();\n let mut d = read_u32();\n\n let cost_a = read_u32();\n let cost_b = read_u32();\n\n let mut rev = 0;\n\n if cost_a > cost_b {\n\n rev += convert_a(&mut a, &mut d, cost_a);\n rev += convert_b(&mut b, &mut c, &mut d, cost_b);\n\n } else {\n\n rev += convert_b(&mut b, &mut c, &mut d, cost_b);\n rev += convert_a(&mut a, &mut d, cost_a);\n\n }\n\n println!(\"{}\", rev);\n}"}, {"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 main() {\n let a = read::();\n let b = read::();\n let c = read::();\n let b = min(b, c);\n let mut d = read::();\n let e = read::();\n let f = read::();\n if e > f {\n let eset = min(a, d);\n d -= eset;\n let fset = min(b, d);\n println!(\"{}\", e * eset + f * fset);\n } else {\n let fset = min(b, d);\n d -= fset;\n let eset = min(a, d);\n println!(\"{}\", e * eset + f * fset);\n }\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"}], "negative_code": [], "src_uid": "84d9e7e9c9541d997e6573edb421ae0a"} {"source_code": "use std::io;\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() -> (u64, u64) {\n let vec = read_line_vec();\n return (vec[0], vec[1]);\n}\n\n\nfn get_bp(n: u64, m: u64) -> u64 {\n if n == 1 {\n return 1;\n }\n assert!(m > 0);\n let left = m - 1;\n let right = n - m;\n \n if left == right {\n return left;\n }\n if left < right {\n return m + 1;\n }\n return left;\n}\n\nfn main() {\n let (n, m) = read_line_pair();\n let res = get_bp(n, m);\n \n println!(\"{}\", res);\n}\n", "positive_code": [{"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!(n,m = input.i());\n let sol = if n == 1 {\n 1\n } else if m - 1 >= n - m {\n m - 1\n } else {\n m + 1\n };\n println!(\"{}\", sol);\n}\n\n"}, {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n// use proconio::input;\nuse std::cmp::{Ordering::*, Reverse};\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 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, m) = scan.pair::();\n\n if n == 1 {\n return answer!(out, 1);\n }\n \n answer!(out, if m-1 < n-m {\n m+1 \n } else {\n m-1\n })\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"}], "negative_code": [{"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n// use proconio::input;\nuse std::cmp::{Ordering::*, Reverse};\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 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, m) = scan.pair::();\n \n answer!(out, if m-1 <= n-m {\n m+1 \n } else {\n m-1\n })\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"}, {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n// use proconio::input;\nuse std::cmp::{Ordering::*, Reverse};\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 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, m) = scan.pair::();\n\n if n == 1 {\n return answer!(out, 1);\n }\n \n answer!(out, if m-1 <= n-m {\n m+1 \n } else {\n m-1\n })\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"}, {"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!(n,m = input.i());\n let sol = if m - 1 >= n - m {\n m - 1\n } else {\n m + 1\n };\n println!(\"{}\", sol);\n}\n\n"}, {"source_code": "use std::io;\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() -> (u64, u64) {\n let vec = read_line_vec();\n return (vec[0], vec[1]);\n}\n\n\nfn get_bp(n: u64, m: u64) -> u64 {\n assert!(m > 0);\n let left = m - 1;\n let right = n - m;\n if left == right {\n return m;\n }\n if left < right {\n return m + 1;\n }\n return left;\n}\n\nfn main() {\n let (n, m) = read_line_pair();\n let res = get_bp(n, m);\n \n println!(\"{}\", res);\n}\n"}], "src_uid": "f6a80c0f474cae1e201032e1df10e9f7"} {"source_code": "use std::io::{self, BufWriter, Write};\nuse std::str::{self, SplitAsciiWhitespace};\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 n: i32 = scan.token();\n\n let mut pten: i32 = 1;\n let mut m = n;\n while m > 9 {\n m /= 10;\n pten *= 10;\n }\n\n m += 1;\n m *= pten;\n\n writeln!(out, \"{}\", m - n)?;\n\n Ok(())\n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn main(){\n let mut inp = String::new();\n io::stdin().read_line(&mut inp).expect(\"Error while taking input\");\n let num: u32 = inp.trim().parse().expect(\"Number can't be parsed\");\n let ipsize: u32 = inp.trim().len() as u32;\n let magicnum = 10u32.pow(ipsize - 1);\n let nlucky = (num/magicnum + 1) * magicnum;\n println!(\"{}\", nlucky-num);\n}\n"}], "negative_code": [], "src_uid": "a3e15c0632e240a0ef6fe43a5ab3cc3e"} {"source_code": "//! http://codeforces.com/contest/208/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!(wubs: String);\n let words = wubs.split(\"WUB\");\n let mut result: Vec = Vec::new();\n for word in words {\n if !word.is_empty() { result.push(word.into()); }\n }\n for (i, word) in result.into_iter().enumerate() {\n if i != 0 { print!(\" \"); }\n print!(\"{}\", word);\n }\n println!(\"\");\n}\n", "positive_code": [{"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n let mut v = Vec::new(); v.reserve(($n) as usize);\n for st in s { v.push(st.parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n let s = scan!(String);\n s.split(\"WUB\").filter(|x| x.len() != 0).map(|x| x.to_owned() + \" \").map(|x| print!(\"{}\", x)).for_each(drop);\n}\n"}, {"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n let mut v = Vec::new(); v.reserve(($n) as usize);\n for st in s { v.push(st.parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n let s = scan!(String);\n s.split(\"WUB\").filter(|x| x.len() != 0).for_each(|x| print!(\"{} \", x));\n}\n"}, {"source_code": "fn main() {\n let line = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n };\n\n println!(\"{}\", line.split(\"WUB\").filter(|&a| a != \"\").collect::>().join(\" \"));\n}"}, {"source_code": "//spnauti-rust\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n input.s().replace(\"WUB\", \" \").split_whitespace().map(|x| print!(\"{} \", x)).count();\n}\n\n"}, {"source_code": "fn main() {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n let line = line.trim();\n\n let words: Vec<&str> = line.split(\"WUB\").collect();\n\n let ret = words.iter().fold(String::new(),\n |s, w| if w.len() != 0 { s + w + \" \" } else { s });\n println!(\"{}\", ret.trim());\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n\n let mut ret = String::new();\n for i in 0..buf.len() {\n if ret.ends_with(\"WUB\") {\n let len = ret.len();\n// ret.replace_range((len - 3)..len, \"\");\n ret = ret[..len - 3].to_string();\n if ret.ends_with(\" \") == false {\n if ret.len() > 0 {\n ret.push(' ');\n }\n }\n }\n ret.push_str(&buf[i..i + 1]);\n }\n println!(\"{}\", ret.trim());\n}\n"}, {"source_code": "use std::io::{self, BufRead};\n\nfn main() {\n let stdin = io::stdin();\n let mut iterator = stdin.lock().lines();\n\n let line = iterator.next().unwrap().unwrap();\n\n let words: Vec<&str> = line\n .split(\"WUB\")\n .filter(|s| !s.is_empty())\n .collect();\n \n println!(\"{}\", words.join(\" \"));\n}"}, {"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 println!(\"{}\", gets().replace(\"WUB\", \" \").split_whitespace().collect::>().join(\" \"));\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let x: String = read(sin);\n\n let ans: Vec = x.split(\"WUB\")\n .filter(|x| *x != \"\")\n .map(|x| x.to_string())\n .collect();\n\n println!(\"{}\", ans.join(\" \"));\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let x: String = read(sin);\n\n let ans: Vec<&str> = x.split(\"WUB\").filter(|x| *x != \"\").collect();\n\n println!(\"{}\", ans.join(\" \"));\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/208/A\nuse std::io;\n\nfn main() {\n let mut song = String::new();\n\n io::stdin()\n .read_line(&mut song)\n .unwrap();\n\n let song = song.trim();\n\n let words: Vec<&str> = \n song\n .split(\"WUB\")\n .filter(|x| x.to_string() != \"\")\n .collect();\n\n for word in words {\n print!(\"{} \", word)\n } println!();\n}\n\n"}, {"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 n = s.len();\n let mut flag = 1; // 0,一般,1,开头, 2,中间\n let mut i = 0;\n while i < n {\n if i+2 < n && s[i..i+3] == String::from(\"WUB\") {\n i += 3;\n if flag == 1 {\n \n } else if flag == 2 {\n \n } else { // flag == 0\n flag = 2;\n print!(\" \");\n }\n }\n else {\n flag = 0;\n print!(\"{}\", s.as_bytes()[i] as char);\n i += 1;\n }\n }\n}"}, {"source_code": "fn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn main() {\n print!(\"{}\", read_str().replace(\"WUB\", \" \").trim().replace(\" \", \" \").replace(\" \", \" \"));\n}"}, {"source_code": "fn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn main() {\n print!(\"{}\", read_str().replace(\"WUB\", \" \"));\n}"}, {"source_code": "use 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 print_original_song(s : &String) {\n let t = s.replace(\"WUB\", \" \");\n let word_iter = t.split_whitespace();\n let mut first = true;\n for word in word_iter {\n if first {\n print!(\"{}\", word);\n first = false;\n } else {\n print!(\" {}\", word);\n }\n }\n println!();\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut s = String::new();\n read_line(&stdin, &mut s);\n print_original_song(&s);\n}\n"}, {"source_code": "fn main() {\n let mut word = String::new();\n std::io::stdin().read_line(&mut word).unwrap();\n\n let word = word.trim();\n let len = word.len();\n let mut i: usize = 0;\n\n while i < len {\n if i as i32 <= len as i32 - 3 &&\n word.as_bytes()[i] == b'W' &&\n word.as_bytes()[i + 1] == b'U' &&\n word.as_bytes()[i + 2] == b'B' {\n print!(\" \");\n i += 3; continue;\n }\n\n print!(\"{}\", word.as_bytes()[i] as char);\n i += 1;\n }\n}"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min,max};\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 out = &mut BufWriter::new(stdout());\n\n\tlet s = scan.next::();\n let sw = s.replace(\"WUB\", \" \");\n let words = sw.split_whitespace().map(String::from).collect::>();\n\n writeln!(out, \"{}\", words.join(\" \")).expect(\"fail\");\n}\n"}], "negative_code": [{"source_code": "fn main() {\n let mut word = String::new();\n std::io::stdin().read_line(&mut word).unwrap();\n\n let word = word.trim();\n let len = word.len();\n let mut i: usize = 0;\n\n while i < len {\n if i <= len - 3 &&\n word.as_bytes()[i] == b'W' &&\n word.as_bytes()[i + 1] == b'U' &&\n word.as_bytes()[i + 2] == b'B' {\n i += 3;\n }\n else {\n print!(\"{}\", word.as_bytes()[i] as char);\n i += 1;\n }\n }\n\n println!();\n}"}], "src_uid": "edede580da1395fe459a480f6a0a548d"} {"source_code": "use std::vec;\r\nfn ksm(mut a:isize, mut b:isize, c:isize) -> isize {\r\n a = a%c;\r\n let mut ret = 1;\r\n while b >= 1{\r\n if b % 2 == 1 {\r\n ret = (ret*a % c) as isize;\r\n }\r\n a = a*a % c;\r\n b /= 2;\r\n }\r\n return ret;\r\n}\r\nfn inv(mut a:isize, c:isize) -> isize {\r\n if a == 0{\r\n return 1;\r\n }\r\n return ksm(a, c-2, c);\r\n}\r\nfn main() {\r\n let mut input = String::new();\r\n std::io::stdin().read_line(&mut input);\r\n let mut n = 0;\r\n let mut m = 0;\r\n let mut i = 0;\r\n let p:isize = 998244353;\r\n for word in input.split_whitespace(){\r\n if i == 0 {\r\n n = word.to_string().parse::().unwrap();\r\n }\r\n if i == 1{\r\n m = word.to_string().parse::().unwrap();\r\n }\r\n i += 1;\r\n }\r\n n -= 1;\r\n let mut f= vec![vec![0;(m+1) as usize];(n+1) as usize];\r\n for i in 0..(m+1) as usize {\r\n f[0][i] = 1;\r\n }\r\n\r\n let mut jc = vec![1];\r\n for i in 1..n+2 {\r\n jc.insert(i as usize, jc[(i-1) as usize] * i %p);\r\n }\r\n\r\n // println!(\"{:?}\",jc);\r\n\r\n let mut ans = 0;\r\n for i in 1..(n+1) as usize {\r\n for j in 1..(m+1) as usize {\r\n f[i][j] = f[i][j-1];\r\n for k in 0..i {\r\n let mut mi = 0;\r\n let mut t = i - k;\r\n f[i][j] = (f[i][j] + f[k][j-1]*ksm(m-j as isize+1, (k*t) as isize, p)%p*ksm(m-j as isize+1, (t*(t-1)/2) as isize , p)%p*jc[i]%p*inv(jc[t] as isize, p)%p*inv(jc[k] as isize, p)%p)%p;\r\n }\r\n }\r\n }\r\n // println!(\"{:?}\", f);\r\n println!(\"{}\", f[n as usize][m as usize]);\r\n}\r\n", "positive_code": [{"source_code": "#![allow(unused_imports)]\nuse input::*;\nuse std::{\n collections::*,\n io::{self, BufWriter, Write},\n};\nfn run(mut ss: I, mut out: O) {\n let t: u32 = 1;\n for _ in 0..t {\n case(&mut ss, &mut out);\n }\n}\nuse mod_int::*;\ndef_mint!(998244353);\nfn case(mut ss: I, mut out: O) {\n let (n, k): (usize, usize) = ss.parse();\n let f = fact::Fact::new(n + k);\n let mut dp = vec![mint(0); n + 1];\n dp[1] = mint(1);\n for i in 1..=k {\n let mut dp_next = dp.clone();\n for a in 1..n {\n for b in a + 1..=n {\n let d = b - a;\n let c = d * (a - 1) + d * (d - 1) / 2;\n let w = k - i + 1;\n d!(c, w);\n dp_next[b] += dp[a] * f.binom(b - 1, d) * Mint::from(w).pow(c);\n }\n }\n dp = dp_next;\n d!(dp);\n }\n let ans = dp[n];\n wln!(out, \"{}\", ans);\n}\nfn main() {\n let stdin = io::stdin();\n let ss = SplitWs::new(stdin.lock());\n let stdout = io::stdout();\n let out = BufWriter::new(stdout.lock());\n run(ss, out);\n}\npub mod fact {\n use super::mod_int::*;\n pub struct Fact {\n f: Vec>,\n finv: Vec>,\n }\n impl Fact {\n pub fn new(n: usize) -> Self {\n let mut f = vec![ModInt::new(0); n + 1];\n f[0] = ModInt::new(1);\n for i in 1..=n {\n f[i] = ModInt::new(i as u32) * f[i - 1];\n }\n let mut finv = vec![ModInt::new(0); n + 1];\n finv[n] = f[n].inv();\n for i in (1..=n).rev() {\n finv[i - 1] = finv[i] * ModInt::new(i as u32);\n }\n Self { f, finv }\n }\n pub fn fact(&self, x: usize) -> ModInt {\n self.f[x]\n }\n pub fn fact_inv(&self, x: usize) -> ModInt {\n self.finv[x]\n }\n pub fn binom(&self, n: usize, k: usize) -> ModInt {\n if n >= k {\n self.fact(n) * self.fact_inv(n - k) * self.fact_inv(k)\n } else {\n ModInt::new(0)\n }\n }\n pub fn perm(&self, n: usize, k: usize) -> ModInt {\n if n >= k {\n self.fact(n) * self.fact_inv(n - k)\n } else {\n ModInt::new(0)\n }\n }\n }\n}\npub mod mod_int {\n use std::{\n cmp,\n fmt::{self, Debug, Display},\n hash::Hash,\n iter::{Product, Sum},\n marker::PhantomData,\n mem,\n ops::*,\n };\n pub struct ModInt {\n x: u32,\n marker: PhantomData<*const M>,\n }\n pub trait Modulo {\n fn modulo() -> u32;\n }\n impl ModInt {\n pub fn new(x: u32) -> Self {\n Self {\n x,\n marker: PhantomData,\n }\n }\n pub fn get(self) -> u32 {\n self.x\n }\n }\n impl ModInt {\n pub fn modulo() -> u32 {\n M::modulo()\n }\n pub fn normalize(self) -> Self {\n Self::new(self.x % M::modulo())\n }\n pub fn inv(self) -> Self {\n assert_ne!(self.get(), 0);\n self.pow(M::modulo() - 2)\n }\n pub fn twice(self) -> Self {\n self + self\n }\n pub fn half(self) -> Self {\n if self.x & 1 == 0 {\n Self::new(self.x >> 1)\n } else {\n Self::new((self.x >> 1) + ((Self::modulo() + 1) >> 1))\n }\n }\n }\n impl Clone for ModInt {\n fn clone(&self) -> Self {\n Self::new(self.x)\n }\n }\n impl Copy for ModInt {}\n impl Neg for ModInt {\n type Output = Self;\n fn neg(self) -> Self {\n Self::new(if self.x != 0 { M::modulo() - self.x } else { 0 })\n }\n }\n impl Neg for &ModInt {\n type Output = ModInt;\n fn neg(self) -> Self::Output {\n -(*self)\n }\n }\n impl Add for ModInt {\n type Output = Self;\n fn add(self, rhs: Self) -> Self {\n let x = self.x + rhs.x;\n Self::new(if x < M::modulo() { x } else { x - M::modulo() })\n }\n }\n impl Sub for ModInt {\n type Output = Self;\n fn sub(self, rhs: Self) -> Self {\n let x = if self.x >= rhs.x {\n self.x - rhs.x\n } else {\n M::modulo() + self.x - rhs.x\n };\n Self::new(x)\n }\n }\n impl Mul for ModInt {\n type Output = Self;\n fn mul(self, rhs: Self) -> Self {\n let x = (self.x as u64 * rhs.x as u64) % M::modulo() as u64;\n Self::new(x as u32)\n }\n }\n impl Div for ModInt {\n type Output = Self;\n #[allow(clippy::suspicious_arithmetic_impl)]\n fn div(self, rhs: Self) -> Self {\n self * rhs.inv()\n }\n }\n macro_rules! biops {\n ($ Op : ident , $ op : ident , $ OpAssign : ident , $ op_assign : ident) => {\n impl $Op<&Self> for ModInt {\n type Output = Self;\n fn $op(self, rhs: &Self) -> Self {\n self.$op(*rhs)\n }\n }\n impl $Op> for &ModInt {\n type Output = ModInt;\n fn $op(self, rhs: ModInt) -> ModInt {\n (*self).$op(rhs)\n }\n }\n impl $Op for &ModInt {\n type Output = ModInt;\n fn $op(self, rhs: Self) -> ModInt {\n (*self).$op(*rhs)\n }\n }\n impl $OpAssign for ModInt {\n fn $op_assign(&mut self, rhs: Self) {\n *self = self.$op(rhs);\n }\n }\n impl $OpAssign<&Self> for ModInt {\n fn $op_assign(&mut self, rhs: &Self) {\n *self = self.$op(rhs);\n }\n }\n };\n }\n biops!(Add, add, AddAssign, add_assign);\n biops!(Sub, sub, SubAssign, sub_assign);\n biops!(Mul, mul, MulAssign, mul_assign);\n biops!(Div, div, DivAssign, div_assign);\n impl Sum for ModInt {\n fn sum>(iter: I) -> Self {\n iter.fold(ModInt::new(0), |x, y| x + y)\n }\n }\n impl Product for ModInt {\n fn product>(iter: I) -> Self {\n iter.fold(ModInt::new(1), |x, y| x * y)\n }\n }\n macro_rules! fold {\n ($ Trait : ident , $ f : ident) => {\n impl<'a, M: Modulo + 'a> $Trait<&'a ModInt> for ModInt {\n fn $f>>(iter: I) -> Self {\n iter.copied().$f()\n }\n }\n };\n }\n fold!(Sum, sum);\n fold!(Product, product);\n pub trait Pow {\n fn pow(self, exp: Exp) -> Self;\n }\n macro_rules! pow {\n ($ uty : ident , $ ity : ident) => {\n impl Pow<$uty> for ModInt {\n fn pow(self, mut exp: $uty) -> Self {\n if exp == 0 {\n return ModInt::new(1);\n }\n let mut res = ModInt::new(1);\n let mut base = self;\n while exp > 1 {\n if exp & 1 != 0 {\n res *= base;\n }\n exp >>= 1;\n base *= base;\n }\n base * res\n }\n }\n impl Pow<$ity> for ModInt {\n fn pow(self, exp: $ity) -> Self {\n if exp >= 0 {\n self.pow(exp as $uty)\n } else {\n self.inv().pow(-exp as $uty)\n }\n }\n }\n };\n }\n macro_rules ! impls { ($ m : ident , $ ($ uty : ident , $ ity : ident) ,*) => { $ ($ m ! ($ uty , $ ity) ;) * } ; }\n impls!(pow, usize, isize, u8, i8, u16, i16, u32, i32, u64, i64, u128, i128);\n impl Default for ModInt {\n fn default() -> Self {\n Self::new(0)\n }\n }\n impl PartialEq for ModInt {\n fn eq(&self, other: &Self) -> bool {\n self.x == other.x\n }\n }\n impl Eq for ModInt {}\n impl PartialOrd for ModInt {\n fn partial_cmp(&self, other: &Self) -> Option {\n self.x.partial_cmp(&other.x)\n }\n }\n impl Ord for ModInt {\n fn cmp(&self, other: &Self) -> cmp::Ordering {\n self.x.cmp(&other.x)\n }\n }\n impl Hash for ModInt {\n fn hash(&self, state: &mut H) {\n self.x.hash(state)\n }\n }\n macro_rules! from_uint {\n ($ ty : ident) => {\n impl From<$ty> for ModInt {\n fn from(x: $ty) -> Self {\n if mem::size_of::<$ty>() <= 4 {\n if ($ty::max_value() as u32) < M::modulo() {\n Self::new(x as u32)\n } else {\n Self::new(x as u32).normalize()\n }\n } else {\n Self::new((x % M::modulo() as $ty) as u32)\n }\n }\n }\n };\n }\n macro_rules ! impls { ($ m : ident , $ ($ ty : ident) ,*) => { $ ($ m ! ($ ty) ;) * } ; }\n impls!(from_uint, usize, u8, u16, u32, u64, u128);\n macro_rules! from_small_int {\n ($ ty : ident) => {\n impl From<$ty> for ModInt {\n fn from(x: $ty) -> Self {\n let mut x = x as i32;\n if x >= 0 {\n Self::from(x as u32)\n } else {\n while x < 0 {\n x += M::modulo() as i32;\n }\n Self::new(x as u32)\n }\n }\n }\n };\n }\n impls!(from_small_int, i8, i16, i32);\n impl Display for ModInt {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n Display::fmt(&self.x, f)\n }\n }\n impl Debug for ModInt {\n fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {\n Debug::fmt(&self.x, f)\n }\n }\n #[macro_export]\n macro_rules! def_mint {\n ($ modulo : expr) => {\n #[derive(Clone, Copy, PartialEq, Eq, Default, Debug)]\n pub struct MintModulo;\n impl crate::mod_int::Modulo for MintModulo {\n fn modulo() -> u32 {\n $modulo\n }\n }\n pub type Mint = crate::mod_int::ModInt;\n pub fn mint>(x: T) -> Mint {\n x.into()\n }\n };\n }\n}\npub mod input {\n use std::{\n io::{self, prelude::*},\n marker::PhantomData,\n mem,\n };\n pub trait Input {\n fn bytes(&mut self) -> &[u8];\n fn bytes_vec(&mut self) -> Vec {\n self.bytes().to_vec()\n }\n fn str(&mut self) -> &str {\n std::str::from_utf8(self.bytes()).unwrap()\n }\n fn parse(&mut self) -> T {\n self.parse_with(DefaultParser)\n }\n fn parse_with(&mut self, mut parser: impl Parser) -> T {\n parser.parse(self)\n }\n fn seq(&mut self) -> Seq {\n self.seq_with(DefaultParser)\n }\n fn seq_with>(&mut self, parser: P) -> Seq {\n Seq {\n input: self,\n parser,\n marker: PhantomData,\n }\n }\n }\n impl Input for &mut T {\n fn bytes(&mut self) -> &[u8] {\n (**self).bytes()\n }\n }\n pub trait Parser {\n fn parse(&mut self, s: &mut I) -> T;\n }\n impl> Parser for &mut P {\n fn parse(&mut self, s: &mut I) -> T {\n (**self).parse(s)\n }\n }\n pub trait Parse {\n fn parse(s: &mut I) -> Self;\n }\n pub struct DefaultParser;\n impl Parser for DefaultParser {\n fn parse(&mut self, s: &mut I) -> T {\n T::parse(s)\n }\n }\n pub struct Seq<'a, T, I: ?Sized, P> {\n input: &'a mut I,\n parser: P,\n marker: PhantomData<*const T>,\n }\n impl<'a, T, I: Input, P: Parser> Iterator for Seq<'a, T, I, P> {\n type Item = T;\n #[inline]\n fn next(&mut self) -> Option {\n Some(self.input.parse_with(&mut self.parser))\n }\n fn size_hint(&self) -> (usize, Option) {\n (!0, None)\n }\n }\n impl Parse for char {\n #[inline]\n fn parse(s: &mut I) -> Self {\n let s = s.bytes();\n debug_assert_eq!(s.len(), 1);\n *s.first().expect(\"zero length\") as char\n }\n }\n macro_rules ! tuple { ($ ($ T : ident) ,*) => { impl <$ ($ T : Parse) ,*> Parse for ($ ($ T ,) *) { # [inline] # [allow (unused_variables)] # [allow (clippy :: unused_unit)] fn parse < I : Input + ? Sized > (s : & mut I) -> Self { ($ ($ T :: parse (s) ,) *) } } } ; }\n tuple!();\n tuple!(A);\n tuple!(A, B);\n tuple!(A, B, C);\n tuple!(A, B, C, D);\n tuple!(A, B, C, D, E);\n tuple!(A, B, C, D, E, F);\n tuple!(A, B, C, D, E, F, G);\n #[cfg(feature = \"newer\")]\n impl Parse for [T; N] {\n fn parse(s: &mut I) -> Self {\n use std::{mem::MaybeUninit, ptr};\n struct Guard {\n arr: [MaybeUninit; N],\n i: usize,\n }\n impl Drop for Guard {\n fn drop(&mut self) {\n unsafe {\n ptr::drop_in_place(&mut self.arr[..self.i] as *mut _ as *mut [T]);\n }\n }\n }\n let mut g = Guard:: {\n arr: unsafe { MaybeUninit::uninit().assume_init() },\n i: 0,\n };\n while g.i < N {\n g.arr[g.i] = MaybeUninit::new(s.parse());\n g.i += 1;\n }\n unsafe { mem::transmute_copy(&g.arr) }\n }\n }\n macro_rules! uint {\n ($ ty : ty) => {\n impl Parse for $ty {\n #[inline]\n fn parse(s: &mut I) -> Self {\n let s = s.bytes();\n s.iter().fold(0, |x, d| 10 * x + (0xf & d) as $ty)\n }\n }\n };\n }\n macro_rules! int {\n ($ ty : ty) => {\n impl Parse for $ty {\n #[inline]\n fn parse(s: &mut I) -> Self {\n let f = |s: &[u8]| {\n s.iter()\n .fold(0 as $ty, |x, d| (10 * x).wrapping_add((0xf & d) as $ty))\n };\n let s = s.bytes();\n if let [b'-', s @ ..] = s {\n f(s).wrapping_neg()\n } else {\n f(s)\n }\n }\n }\n };\n }\n macro_rules! float {\n ($ ty : ty) => {\n impl Parse for $ty {\n fn parse(s: &mut I) -> Self {\n const POW: [$ty; 18] = [\n 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13,\n 1e14, 1e15, 1e16, 1e17,\n ];\n let s = s.bytes();\n let (minus, s) = if let Some((b'-', s)) = s.split_first() {\n (true, s)\n } else {\n (false, s)\n };\n let (int, fract) = if let Some(p) = s.iter().position(|c| *c == b'.') {\n (&s[..p], &s[p + 1..])\n } else {\n (s, &[][..])\n };\n let x = int\n .iter()\n .chain(fract)\n .fold(0u64, |x, d| 10 * x + (0xf & *d) as u64);\n let x = x as $ty;\n let x = if minus { -x } else { x };\n let exp = fract.len();\n if exp == 0 {\n x\n } else if let Some(pow) = POW.get(exp) {\n x / pow\n } else {\n x / (10.0 as $ty).powi(exp as i32)\n }\n }\n }\n };\n }\n macro_rules! from_bytes {\n ($ ty : ty) => {\n impl Parse for $ty {\n #[inline]\n fn parse(s: &mut I) -> Self {\n s.bytes().into()\n }\n }\n };\n }\n macro_rules! from_str {\n ($ ty : ty) => {\n impl Parse for $ty {\n #[inline]\n fn parse(s: &mut I) -> Self {\n s.str().into()\n }\n }\n };\n }\n macro_rules ! impls { ($ m : ident , $ ($ ty : ty) ,*) => { $ ($ m ! ($ ty) ;) * } ; }\n impls!(uint, usize, u8, u16, u32, u64, u128);\n impls!(int, isize, i8, i16, i32, i64, i128);\n impls!(float, f32, f64);\n impls!(from_bytes, Vec, Box<[u8]>);\n impls!(from_str, String);\n #[derive(Clone)]\n pub struct SplitWs {\n src: T,\n buf: Vec,\n pos: usize,\n len: usize,\n }\n const BUF_SIZE: usize = 1 << 26;\n impl SplitWs {\n pub fn new(src: T) -> Self {\n Self {\n src,\n buf: vec![0; BUF_SIZE],\n pos: 0,\n len: 0,\n }\n }\n #[inline(always)]\n fn peek(&self) -> &[u8] {\n unsafe { self.buf.get_unchecked(self.pos..self.len) }\n }\n #[inline(always)]\n fn consume(&mut self, n: usize) -> &[u8] {\n let pos = self.pos;\n self.pos += n;\n unsafe { self.buf.get_unchecked(pos..self.pos) }\n }\n fn read(&mut self) -> usize {\n self.buf.copy_within(self.pos..self.len, 0);\n self.len -= self.pos;\n self.pos = 0;\n if self.len == self.buf.len() {\n self.buf.resize(2 * self.buf.len(), 0);\n }\n loop {\n match self.src.read(&mut self.buf[self.len..]) {\n Ok(n) => {\n self.len += n;\n return n;\n }\n Err(e) if e.kind() == io::ErrorKind::WouldBlock => {}\n Err(e) => panic!(\"io error: {:?}\", e),\n }\n }\n }\n }\n impl Input for SplitWs {\n #[inline]\n fn bytes(&mut self) -> &[u8] {\n loop {\n if let Some(del) = self.peek().iter().position(|c| c.is_ascii_whitespace()) {\n if del > 0 {\n let s = self.consume(del + 1);\n return s.split_last().unwrap().1;\n } else {\n self.consume(1);\n }\n } else if self.read() == 0 {\n return self.consume(self.len - self.pos);\n }\n }\n }\n }\n}\npub mod macros {\n #[macro_export]\n macro_rules ! w { ($ ($ arg : tt) *) => { write ! ($ ($ arg) *) . unwrap () ; } }\n #[macro_export]\n macro_rules ! wln { ($ dst : expr $ (, $ ($ arg : tt) *) ?) => { { writeln ! ($ dst $ (, $ ($ arg) *) ?) . unwrap () ; # [cfg (debug_assertions)] $ dst . flush () . unwrap () ; } } }\n #[macro_export]\n macro_rules! w_iter {\n ($ dst : expr , $ fmt : expr , $ iter : expr , $ delim : expr) => {{\n let mut first = true;\n for elem in $iter {\n if first {\n w!($dst, $fmt, elem);\n first = false;\n } else {\n w!($dst, concat!($delim, $fmt), elem);\n }\n }\n }};\n ($ dst : expr , $ fmt : expr , $ iter : expr) => {\n w_iter!($dst, $fmt, $iter, \" \")\n };\n }\n #[macro_export]\n macro_rules ! w_iter_ln { ($ dst : expr , $ ($ t : tt) *) => { { w_iter ! ($ dst , $ ($ t) *) ; wln ! ($ dst) ; } } }\n #[macro_export]\n macro_rules ! e { ($ ($ t : tt) *) => { # [cfg (debug_assertions)] eprint ! ($ ($ t) *) } }\n #[macro_export]\n macro_rules ! eln { ($ ($ t : tt) *) => { # [cfg (debug_assertions)] eprintln ! ($ ($ t) *) } }\n #[macro_export]\n #[doc(hidden)]\n macro_rules ! __tstr { ($ h : expr $ (, $ t : expr) +) => { concat ! (__tstr ! ($ ($ t) ,+) , \", \" , __tstr ! (@)) } ; ($ h : expr) => { concat ! (__tstr ! () , \" \" , __tstr ! (@)) } ; () => { \"\\x1B[94m[{}:{}]\\x1B[0m\" } ; (@) => { \"\\x1B[1;92m{}\\x1B[0m = {:?}\" } }\n #[macro_export]\n macro_rules ! d { ($ ($ a : expr) ,*) => { if std :: env :: var (\"ND\") . map (| v | & v == \"0\") . unwrap_or (true) { eln ! (__tstr ! ($ ($ a) ,*) , file ! () , line ! () , $ (stringify ! ($ a) , $ a) ,*) ; } } ; }\n}\n"}, {"source_code": "// ---------- begin ModInt ----------\r\n// モンゴメリ乗算を用いる\r\n// ほぼCodeforces用\r\n// 注意\r\n// new_unchecked は値xが 0 <= x < modulo であることを仮定\r\n// ModInt の中身は正規化された値で持ってるので直接読んだり書いたりするとぶっ壊れる\r\n// 奇素数のみ\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 debug_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() -> u64 {{\");\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 = self.0 - rhs.0;\r\n if self.0 < rhs.0 {\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// ---------- begin Precalc ----------\r\nmod precalc {\r\n use super::modint::*;\r\n #[allow(dead_code)]\r\n pub struct Precalc {\r\n inv: Vec>,\r\n fact: Vec>,\r\n ifact: Vec>,\r\n }\r\n #[allow(dead_code)]\r\n impl Precalc {\r\n pub fn new(n: usize) -> Precalc {\r\n let mut inv = vec![ModInt::one(); n + 1];\r\n let mut fact = vec![ModInt::one(); n + 1];\r\n let mut ifact = vec![ModInt::one(); n + 1];\r\n for i in 2..(n + 1) {\r\n fact[i] = fact[i - 1] * ModInt::new_unchecked(i as u32);\r\n }\r\n ifact[n] = fact[n].inv();\r\n if n > 0 {\r\n inv[n] = ifact[n] * fact[n - 1];\r\n }\r\n for i in (1..n).rev() {\r\n ifact[i] = ifact[i + 1] * ModInt::new_unchecked((i + 1) as u32);\r\n inv[i] = ifact[i] * fact[i - 1];\r\n }\r\n Precalc {\r\n inv: inv,\r\n fact: fact,\r\n ifact: ifact,\r\n }\r\n }\r\n pub fn inv(&self, n: usize) -> ModInt {\r\n assert!(n > 0);\r\n self.inv[n]\r\n }\r\n pub fn fact(&self, n: usize) -> ModInt {\r\n self.fact[n]\r\n }\r\n pub fn ifact(&self, n: usize) -> ModInt {\r\n self.ifact[n]\r\n }\r\n pub fn perm(&self, n: usize, k: usize) -> ModInt {\r\n if k > n {\r\n return ModInt::zero();\r\n }\r\n self.fact[n] * self.ifact[n - k]\r\n }\r\n pub fn comb(&self, n: usize, k: usize) -> ModInt {\r\n if k > n {\r\n return ModInt::zero();\r\n }\r\n self.fact[n] * self.ifact[k] * self.ifact[n - k]\r\n }\r\n }\r\n}\r\n// ---------- end Precalc ----------\r\n\r\nuse modint::*;\r\n\r\npub trait NTTFriendly: modint::Modulo {\r\n fn order() -> usize;\r\n fn zeta() -> u32;\r\n}\r\n\r\ntype M = ModInt;\r\n\r\nimpl NTTFriendly for Mod998_244_353 {\r\n fn order() -> usize {\r\n 8388608\r\n }\r\n fn zeta() -> u32 {\r\n 15311432\r\n }\r\n}\r\n\r\n// 列に対する命令をテキトーに詰めあわせ\r\n// modint, primitive type の2つあたりで使うことを想定\r\n// +, -, *\r\n// zero を要求してないのに仮定してる場所がある\r\n//\r\n// 何も考えずに書き始めたらいろいろよくわからないことになった\r\n// 整理\r\n// 長さが等しいときの加算、減算、dot積はok\r\n// 長さが異なるときはどうする?\r\n// 0埋めされてるというイメージなので\r\n// 加算、減算は素直だがdot積はイマイチ\r\n// dot積だけ長さが等しいとしておく?\r\n// あるいは0埋めのイメージを消すか\r\n\r\nuse std::ops::*;\r\n\r\npub trait Zero: Sized + Add {\r\n fn zero() -> Self;\r\n}\r\n\r\npub fn zero() -> T {\r\n T::zero()\r\n}\r\n\r\nimpl Zero for ModInt {\r\n fn zero() -> Self {\r\n Self::zero()\r\n }\r\n}\r\n\r\nimpl Zero for usize {\r\n fn zero() -> Self {\r\n 0\r\n }\r\n}\r\n\r\npub trait ArrayAdd {\r\n type Item;\r\n fn add(&self, rhs: &[Self::Item]) -> Vec;\r\n}\r\n\r\nimpl ArrayAdd for [T]\r\nwhere\r\n T: Zero + Copy,\r\n{\r\n type Item = T;\r\n fn add(&self, rhs: &[Self::Item]) -> Vec {\r\n let mut c = vec![T::zero(); self.len().max(rhs.len())];\r\n c[..self.len()].copy_from_slice(self);\r\n c.add_assign(rhs);\r\n c\r\n }\r\n}\r\n\r\npub trait ArrayAddAssign {\r\n type Item;\r\n fn add_assign(&mut self, rhs: &[Self::Item]);\r\n}\r\n\r\nimpl ArrayAddAssign for [T]\r\nwhere\r\n T: Add + Copy,\r\n{\r\n type Item = T;\r\n fn add_assign(&mut self, rhs: &[Self::Item]) {\r\n assert!(self.len() >= rhs.len());\r\n self.iter_mut().zip(rhs).for_each(|(x, a)| *x = *x + *a);\r\n }\r\n}\r\n\r\nimpl ArrayAddAssign for Vec\r\nwhere\r\n T: Zero + Add + Copy,\r\n{\r\n type Item = T;\r\n fn add_assign(&mut self, rhs: &[Self::Item]) {\r\n if self.len() < rhs.len() {\r\n self.resize(rhs.len(), T::zero());\r\n }\r\n self.as_mut_slice().add_assign(rhs);\r\n }\r\n}\r\n\r\npub trait ArraySub {\r\n type Item;\r\n fn sub(&self, rhs: &[Self::Item]) -> Vec;\r\n}\r\n\r\nimpl ArraySub for [T]\r\nwhere\r\n T: Zero + Sub + Copy,\r\n{\r\n type Item = T;\r\n fn sub(&self, rhs: &[Self::Item]) -> Vec {\r\n let mut c = vec![T::zero(); self.len().max(rhs.len())];\r\n c[..self.len()].copy_from_slice(self);\r\n c.sub_assign(rhs);\r\n c\r\n }\r\n}\r\n\r\npub trait ArraySubAssign {\r\n type Item;\r\n fn sub_assign(&mut self, rhs: &[Self::Item]);\r\n}\r\n\r\nimpl ArraySubAssign for [T]\r\nwhere\r\n T: Sub + Copy,\r\n{\r\n type Item = T;\r\n fn sub_assign(&mut self, rhs: &[Self::Item]) {\r\n assert!(self.len() >= rhs.len());\r\n self.iter_mut().zip(rhs).for_each(|(x, a)| *x = *x - *a);\r\n }\r\n}\r\n\r\nimpl ArraySubAssign for Vec\r\nwhere\r\n T: Zero + Sub + Copy,\r\n{\r\n type Item = T;\r\n fn sub_assign(&mut self, rhs: &[Self::Item]) {\r\n if self.len() < rhs.len() {\r\n self.resize(rhs.len(), T::zero());\r\n }\r\n self.as_mut_slice().sub_assign(rhs);\r\n }\r\n}\r\n\r\npub trait ArrayDot {\r\n type Item;\r\n fn dot(&self, rhs: &[Self::Item]) -> Vec;\r\n}\r\n\r\nimpl ArrayDot for [T]\r\nwhere\r\n T: Mul + Copy,\r\n{\r\n type Item = T;\r\n fn dot(&self, rhs: &[Self::Item]) -> Vec {\r\n assert!(self.len() == rhs.len());\r\n self.iter().zip(rhs).map(|p| *p.0 * *p.1).collect()\r\n }\r\n}\r\n\r\npub trait ArrayDotAssign {\r\n type Item;\r\n fn dot_assign(&mut self, rhs: &[Self::Item]);\r\n}\r\n\r\nimpl ArrayDotAssign for [T]\r\nwhere\r\n T: MulAssign + Copy,\r\n{\r\n type Item = T;\r\n fn dot_assign(&mut self, rhs: &[Self::Item]) {\r\n assert!(self.len() == rhs.len());\r\n self.iter_mut().zip(rhs).for_each(|(x, a)| *x *= *a);\r\n }\r\n}\r\n\r\npub trait ArrayMul {\r\n type Item;\r\n fn mul(&self, rhs: &[Self::Item]) -> Vec;\r\n}\r\n\r\nimpl ArrayMul for [T]\r\nwhere\r\n T: Zero + Mul + Copy,\r\n{\r\n type Item = T;\r\n fn mul(&self, rhs: &[Self::Item]) -> Vec {\r\n if self.is_empty() || rhs.is_empty() {\r\n return vec![];\r\n }\r\n let mut res = vec![zero(); self.len() + rhs.len() - 1];\r\n for (i, a) in self.iter().enumerate() {\r\n for (c, b) in res[i..].iter_mut().zip(rhs) {\r\n *c = *c + *a * *b;\r\n }\r\n }\r\n res\r\n }\r\n}\r\n\r\npub trait ArrayNTT {\r\n type Item;\r\n fn ntt(&mut self);\r\n fn intt(&mut self);\r\n fn multiply(&self, rhs: &[Self::Item]) -> Vec;\r\n}\r\n\r\nimpl ArrayNTT for [ModInt]\r\nwhere\r\n T: NTTFriendly,\r\n{\r\n type Item = ModInt;\r\n fn ntt(&mut self) {\r\n let f = self;\r\n let n = f.len();\r\n assert!(n.count_ones() == 1);\r\n assert!(n <= T::order());\r\n let len = n.trailing_zeros() as usize;\r\n let mut es = [ModInt::zero(); 30];\r\n let mut ies = [ModInt::zero(); 30];\r\n let mut sum_e = [ModInt::zero(); 30];\r\n let cnt2 = T::order().trailing_zeros() as usize;\r\n let mut e = ModInt::new_unchecked(T::zeta());\r\n let mut ie = e.inv();\r\n for i in (2..=cnt2).rev() {\r\n es[i - 2] = e;\r\n ies[i - 2] = ie;\r\n e = e * e;\r\n ie = ie * ie;\r\n }\r\n let mut now = ModInt::one();\r\n for i in 0..(cnt2 - 1) {\r\n sum_e[i] = es[i] * now;\r\n now *= ies[i];\r\n }\r\n for ph in 1..=len {\r\n let p = 1 << (len - ph);\r\n let mut now = ModInt::one();\r\n for (i, f) in f.chunks_exact_mut(2 * p).enumerate() {\r\n let (x, y) = f.split_at_mut(p);\r\n for (x, y) in x.iter_mut().zip(y.iter_mut()) {\r\n let l = *x;\r\n let r = *y * now;\r\n *x = l + r;\r\n *y = l - r;\r\n }\r\n now *= sum_e[(!i).trailing_zeros() as usize];\r\n }\r\n }\r\n }\r\n fn intt(&mut self) {\r\n let f = self;\r\n let n = f.len();\r\n assert!(n.count_ones() == 1);\r\n assert!(n <= T::order());\r\n let len = n.trailing_zeros() as usize;\r\n let mut es = [ModInt::zero(); 30];\r\n let mut ies = [ModInt::zero(); 30];\r\n let mut sum_ie = [ModInt::zero(); 30];\r\n let cnt2 = T::order().trailing_zeros() as usize;\r\n let mut e = ModInt::new_unchecked(T::zeta());\r\n let mut ie = e.inv();\r\n for i in (2..=cnt2).rev() {\r\n es[i - 2] = e;\r\n ies[i - 2] = ie;\r\n e = e * e;\r\n ie = ie * ie;\r\n }\r\n let mut now = ModInt::one();\r\n for i in 0..(cnt2 - 1) {\r\n sum_ie[i] = ies[i] * now;\r\n now *= es[i];\r\n }\r\n for ph in (1..=len).rev() {\r\n let p = 1 << (len - ph);\r\n let mut inow = ModInt::one();\r\n for (i, f) in f.chunks_exact_mut(2 * p).enumerate() {\r\n let (x, y) = f.split_at_mut(p);\r\n for (x, y) in x.iter_mut().zip(y.iter_mut()) {\r\n let l = *x;\r\n let r = *y;\r\n *x = l + r;\r\n *y = (l - r) * inow;\r\n }\r\n inow *= sum_ie[(!i).trailing_zeros() as usize];\r\n }\r\n }\r\n let ik = ModInt::new_unchecked((T::modulo() + 1) >> 1).pow(len as u64);\r\n for f in f.iter_mut() {\r\n *f *= ik;\r\n }\r\n }\r\n fn multiply(&self, rhs: &[Self::Item]) -> Vec {\r\n if self.len().min(rhs.len()) <= 32 {\r\n return self.mul(rhs);\r\n }\r\n let size = (self.len() + rhs.len() - 1).next_power_of_two();\r\n let mut f = vec![ModInt::zero(); size];\r\n let mut g = vec![ModInt::zero(); size];\r\n f[..self.len()].copy_from_slice(self);\r\n g[..rhs.len()].copy_from_slice(rhs);\r\n f.ntt();\r\n g.ntt();\r\n f.dot_assign(&g);\r\n f.intt();\r\n f.truncate(self.len() + rhs.len() - 1);\r\n f\r\n }\r\n}\r\n\r\npub trait PolynomialOperation {\r\n type Item;\r\n fn eval(&self, x: Self::Item) -> Self::Item;\r\n fn derivative(&self) -> Vec;\r\n fn integral(&self) -> Vec;\r\n}\r\n\r\nimpl PolynomialOperation for [ModInt] {\r\n type Item = ModInt;\r\n fn eval(&self, x: Self::Item) -> Self::Item {\r\n self.iter().rev().fold(ModInt::zero(), |s, a| s * x + *a)\r\n }\r\n fn derivative(&self) -> Vec {\r\n if self.len() <= 1 {\r\n return vec![];\r\n }\r\n self[1..]\r\n .iter()\r\n .enumerate()\r\n .map(|(k, a)| ModInt::new_unchecked(k as u32 + 1) * *a)\r\n .collect()\r\n }\r\n fn integral(&self) -> Vec {\r\n if self.is_empty() {\r\n return vec![];\r\n }\r\n let mut inv = vec![ModInt::one(); self.len() + 1];\r\n let mut mul = ModInt::zero();\r\n for i in 1..=self.len() {\r\n mul += ModInt::one();\r\n inv[i] = inv[i - 1] * mul;\r\n }\r\n let mut prod = inv[self.len()].inv();\r\n for i in (1..=self.len()).rev() {\r\n inv[i] = self[i - 1] * inv[i - 1] * prod;\r\n prod *= mul;\r\n mul -= ModInt::one();\r\n }\r\n inv[0] = ModInt::zero();\r\n inv\r\n }\r\n}\r\n\r\npub trait FPSOperation {\r\n type Item;\r\n fn inverse(&self, n: usize) -> Vec;\r\n fn log(&self, n: usize) -> Vec;\r\n fn exp(&self, n: usize) -> Vec;\r\n}\r\n\r\nimpl FPSOperation for [ModInt] {\r\n type Item = ModInt;\r\n fn inverse(&self, n: usize) -> Vec {\r\n assert!(self.len() > 0 && !self[0].is_zero());\r\n let len = n.next_power_of_two();\r\n assert!(2 * len <= T::order());\r\n let mut b = vec![ModInt::zero(); n];\r\n b[0] = self[0].inv();\r\n let mut f = Vec::with_capacity(2 * len);\r\n let mut g = Vec::with_capacity(2 * len);\r\n let mut size = 1;\r\n while size < n {\r\n g.clear();\r\n g.extend(b.iter().take(size));\r\n g.resize(2 * size, ModInt::zero());\r\n f.clear();\r\n f.extend(self.iter().take(2 * size));\r\n f.resize(2 * size, ModInt::zero());\r\n f.ntt();\r\n g.ntt();\r\n f.dot_assign(&g);\r\n f.intt();\r\n f[..size].iter_mut().for_each(|f| *f = ModInt::zero());\r\n f.ntt();\r\n f.dot_assign(&g);\r\n f.intt();\r\n for (b, g) in b[size..].iter_mut().zip(&f[size..]) {\r\n *b = *b - *g;\r\n }\r\n size *= 2;\r\n }\r\n b\r\n }\r\n fn log(&self, n: usize) -> Vec {\r\n assert!(self.get(0).map_or(false, |p| p.get() == 1));\r\n let mut b = self.derivative().multiply(&self.inverse(n));\r\n b.truncate(n - 1);\r\n let mut b = b.integral();\r\n b.resize(n, ModInt::zero());\r\n b\r\n }\r\n fn exp(&self, n: usize) -> Vec {\r\n assert!(self.get(0).map_or(true, |a| a.is_zero()));\r\n assert!(n <= T::order());\r\n let mut b = vec![ModInt::one()];\r\n let mut size = 1;\r\n while size < n {\r\n size <<= 1;\r\n let f = b.log(size);\r\n let g = self[..self.len().min(size)].sub(&f);\r\n b = b.multiply(&g).add(&b);\r\n b.truncate(size);\r\n }\r\n b.truncate(n);\r\n b.resize(n, ModInt::zero());\r\n b\r\n }\r\n}\r\n\r\n// test\r\n// yuki907: https://yukicoder.me/submissions/712523\r\n// hhkb2020: https://atcoder.jp/contests/hhkb2020/submissions/26997806\r\n//\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\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 n: usize,\r\n k: usize,\r\n }\r\n let pc = precalc::Precalc::new(n * n + k);\r\n let mut dp = vec![M::zero(); n];\r\n dp[n - 1] = M::one();\r\n for i in 0..k {\r\n let mut next = dp.clone();\r\n for (j, dp) in dp.iter().enumerate() {\r\n for a in 1..=j {\r\n let mut w = *dp;\r\n w *= pc.comb(j, a);\r\n w *= M::from(k - i).pow((a * (a - 1) / 2 + a * (n - 1 - j)) as u64);\r\n next[j - a] += w;\r\n }\r\n }\r\n dp = next;\r\n }\r\n println!(\"{}\", dp[0]);\r\n}\r\n\r\nfn main() {\r\n run();\r\n}\r\n"}, {"source_code": "pub fn main() {\r\n crate::prepare!();\r\n sc!(n, k);\r\n let mut dp = vec![M::zero(); n + 1];\r\n dp[1] = M::one();\r\n let f = MemorizedFactorial::new(n);\r\n for i in 1..=k {\r\n let mut ndp = vec![M::zero(); n + 1];\r\n for j in 1..=n {\r\n if dp[j].is_zero() {\r\n continue;\r\n }\r\n for x in 0..=n - j {\r\n let d = dp[j] * f.combination(n - j, x);\r\n let nj = j + x;\r\n let e = (nj * nj.saturating_sub(1) - j * j.saturating_sub(1)) / 2;\r\n ndp[nj] += d * M::from(k - i + 1).pow(e - x);\r\n }\r\n }\r\n dp = ndp;\r\n }\r\n pp!(dp[n]);\r\n}\r\npub type M = mint_basic::MInt998244353;\r\n#[allow(unused_imports)]use std::{cmp::{Ordering,Reverse},collections::{BTreeMap,BTreeSet,BinaryHeap,HashMap,HashSet,VecDeque}};\r\nmod main_macros{#[doc=\" Prepare useful macros.\"]#[doc=\" - `prepare!();`: default (all input scanner (`sc!`, `sv!`) + buf print (`pp!`))\"]#[doc=\" - `prepare!(?);`: interactive (line scanner (`scln!`) + buf print (`pp!`))\"]#[macro_export]macro_rules!prepare{(@normal($dol:tt))=>{#[allow(unused_imports)]use std::io::Write as _;let __out=std::io::stdout();#[allow(unused_mut,unused_variables)]let mut __out=std::io::BufWriter::new(__out.lock());#[allow(unused_macros)]macro_rules!pp{($dol($dol t:tt)*)=>{$dol crate::iter_print!(__out,$dol($dol t)*)}}let __in_buf=read_stdin_all_unchecked();#[allow(unused_mut,unused_variables)]let mut __scanner=Scanner::new(&__in_buf);#[allow(unused_macros)]macro_rules!sc{($dol($dol t:tt)*)=>{$dol crate::scan!(__scanner,$dol($dol t)*)}}#[allow(unused_macros)]macro_rules!sv{($dol($dol t:tt)*)=>{$dol crate::scan_value!(__scanner,$dol($dol t)*)}}};(@interactive($dol:tt))=>{#[allow(unused_imports)]use std::io::Write as _;let __out=std::io::stdout();#[allow(unused_mut,unused_variables)]let mut __out=std::io::BufWriter::new(__out.lock());#[allow(unused_macros)]#[doc=\" - to flush: `pp!(@flush);`\"]macro_rules!pp{($dol($dol t:tt)*)=>{$dol crate::iter_print!(__out,$dol($dol t)*)}}#[allow(unused_macros)]#[doc=\" Scan a line, and previous line will be truncated in the next call.\"]macro_rules!scln{($dol($dol t:tt)*)=>{let __in_buf=read_stdin_line();#[allow(unused_mut,unused_variables)]let mut __scanner=Scanner::new(&__in_buf);$dol crate::scan!(__scanner,$dol($dol t)*)}}};()=>{$crate::prepare!(@normal($))};(?)=>{$crate::prepare!(@interactive($))};}}\r\npub use self::iter_print::IterPrint;\r\nmod iter_print{use std::{fmt::Display,io::{Error,Write}};pub trait IterPrint{fn iter_print(self,writer:&mut W,sep:S,is_head:bool)->Result<(),Error>where W:Write,S:Display;}macro_rules!iter_print_tuple_impl{(@impl$($A:ident$a:ident)?,$($B:ident$b:ident)*)=>{impl<$($A,)?$($B),*>IterPrint for($($A,)?$($B),*)where$($A:Display,)?$($B:Display),*{#[allow(unused_variables)]fn iter_print(self,writer:&mut W,sep:S,is_head:bool)->Result<(),Error>where W:Write,S:Display{let($($a,)?$($b,)*)=self;$(if is_head{::std::write!(writer,\"{}\",$a)?;}else{::std::write!(writer,\"{}{}\",sep,$a)?;})?$(::std::write!(writer,\"{}{}\",sep,$b)?;)*Ok(())}}};(@inc,,$C:ident$c:ident$($D:ident$d:ident)*)=>{iter_print_tuple_impl!(@impl,);iter_print_tuple_impl!(@inc$C$c,,$($D$d)*);};(@inc$A:ident$a:ident,$($B:ident$b:ident)*,$C:ident$c:ident$($D:ident$d:ident)*)=>{iter_print_tuple_impl!(@impl$A$a,$($B$b)*);iter_print_tuple_impl!(@inc$A$a,$($B$b)*$C$c,$($D$d)*);};(@inc$A:ident$a:ident,$($B:ident$b:ident)*,)=>{iter_print_tuple_impl!(@impl$A$a,$($B$b)*);};($($t:tt)*)=>{iter_print_tuple_impl!(@inc,,$($t)*);};}iter_print_tuple_impl!(A a B b C c D d E e F f G g H h I i J j K k);#[doc=\" Print expressions with a separator.\"]#[doc=\" - `iter_print!(writer, args...)`\"]#[doc=\" - `@sep $expr`: set separator (default: `' '`)\"]#[doc=\" - `@fmt $lit => {$($expr),*}`: print `format!($lit, $($expr),*)`\"]#[doc=\" - `@flush`: flush writer (auto insert `!`)\"]#[doc=\" - `@iter $expr`: print iterator\"]#[doc=\" - `@iterns $expr`: print iterator with no separators\"]#[doc=\" - `@iterln $expr`: print iterator with separator `'\\\\n'`\"]#[doc=\" - `@iter2d $expr`: print 2d-iterator\"]#[doc=\" - `@tuple $expr`: print tuple (need to import [`IterPrint`], each elements impls `Display`)\"]#[doc=\" - `$expr`: print expr\"]#[doc=\" - `;`: print `'\\\\n'`\"]#[doc=\" - `!`: not print `'\\\\n'` at the end\"]#[macro_export]macro_rules!iter_print{(@@fmt$writer:expr,$sep:expr,$is_head:expr,$lit:literal,$($e:expr),*)=>{if!$is_head{::std::write!($writer,\"{}\",$sep).expect(\"io error\");}::std::write!($writer,$lit,$($e),*).expect(\"io error\");};(@@item$writer:expr,$sep:expr,$is_head:expr,$e:expr)=>{$crate::iter_print!(@@fmt$writer,$sep,$is_head,\"{}\",$e);};(@@line_feed$writer:expr$(,)?)=>{::std::writeln!($writer).expect(\"io error\");};(@@iter$writer:expr,$sep:expr,$is_head:expr,$iter:expr)=>{{let mut iter=$iter.into_iter();if let Some(item)=iter.next(){$crate::iter_print!(@@item$writer,$sep,$is_head,item);}for item in iter{$crate::iter_print!(@@item$writer,$sep,false,item);}}};(@@iterns$writer:expr,$sep:expr,$is_head:expr,$iter:expr)=>{{let mut iter=$iter.into_iter();if let Some(item)=iter.next(){$crate::iter_print!(@@item$writer,$sep,$is_head,item);}for item in iter{$crate::iter_print!(@@item$writer,$sep,true,item);}}};(@@iterln$writer:expr,$sep:expr,$is_head:expr,$iter:expr)=>{{let mut iter=$iter.into_iter();if let Some(item)=iter.next(){$crate::iter_print!(@@item$writer,'\\n',$is_head,item);}for item in iter{$crate::iter_print!(@@item$writer,'\\n',false,item);}}};(@@iter2d$writer:expr,$sep:expr,$is_head:expr,$iter:expr)=>{let mut iter=$iter.into_iter();if let Some(item)=iter.next(){$crate::iter_print!(@@iter$writer,$sep,$is_head,item);}for item in iter{$crate::iter_print!(@@line_feed$writer);$crate::iter_print!(@@iter$writer,$sep,true,item);}};(@@tuple$writer:expr,$sep:expr,$is_head:expr,$tuple:expr)=>{IterPrint::iter_print($tuple,&mut$writer,$sep,$is_head).expect(\"io error\");};(@@assert_tag item)=>{};(@@assert_tag iter)=>{};(@@assert_tag iterns)=>{};(@@assert_tag iterln)=>{};(@@assert_tag iter2d)=>{};(@@assert_tag tuple)=>{};(@@assert_tag$tag:ident)=>{::std::compile_error!(::std::concat!(\"invalid tag in `iter_print!`: `\",std::stringify!($tag),\"`\"));};(@@inner$writer:expr,$sep:expr,$is_head:expr,@sep$e:expr,$($t:tt)*)=>{$crate::iter_print!(@@inner$writer,$e,$is_head,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,@flush$($t:tt)*)=>{$writer.flush().expect(\"io error\");$crate::iter_print!(@@inner$writer,$sep,$is_head,!$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,@fmt$lit:literal=>{$($e:expr),*$(,)?}$($t:tt)*)=>{$crate::iter_print!(@@fmt$writer,$sep,$is_head,$lit,$($e),*);$crate::iter_print!(@@inner$writer,$sep,$is_head,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,@$tag:ident$e:expr,$($t:tt)*)=>{$crate::iter_print!(@@assert_tag$tag);$crate::iter_print!(@@$tag$writer,$sep,$is_head,$e);$crate::iter_print!(@@inner$writer,$sep,false,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,@$tag:ident$e:expr;$($t:tt)*)=>{$crate::iter_print!(@@assert_tag$tag);$crate::iter_print!(@@$tag$writer,$sep,$is_head,$e);$crate::iter_print!(@@line_feed$writer);$crate::iter_print!(@@inner$writer,$sep,true,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,@$tag:ident$e:expr)=>{$crate::iter_print!(@@assert_tag$tag);$crate::iter_print!(@@$tag$writer,$sep,$is_head,$e);$crate::iter_print!(@@inner$writer,$sep,false,);};(@@inner$writer:expr,$sep:expr,$is_head:expr,@$tag:ident$($t:tt)*)=>{::std::compile_error!(::std::concat!(\"invalid expr in `iter_print!`: `\",std::stringify!($($t)*),\"`\"));};(@@inner$writer:expr,$sep:expr,$is_head:expr,,$($t:tt)*)=>{$crate::iter_print!(@@inner$writer,$sep,$is_head,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,;$($t:tt)*)=>{$crate::iter_print!(@@line_feed$writer);$crate::iter_print!(@@inner$writer,$sep,$is_head,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,!$(,)?)=>{};(@@inner$writer:expr,$sep:expr,$is_head:expr,!$($t:tt)*)=>{$crate::iter_print!(@@inner$writer,$sep,$is_head,$($t)*);};(@@inner$writer:expr,$sep:expr,$is_head:expr,)=>{$crate::iter_print!(@@line_feed$writer);};(@@inner$writer:expr,$sep:expr,$is_head:expr,$($t:tt)*)=>{$crate::iter_print!(@@inner$writer,$sep,$is_head,@item$($t)*);};($writer:expr,$($t:tt)*)=>{{$crate::iter_print!(@@inner$writer,' ',true,$($t)*);}};}}\r\npub use self::scanner::*;\r\nmod scanner{use std::{iter::{from_fn,repeat_with,FromIterator},marker::PhantomData};pub fn read_stdin_all()->String{use std::io::Read as _;let mut s=String::new();std::io::stdin().read_to_string(&mut s).expect(\"io error\");s}pub fn read_stdin_all_unchecked()->String{use std::io::Read as _;let mut buf=Vec::new();std::io::stdin().read_to_end(&mut buf).expect(\"io error\");unsafe{String::from_utf8_unchecked(buf)}}pub fn read_all(mut reader:impl std::io::Read)->String{let mut s=String::new();reader.read_to_string(&mut s).expect(\"io error\");s}pub fn read_all_unchecked(mut reader:impl std::io::Read)->String{let mut buf=Vec::new();reader.read_to_end(&mut buf).expect(\"io error\");unsafe{String::from_utf8_unchecked(buf)}}pub fn read_stdin_line()->String{let mut s=String::new();std::io::stdin().read_line(&mut s).expect(\"io error\");s}pub trait IterScan:Sized{type Output;fn scan<'a,I:Iterator>(iter:&mut I)->Option;}pub trait MarkedIterScan:Sized{type Output;fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option;}#[derive(Clone,Debug)]pub struct Scanner<'a>{iter:std::str::SplitAsciiWhitespace<'a>}impl<'a>Scanner<'a>{#[inline]pub fn new(s:&'a str)->Self{let iter=s.split_ascii_whitespace();Self{iter}}#[inline]pub fn scan(&mut self)->::Output where T:IterScan{::scan(&mut self.iter).expect(\"scan error\")}#[inline]pub fn mscan(&mut self,marker:T)->::Output where T:MarkedIterScan{marker.mscan(&mut self.iter).expect(\"scan error\")}#[inline]pub fn scan_vec(&mut self,size:usize)->Vec<::Output>where T:IterScan{(0..size).map(|_|::scan(&mut self.iter).expect(\"scan error\")).collect()}#[inline]pub fn iter<'b,T>(&'b mut self)->ScannerIter<'a,'b,T>where T:IterScan{ScannerIter{inner:self,_marker:std::marker::PhantomData}}}macro_rules!iter_scan_impls{($($t:ty)*)=>{$(impl IterScan for$t{type Output=Self;#[inline]fn scan<'a,I:Iterator>(iter:&mut I)->Option{iter.next()?.parse::<$t>().ok()}})*};}iter_scan_impls!(char u8 u16 u32 u64 usize i8 i16 i32 i64 isize f32 f64 u128 i128 String);macro_rules!iter_scan_tuple_impl{(@impl$($T:ident)*)=>{impl<$($T:IterScan),*>IterScan for($($T,)*){type Output=($(<$T as IterScan>::Output,)*);#[inline]fn scan<'a,It:Iterator>(_iter:&mut It)->Option{Some(($(<$T as IterScan>::scan(_iter)?,)*))}}};(@inner$($T:ident)*,)=>{iter_scan_tuple_impl!(@impl$($T)*);};(@inner$($T:ident)*,$U:ident$($Rest:ident)*)=>{iter_scan_tuple_impl!(@impl$($T)*);iter_scan_tuple_impl!(@inner$($T)*$U,$($Rest)*);};($($T:ident)*)=>{iter_scan_tuple_impl!(@inner,$($T)*);};}iter_scan_tuple_impl!(A B C D E F G H I J K);pub struct ScannerIter<'a,'b,T>{inner:&'b mut Scanner<'a>,_marker:std::marker::PhantomDataT>}impl<'a,'b,T>Iterator for ScannerIter<'a,'b,T>where T:IterScan{type Item=::Output;#[inline]fn next(&mut self)->Option{::scan(&mut self.inner.iter)}}#[doc=\" - `scan_value!(scanner, ELEMENT)`\"]#[doc=\"\"]#[doc=\" ELEMENT :=\"]#[doc=\" - `$ty`: IterScan\"]#[doc=\" - `@$expr`: MarkedIterScan\"]#[doc=\" - `[ELEMENT; $expr]`: vector\"]#[doc=\" - `[ELEMENT]`: iterator\"]#[doc=\" - `($(ELEMENT)*,)`: tuple\"]#[macro_export]macro_rules!scan_value{(@repeat$scanner:expr,[$($t:tt)*]$($len:expr)?)=>{::std::iter::repeat_with(||$crate::scan_value!(@inner$scanner,[]$($t)*))$(.take($len).collect::>())?};(@tuple$scanner:expr,[$([$($args:tt)*])*])=>{($($($args)*,)*)};(@$tag:ident$scanner:expr,[[$($args:tt)*]])=>{$($args)*};(@$tag:ident$scanner:expr,[$($args:tt)*]@$e:expr)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$scanner.mscan($e)]])};(@$tag:ident$scanner:expr,[$($args:tt)*]@$e:expr,$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$scanner.mscan($e)]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*]($($tuple:tt)*)$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$crate::scan_value!(@tuple$scanner,[]$($tuple)*)]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*][@$e:expr;$len:expr]$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$crate::scan_value!(@repeat$scanner,[@$e]$len)]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*][[$($tt:tt)*];$len:expr]$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$crate::scan_value!(@repeat$scanner,[[$($tt)*]]$len)]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*][($($tt:tt)*);$len:expr]$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$crate::scan_value!(@repeat$scanner,[($($tt)*)]$len)]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*][$ty:ty;$len:expr]$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$crate::scan_value!(@repeat$scanner,[$ty]$len)]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*][$($tt:tt)*]$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$crate::scan_value!(@repeat$scanner,[$($tt)*])]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*]$ty:ty)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$scanner.scan::<$ty>()]])};(@$tag:ident$scanner:expr,[$($args:tt)*]$ty:ty,$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*[$scanner.scan::<$ty>()]]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*],$($t:tt)*)=>{$crate::scan_value!(@$tag$scanner,[$($args)*]$($t)*)};(@$tag:ident$scanner:expr,[$($args:tt)*])=>{::std::compile_error!(::std::stringify!($($args)*))};($scanner:expr,$($t:tt)*)=>{$crate::scan_value!(@inner$scanner,[]$($t)*)}}#[doc=\" - `scan!(scanner, $($pat $(: ELEMENT)?),*)`\"]#[macro_export]macro_rules!scan{(@assert$p:pat)=>{};(@assert$($p:tt)*)=>{::std::compile_error!(::std::concat!(\"expected pattern, found `\",::std::stringify!($($p)*),\"`\"));};(@pat$scanner:expr,[][])=>{};(@pat$scanner:expr,[][],$($t:tt)*)=>{$crate::scan!(@pat$scanner,[][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]$x:ident$($t:tt)*)=>{$crate::scan!(@pat$scanner,[$($p)*$x][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]::$($t:tt)*)=>{$crate::scan!(@pat$scanner,[$($p)*::][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]&$($t:tt)*)=>{$crate::scan!(@pat$scanner,[$($p)*&][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]($($x:tt)*)$($t:tt)*)=>{$crate::scan!(@pat$scanner,[$($p)*($($x)*)][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][][$($x:tt)*]$($t:tt)*)=>{$crate::scan!(@pat$scanner,[$($p)*[$($x)*]][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]{$($x:tt)*}$($t:tt)*)=>{$crate::scan!(@pat$scanner,[$($p)*{$($x)*}][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]:$($t:tt)*)=>{$crate::scan!(@ty$scanner,[$($p)*][]$($t)*)};(@pat$scanner:expr,[$($p:tt)*][]$($t:tt)*)=>{$crate::scan!(@let$scanner,[$($p)*][usize]$($t)*)};(@ty$scanner:expr,[$($p:tt)*][$($tt:tt)*]@$e:expr)=>{$crate::scan!(@let$scanner,[$($p)*][$($tt)*@$e])};(@ty$scanner:expr,[$($p:tt)*][$($tt:tt)*]@$e:expr,$($t:tt)*)=>{$crate::scan!(@let$scanner,[$($p)*][$($tt)*@$e],$($t)*)};(@ty$scanner:expr,[$($p:tt)*][$($tt:tt)*]($($x:tt)*)$($t:tt)*)=>{$crate::scan!(@let$scanner,[$($p)*][$($tt)*($($x)*)]$($t)*)};(@ty$scanner:expr,[$($p:tt)*][$($tt:tt)*][$($x:tt)*]$($t:tt)*)=>{$crate::scan!(@let$scanner,[$($p)*][$($tt)*[$($x)*]]$($t)*)};(@ty$scanner:expr,[$($p:tt)*][$($tt:tt)*]$ty:ty)=>{$crate::scan!(@let$scanner,[$($p)*][$($tt)*$ty])};(@ty$scanner:expr,[$($p:tt)*][$($tt:tt)*]$ty:ty,$($t:tt)*)=>{$crate::scan!(@let$scanner,[$($p)*][$($tt)*$ty],$($t)*)};(@let$scanner:expr,[$($p:tt)*][$($tt:tt)*]$($t:tt)*)=>{$crate::scan!{@assert$($p)*}let$($p)* =$crate::scan_value!($scanner,$($tt)*);$crate::scan!(@pat$scanner,[][]$($t)*)};($scanner:expr,$($t:tt)*)=>{$crate::scan!(@pat$scanner,[][]$($t)*)}}#[derive(Debug,Copy,Clone)]pub struct Usize1;impl IterScan for Usize1{type Output=usize;#[inline]fn scan<'a,I:Iterator>(iter:&mut I)->Option{::scan(iter)?.checked_sub(1)}}#[derive(Debug,Copy,Clone)]pub struct CharWithBase(pub char);impl MarkedIterScan for CharWithBase{type Output=usize;#[inline]fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{Some((::scan(iter)?as u8-self.0 as u8)as usize)}}#[derive(Debug,Copy,Clone)]pub struct Chars;impl IterScan for Chars{type Output=Vec;#[inline]fn scan<'a,I:Iterator>(iter:&mut I)->Option{Some(iter.next()?.chars().collect())}}#[derive(Debug,Copy,Clone)]pub struct CharsWithBase(pub char);impl MarkedIterScan for CharsWithBase{type Output=Vec;#[inline]fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{Some(iter.next()?.chars().map(|c|(c as u8-self.0 as u8)as usize).collect())}}#[derive(Debug,Copy,Clone)]pub struct ByteWithBase(pub u8);impl MarkedIterScan for ByteWithBase{type Output=usize;#[inline]fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{Some((::scan(iter)?as u8-self.0)as usize)}}#[derive(Debug,Copy,Clone)]pub struct Bytes;impl IterScan for Bytes{type Output=Vec;#[inline]fn scan<'a,I:Iterator>(iter:&mut I)->Option{Some(iter.next()?.bytes().collect())}}#[derive(Debug,Copy,Clone)]pub struct BytesWithBase(pub u8);impl MarkedIterScan for BytesWithBase{type Output=Vec;#[inline]fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{Some(iter.next()?.bytes().map(|c|(c-self.0)as usize).collect())}}#[derive(Debug,Copy,Clone)]pub struct Collect::Output>>where T:IterScan,B:FromIterator<::Output>{size:usize,_marker:PhantomData(T,B)>}implCollectwhere T:IterScan,B:FromIterator<::Output>{pub fn new(size:usize)->Self{Self{size,_marker:PhantomData}}}implMarkedIterScan for Collectwhere T:IterScan,B:FromIterator<::Output>{type Output=B;#[inline]fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{repeat_with(||::scan(iter)).take(self.size).collect()}}#[derive(Debug,Copy,Clone)]pub struct SizedCollect::Output>>where T:IterScan,B:FromIterator<::Output>{_marker:PhantomData(T,B)>}implIterScan for SizedCollectwhere T:IterScan,B:FromIterator<::Output>{type Output=B;#[inline]fn scan<'a,I:Iterator>(iter:&mut I)->Option{let size=usize::scan(iter)?;repeat_with(||::scan(iter)).take(size).collect()}}#[derive(Debug,Copy,Clone)]pub struct Splittedwhere T:IterScan{pat:P,_marker:PhantomDataT>}implSplittedwhere T:IterScan{pub fn new(pat:P)->Self{Self{pat,_marker:PhantomData}}}implMarkedIterScan for Splittedwhere T:IterScan{type Output=Vec<::Output>;fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{let mut iter=iter.next()?.split(self.pat);Some(from_fn(||::scan(&mut iter)).collect())}}implMarkedIterScan for Splittedwhere T:IterScan{type Output=Vec<::Output>;fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{let mut iter=iter.next()?.split(self.pat);Some(from_fn(||::scan(&mut iter)).collect())}}implMarkedIterScan for F where F:Fn(&str)->Option{type Output=T;fn mscan<'a,I:Iterator>(self,iter:&mut I)->Option{self(iter.next()?)}}}\r\npub mod mint_basic{use super::*;#[macro_export]macro_rules!define_basic_mintbase{($name:ident,$m:expr,$basety:ty,$signedty:ty,$upperty:ty,[$($unsigned:ty),*],[$($signed:ty),*])=>{pub struct$name;impl MIntBase for$name{type Inner=$basety;#[inline]fn get_mod()->Self::Inner{$m}#[inline]fn mod_zero()->Self::Inner{0}#[inline]fn mod_one()->Self::Inner{1}#[inline]fn mod_add(x:Self::Inner,y:Self::Inner)->Self::Inner{let z=x+y;let m=Self::get_mod();if z>=m{z-m}else{z}}#[inline]fn mod_sub(x:Self::Inner,y:Self::Inner)->Self::Inner{if xSelf::Inner{(x as$upperty*y as$upperty%Self::get_mod()as$upperty)as$basety}#[inline]fn mod_div(x:Self::Inner,y:Self::Inner)->Self::Inner{Self::mod_mul(x,Self::mod_inv(y))}#[inline]fn mod_neg(x:Self::Inner)->Self::Inner{if x==0{0}else{Self::get_mod()-x}}fn mod_inv(x:Self::Inner)->Self::Inner{let p=Self::get_mod()as$signedty;let(mut a,mut b)=(x as$signedty,p);let(mut u,mut x)=(1,0);while a!=0{let k=b/a;x-=k*u;b-=k*a;std::mem::swap(&mut x,&mut u);std::mem::swap(&mut b,&mut a);}(if x<0{x+p}else{x})as _}}$(impl MIntConvert<$unsigned>for$name{#[inline]fn from(x:$unsigned)->Self::Inner{(x%::get_mod()as$unsigned)as$basety}#[inline]fn into(x:Self::Inner)->$unsigned{x as$unsigned}#[inline]fn mod_into()->$unsigned{::get_mod()as$unsigned}})*$(impl MIntConvert<$signed>for$name{#[inline]fn from(x:$signed)->Self::Inner{let x=x%::get_mod()as$signed;if x<0{(x+::get_mod()as$signed)as$basety}else{x as$basety}}#[inline]fn into(x:Self::Inner)->$signed{x as$signed}#[inline]fn mod_into()->$signed{::get_mod()as$signed}})*};}#[macro_export]macro_rules!define_basic_mint32{($([$name:ident,$m:expr,$mint_name:ident]),*)=>{$(crate::define_basic_mintbase!($name,$m,u32,i32,u64,[u32,u64,u128,usize],[i32,i64,i128,isize]);pub type$mint_name=MInt<$name>;)*};}define_basic_mint32!([Modulo998244353,998_244_353,MInt998244353],[Modulo1000000007,1_000_000_007,MInt1000000007],[Modulo1000000009,1_000_000_009,MInt1000000009],[DynModuloU32,DYN_MODULUS_U32.with(|cell|unsafe{*cell.get()}),DynMIntU32]);thread_local!(static DYN_MODULUS_U32:std::cell::UnsafeCell =std::cell::UnsafeCell::new(1_000_000_007));impl DynModuloU32{pub fn set_mod(m:u32){DYN_MODULUS_U32.with(|cell|unsafe{*cell.get()=m})}}thread_local!(static DYN_MODULUS_U64:std::cell::UnsafeCell =std::cell::UnsafeCell::new(1_000_000_007));define_basic_mintbase!(DynModuloU64,DYN_MODULUS_U64.with(|cell|unsafe{*cell.get()}),u64,i64,u128,[u64,u128,usize],[i64,i128,isize]);impl DynModuloU64{pub fn set_mod(m:u64){DYN_MODULUS_U64.with(|cell|unsafe{*cell.get()=m})}}pub type DynMIntU64=MInt;pub struct Modulo2;impl MIntBase for Modulo2{type Inner=u32;#[inline]fn get_mod()->Self::Inner{2}#[inline]fn mod_zero()->Self::Inner{0}#[inline]fn mod_one()->Self::Inner{1}#[inline]fn mod_add(x:Self::Inner,y:Self::Inner)->Self::Inner{x^y}#[inline]fn mod_sub(x:Self::Inner,y:Self::Inner)->Self::Inner{x^y}#[inline]fn mod_mul(x:Self::Inner,y:Self::Inner)->Self::Inner{x&y}#[inline]fn mod_div(x:Self::Inner,y:Self::Inner)->Self::Inner{assert_ne!(y,0);x}#[inline]fn mod_neg(x:Self::Inner)->Self::Inner{x}#[inline]fn mod_inv(x:Self::Inner)->Self::Inner{assert_ne!(x,0);x}#[inline]fn mod_pow(x:Self::Inner,y:usize)->Self::Inner{if y==0{1}else{x}}}macro_rules!impl_to_mint_base_for_modulo2{($name:ident,$basety:ty,[$($t:ty),*])=>{$(impl MIntConvert<$t>for$name{#[inline]fn from(x:$t)->Self::Inner{(x&1)as$basety}#[inline]fn into(x:Self::Inner)->$t{x as$t}#[inline]fn mod_into()->$t{1}})*};}impl_to_mint_base_for_modulo2!(Modulo2,u32,[u8,u16,u32,u64,u128,usize,i8,i16,i32,i64,i128,isize]);pub type MInt2=MInt;}\r\n#[repr(transparent)]pub struct MIntwhere M:MIntBase{x:M::Inner,_marker:std::marker::PhantomDataM>}\r\npub trait MIntBase{type Inner:Sized+Copy+Eq+std::fmt::Debug+std::hash::Hash;fn get_mod()->Self::Inner;fn mod_zero()->Self::Inner;fn mod_one()->Self::Inner;fn mod_add(x:Self::Inner,y:Self::Inner)->Self::Inner;fn mod_sub(x:Self::Inner,y:Self::Inner)->Self::Inner;fn mod_mul(x:Self::Inner,y:Self::Inner)->Self::Inner;fn mod_div(x:Self::Inner,y:Self::Inner)->Self::Inner;fn mod_neg(x:Self::Inner)->Self::Inner;fn mod_inv(x:Self::Inner)->Self::Inner;fn mod_pow(x:Self::Inner,y:usize)->Self::Inner{let(mut x,mut y,mut z)=(x,y,Self::mod_one());while y>0{if y&1==1{z=Self::mod_mul(z,x);}x=Self::mod_mul(x,x);y>>=1;}z}}\r\npub trait MIntConvert::Inner>:MIntBase{fn from(x:T)->::Inner;fn into(x:::Inner)->T;fn mod_into()->T;}\r\nmod mint_base{use super::*;use std::{fmt::{self,Debug,Display},hash::{Hash,Hasher},iter::{Product,Sum},marker::PhantomData,ops::{Add,AddAssign,Div,DivAssign,Mul,MulAssign,Neg,Sub,SubAssign},str::FromStr};implMIntwhere M:MIntConvert{#[inline]pub fn new(x:M::Inner)->Self{Self::new_unchecked(>::from(x))}#[inline]pub fn inner(self)->M::Inner{>::into(self.x)}}implMIntwhere M:MIntBase{#[inline]pub fn new_unchecked(x:M::Inner)->Self{Self{x,_marker:PhantomData}}#[inline]pub fn get_mod()->M::Inner{M::get_mod()}#[inline]pub fn pow(self,y:usize)->Self{Self::new_unchecked(M::mod_pow(self.x,y))}#[inline]pub fn inv(self)->Self{Self::new_unchecked(M::mod_inv(self.x))}}implClone for MIntwhere M:MIntBase{#[inline]fn clone(&self)->Self{Self{x:Clone::clone(&self.x),_marker:PhantomData}}}implCopy for MIntwhere M:MIntBase{}implDebug for MIntwhere M:MIntBase{fn fmt(&self,f:&mut fmt::Formatter<'_>)->fmt::Result{Debug::fmt(&self.x,f)}}implDefault for MIntwhere M:MIntBase{#[inline]fn default()->Self{::zero()}}implPartialEq for MIntwhere M:MIntBase{#[inline]fn eq(&self,other:&Self)->bool{PartialEq::eq(&self.x,&other.x)}}implEq for MIntwhere M:MIntBase{}implHash for MIntwhere M:MIntBase{#[inline]fn hash(&self,state:&mut H){Hash::hash(&self.x,state)}}macro_rules!impl_mint_from{($($t:ty),*)=>{$(implFrom<$t>for MIntwhere M:MIntConvert<$t>,{#[inline]fn from(x:$t)->Self{Self::new_unchecked(>::from(x))}}implFrom>for$t where M:MIntConvert<$t>,{#[inline]fn from(x:MInt)->$t{>::into(x.x)}})*};}impl_mint_from!(u8,u16,u32,u64,u128,usize,i8,i16,i32,i64,i128,isize);implZero for MIntwhere M:MIntBase{#[inline]fn zero()->Self{Self::new_unchecked(M::mod_zero())}}implOne for MIntwhere M:MIntBase{#[inline]fn one()->Self{Self::new_unchecked(M::mod_one())}}implAdd for MIntwhere M:MIntBase{type Output=Self;#[inline]fn add(self,rhs:Self)->Self::Output{Self::new_unchecked(M::mod_add(self.x,rhs.x))}}implSub for MIntwhere M:MIntBase{type Output=Self;#[inline]fn sub(self,rhs:Self)->Self::Output{Self::new_unchecked(M::mod_sub(self.x,rhs.x))}}implMul for MIntwhere M:MIntBase{type Output=Self;#[inline]fn mul(self,rhs:Self)->Self::Output{Self::new_unchecked(M::mod_mul(self.x,rhs.x))}}implDiv for MIntwhere M:MIntBase{type Output=Self;#[inline]fn div(self,rhs:Self)->Self::Output{Self::new_unchecked(M::mod_div(self.x,rhs.x))}}implNeg for MIntwhere M:MIntBase{type Output=Self;#[inline]fn neg(self)->Self::Output{Self::new_unchecked(M::mod_neg(self.x))}}implSum for MIntwhere M:MIntBase{#[inline]fn sum>(iter:I)->Self{iter.fold(::zero(),Add::add)}}implProduct for MIntwhere M:MIntBase{#[inline]fn product>(iter:I)->Self{iter.fold(::one(),Mul::mul)}}impl<'a,M:'a>Sum<&'a MInt>for MIntwhere M:MIntBase{#[inline]fn sum>(iter:I)->Self{iter.fold(::zero(),Add::add)}}impl<'a,M:'a>Product<&'a MInt>for MIntwhere M:MIntBase{#[inline]fn product>(iter:I)->Self{iter.fold(::one(),Mul::mul)}}implDisplay for MIntwhere M:MIntConvert,M::Inner:Display{fn fmt<'a>(&self,f:&mut fmt::Formatter<'a>)->Result<(),fmt::Error>{write!(f,\"{}\",self.inner())}}implFromStr for MIntwhere M:MIntConvert,M::Inner:FromStr{type Err=::Err;#[inline]fn from_str(s:&str)->Result{s.parse::().map(Self::new)}}implIterScan for MIntwhere M:MIntConvert,M::Inner:FromStr{type Output=Self;#[inline]fn scan<'a,I:Iterator>(iter:&mut I)->Option{iter.next()?.parse::>().ok()}}macro_rules!impl_mint_ref_binop{($imp:ident,$method:ident,$t:ty)=>{impl$imp<$t>for&$t where M:MIntBase,{type Output=<$t as$imp<$t>>::Output;#[inline]fn$method(self,other:$t)-><$t as$imp<$t>>::Output{$imp::$method(*self,other)}}impl$imp<&$t>for$t where M:MIntBase,{type Output=<$t as$imp<$t>>::Output;#[inline]fn$method(self,other:&$t)-><$t as$imp<$t>>::Output{$imp::$method(self,*other)}}impl$imp<&$t>for&$t where M:MIntBase,{type Output=<$t as$imp<$t>>::Output;#[inline]fn$method(self,other:&$t)-><$t as$imp<$t>>::Output{$imp::$method(*self,*other)}}};}impl_mint_ref_binop!(Add,add,MInt);impl_mint_ref_binop!(Sub,sub,MInt);impl_mint_ref_binop!(Mul,mul,MInt);impl_mint_ref_binop!(Div,div,MInt);macro_rules!impl_mint_ref_unop{($imp:ident,$method:ident,$t:ty)=>{impl$imp for&$t where M:MIntBase,{type Output=<$t as$imp>::Output;#[inline]fn$method(self)-><$t as$imp>::Output{$imp::$method(*self)}}};}impl_mint_ref_unop!(Neg,neg,MInt);macro_rules!impl_mint_ref_op_assign{($imp:ident,$method:ident,$t:ty,$fromimp:ident,$frommethod:ident)=>{impl$imp<$t>for$t where M:MIntBase,{#[inline]fn$method(&mut self,rhs:$t){*self=$fromimp::$frommethod(*self,rhs);}}impl$imp<&$t>for$t where M:MIntBase,{#[inline]fn$method(&mut self,other:&$t){$imp::$method(self,*other);}}};}impl_mint_ref_op_assign!(AddAssign,add_assign,MInt,Add,add);impl_mint_ref_op_assign!(SubAssign,sub_assign,MInt,Sub,sub);impl_mint_ref_op_assign!(MulAssign,mul_assign,MInt,Mul,mul);impl_mint_ref_op_assign!(DivAssign,div_assign,MInt,Div,div);}\r\npub use self::zero_one::{One,Zero};\r\nmod zero_one{pub trait Zero:Sized{fn zero()->Self;#[inline]fn is_zero(&self)->bool where Self:PartialEq{self==&Self::zero()}#[inline]fn set_zero(&mut self){*self=Self::zero();}}pub trait One:Sized{fn one()->Self;#[inline]fn is_one(&self)->bool where Self:PartialEq{self==&Self::one()}#[inline]fn set_one(&mut self){*self=Self::one();}}macro_rules!zero_one_impls{($({$Trait:ident$method:ident$($t:ty)*,$e:expr})*)=>{$($(impl$Trait for$t{fn$method()->Self{$e}})*)*};}zero_one_impls!({Zero zero u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128,0}{Zero zero f32 f64,0.}{One one u8 u16 u32 u64 usize i8 i16 i32 i64 isize u128 i128,1}{One one f32 f64,1.});}\r\n#[derive(Clone,Debug)]pub struct MemorizedFactorial>{pub fact:Vec>,pub inv_fact:Vec>}\r\nimpl>MemorizedFactorial{pub fn new(max_n:usize)->Self{let mut fact=vec![MInt::one();max_n+1];let mut inv_fact=vec![MInt::one();max_n+1];for i in 2..=max_n{fact[i]=fact[i-1]*MInt::from(i);}inv_fact[max_n]=fact[max_n].inv();for i in(3..=max_n).rev(){inv_fact[i-1]=inv_fact[i]*MInt::from(i);}Self{fact,inv_fact}}#[inline]pub fn combination(&self,n:usize,r:usize)->MInt{debug_assert!(nMInt{debug_assert!(nMInt{debug_assert!(n+rMInt{debug_assert!(n0);self.inv_fact[n]*self.fact[n-1]}}\r\n"}, {"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\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 \n#[allow(non_snake_case, non_upper_case_globals)]\nfn main() {\n let num_cases: usize = 1;//read();\n for _case_num in 1..=num_cases {\n let n = read!(usize);\n let k = read!(usize);\n let mc = ModCombinatorics::new(n-1);\n\n fn c2(n: usize) -> usize {\n n * n.saturating_sub(1) / 2\n }\n let m = c2(n-1);\n\n let mut dp = vec![mi(0); n];\n dp[0] = mi(1);\n for x in 0..k {\n let R = mi(k - x).pow_vec(m);\n for j in (1..n).rev() {\n for i in 0..j {\n let d = dp[i] * R[c2(j) - c2(i)] * mc.C(n-1-i, j-i);\n dp[j] += d;\n }\n }\n //dbg!(&dp);\n }\n\n let ans = dp[n-1];\n println!(ans);\n }\n \n out_flush();\n}"}], "negative_code": [], "src_uid": "b2d7ac8e75cbdb828067aeafd803ac62"} {"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 b = rin.l();\n\tlet s = rin.vb();\n\tlet n = s.len();\n\tlet mut dp = v!([n+1] = std::i64::MAX);\n\tdp[0] = 0;\n\tfor i in 0..n {\n\t\tlet mut x = 0;\n\t\tfor j in i..n {\n\t\t\tx = x * 10 + (s[j] - b'0') as i64;\n\t\t\tif (s[i] == b'0' && j > i) || x >= b {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tmin!(dp[j+1], dp[i].saturating_mul(b).saturating_add(x));\n\t\t}\n\t}\n\twriteln!(rout, \"{}\", dp[n]).ok();\n}\n", "positive_code": [{"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 = parse_line!(u64);\n let s: Vec<_> = parse_line!(String).bytes().map(|c| (c - b'0') as u64).collect();\n let l = s.len();\n let mut dp = vec![std::u64::MAX; l + 1];\n dp[0] = 0;\n let mut digits = vec![0; l + 1];\n for (i, &c) in s.iter().enumerate() {\n for j in (1..=i + 1).rev() {\n digits[j] = digits[j - 1] * 10 + c;\n }\n for j in 0..=i {\n if digits[j + 1] >= n {\n break;\n }\n if j > 0 && s[i - j] == 0 {\n continue;\n }\n dp[i + 1] = std::cmp::min(dp[i + 1], dp[i - j] * n + digits[j + 1]);\n }\n }\n println!(\"{}\", dp[l]);\n}\n\nfn main() {\n let tests = 1; // parse_line!(usize);\n for _ in 0..tests {\n solve();\n }\n}\n"}, {"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.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {\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 numero(v: &[i64], b: i64) -> Option {\n let mut cur: i64 = 0;\n for &t in v.iter() {\n cur = match cur.checked_mul(b) {\n Some(v) => v,\n None => return None,\n };\n cur = match cur.checked_add(t) {\n Some(v) => v,\n None => return None,\n }\n }\n Some(cur)\n}\n\nfn checked_propagate(b: i64, x: i64, y: i64) -> Option {\n let cur = match x.checked_mul(b) {\n Some(v) => v,\n None => return None,\n };\n cur.checked_add(y)\n}\n\n\nfn main() {\n let b: i64 = get();\n let s: Vec<_> = get_word().bytes().map(|b| b as i64 - 0x30).collect();\n let n = s.len();\n if b <= 9 {\n // simply read b-base rep.\n let mut cur = 0;\n for v in s {\n cur *= b;\n cur += v;\n }\n println!(\"{}\", cur);\n return;\n }\n let mut dp = vec![-1i64; n + 1];\n const INF: i64 = 1i64 << 60;\n dp[0] = 0;\n for i in 1 .. n + 1 {\n let mut mi = INF;\n for j in 1 .. i + 1 {\n // s[i - j ..i] < b ?\n if j >= 10 || dp[i - j] < 0 || (j >= 2 && s[i - j] == 0) {\n continue;\n }\n let sl = numero(&s[i - j .. i], 10);\n match sl {\n Some(v) if v < b => match checked_propagate(b, dp[i - j], v) {\n Some(v) => { mi = min(mi, v) },\n None => {},\n },\n _ => {},\n }\n }\n if mi < INF {\n dp[i] = mi;\n }\n }\n //println!(\"{:?}\", dp);\n println!(\"{}\", dp[n]);\n}\n"}], "negative_code": [{"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 b = rin.l();\n\tlet s = rin.vb();\n\tlet n = s.len();\n\tlet mut dp = v!([n+1] = std::i64::MAX);\n\tdp[0] = 0;\n\tfor i in 0..n {\n\t\tlet mut x = 0;\n\t\tfor j in i..n {\n\t\t\tx = x * 10 + (s[j] - b'0') as i64;\n\t\t\tif (s[i] == b'0' && j > i) || x >= b {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tmin!(dp[j+1], dp[i] * b + x);\n\t\t}\n\t}\n\twriteln!(rout, \"{}\", dp[n]).ok();\n}\n"}, {"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.is_err() || res.ok().unwrap() == 0 || u8b[0] <= ' ' as u8 {\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 numero(v: &[i64], b: i64) -> i64 {\n let mut cur = 0;\n for &t in v.iter() {\n cur *= b;\n cur += t;\n }\n cur\n}\n\nfn main() {\n let b: i64 = get();\n let s: Vec<_> = get_word().bytes().map(|b| b as i64 - 0x30).collect();\n let n = s.len();\n if b <= 9 {\n // simply read b-base rep.\n let mut cur = 0;\n for v in s {\n cur *= b;\n cur += v;\n }\n println!(\"{}\", cur);\n return;\n }\n let mut dp = vec![-1i64; n + 1];\n const INF: i64 = 1i64 << 60;\n dp[0] = 0;\n for i in 1 .. n + 1 {\n let mut mi = INF;\n for j in 1 .. i + 1 {\n // s[i - j ..i] < b ?\n if j >= 10 || dp[i - j] < 0 || (j >= 2 && s[i - j] == 0) ||\n numero(&s[i - j .. i], 10) >= b {\n continue;\n }\n mi = min(mi, b * dp[i - j] + numero(&s[i - j .. i], 10));\n }\n if mi < INF {\n dp[i] = mi;\n }\n }\n println!(\"{}\", dp[n]);\n}\n"}], "src_uid": "be66399c558c96566a6bb0a63d2503e5"} {"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: usize = scan.next();\n let mut x: usize = 0;\n while n>0 {\n if n&1 == 1 {\n x += 1;\n }\n n >>= 1;\n }\n println!(\"{}\", x);\n}\n\nfn main() {\n std::thread::Builder::new()\n .stack_size(1<<23).spawn(_main).unwrap().join().unwrap();\n}\n", "positive_code": [{"source_code": "fn count(n: u32) -> u32 {\n if n == 1 {\n return 1;\n }\n\n if n % 2 == 1 {\n 1 + count(n / 2)\n } else {\n count(n / 2)\n }\n}\n\nfn main() {\n let n = {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n };\n\n println!(\"{}\", count(n));\n}"}, {"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 n = input.i();\n let mut sol = 0;\n while n > 0 {\n sol += 1;\n n -= n & -n;\n }\n println!(\"{}\", sol);\n}\n\n"}, {"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 solve(x:i32) -> i32 {\n if x==0 {\n return 0;\n } else if (x%2) == 0 {\n return solve(x/2);\n } else if (x%2) == 1 {\n return 1+solve(x/2);\n }\n return -1;\n}\n\nfn main() {\n let n = readln!(i32);\n println!(\"{}\",solve(n));\n}\n"}, {"source_code": "use std::io::stdin;\n\nfn main() {\n\tlet mut n = String::new();\n\tstdin().read_line(&mut n).unwrap();\n\tlet n: i64 = n.trim().parse().unwrap();\n\n\tlet mut ans: i8 = 0;\n\tfor bit in 0..64 {\n\t\tif n & 1< 0 {\n\t\t\tans += 1;\n\t\t}\n\t}\n\tprintln!(\"{}\", ans);\n}\n"}, {"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 (x, ) = R!(usize);\n let mut ans = 0;\n for i in 0.. {\n if (x >> i) == 0 {\n break;\n }\n ans += (x >> i) % 2;\n }\n println!(\"{}\", ans);\n}\n"}, {"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 a:i64=s.trim().parse::().unwrap();\n let mut sum:i64=0;\n while a!=0{\n sum+=a%2;\n a/=2;\n }\n println!(\"{}\",sum);\n}"}, {"source_code": "use std::io;\n\nfn read_line() -> (i32) {\n let mut input = String::new();\n \n io::stdin().read_line(&mut input).unwrap();\n \n let n: i32 = input.trim().parse().unwrap();\n\n n\n}\n\nfn main(){\n \n let mut n = read_line();\n let mut bacterias = 0;\n\n while n > 0 {\n bacterias += n % 2;\n n = n /2;\n }\n\n println!(\"{}\", bacterias);\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/579/A\nuse std::io;\n\nfn main() {\n let mut n = String::new();\n\n io::stdin()\n .read_line(&mut n)\n .unwrap();\n\n let n: i64 = n.trim().parse().unwrap();\n\n let mut ans = 0;\n\n for bit in 0..64 {\n if (n & (1< 0 {\n ans += 1;\n }\n }\n\n println!(\"{}\", ans);\n}\n\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::io;\nuse std::cmp::{min, max};\nuse std::mem;\nuse std::str::FromStr;\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Scanner {\n Scanner {\n reader: reader,\n buffer: Vec::new(),\n }\n }\n\n /// Use \"turbofish\" syntax next::() to select data type of next token.\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n\n pub fn next_vec(&mut self, len: usize) -> Vec\n where\n T::Err: ::std::fmt::Debug,\n {\n (0..len).map(|_| self.next::()).collect::>()\n }\n}\n\nfn main1() {\n let stdin = io::stdin();\n let mut input = Scanner::new(stdin.lock());\n let n = input.next::();\n println!(\"{}\", n.count_ones());\n\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}\n"}, {"source_code": "use std::io;\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 main() {\n let n: usize = read_line().parse().unwrap();\n println!(\"{}\", n.count_ones());\n}"}], "negative_code": [{"source_code": "use std::io;\n\nfn read_line() -> (i64) {\n let mut input = String::new();\n \n io::stdin().read_line(&mut input).unwrap();\n \n let n: i64 = input.trim().parse().unwrap();\n\n n\n}\n\nfn main(){\n \n let n = read_line();\n\n if n % 2 == 0 {\n println!(\"1\");\n } else {\n println!(\"2\");\n }\n\n}\n"}, {"source_code": "use std::io;\n\nfn read_line() -> (f64) {\n let mut input = String::new();\n \n io::stdin().read_line(&mut input).unwrap();\n \n let n: f64 = input.trim().parse().unwrap();\n\n n\n}\n\nfn main(){\n \n let n = read_line();\n\n let log = n.log2().floor();\n let bacterias = 1.0 + (n - (2.0 as f64).powf(log));\n\n println!(\"{}\", bacterias as i64);\n}\n"}], "src_uid": "03e4482d53a059134676f431be4c16d2"} {"source_code": "use std::io;\n\nfn main() {\n\tlet mut n = String::new();\n\tio::stdin().read_line(&mut n).expect(\"Time to panic\");\n\tlet n: u64 = n.trim().parse().unwrap();\n\tif n % 2 != 0 {\n\t\tprintln!(\"Ehab\");\n\t} else {\n\t\tprintln!(\"Mahmoud\")\n\t}\n}\n", "positive_code": [{"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::collections::{HashMap, HashSet};\nuse std::io::{stdin, stdout, BufWriter, 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 solve () {\n let mut scan = Scanner::default();\n let n: usize = scan.next ();\n println! (\"{}\", if n%2 == 0 {\"Mahmoud\"} else {\"Ehab\"});\n}\n\nfn main() {\n let mut scan = Scanner::default();\n // let t = scan.next::();\n let t = 1;\n for _ in 0..t {\n solve();\n }\n}\n"}, {"source_code": "use std::io::stdin;\nfn main() {\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n\n let num: i32 = input.trim().parse().unwrap();\n\n if num % 2 == 0 {\n println!(\"Mahmoud\");\n } else {\n println!(\"Ehab\");\n }\n}\n"}, {"source_code": "fn main() {\n let mut num = String::new();\n std::io::stdin().read_line(&mut num).unwrap();\n let num: u64 = num.trim().parse().unwrap();\n\n let ans = match num % 2 {\n 0 => &\"Mahmoud\",\n 1 => &\"Ehab\",\n _ => &\"\",\n };\n\n println!(\"{}\", ans);\n}\n"}, {"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 println!(\"{}\", if n % 2 == 0 { \"Mahmoud\" } else { \"Ehab\" });\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"}, {"source_code": "use std::io;\n\nfn main() -> io::Result<()> {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input)?;\n\n let n = input.trim().parse::().unwrap();\n\n match n % 2 {\n 0 => println!(\"Mahmoud\"),\n 1 => println!(\"Ehab\"),\n _ => println!(\"Invalid number\"),\n }\n\n Ok(())\n}"}, {"source_code": "\nuse std::io;\n\nfn main() {\n let mut ni = String::new();\n io::stdin().read_line(&mut ni).unwrap();\n let n: i32 = ni.trim().parse().unwrap();\n println!(\"{}\", if (n % 2) == 0 { \"Mahmoud\" } else { \"Ehab\" });\n}"}, {"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 ok = n % 2 == 1;\n writeln!(writer, \"{}\", if ok {\"Ehab\"} else {\"Mahmoud\"}).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"}, {"source_code": "fn main() {\n let mut input = String::new();\n\n std::io::stdin().read_line(&mut input).expect(\"INPUT::Read line failed!\");\n\n let number = input.trim().parse::().expect(\"NUMBER::Parse to i32 failed!\");\n\n if number % 2 == 0 {\n println!(\"Mahmoud\");\n }else {\n println!(\"Ehab\");\n }\n}"}, {"source_code": "use std::io::stdin;\n\n// M => choose EVEN and choose FIRST\n// E => odd\n\nfn main() {\n let mut buffer = String::new();\n let _ = stdin().read_line(&mut buffer);\n\n let number: u32 = buffer.trim().parse().expect(\"Error in parsing\");\n\n if number % 2 == 0 {\n println!(\"Mahmoud\");\n } else {\n println!(\"Ehab\");\n }\n}\n"}, {"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 println!(\"{}\", [\"Mahmoud\",\"Ehab\"][input.u() % 2]);\n}\n\n"}, {"source_code": "use std::io;\n\nfn get_winner(num: u32) -> &'static str {\n if num % 2 == 0 {\n \"Mahmoud\"\n } else {\n \"Ehab\"\n }\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_winner(number));\n Ok(())\n}\n\nfn main() {\n solution();\n}\n"}, {"source_code": "use std::io::{BufReader, BufRead};\n\nfn main() -> Result<(), Box> {\n let mut n = BufReader::new(std::io::stdin())\n .lines()\n .next()\n .unwrap()?\n .parse::()?;\n\n if n & 1 == 0 {\n println!(\"Mahmoud\");\n } else {\n println!(\"Ehab\");\n }\n\n Ok(())\n}\n"}, {"source_code": "\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).unwrap();\n let n : i32 = s.trim().parse().unwrap();\n println!(\"{}\", if n%2==0 {\"Mahmoud\"} else {\"Ehab\"}); \n}\n"}, {"source_code": "use procon::*;\nuse std::io;\nfn main() {\n try_main().unwrap();\n}\n\nfn try_main() -> Result<(), Box> {\n let stdin = io::stdin();\n let mut sc = Scanner::new(stdin.lock());\n let n = sc.next::();\n if n % 2 == 0 {\n println!(\"Mahmoud\");\n } else {\n println!(\"Ehab\");\n }\n Ok(())\n}\n\nmod procon {\n use std::io;\n use std::cmp::Ordering;\n /// Scanner is taken from https://github.com/EbTech/rust-algorithms\n pub struct Scanner {\n reader: B,\n buffer: Vec,\n }\n\n impl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n }\n\n pub fn merge<'a, T>(this: &'a [T], that: &'a [T], out: &'a mut [T])\n where T: Ord + Copy {\n let mut i = 0;\n let mut j = 0;\n let mut oind = 0;\n while i < this.len() && j < that.len() {\n if this[i] <= that[j] {\n out[oind] = this[i];\n i += 1;\n } else {\n out[oind] = that[j];\n j += 1;\n }\n oind += 1;\n }\n while i < this.len() {\n out[oind] = this[i];\n i += 1;\n oind += 1;\n }\n while j < that.len() {\n out[oind] = that[j];\n j += 1;\n oind += 1;\n }\n }\n\n\n /// trait for implementing functions to get lower/upper bounds (implementation is based on the rust std library)\n /// the functions return OK(indx) if self[indx] is the element we queried.\n /// e.g., in lower_bound_by, f(self[indx]) returns Ordering::Equal if the function returned Ok(indx).\n /// Further, if all the elements are less than the queried value, lower_bound/upper_bound must return Err(self.len()).\n /// Similarly, all the elements are greater than the queried value, they must return Err(0).\n pub trait CmpSearch {\n type Item;\n\n fn find_bound_by<'a, F>(&'a self, f: F, is_lower: bool) -> Result\n where F: FnMut(&'a Self::Item) -> Ordering;\n\n fn find_bound_by_key<'a, B, F>(&'a self, b: &B, f: F, is_lower: bool) -> Result\n where F: FnMut(&'a Self::Item) -> B,\n B: Ord;\n\n /// returns Result which contains the lowest index indx that satisfies the following condition,\n /// assuming that self is already sorted:\n /// 1. self[i] < x if i < indx\n /// 2. self[i] >= x if i >= indx\n /// 3. self.insert(indx, x) keeps the sorted order.\n /// The return value is Ok(indx) if there is an index that satisfies x.cmp(self[indx]) == Ordering::Equal.\n /// Otherwise the return value is Err(indx).\n ///\n fn lower_bound(&self, x: &Self::Item) -> Result\n where Self::Item: Ord {\n self.find_bound_by(|elem| { elem.cmp(x) }, true)\n }\n\n\n /// returns Result which contains the highest index indx that satisfies the following condition,\n /// assuming that self is already sorted:\n /// 1. self[i] <= x if i <= indx\n /// 2. self[i] > x if i > indx\n /// 3. self.insert(indx, x) keeps the sorted order.\n /// The return value is Ok(indx) if there is an index that satisfies x.cmp(self[indx]) == Ordering::Equal.\n /// Otherwise the return value is Err(indx).\n ///\n fn upper_bound(&self, x: &Self::Item) -> Result\n where Self::Item: Ord {\n self.find_bound_by(|elem| { elem.cmp(x) }, false)\n }\n }\n\n impl CmpSearch for [T] {\n type Item = T;\n\n /// loop invariants (if is_lower = true):\n /// 1. f(self[lb]) == Less, assuming that lb >= 0\n /// 2. f(self[ub]) == Greater or Equal, assuming that gb < self.len()\n /// 3. lb < ub; in particular, lb != ub\n ///\n /// after the loop:\n /// 1. if ub < self.len(), ub is a valid index in the slice\n /// 2. if lb == -1, ub == 0 and:\n /// 2-1. f(self[0]) == Equal then the return value is Ok(0)\n /// 2-2. f(self[0]) == Greater then the return value is Err(0)\n /// 3. if ub == self.len(), lb == self.len() - 1 and the return value is Err(self.len())\n ///\n /// a similar set of conditions holds if is_lower = false.\n ///\n fn find_bound_by<'a, F>(&'a self, mut f: F, is_lower: bool) -> Result\n where F: FnMut(&'a Self::Item) -> Ordering {\n let mut lb: isize = -1;\n let mut ub: isize = self.len() as isize;\n let mut step = (ub - lb) / 2;\n while step > 0 {\n let m = (lb + step) as usize;\n match f(&self[m]) {\n Ordering::Less => {\n lb = m as isize;\n },\n Ordering::Greater => {\n ub = m as isize;\n },\n Ordering::Equal => {\n if is_lower {\n ub = m as isize;\n } else {\n lb = m as isize;\n }\n }\n }\n step = (ub - lb) / 2\n }\n\n if is_lower {\n if ub as usize == self.len() {\n Err(self.len())\n } else {\n let ub = ub as usize;\n match f(&self[ub]) {\n Ordering::Equal => {\n Ok(ub)\n },\n _ => {\n Err(ub)\n }\n }\n }\n } else {\n if lb == -1 {\n Err(0)\n } else {\n let lb = lb as usize;\n match f(&self[lb]) {\n Ordering::Equal => {\n Ok(lb)\n },\n _ => {\n Err(lb+1)\n }\n }\n }\n }\n }\n\n fn find_bound_by_key<'a, B, F>(&'a self, b: &B, mut f: F, is_lower: bool) -> Result\n where F: FnMut(&'a Self::Item) -> B,\n B: Ord {\n self.find_bound_by(|elem|{ f(elem).cmp(b) }, is_lower)\n }\n\n\n }\n}\n\n#[cfg(test)]\nmod tests {\n use super::procon::*;\n\n #[test]\n fn test_find_bound_by() {\n let s = [0, 2, 2, 2, 4];\n // lower bound\n let seek = 2;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Ok(1));\n let seek = 1;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Err(1));\n let seek = -1;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Err(0));\n let seek = 5;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), true), Err(5));\n // upper bound\n let seek = 2;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Ok(3));\n let seek = 1;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Err(1));\n let seek = 5;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Err(5));\n let seek = -1;\n assert_eq!(s.find_bound_by(|probe| probe.cmp(&seek), false), Err(0));\n }\n}\n"}, {"source_code": "use std::io;\n\nfn get_line() -> io::Result {\n\tlet mut buffer = String::new();\n\n\tio::stdin().read_line(&mut buffer)?;\n\tOk(buffer)\n}\n\nfn main() {\n\tlet input = get_line().unwrap();\n\tlet n: u32 = input.trim().parse().unwrap();\n\n\tprint!(\"{}\", if n % 2 == 0 { \"Mahmoud\" } else { \"Ehab\" });\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\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 if n % 2 == 0 {\n println!(\"Mahmoud\")\n } else {\n println!(\"Ehab\")\n }\n}\n"}, {"source_code": "fn main() {\n use std::io::prelude::*;\n use std::io;\n\n let mut input = String::new();\n\n io::stdin().read_to_string(&mut input).unwrap();\n\n let n: u32 = input.trim().parse().unwrap();\n\n if n % 2 == 1 {\n println!(\"Ehab\");\n } else {\n println!(\"Mahmoud\");\n }\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut val = String::new();\n\n io::stdin().read_line(&mut val)\n .expect(\"Не удалось прочитать строку\");\n\n let val: u32 = val.trim().parse()\n .expect(\"Пожалуйста, введите число!\");\n\n if val % 2 == 0 {\n println!(\"Mahmoud\");\n } else {\n println!(\"Ehab\");\n }\n}\n"}, {"source_code": "\nuse std::io;\n\npub fn main() {\n let input = get_input();\n match input % 2 {\n 0 => println!(\"Mahmoud\"),\n _ => println!(\"Ehab\"),\n };\n}\n\nfn get_input() -> u64 {\n let mut input = String::new();\n io::stdin().read_line(&mut input);\n input.trim().parse::().unwrap()\n}\n\n"}], "negative_code": [{"source_code": "use std::io::stdin;\n\n// M => choose EVEN and choose FIRST\n// E => odd\n\nfn main() {\n let mut buffer = String::new();\n let _ = stdin().read_line(&mut buffer);\n\n let number: u32 = buffer.trim().parse().expect(\"Error in parsing\");\n\n if number % 2 == 0 {\n println!(\"Mahmoud\");\n } else {\n println!(\"Ehad\");\n }\n}\n"}, {"source_code": "use std::io;\n\nfn get_line() -> io::Result {\n\tlet mut buffer = String::new();\n\tio::stdin().read_line(&mut buffer)?;\n\tOk(buffer)\n}\n\nfn main() {\n\tlet employees;\n\t{\n\t\tlet input = get_line().unwrap();\n\t\temployees = input.trim().parse::().unwrap();\n\t}\n\n\tlet mut ways = 0;\n\tfor i in 1..employees {\n\t\tif (employees - i) % i == 0 {\n\t\t\tways += 1;\n\t\t}\n\t}\n\tprint!(\"{}\", ways);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n\tlet mut n = String::new();\n\tio::stdin().read_line(&mut n).expect(\"Time to panic\");\n\tlet n: u64 = n.trim().parse().unwrap();\n\tif n % 2 == 0 {\n\t\tprintln!(\"Ehab\");\n\t} else {\n\t\tprintln!(\"Mahmoud\")\n\t}\n}\n"}, {"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 ok = n == 1;\n writeln!(writer, \"{}\", if ok {\"Ehab\"} else {\"Mahmoud\"}).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": "5e74750f44142624e6da41d4b35beb9a"} {"source_code": "//spnauti-rust\n#[allow(unused_imports)]\nuse std::io::{self,Read};\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 { it : s\n .split_ascii_whitespace()\n .map(String::from).collect::>()\n .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}\n\nfn main() {\n let mut input = WordReader::from_stdin();\n let a = input.i();\n let b = input.i();\n let c = input.i();\n\n use std::cmp::max;\n let ab = max(a + b, a * b);\n let bc = max(b + c, b * c);\n let p = [ab + c, ab * c, a + bc, a * bc];\n let sol = p.iter().max().unwrap();\n println!(\"{}\", sol);\n}\n\n", "positive_code": [{"source_code": "use std::str::FromStr;\n \nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n \nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n \nfn main() {\n let (a, b, c): (u16, u16, u16) = (read_int(), read_int(), read_int());\n \n if a + c == 2 { println!(\"{}\", a + b + c); }\n else if a == 1 || b == 1 || c == 1 {\n if a < c { println!(\"{}\", (a + b) * c); }\n else { println!(\"{}\", a * (b + c)); }\n }\n else { println!(\"{}\", a * b * c); }\n}"}, {"source_code": "use std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_t(stdin : &Stdin) -> T {\n let mut line = String::new();\n read_line(stdin, &mut line);\n parse_t(&line)\n}\n\nfn max_value(a : u64, b : u64, c : u64) -> u64 {\n let v = vec![a + b + c,\n (a + b) * c,\n (a * b) + c,\n a * b * c,\n a + (b * c),\n a * (b + c)];\n match v.iter().max() {\n Some(&x) => x,\n None => panic!(\"Could not compute max value.\"),\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let a = read_t(&stdin);\n let b = read_t(&stdin);\n let c = read_t(&stdin);\n println!(\"{}\", max_value(a, b, c));\n}\n"}, {"source_code": "fn readln() -> Vec {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).unwrap();\n\n line.split_whitespace()\n .map(|s| s.parse().unwrap())\n .collect()\n}\n\n\nfn main() {\n let input = readln();\n let a = input[0];\n\n let input = readln();\n let b = input[0];\n\n let input = readln();\n let c = input[0];\n\n let mut ans = 0;\n\n // a + b + c\n ans = std::cmp::max(ans, a + b + c);\n\n // a + b * c\n ans = std::cmp::max(ans, a + b * c);\n\n // a * b + c\n ans = std::cmp::max(ans, a * b + c);\n\n // a * b * c\n ans = std::cmp::max(ans, a * b * c);\n\n // (a + b) * c\n ans = std::cmp::max(ans, (a + b) * c);\n\n // a * (b + c)\n ans = std::cmp::max(ans, a * (b + c));\n\n println!(\"{}\", ans);\n}"}, {"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n let mut v = Vec::new(); v.reserve(($n) as usize);\n for st in s { v.push(st.parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n let a = scan!(i32);\n let b = scan!(i32);\n let c = scan!(i32);\n println!(\"{}\", max(max(max(max(max(\n a + b + c,\n a * b * c),\n (a + b) * c),\n a + b * c),\n a * (b + c)),\n a * b + c));\n}\n"}, {"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 mut a = parse_input!(usize);\n let mut b = parse_input!(usize);\n let mut c = parse_input!(usize);\n if a == 1 {\n b += 1;\n }\n if b == 1 {\n if c < a {\n c += 1;\n } else {\n a += 1;\n }\n }\n if c == 1 {\n b += 1;\n }\n\n println!(\"{}\", a * b * c);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n let mut c = String::new();\n\n io::stdin().read_line(&mut a).unwrap();\n io::stdin().read_line(&mut b).unwrap();\n io::stdin().read_line(&mut c).unwrap();\n\n let a: u16 = a.trim().parse().unwrap();\n let b: u16 = b.trim().parse().unwrap();\n let c: u16 = c.trim().parse().unwrap();\n\n let mut max_value: u16 = 0;\n\n if (a + b + c) > max_value {\n max_value = a + b + c;\n } \n if (a * b * c) > max_value {\n max_value = a * b * c;\n }\n if (a * b + c) > max_value {\n max_value = a * b + c;\n }\n if (a + b * c) > max_value {\n max_value = a + b * c;\n }\n\n if ((a + b) * c) > max_value {\n max_value = (a + b) * c;\n }\n if (a * (b + c)) > max_value {\n max_value = a * (b + c);\n }\n\n if (a + (b * c)) > max_value {\n max_value = a + (b * c);\n }\n if ((a * b) + c) > max_value {\n max_value = (a * b) + c;\n }\n\n println!(\"{}\", max_value);\n}\n\n\n"}, {"source_code": "fn input() -> u16 {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n}\n\nfn main() {\n let (a, b, c) = (input(), input(), input());\n println!(\n \"{}\",\n [\n a + b + c,\n a + b * c,\n a * b + c,\n a * b * c,\n (a + b) * c,\n a * (b + c)\n ]\n .iter()\n .max()\n .unwrap()\n );\n}"}, {"source_code": "use std::io;\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_val() -> i32 {\n return read_line().parse().unwrap();\n}\n\n\nfn main() {\n let a = read_line_val();\n let b = read_line_val();\n let c = read_line_val();\n\n let results: [i32; 6] = [\n a + b + c,\n a + b * c,\n (a + b) * c,\n a * b + c,\n a * (b + c),\n a * b * c\n ];\n\n let mut max = 0;\n for r in results.iter() {\n if *r > max {\n max = *r;\n }\n }\n \n \n println!(\"{:?}\", max);\n\n \n}"}, {"source_code": "fn main() {\n let a: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n let b: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n let c: i32 = {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line);\n line.trim().parse().unwrap()\n };\n\n let best = |a, b| std::cmp::max(a + b, a * b);\n let x = std::cmp::max(best(best(a, b), c), best(a, best(b, c)));\n println!(\"{:?}\", x);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut buf = String::new();\n let mut r = [0i32; 3];\n for i in 0..3 {\n buf.clear();\n io::stdin().read_line(&mut buf).unwrap();\n r[i] = buf.trim().parse::().unwrap();\n }\n let s = [\n r[0] + r[1] + r[2],\n (r[0] + r[1]) * r[2],\n r[0] * r[1] + r[2],\n r[0] * r[1] * r[2],\n r[0] * (r[1] + r[2]),\n r[0] + r[1] * r[2],\n ];\n let s = s.iter().max().unwrap();\n println!(\"{}\", s);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let (mut a, mut b, mut c) = (String::new(), String::new(), String::new());\n io::stdin().read_line(&mut a).unwrap();\n io::stdin().read_line(&mut b).unwrap();\n io::stdin().read_line(&mut c).unwrap();\n let a: i64 = a.trim().parse().unwrap();\n let b: i64 = b.trim().parse().unwrap();\n let c: i64 = c.trim().parse().unwrap();\n\n let posibles: [i64; 6] = [\n (a + b) * c,\n a * (b + c),\n a + b + c,\n a * b + c,\n a + b * c,\n a * b * c,\n ];\n\n let max = posibles.iter().max().unwrap();\n\n println!(\"{}\", max);\n}\n"}, {"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 (a, ) = R!(i32);\n let (b, ) = R!(i32);\n let (c, ) = R!(i32);\n println!(\"{}\", vec![a+b+c, a+b*c, a*b+c, a*b*c, (a+b)*c, a*(b+c)].into_iter().fold(0, cmp::max));\n}\n"}, {"source_code": "use 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 out = &mut BufWriter::new(stdout());\n\n\tlet a = scan.next::();\n\tlet b = scan.next::();\n\tlet c = scan.next::();\n\n let nums = [a + b + c,\n a + b * c,\n a * b * c,\n (a + b) * c,\n a * b + c,\n a * (b + c)];\n\n let res = nums.iter().max().unwrap();\n\n writeln!(out, \"{}\", res).expect(\"fail\");\n}\n"}, {"source_code": "use std::io;\nuse std::cmp::max;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let a: i32 = s.trim().parse().unwrap();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let b: i32 = s.trim().parse().unwrap();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let c: i32 = s.trim().parse().unwrap();\n\n let x = max(\n a+b+c, max(\n (a+b)*c, max(\n a*(b+c),\n a*b*c\n )));\n\n println!(\"{}\", x);\n return;\n}\n\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let a: i64 = read(sin);\n let b: i64 = read(sin);\n let c: i64 = read(sin);\n\n let ans = match (a, b, c) {\n (1, 1, 1) => 3,\n (a, 1, c) => if a < c {\n (a + 1) * c\n } else {\n a * (c + 1)\n },\n (1, b, 1) => b + 2,\n (1, b, c) => (1 + b) * c,\n (a, b, 1) => a * (b + 1),\n _ => a * b * c,\n };\n\n println!(\"{}\", ans);\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let a: i64 = read(sin);\n let b: i64 = read(sin);\n let c: i64 = read(sin);\n\n if b == 1 {\n let ans = if a <= c {\n if c == 1 {\n // a == b == c == 1\n a + b + c\n } else {\n (a + b) * c\n }\n } else {\n a * (b + c)\n };\n println!(\"{}\", ans);\n return;\n }\n\n if c == 1 && a != 1 {\n println!(\"{}\", a * (b + c));\n return;\n }\n\n let pre_val = if a == 1 { a + b } else { a * b };\n let ans = if c == 1 { pre_val + c } else { pre_val * c };\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n let mut c = String::new();\n\n io::stdin()\n .read_line(&mut a)\n .unwrap();\n\n io::stdin()\n .read_line(&mut b)\n .unwrap();\n\n io::stdin()\n .read_line(&mut c)\n .unwrap();\n\n let a: i64 = a.trim().parse().unwrap();\n let b: i64 = b.trim().parse().unwrap();\n let c: i64 = c.trim().parse().unwrap();\n\n println!(\"{}\",\n [\n (a+b)*c,\n a*b+c,\n a+b*c,\n a+b+c,\n a*b*c,\n a*(b+c)\n ]\n .iter()\n .max()\n .unwrap()\n );\n}\n\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n let mut c = String::new();\n\n io::stdin()\n .read_line(&mut a)\n .unwrap();\n\n io::stdin()\n .read_line(&mut b)\n .unwrap();\n\n io::stdin()\n .read_line(&mut c)\n .unwrap();\n\n let a: i64 = a.trim().parse().unwrap();\n let b: i64 = b.trim().parse().unwrap();\n let c: i64 = c.trim().parse().unwrap();\n\n let mut maxima = 0;\n let uno = (a+b)*c;\n let dos = a*b+c;\n maxima = std::cmp::max(uno,dos);\n let tres = a+b*c;\n maxima = std::cmp::max(maxima,tres);\n let cuatro = a+b+c;\n maxima = std::cmp::max(maxima,cuatro);\n let cinco = a*b*c;\n maxima = std::cmp::max(maxima,cinco);\n let seis = a*(b+c);\n maxima = std::cmp::max(maxima,seis);\n\n println!(\"{}\", maxima);\n}\n"}, {"source_code": "use std::str::FromStr;\n \nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n \nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n \nfn main() {\n let (a, b, c): (u16, u16, u16) = (read_int(), read_int(), read_int());\n \n if a == 1 {\n if c == 1 { println!(\"{}\", a + b + c); }\n else { println!(\"{}\", (a + b) * c); }\n }\n else if b == 1 {\n if a > c { println!(\"{}\", a * (b + c)); }\n else { println!(\"{}\", (a + b) * c); }\n }\n else if c == 1 { println!(\"{}\", a * (b + c)); }\n else { println!(\"{}\", a * b * c); }\n}"}], "negative_code": [{"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n let mut v = Vec::new(); v.reserve(($n) as usize);\n for st in s { v.push(st.parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n let a = scan!(i32);\n let b = scan!(i32);\n let c = scan!(i32);\n println!(\"{}\", max(max(max(a + b + c, a * b * c), (a + b) * c), a + b * c));\n}\n"}, {"source_code": "#[allow(unused)] use std::io::*;\n#[allow(unused)] use std::collections::*;\n#[allow(unused)] use std::mem::*;\n#[allow(unused)] use std::num::*;\n#[allow(unused)] use std::cmp::*;\n#[allow(unused)] macro_rules! scan { ($($x:ty), +) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0).collect();\n let mut cnt : usize = 0;\n fn next(cnt: &mut usize, p: &Vec<&str>) -> T where T:std::str::FromStr\n { *cnt += 1; p[*cnt-1].parse().ok().unwrap() }\n ($(next::<$x>(&mut cnt, &s)), +)\n }}; }\n#[allow(unused)] macro_rules! arr { ($n:expr, $T:ty) => {{\n let mut inp = String::new(); stdin().read_line(&mut inp).ok();\n let mut s = inp.split(' ').map(|x| x.trim()).filter(|x| x.len() != 0);\n let mut v = Vec::new(); v.reserve(($n) as usize);\n for st in s { v.push(st.parse::<$T>().unwrap()); } v\n }}; }\n\n///////////////////////////////////////////////////////////////////////////////\nfn main()\n{\n let a = scan!(i32);\n let b = scan!(i32);\n let c = scan!(i32);\n println!(\"{}\", max(max(max(max(a + b + c, a * b * c), (a + b) * c), (a + c) * b), (b + c) * a));\n}\n"}, {"source_code": "fn input() -> u8 {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim().parse().unwrap()\n}\n\nfn main() {\n let (a, b, c) = (input(), input(), input());\n println!(\n \"{}\",\n [\n a + b + c,\n a + b * c,\n a * b + c,\n a * b * c,\n (a + b) * c,\n a * (b + c)\n ]\n .iter()\n .max()\n .unwrap()\n );\n}"}, {"source_code": "use std::io;\nuse std::cmp::{min, max};\n\nfn main() {\n let stdin = io::stdin();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let a: i32 = s.trim().parse().unwrap();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let b: i32 = s.trim().parse().unwrap();\n let mut s = String::new();\n stdin.read_line(&mut s).unwrap();\n let c: i32 = s.trim().parse().unwrap();\n\n let x = min(a, min(b, c));\n let z = max(a, max(b, c));\n let y = a + b + c - x - z;\n\n if x == 1 && y == 1 && z == 1 {\n println!(\"3\");\n } else if x == 1 && y == 1 {\n println!(\"{}\", 2*z);\n } else if x == 1 {\n println!(\"{}\", (y+1)*z);\n } else {\n println!(\"{}\", x*y*z);\n }\n}\n\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let a: i64 = read(sin);\n let b: i64 = read(sin);\n let c: i64 = read(sin);\n\n let pre_val = if a == 1 || b == 1 { a + b } else { a * b };\n\n let ans = if c == 1 { pre_val + c } else { pre_val * c };\n\n println!(\"{}\", ans);\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let a: i8 = read(sin);\n let b: i8 = read(sin);\n let c: i8 = read(sin);\n\n let pre_val = if a == 1 || b == 1 { a + b } else { a * b };\n\n let ans = if c == 1 { pre_val + c } else { pre_val * c };\n\n println!(\"{}\", ans);\n}\n"}, {"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 main() {\n // initialize stdin\n let sin = std::io::stdin();\n let mut sin = sin.lock();\n let sin = &mut sin;\n\n let a: i64 = read(sin);\n let b: i64 = read(sin);\n let c: i64 = read(sin);\n\n if b == 1 {\n let ans = if a <= c {\n if c == 1 {\n // a == b == c == 1\n a + b + c\n } else {\n (a + b) * c\n }\n } else {\n a * (b + c)\n };\n println!(\"{}\", ans);\n return;\n }\n\n let pre_val = if a == 1 { a + b } else { a * b };\n let ans = if c == 1 { pre_val + c } else { pre_val * c };\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n\nfn main() {\n let (a, b, c): (u8, u8, u8) = (read_int(), read_int(), read_int());\n\n if a == 1 {\n if c == 1 { println!(\"{}\", a + b + c); }\n else { println!(\"{}\", (a + b) * c); }\n }\n else if b == 1 {\n if a > c { println!(\"{}\", a * (b + c)); }\n else { println!(\"{}\", (a + b) * c); }\n }\n else if c == 1 { println!(\"{}\", a * (b + c)); }\n else { println!(\"{}\", a * b * c); }\n}"}, {"source_code": "use std::str::FromStr;\n\nfn read_str() -> String {\n let mut buffer: String = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Error\");\n buffer.trim().to_string()\n}\n\nfn read_int() -> T{\n read_str().parse::().ok().expect(\"Error\")\n}\n\nfn main() {\n let (a, b, c): (u16, u16, u16) = (read_int(), read_int(), read_int());\n\n if a + c == 2 { println!(\"{}\", a + b + c); }\n else if b == 1 || c == 1 {\n if a < c { println!(\"{}\", (a + b) * c); }\n else { println!(\"{}\", a * (b + c)); }\n }\n else { println!(\"{}\", a * b * c); }\n}"}, {"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 = parse_input!(usize);\n let b = parse_input!(usize);\n let c = parse_input!(usize);\n let mut m = vec![a, b, c];\n m.sort();\n m.reverse();\n while *m.last().unwrap() == 1 {\n let p = m.pop().unwrap();\n *m.last_mut().unwrap() += p;\n }\n let mut ans = 1;\n for p in m {\n ans *= p;\n }\n println!(\"{}\", ans);\n}\n"}, {"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 = parse_input!(usize);\n let b = parse_input!(usize);\n let c = parse_input!(usize);\n let mut m = vec![a, b, c];\n m.sort();\n m.reverse();\n while *m.last().unwrap() == 1 {\n let p = m.pop().unwrap();\n *m.last_mut().unwrap() += p;\n m.sort();\n m.reverse();\n }\n let mut ans = 1;\n for p in m {\n ans *= p;\n }\n println!(\"{}\", ans);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut a = String::new();\n let mut b = String::new();\n let mut c = String::new();\n\n io::stdin().read_line(&mut a).unwrap();\n io::stdin().read_line(&mut b).unwrap();\n io::stdin().read_line(&mut c).unwrap();\n\n let a: u8 = a.trim().parse().unwrap();\n let b: u8 = b.trim().parse().unwrap();\n let c: u8 = c.trim().parse().unwrap();\n\n let mut max_value = 0;\n\n if (a + b + c) > max_value {\n max_value = a + b + c;\n } \n if (a * b * c) > max_value {\n max_value = a * b * c;\n }\n if (a * b + c) > max_value {\n max_value = a * b + c;\n }\n if (a + b * c) > max_value {\n max_value = a + b * c;\n }\n\n if ((a + b) * c) > max_value {\n max_value = (a + b) * c;\n }\n if (a * (b + c)) > max_value {\n max_value = a * (b + c);\n }\n\n if (a + (b * c)) > max_value {\n max_value = a + (b * c);\n }\n if ((a * b) + c) > max_value {\n max_value = (a * b) + c;\n }\n\n println!(\"{}\", max_value);\n}\n\n\n"}], "src_uid": "1cad9e4797ca2d80a12276b5a790ef27"} {"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 x: u32 = it.next().unwrap().parse().unwrap();\n let y: u32 = it.next().unwrap().parse().unwrap();\n\n // x^y y^x\n // exp(y * ln(x)) exp(x * ln(y))\n // y * ln(x) x * ln(y)\n // ln(x) / x ln(y) / y\n\n struct F {\n x: u32,\n }\n\n use std::cmp::{Ordering, self};\n\n impl PartialEq for F {\n fn eq(&self, other: &F) -> bool {\n match (self.x, other.x) {\n (2, 4) | (4, 2) => true,\n (a, b) => a.eq(&b),\n }\n }\n }\n\n impl Eq for F {}\n\n impl PartialOrd for F {\n fn partial_cmp(&self, other: &F) -> Option {\n Some(self.cmp(other))\n }\n }\n\n impl Ord for F {\n fn cmp(&self, other: &F) -> Ordering {\n match (self.x, other.x) {\n (a, b) if F { x: a } == F { x: b } => Ordering::Equal,\n (3, _) => Ordering::Greater,\n (_, 3) => Ordering::Less,\n (2, _) => Ordering::Greater,\n (_, 2) => Ordering::Less,\n (1, _) => Ordering::Less,\n (_, 1) => Ordering::Greater,\n (a, b) => b.cmp(&a),\n }\n }\n }\n\n let x = F { x: x };\n let y = F { x: y };\n let ans = x.cmp(&y);\n let txt = match ans {\n Ordering::Less => '<',\n Ordering::Equal => '=',\n Ordering::Greater => '>',\n };\n\n println!(\"{}\", txt);\n}\n", "positive_code": [{"source_code": "use std::io::{self, BufRead};\n\nfn compare(x: i32, y: i32) -> i32 {\n if x == y {\n return 0;\n }\n if (x == 2 && y == 4) || (x == 4 && y == 2) {\n return 0;\n }\n\n if x <= 3 && y <= 3 {\n return if x < y { -1 } else { 1 };\n }\n if x >= 3 && y >= 3 {\n return if x < y { 1 } else { -1 };\n }\n\n if x == 1 {\n return -1;\n }\n if y == 1 {\n return 1;\n }\n\n if x <= 3 { 1 } else { -1 }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut input = String::new();\n stdin.lock().read_line(&mut input).unwrap();\n\n let tokens: Vec<&str> = input.split_whitespace().collect();\n let x = tokens[0].parse::().unwrap();\n let y = tokens[1].parse::().unwrap();\n\n match compare(x, y) {\n -1 => println!(\"<\"),\n 0 => println!(\"=\"),\n 1 => println!(\">\"),\n _ => println!(\"This shouldn't happen...\")\n };\n}"}, {"source_code": "use std::cmp;\nuse std::io;\n\nfn main() {\n let mut mut_line = String::new();\n io::stdin().read_line(&mut mut_line).unwrap();\n let mut iter = mut_line.trim().split(\" \").map(|x| x.parse().unwrap());\n let (x, y): (u64, u64) = (iter.next().unwrap(), iter.next().unwrap());\n if x == y {\n println!(\"=\");\n return;\n }\n let mini = cmp::min(x, y);\n let other = x + y - mini;\n let mut result = if mini >= 3 {\n cmp::Ordering::Greater\n } else if mini == 1 {\n cmp::Ordering::Less\n } else {\n // mini == 2\n if other == 3{\n cmp::Ordering::Less\n } else if other == 4 {\n cmp::Ordering::Equal\n }\n else{\n cmp::Ordering::Greater\n }\n };\n if mini == y {\n result = cmp::Ordering::reverse(result);\n }\n match result{\n cmp::Ordering::Less => println!(\"<\"),\n cmp::Ordering::Equal => println!(\"=\"),\n cmp::Ordering::Greater => println!(\">\")\n }\n}\n"}, {"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 x: u32 = it.next().unwrap().parse().unwrap();\n let y: u32 = it.next().unwrap().parse().unwrap();\n\n // x^y y^x\n // exp(y * ln(x)) exp(x * ln(y))\n // y * ln(x) x * ln(y)\n // ln(x) / x ln(y) / y\n\n fn f_cmp(a: u32, b: u32) -> ::std::cmp::Ordering {\n use std::cmp::{self, Ordering};\n\n if a == b {\n Ordering::Equal\n } else if a == 1 {\n Ordering::Less\n } else if b == 1 {\n Ordering::Greater\n } else if a == 3 {\n Ordering::Greater\n } else if b == 3 {\n Ordering::Less\n } else if a == 2 || a == 4 {\n if b == 2 || b == 4 {\n Ordering::Equal\n } else {\n Ordering::Greater\n }\n } else if b == 2 || b == 4 {\n Ordering::Less\n } else {\n b.cmp(&a)\n }\n }\n\n let ans = f_cmp(x, y);\n use std::cmp::Ordering;\n let txt = match ans {\n Ordering::Less => '<',\n Ordering::Equal => '=',\n Ordering::Greater => '>',\n };\n\n println!(\"{}\", txt);\n}\n"}, {"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 x: f64 = it.next().unwrap().parse().unwrap();\n let y: f64 = it.next().unwrap().parse().unwrap();\n\n // x^y y^x\n // exp(y * ln(x)) exp(x * ln(y))\n // y * ln(x) x * ln(y)\n // ln(x) / x ln(y) / y\n\n let epsilon = 1e-4;\n\n let diff = x * y.ln() - y * x.ln();\n\n let ans = if diff.abs() < epsilon {\n '='\n } else if diff > 0.0 {\n '<'\n } else {\n '>'\n };\n\n println!(\"{}\", ans);\n}\n"}], "negative_code": [{"source_code": "use std::io::{self, BufRead};\n\nfn compare(x: i32, y: i32) -> i32 {\n if x == y {\n return 0;\n }\n if (x == 2 && y == 4) || (x == 4 && y == 2) {\n return 0;\n }\n\n if x <= 3 && y <= 3 {\n return if x < y { -1 } else { 1 };\n }\n if x >= 3 && y >= 3 {\n return if x < y { 1 } else { -1 };\n }\n\n if x == 1 {\n return -1;\n }\n if y == 1 {\n return -1;\n }\n\n if x <= 3 { 1 } else { -1 }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut input = String::new();\n stdin.lock().read_line(&mut input).unwrap();\n\n let tokens: Vec<&str> = input.split_whitespace().collect();\n let x = tokens[0].parse::().unwrap();\n let y = tokens[1].parse::().unwrap();\n\n match compare(x, y) {\n -1 => println!(\"<\"),\n 0 => println!(\"=\"),\n 1 => println!(\">\"),\n _ => println!(\"This shouldn't happen...\")\n };\n}"}], "src_uid": "ec1e44ff41941f0e6436831b5ae543c6"} {"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\tlet mut a = rin.vi(n);\n\ta.sort();\n\tlet mut c = 0;\n\twhile c < n && a[0] == a[c] {\n\t\tc += 1;\n\t}\n\tif c <= n/2 {\n\t\twriteln!(rout, \"Alice\").ok();\n\t} else {\n\t\twriteln!(rout, \"Bob\").ok();\n\t}\n}\n", "positive_code": [{"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 n = scan.next::();\n \n let mut lo = 99;\n let mut rep = 0;\n for _ in 0..n {\n let a = scan.next::();\n if lo > a {\n lo = a;\n rep = 0;\n }\n if lo == a {\n rep += 1;\n }\n }\n if rep <= n / 2 {\n println!(\"Alice\");\n } else {\n println!(\"Bob\");\n }\n}\n\nfn main() {\n std::thread::Builder::new().stack_size(50 << 20)\n .spawn(main1).unwrap().join().unwrap();\n}"}, {"source_code": "#![allow(unused_variables)]\n#![allow(unused_must_use)]\n#![allow(dead_code)]\nuse std::io::{self, prelude::*};\n\nfn solve(mut input: FastInput, mut w: W) {\n let n: usize = input.token();\n let mut a = vec![0usize; n];\n for x in a.iter_mut() {\n *x = input.token();\n }\n let min = a.iter().min().unwrap();\n let cnt = a.iter().filter(|&x| x == min).count();\n if cnt > n / 2 {\n write!(w, \"Bob\\n\");\n } else {\n write!(w, \"Alice\\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 writer = io::BufWriter::new(stdout.lock());\n solve(input, writer);\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_u {\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\npub trait Identity {\n fn identity() -> Self;\n}\n\npub trait SelfIdentity {\n fn self_identity(&self) -> Self;\n}\n\nimpl SelfIdentity for T {\n fn self_identity(&self) -> Self {\n Self::identity()\n }\n}\n\npub trait Inverse {\n fn inverse(self) -> Self;\n}\n\nmacro_rules! define_modular_type {\n ($mod:ident, $value:expr) => {\n #[derive(Copy, Clone, Default, PartialEq)]\n struct $mod(u32);\n\n impl $mod {\n const MOD: u64 = $value;\n }\n\n impl std::fmt::Debug for $mod {\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n write!(f, \"{:?}\", self.0)\n }\n }\n\n impl std::fmt::Display for $mod {\n fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {\n write!(f, \"{}\", self.0)\n }\n }\n\n impl> From for $mod {\n fn from(a: T) -> Self {\n $mod((a.into() % Self::MOD) as u32)\n }\n }\n\n impl Into for $mod {\n fn into(self) -> u32 {\n self.0\n }\n }\n\n impl Identity for $mod {\n fn identity() -> Self {\n 1u32.into()\n }\n }\n\n impl Inverse for $mod {\n fn inverse(self) -> Self {\n let mut t = (Self::default(), Self::identity());\n let mut r = (Self::MOD, self.0 as u64);\n while r.1 != 0 {\n let q = r.0 / r.1;\n t = (t.1, t.0 - t.1 * q.into());\n r = (r.1, r.0 - r.1 * q);\n }\n t.0\n }\n }\n\n impl std::ops::Add for $mod {\n type Output = $mod;\n fn add(self, rhs: $mod) -> Self::Output {\n let mut ret = self.0 + rhs.0;\n if ret >= Self::MOD as u32 {\n ret -= Self::MOD as u32;\n }\n $mod(ret)\n }\n }\n\n impl std::ops::AddAssign for $mod {\n fn add_assign(&mut self, rhs: Self) {\n self.0 += rhs.0;\n if self.0 >= Self::MOD as u32 {\n self.0 -= Self::MOD as u32;\n }\n }\n }\n\n impl std::ops::Neg for $mod {\n type Output = Self;\n fn neg(self) -> Self::Output {\n $mod(Self::MOD as u32 - self.0)\n }\n }\n\n impl std::ops::Sub for $mod {\n type Output = $mod;\n fn sub(self, rhs: Self) -> Self::Output {\n if self.0 < rhs.0 {\n $mod(self.0 + (Self::MOD as u32) - rhs.0)\n } else {\n $mod(self.0 - rhs.0)\n }\n }\n }\n\n impl std::ops::SubAssign for $mod {\n fn sub_assign(&mut self, rhs: Self) {\n if self.0 < rhs.0 {\n self.0 += Self::MOD as u32;\n }\n self.0 -= rhs.0\n }\n }\n\n impl std::ops::Mul for $mod {\n type Output = $mod;\n fn mul(self, rhs: Self) -> Self::Output {\n let a = self.0 as u64;\n let b = rhs.0 as u64;\n let c = a * b % Self::MOD;\n $mod(c as u32)\n }\n }\n\n impl std::ops::MulAssign for $mod {\n fn mul_assign(&mut self, rhs: Self) {\n *self = *self * rhs;\n }\n }\n\n impl std::ops::Div for $mod {\n type Output = Self;\n fn div(self, rhs: Self) -> Self::Output {\n self * rhs.inverse()\n }\n }\n\n impl std::ops::DivAssign for $mod {\n fn div_assign(&mut self, rhs: Self) {\n *self = *self / rhs;\n }\n }\n };\n}\n\n#[derive(Clone)]\npub struct Matrix {\n data: Vec,\n cols: usize,\n rows: usize,\n}\n\nimpl Matrix\nwhere\n T: std::default::Default + Clone,\n{\n pub fn new(rows: usize, cols: usize) -> Matrix {\n let data = vec![T::default(); cols * rows];\n Matrix {\n data: data,\n cols: cols,\n rows: rows,\n }\n }\n}\n\nimpl Matrix {\n pub fn rows(&self) -> std::slice::Chunks {\n self.data.chunks(self.cols)\n }\n pub fn rows_mut(&mut self) -> std::slice::ChunksMut {\n self.data.chunks_mut(self.cols)\n }\n pub fn elem(&self, row: usize, col: usize) -> &T {\n &self.data[self.cols * row + col]\n }\n pub fn elem_mut(&mut self, row: usize, col: usize) -> &mut T {\n &mut self.data[self.cols * row + col]\n }\n}\n\nimpl std::fmt::Debug for Matrix\nwhere\n T: std::fmt::Debug,\n{\n fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {\n self.rows()\n .try_for_each(|row| fmt.write_fmt(format_args!(\"{:?}\\n\", row)))\n }\n}\n\nimpl SelfIdentity for Matrix\nwhere\n T: Identity + std::default::Default + Clone,\n{\n fn self_identity(&self) -> Self {\n assert_eq!(self.cols, self.rows);\n let mut ret = Matrix::new(self.rows, self.cols);\n for (i, row) in ret.rows_mut().enumerate() {\n row[i] = T::identity();\n }\n ret\n }\n}\n\nimpl std::ops::Add for Matrix\nwhere\n T: Clone + std::default::Default + std::ops::Add,\n{\n type Output = Matrix;\n fn add(self, rhs: Matrix) -> Matrix {\n assert_eq!(self.cols, rhs.cols);\n assert_eq!(self.rows, rhs.rows);\n Matrix {\n data: self\n .data\n .iter()\n .zip(rhs.data)\n .map(|(a, b)| a.clone() + b.clone())\n .collect(),\n rows: self.rows,\n cols: self.cols,\n }\n }\n}\nimpl std::ops::Sub for Matrix\nwhere\n T: Clone + std::default::Default + std::ops::Sub,\n{\n type Output = Matrix;\n fn sub(self, rhs: Matrix) -> Matrix {\n assert_eq!(self.cols, rhs.cols);\n assert_eq!(self.rows, rhs.rows);\n Matrix {\n data: self\n .data\n .iter()\n .zip(rhs.data)\n .map(|(a, b)| a.clone() - b.clone())\n .collect(),\n rows: self.rows,\n cols: self.cols,\n }\n }\n}\nimpl std::ops::Mul for Matrix\nwhere\n T: Clone + std::default::Default + std::ops::AddAssign + std::ops::Mul,\n{\n type Output = Matrix;\n fn mul(self, rhs: Matrix) -> Matrix {\n assert_eq!(self.cols, rhs.rows);\n let mut ret: Matrix = Matrix::new(self.rows, rhs.cols);\n for (ret_row, self_row) in ret.rows_mut().zip(self.rows()) {\n for (rhs_row, self_el) in rhs.rows().zip(self_row) {\n for (ret_el, rhs_el) in ret_row.iter_mut().zip(rhs_row) {\n *ret_el += self_el.clone() * rhs_el.clone();\n }\n }\n }\n ret\n }\n}\n\nfn binary_power(a: &T, mut exp: u64) -> T\nwhere\n T: Clone + std::ops::Mul + SelfIdentity,\n{\n let mut base = a.clone();\n let mut acc = a.self_identity();\n while exp > 1 {\n if (exp & 1) == 1 {\n acc = acc * base.clone();\n }\n exp /= 2;\n base = base.clone() * base.clone();\n }\n if exp == 1 {\n acc = acc * base;\n }\n acc\n}\n\nimpl_token_stream_u!(usize);\ndefine_modular_type!(MOD7, 1_000_000_007);\n"}, {"source_code": "//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, 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 let ans = if a[0] == a[n / 2] {\n \"Bob\"\n } else {\n \"Alice\"\n };\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}], "negative_code": [{"source_code": "//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, 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 cnt = vec![0; 10];\n for a in a {\n for i in 0..10 {\n cnt[i] += (a >> i) & 1;\n }\n }\n for i in 0..10 {\n if cnt[i] % (n / 2) != 0 {\n println!(\"Alice\");\n return;\n }\n }\n println!(\"Bob\");\n}\n\nfn main() {\n run();\n}\n"}], "src_uid": "4b9cf82967aa8441e9af3db3101161e9"} {"source_code": "use std::io;\n\nfn main() {\n let mut guess = String::new();\n\n io::stdin().read_line(&mut guess)\n .expect(\"Failed to read whatever you enter\");\n \n \n let first = guess.chars().nth(0).unwrap();\n let second = guess.chars().nth(1).unwrap();\n let mut allow = 8;\n let mut left_or_rigt_most = false;\n\n if first == 'a' || first == 'h' {\n left_or_rigt_most = true;\n allow -= 3;\n }\n\n if second == '1' || second == '8' {\n if left_or_rigt_most {\n allow -= 2;\n } else {\n allow -= 3;\n }\n }\n\n println!(\"{}\", allow);\n}\n", "positive_code": [{"source_code": "fn main() {\n let mut line = String::new();\n std::io::stdin().read_line(&mut line).expect(\"Error\");\n let letter = line.chars().nth(0).expect(\"Error\");\n let number = line.chars().nth(1).expect(\"Error\");\n let array = [letter, number];\n\n fn boundary(a: char) -> bool {\n match a {\n 'a' | 'h' | '1' | '8' => true,\n _ => false,\n }\n }\n let cnt = array.iter().map(|x| boundary(*x)).filter(|x| *x).count();\n\n let res = match cnt {\n 0 => 8,\n 1 => 5,\n 2 => 3,\n _ => unreachable!(),\n };\n println!(\"{}\", res);\n}"}, {"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 next(&mut self) -> T {\n\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 let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn main() {\n let mut s = Scanner::new();\n let input = s.next::();\n let mut iter = input.chars();\n let column = iter.next().unwrap();\n let row = iter.next().unwrap();\n\n if column == 'a' || column == 'h' {\n if row == '1' || row == '8' {\n println!(\"3\");\n } else {\n println!(\"5\");\n }\n } else if row == '1' || row == '8' {\n if column == 'a' || column == 'h' {\n println!(\"3\");\n } else {\n println!(\"5\");\n }\n } else {\n println!(\"8\");\n }\n}\n"}], "negative_code": [{"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 next(&mut self) -> T {\n\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 let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn main() {\n let mut s = Scanner::new();\n let input : String = s.next();\n println!(\"8\");\n}\n"}], "src_uid": "6994331ca6282669cbb7138eb7e55e01"} {"source_code": "use std::io::stdin;\nfn main() {\n let mut text = String::new();\n stdin().read_line(&mut text).unwrap();\n let text: Vec<&str> = text.trim().split_whitespace().collect();\n\n let mut val: Vec = vec![];\n let a = text[0].chars().collect::>();\n let b = text[1].chars().collect::>();\n let mut text1 = String::new();\n if a.len() > 1 {\n for x in &a[1..] {\n if x < &b[0] {\n text1.push(*x);\n } else {\n break;\n }\n }\n }\n val.sort();\n println!(\"{}{}{}\", a[0], text1, b[0]);\n}\n", "positive_code": [{"source_code": "use std::io::stdin;\nfn main() {\n let mut text = String::new();\n stdin().read_line(&mut text).unwrap();\n let text: Vec<&str> = text.trim().split_whitespace().collect();\n let mut value = 0;\n\n let mut val: Vec = vec![];\n let a = text[0].chars().collect::>();\n let b = text[1].chars().collect::>();\n let mut text1 = String::new();\n for x in &a {\n text1.push(*x);\n let mut text2 = String::new();\n\n for y in &b {\n text2.push(*y);\n val.push(text1.clone() + &text2[..]);\n }\n }\n val.sort();\n println!(\"{}\", val[0]);\n}\n"}, {"source_code": "use std::io;\n\nfn main() {\n let mut input = String::new();\n\n io::stdin().read_line(&mut input).unwrap();\n\n let parts: Vec<&str> = input.trim().split(' ').collect();\n let mut logins: Vec = vec![];\n\n for i in 1..(parts[0].len()+1) {\n for j in 1..(parts[1].len()+1) {\n let mut login = String::new();\n login.push_str(&parts[0][0..i]);\n login.push_str(&parts[1][0..j]);\n logins.push(login);\n }\n }\n\n logins.sort();\n\n println!(\"{}\", logins[0]);\n}\n"}], "negative_code": [], "src_uid": "aed892f2bda10b6aee10dcb834a63709"} {"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\nfn 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 {\n () => (get().parse::().unwrap());\n ($t:ty) => (get().parse::<$t>().unwrap()); }\n \n let mut field = vec![vec![]; 9];\n for i in 0..9 {\n for _ in 0..3 {\n field[i].push(get().as_bytes());\n }\n }\n let y = (get!(usize) - 1) % 3;\n let x = (get!(usize) - 1) % 3;\n \n let mut c = 0;\n for i in 0..3 {\n for &ch in &field[y*3+i][x][..] {\n if ch == b'.' {\n c += 1;\n }\n }\n }\n if c == 0 {\n for i in 0..9 {\n for j in 0..3 {\n if j > 0 { print!(\" \"); }\n for k in 0..3 {\n let ch = field[i][j][k];\n if ch == b'.' {\n print!(\"!\");\n } else {\n print!(\"{}\", ch as char);\n }\n }\n }\n println!();\n if i % 3 == 2 { println!(); }\n }\n return;\n }\n for i in 0..9 {\n for j in 0..3 {\n if j > 0 { print!(\" \"); }\n for k in 0..3 {\n let ch = field[i][j][k];\n if ch == b'.' && j == x && i / 3 == y {\n print!(\"!\");\n } else {\n print!(\"{}\", ch as char);\n }\n }\n }\n println!();\n if i % 3 == 2 { println!(); }\n }\n}", "positive_code": [{"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\n let p = input.bytes().position(|b| b'0' <= b && b <= b'9').unwrap();\n\n let grid: Vec<_> = input.as_bytes()[0..p].iter().filter_map(|&b| match b {\n b'.' => Some(Cell::Empty),\n b'x' => Some(Cell::Chip1),\n b'o' => Some(Cell::Chip2),\n _ => None,\n }).collect();\n\n let check = |x: usize, y: usize, grid: &Vec| {\n let x_off = 27 * x;\n let y_off = 3 * y;\n let mut it = grid[x_off + y_off..].iter().take(3)\n .chain(grid[x_off + y_off + 9..].iter().take(3))\n .chain(grid[x_off + y_off + 18..].iter().take(3));\n\n !it.all(|cell| match *cell {\n Cell::Empty => false,\n _ => true,\n })\n };\n\n let mut it = input[p..].split_whitespace();\n let x: usize = it.next().unwrap().parse::().unwrap() - 1;\n let y: usize = it.next().unwrap().parse::().unwrap() - 1;\n\n let bx = x % 3;\n let by = y % 3;\n\n let ans: Vec<_> = if !check(bx, by, &grid) {\n grid.into_iter().map(|cell| match cell {\n Cell::Empty => Cell::Possible,\n _ => cell,\n }).collect()\n } else {\n grid.into_iter().enumerate().map(|(i, cell)| {\n let x = i / 9;\n let y = i % 9;\n match cell {\n Cell::Empty if x / 3 == bx && y / 3 == by => Cell::Possible,\n _ => cell,\n }\n }).collect()\n };\n\n let mut ans_str = Vec::with_capacity(2 * p);\n\n for (i, cell) in ans.into_iter().enumerate() {\n let next = match cell {\n Cell::Empty => b'.',\n Cell::Chip1 => b'x',\n Cell::Chip2 => b'o',\n Cell::Possible => b'!',\n };\n\n ans_str.push(next);\n\n if i % 27 == 26 {\n ans_str.push(b'\\n');\n }\n if i % 9 == 8 {\n ans_str.push(b'\\n');\n } else if i % 3 == 2 {\n ans_str.push(b' ');\n }\n }\n\n let ans = String::from_utf8(ans_str).unwrap();\n\n print!(\"{}\", ans);\n}\n\n#[derive(Debug)]\nenum Cell {\n Empty,\n Chip1,\n Chip2,\n Possible,\n}\n"}, {"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 mut field: Vec> = (0..11).map(|_| util::line().chars().collect()).collect();\n let (mut y, mut x) = get!(usize, usize);\n\n y -= 1;\n x -= 1;\n\n let ry = y - 3 * (y / 3);\n let rx = x - 3 * (x / 3);\n\n let sy = 4 * ry;\n let sx = 4 * rx;\n\n if (sy..sy + 3).all(|y1| (sx..sx + 3).all(|x1| field[y1][x1] != '.')) {\n for v in field.iter_mut() {\n for c in v.iter_mut() {\n if *c == '.' {\n *c = '!';\n }\n }\n }\n } else {\n for y1 in sy..sy + 3 {\n for x1 in sx..sx + 3 {\n if field[y1][x1] == '.' {\n field[y1][x1] = '!';\n }\n }\n }\n }\n\n for line in &field {\n println!(\n \"{}\",\n line.iter()\n .map(|c| c.to_string())\n .collect::>()\n .join(\"\")\n );\n }\n}\n"}], "negative_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\n\nfn 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 {\n () => (get().parse::().unwrap());\n ($t:ty) => (get().parse::<$t>().unwrap()); }\n \n let mut field = vec![vec![]; 9];\n for i in 0..9 {\n for _ in 0..3 {\n field[i].push(get().as_bytes());\n }\n }\n let y = (get!(usize) - 1) % 3;\n let x = (get!(usize) - 1) % 3;\n \n let mut c = 0;\n for i in 0..3 {\n for &ch in &field[y*3+i][x][..] {\n if ch == b'.' {\n c += 1;\n }\n }\n }\n if c == 0 {\n for i in 0..9 {\n for j in 0..3 {\n if j > 0 { print!(\" \"); }\n for k in 0..3 {\n let ch = field[i][j][k];\n if ch == b'.' {\n print!(\"!\");\n } else {\n print!(\"{}\", ch as char);\n }\n }\n }\n println!();\n }\n return;\n }\n for i in 0..9 {\n for j in 0..3 {\n if j > 0 { print!(\" \"); }\n for k in 0..3 {\n let ch = field[i][j][k];\n if ch == b'.' && j == x && i / 3 == y {\n print!(\"!\");\n } else {\n print!(\"{}\", ch as char);\n }\n }\n }\n println!();\n }\n}"}, {"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\n let p = input.bytes().position(|b| b'0' <= b && b <= b'9').unwrap();\n\n let grid: Vec<_> = input.as_bytes()[0..p].iter().filter_map(|&b| match b {\n b'.' => Some(Cell::Empty),\n b'x' => Some(Cell::Chip1),\n b'o' => Some(Cell::Chip2),\n _ => None,\n }).collect();\n\n let check = |x: usize, y: usize, grid: &Vec| {\n let x_off = 27 * x;\n let y_off = 3 * y;\n let mut it = grid[x_off + y_off..].iter().take(3)\n .chain(grid[x_off + y_off + 9..].iter().take(3))\n .chain(grid[x_off + y_off + 18..].iter().take(3));\n\n !it.all(|cell| match *cell {\n Cell::Empty => false,\n _ => true,\n })\n };\n\n let mut it = input[p..].split_whitespace();\n let x: usize = it.next().unwrap().parse::().unwrap() - 1;\n let y: usize = it.next().unwrap().parse::().unwrap() - 1;\n\n let bx = x % 3;\n let by = y % 3;\n\n let ans: Vec<_> = if !check(bx, by, &grid) {\n grid.into_iter().map(|cell| match cell {\n Cell::Empty => Cell::Possible,\n _ => cell,\n }).collect()\n } else {\n grid.into_iter().enumerate().map(|(i, cell)| {\n let x = i / 9;\n let y = i % 9;\n match cell {\n Cell::Empty if x / 3 == bx && y / 3 == by => Cell::Possible,\n _ => cell,\n }\n }).collect()\n };\n\n let mut ans_str = Vec::with_capacity(2 * p);\n\n for (i, cell) in ans.into_iter().enumerate() {\n let next = match cell {\n Cell::Empty => b'.',\n Cell::Chip1 => b'x',\n Cell::Chip2 => b'o',\n Cell::Possible => b'!',\n };\n\n ans_str.push(next);\n\n if i % 9 == 8 {\n ans_str.push(b'\\n');\n } else if i % 3 == 2 {\n ans_str.push(b' ');\n }\n }\n\n let ans = String::from_utf8(ans_str).unwrap();\n\n print!(\"{}\", ans);\n}\n\n#[derive(Debug)]\nenum Cell {\n Empty,\n Chip1,\n Chip2,\n Possible,\n}\n"}], "src_uid": "8f0fad22f629332868c39969492264d3"} {"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 number = input.trim().parse::().expect(\"number: parse to usize failed\");\n\n let vec = vec![\n hp_judge(0, number),\n hp_judge(1, number),\n hp_judge(2, number),\n ];\n \n let outcome = great_hp(vec);\n\n println!(\"{} {}\", outcome.0, outcome.1);\n\n\n\n}\n\nfn great_hp(hp_vec: Vec<(i32, i32)>) -> (i32, String) {\n let mut best_hp = (i32::default(), i32::default());\n\n for item in hp_vec.iter() {\n if item.1 > best_hp.1 {\n best_hp = *item;\n }\n }\n\n\n\n convert(best_hp)\n}\n\nfn hp_judge(offset: i32, number: i32) -> (i32, i32) {\n ( offset, grade_estimation(number + offset) )\n}\n\nfn grade_estimation(hp: i32) -> i32 {\n let reminder = hp % 4;\n\n match reminder {\n 0 => { 0 },\n 1 => { 3 },\n 2 => { 1 },\n 3 => { 2 },\n _ => { -1 },\n\n }\n}\n\nfn convert(hp: (i32, i32)) -> (i32 ,String) {\n match hp.1 {\n 0 => { (hp.0, String::from(\"D\")) },\n 3 => { (hp.0, String::from(\"A\")) },\n 1 => { (hp.0, String::from(\"C\")) },\n 2 => { (hp.0, String::from(\"B\")) },\n _ => { (hp.0, String::from(\"Err\")) },\n }\n}", "positive_code": [{"source_code": "macro_rules! parse {\n () => {{\n let mut buffer = String::new();\n std::io::stdin().read_line(&mut buffer).expect(\"Could not fetch value from stdin\");\n buffer.trim().parse().expect(\"Could not convert input\")\n }};\n}\n\nfn main() {\n let hp: u32 = parse!();\n let current_category = hp % 4;\n match current_category {\n 0 => println!(\"1 A\"),\n 1 => println!(\"0 A\"),\n 2 => println!(\"1 B\"),\n 3 => println!(\"2 A\"),\n _ => unreachable!(\"Since mod 4 this should not be reachable\"),\n };\n}\n"}, {"source_code": "fn main() {\n let mut x = String::new();\n std::io::stdin().read_line(&mut x).unwrap();\n let x: u8 = x.trim().parse().unwrap();\n\n let (a, category) = match x % 4 {\n 0 => (1, 'A'),\n 1 => (0, 'A'),\n 2 => (1, 'B'),\n 3 => (2, 'A'),\n _ => unreachable!()\n };\n\n println!(\"{} {}\", a, category);\n}"}, {"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 x = input.u();\n let a = [3,0,2,1];\n let mut soli = 0;\n let mut sola = a[x % 4];\n for i in 1..=2 {\n let x = x + i;\n if m!(<,sola,a[x % 4]) {\n soli = i;\n }\n }\n println!(\"{} {}\", soli, (sola + b'A') as char);\n}\n\n"}, {"source_code": "use std::collections::HashMap;\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\n\nfn main() {\n\n let hp : i32 = read_string().trim().parse().ok().expect(\"not int\");\n\n let mut category : HashMap = HashMap::new();\n category.insert(1, \"0 A\");\n category.insert(3, \"2 A\");\n category.insert(2, \"1 B\");\n category.insert(0, \"1 A\");\n println!(\"{}\", category[&(hp % 4)]);\n}\n"}, {"source_code": "#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]\nstruct Score{\n grade: String,\n score: i32\n}\n\nfn calculate_grade(grade: i32) -> String{\n let mut words : String;\n match grade {\n 1 => words = String::from(\"A\"),\n 2 => words = String::from(\"C\"),\n 3 => words = String::from(\"B\"),\n _ => words = String::from(\"D\")\n }\n words\n}\n\nfn main() {\n let mut t: String = String::new();\n std::io::stdin().read_line(&mut t).expect(\"input\");\n let counter:Vec = t.trim()\n .split_whitespace()\n .map(|x| x.parse::().expect(\"Not an Integer!\"))\n .collect();\n\n let mut list_of_score : Vec = Vec::new();\n for i in 0..3{\n list_of_score.push( Score {\n score: i ,\n grade: calculate_grade((counter[0] + i) % 4)\n })\n }\n list_of_score.sort();\n println!(\"{} {}\", list_of_score[0].score, list_of_score[0].grade);\n}\n"}, {"source_code": "// Template adapted from submissions by https://codeforces.com/profile/EbTech\n\n#[allow(unused_imports)]\nuse std::io::*;\n\n#[derive(Default)]\nstruct Scanner(Vec);\nimpl Scanner {\n fn read(&mut self) -> T {\n loop {\n if let Some(token) = self.0.pop() {\n return token.parse().ok().unwrap();\n }\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n self.0 = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nfn main() {\n let mut cin = Scanner::default();\n let cout = &mut BufWriter::new(stdout());\n\n let x: u8 = cin.read();\n let (a, b) = match x % 4 {\n 1 => (0, 'A'),\n 3 => (2, 'A'),\n 2 => (1, 'B'),\n 0 => (1, 'A'),\n _ => unreachable!(),\n };\n\n writeln!(cout, \"{} {}\", a, b).unwrap();\n}\n"}, {"source_code": "use std::io::*;\nuse utils::*;\n\npub fn main() {\n let i = stdin();\n let mut o = Vec::new();\n run(i.lock(), &mut o);\n stdout().write_all(&o).unwrap();\n}\n\npub fn run(i: R, o: &mut W) {\n let mut i = CpReader::new(i);\n let x = i.read::();\n\n let (a, b) = solve(x);\n writeln!(o, \"{} {}\", a, b).unwrap();\n}\nfn solve(x: u32) -> (u32, char) {\n fn to_category(x: u32) -> char {\n match x % 4 {\n 1 => 'A',\n 3 => 'B',\n 2 => 'C',\n 0 => 'D',\n _ => unreachable!(),\n }\n }\n [0, 1, 2]\n .iter()\n .map(|&a| (a, to_category(x + a)))\n .min_by_key(|&(_a, c)| c)\n .unwrap()\n}\n\npub mod utils {\n use super::*;\n\n pub struct CpReader {\n r: R,\n b: Vec,\n }\n impl CpReader {\n pub fn new(r: R) -> Self {\n CpReader {\n r: r,\n b: Vec::new(),\n }\n }\n pub fn read_word(&mut self) -> &[u8] {\n self.b.clear();\n let mut consume = 0;\n loop {\n self.r.consume(consume);\n let b = self.r.fill_buf().unwrap();\n assert!(b.len() != 0);\n if let Some(p) = b.iter().position(|&x| x.is_ascii_whitespace()) {\n self.b.extend_from_slice(&b[..p]);\n consume = p + 1;\n break;\n }\n self.b.extend_from_slice(b);\n consume = b.len();\n }\n self.r.consume(consume);\n consume_ws(&mut self.r);\n &self.b\n }\n pub fn read_word_str(&mut self) -> &str {\n unsafe { std::str::from_utf8_unchecked(self.read_word()) }\n }\n\n pub fn read_line(&mut self) -> &[u8] {\n self.b.clear();\n self.r.read_until(b'\\n', &mut self.b).unwrap();\n let end = self\n .b\n .iter()\n .rposition(|x| !x.is_ascii_whitespace())\n .map(|idx| idx + 1)\n .unwrap_or(0);\n &self.b[..end]\n }\n pub fn read_line_str(&mut self) -> &str {\n unsafe { std::str::from_utf8_unchecked(self.read_line()) }\n }\n\n pub fn read(&mut self) -> T {\n T::read_from(self)\n }\n\n pub fn read_vec(&mut self, n: usize) -> Vec {\n (0..n).map(|_| self.read()).collect()\n }\n pub fn read_iter<'a, T: CpIn>(&'a mut self, n: usize) -> CpIter<'a, R, T> {\n CpIter {\n r: self,\n n: n,\n _pd: Default::default(),\n }\n }\n }\n pub struct CpIter<'a, R: BufRead + 'a, T> {\n r: &'a mut CpReader,\n n: usize,\n _pd: std::marker::PhantomData T>,\n }\n impl<'a, R: BufRead, T: CpIn> Iterator for CpIter<'a, R, T> {\n type Item = T;\n fn next(&mut self) -> Option {\n if self.n == 0 {\n None\n } else {\n self.n -= 1;\n Some(self.r.read())\n }\n }\n }\n\n pub trait CpIn {\n fn read_from(r: &mut CpReader) -> Self;\n }\n\n impl CpIn for u64 {\n fn read_from(r: &mut CpReader) -> Self {\n read_u64_fast(&mut r.r)\n }\n }\n impl CpIn for i64 {\n fn read_from(r: &mut CpReader) -> Self {\n read_i64_fast(&mut r.r)\n }\n }\n impl CpIn for char {\n fn read_from(r: &mut CpReader) -> Self {\n let b = r.r.fill_buf().unwrap()[0] as char;\n r.r.consume(1);\n let s = r.r.fill_buf().unwrap()[0];\n assert!(s == b' ' || s == b'\\n');\n r.r.consume(1);\n b\n }\n }\n\n macro_rules! cpin_tuple {\n ($($t:ident),*) => {\n impl<$($t: CpIn),*> CpIn for ($($t),*) {\n fn read_from(r: &mut CpReader) -> Self {\n ($($t::read_from(r)),*)\n }\n }\n };\n }\n\n macro_rules! cpin_cast {\n ($t_self:ty, $t_read:ty) => {\n impl CpIn for $t_self {\n fn read_from(r: &mut CpReader) -> Self {\n <$t_read>::read_from(r) as $t_self\n }\n }\n };\n }\n macro_rules! cpin_parse {\n ($t:ty) => {\n impl CpIn for $t {\n fn read_from(r: &mut CpReader) -> Self {\n r.read_word_str().parse().unwrap()\n }\n }\n };\n }\n cpin_cast!(usize, u64);\n cpin_cast!(u32, u64);\n cpin_cast!(u16, u64);\n cpin_cast!(i32, i64);\n cpin_cast!(i16, i64);\n cpin_cast!(i8, i64);\n\n cpin_parse!(f64);\n\n cpin_tuple!(T1, T2);\n cpin_tuple!(T1, T2, T3);\n cpin_tuple!(T1, T2, T3, T4);\n cpin_tuple!(T1, T2, T3, T4, T5);\n\n fn read_u64_fast(r: &mut R) -> u64 {\n let mut value = 0;\n loop {\n let mut idx = 0;\n let buf_len;\n {\n let buf = r.fill_buf().unwrap();\n buf_len = buf.len();\n assert!(buf_len != 0);\n while idx < buf_len && b'0' <= buf[idx] && buf[idx] <= b'9' {\n value = value * 10 + (buf[idx] - b'0') as u64;\n idx += 1;\n }\n }\n if idx < buf_len {\n r.consume(idx);\n consume_ws(r);\n return value;\n }\n r.consume(idx);\n }\n }\n fn read_i64_fast(r: &mut R) -> i64 {\n let (consume, sign) = match r.fill_buf().unwrap()[0] {\n b'+' => (true, 1),\n b'-' => (true, -1),\n _ => (false, 1),\n };\n if consume {\n r.consume(1);\n }\n read_u64_fast(r) as i64 * sign\n }\n fn consume_ws(r: &mut R) {\n let mut c = 0;\n loop {\n r.consume(c);\n let b = r.fill_buf().unwrap();\n if b.len() == 0 {\n return;\n }\n if let Some(p) = b.iter().position(|&x| !x.is_ascii_whitespace()) {\n c = p;\n break;\n }\n c = b.len();\n }\n r.consume(c);\n }\n\n}\n"}, {"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 get_class(x: usize) -> usize {\n let classes = [0usize, 2, 3, 1];\n return classes.iter().position(|&v| v == (x % 4)).unwrap();\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let x: usize = scan.next();\n let mut maxclass = get_class(x);\n let mut maxb = 0;\n for &step in [1usize, 2].iter() {\n let current_class = get_class(x + step);\n if current_class > maxclass {\n maxclass = current_class;\n maxb = step;\n }\n }\n println!(\"{} {}\", maxb, ['D', 'C', 'B', 'A'][maxclass]);\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"}], "negative_code": [], "src_uid": "488e809bd0c55531b0b47f577996627e"} {"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::num::ParseIntError;\nuse std::ops::Index;\n\nstruct RevBinary {\n data: Vec,\n}\n\nimpl FromStr for RevBinary {\n type Err = ParseIntError;\n\n fn from_str(s: &str) -> Result {\n let i = s.parse::()?;\n\n Ok(RevBinary::new(i))\n }\n}\n\nimpl Index for RevBinary {\n type Output = bool;\n\n fn index(&self, i: usize) -> &Self::Output {\n &self.data[self.data.len() - i - 1]\n }\n}\n\nimpl RevBinary {\n fn new(x : u32) -> RevBinary {\n let mut y = x;\n let mut bin : Vec = Vec::new();\n while y != 0 {\n bin.push(if y % 2 == 1 { true } else { false }); \n y /= 2;\n }\n RevBinary {\n data: bin,\n }\n }\n\n fn size(&self) -> usize {\n self.data.len()\n }\n}\n\nfn process_node(all: &Vec, ind: Vec, depth: usize, k: u32) -> u32 {\n let mut result : u32 = ind.iter().take(k as usize).map(|&x| all[x].size() - depth).sum::() as u32;\n\n if result == 0 {\n return 0;\n }\n\n let new_ind : (Vec, Vec) = ind.iter().filter(|&&x| all[x].size() > depth).partition(|&&x| all[x][depth]);\n if new_ind.0.len() >= k as usize {\n result = result.min(process_node(&all, new_ind.0, depth + 1, k));\n }\n if result != 0 && new_ind.1.len() >= k as usize {\n result = result.min(process_node(&all, new_ind.1, depth + 1, k));\n }\n result\n}\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 n = input_iter.next().unwrap().parse::().unwrap();\n let k = input_iter.next().unwrap().parse::().unwrap();\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let mut a = buffer.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n a.sort_by(|a, b| a.size().cmp(&b.size()));\n \n println!(\"{}\", process_node(&a, (0..n).collect::>(), 0, k));\n}", "positive_code": [{"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::num::ParseIntError;\nuse std::ops::Index;\n\nstruct RevBinary {\n data: Vec,\n}\n\nimpl FromStr for RevBinary {\n type Err = ParseIntError;\n\n fn from_str(s: &str) -> Result {\n let i = s.parse::()?;\n\n Ok(RevBinary::new(i))\n }\n}\n\nimpl Index for RevBinary {\n type Output = bool;\n\n fn index(&self, i: usize) -> &Self::Output {\n &self.data[self.data.len() - i - 1]\n }\n}\n\nimpl RevBinary {\n fn new(x : u32) -> RevBinary {\n let mut y = x;\n let mut bin : Vec = Vec::new();\n while y != 0 {\n bin.push(if y % 2 == 1 { true } else { false }); \n y /= 2;\n }\n RevBinary {\n data: bin,\n }\n }\n\n fn size(&self) -> usize {\n self.data.len()\n }\n}\n\nfn process_node(all: &Vec, ind: Vec, depth: usize, k: u32) -> u32 {\n let mut result : u32 = ind.iter().take(k as usize).map(|&x| all[x].size() - depth).sum::() as u32;\n\n let mut new_ind0 : Vec = Vec::new();\n let mut new_ind1 : Vec = Vec::new();\n for i in ind.iter().filter(|&&x| all[x].size() > depth) {\n if all[*i][depth] {\n new_ind1.push(*i);\n } else {\n new_ind0.push(*i);\n } \n }\n if new_ind0.len() >= k as usize {\n result = result.min(process_node(&all, new_ind0, depth + 1, k));\n }\n if new_ind1.len() >= k as usize {\n result = result.min(process_node(&all, new_ind1, depth + 1, k));\n }\n result\n}\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 n = input_iter.next().unwrap().parse::().unwrap();\n let k = input_iter.next().unwrap().parse::().unwrap();\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let mut a = buffer.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n a.sort_by(|a, b| a.size().cmp(&b.size()));\n \n println!(\"{}\", process_node(&a, (0..n).collect::>(), 0, k));\n}"}, {"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::num::ParseIntError;\nuse std::ops::Index;\n\nstruct RevBinary {\n data: Vec,\n}\n\nimpl FromStr for RevBinary {\n type Err = ParseIntError;\n\n fn from_str(s: &str) -> Result {\n let i = s.parse::()?;\n\n Ok(RevBinary::new(i))\n }\n}\n\nimpl Index for RevBinary {\n type Output = bool;\n\n fn index(&self, i: usize) -> &Self::Output {\n &self.data[self.data.len() - i - 1]\n }\n}\n\nimpl RevBinary {\n fn new(x : u32) -> RevBinary {\n let mut y = x;\n let mut bin : Vec = Vec::new();\n while y != 0 {\n bin.push(if y % 2 == 1 { true } else { false }); \n y /= 2;\n }\n RevBinary {\n data: bin,\n }\n }\n\n fn size(&self) -> usize {\n self.data.len()\n }\n}\n\nfn process_node(all: &Vec, ind: Vec, depth: usize, k: u32) -> u32 {\n let mut result : u32 = ind.iter().take(k as usize).map(|&x| all[x].size() - depth).sum::() as u32;\n\n if result != 0 {\n let mut new_ind0 : Vec = Vec::new();\n let mut new_ind1 : Vec = Vec::new();\n for i in ind.iter().filter(|&&x| all[x].size() > depth) {\n if all[*i][depth] {\n new_ind1.push(*i);\n } else {\n new_ind0.push(*i);\n } \n }\n if new_ind0.len() >= k as usize {\n result = result.min(process_node(&all, new_ind0, depth + 1, k));\n }\n if result != 0 && new_ind1.len() >= k as usize {\n result = result.min(process_node(&all, new_ind1, depth + 1, k));\n }\n }\n result\n}\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 n = input_iter.next().unwrap().parse::().unwrap();\n let k = input_iter.next().unwrap().parse::().unwrap();\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let mut a = buffer.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n a.sort_by(|a, b| a.size().cmp(&b.size()));\n \n println!(\"{}\", process_node(&a, (0..n).collect::>(), 0, k));\n}"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{Ordering};\n\n#[allow(unused_imports)]\nuse std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};\n\n#[allow(unused_imports)]\nuse std::io::{stdin, stdout, BufWriter, Write};\n\n#[allow(unused_imports)]\nuse std::iter::FromIterator;\n\n#[allow(unused_macros)]\nmacro_rules! min {\n ($x: expr) => ($x);\n ($x: expr, $($z: expr),+) => {{\n std::cmp::min($x, min!($($z),*))\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! max {\n ($x: expr) => ($x);\n ($x: expr, $($z: expr),+) => {{\n std::cmp::max($x, max!($($z),*))\n }}\n}\n\n#[allow(unused_macros)]\nmacro_rules! get { \n ([$t: ty]) => { \n { \n let mut line = String::new(); \n stdin().read_line(&mut line).unwrap(); \n line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::>()\n }\n };\n ([$t: ty];$n: expr) => {\n (0..$n).map(|_|get!([$t])).collect::>()\n };\n ($t: ty) => {\n {\n let mut line = 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::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)\n }\n };\n ($t: ty; $n: expr) => {\n (0..$n).map(|_|get!($t)).collect::>()\n };\n ($($t: ty),*; $n: expr) => {\n (0..$n).map(|_|get!($($t),*)).collect::>()\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),*).unwrap();\n }\n}\n\nconst BIG_STACK_SIZE: bool = true;\n\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 (n,k) = get!(usize, usize);\n let a = get!([usize]);\n let mut map = BTreeMap::new();\n for e in a {\n let mut e = e;\n let mut count = 0;\n while e > 0 {\n let entry = map.entry(e).or_insert(BinaryHeap::new());\n entry.push(count);\n if entry.len() > k {\n entry.pop();\n }\n count += 1;\n e /= 2;\n }\n }\n let mut mn = std::usize::MAX;\n for (_, v) in map {\n if v.len() == k {\n mn = min!(mn,v.into_iter().sum::());\n }\n }\n println!(\"{}\", mn);\n}\n"}, {"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::num::ParseIntError;\nuse std::ops::Index;\n\nstruct RevBinary {\n data: Vec,\n}\n\nimpl FromStr for RevBinary {\n type Err = ParseIntError;\n\n fn from_str(s: &str) -> Result {\n let i = s.parse::()?;\n\n Ok(RevBinary::new(i))\n }\n}\n\nimpl Index for RevBinary {\n type Output = bool;\n\n fn index(&self, i: usize) -> &Self::Output {\n &self.data[self.data.len() - i - 1]\n }\n}\n\nimpl RevBinary {\n fn new(x : u32) -> RevBinary {\n let mut y = x;\n let mut bin : Vec = Vec::new();\n while y != 0 {\n bin.push(if y % 2 == 1 { true } else { false }); \n y /= 2;\n }\n RevBinary {\n data: bin,\n }\n }\n\n fn size(&self) -> usize {\n self.data.len()\n }\n}\n\nfn process_node(all: &Vec, ind: Vec, depth: usize, k: u32) -> u32 {\n let mut result : u32 = ind.iter().take(k as usize).map(|&x| all[x].size() - depth).sum::() as u32;\n\n let mut new_ind0 : Vec = Vec::new();\n let mut new_ind1 : Vec = Vec::new();\n for i in ind.iter().filter(|&&x| all[x].size() > depth) {\n if all[*i][depth] {\n new_ind1.push(*i);\n } else {\n new_ind0.push(*i);\n } \n }\n if new_ind0.len() >= k as usize {\n result = result.min(process_node(&all, new_ind0, depth + 1, k));\n }\n if new_ind1.len() >= k as usize {\n result = result.min(process_node(&all, new_ind1, depth + 1, k));\n }\n result\n}\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 n = input_iter.next().unwrap().parse::().unwrap();\n let k = input_iter.next().unwrap().parse::().unwrap();\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let mut a = buffer.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n a.sort_by(|a, b| a.size().cmp(&b.size()));\n \n println!(\"{}\", process_node(&a, (0..n).collect::>(), 0, k));\n}"}, {"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)*) => (write!(out,$($format)*).unwrap());\n }\n\n input!{\n n: usize,\n k: usize,\n mut aa: [u64; n],\n }\n aa.sort();\n let mut m: u64 = *aa.iter().max().unwrap();\n let mut ans: u64 = 1 << 60;\n for t in 0..m+1 {\n let mut temp = 0;\n let mut ok = 0;\n\n for i in 0..n {\n let mut a = aa[i];\n let mut cnt = 0;\n if a < t {\n continue;\n }\n\n while a > t {\n a/=2;\n cnt += 1;\n }\n if t == a {\n temp += cnt;\n ok += 1;\n if ok == k {\n break;\n }\n }\n }\n\n if ok == k {\n ans = min(ans, temp);\n }\n }\n puts!(\"{}\\n\", ans);\n}\n"}, {"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\nconst INF:usize= 2 << 30;\n\nfn rec(cur: usize, u: usize, k: usize, cnt: &Vec, ans: &mut Vec) -> Vec {\n // debug!(cur, u, k);\n let mut v = vec![0; 20];\n if cur > u {\n return v;\n }\n let v1 = rec(cur*2, u, k, cnt, ans);\n let v2 = rec(cur*2+1, u, k, cnt, ans);\n v[0] = cnt[cur];\n\n let mut temp = min(k, cnt[cur]);\n let mut cost = 0;\n for i in 0..19 {\n v[i+1] = v1[i] + v2[i];\n if k - temp > 0 {\n cost += (i+1) * min(k-temp, v[i+1]);\n temp += min(k-temp, v[i+1]);\n }\n }\n if temp == k {\n ans[cur] = cost;\n }\n v\n}\n\n\nfn main() {\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\n input!{\n n: usize,\n k: usize,\n aa: [usize; n],\n }\n let mut m = *aa.iter().max().unwrap();\n let mut cnt = vec![0; m+1];\n let mut ans = vec![INF; m+1];\n for a in aa {\n cnt[a] += 1;\n }\n rec(1, m, k, &cnt, &mut ans);\n let ans = ans.iter().min().unwrap();\n puts!(\"{}\\n\", ans);\n}\n"}, {"source_code": "use std::collections::HashMap;\nuse std::io;\n\nfn lvl(mut x: i32) -> i8 {\n let mut res: i8 = 0;\n\n while x > 1 {\n res += 1;\n x >>= 1;\n }\n\n res\n}\n\nfn main() {\n let mut inp = String::new();\n io::stdin().read_line(&mut inp).unwrap();\n let line: Vec = inp\n .split_whitespace()\n .map(|x| x.trim().parse().unwrap())\n .collect();\n let (_n, k) = (line[0], line[1]);\n\n inp.clear();\n io::stdin().read_line(&mut inp).unwrap();\n\n let mut input: Vec<(i32, i8, i8)> = inp\n .split_whitespace()\n .map(|x| {\n let xx = x.trim().parse::().unwrap();\n (xx, lvl(xx), 0)\n })\n .collect();\n\n let mut min_steps: i32 = std::i32::MAX;\n loop {\n input.sort_unstable_by(|a, b| b.1.partial_cmp(&a.1).unwrap());\n\n //\n let mut eq_map: HashMap = HashMap::new();\n\n // count equal\n input\n .iter()\n .for_each(|x| *eq_map.entry(x.0).or_insert(0) += 1);\n\n eq_map.keys().for_each(|key| {\n if *eq_map.get(key).unwrap() >= k {\n // push equal to separate vector\n let mut eq_vec: Vec = input\n .iter()\n .filter(|x| &x.0 == key)\n .map(|x| x.2 as i32)\n .collect();\n\n // sort vector\n eq_vec.sort_unstable();\n // take(k).sum()\n min_steps = std::cmp::min(min_steps, eq_vec.iter().take(k as usize).sum());\n }\n });\n\n // all on first level\n if input.iter().all(|x| x.1 == 0) {\n break;\n }\n\n //println!(\"steps: {}; lvls: {:?}\", min_steps, input);\n\n let mut f: &mut (i32, i8, i8) = &mut input[0];\n\n f.0 >>= 1;\n f.1 -= 1;\n f.2 += 1;\n }\n\n //println!(\"lvls: {:?}\", input);\n print!(\"{}\", min_steps);\n //println!(\"steps: {}\", min_steps);\n}\n"}, {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\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\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\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 digit(ch: char) -> i64 {\n return (ch as u8 - b'0') as i64\n}\n\nconst MAX:usize = 30;\nconst INF:i64 = std::i64::MAX;\nconst MOD:i64 = 1e9 as i64 + 7;\n\nfn gcd(x:i64, y:i64) -> i64 {\n if y==0 { return x; }\n gcd(y, x%y)\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let k:usize = read();\n let a:Vec = (0..n).map(|_| read()).collect();\n\n let mut map = HashMap::new();\n for i in 0..n {\n let mut b = a[i];\n let mut j = 0;\n while b != 0 {\n let v = map.entry(b).or_insert(vec![]);\n v.push(j);\n j += 1;\n b /= 2;\n }\n }\n //debug!(map);\n\n let mut ans = INF;\n\n for (_,v) in &mut map {\n v.sort();\n if v.len() < k { continue; }\n let mut cnt = 0;\n for i in 0..k {\n cnt += v[i];\n }\n ans = min(ans,cnt);\n }\n\n println!(\"{}\", ans);\n\n //}\n}\n\n/*\n\n\n*/\n"}, {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\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\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\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 digit(ch: char) -> i64 {\n return (ch as u8 - b'0') as i64\n}\n\nconst MAX:usize = 30;\nconst INF:i64 = std::i64::MAX;\nconst MOD:i64 = 1e9 as i64 + 7;\n\nfn gcd(x:i64, y:i64) -> i64 {\n if y==0 { return x; }\n gcd(y, x%y)\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let k:usize = read();\n let a:Vec = (0..n).map(|_| read()).collect();\n\n let mut map = HashMap::new();\n for i in 0..n {\n let mut b = a[i];\n let mut j = 0;\n while b != 0 {\n let v = map.entry(b).or_insert(vec![]);\n v.push(j);\n j += 1;\n b /= 2;\n }\n }\n //debug!(map);\n\n let mut ans = INF;\n\n for (_,v) in &mut map {\n v.sort();\n if v.len() < k { continue; }\n let mut cnt = 0;\n for i in 0..k {\n cnt += v[i];\n }\n ans = min(ans,cnt);\n }\n\n println!(\"{}\", ans);\n\n //}\n}\n\n/*\n\n\n*/\n"}, {"source_code": "use std::rc::Rc;\n \nstruct Scanner {\n reader: Rc,\n buffer: [u8; 4096],\n position: usize,\n size: usize\n}\n \nimpl Scanner {\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 const EOF: i32 = -1;\n \n fn new(reader: T) -> Scanner {\n Scanner {\n reader: Rc::new(reader),\n buffer: [0; 4096],\n position: 0,\n size: 0\n }\n }\n \n fn read_block(&mut self) {\n self.size = Rc::get_mut(&mut self.reader).unwrap().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 Scanner::::EOF;\n }\n }\n \n let ch = self.buffer[self.position];\n self.position += 1;\n \n ch as i32\n }\n \n fn read_char_skip_ws(&mut self) -> i32 {\n let mut ch = self.read_char();\n while ch != Scanner::::EOF && Scanner::::SPACES.contains(&ch) {\n ch = self.read_char();\n }\n \n if ch == Scanner::::EOF {\n return Scanner::::EOF;\n }\n \n return ch;\n }\n \n fn read_int(&mut self) -> Option {\n let mut ch = self.read_char_skip_ws();\n if ch == Scanner::::EOF {\n return None;\n }\n \n let mut negative = false;\n if ch == Scanner::::NEG {\n negative = true;\n ch = self.read_char();\n }\n \n let mut result = 0;\n while ch != Scanner::::EOF && ch >= Scanner::::ZERO && ch <= Scanner::::NINE {\n result = result * 10 + ch - Scanner::::ZERO;\n ch = self.read_char();\n }\n \n Some(if negative {\n -result\n } else {\n result\n })\n }\n}\n \nimpl Scanner {\n fn new_stdin() -> Scanner {\n Scanner::new(std::io::stdin())\n }\n}\n\nfn main() {\n let mut reader = Scanner::new_stdin();\n \n let n = reader.read_int().unwrap() as usize;\n let k = reader.read_int().unwrap();\n let mut a: Vec = Vec::with_capacity(n);\n for _ in 0..n {\n a.push(reader.read_int().unwrap());\n }\n\n let amax = *a.iter().max().unwrap();\n let mut c: Vec = vec![0; (amax + 1) as usize];\n for x in a.iter() {\n c[*x as usize] += 1;\n }\n for i in 1..=amax as usize {\n c[i] += c[i - 1];\n }\n\n let mut ans = std::i32::MAX;\n for val in 1..=amax {\n let mut rest = k;\n let mut curr_ans = 0;\n let mut depth = 0;\n\n while rest > 0 {\n let low = val << depth;\n if low > amax {\n break;\n }\n\n let mut high = low + (1 << depth) - 1;\n if high > amax {\n high = amax;\n }\n let depth_cnt = c[high as usize] - c[(low - 1) as usize];\n\n if depth_cnt <= rest {\n curr_ans += depth_cnt * depth;\n rest -= depth_cnt;\n depth += 1;\n } else {\n curr_ans += rest * depth;\n rest = 0;\n }\n }\n\n if rest > 0 {\n continue;\n }\n\n if curr_ans < ans {\n ans = curr_ans;\n }\n }\n\n println!(\"{}\", ans);\n}\n"}, {"source_code": "//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, 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 k: usize,\n a: [usize; n],\n }\n let m = 200_000;\n let mut cnt = vec![0; m + 1];\n for &a in a.iter() {\n cnt[a] += 1;\n }\n let mut ans = 20 * n;\n let mut s = vec![vec![]; m + 1];\n let mut sum = vec![0; m + 1];\n for i in (0..=m).rev() {\n for _ in 0..cnt[i] {\n s[i].push(0);\n }\n s[i].sort();\n while s[i].len() > k {\n if let Some(v) = s[i].pop() {\n sum[i] -= v;\n }\n }\n if s[i].len() >= k {\n ans = std::cmp::min(ans, sum[i]);\n }\n if i > 0 {\n while let Some(v) = s[i].pop() {\n s[i / 2].push(v + 1);\n sum[i / 2] += v + 1;\n }\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::io::stdin;\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\nuse std::collections::HashMap;\nuse std::cmp::min;\n\nfn main() {\n let mut scan = Scanner::default();\n let n: usize = scan.next();\n let k: usize = scan.next();\n let a: Vec = (0..n).map(|_| scan.next::()).collect();\n let mut to_reach: HashMap> = HashMap::new();\n for x in &a {\n let mut y = x.clone();\n let mut div = 0;\n while y > 0 {\n if !to_reach.contains_key(&y) {\n to_reach.insert(y.clone(), vec![]);\n }\n let v: &mut Vec = to_reach.get_mut(&y).unwrap();\n v.push(div);\n y /= 2;\n div += 1;\n }\n }\n let mut ans = std::u64::MAX;\n for v in to_reach.values_mut() {\n if v.len() < k {\n continue;\n }\n v.sort();\n ans = min(ans, v[0..k].iter().sum::());\n }\n println!(\"{}\", ans);\n}\n"}, {"source_code": "//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, 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 k: usize,\n a: [usize; n],\n }\n let m = 200_000;\n let mut cnt = vec![0; m + 1];\n for &a in a.iter() {\n cnt[a] += 1;\n }\n let mut ans = 20 * n;\n let mut s = vec![vec![]; m + 1];\n let mut sum = vec![0; m + 1];\n for i in (0..=m).rev() {\n for _ in 0..cnt[i] {\n s[i].push(0);\n }\n s[i].sort();\n while s[i].len() > k {\n if let Some(v) = s[i].pop() {\n sum[i] -= v;\n }\n }\n if s[i].len() >= k {\n ans = std::cmp::min(ans, sum[i]);\n }\n if i > 0 {\n while let Some(v) = s[i].pop() {\n s[i / 2].push(v + 1);\n sum[i / 2] += v + 1;\n }\n }\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "use std::io;\nconst Z: usize = 200000;\n\nfn uints() -> Vec {\n let mut buf = String::new();\n\tio::stdin().read_line(&mut buf);\n\tbuf\n .split_ascii_whitespace()\n .map(str::parse::)\n .collect::, _>>()\n .unwrap()\n}\n\nfn solve(k: usize, a: Vec) -> usize {\n let mut t: Vec> = vec![Vec::new(); Z + 1];\n for mut x in a {\n let mut cnt = 0;\n loop {\n t[x].push(cnt);\n cnt += 1;\n if x == 0 {\n break;\n } else {\n x /= 2;\n }\n }\n }\n for mut v in t.iter_mut() {\n v.sort();\n }\n t.iter()\n .filter(|w| w.len() >= k)\n .map(|w| (&w[..k]).iter().sum::())\n .min()\n .unwrap()\n}\n\nfn main() {\n if let [_, k] = &uints()[..2] {\n println!(\"{}\", solve(*k, uints()));\n }\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::io::stdin;\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\nuse std::collections::HashMap;\nuse std::cmp::min;\n\nfn main() {\n let mut scan = Scanner::default();\n let n: usize = scan.next();\n let k: usize = scan.next();\n let a: Vec = (0..n).map(|_| scan.next::()).collect();\n let mut to_reach: HashMap> = HashMap::new();\n for x in &a {\n let mut y = x.clone();\n let mut div = 0;\n while y > 0 {\n if !to_reach.contains_key(&y) {\n to_reach.insert(y.clone(), vec![]);\n }\n let v: &mut Vec = to_reach.get_mut(&y).unwrap();\n v.push(div);\n y /= 2;\n div += 1;\n }\n }\n let mut ans = std::u64::MAX;\n for v in to_reach.values_mut() {\n if v.len() < k {\n continue;\n }\n v.sort();\n ans = min(ans, v[0..k].iter().sum::());\n }\n println!(\"{}\", ans);\n}\n"}], "negative_code": [{"source_code": "use std::io;\nuse std::str::FromStr;\nuse std::num::ParseIntError;\nuse std::ops::Index;\n\nstruct RevBinary {\n data: Vec,\n}\n\nimpl FromStr for RevBinary {\n type Err = ParseIntError;\n\n fn from_str(s: &str) -> Result {\n let i = s.parse::()?;\n\n Ok(RevBinary::new(i))\n }\n}\n\nimpl Index for RevBinary {\n type Output = bool;\n\n fn index(&self, i: usize) -> &Self::Output {\n &self.data[self.data.len() - i - 1]\n }\n}\n\nimpl RevBinary {\n fn new(x : u32) -> RevBinary {\n let mut y = x;\n let mut bin : Vec = Vec::new();\n while y != 0 {\n bin.push(if y % 2 == 1 { true } else { false }); \n y /= 2;\n }\n RevBinary {\n data: bin,\n }\n }\n\n fn size(&self) -> usize {\n self.data.len()\n }\n}\n\nfn process_node(all: &Vec, ind: Vec, depth: usize, k: u32) -> u32 {\n let mut result : u32 = ind.iter().take(k as usize).map(|&x| all[x].size() - depth).sum::() as u32;\n\n let mut new_ind0 : Vec = Vec::new();\n let mut new_ind1 : Vec = Vec::new();\n for i in ind.iter().filter(|&&x| all[x].size() > depth) {\n if all[*i][depth] {\n new_ind1.push(*i);\n } else {\n new_ind0.push(*i);\n } \n }\n if new_ind0.len() >= k as usize {\n result = result.min(process_node(&all, new_ind0, depth + 1, k));\n }\n if new_ind1.len() >= k as usize {\n result = result.min(process_node(&all, new_ind1, depth + 1, k));\n }\n result\n}\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 n = input_iter.next().unwrap().parse::().unwrap();\n let k = input_iter.next().unwrap().parse::().unwrap();\n let mut buffer = String::new();\n io::stdin().read_line(&mut buffer).expect(\"failed to read input\");\n let a = buffer.split_whitespace().map(|x| x.parse::().unwrap()).collect::>();\n \n println!(\"{}\", process_node(&a, (0..n).collect::>(), 0, k));\n}"}, {"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)*) => (write!(out,$($format)*).unwrap());\n }\n\n input!{\n n: usize,\n k: usize,\n mut aa: [usize; n],\n }\n aa.sort();\n\n let mut ans: u64 = 1 << 60;\n for t in 0..n+1 {\n let mut temp = 0;\n let mut ok = 0;\n\n for i in 0..n {\n let mut a = aa[i];\n let mut cnt = 0;\n if a < t {\n continue;\n }\n\n while a > t {\n a/=2;\n cnt += 1;\n }\n if t == a {\n temp += cnt;\n ok += 1;\n if ok == k {\n break;\n }\n }\n }\n\n if ok == k {\n ans = min(ans, temp);\n }\n }\n puts!(\"{}\\n\", ans);\n}\n"}, {"source_code": "use std::io;\n\nfn shift_count(mut from: i32, to: i32) -> i32 {\n let mut cnt = 0;\n while from > to {\n cnt += 1;\n from /= 2;\n }\n cnt\n}\n\nfn normalize(id: usize, input: &Vec) -> Vec {\n let norm_val = input[id];\n let mut normalized: Vec = input\n .iter()\n .map(|x| {\n if x < &norm_val {\n 20000000\n } else {\n shift_count(*x, norm_val)\n }\n })\n .collect();\n\n normalized.sort_unstable();\n normalized\n}\n\nfn cost(normalized: &Vec, cnt: u8) -> i32 {\n normalized\n .iter()\n .take(cnt as usize)\n .fold(0, |acc, x| acc + x)\n}\n\nfn main() {\n let mut inp = String::new();\n io::stdin().read_line(&mut inp).unwrap();\n let line: Vec = inp\n .split_whitespace()\n .map(|x| x.trim().parse().unwrap())\n .collect();\n let (n, k) = (line[0], line[1]);\n\n inp.clear();\n io::stdin().read_line(&mut inp).unwrap();\n\n let input: Vec = inp\n .split_whitespace()\n .map(|x| x.trim().parse::().unwrap())\n .collect();\n\n let mut norm_matrix: Vec> = Vec::with_capacity(input.len());\n\n let mut min_cost = std::i32::MAX;\n for i in 0..n {\n let norm = normalize(i as usize, &input);\n let c = cost(&norm, k);\n if c < min_cost {\n min_cost = c;\n }\n\n norm_matrix.push(norm);\n }\n\n println!(\"{}\", min_cost);\n}\n"}, {"source_code": "#![allow(unused_imports)]\n#![allow(unused_macros)]\n#![allow(dead_code)]\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\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\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 digit(ch: char) -> i64 {\n return (ch as u8 - b'0') as i64\n}\n\nconst MAX:usize = 30;\nconst INF:i64 = std::i64::MAX;\nconst MOD:i64 = 1e9 as i64 + 7;\n\nfn gcd(x:i64, y:i64) -> i64 {\n if y==0 { return x; }\n gcd(y, x%y)\n}\n\nfn main() {\n //let t:usize = read();\n\n //'outer: for _ in 0..t {\n let n:usize = read();\n let k:usize = read();\n let a:Vec = (0..n).map(|_| read()).collect();\n\n let mut map = HashMap::new();\n for i in 0..n {\n let mut b = a[i];\n let mut j = 0;\n while b != 0 {\n let v = map.entry(b).or_insert(vec![]);\n v.push(j);\n j += 1;\n b /= 2;\n }\n }\n //debug!(map);\n\n let mut ans = INF;\n let mut m = 1i64;\n while m < 1000000 {\n let v = map.entry(m).or_insert(vec![]);\n v.sort();\n if v.len() < k { m*=2; continue; }\n let mut cnt = 0i64;\n for i in 0..k {\n cnt += v[i];\n }\n ans = min(ans, cnt);\n m *= 2;\n }\n for i in 0..n {\n let v = map.entry(a[i]).or_insert(vec![]);\n v.sort();\n if v.len() < k { continue; }\n let mut cnt = 0i64;\n for j in 0..k {\n cnt += v[j];\n }\n ans = min(ans, cnt);\n }\n\n println!(\"{}\", ans);\n\n //}\n}\n\n/*\n\n\n*/\n"}, {"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\nconst INF:usize= 2 << 30;\n\nfn rec(cur: usize, u: usize, k: usize, cnt: &Vec, ans: &mut Vec) -> Vec {\n debug!(cur, u, k);\n let mut v = vec![0; 20];\n if cur > u {\n return v;\n }\n let v1 = rec(cur*2, u, k, cnt, ans);\n let v2 = rec(cur*2+1, u, k, cnt, ans);\n v[0] = cnt[cur];\n\n let mut temp = cnt[cur];\n let mut cost = 0;\n for i in 0..19 {\n v[i+1] = v1[i] + v2[i];\n if k - temp > 0 {\n cost += (i+1) * min(k-temp, v[i+1]);\n temp += min(k-temp, v[i+1]);\n }\n }\n if temp == k {\n ans[cur] = cost;\n }\n v\n}\n\n\nfn main() {\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\n input!{\n n: usize,\n k: usize,\n aa: [usize; n],\n }\n let mut m = *aa.iter().max().unwrap();\n let mut cnt = vec![0; m+1];\n let mut ans = vec![INF; m+1];\n for a in aa {\n cnt[a] += 1;\n }\n rec(1, m, k, &cnt, &mut ans);\n let ans = ans.iter().min().unwrap();\n puts!(\"{}\\n\", ans);\n}\n"}], "src_uid": "ed1a2ae733121af6486568e528fe2d84"} {"source_code": "#![allow(unused_variables)]\n#![allow(unused_must_use)]\n \nuse std::io::{self, prelude::*};\n\nfn main() {\n let stdin = io::stdin();\n let stdout = io::stdout();\n let mut input = Input::new(stdin.lock());\n let mut output = io::BufWriter::new(stdout.lock());\n macro_rules! puts {\n ($($format:tt)*) => (write!(output, $($format)*).unwrap());\n }\n \n let n: usize = input.next();\n let mut a: Vec = input.iter().take(n).collect();\n a.sort();\n let mut cur = Vec::new();\n let mut ans = 0usize;\n for x in a {\n if !cur.iter().any(|&y| x % y == 0) {\n cur.push(x);\n ans += 1;\n }\n }\n puts!(\"{}\\n\", ans);\n}\n \nstruct Input {\n lines: io::Lines,\n cur: String,\n split: std::str::SplitAsciiWhitespace<'static>, //'\n}\n \nimpl Input {\n fn new(reader: R) -> Input {\n use std::mem::transmute;\n \n let mut lines = reader.lines();\n let cur = lines.next().unwrap().unwrap();\n let split = unsafe { transmute(cur.split_ascii_whitespace()) };\n Input { lines, cur, split }\n }\n fn update(&mut self) {\n use std::mem::transmute;\n self.cur = self.lines.next().unwrap().unwrap();\n unsafe { self.split = transmute(self.cur.split_ascii_whitespace()) };\n }\n fn next(&mut self) -> F {\n loop {\n if let Some(thing) = self.split.next() {\n return thing.parse().ok().unwrap();\n }\n self.update();\n }\n }\n fn iter(&mut self) -> InputIter {\n InputIter {\n input: self,\n _phantom: std::marker::PhantomData,\n }\n }\n}\n \nstruct InputIter<'a, R, I> {\n input: &'a mut Input,\n _phantom: std::marker::PhantomData,\n}\n \nimpl<'a, R, I> Iterator for InputIter<'a, R, I>\nwhere\n R: BufRead,\n I: std::str::FromStr,\n{\n type Item = I;\n fn next(&mut self) -> Option {\n Some(self.input.next())\n }\n}\n", "positive_code": [{"source_code": "// ######### contest shortcuts\n#![allow(unused_imports, dead_code, unused_variables)]\nuse std::io::{stdin, stdout, BufWriter, BufReader, Read, Write};\nuse std::cmp;\n\n#[derive(Default)]\nstruct Scanner (Vec,);\n \nimpl Scanner {\n fn next(&mut self) -> T {\n loop {\n if let Some(token) = self.0.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.0 = input.split_whitespace().rev()\n .map(String::from).collect();\n }\n }\n}\n// ## END ## contest shortcuts\n\nfn main() {\n let mut scan = Scanner::default();\n let out = &mut BufWriter::new(stdout());\n\n let n = scan.next::();\n // let mut a = scan.next::();\n let a: Vec = (0..n)\n .map(|_| scan.next::())\n .collect();\n let mut s_a: Vec<_> = a.iter()\n .map(|e| e.clone())\n .enumerate()\n .collect();\n s_a.sort_by_key(|&(_, e)| e);\n // println!(\"{:?}\", s_a);\n let mut marks = vec![false; n];\n let mut colors = 0usize;\n for &(j, e) in s_a.iter() {\n if marks[j] { continue; }\n colors += 1;\n \n for (i, ae) in a.iter().enumerate(){\n if marks[i] == false && ae % e == 0 {\n marks[i] = true;\n // println!(\"{:?}\", e);\n }\n }\n }\n write!(out, \"{}\", colors).ok();\n}\n"}, {"source_code": "// ____ _ _ _ _\n// | _ \\ _ _ ___| |_ ___ _ __ | |_ ___ _ __ ___ _ __ | | __ _| |_ ___\n// | |_) | | | / __| __| / __| '_ \\ | __/ _ \\ '_ ` _ \\| '_ \\| |/ _` | __/ _ \\\n// | _ <| |_| \\__ \\ |_ | (__| |_) | | || __/ | | | | | |_) | | (_| | || __/\n// |_| \\_\\\\__,_|___/\\__| \\___| .__/___\\__\\___|_| |_| |_| .__/|_|\\__,_|\\__\\___|\n// |_| |_____| |_|\n\n// _ _ _ _____ ___\n// _ __ ___ __ _ _ __ | |_ __ _/ / |___ / / _ \\\n// | '_ ` _ \\ / _` | '_ \\| __/ _` | | | |_ \\| | | |\n// | | | | | | (_| | | | | || (_| | | |___) | |_| |\n// |_| |_| |_|\\__,_|_| |_|\\__\\__,_|_|_|____/ \\___/\n\n//https://github.com/manta1130/Competitive_Programming_Template_Rust\n\n#[macro_use]\nmod input {\n\n use std;\n use std::io;\n\n const SPLIT_DELIMITER: char = ' ';\n\n #[macro_export]\n #[allow(unused_macros)]\n macro_rules! input {\n ( $($x:expr ),*) => {\n {\n let temp_str = input_line_str();\n let mut split_result_iter = temp_str.split_whitespace();\n $(\n let buf_split_result = split_result_iter.next();\n let buf_split_result = buf_split_result.unwrap();\n ($x) = buf_split_result.parse().unwrap();\n )*\n }\n };\n}\n\n #[allow(dead_code)]\n pub fn input_line_str() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn p(t: T)\n where\n T: std::fmt::Display,\n {\n println!(\"{}\", t);\n }\n\n #[allow(dead_code)]\n pub fn input_vector2d(line: usize) -> Vec>\n where\n T: std::str::FromStr,\n {\n let mut v: Vec> = Vec::new();\n\n for _ in 0..line {\n let vec_line = input_vector();\n v.push(vec_line);\n }\n v\n }\n\n #[allow(dead_code)]\n pub fn input_vector() -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v: Vec = Vec::new();\n\n let s = input_line_str();\n let split_result = s.split(SPLIT_DELIMITER);\n for z in split_result {\n let buf = match z.parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\"),\n };\n v.push(buf);\n }\n v\n }\n\n #[allow(dead_code)]\n pub fn input_vector_row(n: usize) -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v = Vec::with_capacity(n);\n for _ in 0..n {\n let buf = match input_line_str().parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\"),\n };\n v.push(buf);\n }\n v\n }\n\n pub trait ToCharVec {\n fn to_charvec(&self) -> Vec;\n }\n\n impl ToCharVec for String {\n fn to_charvec(&self) -> Vec {\n self.to_string().chars().collect::>()\n }\n }\n}\n\nuse input::*;\n\nfn main() {\n let n: usize;\n input!(n);\n let mut v = input_vector::();\n v.sort();\n let mut flag = vec![false; n];\n let mut ans = 0;\n for i in 0..n {\n if flag[i] {\n continue;\n }\n ans += 1;\n flag[i] = true;\n for j in i + 1..n {\n if v[j] % v[i] == 0 {\n flag[j] = true;\n }\n }\n }\n p(ans);\n}\n"}, {"source_code": "//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, 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: [u32; n],\n }\n let mut n = n;\n let mut a = a;\n let mut ans = 0;\n while n > 0 {\n a.sort();\n let v = a[0];\n let mut b = vec![];\n for i in 1..n {\n if a[i] % v != 0 {\n b.push(a[i]);\n }\n }\n a = b;\n n = a.len();\n ans += 1;\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "//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, 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: [u32; n],\n }\n let mut a = a;\n let mut ans = 0;\n while a.len() > 0 {\n ans += 1;\n let v = *a.iter().min().unwrap();\n a = a.into_iter().filter(|a| *a % v != 0).collect();\n }\n println!(\"{}\", ans);\n}\n\nfn main() {\n run();\n}\n"}], "negative_code": [], "src_uid": "63d9b7416aa96129c57d20ec6145e0cd"} {"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 next(&mut self) -> T {\n\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 let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn checked_sub(a : usize, b : usize) -> usize {\n if b > a {\n println!(\"Checked sub failed!, {}, {}\", a, b);\n }\n a - b\n}\n\nfn main() {\n let mut s = Scanner::new();\n let buffer : String = s.next();\n let mut input = buffer.into_bytes();\n\n let mut set : [i32; 30] = [0; 30];\n let mut count = 0;\n let mut left = 0;\n let mut right = 26;\n let b = 'A' as usize;\n\n if input.len() < 26 {\n println!(\"-1\");\n return;\n }\n\n for i in left..right {\n let c = input[i] as char;\n let k = input[i] as usize;\n if c == '?' {\n count += 1;\n set[26] += 1;\n } else {\n\n if set[checked_sub(k, b)] == 0 {\n count += 1;\n }\n set[checked_sub(k, b)] += 1;\n }\n }\n\n let mut tail = input[left] as usize;\n for i in right..input.len() {\n let c = input[i] as char;\n let k = input[i] as usize;\n\n if count == 26 {\n break;\n }\n\n if tail == '?' as usize {\n set[26] -= 1;\n count -= 1;\n } else {\n set[checked_sub(tail, b)] -= 1;\n if set[checked_sub(tail, b)] == 0 {\n count -= 1;\n }\n }\n\n if c == '?' {\n count += 1;\n set[26] += 1;\n } else {\n if set[checked_sub(k, b)] == 0 {\n count += 1;\n }\n set[checked_sub(k, b)] += 1;\n }\n\n left += 1;\n right += 1;\n tail = input[left] as usize;\n }\n\n if count == 26 {\n\n for i in 0..left {\n let c = input[i] as char;\n if c == '?' {\n input[i] = 'A' as u8;\n }\n }\n\n for i in left..right {\n let c = input[i] as char;\n if c == '?' {\n for j in 0..27 {\n if set[j] == 0 {\n let k = j as u8;\n input[i] = k + b as u8;\n set[j] = 1;\n break;\n }\n }\n }\n }\n\n for i in right..input.len() {\n let c = input[i] as char;\n if c == '?' {\n input[i] = 'A' as u8;\n }\n }\n\n for i in input.iter() {\n print!(\"{}\", *i as char);\n }\n println!(\"\");\n } else {\n println!(\"-1\");\n }\n}\n", "positive_code": [{"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\nfn main() {\n let mut buffer : String = String::new();\n stdin().read_line(&mut buffer).ok();\n let mut input = buffer.trim().to_string().into_bytes();\n\n let mut set : [i32; 30] = [0; 30];\n let mut count = 0;\n let mut left = 0;\n let mut right = 26;\n let b = 'A' as usize;\n\n if input.len() < 26 {\n println!(\"-1\");\n return;\n }\n\n for i in left..right {\n let c = input[i] as char;\n let k = input[i] as usize;\n if c == '?' {\n count += 1;\n set[26] += 1;\n } else {\n\n if set[k - b] == 0 {\n count += 1;\n }\n set[k - b] += 1;\n }\n }\n\n let mut tail = input[left] as usize;\n for i in right..input.len() {\n let c = input[i] as char;\n let k = input[i] as usize;\n\n if count == 26 {\n break;\n }\n\n if tail == '?' as usize {\n set[26] -= 1;\n count -= 1;\n } else {\n set[tail - b] -= 1;\n if set[tail - b] == 0 {\n count -= 1;\n }\n }\n\n if c == '?' {\n count += 1;\n set[26] += 1;\n } else {\n if set[k - b] == 0 {\n count += 1;\n }\n set[k - b] += 1;\n }\n\n left += 1;\n right += 1;\n tail = input[left] as usize;\n }\n\n if count == 26 {\n\n for i in 0..left {\n let c = input[i] as char;\n if c == '?' {\n input[i] = 'A' as u8;\n }\n }\n\n for i in left..right {\n let c = input[i] as char;\n if c == '?' {\n for j in 0..27 {\n if set[j] == 0 {\n let k = j as u8;\n input[i] = k + b as u8;\n set[j] = 1;\n break;\n }\n }\n }\n }\n\n for i in right..input.len() {\n let c = input[i] as char;\n if c == '?' {\n input[i] = 'A' as u8;\n }\n }\n\n for i in input.iter() {\n print!(\"{}\", *i as char);\n }\n println!(\"\");\n } else {\n println!(\"-1\");\n }\n}\n"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\nuse std::str;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n let mut laschr : Vec = vec![];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for (i, ch) in s.chars().enumerate() {\n laschr.push(ch);\n\n match ch {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 25 {\n match laschr.remove(0) {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and store the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string\n if count + wildcd >= 26 {\n\n let mut output = String::new();\n\n for chr in s.chars().take(i-25) {\n //print 'A' in the question mark spots before the substring\n match chr {\n '?' => {\n output.push('A');\n },\n c => {\n output.push(c);\n }\n }\n }\n\n for chr in s.chars().skip(i-25) {\n\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n output.push(letters.pop().unwrap_or('Z'));\n },\n c => {\n output.push(c);\n }\n }\n }\n\n println!(\"{}\", output);\n return;\n }\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{min, max};\n\nfn main(){\n\n let cs: Vec = get_line().chars().collect();\n let len = cs.len();\n\n if len < 26 {\n println!(\"-1\");\n return;\n }\n\n for i in 0..len-25 {\n let mut freq: Vec = vec![0;26];\n for j in i..i+26 {\n if cs[j] == '?' {\n continue;\n }\n let c = cs[j] as usize - 'A' as usize;\n freq[c] += 1;\n }\n\n if freq.iter().any(|&x: &usize| x > 1) {\n continue;\n }\n\n for j in 0..i {\n print!(\"{}\", if cs[j] == '?' { 'A' } else { cs[j] })\n }\n\n for j in i..i+26 {\n if cs[j] != '?' {\n print!(\"{}\", cs[j]);\n } else {\n for k in 0..26 {\n if freq[k] == 0 {\n print!(\"{}\", (k as u8 + 'A' as u8) as char);\n freq[k] = 1;\n break;\n }\n }\n }\n }\n\n for j in i+26..len {\n print!(\"{}\", if cs[j] == '?' { 'A' } else { cs[j] })\n }\n return;\n }\n\n println!(\"-1\")\n}\n\n#[allow(dead_code)]\nfn get_line() -> String{\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n buf.trim_right().to_string()\n}\n\n#[allow(dead_code)]\nfn readln() -> T{\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n T::read(buf.trim_right())\n}\n\ntrait Read{\n fn read(s: &str) -> Self;\n}\n\nmacro_rules! read_impl{\n ($($t:ty)*) => ($(\n impl Read for $t {\n fn read(s: &str) -> $t{\n s.parse().unwrap()\n }\n }\n )*)\n}\nread_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }\n\nimpl Read for Vec{\n fn read(s: &str) -> Self {\n s.split_whitespace().map(T::read).collect()\n }\n}\n\nimpl Read for (A, B){\n fn read(s: &str) -> Self {\n let tokens: Vec<_> = s.split_whitespace().collect();\n (A::read(tokens[0]), B::read(tokens[1]))\n }\n}\n\nimpl Read for (A, B, C){\n fn read(s: &str) -> Self {\n let tokens: Vec<_> = s.split_whitespace().collect();\n (A::read(tokens[0]), B::read(tokens[1]), C::read(tokens[2]))\n }\n}"}], "negative_code": [{"source_code": "use std::io::prelude::*;\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [(s.len()); 26];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for i in 0..(s.len()) {\n match s.chars().skip(i).next().unwrap() {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i;\n }\n }\n\n if i > 26 {\n match s.chars().skip(i-26).next().unwrap() {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if i - laspos[j] < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string.\n if count + wildcd >= 26 {\n for chr in s.chars().skip(i-25).take(26) {\n match chr {\n '?' => {\n print!(\"{}\", letters.pop().unwrap_or('?'));\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n println!(\"\");\n return;\n }\n\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [(s.len()+27); 26];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for i in 0..(s.len()) {\n match s.chars().skip(i).next().unwrap() {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i;\n }\n }\n\n if i > 26 {\n match s.chars().skip(i-26).next().unwrap() {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if i - laspos[j] < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string.\n if count + wildcd >= 26 {\n for chr in s.chars().skip(i-25).take(26) {\n match chr {\n '?' => {\n print!(\"{}\", letters.pop().unwrap_or('?'));\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n println!(\"\");\n return;\n }\n\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for i in 0..(s.len()) {\n match s.chars().skip(i).next().unwrap() {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 26 {\n match s.chars().skip(i-26).next().unwrap() {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string.\n if count + wildcd >= 26 {\n for chr in s.chars().skip(i-25).take(26) {\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"{}\", letters.pop().unwrap_or('?'));\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n println!(\"\");\n return;\n }\n\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\nuse std::str;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n let mut laschr : Vec = vec![];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for (i, ch) in s.chars().enumerate() {\n laschr.push(ch);\n\n match ch {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 26 {\n match laschr.remove(0) {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string\n if count + wildcd >= 26 {\n\n let mut output = String::new();\n\n for chr in s.chars().take(i-25) {\n //print 'A' in the question mark spots before the substring\n match chr {\n '?' => {\n output.push('A');\n },\n c => {\n output.push(c);\n }\n }\n }\n\n for chr in s.chars().skip(i-25) {\n\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n output.push(letters.pop().unwrap_or('Z'));\n },\n c => {\n output.push(c);\n }\n }\n }\n\n println!(\"{}\", output);\n return;\n }\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for i in 0..(s.len()) {\n match s.chars().skip(i).next().unwrap() {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 26 {\n match s.chars().skip(i-26).next().unwrap() {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string.\n if count + wildcd >= 26 {\n\n\n for chr in s.chars().take(i-25) {\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"A\");\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n\n for chr in s.chars().skip(i-25).take(26) {\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"{}\", letters.pop().unwrap_or('?'));\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n\n for chr in s.chars().skip(i) {\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"A\");\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n println!(\"\");\n return;\n }\n\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\nuse std::str;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n let mut laschr : Vec = vec![];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for (i, ch) in s.chars().enumerate() {\n laschr.push(ch);\n\n match ch {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 26 {\n match laschr.remove(0) {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string\n if count + wildcd >= 26 {\n\n let mut output = String::new();\n\n for chr in s.chars().take(i-25) {\n //print 'A' in the question mark spots before the substring\n match chr {\n '?' => {\n output.push('A');\n },\n c => {\n output.push(c);\n }\n }\n }\n\n for chr in s.chars().skip(i-25).take(26) {\n\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n output.push(letters.pop().unwrap_or('?'));\n },\n c => {\n output.push(c);\n }\n }\n }\n\n for chr in s.chars().skip(i+1) {\n\n //print 'Z' in the question mark spots after the substring\n match chr {\n '?' => {\n output.push('Z');\n },\n c => {\n output.push(c);\n }\n }\n }\n println!(\"{}\", output);\n return;\n }\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n let mut laschr : Vec = vec![];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for (i, ch) in s.chars().enumerate() {\n laschr.push(ch);\n\n match ch {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 26 {\n match laschr.remove(0) {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string.\n if count + wildcd >= 26 {\n\n\n for chr in s.chars().take(i-25) {\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"A\");\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n\n for chr in s.chars().skip(i-25).take(26) {\n\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"{}\", letters.pop().unwrap_or('?'));\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n\n for chr in s.chars().skip(i+1) {\n\n //print missing letters in the question mark spots\n match chr {\n '?' => {\n print!(\"A\");\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n println!(\"\");\n return;\n }\n\n }\n\n println!(\"-1\");\n}"}, {"source_code": "use std::io::prelude::*;\nuse std::io;\n\nfn main() {\n let stdin = io::stdin();\n let mut s = stdin.lock().lines().next().unwrap().unwrap();\n\n is_nice_word(&s);\n}\n\nfn is_nice_word(s: &String) {\n\n // list of the last position each letter A-Z was seen\n let mut laspos = [-1i32; 26];\n //how many wildcards '?' there were in the last 26 characters\n let mut wildcd = 0;\n\n for i in 0..(s.len()) {\n match s.chars().skip(i).next().unwrap() {\n '?' => {\n wildcd += 1;\n },\n chr => {\n laspos[((chr as u8) - ('A' as u8)) as usize] = i as i32;\n }\n }\n\n if i > 26 {\n match s.chars().skip(i-26).next().unwrap() {\n '?' => {\n wildcd -= 1;\n },\n _ => ()\n }\n }\n\n // count how many letters occur in the last 26 characters and remember the ones that didn't\n // also keep track of how many wildcards we have seen\n let mut count = 0;\n let mut letters : Vec= vec![];\n for j in 0..26 {\n if laspos[j] != -1 && i - (laspos[j] as usize) < 26 {\n count += 1;\n } else {\n letters.push((('A' as u8) + j as u8) as char);\n }\n }\n \n //If we have seen enough characters and wildcards, print out the string.\n if count + wildcd >= 26 {\n for chr in s.chars().skip(i-25).take(26) {\n match chr {\n '?' => {\n print!(\"{}\", letters.pop().unwrap_or('?'));\n },\n c => {\n print!(\"{}\", c);\n }\n }\n }\n println!(\"\");\n return;\n }\n\n\n }\n\n println!(\"-1\");\n}"}, {"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 next(&mut self) -> T {\n\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 let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn main() {\n let mut s = Scanner::new();\n let input = s.next::();\n let mut set = [0; 27];\n let mut count = 0;\n let mut left = 0;\n let mut right = 26;\n\n for i in input.chars().take(26) {\n let k = i as usize;\n let b = 'A' as usize;\n if i == '?' {\n count += 1;\n set[26] += 1;\n } else {\n if set[k - b] == 0 {\n count += 1;\n }\n set[k - b] += 1;\n }\n }\n\n let mut ans : String = input[left..right].to_string();\n\n let mut tail = input.chars().nth(1).unwrap() as usize;\n for i in input.chars().skip(26) {\n let k = i as usize;\n let b = 'A' as usize;\n\n if count == 26 {\n ans = input[left..right].to_string();\n break;\n }\n\n if tail == '?' as usize {\n set[26] -= 1;\n count -= 1;\n } else {\n set[tail - b] -= 1;\n if set[tail - b] == 0 {\n count -= 1;\n }\n }\n\n if i == '?' {\n count += 1;\n set[26] += 1;\n } else {\n if set[k - b] == 0 {\n count += 1;\n }\n set[k - b] += 1;\n }\n\n tail = k;\n left += 1;\n right += 1;\n }\n\n let mut filled : String = String::new();\n\n for i in ans.chars() {\n let b = 'A' as u8;\n if i == '?' {\n for j in 0..27 {\n if set[j] == 0 {\n let k = j as u8;\n filled.push((k + b) as char);\n set[j] = 1;\n break;\n }\n }\n } else {\n filled.push(i);\n }\n }\n\n if count == 26 {\n println!(\"{}\", filled);\n } else {\n println!(\"-1\");\n }\n}\n"}, {"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 next(&mut self) -> T {\n\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 let front = self.buffer.pop_front().unwrap();\n front.parse::().ok().unwrap()\n }\n}\n\nfn main() {\n let mut s = Scanner::new();\n let input = s.next::();\n let mut set = [0; 27];\n let mut count = 0;\n let mut left = 0;\n let mut right = 26;\n\n for i in input.chars().take(26) {\n let k = i as usize;\n let b = 'A' as usize;\n if i == '?' {\n count += 1;\n set[26] += 1;\n } else {\n if set[k - b] == 0 {\n count += 1;\n }\n set[k - b] += 1;\n }\n }\n\n let mut tail = input.chars().nth(left).unwrap() as usize;\n for i in input.chars().skip(26) {\n let k = i as usize;\n let b = 'A' as usize;\n\n if count == 26 {\n break;\n }\n\n if tail == '?' as usize {\n set[26] -= 1;\n count -= 1;\n } else {\n set[tail - b] -= 1;\n if set[tail - b] == 0 {\n count -= 1;\n }\n }\n\n if i == '?' {\n count += 1;\n set[26] += 1;\n } else {\n if set[k - b] == 0 {\n count += 1;\n }\n set[k - b] += 1;\n }\n\n left += 1;\n right += 1;\n tail = input.chars().nth(left).unwrap() as usize;\n }\n\n let mut filled : String = String::new();\n\n if count == 26 {\n for i in input.chars().take(left) {\n if i == '?' {\n filled.push('A');\n } else {\n filled.push(i);\n }\n }\n\n for i in input.chars().skip(left).take(right) {\n let b = 'A' as u8;\n if i == '?' {\n for j in 0..27 {\n if set[j] == 0 {\n let k = j as u8;\n filled.push((k + b) as char);\n set[j] = 1;\n break;\n }\n }\n } else {\n filled.push(i);\n }\n }\n\n for i in input.chars().skip(left + right) {\n if i == '?' {\n filled.push('A');\n } else {\n filled.push(i);\n }\n }\n\n println!(\"{}\", filled);\n } else {\n println!(\"-1\");\n }\n}\n"}], "src_uid": "a249431a4b0b1ade652997fe0b82edf3"} {"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: u64 = it.next().unwrap().parse().unwrap();\n let x: u64 = it.next().unwrap().parse().unwrap();\n let y: u64 = it.next().unwrap().parse().unwrap();\n\n let sum = x + y;\n let answer = if sum > n + 1 {\n Answer::Black\n } else {\n Answer::White\n };\n\n match answer {\n Answer::Black => {\n println!(\"Black\");\n }\n Answer::White => {\n println!(\"White\");\n }\n };\n}\n\nenum Answer {\n Black,\n White,\n}\n", "positive_code": [{"source_code": "fn dist(x:i64,y:i64,x1:i64,y1:i64) -> i64{\n return std::cmp::max((x-x1).abs(), (y-y1).abs());\n}\n\nfn read_line() -> Vec{\n let mut input = String::new();\n std::io::stdin().read_line(&mut input).unwrap();\n return input.trim().split(\" \").map(|x|{x.parse::().unwrap()}).collect();\n}\n\nfn main(){\n let WHITE = \"White\";\n let BLACK = \"Black\";\n let mut line = read_line();\n let n = line[0];\n line = read_line();\n let (x,y) = (line[0],line[1]);\n if dist(1,1,x,y)<=dist(n,n,x,y){\n println!(\"{}\",WHITE);\n }else{\n println!(\"{}\",BLACK);\n }\n}"}, {"source_code": "fn dist(x: i64, y: i64) -> i64 {\n return std::cmp::min(x, y) + (x - y).abs();\n}\n\nfn read_line() -> Vec {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n return buf.trim().split(\" \").map(|x| { x.parse::().unwrap() }).collect();\n}\n\nfn main() {\n let l1 = read_line();\n let l2 = read_line();\n let n: i64 = l1[0];\n let x: i64 = l2[0];\n let y: i64 = l2[1];\n let d1 = dist(x, y);\n let d2 = dist(n - x + 1, n - y + 1);\n if d2 < d1 {\n println!(\"Black\");\n } else {\n println!(\"White\");\n }\n}\n"}], "negative_code": [], "src_uid": "b8ece086b35a36ca873e2edecc674557"} {"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 if n == 1 {\n let s = get();\n println!(\"{}\", s);\n return;\n }\n let s = get().as_bytes();\n let mut zeros = 0;\n for &c in s {\n if c== b'0' {\n zeros += 1;\n }\n }\n print!(\"1\");\n for _ in 0..zeros {\n print!(\"0\");\n }\n println!();\n \n}\n", "positive_code": [{"source_code": "use std::io::*;\nuse std::str::FromStr;\n\nfn main() {\n let stdin = stdin();\n let mut sc = Scanner::new(stdin.lock());\n let n = sc.next::();\n let s = sc.next::();\n let zeros = s.chars().filter(|&c| c == '0').count() as u32;\n let result = std::iter::repeat(\"0\")\n .take(zeros as usize)\n .collect::();\n if n == zeros {\n println!(\"{}\", result);\n } else {\n println!(\"1{}\", result);\n }\n}\n\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n}\n"}], "negative_code": [{"source_code": "use std::io::*;\nuse std::str::FromStr;\n\nfn main() {\n let stdin = stdin();\n let mut sc = Scanner::new(stdin.lock());\n let n = sc.next::();\n let s = sc.next::();\n let zeros = s.chars().filter(|&c| c == '0').count() as u32;\n let result = std::iter::repeat(\"0\")\n .take(zeros as usize)\n .collect::();\n println!(\"1{}\", result);\n}\n\npub struct Scanner {\n reader: B,\n buffer: Vec,\n}\n\nimpl Scanner {\n pub fn new(reader: B) -> Self {\n Self {\n reader,\n buffer: Vec::new(),\n }\n }\n\n pub fn next(&mut self) -> T\n where\n T::Err: ::std::fmt::Debug,\n {\n if let Some(front) = self.buffer.pop() {\n front.parse::().expect(&front)\n } else {\n let mut input = String::new();\n self.reader.read_line(&mut input).expect(\"Line not read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n self.next()\n }\n }\n}\n"}], "src_uid": "ac244791f8b648d672ed3de32ce0074d"} {"source_code": "\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).ok();\n let nk: Vec = s.trim().split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n for m in (1..nk[1]).rev() {\n if nk[0] % m == 0 {\n let x = (nk[0] / m) * nk[1] + m;\n println!(\"{}\", x);\n break;\n }\n } \n}", "positive_code": [{"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 main() {\n input! {\n n: i64,\n k: i64,\n }\n let mut res = None;\n for right in 1..k {\n if n % right == 0 {\n let left = n / right;\n let x = left * k + right;\n if res.is_none() || res.unwrap() > x {\n res = Some(x);\n }\n }\n }\n println!(\"{}\", res.unwrap());\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"}, {"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 (result, divider) = readln!(i32, i32);\n\n let mut min = std::i32::MAX;\n for right in 1..divider {\n if result % right == 0 {\n let x = right + divider * result / right;\n if x < min {\n min = x;\n }\n }\n }\n\n println!(\"{}\", min);\n}\n"}, {"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 mut buffer_iter = buffer.split_whitespace().map(|n| n.parse::().unwrap());\n let n = buffer_iter.next().unwrap();\n let k = buffer_iter.next().unwrap();\n\n let md = (1..k).rev().find(|x| n % x == 0).unwrap();\n println!(\"{}\", (n / md) * k + md);\n}"}], "negative_code": [{"source_code": "\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).ok();\n let nk: Vec = s.trim().split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n let m = nk[0] * nk[1] + 1;\n for x in 1..m {\n let y = x - x % nk[1];\n if (y / nk[1]) * (x % nk[1]) == nk[0] {\n println!(\"{}\", x);\n break;\n }\n } \n}"}, {"source_code": "\nfn main() {\n let mut s = String::new();\n std::io::stdin().read_line(&mut s).ok();\n let nk: Vec = s.trim().split_whitespace()\n .map(|x| x.parse().unwrap())\n .collect();\n for x in 1..10000001 {\n if (x/nk[1])*(x%nk[1]) == nk[0] {\n println!(\"{}\", x);\n break;\n }\n } \n}"}], "src_uid": "ed0ebc1e484fcaea875355b5b7944c57"} {"source_code": "use std::io::stdin;\nuse std::isize;\nfn main() {\n let (x,y) = parse_input();\n let abs_x = x.abs();\n let abs_y = y.abs();\n let a = abs_x+abs_y;\n if abs_x == x && abs_y == y{\n print(0,a ,a,0)\n }else if abs_x != x && abs_y !=y{\n print(-a,0,0,-a)\n }else if abs_x !=x {\n print(-a,0,0,a)\n }else{\n print(0,-a,a,0)\n }\n}\nfn parse_input()->(isize,isize){\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let v:Vec = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();\n (v[0],v[1])\n}\nfn print(a:isize,b:isize,c:isize,d:isize){\n println!(\"{} {} {} {}\",a,b,c,d)\n}", "positive_code": [{"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 x: isize = scan.next();\n let y: isize = scan.next();\n let val = x.abs() + y.abs();\n let first = (0, val * y.signum());\n let second = (val * x.signum(), 0);\n let min = first.min(second);\n let max = first.max(second);\n println!(\"{} {} {} {}\", min.0, min.1, max.0, max.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"}], "negative_code": [{"source_code": "use std::io::stdin;\nuse std::isize;\nfn main() {\n let (x,y) = parse_input();\n let abs_x = x.abs();\n let abs_y = y.abs();\n let a = abs_x+abs_y;\n if abs_x == x && abs_y == y{\n print(0,a ,a,0)\n }else if abs_x != x && abs_y !=y{\n print(-a,0,0,a)\n }else if abs_x !=x {\n print(-a,0,0,a)\n }else{\n print(0,-a,a,0)\n }\n}\nfn parse_input()->(isize,isize){\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let v:Vec = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();\n (v[0],v[1])\n}\nfn print(a:isize,b:isize,c:isize,d:isize){\n println!(\"{} {} {} {}\",a,b,c,d)\n}"}, {"source_code": "use std::io::stdin;\nfn main() {\n let (x,y) = parse_input();\n let abs_x = x.abs();\n let abs_y = y.abs();\n let a = abs_x+abs_y;\n if abs_x == x && abs_y == y{\n println!(\"{} {} {} {}\",0,a ,a,0)\n }else if abs_x != x && abs_y !=y{\n println!(\"{} {} {} {}\",-a,0,0,a)\n }else if abs_x !=x {\n println!(\"{} {} {} {}\",-a,0,0,a)\n }else{\n println!(\"{} {} {} {}\",0,-a,a,0)\n }\n}\nfn parse_input()->(isize,isize){\n let mut input = String::new();\n stdin().read_line(&mut input).unwrap();\n let v:Vec = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();\n (v[0],v[1])\n}"}], "src_uid": "e2f15a9d9593eec2e19be3140a847712"} {"source_code": "use std::io;\n\nfn get_line() -> String {\n\tlet mut input = String::new();\n\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"\");\n\n\tString::from(input.trim())\n}\n\nfn main() {\n\tlet s = get_line();\n\tlet t = get_line();\n\n\tlet mut l = String::new();\n\tlet mut r = String::new();\n\n\tlet mut k = 0usize;\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif c == '|' {\n\t\t\tk = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif i == k {\n\t\t\tbreak;\n\t\t}\n\t\tl.push(c);\n\t}\n\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif i <= k {\n\t\t\tcontinue;\n\t\t}\n\t\tr.push(c);\n\t}\n\n\tfor c in t.chars() {\n\t\tif l.len() < r.len() {\n\t\t\tl.push(c);\n\t\t} else {\n\t\t\tr.push(c);\n\t\t}\n\t}\n\n\tif l.len() != r.len() {\n\t\tprintln!(\"Impossible\");\n\t} else {\n\t\tprintln!(\"{}|{}\", l, r);\n\t}\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\n}", "positive_code": [{"source_code": "//! http://codeforces.com/contest/382/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 scanln!(scale: String);\n scanln!(weights: String);\n let mut pans = scale.split('|');\n let pan1 = pans.next().unwrap();\n let pan2 = pans.next().unwrap();\n let diff = std::cmp::max(pan1.len(), pan2.len()) - std::cmp::min(pan1.len(), pan2.len());\n let common = weights.len() as i32 - diff as i32;\n if common >= 0 && common % 2 == 0 {\n let (less, more) = weights.as_bytes().split_at((weights.len() - diff) / 2);\n let (front, back) = if pan1.len() > pan2.len() { (less, more) } else { (more, less) };\n for c in front.iter().map(|&b| b as char).chain(pan1.chars()) {\n print!(\"{}\", c);\n }\n print!(\"|\");\n for c in back.iter().map(|&b| b as char).chain(pan2.chars()) {\n print!(\"{}\", c);\n }\n println!(\"\");\n } else {\n println!(\"Impossible\");\n }\n}\n"}], "negative_code": [{"source_code": "use std::io;\n\nfn get_line() -> String {\n\tlet mut input = String::new();\n\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"\");\n\n\tString::from(input.trim())\n}\n\nfn main() {\n\tlet s = get_line();\n\tlet t = get_line();\n\n\tlet mut k = 0usize;\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif c == '|' {\n\t\t\tk = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tlet mut l = String::new();\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif i == k {\n\t\t\tbreak;\n\t\t}\n\n\t\tl.push(c);\n\t}\n\n\tlet mut r = String::new();\n\tfor (j, d) in s.chars().enumerate() {\n\t\tif j <= k {\n\t\t\tcontinue;\n\t\t}\n\n\t\tr.push(d);\n\t}\n\n\tif (t.len() + l.len() + r.len())%2 != 0 {\n\t\tprintln!(\"Impossible\");\n\t\treturn;\n\t}\n\n\n\tif l.len() == 0 {\n\t\tl.push_str(&t);\n\t} else if r.len() == 0 {\n\t\tr.push_str(&t);\n\t} else {\n\t\tlet mut f = if l.len() < r.len() { true } else { false };\n \tfor c in t.chars() {\n\t\t\tif f {\n\t\t\t\tl.push(c);\n\t\t\t\tf = false;\n\t\t\t} else {\n\t\t\t\tr.push(c);\n\t\t\t\tf = true;\n\t\t\t}\n\t\t}\n\t}\n\tprintln!(\"{}|{}\", l, r);\n}"}, {"source_code": "use std::io;\n\nfn get_line() -> String {\n\tlet mut input = String::new();\n\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"\");\n\n\tString::from(input.trim())\n}\n\nfn main() {\n\tlet s = get_line();\n\tlet t = get_line();\n\n\tlet mut k = 0usize;\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif c == '|' {\n\t\t\tk = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tlet mut l = String::new();\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif i == k {\n\t\t\tbreak;\n\t\t}\n\n\t\tl.push(c);\n\t}\n\n\tlet mut r = String::new();\n\tfor (j, d) in s.chars().enumerate() {\n\t\tif j <= k {\n\t\t\tcontinue;\n\t\t}\n\n\t\tr.push(d);\n\t}\n\n\tlet d = if l.len() < r.len() { r.len()-r.len() } else { l.len()-r.len() };\n\n\tif (t.len() + l.len() + r.len())%2 != 0 || d > t.len() {\n\t\tprintln!(\"Impossible\");\n\t\treturn;\n\t}\n\n\n\tif l.len() == 0 {\n\t\tl.push_str(&t);\n\t} else if r.len() == 0 {\n\t\tr.push_str(&t);\n\t} else {\n\t\tlet mut f = if l.len() < r.len() { true } else { false };\n \tfor c in t.chars() {\n\t\t\tif f {\n\t\t\t\tl.push(c);\n\t\t\t\tf = false;\n\t\t\t} else {\n\t\t\t\tr.push(c);\n\t\t\t\tf = true;\n\t\t\t}\n\t\t}\n\t}\n\tprintln!(\"{}|{}\", l, r);\n}"}, {"source_code": "use std::io;\n\nfn get_line() -> String {\n\tlet mut input = String::new();\n\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"\");\n\n\tString::from(input.trim())\n}\n\nfn main() {\n\tlet s = get_line();\n\tlet t = get_line();\n\n\tlet mut k = 0usize;\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif c == '|' {\n\t\t\tk = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tlet mut l = String::new();\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif i == k {\n\t\t\tbreak;\n\t\t}\n\n\t\tl.push(c);\n\t}\n\n\tlet mut r = String::new();\n\tfor (j, d) in s.chars().enumerate() {\n\t\tif j <= k {\n\t\t\tcontinue;\n\t\t}\n\n\t\tr.push(d);\n\t}\n\n\tlet d = if l.len() < r.len() { r.len()-s.len() } else { l.len()-r.len() };\n\n\tif (t.len() + l.len() + r.len())%2 != 0 || d > t.len() {\n\t\tprintln!(\"Impossible\");\n\t\treturn;\n\t}\n\n\n\tif l.len() == 0 {\n\t\tl.push_str(&t);\n\t} else if r.len() == 0 {\n\t\tr.push_str(&t);\n\t} else {\n\t\tlet mut f = if l.len() < r.len() { true } else { false };\n \tfor c in t.chars() {\n\t\t\tif f {\n\t\t\t\tl.push(c);\n\t\t\t\tf = false;\n\t\t\t} else {\n\t\t\t\tr.push(c);\n\t\t\t\tf = true;\n\t\t\t}\n\t\t}\n\t}\n\tprintln!(\"{}|{}\", l, r);\n}"}, {"source_code": "use std::io;\n\nfn get_line() -> String {\n\tlet mut input = String::new();\n\n\tio::stdin().read_line(&mut input)\n\t\t.expect(\"\");\n\n\tString::from(input.trim())\n}\n\nfn main() {\n\tlet s = get_line();\n\tlet t = get_line();\n\n\tlet mut k = 0usize;\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif c == '|' {\n\t\t\tk = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\t\n\tlet mut l = String::new();\n\tfor (i, c) in s.chars().enumerate() {\n\t\tif i == k {\n\t\t\tbreak;\n\t\t}\n\n\t\tl.push(c);\n\t}\n\n\tlet mut r = String::new();\n\tfor (j, d) in s.chars().enumerate() {\n\t\tif j <= k {\n\t\t\tcontinue;\n\t\t}\n\n\t\tr.push(d);\n\t}\n\n\tlet d = if l.len() < r.len() { r.len()-l.len() } else { l.len()-r.len() };\n\n\tif d == 0 {\n\t \tif t.len()%2 == 0 {\n\t \t\tlet mut f = true;\n\t \t\tfor c in t.chars() {\n\t \t\t\tif f {\n\t \t\t\t\tl.push(c);\n\t \t\t\t\tf = false;\n\t\t\t\t} else {\n\t\t\t\t\tr.push(c);\n\t\t\t\t\tf = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\tprintln!(\"{}|{}\", l, r);\n\t \t} else {\n\t \t\tprintln!(\"Impossible\");\n\t\t}\n\t} else {\n\t\tif d != t.len() {\n\t\t\tprintln!(\"Impossible\");\n\t\t} else {\n\t\t\tif l.len() < r.len() {\n\t\t\t\tfor c in t.chars() {\n\t\t\t\t\tl.push(c);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tfor c in t.chars() {\n\t\t\t\t\tr.push(c);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tprintln!(\"{}|{}\", l, r);\t\t\t\t\t\t\t\t\t\t\t\t\t\n\t\t}\n\t}\n}"}], "src_uid": "917f173b8523ddd38925238e5d2089b9"} {"source_code": "//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, 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: i64,\n p: i64,\n w: i64,\n d: i64,\n }\n for r in 0..d {\n if p - w * r < 0 || (p - w * r) % d != 0 {\n continue;\n }\n let q = (p - w * r) / (w * d);\n let x = d * q + r;\n let y = (p - w * r) / d - w * q;\n if x + y <= n {\n assert!(x * w + y * d == p);\n let z = n - x - y;\n println!(\"{} {} {}\", x, y, z);\n return;\n }\n }\n println!(\"-1\");\n}\n\nfn main() {\n run();\n}\n", "positive_code": [{"source_code": "use std::io::stdin;\n\nmacro_rules! readln {\n ($type:ty) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().next().unwrap().parse::<$type>().unwrap() }};\n (|$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|it| it.parse::<$type_vec>().unwrap()).collect::>() }};\n ($($type:ty),*) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace(); ($(iter.next().unwrap().parse::<$type>().unwrap(),)*) }};\n ($($type:ty),* |$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n ($(iter.next().unwrap().parse::<$type>().unwrap(),)*iter.map(|it| it.parse::<$type_vec>().unwrap()).collect::>(),)}}\n}\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 main() {\n let (n, p, w, d) = readln!(u64, u64, u64, u64);\n\n let gcd = gcd(w, d);\n let lcm = w * d / gcd;\n let x_count = lcm / w;\n let y_count = lcm / d;\n\n if p % gcd != 0 {\n println!(\"-1\");\n return;\n }\n\n let mut max_x = if p / w < n { p / w } else { n };\n while max_x != 0 && (p - max_x * w) % d != 0 {\n max_x -= 1;\n }\n let y = (p - max_x * w) / d;\n\n if max_x + y > n || max_x * w + y * d < p {\n println!(\"-1\")\n } else {\n println!(\"{} {} {}\", max_x, y, n - max_x - y);\n }\n}"}, {"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 ext_euclid(a: i128, b: i128, x: &mut i128, y: &mut i128) -> i128 {\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 g = ext_euclid(b % a, a, &mut x1, &mut y1);\n *x = y1 - b / a * x1;\n *y = x1;\n return g;\n}\n\nfn solve(writer: &mut std::io::BufWriter) {\n let (n, p, w, d) = parse_line!(i128, i128, i128, i128);\n let mut x = 0;\n let mut y = 0;\n let g = ext_euclid(w, d, &mut x, &mut y);\n if p % g != 0 {\n writeln!(writer, \"-1\").unwrap();\n return;\n }\n x *= p / g;\n y *= p / g;\n let step_x = d / g;\n let step_y = w / g;\n if x < 0 {\n let k = (-x + step_x - 1) / step_x;\n x += k * step_x;\n y -= k * step_y;\n }\n if y < 0 {\n let k = (-y + step_y - 1) / step_y;\n x -= k * step_x;\n y += k * step_y;\n }\n if x < 0 {\n writeln!(writer, \"-1\").unwrap();\n return;\n }\n let k = x / step_x;\n x -= k * step_x;\n y += k * step_y;\n if x + y <= n {\n writeln!(writer, \"{} {} {}\", x, y, n - x - y).unwrap();\n return;\n }\n let k = y / step_y;\n x += k * step_x;\n y -= k * step_y;\n if x + y <= n {\n writeln!(writer, \"{} {} {}\", x, y, n - x - y).unwrap();\n return;\n }\n writeln!(writer, \"-1\").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"}, {"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! 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\n// Extended Euclidean GCD {{{\nfn extended_euclid(a: i64, b: i64) -> (i64,i64,i64) {\n\tif b == 0 {\n\t\t(a,1,0)\n\t} else {\n\t\tlet q = div_floor(a,b);\n\t\tlet r = a - q*b;\n\t\tlet (d,x,y) = extended_euclid(b, r);\n\t\t(d, y, x-q*y)\n\t}\n}//}}}\nfn div_floor(a: i64, b: i64) -> i64 {\n\tassert!(b != 0);\n\tlet (a,b) = if b < 0 {(-a,-b)} else {(a,b)};\n\tif a % b == 0 || a >= 0 {\n\t\ta / b\n\t} else {\n\t\ta / b - 1\n\t}\n}\nfn div_ceil(a: i64, b: i64) -> i64 {\n\tassert!(b != 0);\n\tlet (a,b) = if b < 0 {(-a,-b)} else {(a,b)};\n\tif a % b == 0 || a <= 0 {\n\t\ta / b\n\t} else {\n\t\ta / b + 1\n\t}\n}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tl!(n,p,a,b = rin.l());\n\tlet (g,x0,y0) = extended_euclid(a,b);\n\tif p % g == 0 {\n\t\tl!(mut x,y = 0);\n\t\tlet mut e = p / g;\n\t\tlet mut ee = Vec::new();\n\t\twhile e > 0 {\n\t\t\tee.push(e % 10);\n\t\t\te /= 10;\n\t\t}\n\t\tee.reverse();\n\t\tfor e in ee {\n\t\t\t// writeln!(rout, \"g {} x0 {} y0 {} : e {}\", g, x0, y0, e).ok();\n\t\t\tx = x * 10 + x0 * e;\n\t\t\ty = y * 10 + y0 * e;\n\t\t\tlet ca = -b / g;\n\t\t\tlet cb = a / g;\n\t\t\tlet kx0 = div_ceil(n - x, ca);\n\t\t\tlet kx1 = div_floor(-x, ca);\n\t\t\tlet ky0 = div_ceil(-y, cb);\n\t\t\tlet ky1 = div_floor(n - y, cb);\n\t\t\tlet k0 = kx0.max(ky0);\n\t\t\tlet k1 = kx1.min(ky1);\n\t\t\tif k0 <= k1 {\n\t\t\t\tx += k0 * ca;\n\t\t\t\ty += k0 * cb;\n\t\t\t}\n\t\t}\n\t\tif x.min(y) >= 0 && x + y <= n {\n\t\t\twriteln!(rout, \"{} {} {}\", x, y, n - x - y).ok();\n\t\t\treturn;\n\t\t}\n\t}\n\twriteln!(rout, \"-1\").ok();\n}\n\n"}, {"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! 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!(n,p,a,b = rin.l());\n\tfor y in 0..a {\n\t\tif (p - b*y) % a == 0 {\n\t\t\tlet x = (p - b*y) / a;\n\t\t\tif x >= 0 && x + y <= n {\n\t\t\t\twriteln!(rout, \"{} {} {}\", x, y, n - x - y).ok();\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\t}\n\twriteln!(rout, \"-1\").ok();\n}\n\n"}, {"source_code": "mod io {\n use std::io::{self, BufRead};\n use std::str::{self, FromStr, SplitAsciiWhitespace};\n use super::Result;\n\n pub struct Scanner<'a, R> {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'a>,\n }\n\n impl Scanner<'_, R> {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn token(&mut self) -> Result\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return Ok(token.parse()?);\n }\n self.buf_str.clear();\n let bytes_read = self.reader\n .read_until(b'\\n', &mut self.buf_str)?;\n if bytes_read == 0 {\n return Err(Box::new(io::Error::from(io::ErrorKind::UnexpectedEof)));\n }\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\nuse std::io::{stdin, stdout, BufRead, Write};\nuse io::Scanner;\n\npub type Result = std::result::Result>;\n\nfn main() -> Result<()> {\n let stdin = stdin();\n solve(Scanner::new(stdin.lock()), stdout().lock())\n}\n\nfn solve(mut scan: Scanner, mut out: W) -> Result<()> {\n let (n, mut p, mut w, mut d) =\n (scan.token::()?, scan.token::()?, scan.token::()?, scan.token::()?);\n let (g, ..) = ext_euclid(w, d);\n if p % g != 0 {\n writeln!(out, \"-1\")?;\n return Ok(());\n }\n p /= g;\n w /= g;\n d /= g;\n let y = p % w * inv(d, w) % w;\n let x = (p - d * y) / w;\n if x < 0 || x + y > n {\n writeln!(out, \"-1\")?;\n return Ok(());\n }\n let z = n - x - y;\n writeln!(out, \"{} {} {}\", x, y, z)?;\n Ok(())\n}\n\npub fn ext_euclid(a: i64, b: i64) -> (i64, i64, i64) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d, x, y) = ext_euclid(b, a % b);\n (d, y, x - a / b * y)\n }\n}\n\nfn inv(a: i64, n: i64) -> i64 {\n let (_, x, ..) = ext_euclid(a, n);\n (n + x) % n\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n\n macro_rules! t {\n ( $inp:expr, $expected:expr ) => {\n let mut out = String::new();\n solve(Scanner::new($inp.as_bytes()), unsafe { out.as_mut_vec() }).unwrap();\n assert_eq!(out, $expected);\n };\n }\n\n #[test]\n fn example1() {\n //t!(\"30 60 3 1\\n\", \"17 9 4\\n\");\n t!(\"30 60 3 1\\n\", \"20 0 10\\n\");\n }\n\n #[test]\n fn example2() {\n t!(\"10 51 5 4\\n\", \"-1\\n\");\n }\n\n #[test]\n fn example3() {\n t!(\"20 0 15 5\\n\", \"0 0 20\\n\");\n }\n\n #[test]\n fn t() {\n t!(\"4 7 3 2\\n\", \"1 2 1\\n\");\n t!(\"1000000000000 99999999999999999 100000 99999\\n\", \"999999999999 1 0\\n\");\n t!(\"923399641127 50915825165227299 94713 49302\\n\", \"537580105939 11996 385819523192\\n\");\n }\n}"}], "negative_code": [{"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! 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\n// Extended Euclidean GCD {{{\nfn extended_euclid(a: i64, b: i64) -> (i64,i64,i64) {\n\tif b == 0 {\n\t\t(a,1,0)\n\t} else {\n\t\tlet q = div_floor(a,b);\n\t\tlet r = a - q*b;\n\t\tlet (d,x,y) = extended_euclid(b, r);\n\t\t(d, y, x-q*y)\n\t}\n}//}}}\nfn div_floor(a: i64, b: i64) -> i64 {\n\tassert!(b != 0);\n\tlet (a,b) = if b < 0 {(-a,-b)} else {(a,b)};\n\tif a % b == 0 || a >= 0 {\n\t\ta / b\n\t} else {\n\t\ta / b - 1\n\t}\n}\nfn div_ceil(a: i64, b: i64) -> i64 {\n\tassert!(b != 0);\n\tlet (a,b) = if b < 0 {(-a,-b)} else {(a,b)};\n\tif a % b == 0 || a <= 0 {\n\t\ta / b\n\t} else {\n\t\ta / b + 1\n\t}\n}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tl!(n,p,a,b = rin.l());\n\tlet (g,x0,y0) = extended_euclid(a,b);\n\tif p % g == 0 {\n\t\tl!(mut x,y = 0);\n\t\tlet mut e = p / g;\n\t\tlet mut ee = Vec::new();\n\t\twhile e > 0 {\n\t\t\tee.push(e % 10);\n\t\t\te /= 10;\n\t\t}\n\t\tee.reverse();\n\t\tfor e in ee {\n\t\t\t// writeln!(rout, \"g {} x0 {} y0 {} : e {}\", g, x0, y0, e).ok();\n\t\t\tx = x * 10 + x0 * e;\n\t\t\ty = y * 10 + y0 * e;\n\t\t\tlet ca = -b / g;\n\t\t\tlet cb = a / g;\n\t\t\tlet kx0 = div_ceil(n - x, ca);\n\t\t\tlet kx1 = div_floor(-x, ca);\n\t\t\tlet ky0 = div_ceil(-y, cb);\n\t\t\tlet ky1 = div_floor(n - y, cb);\n\t\t\tlet k0 = kx0.max(ky0);\n\t\t\tlet k1 = kx1.min(ky1);\n\t\t\tif k0 <= k1 {\n\t\t\t\tx += k0 * ca;\n\t\t\t\ty += k0 * cb;\n\t\t\t}\n\t\t}\n\t\tif x + y <= n {\n\t\t\twriteln!(rout, \"{} {} {}\", x, y, n - x - y).ok();\n\t\t\treturn;\n\t\t}\n\t}\n\twriteln!(rout, \"-1\").ok();\n}\n\n"}, {"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! 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\n// Extended Euclidean GCD {{{\nfn extended_euclid(a: i64, b: i64) -> (i64,i64,i64) {\n\tif b == 0 {\n\t\t(a,1,0)\n\t} else {\n\t\tlet q = div_floor(a,b);\n\t\tlet r = a - q*b;\n\t\tlet (d,x,y) = extended_euclid(b, r);\n\t\t(d, y, x-q*y)\n\t}\n}//}}}\nfn div_floor(a: i64, b: i64) -> i64 {\n\tassert!(b != 0);\n\tlet (a,b) = if b < 0 {(-a,-b)} else {(a,b)};\n\tif a % b == 0 || a >= 0 {\n\t\ta / b\n\t} else {\n\t\ta / b - 1\n\t}\n}\nfn div_ceil(a: i64, b: i64) -> i64 {\n\tassert!(b != 0);\n\tlet (a,b) = if b < 0 {(-a,-b)} else {(a,b)};\n\tif a % b == 0 || a <= 0 {\n\t\ta / b\n\t} else {\n\t\ta / b + 1\n\t}\n}\n\nfn main() {\n\tlet mut rin = reader();\n\tlet mut rout = writer();\n\n\tl!(n,p,a,b = rin.l());\n\tlet (g,x0,y0) = extended_euclid(a,b);\n\tif p % g == 0 {\n\t\tlet e = p / g;\n\t\tlet x = x0 * e;\n\t\tlet y = y0 * e;\n\t\tlet ca = -b / g;\n\t\tlet cb = a / g;\n\t\tlet kx0 = div_ceil(n - x, ca);\n\t\tlet kx1 = div_floor(-x, ca);\n\t\tlet ky0 = div_ceil(-y, cb);\n\t\tlet ky1 = div_floor(n - y, cb);\n\t\tlet k0 = kx0.max(ky0);\n\t\tlet k1 = kx1.min(ky1);\n\t\tif k0 <= k1 {\n\t\t\tfor k in vec![k0,k1] {\n\t\t\t\tlet xx = x + k * ca;\n\t\t\t\tlet yy = y + k * cb;\n\t\t\t\tif xx + yy <= n {\n\t\t\t\t\twriteln!(rout, \"{} {} {}\", xx, yy, n - xx - yy).ok();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\twriteln!(rout, \"-1\").ok();\n}\n\n"}, {"source_code": "mod io {\n use std::io::{self, BufRead};\n use std::str::{self, FromStr, SplitAsciiWhitespace};\n use super::Result;\n\n pub struct Scanner<'a, R> {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'a>,\n }\n\n impl Scanner<'_, R> {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn token(&mut self) -> Result\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return Ok(token.parse()?);\n }\n self.buf_str.clear();\n let bytes_read = self.reader\n .read_until(b'\\n', &mut self.buf_str)?;\n if bytes_read == 0 {\n return Err(Box::new(io::Error::from(io::ErrorKind::UnexpectedEof)));\n }\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\nuse std::io::{stdin, stdout, BufRead, Write};\nuse io::Scanner;\n\npub type Result = std::result::Result>;\n\nfn main() -> Result<()> {\n let stdin = stdin();\n solve(Scanner::new(stdin.lock()), stdout().lock())\n}\n\nfn solve(mut scan: Scanner, mut out: W) -> Result<()> {\n let (n, mut p, mut w, mut d) =\n (scan.token::()?, scan.token::()?, scan.token::()?, scan.token::()?);\n let g = gcd(w, d);\n p /= g;\n let rem_p = p % g;\n if rem_p != 0 {\n writeln!(out, \"-1\")?;\n return Ok(());\n }\n w /= g;\n d /= g;\n let y = p * mpow(d, w - 2, w) % w;\n let x = (p - d * y) / w;\n if x + y > n {\n writeln!(out, \"-1\")?;\n return Ok(());\n }\n let z = n - x - y;\n writeln!(out, \"{} {} {}\", x, y, z)?;\n Ok(())\n}\n\nfn gcd(mut a: u64, mut b: u64) -> u64 {\n while a != b {\n if a > b { a = a - b; } else { b = b - a; }\n }\n a\n}\n\npub fn mpow(mut base: u64, mut exp: u64, m: u64) -> u64 {\n let mut result = 1;\n base %= m;\n while exp > 1 {\n if exp & 1 == 1 {\n result = (result * base) % m;\n }\n exp >>= 1;\n base = (base * base) % m;\n }\n if exp == 1 {\n result = (result * base) % m;\n }\n result\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n\n macro_rules! t {\n ( $inp:expr, $expected:expr ) => {\n let mut out = String::new();\n solve(Scanner::new($inp.as_bytes()), unsafe { out.as_mut_vec() }).unwrap();\n assert_eq!(out, $expected);\n };\n }\n\n #[test]\n fn example1() {\n //t!(\"30 60 3 1\\n\", \"17 9 4\\n\");\n t!(\"30 60 3 1\\n\", \"20 0 10\\n\");\n }\n\n #[test]\n fn example2() {\n t!(\"10 51 5 4\\n\", \"-1\\n\");\n }\n\n #[test]\n fn example3() {\n t!(\"20 0 15 5\\n\", \"0 0 20\\n\");\n }\n\n #[test]\n fn t() {\n t!(\"4 7 3 2\\n\", \"1 2 1\\n\");\n }\n}\n"}, {"source_code": "mod io {\n use std::io::{self, BufRead};\n use std::str::{self, FromStr, SplitAsciiWhitespace};\n use super::Result;\n\n pub struct Scanner<'a, R> {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'a>,\n }\n\n impl Scanner<'_, R> {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn token(&mut self) -> Result\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return Ok(token.parse()?);\n }\n self.buf_str.clear();\n let bytes_read = self.reader\n .read_until(b'\\n', &mut self.buf_str)?;\n if bytes_read == 0 {\n return Err(Box::new(io::Error::from(io::ErrorKind::UnexpectedEof)));\n }\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\nuse std::io::{stdin, stdout, BufRead, Write};\nuse io::Scanner;\n\npub type Result = std::result::Result>;\n\nfn main() -> Result<()> {\n let stdin = stdin();\n solve(Scanner::new(stdin.lock()), stdout().lock())\n}\n\nfn solve(mut scan: Scanner, mut out: W) -> Result<()> {\n let (n, mut p, mut w, mut d) =\n (scan.token::()?, scan.token::()?, scan.token::()?, scan.token::()?);\n let (g, ..) = ext_euclid(w, d);\n p /= g;\n if p % g != 0 {\n writeln!(out, \"-1\")?;\n return Ok(());\n }\n w /= g;\n d /= g;\n let y = p % w * inv(d, w) % w;\n let x = (p - d * y) / w;\n if x < 0 || x + y > n {\n writeln!(out, \"-1\")?;\n return Ok(());\n }\n let z = n - x - y;\n writeln!(out, \"{} {} {}\", x, y, z)?;\n Ok(())\n}\n\npub fn ext_euclid(a: i64, b: i64) -> (i64, i64, i64) {\n if b == 0 {\n (a, 1, 0)\n } else {\n let (d, x, y) = ext_euclid(b, a % b);\n (d, y, x - a / b * y)\n }\n}\n\nfn inv(a: i64, n: i64) -> i64 {\n let (_, x, ..) = ext_euclid(a, n);\n (n + x) % n\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n\n macro_rules! t {\n ( $inp:expr, $expected:expr ) => {\n let mut out = String::new();\n solve(Scanner::new($inp.as_bytes()), unsafe { out.as_mut_vec() }).unwrap();\n assert_eq!(out, $expected);\n };\n }\n\n #[test]\n fn example1() {\n //t!(\"30 60 3 1\\n\", \"17 9 4\\n\");\n t!(\"30 60 3 1\\n\", \"20 0 10\\n\");\n }\n\n #[test]\n fn example2() {\n t!(\"10 51 5 4\\n\", \"-1\\n\");\n }\n\n #[test]\n fn example3() {\n t!(\"20 0 15 5\\n\", \"0 0 20\\n\");\n }\n\n #[test]\n fn t() {\n t!(\"4 7 3 2\\n\", \"1 2 1\\n\");\n t!(\"1000000000000 99999999999999999 100000 99999\\n\", \"999999999999 1 0\\n\");\n }\n}"}, {"source_code": "use std::io::stdin;\n\nmacro_rules! readln {\n ($type:ty) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().next().unwrap().parse::<$type>().unwrap() }};\n (|$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|it| it.parse::<$type_vec>().unwrap()).collect::>() }};\n ($($type:ty),*) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace(); ($(iter.next().unwrap().parse::<$type>().unwrap(),)*) }};\n ($($type:ty),* |$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n ($(iter.next().unwrap().parse::<$type>().unwrap(),)*iter.map(|it| it.parse::<$type_vec>().unwrap()).collect::>(),)}}\n}\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 main() {\n let (n, p, w, d) = readln!(u64, u64, u64, u64);\n\n let gcd = gcd(w, d);\n let lcm = w * d / gcd;\n let x_count = lcm / w;\n let y_count = lcm / d;\n\n if p % gcd != 0 {\n println!(\"-1\");\n return;\n }\n\n let mut max_x = if p / w < n { p / w } else { n };\n while (p - max_x * w) % d != 0 {\n max_x -= 1;\n }\n let y = (p - max_x * w) / d;\n\n if max_x + y > n || max_x * w + y * d < p {\n println!(\"-1\")\n } else {\n println!(\"{} {} {}\", max_x, y, n - max_x - y);\n }\n}"}, {"source_code": "use std::io::stdin;\n\nmacro_rules! readln {\n ($type:ty) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().next().unwrap().parse::<$type>().unwrap() }};\n (|$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|it| it.parse::<$type_vec>().unwrap()).collect::>() }};\n ($($type:ty),*) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace(); ($(iter.next().unwrap().parse::<$type>().unwrap(),)*) }};\n ($($type:ty),* |$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n ($(iter.next().unwrap().parse::<$type>().unwrap(),)*iter.map(|it| it.parse::<$type_vec>().unwrap()).collect::>(),)}}\n}\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 main() {\n let (n, p, w, d) = readln!(u64, u64, u64, u64);\n\n let gcd = gcd(w, d);\n let lcm = w * d / gcd;\n let x_count = lcm / w;\n let y_count = lcm / d;\n\n let max_x = if p / w < n { p / w } else { n };\n let mut y = (p - max_x * w) / d;\n let max_x = max_x - y * d;\n\n if max_x + y > n || p % lcm != 0 {\n println!(\"-1\")\n } else {\n for x in (0..=max_x).rev().step_by(x_count as usize) {\n if x * w + y * d != p {\n y += y_count;\n } else {\n println!(\"{} {} {}\", x, y, n - x - y);\n break\n }\n }\n }\n}"}, {"source_code": "use std::io::stdin;\n\nmacro_rules! readln {\n ($type:ty) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().next().unwrap().parse::<$type>().unwrap() }};\n (|$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n line.split_whitespace().map(|it| it.parse::<$type_vec>().unwrap()).collect::>() }};\n ($($type:ty),*) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace(); ($(iter.next().unwrap().parse::<$type>().unwrap(),)*) }};\n ($($type:ty),* |$type_vec:ty|) => {{\n let mut line = String::new();\n stdin().read_line(&mut line).unwrap();\n let mut iter = line.split_whitespace();\n ($(iter.next().unwrap().parse::<$type>().unwrap(),)*iter.map(|it| it.parse::<$type_vec>().unwrap()).collect::>(),)}}\n}\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 main() {\n let (n, p, w, d) = readln!(u64, u64, u64, u64);\n\n let gcd = gcd(w, d);\n let lcm = w * d / gcd;\n let x_count = lcm / w;\n let y_count = lcm / d;\n\n let max_x = if p / w < n { p / w } else { n };\n let mut y = (p - max_x * w) / d;\n let max_x = max_x - y * d;\n\n if max_x + y > n || p % gcd != 0 || max_x * w + y * d < p {\n println!(\"-1\")\n } else {\n println!(\"{} {} {}\", max_x, y, n - max_x - y);\n }\n}"}, {"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 ext_euclid(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 g = ext_euclid(b % a, a, &mut x1, &mut y1);\n *x = y1 - b / a * x1;\n *y = x1;\n return g;\n}\n\nfn solve(writer: &mut std::io::BufWriter) {\n let (n, p, w, d) = parse_line!(i64, i64, i64, i64);\n let mut x = 0;\n let mut y = 0;\n let g = ext_euclid(w, d, &mut x, &mut y);\n if p % g != 0 {\n writeln!(writer, \"-1\").unwrap();\n return;\n }\n x *= p / g;\n y *= p / g;\n let step_x = d / g;\n let step_y = w / g;\n if x < 0 {\n let k = (-x + step_x - 1) / step_x;\n x += k * step_x;\n y -= k * step_y;\n }\n if y < 0 {\n let k = (-y + step_y - 1) / step_y;\n x -= k * step_x;\n y += k * step_y;\n }\n if x < 0 {\n writeln!(writer, \"-1\").unwrap();\n return;\n }\n let k = x / step_x;\n x -= k * step_x;\n y += k * step_y;\n if x + y <= n {\n writeln!(writer, \"{} {} {}\", x, y, n - x - y).unwrap();\n return;\n }\n let k = y / step_y;\n x += k * step_x;\n y -= k * step_y;\n if x + y <= n {\n writeln!(writer, \"{} {} {}\", x, y, n - x - y).unwrap();\n return;\n }\n writeln!(writer, \"-1\").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": "503116e144d19eb953954d99c5526a7d"} {"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: i64,\n v: i64,\n }\n if v>=n-1 {\n return println!(\"{}\", n-1);\n }\n let mut ans = 0;\n for i in 1..(n-v+1) {\n if i == 1 {\n ans += v;\n } else {\n ans += i;\n }\n }\n println!(\"{}\", ans);\n}\n", "positive_code": [{"source_code": "use 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\n let info: Vec = (0..2).map(|_| scan.next()).collect();\n let mut cost = 0;\n let mut tank = 0;\n\n if info[0] - 1 <= info[1] {\n println!(\"{}\", info[0] - 1);\n return;\n }\n\n for i in 0..info[0] - 1 {\n if tank < (info[0] - 1 - i) {\n cost += (info[1] - tank) * (i + 1);\n tank = info[1];\n }\n tank -= 1;\n }\n\n println!(\"{}\", cost);\n}\n"}, {"source_code": "/*input\n97 99\n*/\nfn main() {\n let mut input = format!(\"\");\n std::io::stdin().read_line(&mut input).ok();\n let v: Vec = input\n .trim()\n .split_whitespace()\n .map(|x| x.parse().expect(\"\"))\n .collect();\n if v[0] - 1 <= v[1] {\n println!(\"{}\", v[0] - 1);\n std::process::exit(0);\n }\n let mut money_to_spent = v[1];\n let mut fuel = v[1];\n for i in 1..v[0] {\n if i != 1 {\n fuel = fuel - 1;\n }\n //println!(\"CITY: {} F: {} SISA: {}\", i, fuel, v[0] - i);\n // 1 2 3 4 5 6 7 8 9\n // 2\n if v[0] - i <= fuel {\n break;\n }\n if i != 1 {\n money_to_spent = money_to_spent + i;\n fuel = fuel + 1;\n }\n }\n println!(\"{}\", money_to_spent);\n}\n"}, {"source_code": "#[warn(unused_variables)]\nfn main() {\n let input = input_vec::(\" \");\n let n = input[0];\n let v = input[1];\n\n println!(\"{}\", if (n-1) <= v {n-1} else {(n-v+1)*(n-v)/2 + v-1})\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}"}], "negative_code": [{"source_code": "use 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\n let info: Vec = (0..2).map(|_| scan.next()).collect();\n let mut cost = 0;\n let mut tank = 0;\n\n for i in 0..info[0] - 1 {\n if tank < (info[0] - 1 - i) {\n cost += (info[1] - tank) * (i + 1);\n tank = info[1];\n }\n tank -= 1;\n }\n\n println!(\"{}\", cost);\n}\n"}], "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"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 (n,k) = readln!(i32,i32);\n let a = readvec!(i32);\n let mut res = vec![n as usize;k as usize];\n for i in 0..k {\n for j in 0..n {\n let mut good = true;\n for kk in 0..i {\n if a[res[kk as usize]] == a[j as usize] {\n good = false;\n break;\n }\n }\n if good {\n res[i as usize] = j as usize;\n break;\n }\n }\n if res[i as usize] == n as usize{\n println!(\"NO\");\n return;\n }\n }\n println!(\"YES\");\n println!(\"{}\",res.iter().map(|&x|(x+1).to_string()).collect::>().join(\" \"));\n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn read_vector() -> Vec {\n\tlet mut input = String::new();\n\tio::stdin().read_line(&mut input).expect(\"Reading error\");\n\n\treturn input.split_whitespace().map(|s| s.trim().parse::().unwrap()).collect();\n}\n\nfn new_rank(ranks: &Vec, indexes: &Vec, rank: i32) -> bool {\n\tfor ind in indexes {\n\t\tif ranks[*ind as usize] == rank {\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n}\n\nfn main() {\n\tlet nums = read_vector();\n\tlet team_size = nums[1];\n\n\tlet ranks = read_vector();\n\tlet mut team = Vec::::new();\n\n\tfor tup in ranks.iter().enumerate() {\n\t\tif new_rank(&ranks, &team, *tup.1) {\n\t\t\tteam.push(tup.0 as i32);\n\t\t}\n\t\tif team.len() >= (team_size as usize) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif team.len() >= (team_size as usize) {\n\t\tprintln!(\"YES\");\n\t\tfor rank in team {\n\t\t\tprint!(\"{} \", rank + 1);\n\t\t}\n\t} else {\n\t\tprintln!(\"NO\");\n\t}\n}"}, {"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 = input.u();\n let k = input.u();\n let res = input.vi(n).into_iter().enumerate().map(|(a,b)| (b,a)).collect::>();\n if res.len() < k {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n for x in res.values().take(k) {\n print!(\"{} \", x + 1);\n }\n }\n}\n\n"}, {"source_code": "use std::io;\nuse std::collections::HashMap;\n\nfn main() {\n let mut l1 = String::new();\n let mut l2 = String::new();\n {\n let stdin = io::stdin();\n stdin.read_line(&mut l1).unwrap();\n stdin.read_line(&mut l2).unwrap();\n }\n\n let p: Vec = l1.trim()\n .split(\" \")\n .map(|val| val.parse().unwrap())\n .collect();\n \n let mut k = p[1];\n \n let h: HashMap = l2.trim()\n .split(\" \")\n .map(|val| val.parse().unwrap())\n .enumerate()\n .map(|(a, b)| (b, a))\n .collect();\n \n // println!(\"{:?}\", h);\n // println!(\"k: {}\", k);\n // println!(\"h.len(): {}\", h.len());\n \n if h.len() >= k {\n println!(\"YES\");\n let mut hm_iter = h.iter();\n while k > 1 {\n k -= 1;\n\n print!(\"{} \", hm_iter.next().unwrap().1 + 1);\n }\n println!(\"{}\", hm_iter.next().unwrap().1 + 1);\n } else {\n println!(\"NO\");\n }\n}"}, {"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 k:usize = read();\n let a:Vec = (0..n).map(|_| read()).collect();\n\n let mut f = vec![false;101];\n let mut cnt = 0;\n let mut v = vec![];\n for i in 0..n {\n if !f[a[i] as usize] {\n cnt += 1;\n v.push(i);\n f[a[i] as usize] = true;\n }\n if cnt == k { break; }\n }\n\n if cnt != k { println!(\"NO\"); return; }\n println!(\"YES\");\n for e in v {print!(\"{} \", e+1); } println!();\n\n //}\n}\n\n/*\n\n\n*/\n"}, {"source_code": "use std::collections::HashMap;\n\npub fn main() {\n let mut input = io::Input::new();\n\n let mut map = HashMap::new();\n\n let n = input.next::();\n let k = input.next::();\n\n for i in 1..(n+1) {\n let a = input.next::();\n map.entry(a).or_insert(i);\n if map.len() == k {\n break;\n }\n }\n\n if map.len() == k {\n println!(\"YES\");\n\n let mut v = Vec::new();\n\n for (_, u) in map {\n v.push(u);\n }\n\n v.sort();\n\n for u in v {\n print!(\"{} \", u);\n }\n println!();\n } else {\n println!(\"NO\");\n }\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"}, {"source_code": "use std::collections::HashMap;\nuse std::io;\n\nfn main()\n{\n let mut line1 = String::new();\n let mut line2 = String::new();\n let mut team = HashMap::new();\n\n io::stdin().read_line(&mut line1).unwrap();\n io::stdin().read_line(&mut line2).unwrap();\n let nums: Vec<&str> = line1.trim().split_whitespace().collect();\n let rates: Vec<&str> = line2.trim().split_whitespace().collect();\n\n for i in 0..nums[0].parse().unwrap()\n {\n team.insert(rates[i], i + 1);\n }\n if team.len() < nums[1].parse().unwrap()\n {\n println!(\"{}\", \"NO\");\n return;\n }\n else\n {\n println!(\"{}\", \"YES\");\n }\n\n let mut it = team.iter();\n for _i in 0..nums[1].parse().unwrap()\n {\n if let Some((_, &output)) = it.next()\n {\n print!(\"{} \", output);\n }\n }\n\n print!(\"\\n\");\n}"}, {"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 m: usize = scan.next();\n let mut arr: Vec<(usize, usize)> = vec![];\n let mut result: Vec = vec![];\n for i in 1..=n {\n let current: usize = scan.next();\n arr.push((current, i));\n }\n arr.sort();\n result.push(arr[0].1);\n for i in 1..n {\n if arr[i].0 != arr[i - 1].0 {\n result.push(arr[i].1);\n if result.len() == m {\n break;\n }\n }\n }\n if result.len() < m {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n for &item in result.iter() {\n print!(\"{} \", item);\n }\n println!();\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"}, {"source_code": "use std::collections::BTreeSet;\nuse std::collections::BTreeMap;\nuse std::io;\nuse std::io::Stdin;\nuse std::str::FromStr;\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 parse_t(s : &str) -> T {\n match s.trim().parse() {\n Ok(y) => y,\n Err(_) => panic!(\"Could not read from string!\"),\n }\n}\n\nfn read_ts(stdin : &Stdin, ts : &mut Vec) {\n let mut line = String::new();\n read_line(stdin, &mut line);\n let word_iter = line.split_whitespace();\n for word in word_iter {\n let x = parse_t(word);\n ts.push(x);\n }\n}\n\nfn print_can_form_team(k : usize, ratings : &Vec) {\n let mut rating_index_map = BTreeMap::new();\n let mut index = 1;\n let mut distinct_ratings = BTreeSet::new();\n for rating in ratings {\n distinct_ratings.insert(rating);\n if rating_index_map.contains_key(&rating) {\n // Do nothing ...\n } else {\n rating_index_map.insert(rating, index);\n }\n index = index + 1;\n }\n let num_distinct_ratings = distinct_ratings.len();\n if num_distinct_ratings >= k {\n println!(\"YES\");\n let mut i = 0;\n let mut is_first = true;\n for rating in distinct_ratings {\n if i < k {\n if is_first {\n is_first = false;\n } else {\n print!(\" \");\n }\n print!(\"{}\", rating_index_map.get(rating).unwrap());\n } else {\n break;\n }\n i = i + 1;\n }\n println!();\n } else {\n println!(\"NO\");\n }\n}\n\nfn main() {\n let stdin = io::stdin();\n let mut n_k = vec![];\n read_ts(&stdin, &mut n_k);\n let k = n_k[1];\n let mut ratings = vec![];\n read_ts(&stdin, &mut ratings);\n print_can_form_team(k, &ratings);\n}\n"}, {"source_code": "use std::collections::HashMap;\nuse std::io::{self, BufRead, Write, stdin};\n\nfn main() {\n\n let mut line = String::new();\n stdin().read_line(&mut line).ok();\n let params: Vec = line.split_whitespace().map(|s| s.parse().unwrap()).collect();\n\n let k = params[1];\n\n let mut oline = String::new();\n stdin().read_line(&mut oline).ok();\n let elems: Vec = oline.split_whitespace().map(|s| s.parse().unwrap()).collect();\n\n let mut numbers = HashMap::new();\n for (pos, el) in elems.iter().enumerate() {\n if ! numbers.contains_key(el) {\n numbers.insert(el, pos);\n }\n }\n\n if (numbers.len() as i32) < k {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n let mut i = 1;\n for (_, val) in numbers.iter() {\n if i > k {\n break;\n }\n if i == 1 {\n print!(\"{}\", val + 1);\n } else {\n print!(\" {}\", val + 1);\n }\n i += 1;\n }\n io::stdout().flush().unwrap();\n }\n}\n\n\n \n\n\n\n\n\n\n"}, {"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 = get();\n let k = get();\n let mut hm = HashMap::new();\n for i in 0 .. n {\n let rat: i64 = get();\n hm.insert(rat, i + 1);\n }\n if hm.len() < k {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n let mut it = hm.iter();\n for i in 0 .. k {\n if let Some((_, x)) = it.next() {\n print!(\"{}{}\", x, if i == k - 1 { \"\\n\" } else { \" \" });\n }\n }\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"}], "negative_code": [{"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 m: usize = scan.next();\n let mut arr: Vec<(usize, usize)> = vec![];\n let mut result: Vec = vec![];\n for i in 1..=n {\n let current: usize = scan.next();\n arr.push((current, i));\n }\n arr.sort();\n result.push(arr[0].1);\n for i in 1..n {\n if arr[i].0 != arr[i - 1].0 {\n result.push(arr[i].1);\n if result.len() == m {\n break;\n }\n }\n }\n if result.len() < m {\n println!(\"NO\");\n } else {\n for &item in result.iter() {\n print!(\"{} \", item);\n }\n println!();\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"}, {"source_code": "use std::collections::HashMap;\nuse std::io::{self, BufRead, Write, stdin};\n\nfn main() {\n\n let mut line = String::new();\n stdin().read_line(&mut line).ok();\n let params: Vec = line.split_whitespace().map(|s| s.parse().unwrap()).collect();\n\n let k = params[1];\n\n let mut oline = String::new();\n stdin().read_line(&mut oline).ok();\n let elems: Vec = oline.split_whitespace().map(|s| s.parse().unwrap()).collect();\n\n let mut numbers = HashMap::new();\n for (pos, el) in elems.iter().enumerate() {\n if ! numbers.contains_key(el) {\n numbers.insert(el, pos);\n }\n }\n\n if (numbers.len() as i32) < k {\n println!(\"NO\");\n } else {\n println!(\"YES\");\n let mut i = 1;\n for (_, val) in numbers.iter() {\n if i == 1 {\n print!(\"{}\", val + 1);\n } else {\n print!(\" {}\", val + 1);\n }\n i += 1;\n }\n io::stdout().flush().unwrap();\n }\n}\n\n\n \n\n\n\n\n\n\n"}], "src_uid": "5de6574d57ab04ca195143e08d28d0ad"} {"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\n\nfn main() {\n let mut n: u32 = read_line().parse().unwrap();\n let week = read_line_vec();\n let s: u32 = week.iter().sum();\n \n n = ((n - 1) % s) + 1;\n \n for i in 0..week.len() {\n if n <= week[i] {\n println!(\"{}\", i + 1);\n break;\n }\n n -= week[i];\n }\n \n \n}\n", "positive_code": [{"source_code": "use std::io;\n\nfn raw_input() -> String {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n buf.trim().to_string()\n}\n\nfn input_split() -> Vec {\n raw_input()\n .split_whitespace()\n .map(|elem| elem.parse().unwrap())\n .collect()\n}\n\nfn input() -> u16 {\n raw_input().parse().unwrap()\n}\n\nfn main() {\n let mut n = input();\n let days = input_split();\n\n let week_total: u16 = days.iter().sum();\n while n > week_total {\n n -= week_total;\n }\n\n let mut current_day = 0;\n loop {\n if days[current_day] >= n {\n break;\n } else {\n n -= days[current_day];\n }\n current_day += 1;\n }\n\n print!(\"{}\", current_day + 1);\n}"}, {"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 mut n: u128 = scanner.next();\n let mut week: Vec = (1..=7).map(|_| scanner.next()).collect();\n let mut cur: u128 = 0;\n let mut i: usize = 0;\n while cur < n {\n \tcur += week[i];\n \tif cur >= n {\n \t\tprintln![\"{}\", i+1];\n \t}\n \ti += 1;\n \ti %= 7;\n }\n}"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n //println!(\"total is {}\", total);\n let m = {\n if total > n {\n n\n } else if total == n || n % total == 0 {\n total\n } else {\n n % total\n }\n };\n\n let mut c = 0;\n\n //println!(\"mod is {}\", m);\n for i in 0..days.len() {\n //println!(\"c is {}\", c);\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}], "negative_code": [{"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n //println!(\"total is {}\", total);\n let m = {\n if total > n {\n n % total\n } else if total == n {\n n\n } else {\n n - total\n }\n };\n\n let mut c = 0;\n\n //println!(\"mod is {}\", m);\n for i in 0..days.len() {\n //println!(\"c is {}\", c);\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n //println!(\"total is {}\", total);\n let m = {\n if total > n {\n n\n } else if total == n {\n n\n } else {\n total\n }\n };\n\n let mut c = 0;\n\n //println!(\"mod is {}\", m);\n for i in 0..days.len() {\n //println!(\"c is {}\", c);\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n\n let m = {\n if total == n {\n n\n } else {\n n % total\n }\n };\n\n let mut c = 0;\n for i in 0..days.len() {\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n\n let m = {\n if total > n {\n n % total\n } else if total == n {\n n\n } else {\n total % n\n }\n };\n\n let mut c = 0;\n for i in 0..days.len() {\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n //println!(\"total is {}\", total);\n let m = {\n if total > n {\n total % n\n } else if total == n {\n n\n } else {\n n % total\n }\n };\n\n let mut c = 0;\n\n //println!(\"mod is {}\", m);\n for i in 0..days.len() {\n //println!(\"c is {}\", c);\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n\n let m = {\n if total == n {\n n\n } else {\n n % total\n }\n };\n\n let mut c = 0;\n\n println!(\"mod is {}\", m);\n for i in 0..days.len() {\n println!(\"c is {}\", c);\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "fn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n\n let m = n % total;\n\n let mut c = 0;\n for i in 0..days.len() {\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}, {"source_code": "\nfn main() {\n let n: u32 = get_input().parse().unwrap();\n let days: Vec = get_input().split_ascii_whitespace().map(|v| v.parse().unwrap()).collect();\n let total: u32 = days.iter().sum();\n //println!(\"total is {}\", total);\n let m = {\n if total > n {\n n\n } else if total == n {\n n\n } else {\n n % total\n }\n };\n\n let mut c = 0;\n\n //println!(\"mod is {}\", m);\n for i in 0..days.len() {\n //println!(\"c is {}\", c);\n c += days[i];\n\n if c >= m {\n println!(\"{}\", i+1);\n break;\n }\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"}], "src_uid": "007a779d966e2e9219789d6d9da7002c"} {"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\nconst m:i64 = 1000000007;\n\nfn main() {\n\tlet mut inp = Iinput::default();\n\tlet out = &mut BufWriter::new(stdout());\n\tlet n:usize = inp.scan::();\n\tlet k:i64 = inp.scan::();\n\tlet mut nCr = vec![vec![0 as i64; n + 1]; n + 1];\n\tnCr[0][0] = 1;\n\tfor i in 1..n+1 {\n\t\tfor j in 0..i+1 {\n\t\t\tif j > 0 {\n\t\t\t\tnCr[i][j] += nCr[i - 1][j - 1];\n\t\t\t}\n\t\t\tif j < i {\n\t\t\t\tnCr[i][j] += nCr[i - 1][j];\n\t\t\t}\n\t\t\tnCr[i][j] %= m;\n\t\t}\n\t}\n\tlet mut dp = vec![0; n + 1];\n\tdp[0] = 1;\n\tlet mut pow2 = vec![1 as i64; n + 1];\n\tfor i in 1..n+1 {\n\t\tpow2[i] = pow2[i - 1] * (k - 1) % m;\n\t}\n\tfor _row in 0..n {\n\t\tlet mut tp = vec![0; n + 1];\n\t\tlet mut powa = 1 as i64;\n\t\tfor i in 0..n+1 {\n\t\t\tfor j in i..n+1 {\n\t\t\t\tlet mut val = pow2[n - j] * powa % m;\n\t\t\t\tif i == j {\n\t\t\t\t\tval += m - pow2[n];\n\t\t\t\t}\n\t\t\t\tval = val * nCr[n - i][n - j] % m;\n\t\t\t\ttp[j] = (tp[j] + val * dp[i]) % m;\n\t\t\t}\n\t\t\tpowa = powa * k % m;\n\t\t}\n\t\tdp = tp;\n\t}\n\twriteln!(out, \"{}\", dp[n]);\n}\n\n#[derive(Default)]\nstruct Iinput {\n\tbuffer: Vec\n}\n\nimpl Iinput {\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}", "positive_code": [{"source_code": "mod io {\n use std::io::{self, BufRead};\n use std::str::{self, FromStr, SplitAsciiWhitespace};\n\n pub type Result = std::result::Result>;\n\n pub struct Scanner<'a, R> {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'a>,\n }\n\n impl Scanner<'_, R> {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n pub fn try_token(&mut self) -> Result\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return Ok(token.parse()?);\n }\n self.buf_str.clear();\n let bytes_read = self.reader\n .read_until(b'\\n', &mut self.buf_str)?;\n if bytes_read == 0 {\n return Err(Box::new(io::Error::from(io::ErrorKind::UnexpectedEof)));\n }\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 token(&mut self) -> T\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n self.try_token().unwrap()\n }\n }\n}\n\nuse std::io::{stdin, stdout, BufRead, Write};\nuse io::Scanner;\n\nfn main() {\n let stdin = stdin();\n solve(Scanner::new(stdin.lock()), stdout().lock());\n}\n\nconst M: u64 = 1e9 as u64 + 7;\n\nfn solve(mut scan: Scanner, mut output: W) {\n let n: u64 = scan.token();\n let k: u64 = scan.token();\n let k_1 = k - 1;\n let kp3 = mpow(k_1, n);\n let mut sum = mpow((mpow(k, n) + (M - kp3)) % M, n);\n let mut bcf = 1;\n let mut kp2 = 1;\n for i in 1..=n {\n bcf = (n - i + 1) * mpow(i, M - 2) % M * bcf % M;\n let kp1 = mpow(k, n - i);\n kp2 = kp2 * k_1 % M;\n sum = (sum + mpow(M - 1, i & 1) * bcf % M * mpow((kp1 * kp2 % M + (M - kp3)) % M, n) % M) % M;\n }\n writeln!(output, \"{}\", sum).unwrap();\n}\n\npub fn mpow(mut base: u64, mut exp: u64) -> u64 {\n let mut result = 1;\n while exp > 0 {\n if exp & 1 == 1 {\n result = (result * base) % M;\n }\n exp >>= 1;\n base = (base * base) % M;\n }\n result\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n use helpers::t;\n\n\n #[test]\n fn example1() {\n t!(\"2 2\\n\", \"7\\n\");\n }\n\n #[test]\n fn example2() {\n t!(\"123 456789\\n\", \"689974806\\n\");\n }\n}\n"}, {"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 pub fn comb(n: u32, k: u32) -> ModInt {\n if k > n {\n return ModInt::zero();\n }\n let k = std::cmp::min(k, n - k);\n let mut nu = ModInt::one();\n let mut de = ModInt::one();\n for i in 0..k {\n nu *= ModInt(n - i);\n de *= ModInt(i + 1);\n }\n nu * de.inv()\n }\n}\n\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 ModInt ----------\n//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, 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 k: u32,\n }\n let mut ans = ModInt::zero();\n let pc = Precalc::new(n);\n for i in 0..=n {\n for j in 0..=n {\n let v = (n - i) * (n - j);\n let way = ModInt(k).pow(v as u32) * ModInt(k - 1).pow((n * n - v) as u32);\n ans += ModInt(MOD - 1).pow((i + j) as u32) * pc.comb(n, i) * pc.comb(n, j) * way;\n }\n }\n println!(\"{}\", ans.0);\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "pub struct Scanner {\n buffer: Vec\n}\n\nimpl Scanner {\n pub fn new() -> Scanner {\n Scanner { buffer: Vec::new() }\n }\n\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 std::io::stdin().read_line(&mut input).expect(\"Failed read\");\n self.buffer = input.split_whitespace().rev().map(String::from).collect();\n }\n }\n}\n\nconst MOD: u64 = 1_000_000_007;\n\nfn bin_pow(mut a: u64, mut n: u64) -> u64 {\n let mut x: u64 = 1;\n while n > 0 {\n if (n & 1) == 1 {\n x = x * a % MOD;\n }\n a = a * a % MOD;\n n >>= 1;\n }\n return x;\n}\n\nfn rev(a: u64) -> u64 {\n return bin_pow(a, MOD - 2);\n}\n\n\nfn main() {\n let mut scan = Scanner::new();\n let n: usize = scan.next();\n let x: usize = scan.next();\n\n let mut f: Vec = vec![0; 1000];\n f[0] = 1;\n for i in 1..1000 {\n f[i] = f[i - 1] * (i as u64) % MOD;\n }\n\n let mut rf: Vec = vec![0; 1000];\n for i in 0..1000 {\n rf[i] = rev(f[i]);\n }\n\n let mut px: Vec = vec![0; 1000];\n px[0] = 1;\n for i in 1..1000 {\n px[i] = px[i - 1] * ((x-1) as u64) % MOD;\n }\n\n let c = |n, k|{ f[n] * rf[n-k] % MOD * rf[k] % MOD };\n\n let mut dp: Vec> = vec![vec![0; n + 1]; n + 1];\n dp[0][0] = 1;\n for ones_now in 1..(n+1) {\n for ones_before in 0..(ones_now+1) {\n let mut ways: u64 = 0;\n for place_non_one in 0..std::cmp::min(ones_before + 1, ones_now) {\n ways += px[place_non_one] * rf[place_non_one] % MOD * rf[ones_before - place_non_one] % MOD;\n }\n ways %= MOD;\n ways = ways * f[ones_before] % MOD;\n ways = ways * c(n-ones_before, ones_now-ones_before) % MOD;\n ways = ways * px[n-ones_now] % MOD;\n for i in 1..(n+1) {\n dp[i][ones_now] = (dp[i][ones_now] + dp[i-1][ones_before] * ways) % MOD;\n }\n }\n }\n\n println!(\"{}\", dp[n][n]);\n}"}], "negative_code": [], "src_uid": "f67173c973c6f83e88bc0ddb0b9bfa93"} {"source_code": "use std::io;\nuse std::cmp::max;\n\ntrait Substring {\n fn substring(&self, start: i32, len: i32) -> String;\n}\n\nimpl Substring for String {\n\n fn substring(&self, start: i32, len: i32) -> String {\n self.chars().skip(start as usize).take(len as usize).collect()\n }\n}\n\nfn main() {\n\n let mut n: String = String::new();\n let mut inp: String = String::new();\n\n io::stdin().read_line(&mut n).unwrap();\n io::stdin().read_line(&mut inp).unwrap();\n\n let n: i32 = n.trim().parse().unwrap();\n\n let mut ans: Vec<_> = (0..n/2+1).filter(|&i: &i32| -> bool {\n inp.substring(0, i) == inp.substring(i, i)\n }).collect();\n\n let ans: i32 = ans.pop().unwrap();\n let display: i32 = n - max(ans-1, 0); \n\n println!(\"{}\", display);\n}\n", "positive_code": [{"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::*;\nuse std::iter::FromIterator;\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}\n\nfn bfs(graph: &Vec>, start: usize) -> Vec {\n let mut visited: Vec = vec![-1; graph.len()];\n let mut prev: Vec = vec![0; graph.len()];\n prev[start] = usize::max_value();\n let mut q: VecDeque = VecDeque::new();\n visited[start] = 0;\n q.push_back(start);\n while !q.is_empty() {\n let &c_idx = q.front().unwrap();\n let c_cost = visited[c_idx];\n for n_idx in graph[c_idx].iter() {\n let c = visited[*n_idx];\n if c < 0 {\n let n_cost = c_cost + 1;\n visited[*n_idx] = n_cost;\n prev[*n_idx] = c_idx;\n q.push_back(*n_idx);\n }\n }\n q.pop_front();\n }\n prev\n}\n\nfn get_path(prev: Vec, goal: usize) -> Vec {\n let mut path = Vec::new();\n let mut c = goal;\n while c != usize::max_value() {\n path.push(c);\n c = prev[c];\n }\n path\n}\n\nfn main() {\n let mut pr = ContestPrinter::new();\n /*let (N, M, S, T) = readl!(usize, usize, usize, usize);\n let mut g: Vec> = vec![Vec::new(); N];\n for i in 0..M {\n let (a, b) = readl!(usize, usize);\n g[a-1].push(b-1);\n g[b-1].push(a-1);\n }\n\n let path = bfs(&g, S-1);\n let p_nodes = get_path(path, T-1);\n let p_set: HashSet = HashSet::from_iter(p_nodes.iter().cloned());\n let num = p_nodes.len();\n let mut ans = 0;\n for i in 0..N {\n ans += N - num;\n let mut cnt = 0;\n let on = p_set.contains(&i);\n for j in 0..g[i].len() {\n let idx = g[i][j];\n if on & !p_set.contains(&idx) {\n cnt += 1;\n }\n }\n ans -= cnt;\n }\n\n pr.println(ans);*/\n let N = readl!(usize);\n let s = readl!(String);\n\n let mut ans = 0;\n for i in 1..N/2+1 {\n let pr = &s[0..i];\n let co = &s[i..i+i];\n if pr == co { ans = i-1; };\n }\n\n pr.println(N - ans);\n}"}], "negative_code": [], "src_uid": "ed8725e4717c82fa7cfa56178057bca3"} {"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 = input.u());\n for i in a..=b {\n let mut x = i;\n let mut c = [0; 10];\n while x > 0 {\n c[x % 10] += 1;\n x /= 10;\n }\n if c.iter().max().unwrap() == &1 {\n println!(\"{}\", i);\n return;\n }\n }\n println!(\"-1\");\n}\n\n", "positive_code": [{"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 check(mut x:i64) -> bool {\n\tlet mut ch = vec![false; 10];\n\twhile x > 0 {\n\t\tif ch[(x % 10) as usize] {\n\t\t\treturn false;\n\t\t}\n\t\tch[(x % 10) as usize] = true;\n\t\tx /= 10;\n\t}\n\treturn true;\n}\n\nfn main() {\n\tlet mut inp = my_input::default();\n\tlet out = &mut BufWriter::new(stdout());\n\tlet l:i64 = inp.scan::();\n\tlet r:i64 = inp.scan::();\n\tfor i in l..r+1 {\n\t\tif check(i) {\n\t\t\twriteln!(out, \"{}\", i);\n\t\t\treturn;\n\t\t}\n\t}\n\twriteln!(out, \"-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}"}, {"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 l = get!(usize);\n let r = get!(usize);\n \n for x in l ..= r {\n let mut y = x;\n let mut f = vec![false; 10];\n let mut ok = true;\n while y > 0 {\n if f[y % 10] {\n ok = false;\n break;\n }\n f[y % 10] = true;\n y /= 10;\n }\n if ok {\n println!(\"{}\", x);\n return;\n }\n }\n \n println!(\"-1\");\n}"}, {"source_code": "use std::io::{self, BufRead, Write};\nuse std::str::{self, FromStr, SplitAsciiWhitespace};\n\nfn main() {\n let stdin = io::stdin();\n solve(stdin.lock(), io::stdout());\n}\n\ntype Result = std::result::Result>;\n\nstruct Scanner<'a, R> {\n reader: R,\n buf_str: Vec,\n buf_iter: SplitAsciiWhitespace<'a>,\n}\n\nimpl Scanner<'_, R> {\n pub fn new(reader: R) -> Self {\n Self {\n reader,\n buf_str: Vec::new(),\n buf_iter: \"\".split_ascii_whitespace(),\n }\n }\n\n fn try_token(&mut self) -> Result\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n loop {\n if let Some(token) = self.buf_iter.next() {\n return Ok(token.parse()?);\n }\n self.buf_str.clear();\n let bytes_read = self.reader\n .read_until(b'\\n', &mut self.buf_str)?;\n if bytes_read == 0 {\n return Err(Box::new(io::Error::from(io::ErrorKind::UnexpectedEof)));\n }\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 fn token(&mut self) -> T\n where T: FromStr,\n ::Err: 'static + std::error::Error\n {\n self.try_token().unwrap()\n }\n}\n\nfn solve(input: R, mut output: W) {\n let mut scan = Scanner::new(input);\n\n let l: u32 = scan.token();\n let r: u32 = scan.token();\n let mut met;\n 'numbers: for x in l..=r {\n met = [false; 10];\n let mut xx = x;\n while xx != 0 {\n let digit = (xx % 10) as usize;\n if met[digit] { continue 'numbers; }\n met[digit] = true;\n xx /= 10;\n }\n writeln!(output, \"{}\", x).unwrap();\n return;\n }\n writeln!(output, \"-1\").unwrap();\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn example1() {\n let inp = &b\"121 130\\n\"[..];\n let mut out = String::new();\n solve(inp, unsafe { out.as_mut_vec() });\n assert_eq!(out, \"123\\n\");\n }\n\n #[test]\n fn example2() {\n let inp = &b\"98766 100000\\n\"[..];\n let mut out = String::new();\n solve(inp, unsafe { out.as_mut_vec() });\n assert_eq!(out, \"-1\\n\");\n }\n\n #[test]\n fn badhead() {\n let inp = &b\"110 119\\n\"[..];\n let mut out = String::new();\n solve(inp, unsafe { out.as_mut_vec() });\n assert_eq!(out, \"-1\\n\");\n }\n\n #[test]\n fn t() {\n let inp = &b\"1211 1240\\n\"[..];\n let mut out = String::new();\n solve(inp, unsafe { out.as_mut_vec() });\n assert_eq!(out, \"1230\\n\");\n }\n}"}, {"source_code": "// ____ _ _ _ _\n// | _ \\ _ _ ___| |_ ___ _ __ | |_ ___ _ __ ___ _ __ | | __ _| |_ ___\n// | |_) | | | / __| __| / __| '_ \\ | __/ _ \\ '_ ` _ \\| '_ \\| |/ _` | __/ _ \\\n// | _ <| |_| \\__ \\ |_ | (__| |_) | | || __/ | | | | | |_) | | (_| | || __/\n// |_| \\_\\\\__,_|___/\\__| \\___| .__/___\\__\\___|_| |_| |_| .__/|_|\\__,_|\\__\\___|\n// |_| |_____| |_|\n\n// _ _ _ _____ ___\n// _ __ ___ __ _ _ __ | |_ __ _/ / |___ / / _ \\\n// | '_ ` _ \\ / _` | '_ \\| __/ _` | | | |_ \\| | | |\n// | | | | | | (_| | | | | || (_| | | |___) | |_| |\n// |_| |_| |_|\\__,_|_| |_|\\__\\__,_|_|_|____/ \\___/\n\n//https://github.com/manta1130/Competitive_Programming_Template_Rust\n\n#[macro_use]\nmod input {\n\n use std;\n use std::io;\n\n const SPLIT_DELIMITER: char = ' ';\n\n #[macro_export]\n #[allow(unused_macros)]\n macro_rules! input {\n ( $($x:expr ),*) => {\n {\n let temp_str = input_line_str();\n let mut split_result_iter = temp_str.split_whitespace();\n $(\n let buf_split_result = split_result_iter.next();\n let buf_split_result = buf_split_result.unwrap();\n ($x) = buf_split_result.parse().unwrap();\n )*\n }\n };\n}\n\n #[allow(dead_code)]\n pub fn input_line_str() -> String {\n let mut s = String::new();\n io::stdin().read_line(&mut s).unwrap();\n s.trim().to_string()\n }\n\n #[allow(dead_code)]\n pub fn p(t: T)\n where\n T: std::fmt::Display,\n {\n println!(\"{}\", t);\n }\n\n #[allow(dead_code)]\n pub fn input_vector2d(line: usize) -> Vec>\n where\n T: std::str::FromStr,\n {\n let mut v: Vec> = Vec::new();\n\n for _ in 0..line {\n let vec_line = input_vector();\n v.push(vec_line);\n }\n v\n }\n\n #[allow(dead_code)]\n pub fn input_vector() -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v: Vec = Vec::new();\n\n let s = input_line_str();\n let split_result = s.split(SPLIT_DELIMITER);\n for z in split_result {\n let buf = match z.parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\"),\n };\n v.push(buf);\n }\n v\n }\n\n #[allow(dead_code)]\n pub fn input_vector_row(n: usize) -> Vec\n where\n T: std::str::FromStr,\n {\n let mut v = Vec::with_capacity(n);\n for _ in 0..n {\n let buf = match input_line_str().parse() {\n Ok(r) => r,\n Err(_) => panic!(\"Parse Error\"),\n };\n v.push(buf);\n }\n v\n }\n\n pub trait ToCharVec {\n fn to_charvec(&self) -> Vec;\n }\n\n impl ToCharVec for String {\n fn to_charvec(&self) -> Vec {\n self.to_string().chars().collect::>()\n }\n }\n}\n\nuse input::*;\nuse std::collections::BTreeSet;\n\nfn func(n: usize) -> bool {\n let mut set = BTreeSet::new();\n let s = n.to_string().to_charvec();\n let sl = s.len();\n\n for c in s {\n set.insert(c);\n }\n if sl == set.len() {\n true\n } else {\n false\n }\n}\n\nfn main() {\n let (l, r): (usize, usize);\n input!(l, r);\n\n for x in l..r + 1 {\n if func(x) {\n p(x);\n return;\n }\n }\n p(-1);\n}\n"}, {"source_code": "//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, 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 l: usize,\n r: usize,\n }\n for x in l..=r {\n let s: Vec = x.to_string().chars().collect();\n let k = s.len();\n let mut ok = true;\n for i in 0..k {\n for j in 0..i {\n if s[i] == s[j] {\n ok = false;\n }\n }\n }\n if ok {\n println!(\"{}\", x);\n return;\n }\n }\n println!(\"-1\");\n}\n\nfn main() {\n run();\n}\n"}, {"source_code": "use std::io;\n \nuse std::collections::HashSet;\n \nfn main() {\n let mut buf = String::new();\n io::stdin().read_line(&mut buf).unwrap();\n let input: Vec = buf.trim().split(' ').map(|x| x.parse().unwrap()).collect();\n let (left, right) = (input[0], input[1]);\n let res = (left..=right)\n .map(|x| {\n let s = x.to_string();\n (\n x.to_string(),\n s.chars().collect::>().len(),\n s.chars().count(),\n )\n })\n .find(|(_, len1, len2)| len1 == len2);\n let res = match res {\n Some(r) => r.0,\n None => (-1).to_string(),\n };\n println!(\"{}\", res);\n}"}, {"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 is_good(x: usize) -> bool {\n let mut isused: [bool; 10] = [false; 10];\n let mut a = x;\n while a > 0 {\n let dig = a % 10;\n a /= 10;\n if isused[dig] {\n return false;\n }\n isused[dig] = true;\n }\n return true;\n}\n\nfn _main() {\n let mut scan = Scan::new();\n let l: usize = scan.next();\n let r: usize = scan.next();\n for i in l..=r {\n if is_good(i) {\n println!(\"{}\", i);\n return;\n }\n }\n println!(\"-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"}, {"source_code": "fn ud(mut a: i32) -> bool {\n let mut m = 0;\n while a != 0 {\n let c = 1 << (a % 10);\n if m & c != 0 {\n return false;\n }\n m |= c;\n a /= 10;\n }\n true\n}\n\nfn solve(a: i32, b: i32) -> i32 {\n for i in a..=b {\n if ud(i) {\n return i;\n }\n }\n -1\n}\n\nfn main() {\n let mut buf = String::new();\n std::io::stdin().read_line(&mut buf).unwrap();\n let mut it = buf.trim().split_whitespace();\n println!(\n \"{}\",\n solve(\n it.next().unwrap().parse().unwrap(),\n it.next().unwrap().parse().unwrap()\n )\n );\n}\n\n#[cfg(test)]\nmod tests {\n use super::*;\n\n #[test]\n fn test_canonical() {\n assert_eq!(solve(121, 130), 123);\n assert_eq!(solve(98766, 100000), -1);\n }\n}\n"}, {"source_code": "use std::io;\nuse std::collections::HashSet;\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\nfn is_diff(n: i64) -> bool {\n let mut nn = n;\n let mut hs = HashSet::new();\n while nn > 0 {\n let ni = nn % 10;\n nn /= 10;\n if hs.contains(&ni) { \n return false;\n }\n hs.insert(ni);\n }\n return true;\n}\n\nfn has(l: i64, r: i64) -> Option {\n for i in l..(r+1) {\n if is_diff(i) {\n return Some(i);\n }\n }\n return None;\n}\n\n\nfn main() {\n let (l, r) = read_line_pair();\n \n // let r = is_diff(1101231);\n \n match has(l, r) {\n Some(n) => println!(\"{}\", n),\n None => println!(\"-1\")\n }\n \n // println!(\"{:?}\", r);\n \n \n}\n"}, {"source_code": "#![allow(unused_imports, unused_macros, dead_code)]\n\nmacro_rules! min {\n (.. $x:expr) => {{\n let mut it = $x.iter();\n it.next().map(|z| it.fold(z, |x, y| min!(x, y)))\n }};\n ($x:expr) => ($x);\n ($x:expr, $($ys:expr),*) => {{\n let t = min!($($ys),*);\n if $x < t { $x } else { t }\n }}\n}\nmacro_rules! max {\n (.. $x:expr) => {{\n let mut it = $x.iter();\n it.next().map(|z| it.fold(z, |x, y| max!(x, y)))\n }};\n ($x:expr) => ($x);\n ($x:expr, $($ys:expr),*) => {{\n let t = max!($($ys),*);\n if $x > t { $x } else { t }\n }}\n}\n\n\nmacro_rules! ewriteln {\n ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };\n}\nmacro_rules! trace {\n ($x:expr) => { ewriteln!(\">>> {} = {:?}\", stringify!($x), $x) };\n ($($xs:expr),*) => { trace!(($($xs),*)) }\n}\nmacro_rules! put {\n (.. $x:expr) => {{\n let mut it = $x.iter();\n if let Some(x) = it.next() { print!(\"{}\", x); }\n for x in it { print!(\" {}\", x); }\n println!(\"\");\n }};\n ($x:expr) => { println!(\"{}\", $x) };\n ($x:expr, $($xs:expr),*) => { print!(\"{} \", $x); put!($($xs),*) }\n}\n\nfn ok(a: usize) -> bool {\n let mut a = a;\n let mut d = vec![];\n while a > 0 {\n d.push(a % 10);\n a /= 10;\n }\n use std::collections::HashSet;\n let s : HashSet<_> = d.iter().collect();\n d.len() == s.len()\n}\n\nfn main() {\n let mut sc = Scanner::new();\n let n: usize = sc.cin();\n let m: usize = sc.cin();\n for a in n..m+1 {\n if ok(a) {\n put!(a);\n return;\n }\n }\n put!(-1);\n}\n\nuse std::io::{self, Write};\nuse std::str::FromStr;\nuse std::collections::VecDeque;\n\nstruct Scanner { stdin: io::Stdin, buffer: VecDeque, }\nimpl Scanner {\n fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }\n fn cin(&mut self) -> T {\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 self.buffer.pop_front().unwrap().parse::().ok().unwrap()\n }\n}\n"}, {"source_code": "#[allow(unused_imports)]\nuse std::cmp::{max, min};\nuse std::collections::HashSet;\n \ntype GenError = Box;\ntype GenResult = Result;\n \nstruct Reader {}\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 let tokens = Reader::read_tokens().unwrap();\n let n: i32 = tokens[0].parse().unwrap();\n let m: i32 = tokens[1].parse().unwrap();\n for value in n .. m + 1 {\n let mut chars = HashSet::new();\n let string = value.to_string();\n for ch in string.chars(){\n chars.insert(ch);\n }\n if chars.len() == string.len() {\n println!(\"{}\", string);\n return;\n }\n }\n println!(\"{}\", -1);\n}\n"}], "negative_code": [{"source_code": "use std::io;\nuse std::collections::HashSet;\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\nfn is_diff(n: i64) -> bool {\n let mut nn = n;\n let mut hs = HashSet::new();\n while nn > 0 {\n let ni = nn % 10;\n nn /= 10;\n if hs.contains(&ni) {\n return false;\n }\n hs.insert(ni);\n }\n return true;\n}\n\nfn has(l: i64, r: i64) -> Option {\n for i in l..r {\n if is_diff(i) {\n return Some(i);\n }\n }\n return None;\n}\n\n\nfn main() {\n let (l, r) = read_line_pair();\n \n // let r = is_diff(1101231);\n \n match has(l, r) {\n Some(n) => println!(\"{}\", n),\n None => println!(\"-1\")\n }\n \n // println!(\"{:?}\", r);\n \n \n}\n"}], "src_uid": "3041b1240e59341ad9ec9ac823e57dd7"}