CF645E.Intellectual Inquiry

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After getting kicked out of her reporting job for not knowing the alphabet, Bessie has decided to attend school at the Fillet and Eggs Eater Academy. She has been making good progress with her studies and now knows the first kk English letters.

Each morning, Bessie travels to school along a sidewalk consisting of m+nm+n tiles. In order to help Bessie review, Mr. Moozing has labeled each of the first mm sidewalk tiles with one of the first kk lowercase English letters, spelling out a string tt . Mr. Moozing, impressed by Bessie's extensive knowledge of farm animals, plans to let her finish labeling the last nn tiles of the sidewalk by herself.

Consider the resulting string ss ( s=m+n|s|=m+n ) consisting of letters labeled on tiles in order from home to school. For any sequence of indices p1<p2<...<pqp_{1}<p_{2}<...<p_{q} we can define subsequence of the string ss as string sp1sp2... spqs_{p1}s_{p2}...\ s_{pq} . Two subsequences are considered to be distinct if they differ as strings. Bessie wants to label the remaining part of the sidewalk such that the number of distinct subsequences of tiles is maximum possible. However, since Bessie hasn't even finished learning the alphabet, she needs your help!

Note that empty subsequence also counts.

输入格式

The first line of the input contains two integers nn and kk ( 0<=n<=10000000<=n<=1000000 , 1<=k<=261<=k<=26 ).

The second line contains a string tt ( t=m,1<=m<=1000000|t|=m,1<=m<=1000000 ) consisting of only first kk lowercase English letters.

输出格式

Determine the maximum number of distinct subsequences Bessie can form after labeling the last nn sidewalk tiles each with one of the first kk lowercase English letters. Since this number can be rather large, you should print it modulo 109+710^{9}+7 .

Please note, that you are not asked to maximize the remainder modulo 109+710^{9}+7 ! The goal is to maximize the initial value and then print the remainder.

输入输出样例

  • 输入#1

    1 3
    ac
    

    输出#1

    8
    
  • 输入#2

    0 2
    aaba
    

    输出#2

    10
    

说明/提示

In the first sample, the optimal labeling gives 88 different subsequences: "" (the empty string), "a", "c", "b", "ac", "ab", "cb", and "acb".

In the second sample, the entire sidewalk is already labeled. The are 1010 possible different subsequences: "" (the empty string), "a", "b", "aa", "ab", "ba", "aaa", "aab", "aba", and "aaba". Note that some strings, including "aa", can be obtained with multiple sequences of tiles, but are only counted once.

首页