C. DNA Alignment

本文介绍了一种用于评估循环DNA序列相似性的新颖方法,并探讨了如何计算达到最大可能值的字符串数量。通过循环移位操作,定义了一个新的距离度量函数,并给出了具体的计算实例。

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):

where 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: .

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.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 105).

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 109 + 7.

Examples
Input
Copy
1
C
Output
Copy
1
Input
Copy
2
AG
Output
Copy
4
Input
Copy
3
TTT
Output
Copy
1
Note

Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) 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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int mod=1e9+7;
const int maxn=1e5+10;
char str[maxn];

int num[4];
/*
这道题是思维题,而且思维性还很强
到现在都不知道是怎么做的,晚上再来想一想 
*/

int get_ans(ll base,int n){
	ll ans=1;
	while(n){
		if(n&1){
			ans=(ans*base)%mod;
		}
		base=(base*base)%mod;
		n>>=1;
	}
	return ans;
}

int main(){
	int len;
	scanf("%d",&len);
	scanf("%s",str);
	for(int i=0;i<len;i++){
		if(str[i]=='A')	
			num[0]++;
		else if(str[i]=='C')
			num[1]++;
		else if(str[i]=='G')
			num[2]++;
		else
			num[3]++;
	}
	sort(num,num+4);
	int max_num=num[3];
	int n=0;
	for(int i=0;i<4;i++){
		if(num[i]==max_num) n++;
	}
	ll ans=get_ans((ll)n,len);
	printf("%lld\n",ans);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值