Alex was typing away on a Linux terminal when he noticed something interesting. He tried…
- User
Alex was typing away on a Linux terminal when he noticed something interesting. He tried typing the commands clear and ls in quick succession. He pressed Enter at the wrong time and accidentally typed clea and rls instead. While neither was a valid command, he wondered whether he could have entered something more dangerous.
Alex wants to take a list of known commands and find which ones can be typed unintentionally. To qualify, it must be possible to type the command by writing two commands and separating them with one line break at the wrong location. This includes inserting the line break before or after the text of the pair. Could you help him investigate this? Input
The input will begin with a single line containing an integer N, where 1≤N≤5000. Then N commands will follow. Each command will be a string consisting of lowercase English letters on its own line. Commands will be distinct. The total length of all commands will not exceed 106. Output
Output a line containing the number of commands that could be typed by accident. Then output the indices of these commands in the input list, with one index per line. The index of the first command is 1, and the last command is N. The indices must be in ascending order. Sample test(s) Input 7 rm ps zip unzip rmdir cp scp Output 4 1 3 6 7
- Assistant
To solve this problem, we need to determine which commands on the list could be accidentally typed by misplacing a line break when typing two other commands.