Recently, your friend discovered one special operation on an integer array $$$a$$$:   Choose two indices $$$i$$$ and $$$j$$$ ($$$i \neq j$$$);  Set $$$a_i = a_j = |a_i - a_j|$$$. After playing with this operation for a while, he came to the next conclusion:   For every array $$$a$$$ of $$$n$$$ integers, where $$$1 \le a_i \le 10^9$$$, you can find a pair of indices $$$(i, j)$$$ such that the total sum of $$$a$$$ will decrease after performing the operation. This statement sounds fishy to you, so you want to find a counterexample for a given integer $$$n$$$. Can you find such counterexample and prove him wrong?In other words, find an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) such that for all pairs of indices $$$(i, j)$$$ performing the operation won't decrease the total sum (it will increase or not change the sum).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first and only line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the length of array $$$a$$$.

For each test case, if there is no counterexample array $$$a$$$ of size $$$n$$$, print NO. Otherwise, print YES followed by the array $$$a$$$ itself ($$$1 \le a_i \le 10^9$$$). If there are multiple counterexamples, print any.

NoteIn the first test case, the only possible pairs of indices are $$$(1, 2)$$$ and $$$(2, 1)$$$.If you perform the operation on indices $$$(1, 2)$$$ (or $$$(2, 1)$$$), you'll get $$$a_1 = a_2 = |1 - 337| = 336$$$, or array $$$[336, 336]$$$. In both cases, the total sum increases, so this array $$$a$$$ is a counterexample.

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	for(i = 1; i <= t; i++) {
	    var a = lines[i];
        if(a < 20){
            console.log('YES');
            var ans = '';
            var b = 1;
            for(j = 0; j < a; j++){
                ans += b + ' ';
                b *= 3;
            }
            console.log(ans);
        }else{
            console.log('NO');
        }
	}
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 19){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 19){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = [];
        if (n >= 20) {
            output('NO');
            continue;
        }

        for (let i = 0; i < n; i++) {
            arr[i] = 3 ** i;
        }

        output('YES');
        output(arr.join(' '));
    }
}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n) {
  if (n > 19) {
    console.log('NO');
    return;
  }
  let res = [];
  for (let i = 0; i < n; i++) {
    res.push(3 ** i);
  }
  console.log('YES');
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    solve(n);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict'; /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;

const calc = n=>{
  let ans = [1];
  while (ans.length<n && ans[ans.length-1]*3<=1e9)
    ans.push(ans[ans.length-1]*3);
  if (ans.length==n)
    return 'YES\n'+ans.join(' ')
  return 'NO';

};

function main() {
    let T = +readline();
    while (T--){
      let n = +readline();
      print(calc(n));
    }
}

E.calc = calc;

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() {
  const testCases = readline();
  // let isPalindrome = true;

  for (let i = 0; i < testCases; i++) {
    let n = Number(readline());
    if (n > 19) {
      console.log("NO");
    } else {
      console.log("YES");
      let result = [1];
      let counter = 2;
      while (counter <= n) {
        result.push(result[result.length - 1] * 3);
        counter++;
      }
      console.log(result.join(" "));
    }
  }
}

var n = readline(), s, m, k, ans;

while (n--) {
  ans = '';
	s = readline();
	m = Math.pow(3, s - 1);
	k = Math.pow(10, 9);
	if (m > k) {
	  print('NO');
	} else {
	  print('YES');
	  for (var i = 0; i < s; i++) {
	    ans += `${Math.pow(3, i)} `;
	  }
	  print(ans);
	}
}

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 19){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 4;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 19){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 2;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 20){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 21){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 22){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 23){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 25){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 30){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        var a = 1;
        if(k <= 18){
            for(i = 0; i < k; i++){
                ans += a + ' ';
                a *= 3;
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var a = [1, 3, 9, 27, 81];
    for(j = 1; j <= n; j++){
        var k = lines[j];
        var ans = '';
        if(k < 5){
            for(i = 0; i < k; i++){
                ans += a[i] + ' ';
            }
            console.log('YES' + "\n" + ans);

        }else{
            console.log('NO');
        }
    }
});

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    for(j = 1; j <= n; j++){
        var k = lines[j].split(' ').map(Number);
        var a = k[0]; var b = k[1];
        if(a == 1){
            console.log(0);
        }else if(a == 2){
            console.log(b);
        }else{
            console.log(b * 2);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k >= 19){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 20){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 5){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l) + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 5){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += Math.pow(3, l)
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var a = [1, 3, 9, 27, 81]
    for(j = 1; j <= n; j++){
        var k = lines[j]
        if(k > 5){
            console.log('NO')
        }else{
            g = ''
            for(l = 0; l < k; l++){
                g += a[l] + ' '
            }
            console.log('YES' + '\n' + g)
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = parseInt(lines[0], 2), e = 0, g =0

    while(Math.pow(4, e) < n){
        e++
    }
    var b = lines[0].split('')
    var c = lines[0].split('')
    b.reverse()
    f = false
    for(j = 0; j < b.length; j++){
        if(b[j] == c[j]){
            f = true
        }else{
            f = false
            break;
        }
    }
    if(f === true && b.length >= 60 && b[30] == 0){
        e++
    }
    console.log(e)

});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = [];
        if (n >= 30) {
            output('NO');
            continue;
        }

        for (let i = 0; i < n; i++) {
            arr[i] = 2 ** i;
        }

        output('YES');
        output(arr.join(' '));
    }
}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n) {
  if (n >= 19) {
    console.log('NO');
    return;
  }
  let res = [];
  for (let i = 0; i <= n; i++) {
    res.push(3 ** i);
  }
  console.log('YES');
  console.log(res.join(' '));
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    solve(n);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();


Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.

Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.

3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749

3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450

NoteIn the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.

var n = +readline();

var ans = "NO";
for(var i = 0; i < n; i++){
    var rating = readline().split(" ").slice(1).map(Number);

    if(rating[0] >= 2400 && rating[1] > rating[0]){
        ans = "YES";
        break;
    }
}

write(ans);

var flag = 0;
var n = readline();
for( var i = 0; i < n; i++)
{
    var value = readline().split(" ");
    if(parseInt(value[1]) >= 2400 && parseInt(value[2]) > parseInt(value[1]))
        flag = 1;
}

if(flag != 0) print("YES");
else print("NO");

var n=parseInt(readline());
var res="";
var ar=new Array(n);
for (var i=0;i<n;i++) {
	ar[i]=readline();
}
for(var i=0;i<n;i++){
	var num1,num2;
	var ret=new Array(3);
	 ret=ar[i].split(" ");
	 num1=parseInt(ret[1]);
	 num2=parseInt(ret[2]);
	 if(num1>=2400&&num2>num1){ res="YES";break;}

}if(res==="YES"){print("YES\n");}
else{print("NO\n");}

var n = parseInt(readline());
for(i = 0; i < n; i++) {
    var t = readline().split(' ');
    var t1 = parseInt(t[1]);
    var t2 = parseInt(t[2]);
    if(t1<t2&&t1>2399) {
        print("YES");
        quit(0);
    }
}
print("NO");

var n = parseInt(readline());
var s=Array(n);
for(var i = 0; i<n; i++) {s[i]=readline().split(' ').slice(1).map(Number);}
var p =function () { for (var i=0;i<n;i++) {if (s[i][0]>=2400 && s[i][1]>s[i][0]) return 'YES';} return 'NO'};
print(p());

var n = readline();
var check = true;
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    if(Number(y[1]) >= 2400 && Number(y[2]) > Number(y[1])){
        print("YES")
        check = false;
        break;
    }
}
if(check == true){
    print("NO");
}

var n = Number(readline());

var answer = "NO";

for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ')
    var before = parseInt(line[1]);
    var after = parseInt(line[2]);
    if (2400 <= before && before < after) {
        answer = "YES";
    }
}
print(answer);

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var n, participant, scores, answer;

n = Number(readline());

for (i = 0; i < n; i++) {

    answer = 'NO';
    participant = readline().replace(/\r$/, '').split(' ');
    scores = [Number(participant[1]), Number(participant[2])];

    if (scores[0] < 2400) {continue};
    if (scores[1] <= scores[0]) {continue};

    answer = 'YES';
    break
}

print(answer);

var n = readline();
var user;
var flag = 0;
for (var i = 0; i < n; i++){
	user = readline().split(" ");
	if(parseInt(user[1]) >= 2400 && parseInt(user[2]) > parseInt(user[1]))
		flag = 1;
}
print((flag) ? "YES" : "NO");

var n = readline();
var flag = 0
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after > before){
    	flag = 1;
        print("YES");
        break;
    }
}
if(flag == 0){
	print("NO")
}

	function main(){
	var line1 = readline();
	for (var i = 0; i<line1;i++){
		var line2 = readline().split(' ');
		var beforei = parseInt(line2[1]);
		var afteri = parseInt(line2[2]);
		result = afteri - beforei;
		if (beforei>=2400 & result>0)
		{
		print('YES');
		return 0;

			}

	};
	print("NO");
	};

