Difficult Password
시간 제한3초메모리 제한2048 MB
L자 이상 R자 이하이며 숫자와 영문자를 모두 포함하고, 같은 문자가 A번 연속하거나 B번 연속 오름차순/내림차순이 되는 일이 없는 비밀번호의 개수를 구한다.
문제
To ensure that students use a strong cluster login password, the course team has configured a password complexity policy on the cluster. At the beginning of the semester, all enrolled students will receive a randomly generated initial password. After logging into the cluster with the initial password, the cluster will require students to enter a new password, and access to the cluster will only be granted after the password has been changed. In this problem, we assume the password complexity policy is as follows:
-
The password must contain at least characters, and must include at least one digit and at least one letter.
-
The password cannot contain consecutive repeated characters. For example,
2333contains three consecutive repeated characters. -
The password cannot contain consecutive characters that form an ascending or descending sequence. An ascending sequence is defined as a consecutive substring of one of the three strings:
0123456789,ABCDEFGHIJKLMNOPQRSTUVWXYZ, andabcdefghijklmnopqrstuvwxyz. A descending sequence is the reverse of a consecutive substring of one of these three strings. For example:6789is an ascending sequence of length 4, andFEDis a descending sequence of length 3;90,AZ, andazare not ascending or descending sequences;GPUis not an ascending sequence because it is not consecutive;Defis not an ascending sequence because the letter case is inconsistent (but it contains the ascending consecutive subsequenceefof length 2);1112345678999is not an ascending sequence, but its subsequence123456789is ascending.
Assuming the password consists only of digits and uppercase and lowercase letters, determine how many passwords of length not exceeding satisfy the password complexity policy. This number can be very large, so find it modulo .
입력
The input consists of a single line containing four positive integers: , , , (; ; ).
출력
Output a non-negative integer representing the number of passwords that satisfy the password complexity policy and have length not exceeding , modulo .
힌트
In Sample 1, since the password must contain at least one digit and at least one letter, there are valid passwords.