logo AlgoBeat OnlineJudge
登录 注册

#217805. [JAG 2026 Summer Camp #3] ABbreviation

内存限制:2048 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given a string consisting of A and B.

You may perform the following operation on any number of times, possibly zero.

  • Choose an occurrence of AB as a contiguous substring of , and replace these two characters with a single uppercase English letter (one of A through Z) of your choice. If the replacement letter is A or B, it may be used as part of AB in a later operation.

For example, if is AAB, you may replace the last two characters AB with C, resulting in AC. If you replace them with B instead, the resulting string is AB, on which you may perform the operation again.

Find the number of distinct strings that can be obtained from by performing the operation any number of times.

Since the answer may be large, print it modulo .

输入格式

The input consists of a single test case of the following format.

N
S

The first line contains an integer (), representing the length of .

The second line contains a string of length consisting of A and B.

输出格式

Print a single integer representing the number of distinct strings that can be obtained, modulo .

样例

样例输入 1

4
AABB

样例输出 1

104

样例输入 2

1
A

样例输出 2

1

样例输入 3

17
ABBABABAAABBAABBB

样例输出 3

894459821