Andre has very specific tastes. Recently he started falling in love with arrays.Andre calls an nonempty array $$$b$$$ good, if sum of its elements is divisible by the length of this array. For example, array $$$[2, 3, 1]$$$ is good, as sum of its elements — $$$6$$$ — is divisible by $$$3$$$, but array $$$[1, 1, 2, 3]$$$ isn't good, as $$$7$$$ isn't divisible by $$$4$$$. Andre calls an array $$$a$$$ of length $$$n$$$ perfect if the following conditions hold:   Every nonempty subarray of this array is good.  For every $$$i$$$ ($$$1 \le i \le n$$$), $$$1 \leq a_i \leq 100$$$. Given a positive integer $$$n$$$, output any perfect array of length $$$n$$$. We can show that for the given constraints such an array always exists.An array $$$c$$$ is a subarray of an array $$$d$$$ if $$$c$$$ can be obtained from $$$d$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).

For every test, output any perfect array of length $$$n$$$ on a separate line.

NoteArray $$$[19, 33]$$$ is perfect as all $$$3$$$ its subarrays: $$$[19]$$$, $$$[33]$$$, $$$[19, 33]$$$, have sums divisible by their lengths, and therefore are good.

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++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = Array(len).fill(1);
    console.log(arr.join(" "));
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var s = new Array(N).fill(1);
		output[i] = myconv(s, 8);
	}
	myout(myconv(output, 9));
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t]=i.default.nextNumbers();i.default.puts("1 ".repeat(t))}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   io.puts("1 ".repeat(n))
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let input = ''

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

process.stdin.on('end', () => {
  input.trim().split('\n').slice(1).map((x) => parseInt(x)).forEach((n) => {
    console.log([...new Array(n)].map(() => 1).join(' '))
  })
})

'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++];
}
/**
3
1
2
4

**/

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

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let n = Number(readline());
    let a = [];
    let j = 1;

    for(let i=1;i<=n;i++) {
        a.push(j);
    }

    console.log(a.join(" "));

}

var t = readline();
var a = [];
var b = [];
for (var i = 0; i < t; i++) {
    b.push(readline());
}
for (var i = 0; i < t; i++) {
    for (var j = 0; j < b[i]; j++) {
        a.push(1);
    }
    for (var j = 0; j < a.length; j++) {
        write(a[j] + " ");
    }
    a = [];
    write("\n");
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  for (var j = 0; j < l; j++) {
    res[j] = 1;
  }

    print(res.toString().replace(/\,/g, ' '));
}

var tc = parseInt(readline());
for(; tc--; ){
    var n = parseInt(readline());
    for(var i=0; i<n; i++) write(1 +' ');
}

'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++];
}
/**
3
1
2
4

**/

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

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let n = Number(readline());
    let a = [];
    let j = 1;

    for(let i=1;i<=n;i++) {
        a.push(j);
        j = j + 2;
    }

    console.log(a.join(" "));

}

(function() {
    var t = +readline()

    function checker(arr) {
        var sum = 0
        arr.map(item => sum += item)
        if (sum % arr.length === 0) {
           return true
        } else {
            return false
        }
    }

    function geter(arr) {
        var arr2 = []
        arr.map((item,index) => {
            if (index !== arr.length - 2) {
                arr2.push(item)
            }
        })
        var flag = checker(arr2)
        return flag
    }

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

        var n = +readline()
        var arr = []

        if (n % 2 === 0) {
             var num = 2
            for (j = 0; j < n; j++) {
                arr.push(num)
                num += 2
                var tempArr = arr
                var flag = geter(arr)
                if (!flag) {
                    while (!flag) {
                        tempArr = tempArr.filter((el,i) => i !== arr.length - 1)
                        num += 1
                        tempArr.push(num)
                        flag = geter(tempArr)
                    }
                    arr = tempArr
                }
            }
        } else {
            var num = 1
            for (j = 0; j < n; j++) {
                arr.push(num)
                num += 2
                var tempArr = arr
                var flag = geter(arr)
                if (!flag) {
                    while (!flag) {
                        tempArr = tempArr.filter((el,i) => i !== arr.length - 1)
                        num += 1
                        tempArr.push(num)
                        flag = geter(tempArr)
                    }
                    arr = tempArr
                }
            }
        }
        print(arr)
    }

}())

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  if (l === 1) {
    var num = Math.floor(Math.random() * (100 - 1) + 1);

    if (num % 2 !== 0) {
      num++;
    }

    print(num.toString().replace(/\,/g, ' '));
  } else {
    for (var j = 0; j < l; j++) {
      var num = Math.floor(Math.random() * (100 - 0) + 0);

      while (num % l !== 0) {
        num = Math.floor(Math.random() * (100 - 0) + 0);
      }

      res[j] = num;
    }

    print(res.toString().replace(/\,/g, ' '));
  }
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  if (l === 1) {
    var num = Math.floor(Math.random() * (100 - 1) + 1);

    if (num % 2 !== 0) {
      num++;
    }

    print(num.toString().replace(/\,/g, ' '));
  } else {
    for (var j = 0; j < l; j++) {
      var num = Math.floor(Math.random() * (100 - 1) + 1);

      while (num % l !== 0) {
        num = Math.floor(Math.random() * (100 - 1) + 1);
      }

      res[j] = num;
    }

    print(res.toString().replace(/\,/g, ' '));
  }
}

var t = +readline();

for (var i = 0; i < t; i++) {
  var l = +readline();
  var res = [];

  if (l === 1) {
    var num = Math.floor(Math.random() * (100 - 0) + 0);

    if (num % 2 !== 0) {
      num++;
    }

    print(num.toString().replace(/\,/g, ' '));
  } else {
    for (var j = 0; j < l; j++) {
      var num = Math.floor(Math.random() * (100 - 0) + 0);

      if (num % 2 === 0) {
        num++;
      }

      res[j] = num;
    }

    print(res.toString().replace(/\,/g, ' '));
  }
}


C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (expression is the main term):  expression ::= summand | expression + summand | expression - summand  summand ::= increment | coefficient*increment  increment ::= a++ | ++a  coefficient ::= 0|1|2|...|1000 For example, "5*a++-3*++a+a++" is a valid expression in C*++.Thus, we have a sum consisting of several summands divided by signs "+" or "-". Every summand is an expression "a++" or "++a" multiplied by some integer coefficient. If the coefficient is omitted, it is suggested being equal to 1.The calculation of such sum in C*++ goes the following way. First all the summands are calculated one after another, then they are summed by the usual arithmetic rules. If the summand contains "a++", then during the calculation first the value of the "a" variable is multiplied by the coefficient, then value of "a" is increased by 1. If the summand contains "++a", then the actions on it are performed in the reverse order: first "a" is increased by 1, then — multiplied by the coefficient.The summands may be calculated in any order, that's why sometimes the result of the calculation is completely unpredictable! Your task is to find its largest possible value.

