use std::collections::*; use std::io::*; use std::str::FromStr; use utils::*; pub fn main() { let i = stdin(); let mut o = Vec::new(); run(i.lock(), &mut o); stdout().write_all(&o).unwrap(); } fn run(i: R, o: &mut W) { let mut i = CpReader::new(i); let n = i.read::(); let w = i.read_vec::(n); let r = if solve(&w) { "possible" } else { "impossible" }; writeln!(o, "{}", r).unwrap(); } fn solve(w: &[usize]) -> bool { let sum: usize = w.iter().sum(); if sum % 2 == 1 { return false; } let mut m = BTreeMap::new(); for &w in w { *m.entry(w).or_insert(0) += 1; } fn get_result<'a>(mut i: btree_map::Iter<'a, usize, usize>, mut l0: usize, l1: usize) -> bool { if let Some((&k, &v)) = i.next() { for c in 0..v + 1 { let l1_use = (v - c) * k; if l1_use == l1 || (l1_use < l1 && get_result(i.clone(), l0, l1 - l1_use)) { return true; } if l0 < k { return false; } l0 -= k; if l0 == 0 { return true; } } } false } get_result(m.iter(), sum / 2, sum / 2) } mod utils { use super::*; pub struct CpReader { r: R, s: String, } impl CpReader { pub fn new(r: R) -> Self { CpReader { r: r, s: String::new(), } } pub fn read_line(&mut self) -> &str { self.s.clear(); self.r.read_line(&mut self.s).unwrap(); self.s.trim() } pub fn read(&mut self) -> T { self.read_line().parse().ok().unwrap() } pub fn read_vec(&mut self, n: usize) -> Vec { self.read_line() .split(' ') .take(n) .map(|x| x.parse().ok().unwrap()) .collect() } } }