The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it.However, one day, the members somehow entered the sequence into the document at the same time, creating a jumbled mess. Therefore, it is Suguru Doujima's task to figure out whether the document has malfunctioned. Specifically, he is given a string of length $$$n$$$ whose characters are all either T or M, and he wants to figure out if it is possible to partition it into some number of disjoint subsequences, all of which are equal to TMT. That is, each character of the string should belong to exactly one of the subsequences.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero) characters.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$)  — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$3 \le n < 10^5$$$), the number of characters in the string entered in the document. It is guaranteed that $$$n$$$ is divisible by $$$3$$$. The second line of each test case contains a string of length $$$n$$$ consisting of only the characters T and M. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single line containing YES if the described partition exists, and a single line containing NO otherwise.

5
3
TMT
3
MTT
6
TMTMTT
6
TMTTTT
6
TTMMTT

NoteIn the first test case, the string itself is already a sequence equal to TMT.In the third test case, we may partition the string into the subsequences TMTMTT. Both the bolded and the non-bolded subsequences are equal to TMT.

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const s = readLine();

        b(n,s);

    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

function b(n,s){
    let t = [];
    let m = [];
    let cnt = 0;
        for(let i= 0 ; i < n; i++) s[i] === 'T' ? t.push(i) : m.push(i);
        if(t.length/m.length !== 2) return console.log('NO');
        for(let i = 0; i < m.length; i++)
            if(m[i] < t[i] || m[i] > t[i + m.length]) return console.log('NO');
    return console.log('YES');
}

module.exports = b

"use strict";
//////////// LIBS
Object.defineProperty(exports, "__esModule", { value: true });
class IO {
    constructor() {
        this.lines = [];
        this.tokens = [];
        this.lines = require('fs').readFileSync(0, 'utf8').split('\n');
    }
    getTokens() {
        if (!this.tokens.length) {
            this.tokens = this.nextLine().split(' ');
        }
        return this.tokens;
    }
    nextLine() {
        return this.lines.shift().trim();
    }
    nextNum() {
        return Number(this.getTokens().shift());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
}
function solve(n, str) {
    let m = [];
    let t = [];
    str.split('').forEach((c, i) => {
        if (c === 'T') {
            t.push(i);
        }
        else {
            m.push(i);
        }
    });
    if (m.length * 2 !== t.length) {
        console.log('NO');
        return;
    }
    for (let i = 0; i < m.length; i++) {
        if (t[i] > m[i] || t[i + m.length] < m[i]) {
            console.log('NO');
            return;
        }
    }
    console.log('YES');
}
function main() {
    const io = new IO();
    let t = io.nextNum();
    while (t--) {
        let n = io.nextNum();
        let str = io.nextLine();
        solve(n, str);
    }
}
main();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var s = next();
		var T = [];
		var M = [];
		for(var j = 0; j < N; j++){
			if(s[j] == "T"){
				T.push(j);
			}else{
				M.push(j);
			}
		}
		if(T.length == M.length * 2){
			var isOK = true;
			for(var j = 0; j < M.length; j++){
				if(M[j] < T[j] || M[j] > T[j + M.length]){
					isOK = false;
					break;
				}
			}
			myout((isOK) ? "YES" : "NO");
		}else{
			myout("NO");
		}
	}
}

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1);

	for (let i=1; i<lines.length; i+=2) {
		const str = lines[i].trim();

		let tCounter = 0;
		let mCounter = 0;
		let tCounter2 = 0;
		let mCounter2 = 0;

		let flag = true;

		for (let j=0; j<str.length; j++) {
			if (str[str.length-1-j] === 'M') {
				mCounter2++;

				if (mCounter2 > tCounter2) {
					flag = false;
					break;
				}
			}

			if (str[str.length-1-j] === 'T') {
				tCounter2++;
			}

			if (str[j] === 'M') {
				mCounter++;

				if (mCounter > tCounter) {
					flag = false;
					break;
				}
			}

			if (str[j] === 'T') {
				tCounter++;
			}
		}

		if (flag && (mCounter * 2 === tCounter)) {
			console.log('YES')
		} else {
			console.log('NO')
		}
	}

})

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim().split("");
    let tc = 0,
      mc = 0,
      ans = true;
    for (let i = 0; i < n; i++) {
      if (str[i] === "T") tc++;
      else mc++;
      if (mc > tc) {
        ans = false;
        break;
      }
    }
    if (ans === false) {
      console.log("NO");
      continue;
    }
    (tc = 0), (mc = 0);
    for (let i = n - 1; i >= 0; i--) {
      if (str[i] === "T") tc++;
      else mc++;
      if (mc > tc) {
        ans = false;
        break;
      }
    }
    if (ans === false) console.log("NO");
    else {
      if (tc / 2 === mc) console.log("YES");
      else console.log("NO");
    }
  }
};
solve();

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        main()
        process.exit(0)
    }
})

function solve(n, str) {
    str = str.split('')
    let tc = 0, mc = 0, cc = 0
    for (let i = 0; i < n; i++) {
        if (str[i] === 'T') {
            tc++
            if (cc < 0) cc++
        } else {
            mc++
            cc--
        }
        if (mc > tc) return false
    }
    mc *= 2
    return !(cc !== 0 || mc !== tc)
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i], inputArr[i + 1]);
        (res) ? console.log('YES') : console.log('NO')
    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  const xx = readline();
  Array(Number(xx)).fill(1).map((t, i) => {
    var n = parseInt(readline());
    // var [n, k] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // })
    var a = readline().split('').map((x, iii) => {
      return x
    });
    var count1 = 0
    var count2 = 0

    for (let j = 0; j < n; j++) {
      if (a[j] === 'T') count1++
      if (a[j] === 'M') count2++
      if (a[j] === 'M' && count1 < count2) return console.log('NO')
    }
    count1 = 0
    count2 = 0

    for (let j = n - 1; j >= 0; j--) {
      if (a[j] === 'T') count1++
      if (a[j] === 'M') count2++
      if (a[j] === 'M' && count1 < count2) return console.log('NO')
    }
    if (count1 !== count2 * 2) return console.log('NO')
    console.log('YES')
  })
}

