题干:

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

1
C

Output

1

Input

2
AG

Output

4

Input

3
TTT

Output

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

解题报告:

直接看哪个字母出现的次数最多就行了,注意有可能很多字母出现的次数一样多,所以扫两遍就做完了。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
#define fi first
#define se second
using namespace std;
const int MAX = 2e5 + 5;
char s[MAX];
int bk[20];
ll mod = 1e9+7;
ll qpow(ll a,ll k) {ll res = 1;while(k) {if(k&1) res = (res*a)%mod;k>>=1;a=(a*a)%mod; }return res;
}
int main()
{ll n;cin>>n;cin>>(s+1);int len = strlen(s+1);for(int i = 1; i<=len; i++) {if(s[i] == 'A') bk[1]++;if(s[i] == 'C') bk[2]++;if(s[i] == 'G') bk[3]++;if(s[i] == 'T') bk[4]++;}int maxx = *max_element(bk+1,bk+5);ll cur = 0;for(int i = 1; i<=4; i++) {if(bk[i] == maxx) cur++;}printf("%lld\n",qpow(cur,n));return 0 ;}

【CodeForces - 520C】DNA Alignment (快速幂,思维)相关推荐

  1. CodeForces - 520C DNA Alignment(思维)

    题目链接:点击查看 题目大意:给出定义函数h(s,t),其值等于字符串s和字符串t中相同字符的位置的个数,再给出一个函数p(s,t),简单来说就是一个二重循环,每次让字符串的第一个元素移到最后一个元素 ...

  2. Codeforces 696C. PLEASE(快速幂+费马小定理)

    题目链接 题目大意 三个杯子,硬币一开始在中间的杯子里,每次操作可能是左边和中间或右边和中间交换,问n次操作后,硬币在中间的概率 思路 设 f(n) f(n) 是n次操作后硬币在中间的概率,则很明显, ...

  3. CodeForces - 1139C Edgy Trees (快速幂+dfs)

    题目:CodeForces - 1139C 题意:一个n个节点的无向图,有n-1条边每条边是黑色或者红色,现在统计包含k个点(不需要连续)的路中至少有1条黑边的路径数目 分析:总共有n^k条路径,将所 ...

  4. POJ 2778 DNA Sequence [AC自动机 + 矩阵快速幂]

    http://poj.org/problem?id=2778 题意:给一些只由ACGT组成的模式串,问有多少种长度为n且不含有给出的模式串的DNA序列. 自动机的状态转换可以看成一个有向图(有重边的) ...

  5. 【Codeforces Gym - 101635C Macarons 】【矩阵快速幂+状压】【dfs时间换空间】

    [链接] http://codeforces.com/gym/101635/attachments [题意] 求用1*1,1*2的方格填n*m的矩阵的方法数 [知识点] 状压dfs+矩阵快速幂 [分析 ...

  6. Codeforces 621E Wet Shark and Block【dp + 矩阵快速幂】

    题意: 有b个blocks,每个blocks都有n个相同的0~9的数字,如果从第一个block选1,从第二个block选2,那么就构成12,问对于给定的n,b有多少种构成方案使最后模x的余数为k. 分 ...

  7. 【分解质因数】【树状数组】【快速幂】codeforces 2014 ACM-ICPC Vietnam National Second Round E. ACM...

    乘除都在150以内,分解质因数后发现只有35个,建立35个树状数组/线段树,做区间加.区间查询,最后快速幂起来. #include<cstdio> #include<cstring& ...

  8. HDU 4869 Turn the pokers(思维+组合公式+快速幂)

    Turn the pokers 大意:给出n次操作,给出m个扑克,然后给出n个操作的个数a[i],每个a[i]代表可以翻的扑克的个数,求最后可能出现的扑克的组合情况. Hint Sample Inpu ...

  9. POJ - 2778 DNA Sequence(AC自动机+矩阵快速幂)

    题目链接:点击查看 题目大意:给出 n 个长度不大于 10 的字符串表示病毒串,再给出一个长度 len ,问长度为 len 的字符串中,有多少个字符串不含有病毒串作为子串 题目分析:因为病毒串的长度和 ...

  10. CodeForces - 1236B Alice and the List of Presents(组合数学+快速幂)

    题目链接:点击查看 题目大意:爱丽丝现在有n种礼物,每种礼物有无限种,现在有m个盒子,需要向里面放礼物,满足以下两个条件: 每个背包里不能出现相同种类的物品(允许有空背包) 在所有的m个背包中,每种物 ...

最新文章

  1. 比尔盖茨宣布离开微软董事会:昔日全球首富致力于改变世界
  2. CTF盲水印工具安装(排雷)
  3. 启明云端分享|ESP32 AT 相关资源从哪里获得?以及经常会遇到的AT相关问题
  4. 数学三大核心领域概述:代数、几何、分析
  5. 【Java】while和do-while循环比较测试案例
  6. 机器学习-吴恩达-笔记-15-总结
  7. js面向对象编程(三)非构造函数的继承(转载)
  8. 剧透和评析之車輪の国、向日葵の少女
  9. git使用puttygen生成公钥私钥
  10. 机器学习算法初识—二分k均值算法
  11. Python爬虫入门教程13:高质量电脑桌面壁纸爬取
  12. 【MILP】Mixed-Integer Quadratic Programming portfolio optimzation
  13. 数据分析需要学习的技能有哪些?
  14. python计算FID
  15. CentOS 7下的软件安装方法及策略
  16. Geospatial Data Science (4): Spatial weights
  17. 电影院3d是什么模式的_3D的完整形式是什么?
  18. html div挤下去了,宽度足够的时候元素还是被挤下去了
  19. 【资源分享】疫情居家一个月,精心整理了一个PPT资源社区(含模板-资源-高级技巧)
  20. #hihocoder #1135 : Magic Box

热门文章

  1. 93. Restore IP Addresses 1
  2. lua 调用文件中的函数调用_深入Lua:调用相关的指令
  3. vue(el-button的五种类型,三种css格式)
  4. 与自定义词典 分词_使用jieba库进行中文分词、关键词提取、添加自定义的词典进行分词...
  5. jenkins执行bat失败_关于批处理文件:即使在BAT脚本中成功执行了ROBOCOPY命令,JENKINS作业也会失败...
  6. python生成表达式_说说 Python 的生成器表达式
  7. 如何实现listbox选项,然后双击鼠标实现选项的删除
  8. linux系统安装佳能打印机驱动,在ubuntu16.04 64-bit上安装佳能打印机驱动Linux_UFRII_PrinterDriver_V320_us_EN...
  9. 获取场景中指定类的实例
  10. 领导者/追随者(Leader/Followers)模型和半同步/半异步(half-sync/half-async)模型