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:
Pattern | Name |
---|---|
AAAAA |
Appleboom |
ABBA |
Stockholm Syndrome |
ABCABC |
Double Rainbow |
A safe spell contains none of these patterns.
Help Twilight determine whether a spell is safe or unsafe.
BAAAAAB
is unsafe, as it contains an Appleboom.
AAAACA
is safe.
While it has five Apples, the Ciwifruit in between means that it can't form an Appleboom.
ABBABBA
is unsafe, as it contains two (overlapping) Stockholm Syndromes.
ABBAAAAA
is also unsafe, as it contains both a Stockholm and an Appleboom.
They don't cancel out!
CBACBA
is safe.
It has the same fruit as a Double Rainbow, but the fruit are in the wrong order.
The first line of input will contain a single integer, 0 < N ≤ 100
, representing the length of the spell.
The next line will contain a string of letters, each either A
, B
, or C
.
This is the spell itself.
Output SAFE
if the spell is safe; otherwise UNSAFE
.
Input:
1
A
Output:
SAFE
Input:
4
ABBA
Output:
UNSAFE