/**
 * 04/16/21 morning
 * https://codeforces.com/contest/1509/problem/B
 */

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, s) => {
    let t = [];
    let m = [];
    for (let i = 0; i < n; i++) {
        s[i] == 'T' ? t.push(i) : m.push(i);
    }
    // pr(t, m)
    let tn = t.length;
    let mn = m.length;
    if (2 * mn != tn) return pr("NO");
    let res = [];
    while (1) {
        if (t.length == 0 || m.length == 0) break;
        let t1 = t.shift();
        let t2 = t.pop();
        let m1 = m.shift();
        // pr([t1, m1, t2]);
        if (m1 < t1 || m1 > t2) return pr("NO");
        res.push([t1, m1, t2]);
    }
    // pr(res);
    if (res.length * 3 != n) return pr("NO");
    pr("YES");
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

/**
 * 04/16/21 morning
 * https://codeforces.com/contest/1509/problem/B
 */

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, s) => {
    let t = [];
    let m = [];
    for (let i = 0; i < n; i++) {
        s[i] == 'T' ? t.push(i) : m.push(i);
    }
    // pr(t, m)
    let tn = t.length;
    let mn = m.length;
    if (2 * mn != tn) return pr("NO");
    let res = [];
    while (1) {
        if (t.length == 0 || m.length == 0) break;
        let t1 = t.shift();
        let t2 = t.pop();
        let m1 = m.shift();
        // pr([t1, m1, t2]);
        if (m1 < t1 || m1 > t2) return pr("NO");
        res.push([t1, m1, t2]);
    }
    // pr(res);
    pr("YES");
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const s = readLine();

        let t = 0;
        let m = 0;
        let cnt = 0;
        for(let i= 0 ; i < n; i++){
            if(s[i] === 'T')
            {
                t++;
                if(cnt < 0) cnt++;
            }
            else
            {
                m++;
                cnt--;
            }
            if(m > t)
            {
                console.log('NO');
                break;
            }
        }
        cnt != 0 || m*2 != t ?  console.log('NO') : console.log('YES');
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
data += chunk;
});

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

    let testCases = parseInt(readLine());

    while(testCases--) {

        const n = parseInt(readLine());

        const s = readLine();

        let t = 0;
        let m = 0;
        let end = false;
        for(let i= 0 ; i < n; i++){
            if(s[i] === 'T') t++;
            else m++;
            if(m > t){
                console.log('NO');
                end = true;
                break;
            }
        }
        if(!end) m*2 === t ?  console.log('YES') : console.log('NO');

    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

function readLine() {
        return data[currentLine++];
}

"use strict";
//////////// LIBS
Object.defineProperty(exports, "__esModule", { value: true });
class IO {
    constructor() {
        this.lines = [];
        this.tokens = [];
        this.lines = require('fs').readFileSync(0, 'utf8').split('\n');
    }
    getTokens() {
        if (!this.tokens.length) {
            this.tokens = this.nextLine().split(' ');
        }
        return this.tokens;
    }
    nextLine() {
        return this.lines.shift();
    }
    nextNum() {
        return Number(this.getTokens().shift());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
}
function solve(n, str) {
    let m = [];
    let t = [];
    str.split('').forEach((c, i) => {
        if (c === 'T') {
            t.push(i);
        }
        else {
            m.push(i);
        }
    });
    if (m.length * 2 !== t.length) {
        console.log('NO');
        return;
    }
    for (let i = 0; i < m.length; i++) {
        if (t[i] > m[i] || t[i + m.length] < m[i]) {
            console.log('NO');
            return;
        }
    }
    console.log('YES');
}
function main() {
    const io = new IO();
    let t = io.nextNum();
    while (t--) {
        let n = io.nextNum();
        let str = io.nextLine();
        solve(n, str);
    }
}
main();

"use strict";
//////////// LIBS
Object.defineProperty(exports, "__esModule", { value: true });
class IO {
    constructor() {
        this.lines = [];
        this.tokens = [];
        this.lines = require('fs').readFileSync(0, 'utf8').split('\n');
    }
    getTokens() {
        if (!this.tokens.length) {
            this.tokens = this.nextLine().split(' ');
        }
        return this.tokens;
    }
    nextLine() {
        return this.lines.shift();
    }
    nextNum() {
        return Number(this.getTokens().shift());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
}
function solve(n, str) {
    let l = 0;
    let r = n - 1;
    let count = 0;
    for (let i = 0; i < n; i++) {
        if (str[i] === 'M') {
            count++;
        }
    }
    if (n / 3 !== count) {
        console.log('NO');
        return;
    }
    for (let i = 0; i < n; i++) {
        // console.log(str[i], { l, r });
        if (str[i] === 'M') {
            if (str[l] === 'M' || str[r] === 'M') {
                console.log('NO');
                return;
            }
            l++;
            r--;
            if (l == i) {
                l++;
            }
        }
    }
    console.log('YES');
}
function main() {
    const io = new IO();
    let t = io.nextNum();
    while (t--) {
        let n = io.nextNum();
        let str = io.nextLine();
        solve(n, str);
    }
}
main();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var s = nextCharArray();
		var T = [];
		var M = [];
		for(var j = 0; j < N; j++){
			if(s[j] == "T"){
				T.push(j);
			}else{
				M.push(j);
			}
		}
		var isOK = true;
		for(var j = 0; j < M.length; j++){
			var index = M[j];
			var L = T[0];
			var R = T[T.length - 1];
			if(L < index && index < R){
				T.shift();
				T.pop();
			}else{
				isOK = false;
			}
		}
		if(isOK && T.length == 0){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1);

	for (let i=1; i<lines.length; i+=2) {
		const str = lines[i].trim();

		let tCounter = 0;
		let mCounter = 0;
		let flag = true;

		for (let j=0; j<str.length; j++) {
			if (str[j] === 'M') {
				mCounter++;

				if (mCounter > tCounter) {
					flag = false;
					break;
				}
			}

			if (str[j] === 'T') {
				tCounter++;
			}
		}

		if (flag && (mCounter * 2 === tCounter)) {
			console.log('YES')
		} else {
			console.log('NO')
		}
	}

})

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1);

	for (let i=1; i<lines.length; i+=2) {
		const str = lines[i].trim();

		let tCounter = 0;
		let mCounter = 0;
		for (let j=0; j<str.length; j++) {
			if (str[j] === 'M') {
				mCounter++;
			}

			if (str[j] === 'T') {
				tCounter++;
			}
		}

		if (
			mCounter*2 === tCounter &&
			str[0] !== 'M' &&
			str[str.length-1] !== 'M'
		) {
			console.log('YES');
		} else {
			console.log('NO')
		}
	}

})

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let str = readline().trim().split("");
    let tc = 0,
      mc = 0,
      ans = true;
    for (let i = 0; i < n; i++) {
      if (str[i] === "T") tc++;
      else mc++;
      if (mc > tc) {
        ans = false;
        break;
      }
    }
    if (ans === false) console.log("NO");
    else {
      if (tc / 2 === mc) console.log("YES");
      else console.log("NO");
    }
  }
};
solve();


Mihai has just learned about the MEX concept and since he liked it so much, he decided to use it right away.Given an array $$$a$$$ of $$$n$$$ non-negative integers, Mihai wants to create a new array $$$b$$$ that is formed in the following way:While $$$a$$$ is not empty:   Choose an integer $$$k$$$ ($$$1 \leq k \leq |a|$$$).  Append the MEX of the first $$$k$$$ numbers of the array $$$a$$$ to the end of array $$$b$$$ and erase them from the array $$$a$$$, shifting the positions of the remaining numbers in $$$a$$$. But, since Mihai loves big arrays as much as the MEX concept, he wants the new array $$$b$$$ to be the lexicographically maximum. So, Mihai asks you to tell him what the maximum array $$$b$$$ that can be created by constructing the array optimally is.An array $$$x$$$ is lexicographically greater than an array $$$y$$$ if in the first position where $$$x$$$ and $$$y$$$ differ $$$x_i > y_i$$$ or if $$$|x| > |y|$$$ and $$$y$$$ is a prefix of $$$x$$$ (where $$$|x|$$$ denotes the size of the array $$$x$$$).The MEX of a set of non-negative integers is the minimal non-negative integer such that it is not in the set. For example, MEX({$$${1, 2, 3}$$$}) $$$= 0$$$ and MEX({$$${0, 1, 2, 4, 5}$$$}) $$$= 3$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of elements in the array $$$a$$$. The second line of each test case contains $$$n$$$ non-negative integers $$$a_1, \ldots, a_n$$$ ($$$0 \leq a_i \leq n$$$), where $$$a_i$$$ is the $$$i$$$-th integer from the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print $$$m$$$ — the length of the maximum array $$$b$$$ Mihai can create, followed by $$$m$$$ integers denoting the elements of the array $$$b$$$.

NoteIn the first test case, the lexicographically maximum array $$$b$$$ is obtained by selecting $$$k=5$$$, resulting in the $$$MEX$$$ of the whole array $$$a$$$. It is lexicographically maximum because an array starting with a smaller number than $$$4$$$ is lexicographically smaller, and choosing a $$$k<5$$$ would result in an array starting with a number smaller than $$$4$$$.In the second test case, there are two ways to obtain the maximum array: first selecting $$$k=6$$$, then $$$k=2$$$, or first selecting $$$k=7$$$ and then $$$k=1$$$.

// https://codeforces.com/problemset/problem/1628/A

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline());
        const arr = readline().split(' ').map(el=>parseInt(el));
        const sol = findMeximum(arr);
        console.log(sol.length)
        for(let el of sol){
            process.stdout.write(`${el} `)
        }
        console.log()
    }
}

