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;
int main () {
  long long N, A, B, C;
  cin >> N >> A >> B >> C;
  string s;
  cin >> s;
  if (!(A + B) && s == "AB") {
    cout << "No" << endl;
    return 0;
  }
  if (!(B + C) && s == "BC") {
    cout << "No" << endl;
    return 0;
  }
  if (!(C + A) && s == "AC") {
    cout << "No" << endl;
    return 0;
  }
  if (A + B + C >= 3) {
    cout << "Yes" << endl;
    if (s == "AB") {
      cout << (A < B ? 'A' : 'B') << endl;
    }
    if (s == "BC") {
      cout << (B < C ? 'B' : 'C') << endl;
    }
    if (s == "AC") {
      cout << (C < A ? 'C' : 'A') << endl;
    }
    for (int i = 0; i < N - 1; i ++) {
      string S;
      cin >> S;
      if (S == "AB") {
        cout << (A < B ? 'A' : 'B') << endl;
      }
      if (S == "BC") {
        cout << (B < C ? 'B' : 'C') << endl;
      }
      if (S == "AC") {
        cout << (C < A ? 'C' : 'A') << endl;
      }
    }
    return 0;
  }
  vector<string>ch(N);
  ch[0] = s;
  for (int i = 1; i < N; i ++) cin >> ch[i];
  vector<char>ans(N);
  for (int i = 0; i < N; i ++) {
    string b = ch[i];
    if (!(A + B) && b == "AB") {
      cout << "No" << endl;
      return 0;
    }
    if (!(B + C) && b == "BC") {
      cout << "No" << endl;
      return 0;
    }
    if (!(C + A) && b == "AC") {
      cout << "No" << endl;
      return 0;
    }
    if (b == "AB") {
      if (A < B) ans[i] = 'A';
      if (B < A) ans[i] = 'B';
      if (A == B) {
        if (i == N - 1) ans[i] = 'A';
        else {
          string b_ = ch[i + 1];
          if (b_ == "AB") ans[i] = 'A';
          if (b_ == "BC") ans[i] = 'B';
          if (b_ == "AC") ans[i] = 'A';
        }
      }
      if (ans[i] == 'A') {
        A ++;
        B --;
      }
      else {
        A --;
        B ++;
      }
    }
    if (b == "BC") {
      if (C < B) ans[i] = 'C';
      if (B < C) ans[i] = 'B';
      if (C == B) {
        if (i == N - 1) ans[i] = 'C';
        else {
          string b_ = ch[i + 1];
          if (b_ == "AB") ans[i] = 'B';
          if (b_ == "BC") ans[i] = 'B';
          if (b_ == "AC") ans[i] = 'C';
        }
      }
      if (ans[i] == 'C') {
        C ++;
        B --;
      }
      else {
        C --;
        B ++;
      }
    }
    if (b == "AC") {
      if (A < C) ans[i] = 'A';
      if (C < A) ans[i] = 'C';
      if (A == C) {
        if (i == N - 1) ans[i] = 'A';
        else {
          string b_ = ch[i + 1];
          if (b_ == "AB") ans[i] = 'A';
          if (b_ == "BC") ans[i] = 'C';
          if (b_ == "AC") ans[i] = 'A';
        }
      }
      if (ans[i] == 'A') {
        A ++;
        C --;
      }
      else {
        A --;
        C ++;
      }
    }
  }
  cout << "Yes" << endl;
  for (int i = 0; i < N; i ++) cout << ans[i] << endl;
}