Problem: At Akabe High School, a programmer training school, there is a unique study session run by the students themselves. It is important for programmers to constantly adopt new technologies, so the aim of this activity is to develop the habit of self-study through this study session.

There are a total of N students, each with a score obtained as a result of the programming contest at the time of admission. At the study session, some of the N students will become leaders, and each leader will run their own group and join the group they run.

Students other than the leader cannot join a group run by a leader with a score lower than their own. In addition, one value r that is 0 or more is decided so that the difference between the scores of the students participating in the group and the leader is within r. That is, if the leader of a group has a score of s and your score is greater than or less than s --r, you will not be able to join the group.

You are the executive committee chair of the study session and decided to do a simulation to prepare for the operation. In the simulation, start with no leader and repeat the following operations several times.

* Add students as leaders.
* Remove the student from the leader.
* For the combination of leaders at the time of request, find the minimum r such that the number of students who cannot participate in any group is x or less.



Create a program that performs such a simulation.



input

The input consists of one dataset. The input is given in the following format.


N Q
s1
s2
::
sN
QUERY1
QUERY2
::
QUERYQ


The first line gives the number of students N (1 ≤ N ≤ 1000000) and the number of processing requests Q (0 ≤ Q ≤ 1000).

The following N lines are given the integer si (0 ≤ si ≤ 1,000,000,000) indicating the score of the i-th student. Students shall be numbered 1,2, ..., N.

The processing request QUERYi is given to the following Q line. Processing requests are given in chronological order. There are three types of processing requests: ADD, REMOVE, and CHECK, and each QUERYi is given in one of the following formats.


ADD a


Or


REMOVE a


Or


CHECK x


ADD a stands for adding a student with the number a (1 ≤ a ≤ N) to the leader.

REMOVE a represents removing the student with the number a (1 ≤ a ≤ N) from the leader.

CHECK x represents an output request. An upper limit on the number of students who cannot join any group x (0 ≤ x ≤ N) is given.

The input shall satisfy the following conditions.

* At any given time, the number of leaders will not exceed 100.
* Do not add students who are leaders at that time to leaders.
* Students who are not leaders at that time will not be removed from the leader.

output

At the time of each output request in chronological order, the minimum r is output on one line so that the number of students who cannot join any group is x or less. However, if it is impossible to reduce the number of people to x or less no matter what r is selected, NA is output.

Example

Input

5 8
5
10
8
7
3
ADD 1
ADD 3
CHECK 0
CHECK 1
CHECK 2
CHECK 3
CHECK 4
CHECK 5


Output

NA
2
1
0
0
0

Solution (in CPP):

Solution:
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	bool operator<(const struct Info &arg) const{
		return score < arg.score;
	};
	int score,id;
};


