Codeforces Round 295 (Div. 1)
A
DNA Alignment
Codeforces
未评级
原题
←B →
翻译中…

Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

翻译中…

Let's assume that strings $*s*$ and $*t*$ have the same length $*n*$, then the function $*h*(*s*, *t*)$ is defined as the number of positions in which the respective symbols of $*s*$ and $*t*$ are the same. Function $*h*(*s*, *t*)$ can be used to define the function of Vasya distance $ρ(*s*, *t*)$:

翻译中…

image

翻译中…

where

翻译中…

image

翻译中…

is obtained from string

翻译中…

s

翻译中…

, by applying left circular shift

翻译中…

i

翻译中…

times. For example,

翻译中…

$ρ("*AGC*", "*CGT*") =$

翻译中…

$*h*("*AGC*", "*CGT*") + *h*("*AGC*", "*GTC*") + *h*("*AGC*", "*TCG*") +$

翻译中…

$*h*("*GCA*", "*CGT*") + *h*("*GCA*", "*GTC*") + *h*("*GCA*", "*TCG*") +$

翻译中…

$*h*("*CAG*", "*CGT*") + *h*("*CAG*", "*GTC*") + *h*("*CAG*", "*TCG*") =$

翻译中…

$1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6$

翻译中…

Vasya found a string $*s*$ of length $*n*$ on the Internet. Now he wants to count how many strings $*t*$ there are such that the Vasya distance from the string $*s*$ attains maximum possible value. Formally speaking, $*t*$ must satisfy the equation: image.

翻译中…

Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo $10^{9} + 7$.

翻译中…

Input

翻译中…

The first line of the input contains a single integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$).

翻译中…

The second line of the input contains a single string of length $*n*$, consisting of characters "ACGT".

翻译中…

Output

翻译中…

Print a single number — the answer modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

Please note that if for two distinct strings $*t*_{1}$ and $*t*_{2}$ values $ρ(*s*, *t*_{1})$ и $ρ(*s*, *t*_{2})$ are maximum among all possible $*t*$, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

翻译中…

In the first sample, there is $ρ("*C*", "*C*") = 1$, for the remaining strings $*t*$ of length 1 the value of $ρ(*s*, *t*)$ is 0.

翻译中…

In the second sample, $ρ("*AG*", "*AG*") = ρ("*AG*", "*GA*") = ρ("*AG*", "*AA*") = ρ("*AG*", "*GG*") = 4$.

翻译中…

In the third sample, $ρ("*TTT*", "*TTT*") = 27$

翻译中…

样例

Input #1
1
C
Output #1
1
InputCopy OutputCopy
Input #2
2
AG
Output #2
4
InputCopy OutputCopy
Input #3
3
TTT
Output #3
1
InputCopy OutputCopy
题目信息
题号
521A
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。