Language: C++

////////////////////////////////////////
///  tu3 pro-con template            ///
////////////////////////////////////////
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <regex>
using namespace std;

//// MACRO ////
#define countof(a) (sizeof(a)/sizeof(a[0]))

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define RFOR(i,s,n) for (int i = (n)-1; i >= (s); i--)
#define pos(c,i) c.being() + (i)
#define allof(c) c.begin(), c.end()
#define aallof(a) a, countof(a)
#define partof(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define apartof(a,i,n) a + (i), a + (i) + (n)
#define long long long

#define EPS 1e-9
#define INF (1L << 30)
#define LINF (1LL << 60)

//// i/o helper ////

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
struct _Writer { bool f; _Writer() : f(false) { } template <class T> _Writer operator ,(const T &rhs) { cout << (f ? " " : "") << rhs; f = true; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__
#define WRITE(...) _Writer(), __VA_ARGS__; cout << endl


//// algorithm ////

// 文字列の置換
void inplaceReplace(string &target, const string &from, const string &to, bool global = false)
{
	do
	{
		string::size_type pos = target.find(from);
		if (pos == target.npos) { break; }
		target.replace(pos, from.length(), to);
	} while (true);
}

// 文字列の分割
vector<string> split(const string &str, const string &s, bool removeEmpty = false)
{
	vector<string> ret;
	size_t p = 0, sl = s.size();
	while (true)
	{
		size_t q = str.find(s, p);
		if (q == str.npos) break;
		ret.push_back(str.substr(p, q - p));
		p = q + sl;
	}
	ret.push_back(str.substr(p));
	if (removeEmpty) ret.erase(remove(allof(ret), string()), ret.end());
	return ret;
}

// 対応する括弧のインデクス
int findbrace(const string &str, int l)
{
	stack<char> stack;
	FOR(i, l, str.size())
	{
		switch (str[i])
		{
#define CASE(x,y) case x: stack.push(str[i]); break; case y: if(stack.top() != x) return -2; stack.pop(); break
			CASE('(', ')');
			CASE('[', ']');
			CASE('<', '>');
			CASE('{', '}');
#undef  CASE
		}
		if (stack.size() == 0) return i;
	}
	return -1;
}

//// start up ////
void solve();
int main()
{
	solve();
	return 0;
}

////////////////////
/// template end ///
////////////////////

set<int> eval(const string &str, int l, int r)
{
	vector<set<int>> operands;
	vector<char> operators(1);

	// 式を読む
	int val = 0;
	FOR(p, l, r)
	{
		if (isdigit(str[p]))
		{
			val = val * 10 + str[p] - '0';
		}
		else if (str[p] == '(')
		{
			operands.push_back(eval(str, p + 1, findbrace(str, p)));
			p = findbrace(str, p);
			val = -1;
		}
		else
		{
			if (val >= 0)
			{
				operands.push_back(set<int>({ val }));
			}
			val = 0;
			operators.push_back(str[p]);
		}
	}
	
	if (val >= 0)
	{
		operands.push_back(set<int>({ val }));
		val = 0;
	}

	set<int> result;

	// よんだ
	int n = operands.size();
	vector<vector<set<int> > > dp(n + 1, vector<set<int>>(n + 1)); // [l][r] 範囲[l,r)のオペランドを計算して出てくる整数セット
	
	REP(i, n) dp[i][i + 1] = operands[i];
	FOR(i, 2, n + 1) // 統合幅
	{
		REP(j, n - i + 1) // 始点 j から i 文字
		{
			FOR(k, 1, i) // jからk文字と j+kからi-k文字
			{
				int s = j;
				int m = j + k;
				int e = j + i;
				// WRITE("sme", s, m, e);
		
				// 演算
				for (int x : dp[s][m]) for (int y : dp[m][e])
				{
					switch (operators[m])
					{
					case '+': dp[s][e].insert(x + y); break;
					case '-': dp[s][e].insert(x - y); break;
					case '*': dp[s][e].insert(x * y); break;
					case '/': if (y) dp[s][e].insert(x / y); break;
					}
				}
			}
		}
	}
	return memo[0][n];
}

void solve()
{
	int testcases = INF;
	REP(testcase, testcases)
	{
		READ(string, expr);
		if (expr == "#") { break; }
		WRITE(eval(expr, 0, expr.size()).size());
	}
}

Compiler output:
a.cc: In function 'std::set<int> eval(const std::string&, int, int)':
a.cc:183:16: error: 'memo' was not declared in this scope
  183 |         return memo[0][n];
      |                ^~~~