using System;
using System.Collections.Generic;
using System.Linq;

namespace P0043_Puzzle
{
    class Program
    {
        static void Main(string[] args)
        {
            string readLine;
           
            var rList = new List<List<string>>();

            do
            {
                int[] p = new int[10];
                var r = new List<string>();

                readLine = Console.ReadLine();
                if (readLine != null)
                {
                    for (int i = 0; i < 13; i++)
                    {
                        int num = int.Parse(readLine.Substring(i, 1));
                        p[num]++;
                    }

                    for (int i = 1; i <= 9; i++) 
                    {

                        int[] pWork = new int[10];
                        for (int j = 1; j <= 9; j++)
                        {
                            pWork[j] = p[j];
                        }

                        pWork[i]++;

                        if (pWork[i] == 5)
                        {
                            continue;
                        }

                        for (int jt = 1; jt <= 9; jt++)
                        {
                            int[] pWork2 = new int[10];
                            for (int j = 1; j <= 9; j++)
                            {
                                pWork2[j] = pWork[j];
                            }

                            if(pWork2[jt] >= 2)
                            {
                                pWork2[jt] -= 2;
                            }
                            else 
                            {
                                continue;
                            }


                                for (int sa = 1; sa <= 9; sa++) 
                                {
                                    for (int k = 1; k <= 4; k++)
                                    {
                                    if (pWork2[sa] >= 3) 
                                    {
                                        pWork2[sa] -= 3;
                                    }

                                    if (sa <= 7 && pWork2[sa] >= 1 && pWork2[sa + 1] >= 1 && pWork2[sa + 2] >= 1) 
                                    {
                                        pWork2[sa] -= 1;
                                        pWork2[sa + 1] -= 1;
                                        pWork2[sa + 2] -= 1;
                                    }
                                }
                            }

                            if (pWork2.Max() == 0) 
                            {
                                r.Add(i.ToString());
                                //Console.WriteLine(i);
                                break;
                            }

                            
                        }


                    }

                    if (r.Count == 0)
                    {
                        r.Add("0");
                    }

                    rList.Add(r);
                }
                


            }
            while (readLine != null);

            foreach(var rr in rList)
            {
                Console.WriteLine(string.Join(" ",rr.ToArray()));
            }

        }
    }
}

Measured memory_bytes: 5976