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 (0..30).each do |bit| if (j = hash[a[i] ^ (1 << bit)]?) && dist[j].nil? dist[j] = d + 1 que << j end end end puts -1