findMeximum = (arr)=>{
    let lowerBound = (arr, target)=>{
        if(arr.length == 0 )
            return undefined;
        let start = 0, end = arr.length;
        while(start !== end){
            const middle = Math.floor((start + end) / 2);

            if(arr[middle] < target){
                start = middle + 1;
            }
            else{
                end = middle;
            }
        }
        if(arr[start] >= target){
            return arr[start]
        }
        else{
            return undefined;
        }
    }
    // find pos array

    let max = arr.length;
    // for(let el of arr){
    //     max = Math.max(max,el)
    // }
    let pos = new Array(max+1);

    for(let i =0; i<= max; ++i){
        pos[i] = [];
    }

    for(let i=0; i<arr.length; ++i){

        try{
            pos[arr[i]].push(i);
        }
        catch(e){
            console.log(e, i, arr[i], pos.length)
            break;
        }
    }
    let l = 0, r = 0;
    let sol = [];
    while(l < arr.length){
        let mex = 0;
        r = l;

        for(;mex<=max; ++mex){
            const elPos = lowerBound(pos[mex], l);
            if(elPos!= undefined){
                r = Math.max(elPos, r);
            }
            else{// mex is not present
                break;
            }

        }

        l = r + 1
        sol.push(mex);
    }
    return sol;

}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 2e5+5;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const smex = [];
		let cnt = [];
		for (let i = n-1, cmex = 0; i >= 0; i--) {
			cnt[a[i]] = cnt[a[i]] + 1 || 1;
			while (cnt[cmex]) cmex++;
			smex[i] = cmex;
		}

		const ans = [];
		cnt = [];
		for (let i = 0, cmex = 0, L = 0; i < n; i++) {
			cnt[a[i]] = cnt[a[i]] + 1 || 1;
			while (cnt[cmex]) cmex++;
			if (cmex == smex[L]) {
				ans.push(cmex);
				cmex = 0;
				cnt = [];
				L = i + 1;
			}
		}

		console.log(ans.length);
		console.log(ans.join(' '));
	}
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 2e5+5;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const smex = [];
		let cnt = Array(mxN).fill(0);
		for (let i = n-1, cmex = 0; i >= 0; i--) {
			cnt[a[i]]++;
			while (cnt[cmex]) cmex++;
			smex[i] = cmex;
		}

		const ans = [];
		cnt = Array(mxN).fill(0);
		for (let i = 0, cmex = 0, L = 0; i < n; i++) {
			if (!cnt[a[i]]) cnt[a[i]] = 0;
			cnt[a[i]]++;
			while (cnt[cmex]) cmex++;
			if (cmex == smex[L])  {
				ans.push(cmex);
				cmex = 0;
				cnt = [];
				L = i + 1;
			}
		}

		console.log(ans.length);
		console.log(ans.join(' '));
	}
}

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		const freq = Array(n+1).fill(0);
		const delP = Array(n+1).fill(-1);

		for (let i = 0; i < n; i++) freq[a[i]]++;

		let mexC = 0;
		while (mexC < n && freq[mexC]) mexC++;

		const ans = [];
		let cnt = 0, lftP = 0, mexN = mexC;
		for (let i = 0; i < n; i++) {
			if (a[i] < mexC && delP[a[i]] < lftP) cnt++;

			freq[a[i]]--;
			if (freq[a[i]] == 0) mexN = Math.min(mexN, a[i]);

			delP[a[i]] = i;

			if (cnt == mexC) {
				ans.push(mexC);
				mexC = mexN;
				lftP = i + 1;
				cnt = 0;
			}
		}

		console.log(ans.length);
		console.log(ans.join(' '));
	}
}

// https://codeforces.com/problemset/problem/1628/A

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString
        .trim()
        .split("\n")
        .map((string) => {
            return string.trim();
        });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline());
        const arr = readline().split(' ').map(el=>parseInt(el));
        const sol = findMeximum(arr);
        console.log(sol.length)
        for(let el of sol){
            process.stdout.write(`${el} `)
        }
        console.log()
    }
}
findMeximum = (arr)=>{
    // find pos array

    let max = 0;
    for(let el of arr){
        max = Math.max(max,el)
    }
    console.log(max)
    let pos = new Array(max+1);

    for(let i =0; i<= max; ++i){
        pos[i] = [];
    }

    for(let i=0; i<arr.length; ++i){

        try{
            pos[arr[i]].push(i);
        }
        catch(e){
            console.log(e, i, arr[i], pos.length)
            break;
        }
    }
    let l = 0, r = 0;
    let sol = [];
    while(l < arr.length){
        let mex = 0;
        r = l;

        for(;mex<=max; ++mex){
            const elPos = pos[mex].find(el=>el >=l)
            if(elPos!= undefined){
                r = Math.max(elPos, r);
            }
            else{// mex is not present
                break;
            }

        }

        l = r + 1
        sol.push(mex);
    }
    return [...sol];

}


The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: d1 is the distance between the 1-st and the 2-nd station; d2 is the distance between the 2-nd and the 3-rd station;... dn - 1 is the distance between the n - 1-th and the n-th station; dn is the distance between the n-th and the 1-st station.The trains go along the circle line in both directions. Find the shortest distance between stations with numbers s and t.

The first line contains integer n (3 ≤ n ≤ 100) — the number of stations on the circle line. The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 100) — the distances between pairs of neighboring stations. The third line contains two integers s and t (1 ≤ s, t ≤ n) — the numbers of stations, between which you need to find the shortest distance. These numbers can be the same. The numbers in the lines are separated by single spaces.

Print a single number — the length of the shortest path between stations number s and t.

NoteIn the first sample the length of path 1 → 2 → 3 equals 5, the length of path 1 → 4 → 3 equals 13.In the second sample the length of path 4 → 1 is 100, the length of path 4 → 3 → 2 → 1 is 15.In the third sample the length of path 3 → 1 is 1, the length of path 3 → 2 → 1 is 2.In the fourth sample the numbers of stations are the same, so the shortest distance equals 0.

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
let arr;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (c === 1) {
    arr = d.split(' ').map(Number);
    c++;
    return;
  }

  let [start, end] = d.split(' ').map(Number);
  let left = 0;
  let right = 0;
  start--;
  end--;

  let x = start;
  let y = end;

  while(x !== y) {
    left += arr[x];
    x = (x + 1) % arr.length;
  }

  x = start;
  y = end;

  while (x !== y) {
    let r = (x - 1) % arr.length;
    if (r < 0) {
      r = r + arr.length;
    }
    x = r;
    right += arr[x];
  }

  const ans = Math.min(left, right);

  console.log(ans);

  c++;
});

var n=+readline();
var d=readline().split(' ').map(function(v){return+v});
var l=readline().split(' ');
var s=+l[0]-1;
var t=+l[1]-1;
var a=d.splice(Math.min(s, t), Math.abs(t-s) ).reduce(function(sum, v){return sum+v},0);
var b=d.reduce(function(sum, v){return sum+v},0);
print(Math.min(a,b));

var n = +readline(), d = readline().split(" ").map(Number), input = readline().split(" "),
s = +input[0], t = +input[1];
var cnt1 = 0, cnt2 = 0, check = true;

if(s == t){
	write(0);
	check = false;
}
else{
	for(var i = s-1; ;){
		cnt1 += d[i];
		i = (i == n-1) ? 0 : i+1;
		if(i == t-1){
			break;
		}
	}
	for(var i = ((s-2 < 0) ? n-1 : s-2); ;){
		cnt2 += d[i];
		i = (i == 0) ? n-1 : i-1;
		if(i == ((t-2 < 0) ? n-1 : t-2)){
			break;
		}
	}
}

if(check){
	write(Math.min(cnt1, cnt2));
}

;(function () {

	var n = +readline();
	var s = readline().split(' ').map(function (i) { return +i; });
	var p = readline().split(' ').map(function (i) { return +i; }).sort(function (a, b) { return a - b; });

	if (p[0] == p[1]) {
		print( 0 );
		return;
	} else {
		p[0]--;
		p[1]--;
	}

	var a = s.slice(p[0], p[1]).reduce(function (p, c, i, a) { return p + c; }, 0);
	var b = s.reduce(function (p, c, i, a) { return p + c; }, 0);

	print( Math.min(a, b-a) );

}).call(this);

;(function () {

	var n = +readline();
	var s = readline().split(' ').map(function (i) { return +i; });
	var p = readline().split(' ').map(function (i) { return +i; }).sort(function (a, b) { return a - b; });

	if (p[0] == p[1]) {
		print( 0 );
		return;
	} else {
		p[0]--;
		p[1]--;
	}

	var a = s.slice(p[0], p[1] - p[0]).reduce(function (p, c, i, a) { return p + c; }, 0);
	var b = s.reduce(function (p, c, i, a) { return p + c; }, 0);

	print( Math.min(a, b-a) );

}).call(this);


A TV show called "Guess a number!" is gathering popularity. The whole Berland, the old and the young, are watching the show.The rules are simple. The host thinks of an integer y and the participants guess it by asking questions to the host. There are four types of acceptable questions:  Is it true that y is strictly larger than number x?  Is it true that y is strictly smaller than number x?  Is it true that y is larger than or equal to number x?  Is it true that y is smaller than or equal to number x? On each question the host answers truthfully, "yes" or "no".Given the sequence of questions and answers, find any integer value of y that meets the criteria of all answers. If there isn't such value, print "Impossible".

The first line of the input contains a single integer n (1 ≤ n ≤ 10000) — the number of questions (and answers). Next n lines each contain one question and one answer to it. The format of each line is like that: "sign x answer", where the sign is:   ">" (for the first type queries),  "<" (for the second type queries),  ">=" (for the third type queries),  "<=" (for the fourth type queries).  All values of x are integer and meet the inequation  - 109 ≤ x ≤ 109. The answer is an English letter "Y" (for "yes") or "N" (for "no"). Consequtive elements in lines are separated by a single space.

