Suffix Array 1

Given S, decide whether some lexicographically smaller string of the same length has an identical suffix array. Constraints: |S| <= 50.

Medium7StringSortingGreedyNo attempts yetTime limit2sMemory limit512 MB

Problem

The ii-th suffix of a string SS is the part of SS that starts at position ii and runs to the end of the string. Positions are numbered from 0. For example, if SS = "abcde", the 0th suffix is "abcde" and the 3rd suffix is "de".

The suffix array of SS is built by sorting all suffixes of SS in lexicographic order and then writing down the starting position of each suffix in that order. For example, if SS = "abca", the suffix array is (3,0,1,2)(3, 0, 1, 2).

Given a string SS, write a program that decides whether a string TT exists that has the same suffix array as SS and comes before SS in lexicographic order. TT has the same length as SS, and TT also consists of lowercase letters only.

Input

The first line contains the string SS. The length of SS is between 1 and 50, and SS consists of lowercase letters only.

Output

Print 1 if a string exists that comes before SS in lexicographic order and has the same suffix array as SS. Otherwise print 0.