ABC Supremacy

AtCoder
IDagc055_b
Time2000ms
Memory256MB
Difficulty
You are given a string $S$ of length $N$, consisting of `A`, `B`, and `C`. You are allowed to perform the following operation any number of times: * Choose any $i$ with $1 \le i \le N-2$, such that $S_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 $T$ from string $S$ with some finite (maybe zero) number of operations above. ## Constraints * $3\le N \le 5\cdot 10^5$ * $S$ is a string of length $N$ consisting of `A`, `B`, and `C`. * $T$ is a string of length $N$ consisting of `A`, `B`, and `C`. ## Input Input is given from Standard Input in the following format: $N$ $S$ $T$ [samples]
Samples
Input #1
4
AABC
BCAA
Output #1
YES

This example was explained in the statement.
Input #2
4
ABCA
BCAB
Output #2
NO
API Response (JSON)
{
  "problem": {
    "name": "ABC Supremacy",
    "description": {
      "content": "You are given a string $S$ of length $N$, consisting of `A`, `B`, and `C`. You are allowed to perform the following operation any number of times: *   Choose any $i$ with $1 \\le i \\le N-2$, such that",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "agc055_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You are given a string $S$ of length $N$, consisting of `A`, `B`, and `C`. You are allowed to perform the following operation any number of times:\n\n*   Choose any $i$ with $1 \\le i \\le N-2$, such that...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments