use proconio::input; use std::collections::HashMap; fn main() { input! { n: usize, a: [usize; n] } // x <= y // if x == 1 かつ y == 1 => 2 // if x == 1 かつ y == 2 => 3 // if x == 1 かつ 3 <= y => 2 // else => 1 let mut map = HashMap::new(); for &x in &a { *map.entry(if x != 1 && x != 2 { 3 } else { x }).or_insert(0) += 1; } let mut res = 0_usize; let one = map.get(&1); let two = map.get(&2); let other = map.get(&3); if let Some(&onec) = one { res += 2 * onec * (onec - 1) / 2; if let Some(&tc) = two { res += 3 * onec * tc; } if let Some(&oc) = other { res += 2 * onec * oc; } } match (two, other) { (Some(tc), Some(oc)) => { res += tc * (tc - 1) / 2; res += oc * (oc - 1) / 2; res += oc * tc; } (None, Some(oc)) => { res += oc * (oc - 1) / 2; } (Some(tc), None) => { res += tc * (tc - 1) / 2; } (None, None) => {} } println!("{res}"); }