The first input line contains an integer a ( - 1000 ≤ a ≤ 1000) — the initial value of the variable "a". The next line contains an expression in C*++ language of the described type. The number of the summands in the expression does not exceed 1000. It is guaranteed that the line describing the expression contains no spaces and tabulation.

Output a single number — the maximal possible value of the expression.

NoteConsider the second example. Initially a = 3. Suppose that at first the first summand is calculated, and then the second one is. The first summand gets equal to 3, and the value of a is increased by 1. At the calculation of the second summand a is increased once more (gets equal to 5). The value of the second summand is 5, and together they give 8. If we calculate the second summand first and the first summand later, then the both summands equals to 4, and the result is 8, too.

'use strict'

let a = +readline()
let lll = readline()
if (lll[0] != '-') lll = '+' + lll

let ss = {}
for (let i = -1000; i <= 1000; i++) {
  ss[i] = []
}

let i = 0
while (i < lll.length) {
  let z = 1
  let k = 1
  let b = true
  z = lll[i] == '+' ? z = 1 : -1
  i++
  let idp = lll.indexOf('++', i)
  let ia = lll.indexOf('*', i)
  k = ~ia && ia < idp ? +lll.slice(i, ia) : 1
  if (~ia && ia < idp) i = ia + 1
  b = lll[idp + 2] == 'a'
  ss[z * k].push(b)
  i += 3
}

let s = 0
for (let i = -1000; i <= 1000; i++) {
  let bef = 0
  let aft = 0
  ss[i].forEach(v => v ? bef++ : aft++)
  if (i < 0) {
    for (let j = 0; j < aft; j++) {
      s += i * a++
    }
    for (let j = 0; j < bef; j++) {
      s += i * ++a
    }
  } else {
    for (let j = 0; j < bef; j++) {
      s += i * ++a
    }
    for (let j = 0; j < aft; j++) {
      s += i * a++
    }
  }
}

print(s)


A sequence $$$a_1, a_2, \dots, a_n$$$ is called good if, for each element $$$a_i$$$, there exists an element $$$a_j$$$ ($$$i \ne j$$$) such that $$$a_i+a_j$$$ is a power of two (that is, $$$2^d$$$ for some non-negative integer $$$d$$$).For example, the following sequences are good:  $$$[5, 3, 11]$$$ (for example, for $$$a_1=5$$$ we can choose $$$a_2=3$$$. Note that their sum is a power of two. Similarly, such an element can be found for $$$a_2$$$ and $$$a_3$$$),  $$$[1, 1, 1, 1023]$$$,  $$$[7, 39, 89, 25, 89]$$$,  $$$[]$$$. Note that, by definition, an empty sequence (with a length of $$$0$$$) is good.For example, the following sequences are not good:  $$$[16]$$$ (for $$$a_1=16$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two),  $$$[4, 16]$$$ (for $$$a_1=4$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two),  $$$[1, 3, 2, 8, 8, 8]$$$ (for $$$a_3=2$$$, it is impossible to find another element $$$a_j$$$ such that their sum is a power of two). You are given a sequence $$$a_1, a_2, \dots, a_n$$$. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements.

The first line contains the integer $$$n$$$ ($$$1 \le n \le 120000$$$) — the length of the given sequence. The second line contains the sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all $$$n$$$ elements, make it empty, and thus get a good sequence.

NoteIn the first example, it is enough to delete one element $$$a_4=5$$$. The remaining elements form the sequence $$$[4, 7, 1, 4, 9]$$$, which is good.

function main() {
  const is = new Scanner();
  const LIMIT = parseInt(1e9, 10) + 1;
  const powerOfTwo = [1];
  while (powerOfTwo[powerOfTwo.length - 1] < LIMIT)
    powerOfTwo.push(2 * powerOfTwo[powerOfTwo.length - 1]);

  const n = is.nextInt();
  const sequence = is.nextArray();
  const tmpMap = {};
  let maxElement = 0;
  for (let i = 0; i < n; i++) { // conver numbers
    sequence[i] = parseInt(sequence[i], 10);
    maxElement = Math.max(maxElement, sequence[i]);
    if (!tmpMap.hasOwnProperty(sequence[i]))
      tmpMap[sequence[i]] = [];
    tmpMap[sequence[i]].push(i);
  }

  let answer = 0, canIUse;
  sequence.forEach((i) => {
    canIUse = false;
    for (let j = lowerBound(powerOfTwo, i + 1); powerOfTwo[j] <= i + maxElement && j < powerOfTwo.length; j += 1)
      if (tmpMap.hasOwnProperty(powerOfTwo[j] - i)) {
        canIUse = true;
        if (i === (powerOfTwo[j] - i) && tmpMap[i].length === 1)
          canIUse = false;
      }

    if (!canIUse)
      answer++;
    // console.log(i, canIUse);
  });

  console.log(answer);
}

function lowerBound(array, value) {
  let left = 0, middle;
  let right = array.length;
  while (left < right) {
    middle = parseInt((left + right) / 2);
    if (value <= array[middle])
      right = middle;
    else
      left = middle + 1;
  }

  return left; // not found
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const LIMIT = parseInt(1e9, 10) + 1;
  const powerOfTwo = [1];
  let last;
  while ((last = 2 * powerOfTwo[powerOfTwo.length - 1]) < LIMIT)
    powerOfTwo.push(last);

  const n = is.nextInt();
  const sequence = is.nextArray();
  const tmpMap = {};
  let maxElement = 0;
  for (let i = 0; i < n; i++) { // conver numbers
    sequence[i] = parseInt(sequence[i], 10);
    maxElement = Math.max(maxElement, sequence[i]);
    if (!tmpMap.hasOwnProperty(sequence[i]))
      tmpMap[sequence[i]] = [];
    tmpMap[sequence[i]].push(i);
  }

  let answer = 0, canIUse;
  sequence.forEach((i) => {
    canIUse = false;
    for (let j = lowerBound(powerOfTwo, i + 1); powerOfTwo[j] <= i + maxElement; j += 1)
      if (tmpMap.hasOwnProperty(powerOfTwo[j] - i)) {
        canIUse = true;
        if (i === (powerOfTwo[j] - i) && tmpMap[i].length === 1)
          canIUse = false;
      }

    if (!canIUse)
      answer++;
    // console.log(i, canIUse);
  });

  console.log(answer);
}

