You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we can permute it so that it becomes $$$[20, 40, 10, 30]$$$. Then on the first and the second positions the integers became larger ($$$20>10$$$, $$$40>20$$$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $$$2$$$. Read the note for the first example, there is one more demonstrative test case.Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

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

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

NoteIn the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr = arr.sort(function ( x, y ) {
    return x - y;
});

//print(arr.join(' '));

var ans = 0;

for( var i=0, cnt = 1; i<n && cnt < n;  ) {
   if( arr[i] < arr[cnt]) {
       i++; cnt++; ans++;
   } else cnt++;
}

print(ans);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x - y;
});

//print(arr.join(' '));

var ans = 0;

for( var i=0, cnt = 1; i<n && cnt < n;  ) {
   if( arr[i] < arr[cnt]) {
       i++; cnt++; ans++;
   } else cnt++;
}

print(ans);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x - y;
});

//print(arr.join(' '));

var used = [];

for( var i=1; i<=100005; i++ ) {
    used.push(0);
}

var cnt = 1, ans = 0;

for( var i=0; i<=n; i++ ) {
    while ( cnt <= n && arr[i] >= arr[cnt] && !used[cnt]) {
        cnt++;
    }
    if( cnt > n ) {
        break;
    }
    if( arr[cnt] > arr[i] ) {
        //print(cnt + " " + arr[i] + " " + arr[cnt] );
        ans++;
        used[cnt++] = 1;
    }
}

print(ans);

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const sequence = is.nextArray();
  for (let i = 0; i < n; i += 1)
    sequence[i] = parseInt(sequence[i], 10);
  sequence.sort((a, b) => a - b);
  sequence.reverse();

  let answer = 0;
  for (let i = 0, j = 0; i < n; i += 1) {
    if (sequence[j] > sequence[i]) {
      j += 1;
      answer += 1;
    }
  }

  console.log(answer);
}

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

var n = (+ readline ());
var a = readline ();
a = a.trim ().split ( ' ' );
for ( var i = 0; i < a.length; i ++ ) a [ i ] = Number ( a [ i ] );
a.sort ( function ( a, b ) { return a - b; } );
var pa = 0, pb = 1;
while ( pb < a.length ) {
    if ( a [ pb ] > a [ pa ] )
        pa ++;
    pb ++;
}
print ( pa );

"use strict";

var _slicedToArray = (function() {
  function sliceIterator(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
    try {
      for (
        var _i = arr[Symbol.iterator](), _s;
        !(_n = (_s = _i.next()).done);
        _n = true
      ) {
        _arr.push(_s.value);
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"]) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
  return function(arr, i) {
    if (Array.isArray(arr)) {
      return arr;
    } else if (Symbol.iterator in Object(arr)) {
      return sliceIterator(arr, i);
    } else {
      throw new TypeError(
        "Invalid attempt to destructure non-iterable instance"
      );
    }
  };
})();

function _toConsumableArray(arr) {
  if (Array.isArray(arr)) {
    for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) {
      arr2[i] = arr[i];
    }
    return arr2;
  } else {
    return Array.from(arr);
  }
}

var compose = function compose() {
  for (
    var _len = arguments.length, functions = Array(_len), _key = 0;
    _key < _len;
    _key++
  ) {
    functions[_key] = arguments[_key];
  }

  return function() {
    for (
      var _len2 = arguments.length, args = Array(_len2), _key2 = 0;
      _key2 < _len2;
      _key2++
    ) {
      args[_key2] = arguments[_key2];
    }

    return functions.reduce(function(currArgs, func) {
      return func(currArgs);
    }, args);
  };
};

var lineToStringArray = function lineToStringArray(str) {
  return str.split(" ");
};
var lineToNumberArray = function lineToNumberArray(str) {
  return lineToStringArray(str).map(function(num) {
    return parseInt(num, 10);
  });
};

var readNumbersLine = compose(
  readline,
  lineToNumberArray
);
var readStringsLine = compose(
  readline,
  lineToStringArray
);

var _readNumbersLine = readNumbersLine(),
  _readNumbersLine2 = _slicedToArray(_readNumbersLine, 1),
  n = _readNumbersLine2[0];

var arr = readNumbersLine();
var sortedArr = [].concat(_toConsumableArray(arr)).sort(function(a, b) {
  return a - b;
});
var j = 0;
var res = 0;

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
  for (
    var _iterator = sortedArr.entries()[Symbol.iterator](), _step;
    !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
    _iteratorNormalCompletion = true
  ) {
    var _ref = _step.value;

    var _ref2 = _slicedToArray(_ref, 2);

    var index = _ref2[0];
    var value = _ref2[1];

    while (sortedArr[index] >= sortedArr[j] && j < n) {
      j++;
    }
    if (j === n) {
      break;
    }
    res = index + 1;
    j++;
  }
} catch (err) {
  _didIteratorError = true;
  _iteratorError = err;
} finally {
  try {
    if (!_iteratorNormalCompletion && _iterator.return) {
      _iterator.return();
    }
  } finally {
    if (_didIteratorError) {
      throw _iteratorError;
    }
  }
}

write(res);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x > y;
});

//print(arr.join(' '));

var ans = 0;

for( var i=0, cnt = 1; i<n && cnt < n;  ) {
   if( arr[i] < arr[cnt]) {
       i++; cnt++; ans++;
   } else cnt++;
}

print(ans);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x > y;
});

//print(arr.join(' '));

var used = [];

for( var i=1; i<=100005; i++ ) {
    used.push(0);
}

var cnt = 1, ans = 0;

for( var i=1; i<=n; i++ ) {
    while ( cnt <= n && arr[i] >= arr[cnt] ) {
        cnt++;
    }
    if( cnt > n ) {
        break;
    }
    if( arr[cnt] > arr[i] ) {
        //print(cnt + " " + arr[i] + " " + arr[cnt] );
        ans++;
        used[cnt++] = 1;
    }
}

print(ans);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x > y;
});

//print(arr.join(' '));

var used = [];

for( var i=1; i<=100005; i++ ) {
    used.push(0);
}

var cnt = 1, ans = 0;

for( var i=0, cnt = 1; i<n && cnt < n;  ) {
   if( arr[i] < arr[cnt]) {
       i++; cnt++; ans++;
   } else cnt++;
}

print(ans);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x > y;
});

//print(arr.join(' '));

var used = [];

for( var i=1; i<=100005; i++ ) {
    used.push(0);
}

var cnt = 1, ans = 0;

for( var i=0; i<=n; i++ ) {
    while ( cnt <= n && arr[i] >= arr[cnt] && !used[cnt]) {
        cnt++;
    }
    if( cnt > n ) {
        break;
    }
    if( arr[cnt] > arr[i] ) {
        //print(cnt + " " + arr[i] + " " + arr[cnt] );
        ans++;
        used[cnt++] = 1;
    }
}

print(ans);

var n = readline();

var arr = readline().split(' ').map(Number);

//print(arr.join(' '));

arr.sort(function ( x, y ) {
    return x > y;
});

//print(arr.join(' '));

var used = [];

for( var i=1; i<=100005; i++ ) {
    used.push(0);
}

var cnt = 1, ans = 0;

for( var i=0; i<=n; i++ ) {
    while ( cnt <= n && arr[i] >= arr[cnt] ) {
        cnt++;
    }
    if( cnt > n ) {
        break;
    }
    if( arr[cnt] > arr[i] ) {
        //print(cnt + " " + arr[i] + " " + arr[cnt] );
        ans++;
        used[cnt++] = 1;
    }
}

print(ans);


Wherever the destination is, whoever we meet, let's render this song together.On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the stage.On the sides of the stage stand n dancers. The i-th of them falls into one of the following groups:   Vertical: stands at (xi, 0), moves in positive y direction (upwards);  Horizontal: stands at (0, yi), moves in positive x direction (rightwards).   According to choreography, the i-th dancer should stand still for the first ti milliseconds, and then start moving in the specified direction at 1 unit per millisecond, until another border is reached. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.When two dancers collide (i.e. are on the same point at some time when both of them are moving), they immediately exchange their moving directions and go on.  Dancers stop when a border of the stage is reached. Find out every dancer's stopping position.

