Problem: There is a puzzle to complete by combining 14 numbers from 1 to 9. Complete by adding another number to the given 13 numbers.

The conditions for completing the puzzle are

* You must have one combination of the same numbers.
* The remaining 12 numbers are 4 combinations of 3 numbers.
The combination of three numbers is either three of the same numbers or three consecutive numbers. However, sequences such as 9 1 2 are not considered consecutive numbers.
* The same number can be used up to 4 times.



Create a program that reads a string of 13 numbers and outputs all the numbers that can complete the puzzle in ascending order. If you cannot complete the puzzle by adding any number from 1 to 9, output 0.

For example, if the given string is 3456666777999

If there is a "2", 234 567 666 77 999
If there is a "3", then 33 456 666 777 999
If there is a "5", then 345 567 666 77 999
If there is an "8", then 345 666 678 77 999

And so on, the puzzle is complete when one of the numbers 2 3 5 8 is added. Note that "6" is fine, but it will be used for the 5th time, so it cannot be used in this example.



Input

The input consists of multiple datasets. For each dataset, 13 numbers are given on one line. The number of datasets does not exceed 50.

Output

For each dataset, the numbers that can complete the puzzle are output on one line in ascending order, separated by blanks.

Example

Input

3649596966777
6358665788577
9118992346175
9643871425498
7755542764533
1133557799246


Output

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

Solution (in JAVA):

Solution:
import java.util.Scanner;
import java.util.Collections; 
import java.util.ArrayList; 

public class Main{
    void run(){
	Scanner sc = new Scanner(System.in);
	while(sc.hasNext()){
	    String str = sc.nextLine();

	    ArrayList<Character> tmp_e = new ArrayList<Character>();
	    char[] freq = new char[255];
	    for(int i=0;i<str.length();i++){
		tmp_e.add(str.charAt(i));
		freq[str.charAt(i)]++;
	    }

	    ArrayList<Character> res = new ArrayList<Character>();
	    for(char lastChar='1';lastChar<='9';lastChar++){
		if(freq[lastChar] >= 4) continue;
		ArrayList<Character> e  = new ArrayList<Character>(tmp_e);
		e.add(lastChar);

		Collections.sort(e);
		// System.out.println(e);
		ArrayList<Integer> JantoList = findJanto(e,0);
		// printBitArray(JantoList,14);
		for(int i=0;i<JantoList.size();i++){
		    ArrayList<Integer> cand = findKotsu(e,JantoList.get(i));

		    // System.out.println("after find kotsu");
		    // printBitArray(cand,14);

		    for(int S=0;S<=(1<<cand.size())-1;S++){
			ArrayList<Integer> cand2 = new ArrayList<Integer>();
			for(int j=0;j<cand.size();j++){
			    if((S & (1<<j)) > 0){
				cand2.add(cand.get(j));
			    }
			}

			if(!isIntersect(cand2,14)){
			    int visited = JantoList.get(i);
			    for(int k=0;k<cand2.size();k++){
				visited |= cand2.get(k);
			    }

			    // System.out.println("after fill kotsu");
			    // printBit(visited,14);
			    // System.out.println(fillShuntsu(e,visited));
			    if(fillShuntsu(e,visited)){
				res.add(lastChar);
				// System.out.println(lastChar);
				break;
			    }
			}
		    }
		    //System.out.println(cand);
		
		}
	    }
	    
	    show(res);
	}
    }

    void show(ArrayList<Character> e){
	Collections.sort(e);
	int[] freq = new int[255];
	ArrayList<Character> res = new ArrayList<Character>();
	
	for(int i=0;i<e.size();i++){
	    if(freq[e.get(i)] > 0) continue;
	    freq[e.get(i)]++;
	    res.add(e.get(i));
	}

	if(res.size() == 0){
	    System.out.println(0);
	    return;
	}

	for(int i = 0; i<res.size(); i++){
	    System.out.printf("%s%c",i==0 ? "" : " ",res.get(i));
	}
	System.out.println();
    }
    void printBitArray(ArrayList<Integer> e,int w){
	for(int i=0;i<e.size();i++){
	    printBit(e.get(i),w);
	}
    }
    void printBit(int num,int w){
	for(int i=0;i<w;i++){
	    if((num & (1<<i)) > 0){
		System.out.print("1");
	    }
	    else{
		System.out.print("0");
	    }
	}
	System.out.println();
    }

    ArrayList<Integer> findJanto(ArrayList<Character> e,int visited){
	ArrayList<Integer> res = new ArrayList<Integer>();
	for(int base=1;base<=9;base++){
	    for(int i=0;i+1<e.size();i++){
		int tmp = visited;
		if(e.get(i) == base + '0'
		   && e.get(i+1) == base + '0'){
		    tmp |= (1<<i);
		    tmp |= (1<<(i+1));
		    res.add(tmp);
		    //System.out.println(e.get(i));
		}
	    }
	}

	//System.out.println(res);
	return res;
    }

    boolean isIntersect(ArrayList<Integer> e,int width){
	for(int i=0;i<e.size();i++){
	    for(int j=i+1;j<e.size();j++){
		for(int k=0;k<width;k++){
		    int a = e.get(i);
		    int b = e.get(j);

		    if(((a & (1<<k))
			& (b & (1<<k))) > 0){
			return true;
		    }
		}
	    }
	}
	return false;
    }

    ArrayList<Integer> findKotsu(ArrayList<Character> e,int visited){
	ArrayList<Integer> res = new ArrayList<Integer>();
	for(int base=1;base<=9;base++){
	    for(int i=0;i+2<e.size();i++){
		if((
		    (visited & (1<<i))
		    | (visited & (1<<(i+1)))
		    | (visited & (1<<(i+2)))
		    ) > 0) continue;
		int tmp = 0;
		if(e.get(i) == base + '0'
		   && e.get(i+1) == base + '0'
		   && e.get(i+2) == base + '0'){
		    tmp |= (1<<i);
		    tmp |= (1<<(i+1));
		    tmp |= (1<<(i+2));
		    res.add(tmp);
		    //System.out.println(e.get(i));
		}
	    }
	    //System.out.println(res);
	}
	return res;
    }

    boolean fillShuntsu(ArrayList<Character> e,int visited){
	
	for(int i=0;i<e.size();i++){
	    int count = 0;
	    if((visited & (1<<i)) > 0) continue;
	    int tmp = visited;
	    int first = e.get(i);
	    count++;
	    tmp |= (1<<i);
	    for(int j=i+1;j<e.size();j++){
		if((visited & (1<<j)) > 0) continue;
		if(first + 1 == e.get(j)
		   && (tmp & (1<<j)) == 0
		   && count == 1){
		    tmp |= (1<<j);
		    count++;
		}
		if(first + 2 == e.get(j)
		   && (tmp & (1<<j)) == 0
		   && count == 2){
		    tmp |= (1<<j);
		    count++;
		    break;
		    
		}
		if(first + 2 < e.get(j)){
		    count = 0;
		    break;
		}
	    }

	    if(count == 3){
		visited = tmp;
	    }
	}
	//System.out.println(res);
	return (visited == ((1<<14)-1));
    }

    public static void main(String args[]){
	new Main().run();
    }
}