#[macro_export] macro_rules! setup { { mut $input:ident: SplitWhitespace $(,)? } => { use std::io::Read; let mut buf = String::new(); std::io::stdin().read_to_string(&mut buf).unwrap(); let mut $input = buf.split_whitespace(); }; } #[macro_export] macro_rules! parse_next { ($str_iter:expr) => { $str_iter.next().unwrap().parse().unwrap() }; } use std::collections::HashMap; fn main() { setup! { mut input: SplitWhitespace }; let a: i64 = parse_next!(input); let b: i64 = parse_next!(input); let c: i64 = parse_next!(input); let d: i64 = parse_next!(input); let p: i64 = parse_next!(input); let q: i64 = parse_next!(input); let f = |x: i64| -> i64 { a * x.pow(3) + b * x.pow(2) + c * x + d }; let mut f_x = HashMap::new(); let mut x_max = p; let mut x_min = p; for x in p..=q { let y = f(x); match x { x if x == p => {} _ => { if *f_x.get(&x_max).unwrap() < y { x_max = x; } if *f_x.get(&x_min).unwrap() > y { x_min = x; } } } f_x.insert(x, y); } let max = *f_x.get(&x_max).unwrap(); let min = *f_x.get(&x_min).unwrap(); println!("{} {} {} {}", max, x_max, min, x_min); }