eolymp
bolt
Try our new interface for solving problems
Problems

Unique Activities

Unique Activities

Emily is tired of having studied at home throughout 2020. She has noticed the same tasks occur over and over: she has to cook and wash the dishes. Then it's time for her class; afterwards she resumes washing the dishes, has to attend another class, washes some more dishes before cooking and washing the dishes for the last time of the day. There is a part of her day she loves, though: it's when the sequence of activities she is currently carrying out happens only once during her day. She rejoices the most when that activity sequence is unique and really short. Each activity is represented by an uppercase letter. Given the list of activities Emily has to carry out today, help Emily find the best moment of her day by finding the shortest substring that only occurs once in the input. If Cooking is $C$, Dishes is $D$, and Studying is $S$, the list of activities in the example above are $C D S D S D C D$, and the shortest substring that occurs only once is $D C$. (All the one-letter substrings and the other two-letter substrings occur at least twice). \InputFile Consists of a single line, with a sequence of $n~(0 < n \le 300000)$ uppercase letters (from $'A'$ to $'Z'$). \OutputFile Print a single line with the shortest substring that happens only once in the input string. If there are multiple shortest substrings (with the same length), output the one that occurs first.
Time limit 1 second
Memory limit 256 MiB
Input example #1
AABAABB
Output example #1
BA
Source 2020 ACM Southwestern Europe Regional Contest (SWERC), Paris, March 7 (2021), Problem K