Language: C++

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int* minus(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
	int x;
	if(v1.size() > a) {
		x = v1[a];
		n[x]--, n[x+1]--, n[x+2]--;
	} else {
		x = v2[a - v1.size()];
		rep(j,3) n[x]--;
	}
	return n;
}

bool judge(int j, int k, int l, int m, vector<int> v1, vector<int> v2, int *n) {
	int nn[10];
	rep(i,10) {
		nn[i] = n[i];
	}
	minus(j,v1,v2, nn);
	minus(k,v1,v2, nn);
	minus(l,v1,v2, nn);
	minus(m,v1,v2, nn);
	bool f = 0;
	rep(i,10) {
		if(nn[i] < 0) {
			f = 0;
			break;
		}
		if(nn[i] == 2) f = 1;
	}
	if(f) return true;
	return false;
}
int main() {
	string s;
	while(cin >> s) {
		bool bl = 1;
		int n[10];
		rep(i,10) {
			n[i] = 0;
		}
		rep(i,s.length()) {
			n[s[i] - '0']++;
		}
		rep2(i,1,10) {
			n[i]++;
			bool f = 0;
			rep(j,10) {
				if(n[j] > 4) f = 1;
			}
			if(f) {
				n[i]--;
				continue;
			}
			vector<int> v1;
			rep2(j,1,8) {
				int c = min(n[j],min(n[j+1], n[j+2]));
				if(c > 0) {
					rep(k,c) {
						v1.push_back(j);
					}
				}
			}
			vector<int> v2;
			rep2(j,1,10) {
				if(n[j] >= 3) v2.push_back(j);
			}
			int len = v1.size() + v2.size();
			f = 0;
			rep(j,len) {	
				rep2(k,j+1,len) {
					rep2(l,k+1,len) {
						rep2(m,l+1,len) {
							if(judge(j, k, l, m, v1, v2, n)) {
								bl = 0;
								if(i != 9) cout << i << " " ;
								else cout << i;
								f = 1;
								break;
							}
						}
						if(f) break;
					}
					if(f) break;
				}
				if(f) break;
			}
			n[i]--;
		}
		if(bl) cout << 0 << endl;
		else cout << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'bool judge(int, int, int, int, std::vector<int>, std::vector<int>, int*)':
a.cc:26:9: error: reference to 'minus' is ambiguous
   26 |         minus(j,v1,v2, nn);
      |         ^~~~~
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:9:6: note:                 'int* minus(int, std::vector<int>, std::vector<int>, int (&)[10])'
    9 | int* minus(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
      |      ^~~~~
a.cc:27:9: error: reference to 'minus' is ambiguous
   27 |         minus(k,v1,v2, nn);
      |         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:9:6: note:                 'int* minus(int, std::vector<int>, std::vector<int>, int (&)[10])'
    9 | int* minus(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
      |      ^~~~~
a.cc:28:9: error: reference to 'minus' is ambiguous
   28 |         minus(l,v1,v2, nn);
      |         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:9:6: note:                 'int* minus(int, std::vector<int>, std::vector<int>, int (&)[10])'
    9 | int* minus(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
      |      ^~~~~
a.cc:29:9: error: reference to 'minus' is ambiguous
   29 |         minus(m,v1,v2, nn);
      |         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:9:6: note:                 'int* minus(int, std::vector<int>, std::vector<int>, int (&)[10])'
    9 | int* minus(int a, vector<int> v1, vector<int> v2, int (&n)[10]) {
      |      ^~~~~