Suffix Array 1
Time limit2sMemory limit512 MB
Given S, decide whether some lexicographically smaller string of the same length has an identical suffix array. Constraints: |S| <= 50.
Problem
The -th suffix of a string is the part of that starts at position and runs to the end of the string. Positions are numbered from 0. For example, if = "abcde", the 0th suffix is "abcde" and the 3rd suffix is "de".
The suffix array of is built by sorting all suffixes of in lexicographic order and then writing down the starting position of each suffix in that order. For example, if = "abca", the suffix array is .
Given a string , write a program that decides whether a string exists that has the same suffix array as and comes before in lexicographic order. has the same length as , and also consists of lowercase letters only.
Input
The first line contains the string . The length of is between 1 and 50, and consists of lowercase letters only.
Output
Print 1 if a string exists that comes before in lexicographic order and has the same suffix array as . Otherwise print 0.