function lowerBound(array, value) {
  let left = 0, middle;
  let right = array.length;
  while (left < right) {
    middle = parseInt((left + right) / 2);
    if (value <= array[middle])
      right = middle;
    else
      left = middle + 1;
  }

  return left; // not found
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const LIMIT = parseInt(1e9, 10) + 1;
  const powerOfTwo = [1];
  let last;
  while ((last = 2 * powerOfTwo[powerOfTwo.length - 1]) < LIMIT)
    powerOfTwo.push(last);

  const n = is.nextInt();
  const sequence = is.nextArray();
  const tmpMap = {};
  let maxElement = 0;
  for (let i = 0; i < n; i++) { // conver numbers
    sequence[i] = parseInt(sequence[i], 10);
    maxElement = Math.max(maxElement, sequence[i]);
    if (!tmpMap.hasOwnProperty(sequence[i]))
      tmpMap[sequence[i]] = [];
    tmpMap[sequence[i]].push(i);
  }

  let answer = 0, canIUse;
  sequence.forEach((i) => {
    canIUse = false;
    for (let j = lowerBound(powerOfTwo, i + 1); powerOfTwo[j] <= i + maxElement; j += 1)
      if (tmpMap.hasOwnProperty(powerOfTwo[j] - i)) {
        canIUse = true;
        if (i === (powerOfTwo[j] - i) && tmpMap[i].length === 1)
          canIUse = false;
      }

    if (!canIUse)
      answer++;
    console.log(i, canIUse);
  });

  console.log(answer);
}

function lowerBound(array, value) {
  let left = 0, middle;
  let right = array.length;
  while (left < right) {
    middle = parseInt((left + right) / 2);
    if (value <= array[middle])
      right = middle;
    else
      left = middle + 1;
  }

  return left; // not found
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });


On a chessboard with a width of $$$10^9$$$ and a height of $$$10^9$$$, the rows are numbered from bottom to top from $$$1$$$ to $$$10^9$$$, and the columns are numbered from left to right from $$$1$$$ to $$$10^9$$$. Therefore, for each cell of the chessboard you can assign the coordinates $$$(x,y)$$$, where $$$x$$$ is the column number and $$$y$$$ is the row number.Every day there are fights between black and white pieces on this board. Today, the black ones won, but at what price? Only the rook survived, and it was driven into the lower left corner — a cell with coordinates $$$(1,1)$$$. But it is still happy, because the victory has been won and it's time to celebrate it! In order to do this, the rook needs to go home, namely — on the upper side of the field (that is, in any cell that is in the row with number $$$10^9$$$).Everything would have been fine, but the treacherous white figures put spells on some places of the field before the end of the game. There are two types of spells:   Vertical. Each of these is defined by one number $$$x$$$. Such spells create an infinite blocking line between the columns $$$x$$$ and $$$x+1$$$.  Horizontal. Each of these is defined by three numbers $$$x_1$$$, $$$x_2$$$, $$$y$$$. Such spells create a blocking segment that passes through the top side of the cells, which are in the row $$$y$$$ and in columns from $$$x_1$$$ to $$$x_2$$$ inclusive. The peculiarity of these spells is that it is impossible for a certain pair of such spells to have a common point. Note that horizontal spells can have common points with vertical spells.    An example of a chessboard. Let's recall that the rook is a chess piece that in one move can move to any point that is in the same row or column with its initial position. In our task, the rook can move from the cell $$$(r_0,c_0)$$$ into the cell $$$(r_1,c_1)$$$ only under the condition that $$$r_1 = r_0$$$ or $$$c_1 = c_0$$$ and there is no blocking lines or blocking segments between these cells (For better understanding, look at the samples).Fortunately, the rook can remove spells, but for this it has to put tremendous efforts, therefore, it wants to remove the minimum possible number of spells in such way, that after this it can return home. Find this number!

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n,m \le 10^5$$$) — the number of vertical and horizontal spells. Each of the following $$$n$$$ lines contains one integer $$$x$$$ ($$$1 \le x < 10^9$$$) — the description of the vertical spell. It will create a blocking line between the columns of $$$x$$$ and $$$x+1$$$. Each of the following $$$m$$$ lines contains three integers $$$x_1$$$, $$$x_2$$$ and $$$y$$$ ($$$1 \le x_{1} \le x_{2} \le 10^9$$$, $$$1 \le y < 10^9$$$) — the numbers that describe the horizontal spell. It will create a blocking segment that passes through the top sides of the cells that are in the row with the number $$$y$$$, in columns from $$$x_1$$$ to $$$x_2$$$ inclusive. It is guaranteed that all spells are different, as well as the fact that for each pair of horizontal spells it is true that the segments that describe them do not have common points.

In a single line print one integer — the minimum number of spells the rook needs to remove so it can get from the cell $$$(1,1)$$$ to at least one cell in the row with the number $$$10^9$$$

NoteIn the first sample, in order for the rook return home, it is enough to remove the second horizontal spell.  Illustration for the first sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the second horizontal spell. It also shows the path, on which the rook would be going home. In the second sample, in order for the rook to return home, it is enough to remove the only vertical spell. If we tried to remove just one of the horizontal spells, it would not allow the rook to get home, because it would be blocked from above by one of the remaining horizontal spells (either first one or second one), and to the right it would be blocked by a vertical spell.  Illustration for the second sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletion of the vertical spell. It also shows the path, on which the rook would be going home. In the third sample, we have two horizontal spells that go through the whole field. These spells can not be bypassed, so we need to remove both of them.  Illustration for the third sample. On the left it shows how the field looked at the beginning. On the right it shows how the field looked after the deletion of the horizontal spells. It also shows the path, on which the rook would be going home. In the fourth sample, we have no spells, which means that we do not need to remove anything.In the fifth example, we can remove the first vertical and third horizontal spells.  Illustration for the fifth sample. On the left it shows how the field looked at the beginning. On the right it shows how it looked after the deletions. It also shows the path, on which the rook would be going home.

var n = Math.pow(10, 9);

var fl = readline().split(' ').map(v=>+v);
var v = fl[0]; var h = fl[1];

var vert = [];
for(var i = 0; i < v; i++) {
    vert.push(+readline());
}
vert.push(n);
vert.sort((a, b) => a - b);

var hor = [];
for(var i = 0; i < h; i++) {
    var line = readline();
    if(line[0] !== '1' || line[1] !== ' ') continue;

    line = line.substr(2).split(' ');

    hor.push({x: +line[0], y: +line[1]});
}

hor.sort((a, b) => a.x - b.x);

var min, pos = 0;
for(i = 0; i < vert.length; i++) {

    if(min !== undefined && i >= min) break;
    while (pos < hor.length && hor[pos].x < vert[i]) {
        pos += 1;
    }

    var hLines = i + hor.length - pos;
    if(!min || hLines < min) min = hLines;
}

print(min || 0);


Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all n prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question?

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.

Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.

NoteConsider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.There could be other possibilities, but this minimizes the time needed for all prices to become equal. Thus the answer is 3.In the second example we can notice that parity of first and second price is different and never changes within described process. Thus prices never can become equal.In the third example following scenario can take place: firstly, the second price drops, then the third price, and then fourth price. It happens 999999999 times, and, since in one second only one price can drop, the whole process takes 999999999 * 3 = 2999999997 seconds. We can note that this is the minimum possible time.

  var tmp = readline().split(' ').map(x => parseInt(x));
  var n = tmp[0];
  var k = tmp[1];
  var a = readline().split(' ').map(x => parseInt(x));
  var min = a.reduce((a, b) => Math.min(a, b));
  var res = 0;
  var flag = true;
  a.forEach((x) => {
    if((x - min) % k === 0) {
      res += (x - min) / k;
    } else {
      flag = false;
    }
  });
  if(flag) {
    print(res);
  } else {
    print(-1);
  }


