NOI Game
Mr. Ian is a past contestant of NOI and he has an interest in playing games with the letters ‘n’ ,o’ and ‘i’. Initially his friend Ms.Nio gives him a random string(text) which only contains the letters ‘n’, ‘o’ and ‘i’. Then he performs the following operations on the string
- Find an even substring that only contains one character type(‘n’/’o’/’i’)
- Removes it from the original string to make a new string
- Continue step 1 with the new string until there are no even substrings of same character type(‘n’/’o’/’i’) or the resulting string is empty
After all the operations Mr. Ian comes up with the resulting string. Having a programming background Mr. Ian wishes to make his task easy by using a program. Your task is to help Ian find the resulting string after following the above operations
Input Format
One line containing a string of length N that has only lowercase characters ‘n’ ,’o’ and ‘i’
Output Format
A single line containing the resulting string If the resulting string is empty print -1
Constraints
5 <= N <= 100 000
Limits
- Time Limit: 1s
- Memory Limit: 256MB
Sample Input 0
nonooni
Sample Output 0
noi
Sample Input 1
noooiion
Sample Output 1
-1
Sample Input 2
nnooinnnnoinooiin
Sample Output 2
ioi
Open on HackerRank ↗ · Markdown source · Back to the archive