Language: C++

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

#define MAX_N 10000

int bit(int C1,bool C2);
int minus(int C3);
int kake(int C4,int C5);
int plus(int C6,int C7);
string tstring(int C8);

string S,T;
int sum;
char U[4]="012";
int x[MAX_N];

int bit(int C1,bool C2){
	if(C2==true){return C1;}
	return minus(C1);
}

int minus(int C3){
	return 2-C3;
}
int plus(int C4,int C5){
	return max(C4,C5);
}
int kake(int C6,int C7){
	return max(C6,C7);
}

string tstring(int C8)
{
	if(C8==0)
	{
		return "0";
	}
	if(C8==1)
	{
		return "1";
	}
	return "2";
}

int kaiseki2(string Z){
	int ans=3,ans2=3;
	bool ok=true;
	char op=' ';
	for(int i=0;i<Z.size();i++)
	{
		if(Z[i]=='-')
		{
			if(ok==true){ok=false;}
			if(ok==false){ok=true;}
		}
		if(ans==3){
			if(Z[i]=='0')
			{
				ans=bit(0,ok);
				ok=true;
			}
			if(Z[i]=='1')
			{
				ans=bit(1,ok);
				ok=true;
			}
			if(Z[i]=='2')
			{
				ans=bit(2,ok);
				ok=true;
			}
		}
		else{
			if(Z[i]=='0')
			{
				ans2=bit(0,ok);
				ok=true;
			}
			if(Z[i]=='1')
			{
				ans2=bit(1,ok);
				ok=true;
			}
			if(Z[i]=='2')
			{
				ans2=bit(2,ok);
				ok=true;
			}
		}
		if(Z[i]=='+')
		{
			op='+';
		}
		if(Z[i]=='*')
		{
			op='*';
		}
	}
	if(op==' '){return ans;}
	if(op=='+'){return plus(ans,ans2);}
	return kake(ans,ans2);
}

int kaiseki(string V){
	while(V.size()>=2)
	{
		int s=0,maxn=0;
		string W="",X="";
		for(int i=0;i<V.size();i++)
		{
			if(V[i]=='(')
			{
				s++;
			}
			if(V[i]==')')
			{
				s--;
			}
			x[i]=s;
			maxn=max(s,maxn);
		}
		for(int i=0;i<V.size();i++)
		{
			if(x[i]==maxn)
			{
				if(V[i]!='(')
				{
					W+=V[i];
				}
				goto E;
			}
			if(i>=1)
			{
				if(x[i-1]==maxn)
				{
					X+=tstring((long long)kaiseki2(W));
					W="";
					goto E;
				}
			}
			X+=V[i];
E:;
		}
	}
	if(V=="2"){return 1;}
	return 0;
}

int main(){
	while(true){
		cin>>S;
		sum=0;
		if(S=="."){break;}
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				for(int k=0;k<3;k++)
				{
					T="";
					for(int l=0;l<S.size();l++)
					{
						if(S[l]=='P')
						{
							T+=U[i];
						}
						else if(S[l]=='Q')
						{
							T+=U[j];
						}
						else if(S[l]=='R')
						{
							T+=U[k];
						}
					}
					sum+=kaiseki(T);
				}
			}
		}
		cout<<sum<<endl;
	}
}

Compiler output:
a.cc: In function 'int bit(int, bool)':
a.cc:21:16: error: reference to 'minus' is ambiguous
   21 |         return minus(C1);
      |                ^~~~~
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:5: note:                 'int minus(int)'
    9 | int minus(int C3);
      |     ^~~~~
a.cc: In function 'int kaiseki2(std::string)':
a.cc:102:28: error: reference to 'plus' is ambiguous
  102 |         if(op=='+'){return plus(ans,ans2);}
      |                            ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:27:5: note:                 'int plus(int, int)'
   27 | int plus(int C4,int C5){
      |     ^~~~