Mainak has an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers. He will do the following operation to this array exactly once:  Pick a subsegment of this array and cyclically rotate it by any amount.  Formally, he can do the following exactly once:  Pick two integers $$$l$$$ and $$$r$$$, such that $$$1 \le l \le r \le n$$$, and any positive integer $$$k$$$.  Repeat this $$$k$$$ times: set $$$a_l=a_{l+1}, a_{l+1}=a_{l+2}, \ldots, a_{r-1}=a_r, a_r=a_l$$$ (all changes happen at the same time). Mainak wants to maximize the value of $$$(a_n - a_1)$$$ after exactly one such operation. Determine the maximum value of $$$(a_n - a_1)$$$ that he can obtain.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 999$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, output a single integer — the maximum value of $$$(a_n - a_1)$$$ that Mainak can obtain by doing the operation exactly once.

Note In the first test case, we can rotate the subarray from index $$$3$$$ to index $$$6$$$ by an amount of $$$2$$$ (i.e. choose $$$l = 3$$$, $$$r = 6$$$ and $$$k = 2$$$) to get the optimal array: $$$$$$[1, 3, \underline{9, 11, 5, 7}] \longrightarrow [1, 3, \underline{5, 7, 9, 11}]$$$$$$ So the answer is $$$a_n - a_1 = 11 - 1 = 10$$$. In the second testcase, it is optimal to rotate the subarray starting and ending at index $$$1$$$ and rotating it by an amount of $$$2$$$. In the fourth testcase, it is optimal to rotate the subarray starting from index $$$1$$$ to index $$$4$$$ and rotating it by an amount of $$$3$$$. So the answer is $$$8 - 1 = 7$$$.

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = y[n-1]-y[0];
        for (let i = 1; i < n;++i) {
          res = Math.max(res,y[i]-y[0]);
          res = Math.max(res,y[n-1]-y[i-1])
          res = Math.max(res,y[i-1]-y[i])
        }
        console.log(res);
    }
}

var inputString = [], currentLine = 0;
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var readline = require('readline');
var rl = readline.createInterface(process.stdin);
rl.on('line', line => { inputString.push(line) });
process.stdin.on('end', () => {  main()  });

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

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        const n = +readLine();
        const arr = readLine().split(' ').map(p => +p);
        let result = myFunc(n, arr);
        console.log(result);
    }
}

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        const n = +readLine();
        const arr = readLine().split(' ').map(p => +p);
        let result = myFunc(n, arr);
        console.log(result);
    }
}

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

'use strict';

var readline = require('readline');

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

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

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const a = await rns();
  let res = a[n - 1] - a[0],
      min = Infinity,
      max = -Infinity;
  for (let i = 0; i < n; i++) {
    if (i < n - 1) {
      res = Math.max(res, a[i] - a[i + 1]);
      min = Math.min(min, a[i]);
    }
    if (i > 0) max = Math.max(max, a[i]);
  }
  res = Math.max(res, max - a[0], a[n - 1] - min);
  return res;
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();

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

let i = 0;
rl.on('line', function(line){
    i++;
    if (i > 1 && i % 2 === 1) {
        // console.log('--->', line);
        processLine(line)
    }
})

function processLine(line) {
    const arr = line.split(' ').map(Number);
    if (arr.length < 2) {
        console.log(0);
        return;
    };
    if (arr.length === 2) {
        console.log(Math.abs(arr[1] - arr[0]));
        return;
    }
    const asIs = arr[arr.length - 1] - arr[0];
    const left = Math.max(...arr.slice(1)) - arr[0];
    const right = arr[arr.length - 1] - Math.min(...arr.slice(0, arr.length - 1));
    const pairs = [];
    for (let i = 0; i < arr.length - 1; i++) {
        pairs.push(arr[i] - arr[i+1]);
    }
    console.log(Math.max(asIs, left, right, ...pairs));
}

;
var inp = [];
var lines;
var lineCounter = 0;
var readline = function () { return lines[lineCounter++]; };
process.stdin.on('data', function (c) { return inp.push(c); });
process.stdin.on('end', function () {
    lines = inp.join('').split('\n');
    myMain();
});
function myMain() {
    var ntest = +readline();
    for (var testcase = 0; testcase < ntest; ++testcase) {
        var n = +readline();
        var a = readline().split(' ').map(function (x) { return +x; });
        var ans = a[n - 1] - a[0];
        for (var i = 0; i < n - 1; ++i) {
            ans = Math.max(ans, a[i] - a[i + 1]);
        }
        for (var i = 1; i < n; ++i) {
            ans = Math.max(ans, a[i] - a[0]);
        }
        for (var i = 0; i < n - 1; ++i) {
            ans = Math.max(ans, a[n - 1] - a[i]);
        }
        console.log(ans);
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = 0;
        for (let i = 1; i < n;++i) {
          res = Math.max(res,y[i]-y[0]);
          res = Math.max(res,y[n-1]-y[i-1])
        }
        if (n > 1) {
          res = Math.max(res,y[n-2]-y[n-1]);
        }
        console.log(res);
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = 0;
        for (let i = 1; i < n;++i) {
          res = Math.max(res,y[i]-y[0]);
          res = Math.max(res,y[n-1]-y[i-1])
        }
        console.log(res);
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        let res = 0;
        for (let i = 0; i < n;++i) {
          for (let j = 0;j < n;++j) {
            res = Math.max(res,y[i]-y[j]);
          }
        }
        console.log(res);
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
    var t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        var n = parseInt(readline());
        var x = Array.from(readline().split(" "));
        var y = [];
        for (let i = 0;i < n;++i) {
          y.push(parseInt(x[i]));
        }
        let nax = 0;
        let nin = 1000;
        for (let i = 0; i < n;++i) {
          nin = Math.min(nin,y[i]);
          nax = Math.max(nax,y[i]);
        }
        console.log(nax-nin);
    }
}

let inputString = [], currentLine = 0;
var fs = require( 'fs');
var readline = require('readline');
function read() {
   const readStream = fs.createReadStream('data', 'utf-8');
   let rl = readline.createInterface({ input: readStream });
   rl.on('line', line => { inputString.push(line) });
   readStream.on('error', (error) => console.log(error.message));
   readStream.on('end', () => {  main()  });
};
read();

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

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        const n = +readLine();
        const arr = readLine().split(' ').map(p => +p);
        let result = myFunc(n, arr);
        console.log(result);
    }
}

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

