Difficult Password
Time limit3sMemory limit2048 MB
Count passwords of length L to R that contain a digit and a letter, have no A equal characters in a row, and have no B-long ascending or descending run, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Matrix, String
- Solved
- No attempts yet
Problem
The course team set a password complexity policy on the cluster so that students use strong login passwords. At the start of the semester, every enrolled student receives a randomly generated initial password. When a student logs in with the initial password, the cluster asks for a new password. Access to the cluster is granted only after the password is changed. This problem uses the following policy.
- The password must have at least characters, and it must include at least one digit and at least one letter.
- The password cannot contain identical characters in a row. For example,
2333contains three identical characters in a row. - The password cannot contain consecutive characters that form an ascending or descending sequence. An ascending sequence is a consecutive substring of one of the strings
0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ, orabcdefghijklmnopqrstuvwxyz. A descending sequence is the reverse of a consecutive substring of one of these strings. For example:6789is an ascending sequence of length 4, andFEDis a descending sequence of length 3.90,AZ, andazare neither ascending nor descending sequences.GPUis not an ascending sequence because its letters are not consecutive.Defis not an ascending sequence because the letter case is mixed. It does contain the ascending subsequenceefof length 2.1112345678999is not an ascending sequence, but its subsequence123456789is.
The password consists only of digits and uppercase and lowercase letters. Count the passwords of length at most that satisfy this policy. The count can be very large, so output it modulo .
Input
The input is a single line with four positive integers , , , (; ; ).
Output
Print one non-negative integer: the number of passwords that satisfy the policy and have length at most , modulo .
Hint
In Sample 1, the password must contain at least one digit and at least one letter, so there are valid passwords.