Carry Bit

Time limit: 0.5s Memory limit: 64MB Input: Output:

Task

Valerio is currently visiting Poland, and on the street he found two strings AA and BB of length NN each, consisting of 00's and 11's.

When he returned home, he decided to write a program that chooses two contiguous substrings of length LL, one from AA and one from BB, then interprets them as binary numbers (i.e. numbers written in base 2) and computes their sum.
Unfortunately Valerio made a mistake: he decided to store the result of the sum in an LL-bit variable (i.e., a variable that can store numbers from 00 to 2L12^L-1 inclusive), but in some cases the sum can be too larger! Help him to verify the correctness of the result.

You are given QQ queries, each consisting of 33 integers XX, YY and LL.
For each query, determine whether Valerio's program is correct for the strings A[XX+L1]A[X\ldots X+L-1] and B[YY+L1]B[Y\ldots Y+L-1].
In other words, you need to determine whether the sum of the numbers with binary representation A[XX+L1]A[X\ldots X+L-1] and B[YY+L1]B[Y\ldots Y+L-1] is strictly less than 2L2^L.

Input data

The input file consists of:

  • a line containing integer NN.
  • a line containing string AA of length NN.
  • a line containing string BB of length NN.
  • a line containing integer QQ.
  • QQ lines, the ii-th of which consisting of integers XiX_{i}, YiY_{i} and LiL_{i}.

Output data

The output file must contain a single line consisting of the QQ integers: the ii-th value must be 11 if Valerio's program gives the correct result to query ii, otherwise the value must be 00.

Constraints and clarifications

  • 1N21051 \le N \le 2 \cdot 10^5.
  • AA and BB consist of characters 0 and 1.
  • 1Q21051 \le Q \le 2 \cdot 10^5.
  • 0Xi,Yi<N0 \le X_i, Y_i < N for each i=0Q1i=0\ldots Q-1.
  • 1Xi+LN1 \le X_i+L \le N for each i=0Q1i=0\ldots Q-1.
  • 1Yi+LN1 \le Y_i+L \le N for each i=0Q1i=0\ldots Q-1.
# Points Constraints
1 0 Examples.
2 40 N4000N \le 4000 and Q4000Q \le 4000
3 30 Xi=YiX_i=Y_i for each i=0Q1i=0\ldots Q-1
4 30 No additional limitations.

Example 1

stdin

7
1001010
0111101
5
0 0 1
0 0 3
0 0 4
0 4 3
4 5 2

stdout

1 1 0 0 1

Explanation

In the first sample case there are 55 queries:

  • in the first query the 22 substrings are 1 and 0, and their sum is 11, less than 212^1;
  • in the second query the 22 substrings are 100 and 011, and their sum is 77, less than 232^3;
  • in the third query the 22 substrings are 1001 and 0111, and their sum is 1616, not less than 242^4;
  • in the fourth query the 22 substrings are 100 and 101, and their sum is 99, not less than 232^3;
  • in the fifth query the 22 substrings are 01 and 01, and their sum is 22, less than 222^2.

Example 2

stdin

12
101000010101
011110101110
7
1 5 4
8 2 3
9 4 2
10 3 1
0 0 3
0 0 6
3 5 6

stdout

1 0 0 1 0 0 1

Log in or sign up to be able to send submissions!