One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".

Print a single integer — the maximum possible size of beautiful string Nikita can get.

NoteIt the first sample the string is already beautiful.In the second sample he needs to delete one of "b" to make it beautiful.

s=' '+readline()

as=[0]
bs=[0]

for (i=1;i<s.length;i++)
{
    as.push(as[i-1])
    bs.push(bs[i-1])
    if (s[i]=='a')
    {
        as[i]++
    }
    else
    {
        bs[i]++
    }
}
res=0
if (bs[s.length-1]==0)
{
    res=s.length-1
}
for (i=1;i<s.length;i++)
{
    if (s[i]=='a')
        continue
    for (j=i;j<s.length;j++)
    {
        if (s[j]=='a')
            continue
        x=as[i-1]+as[s.length-1]-as[j]+bs[j]-bs[i-1]
        if (x>res)
            res=x
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if(z[0]=='b')
{
    s.shift()
}
if (1)
{
    n=s.length
    s.push(0)
    s.push(0)
    s.push(0)
    for (i=0;i<n;i+=2)
    {
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if(z[0]=='b')
{
    s.unshift(0)
}
if (1)
{
    n=s.length
    s.push(0)
    s.push(0)
    s.push(0)
    for (i=0;i<n;i+=2)
    {
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)

s=readline()
for (i=0;i<=0;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=0;i++)
{
    s=s.replace(/ab/gi,"a b")
}
s=s.split(" ")
if (s[0][0]=='b')
{
    s.unshift("");
}
res=0
if (1)
{
    n=s.length
    s.push("")
    s.push("")
    s.push("")
    for (i=0;i<n;i++)
    {
        if (s[i][0]=="b")
        {
            continue
        }
        if (s[i].length+s[i+1].length+s[i+2].length>res)
        {
            res=s[i].length+s[i+1].length+s[i+2].length
        }
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if(z[0]=='b')
{
    s.shift()
}
if (s.length==1)
{
    res=s[0]
}
if (s.length==2)
{
    res=s[0]+s[1]
}
if (s.length>2)
{
    var b=0
    n=s.length
    s.push(0)
    s.push(0)
    s.push(0)
    for (i=0;i<n;i+=2)
    {
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if (s.length==1)
{
    res=s[0]
}
if (s.length==2)
{
    res=s[0]+s[1]
}
if (s.length>2)
{
    var b=0
    if (z[0]=='b')
    {
        s.unshift(0)
    }
    s.push(0)
    s.push(0)
    s.push(0)
    for (i=b;i<s.length;i+=2)
    {
        if (i+1>=s.length)
        {
            break;
        }
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if(z[0]=='b')
{
    s.shift()
}
if (s.length==1)
{
    res=s[0]
}
if (s.length==2)
{
    res=s[0]+s[1]
}
if (s.length>2)
{
    var b=0
    if (z[0]=='b')
    {
        b=1
    }
    s.push(0)
    for (i=b;i<s.length;i++)
    {
        if (i+1>=s.length)
        {
            break;
        }
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if (s.length==1)
{
    res=s[0]
}
if (s.length==2)
{
    res=s[0]+s[1]
}
if (s.length>2)
{
    var b=0
    if (z[0]=='b')
    {
        s.unshift(0)
    }
    s.push(0)
    s.push(0)
    s.push(0)
    for (i=b;i<s.length;i++)
    {
        if (i+1>=s.length)
        {
            break;
        }
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)

s=readline()
for (i=0;i<=1;i++)
{
    s=s.replace(/ba/gi,"b a")
}

for (i=0;i<=1;i++)
{
    s=s.replace(/ab/gi,"a b")
}
z=s;
s=s.split(' ').map(function(x){return x.length})
res=0
if (s.length==1)
{
    res=s[0]
}
if (s.length==2)
{
    res=s[0]+s[1]
}
if (s.length>2)
{
    var b=0
    if (z[0]=='b')
    {
        b=1
    }
    s.push(0)
    for (i=b;i<s.length;i++)
    {
        if (i+1>=s.length)
        {
            break;
        }
        if (s[i]+s[i+1]+s[i+2]>res)
        {
            res=s[i]+s[i+1]+s[i+2]
        }
    }
}
print(res)


You invited $$$n$$$ guests to dinner! You plan to arrange one or more circles of chairs. Each chair is going to be either occupied by one guest, or be empty. You can make any number of circles. Your guests happen to be a little bit shy, so the $$$i$$$-th guest wants to have a least $$$l_i$$$ free chairs to the left of his chair, and at least $$$r_i$$$ free chairs to the right. The "left" and "right" directions are chosen assuming all guests are going to be seated towards the center of the circle. Note that when a guest is the only one in his circle, the $$$l_i$$$ chairs to his left and $$$r_i$$$ chairs to his right may overlap.What is smallest total number of chairs you have to use?

First line contains one integer $$$n$$$  — number of guests, ($$$1 \leqslant n \leqslant 10^5$$$).  Next $$$n$$$ lines contain $$$n$$$ pairs of space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \leqslant l_i, r_i \leqslant 10^9$$$).

Output a single integer — the smallest number of chairs you have to use.

NoteIn the second sample the only optimal answer is to use two circles: a circle with $$$5$$$ chairs accomodating guests $$$1$$$ and $$$2$$$, and another one with $$$10$$$ chairs accomodationg guests $$$3$$$ and $$$4$$$.In the third sample, you have only one circle with one person. The guest should have at least five free chairs to his left, and at least six free chairs to his right to the next person, which is in this case the guest herself. So, overall number of chairs should be at least 6+1=7.

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

let input = "";
process.stdin.on("data", data => input += data);
process.stdin.on("end", () => {
	const nonDecrease = (a, b) => a - b;
	const [n, ...rest] = input.trim().split("\n");
	const [left, right] = [rest
		.map(line => line.split(" ").map(Number))]
		.map(x => [
			x.map(x => x[0]).sort(nonDecrease),
			x.map(x => x[1]).sort(nonDecrease)
		])[0];
	console.log(left.map((v, i) => Math.max(v, right[i])).reduce((a, b) => a + b) + Number(n));
});

n = +readline();
left = []
right = [];
for (i = 0;i<n;i++){
    num = readline().split(' ').map(Number);
    left.push(num[0]);
    right.push(num[1]);
}
left = left.sort((a,b)=>a-b);
right = right.sort((a,b)=>a-b);
ans = 0;
for (i = 0;i<n;i++){
    ans += Math.max(left[i],right[i]);
}
print(ans+n);


A tree is a connected undirected graph without cycles. Note that in this problem, we are talking about not rooted trees.You are given four positive integers $$$n, d_{12}, d_{23}$$$ and $$$d_{31}$$$. Construct a tree such that:  it contains $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$,  the distance (length of the shortest path) from vertex $$$1$$$ to vertex $$$2$$$ is $$$d_{12}$$$,  distance from vertex $$$2$$$ to vertex $$$3$$$ is $$$d_{23}$$$,  the distance from vertex $$$3$$$ to vertex $$$1$$$ is $$$d_{31}$$$. Output any tree that satisfies all the requirements above, or determine that no such tree exists.

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases in the test. This is followed by $$$t$$$ test cases, each written on a separate line. Each test case consists of four positive integers $$$n, d_{12}, d_{23}$$$ and $$$d_{31}$$$ ($$$3 \le n \le 2\cdot10^5; 1 \le d_{12}, d_{23}, d_{31} \le n-1$$$). It is guaranteed that the sum of $$$n$$$ values for all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, print YES if the suitable tree exists, and NO otherwise.  If the answer is positive, print another $$$n-1$$$ line each containing a description of an edge of the tree — a pair of positive integers $$$x_i, y_i$$$, which means that the $$$i$$$th edge connects vertices $$$x_i$$$ and $$$y_i$$$.  The edges and vertices of the edges can be printed in any order. If there are several suitable trees, output any of them.

var n;
    var a;

    function logNodes(x, y) {
        print(x + ' ' + y);
    }

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var nd = readline().split(' ').map(x=>parseInt(x));
        n = nd[0];
        a = [];
        a.push([nd[1], 1, 2]);
        a.push([nd[2], 2, 3]);
        a.push([nd[3], 1, 3]);
        a.sort((b, c) => c[0] - b[0]);

        var x, y ,z;
        x = a[0][0];
        y = a[1][0];
        z = a[2][0];
        var br = (y+z) - x;
        if (br & 1 || br < 0) {
            print('NO');
            continue;
        }
        br = br / 2;
        if (n < a[0][0] + 1 + br) {
            print('NO');
            continue;
        }
        print('YES');
        if (a[1][1] == a[0][2] || a[1][2] == a[0][2]) {
            var temp = a[0][1];
            a[0][1] = a[0][2];
            a[0][2] = temp;
        }
        var nodes = [1, 2, 3];
        var brNode = nodes.filter(x => x != a[0][1] && x != a[0][2])[0];

        var brStart = brNode;
        var reserve = 4;
        for (var i = 0; i < br; i++) {
            logNodes(reserve, brStart);
            brStart = reserve;
            reserve++;
        }
        var lineNode = a[0][1];
        for (var i = 0; i < (y - br - 1); i++) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
        logNodes(lineNode, brStart);
        lineNode = brStart;
        for (var i = 0; i < (z - br - 1); i++) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
        logNodes(lineNode, a[0][2]);
        lineNode = a[0][2];
        while( reserve <= n ) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
    }

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 arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(arr) {
    const n = arr.shift()
    const pair = ['12', '23', '31']
    const sorted = arr.map((x, i) => [x, pair[i]])
        .sort((a, b) => a[0] - b[0])
    const [a, b, c] = sorted.map(x => x[0])
    const [sa, sb, sc] = sorted.map(x => x[1])
    const va = getv(sa, sb)
    const vb = getv(sa, sc)
    const vc = getv(sb, sc)
// console.log(sa, sb, sc)
// return
    if (c > a + b || (a + b - c) & 1) return 'NO'
    const share = (a + b - c) / 2
// console.log('share', share)
    const edges = []
    let now = 3
    let lca = fill(va, share)
    if (share === a) {
        fixLast(va)
        lca = va
    }
    fill(lca, a - share)
    fixLast(vb)
    fill(lca, b - share)
    fixLast(vc)
    if (now <= n) {
        fill(va, n - now)
    } else {
        return 'NO'
    }
    function fill(u, d) {
        while (d--) {
            const v = ++now
            edges.push([u, v])
            u = v
        }
        return u
    }
    function fixLast(u) {
        edges[edges.length - 1][1] = u
        now--
    }
    return 'YES\n' + edges.map(x => x.join(' ')).join('\n')
}
function getv(sa, sb) {
    for (let x of [1,2,3]) {
        if (sa.indexOf(x) >= 0 && sb.indexOf(x) >= 0) return x
    }
}

var n;
    var a;

    function logNodes(x, y) {
        print(x + ' ' + y);
    }

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var nd = readline().split(' ').map(x=>parseInt(x));
        n = nd[0];
        a = [];
        a.push([nd[1], 1, 2]);
        a.push([nd[2], 2, 3]);
        a.push([nd[3], 1, 3]);
        a.sort((b, c) => c[0] - b[0]);

        var x, y ,z;
        x = a[0][0];
        y = a[1][0];
        z = a[2][0];
        var br = (y+z) - x;
        if (br & 1 || br < 0) {
            print('NO');
            continue;
        }
        br = br / 2;
        if (n < a[0][0] + 1 + br) {
            print('NO');
            continue;
        }
        print('YES');
        if (a[1][1] == a[0][2] || a[1][2] == a[0][2]) {
            var temp = a[0][1];
            a[0][1] = a[0][2];
            a[0][2] = temp;
        }
        var nodes = [1, 2, 3];
        var brNode = nodes.filter(x => x != a[0][1] && x != a[0][2])[0];

        var brStart = brNode;
        var reserve = 4;
        for (var i = 0; i < br; i++) {
            logNodes(reserve, brNode);
            brStart = reserve;
            reserve++;
        }
        var lineNode = a[0][1];
        for (var i = 0; i < (y - br - 1); i++) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
        logNodes(lineNode, brStart);
        lineNode = brStart;
        for (var i = 0; i < (z - br - 1); i++) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
        logNodes(lineNode, a[0][2]);
        lineNode = a[0][2];
        while( reserve <= n ) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
    }

var n;
    var a;

    function logNodes(x, y) {
        print(x + ' ' + y);
    }

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var nd = readline().split(' ').map(x=>parseInt(x));
        n = nd[0];
        a = [];
        a.push([nd[1], 1, 2]);
        a.push([nd[2], 2, 3]);
        a.push([nd[3], 1, 3]);
        a.sort((b, c) => c[0] - b[0]);

        var x, y ,z;
        x = a[0][0];
        y = a[1][0];
        z = a[2][0];
        var br = (y+z) - x;
        if (br & 1 || br < 0) {
            print('NO');
            continue;
        }
        br = br / 2;
        if (n - 2 < (a - 1) + br) {
            print('NO');
            continue;
        }
        print('YES');
        if (a[1][1] == a[0][2] || a[1][2] == a[0][2]) {
            var temp = a[0][1];
            a[0][1] = a[0][2];
            a[0][2] = temp;
        }
        var nodes = [1, 2, 3];
        var brNode = nodes.filter(x => x != a[0][1] && x != a[0][2])[0];

        var brStart = brNode;
        var reserve = 4;
        for (var i = 0; i < br; i++) {
            logNodes(reserve, brNode);
            brStart = reserve;
            reserve++;
        }
        var lineNode = a[0][1];
        for (var i = 0; i < (y - br - 1); i++) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
        logNodes(lineNode, brStart);
        lineNode = brStart;
        for (var i = 0; i < (z - br - 1); i++) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
        logNodes(lineNode, a[0][2]);
        lineNode = a[0][2];
        while( reserve <= n ) {
            logNodes(lineNode, reserve);
            lineNode = reserve;
            reserve++;
        }
    }

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 arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(arr) {
    const n = arr.shift()
    const pair = ['12', '23', '31']
    const sorted = arr.map((x, i) => [x, pair[i]])
        .sort((a, b) => a[0] - b[0])
    const [a, b, c] = sorted.map(x => x[0])
    const [sa, sb, sc] = sorted.map(x => x[1])
    const va = getv(sa, sb)
    const vb = getv(sa, sc)
    const vc = getv(sb, sc)
// console.log(sa, sb, sc)
// return
    if (c > a + b || (a + b - c) & 1) return 'NO'
    const share = (a + b - c) / 2
// console.log('share', share)
    const edges = []
    let now = 3
    let lca = fill(va, share)
    if (share === a) {
        fixLast(va)
        lca = va
    }
    fill(lca, a - share)
    fixLast(vb)
    fill(lca, b - share)
    fixLast(vc)
    if (now < n) {
        fill(va, n - now)
    }
    function fill(u, d) {
        while (d--) {
            const v = ++now
            edges.push([u, v])
            u = v
        }
        return u
    }
    function fixLast(u) {
        edges[edges.length - 1][1] = u
        now--
    }
    return 'YES\n' + edges.map(x => x.join(' ')).join('\n')
}
function getv(sa, sb) {
    for (let x of [1,2,3]) {
        if (sa.indexOf(x) >= 0 && sb.indexOf(x) >= 0) return x
    }
}


«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test.You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests.

The first line contains one integer n (1 ≤ n ≤ 3000) — the amount of previously added tests. The second line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ 3000) — indexes of these tests.

Output the required default value for the next test index.

const readline = require('readline');

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

var N = -1;

rl.on('line', function (input) {

    if (N == -1) {
        N = parseInt(input);
    }
    else {
        var tests = [];
        tests = input.split(' ').map(item => { return parseInt(item); });
        tests.sort(sortNumber);
        /*console.log("*************");
        tests.forEach(element => {
            rl.write(element + ", ");
        });
        console.log("************");
        */
        var i = 0;
        for (i = 0; i < N; i++)
            if (i + 1 != tests[i]) break;

        console.log(i + 1);
        rl.close();
    }
}
)

function sortNumber(a, b) {
    return a - b;
  }

const readline = require('readline');

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

var N = -1;

rl.on('line', function (input) {

    if (N == -1) {
        N = parseInt(input);
    }
    else {
        var tests = [];
        tests = input.split(' ').map(item => { return parseInt(item); });
        //tests.sort(sortNumber);
        tests.sort((a,b)=>{return a-b;});
        /*console.log("*************");
        tests.forEach(element => {
            rl.write(element + ", ");
        });
        console.log("************");
        */
        var i = 0;
        for (i = 0; i < N; i++)
            if (i + 1 != tests[i]) break;

        console.log(i + 1);
        rl.close();
    }
}
)
/*
function sortNumber(a, b) {
    return a - b;
  }*/

function checkValue(value) {
  return value != 1;
}
function getNextIdx (n, restArgs) {
    var arr = [];
    arr[3000] = 0;
    var i;
    for (i=0;i<n;i++) {
        arr[restArgs[i]-1] = 1;
    }
    return (arr.findIndex(checkValue) +1);
}
var n = readline();
print(getNextIdx(n, readline().split(" ")));

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 n = parseInt(readline());
	var previous = tokenizeIntegers(readline());
	var seen = new Array(3001);
	for (var i = 0; i < n; ++i) {
		seen[previous[i]] = true;
	}
	for (i = 1; seen[i]; ++i) {
	}
	print(i);
}

main();

'use strict'

const N = readline()
let lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)
if (lll[0] != 1) {
  print(1)
} else {
  for (var i = 1; i < lll.length; i++) {
    if (lll[i] - lll[i - 1] != 1) break
  }
  print(i + 1)
}

const readline = require('readline');

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

var N = -1;

rl.on('line', function (input) {

    if (N == -1) {
        N = parseInt(input);
    }
    else {
        var tests = [];
        tests = input.split(' ').map(item => { return parseInt(item); });
        tests.sort();
        var i = 0;
        for (i = 0; i < N; i++)
            if (i + 1 != tests[i]) break;

        console.log(i + 1);
        rl.close();
    }
}
)

function checkValue(value) {
  return value != 1;
}
function getNextIdx (n, restArgs) {
    var arr = [];
    var i;
    for (i=0;i<n;i++) {
        arr[restArgs[i]-1] = 1;
    }
    return (arr.findIndex(checkValue) +1);
}
var n = readline();
print(getNextIdx(n, readline().split(" ")));

function checkValue(value) {
  return value != 1;
}
function getNextIdx (n, restArgs) {
    var arr = [];
    var i;
    for (i=0;i<n;i++) {
        arr[restArgs[i]-1] = 1;
    }
    print(arr);
    return (arr.findIndex(checkValue) +1);
}
var n = readline();
print(getNextIdx(n, readline().split(" ")));

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 n = parseInt(readline());
	var previous = tokenizeIntegers(readline());
	var seen = new Array(3001);
	for (var i = 0; i < n; ++i) {
		seen[i] = true;
	}
	for (i = 1; seen[i]; ++i) {
	}
	print(i);
}

main();

'use strict'

const N = readline()
let lll = readline().split(' ').map(v => parseInt(v)).sort((a, b) => a - b)
for (var i = 1; i < lll.length; i++) {
  if (lll[i] - lll[i - 1] != 1) break
}
print(i + 1)


You have a board represented as a grid with $$$2 \times n$$$ cells.The first $$$k_1$$$ cells on the first row and first $$$k_2$$$ cells on the second row are colored in white. All other cells are colored in black.You have $$$w$$$ white dominoes ($$$2 \times 1$$$ tiles, both cells are colored in white) and $$$b$$$ black dominoes ($$$2 \times 1$$$ tiles, both cells are colored in black).You can place a white domino on the board if both board's cells are white and not occupied by any other domino. In the same way, you can place a black domino if both cells are black and not occupied by any other domino.Can you place all $$$w + b$$$ dominoes on the board if you can place dominoes both horizontally and vertically?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 3000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$k_1$$$ and $$$k_2$$$ ($$$1 \le n \le 1000$$$; $$$0 \le k_1, k_2 \le n$$$). The second line of each test case contains two integers $$$w$$$ and $$$b$$$ ($$$0 \le w, b \le n$$$).

For each test case, print YES if it's possible to place all $$$w + b$$$ dominoes on the board and NO, otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as positive answer).

NoteIn the first test case, $$$n = 1$$$, $$$k_1 = 0$$$ and $$$k_2 = 1$$$. It means that $$$2 \times 1$$$ board has black cell $$$(1, 1)$$$ and white cell $$$(2, 1)$$$. So, you can't place any white domino, since there is only one white cell.In the second test case, the board of the same size $$$2 \times 1$$$, but both cell are white. Since $$$w = 0$$$ and $$$b = 0$$$, so you can place $$$0 + 0 = 0$$$ dominoes on the board.In the third test case, board $$$2 \times 3$$$, but fully colored in black (since $$$k_1 = k_2 = 0$$$), so you can't place any white domino.In the fourth test case, cells $$$(1, 1)$$$, $$$(1, 2)$$$, $$$(1, 3)$$$, and $$$(2, 1)$$$ are white and other cells are black. You can place $$$2$$$ white dominoes at positions $$$((1, 1), (2, 1))$$$ and $$$((1, 2), (1, 3))$$$ and $$$2$$$ black dominoes at positions $$$((1, 4), (2, 4))$$$ $$$((2, 2), (2, 3))$$$.

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split(" ").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    const [n, k1, k2] = numArray(rl());
    const [w, b] = numArray(rl());
    solution(n, k1, k2, w, b);
  }
  /************************Solution****************************************/
  function solution(n, k1, k2, w, b) {
    // cl(n, k1, k2, w, b);
    const whiteArea = k1 + k2;
    const blackArea = 2 * n - whiteArea;

    // console.log("solution", w, whiteArea, b, blackArea);
    if (w * 2 <= whiteArea && b * 2 <= blackArea) {
      cl("yes");
    } else {
      cl("no");
    }
  }
}

var a = function(a, b, c){
    if(a < b){
    var temp = a;
        a = b;
        b = temp;
    }
    a -= b;
    var a2 = a / 2;
    var b2 = c - b;
    if(a2 >= b2){
        return true;
    }else{
        return false;
    }
};
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 e = 0;
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j].split(' ').map(Number);
        }else{
            var k = lines[j].split(' ').map(Number);
            var N = e[0];
            var k1 = e[1];
            var k2 = e[2];
            var w = k[0];
            var b = k[1];
            b1 = N - k1;
            b2 = N - k2;
            if(a(k1, k2, w) === true && a(b1, b2, b) === true){
                console.log('YES');
            }else{
                console.log('NO');
            }
        }
    }
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var w1 = nextInt();
		var w2 = nextInt();
		var b1 = N - w1;
		var b2 = N - w2;
		var w = nextInt();
		var b = nextInt();
		if(w1 % 2 != w2 % 2){
			if(w1 > w2){
				w1--;
			}else{
				w2--;
			}
		}
		if(b1 % 2 != b2 % 2){
			if(b1 > b2){
				b1--;
			}else{
				b2--;
			}
		}
		var L = w1 + w2;
		var R = b1 + b2;
		if(L < w * 2 || R < b * 2){
			myout("NO");
		}else{
			myout("YES");
		}
	}
}

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

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

