#include <iostream>
#include <vector>
#include <algorithm> 
using namespace std; 
vector<char> temp ; 
void check_loop(vector<char> &s, vector<char> &t){
    if(s == t){cout << 1 << endl; exit(0);}
    if(s.size() >= t.size()){return ; }
    if(t.back() == 'A'){
        temp = t ; 
        temp.pop_back() ; 
        check_loop(s,temp) ;
    }
    if(t[0] == 'B'){
        temp = t; 
        reverse(temp.begin(), temp.end()) ; 
        t.pop_back() ; 
        check_loop(s,temp) ; 
    }    
}
int main(){
    string k  ; cin >> k ; 
    vector<char> s(k.begin(), k.end()) ;
    string k2 ; cin >> k2 ; 
    vector<char> t(k2.begin() , k2.end()) ; 
    check_loop(s,t) ; 
    cout << 0 << endl ; 
    return 0;
}