n = read_line.to_i s, t = read_line.split.map(&.to_i) a = read_line.split.map(&.to_i) + [s, t] hash = a.zip(0..).to_h que = Deque{n} dist = [nil.as(Int32?)] * (n + 2) dist[n] = -1 while i = que.shift? d = dist[i].not_nil! puts(d) + exit if i == n + 1 a.each_with_index do |x, j| if (a[i] ^ x).popcount == 1 dist[j] = d + 1 que << j end end end puts -1