let count = -1
let inputArr = []

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

function solve([n, k1, k2], [w, b]) {
    const wArea = k1 + k2, bArea = (2 * n) - (k1 + k2)
    let res = false
    if (k1 % 2 === k2 % 2) {
        if (wArea >= w * 2 && bArea >= b * 2) res = true
    } else {
        if (wArea - 1 >= w * 2 && bArea - 1 >= b * 2) res = true
    }
    res ? console.log('YES') : console.log('NO')
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])
}

'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++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 10e6 + 1

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

  Array(parseInt(x)).fill(1).map((t, iii) => {
    // var n = parseInt(readline())
    var [n, k1, k2] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var [w, b] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });

    // if ((k1 + k2) % 2 !== 0) return console.log('NO')
// console.log(w * 2 <= (k1 + k2), b * 2 <= (n - k1 + n - k2))
    if ((w * 2 <= (k1 + k2) )&& (b * 2 <= (n - k1 + n - k2))) return console.log('YES')
    console.log('NO')
    // var a = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });

  });
}

function getInt(num){
    return parseInt(num, 10)
}

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

for(var i = 0; i<t; i++){
    var line1 = readline().split(' ').map(getInt);
    var line2 = readline().split(' ').map(getInt);
    print(solution(line1[0], line1[1], line1[2], line2[0], line2[1]));
}
function solution(n, k1, k2, w, b){
    if(w + b > n){
        return 'NO';
    }
    if(k1 < k2){
        var temp;
        temp = k1;
        k1=k2;
        k2 =temp;
    }
    var ws = k2;
    var bs = n-k1;

    if(ws >= w && bs>=b){
        return 'YES';
    }
    b = Math.max(b - bs, 0);
    w = Math.max(w - ws, 0);

    n = n - bs - ws;
    var rest = Math.floor(n/2);
    if(b <= rest && w<=rest){
        return 'YES'
    }
    return 'NO';

}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let currentLine = 0;
function readLine() {
  return standardInputString[currentLine++];
}
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  const numArray = (a) => a.split("").map((line) => +line),
    cl = console.log,
    rl = readLine,
    tc = rl();

  for (let i = 0; i < tc; i++) {
    const [n, k1, k2] = numArray(rl());
    const [w, b] = numArray(rl());
    solution(n, k1, k2, w, b);
  }
  /************************Solution****************************************/
  function solution(n, k1, k2, w, b) {
    const whiteArea = k1 + k2;
    const blackArea = 2 * n - whiteArea;

    // console.log("solution", w, whiteArea, b, blackArea);
    if (w <= whiteArea && b <= blackArea) {
      cl("yes");
    } else {
      cl("no");
    }
  }
}


Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by $$$1$$$. If he manages to finish the level successfully then the number of clears increases by $$$1$$$ as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.So he peeked at the stats $$$n$$$ times and wrote down $$$n$$$ pairs of integers — $$$(p_1, c_1), (p_2, c_2), \dots, (p_n, c_n)$$$, where $$$p_i$$$ is the number of plays at the $$$i$$$-th moment of time and $$$c_i$$$ is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.Help him to check the correctness of his records.For your convenience you have to answer multiple independent test cases.

