macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); input_inner!{iter, $($r)*} }; ($($r:tt)*) => { let mut s = { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s }; let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } macro_rules! input_inner { ($iter:expr) => {}; ($iter:expr, ) => {}; ($iter:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($iter, $t); input_inner!{$iter $($r)*} }; } macro_rules! read_value { ($iter:expr, ( $($t:tt),* )) => { ( $(read_value!($iter, $t)),* ) }; ($iter:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($iter, $t)).collect::>() }; ($iter:expr, chars) => { read_value!($iter, String).chars().collect::>() }; ($iter:expr, usize1) => { read_value!($iter, usize) - 1 }; ($iter:expr, $t:ty) => { $iter.next().unwrap().parse::<$t>().expect("Parse error") }; } fn read_vec() -> Vec { let mut s = String::new(); std::io::stdin().read_line(&mut s).ok(); s.trim() .split_whitespace() .map(|e| e.parse().ok().unwrap()) .collect() } fn main() { input!(n: usize); let max = 2usize.pow(n as u32); let lines = (0..max) .map(|_i| { let line: Vec = read_vec(); if line[n] == 0 { None } else { Some( line[0..n] .iter() .enumerate() .map(|(idx, &flg)| { let num = (idx + 1).to_string(); if flg == 0 { "¬P_".to_string() + &num } else { "P_".to_string() + &num } }) .collect::>() .join("∧"), ) } }) .filter(|v| v.is_some()) .map(|v| v.unwrap()) .collect::>(); if lines.len() == 0 { println!("A=⊥"); } else if lines.len() == max { println!("A=⊤"); } else { print!("A=({})", lines.join(")∨(")); } }