main();

var n = parseInt(readline().trim());
var goodPerf = false;
for (var i = 0; i < n; i++) {
   var inpStr = readline().trim().split(' ');
   if (!goodPerf && parseInt(inpStr[1]) >= 2400 && parseInt(inpStr[2]) > inpStr[1]) {
     goodPerf = true;
   }
}
print((goodPerf) ? 'YES' : 'NO');

;(function () {
	var n = parseInt(readline())

	for (var i = 1; i <= n; i++) {
		var s = readline().split(' '),
			x = parseInt(s[1]),
			y = parseInt(s[2]);

		if (x >= 2400 && y > x)
			return print("YES");
	}
	print("NO");
})();

var numberOfResults = readline();
var improved = 'NO';
for (var i=0; i<numberOfResults; i++) {
  var scores = readline().split(' ');
  if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
    improved = 'YES';
    break;
  }
}
print(improved);

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

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

  let [participant, startRating, endRating] = d.split(' ');
  if (+startRating < +endRating && +startRating >= redRating) {
    ans = 'YES';
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

var n, before, after, name, flag = 0;

n = readline("\n");
for( var i = 0; i < n; i++)
{
    name = readline("\n");
    before = readline("\n");
    after = readline("\n");

    if(before >= 2400 && after > before)
        flag++;
}

if(flag != 0) print("YES");
else print("NO");

var n = readline();
var check = true;
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    if(y[1] >= 2400 && y[2] > y[1]){
        print("YES")
        check = false;
        break;
    }
}
if(check == true){
    print("NO");
}

var n = readline();
var check = true;
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    if(y[1] > 2400 && y[2] > y[1]){
        print("YES")
        check = false;
        break;
    }
}
if(check == true){
    print("NO");
}

var n = Number(readline());

print(n);

var answer = "NO";

for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ')
    print(line);
    var before = parseInt(line[1]);
    var after = parseInt(line[2]);
    if (2400 <= before && before < after) {
        answer = "YES";
    }
}
print(answer);

var n = Number(readline());

var answer = "NO";

for (var i = 1; i <= n; ++i) {
    var line = readline().split(' ');
    var before = parseInt(line[1]);
    var after = parseInt(line[2]);
    if (2400 < before && before < after) {
        answer = "YES";
    }
    print(answer);
}

var n = readline();
var user;
var flag = 0;
for (var i = 0; i < n; i++){
	user = readline().split(" ");
	if(user[1] >= 2400 && user[2] > user[1])
		flag = 1;
}
print((flag) ? "YES" : "NO");

var n = readline();
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after >before){
        print("YES");
        break;
    }
}

var n = readline();
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after >2400){
        print("YES");
        break;
    }
}

var n = readline();
for(i=0;i<n;i++){
    var y = readline();
    y = y.split(" ");
    var handle = y[0];
    var before = Number(y[1]);
    var after = Number(y[2]);
    if(before >= 2400 && after > before){
        print("YES");
        break;
    }
}
print("NO");

;(function () {
	var x = parseInt(readline())

	for (var i = 1; i <= x; i++) {
		var s = readline().split(' '),
			x = parseInt(s[1]),
			y = parseInt(s[2]);

		if (x >= 2400 && y > x)
			return print("YES");
	}
	print("NO");
})();

function performedGood(inputString) {
  var lines = inputString.split("\n");
  for (var i=1; i<lines.length; i++) {
    var scores = lines[i].split(' ');
    if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
      console.log('YES');
      return 'YES';
    }
  }
  console.log('NO');
  return 'NO';
}

function performedGood(inputString) {
  var lines = inputString.split("\n");
  for (var i=1; i<lines.length; i++) {
    var scores = lines[i].split(' ');
    if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
      return 'YES';
    }
  }
  return 'NO';
}

function performedGood(input) {
  var lines = input.split("\n");
  for (var i=1; i<lines.length; i++) {
    var scores = lines[i].split(' ');
    if (parseInt(scores[1]) >= 2400 && parseInt(scores[2]) > parseInt(scores[1])) {
      return 'YES';
    }
  }
  return 'NO';
}


Ksenia has an array $$$a$$$ consisting of $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$. In one operation she can do the following:   choose three distinct indices $$$i$$$, $$$j$$$, $$$k$$$, and then  change all of $$$a_i, a_j, a_k$$$ to $$$a_i \oplus a_j \oplus a_k$$$ simultaneously, where $$$\oplus$$$ denotes the bitwise XOR operation. She wants to make all $$$a_i$$$ equal in at most $$$n$$$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!

The first line contains one integer $$$n$$$ ($$$3 \leq n \leq 10^5$$$) — the length of $$$a$$$. The second line contains $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — elements of $$$a$$$.

Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $$$n$$$ operations. If it is possible, print an integer $$$m$$$ ($$$0 \leq m \leq n$$$), which denotes the number of operations you do. In each of the next $$$m$$$ lines, print three distinct integers $$$i, j, k$$$, representing one operation.  If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.

NoteIn the first example, the array becomes $$$[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$$$.

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const v = input.trim().split('\n')[1].split(' ').map((x) => parseInt(x))
  const ops = []

  let idx = 0

  while (true) {
    if (idx + 2 >= v.length) {
      break
    }

    ops.push([idx + 1, idx + 2, idx + 3])
    const val = v[idx] ^ v[idx + 1] ^ v[idx + 2]
    v[idx] = val
    v[idx + 1] = val
    v[idx + 2] = val
    idx += 2
  }

  idx -= 2

  while (true) {
    if (idx - 2 < 0) {
      break
    }

    idx -= 2
    ops.push([idx + 1, idx + 2, idx + 3])
    const val = v[idx] ^ v[idx + 1] ^ v[idx + 2]
    v[idx] = val
    v[idx + 1] = val
    v[idx + 2] = val
  }

  if (v.length % 2 === 1 || v[v.length - 1] === v[v.length - 2]) {
    console.log('YES')
    console.log(ops.length)
    console.log(ops.map((t) => t.join(' ')).join('\n'))
  } else {
    console.log('NO')
  }
})

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const v = input.trim().split('\n')[1].split(' ').map((x) => parseInt(x))
  const ops = []

  let idx = 0

  while (true) {
    if (idx + 2 >= v.length) {
      break
    }

    ops.push([idx, idx + 1, idx + 2])
    const val = v[idx] ^ v[idx + 1] ^ v[idx + 2]
    v[idx] = val
    v[idx + 1] = val
    v[idx + 2] = val
    idx += 2
  }

  idx -= 2

  while (true) {
    if (idx - 2 < 0) {
      break
    }

    idx -= 2
    ops.push([idx, idx + 1, idx + 2])
    const val = v[idx] ^ v[idx + 1] ^ v[idx + 2]
    v[idx] = val
    v[idx + 1] = val
    v[idx + 2] = val
  }

  if (v.length % 2 === 1 || v[v.length - 1] === v[v.length - 2]) {
    console.log('YES')
    console.log(ops.length)
    console.log(ops.map((t) => t.join(' ')).join('\n'))
  } else {
    console.log('NO')
  }
})


Bob came to a cash & carry store, put n items into his trolley, and went to the checkout counter to pay. Each item is described by its price ci and time ti in seconds that a checkout assistant spends on this item. While the checkout assistant is occupied with some item, Bob can steal some other items from his trolley. To steal one item Bob needs exactly 1 second. What is the minimum amount of money that Bob will have to pay to the checkout assistant? Remember, please, that it is Bob, who determines the order of items for the checkout assistant.

The first input line contains number n (1 ≤ n ≤ 2000). In each of the following n lines each item is described by a pair of numbers ti, ci (0 ≤ ti ≤ 2000, 1 ≤ ci ≤ 109). If ti is 0, Bob won't be able to steal anything, while the checkout assistant is occupied with item i.

Output one number — answer to the problem: what is the minimum amount of money that Bob will have to pay.

var parseIntFunc = function(x) { return parseInt(x); };
var numbers = readline().split(" ").map(parseIntFunc)[0];
var goods = [];
var sumTime = 0;
for (var i = 0; i < numbers; i++){
    var values = readline().split(" ").map(parseIntFunc);
    goods[i] = {
        t: values[0],
        v: values[1]
    };
}
var row = [];
row[0] = 0;
for (var i = 1; i <= numbers; i++){
    row[i] = Number.MAX_VALUE;
}
for (var i = 0; i < numbers; i++){
    var good = goods[i];
    good.t += 1;
    for (var j = numbers; j > 0; j--){
        row[j] = Math.min(row[j], Math.min(row[Math.min(numbers, j+1)], row[ Math.max(0, j-good.t)]+good.v));
    }
}
print(row[numbers]);

var parseIntFunc = function(x) { return parseInt(x); };
var numbers = readline().split(" ").map(parseIntFunc)[0];
var goods = [];
for (var i = 0; i < numbers; i++){
    var values = readline().split(" ").map(parseIntFunc);
    goods[i] = {
        t: values[0],
        v: values[1]
    };
}
goods.sort(function(a,b){
    var avdivt = a.t / a.v;
    var bvdivt = b.t / b.v;
    if (bvdivt === avdivt) {
        return a.v - b.v;
    }
    return bvdivt - avdivt;
});

