A and B

Given two strings of A and B, decide whether S can be turned into T using only: append A, or reverse then append B.

Medium6GreedyStringImplementationSimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Subin was surprised to learn that some English words use only the letters A and B. AB (short for Abdominal), BAA (the sound a sheep makes), AA (a type of lava), and ABBA (the Swedish pop group) are examples.

Starting from that idea, Subin made a simple game. Given two strings SS and TT, the goal is to turn SS into TT. Only these two operations can change a string.

  • Append A to the end of the string.
  • Reverse the string, then append B to the end.

Write a program that decides whether these operations can turn SS into TT.

Input

The first line contains SS and the second line contains TT. Both strings consist only of the uppercase letters A and B. (1S9991 \le |S| \le 999, 2T10002 \le |T| \le 1000, S<T|S| < |T|)

Output

Print 1 if SS can be turned into TT, and 0 if it cannot.