Print any of such integers y, that the answers to all the queries are correct. The printed number y must meet the inequation  - 2·109 ≤ y ≤ 2·109. If there are many answers, print any of them. If such value doesn't exist, print word "Impossible" (without the quotes).

print(function(n){
	var high = 1e9+5;
	var low = -1e9-5;
	for(var i=0; i<n; i++){
		var l = readline().split(' ');

		if(l[0] === '>='){
			if(l[2] === 'Y'){
				low = Math.max(+l[1], low);
			}else{
				high = Math.min(+l[1]-1, high);
			}
		}else if(l[0] === '<='){
			if(l[2] === 'Y'){
				high = Math.min(+l[1], high);
			}else{
				low = Math.max(+l[1]+1, low);
			}
		}else if(l[0] === '>'){
			if(l[2] === 'Y'){
				low = Math.max(+l[1]+1, low);
			}else{
				high = Math.min(+l[1], high);
			}
		}else if(l[0] === '<'){
			if(l[2] === 'Y'){
				high = Math.min(+l[1]-1, high);
			}else{
				low = Math.max(+l[1], low);
			}
		}
	}
	if( high >= low ){
		return low;
	}
	return 'Impossible';

}(+readline()));

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
    return trim(s).split(/\s+/);
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=2*1000*1000*1000;
    var n = trim(readline());
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=parseInt(tokens[1]);
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);
            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);
        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function main(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    // var test = [">= 1 Y",
    //     "< 3 N",
    //     "<= -3 N",
    //     "> 55 N"
    // ];
    for (var i = 0; i < n; i++) {
        var li = readline().split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (maxn < minn) {
        print("Impossible");
    } else {
        print(maxn + "");
    }
}
main(+readline())

print(function(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    for (var i = 0; i < n; i++) {
        var li = readline().split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (maxn < minn) {
        return "Impossible";
    } else {
        return maxn;
    }
}(+readline()))

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var numConstraints = trim(readline()),
		minValue = -2*Math.pow(10, 9),
		maxValue = -minValue,
		inverse = { '<': '>=', '<=': '>', '>': '<=', '>=': '<' };
	for (var i = 0; i < numConstraints; ++i) {
		var tokens = trim(readline()).split(/\s+/),
			condition = tokens[0],
			limit = tokens[1],
			answer = tokens[2];
		if (answer == 'N') {
			condition = inverse[condition];
		}
		if (condition.charAt(0) == '>') {
			if (condition.length == 1) {
				++limit;
			}
			if (limit > maxValue) {
				print("Impossible");
				return;
			}
			minValue = Math.max(minValue, limit);
		} else {
			if (condition.length == 1) {
				--limit;
			}
			if (limit < minValue) {
				print("Impossible");
				return;
			}
			maxValue = Math.min(maxValue, limit);
		}
	}
	print(minValue);
}

main();

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else if (v==">")
    r = "<=";
  return r;
}
var min_ = -2000000000;
var max_ = 2000000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = l[2];
  if(yn=="N")
    sign = f(sign);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num - 1,max_);
  else if (sign==">")
    min_ = Math.max(num + 1,min_ );
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else if (v==">")
    r = "<=";
  return r;
}
var min_ = -2000000000;
var max_ = 2000000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = l[2];
  if(yn=="N")
    sign = f(sign);//equivoque de variablr

  if(sign==">=")
    min_ = Math.max(num,min_);//libreria
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num - 1,max_);
  else if (sign==">")
    min_ = Math.max(num + 1,min_ );
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");

print(function(n){
	var high = 1e9;
	var low = -1e9;
	for(var i=0; i<n; i++){
		var l = readline().split(' ');

		if(l[0] === '>='){
			if(l[2] === 'Y'){
				low = Math.max(+l[1], low);
			}else{
				high = Math.min(l[1]-1, high);
			}
		}else if(l[0] === '<='){
			if(l[2] === 'Y'){
				high = Math.min(+l[1], high);
			}else{
				low = Math.max(l[1]+1, low);
			}
		}else if(l[0] === '>'){
			if(l[2] === 'Y'){
				low = Math.max(l[1]+1, low);
			}else{
				high = Math.min(+l[1], high);
			}
		}else if(l[0] === '<'){
			if(l[2] === 'Y'){
				high = Math.min(l[1]-1, high);
			}else{
				low = Math.max(+l[1], low);
			}
		}
	}
	if( high >= low ){
		return low;
	}
	return 'Impossible';

}(+readline()));

print(function(n){
	var high = 1e9;
	var low = -1e9;
	for(var i=0; i<n; i++){
		var l = readline().split(' ');

		if(l[0] === '>='){
			if(l[2] === 'Y'){
				low = Math.max(+l[1], low);
			}else{
				high = Math.min(+l[1]-1, high);
			}
		}else if(l[0] === '<='){
			if(l[2] === 'Y'){
				high = Math.min(+l[1], high);
			}else{
				low = Math.max(+l[1]+1, low);
			}
		}else if(l[0] === '>'){
			if(l[2] === 'Y'){
				low = Math.max(+l[1]+1, low);
			}else{
				high = Math.min(+l[1], high);
			}
		}else if(l[0] === '<'){
			if(l[2] === 'Y'){
				high = Math.min(+l[1]-1, high);
			}else{
				low = Math.max(+l[1], low);
			}
		}
	}
	if( high >= low ){
		return low;
	}
	return 'Impossible';

}(+readline()));

print(function(n){
    var high = 1e9+5;
    var low = -1e9-5;
    for(var i=0; i<n; i++){
        var l = readline().split(' ');

        if(l[0] === '>='){
            if(l[2] === 'Y'){
                low = Math.max(+l[1], low);
            }else{
                high = Math.min(+l[1]-1, high);
            }
        }else if(l[0] === '<='){
            if(l[2] === 'Y'){
                high = Math.min(+l[1], high);
            }else{
                low = Math.max(+l[1]+1, low);
            }
        }else if(l[0] === '>'){
            if(l[2] === 'Y'){
                low = Math.max(+l[1]+1, low);
            }else{
                high = Math.min(+l[1], high);
            }
        }else if(l[0] === '<'){
            if(l[2] === 'Y'){
                high = Math.min(+l[1]-1, high);
            }else{
                low = Math.max(+l[1], low);
            }
        }
    }
    if( high >= low ){
        return low;
    }
    return 'Impossible';

} );

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
    return trim(s).split(/\s+/);
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=2*1000*1000*1000;
    var n = trim(readline());
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=tokens[1];
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);
            if(x==-6) print("aaaaaaaaaaaaaaa")
            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);
        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split();
}
function integers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=2*1000*1000*1000;
    var n = trim(readline());
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=tokens[1];
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);

            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);
        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split();
}
function integers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=-2*1000*1000*1000;
    var n = readline();
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=tokens[1];
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);

            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);

        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split();
}
function integers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=2*1000*1000*1000;
    var n = readline();
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=tokens[1];
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);

            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);

        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
    return trim(s).split(/\s+/);
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=2*1000*1000*1000;
    var n = trim(readline());
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=tokens[1];
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);

            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);
        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
    return trim(s).split(/\s+/);
}
function main() {
    minValue=-2*1000*1000*1000;
    maxValue=2*1000*1000*1000;
    var n = trim(readline());
    for(var i=0; i<n; ++i) {
        var tokens=trim(readline()).split(/\s+/);
        var r=tokens[0];
        var x=tokens[1];
        var a=tokens[2];
        if("Y"==a) {
            if(">="==r) minValue=Math.max(minValue, x);
            if(">"==r) minValue=Math.max(minValue, x+1);
            if(x==-6) print("aaaaaaaaaaaaaaa" +  minValue)
            if("<="==r) maxValue=Math.min(maxValue, x);
            if("<"==r) maxValue=Math.min(maxValue, x-1);
        } else {
            if("<"==r) minValue=Math.max(minValue, x);
            if("<="==r) minValue=Math.max(minValue, x+1);

            if(">"==r) maxValue=Math.min(maxValue, x);
            if(">="==r) maxValue=Math.min(maxValue, x-1);
        }
    }
    if(minValue<=maxValue) print(minValue);
    else print("Impossible");
}
main();