let inputString = [], currentLine = 0;
var fs = require( 'fs');
var readline = require('readline');
function read() {
   const readStream = fs.createReadStream('data.txt', 'utf-8');
   let rl = readline.createInterface({ input: readStream });
   rl.on('line', line => { inputString.push(line) });
   readStream.on('error', (error) => console.log(error.message));
   readStream.on('end', () => {  main()  });
};
read();

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

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        const n = +readLine();
        const arr = readLine().split(' ').map(p => +p);
        let result = myFunc(n, arr);
        console.log(result);
    }
}

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = arr[n-1-i] - arr[(n-i)%n];
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = Math.min(min, arr[0]);
    else arr[n-1] = Math.max(max, arr[n-1]);

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '', currentLine = 0;
process.stdin.on('data', inputStdin => { inputString += inputStdin; });
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    main();
});
function readLine() {
    return inputString[currentLine++];
}

function main() {
    const t = +readLine();
    for(let i = 0; i < t; i++){
        const n = +readLine();
        const arr = readLine().split(' ').map(p => +p);
        let result = myFunc(n, arr);
        console.log(result);
    }
}

function myFunc(n, arr){

    let min = arr[0];
    let max = arr[n-1];
    let sum_max = 0;
    let sum;
    for(let i = 0; i < n; i++){
        sum = Math.abs(arr[n-1-i] - arr[(n-i)%n]);
        // console.log('...',sum);
        if(sum > sum_max) sum_max = sum;
        if(arr[i] < min) min = arr[i];
        if(arr[i] > max) max = arr[i];
    }

    if(Math.abs(arr[0]-min) >= Math.abs(arr[n-1]-max)) arr[0] = min;
    else arr[n-1] = max;

    let sum2 = arr[n-1] - arr[0];

    return sum_max > sum2 ? sum_max : sum2;

}

'use strict';

var readline = require('readline');

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

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

async function solve(read) {
  const rn = async () => Number(await read());
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const n = await rn();
  const a = await rns();
  let res = a[n - 1] - a[0],
      min = Infinity,
      max = -Infinity;
  for (let i = 0; i < n; i++) {
    if (i < n - 1) {
      res = Math.max(res, a[i + 1] - a[i]);
      min = Math.min(min, a[i]);
    }
    if (i > 0) max = Math.max(max, a[i]);
  }
  res = Math.max(res, max - a[0], a[n - 1] - min);
  return res;
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();


You are given an array $$$a$$$ consisting of $$$n$$$ integers. In one move, you can jump from the position $$$i$$$ to the position $$$i - a_i$$$ (if $$$1 \le i - a_i$$$) or to the position $$$i + a_i$$$ (if $$$i + a_i \le n$$$).For each position $$$i$$$ from $$$1$$$ to $$$n$$$ you want to know the minimum the number of moves required to reach any position $$$j$$$ such that $$$a_j$$$ has the opposite parity from $$$a_i$$$ (i.e. if $$$a_i$$$ is odd then $$$a_j$$$ has to be even and vice versa).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$, where $$$d_i$$$ is the minimum the number of moves required to reach any position $$$j$$$ such that $$$a_j$$$ has the opposite parity from $$$a_i$$$ (i.e. if $$$a_i$$$ is odd then $$$a_j$$$ has to be even and vice versa) or -1 if it is impossible to reach such a position.

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let line = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)[0];

    let numbers = line.split(' ').map(Number);
    let result = numbers.map(_ => -1);

    const predecessorMap = {};
    numbers.forEach((v, ind) => {
        if (ind - v >= 0) {
            if (!predecessorMap[ind - v]) predecessorMap[ind - v] = [];
            predecessorMap[ind - v].push(ind);
        }
        if (ind + v < numbers.length) {
            if (!predecessorMap[ind + v]) predecessorMap[ind + v] = [];
            predecessorMap[ind + v].push(ind);
        }
    });

    let indexes = [];
    numbers.forEach((v, ind) => {
        if (ind - v >= 0 && (v + numbers[ind - v]) % 2 === 1) {
            result[ind] = 1;
            indexes.push(ind);
        } else if (ind + v < numbers.length && (v + numbers[ind + v]) % 2 === 1) {
            result[ind] = 1;
            indexes.push(ind);
        }
    });

    for (let i = 2; i < numbers.length; i++) {
        let found = 0;
        let newIndexes = [];
        indexes.forEach((ind) => {
            if (predecessorMap[ind]) {
                predecessorMap[ind].forEach(pred => {
                    if (result[pred] === -1) {
                        result[pred] = i;
                        newIndexes.push(pred);
                        found++;
                    }
                });
            }
        });
        indexes = newIndexes;
        if (found === 0) break;
    }
    console.log(result.join(' '));
});

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let line = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)[0];

    let numbers = line.split(' ').map(Number);
    let result = numbers.map((no, index) => {
        return getMoves(numbers, index);
    });

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

function getMoves(numbers, i) {
    let neededParity = (numbers[i] + 1) % 2;
    let moves = getMovesToParity(numbers, i, neededParity, {}, 0);
    return moves < Number.MAX_VALUE ? moves : -1;
}

function getMovesToParity(numbers, i, neededParity, seen, stepNo) {
    // console.log(i, neededParity, seen);
    if (i < 0 || i >= numbers.length || seen[i]) {
        return Number.MAX_VALUE;
    } else if (numbers[i] % 2 === neededParity) {
        return stepNo;
    } else {
        seen[i] = true;
        return Math.min(getMovesToParity(numbers, i - numbers[i], neededParity, seen, stepNo + 1), getMovesToParity(numbers, i + numbers[i], neededParity, seen, stepNo + 1));
    }
}

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let line = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)[0];

    let numbers = line.split(' ').map(Number);
    let result = numbers.map((no, index) => {
         return getMoves(numbers, index);
    });

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

