logo AlgoBeat OnlineJudge
登录 注册

#215814. [JAG 2025 Summer Camp #1] Inversion of Suffix Array

内存限制:1024 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

You are given positive integers , and a string of length consisting of lowercase English letters.

Let be the string obtained by concatenating copies of .

Find the inversion number of the Suffix Array of , modulo .

For a string of length , the suffix array of is a permutation of integers from to that represents the starting positions of all non-empty suffixes of , sorted in lexicographical order.

输入格式

The input is given in the following format:

  • is a string of length consisting of lowercase English letters.
  • and are integers.

输出格式

Output the answer in a single line.

样例

样例输入 1

4 2
icpc

样例输出 1

18

样例输入 2

13 92025
jagsummercamp

样例输出 2

996562345