function main(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    for (var i = 0; i < n; i++) {
        var li = readline.split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (1) {
        print("Impossible");
    } else {
        print(maxn + "");
    }
}(+readline())

function main(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    for (var i = 0; i < n; i++) {
        var li = readline.split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (maxn < minn) {
        print("Impossible");
    } else {
        print(maxn + "");
    }
}(+readline())

function main(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    for (var i = 0; i < n; i++) {
        var li = readline.split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (maxn < minn) {
        console.log("Impossible");
    } else {
        console.log(maxn);
    }
}(+readline)

function main(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    for (var i = 0; i < n; i++) {
        var li = readline.split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (maxn < minn) {
        print("Impossible");
    } else {
        print(maxn);
    }
}(+readline)

function main(n) {
    var eq, YN, num, minn = -2 * 1e9,
        maxn = 2 * 1e9;
    // var test = [">= 1 Y",
    //     "< 3 N",
    //     "<= -3 N",
    //     "> 55 N"
    // ];
    for (var i = 0; i < n; i++) {
        var li = readline().split(" ");
        eq = li[0], num = +li[1], YN = li[2];
        if (eq === ">=") {
            if (YN === "Y") {
                minn = Math.max(minn, num);
            } else {
                maxn = Math.min(maxn, num - 1);
            }
        } else if (eq === "<=") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num);
            } else {
                minn = Math.max(minn, num + 1);
            }
        } else if (eq === "<") {
            if (YN === "Y") {
                maxn = Math.min(maxn, num - 1);
            } else {
                minn = Math.max(minn, num);
            }
        } else if (eq === ">") {
            if (YN === "Y") {
                minn = Math.max(minn, num + 1);
            } else {
                maxn = Math.min(maxn, num);
            }
        }
    }
    if (maxn < minn) {
        print("Impossible");
    } else {
        print(maxn + "");
    }
}(+readline())

function main()
{
    var n = parseInt(readline());
    var up = 1<<30;
    var low = -up;
    while ( n-- )
    {
        var tmp = readline().split(" ");
        tmp[1] = parseInt(tmp[1]);
        if ( tmp[2] == "N" )
        {
            if ( tmp[0] == ">=" )
                tmp[0] = "<=";
            else if ( tmp[0] == "<=" )
                tmp[0] = ">=";
            else if ( tmp[0] == ">" )
                tmp[0] = "<";
            else if ( tmp[0] == "<" )
                tmp[0] = ">";
        }
        if ( tmp[0] == ">" )
        {
            if ( tmp[1]+1 > low )
                low = tmp[1]+1;
        }
        else if ( tmp[0] == ">=" )
        {
            if ( tmp[1] > low )
                low = tmp[1];
        }
        else if ( tmp[0] == "<" )
        {
            if ( tmp[1]-1 < up )
                up = tmp[1]-1;
        }
        else if ( tmp[0] == "<=" )
        {
            if ( tmp[1] < up )
                up = tmp[1];
        }
    }
    if ( up < low )
        print("Impossible");
    else
        print(low);
}

main();

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else
    r = "<=";
  return r;
}
var min_ = -200000000;
var max_ = 200000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = +l[2];
  if(yn=="N")
    sign = f(yn);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num,max_- 1);
  else
    min_ = Math.max(num,min_ + 1);
}
if(min_ <= min_)
  print(min_);
else
  print("Impossible");

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else if (v==">")
    r = "<=";
  return r;
}
var min_ = -200000000;
var max_ = 200000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = l[2];
  if(yn=="N")
    sign = f(sign);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num,max_- 1);
  else if (sign==">")
    min_ = Math.max(num,min_ + 1);
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else if (v==">")
    r = "<=";
  return r;
}
var min_ = -200000000;
var max_ = 200000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = l[2];
  if(yn=="N")
    sign = f(yn);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num,max_- 1);
  else if (sign==">")
    min_ = Math.max(num,min_ + 1);
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else if (v==">")
    r = "<=";
  return r;
}
var min_ = -200000000;
var max_ = 200000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = +l[2];
  if(yn=="N")
    sign = f(yn);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num,max_- 1);
  else if (sign==">")
    min_ = Math.max(num,min_ + 1);
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else
    r = "<=";
  return r;
}
var min_ = -200000000;
var max_ = 200000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = +l[2];
  if(yn=="N")
    sign = f(yn);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num,max_- 1);
  else
    min_ = Math.max(num,min_ + 1);
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");

function f(v){
  var r = "";
  if(v==">=")
    r = "<";
  else if (v=="<=")
    r = ">";
  else if (v=="<")
    r = ">=";
  else if (v==">")
    r = "<=";
  return r;
}
var min_ = -200000000;
var max_ = 200000000;
var n = readline();
var sign;
var num;
var yn;
for(var i = 0; i < n; i++)//error poner var
{
  var l = readline().split(' ');
  sign = l[0];
  num = +l[1];
  yn = l[2];
  if(yn=="N")
    sign = f(sign);

  if(sign==">=")
    min_ = Math.max(num,min_);
  else if (sign=="<=")
    max_ = Math.min(num,max_);
  else if (sign=="<")
    max_ = Math.min(num - 1,max_);
  else if (sign==">")
    min_ = Math.max(num + 1,min_ );
}
if(min_ <= max_)
  print(min_);
else
  print("Impossible");


Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line. Unfortunately, from time to time Anton would forget writing some letter and write it again. He asks you to count the total number of distinct letters in his set.

The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space.

Print a single number — the number of distinct letters in Anton's set.

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin
});

rl.on('line', function(line){
    const set = new Set(line.replace(/{|}/g, '').split(',').map(e => e.trim()).filter(e => e.length));
    console.log(set.size);
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    if (input[0] === '{}') { console.log(0); process.exit(); }
    const n = new Set(input[0].slice(1, -1).split(' ').map(v => v[0]));
    console.log(n.size);
});

let fs = require('fs');

let txt = fs.readFileSync(0, "utf-8").split(/[\n\r]/).filter(data => data.length > 0);

for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split(/[{}, ]/).filter(data => data.length > 0));
}

function doit(tab) {
    console.log([...new Set(tab)].length);
}

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.replace(/[{()}\s+]/g, '').trim();
    let distinctLetters = inputs !== '' ? [...new Set(inputs.split(','))].length : 0;
    return distinctLetters.toString();
}

const readLine = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readLine.on('line', line => input.push(line));
const anton = () => {
    if (input[0] === '{}') {
        console.log(0);
    }
    else {
        let s = input[0].slice(1, -1);
        let ar = s.split(', ');
        let ar2 = new Set(ar);
        console.log(ar2.size);
    }
};

readLine.on('close', anton);

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

function count(s) {
    let c = 0;
    for (var i = 0; i < s.length; i++) {
        if (s.indexOf(s[i]) == i) {
            c++
        }
    }
    return c;
}

function readLine() {
    return inputString[currentLine++];
}

function main() {
    let s = readLine().replace(/[{}, ]/g, '');
    console.log(count(s));
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var s = next().replace("{", "").replace("}", "").replace(/ /g, "").split(",");
  if(s[0] == ""){
    myout(0);
  }else{
    myout(new Set(s).size);
  }

}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');

    check(letters)
})

