#ARC110E. [ARC110E] Shorten ABC

[ARC110E] Shorten ABC

Score : 800800 points

Problem Statement

We have a string SS of length NN consisting of A, B, and C.

You can do the following operation on SS zero or more times:

  • Choose ii (1iS1)(1 \leq i \leq |S| - 1) such that SiSi+1S_i \neq S_{i + 1}. Replace SiS_i with the character (among A, B, and C) that is different from both SiS_i and Si+1S_{i + 1}, and remove Si+1S_{i + 1} from SS.

Find the number of distinct strings that SS can be after zero or more operations, and print the count modulo (109+7)(10^9+7).

Constraints

  • 1N1061 \leq N \leq 10^6
  • SS 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

Output

Print the number of distinct strings that SS can be after zero or more operations, modulo (109+7)(10^9+7).

5
ABAAC
11

For example, the following sequence of operations turns SS into ACB:

  • First, choose i=2i=2. We replace S2S_2 with C and remove S3S_3, turning SS into ACAC.
  • Then, choose i=3i=3. We replace S3S_3 with B and remove S4S_4, turning SS into ACB.
50
AACCCCBBBACCCCABABCCCCABACCACACACCACABABBBABABACCB
256972022