import itertools def main(): n = int(input()) K = list(map(int, input().split())) valid_moves = [] # Precompute all valid Kadomatsu triples (a, b, c) for a, b, c in itertools.combinations(range(n), 3): x, y, z = K[a], K[b], K[c] if x == y or y == z or x == z: continue sorted_xyz = sorted([x, y, z]) mid_val = sorted_xyz[1] if mid_val == x or mid_val == z: valid_moves.append((a, b, c)) if not valid_moves: print(-1) return max_mask = 1 << n dp = [False] * max_mask # Process masks in reverse order to fill DP table correctly for mask in reversed(range(max_mask)): for a, b, c in valid_moves: abc_mask = (1 << a) | (1 << b) | (1 << c) if (mask & abc_mask) == 0: new_mask = mask | abc_mask if not dp[new_mask]: dp[mask] = True break # Only one winning move needed # Check if D can win by selecting any initial valid move for a, b, c in valid_moves: abc_mask = (1 << a) | (1 << b) | (1 << c) new_mask = abc_mask if not dp[new_mask]: print(f"{a} {b} {c}") return print(-1) if __name__ == "__main__": main()