Suffix Array

No attempts yetTime limit3sMemory limit256 MB

Problem

The suffix array of a string SS lists the starting positions of every suffix of SS in lexicographic order. Positions are counted from 1. For example, if SS is banana, there are six suffixes.

SuffixStarting position
banana1
anana2
nana3
ana4
na5
a6

Sorted lexicographically, they come out in this order.

SuffixStarting position
a6
ana4
anana2
banana1
na5
nana3

Reading the starting positions down the sorted table gives [6, 4, 2, 1, 5, 3], the suffix array of banana.

The LCP array is built on top of the suffix array. For each suffix in sorted order it stores the length of the LCP (Longest Common Prefix) shared with the suffix immediately before it. The first suffix has nothing before it, so its value is undefined. For banana the LCP array is [x, 1, 3, 0, 0, 2].

Given a string of length at most 500000, write a program that computes its suffix array and its LCP array.

Input

The first line contains a string SS made up of lowercase letters only. The length of SS is at most 500000.

Output

Print the suffix array on the first line and the LCP array on the second line, separating values with a single space. Print the first value of the LCP array as x.