Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 4005;

int x, y, z;
string s;

int dp[51][51][51][51];
int link[51][3]; // -1 if failure, otherwise follow it's next
int fail[51];

bool rend[MAXN];

bool f(int x, int y, int z, int m){
	if(m == s.size()) m = fail[m];
	if(x + y + z == 0) return rend[m];
	if(~dp[x][y][z][m]) return dp[x][y][z][m];
	int ret = 0;
	if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
	if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
	if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
	return dp[x][y][z][m] = ret;
}

bool trial(){
	int p = 0;
	for(int i=1; i<s.size(); i++){
		while(p && s[i] != s[p]) p = fail[p];
		if(s[i] == s[p]) p++;
		fail[i+1] = p;
	}
	for(int i=0; i<s.size(); i++){
		for(int j=0; j<3; j++){
			int pos = i;
			if(s[i] > j + 'a'){
				link[i][j] = -1;
				continue;
			}
			while(pos && s[pos] != j + 'a') pos = fail[pos];
			if(s[pos] == j + 'a') pos++;
			link[i][j] = pos;
		}
	}
	for(int i=0; i<s.size(); i++){
		int pos = i;
		rend[i] = 1;
		for(int j=0; j<s.size(); j++){
			pos = link[pos][s[j] - 'a'];
			if(pos == -1){
				rend[i] = 0;
				break;
			}
		}
	}
	memset(dp, -1, sizeof(dp));
	return f(x, y, z, 0);
}

int main(){
	cin >> x >> y >> z;
	while(s.size() < x + y + z){
		s.push_back('c');
		if(trial()) continue;
		s.back() = 'b';
		if(trial()) continue;
		s.back() = 'a';
	}
	cout << s << endl;
}


Compiler output:
a.cc:12:15: error: 'int link [51][3]' redeclared as different kind of entity
   12 | int link[51][3]; // -1 if failure, otherwise follow it's next
      |               ^
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:1:
/usr/include/unistd.h:819:12: note: previous declaration 'int link(const char*, const char*)'
  819 | extern int link (const char *__from, const char *__to)
      |            ^~~~
a.cc: In function 'bool f(int, int, int, int)':
a.cc:19:35: error: reference to 'rend' is ambiguous
   19 |         if(x + y + z == 0) return rend[m];
      |                                   ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52:
/usr/include/c++/14/bits/range_access.h:227:5: note: candidates are: 'template<class _Tp> constexpr std::reverse_iterator<const _Tp*> std::rend(initializer_list<_Tp>)'
  227 |     rend(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:205:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr std::reverse_iterator<_Tp*> std::rend(_Tp (&)[_Nm])'
  205 |     rend(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:183:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(const _Container&)'
  183 |     rend(const _Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:172:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(_Container&)'
  172 |     rend(_Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
a.cc:15:6: note:                 'bool rend [4005]'
   15 | bool rend[MAXN];
      |      ^~~~
a.cc:22:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   22 |         if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
      |                  ^
a.cc:22:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   22 |         if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
      |                     ^
a.cc:22:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   22 |         if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
      |            ~~~~~~~~~~~^~~~~
a.cc:22:56: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   22 |         if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
      |                                                        ^
a.cc:22:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   22 |         if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
      |                                                           ^
a.cc:22:59: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   22 |         if(link[m][0] != -1 && x && f(x-1, y, z, link[m][0])) ret = 1;
      |                                                  ~~~~~~~~~^
      |                                                           |
      |                                                           int (*)(const char*, const char*) noexcept
a.cc:17:33: note:   initializing argument 4 of 'bool f(int, int, int, int)'
   17 | bool f(int x, int y, int z, int m){
      |                             ~~~~^
a.cc:23:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |         if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
      |                  ^
a.cc:23:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |         if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
      |                     ^
a.cc:23:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   23 |         if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
      |            ~~~~~~~~~~~^~~~~
a.cc:23:56: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |         if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
      |                                                        ^
a.cc:23:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |         if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
      |                                                           ^
a.cc:23:59: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   23 |         if(link[m][1] != -1 && y && f(x, y-1, z, link[m][1])) ret = 1;
      |                                                  ~~~~~~~~~^
      |                                                           |
      |                                                           int (*)(const char*, const char*) noexcept
a.cc:17:33: note:   initializing argument 4 of 'bool f(int, int, int, int)'
   17 | bool f(int x, int y, int z, int m){
      |                             ~~~~^
a.cc:24:18: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |         if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
      |                  ^
a.cc:24:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |         if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
      |                     ^
a.cc:24:23: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   24 |         if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
      |            ~~~~~~~~~~~^~~~~
a.cc:24:56: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |         if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
      |                                                        ^
a.cc:24:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |         if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
      |                                                           ^
a.cc:24:59: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   24 |         if(link[m][2] != -1 && z && f(x, y, z-1, link[m][2])) ret = 1;
      |                                                  ~~~~~~~~~^
      |                                                           |
      |                                                           int (*)(const char*, const char*) noexcept
a.cc:17:33: note:   initializing argument 4 of 'bool f(int, int, int, int)'
   17 | bool f(int x, int y, int z, int m){
      |                             ~~~~^
a.cc: In function 'bool trial()':
a.cc:39:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   39 |                                 link[i][j] = -1;
      |                                       ^
a.cc:39:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   39 |                                 link[i][j] = -1;
      |                                          ^
a.cc:39:44: error: assignment of read-only location '*(link + (((sizetype)i) + ((sizetype)j)))'
   39 |                                 link[i][j] = -1;
      |                                 ~~~~~~~~~~~^~~~
a.cc:44:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   44 |                         link[i][j] = pos;
      |                               ^
a.cc:44:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   44 |                         link[i][j] = pos;
      |                                  ^
a.cc:44:36: error: assignment of read-only location '*(link + (((sizetype)i) + ((sizetype)j)))'
   44 |                         link[i][j] = pos;
      |                         ~~~~~~~~~~~^~~~~
a.cc:49:17: error: reference to 'rend' is ambiguous
   49 |                 rend[i] = 1;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:227:5: note: candidates are: 'template<class _Tp> constexpr std::reverse_iterator<const _Tp*> std::rend(initializer_list<_Tp>)'
  227 |     rend(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:205:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr std::reverse_iterator<_Tp*> std::rend(_Tp (&)[_Nm])'
  205 |     rend(_Tp (&__arr)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:183:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(const _Container&)'
  183 |     rend(const _Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:172:5: note:                 'template<class _Container> constexpr decltype (__cont.rend()) std::rend(_Container&)'
  172 |     rend(_Container& __cont) -> decltype(__cont.rend())
      |     ^~~~
a.cc:15:6: note:                 'bool rend [4005]'
   15 | bool rend[MAXN];
      |      ^~~~
a.cc:51:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   51 |                         pos = link[pos][s[j] - 'a'];
      |                                       ^
a.cc:51:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   51 |                         pos = link[pos][s[j] - 'a'];
      |                                                   ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:51:51: error: invalid conversion from 'int (*)(const char*, const char*) noexcept' to 'int' [-fpermissive]
   51 |                         pos = link[pos][s[j] - 'a'];
      |                               ~~~~~~~~~~~~~~~~~~~~^
      |                                                   |
      |                                                   int (*)(const char*, const char*) noexcept
a.cc:53:33: error: reference to 'rend' is ambiguous
   53 |