Twilight Sparkle's Magic Spells
Output: Standard Output (stdout)
Memory limit: 100 megabytes
Time limit: 1.0 seconds
Twilight Sparkle is researching some magic spells. A spell is a non-empty finite sequence of Apples, Bananas, or Ciwifruit.
Spells can be safe or unsafe. An unsafe spell contains one or more of the following patterns:
Help Twilight determine whether a spell is safe or unsafe.
The first line of input will contain a single integer, 0 \lt N \le 100, representing the length of the spell.
The next line will contain a string of N letters, each either
C. This is the spell itself.
Output SAFE if the spell is safe; otherwise UNSAFE.
BAAAAABis unsafe, as it contains an Appleboom.
AAAACAis safe. While it has five Apples, the Ciwifruit in between means that it can't form an Appleboom.
ABBABBAis unsafe, as it contains two (overlapping) Stockholm Syndromes.
ABBAAAAAis also unsafe, as it contains both a Stockholm and an Appleboom. They don't cancel out!
CBACBAis safe. It has the same fruit as a Double Rainbow, but the fruit are in the wrong order.
Sample Input 1
Sample Output 1
Sample Input 2
Sample Output 2