The first line contains a single integer $$$T$$$ $$$(1 \le T \le 500)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of moments of time Polycarp peeked at the stats. Each of the next $$$n$$$ lines contains two integers $$$p_i$$$ and $$$c_i$$$ ($$$0 \le p_i, c_i \le 1000$$$) — the number of plays and the number of clears of the level at the $$$i$$$-th moment of time. Note that the stats are given in chronological order.

For each test case print a single line. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.The second test case is a nice example of a Super Expert level.In the third test case the number of plays decreased, which is impossible.The fourth test case is probably an auto level with a single jump over the spike.In the fifth test case the number of clears decreased, which is also impossible.Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it.

// Q: https://codeforces.com/contest/1339/problem/B

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	let sum = 0;
	for (let t=0; t < test; t++) {
		let ans = true;
		let n = parseInt(input[sum+t+1]);
		let arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));
		let arr2 = [];
		if (n == 1) {
			if ((arr1[0] < arr1[1])) {
				ans = false;
			}
		} else {
			for (let i = 1; i < n; i++) {
				arr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));
				if ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1]) || (arr2[0] - arr1[0] < arr2[1] - arr1[1])) {
					ans = false;
					break;
				}
				if (arr1[0] === arr2[0] && arr2[1] > arr1[1]) {
					ans = false;
					break;
				}
				arr1 = [...arr2];
			}
		}

		console.log(ans ? 'YES' : 'NO');
		sum += n;
	}
});

