N = gets.to_i Q = 2.pow(N).times.map { gets.split.map(&:to_i) } def f(q) res = [] q[0..-2].each.with_index(1) do |v, i| if v == 0 res << "¬P_#{i}" else res << "P_#{i}" end end '(' + res.join('∧') + ')' end if Q.all? { |q| q.last == 0 } puts 'A=⊥' elsif Q.all? { |q| q.last == 1 } puts 'A=⊤' else puts "A=#{Q.select { |q| q.last == 1 }.map { |q| f(q) }.join('v')}" end