function getMoves(numbers, i) {
    let neededParity = (numbers[i] + 1) % 2;
    let moves = getMovesToParity(numbers, i, neededParity, {});
    return moves < Number.MAX_VALUE ? moves : -1;
}

function getMovesToParity(numbers, i, neededParity, seen) {
    // console.log(i, neededParity, seen);
    if (i < 0 || i >= numbers.length || seen[i]) {
        return Number.MAX_VALUE;
    } else if (numbers[i] % 2 === neededParity) {
        return Object.keys(seen).length;
    } else {
        seen[i] = true;
        return Math.min(getMovesToParity(numbers, i - numbers[i], neededParity, seen), getMovesToParity(numbers, i + numbers[i], neededParity, seen));
    }
}

let finalInput = '';

process.stdin.setEncoding('utf-8').on('data', input => {
    finalInput += input;
});

process.stdin.setEncoding('utf-8').on('end', () => {
    let line = finalInput.split('\r\n').filter((_, i) => i >= 1).filter(l => l && l.length > 0)[0];

    let numbers = line.split(' ').map(Number);
    let result = numbers.map((no, index) => {
         return getMoves(numbers, index);
    });

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

function getMoves(numbers, i) {
    let neededParity = (numbers[i] + 1) % 2;
    let moves = getMovesToParity(numbers, i, neededParity, {});
    return moves < Number.MAX_VALUE ? moves : -1;
}

function getMovesToParity(numbers, i, neededParity, seen) {
    // console.log(i, neededParity, seen);
    if (i < 0 || i >= numbers.length || seen[i]) {
        return Number.MAX_VALUE;
    } else if (Object.keys(seen).length > 0 && numbers[i] % 2 === neededParity) {
        return Object.keys(seen).length;
    } else {
        seen[i] = true;
        return Math.min(getMovesToParity(numbers, i - numbers[i], neededParity, seen), getMovesToParity(numbers, i + numbers[i], neededParity, seen))
    }
}


There are two sisters Alice and Betty. You have $$$n$$$ candies. You want to distribute these $$$n$$$ candies between two sisters in such a way that:  Alice will get $$$a$$$ ($$$a > 0$$$) candies;  Betty will get $$$b$$$ ($$$b > 0$$$) candies;  each sister will get some integer number of candies;  Alice will get a greater amount of candies than Betty (i.e. $$$a > b$$$);  all the candies will be given to one of two sisters (i.e. $$$a+b=n$$$). Your task is to calculate the number of ways to distribute exactly $$$n$$$ candies between sisters in a way described above. Candies are indistinguishable.Formally, find the number of ways to represent $$$n$$$ as the sum of $$$n=a+b$$$, where $$$a$$$ and $$$b$$$ are positive integers and $$$a>b$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^9$$$) — the number of candies you have.

For each test case, print the answer — the number of ways to distribute exactly $$$n$$$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $$$0$$$.

NoteFor the test case of the example, the $$$3$$$ possible ways to distribute candies are:  $$$a=6$$$, $$$b=1$$$;  $$$a=5$$$, $$$b=2$$$;  $$$a=4$$$, $$$b=3$$$.

'use strict';

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

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

rl.on('close', main);

let rli = 0;
function readline() {
  return lines[rli++];
}

function main() {
  const time = parseInt(readline());
  for(let t = 0; t < time; ++t) {
    let number = Math.ceil(parseInt(readline())/2);
    if(number > 0) {
      number = number - 1;
    }
    write(`${number}\n`);
  }
  //write(`${one_line}\n`);
}

// solved by: asmjaime

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var input_lines;
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    input_lines = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function input() {
    return input_lines[currentLine++];
}
function EOF() {
    return currentLine >= input_lines.length;
}
function main() {
    var t = parseInt(input());
    for (var i = 0; i < t; i++) {
        var n = parseInt(input());
        console.log(Math.floor((n - 1) / 2));
    }
}

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

const MOD1 = 1000000007

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if (inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  let t = readInt()
  while(t--) {
    const n = readInt()
    if(n <= 2) wr(0)
    else {
      let half = Math.floor(n / 2)
      if((n & 1) === 0) wr(half - 1)
      else wr(half)
    }

  }
}

const readline = require('readline');

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

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
  for (i = 1; i < lines.length; i++) {
    if (+lines[i] > 2) {
      process.stdout.write(
        +lines[i] % 2 !== 0 ?
          `${Math.floor(+lines[i] / 2)}\n` :
          `${+lines[i] / 2 - 1}\n`
      );
    } else {
      process.stdout.write('0\n');
    }
  }
});

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var N = nextInt();
    if(N < 3){
      output[i] = 0;
    }else{
      if(N % 2 == 1){
        output[i] = Math.floor(N / 2);
      }else{
        output[i] = N / 2 - 1;
      }
    }
  }
  myout(myconv(output, 9));
}

//DISABLE THIS LINE END ENABLE NEXT
//const rl =  require('readline').createInterface({input: require('fs').createReadStream('input.txt')});
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
const print = console.log
const write = (...args) => {
    process.stdout.write(args.join(' ') );
}
const lines = []
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)

let rli = 0;
function readline() {
    return lines[rli++];
}

function main() {
	var y = +readline()
	while(y > 0) {
		var z = +readline();
		var p1 = z % 2;
		var z_corr = z - p1;
		var res = p1 +  (z_corr/2  - 1) ;
		if (res < 0) { res = 0;}
		if (y > 1) {
			write(res + '\n');
		} else {
			write(res);
		}
		y--;
	}
}

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 nr = +d;

  if (nr % 2 === 0) {
    console.log(nr / 2 - 1);
  }
  else {
    console.log(Math.floor(nr / 2));
  }

  c++;
});

const processData = (input) => {
    let exp = /\s+/;
    let arr = input.split(exp);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 === 0){
            console.log((+arr[i])/2 - 1);
        } else {
            console.log(Math.floor((+arr[i])/2))
        }
    }
}

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

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

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

const input = [];

function splitAndParseInt(line) {
  return line.split(" ").map((x) => parseInt(x));
}