var value = 0;
var availableTime = 0;
var i = 0;
while (i < goods.length){
    value += goods[i].v;
    availableTime = goods[i].t;
    for (var j = 0; j < availableTime; j++) {
        if (!goods.length){
            break;
        }
        goods.pop();
    }
    i++;
}
print(value);


According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are of the same height. Bob wants to know, how many ways exist to form a reconnaissance unit of two soldiers from his detachment.Ways (1, 2) and (2, 1) should be regarded as different.

The first line contains two integers n and d (1 ≤ n ≤ 1000, 1 ≤ d ≤ 109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains n space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 109.

Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed d.

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]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], maxDiff = integers[1];
	var soldiers = tokenizeIntegers(readline());
	var count = 0;
	for (var i = 0; i < n; ++i) {
		for (var j = 0; j < n; ++j) {
			if (i != j && Math.abs(soldiers[i] - soldiers[j]) <= maxDiff) {
				count += 1;
			}
		}
	}
	print(count);
}

main();

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let N = lll[0]
let D = lll[1]

lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)

let co = 0

for (let i = 0; i < N - 1; i++) {
  let j = i + 1
  while (lll[j++] - lll[i] <= D) co++
}

print(co * 2)

var input;
input = readline().split(" ").map(function(a){return parseInt(a)});
var n = input[0];
var d = input[1];
var sizes = readline().split(" ").map(function(a){return parseInt(a)});
sizes = sizes.sort(function(a, b){return a - b});
var res = 0;

for (var i = 0; i < n - 1; i++) {
	for (var j = i + 1; j < n; j++) {
		if ((sizes[j] - sizes[i]) <= d) {
			res++;
			res++;
		} else {
			break;
		}
	}
}

print(res);

const { on } = require('process');
const readline = require('readline');

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

var indicator = 0, ans = 0, temp = [], n, d, cont = [];

rl.on('line', (input) => {

    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        n = temp[0], d = temp[1];
        indicator++;
    }
    else {

        cont = input.split(' ').map(item => parseInt(item));
        for (let i = 0; i < n - 1; i++)
            for (let j = i + 1; j < n; j++)
                if (Math.abs(cont[i] - cont[j]) <= d)
                    ans += 2;

        console.log(ans);
        rl.close();
    }

});

/*

      i         j
10 20 30 40 50 60

*/

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var indicator = 0;
var soldiers, heightDiff;
var temp = [];
var ans = 0;
rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        soldiers = temp[0];
        heightDiff = temp[1];
        indicator++;
    }
    else {
        temp = input.split(' ').map(item => parseInt(item));
        for (let i = 0; i < soldiers - 1; i++) {
            for (let j = i + 1; j < soldiers; j++) {
                if (Math.abs(temp[i] - temp[j]) <= heightDiff)
                    ans += 2;
            }
        }
        console.log(ans);
        rl.close();
    }

});

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

rl.on('line', (data) => {
  if (c === 0) {
    c++;
    [n, d] = data.split(' ').map(Number);
    return;
  }

  arr = data.split(' ').map(Number);
  let ans = 0;

  for (let i = 0; i < arr.length ; i++) {
    for (let j = 0; j < arr.length; j++) {
      if (i !== j) {
        const v = Math.abs(arr[i] - arr[j]);
        if(v <= d) {
          ans++;
        }
      }
    }
  }

  console.log(ans);
  c++;
});

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

  var temp = [], indicator = 0, ans = 0, n , d;

  rl.on('line', (input) => {
    if(indicator==0){
        temp = input.split(' ').map(x=>parseInt(x));
        n = temp[0], d = temp[1];
        indicator++;
    } else {
        temp = input.split(' ').map(x=>parseInt(x));
        for (let i=0; i<n-1;i++)
            for(let j=i+1; j<n;j++)
                ans += (Math.abs(temp[i]-temp[j])<=d)*2;
        console.log(ans);
        rl.close();
    }

  });


You are given an array $$$a_1, a_2 \dots a_n$$$. Calculate the number of tuples $$$(i, j, k, l)$$$ such that:   $$$1 \le i < j < k < l \le n$$$;  $$$a_i = a_k$$$ and $$$a_j = a_l$$$;

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$4 \le n \le 3000$$$) — the size of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$) — the array $$$a$$$. It's guaranteed that the sum of $$$n$$$ in one test doesn't exceed $$$3000$$$.

For each test case, print the number of described tuples.

NoteIn the first test case, for any four indices $$$i < j < k < l$$$ are valid, so the answer is the number of tuples.In the second test case, there are $$$2$$$ valid tuples:   $$$(1, 2, 4, 6)$$$: $$$a_1 = a_4$$$ and $$$a_2 = a_6$$$;  $$$(1, 3, 4, 6)$$$: $$$a_1 = a_4$$$ and $$$a_3 = a_6$$$.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const dp = [...Array(len + 1).fill(0)].map((_) => Array(len + 1).fill(0));
    let count = 0;

    for (let i = 1; i < len; i++) {
      for (let j = 0; j < i; j++) {
        let [a, b] = [arr[j], arr[i]];
        dp[a][b]++;
      }
      for (let k = i + 2; k < len; k++) {
        let [c, d] = [arr[i + 1], arr[k]];
        count += dp[c][d];
      }
    }
    console.log(count);
  }
}

'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() {
  const T = parseInt(readline());
  for (let t=0; t<T; t++) {
    const n = parseInt(readline());
    const nums = readline().split(" ").map(x => parseInt(x));

    let result = 0;
    // left[x] is the number of smaller than index j with value x
    let left = new Array(n+1).fill(0);
    // right[x] is the number of greater than index k with value x
    let right = new Array(n+1).fill(0);

    // iterate over each j and k
    for (let j=0; j<n; j++) {
      right.fill(0);
      for (let k=n-1; j<k; k--) {
        result += left[nums[k]] * right[nums[j]];
        right[nums[k]]++;
      }
      left[nums[j]]++;
    }
    console.log(result);
  }
}

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();
    });

    probD();
});

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;

        let n = parseInt(readline());
        let s = readline().split('');
        let c = s[n-1];
        let res = '';
        for(let i = 0;  i< n; i++){
            res += c;
        }

        console.log(res);
    }
}

function probB(){
    let t = parseInt(readline());

    while(t > 0){
        t--;
        let [p,f] = readline().split(' ');
        let cap = parseInt(p) + parseInt(f);

        let [cs, cw] = readline().split(' ');
        let [s, w] = readline().split(' ');

        let ava = (parseInt(cs) * parseInt(s)) + (parseInt(cw) * parseInt(w));

        let tot = parseInt(cs) + parseInt(cw);
        if(cap > ava){
            console.log(tot);
            continue;
        }

        let x = Math.min(parseInt(s), parseInt(w));
        if(parseInt(s) === x){
            if(parseInt(cs) * x > cap){
                console.log(Math.floor(cap / parseInt(cs)));
            }else{
                let rem = cap - (x * parseInt(cs));
                console.log(parseInt(cs) + Math.floor(rem/parseInt(w)));
            }
        }else{
            if(parseInt(cw) * x > cap){
                console.log(Math.floor(cap / parseInt(cw)));
            }else{
                let rem = cap - (x * parseInt(cw));
                console.log(parseInt(cw) + Math.floor(rem/parseInt(s)));
            }
        }
    }
}

function probC(){
    let t = parseInt(readline());
    while(t > 0){
        t--;

        let s = readline().split('');
        let x = parseInt(readline());
        let isPossible = true;

        let w = new Array(s.length);
        for(let i = 0; i < s.length; i++){
            if(s[i] === '0'){
                if(i+x < s.length)
                    w[i+x] = '0';

                if(i-x >= 0)
                    w[i-x] = '0';
            }
        }

        if(!isPossible){
            console.log(-1);
            continue;
        }

        for(let i = 0; i < s.length; i++){
            if(w[i] !== '0')
                w[i] = '1';
        }

        for(let i = 0; i < s.length; i++){
            if(s[i] === '1'){
                if(i+x < s.length && i-x >= 0){
                    if(w[i+x] === '0' && w[i-x] === '0'){
                        isPossible = false;
                        break;
                    }
                }
                else if(i+x < s.length){
                    if(w[i+x] === '0'){
                        isPossible = false;
                        break;
                    }
                }else if(i-x >= 0){
                    if(w[i-x] === '0'){
                        isPossible = false;
                        break;
                    }
                }else{
                    isPossible = false;
                    break;
                }
            }
        }

        if(!isPossible){
            console.log(-1);
            continue;
        }

        console.log(w.join(''));
    }
}