The first line of input contains three space-separated positive integers n, w and h (1 ≤ n ≤ 100 000, 2 ≤ w, h ≤ 100 000) — the number of dancers and the width and height of the stage, respectively. The following n lines each describes a dancer: the i-th among them contains three space-separated integers gi, pi, and ti (1 ≤ gi ≤ 2, 1 ≤ pi ≤ 99 999, 0 ≤ ti ≤ 100 000), describing a dancer's group gi (gi = 1 — vertical, gi = 2 — horizontal), position, and waiting time. If gi = 1 then pi = xi; otherwise pi = yi. It's guaranteed that 1 ≤ xi ≤ w - 1 and 1 ≤ yi ≤ h - 1. It is guaranteed that no two dancers have the same group, position and waiting time at the same time.

Output n lines, the i-th of which contains two space-separated integers (xi, yi) — the stopping position of the i-th dancer in the input.

NoteThe first example corresponds to the initial setup in the legend, and the tracks of dancers are marked with different colours in the following figure.  In the second example, no dancers collide.

var l1 = readline().split(' ');
var n = +l1[0];
var w = +l1[1];
var h = +l1[2];

var src = new Array(n);
var dest = new Array(n);
for(var i = 0; i < n; i++) {
    var line = readline().split(' ');
    var p = +line[1], t = +line[2];
    var x1, y1, x2, y2;
    if(line[0] == '1') { // vertical
        x1 = p; y1 = -t;
        x2 = p; y2 = +h;
    }else {
        x1 = -t; y1 = p;
        x2 = +w; y2 = p;
    }
    src[i] = ([x1+y1, x1, y1, i]);
    dest[i] = ([x1+y1, x2, y2, i]);
}

function comp (p, q) {
    return p[0] != q[0] ? p[0] - q[0] : p[1] != q[1] ? p[1] - q[1] : p[2] != q[2] ? q[2] - p[2] : p[3] - q[3];

}

src.sort(comp);
dest.sort(comp);

var ans = new Array(n);
for(var i = 0; i < n; i++) {
    ans[src[i][3]] = dest[i][1] + " " + dest[i][2];
}
print(ans.join("\n"));


Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic. One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon. The dragon has a hit point of $$$x$$$ initially. When its hit point goes to $$$0$$$ or under $$$0$$$, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells.  Void Absorption Assume that the dragon's current hit point is $$$h$$$, after casting this spell its hit point will become $$$\left\lfloor \frac{h}{2} \right\rfloor + 10$$$. Here $$$\left\lfloor \frac{h}{2} \right\rfloor$$$ denotes $$$h$$$ divided by two, rounded down. Lightning Strike This spell will decrease the dragon's hit point by $$$10$$$. Assume that the dragon's current hit point is $$$h$$$, after casting this spell its hit point will be lowered to $$$h-10$$$.Due to some reasons Kana can only cast no more than $$$n$$$ Void Absorptions and $$$m$$$ Lightning Strikes. She can cast the spells in any order and doesn't have to cast all the spells. Kana isn't good at math, so you are going to help her to find out whether it is possible to defeat the dragon.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)  — the number of test cases. The next $$$t$$$ lines describe test cases. For each test case the only line contains three integers $$$x$$$, $$$n$$$, $$$m$$$ ($$$1\le x \le 10^5$$$, $$$0\le n,m\le30$$$)  — the dragon's intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.

If it is possible to defeat the dragon, print "YES" (without quotes). Otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower).

NoteOne possible casting sequence of the first test case is shown below: Void Absorption $$$\left\lfloor \frac{100}{2} \right\rfloor + 10=60$$$. Lightning Strike $$$60-10=50$$$. Void Absorption $$$\left\lfloor \frac{50}{2} \right\rfloor + 10=35$$$. Void Absorption $$$\left\lfloor \frac{35}{2} \right\rfloor + 10=27$$$. Lightning Strike $$$27-10=17$$$. Lightning Strike $$$17-10=7$$$. Lightning Strike $$$7-10=-3$$$.

// Q: https://codeforces.com/contest/1337/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]);
	for (let t = 0; t < test; t++) {
		let vals = input[t+1].split(' ').map((a) => {return parseInt(a)});
		console.log(solution(vals[0], vals[1], vals[2]));
	}
});

function solution(x, n, m) {
	if (x <= m*10) {
		return 'YES';
	}
	for (let i = 0; i < n; i++) {
		x = Math.floor((x/2 + 10));
		if ( x <= m*10) {
			return 'YES';
		}
	}
	return 'NO';
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const cases = readline();
    var i;
    for (i = 0; i < cases; i++) {
        const line = readline();
        var a = parseInt(line.split(" ")[0]);
        var b = parseInt(line.split(" ")[1]);
        var c = parseInt(line.split(" ")[2]);

        solve(a, b, c);
    }
}

function solve(hp, attack1, attack2) {
    while ((attack1 + attack2) > 0 && hp > 0) {
        var attack1Damage = Math.floor(hp/2);

        if (attack1 > 0 && (hp - attack1Damage) > 10) {
            hp = attack1Damage;
            hp += 10;
            attack1--;
            continue;
        } else if (attack2 > 0) {
            hp -= 10;
            attack2--;
            continue;
        } else {
            break;
        }
    }

    console.log(hp > 0 ? 'NO' : 'YES');
}

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

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

  let [x, n, m] = d.split(' ').map(Number);

  while (n > 0 && x > m * 10) {
    x = Math.floor(x / 2) + 10;
    n--;
  }

  x -= m * 10;

  if (x > 0) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    let l = arr[0];
    arr = arr.slice(1);
    arr = arr.map(el => +el);
    for (let z = 0; z < l; z++) {
        let x = arr[0];
        let n = arr[1];
        let m = arr[2];
        while (x > 20 && n > 0) {
            x = Math.floor(x/2);
            x += 10;
            n--;
        }
        console.log(x <= m * 10 ? "YES" : "NO");
        arr = arr.slice(3);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

"use strict";
exports.__esModule = true;
var str = "", lines = [], idxLine = 0;
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (x) { str += x; });
process.stdin.on('end', function () {
    lines = str.trim().split('\n').map(function (x) { return x.trim(); });
    main();
});
function readline() {
    return lines[idxLine++];
}
var print = console.log;
//===============================
//===============================
function canSolve(x, n, m) {
    while (n > 0 && x > 20) {
        x = Math.floor(x / 2) + 10;
        n--;
    }
    while (m > 0 && x > 0) {
        x = x - 10;
        m--;
    }
    if (x <= 0)
        return true;
    return false;
}
function main() {
    var t = parseInt(readline());
    for (var _ = 0; _ < t; _++) {
        var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];
        print(canSolve(x, n, m) ? 'YES' : 'NO');
    }
}

"use strict";
exports.__esModule = true;
var str = "", lines = [], idxLine = 0;
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (x) { str += x; });
process.stdin.on('end', function () {
    lines = str.trim().split('\n').map(function (x) { return x.trim(); });
    main();
});
function readline() {
    return lines[idxLine++];
}
var print = console.log;
//===============================
//===============================
function canSolve(x, n, m) {
    while (n > 0 && x > 20) {
        x = Math.floor(x / 2) + 10;
        n--;
    }
    while (m > 0 && x > 0) {
        x = x - 10;
        m--;
    }
    if (x <= 0)
        return true;
    return false;
}
function main() {
    var e = parseInt(readline());
    for (var _ = 0; _ < e; _++) {
        var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];
        print(canSolve(x, n, m) ? 'YES' : 'NO');
    }
}