readLine.on("line", (line) => input.push(line));
readLine.on("close", () => {
  const t = parseInt(input[0]);

  for (let i = 1; i <= t; i += 1) {
    const n = parseInt(input[i]);
    if (n <= 2) console.log(0);
    else {
      if (n % 2 === 0) console.log(n / 2 - 1);
      else console.log((n - 1) / 2);
    }
  }
});

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n'); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var tests = parseInt(readline());
    while (tests--) {
        var n = parseInt(readline());
        if ((n % 2) === 0) {
            console.log(Math.floor((n / 2) - 1));
        }
        else {
            console.log(Math.floor(n / 2));
        }
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input = parseInt(readline());
        if (input % 2 == 0) {
            print(parseInt((input / 2) - 1))
        }
        else {
            print(parseInt(input / 2))
        }

    }

}

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const n = +lines[i+1]
    if (n > 2) {
      console.log(Math.floor((n-1)/2))
    } else {
      console.log(0)
    }
  }
}

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

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

const main = () => {
  let t = Number(readline());
  while (t--) {
    const n = Number(readline());
    print(n - Math.ceil(n / 2) - (n % 2 === 0 ? 1 : 0));
  }
  // let t = readline().split(' ').map(x => parseInt(x));
};

function div(a, b) {
  if (a < 0) {
    throw Error('numerator must be non-negative');
  } else if (b <= 0) {
    throw Error('denominator must be positive');
  } else {
    const r = a % b;
    return (a - r) / b;
  }
}

function solve(n) {
  return ((n % 2) === 0) ? div(n - 2, 2) : div(n - 1, 2);
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    const n = Number(line);
    const result = solve(n);
    console.log(result);
  }
}

function trim_line(s) {
  return s.trim();
}

function has_content(s) {
  return (s.length > 0);
}

async function processLinesFromStream(rs, pf) {
  const chunks = [];
  const encoding = 'utf-8';
  rs.setEncoding(encoding);
  for await (let chunk of rs) {
    chunks.push(chunk);
  }
  const empty = '';
  const newline = /\n/;
  const lines = chunks.join(empty)
                      .split(newline)
                      .map(trim_line)
                      .filter(has_content);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

function div(a, b) {
  if (a < 0) {
    throw Error('numerator must be positive');
  } else if (b <= 0) {
    throw Error('denominator must be positive');
  } else {
    const r = a % b;
    return (a - r) / b;
  }
}

function solve(n) {
  return ((n % 2) === 0) ? div(n - 2, 2) : div(n - 1, 2);
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    let t = line.trim();
    if (line.length > 0) {
      const n = Number(t);
      console.log(solve(n));
    }
  }
}

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding("utf-8");
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function solve(n) {
  return Math.floor((n-1)/2);
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    // let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

var data = "";

process.stdin.on("data", x => data += x);

// process.on("SIGINT", () => {
process.stdin.on("end", () => {

    var eol = data.indexOf("\r")+1 ? (data.indexOf("\n")+1 ? "\r\n" : "\r") : "\n";

    var lines = data.split(eol);

	var lines0 = lines.shift();

    var n = lines0;

    if(lines[lines.length-1] == "") lines.pop();

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

        var arr = [];
        var l = f.length;
        for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);
        if(!l) {
            arr = lines;
            i = n;
        }
        f.apply({lines0}, arr);
    }

	console.log(ans);

    process.exit(0);
});

var ans = "";

function f(l) {
	ans += `${l > 2 ? (l-1)/2|0 : 0} `;
}

// Sample code to perform I/O:

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

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

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

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

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

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

    let inputs = str.trim().split('\n');
    let testCase = +inputs[0];
    let ways = [];
    for (let index = 1; index <= testCase; index++) {
        const element = +inputs[index];

        if (element > 2) {
            let quotient = element / 2;
            ways.push(quotient % 1 === 0 ? quotient - 1 : Math.trunc(quotient));
        }
        else {
            ways.push(0);
        }

    }

    return ways.join('\n').toString();
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let n = parseInt(readLine());
    for (var i = 0; i < n; i++) {
        let t = parseInt(readLine());
        if (t % 2 == 1) {
            console.log((t + 1) / 2 - 1)
        } else {
            if (t == 0) console.log(0)
            else
                console.log(t / 2 - 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();

function solve(x) {
    if (x % 2 === 0) {
        console.log((x/2)-1);
    } else {
        console.log(Math.floor(x/2));
    }
}

function main() {
    let n = parseInt(readline(), 10);

    for (var i = 0; i < n; i++) {
        solve(parseInt(readline()));
    }

}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const n = getInt()
    print(parseInt(n / 2) - ((n % 2) === 0))
  }
}

var n = parseInt(readline());

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

for (var i = 0; i < n; i++) {
    var a = parseInt(readline());
    var res = (a - 1) >> 1;
    write(res+'\n');
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    if(input <=2){
        print(0);
        continue;
    }
    var temp = input%2;
    if(temp === 0){
        temp = (input/2)+1;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

var t = +readline();
while(t--){
    var n = +readline();
    var ans = (n%2==0)?n/2-1:(n-1)/2;
    print(ans);
}

const n = readline();

for (var i = 0; i < n; i++) {
    var num = readline();
    print(Math.ceil(num / 2) - 1);
}

const n = readline();

for (var i = 0; i < n; i++) {
    print(Math.ceil(readline() / 2) - 1);
}

var t = parseInt(readline());

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

    if (n <= 2) {
        print(0);
    } else {
        if (n % 2 === 0) {
            print(n / 2 - 1);
        } else {
            print(Math.floor(n / 2));
        }
    }
}

var candies=readline();
// var candies=prompt();
var candiesNum=[];
for(var i=0;i<candies;i++){
    candiesNum[i]=readline();
    // candiesNum[i]=prompt();
    if(candiesNum[i]<3){
        print(0);
        // console.log("0");
    }
    else{
        if(candiesNum[i]%2===0){
            print((candiesNum[i]/2)-1);
            // console.log((candiesNum[i]/2)-1);
        }
        else{
            print(Math.floor(candiesNum[i]/2));
            // console.log(Math.floor(candiesNum[i]/2));
        }
    }
}

var str = +readline();

for (var i=0; i<str; i++) {
    var x = +readline();
     if (x <= 2) {
        write("0\n");
    } else {
        write(parseInt((x - 1) / 2) + '\n');
    }
}

var t = readline();

while (t--) {
  var n = readline();

  if (n % 2) {
    print(~~(n / 2));
  } else {
    print(~~(n / 2) - 1);
  }
}

function data()
{
	  var t=readline();
	  while(t--)
	  {
		  var n=readline();
		  print(parseInt((n-1)/2));
	  }
}
data();

var inputs = readline();

for(var k=0;k<inputs;k++) {
    var candies = readline();

    if(candies < 3) {
        print(0);
    } else {
        if(candies % 2 === 0) {
            print((candies / 2) - 1);
        } else {
            print(Math.floor(candies / 2))
        }
    }

}

var numberTestData = +readline();
for (var currentTest = 0; currentTest<numberTestData; currentTest++) {
    var numberCandies = +readline();
    if (numberCandies>2) {
        numberCandies%2===0 ? print(numberCandies/2-1) : print((numberCandies-1)/2);
    } else print(0);
}

const processData = (input) => {
    console.log(input);
}

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);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 == 0){
            console.log(arr[i]/2 - 1);
        } else {
            console.log(Math.floor(arr[i]/2))
        }
    }
}

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);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    console.log(arr);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 === 0){
            console.log((+arr[i])/2 - 1);
        } else {
            console.log(Math.floor((+arr[i])/2))
        }
    }
}

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);
    arr = arr.map(el => +el);
    let l = arr[0];
    arr = arr.slice(1);
    for (let i = 0; i < l; i++){
        if (arr[i] % 2 == 0){
            console.log((+arr[i])/2 - 1);
        } else {
            console.log(Math.floor((+arr[i])/2))
        }
    }
}

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";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var T = parseInt(readline());
    while (T--) {
        var input = parseInt(readline());
        if (input % 2 == 0) {
            print((input / 2) - 1)
        }
        else {
            print(input / 2)
        }

    }

}