function probD(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let n = parseInt(readline());
        let a = readline().split(' ');
        for(let i = 0; i < a.length; i++)
            a[i] = parseInt(a[i]);

        let left = new Array(n+10);
        left.fill(0);
        let ans = 0;
        for(let i = 0; i < n; i++){
            let right = new Array(n+10);
            right.fill(0);
            for(let j = n-1; j > i; j--){
                ans += left[a[j]] * right[a[i]];
                right[a[j]] += 1;
            }
            left[a[i]] += 1;
        }

        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 main() {
  const T = parseInt(readline());
  for (let t=0; t<T; t++) {
    const n = parseInt(readline());
    const nums = readline().split(" ").map(x => parseInt(x));

    let result = 0;
    // left[x] is the number of smaller than index j with value x
    let left = new Array(n).fill(0);
    // right[x] is the number of greater than index k with value x
    let right = new Array(n).fill(0);

    // iterate over each j and k
    for (let j=0; j<n; j++) {
      right.fill(0);
      for (let k=n-1; j<k; k--) {
        result += left[nums[k]] * right[nums[j]];
        right[nums[k]]++;
      }
      left[nums[j]]++;
    }
    console.log(result);
  }
}


This is the easy version of Problem F. The only difference between the easy version and the hard version is the constraints.We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and "++-+--" are balanced, and strings "+--", "--" and "" are not balanced.We will call a string promising if the string can be made balanced by several (possibly zero) uses of the following operation:  replace two adjacent minus signs with one plus sign. In particular, every balanced string is promising. However, the converse is not true: not every promising string is balanced.For example, the string "-+---" is promising, because you can replace two adjacent minuses with plus and get a balanced string "-++-", or get another balanced string "-+-+".How many non-empty substrings of the given string $$$s$$$ are promising? Each non-empty promising substring must be counted in the answer as many times as it occurs in string $$$s$$$.Recall that a substring is a sequence of consecutive characters of the string. For example, for string "+-+" its substring are: "+-", "-+", "+", "+-+" (the string is a substring of itself) and some others. But the following strings are not its substring: "--", "++", "-++".

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 500$$$) —the number of test cases in the test. Then the descriptions of test cases follow. Each test case of input data consists of two lines. The first line consists of the number $$$n$$$ ($$$1 \le n \le 3000$$$): the length of $$$s$$$. The second line of the test case contains the string $$$s$$$ of length $$$n$$$, consisting only of characters "+" and "-". It is guaranteed that the sum of values $$$n$$$ over all test cases does not exceed $$$3000$$$.

For each test case, print a single number: the number of the promising non-empty substrings of string $$$s$$$. Each non-empty promising substring must be counted in the answer as many times as it occurs in string $$$s$$$.

'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);

class SegTree {
  constructor(l, r) {
    this.l = l;
    this.r = r;
    this.root = this._newNode(l, r);
    this.update = this._update.bind(this, this.root);
    this.query = this._query.bind(this, this.root);
  }

  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return {
      val,
      l,
      r,
      left,
      right
    };
  }

  _update(node, x, y, z) {
    if (!node) return;
    const {
      l,
      r
    } = node;

    if (l === x && r === y) {
      node.val[z % 3]++;
      return;
    }

    const mid = Math.floor((l + r) / 2);

    if (!node.left) {
      node.left = this._newNode(l, mid);
      node.right = this._newNode(mid + 1, r);
    }

    if (y <= mid) this._update(node.left, x, y, z);else if (x > mid) this._update(node.right, x, y, z);else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z);

    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i];
  }

  _query(node, x, y, z) {
    if (y < x) return 0;
    if (!node) return 0;
    const {
      l,
      r
    } = node;
    if (l === x && r === y) return node.val[z];
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (y <= mid) res = this._query(node.left, x, y, z);else if (x > mid) res = this._query(node.right, x, y, z);else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z);
    return res;
  }

}

function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
      sum = 0,
      max = 0,
      min = 0;

  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0;
    pre[i + 1] = i + 1 - 2 * sum;
    max = Math.max(max, pre[i + 1]);
    min = Math.min(min, pre[i + 1]);
  }

  let res = 0;
  const segTree = new SegTree(min, max);

  for (let i = 0; i <= n; i++) {
    const cur = pre[i];
    res += segTree.query(min, cur, (cur % 3 + 3) % 3);
    segTree.update(cur, cur, (cur % 3 + 3) % 3);
  }

  return res;
}

// 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() {
  let t = Number(inputs[0]),
      __ = 1,
      res = [];

  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++]);
    let str = inputs[__++].trim();
    res.push(solve(n, str));
  }

  console.log(res.join('\n'));
}();

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

class SegTree {
  constructor(l, r) {
    this.l = l
    this.r = r
    this.root = this._newNode(l, r)
    this.update = this._update.bind(this, this.root)
    this.query = this._query.bind(this, this.root)
  }
  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return { val, l, r, left, right }
  }
  _update(node, x, y, z) {
    if (!node) return
    const { l, r } = node
    if (l === x && r === y) {
      node.val[z % 3]++
      return
    }
    const mid = Math.floor((l + r) / 2)
    if (!node.left) {
      node.left = this._newNode(l, mid)
      node.right = this._newNode(mid + 1, r)
    }
    if (y <= mid) this._update(node.left, x, y, z)
    else if (x > mid) this._update(node.right, x, y, z)
    else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)
    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]
  }
  _query(node, x, y, z) {
    if (y < x) return 0
    if (!node) return 0
    const { l, r } = node
    if (l === x && r === y) return node.val[z]
    let res = 0,
      mid = Math.floor((l + r) / 2)
    if (y <= mid) res = this._query(node.left, x, y, z)
    else if (x > mid) res = this._query(node.right, x, y, z)
    else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)
    return res
  }
}
function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
    sum = 0,
    max = 0,
    min = 0
  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0
    pre[i + 1] = i + 1 - 2 * sum
    max = Math.max(max, pre[i + 1])
    min = Math.min(min, pre[i + 1])
  }
  let res = 0
  const segTree = new SegTree(min, max)
  for (let i = 0; i <= n; i++) {
    const cur = pre[i]
    res += segTree.query(min, cur, ((cur % 3) + 3) % 3)
    segTree.update(cur, cur, ((cur % 3) + 3) % 3)
  }
  return res
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    let str = inputs[__++].trim()
    res.push(solve(n, str))
  }
  console.log(res.join('\n'))
})()

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 s = rl();

		const preplus = [0], preminus = [0];
		for (let i = 0; i < n; i++) {
			preplus[i+1] = preplus[i] + (s[i] == '+');
			preminus[i+1] = preminus[i] + (s[i] == '-');
		}

		let ans = 0;
		for (let i = 0; i < n; i++) {
			for (let j = i; j < n; j++) {
				const pluses = preplus[j+1] - preplus[i];
				const minuses = preminus[j+1] - preminus[i];
				ans += minuses >= pluses && (minuses - pluses) % 3 == 0;
			}
		}

		console.log(ans);
	}
}

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
let n;
let s;
function can(l, p) {
    let m = l - p;
    if (m < p) {
        return false;
    }
    let rem = m - p;
    return ((rem % 3) == 0);
}
function solve() {
    const pre = af(n).fill(0);
    for (let i = 0; i < n; i++) {
        if (i > 0) {
            pre[i] = pre[i - 1];
        }
        if (s[i] == '+') {
            pre[i]++;
        }
    }
    let ans = 0;
    for (let i = 0; i < n; i++) {
        for (let j = i + 2; j <= n; j++) {
            let l = j - i;
            let p = pre[j - 1] - ((i > 0) ? pre[i - 1] : 0);
            let t = can(l, p);
            // printf("%s: %d %d can %d\n", s.substring(i,j), l, p, t);
            if (t) {
                ans++;
            }
        }
    }
    return ans;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        s = nextStr();
        printf("%d\n", solve());
    }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const str = lines[l++]
        output[i] = solve(n, str)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, str) {
    const sum = []
    const count = [] // of '--'
    let ans = 0
    for (let i = 0; i < n; i++) {
        sum[i] = []
        count[i] = []
        for (let j = i; j < n; j++) {
            const now = str[j] === '+' ? 1 : -1
            sum[i][j] = j > i ? sum[i][j - 1] + now : now
            //
            if (str[j] === '-' && str[j - 1] === '-') {
                count[i][j] = (count[i][j - 2] || 0) + 1
            } else {
                count[i][j] = j > i ? count[i][j - 1] : 0
            }
            //
            if (sum[i][j] === 0) {
                ans++
            } else if (sum[i][j] < 0 && !(sum[i][j] % 3)) {
                if (-sum[i][j] / 3 <= count[i][j]) ans++
            }
        }
    }
// console.log(sum, count)
    return ans
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')

class SegTree {
  constructor(l, r) {
    this.l = l
    this.r = r
    this.root = this._newNode(l, r)
    this.update = this._update.bind(this, this.root)
    this.query = this._query.bind(this, this.root)
  }
  _newNode(l, r, val = new Array(3).fill(0), left = null, right = null) {
    return { val, l, r, left, right }
  }
  _update(node, x, y, z) {
    if (!node) return
    const { l, r } = node
    if (l === x && r === y) {
      node.val[z % 3]++
      return
    }
    const mid = Math.floor((l + r) / 2)
    if (!node.left) {
      node.left = this._newNode(l, mid)
      node.right = this._newNode(mid + 1, r)
    }
    if (y <= mid) this._update(node.left, x, y, z)
    else if (x > mid) this._update(node.right, x, y, z)
    else this._update(node.left, x, mid, z), this._update(node.right, mid + 1, y, z)
    for (let i = 0; i < 3; i++) node.val[i] = node.left.val[i] + node.right.val[i]
  }
  _query(node, x, y, z) {
    if (y < x) return 0
    if (!node) return 0
    const { l, r } = node
    if (l === x && r === y) return node.val[z]
    let res = 0,
      mid = Math.floor((l + r) / 2)
    if (y <= mid) res = this._query(node.left, x, y, z)
    else if (x > mid) res = this._query(node.right, x, y, z)
    else res = this._query(node.left, x, mid, z) + this._query(node.right, mid + 1, y, z)
    return res
  }
}
function solve(n, s) {
  let pre = new Array(n + 1).fill(0),
    sum = 0,
    max = 0,
    min = 0
  for (let i = 0; i < n; i++) {
    sum += s[i] === '+' ? 1 : 0
    pre[i + 1] = i + 1 - 2 * sum
    max = Math.max(max, pre[i + 1])
    min = Math.min(min, pre[i + 1])
  }
  let res = 0
  const segTree = new SegTree(min, max)
  for (let i = 0; i <= n; i++) {
    const cur = pre[i]
    res += segTree.query(min, cur, (cur + 3) % 3)
    segTree.update(cur, cur, (cur + 3) % 3)
  }
  return res
}

void (function main() {
  let t = Number(inputs[0]),
    __ = 1,
    res = []
  for (let _ = 0; _ < t; _++) {
    const n = Number(inputs[__++])
    let str = inputs[__++].trim()
    res.push(solve(n, str))
  }
  console.log(res.join('\n'))
})()


Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C.There are $$$n$$$ flights from A to B, they depart at time moments $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, ..., $$$a_n$$$ and arrive at B $$$t_a$$$ moments later.There are $$$m$$$ flights from B to C, they depart at time moments $$$b_1$$$, $$$b_2$$$, $$$b_3$$$, ..., $$$b_m$$$ and arrive at C $$$t_b$$$ moments later.The connection time is negligible, so one can use the $$$i$$$-th flight from A to B and the $$$j$$$-th flight from B to C if and only if $$$b_j \ge a_i + t_a$$$.You can cancel at most $$$k$$$ flights. If you cancel a flight, Arkady can not use it.Arkady wants to be in C as early as possible, while you want him to be in C as late as possible. Find the earliest time Arkady can arrive at C, if you optimally cancel $$$k$$$ flights. If you can cancel $$$k$$$ or less flights in such a way that it is not possible to reach C at all, print $$$-1$$$.

The first line contains five integers $$$n$$$, $$$m$$$, $$$t_a$$$, $$$t_b$$$ and $$$k$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$, $$$1 \le k \le n + m$$$, $$$1 \le t_a, t_b \le 10^9$$$) — the number of flights from A to B, the number of flights from B to C, the flight time from A to B, the flight time from B to C and the number of flights you can cancel, respectively. The second line contains $$$n$$$ distinct integers in increasing order $$$a_1$$$, $$$a_2$$$, $$$a_3$$$, ..., $$$a_n$$$ ($$$1 \le a_1 < a_2 < \ldots < a_n \le 10^9$$$) — the times the flights from A to B depart. The third line contains $$$m$$$ distinct integers in increasing order $$$b_1$$$, $$$b_2$$$, $$$b_3$$$, ..., $$$b_m$$$ ($$$1 \le b_1 < b_2 < \ldots < b_m \le 10^9$$$) — the times the flights from B to C depart.

