import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### class scc_graph: def __init__(self, N): self.N = N self.edges = [] self.start = [0] * (N + 1) def csr(self): for i in range(1, self.N + 1): self.start[i] += self.start[i - 1] counter = self.start[:] self.elist = [0] * len(self.edges) for a, b in self.edges: self.elist[counter[a]] = b counter[a] += 1 def add_edge(self, a, b): self.edges.append((a, b)) self.start[a + 1] += 1 def scc(self): self.csr() N = self.N now_ord = group_num = 0 visited = [] low = [0] * N order = [-1] * N ids = [0] * N parent = [-1] * N stack = [] groups = [] for i in range(N): if order[i] == -1: stack.append(i) stack.append(i) while stack: v = stack.pop() if order[v] == -1: low[v] = order[v] = now_ord now_ord += 1 visited.append(v) for i in range(self.start[v], self.start[v + 1]): to = self.elist[i] if order[to] == -1: stack.append(to) stack.append(to) parent[to] = v else: low[v] = min(low[v], order[to]) else: if low[v] == order[v]: group = [] while True: u = visited.pop() order[u] = N ids[u] = group_num group.append(u) if u == v: break groups.append(group) group_num += 1 if parent[v] != -1: low[parent[v]] = min(low[parent[v]], low[v]) for i, x in enumerate(ids): ids[i] = group_num - 1 - x return group_num, ids, groups[::-1] def ask(i, j): print("1", i, j, flush=True) return ni() n = ni() p = [-1] + [ask(i, i) for i in range(1, n + 1)] scc = scc_graph(n + 1) for i in range(1, n + 1): if p[i] != -1: scc.add_edge(p[i], i) group_num, ids, groups = scc.scc() dp = [0] * (n + 1) for i in groups: x = i[0] if p[x] == -1: continue dp[x] = dp[p[x]] + 1 i = dp.index(max(dp)) ans = [-1] * (1 + n) ans[i] = 1 now = i for j in range(n - 1): k = ask(now, i) ans[k] = j + 2 now = k print(2, *ans[1:])