# frozen_string_literal: true AND = '∧' OR = '∨' NOT = '¬' BOT = '⊥' TOP = '⊤' def make_exp(prop, index) case prop when 0 "#{NOT}P_#{index + 1}" when 1 "P_#{index + 1}" end end # ----------------------------------- exec table = [] N = gets.to_i (2**N).times do input = gets.chomp.split.map(&:to_i) qs = input[0..-2] r = input[-1] table << [qs, r] end puts( 'A=' + if table.map { |r| r[1] }.uniq.size == 1 if table[0][1].zero? BOT else TOP end else EXPS = table.select { |r| r[1] == 1 }.map do |r| r[0].map.with_index { |q, i| make_exp(q, i) }.join(AND) end EXPS.map { |e| "(#{e})" }.join(OR) end )