#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000005

int N;
int BIT[NUM];
int A[NUM],B[NUM];
int len_A,len_B,len_max;
char buf_A[NUM],buf_B[NUM];
bool table[NUM];
set<int> B_POS,COMMON_POS;

void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}


int calc(int left,int right){
	return getSum(right)-getSum(left-1);
}

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int loc){
	loc += N-1;

	table[loc] = (A[loc-(N-1)-1] == 1 || B[loc-(N-1)-1]);

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[parent] = table[2*parent+1] && table[2*parent+2];

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}

bool is_all_1(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right){
		return true;
	}

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id];
	}

	bool is_left = is_all_1(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	bool is_right = is_all_1(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return is_left && is_right;
}

int get_index(int loc){

	return loc+1;
}


int main(){

	int num_query;
	scanf("%d %s %s",&num_query,buf_A,buf_B);

	for(len_A = 0; buf_A[len_A] != '\0'; len_A++);
	for(len_B = 0; buf_B[len_B] != '\0'; len_B++);

	len_max = max(len_A,len_B);

	for(int i = 0; i < len_max; i++){
		A[i] = 0;
		B[i] = 0;
	}

	for(int i = len_A-1; i >= 0; i--){
		A[(len_A-1)-i] = buf_A[i]-'0';
	}
	for(int i = len_B-1; i >= 0; i--){
		B[(len_B-1)-i] = buf_B[i]-'0';
		if(B[(len_B-1)-i] == 1){
			B_POS.insert(get_index((len_B-1)-i));
			if(A[(len_B-1)-i] == 1){
				COMMON_POS.insert(get_index((len_B-1)-i));
			}
		}
	}

	N = 1;
	init(len_max+1);

	for(int i = 0; i <= 2*N-2; i++)table[i] = false;
	for(int i = 0; i <= len_max; i++)BIT[i] = 0;

	for(int i = 0; i < len_max; i++){
		add(get_index(i),A[i]);
		update(get_index(i));
	}

	char command[2];
	int tmp_loc,B_head_loc,tmp,COMMON_head_loc;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%s",command);

		switch(command[0]){
		case 'A':
			scanf("%d",&tmp_loc);

			if(A[tmp_loc] == 0){

				A[tmp_loc] = 1;
				add(get_index(tmp_loc),1);
				if(B[tmp_loc] == 1){
					COMMON_POS.insert(get_index(tmp_loc));
				}

			}else{ //A[tmp_loc] == 1

				A[tmp_loc] = 0;
				add(get_index(tmp_loc),-1);
				COMMON_POS.erase(get_index(tmp_loc));

			}
			update(get_index(tmp_loc));

			break;
		case 'B':
			scanf("%d",&tmp_loc);

			if(B[tmp_loc] == 0){

				B[tmp_loc] = 1;
				B_POS.insert(get_index(tmp_loc));
				if(A[tmp_loc] == 1){
					COMMON_POS.insert(get_index(tmp_loc));
				}

			}else{ //B[tmp_loc] == 1

				B[tmp_loc] = 0;
				B_POS.erase(get_index(tmp_loc));
				COMMON_POS.erase(get_index(tmp_loc));

			}
			update(get_index(tmp_loc));

			break;
		case 'Q':

			B_head_loc = *B_POS.rbegin();

			if(B_head_loc < 0){

				printf("%d\n",getSum(get_index(len_max)));

			}else{

				tmp = calc(B_head_loc+1,get_index(len_max))+B_head_loc-1;

				if(A[B_head_loc-1] == 1){

					printf("%d\n",tmp+1);

				}else{

					if(!COMMON_POS.empty()){

						COMMON_head_loc = *COMMON_POS.rbegin();

						if(is_all_1(COMMON_head_loc+1,B_head_loc,0,0,N-1)){

							printf("%d\n",tmp+1);

						}else{

							printf("%d\n",tmp);
						}

					}else{
						printf("%d\n",tmp);
					}
				}
			}

			break;
		}
	}

	return 0;
}


### Prompt

Construct a Cpp code solution to the problem outlined:

Ikta, who was in trouble because he couldn't come up with an idea for the problem to be presented at the training camp of the programming contest, consulted with a friend one day.

Mr. Ikta "I want to create a problem that cannot be solved without using such an algorithm. Is there anything?"

Friend "Then why not think about something like this?"

In this way, the friend came up with the idea that would be the basis for the following problems.

Given binary numbers A and B, process the following query.

* Output query: Outputs the number of 1s when max {x is expressed in binary | A ≤ x <A + B}
* A change query: Inverts the i-th bit (0-origin) from the least significant bit of A
* B change query: Inverts the i-th bit (0-origin) from the least significant bit of B



Note that the i-bit is represented by 0-origin. That is, the 0th bit from the least significant bit of A represents the least significant bit.



Input

The input is given in the following format.


N A B
Q1
...
QN

The number of queries N, binary numbers A and B are given in the first line.

The following query is given in the 2nd to N + 1 lines.

* Q
* A i
* B i



Q represents the output query, and A i and B i represent the change query that inverts the i-th bit from the least significant bit of A and the i-th bit from the least significant bit of B, respectively.

Constraints

Each variable being input satisfies the following constraints.

* 1 ≤ N <300,000
* 1 ≤ | A |, | B | ≤ 300,000 (| A | is the length of A)
* In the query A i, 0 ≤ i <| A |
* In the query B i 0 ≤ i <| B |
* B can never be 0

