#P4823. DNA Alignment

DNA Alignment

DNA Alignment

题面翻译

给定一个n长度的由AACCGGTT四种序列构成的DNADNA序列。问有多少种方案,构造另一种序列,使得两种序列在shiftshift过程中,两者相同的位数总和最大。shiftshift操作即移位操作,两者分别移动,然后求相同位的个数。

题目描述

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 s and t t have the same length n n , then the function h(s,t) h(s,t) is defined as the number of positions in which the respective symbols of s s and t t are the same. Function h(s,t) h(s,t) can be used to define the function of Vasya distance ρ(s,t) ρ(s,t) :

where is obtained from string s s , by applying left circular shift i 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 1+1+0+0+1+1+1+0+1=6 Vasya found a string s s of length n n on the Internet. Now he wants to count how many strings t t there are such that the Vasya distance from the string s s attains maximum possible value. Formally speaking, t t must satisfy the equation: .

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 109+7 10^{9}+7 .

输入格式

The first line of the input contains a single integer n n ( 1<=n<=105 1<=n<=10^{5} ).

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

输出格式

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

样例 #1

样例输入 #1

1
C

样例输出 #1

1

样例 #2

样例输入 #2

2
AG

样例输出 #2

4

样例 #3

样例输入 #3

3
TTT

样例输出 #3

1

提示

Please note that if for two distinct strings t1 t_{1} and t2 t_{2} values ρ(s,t1) ρ(s,t_{1}) и ρ(s,t2) ρ(s,t_{2}) are maximum among all possible t 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 ρ(&quot;C&quot;,&quot;C&quot;)=1 , for the remaining strings t t of length 1 the value of ρ(s,t) ρ(s,t) is 0.

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

In the third sample, ρ(&quot;TTT&quot;,&quot;TTT&quot;)=27