Language: C++

#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-6;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int32 add(int32 a, int32 b){
	if(a == 1 && b == 1) return 1;
	return min(2, a+b);
}

int32 mul(int32 a, int32 b){
	if(a*b == 0) return 0;
	if(a == 1 || b == 1) return 1;
	return 2;
}

int32 nnot(int32 a){
	return 2-a;
}

int32 val[3];

int32 eval(string s){
	if(s.size() == 1 && '0' <= s[0] && s[0] <= '3') return s[0]-'0';
	if(s.size() == 1) return val[s[0]-'P'];
	if(s[0] == '-') return nnot(eval(s.substr(1, s.size()-1)));
	int32 now = 0;
	REP(i, s.size()){
		if(s[i] == '(') now++;
		if(s[i] == ')') now--;
		if(now == 1 && s[i] == '+') return add(eval(s.substr(1, i-1)), eval(s.substr(i+1, s.size()-i-2)));
		if(now == 1 && s[i] == '*') return mul(eval(s.substr(1, i-1)), eval(s.substr(i+1, s.size()-i-2)));
	}
}

int main(void){
	string s;
	while(cin >> s && s != "."){
		int32 res = 0;
		REP(i, 3){
			REP(j, 3){
				REP(k, 3){
					val[0] = i; val[1] = j; val[2] = k;
					if(eval(s) == 2) res++;
				}
			}
		}
		cout << res << endl;
	}
}


Compiler output:
a.cc: In function 'int32 add(int32, int32)':
a.cc:28:19: error: no matching function for call to 'min(int, int32)'
   28 |         return min(2, a+b);
      |                ~~~^~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:28:19: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'int32' {aka 'long int'})
   28 |         return min(2, a+b);
      |                ~~~^~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:28:19: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   28 |         return min(2, a+b);
      |                ~~~^~~~~~~~
a.cc: In function 'int32 eval(std::string)':
a.cc:54:1: warning: control reaches end of non-void function [-Wreturn-type]
   54 | }
      | ^