Namomo Subsequence

시간 제한3초메모리 제한1024 MB

요약
문자열에서 문자 간 같은지 다른지의 패턴이 namomo와 같은 길이 6 부분수열의 개수를 998244353으로 나눈 나머지로 구한다.
난이도

보통10점 중 7점

유형
동적 계획법, 조합론, 누적 합
정답자
아직 제출이 없습니다

문제

"gshfd1jkhaRaadfglkjerVcvuy0gf" said Prof. Pang.

To understand Prof. Pang's word, we would like to calculate the number of namomo subsequences of it. The word by Prof. Pang is a string ss with nn characters where each character is either an English letter (lower or upper case) or a digit. The ii-th character of ss is denoted by s\[i]s\[i] (1≤i≤n1\le i\le n). A subsequence tt of ss is defined by a list of indices t_1,…,t_6t\_1, \ldots, t\_6 such that 1≤t_1<t_2<…<t_6≤n1\le t\_1 < t\_2 < \ldots < t\_6\le n. Let compare(c_1,c_2)compare(c\_1, c\_2) be a function on two characters such that compare(c_1,c_2)=1compare(c\_1, c\_2)=1 when c_1=c_2c\_1=c\_2 and compare(c_1,c_2)=0compare(c\_1, c\_2)=0 otherwise. tt is a namomo subsequence of ss if and only if for any 1≤i\<j≤61\le i\<j\le 6, compare(s\[t_i],s\[t_j])=compare(namomo\[i],namomo\[j])compare(s\[t\_i], s\[t\_j]) = compare(namomo\[i], namomo\[j]), where namomo\[x]namomo\[x] represents the xx-th character of the string "namomo" (1≤x≤61\le x\le 6).

Output the number of namomo subsequences of a given string ss modulo 998244353998244353.

입력

The first line contains a string ss with nn characters (6≤n≤10000006\le n\le 1000000). ss contains only lower case English letters ('a' -- 'z'), upper case English letters ('A' -- 'Z') and digits ('0' -- '9').

출력

Output one integer -- the answer modulo 998244353998244353.

예제4

  1. 예제 1

    입력
    wohaha
    
    예상 출력
    1
    
  2. 예제 2

    입력
    momomo
    
    예상 출력
    0
    
  3. 예제 3

    입력
    gshfd1jkhaRaadfglkjerVcvuy0gf
    
    예상 출력
    73
    
  4. 예제 4

    입력
    retiredMiFaFa0v0
    
    예상 출력
    33