"use strict";
exports.__esModule = true;
var str = "", lines = [], idxLine = 0;
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function (x) { str += x; });
process.stdin.on('end', function () {
    lines = str.trim().split('\n').map(function (x) { return x.trim(); });
    main();
});
function readline() {
    return lines[idxLine++];
}
var print = console.log;
//===============================
//===============================
function canSolve(x, n, m) {
    while (n > 0 && x > 20) {
        x = Math.floor(x / 2) + 10;
        n--;
    }
    while (m > 0 && x > 0) {
        x = x - 10;
        m--;
    }
    if (x <= 0)
        return true;
    return false;
}
function main() {
    var r = parseInt(readline());
    for (var _ = 0; _ < r; _++) {
        var _a = readline().split(' ').map(function (e) { return parseInt(e); }), x = _a[0], n = _a[1], m = _a[2];
        print(canSolve(x, n, m) ? 'YES' : 'NO');
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function checkValidity(a, b, c) {
  if ((a + b <= c) || (a + c <= b) || (b + c <= a)) {
    return false;
  } else {
    return true;
  }
}

function main() {
  let X = parseInt(readline());
  for (var cases = 0; cases < X; cases++) {
    let [h, v, l] = readline().split(" ").map(e => parseInt(e));

    while (h >= 0 && (v > 0 || l > 0)) {
      //console.log(h,v,l);
      if (v > 0 && h >= 21) {
        h = Math.floor(h/2) + 10;
        v--;
      } else if (l > 0) {
        h = h - 10;
        l--;
      } else {
        break;
      }
    }

    if (h > 0) {
      console.log('NO')
    } else {
      console.log('YES');
    }
  }
}

const n = Number(readline());
for (var i = n; i; i--) {
  var line = readline().split(" ");
  var hp = Number(line[0]);
  var a = Number(line[1]);
  var b = Number(line[2]);
  while (hp > 20 && a--)
    hp = (hp >> 1) + 10;
  print(hp <= b * 10 ? "YES" : "NO");
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var tmp = nextIntArray();
		var x = tmp[0];
		var n = tmp[1];
		var m = tmp[2];
		var mae = x;
		var isDefeat = false;
		for(var j = 0; j < n; j++){
			if(mae < Math.floor(x / 2) + 10){
				break;
			}
			x = Math.floor(x / 2) + 10;
		}
		for(var j = 0; j < m; j++){
			x -= 10;
			if(x <= 0){
				isDefeat = true;
			}
		}
		if(isDefeat){
			output[i] = "YES";
		}else{
			output[i] = "NO";
		}
	}
	myout(myconv(output,9));
}

var T = parseInt(readline());
while (T--) {
    var input1 = readline().split(' ').map(x => parseInt(x));
    var a = input1[0]
    var b = input1[1]
    var c = input1[2]
    if (0 >= (a - (c * 10))) {
        print("yes")
    }
    else {
        while (b--) {
            var r = parseInt(a / 2) + 10
            a = r
        }
        var res = a - (c * 10)
        if (res <= 0) {
            print("yes")
        }
        else {
            print("no")
        }
    }
}

var n = Number(readline());
var inp ;

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

    inp = readline().split(' ').map(cur => Number(cur));
    var h = inp[0];
    var v = inp[1];
    var l = inp[2];

if(h < 20){
while( l > 0 ){
    l--;
    h = lightning(h);
    if(h <= 0) break;
}
    (h <= 0) ? print("YES"): print("NO");

}else{
while(v > 0){
    v--;
h = voidAbs(h);
if(h < 20) break;
}
while( l > 0 ){
    l--;
    h = lightning(h);
    if(h <= 0) break;
}
    (h <= 0) ? print("YES"): print("NO");

}

}

function voidAbs(x){
    return Math.floor(x/2) + 10
}

function lightning(x){
    return x-10
}

var range = readline();

for(var i=0;i<range;i++) {
    var inputs = readline().split(" ").map((x) => parseInt(x));

    var score = inputs[0];
    var absorb = inputs[1];
    var strike = inputs[2];

    for(var j=0;j<absorb;j++) {
        if(score > 10) {
            score = Math.floor(score / 2) + 10;
        }
    }

    for(var j=0;j<strike;j++) {
        score = score - 10;
    }

    print(score > 0 ? 'NO': 'YES');

}

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

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

  let [x, n, m] = d.split(' ').map(Number);

  if (x <= 10) {
    [m, n] = [n, m];
  }

  while (n > 0) {
    x = Math.floor(x / 2) + 10;
    n--;
  }

  while (m > 0) {
    x -= 10;
    m--;
  }

  if (x > 0) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

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

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

  let [x, n, m] = d.split(' ').map(Number);

  if (x <= 10) {
    [m, n] = [n, m];
  }

  while (n > 0) {
    x = Math.floor(x / 2) + 10;

    if (x <= 10) {
      break;
    }
    n--;
  }

  while (m > 0) {
    x -= 10;
    m--;
  }

  if (x > 0) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    let l = arr[0];
    arr = arr.slice(1);
    arr = arr.map(el => +el);
    for (let z = 0; z < l; z ++){
        let x = arr[0];
        let n = arr[1];
        let m = arr[2];
        let val = m*10*Math.pow(2,n);
        console.log(val > x ? "YES" : "NO");
        arr = arr.slice(3);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    let l = arr[0];
    arr = arr.slice(1);
    arr = arr.map(el => +el);
    for (let z = 0; z < l; z ++){
        let x = arr[0];
        let n = arr[1];
        let m = arr[2];
        while (x > 20 && n > 0){
            x/=2;
            x+=10;
            n--;
        }
        console.log(x < m*10 ? "YES" : "NO");
        arr = arr.slice(3);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});


You are given three multisets of pairs of colored sticks:   $$$R$$$ pairs of red sticks, the first pair has length $$$r_1$$$, the second pair has length $$$r_2$$$, $$$\dots$$$, the $$$R$$$-th pair has length $$$r_R$$$;  $$$G$$$ pairs of green sticks, the first pair has length $$$g_1$$$, the second pair has length $$$g_2$$$, $$$\dots$$$, the $$$G$$$-th pair has length $$$g_G$$$;  $$$B$$$ pairs of blue sticks, the first pair has length $$$b_1$$$, the second pair has length $$$b_2$$$, $$$\dots$$$, the $$$B$$$-th pair has length $$$b_B$$$; You are constructing rectangles from these pairs of sticks with the following process:   take a pair of sticks of one color;  take a pair of sticks of another color different from the first one;  add the area of the resulting rectangle to the total area. Thus, you get such rectangles that their opposite sides are the same color and their adjacent sides are not the same color.Each pair of sticks can be used at most once, some pairs can be left unused. You are not allowed to split a pair into independent sticks.What is the maximum area you can achieve?

The first line contains three integers $$$R$$$, $$$G$$$, $$$B$$$ ($$$1 \le R, G, B \le 200$$$) — the number of pairs of red sticks, the number of pairs of green sticks and the number of pairs of blue sticks. The second line contains $$$R$$$ integers $$$r_1, r_2, \dots, r_R$$$ ($$$1 \le r_i \le 2000$$$) — the lengths of sticks in each pair of red sticks. The third line contains $$$G$$$ integers $$$g_1, g_2, \dots, g_G$$$ ($$$1 \le g_i \le 2000$$$) — the lengths of sticks in each pair of green sticks. The fourth line contains $$$B$$$ integers $$$b_1, b_2, \dots, b_B$$$ ($$$1 \le b_i \le 2000$$$) — the lengths of sticks in each pair of blue sticks.

Print the maximum possible total area of the constructed rectangles.

NoteIn the first example you can construct one of these rectangles: red and green with sides $$$3$$$ and $$$5$$$, red and blue with sides $$$3$$$ and $$$4$$$ and green and blue with sides $$$5$$$ and $$$4$$$. The best area of them is $$$4 \times 5 = 20$$$.In the second example the best rectangles are: red/blue $$$9 \times 8$$$, red/blue $$$5 \times 5$$$, green/blue $$$2 \times 1$$$. So the total area is $$$72 + 25 + 2 = 99$$$.In the third example the best rectangles are: red/green $$$19 \times 8$$$ and red/blue $$$20 \times 11$$$. The total area is $$$152 + 220 = 372$$$. Note that you can't construct more rectangles because you are not allowed to have both pairs taken to be the same color.

let input = ''

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

process.stdin.on('end', () => {
    let lines = input.trim().split('\n')

    lines.shift()
    let [r, g, b] = lines.map(l => l.split(' ').map(Number).sort((a, b) => b - a))

    let dp = new Array(r.length + 1)
    let ans = 0

    for (let i = 0; i <= r.length; i++) {
        dp[i] = new Array(g.length + 1)
        for (let j = 0; j <= g.length; j++) {
            dp[i][j] = new Array(b.length + 1).fill(0)
            for (let k = 0; k <= b.length; k++) {
                function upd(val) {
                    dp[i][j][k] = Math.max(dp[i][j][k], val)
                    ans = Math.max(ans, val)
                }
                if (i > 0 && j > 0)
                    upd(dp[i - 1][j - 1][k] + r[i - 1] * g[j - 1])
                if (i > 0 && k > 0)
                    upd(dp[i - 1][j][k - 1] + r[i - 1] * b[k - 1])
                if (j > 0 && k > 0)
                    upd(dp[i][j - 1][k - 1] + g[j - 1] * b[k - 1])
            }
        }
    }

    console.log(ans)
})

