atcoder#AGC055B. [AGC055B] ABC Supremacy

[AGC055B] ABC Supremacy

Score : 700700 points

Problem Statement

You are given a string SS of length NN, consisting of A, B, and C. You are allowed to perform the following operation any number of times:

  • Choose any ii with 1iN21 \le i \le N-2, such that SiSi+1Si+2S_iS_{i+1}S_{i+2} is equal to ABC, BCA, or CAB. Then, replace the three characters with ABC, BCA, or CAB.

For example, you can perform the following transformations with string AABC:

  • AABC \to ABCA \to BCAA

Determine if you can obtain string TT from string SS with some finite (maybe zero) number of operations above.

Constraints

  • 3N51053\le N \le 5\cdot 10^5
  • SS is a string of length NN consisting of A, B, and C.
  • TT is a string of length NN consisting of A, B, and C.

Input

Input is given from Standard Input in the following format:

NN

SS

TT

Output

If you can transform SS into TT with the operations above, output YES, otherwise output NO. The checker is case-insensitive: you can use either uppercase or lowercase letters.

4
AABC
BCAA
YES

This example was explained in the statement.

4
ABCA
BCAB
NO