Repeating Subsequence Tests
Time limit2sMemory limit512 MB
Given a string and up to 10^6 generated substring queries, count distinct subsequences of each substring modulo 10^9+7 and output the last answer.
- Level
Hard8 of 10
- Topics
- String, Prefix sum, Dynamic programming, Divide and conquer
- Solved
- No attempts yet
Problem
A subsequence of a string is the string that remains after removing some of its characters. You may remove no characters, or all of them. For example, the distinct subsequences of "ababA" are "" (the empty string), "a", "b", "A", "ab", "aa", "aA", "ba", "bb", "bA", "aba", "abb", "abA", "aab", "aaA", "bab", "baA", "bbA", "abab", "abaA", "abbA", "aabA", "babA", and "ababA", 24 in total. This problem treats uppercase and lowercase letters as different.
You are given a string of length . Write a program that finds, for each of contiguous substrings of , the number of distinct subsequences of that substring.
To reduce input time, the problem uses the following pseudorandom generator. Given , , , , , for the values , , , , and are defined as follows. First, let and .
is the remainder when is divided by . The way the generator produces its numbers has no meaning, and for any input there is an algorithm that outputs the answer within the time limit.
Find .
Input
The first line contains the string . Its length satisfies to , and consists only of uppercase and lowercase English letters.
The second line contains six integers , , , , , , separated by single spaces. It is given that and .
Output
On the first line, print .