var data = "";

process.stdin.on("data", x => data += x);

process.on("SIGINT", () => {
// process.stdin.on("end", () => {

    var eol = data.indexOf("\r")+1 ? (data.indexOf("\n")+1 ? "\r\n" : "\r") : "\n";

    var lines = data.split(eol);

	var lines0 = lines.shift();

    var n = lines0;

    if(lines[lines.length-1] == "") lines.pop();

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

        var arr = [];
        var l = f.length;
        for(let ii = 0; ii < l; ii++) arr.push(lines[l*i+ii]);
        if(!l) {
            arr = lines;
            i = n;
        }
        f.apply({lines0}, arr);
    }

	console.log(ans);

    process.exit(0);
});

var ans = "";

function f(l) {
	ans += `${l > 2 ? (l-1)/2|0 : 0} `;
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = readline();
    var temp = input%2;
    if(temp === 0){
        temp++;
    }else{
        temp = Math.ceil(temp);
    }
    print(input-temp)
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    var temp = input%2;
    if(temp === 0){
        temp = input/2;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    if(input <=2){
        print(0);
        continue;
    }
    var temp = input%2;
    if(temp === 0){
        temp = input/2;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

var no_of_test_cases = readline();
for(var i=0; i < no_of_test_cases; i++){
    var input = parseInt(readline());
    if(input <=2){
        print(0);
        break;
    }
    var temp = input%2;
    if(temp === 0){
        temp = input/2;
    }else{
        temp = Math.ceil(input/2);
    }
    print(input-temp)
}

const n = readline();

for (var i = 0; i < n; i++) {
    var num = readline();
    print(Math.ceil(n / 2) - 1);
}

var candies=readline();
// var candies=prompt();
var candiesNum=[];
for(var i=0;i<candies;i++){
    candiesNum[i]=readline();
    // candiesNum[i]=prompt();
    if(candiesNum[i]<3){
        print(0);
        // console.log("0");
    }
    else{
        if(candiesNum[i]%2===0){
            print((candiesNum/2)-1);
            // console.log((candiesNum[i]/2)-1);
        }
        else{
            print(Math.floor(candiesNum[i]/2));
            // console.log(Math.floor(candiesNum[i]/2));
        }
    }
}

var str = +readline();

for (var i=0; i<str; i++) {
var x = +readline();
 if (x <= 2) {
    write("0\n");
} else {
    write(parseInt(x / 2) + '\n');
}
}

function data()
{
	  var t=readline();
	  while(t--)
	  {
		  var n=readline();
		  print((n-1)/2);
	  }
}
data();

function data()
{
	  var t=readline();
	  while(t--)
	  {
		  var n=readline();
		  print(parseInt(n-1)/2);
	  }
}
data();


In the snake exhibition, there are $$$n$$$ rooms (numbered $$$0$$$ to $$$n - 1$$$) arranged in a circle, with a snake in each room. The rooms are connected by $$$n$$$ conveyor belts, and the $$$i$$$-th conveyor belt connects the rooms $$$i$$$ and $$$(i+1) \bmod n$$$. In the other words, rooms $$$0$$$ and $$$1$$$, $$$1$$$ and $$$2$$$, $$$\ldots$$$, $$$n-2$$$ and $$$n-1$$$, $$$n-1$$$ and $$$0$$$ are connected with conveyor belts.The $$$i$$$-th conveyor belt is in one of three states:  If it is clockwise, snakes can only go from room $$$i$$$ to $$$(i+1) \bmod n$$$.  If it is anticlockwise, snakes can only go from room $$$(i+1) \bmod n$$$ to $$$i$$$.  If it is off, snakes can travel in either direction.   Above is an example with $$$4$$$ rooms, where belts $$$0$$$ and $$$3$$$ are off, $$$1$$$ is clockwise, and $$$2$$$ is anticlockwise.Each snake wants to leave its room and come back to it later. A room is returnable if the snake there can leave the room, and later come back to it using the conveyor belts. How many such returnable rooms are there?

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$): the number of test cases. The description of the test cases follows.   The first line of each test case description contains a single integer $$$n$$$ ($$$2 \le n \le 300\,000$$$): the number of rooms.  The next line of each test case description contains a string $$$s$$$ of length $$$n$$$, consisting of only '<', '>' and '-'.   If $$$s_{i} = $$$ '>', the $$$i$$$-th conveyor belt goes clockwise.  If $$$s_{i} = $$$ '<', the $$$i$$$-th conveyor belt goes anticlockwise.  If $$$s_{i} = $$$ '-', the $$$i$$$-th conveyor belt is off.  It is guaranteed that the sum of $$$n$$$ among all test cases does not exceed $$$300\,000$$$.

For each test case, output the number of returnable rooms.

NoteIn the first test case, all rooms are returnable except room $$$2$$$. The snake in the room $$$2$$$ is trapped and cannot exit. This test case corresponds to the picture from the problem statement. In the second test case, all rooms are returnable by traveling on the series of clockwise belts.

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

let lineNum = 0;
let countOfData = null;
let data = [];
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line * 2;
    return;
  }

  data.push(line.split(' '));

  if(lineNum - 1 === countOfData) {
    goToSolution(data);
  }

});

