codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

520C.md (2801B)


      1 Source: https://codeforces.com/problemset/problem/520/C
      2 
      3 C. DNA Alignment
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 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.
     22 
     23 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*):
     24 
     25 ![](https://espresso.codeforces.com/3185549447bcef14eee362fe5c14adf50d614ba9.png) where ![](https://espresso.codeforces.com/1630c222ae6ec5b71031376e94c16cf5c6ed4fda.png) 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
     26 
     27 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: ![](https://espresso.codeforces.com/8689349142c7afec51741bca879d960cce9678c8.png).
     28 
     29 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.
     30 
     31 Input
     32 
     33 The first line of the input contains a single integer *n* (1 ≤ *n* ≤ 105).
     34 
     35 The second line of the input contains a single string of length *n*, consisting of characters "ACGT".
     36 
     37 Output
     38 
     39 Print a single number — the answer modulo 109 + 7.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 1  
     47 C
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 1
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 2  
     60 AG
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 4
     67 ```
     68 
     69 Input
     70 
     71 ```
     72 3  
     73 TTT
     74 ```
     75 
     76 Output
     77 
     78 ```
     79 1
     80 ```
     81 
     82 Note
     83 
     84 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.
     85 
     86 In the first sample, there is ρ("*C*", "*C*") = 1, for the remaining strings *t* of length 1 the value of ρ(*s*, *t*) is 0.
     87 
     88 In the second sample, ρ("*AG*", "*AG*") = ρ("*AG*", "*GA*") = ρ("*AG*", "*AA*") = ρ("*AG*", "*GG*") = 4.
     89 
     90 In the third sample, ρ("*TTT*", "*TTT*") = 27