let i = '';
let lines;
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
  const { EOL } = require('os');
  lines = i.split(EOL); /*your input text, split by lines*/
  main();
});

function solve(n, a) {
  if (a[0][0] < a[0][1]) return 'NO';
  for(let i = 1; i < n; ++i) {
    const x = a[i][0] - a[i - 1][0];
    const y = a[i][1] - a[i - 1][1];
    if (x < 0 || y < 0) return 'NO';
    if (x < y) return 'NO';
  }
  return 'YES';
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const test = readLine()[0];
  for (let t = 1; t <= test; ++t) {
    const n = readLine()[0];
    let a = [];
    for(let i = 0; i < n; ++i) a.push(readLine());
    console.log(solve(n, a));
  }
}

'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const cases = readline();
    var i, j;
    for (i = 0; i < cases; i++) {
        const n = readline();
        var terminate = false;
        var lastX = 0;
        var lastY = 0;
        for (j = 0; j < n; j++) {
            const line = readline();
// console.log('x' +line+'\n');
            var x = parseInt(line.split(" ")[0]);
            var y = parseInt(line.split(" ")[1]);
// console.log("* "+x+" "+y+" "+((!terminate) && ((y > x) || ((y-lastY) > (x-lastX))))+"\n");
            if((!terminate) && ((x < lastX) || (y < lastY) || (y > x) || ((y-lastY) > (x-lastX)))) {
                process.stdout.write("NO\n");
                terminate = true;
            }

            lastX = x;
            lastY = y;
        }

        !terminate && process.stdout.write("YES\n");
    }
}