function goToSolution(data) {
  for(let i = 0;i < data.length; i+=2) {
    const rooms = data[i][0];
    const directions = data[i + 1][0];
    let roomsWithReturn = 0;
    let isLeftAvailable = false;
    let isRightAvailable = false;

    if(directions[0] === '-' && directions[directions.length - 1] === '-') roomsWithReturn--;
    for(let j = 0; j < directions.length; j++) {
      const state = directions[j];
      if(state === '-') {
        directions[j - 1] === '-' ? roomsWithReturn++ : roomsWithReturn += 2;
      }
      if(state === '>') {
        isRightAvailable = true;
      }
      if(state === '<') {
        isLeftAvailable = true;
      }
    }

    if((isLeftAvailable && !isRightAvailable) || (!isLeftAvailable && isRightAvailable) || (!isLeftAvailable && !isRightAvailable)) {
      console.log(+rooms)
    } else {
      console.log(roomsWithReturn)
    }
  }

}

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 str = readLine();
    let [countD, seq, countR, countL] = [0, 0, 0, 0];

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") {
        if ((i > 0 && str[i - 1] !== "-") || i === 0) seq++;
        countD++;
      } else if (char === ">") countR++;
      else countL++;
    }

    if (str[0] === "-" && str[len - 1] === "-") seq--;

    if (countD === len || countD + countL === len || countD + countR === len || countL === len || countR === len) {
      console.log(len);
    } else {
      if (countD) {
        console.log(countD + seq);
      } else {
        console.log(0);
      }
    }
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
// alpha = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = +$()
  while (t--) {
    let n = +$(), s = $()
    if (s.includes('<') && s.includes('>')) {
      s += s[0];
      let res = 0;
      For(n, i => {
        if (s[i] == '-' || s[i + 1] == '-') res++;
      })
      log(res)
    } else {
      log(n);
    }
  }
}

let readline = require('readline');
let rl = readline.createInterface({input: process.stdin, output: process.stdout});
let lines = [];
let index = 0;
rl.on('line', line => lines.push(line.trim()));
rl.on('close', line => main());

function read() {
  return lines[index++];
}

function main(){
 let t = Number(read());
  while (t--) {
    let num = Number(read())
    let line = read().split('');
    let map = {'-': 0, '>': 0, '<': 0};
    line.forEach(key => map[key]++);
    let zeros = Object.values(map).filter(count => count === 0).length;
    if (zeros === 2 || zeros === 1 && map['-'] !== 0) {
      console.log(num)
      continue
    }
    let prev = line[line.length - 1];
    let count = 0;
    for(let i = 0; i < line.length; i++) {
      let curr = line[i];
      if (curr === '-'){
        count += (prev === '-' ? 0 : 1) + 1
      }
      prev = curr
    }
    console.log(count)
  }
}

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 => string.trim());

    main();
});

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

function main() {
    const numCases = readLine();
    for (let i = 0; i < numCases; i++) {
        const numRooms = readLine();
        let belts = readLine();
        let returnableRooms = 0;

        if (!(belts.includes('<') && belts.includes('>'))) {
            console.log(numRooms);
            continue;
        }

        const lastNonMinus = Math.max(belts.lastIndexOf('<'), belts.lastIndexOf('>'));
        const numMinusAtEnd = belts.length - lastNonMinus - 1;
        if (numMinusAtEnd > 0) {
            belts = '-'.repeat(numMinusAtEnd) + belts.slice(0, lastNonMinus + 1);
        }

        for (let k = 0; k < belts.length; k++) {
            if (belts[k] !== '-') continue;
            let end = k + 1;
            while (end < belts.length && belts[end] === '-') {
                end++;
            }
            returnableRooms += end - k + 1
            k = end;
        }
        console.log(returnableRooms);
    }
}

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 str = readLine();
    let [countD, countR, countL] = [0, 0, 0];

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") countD++;
      else if (char === ">") countR++;
      else countL++;
    }

    if (countD === len || countD + countL === len || countD + countR === len || countL === len || countR === len) {
      console.log(len);
    } else {
      if (countD) {
        console.log(countD + 1);
      } else {
        console.log(countD);
      }
    }
  }
}

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 str = readLine();
    let countDash = 0;
    let tmpStr = "";

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") countDash++;
      else tmpStr += char;
    }

    if (str.includes("><") || str.includes("<>") || tmpStr.includes("><")) {
      if (countDash) {
        console.log(countDash + 1);
      } else {
        console.log(countDash);
      }
    } else {
      console.log(len);
    }
  }
}

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 str = readLine();
    let countDash = 0;

    for (let i = 0; i < len; i++) {
      const char = str[i];
      if (char === "-") countDash++;
    }

    if (str.includes("><") || str.includes("<>")) {
      if (countDash) {
        console.log(countDash + 1);
      } else {
        console.log(countDash);
      }
    } else {
      console.log(len);
    }
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
// alpha = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = +$()
  while (t--) {
    let n = $(), s = $(), a = Arr(n, i => 0);
    For(n, i => {
      let j = i == 0 ? n - 1 : i - 1;
      if ((s[i] == '>' && s[j] == '<') || (s[i] == '<' && s[j] == '>')) a[i] = 1;
    })
    For(n, i => {
      if (a[i] != 1) return;
      let j = (i - 1 + n) % n;
      while (a[j] == 0 && s[j] != '-') {
        a[j] = 1;
        j = (j - 1 + n) % n;
      }
    })
    For(n, i => {
      if (a[i] != 1) return;
      let j = (i + 1) % n;
      while (a[j] == 0 && s[j] != '-') {
        a[j] = 1;
        j = (j + 1) % n;
      }
    })
    // log(a)
    log(n - a.sum());
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i - a] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1], i, this)) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
// alpha = "abcdefghijklmnopqrstuvwxyz"

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = +$()
  while (t--) {
    let n = $(), s = $()
    s += s[0];
    let res = 0;
    For(n, i => {
      if ((s[i] == '>' && s[i + 1] == '<') || (s[i] == '<' && s[i + 1] == '>')) res++;
    })
    log(n-res);
  }
}