var readline=require('readline');
var rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
var arr=[],sol;
function Solve(){
    this.val=0;
    this.dp=new Array(205);
    for(var i=0;i<205;i++){
        this.dp[i]=new Array(205);
        for(var j=0;j<205;j++) this.dp[i][j]=new Array(205).fill(0);
    }
}
Solve.prototype.dfs=function(i,j,k){
    if(i<0||j<0||k<0) return 0;
    if(this.dp[i][j][k]) return this.dp[i][j][k];
    var x=0,y=0,z=0;
    x=this.dfs(i-1,j-1,k)+(i>0&&j>0?(this.a[0][i-1]*this.a[1][j-1]):0);
    y=this.dfs(i-1,j,k-1)+(i>0&&k>0?(this.a[0][i-1]*this.a[2][k-1]):0);
    z=this.dfs(i,j-1,k-1)+(j>0&&k>0?(this.a[1][j-1]*this.a[2][k-1]):0);
    return this.val=this.dp[i][j][k]=Math.max(x,Math.max(y,z));
    return 0;
}
Solve.prototype.init=function(){
    this.a=new Array(3);
}
rl.on('line',function(inp){
    arr.push(inp);
    var len=arr.length;
    if(len===1){
        sol=new Solve();
        sol.rgb=arr[0].split(' ');
        sol.init();
        for(var i=0;i<sol.rgb.length;i++) sol.rgb[i]=parseInt(sol.rgb[i]);
    }else{
        var b=arr[len-1].split(' ');
        for(var i=0;i<sol.rgb[len-2];i++) b[i]=parseInt(b[i]);
        sol.a[len-2]=b;
        sol.a[len-2].sort(function(x,y){
            if(x<y) return -1;
            else if(x===y) return 0;
            else return 1;
        });
    }
    if(len===4){
        sol.dfs(sol.rgb[0],sol.rgb[1],sol.rgb[2]);
        console.log(sol.val);
        process.exit(0);
    }
});

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 [rNum, gNum, bNum] = readLine().split(/\s/).map(Number)
  const rs = readLine().split(/\s/).map(Number).sort((a, b) => b - a)
  const gs = readLine().split(/\s/).map(Number).sort((a, b) => b - a)
  const bs = readLine().split(/\s/).map(Number).sort((a, b) => b - a)
  const dp = Array(rNum + 1)
    .fill(0)
    .map(() => Array(gNum + 1)
      .fill(0)
      .map(() => Array(bNum + 1)
        .fill(0)
      )
    )
  let result = 0
  for (let r = 0; r <= rNum; r++) {
    for (let g = 0; g <= gNum; g++) {
	  for (let b = 0; b <= bNum; b++) {
        if ((r + g + b) % 2 === 1) {
          continue
        }
        if (r < rNum && g < gNum) {
          dp[r + 1][g + 1][b] = Math.max(dp[r + 1][g + 1][b], dp[r][g][b] + rs[r] * gs[g])
        }
        if (r < rNum && b < bNum) {
          dp[r + 1][g][b + 1] = Math.max(dp[r + 1][g][b + 1], dp[r][g][b] + rs[r] * bs[b])
        }
        if (g < gNum && b < bNum) {
          dp[r][g + 1][b + 1] = Math.max(dp[r][g + 1][b + 1], dp[r][g][b] + gs[g] * bs[b])
        }
        result = Math.max(result, dp[r][g][b])
      }
  	}
  }
  console.log(result)
}

'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 [r,g,b] = readline().split(" ").map(x => parseInt(x));
  const ar = readline().split(" ").map(x => parseInt(x));
  const ag = readline().split(" ").map(x => parseInt(x));
  const ab = readline().split(" ").map(x => parseInt(x));
  ar.sort((a,b)=>b-a);
  ag.sort((a,b)=>b-a);
  ab.sort((a,b)=>b-a);

  let ans = 0;
  let dp = Array(r+1).fill().map(
    _ => Array(g+1).fill().map(
      _ => Array(b+1).fill(0)));

  for (let i=0; i<=r; i++) {
    for (let j=0; j<=g; j++) {
      for (let k=0; k<=b; k++) {
        if (i<r && j<g) {
          dp[i+1][j+1][k] = Math.max(dp[i+1][j+1][k], dp[i][j][k] + ar[i]*ag[j]);
        }
        if (i<r && k<b) {
          dp[i+1][j][k+1] = Math.max(dp[i+1][j][k+1], dp[i][j][k] + ar[i]*ab[k]);
        }
        if (j<g && k<b) {
          dp[i][j+1][k+1] = Math.max(dp[i][j+1][k+1], dp[i][j][k] + ag[j]*ab[k]);
        }
        ans = Math.max(ans, dp[i][j][k]);
      }
    }
  }
  console.log(ans);
}

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(){
    let [r,g,b] = readline().split(' ');
        let ar = readline().split(' ');
        let ag = readline().split(' ');
        let ab = readline().split(' ');

        ar.sort((a,b) => parseInt(b)-parseInt(a));
        ag.sort((a,b) => parseInt(b)-parseInt(a));
        ab.sort((a,b) => parseInt(b)-parseInt(a));
        let dp = new Array(205);
        for(let i = 0; i < 205; i++){
            dp[i] = new Array(205);
            for(let j = 0; j < 205; j++){
                dp[i][j] = new Array(205);
                dp[i][j].fill(-1);
            }
        }
        let res = 0;
        let solve = (x, y, z) => {
            if((x >= r && y >= g) || (x >= r && z >= b) || (y >= g && z >= b))
                return 0;

            if(dp[x][y][z] !== -1)
                return dp[x][y][z];
            let max = 0;
            if(x < r && y < g)
                max = Math.max(max, parseInt(ar[x]) * parseInt(ag[y]) + solve(x+1, y+1, z));
            if(x < r && z < b)
                max = Math.max(max, parseInt(ar[x]) * parseInt(ab[z]) + solve(x+1, y, z+1));
            if(y < g && z < b)
                max = Math.max(max, parseInt(ag[y]) * parseInt(ab[z]) + solve(x, y+1, z+1));

            dp[x][y][z] = max;
            res = Math.max(res, max);
            return max;
        }

        solve(0,0,0);
        console.log(res);
}

'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 [r,g,b] = readline().split(" ").map(x => parseInt(x));
  const ar = readline().split(" ").map(x => parseInt(x));
  const ag = readline().split(" ").map(x => parseInt(x));
  const ab = readline().split(" ").map(x => parseInt(x));
  ar.sort((a,b)=>b-a);
  ag.sort((a,b)=>b-a);
  ab.sort((a,b)=>b-a);

  let area = 0;
  while (ar.length + ag.length + ab.length >1) {
    let [a,b,c] = [ar, ag, ab].sort((a,b)=>(b[0]|0)-(a[0]|0));
    let a0 = a.shift();
    let b0 = b.shift();
    // consider special case e.g. [3],[3],[2,2]
    // greedy way will do 3*3, leaving [2,2] unusable
    // the optimal matching is 3*2 + 3*2
    if (a.length == 0 && b.length == 0 && c.length >= 2) {
      if (a0 * c[0] + b0 * c[1] > a0*b0) {
        let c0 = c.shift();
        let c1 = c.shift();
        area += a0*c0 + b0*c1;
        break;
      }
    } else {
      area += a0 * b0;
    }
  }
  console.log(area);
}

'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 [r,g,b] = readline().split(" ").map(x => parseInt(x));
  const ar = readline().split(" ").map(x => parseInt(x));
  const ag = readline().split(" ").map(x => parseInt(x));
  const ab = readline().split(" ").map(x => parseInt(x));
  ar.sort((a,b)=>b-a);
  ag.sort((a,b)=>b-a);
  ab.sort((a,b)=>b-a);

  let area = 0;
  while (ar.length + ag.length + ab.length >1) {
    let [a,b,c] = [ar, ag, ab].sort((a,b)=>(b[0]|0)-(a[0]|0));
    let a0 = a.shift() | 0;
    let b0 = b.shift() | 0;
    // consider special case e.g. [3],[3],[2,2]
    // greedy way will do 3*3, leaving [2,2] unusable
    // the optimal matching is 3*2 + 3*2
    if (a.length == 0 && b.length == 0 && c.length >= 2) {
      if (a0 * c[0] + b0 * c[1] > a0*b0) {
        let c0 = c.shift();
        let c1 = c.shift();
        area += a0*c0 + b0*c1;
        break;
      }
    } else {
      area += a0 * b0;
    }
  }
  console.log(area);
}