function check(letters) {
    let counter = 1;

    if (letters.length == 0)
        return console.log(0)

    letters.sort((a, b) => {
        return a > b ? 1 : -1
    }).reduce((prev, curr) => {
        if (prev != curr)
            counter++;
        return curr
    })

    return console.log(counter)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const line = readline();
  const a = line.slice(1, line.length - 1)
    .split(',')
    .map(x => x.trim())
    .filter(x => x !== '');
  const s = new Set();
  for (let i = 0; i < a.length; i++) {
    s.add(a[i]);
  }
  // output
  print(s.size);
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (d) => {
  const str = d.slice(1, d.length - 1);

  if (str.length === 0) {
    console.log(0);
    return;
  }

  const data = str.split(', ');
  const ans = new Set(data).size;

  console.log(ans);
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function readint() {
    let line = readline().split(' ').map(function(num) {
        return parseInt(num);
    });
    return line;
}

function readfloat() {
    let line = readline().split(' ').map(function(num) {
        return parseFloat(num);
    });
    return line;
}

function print(x) {
    console.log(x);
}

function write(x) {
    process.stdout.write(x);
}
function main() {
    let a = readline();
    let set = new Set();
    if(a.length < 3) {
        print("0");
        return;
    }
    for (let i = 1; i < a.length; i+=3) {
        const element = a[i];
        set.add(element);
    }

    print(set.size);

}

const input = [];

const RL = require('readline').createInterface({
   input : process.stdin,
   output : process.stdout
});

RL.on('line', (line) => {
    input.push(line);
});

RL.on('close', () => {
  const line = input[0];
  const set = new Set();
  for (let i = 0; i < line.length; i += 1) {
    if (line[i] !== '{' && line[i] !== '}' && line[i] !== ' ' && line[i] !== ',')
      set.add(line[i]);
  }

  console.log(set.size);
});

if (!this.readline) print = console.log, readline = require('./readline');

var m = {};
var a = readline();

for (var i = 0; i < a.length; i++) {
  if (a[i] != '{' && a[i] != '}' && a[i] != ',' && a[i] != ' ') {
    m[a[i]] = 1;
  }
}

print(Object.keys(m).length);

var letters = readline().split(""), unique = [];
letters.pop();
letters.shift();
letters = letters.join("").split(", ");

for(i = 0; i < letters.length; i++){
	if( letters[0].length == 0 ){
		unique.length = 0;
		break;
	}
	if(i == 0){
		unique.push(letters[i]);
		continue;
	}
	if( unique.every(function(a){ return (a != letters[i]) ? true : false }) ){
		unique.push(letters[i]);
	}
}
write(unique.length);

var input = readline();
input = input.slice(1, input.length - 1);
if (input == '') {
    print(0);
} else {
    input = input.split(', ');
    var unique = {};

    for (var i = 0; i < input.length; i++) {
        unique[input[i]] = true;
    }
    print(Object.keys(unique).length);
}

var s = readline();
s = s.slice(1, s.length - 1).split(/\s*,\s*/);
var used = {};
var answer = 0;

for (var i = 0; i < s.length; i++) {
	if (s[i].length === 1 && !used.hasOwnProperty(s[i])) {
		answer++;
		used[s[i]] = null;
	}
}

print(answer);

var s = readline();
s = s.slice(1, s.length - 1).split(/\s*,\s*/);
var used = {};
var answer = 0;

for (var i = 0; i < s.length; i++) {
	if (s[i].length === 1 && used[s[i]] === undefined) {
		answer++;
		used[s[i]] = null;
	}
}

print(answer);

var input = readline();
var arr = [];
for (var i = 1; i < input.length; i+=3) {
    if (input.charAt(i) != "{" || input.charAt(i) != "}") {
        var checker = false;
        for (var j = 0; j < arr.length; j++) {
            if (input.charAt(i) == arr[j]) {
                checker = true;
            }
        }
        if (checker == false) {
            arr.push(input.charAt(i));
        }
    }
}
if (input.length < 3) {
    print(0);
}
else {
    print(arr.length);
}

print(readline().trim().split(/[, {}]+/).sort().splice(2).map(function(x,i,a){ return a.indexOf(x) == i ? 1: 0}).reduce(function(a,b) {return a+b}, 0));

function onlyUnique(value, index, self) {
    return self.indexOf(value) === index;
}

function trimMap(el) {

    return el.trim();
}

var levels = readline();

if (levels == '{}') print(0);
else {

    levels = levels.slice(0, -1)
                   .substr(1)
                   .split(',')
                   .map(trimMap)
                   .filter(onlyUnique);

    print(levels.length);
}

var string = readline()

  var arr = new Array('z'.charCodeAt(0) - 'a'.charCodeAt(0)).fill(0)
  for (var i = 0; i < string.length; i++) {
    if (string[i] !== '{' && string[i] !== ' ' && string[i] !== ',' && string[i] !== '}') {
      arr[string.charCodeAt(i) - 'a'.charCodeAt(0)] += 1
    }
  }

  var count = 0
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] !== 0) {
      count += 1
    }
  }

  print(count)

var input = readline();
var count = [];
for(var i= 0; i< input.length; i++){
    if(input.charCodeAt(i) >=97 && input.charCodeAt(i) <=122 && !count.includes(input[i]))count.push(input[i]);
}
print(count.length);

;(function () {
	print( readline().split('').filter(function (e) { return /\w+/.test(e); }).filter(function (e, i, a) { return i == a.lastIndexOf(e); }).length );
}).call(this)

var input = readline().slice(1, -1);
write(input ? new Set(input.split(', ')).size : 0);

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var s = trim(readline());
	s = s.substring(1, s.length-1);
	var tokens = s.split(','),
		count = 0, hash = {};
	for (var i = 0; i < tokens.length; ++i) {
		var token = trim(tokens[i]);
		if (token.length == 0) {
			continue;
		}
		if (hash[token] === undefined) {
			++count;
			hash[token] = true;
		}
	}
	print(count);
}

main();

var s = readline();
var arr = s.substring(1, s.length-1).split(", ");
var obj = {};
for(var i =0; i<arr.length; i++) {
    if (arr[i]!=='')
        obj[arr[i]] = true;
}
print(Object.keys(obj).length);

(function() {
    'use strict';
    let n = readline();
    let x = /\w+/g;
    let y = new Set(n.match(x)).size;
    print(y);
}());

var toObject = x => {
    var y = {};
    y[x] = true;
    return y;
    // {`${x}`: true}
};
var toKeyMap = (a, b) => (Object.assign(a, b));

var noise = '{, }'.split('').map(toObject).reduce(toKeyMap);
var noiseFilter = x => (!noise[x]);

var ar = readline().split('').filter(noiseFilter).map(toObject);

print(
    ar.length > 0 ?
        Object.keys(ar.reduce(toKeyMap)).length
        : 0
);

'use strict';
const obj = {};
readline()
  .replace('}', '')
  .replace('{', '')
  .split(',')
  .forEach((letter) => {
    letter = letter.trim();
    if (letter.length) obj[letter] = 1;
  });

write(Object.keys(obj).length);

var s = readline();
s = s.replace("}", "");
s = s.replace("{", "");
var a = [];
a = s.split(", ");
var res = 0;
for(i = 0; i < a.length; i++){
    if(a.indexOf(a[i]) == i){
        res++;
    }
}
if(s == ""){
    res = 0;
}
print(res);

var n = readline().slice(1,-1).replace(/, /g, "").split("");
var s = new Set(n).size;
print(s);

var values = readline()
var set = new Set(values.split(/[\{\}\, ]/g))
if(set.size == 0)
    print(0)
else
    print(set.size - 1)

var input = readline();
input = input.slice(1, input.length-1);
var array = input.split(", ");
var k=0;
var bArr = {};
for (i=0; i<array.length; ++i) {
if (bArr[array[i]] === undefined && array[i].length > 0){
++k;
bArr[array[i]] = "*";
}

}
print(k);

var main = function(str)
{
    if (str === '{}') return 0;
	var obj = {},
	sum = 0,
    arr  = str.split(', ');
	arr[0] = arr[0][1];
	arr[arr.length - 1] = arr[arr.length - 1][0];
	arr = arr.sort();

	for (var i = 0; i <= arr.length - 1; i++)
	{
		if (typeof(obj[arr[i]]) === 'number') obj[arr[i]]++;
		else {
			obj[arr[i]] = 1;
			sum++;
		}
	}
	return sum;
}
var input = readline();
print(main(input));

var input = readline().slice(1, -1);
if (input.length === 0)
	print(0);
else
	print(input.split(", ")
	.reduce(function(set, value) {
		if (set.indexOf(value) === -1)
			set.push(value);
		return set;
	}, [])
	.length);

var line = readline();

var alphabet = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var distinct = 0;

for(i=0;i<line.length;i++){
    if(line.charCodeAt(i)<97 || line.charCodeAt(i)>122){
	continue;
    }else {
	alphabet[line.charCodeAt(i)-97]+=1;
    }
}

for(i=0;i<26;i++){
    if(alphabet[i]>0){
	distinct+=1;
    }
}

print(distinct);

var line = readline();

var alphabet = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var distinct = 0;

for(i=0;i<line.length;i++){
    if(line.charCodeAt(i)-97<27){
	alphabet[line.charCodeAt(i)-97]+=1;
    }
}

for(i=0;i<26;i++){
    if(alphabet[i]>0){
	distinct+=1;
    }
}

print(distinct);

function main(str) {
  var setArr = [];
  var clearStr = str ? str.slice(1, -1) : '';
  if (clearStr) {
    var arr = clearStr.split(', ');
    arr.sort();
    var i = 0;
    for (i; i < arr.length; i++) {
      if (setArr[setArr.length - 1] !== arr[i]) {
        setArr.push(arr[i]);
      }
    }
  }
  write(setArr.length);
}
var data = readline();
main(data);

var letters = readline().split("");
var set = new Set(letters);
set.delete("{");
set.delete(",");
set.delete("}");
set.delete(" ");
print(set.size)

