from strutils import parseInt from sequtils import mapIt let N = stdin.readLine.parseInt var participants = (1..N).mapIt(it) proc ask(x, y: int): int = echo "? ", x, " ", y stdin.readLine.parseInt var next = newSeq[int]() while participants.len > 4: next = @[] for i in countup(1, participants.high, 2): let ans = ask(participants[i - 1], participants[i]) next.add(ans) if participants.len mod 2 == 1: next.add(participants[^1]) participants = next doAssert participants.len > 1 if ask(participants[0], participants[1]) == participants[1]: swap(participants[0], participants[1]) case participants.len: of 2: discard of 3: if ask(participants[0], participants[2]) == participants[2]: swap(participants[0], participants[2]) if ask(participants[1], participants[2]) == participants[2]: swap(participants[1], participants[2]) of 4: if ask(participants[2], participants[3]) == participants[3]: swap(participants[2], participants[3]) if ask(participants[0], participants[2]) == participants[2]: swap(participants[0], participants[2]) if ask(participants[1], participants[2]) == participants[2]: swap(participants[1], participants[2]) else: discard echo "! ", participants[1]