Eugeny loves listening to music. He has n songs in his play list. We know that song number i has the duration of ti minutes. Eugeny listens to each song, perhaps more than once. He listens to song number i ci times. Eugeny's play list is organized as follows: first song number 1 plays c1 times, then song number 2 plays c2 times, ..., in the end the song number n plays cn times.Eugeny took a piece of paper and wrote out m moments of time when he liked a song. Now for each such moment he wants to know the number of the song that played at that moment. The moment x means that Eugeny wants to know which song was playing during the x-th minute of his listening to the play list.Help Eugeny and calculate the required numbers of songs.

The first line contains two integers n, m (1 ≤ n, m ≤ 105). The next n lines contain pairs of integers. The i-th line contains integers ci, ti (1 ≤ ci, ti ≤ 109) — the description of the play list. It is guaranteed that the play list's total duration doesn't exceed 109 . The next line contains m positive integers v1, v2, ..., vm, that describe the moments Eugeny has written out. It is guaranteed that there isn't such moment of time vi, when the music doesn't play any longer. It is guaranteed that vi < vi + 1 (i < m). The moment of time vi means that Eugeny wants to know which song was playing during the vi-th munite from the start of listening to the playlist.

Print m integers — the i-th number must equal the number of the song that was playing during the vi-th minute after Eugeny started listening to the play list.

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], m = data[1],
		times = [0], time = 0;
	for (var i = 0; i < n; ++i) {
		data = tokenizeIntegers(readline());
		time += data[0] * data[1];
		times.push(time);
	}
	function search(x) {
		var low = 1, high = n, mid;
		while (true) {
			mid = Math.floor((low+high)/2);
			if (x > times[mid-1] && x <= times[mid]) {
				break;
			}
			if (x <= times[mid]) {
				high = mid-1;
			} else {
				low = mid+1;
			}
		}
		return mid;
	}
	var result = [];
	var queries = tokenizeIntegers(readline());
	for (var i = 0; i < m; ++i) {
		result.push(search(queries[i]));
	}
	print(result.join('\n'));
}

main();


There are $$$n$$$ bags with candies, initially the $$$i$$$-th bag contains $$$i$$$ candies. You want all the bags to contain an equal amount of candies in the end. To achieve this, you will: Choose $$$m$$$ such that $$$1 \le m \le 1000$$$Perform $$$m$$$ operations. In the $$$j$$$-th operation, you will pick one bag and add $$$j$$$ candies to all bags apart from the chosen one.Your goal is to find a valid sequence of operations after which all the bags will contain an equal amount of candies. It can be proved that for the given constraints such a sequence always exists.You don't have to minimize $$$m$$$.If there are several valid sequences, you can output any.

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 each test case contains one integer $$$n$$$ ($$$2 \le n\le 100$$$).

For each testcase, print two lines with your answer.  In the first line print $$$m$$$ ($$$1\le m \le 1000$$$) — the number of operations you want to take.  In the second line print $$$m$$$ positive integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le n$$$), where $$$a_j$$$ is the number of bag you chose on the $$$j$$$-th operation.

NoteIn the first case, adding $$$1$$$ candy to all bags except of the second one leads to the arrangement with $$$[2, 2]$$$ candies.In the second case, firstly you use first three operations to add $$$1+2+3=6$$$ candies in total to each bag except of the third one, which gives you $$$[7, 8, 3]$$$. Later, you add $$$4$$$ candies to second and third bag, so you have $$$[7, 12, 7]$$$, and $$$5$$$ candies to first and third bag  — and the result is $$$[12, 12, 12]$$$.

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 = [];
    for (let i = 1; i <= len; i++) arr.push(i);
    console.log(len);
    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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		output.push(N);
		var list = [];
		for(var j = 1; j <= N; j++){
			list.push(j);
		}
		output.push(myconv(list, 8));
	}
	myout(myconv(output, 9));
}

function* range(first, last, step = 1) {
  for (let i = first; i <= last; i += step) {
    yield i;
  }
}

async function main() {
  const { EOL } = require('os');

  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .filter(str => !!str)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    const n = lines[i];
    output.push(n - 1);
    output.push([...range(2, n)].join(' '));
  }
  console.log(output.join(EOL));
}

main();

function* range(first, last, step = 1) {
  for (let i = first; i <= last; i += step) {
    yield i;
  }
}

function checkState(state) {
  for (let i = 0; i + 1 < state.length; i++) {
    if (state[i] !== state[i + 1]) {
      return false;
    }
  }
  return true;
}

function solve(n) {
  let oldStates = [
    {
      state: [...range(1, n)],
      path: [],
    }
  ];
  for (const m of range(1, 1000)) {
    const newStates = [];
    for (const oldState of oldStates) {
      for (const i of range(0, n - 1)) {
        const newState = {
          state: [...oldState.state],
          path: [...oldState.path],
        }
        newState.path.push(i + 1);
        for (const j of range(0, n - 1)) {
          if (i !== j) {
            newState.state[j] += m;
          }
        }
        if (checkState(newState.state)) {
          return {
            m,
            a: newState.path,
          }
        }
        newStates.push(newState);
      }
    }
    oldStates = newStates;
  }
}

// function main() {
//   const a2 = solve(2);
//   const a3 = solve(3);
//   console.log('finished');
// }

// main();

async function main() {
  const { EOL } = require('os');

  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    const solution = solve(lines[i]);
    output.push(solution.m);
    output.push(solution.a.join(' '));
  }
  console.log(output.join(EOL));
}

main();

function* range(first, last, step = 1) {
  for (let i = first; i <= last; i += step) {
    yield i;
  }
}

function checkState(state) {
  for (let i = 0; i + 1 < state.length; i++) {
    if (state[i] !== state[i + 1]) {
      return false;
    }
  }
  return true;
}

function solve(n) {
  let oldStates = [
    {
      state: [...range(1, n)],
    }
  ];
  for (const m of range(1, 1000)) {
    const newStates = [];
    for (const oldState of oldStates) {
      for (const i of range(0, n - 1)) {
        const newState = {
          state: [...oldState.state],
          previous: oldState,
          path: i + 1,
        }
        for (const j of range(0, n - 1)) {
          if (i !== j) {
            newState.state[j] += m;
          }
        }
        if (checkState(newState.state)) {
          const a = [];
          let current = newState
          do {
            if (current.path) {
              a.push(current.path);
            }
            current = current.previous;
          } while (current);
          return {
            m,
            a,
          }
        }
        newStates.push(newState);
      }
    }
    oldStates = newStates;
  }
}

// function main() {
//   const a2 = solve(2);
//   const a3 = solve(3);
//   console.log('finished');
// }

async function main() {
  const { EOL } = require('os');

  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .filter(str => !!str)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    const solution = solve(lines[i]);
    output.push(solution.m);
    output.push(solution.a.join(' '));
  }
  console.log(output.join(EOL));
}

main();

async function main() {
  const { EOL } = require('os');

  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    output.push(1);
    output.push(2);
  }
  console.log(output.join(EOL));
}

main();

function* range(first, last, step = 1) {
  for (let i = first; i <= last; i += step) {
    yield i;
  }
}

function checkState(state) {
  for (let i = 0; i + 1 < state.length; i++) {
    if (state[i] !== state[i + 1]) {
      return false;
    }
  }
  return true;
}

function solve(n) {
  let oldStates = [
    {
      state: [...range(1, n)],
      path: [],
    }
  ];
  for (const m of range(1, 1000)) {
    const newStates = [];
    for (const oldState of oldStates) {
      for (const i of range(0, n - 1)) {
        const newState = {
          state: [...oldState.state],
          path: [...oldState.path],
        }
        newState.path.push(i + 1);
        for (const j of range(0, n - 1)) {
          if (i !== j) {
            newState.state[j] += m;
          }
        }
        if (checkState(newState.state)) {
          return {
            m,
            a: newState.path,
          }
        }
        newStates.push(newState);
      }
    }
    oldStates = newStates;
  }
}

// function main() {
//   const a2 = solve(2);
//   const a3 = solve(3);
//   console.log('finished');
// }

// main();

async function main() {
  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
      .toString()
      .split(EOL)
      .map(str => +str);

  for (let i = 1; i < lines.length; i++) {
    const solution = solve(lines[i]);
    console.log(solution.m);
    console.log(solution.a.join(' '));
  }
}