var input = readline();

if (input.length === 2) {
    print(0);
} else {
    var val = input.slice(1, input.length - 1).split(", ");

    var se = new Set();

    for (var i = 0; i < val.length; i++) {
        se.add(val[i]);
    }

    print(se.size);
}

const regExp = /[{} ]/g;
var modifiedPlentyToArray = readline().replace(regExp, "").split(',');
if (modifiedPlentyToArray[0]){
    var newSet = new Set(modifiedPlentyToArray);
    print(newSet.size);
} else {
    print(0);
}

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    const n = new Set(input[0].slice(1, -1).split(' ').map(v => v[0]));
    console.log(n.size);
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    const n = new Set(input[0].slice(1, -1).split(' '));
    console.log(n.size);
});

const readline = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout,
});

const input = [];
readline.on('line', line => { input.push(line); });

readline.on('close', () => {
    if (input[0] = '{}') { console.log(0); process.exit(); }
    const n = new Set(input[0].slice(1, -1).split(' ').map(v => v[0]));
    console.log(n.size);
});

let fs = require('fs');

let txt = fs.readFileSync(0, "utf-8").split("\n").filter(data => data.length > 0);
for (let i = 0; i < txt.length; i++) {
    doit(txt[i].split(/[{}, ]/).filter(data => data.length > 0));
}

function doit(tab) {
    console.log([...new Set(tab)].length);
}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');

    check(letters)
})

function check(letters) {
    let counter = 1;

    if (letters.length == 0)
        return console.log(0)

    let sorted = letters.sort((a, b) => a > b)

    sorted.reduce((prev, curr) => {
        if (prev != curr)
            counter++;
        return curr
    })

    if (counter > 26)
        return console.log(26)
    else
        return console.log(counter)
}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');
    check(letters)
})

function check(letters) {
    let counter = letters.length;

    if (counter == 0)
        return console.log(counter)

    letters.sort((a, b) => a > b).reduce((prev, curr) => {
        if (prev == curr)
            counter--;
        return curr
    })

    console.log(counter)
}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');

    check(letters)
})

function check(letters) {
    let counter = 1;

    if (letters.length == 0)
        return console.log(0)

    let sorted = letters.sort((a, b) => a > b)

    sorted.reduce((prev, curr) => {
        if (prev != curr)
            counter++;
        return curr
    })

    return console.log(counter)
}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');
    check(letters)
})

function check(letters) {
    let counter = letters.length;

    if (counter == 0)
        return console.log(counter)

    letters.sort((a, b) => a < b).reduce((prev, curr) => {
        if (prev == curr)
            counter--;
        return curr
    })

    return console.log(counter)
}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');

    check(letters)
})

function check(letters) {
    let counter = 1;

    if (letters.length == 0)
        return console.log(0)

    let sorted = letters.sort((a, b) => a > b)

    console.log(sorted);

    sorted.reduce((prev, curr) => {
        if (prev != curr)
            counter++;
        return curr
    })

    return console.log(counter)
}

const readline = require('readline');

// Create readline Interface
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})

// Read Inputs
rl.on('line', set => {
    const letters = set.split(/\W/).filter(letter => letter != '');

    check(letters)
})

function check(letters) {
    let counter = 1;

    if (letters.length == 0)
        return console.log(0)

    let sorted = letters.sort((a, b) => a > b)

    sorted.reduce((prev, curr) => {
        if (prev != curr)
            counter++;

        if (counter > 26)
            return console.log(counter)

        return curr
    })

    return console.log(counter)
}

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin
});

rl.on('line', function(line){
    const set = new Set(line.replace(/{|}/g, '').split(',').map(e => e.trim()));
    console.log(set.size);
});

var letters = readline().split(""), unique = [];
letters.pop();
letters.shift();
letters = letters.join("").split(", ");

for(i = 0; i < letters.length; i++){
	if( !!letters ){
		unique.length = 0;
		break;
	}
	if(i == 0){
		unique.push(letters[i]);
		continue;
	}
	if( unique.every(function(a){ return (a != letters[i]) ? true : false }) ){
		unique.push(letters[i]);
	}
}
write(unique.length);

var input = readline();
input = input.slice(1, input.length - 1).split(', ');
var unique = {};
for (var i = 0; i < input.length; i++) {
    unique[input[i]] = true;
}
print(Object.keys(unique).length);

var s = readline();
s = s.slice(1, s.length - 1).split(/\s+,\s+/);
var used = {};
var answer = 0;

for (var i = 0; i < s.length; i++) {
	print(s[i]);
	print(s[i].length);
	print(used[s[i]]);
	if (s[i].length === 1 && used.hasOwnProperty(s[i])) {
		answer++;
		used[s[i]] = null;
	}
}

print(answer);

var s = readline();
s = s.slice(1, s.length - 1).split(/\s+,\s+/);
var used = {};
var answer = 0;

for (var i = 0; i < s.length; i++) {
	if (s[i].length === 1 && used[s[i]] === undefined) {
		answer++;
		used[s[i]] = null;
	}
}

print(answer);

var s = readline();
s = s.slice(1, s.length - 1).split(/\s+,\s+/);
var used = {};
var answer = 0;

print(s)
print(used)

for (var i = 0; i < s.length; i++) {

	if (s[i].length === 1 && used[s[i]] === undefined) {
		answer++;
		used[s[i]] = null;
	}
}

print(answer);

var s = readline();
s = s.slice(1, s.length - 1).split(/\s*,\s*/);
var used = {};
var answer = 0;

for (var i = 0; i < s.length; i++) {
	print(s[i]);
	print(s[i].length);
	print(used[s[i]]);
	if (s[i].length === 1 && !used.hasOwnProperty(s[i])) {
		answer++;
		used[s[i]] = null;
	}
}

print(answer);

var input = readline();
var arr = [];
for (var i = 1; i < input.length; i+=3) {
    if (input.charAt(i) != "{" || input.charAt(i) != "," || input.charAt(i) != " " || input.charAt(i) != "}") {
        var checker = false;
        for (var j = 0; j < arr.length; j++) {
            if (input.charAt(i) == arr[j]) {
                checker = true;
            }
        }
        if (checker == false) {
            arr.push(input.charAt(i));
        }
    }
}
print(arr.length);

var input = readline().split("");
var count = [];
for(var e of input){
    if(e == '}' && e == '{' && !cout.includes(e))count.push(e);
}
print(count.length);

var s = readline();
var arr = s.substring(1, s.length-1).split(", ");
var obj = {};
for(var i =0; i<arr.length; i++) {
    obj[arr[i]] = true;
}
print(Object.keys(obj).length);

var s = readline();
var arr = s.substring(1, -1).split(", ");
var obj = {};
for(var i =0; i<arr.length; i++) {
    obj[arr[i]] = true;
}
print(Object.keys(obj).length);

'use strict';
const obj = {};
readline()
  .replace('}', '')
  .replace('{', '')
  .split(',')
  .map(letter => obj[letter.trim()] = 1);

write(Object.keys(obj).length);

'use strict';
const obj = {};
readline()
  .replace('}', '')
  .replace('{', '')
  .replace(' ', '')
  .split(',')
  .map(letter => obj[letter] = 1);

write(Object.keys(obj).length);

var s = readline();
s = s.replace("}", "");
s = s.replace("{", "");
var a = [];
a = s.split(", ");
var res = 0;
for(i = 0; i < a.length; i++){
    if(a.indexOf(a[i]) == i){
        res++;
    }
}
print(res);

var s = readline();
s = s.replace("}", "");
s = s.replace("{", "");
var a = [];
a = s.split(", ");
var res = 0;
for(i = 0; i < a.length; i++){
    if(a.indexOf(a[i]) == i){
        res++;
    }
}
if(a.length == 0){
    res++;
}
print(res);

var n = readline().slice(1,-1);
var s = new Set(n.split(", ")).size;
print(s);

var input = readline();
input = input.slice(1, input.length-1);
var array = input.split(", ");
var k=0;
var bArr = {};
for (i=0; i<array.length; ++i) {
if (bArr[array[i]] === undefined && bArr[array[i] !== ""]){
++k;
bArr[array[i]] = "*";
}

}
print(k);

var input = readline();
input = input.slice(1, input.length-1);
var array = input.split(", ");
var k=0;
var bArr = {};
for (i=0; i<array.length; ++i) {
if (bArr[array[i]] === undefined){
++k;
bArr[array[i]] = "*";
}

}
print(k);

