Problem:
Score : 100 points

Problem Statement

AtCoder Inc. holds a contest every Saturday.

There are two types of contests called ABC and ARC, and just one of them is held at a time.

The company holds these two types of contests alternately: an ARC follows an ABC and vice versa.

Given a string S representing the type of the contest held last week, print the string representing the type of the contest held this week.

Constraints

S is ABC or ARC.

Input

Input is given from Standard Input in the following format:

S

Output

Print the string representing the type of the contest held this week.

Sample Input 1

ABC

Sample Output 1

ARC

They held an ABC last week, so they will hold an ARC this week.

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+7;
typedef long long ll;
string s[N];
ll n; 
char ans[N];
bool flag=0;
void  dfs(ll x,ll a,ll b,ll c){
	if(flag||a<0||b<0||c<0) return ;
	if(x>n){
		if(flag) return ;
		flag=1;
		puts("Yes");
		for(ll i=1;i<=n;i++) cout<<ans[i]<<endl;
		return ;
	}
	if(s[x]=="AB"){
		if(a>b) {
			if(a==0) return ;
			a--;b++;
			ans[x]='B';
			dfs(x+1,a,b,c);
		}
		else if(a<b){
			if(b==0) return ;
			a++;b--;
			ans[x]='A';
			dfs(x+1,a,b,c);
		}
		else{
			for(ll i=0;i<=1;i++){
				if(i==0) {
					if(b==0) continue ;
//					a++;b--;
					int a1=a+1;
					int b1=b-1;
					ans[x]='A';
					dfs(x+1,a1,b1,c);
				}
				else {
					if(a==0) continue ;
//					a--;b++;
					int a1=a-1;
					int b1=b+1;
					ans[x]='B';
					dfs(x+1,a1,b1,c);
				}
				
			}
		}
	}
	else if(s[x]=="AC"){
		if(a>c) {
			if(a==0) return ;
			a--;
			c++;
			ans[x]='C';
			dfs(x+1,a,b,c);
		}
		else if(a<c){
			if(c==0) return ; 
			a++;
			c--;
			ans[x]='A';
			dfs(x+1,a,b,c);
		}
		else{
			for(ll i=0;i<=1;i++){
				if(i==0) {
					if(c==0) continue ;
					int a1=a+1;
					int c1=c-1;
					ans[x]='A';
					dfs(x+1,a1,b,c1);
				}
				else {
					if(a==0) continue ;
//					a--;c++;
					int a1=a-1;
					int c1=c+1;
					ans[x]='C';
					dfs(x+1,a1,b,c1);
				}
			}
		}
	}
	else {
		if(b>c) {//ab  bc 
			if(b==0) return  ;
			b--;
			c++;
			ans[x]='C';
			dfs(x+1,a,b,c);
		}
		else if(a<b){
			if(c==0) return ;
			b++;
			c--;
			ans[x]='B';
			dfs(x+1,a,b,c);
		}
		else{
			for(ll i=0;i<=1;i++){
				if(i==0) {
					if(c==0) continue ;
//					b++;c--;
					int b1=b+1;
					int c1=c-1;
					ans[x]='B';
					dfs(x+1,a,b1,c1);
				}
				else {
					if(b==0) continue ;
//					b--;c++;
					int b1=b-1;
					int c1=c+1;
					ans[x]='C';
					dfs(x+1,a,b1,c1);
				}
			}
		}
	} 
	
}
int main(){
	ios::sync_with_stdio(0);
	ll a,b,c;
	cin>>n>>a>>b>>c;
	for(ll i=1;i<=n;i++) cin>>s[i];
	dfs(1,a,b,c);
	if(!flag){
		puts("No");
	}
	return 0;
}