#include using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) #define unless(p) if(!(p)) #define until(p) while(!(p)) using ll = long long; using P = std::tuple; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int N; int dp[1 << 12]; int K[12]; bool isKadomatsuSequence(int a, int b, int c){ return a != b && b != c && c != a && (max({a, b, c}) == b || min({a, b, c}) == b); } int rec(int state, int n){ if(n == N){ return -1; } if(dp[state] != -2){ return dp[state]; } dp[state] = -1; for(int i=0;i> i & 1){continue;} for(int j=i+1;j> j & 1){continue;} for(int k=j+1;k> k & 1){continue;} if(isKadomatsuSequence(K[i], K[j], K[k]) && rec(state | (1 << i) | (1 << j) | (1 << k), n + 3) == -1){ dp[state] = i + ((j + (k << 4)) << 4); return dp[state]; } } } } return dp[state]; } int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cin >> N; for(int i=0;i> K[i]; } fill(dp, dp + (1 << 12), -2); int x = rec(0, 0); if(x == -1){ std::cout << x << std::endl; }else{ int a = x & 0xf, b = x >> 4 & 0xf, c = x >> 8 & 0xf; std::cout << a << " " << b << " " << c << std::endl; } }