PivotOJ

String Rank

시간 제한: 500ms메모리 제한: 2048MB출처: ICPC Asia Seoul Regional 2024BOJ 32839

문제

Let ww and uu be strings consisting of the English lowercase alphabet. We say that a string uu is a subsequence of a string ww if there exists a strictly increasing sequence of integers i1,,iki_1, \cdots , i_k, where w=n|w| = n, u=k|u| = k and u[j]=w[ij]u[j] = w[i_j] for all j=1,,kj = 1, \dots , k. Here, v[i]v[i] denotes the ii-th character of the string vv. Let w[i:]w[i:] denote the suffix w[i]w[n]w[i] \cdots w[n]. If i>ni > n, then w[i:]w[i: ] is the empty string denoted by λ\lambda.

Given a nonempty string ww and a positive integer kk, we define the kk-set of ww to be the set Qk(w)Q_k(w) of subsequences of ww whose lengths are 0,1,,k0, 1, \cdots , k. This implies that, for any string ww, the empty string λ\lambda belongs to Qk(w)Q_k(w) by definition.

For example, when w=w = aaba, we have Q3(Q_3(aaba)={λ) = \{\lambda, a, b, ba, ab, aa, aba, aab, aaa}\}.

For a string ww, we define the rank of ww to be the minimum integer tt such that the tt-sets for all suffixes of ww are all different. In other words, the rank of ww is \min\{t &ge; 1 | Q_t(w[i:]) \ne Q_t(w[j:]), &forall;1 &le; i < j &le; 𝑛\}.

For instance, when w=w = aaba, the 22-sets Q2(Q_2(aba)) and Q2(Q_2(aaba)) are equal. On the other hand, for t=3t = 3, we have

  • Q3(λ)={λ}Q_3(\lambda) = \{\lambda\},
  • Q3(Q_3(a)={λ) = \{\lambda, a}\},
  • Q3(Q_3(ba)={λ) = \{\lambda, a, b, ba}\},
  • Q3(Q_3(aba)={λ) = \{\lambda, a, b, ba, ab, aa, aba}\},
  • Q3(Q_3(aaba)={λ) = \{\lambda, a, b, ba, ab, aa, aba, aab, aaa}\}.

Therefore, the rank of the string w=w = aaba is 33.

Given a string ww, write a program to output its rank.

입력

Your program is to read from standard input. The input consists of a single nonempty string ww, which consists only of lowercase characters from the English alphabet. The length of the string is at most 3×1063 \times 10^6.

출력

Your program is to write to standard output. Print exactly one line. The line should contain a positive integer to represent the rank tt of the input string ww.

예제

예제 1

입력
aabbb
출력
3

예제 2

입력
abacb
출력
2

예제 3

입력
azadzzadaz
출력
4

예제 4

입력
a
출력
1
코드를 제출하려면 로그인하세요.