Output

Print the answer on one line for each output query.

Examples

Input

4 10000 00101
Q
A 0
B 1
Q


Output

3
4


Input

9 0110111101 0010100111
Q
B 4
Q
A 4
Q
B 9
Q
A 8
Q


Output

9
9
9
10
9

### Response

```cpp
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000005

int N;
int BIT[NUM];
int A[NUM],B[NUM];
int len_A,len_B,len_max;
char buf_A[NUM],buf_B[NUM];
bool table[NUM];
set<int> B_POS,COMMON_POS;

void add(int loc,int value){

	BIT[loc] += value;

	loc += loc & -loc;

	while(loc <= N){
		BIT[loc] += value;
		loc += loc & -loc;
	}
}

int getSum(int loc){

	int sum = BIT[loc];

	loc -= loc & -loc;

	while(loc > 0){
		sum += BIT[loc];
		loc -= loc & -loc;
	}
	return sum;
}


int calc(int left,int right){
	return getSum(right)-getSum(left-1);
}

void init(int first_N){
	while(N < first_N)N *= 2;
}

void update(int loc){
	loc += N-1;

	table[loc] = (A[loc-(N-1)-1] == 1 || B[loc-(N-1)-1]);

	if(N == 1)return;

	int parent = (loc-1)/2;

	while(true){
		table[parent] = table[2*parent+1] && table[2*parent+2];

		if(parent == 0)break;
		else{
			parent = (parent-1)/2;
		}
	}
}

bool is_all_1(int search_left,int search_right,int node_id,int node_left,int node_right){

	if(search_right < node_left || search_left > node_right){
		return true;
	}

	if(search_left <= node_left && search_right >= node_right){
		return table[node_id];
	}

	bool is_left = is_all_1(search_left,search_right,2*node_id+1,node_left,(node_left+node_right)/2);
	bool is_right = is_all_1(search_left,search_right,2*node_id+2,(node_left+node_right)/2+1,node_right);

	return is_left && is_right;
}

int get_index(int loc){

	return loc+1;
}


int main(){

	int num_query;
	scanf("%d %s %s",&num_query,buf_A,buf_B);

	for(len_A = 0; buf_A[len_A] != '\0'; len_A++);
	for(len_B = 0; buf_B[len_B] != '\0'; len_B++);

	len_max = max(len_A,len_B);

	for(int i = 0; i < len_max; i++){
		A[i] = 0;
		B[i] = 0;
	}

	for(int i = len_A-1; i >= 0; i--){
		A[(len_A-1)-i] = buf_A[i]-'0';
	}
	for(int i = len_B-1; i >= 0; i--){
		B[(len_B-1)-i] = buf_B[i]-'0';
		if(B[(len_B-1)-i] == 1){
			B_POS.insert(get_index((len_B-1)-i));
			if(A[(len_B-1)-i] == 1){
				COMMON_POS.insert(get_index((len_B-1)-i));
			}
		}
	}

	N = 1;
	init(len_max+1);

	for(int i = 0; i <= 2*N-2; i++)table[i] = false;
	for(int i = 0; i <= len_max; i++)BIT[i] = 0;

	for(int i = 0; i < len_max; i++){
		add(get_index(i),A[i]);
		update(get_index(i));
	}

	char command[2];
	int tmp_loc,B_head_loc,tmp,COMMON_head_loc;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%s",command);

		switch(command[0]){
		case 'A':
			scanf("%d",&tmp_loc);

			if(A[tmp_loc] == 0){

				A[tmp_loc] = 1;
				add(get_index(tmp_loc),1);
				if(B[tmp_loc] == 1){
					COMMON_POS.insert(get_index(tmp_loc));
				}

			}else{ //A[tmp_loc] == 1

				A[tmp_loc] = 0;
				add(get_index(tmp_loc),-1);
				COMMON_POS.erase(get_index(tmp_loc));

			}
			update(get_index(tmp_loc));

			break;
		case 'B':
			scanf("%d",&tmp_loc);

			if(B[tmp_loc] == 0){

				B[tmp_loc] = 1;
				B_POS.insert(get_index(tmp_loc));
				if(A[tmp_loc] == 1){
					COMMON_POS.insert(get_index(tmp_loc));
				}

			}else{ //B[tmp_loc] == 1

				B[tmp_loc] = 0;
				B_POS.erase(get_index(tmp_loc));
				COMMON_POS.erase(get_index(tmp_loc));

			}
			update(get_index(tmp_loc));

			break;
		case 'Q':

			B_head_loc = *B_POS.rbegin();

			if(B_head_loc < 0){

				printf("%d\n",getSum(get_index(len_max)));

			}else{

				tmp = calc(B_head_loc+1,get_index(len_max))+B_head_loc-1;

				if(A[B_head_loc-1] == 1){

					printf("%d\n",tmp+1);

				}else{

					if(!COMMON_POS.empty()){

						COMMON_head_loc = *COMMON_POS.rbegin();

						if(is_all_1(COMMON_head_loc+1,B_head_loc,0,0,N-1)){

							printf("%d\n",tmp+1);

						}else{

							printf("%d\n",tmp);
						}

					}else{
						printf("%d\n",tmp);
					}
				}
			}

			break;
		}
	}

	return 0;
}


```