#include <cstdio>
#include <iostream>
#include <string>

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

struct hc{int c[10];};
hc ina;
//int mm[6][[10];

int calc(hc a, int mc)
{
  int ret=0;
  rep(j,4-mc) printf("   ");
  printf("calc called ");
  rep(j,mc) printf("   ");
  rep(i,10) {
    printf("%d ", a.c[i]);
  }
  printf("\n\n");
  if(!mc){
    rep(i,10)
      if(a.c[i]==2 && ina.c[i] < 4)
        ret++;
  }
  else{
    rep(i,10) if(a.c[i]>=3){
      hc tmp=a;tmp.c[i]-=3;
      ret+=calc(tmp,mc-1);
    }
    rep(i,8) if(a.c[i]*a.c[i+1]*a.c[i+2]>0){
      hc tmp=a;
      tmp.c[i]-=1;
      tmp.c[i+1]-=1;
      tmp.c[i+2]-=1;
      ret+=calc(tmp,mc-1);
    }
  }
  rep(j,4-mc) printf("   ");
  printf("calc return ");
  rep(j,mc) printf("   ");
  printf("%d ", ret);
  printf("\n\n");
  return ret;
}

int main()
{
  char str[15];
  int count=0;
  while(scanf(" %s",str)==1 && *str) {
    rep(i,10) ina.c[i]=0;
    rep(i,13) ina.c[str[i]-'0']++;
    printf("%d:\n",count++);
    rep(i,10)
      printf("%d: %d\n", i, ina.c[i]);
    printf("\n");
    hc ret; rep(i,10)ret.c[i]=0;
    for(int i=1; i<10; i++)
      if(ina.c[i]<4){
        hc tmp=ina;
        tmp.c[i]+=1;
        ret.c[i]=calc(tmp,4);
      }
    
    string s;
    rep(i,10)
      if(ret.c[i]){
        s+=i+'0';
        s+=" ";
      }
    if(s.size()){
      s.erase(s.end()-1);
      cout << s << endl;
    }else{
      cout << "0" << endl;
    }
  }
  return 0;
}