Subin was surprised that some English words are spelled with only the letters A and B. AB (short for Abdominal), BAA (the cry of a sheep), AA (a type of lava), and ABBA (the Swedish pop group) are such words.
Subin turned that into a simple game. You are given two strings S and T, and the goal is to turn S into T. Only these two operations are allowed.
- Append A to the end of the string.
- Append B to the end of the string, then reverse the whole string.
Write a program that decides whether applying the two operations any number of times, in any order, can turn S into T.