If you can cancel $$$k$$$ or less flights in such a way that it is not possible to reach C at all, print $$$-1$$$. Otherwise print the earliest time Arkady can arrive at C if you cancel $$$k$$$ flights in such a way that maximizes this time.

NoteConsider the first example. The flights from A to B depart at time moments $$$1$$$, $$$3$$$, $$$5$$$, and $$$7$$$ and arrive at B at time moments $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$, respectively. The flights from B to C depart at time moments $$$1$$$, $$$2$$$, $$$3$$$, $$$9$$$, and $$$10$$$ and arrive at C at time moments $$$2$$$, $$$3$$$, $$$4$$$, $$$10$$$, $$$11$$$, respectively. You can cancel at most two flights. The optimal solution is to cancel the first flight from A to B and the fourth flight from B to C. This way Arkady has to take the second flight from A to B, arrive at B at time moment $$$4$$$, and take the last flight from B to C arriving at C at time moment $$$11$$$.In the second example you can simply cancel all flights from A to B and you're done.In the third example you can cancel only one flight, and the optimal solution is to cancel the first flight from A to B. Note that there is still just enough time to catch the last flight from B to C.

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
var STATE = 1;
var n, m, t_a, t_b, k, a, b, a_t, b_t;
rl.on('line', function (input) {
  switch (STATE) {
    case 1:
      var params = input.split(' ');
      n = parseInt(params[0], 10);
      m = parseInt(params[1], 10);
      t_a = parseInt(params[2], 10);
      t_b = parseInt(params[3], 10);
      k = parseInt(params[4], 10);
      // console.log(STATE + ':', n, m, t_a, t_b, k);
      STATE = 2;
      break;
    case 2:
      a = input.split(' ').map(Number);
      a_t = a.map(function(elem) { return elem + t_a });
      // console.log(STATE + ':', a, a_t);
      STATE = 3;
      break;
    case 3:
      b = input.split(' ').map(Number);
      b_t = b.map(function(elem) { return elem + t_b });
      // console.log(STATE + ':', b, b_t);

      calc(k, a, b, a_t, b_t);

      STATE = 1;
      break;
    default:
      // code
  }
}).on('close', function() {
  process.exit(0);
});

function calc(k, a, b, a_t, b_t) {
  // console.log('calc', k, a, b, a_t, b_t);
  if (a.length <= k) {
    console.log(-1);
    return;
  }

  if (b.length <= k) {
    console.log(-1);
    return;
  }

  var max_b = b.reduce(function(max, p) { return p > max ? p : max }, b[0]);
  // console.log(max_b);
  if (a_t[k] > max_b) {
    console.log(-1);
    return;
  }

  var result = 0;
  var idx = -1;
  for (var i = 0; i <= k; i++) {
    var a_t_elem = a_t[i];
    idx = findIndexFirstGreater(b, a_t_elem, idx);
    if (idx === -1) {
      console.log(-1);
      return;
    }
    var current = b_t[idx + k - i];
    if (typeof current !== 'number') {
      console.log(-1);
      return;
    }
    result = Math.max(result, current);
    // console.log('for', a_t_elem, idx, current, result);
  }
  console.log(result);
}

function findIndexFirstGreater(arr, elem, start) {
  for(var i = start, len = arr.length; i < len; i++){
    if(arr[i] >= elem){
      return i;
    }
  }
  return -1;
}

var readline = require('readline');
var rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});
var STATE = 1;
var n, m, t_a, t_b, k, a, b, a_t, b_t;
rl.on('line', function (input) {
  switch (STATE) {
    case 1:
      var params = input.split(' ');
      n = parseInt(params[0], 10);
      m = parseInt(params[1], 10);
      t_a = parseInt(params[2], 10);
      t_b = parseInt(params[3], 10);
      k = parseInt(params[4], 10);
      // console.log(STATE + ':', n, m, t_a, t_b, k);
      STATE = 2;
      break;
    case 2:
      a = input.split(' ').map(Number);
      a_t = a.map(function(elem) { return elem + t_a });
      // console.log(STATE + ':', a, a_t);
      STATE = 3;
      break;
    case 3:
      b = input.split(' ').map(Number);
      b_t = b.map(function(elem) { return elem + t_b });
      // console.log(STATE + ':', b, b_t);

      calc(k, a, b, a_t, b_t);

      STATE = 1;
      break;
    default:
      // code
  }
}).on('close', function() {
  process.exit(0);
});

function calc(k, a, b, a_t, b_t) {
  // console.log('calc', k, a, b, a_t, b_t);
  if (a.length <= k) {
    console.log(-1);
    return;
  }

  if (b.length <= k) {
    console.log(-1);
    return;
  }

  var max_b = b.reduce(function(max, p) { return p > max ? p : max }, b[0]);
  // console.log(max_b);
  if (a_t[k] > max_b) {
    console.log(-1);
    return;
  }

  var result = 0;
  var idx = -1;
  for (var i = 0; i <= k; i++) {
    var a_t_elem = a_t[i];
    idx = findIndexFirstGreater(b, a_t_elem, idx);
    if (idx === -1) {
      console.log(-1);
      return;
    }
    result = Math.max(result, b_t[idx + k - i]);
    // console.log('for', a_t_elem, idx, b_t[idx + k - i], result);
  }
  console.log(result);
}

