Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times:
A BCB ACC ABAAA empty stringNote that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source.
InputThe first line contains a string S (1 ≤ |S| ≤ 105). The second line contains a string T (1 ≤ |T| ≤ 105), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'.
The third line contains the number of queries Q (1 ≤ Q ≤ 105).
The following Q lines describe queries. The i-th of these lines contains four space separated integers ai, bi, ci, di. These represent the i-th query: is it possible to create T[ci..di] from S[ai..bi] by applying the above transitions finite amount of times?
Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U.
It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|.
OutputPrint a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise.
Example input Copy AABCCBAAB ABCB 5 1 3 1 2 2 2 2 4 7 9 1 1 3 4 2 3 4 5 1 3 output 10011 NoteIn the first query we can achieve the result, for instance, by using transitions .
The third query asks for changing AAB to A — but in this case we are not able to get rid of the character 'B'.
题意:给你两个长度不超过1e5的字符串S和T,只包含'A','B','C'。可以有4种对子串的操作:1)A->BC,2)B->AC,3)C->AB,4)AAA->empty。接着给Q个查询(Q<=1e5),每次查询指定S和T各自的一个子串,问能否使用上述四种操作把S的子串转换为T的子串。
分析:两个观察:1)操作中,BC字符的个数是不减的,而且每次增加的单位是2;2)B->C,C->B,B->AB,BA->B,所以如果两个非空串都不以A结尾,它们可转换等价于目标串中BC的个数比起始串多偶数个。所以我们可以集中考虑后缀全为A的串转换的条件,首先:1)如果目标串A后缀的长度大于起始串,无解;2)如果目标串A后缀长度大于起始串,有两种情况都可以转化,一是起始串BC的数量严格小于目标串,而是A正好多了3k个。等于的情况就不用说了,注意一下起始串全为A的特例。