main();

async function main() {
  const { EOL } = require('os');

  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .filter(str => !!str)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    output.push(1);
    output.push(2);
  }
  console.log(output.join(EOL));
}

main();

function* range(first, last, step = 1) {
  for (let i = first; i <= last; i += step) {
    yield i;
  }
}

function checkState(state) {
  for (let i = 0; i + 1 < state.length; i++) {
    if (state[i] !== state[i + 1]) {
      return false;
    }
  }
  return true;
}

function solve(n) {
  let oldStates = [
    {
      state: [...range(1, n)],
      path: [],
    }
  ];
  for (const m of range(1, 1000)) {
    const newStates = [];
    for (const oldState of oldStates) {
      for (const i of range(0, n - 1)) {
        const newState = {
          state: [...oldState.state],
          path: [...oldState.path],
        }
        newState.path.push(i + 1);
        for (const j of range(0, n - 1)) {
          if (i !== j) {
            newState.state[j] += m;
          }
        }
        if (checkState(newState.state)) {
          return {
            m,
            a: newState.path,
          }
        }
        newStates.push(newState);
      }
    }
    oldStates = newStates;
  }
}

// function main() {
//   const a2 = solve(2);
//   const a3 = solve(3);
//   console.log('finished');
// }

// main();

async function main() {
  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    const solution = solve(lines[i]);
    output.push(solution.m);
    output.push(solution.a.join(' '));
  }
  console.log(output.join('\n'));
}

main();

async function main() {
  const { EOL } = require('os');

  const dataArray = []
  for await (const chunk of process.stdin) {
    dataArray.push(chunk);
  }
  const lines = Buffer.concat(dataArray)
    .toString()
    .split(EOL)
    .map(str => +str);

  const output = [];
  for (let i = 1; i < lines.length; i++) {
    output.push(1);
    output.push(1);
  }
  console.log(output.join(EOL));
}


Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows:   $$$a_1 = -1$$$  $$$a_2 = 2$$$  $$$a_3 = -3$$$  $$$a_4 = 4$$$  $$$a_5 = -5$$$  And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.

Print $$$q$$$ lines, each containing one number — the answer to the query.

NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.

function doIt() {
    var cnt = +readline();
    for(var i = 0; i < cnt; i++) {
        var query = readline().split(' ').map(v=>+v);
        var start = query[0];
        var finish = query[1];

        var step = start % 2 ? 1 : -1;
        var diff = (finish - start + 1);

        var res = Math.floor(diff / 2) * step;
        if(diff % 2) {
            var add = finish;
            if(add % 2) add *= -1;
            res += add;
        }

        print(res);
    }
}

doIt();

var numbers = readline();

var numArr = [];
var splitArray = 0;
var sumPos = 0, sumNeg = 0;
var start = 0, end = 0;
for(var i = 0; i < numbers; i++){
   splitArray = readline().split(' ')
     numArr.push(splitArray);
}

for(var i = 0; i < numbers; i++){
     start = numArr[i][0], end = numArr[i][1];
      start = parseInt(start) ,end = parseInt(end)
      if(start%2===0 && end%2!==0){
      sumPos= Math.floor(start/2 - end/2)
      }
      if(start%2!==0 && end%2!==0){
       sumPos =  - Math.floor((start + end)/2)
      }
     if(start%2!==0 && end%2===0){
      sumPos = Math.floor(start/2 - end/2)
      }
    if(start%2===0 && end%2===0){
        sumPos =  Math.floor((start + end)/2)
      }

    if(end%2===0 && sumPos<0){sumPos = sumPos*(-1)}
    if(start === end){sumPos = end}
    if(sumPos%2!==0 && start === end){
    sumPos = sumPos*(-1)
    }
    print(sumPos)
}

solve();

function solve() {
    var q = Number(readline());
    var input, l, r, ans;
    for (;q--;) {
        input = readline().split(' ').map(Number);
        l = input[0];
        r = input[1];
        ans = 0;
        if (!(l & 1)) {
            ans += l;
            l++;
        }
        if (r & 1) {
            ans -= r;
            r--;
        }
        if (r >= l) {
            ans += (r - l + 1) / 2;
        }
        print(ans);
    }
}

// NYAN NYAN
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
// ░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
// ░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
// ░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
// ░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
// ░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
// ░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
// ░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
// ░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
// ░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
// ░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
// ░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

// 백준의 노드 버전이 너무 낮아 babel 사용.
// 풀이는 solve() 함수에 있음.

const CODEFORCES_NODE = "cf";
const CODEFORCES_V8 = "cf-v8";
const BEAKJOON = "bj";
const TEST = "test";
// var SITE = BEAKJOON;
var SITE = CODEFORCES_NODE;
var DEBUG = false;

if(SITE == BEAKJOON){
  if (!String.prototype.startsWith) {
    String.prototype.startsWith = function(search, pos) {
      return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
    };
  }
  if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
      if (this_len === undefined || this_len > this.length) {
        this_len = this.length;
      }
      return this.substring(this_len - search.length, this_len) === search;
    };
  }
  if (!String.prototype.repeat) {
    String.prototype.repeat = function(count) {
      'use strict';
      if (this == null) {
        throw new TypeError('can\'t convert ' + this + ' to object');
      }
      var str = '' + this;
      count = +count;
      if (count != count) {
        count = 0;
      }
      if (count < 0) {
        throw new RangeError('repeat count must be non-negative');
      }
      if (count == Infinity) {
        throw new RangeError('repeat count must be less than infinity');
      }
      count = Math.floor(count);
      if (str.length == 0 || count == 0) {
        return '';
      }
      // Ensuring count is a 31-bit integer allows us to heavily optimize the
      // main part. But anyway, most current (August 2014) browsers can't handle
      // strings 1 << 28 chars or longer, so:
      if (str.length * count >= 1 << 28) {
        throw new RangeError('repeat count must not overflow maximum string size');
      }
      var maxCount = str.length * count;
      count = Math.floor(Math.log(count) / Math.log(2));
      while (count) {
         str += str;
         count--;
      }
      str += str.substring(0, maxCount - str.length);
      return str;
    }
  }
}