One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall.Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric.

The first line contains the single integer n (1 ≤ n ≤ 100). The second line contains n space-separated integers ri (1 ≤ ri ≤ 1000) — the circles' radii. It is guaranteed that all circles are different.

Print the single real number — total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10 - 4.

NoteIn the first sample the picture is just one circle of radius 1. Inner part of the circle is painted red. The area of the red part equals π × 12 = π.In the second sample there are three circles of radii 1, 4 and 2. Outside part of the second circle is painted blue. Part between the second and the third circles is painted red. Part between the first and the third is painted blue. And, finally, the inner part of the first circle is painted red. Overall there are two red parts: the ring between the second and the third circles and the inner part of the first circle. Total area of the red parts is equal (π × 42 - π × 22) + π × 12 = π × 12 + π = 13π

print(function(n, a) {

	if (n % 2 === 1) a.push(0);

	return Math.PI * a.sort(function(a, b) {
		return b - a;
	}).map(function(v) {
		return v * v;
	}).reduce(function(sum, v, i, a) {
		if (i % 2 === 0) return sum + v - a[i + 1];
		return sum;
	}, 0);

}(+readline(), readline().split(' ').map(Number)));

print(function(n, a) {

	a = a.sort(function(a, b) {
		return a - b;
	}).map(function(v) {
		return v * v;
	});

	var sum = 0;
	for (var i = n; i >= 1; i -= 2) {
		sum += a[i] - a[i - 1];
	}

	return sum * Math.PI;

}(+readline(), ('0 ' + readline()).split(' ').map(Number)));

;(function () {
	print(function () {
		var n = +readline(), t = 0,
			a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

		if ((n%2) === 1) a.unshift(0);

		for (var i = a.length - 1; i > 0; i -= 2)
			t += Math.PI * (Math.pow(a[i], 2) - Math.pow(a[i - 1], 2));

		return t;
	}());
}).call(this);

var n = Number(readline());
var radi = readline().split(' ').map(function (e) { return Number(e); });

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

radi.sort(compareNumbers);

var pi = 3.1415926536;
var ans = 0;

for (var i=n - 1; i >= 0; i -= 2) {
	ans += pi * (radi[i] * radi[i]);
	if (i > 0) ans -= pi * (radi[i-1]*radi[i-1]);
}

print(ans);

print(function(n, a) {

	a = a.sort(function(a, b) {
		return a - b;
	}).map(function(v) {
		return v * v;
	});

	for (var i = n-2; i >= 0; i--) {
		a[i + 1] -= a[i];
	}

	var s1 = 0,
		s2 = 0;
	for (var i = 0; i < n; i++)
		if (i % 2 === 0) s1 += a[i];
		else s2 += a[i];

	return Math.max(s1, s2) * Math.PI;

}(+readline(), readline().split(' ').map(Number)));

var n = Number(readline());
var radi = readline().split(' ').map(function (e) { return Number(e); });
radi.sort();

var pi = 3.1415926536;
var ans = 0;

for (var i=n - 1; i >= 0; i -= 2) {
	ans += pi * (radi[i] * radi[i]);
	if (i > 0) ans -= pi * (radi[i-1]*radi[i-1]);
}

print(ans);


Colossal! — exclaimed Hawk-nose. — A programmer! That's exactly what we are looking for.Arkadi and Boris Strugatsky. Monday starts on SaturdayReading the book "Equations of Mathematical Magic" Roman Oira-Oira and Cristobal Junta found an interesting equation: $$$a - (a \oplus x) - x = 0$$$ for some given $$$a$$$, where $$$\oplus$$$ stands for a bitwise exclusive or (XOR) of two integers (this operation is denoted as ^ or xor in many modern programming languages). Oira-Oira quickly found some $$$x$$$, which is the solution of the equation, but Cristobal Junta decided that Oira-Oira's result is not interesting enough, so he asked his colleague how many non-negative solutions of this equation exist. This task turned out to be too difficult for Oira-Oira, so he asks you to help.

Each test contains several possible values of $$$a$$$ and your task is to find the number of equation's solution for each of them. The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of these values. The following $$$t$$$ lines contain the values of parameter $$$a$$$, each value is an integer from $$$0$$$ to $$$2^{30} - 1$$$ inclusive.

For each value of $$$a$$$ print exactly one integer — the number of non-negative solutions of the equation for the given value of the parameter. Print answers in the same order as values of $$$a$$$ appear in the input. One can show that the number of solutions is always finite.

NoteLet's define the bitwise exclusive OR (XOR) operation. Given two integers $$$x$$$ and $$$y$$$, consider their binary representations (possibly with leading zeroes): $$$x_k \dots x_2 x_1 x_0$$$ and $$$y_k \dots y_2 y_1 y_0$$$. Here, $$$x_i$$$ is the $$$i$$$-th bit of the number $$$x$$$ and $$$y_i$$$ is the $$$i$$$-th bit of the number $$$y$$$. Let $$$r = x \oplus y$$$ be the result of the XOR operation of $$$x$$$ and $$$y$$$. Then $$$r$$$ is defined as $$$r_k \dots r_2 r_1 r_0$$$ where:$$$$$$ r_i = \left\{ \begin{aligned} 1, ~ \text{if} ~ x_i \ne y_i \\ 0, ~ \text{if} ~ x_i = y_i \end{aligned} \right. $$$$$$For the first value of the parameter, only $$$x = 0$$$ is a solution of the equation.For the second value of the parameter, solutions are $$$x = 0$$$ and $$$x = 2$$$.

