#include <iostream>
#include <algorithm>
using namespace std;
string s, t;
int answer = 0;
void getAnswer(string t)
{
if (t == s)
{
answer = 1;
return;
}
if (t[t.length() - 1] == 'A')
{
getAnswer(t.substr(0, t.length() - 1));
}
reverse(t.begin(), t.end());
if (t[t.length() - 1] == 'B')
{
getAnswer(t.substr(0, t.length() - 1));
}
else
{
return;
}
}
int main()
{
cin >> s >> t;
getAnswer(t);
cout << answer;
}