String.prototype.replaceAt=function(index, replacement) {
  return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

Function.prototype.repeat = function(times){
  for(let i = 0; i < times; i++){
    this();
  }
}

Array.prototype.getMaxConsecutiveSum = function(defaultValue = -Infinity){
  const N = this.length;
  let maxsum = defaultValue;
  let cursum = defaultValue;
  let cur;
  for(var ii = 0; ii < N; ii++){
    cur = this[ii];
    if(cursum + cur > 0){
      if(cur > cursum + cur){
        cursum = cur;
      } else cursum += cur;
    } else {
      cursum = cur;
      if(maxsum < cursum){
        maxsum = cursum;
      }
    }
    if(maxsum < cursum){
      maxsum = cursum;
    }
  }
  this.maxConsecutiveSum = maxsum;
  return maxsum;
}

try {
  require('manakin').global;
  // require ("babel-polyfill");
} catch (error) {

}
try {
  process.argv.forEach(function (val, index, array) {
    if (val.startsWith("site")) {
      switch (val.split("=")[1]) {
        case "test":
          // console.log('change site to test')
          SITE = TEST;
          break;
        case "cf-node":
          // console.log('change site to cf')
          SITE = CODEFORCES_NODE;
          break;
        case "cf":
          // console.log('change site to cf')
          SITE = CODEFORCES_NODE;
          break;
        case "cf-v8":
          // console.log('change site to cf')
          SITE = CODEFORCES_V8;
          break;
        case "bj":
          // console.log('change site to bj')
          SITE = BEAKJOON;
          break;
      }
    }
    if (val.startsWith("debug")) {
      switch (val.split("=")[1]) {
        case "true":
          DEBUG = true;
          break;
        case "false":
          DEBUG = false;
          break;
      }
    }
  });
} catch (error) {
}

let inputFilePath = '';
switch(SITE){
  case TEST:
    const config = require('config');
    var fs = require("fs");
    var path = require('path');
    inputFilePath = config.get('INPUTFILEPATH') || path.resolve(__dirname, "input.txt");
    break;
  default:
    inputFilePath = './input.txt';
    break;
}
const INPUTFILEPATH = inputFilePath;

// if (!String.prototype.endsWith) {
// 	String.prototype.endsWith = function(search, this_len) {
// 		if (this_len === undefined || this_len > this.length) {
// 			this_len = this.length;
// 		}
// 		return this.substring(this_len - search.length, this_len) === search;
// 	};
// }
// if (!Array.prototype.includes) {
//   Array.prototype.includes = function (target) {
//     return this.indexOf(target) !== -1
//   }
// }

const newLine = '\n';
var ans;
var inputText = "";
var lineCount = 0;
var lines;
var input;
var readline;
var getlines;
var lineOpen = false;
var readingLine = '';

var clockStart;
var clock;

var print;
print = console.log;
var it;
var step;
function EnableLogging(){
  it = console.info;
  step = console.success;
}
function DisableLogging(){
  it = function it(params) {
    return 0;
  }
  step = it;
}
if (DEBUG) {
  EnableLogging();
  clock = function(start) {
    if ( !start ) return process.hrtime();
    var end = process.hrtime(start);
    return Math.round((end[0]*1000) + (end[1]/1000000));
  }
} else {
  DisableLogging();
}

// prepares test data. to replace line input, assign arrays to lines variable.
function prepareTestData() {
  // it(lines);

  // lines = ['custom line 1', 'custom line 2'];
}

// executes exactly once for both test and run. execution time will be included to elapsed time.
const prepareSolve = () => {

}

function power(x, y) {    //분할 정복을 이용하여 x^y 구하기
  let ret = 1;
  while (y > 0) {
    if (y % 2) {
        ret *= x;
        ret %= P;
    }
    x *= x;
    x %= P;
    y /= 2;
  }
  return ret;
}

function createArray(lengths) {
  var arr = new Array(lengths || 0),
    i = lengths;
  if (arguments.length > 1) {
    var args = Array.prototype.slice.call(arguments, 1);
    while (i--) arr[lengths - 1 - i] = createArray.apply(this, args);
  }
  return arr;
}

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ MAIN SOLVE FUNCTION ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

function numericSortList(list){
  list.sort((a,b)=>a-b);
}

//[-1,1,-2,2,-3,3,...]
function solve(){
  const [n] = readInts();
  let [l,r] = [0,0];

  const LIMIT = 15;
  // const LIMIT = 1000000000;

  function getSum(to){
    return (to % 2 == 0?1:-1)*(Math.ceil(to/2));
  }

  for(var t = 0; t < n; t++){
    [l,r] = readInts();

    print(getSum(r) - getSum(l-1));
  }
}

// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

function resetRead(){
  lineCount = 0;
}

function checkMemoryUsage() {
  it(process.memoryUsage());
}

function readOne(separator=' ') {
  if(lineOpen && readingLine != null){
  // if(lineOpen){
    // it(readingLine);
    let splitPos = readingLine.search(separator)

    let ret = readingLine.slice(0, splitPos);
    if(splitPos == -1){
      // it('close');
      ret = readingLine;
      readingLine = '';
      lineOpen = false;
    }
    readingLine = readingLine.substr(splitPos + 1)
    // it(ret, readingLine, splitPos);
    return ret;
  } else {
    readingLine = readline();
    lineOpen = true;
    if(readingLine == null) return '';
    return readOne(separator);
  }
}

function readInts() {
  try {
    lineOpen = false;
    return readline()
      .split(" ")
      .map(x => parseInt(x));
  } catch (error) {
    console.error(error);
    return null;
  }
}

switch (SITE) {
  case TEST:
    var fs = require("fs");
    var path = require('path');
    // input = fs.createReadStream(path.resolve(__dirname, "input.txt"), {
    //   encoding: "utf8"
    // });
    input = fs.createReadStream(INPUTFILEPATH, {
      encoding: "utf8"
    });

    function inputListener(line) {
      console.log(line);
      if(line.startsWith('end')){
        console.log('end');
        closing();
      }
      if (!line) {
        closing();
      }
      lineCount++;
      inputText += line + "\r\n";
    }

    function readlines() {
      const readline = require("readline");
      const rl = readline.createInterface({
        input,
        output: process.stdout,
        terminal: false
      });
      rl.on("line", inputListener);
      rl.on('close', closing);
    }

    getlines = function* (inputText) {
      var lines = inputText.split(/\r?\n/);
      for (let line of lines) {
        yield line + newLine;
      }
    }

    readline = function () {
      return lines.next().value.trim();
    }

    readlines();

    break;

  case CODEFORCES_NODE:
    input = process.stdin;

    function inputListener(line) {
      if (!line) {
        closing();
      }
      lineCount++;
      inputText += line + "\r\n";
    }

    function readlines() {
      const readline = require("readline");
      const rl = readline.createInterface({
        input,
        output: process.stdout,
        terminal: false
      });
      rl.on("line", inputListener);
      rl.on('close', closing);
    }

    getlines = function* (inputText) {
      var lines = inputText.split(/\r?\n/);
      for (let line of lines) {
        yield line + newLine;
      }
    }

    readline = function () {
      return lines.next().value.trim();
    }

    readlines();

    break;
  case BEAKJOON:
    var fs = require('fs');
    if (DEBUG) {
      // input = fs.readFileSync('./input.txt').toString();
      inputText = fs.readFileSync(INPUTFILEPATH).toString();

    } else {
      inputText = fs.readFileSync('/dev/stdin').toString();
    }

    readline = function () {
      lineCount++;
      let line = lines[lineCount - 1];
      if (line)
        return lines[lineCount - 1].trim();
      else return null;
    }

    getlines = function (inputText) {
      lineCount = 0;
      return inputText.split(/\r?\n/);
    }

    // lines = getlines(input);
    closing();
    break;
  default:
    break;
}

function closing() {
  if(DEBUG){
    DisableLogging();
    const prepareClock = clock();
    lines = getlines(inputText);
    prepareSolve();
    const prepareClockElapsedTime = clock(prepareClock);
    EnableLogging();
    prepareTestData();
    solve();
    resetRead();
    console.warn('performance check');
    DisableLogging();
    clockStart = clock();
    // lines = getlines(inputText);
    solve();
    console.warn(`${clock(clockStart) + prepareClockElapsedTime} ms`);
    EnableLogging();
    process.exit();
  } else {
    lines = getlines(inputText);
    prepareSolve();
    solve();
    process.exit();
  }
}

const stdin = process.stdin;
stdin.setEncoding("utf8");
let n;
let data;
stdin.on("data", function(chunk) {
  if (!n) {
    const reg = /\d*/;
    n = chunk.match(reg)[0];
    data = chunk.slice(n.toString().length + 2);
  } else {
    data += chunk;
  }
});
stdin.on("end", function() {
  const inputLines = data.split("\n").slice(0, n);
  inputLines.forEach(inputLine => {
    const [l, r] = splitAndConvert(inputLine, 2);
    const result = solve(l, r);
    console.log(result);
    // console.log(l, r, result);
  });
});
function splitAndConvert(stringOfNumbers, numOfValid) {
  return stringOfNumbers
    .split(" ")
    .slice(0, numOfValid)
    .map(function(num) {
      return parseInt(num);
    });
}
function solve(l, r) {
  const delta = r - l;
  if (delta % 2 === 1) {
    const n = (delta + 1) / 2;
    const sign = r % 2 === 0 ? 1 : -1;
    return n * sign;
  } else {
    const n = delta / 2;
    const sign = r % 2 === 0 ? 1 : -1;
    const element = l * Math.pow(-1, l);
    return element + n * sign;
  }
}

var numbers = readline();

var numArr = [];
var splitArray = 0;
var sumPos = 0, sumNeg = 0;
var start = 0, end = 0;
for(var i = 0; i < numbers; i++){
   splitArray = readline().split(' ')
     numArr.push(splitArray);
}

for(var i = 0; i < numbers; i++){
     start = numArr[i][0], end = numArr[i][1];
      start = parseInt(start) ,end = parseInt(end)
      if(start%2===0 && end%2!==0){
      sumPos= Math.floor(start/2 - end/2)
      }
      if(start%2!==0 && end%2!==0){
      sumPos= start/2 - end/2-1
      }
     if(start%2!==0 && end%2===0){
      sumPos = Math.floor(start/2 - end/2)
      }
    if(start%2===0 && end%2===0){
        sumPos =  Math.floor((start + end)/2)
      }

    if(end%2==0 && sumPos<0){sumPos = sumPos*(-1)}
    if(start === end){sumPos = end}
    if(sumPos%2!==0 && start === end){
    sumPos = sumPos*(-1)
    }
    print(sumPos)
}

var numbers = readline();

var numArr = [];
var splitArray = 0;
var sumPos = 0, sumNeg = 0;
var start = 0, end = 0;
for(var i = 0; i < numbers; i++){
   splitArray = readline().split(' ')
     numArr.push(splitArray);
}

for(var i = 0; i < numbers; i++){
     start = numArr[i][0], end = numArr[i][1];
      start = parseInt(start) ,end = parseInt(end)
      if(start*2<end && start*3!==end && end<10){
          sumPos = Math.floor(start/2 - end/2);
      }  else sumPos = start - end
      if(start*3!==end && end>10){
          sumPos = Math.ceil(end/2 - start/2);
      }

    if(start === end){sumPos = end}
    if(sumPos%2!==0 && start === end){
    sumPos = sumPos*(-1)
    }
    print(sumPos)
}

var numbers = readline();

var numArr = [];
var splitArray = 0;
var sumPos = 0, sumNeg = 0;
var start = 0, end = 0;
for(var i = 0; i < numbers; i++){
   splitArray = readline().split(' ')
     numArr.push(splitArray);
}

for(var i = 0; i < numbers; i++){
     start = numArr[i][0], end = numArr[i][1];
      start = parseInt(start) ,end = parseInt(end)
      if(start*2<end){ sumPos = start*4 - end*2}
    else sumPos = start - end
    if(start === end){sumPos = start}
    if(sumPos%2!==0){
    sumPos = -Math.abs(sumPos)
    }
    print(sumPos)
}

const stdin = process.stdin;
stdin.setEncoding("utf8");
let n;
let data;
stdin.on("data", function(chunk) {
  if (!n) {
    const reg = /\d*/;
    n = chunk.match(reg)[0];
    data = chunk.slice(n.toString().length + 1);
  } else {
    data += chunk;
  }
});
stdin.on("end", function() {
  const inputLines = data.split("\n").slice(0, n);
  inputLines.forEach(inputLine => {
    const [l, r] = splitAndConvert(inputLine, 2);
    const result = solve(l, r);
    console.log(result);
    // console.log(l, r, result);
  });
});
function splitAndConvert(stringOfNumbers, numOfValid) {
  return stringOfNumbers
    .split(" ")
    .slice(0, numOfValid)
    .map(function(num) {
      return parseInt(num);
    });
}
function solve(l, r) {
  const delta = r - l;
  if (delta % 2 === 1) {
    const n = (delta + 1) / 2;
    const sign = r % 2 === 0 ? 1 : -1;
    return n * sign;
  } else {
    const n = delta / 2;
    const sign = r % 2 === 0 ? 1 : -1;
    const element = l * Math.pow(-1, l);
    return element + n * sign;
  }
}


You are given a program that consists of $$$n$$$ instructions. Initially a single variable $$$x$$$ is assigned to $$$0$$$. Afterwards, the instructions are of two types:   increase $$$x$$$ by $$$1$$$;  decrease $$$x$$$ by $$$1$$$. You are given $$$m$$$ queries of the following format:   query $$$l$$$ $$$r$$$ — how many distinct values is $$$x$$$ assigned to if all the instructions between the $$$l$$$-th one and the $$$r$$$-th one inclusive are ignored and the rest are executed without changing the order?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the description of $$$t$$$ testcases follows. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of instructions in the program and the number of queries. The second line of each testcase contains a program — a string of $$$n$$$ characters: each character is either '+' or '-' — increment and decrement instruction, respectively. Each of the next $$$m$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$) — the description of the query. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$. The sum of $$$m$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase print $$$m$$$ integers — for each query $$$l$$$, $$$r$$$ print the number of distinct values variable $$$x$$$ is assigned to if all the instructions between the $$$l$$$-th one and the $$$r$$$-th one inclusive are ignored and the rest are executed without changing the order.