int main(){

	int N,Q;
	scanf("%d %d",&N,&Q);

	Info* info = (Info*)malloc(sizeof(Info)*(N+1));

	info[0].score = -1;
	vector<int> SCORE;
	SCORE.push_back(-1);
	for(int i = 1; i <= N; i++){
		scanf("%d",&info[i].score);
		SCORE.push_back(info[i].score);
	}

	sort(SCORE.begin(),SCORE.end());

	int* score_ruisekiwa = new int[N+1];
	int* score = new int[N+1];

	int score_index = 1;

	score[0] = -1;
	score_ruisekiwa[0] = 0;

	for(int i = 1; i <= N; ){

		score[score_index] = SCORE[i];
		score_ruisekiwa[score_index] = 0;

		while(score[score_index] == SCORE[i] && i <= N){
			score_ruisekiwa[score_index]++;
			i++;
		}
 		score_ruisekiwa[score_index] += score_ruisekiwa[score_index-1];
 		score_index++;
	}

	int* loc = new int[N+1];

	int left,right,m;

	for(int i = 1; i <= N; i++){

		left = 1,right = score_index-1,m = (left+right)/2;

		while(left <= right){
			if(score[m] == info[i].score){
				loc[i] = m;
				break;
			}else if(score[m] < info[i].score){
				left = m+1;
			}else{
				right = m-1;
			}
			m = (left+right)/2;
		}
	}

	char order[10];
	int value,current_number,need_number,max_loc;

	bool* check = new bool[score_index];

	vector<int> V;
	vector<Info> work;
	bool FLG;

	int calc_left,calc_right,calc_m;

	for(int loop = 0; loop < Q; loop++){
		scanf("%s %d",order,&value);

		switch(order[0]){
		case 'A':
			V.push_back(value);
			break;
		case 'R':
			for(int i = 0; i < V.size(); i++){
				if(V[i] == value){
					V.erase(V.begin()+i);
					break;
				}
			}
			break;
		case 'C':

			work.clear();

			need_number = N - value;
			max_loc = 0;

			for(int i = 0 ; i <= score_index-1; i++)check[i] = false;

			for(int i = 0; i < V.size(); i++){
				max_loc = max(max_loc,loc[V[i]]);
				FLG = true;
				for(int k = i+1; k < V.size(); k++){
					if(loc[V[i]] == loc[V[k]]){
						FLG = false;
					}
				}
				if(FLG){
					Info new_info;
					new_info.id = V[i];
					new_info.score = score[loc[V[i]]];
					work.push_back(new_info);
					check[loc[V[i]]] = true;
				}
			}

			if(score_ruisekiwa[max_loc] < need_number){
				printf("NA\n");
				continue;
			}

			current_number = 0;
			for(int i = 0; i < work.size(); i++){
				current_number += score_ruisekiwa[loc[work[i].id]] - score_ruisekiwa[loc[work[i].id]-1];
			}

			if(current_number >= need_number){
				printf("0\n");
				continue;
			}

			int ans = 0;
			int left_loc,right_loc;

			sort(work.begin(),work.end());

			left = 0,right = score[max_loc],m = (left+right)/2;

			while(left <= right){

				int tmp = 0;

				for(int i = 0; i < work.size(); i++){

					int left_score = 0;
					if(i > 0){
						left_score = work[i-1].score;

						if(work[i].score-m <= left_score){

							left_loc = loc[work[i-1].id]+1;
							right_loc = loc[work[i].id]-1;

							if(left_loc <= right_loc){
								tmp += score_ruisekiwa[right_loc]-score_ruisekiwa[left_loc-1];
							}
						}else{

							if(work[i].score-m > score[loc[work[i].id]-1]){
								continue;
							}
							right_loc = loc[work[i].id]-1;

							calc_left = loc[work[i-1].id]+1;
							calc_right = right_loc;
							calc_m = (calc_left+calc_right)/2;

							while(calc_left <= calc_right){

								if(score[calc_m] >= work[i].score-m){
									left_loc = calc_m;
									calc_right = calc_m-1;
								}else{
									calc_left = calc_m+1;
								}
								calc_m = (calc_left+calc_right)/2;
							}
							tmp += score_ruisekiwa[right_loc]-score_ruisekiwa[left_loc-1];
						}

					}else{ // i == 0

						if(loc[work[i].id] == 1 || work[i].score-m > score[loc[work[i].id]-1]){
							continue;
						}

						right_loc = loc[work[i].id]-1;

						calc_left = 1;
						calc_right = right_loc;
						calc_m = (calc_left+calc_right)/2;

						while(calc_left <= calc_right){

							if(score[calc_m] >= work[i].score-m){
								left_loc = calc_m;
								calc_right = calc_m-1;
							}else{
								calc_left = calc_m+1;
							}
							calc_m = (calc_left+calc_right)/2;
						}
						tmp += score_ruisekiwa[right_loc]-score_ruisekiwa[left_loc-1];
					}
				}

				if(current_number+tmp >= need_number){
					ans = m;
					right = m-1;
				}else{
					left = m+1;
				}
				m = (left+right)/2;
			}

			printf("%d\n",ans);

			break;
		}
	}

	return 0;
}