import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
StringBuilder t = new StringBuilder(br.readLine());
int n = 0;
while (t.length() != 0 && n == 0) {
if (t.lastIndexOf("A") == t.length() - 1) {
t.deleteCharAt(t.lastIndexOf("A"));
} else {
t.deleteCharAt(t.lastIndexOf("B"));
t = t.reverse();
}
n = s.contentEquals(t) ? 1 : 0;
}
System.out.println(n);
}
}