NoteThe instructions that remain for each query of the first testcase are:   empty program — $$$x$$$ was only equal to $$$0$$$;  "-" — $$$x$$$ had values $$$0$$$ and $$$-1$$$;  "---+" — $$$x$$$ had values $$$0$$$, $$$-1$$$, $$$-2$$$, $$$-3$$$, $$$-2$$$ — there are $$$4$$$ distinct values among them;  "+--+--+" — the distinct values are $$$1$$$, $$$0$$$, $$$-1$$$, $$$-2$$$.

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

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

const INF = 2e5+1;

function main () {
	let T = rn();
	while (T--) {
		let [n, m] = rna();
		let s = rl();

		s = '0' + s;
		let lmx = [], lmn = [], rmx = [], rmn = [], vl = [];

		vl[0] = 0;
		for (let i = 1; i <= n; i++) {
			vl[i] = vl[i-1] + (s[i] == '+' ? 1 : -1);
		}
		vl[n+1] = vl[n];

		lmx[0] = lmn[0] = vl[0];
		rmx[n+1] = rmn[n+1] = vl[n+1];
		for (let i = 1, smr = 0 ; i <= n; i++) {
			lmx[i] = Math.max(lmx[i-1], vl[i]);
			lmn[i] = Math.min(lmn[i-1], vl[i]);

			const j = n - i + 1;
			rmx[j] = Math.max(rmx[j+1], vl[j]);
			rmn[j] = Math.min(rmn[j+1], vl[j]);
		}

		while (m--) {
			const [l, r] = rna();
			const chng = vl[r] - vl[l-1];
			const mx = Math.max(lmx[l-1], rmx[r+1] - chng);
			const mn = Math.min(lmn[l-1], rmn[r+1] - chng);
			const ans = mx - mn + 1;

			console.log(ans);
		}
	}
}


Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.

The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Print the single number — the number of the winning squares.

NoteIn the first example two upper squares are winning.In the third example three left squares in the both middle rows are winning:5 7 8 49 5 3 21 6 6 49 5 7 3

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

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

  arr.push(d.split(' ').map(Number));

  c++;
});

rl.on('close', () => {
  let ans = 0;

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

    for (let j = 0; j < arr[i].length; j++) {
      sumCol += arr[i][j];
    }

    let z = 0;
    while (z < arr.length) {
      let sumRow = 0;
      for (let k = 0; k < arr.length; k++) {
        sumRow += arr[k][z];
      }

      if (sumRow > sumCol) {
        ans++;
      }

      z++;
    }
  }

  console.log(ans);
});

print(function(n) {

	var i, j, a = [],
		ans = 0,
		x = new Int32Array(n),
		y = new Int32Array(n);

	for (i = 0; i < n; i++)
		a.push(readline().split(' ').map(Number));

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++) {
			x[i] += a[i][j];
			y[j] += a[i][j];
		}

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (x[i] < y[j]) ans++;

	return ans;

}(+readline()));

var inp = readline().split(' ');
var n = Number(inp[0]);
var A = [];
var R = [];
var C = [];

for(var i=1; i<=n; i++)
R[i]=C[i]=0;

for(var i=1; i<=n; i++)
{
inp = readline().split(' ');
A[i]=[];
for(var j=1; j<=n; j++)
{
	A[i][j]=Number(inp[j-1]);
	R[i]+=A[i][j];
	C[j]+=A[i][j];
}
}

var ats = 0;

for(var i=1; i<=n; i++)
for(var j=1; j<=n; j++)
if(C[j] > R[i])ats++;

print(ats);

Array.prototype.sum = function () {
	var l = this.length,
		ret = 0;

	for (var i = 0; i < l; i++) {
		ret += this[i];
	}

	return ret;
}

;(function () {

	var n = +readline();

	for (var i = 0, k = []; i < n; i++) k.push(readline().split(' ').map(Number));
	for (var i = 0, s = []; i < n; i++) s.push(k[i].sum());
	for (var i = 0, c = []; i < n; i++) c.push(k.map(function (e) { return e[i]; }).sum());

	print((function () {
		for (var i = 0, ret = 0; i < n; i++)
			for (var j = 0; j < n; j++)
				ret += c[j] > s[i];
		return ret;
	})());

}).call(this);

print(function(n) {

	var i, j, a = [],
		ans = 0,
		x = new Int32Array(n),
		y = new Int32Array(n);

	for (i = 0; i < n; i++)
		a.push(readline().split(' ').map(Number));

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++) {
			x[i] += a[i][j];
			y[j] += a[i][j];
		}

	for (i = 0; i < n; i++)
		for (j = 0; j < n; j++)
			if (x[i] > y[j]) ans++;

	return ans;

}(+readline()));