var main = function(str)
{
	var revoke = 0,
	count = 0,
    arr  = str.split(', ');
	arr[0] = arr[0][1];
	arr[arr.length - 1] = arr[arr.length - 1][0];
	arr = arr.sort();
	for (var i = 1; i <= arr.length - 1; i++)
	{
		if ((arr[i] !== arr[i - 1]) && (i === 1)) count += 2;
		else
		{
			if ((arr[i] !== arr[i - 1])) count++;
		}
	}
	return count;
}
var input = readline();
print(main(input));

var main = function(str)
{
	var obj = {},
	sum = 0,
    arr  = str.split(', ');
	arr[0] = arr[0][1];
	arr[arr.length - 1] = arr[arr.length - 1][0];
	arr = arr.sort();
	for (var i = 0; i <= arr.length - 1; i++)
	{
		if (typeof(obj[arr[i]]) === 'number') obj[arr[i]]++;
		else {
			obj[arr[i]] = 1;
			sum++;
		}
	}
	return sum;
}
var input = readline();
print(main(input));

write(new Set(readline().slice(1, -1).split(', ')).size);

function main(str) {
  var setArr = [];
  var clearStr = str ? str.slice(1, -1) : '';
  write('clearStr: ' + clearStr);
  if (clearStr) {
    var arr = clearStr.split(', ');
    arr.sort();
    var i = 0;
    for (i; i < arr.length; i++) {
      if (setArr[setArr.length - 1] !== arr[i]) {
        setArr.push(arr[i]);
      }
    }
  }
  write(setArr.length);
}
var data = readline();
print('data: ' + data);
main(data);

var letters = readline().split("");
var set = new Set(letters);
print(set.size-4)

var letters = readline().split("");
var set = new Set(letters);
print(set.size-3)

var letters = readline().split("");
var set = new Set(letters);
print(set)
print(set.size-3)

var input = readline();
var val = input.slice(1, input.length - 1).split(", ");

var se = new Set();

for (var i = 0; i < val.length; i++) {
    se.add(val[i]);
}

print(se.size);


We say that a positive integer $$$n$$$ is $$$k$$$-good for some positive integer $$$k$$$ if $$$n$$$ can be expressed as a sum of $$$k$$$ positive integers which give $$$k$$$ distinct remainders when divided by $$$k$$$.Given a positive integer $$$n$$$, find some $$$k \geq 2$$$ so that $$$n$$$ is $$$k$$$-good or tell that such a $$$k$$$ does not exist.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. Each test case consists of one line with an integer $$$n$$$ ($$$2 \leq n \leq 10^{18}$$$).

For each test case, print a line with a value of $$$k$$$ such that $$$n$$$ is $$$k$$$-good ($$$k \geq 2$$$), or $$$-1$$$ if $$$n$$$ is not $$$k$$$-good for any $$$k$$$. If there are multiple valid values of $$$k$$$, you can print any of them.

Note$$$6$$$ is a $$$3$$$-good number since it can be expressed as a sum of $$$3$$$ numbers which give different remainders when divided by $$$3$$$: $$$6 = 1 + 2 + 3$$$.$$$15$$$ is also a $$$3$$$-good number since $$$15 = 1 + 5 + 9$$$ and $$$1, 5, 9$$$ give different remainders when divided by $$$3$$$.$$$20$$$ is a $$$5$$$-good number since $$$20 = 2 + 3 + 4 + 5 + 6$$$ and $$$2,3,4,5,6$$$ give different remainders when divided by $$$5$$$.

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(n) {
  let i = 1n;

  while (n % 2n === 0n) {
    n /= 2n;
    i *= 2n;
  }

  if (n === 1n) return -1;else if (2n * i < n) return 2n * i;else return n;
}

// const inputs = fs.readFileSync(path.join(__dirname, './codeforces.test.txt'), 'utf-8').split('\n')

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function main() {
  const _ = Number(inputs[0]);

  for (let __ = 1; __ <= _; __++) {
    const n = BigInt(inputs[__]);
    console.log(solve(n).toString());
  }
}();


The only difference between easy and hard versions is constraints.You are given a sequence $$$a$$$ consisting of $$$n$$$ positive integers.Let's define a three blocks palindrome as the sequence, consisting of at most two distinct elements (let these elements are $$$a$$$ and $$$b$$$, $$$a$$$ can be equal $$$b$$$) and is as follows: $$$[\underbrace{a, a, \dots, a}_{x}, \underbrace{b, b, \dots, b}_{y}, \underbrace{a, a, \dots, a}_{x}]$$$. There $$$x, y$$$ are integers greater than or equal to $$$0$$$. For example, sequences $$$[]$$$, $$$[2]$$$, $$$[1, 1]$$$, $$$[1, 2, 1]$$$, $$$[1, 2, 2, 1]$$$ and $$$[1, 1, 2, 1, 1]$$$ are three block palindromes but $$$[1, 2, 3, 2, 1]$$$, $$$[1, 2, 1, 2, 1]$$$ and $$$[1, 2]$$$ are not.Your task is to choose the maximum by length subsequence of $$$a$$$ that is a three blocks palindrome.You have to answer $$$t$$$ independent test cases.Recall that the sequence $$$t$$$ is a a subsequence of the sequence $$$s$$$ if $$$t$$$ can be derived from $$$s$$$ by removing zero or more elements without changing the order of the remaining elements. For example, if $$$s=[1, 2, 1, 3, 1, 2, 1]$$$, then possible subsequences are: $$$[1, 1, 1, 1]$$$, $$$[3]$$$ and $$$[1, 2, 1, 3, 1, 2, 1]$$$, but not $$$[3, 2, 3]$$$ and $$$[1, 1, 1, 1, 2]$$$.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 26$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. Note that the maximum value of $$$a_i$$$ can be up to $$$26$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer — the maximum possible length of some subsequence of $$$a$$$ that is a three blocks palindrome.

var t = parseInt(readline());

function div(val, by){
    return (val - val % by) / by;
}

function setCharAt(str,index,chr) {
    if(index > str.length-1) return str;
    return str.substr(0,index) + chr + str.substr(index+1);
}

var ch = 'a';
var acode = ch.charCodeAt(0);

for (var tt = 0; tt < t; tt++) {
    var n = parseInt(readline());
    var a = readline().split(' ').map(Number);
    var m = {};
    for (var i = 0; i < n; i++) {
        m[a[i]] = m[a[i]] ? m[a[i]] + 1 : 1;
    }
    var nums = Object.keys(m).map(Number);
    var res = 1;
    for (var i = 0; i < nums.length; i++) {
        var num = nums[i];
        var l = 0;
        var r = n - 1;
        var mcopy = Object.assign({}, m);
        var locallen = 0;
        while (l < r) {
            while (l < n && a[l] != num) {
                mcopy[a[l]] -= 1;
                l += 1;
            }
            while (r >= 0 && a[r] != num) {
                mcopy[a[r]] -= 1;
                r -= 1;
            }
            if (l >= r) {
                break;
            }
            mcopy[a[l]] -= 1;
            l += 1;
            mcopy[a[r]] -= 1;
            r -= 1;
            locallen += 2;
            var localmax = 0;
            var mcopykeys = Object.keys(mcopy);
            for (var j = 0; j < mcopykeys.length; j++) {
                var localkey = mcopykeys[j];
                if (mcopy[localkey] > localmax) {
                    localmax = mcopy[localkey];
                }
            }

            if (locallen + localmax > res) {
                res = locallen + localmax;
            }
        }
    }

    write(res+'\n');
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
function main(){
	var tt = parseInt(readline());
	while(tt--){
		var n = parseInt(readline());
		var a = readline().split(" ").map(function(x){ return parseInt(x) - 1;});
		var pre = [];
		var fix = [];
		var M = 200;
		var ans = 0;
		for(var i = 0; i < M; i++){
			pre[i] = [], fix[i] = [];
			pre[i][0] = 0;
			for(var j = 0; j < n; j++){
				pre[i][j + 1] = pre[i][j] + (a[j] == i);
				if(a[j] == i){
					fix[i].push(j);
				}
			}
		}
		for(var x = 0; x < M; x++){
			var u = pre[x][n];
			ans = Math.max(ans, u);
			for(var c = 1; 2 * c <= u; c++){
				var l = fix[x][c - 1];
				var r = fix[x][u - c];
				for(var y = 0; y < M; y++){
					if(x != y)
						ans = Math.max(ans, 2 * c + pre[y][r] - pre[y][l]);
				}
			}
		}
		console.log(ans);
	}
}