#![allow(non_snake_case, unused_imports, unused_macros)] use itertools::Itertools; use proconio::{fastout, input, marker::Usize1}; macro_rules! debug { ($($a:expr),* $(,)*) => { #[cfg(debug_assertions)] eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*); }; } macro_rules! ndvec { ($v:expr; $n:expr) => { vec![$v; $n] }; ($v:expr; $n:expr, $($ns:expr),+) => { vec![ndvec![$v; $($ns),+]; $n] }; } macro_rules! yes_no { ($e:expr) => { if $e { println!("Yes"); } else { println!("No"); } }; } #[fastout] fn main() { input! { n: i128, mut a: i128, b: i128, c: i128, mut d: i128, e: i128, f: i128 } debug!(a, b, c, d, e, f); let k0 = partition_point(0, n / a + 1, |r| (a * r + c * r * (r - 1) / 2) <= n / b) - 1; let c0 = k0 * b + (n - (a * k0 + c * k0 * (k0 - 1) / 2) * b) / (a + c * k0); let k1 = partition_point(0, n / d + 1, |r| (d * r + f * r * (r - 1) / 2) <= n / e) - 1; let c1 = k1 * e + (n - (d * k1 + f * k1 * (k1 - 1) / 2) * e) / (d + f * k1); debug!(k0, k1, c0, c1); if c0 == c1 { println!("Same"); } else if c0 < c1 { println!("KCPC"); } else { println!("KUPC"); } } #[allow(unused)] fn partition_point(mut l: I, mut r: I, mut f: impl FnMut(I) -> bool) -> I { let one = I::one(); let two = one + one; while l < r { let p = (r - l) / two + l; if f(p) { l = p + one; } else { r = p; } } l } #[test] fn test_isqrt() { for i in 0..100usize { assert_eq!(i.isqrt(), partition_point(0, i + 1, |k| k * k <= i) - 1); } }