prev, current, N = gets.split.map(&:to_i) answer = nil if N.zero? or N == 1 puts N.zero? ? prev : current exit end (N - 1).times do answer = prev ^ current prev, current = current, answer end puts answer