function findIndexFirstGreater(arr, elem, start) {
  for(var i = start, len = arr.length; i < len; i++){
    if(arr[i] >= elem){
      return i;
    }
  }
  return -1;
}


The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement. UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:  The query to swap two table rows;  The query to swap two table columns;  The query to obtain a secret number in a particular table cell. As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.

The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly. Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106. Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers.   If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y);  If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y);  If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m).  The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.

For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.

NoteLet's see how the table changes in the second test case.After the first operation is fulfilled, the table looks like that:2 1 41 3 5After the second operation is fulfilled, the table looks like that:1 3 52 1 4So the answer to the third query (the number located in the first row and in the third column) will be 5.

var s = "";
var buf = "";

s = readline().split(' ');

var n = s[0] - 0;
var m = s[1] - 0;
var k = s[2] - 0;

var row = new Array(n + 1);
for (var i = 0; i < n + 1; i++) row[i] = i;

var col = new Array(m + 1);
for (var i = 0; i < m + 1; i++) col[i] = i;

var matrix = new Array(n);
for (var i = 0; i < n; i++) {
    matrix[i] = readline().split(' ');
}

for (var i = 0; i < k; i++) {

    s = readline().split(' ');

    var q = s[0];
    var x = s[1] - 0;
    var y = s[2] - 0;

    if (q == 'c') {
        var c = col[x]; col[x] = col[y], col[y] = c;
    } else if (q == 'r') {
        var c = row[x]; row[x] = row[y], row[y] = c;
    } else {
        buf += matrix[row[x] - 1][col[y] - 1] + '\n';
    }
}

print(buf);

var s = "";

s = readline().split(' ');

var n = s[0] - 0;
var m = s[1] - 0;
var k = s[2] - 0;

var row = new Array(n + 1);
for (var i = 0; i < n + 1; i++) row[i] = i;

var col = new Array(m + 1);
for (var i = 0; i < m + 1; i++) col[i] = i;

var matrix = new Array(n);
for (var i = 0; i < n; i++) {
    matrix[i] = readline().split(' ');
}

for (var i = 0; i < k; i++) {

    s = readline().split(' ');

    var q = s[0];
    var x = s[1] - 0;
    var y = s[2] - 0;

    if (q == 'c') {
        var c = col[x]; col[x] = col[y], col[y] = c;
    } else if (q == 'r') {
        var c = row[x]; row[x] = row[y], row[y] = c;
    } else {
        print(matrix[row[x] - 1][col[y] - 1]);
    }
}

var s = "";
var buf = "";

s = readline().split(' ');

var n = s[0] - 0;
var m = s[1] - 0;
var k = s[2] - 0;

var row = new Array(n + 1);
for (var i = 0; i < n + 1; i++) row[i] = i;

var col = new Array(m + 1);
for (var i = 0; i < m + 1; i++) col[i] = i;

var matrix = new Array(n);
for (var i = 0; i < n; i++) {
    matrix[i] = readline().split(' ');
}

for (var i = 0; i < k; i++) {

    s = readline().split(' ');

    var q = s[0];
    var x = s[1] - 0;
    var y = s[2] - 0;

    if (q == 'c') {
        var c = col[x]; col[x] = col[y], col[y] = c;
    } else if (q == 'r') {
        var c = row[x]; row[x] = row[y], row[y] = c;
    } else {
        buf += matrix[row[x] - 1][col[y] - 1] + '\n';
        if (i % 65536 == 0) {
            print(buf);
            buf = "";
        };
    }
}

print(buf);

(function main() {
    var l = readline().split(' ');
    var nrow = parseInt(l[0]);
    var ncol = parseInt(l[1]);
    var nreq = parseInt(l[2]);
    var rows = new Array(nrow);
    var cols = new Array(ncol);
    var elem = new Array(nrow * ncol);
    var answer = '';
    for (var i = 0; i < nrow; ++i)
        rows[i] = i;
    for (var i = 0; i < ncol; ++i)
        cols[i] = i;
    var q = 0;
    for (var i = 0; i < nrow; ++i) {
        var l = readline().split(' ');
        for (var j = 0; j < ncol; ++j, ++q)
            elem[q] = parseInt(l[j]);
    }
    for (var i = 0; i < nreq; ++i) {
        var l = readline().split(' ');
        var a = l[0];
        var b = parseInt(l[1]) - 1;
        var c = parseInt(l[2]) - 1;
        if (a == 'c') {
            var t = cols[b];
            cols[b] = cols[c];
            cols[c] = t;
        } else if (a == 'r') {
            var t = rows[b];
            rows[b] = rows[c];
            rows[c] = t;
        } else {
            answer += elem[rows[b] * ncol + cols[c]] + '\n';
        }
    }
    print(answer);
})();


You have a description of a lever as string s. We'll represent the string length as record |s|, then the lever looks as a horizontal bar with weights of length |s| - 1 with exactly one pivot. We will assume that the bar is a segment on the Ox axis between points 0 and |s| - 1.The decoding of the lever description is given below.  If the i-th character of the string equals "^", that means that at coordinate i there is the pivot under the bar.  If the i-th character of the string equals "=", that means that at coordinate i there is nothing lying on the bar.  If the i-th character of the string equals digit c (1-9), that means that at coordinate i there is a weight of mass c on the bar. Your task is, given the lever description, print if it will be in balance or not. Assume that the bar doesn't weight anything. Assume that the bar initially is in balance then all weights are simultaneously put on it. After that the bar either tilts to the left, or tilts to the right, or is in balance.

The first line contains the lever description as a non-empty string s (3 ≤ |s| ≤ 106), consisting of digits (1-9) and characters "^" and "=". It is guaranteed that the line contains exactly one character "^". It is guaranteed that the pivot of the lever isn't located in any end of the lever bar. To solve the problem you may need 64-bit integer numbers. Please, do not forget to use them in your programs.

Print "left" if the given lever tilts to the left, "right" if it tilts to the right and "balance", if it is in balance.

NoteAs you solve the problem, you may find the following link useful to better understand how a lever functions: http://en.wikipedia.org/wiki/Lever.The pictures to the examples:

print(function(s) {

	var i,
		ans = 0,
		c = s.indexOf('^');

	for (i = 0; i < s.length; i++)
		if (s[i] <= '9') ans += (c - i) * s[i];

	if (ans > 0) return 'left';
	if (ans < 0) return 'right';
	return 'balance';

}(readline()));

var countOnce = function (res,item,position) {
    return res + (position+1)*(item=='='?0:item);
}

var a = readline().split('^'),
    l = a[0].split('').reverse().reduce(countOnce,0),
    r = a[1].split('').reduce(countOnce,0);

if (l==r) {
    print('balance')
} else if (l>r) {
    print('left')
} else {
    print('right')
}

// Generated by CoffeeScript 1.4.0
(function() {
  var c, lmom, lsum, op, rdist, rmom, s, _i, _len;

  String.prototype.reverse = function() {
    return this.split("").reverse().join("");
  };

  s = readline();

  lsum = lmom = 0;

  rdist = rmom = 0;

  op = false;

  for (_i = 0, _len = s.length; _i < _len; _i++) {
    c = s[_i];
    if (!op) {
      lmom += lsum;
    } else {
      rdist++;
    }
    if (c === '^') {
      op = true;
      continue;
    }
    if (c === '=') {
      continue;
    }
    if (!op) {
      lsum += c | 0;
    } else {
      rmom += (c | 0) * rdist;
    }
  }

  print(lmom > rmom ? 'left' : rmom > lmom ? 'right' : 'balance');

}).call(this);

;(function () {
	print(function () {
		var w = readline(),
			n = w.indexOf('^'), r = 0, l = 0;

		for (var i = 0; i < n; i++) {
			var q = w[i];
			if (q !== '=') {
				q = parseInt(q);
				l += (n - i) * q;
			}
		}

		for (var i = n + 1, _i = w.length; i < _i; i++) {
			var q = w[i];
			if (q !== '=') {
				q = parseInt(q);
				r += (i - n) * q;
			}
		}

		return l === r ? 'balance' : (r > l ? 'right' : 'left');
	}());
}).call(this);

var input = readline();
var idx = input.search(/\^/);
var result = 0;

for(var i=0; i<input.length; i++)
{
    if(input[i]!='=' && input[i]!='^') result+=parseInt(input[i])*(idx-i);
}
if(Math.abs(result)<0.001) print('balance');
else if(result>0) print('left');
else print('right');

var lever = readline();

var isLeft = true;
var leftCount = 0;
var rightCount = 0;
var center = 0;

for (var i = 0; i < lever.length; ++i) {
    if (lever.charAt(i) == '^') {
        center = i;
        break;
    }
}

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

    if (lever.charAt(i) == '=') {
        continue;
    }
    else if (lever.charAt(i) == '^') {
        isLeft = false;
    }
    else {
        value = lever.charAt(i) - '0';
    }

    if (isLeft == true) {
        leftCount += value * (center - i);
    } else {
        rightCount += value * (i - center);
    }
}

