Boundary Spell
Time limit2sMemory limit1024 MB
Given a string w, output a binary string where position i is 1 if the i-th cyclic shift of w has a nonempty proper prefix that is also a suffix.
- Level
Medium6 of 10
- Topics
- String matching, String
- Solved
- No attempts yet
Problem
The great wizard Merlin is developing a new spell to protect the border of the Nearby Kingdom. To analyze the spell in more detail, Merlin wants to find its magic code and compare it with the codes recommended in the spellbooks.
The spell is a word of length , made of magic runes written as lowercase Latin letters. A spell is called nontrivial if it has a nonempty prefix, different from the whole spell, that is also a suffix of it. For example, abababa is nontrivial because its prefix ababa is also its suffix. aababab is not nontrivial.
Merlin considers all cyclic shifts of from 1 to . The -th cyclic shift starts at the -th character of the original spell. For example, the first cyclic shift of abababa is abababa, the second is bababaa, and the seventh is aababab.
The magic code of spell , written , is a word of characters, each 0 or 1. The -th character of is 1 if the -th cyclic shift of is nontrivial, and 0 otherwise. For example, the magic code of abababa is 1011110.
Given spell , find its magic code.
Input
The input file contains the spell , consisting of lowercase Latin letters. Its length does not exceed 100,000.
Output
Print the magic code of the given spell.