F: Transparent mahjong tiles

You will play mahjong against Mr. Takanosu, a gambler who is rumored to have fallen into the darkness. Mr. Takanosu has been rumored to be a natural disaster, so he has proposed a game using a bizarre mahjong tile called Takanosu tile.

Mahjong is a game in which players hold multiple tiles called hand tiles, and their hand tiles are no longer more than their opponents, and the victory is confirmed by making them into the shape of an agari. On the front side of the mahjong tile, what the tile is is drawn, and on the back side of the tile, nothing is drawn. Therefore, when you play mahjong, you should face the front side of your Tehai to your side and the back side to the player's side. This way, only you can know what your Tehai is. The real thrill of mahjong is that players read each other's arrangements and enjoy it.

However, Takanosu tiles are transparent mahjong tiles. Since the Takanosu tiles are transparent, players can know each other's hand tiles. With this, you cannot enjoy reading the arrangements.

"This is no longer a mahjong tile." If you are not convinced to use the mahjong tiles, as a result of twists and turns with Mr. Takanashi, you will play a mixture of mahjong tiles and ordinary mahjong tiles. It was.

As a starting point, you decide to predict what Takanosu's Tehai tiles are. Mr. Takanosu's hand tiles consist of Takanosu tiles and ordinary tiles. For the sake of simplicity, the Takanosu tiles and ordinary tiles shall consist of 4 tiles of 12 types from 1 to 12.

For a hand tile consisting of 3n + 2 tiles, the hand tile is agari when the following three conditions are met.

* There is one set of tiles that combines the same numbers
* The remaining 3n tiles are n groups of 3 number combinations.
* Each group is either a combination of three identical numbers or a combination of three consecutive numbers.



For example


1 1 1 3 3 3 5 5 5 7 7 7 8 9


All 14 tiles like this are made up of Takanosu tiles. In this case, one combination of two tiles and four groups can be made as follows, which is Agari.


(1 1 1) (3 3 3) (5 5 5) (7 7) (7 8 9)


Next, we will give an example of a hand tile that is a mixture of ordinary tiles and Takanosu tiles.


1 1 1 3 3 3 5 5 5 7 7 7 * *


14 tiles like this are composed of 12 Takanosu tiles and 2 ordinary tiles (*). In this case, two ordinary tiles may be 8 and 9, so one combination of two tiles and four groups can be made, which may be agari.


(1 1 1) (3 3 3) (5 5 5) (7 7) (7 [8] [9])


For the same example, two ordinary tiles may be 8 and 8 as follows, so it may be an agari of the form:


(1 1 1) (3 3 3) (5 5 5) (7 7 7) ([8] [8])


However, since the same tile of 7 can only be used up to 4 tiles, it is not an agari of the following shape.


(1 1 1) (3 3 3) (5 5 5) (7 7 7) ([7] [7])


When Mr. Takanashi's 3n + 1 hand tile is given as an input, consider adding one tile to Mr. Takanashi's hand tile to make 3n + 2 hand tiles. At this time, find all the additional tiles (Agari tiles) that can turn 3n + 2 hand tiles into Agari.

Input

The input is given in the following format.


n
Tile 1 Tile 2 ... Tile 3n + 1


The input data satisfies the following conditions, and n satisfies 0 <= n <= 15. Each tile is a Takanosu tile or an ordinary tile. In the case of Takanosu tiles, it is represented by an integer of 1 or more and 12 or less, and in the case of ordinary tiles, it is represented by the character *.

Output

Output the list of tiles in ascending order. Output a line break each time you output one tile. If you don't have a tile, display -1 on one line.

Sample Input 1


Four
1 1 1 3 3 3 5 5 5 7 7 7 9


Sample Output 1


8
9


Sample Input 2


Four
1 2 2 3 3 4 5 6 7 8 8 8 9


Sample Output 2


1
Four
7
9
Ten


Sample Input 3


Four
1 1 1 4 4 4 7 7 7 8 8 9 *


Sample Output 3


6
7
8
9
Ten
11


Sample Input 4


Four
1 * * * * * * * * * * * *


Sample Output 4


1
2
3
Four
Five
6
7
8
9
Ten
11
12


Sample Input 5


1
3 * 1 4


Sample Output 5


1
2
Four
Five






Example

Input

4
1 1 1 3 3 3 5 5 5 7 7 7 9


Output

8
9
#include<cstdio>
#include<cstring>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int n,star;
int cnt[12]; // 数字 i が書かれた牌はあと i 個
int rem[12]; // * が i に成れるのは rem[i] 個まで

bool dfs(int i){
	if(i==12) return star==0;

	if(cnt[i]==0){
		if(dfs(i+1)) return true;
	}

	// i, i, i
	if(cnt[i]+min(star,rem[i])>=3){
		int tmp=min(cnt[i],3);
		cnt[i]-=tmp;
		star-=3-tmp;
		rem[i]-=3-tmp;
		bool res=dfs(i);
		cnt[i]+=tmp;
		star+=3-tmp;
		rem[i]+=3-tmp;
		if(res) return true;
	}

	// i, i+1, i+2
	if(i<=9){
		bool b=true; // i, i+1, i+2 の割り当てが可能かどうか
		int minus=0;
		rep(j,3){
			if(cnt[i+j]==0 && min(star-minus,rem[i+j])==0) b=false;
			if(cnt[i+j]==0) minus++;
		}
		if(b){
			bool used[3]={};
			rep(j,3){
				if(cnt[i+j]>0) cnt[i+j]--, used[j]=true;
				else           star--, rem[i+j]--;
			}
			bool res=dfs(i);
			rep(j,3){
				if(used[j]) cnt[i+j]++;
				else        star++, rem[i+j]++;
			}
			if(res) return true;
		}
	}

	return false;
}

int main(){
	scanf("%d",&n);
	int hai[47],star=0;
	rep(i,3*n+1){
		char s[4]; scanf("%s",s);
		if(s[0]=='*'){
			hai[i]=-1;
			star++;
		}
		else{
			hai[i]=atoi(s)-1;
			cnt[hai[i]]++;
		}
	}

	bool none=true;
	rep(a,12) if(cnt[a]<4) { // 3*n+2 枚目の牌
		hai[3*n+1]=a;
		cnt[a]++;

		rep(i,12) rem[i]=4-cnt[i];

		bool ok=false;
		rep(b,12) if(cnt[b]+star>=2) { // 最後の二つの牌
			int tmp1[47],tmp2[12],tmp3[12];
			memcpy(tmp1,hai,sizeof hai);
			memcpy(tmp2,cnt,sizeof cnt);
			memcpy(tmp3,rem,sizeof rem);

			::star=star;
			int m=3*n+2,two=2;
			rep(i,m) if(two>0 && hai[i]== b) swap(hai[i],hai[m-1]), i--, m--, two--, cnt[b]--;
			rep(i,m) if(two>0 && hai[i]==-1) swap(hai[i],hai[m-1]), i--, m--, two--, rem[b]--, ::star--;
			ok=dfs(0);

			memcpy(hai,tmp1,sizeof hai);
			memcpy(cnt,tmp2,sizeof cnt);
			memcpy(rem,tmp3,sizeof rem);

			if(ok) break;
		}

		if(ok) printf("%d\n",a+1), none=false;

		cnt[a]--;
	}
	if(none) puts("-1");

	return 0;
}