if (leftCount > rightCount) {
    print("left");
} else if (leftCount < rightCount) {
    print("right");
} else {
    print("balance");
}

// Generated by CoffeeScript 1.4.0
(function() {
  var c, lmom, lsum, op, rdist, rmom, s, _i, _len;

  String.prototype.reverse = function() {
    return this.split("").reverse().join("");
  };

  s = readline();

  lsum = lmom = 0;

  rdist = rmom = 0;

  op = false;

  for (_i = 0, _len = s.length; _i < _len; _i++) {
    c = s[_i];
    if (!op) {
      lmom += lsum;
    } else {
      rdist++;
    }
    if (c === '^') {
      op = true;
      continue;
    }
    if (c === '=') {
      continue;
    }
    if (!op) {
      lsum += c | 0;
    } else {
      rmom += (c | 0) * rdist;
    }
  }

  print(lmom > rmom ? 'left' : rmom < lmom ? 'right' : 'balance');

}).call(this);

// Generated by CoffeeScript 1.4.0
(function() {
  var s, solve;

  String.prototype.reverse = function() {
    return this.split("").reverse().join("");
  };

  s = readline();

  solve = function(s) {
    var c, lmom, lsum, op, rdist, rmom, rsum, _i, _len;
    lsum = lmom = 0;
    rdist = rsum = rmom = 0;
    op = false;
    for (_i = 0, _len = s.length; _i < _len; _i++) {
      c = s[_i];
      if (!op) {
        lmom += lsum;
      } else {
        rdist++;
      }
      if (c === '^') {
        op = true;
        continue;
      }
      if (c === '=') {
        continue;
      }
      if (!op) {
        lsum += c | 0;
      } else {
        rsum += (c | 0) * rdist;
      }
    }
    return lsum > rsum;
  };

  print(solve(s) ? 'left' : solve(s.reverse()) ? 'right' : 'balance');

}).call(this);


Acingel is a small town. There was only one doctor here — Miss Ada. She was very friendly and nobody has ever said something bad about her, so who could've expected that Ada will be found dead in her house? Mr Gawry, world-famous detective, is appointed to find the criminal. He asked $$$m$$$ neighbours of Ada about clients who have visited her in that unlucky day. Let's number the clients from $$$1$$$ to $$$n$$$. Each neighbour's testimony is a permutation of these numbers, which describes the order in which clients have been seen by the asked neighbour.However, some facts are very suspicious – how it is that, according to some of given permutations, some client has been seen in the morning, while in others he has been seen in the evening? "In the morning some of neighbours must have been sleeping!" — thinks Gawry — "and in the evening there's been too dark to see somebody's face...". Now he wants to delete some prefix and some suffix (both prefix and suffix can be empty) in each permutation, so that they'll be non-empty and equal to each other after that — some of the potential criminals may disappear, but the testimony won't stand in contradiction to each other.In how many ways he can do it? Two ways are called different if the remaining common part is different.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le m \le 10$$$) — the number of suspects and the number of asked neighbors. Each of the next $$$m$$$ lines contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that these integers form a correct permutation (that is, each number from $$$1$$$ to $$$n$$$ appears exactly once).

Output a single integer denoting the number of ways to delete some prefix and some suffix of each permutation (possibly empty), such that the remaining parts will be equal and non-empty.

NoteIn the first example, all possible common parts are $$$[1]$$$, $$$[2]$$$, $$$[3]$$$ and $$$[2, 3]$$$.In the second and third examples, you can only leave common parts of length $$$1$$$.

        'use strict';

        const tmp = readline().split(' ').map(Number);
        const n = tmp[0];
        const m = tmp[1];
        const perm = new Array(m);
        const pos = new Array(n).fill(0).map(function (value) { return new Array(m).fill(0); });

        for (let i = 0; i < m; i++) {
            perm[i] = readline().split(' ').map(Number);
            for (let j = 0; j < n; j++) {
                --perm[i][j];
                pos[perm[i][j]][i] = j;
            }
        }

        const visited = new Array(n).fill(false);
        const len = new Array(n);

        const similar = function (positions) {
            for (let i = 1; i < m; i++) {
                if (perm[i][positions[i]] !== perm[0][positions[0]]) {
                    return false;
                }
            }
            return true;
        };

        const increase = function (positions) {
            for (let i = 0; i < m; i++) {
                ++positions[i];
                if (positions[i] >= n) {
                    return false;
                }
            }
            return true;
        };

        for (let i = 0; i < n; i++) {
            if (visited[i]) {
                continue;
            }
            const positions = new Array(m);
            for (let j = 0; j < m; j++) {
                positions[j] = pos[i][j];
            }
            let val = 1;
            while (increase(positions) && similar(positions)) {
                const el = perm[0][positions[0]];
                if (visited[el]) {
                    val += len[el];
                    break;
                } else {
                    ++val;
                }
            }
            const start = pos[i][0];
            for (let j = positions[0] - 1; j >= start; j--) {
                const el = perm[0][j];
                len[perm[0][j]] = val - j + start;
                visited[perm[0][j]] = true;
            }
        }

        let ans = 0;
        for (let i = 0; i < n; i++) {
            ans += len[i];
        }
        print(ans);

        'use strict';

        const tmp = readline().split(' ').map(Number);
        const n = tmp[0];
        const m = tmp[1];
        const perm = new Array(m);
        const pos = new Array(n).fill(0).map(function (value) { return new Array(m).fill(0); });

        for (let i = 0; i < m; i++) {
            perm[i] = readline().split(' ').map(Number);
            for (let j = 0; j < n; j++) {
                --perm[i][j];
                pos[perm[i][j]][i] = j;
            }
        }

        const visited = new Array(n).fill(false);
        const len = new Array(n);

        const similar = function (positions) {
            for (let i = 1; i < m; i++) {
                if (perm[i][positions[i]] !== perm[0][positions[0]]) {
                    return false;
                }
            }
            return true;
        };

        const increase = function (positions) {
            for (let i = 0; i < m; i++) {
                ++positions[i];
                if (positions[i] >= n) {
                    return false;
                }
            }
            return true;
        };

        for (let i = 0; i < n; i++) {
            const positions = new Array(m);
            for (let j = 0; j < m; j++) {
                positions[j] = pos[i][j];
            }
            let val = 1;
            while (increase(positions) && similar(positions)) {
                if (visited[pos[positions[0]]]) {
                    val += len[pos[positions[0]]];
                    break;
                } else {
                    ++val;
                }
            }
            for (let j = pos[positions[0] - 1][0]; j >= pos[i][0]; j--) {
                len[perm[0][j]] = val - j + i;
                visited[j] = true;
            }
        }

        let ans = 0;
        for (let i = 0; i < n; i++) {
            ans += len[i];
        }
        print(ans);

        'use strict';

        const tmp = readline().split(' ').map(Number);
        const n = tmp[0];
        const m = tmp[1];
        const perm = new Array(m);
        const pos = new Array(n).fill(0).map(function (value) { return new Array(m).fill(0); });

        for (let i = 0; i < m; i++) {
            perm[i] = readline().split(' ').map(Number);
            for (let j = 0; j < n; j++) {
                --perm[i][j];
                pos[perm[i][j]][i] = j;
            }
        }

        const visited = new Array(n).fill(false);
        const len = new Array(n);

        const similar = function (positions) {
            for (let i = 1; i < m; i++) {
                if (perm[i][positions[i]] !== perm[0][positions[0]]) {
                    return false;
                }
            }
            return true;
        };

        const increase = function (positions) {
            for (let i = 0; i < m; i++) {
                ++positions[i];
                if (positions[i] >= n) {
                    return false;
                }
            }
            return true;
        };

        for (let i = 0; i < n; i++) {
            const positions = new Array(m);
            for (let j = 0; j < m; j++) {
                positions[j] = pos[i][j];
            }
            let val = 1;
            while (increase(positions) && similar(positions)) {
                if (visited[pos[positions[0]]]) {
                    val += len[pos[positions[0]]];
                    break;
                } else {
                    ++val;
                }
            }
            for (let j = positions[0] - 1; j >= i; j--) {
                len[perm[0][j]] = val - j + i;
                visited[perm[0][j]] = true;
            }
        }

        let ans = 0;
        for (let i = 0; i < n; i++) {
            ans += len[i];
        }
        print(ans);

        'use strict';

        const tmp = readline().split(' ').map(Number);
        const n = tmp[0];
        const m = tmp[1];
        const perm = new Array(m);
        const pos = new Array(n).fill(0).map(function (value) { return new Array(m).fill(0); });

        for (let i = 0; i < m; i++) {
            perm[i] = readline().split(' ').map(Number);
            for (let j = 0; j < n; j++) {
                --perm[i][j];
                pos[perm[i][j]][i] = j;
            }
        }

        const visited = new Array(n).fill(false);
        const len = new Array(n);

        const similar = function (positions) {
            for (let i = 1; i < m; i++) {
                if (perm[i][positions[i]] !== perm[0][positions[0]]) {
                    return false;
                }
            }
            return true;
        };

        const increase = function (positions) {
            for (let i = 0; i < m; i++) {
                ++positions[i];
                if (positions[i] >= n) {
                    return false;
                }
            }
            return true;
        };

        for (let i = 0; i < n; i++) {
            const positions = new Array(m);
            for (let j = 0; j < m; j++) {
                positions[j] = pos[i][j];
            }
            let val = 1;
            while (increase(positions) && similar(positions)) {
                if (visited[pos[positions[0]]]) {
                    val += len[pos[positions[0]]];
                    break;
                } else {
                    ++val;
                }
            }
            for (let j = positions[0] - 1; j >= i; j--) {
                len[perm[0][j]] = val - j + i;
                visited[j] = true;
            }
        }

        let ans = 0;
        for (let i = 0; i < n; i++) {
            ans += len[i];
        }
        print(ans);


