# frozen_string_literal: true class Array def swap!(a, b) ia = a ib = b self[ia], self[ib] = self[ib], self[ia] end def divide_by_question question_index = index { _1[0] == '?' } if question_index.zero? [[], to_integer] else [self[0..(question_index - 1)], self[(question_index + 1)..-1]] .map { _1.to_integer } end end def to_integer map { _1.map(&:to_i) } end def move_cups(moves) moves.each do |left, right| swap!(left - 1, right - 1) end self end def detect_position(other) zip(other) .map .with_index { |pair, index| [pair[0] != pair[1], index] } .filter { |flag, _index| flag } .map { |_flag, index| index + 1 } .join(' ') end end def solve t, b = A.divide_by_question ct = (1..N).to_a.move_cups(t) cb = C.move_cups(b.reverse) ct.detect_position(cb) end N, K, X = gets.split.map(&:to_i) A = K.times.map { gets.chomp.split } C = gets.chomp.split.map(&:to_i) puts solve