t = +readline();
out = '';
while (t-->0){
    n = +readline();
    attemps = 0;
    clears = 0;
    possible = true;
    while (n-->0){
        p = readline().split(' ').map(Number);
        if (!possible){
            continue;
        }
        if (p[0] < attemps || p[1] < clears || p[0] - attemps < p[1] - clears){
            possible = false;
        }
        attemps = p[0];
        clears = p[1];
    }
    out += possible?"YES\n":"NO\n";
}
print(out);

// Q: https://codeforces.com/contest/1339/problem/B

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	let sum = 0;
	for (let t=0; t < test; t++) {
		let ans = true;
		let n = parseInt(input[sum+t+1]);
		let arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));
		let arr2 = [];
		if (n == 1) {
			if ((arr1[0] < arr1[1])) {
				ans = false;
			}
		} else {
			for (let i = 1; i < n; i++) {
				arr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));
				if ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1])) {
					ans = false;
					break;
				}
				arr1 = [...arr2];
			}
		}

		console.log(ans ? 'YES' : 'NO');
		sum += n;
	}
});

// Q: https://codeforces.com/contest/1339/problem/B

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	let sum = 0;
	for (let t=0; t < test; t++) {
		let ans = true;
		let n = parseInt(input[sum+t+1]);
		let arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));
		let arr2 = [];
		if (n == 1) {
			if ((arr1[0] < arr1[1])) {
				ans = false;
			}
		} else {
			for (let i = 1; i < n; i++) {
				arr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));
				if ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1]) || (arr1[0] == arr2[0] && arr2[1] > arr1[0])) {
					ans = false;
					break;
				}
				arr1 = [...arr2];
			}
		}

		console.log(ans ? 'YES' : 'NO');
		sum += n;
	}
});

// Q: https://codeforces.com/contest/1339/problem/B

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	let sum = 0;
	for (let t=0; t < test; t++) {
		let ans = true;
		let n = parseInt(input[sum+t+1]);
		let arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));
		let arr2 = [];
		if (n == 1) {
			if ((arr1[0] < arr1[1])) {
				ans = false;
			}
		} else {
			for (let i = 1; i < n; i++) {
				arr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));
				if ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1])) {
					ans = false;
					break;
				}
				if (arr1[0] === arr2[0] && arr2[1] > arr1[1]) {
					ans = false;
					break;
				}
				arr1 = [...arr2];
			}
		}

		console.log(ans ? 'YES' : 'NO');
		sum += n;
	}
});

// Q: https://codeforces.com/contest/1339/problem/B

const readline = require('readline');

let input = [];

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

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

rl.on('close', () => {
	const test = parseInt(input[0]);
	let sum = 0;
	for (let t=0; t < test; t++) {
		let ans = true;
		let n = parseInt(input[sum+t+1]);
		let arr1 = input[t+sum+2].split(' ').map((a) => parseInt(a));
		let arr2 = [];
		for (let i = 1; i < n; i++) {
			arr2 = input[t+sum+2+i].split(' ').map((a) => parseInt(a));
			if ((arr2[0] < arr1[0]) || (arr2[1] < arr1[1]) || (arr2[0] < arr2[1]) || (arr1[0] < arr1[1])) {
				ans = false;
				break;
			}
			arr1 = [...arr2];
		}
		console.log(ans ? 'YES' : 'NO');
		sum += n;
	}
});

let i = '';
let lines;
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
  const { EOL } = require('os');
  lines = i.split(EOL); /*your input text, split by lines*/
  main();
});

function solve(n, a) {
  for(let i = 1; i < n; ++i) {
    if (a[i][1] < a[i - 1][1]) return 'NO';
    if (a[i][0] < a[i - 1][0]) return 'NO';
    if (a[i][1] > a[i - 1][1] && a[i][0] === a[i - 1][0]) return 'NO';
  }
  return 'YES';
}

function main() {
  let currentLine = 0;
  const readLine = (_) => lines[currentLine++].split(' ').map((val) => parseInt(val));

  const test = readLine()[0];
  for (let t = 1; t <= test; ++t) {
    const n = readLine()[0];
    let a = [];
    for(let i = 0; i < n; ++i) a.push(readLine());
    console.log(solve(n, a));
  }
}

'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const cases = readline();
    var i, j;
    for (i = 0; i < cases; i++) {
        const n = readline();
        var terminte = false;
        var lastX = 0;
        var lastY = 0;
        loop1: for (j = 0; j < n; j++) {
            const line = readline();

            var x = line.split(" ")[0];
            var y = line.split(" ")[1];

            if(!terminte && (y > x || (y-lastY) > (x-lastX))) {
                process.stdout.write("NO\n");
                terminte = true;
            }

            lastX = x;
            lastY = y;
        }

        terminte ? process.stdout.write("YES\n") : null;
    }
}