A positive integer $$$x$$$ is called a power of two if it can be represented as $$$x = 2^y$$$, where $$$y$$$ is a non-negative integer. So, the powers of two are $$$1, 2, 4, 8, 16, \dots$$$.You are given two positive integers $$$n$$$ and $$$k$$$. Your task is to represent $$$n$$$ as the sum of exactly $$$k$$$ powers of two.

The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le k \le 2 \cdot 10^5$$$).

If it is impossible to represent $$$n$$$ as the sum of $$$k$$$ powers of two, print NO. Otherwise, print YES, and then print $$$k$$$ positive integers $$$b_1, b_2, \dots, b_k$$$ such that each of $$$b_i$$$ is a power of two, and $$$\sum \limits_{i = 1}^{k} b_i = n$$$. If there are multiple answers, you may print any of them.

function test() {
  assert(task(['9 4']), 'YES\n' +
    '4 1 2 2');
  assert(task(['8 1']), 'YES\n8');
  assert(task(['5 1']), 'NO');
}

function task([input]) {
  let [n, k] = input.split(' ');
  n = Number(n);
  k = Number(k);

  if (k > n) return 'NO';

  let result = [];
  let nBinary = n.toString(2);

  for (let i = 0; i < nBinary.length; i++) {
    if (nBinary[i] === '1') result.push(Math.pow(2, nBinary.length - i - 1));
  }

  let i = 0;
  let count = result.length;

  while (count < k) {
    let item = result[i];
    result[i] = false;
    if (item > 1) {
      result.push(item / 2, item / 2);
      count += 1;
    } else {
      result.push(item);
    }
    i++;
  }

  result = result.filter(Boolean);

  if (result.length !== k) {
    return 'NO';
  }

  return `YES\n${result.join(' ')}`
}

function assert(result, expectation, unordered) {
  if (unordered) {
    result = result.split(' ');
    expectation = expectation.split(' ');

    if (result.sort().join(' ') !== expectation.sort().join(' ')) {
      console.error(`${result}: ${expectation}`);
    }
  } else if (result !== expectation) {
    console.error(`${result}: ${expectation}`);
  }
}

function run() {
  // codeforces uses windows. Really??!
  if (process.platform === 'win32') {
    const readline = require('readline');
    const rl = readline.createInterface({ input: process.stdin });

    const input = [];

    rl.on('line', (line) => input.push(line));
    rl.on('close', () => console.log(task(input)));
  } else {
    test();
  }
}

run();

const read = [];
const M = new Map();

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

RL.on('line', line => {
  read.push(line.trim());
});
RL.on('close', () => {
  const [n, k] = read[0].split(' ').map(Number);
  const obj = {
    pointer: 0,
    counter: 0,
  };

  preCalc(n, obj);

  if (obj.counter > k) {
    console.log('NO');
    return;
  }

  while (obj.counter !== k && obj.pointer !== 1) {
    M.set(obj.pointer, M.get(obj.pointer) - 1);
    obj.counter -= 1;

    M.set(obj.pointer >> 1, M.get(obj.pointer >> 1) + 2);
    obj.counter += 2;

    if (M.get(obj.pointer) === 0) {
      obj.pointer >>= 1;
    }
  }

  if (obj.counter !== k) {
    console.log('NO');
    return;
  }

  const answer = [];
  for (const [key, value] of M.entries()) {
    if (value === 0) {
      continue;
    }

    for (let i = 0; i < value; i += 1) {
      answer.push(key);
    }
  }

  console.log('YES');
  console.log(`${answer.join(' ')}`);
});

function preCalc(n, obj) {
  for (let i = 0; i < 32; i += 1) {
    if (((1 << i) & n) > 0) {
      M.set(1 << i, 1);
      obj.counter += 1;
      obj.pointer = 1 << i;
    } else {
      M.set(1 << i, 0);
    }
  }
}


You have $$$n$$$ rectangular wooden blocks, which are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th block is $$$1$$$ unit high and $$$\lceil \frac{i}{2} \rceil$$$ units long.Here, $$$\lceil \frac{x}{2} \rceil$$$ denotes the result of division of $$$x$$$ by $$$2$$$, rounded up. For example, $$$\lceil \frac{4}{2} \rceil = 2$$$ and $$$\lceil \frac{5}{2} \rceil = \lceil 2.5 \rceil = 3$$$.For example, if $$$n=5$$$, then the blocks have the following sizes: $$$1 \times 1$$$, $$$1 \times 1$$$, $$$1 \times 2$$$, $$$1 \times 2$$$, $$$1 \times 3$$$.  The available blocks for $$$n=5$$$ Find the maximum possible side length of a square you can create using these blocks, without rotating any of them. Note that you don't have to use all of the blocks.  One of the ways to create $$$3 \times 3$$$ square using blocks $$$1$$$ through $$$5$$$

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^9$$$) — the number of blocks.

For each test case, print one integer — the maximum possible side length of a square you can create.

NoteIn the first test case, you can create a $$$1 \times 1$$$ square using only one of the blocks.In the second test case, one of the possible ways to create a $$$3 \times 3$$$ square is shown in the statement. It is impossible to create a $$$4 \times 4$$$ or larger square, so the answer is $$$3$$$.

n =readline();
for(i=0;i<n;i++){
    t = readline();
    print(Math.round(t/2));
}

n = +readline();
for(i=0;i<n;i++){
    t = readline();
    print(Math.round(t/2));
}

var numOfCases = Number(readline());

for (var testCase = 0; testCase < numOfCases; testCase++) {
    var input = Number(readline());
    var result = process(input);
    print(result)
}

function process(input) {
    var inputVal = input;

    if (inputVal % 2 !== 0) {
        inputVal++
    }

    return inputVal / 2;
}

var line = readline();

for(var i=0; i<line;i++) {
    var number = readline();
    print(Math.round(number/2));
}

var t = readline();
t = parseInt(t);

while(t--){
    var n = readline();
    n = parseInt(n);
   print(Math.ceil(n/2));
}

const fs = require("fs");

// console.log(fs.readdirSync('./'));
// console.log(null);

fs.readFile("./input.fd0138e687.txt", "utf-8", (err, data) => {
  if (err) throw err;
  const tests = data.split("\r\n");
  tests.shift();
  tests.forEach((e) => {
    const ans = (Math.ceil(Number.parseInt(e) / 2));
    if (!Number.isNaN(ans)) console.log(ans);
  });
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t; i++){
        var a = lines[i];
        console.log(Math.ceil(a / 2));
    }
});

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0) {
        console.log(Math.ceil(parseInt(line) / 2));
        return;
    }

    index++;
})

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0) {
        console.log(Math.ceil(parseInt(line) / 2))
    }

    index++;
})

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

var input = '';
process.stdin.on('data', function(chunk) {
    input += chunk;
});

process.stdin.on('end', function() {
    // mb there can be overflow
    const data = input.trim().split('\n').map(Number);

    for (let i = 1; i < data.length; i++) {
        const solution = Math.ceil(data[i] / 2);
        console.log(solution);
    }
});

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline();
	var rem = BigInt(n) % BigInt(2);
	console.log(" " + (rem + (BigInt(n) / BigInt(2))))
}

function solve() {
    var n = Number(read());
    write((n + 1) >> 1);
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

function gcd(a, b) {
    if (b === 0) {
        return a;
    }
    return gcd(b, a % b)
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');

    main();
});

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

function gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        //let arr = readLine().trim().split(" ").map(x=>parseInt(x))

        console.log(Math.ceil(n/2))
   }
}

const fs = require("fs");

// console.log(fs.readdirSync('./'));
// console.log(null);

fs.readFile("./input.fd0138e687.txt", "utf-8", (err, data) => {
  if (err) throw err;
  const tests = data.split("\r\n");
  tests.shift();
  tests.forEach((e) => {
    console.log(Math.ceil(Number.parseInt(e) / 2));
  });
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t; i++){
        var a = lines[i];
        console.log(Math.ceil(a));
    }
});