var length = +readline();
var cnts = [];

for(var i = 0; i < length; i++) {
    var number = +readline();
    var cnt = 1;

    while(number) {
        var rest = number % 2;
        number = Math.round(number / 2) - rest;

        if(rest) cnt *= 2;
    }

    cnts.push(cnt);
}

cnts.forEach(v => print(v));

var n = +readline();

for (var i=0; i<n; i++){
	var q = +readline();
	q = q.toString(2);
	var numown = 0;
		for (var j=0; j<q.length; j++){
			numown += parseInt(q[j]);
		}
	print (Math.pow(2, numown));
}


You are given a list of $$$n$$$ integers. You can perform the following operation: you choose an element $$$x$$$ from the list, erase $$$x$$$ from the list, and subtract the value of $$$x$$$ from all the remaining elements. Thus, in one operation, the length of the list is decreased by exactly $$$1$$$.Given an integer $$$k$$$ ($$$k>0$$$), find if there is some sequence of $$$n-1$$$ operations such that, after applying the operations, the only remaining element of the list is equal to $$$k$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2\cdot 10^5$$$, $$$1 \leq k \leq 10^9$$$), the number of integers in the list, and the target value, respectively. The second line of each test case contains the $$$n$$$ integers of the list $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases is not greater that $$$2 \cdot 10^5$$$.

For each test case, print YES if you can achieve $$$k$$$ with a sequence of $$$n-1$$$ operations. Otherwise, print NO. You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as a positive answer).

NoteIn the first example we have the list $$$\{4, 2, 2, 7\}$$$, and we have the target $$$k = 5$$$. One way to achieve it is the following: first we choose the third element, obtaining the list $$$\{2, 0, 5\}$$$. Next we choose the first element, obtaining the list $$$\{-2, 3\}$$$. Finally, we choose the first element, obtaining the list $$$\{5\}$$$.

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});
  let ans = isPairSum(line, n, k);
  console.log(ans);
}

function isPairSum (a, n, x) {
  let i = 0;
  let j = 1;
  x = Math.abs(x);
  while (i < n && j < n) {
    if (a[i] + x === a[j]) return "YES";
    else if (a[i] + x < a[j]) i++;
    else j++;
  }
  return "NO";
}

// load('js/subtract_operation.js')

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

const EPS = 1e-6;

function main() {
    let T = +readline();
    while (T--){
      let [n, k] = readline().split(' ').map(a=>+a);
      let arr = readline().split(' ').map(a=>+a);
      let set = new Set();
      let set2 = new Set();
      let yes = false;
      for (let i=0; i<n; i++){
        if (set.has(arr[i]-k) || set2.has(arr[i]))
        {
          yes = true
          break;
        }
        set.add(arr[i])
        set2.add(arr[i]-k)
      }
      print(yes ? 'yes' : 'no')
    }
}

const solve = (n,arr,k)=>{
     arr = arr.sort((a,b)=>a-b);
     let i=0;j=1,ans = false;
     if(n===1) ans = arr[0]===k;
     else{
          while(i<n && j<n){
               if(arr[i]+k===arr[j]){
                    ans = true;
                    break;
               }
               if(arr[i]+k<=arr[j]) i++;
               else j++;
          }
     }
     return ans?"YES":"NO";
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let [n,k] = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(n,arr,k));
  }
}
main();

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});
  let ans = isPairSum(line, n, k);

  console.log(ans);
}

function isPairSum (a, n, x) {
  let i = 0;
  let j = n-1;

  while (i < j) {
    if (a[j] - a[i] == x) return "YES";
    else if (a[j] - a[i] < x) i++;
    else j--;
  }
  return "NO";
}
// load('js/cf.js')

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  var t = +(readline());
  console.log(t);
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  let t = +(readline());
  console.log(t);
  while (t--) {
    solution();
  }
}

function solution() {
  console.log("solution");
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  let t = +(readline());
  console.log("main");
  while (t--) {
    solution();
  }
}

function solution() {
  console.log("solution");
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();
// load('js/cf.js')

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  console.log("Solution");
  const param = readline().split(" ");
  console.log(param);
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});
  console.log('n : ' + n + ', k :' + k);
  console.log(line);

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();

"use strict";

//..................................import for reading input...................................//
  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.split("\n");
    main();
  });
  function readline() {
    return inputString[currentLine++];
  }
//............................................................................................//

function main() {
  var t = +(readline());
  while (t--) {
    solution();
  }
}

function solution() {
  const param = readline().split(" ");
  const n = +(param[0]);
  const k = +(param[1]);
  const line = readline().split(" ").map((el) => {return +el}).sort((a,b) => {return a - b});

  let ans = false;
  outer:
  for(let i = n-1; i > 0; i--) {
    for (let j = i-1; j >= 0; j--) {
      if(line[i]-line[j] === k) {
        ans = true;
        break outer;
      }
    }
  }

  if (ans) {
    console.log("YES");
  }
  else console.log("NO");
}

main();
// load('js/cf.js')

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

const EPS = 1e-6;

function main() {
    let T = +readline();
    while (T--){
      let [n, k] = readline().split(' ').map(a=>+a);
      let arr = readline().split(' ').map(a=>+a);
      let set = new Set();
      let yes = false;
      for (let i=0; i<n; i++){
        if (set.has(arr[i]+k))
        {
          yes = true
          break;
        }
        set.add(arr[i])
      }
      print(yes ? 'yes' : 'no')
    }
}

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

const EPS = 1e-6;

function main() {
    let T = +readline();
    while (T--){
      let [n, k] = readline().split(' ').map(a=>+a);
      let arr = readline().split(' ').map(a=>+a);
      let minI = -1, maxI = -1;
      for (let i=0; i<n; i++){
        if (minI==-1 || arr[minI]<arr[i])
          minI = i;
        if (maxI==-1 || arr[maxI]>arr[i])
          maxI = i;
      }
      print(arr[minI]-arr[maxI]==k ? 'yes' : 'no')
    }
}