#!/usr/bin/env python3 n = int(input()) ans = [None] * n def query(a, b): print('?', a+1, b+1, flush=True) x, y = map(int, input().split()) return (x,y) # If querying (i, i+1) and (i+1, i+2) both give the same pair (a,b), position i can be both a and b. # Store this, and resolve conflicts in the end when we know the rest of the array. ans[0], ans[1] = query(0, 1) last_ans = None for i in range(1, n-1): x, y = query(i, i+1) if {x,y} == last_ans: ans[i-1] = {x, y} last_ans = {x, y} if ans[i] not in [x,y]: ans[i], ans[i-1] = ans[i-1], ans[i] assert ans[i] in [x,y] ans[i] = x assert ans[i+1] is None ans[i+1] = y # Count the number of times each integer occurs, and fix unresolved positions. count = {i: 0 for i in range(1, n+1)} for x in ans: if isinstance(x, int): count[x] += 1 for i, x in enumerate(ans): if isinstance(x, set): for y in x: if count[y] < 2: ans[i] = y count[y] += 1 break # The two remaining unfixed positions uk = (n-2, n-1) while ans[uk[0]] != ans[uk[1]]: # Find another position with the given value. p1 = uk[0] p2 = None for i in range(n): if ans[i] == ans[uk[0]] and i != p1: p2 = i break assert p2 is not None x, y = query(p1, p2) # Happens with probability 0.5. if x == y: break z = ans[uk[1]] assert x == z or y == z ans[uk[0]], ans[uk[1]] = ans[uk[1]], ans[uk[0]] uk = (p1, p2) print('!', *ans)