This is the hard version of the problem. The only difference between the versions is the constraints on $$$n$$$, $$$k$$$, $$$a_i$$$, and the sum of $$$n$$$ over all test cases. You can make hacks only if both versions of the problem are solved.Note the unusual memory limit.You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$ of length $$$n$$$, and an integer $$$k$$$.The cost of an array of integers $$$p_1, p_2, \ldots, p_n$$$ of length $$$n$$$ is $$$$$$\max\limits_{1 \le i \le n}\left(\left \lfloor \frac{a_i}{p_i} \right \rfloor \right) - \min\limits_{1 \le i \le n}\left(\left \lfloor \frac{a_i}{p_i} \right \rfloor \right).$$$$$$Here, $$$\lfloor \frac{x}{y} \rfloor$$$ denotes the integer part of the division of $$$x$$$ by $$$y$$$. Find the minimum cost of an array $$$p$$$ such that $$$1 \le p_i \le k$$$ for all $$$1 \le i \le n$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_1 \le a_2 \le \ldots \le a_n \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single integer — the minimum possible cost of an array $$$p$$$ satisfying the condition above.

NoteIn the first test case, the optimal array is $$$p = [1, 1, 1, 2, 2]$$$. The resulting array of values of $$$\lfloor \frac{a_i}{p_i} \rfloor$$$ is $$$[4, 5, 6, 4, 5]$$$. The cost of $$$p$$$ is $$$\max\limits_{1 \le i \le n}(\lfloor \frac{a_i}{p_i} \rfloor) - \min\limits_{1 \le i \le n}(\lfloor \frac{a_i}{p_i} \rfloor) = 6 - 4 = 2$$$. We can show that there is no array (satisfying the condition from the statement) with a smaller cost.In the second test case, one of the optimal arrays is $$$p = [12, 12, 12, 12, 12]$$$, which results in all $$$\lfloor \frac{a_i}{p_i} \rfloor$$$ being $$$0$$$.In the third test case, the only possible array is $$$p = [1, 1, 1]$$$.

'use strict';

function solve(n, m, a) {
  const N = Math.min(...a);
  const max = new Array(N + 10).fill(-1);
  max[N] = N;
  let min = 1;
  for (let num of a) {
    const tmp = Math.floor(num / m);
    min = Math.max(min, tmp);
    let p = num;
    for (let i = Math.max(2, Math.floor(num / N)); i <= N; i++) {
      const cur = Math.floor(num / i);
      if (cur === p) {
        break;
      }
      if (cur <= N) {
        max[cur + 1] = Math.max(max[cur + 1], p);
      }
      p = cur;
    }
  }
  let res = Infinity;
  let p = -1;
  for (let i = 1; i <= N; i++) {
    p = Math.max(p, max[i]);
    res = Math.min(res, Math.max(min, p) - i);
  }
  return res === Infinity ? Math.max(min - N, 0) : Math.max(res, 0);
}

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(n, m, a) {
  a = [...new Set(a)];
  n = a.length;
  let max = 0;
  const p = new Array(n).fill(m),
        b = Array.from({
    length: n
  }, (_, i) => {
    const num = Math.floor(a[i] / m);
    max = Math.max(max, num);
    return num;
  });
  const heap = new Heap((i, j) => b[i] - b[j], [...new Array(n).keys()]);
  let res = max;
  let count = 0;
  while (true) {
    const i = heap.pop();
    const cur = res;
    res = Math.min(res, max - b[i]);
    if (res === cur) count++;else count = 0;
    if (count === Math.max(n, 1000)) break;
    if (res === 0) return 0;
    if (p[i] === 1) break;
    b[i]++;
    p[i] = Math.floor(a[i] / b[i]);
    b[i] = Math.floor(a[i] / p[i]);
    max = Math.max(max, b[i]);
    heap.push(i);
  }
  return res;
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(n, m, a) {
  a = [...new Set(a)];
  n = a.length;
  let max = 0;
  const p = new Array(n).fill(m),
        b = Array.from({
    length: n
  }, (_, i) => {
    const num = Math.floor(a[i] / m);
    max = Math.max(max, num);
    return num;
  });
  const heap = new Heap((i, j) => b[i] - b[j], [...new Array(n).keys()]);
  let res = max;
  let count = 0;
  while (true) {
    const i = heap.pop();
    const cur = res;
    res = Math.min(res, max - b[i]);
    if (res === cur) count++;else count = 0;
    if (count === n) break;
    if (res === 0) return 0;
    if (p[i] === 1) break;
    b[i]++;
    p[i] = Math.floor(a[i] / b[i]);
    b[i] = Math.floor(a[i] / p[i]);
    if (p[i] === 1) break;
    max = Math.max(max, b[i]);
    heap.push(i);
  }
  return res;
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(n, m, a) {
  a = [...new Set(a)];
  n = a.length;
  let max = 0;
  const p = new Array(n).fill(m),
        b = Array.from({
    length: n
  }, (_, i) => {
    const num = Math.floor(a[i] / m);
    max = Math.max(max, num);
    return num;
  });
  const heap = new Heap((i, j) => b[i] - b[j], [...new Array(n).keys()]);
  let res = max;
  let count = 0;
  while (true) {
    const i = heap.pop();
    const cur = res;
    res = Math.min(res, max - b[i]);
    if (res === cur) count++;else count = 0;
    if (count === n) break;
    if (res === 0) return 0;
    if (p[i] === 1) break;
    b[i]++;
    p[i] = Math.floor(a[i] / b[i]);
    b[i] = Math.floor(a[i] / p[i]);
    if (p[i] === 1) break;
    max = Math.max(max, b[i]);
    heap.push(i);
  }
  return res;
}
class Heap {
  constructor(_comparator, arr) {
    _defineProperty(this, "_heap", []);
    this._comparator = _comparator;
    if (arr) {
      this._heap = [...arr];
      for (let i = arr.length >> 1; i; i--) this.down(i);
    }
  }
  swap(i, j) {
    [this._heap[i], this._heap[j]] = [this._heap[j], this._heap[i]];
  }
  _has(i) {
    return Object.prototype.hasOwnProperty.call(this._heap, i);
  }
  comparator(i, j) {
    return this._comparator(this._heap[i], this._heap[j]) < 0;
  }
  parent(i) {
    return i - 1 >> 1;
  }
  children(i) {
    return [2 * i + 1, 2 * i + 2];
  }
  up(i) {
    let parent = this.parent(i);
    while (i > 0 && this.comparator(i, parent)) {
      this.swap(i, parent);
      [i, parent] = [parent, parent - 1 >> 1];
    }
  }
  down(i) {
    let [left, right] = this.children(i);
    while (left < this._heap.length) {
      if (!this._has(right)) right = left;
      if (this.comparator(right, left)) [left, right] = [right, left];
      if (this.comparator(i, left)) break;
      this.swap(i, left);
      i = left;
      [left, right] = [2 * i + 1, 2 * i + 2];
    }
  }
  push(node) {
    this._heap.push(node);
    this.up(this._heap.length - 1);
  }
  pop() {
    if (this.size() === 0) return null;
    let res = this._heap[0];
    this.swap(0, this._heap.length - 1);
    this._heap.pop();
    this.down(0);
    return res;
  }
  remove(i) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this.swap(i, this._heap.length - 1);
    this._heap.pop();
    this.down(i);
    this.up(i);
    return res;
  }
  modify(i, val) {
    if (i >= this.size()) return;
    let res = this._heap[i];
    this._heap[i] = val;
    this.down(i);
    this.up(i);
    return res;
  }
  top() {
    if (this.size() === 0) return null;
    return this._heap[0];
  }
  size() {
    return this._heap.length;
  }
}
let n = 100000,
    a = [];
for (let i = 0; i < n; i++) {
  a.push(i + 950);
}
console.log(n, solve(n, 600, a));

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, m, a) {
  const N = Math.min(...a);
  const max = new Array(N + 10).fill(-1);
  max[N] = N;
  let min = 1;
  for (let num of a) {
    const tmp = Math.floor(num / m);
    min = Math.max(min, tmp);
    let p = num;
    for (let i = Math.max(2, Math.floor(num / N)); i <= N; i++) {
      const cur = Math.floor(num / i);
      if (cur === p) {
        break;
      }
      if (cur <= N) {
        max[cur + 1] = Math.max(max[cur + 1], p);
      }
      p = cur;
    }
  }
  let res = Infinity;
  let p = -1;
  for (let i = 1; i <= N; i++) {
    p = Math.max(p, max[i]);
    res = Math.min(res, Math.max(min, p) - i);
  }
  return res === Infinity ? Math.max(min - N, 0) : res;
}

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

function solve(n, m, a) {
  const N = Math.min(...a);
  const max = new Array(N + 10).fill(-1);
  max[N] = N;
  let min = 1;
  for (let num of a) {
    const tmp = Math.floor(num / m);
    min = Math.max(min, tmp);
    let p = num;
    for (let i = Math.max(2, Math.floor(num / N)); i <= N; i++) {
      const cur = Math.floor(num / i);
      if (cur === p) {
        break;
      }
      if (cur <= N) {
        max[cur + 1] = Math.max(max[cur + 1], p);
      }
      p = cur;
    }
  }
  let res = Infinity;
  let p = -1;
  for (let i = 1; i <= N; i++) {
    p = Math.max(p, max[i]);
    res = Math.min(res, Math.max(min, p) - i);
  }
  return res === Infinity ? min - N : res;
}

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

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});


Alice and Bob play a game. They have a binary string $$$s$$$ (a string such that each character in it is either $$$0$$$ or $$$1$$$). Alice moves first, then Bob, then Alice again, and so on.During their move, the player can choose any number (not less than one) of consecutive equal characters in $$$s$$$ and delete them.For example, if the string is $$$10110$$$, there are $$$6$$$ possible moves (deleted characters are bold):  $$$\textbf{1}0110 \to 0110$$$;  $$$1\textbf{0}110 \to 1110$$$;  $$$10\textbf{1}10 \to 1010$$$;  $$$101\textbf{1}0 \to 1010$$$;  $$$10\textbf{11}0 \to 100$$$;  $$$1011\textbf{0} \to 1011$$$. After the characters are removed, the characters to the left and to the right of the removed block become adjacent. I. e. the following sequence of moves is valid: $$$10\textbf{11}0 \to 1\textbf{00} \to 1$$$.The game ends when the string becomes empty, and the score of each player is the number of $$$1$$$-characters deleted by them.Each player wants to maximize their score. Calculate the resulting score of Alice.

The first line contains one integer $$$T$$$ ($$$1 \le T \le 500$$$) — the number of test cases. Each test case contains exactly one line containing a binary string $$$s$$$ ($$$1 \le |s| \le 100$$$).

For each test case, print one integer — the resulting score of Alice (the number of $$$1$$$-characters deleted by her).

NoteQuestions about the optimal strategy will be ignored.

var N = parseInt(readline());
var s = [];
for (var i=0; i < N; i++) {
  s.push(readline());
}
for (var n=0; n < N; n++) {
  ones = [];
  var count = 0;
  for (var i=0; i < s[n].length; i++) {
    if (s[n][i] === '1') {
      count += 1;
    } else {
      if (count) {
        ones.push(count);
        count = 0;
      }
    }
  }
  if (count) {
    ones.push(count);
  }
  // sort in descending order
  var onessorted = ones.sort((a, b) => b - a);
  var sum = 0;
  for (var i=0; i < onessorted.length; i += 2) {
    sum += onessorted[i];
  }
  print(sum)
}

var readline=require('readline');
var rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
var arr=[];
rl.on('line',function(inp){
    arr.push(inp);
    var len=arr.length;
    if(len>1){
        var s=arr[arr.length-1],
            a=[],
            ans=0,
            sum=0;
        for(var i=0;i<s.length;i++){
            if(parseInt(s[i])===1) ans++;
            else if(ans!==0){
                a.push(ans);
                ans=0;
            }
        }
        if(ans!==0) a.push(ans),ans=0;
        a.sort(function(x,y){
            if(x>y) return -1;
            else if(x===y) return 0;
            else return 1;
        });
        for(var i=0;i<a.length;i+=2)  sum+=a[i];
        console.log(sum);
    }
    if(len===parseInt(arr[0])+1) process.exit(0);
});

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let store = [];
    let count = 0;
    let result = 0;

    for (let i = 0; i < str.length; i++) {
      const num = str[i];
      if (num === "1") {
        count++;
      } else {
        count && store.push(count);
        count = 0;
      }
    }
    if (count) store.push(count);
    store.sort((a, b) => b - a);

    for (let i = 0; i < store.length; i += 2) {
      result += store[i];
    }

    console.log(result);
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const a = readLine().split(/0+/).map(el => el.length).sort((a, b) => b - a);
    let result = 0;
    for (let i = 0; i < a.length; i += 2) {
      result += a[i];
    }
    console.log(result);
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    // const a = readLine().split(/0+/).map(el => el.length).sort().reverse();
    const a = readLine().split(/0+/).sort((a, b) => b.length - a.length);
    let result = 0;
    for (let i = 0; i < a.length; i += 2) {
      result += a[i].length;
    }
    console.log(result);
    // console.log(a.reduce((acc, cur, idx) => acc + ((idx % 2 === 0) ? cur : 0), 0));
  }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
  const t = Number(readLine())
  for (let i = 0; i < t; i++) {
	const ones = readLine().split(/0+/).sort((a, b) => b.length - a.length)
    const length = ones.length
    let result = 0
    for (let i = 0; i < length; i += 2) {
      result += ones[i].length
    }
    console.log(result)
  }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var inputArray = [];
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    inputArray = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function readline() {
    return inputArray[currentLine++];
}
function main() {
    var t = parseInt(readline());
    for (var i = 0; i < t; i++) {
        var s = readline();
        var lengths = [];
        var count = 0;
        for (var _i = 0, s_1 = s; _i < s_1.length; _i++) {
            var c = s_1[_i];
            if (c == "1") {
                count++;
            }
            else if (count > 0) {
                lengths.push(count);
                count = 0;
            }
        }
        if (count > 0)
            lengths.push(count);
        lengths.sort(function (a, b) { return a - b; });
        var answer = 0;
        for (var j = lengths.length - 1; j >= 0; j -= 2) {
            answer += lengths[j];
        }
        console.log(answer);
    }
}

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

var dp = {};

function fibonacci(n) {
	if (n === 0) return 0;
	if (n === 1) return 1;

	if (dp[n] !== undefined) return dp[n];
	let result = fibonacci(n - 1) + fibonacci(n - 2);
	return (dp[n] = result);
}

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

function gcdArr() {
	let args = arguments;
	let res = args[0];
	let { length } = args;
	for (let i = 1; i < length; i++) {
		res = gcd(res, args[i]);
	}
	return res;
}

function main() {
	let t = readLine() >> 0;
	while (t--) {
		let s = readLine().split('');
		let l = s.length;
		let cons = [];
		let i = 0;
		while (i < l) {
			if (s[i] == '1') {
				i++;
				let c = 1,
					j = i + 1;
				while (s[i] !== undefined && s[i] == '1') {
					c++;
					i++;
				}
				cons.push(c);
			} else {
				i++;
			}
		}

		let total = 0;
		if (cons.length === 0) {
			console.log(0);
		} else {
			cons.sort((a, b) => b - a);
			for (let i = 0; i < cons.length; i += 2) {
				total += cons[i];
			}
			console.log(total);
		}
	}
}

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 = parseInt(readLine());
    for (let c = 0; c < numCases; c++) {
        let bstring = readLine();
        let alice = 0;
        while (bstring.length > 0) {
            const result = play(bstring);
            alice += result.points;
            bstring = result.bstring;

            bstring = play(bstring).bstring; // bob
        }
        console.log(alice);
    }
}

function play(s) {
    if (s.length === 0) return {
        points: 0,
        bstring: ""
    };

    const chain = longestChain(s);
    if (chain.length > 0) {
        return {
            points: chain.length,
            bstring: s.substring(0, chain.index) + s.substring(chain.index + chain.length)
        }
    } else {
        return {
            points: 0,
            bstring: ""
        }
    }
}

function longestChain(s) {
    let max = 0;
    let index = -1;

    let current = 0;
    let currentIndex = -1;
    for (let i = 0; i < s.length; i++) {
        if (s[i] === '1') {
            current++;
            if (currentIndex === -1) {
                currentIndex = i;
            }
        } else {
            if (current > max) {
                max = current;
                index = currentIndex;
            }
            current = 0;
            currentIndex = -1;
        }
    }
    if (current > max) {
        max = current;
        index = currentIndex;
    }
    return {
        index,
        length: max
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());
    for(let o = 0; o < t; o++){
        let s = readline();

        let arr = [];
        for(let i = 0; i < s.length; i++){
            if(s.charAt(i) === '1'){
                let st = i;
                let en = i;
                while(en < s.length && s.charAt(en) !== '0'){
                    en++;
                }
                arr.push(en-st);
                i = en;
            }
        }

        //console.log(arr);
        arr.sort((a,b) => b-a);
        let count = 0;
        for(let i = 0; i < arr.length; i++){
            if(i % 2 === 0)
                count += arr[i];
        }

        console.log(count);
    }
}

'use strict';

var readline = require('readline');

function _slicedToArray(arr, i) {
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}

function _toConsumableArray(arr) {
  return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}

function _arrayWithoutHoles(arr) {
  if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}

function _arrayWithHoles(arr) {
  if (Array.isArray(arr)) return arr;
}

function _iterableToArray(iter) {
  if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}

function _iterableToArrayLimit(arr, i) {
  if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
  var _arr = [];
  var _n = true;
  var _d = false;
  var _e = undefined;

  try {
    for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
      _arr.push(_s.value);

      if (i && _arr.length === i) break;
    }
  } catch (err) {
    _d = true;
    _e = err;
  } finally {
    try {
      if (!_n && _i["return"] != null) _i["return"]();
    } finally {
      if (_d) throw _e;
    }
  }

  return _arr;
}

function _unsupportedIterableToArray(o, minLen) {
  if (!o) return;
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  var n = Object.prototype.toString.call(o).slice(8, -1);
  if (n === "Object" && o.constructor) n = o.constructor.name;
  if (n === "Map" || n === "Set") return Array.from(o);
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}

function _arrayLikeToArray(arr, len) {
  if (len == null || len > arr.length) len = arr.length;

  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];

  return arr2;
}

function _nonIterableSpread() {
  throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

function _nonIterableRest() {
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}

/**
 * Reads the number of tests line followed by one line per test. It passes each test line to the callback
 */

function tStdinReader(cb) {
  var stdin = readline.createInterface(process.stdin);
  var tests = null;
  stdin.on('line', function (line) {
    if (tests === null) {
      tests = +line;
    } else {
      cb(line);

      if (--tests === 0) {
        stdin.close();
      }
    }
  });
}

tStdinReader(function (line) {
  var result = _toConsumableArray(line.matchAll(/1+/g));

  var counts = result.map(function (_ref) {
    var _ref2 = _slicedToArray(_ref, 1),
        match = _ref2[0];

    return match.length;
  }).sort(function (a, b) {
    return b - a;
  }).filter(function (_, i) {
    return i % 2 === 0;
  }).reduce(function (sum, x) {
    return sum + x;
  }, 0);
  console.log(counts);
});

//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 (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var s = nextCharArray();
    var count = [0];
    for(var j = 0; j < s.length; j++){
      if(s[j] == "1"){
        count[count.length - 1]++;
      }else{
        count.push(0);
      }
    }
    count.sort(function(a,b){
    	return b - a;
    });
    var add = 0;
    for(var j = 0; j < count.length; j++){
      if(j % 2 == 0){
        add += count[j];
      }
    }
    output[i] = add;
  }
  myout(myconv(output, 9));
}
//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 (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var s = nextCharArray();
    var count = [0];
    for(var j = 0; j < s.length; j++){
      if(s[j] == "1"){
        count[count.length - 1]++;
      }else{
        count.push(0);
      }
    }
    count.sort(function(a,b){
    	return b - a;
    });
    var add = 0;
    for(var j = 0; j < count.length; j++){
      if(j % 2 == 0){
        add += count[j];
      }
    }
    output[i] = add;
  }
  myout(myconv(output, 9));
}

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

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
//process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const a = readLine().split(/0+/).map(el => el.length).sort().reverse();
    let result = 0;
    for (let i = 0; i < a.length; i += 2) {
      result += a[i];
    }
    console.log(result);
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const str = readLine();
    let count = 0;
    const b = [];
    for (var i = 0; i < str.length; i++) {
      if (str.charAt(i) === '1') {
        count++;
      } else if (count) {
        b.push(count);
        count = 0;
      }
    }
    b.push(count);
    b.sort().reverse();
    let res = 0;
    for (var i = 0; i < b.length; i += 2) {
      res += b[i]
    }
    console.log(res);
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const a = readLine().split(/0+/).map(el => el.length).sort().reverse();
    console.log(a.reduce((acc, cur, idx) => acc + ((idx % 2 === 0) ? cur : 0), 0));
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const a = readLine().split(/0+/).map(el => el.length).sort().reverse();
    let result = 0;
    for (let i = 0; i < a.length; i += 2) {
      result += a[i];
    }
    console.log(result);
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  let rr = 0;
  while (t--) {
    const a = readLine().split(/0+/).map(el => el.length).sort().reverse();
    let result = 0;
    for (let i = 0; i < a.length; i += 2) {
      result += a[i];
    }
    console.log(result);
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const a = readLine().split('0').map(el => el.length).sort().reverse();
    console.log(a.reduce((acc, cur, idx) => acc + ((idx % 2 === 0) ? cur : 0), 0));
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    // const a = readLine().split(/0+/).map(el => el.length).sort().reverse();
    const a = readLine().split(/0+/).map(el => el.length).sort((a, b) => b - a);
    let result = 0;
    for (let i = 0; i < a.length; i += 2) {
      result += a[i].length;
    }
    console.log(result);
    // console.log(a.reduce((acc, cur, idx) => acc + ((idx % 2 === 0) ? cur : 0), 0));
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    console.log(readLine().split('0').map(el => el.length).sort().reverse());
  }
}

let inputString = '';
let currentLine = 0;

const runMain = () => {
  inputString = inputString.trim().split('\n').map(string => string.trim());
  main();
  process.exit();
}
const readLine = () => inputString[currentLine++];

process.stdin.on('data', inputStdin => inputString += inputStdin);
process.stdin.on('end', runMain);
process.on('SIGINT', runMain);

function main() {
  let t = readLine();
  while (t--) {
    const str = readLine();
    let count = 0;
    const b = [];
    for (var i = 0; i < str.length; i++) {
      if (str.charAt(i) === '1') {
        count++;
      } else if (count) {
        b.push(count);
        count = 0;
      }
    }
    count && b.push(count);
    b.sort().reverse();
    let res = 0;
    for (var i = 0; i < b.length; i += 2) {
      res += b[i]
    }
    console.log(b);
    console.log(res);
  }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var inputArray = [];
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    inputArray = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function readline() {
    return inputArray[currentLine++];
}
function main() {
    var t = parseInt(readline());
    for (var i = 0; i < t; i++) {
        var s = readline();
        var lengths = [];
        var count = 0;
        for (var j = 0; j < s.length; j++) {
            if (s.charAt(j) == "1") {
                count++;
            }
            else if (s.charAt(j) == "0" && count > 0) {
                lengths.push(count);
                count = 0;
            }
        }
        if (count > 0)
            lengths.push(count);
        lengths.sort();
        var answer = 0;
        for (var j = lengths.length - 1; j >= 0; j -= 2) {
            answer += lengths[j];
        }
        console.log(answer);
    }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var inputArray = [];
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    inputArray = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function readline() {
    return inputArray[currentLine++];
}
function main() {
    var t = parseInt(readline());
    for (var i = 0; i < t; i++) {
        var s = readline();
        var lengths = [];
        var count = 0;
        for (var j = 0; j < s.length; j++) {
            if (s.charAt(j) == "1") {
                count++;
            }
            else if (s.charAt(j) == "0" && count > 0) {
                lengths.push(count);
                count = 0;
            }
        }
        if (count > 0)
            lengths.push(count);
        lengths.sort();
        var answer = 0;
        for (var j = lengths.length - 1; j >= 0; j -= 2) {
            answer += lengths[j];
        }
        if (answer == 14) {
            console.log(s);
        }
        else {
            console.log(answer);
        }
    }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var inputArray = [];
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    inputArray = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function readline() {
    return inputArray[currentLine++];
}
function main() {
    var t = parseInt(readline());
    var _loop_1 = function (i) {
        var s = readline();
        var lengths = [];
        var count = 0;
        s.split("").forEach(function (c) {
            if (c == "1") {
                count++;
            }
            else if (c == "0" && count > 0) {
                lengths.push(count);
                count = 0;
            }
        });
        if (count > 0)
            lengths.push(count);
        lengths.sort();
        var answer = 0;
        for (var j = lengths.length - 1; j >= 0; j -= 2) {
            answer += lengths[j];
        }
        console.log(answer);
    };
    for (var i = 0; i < t; i++) {
        _loop_1(i);
    }
}

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var inputArray = [];
var currentLine = 0;
process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
});
process.stdin.on('end', function (_) {
    inputArray = inputString.trim().split('\n').map(function (string) {
        return string.trim();
    });
    main();
});
function readline() {
    return inputArray[currentLine++];
}
function main() {
    var t = parseInt(readline());
    var _loop_1 = function (i) {
        var s = readline();
        var lengths = [];
        var count = 0;
        s.split("").forEach(function (c) {
            if (c == "1") {
                count++;
            }
            else if (c == "0" && count > 0) {
                lengths.push(count);
                count = 0;
            }
        });
        if (count > 0)
            lengths.push(count);
        lengths.sort();
        var answer = 0;
        while (lengths.length > 0) {
            answer += lengths.pop();
            lengths.pop();
        }
        console.log(answer);
    };
    for (var i = 0; i < t; i++) {
        _loop_1(i);
    }
}


$$$n$$$ people live on the coordinate line, the $$$i$$$-th one lives at the point $$$x_i$$$ ($$$1 \le i \le n$$$). They want to choose a position $$$x_0$$$ to meet. The $$$i$$$-th person will spend $$$|x_i - x_0|$$$ minutes to get to the meeting place. Also, the $$$i$$$-th person needs $$$t_i$$$ minutes to get dressed, so in total he or she needs $$$t_i + |x_i - x_0|$$$ minutes. Here $$$|y|$$$ denotes the absolute value of $$$y$$$.These people ask you to find a position $$$x_0$$$ that minimizes the time in which all $$$n$$$ people can gather at the meeting place.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Then the test cases follow. Each test case consists of three lines. The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of people.  The second line contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 \le x_i \le 10^{8}$$$) — the positions of the people. The third line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$0 \le t_i \le 10^{8}$$$), where $$$t_i$$$ is the time $$$i$$$-th person needs to get dressed. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single real number — the optimum position $$$x_0$$$. It can be shown that the optimal position $$$x_0$$$ is unique. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{−6}$$$. Formally, let your answer be $$$a$$$, the jury's answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a−b|}{max(1,|b|)} \le 10^{−6}$$$.

Note  In the $$$1$$$-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in $$$3$$$ minutes, that he or she need to get dressed.  In the $$$2$$$-nd test case there are $$$2$$$ people who don't need time to get dressed. Each of them needs one minute to get to position $$$2$$$.  In the $$$5$$$-th test case the $$$1$$$-st person needs $$$4$$$ minutes to get to position $$$1$$$ ($$$4$$$ minutes to get dressed and $$$0$$$ minutes on the way); the $$$2$$$-nd person needs $$$2$$$ minutes to get to position $$$1$$$ ($$$1$$$ minute to get dressed and $$$1$$$ minute on the way); the $$$3$$$-rd person needs $$$4$$$ minutes to get to position $$$1$$$ ($$$2$$$ minutes to get dressed and $$$2$$$ minutes on the way).

'use strict';

var fs = require('fs');

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

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

function _defineProperty(obj, key, value) {
  if (key in obj) {
    Object.defineProperty(obj, key, {
      value: value,
      enumerable: true,
      configurable: true,
      writable: true
    });
  } else {
    obj[key] = value;
  }

  return obj;
}

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns(n),
        b = rns(n);
  const nodes = [...new Array(n).keys()].sort((i, j) => a[i] - a[j]).map((i, j) => [i, b[i] - a[i], b[i] + a[i]]);
  const r = new BinarySearchTree((a, b) => a[2] - b[2]);
  const l = new BinarySearchTree((a, b) => a[1] - b[1]);
  for (let i = 0; i < n; i++) {
    r.insert(nodes[i]);
  }
  let res = a[nodes[0][0]],
      max = r.getMax()[2] - a[nodes[0][0]];
  for (let i = 0; i < n - 1; i++) {
    const j = nodes[i][0],
          k = nodes[i + 1][0];
    r.delete(nodes[i]);
    l.insert(nodes[i]);
    const lm = l.getMax(),
          rm = r.getMax();
    const d = rm[2] - lm[1],
          x = a[j],
          y = a[k];
    if (d <= 2 * x) {
      const z = lm[1] + x;
      if (z < max) {
        max = z;
        res = x;
      }
    } else if (d >= 2 * y) {
      const z = rm[2] - x;
      if (z < max) {
        max = z;
        res = x;
      }
    } else {
      const z = lm[1] + d / 2;
      if (z < max) {
        max = z;
        res = d / 2;
      }
    }
  }
  if (n > 1) {
    const z = l.getMax()[1] + a[nodes[nodes.length - 1][0]];
    if (z < max) {
      max = z;
      res = a[nodes[nodes.length - 1][0]];
    }
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 100;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}
class BinarySearchTree {
  constructor(_compare = (a, b) => a - b) {
    _defineProperty(this, "root", null);
    _defineProperty(this, "length", 0);
    _defineProperty(this, "min", null);
    _defineProperty(this, "max", null);
    _defineProperty(this, "minCache", true);
    _defineProperty(this, "maxCache", true);
    _defineProperty(this, "deleteResult", false);
    this._compare = _compare;
    this.compare = this.compare.bind(this);
  }
  isT(t) {
    return t !== undefined && t !== null;
  }
  compare(a, b) {
    const {
      isT
    } = this;
    if (isT(a) && isT(b)) return this._compare(a, b);
    if (isT(a)) return 1;
    if (isT(b)) return -1;
    return 0;
  }
  isEmpty() {
    return !this.root;
  }
  size() {
    return this.root ? this.root.size : 0;
  }
  getRoot() {
    return this.root;
  }
  getMin() {
    if (this.minCache) {
      return this.min;
    }
    const min = this.searchKth(this.size());
    this.min = min;
    this.minCache = true;
    return min;
  }
  getMax() {
    if (this.maxCache) {
      return this.max;
    }
    const max = this.searchKth(1);
    this.max = max;
    this.maxCache = true;
    return max;
  }
  balance(node) {
    node.height = this.getHeight(node);
    const blance = this.getBalance(node);
    let res;
    if (Math.abs(blance) === 2) {
      if (blance > 0) {
        var _node$left$left$heigh, _node$left, _node$left$left, _node$left$right$heig, _node$left2, _node$left2$right;
        const heightDif = ((_node$left$left$heigh = (_node$left = node.left) === null || _node$left === void 0 ? void 0 : (_node$left$left = _node$left.left) === null || _node$left$left === void 0 ? void 0 : _node$left$left.height) !== null && _node$left$left$heigh !== void 0 ? _node$left$left$heigh : 0) - ((_node$left$right$heig = (_node$left2 = node.left) === null || _node$left2 === void 0 ? void 0 : (_node$left2$right = _node$left2.right) === null || _node$left2$right === void 0 ? void 0 : _node$left2$right.height) !== null && _node$left$right$heig !== void 0 ? _node$left$right$heig : 0);
        if (heightDif > 0) {
          res = this.rotateRight(node);
        } else if (heightDif < 0) {
          res = this.rotateLeftRight(node);
        }
      } else {
        var _node$right$left$heig, _node$right, _node$right$left, _node$right$right$hei, _node$right2, _node$right2$right;
        const heightDif = ((_node$right$left$heig = (_node$right = node.right) === null || _node$right === void 0 ? void 0 : (_node$right$left = _node$right.left) === null || _node$right$left === void 0 ? void 0 : _node$right$left.height) !== null && _node$right$left$heig !== void 0 ? _node$right$left$heig : 0) - ((_node$right$right$hei = (_node$right2 = node.right) === null || _node$right2 === void 0 ? void 0 : (_node$right2$right = _node$right2.right) === null || _node$right2$right === void 0 ? void 0 : _node$right2$right.height) !== null && _node$right$right$hei !== void 0 ? _node$right$right$hei : 0);
        if (heightDif > 0) {
          res = this.rotateRightLeft(node);
        } else if (heightDif < 0) {
          res = this.rotateLeft(node);
        }
      }
    }
    return res ? res : node;
  }
  rotateRight(node) {
    const left = node.left;
    const leftRight = left.right;
    left.right = node;
    node.left = leftRight;
    node.height = this.getHeight(node);
    left.height = this.getHeight(left);
    node.size = this.getSize(node);
    left.size = this.getSize(left);
    return left;
  }
  rotateLeft(node) {
    const right = node.right;
    const rightLeft = right.left;
    right.left = node;
    node.right = rightLeft;
    node.height = this.getHeight(node);
    right.height = this.getHeight(right);
    node.size = this.getSize(node);
    right.size = this.getSize(right);
    return right;
  }
  rotateLeftRight(node) {
    node.left = this.rotateLeft(node.left);
    return this.rotateRight(node);
  }
  rotateRightLeft(node) {
    node.right = this.rotateRight(node.right);
    return this.rotateLeft(node);
  }
  getBalance(node) {
    return this.getHeight(node.left) - this.getHeight(node.right);
  }
  getHeight(node) {
    var _node$left$height, _node$left3, _node$right$height, _node$right3;
    if (!node) return 0;
    return Math.max((_node$left$height = (_node$left3 = node.left) === null || _node$left3 === void 0 ? void 0 : _node$left3.height) !== null && _node$left$height !== void 0 ? _node$left$height : 0, (_node$right$height = (_node$right3 = node.right) === null || _node$right3 === void 0 ? void 0 : _node$right3.height) !== null && _node$right$height !== void 0 ? _node$right$height : 0) + 1;
  }
  getSize(node) {
    var _node$left$size, _node$left4, _node$right$size, _node$right4;
    if (!node) return 0;
    return ((_node$left$size = (_node$left4 = node.left) === null || _node$left4 === void 0 ? void 0 : _node$left4.size) !== null && _node$left$size !== void 0 ? _node$left$size : 0) + ((_node$right$size = (_node$right4 = node.right) === null || _node$right4 === void 0 ? void 0 : _node$right4.size) !== null && _node$right$size !== void 0 ? _node$right$size : 0) + node.count;
  }
  createNode(val) {
    return {
      id: Math.random() * new Date().valueOf(),
      val,
      left: null,
      right: null,
      size: 1,
      height: 1,
      count: 1
    };
  }
  insert(val) {
    let cur = this.createNode(val);
    if (this.isEmpty()) {
      this.root = cur;
      this.length++;
    } else {
      [, cur] = this.insertNode(this.root, cur);
    }
    if (this.min === null || this.compare(this.min, val) > 0) {
      this.min = val;
    }
    if (this.max === null || this.compare(this.max, val) < 0) {
      this.max = val;
    }
  }
  insertNode(node, cur, parent = null) {
    node.size++;
    const compareResult = this.compare(cur.val, node.val);
    let res;
    if (compareResult === 0) {
      node.count++;
      return [false, node];
    } else if (compareResult > 0) {
      if (node.right) {
        res = this.insertNode(node.right, cur, node);
        if (!res[0]) return res;
      } else {
        node.right = cur;
        this.length++;
        res = [true, cur];
      }
    } else {
      if (node.left) {
        res = this.insertNode(node.left, cur, node);
        if (!res[0]) return res;
      } else {
        node.left = cur;
        this.length++;
        res = [true, cur];
      }
    }
    let preHeight = node.height;
    const newNode = this.balance(node);
    if (newNode === node && node.height === preHeight) {
      res = [false, res[1]];
    } else if (newNode !== node) {
      if (parent) {
        parent.left === node ? parent.left = newNode : parent.right = newNode;
      } else {
        this.root = newNode;
      }
      res = [false, res[1]];
    }
    return res;
  }
  delete(val) {
    this.deleteResult = false;
    if (!this.root) return this.deleteResult;
    this.deleteNode(val, this.root, null);
    return this.deleteResult;
  }
  deleteNode(val, node, parent) {
    if (!node) return null;
    let res = this.compare(val, node.val);
    if (res === 0) {
      this.deleteResult = true;
      node.count--;
      node.size--;
      if (node.count > 0) return node;
      if (!node.left || !node.right) {
        if (this.min === val) {
          this.minCache = false;
        }
        if (this.max === val) {
          this.maxCache = false;
        }
        this.length--;
        if (!parent) {
          var _node$left5;
          this.root = (_node$left5 = node.left) !== null && _node$left5 !== void 0 ? _node$left5 : node.right;
          return this.root;
        } else {
          var _node$left6;
          return (_node$left6 = node.left) !== null && _node$left6 !== void 0 ? _node$left6 : node.right;
        }
      } else {
        const selectLeft = node.left.height > node.right.height;
        let replaceNode = selectLeft ? this.pre(node) : this.next(node),
            name = selectLeft ? 'left' : 'right';
        node.val = replaceNode.val;
        node.count = replaceNode.count;
        replaceNode.count = 0;
        node[name] = this.deleteNode(replaceNode.val, node[name], node);
      }
    } else if (res > 0) {
      node.right = this.deleteNode(val, node.right, node);
    } else {
      node.left = this.deleteNode(val, node.left, node);
    }
    node.size = this.getSize(node);
    node.height;
    const newNode = this.balance(node);
    if (parent) {
      parent.left === node ? parent.left = newNode : parent.right = newNode;
    } else {
      this.root = newNode;
    }
    return newNode;
  }
  next(node) {
    let next = node.right;
    while ((_next = next) !== null && _next !== void 0 && _next.left) {
      var _next;
      next = next.left;
    }
    return next;
  }
  pre(node) {
    let pre = node.left;
    while ((_pre = pre) !== null && _pre !== void 0 && _pre.right) {
      var _pre;
      pre = pre.right;
    }
    return pre;
  }
  search(val, compare) {
    if (this.isEmpty()) {
      return null;
    }
    const [, node] = this.searchCeilingNode(this.root, val, compare !== null && compare !== void 0 ? compare : this.compare);
    return node.val;
  }
  searchCeilingNode(node, val, compare, parent = null) {
    const res = compare(val, node.val);
    if (res === 0) {
      return [parent, node];
    } else if (res > 0) {
      if (node.right) {
        return this.searchCeilingNode(node.right, val, compare, node);
      } else {
        return [parent, node];
      }
    } else {
      if (node.left) {
        const [p, value] = this.searchCeilingNode(node.left, val, compare, node);
        if (compare(value.val, val) < 0) {
          return [parent, node];
        } else {
          return [p, value];
        }
      } else {
        return [parent, node];
      }
    }
  }
  ceiling(val) {
    if (this.isEmpty()) {
      return null;
    }
    const [, node] = this.searchCeilingNode(this.root, val, this.compare);
    return this.compare(node.val, val) >= 0 ? node.val : null;
  }
  searchFloorNode(node, val, compare, parent = null) {
    const res = compare(val, node.val);
    if (res === 0) {
      return [parent, node];
    } else if (res > 0) {
      if (node.right) {
        const [p, value] = this.searchFloorNode(node.right, val, compare, node);
        if (compare(value.val, val) > 0) {
          return [parent, node];
        } else {
          return [p, value];
        }
      } else {
        return [parent, node];
      }
    } else {
      if (node.left) {
        return this.searchFloorNode(node.left, val, compare, node);
      } else {
        return [parent, node];
      }
    }
  }
  floor(val) {
    if (this.isEmpty()) {
      return null;
    }
    const [, node] = this.searchFloorNode(this.root, val, this.compare);
    return this.compare(node.val, val) <= 0 ? node.val : null;
  }
  searchKth(k) {
    if (this.isEmpty()) {
      return null;
    }
    if (k <= 0 || k > this.size()) {
      return null;
    }
    const node = this.searchNodeKth(this.root, k);
    return node.val;
  }
  searchNodeKth(node, k) {
    var _node$right$size2, _node$right5, _node$right$size3, _node$right6;
    const rSize = (_node$right$size2 = (_node$right5 = node.right) === null || _node$right5 === void 0 ? void 0 : _node$right5.size) !== null && _node$right$size2 !== void 0 ? _node$right$size2 : 0;
    if (rSize === k - 1 || rSize < k && rSize + node.count >= k) return node;
    if (node.right && rSize > k - 1) return this.searchNodeKth(node.right, k);else return this.searchNodeKth(node.left, k - ((_node$right$size3 = (_node$right6 = node.right) === null || _node$right6 === void 0 ? void 0 : _node$right6.size) !== null && _node$right$size3 !== void 0 ? _node$right$size3 : 0) - node.count);
  }
  countGreaterThanEq(val) {
    if (!this.root) return 0;
    return this.countCompare(val, (a, b) => this._compare(a, b), this.root);
  }
  countCompare(val, compare, node, pre = 0) {
    const res = compare(val, node.val);
    if (res === 0) {
      var _node$right$size4, _node$right7;
      return pre + ((_node$right$size4 = (_node$right7 = node.right) === null || _node$right7 === void 0 ? void 0 : _node$right7.size) !== null && _node$right$size4 !== void 0 ? _node$right$size4 : 0) + node.count;
    } else if (res > 0) {
      if (node.right) {
        return this.countCompare(val, compare, node.right, pre);
      } else {
        return pre;
      }
    } else {
      var _node$right$size5, _node$right8;
      let count = pre + ((_node$right$size5 = (_node$right8 = node.right) === null || _node$right8 === void 0 ? void 0 : _node$right8.size) !== null && _node$right$size5 !== void 0 ? _node$right$size5 : 0) + node.count;
      if (node.left) {
        return this.countCompare(val, compare, node.left, count);
      } else {
        return count;
      }
    }
  }
  toArray() {
    if (!this.root) return [];
    const res = [];
    const dfs = node => {
      if (node.left) dfs(node.left);
      res.push(node.val);
      if (node.right) dfs(node.right);
    };
    dfs(this.root);
    return res;
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();


You've got an array, consisting of n integers a1, a2, ..., an. Also, you've got m queries, the i-th query is described by two integers li, ri. Numbers li, ri define a subsegment of the original array, that is, the sequence of numbers ali, ali + 1, ali + 2, ..., ari. For each query you should check whether the corresponding segment is a ladder. A ladder is a sequence of integers b1, b2, ..., bk, such that it first doesn't decrease, then doesn't increase. In other words, there is such integer x (1 ≤ x ≤ k), that the following inequation fulfills: b1 ≤ b2 ≤ ... ≤ bx ≥ bx + 1 ≥ bx + 2... ≥ bk. Note that the non-decreasing and the non-increasing sequences are also considered ladders.

The first line contains two integers n and m (1 ≤ n, m ≤ 105) — the number of array elements and the number of queries. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where number ai stands for the i-th array element. The following m lines contain the description of the queries. The i-th line contains the description of the i-th query, consisting of two integers li, ri (1 ≤ li ≤ ri ≤ n) — the boundaries of the subsegment of the initial array. The numbers in the lines are separated by single spaces.

Print m lines, in the i-th line print word "Yes" (without the quotes), if the subsegment that corresponds to the i-th query is the ladder, or word "No" (without the quotes) otherwise.

'use strict';

var requests = [],
    steps = [];

var dataLine = readline().split(' ').map(function (number) {
  return parseInt(number);
});

steps = readline().split(' ').map(function (number) {
  return parseInt(number);
});

for (var i = 0; i < dataLine[1]; i++) {
  requests.push(readline().split(' ').map(function (number) {
    return parseInt(number);
  }));
}

var getCleanSteps = function getCleanSteps(originSteps) {

  var _steps = new Array(originSteps.length);
  _steps[0] = 0;

  for (var index = 1; index < originSteps.length; index++) {
    if (originSteps[index] > originSteps[index - 1]) {
      _steps[index] = 1;
    } else if (originSteps[index] < originSteps[index - 1]) {
      _steps[index] = -1;
    } else {
      _steps[index] = 0;
    }
  }

  return _steps;
};

steps = getCleanSteps(steps);

var checkSteps = function checkSteps(_steps) {
  _steps[0] = 0;

  var waitForUpCrash = false;
  var isSteps = 'yes';

  _steps.map(function (value, index) {
    if (value === -1) waitForUpCrash = true;
    if (value === 1 && waitForUpCrash) {
      isSteps = 'no';
    }
  });

  return isSteps;
};

for (var index = 0; index < requests.length; index++) {
  write(checkSteps(steps.slice(requests[index][0] - 1, requests[index][1])));
}

'use strict';var requests=[],steps=[],dataLine=readline().split(' ').map(function(a){return parseInt(a)});steps=readline().split(' ').map(function(a){return parseInt(a)});for(var i=0;i<dataLine[1];i++)requests.push(readline().split(' ').map(function(a){return parseInt(a)}));write('test');


Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it.You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.

The only line contains an integer n (3 ≤ n ≤ 101; n is odd).

***D***
**DDD**
*DDDDD*
DDDDDDD
*DDDDD*
**DDD**
***D***

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

rl.on('line', (d) => {
  const n = +d;
  const ans = [];
  let idx = 1;
  const asterix = '*';
  const digit = 'D';
  let dir = 2;

  while (idx > 0) {
    let half = (n - idx) / 2;
    let str = asterix.repeat(half) + digit.repeat(idx) + asterix.repeat(half);
    ans.push(str);

    if (idx === n) {
      dir = -2;
    }

    idx += dir;
  }

  for (let i = 0; i < ans.length; i++) {
    console.log(ans[i]);
  }
});

var n = parseInt(readline());
var curr = 1;
var stars, out;

while (curr < n) {
    stars = (n - curr) / 2;
    out = repeat('*', stars) + repeat('D', curr) + repeat('*', stars);
    print(out);
    curr += 2;
}
print(repeat('D', n));
curr = n - 2;
while (curr > 0) {
    stars = (n - curr) / 2;
    out = repeat('*', stars) + repeat('D', curr) + repeat('*', stars);
    print(out);
    curr -= 2;
}

function repeat(str, n) {
    return new Array(n + 1).join(str);
}

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

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

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

function main() {
	var n = parseInt(readline()),
		star = [], diamond = [];
	for (var i = 0; i < n; ++i) {
		star.push('*');
		diamond.push('D');
	}
	star = star.join('');
	diamond = diamond.join('');
	var rows = [], starCount = (n-1)/2, starGrow = -1;
	for (var r = 0; r < n; ++r) {
		var diamondCount = n - 2*starCount,
			stars = star.substring(0, starCount),
			diamonds = diamond.substring(0, diamondCount);
		rows.push(stars + diamonds + stars);
		starCount += starGrow;
		if (starCount == -1) {
			starCount = 1;
			starGrow = 1;
		}
	}
	print(rows.join('\n'));
}

main();

function popochonguis(n){
        var res = ""
        var mitad = parseInt(n/2);
        var maxMitad = mitad;
        for(var i=1;i<=n;i++){
                var b = 0;
                if(i<=(mitad+1)){
                    b = i + (i-1);
                }else{
                    maxMitad = maxMitad - 1;
                    b = maxMitad + (maxMitad+1);
                }
                    var a = [(n-b)/2,b,(n-b)/2]
                    for(var k = 0; k < a.length; k++){
                        for (var j = 0; j < a[k]; j++) {
                            if(k==1){
                                res = res  + "D";
                            }else{
                                res = res + "*";
                            }
                        }
                    }
                    res = res + "\n";
            }
        return res;
    }
            var num = parseInt(readline());
            print(popochonguis(num));

    function cristal(n){
            if (n%1 == 0 & n>0 & n<=101){
                var i = 1;
                var res = "";
                while(i<=n){
                    if(i%2!=0){
                        k = n - i; //4,2,0
                        if(k!=0){
                            for(var j = 1; j <= k; j++){
                                res = res + "*";
                                if(j == k/2){
                                    for(var l = 1; l <= i; l++){
                                        res = res + "D";
                                    }
                                }
                            }
                        }else{
                            for(var l = 1; l <= i; l++){
                                res = res + "D";
                            }
                        }
                        if(i!=n){
                            res = res + '\n';
                        }
                    }
                    i = i + 1;
                }
                var x = res.length-(n+1);
                while (x>=0) {
                    res = res + res.charAt(x);
                    x--;
                }
                return res;
            }else{
                return 0;
            }
        }
            var num = parseInt(readline());
            print(cristal(num));

    function popochonguis(n){
        var res = ""
        var decrementar = parseInt(n/2);
        for(var i=1;i<=n;i++){
                var b = 0;
                if(
                    i<=(parseInt(n/2)+1)){b = i + (i-1);
                }else{
                    decrementar  = decrementar  - 1;
                    b = decrementar + (decrementar +1);
                }
                    for(var e=1;e<=n;e++){
                        e > (n-b)/2 && e<=((n-b)/2+b)?res = res  + "D":res = res + "*";
                    }
                    res = res + "\n";
            }
        return res;
    }
            var num = parseInt(readline());
            print(popochonguis(num));

//

var line = readline();
line = parseInt(line);
foo(line);
function foo(n) {
	var d = 1;
	var on = true;
	for(var i =0 ; i < n ;i++) {
		var s = "";
		var p = (n-d)/2;
		for(var  j = 0 ; j < p ; j++) {
			s += "*";

		}

		for(var j = 0 ; j < d ; j++) {
			s += "D";
		}

		for(var j = 0 ; j < p ; j++) {
			s+= "*";
		}
		if (d === n) {
			on = false;
		}
		if ( d < n && on) {
		d += 2;
	}

	if (!on) {
		d  = d -2;
	}

	print(s);
	}

}

/**
 * Created by Dub4ek on 6/1/14.
 */

function crystal(arg) {
    var result = [];
    var middle = Math.floor(arg / 2);

    for (var i = 0; i < arg; i++) {
        var row = [];
        for (var j = 0; j < arg; j++) {
            if (i < middle) {
                if ( j < middle - i || j > middle + i) {
                    row.push('*');
                } else {
                    row.push('D');
                }
            } else {
                if ( j < i - middle || j > arg - (i - middle) - 1) {
                    row.push('*');
                } else {
                    row.push('D');
                }
            }
        }
        result.push(row);
    }

    return result;
};

var num = readline();
var result = crystal(num);

for (var i = 0; i < result.length; i++) {
    print( result[i].reduce(function(prev, cur) {
        return prev + cur;
    }));
}

var n = readline();
var c = Math.floor(n/2);
for(var i=0; i<n; i++){
    var d = Math.abs(c-i);
    var line = "";
    for(var j=0; j<d; j++){
        line += "*";
    }
    for(; j<n-d; j++){
        line += "D";
    }
    for(; j<n; j++){
        line += "*";
    }
    print(line);
}

var n = +readline();
var j = 1;
for (var i=1; i<=n; i++) {
	var s = '*'.repeat((n-j)/2) + 'D'.repeat(j) + '*'.repeat((n-j)/2);
	if (i<n/2) j = j + 2;
	else j = j - 2;
	print(s);
}

var num = readline(),
				cNum = Math.floor(num / 2),
				arraySize = Math.ceil(num / 2),
				strStar = '*',
				strChar = 'D',
				tempStr = '';
				array = [];

			for(var idx=0; idx<arraySize - 1; idx++)    {
	        	tempStr = '';

	            for(var idx2=0; idx2<num; idx2++)   {
	                if(idx2 >= cNum - idx && idx2 <= cNum + idx)    tempStr += strChar;
	                else    {
	                    tempStr += strStar;
	                }
	            }

	            array.push(tempStr);
	        }

	        tempStr = '';

	        for(var idx=0; idx<num; idx++)  tempStr += strChar;

	        array.push(tempStr);

	        for(var idx=0; idx<array.length; idx++)	print(array[idx]);
	        for(var idx=array.length - 2; idx>=0; idx--)	print(array[idx]);

var n = readline();
var curr = 1;
var stars, out;

while (curr < n) {
    stars = (n - curr) / 2;
    out = repeat('*', stars) + repeat('D', curr) + repeat('*', stars);
    print(out);
    curr += 2;
}
print(repeat('D', n));
curr = n - 2;
while (curr > 0) {
    stars = (n - curr) / 2;
    out = repeat('*', stars) + repeat('D', curr) + repeat('*', stars);
    print(out);
    curr -= 2;
}

function repeat(str, n) {
    return new Array(n + 1).join(str);
}

var n = readline();
var curr = 1;
var stars;

while (curr < n) {
    stars = (n - curr) / 2;
    printStars(stars);
    printD(curr);
    printStars(stars);
    print('\n');
    curr += 2;
}
printD(n);
print('\n');
curr = n - 2;
while (curr > 0) {
    stars = (n - curr) / 2;
    printStars(stars);
    printD(curr);
    printStars(stars);
    print('\n');
    curr -= 2;
}

function printStars(n) {
    for (var s = 0; s < n; s++) {
    	print('*');
    }
}

function printD(n) {
    for (var d = 0; d < n; d++) {
    	print('D');
    }
}

var n = 23;
var curr = 1;
var stars, out;

while (curr < n) {
    stars = (n - curr) / 2;
    out = repeat('*', stars) + repeat('D', curr) + repeat('*', stars);
    print(out);
    curr += 2;
}
print(repeat('D', n));
curr = n - 2;
while (curr > 0) {
    stars = (n - curr) / 2;
    out = repeat('*', stars) + repeat('D', curr) + repeat('*', stars);
    print(out);
    curr -= 2;
}

function repeat(str, n) {
    return new Array(n + 1).join(str);
}

//

var line = readline().split('');
line = parseInt(line[0]);
foo(line);
function foo(n) {
	var d = 1;
	var on = true;
	for(var i =0 ; i < n ;i++) {
		var s = "";
		var p = (n-d)/2;
		for(var  j = 0 ; j < p ; j++) {
			s += "*";

		}

		for(var j = 0 ; j < d ; j++) {
			s += "D";
		}

		for(var j = 0 ; j < p ; j++) {
			s+= "*";
		}
		if (d === n) {
			on = false;
		}
		if ( d < n && on) {
		d += 2;
	}

	if (!on) {
		d  = d -2;
	}

	print(s);
	}

}

function crystal(arg) {
    var result = [];
    var middle = Math.floor(arg / 2);

    for (var i = 0; i < arg; i++) {
        var row = [];
        for (var j = 0; j < arg; j++) {
            if (i < middle) {
                if ( j < middle - i || j > middle + i) {
                    row.push('*');
                } else {
                    row.push('D');
                }
            } else {
                if ( j < i - middle || j > arg - (i - middle) - 1) {
                    row.push('*');
                } else {
                    row.push('D');
                }
            }
        }
        result.push(row);
    }

    return result;
}

var num = readline();

print(crystal(num));

function crystal(arg) {
    var result = [];
    var middle = Math.floor(arg / 2);

    for (var i = 0; i < arg; i++) {
        var row = [];
        for (var j = 0; j < arg; j++) {
            if (i < middle) {
                if ( j < middle - i || j > middle + i) {
                    row.push('*');
                } else {
                    row.push('D');
                }
            } else {
                if ( j < i - middle || j > arg - (i - middle) - 1) {
                    row.push('*');
                } else {
                    row.push('D');
                }
            }
        }
        result.push(row);
    }

    return result;
};

var num = readline();
var result = crystal(num);

for (var i = 0; i < result.length; i++) {
    print(result[i]);
}


You are given a sequence of $$$n$$$ integers $$$a_1, \, a_2, \, \dots, \, a_n$$$.Does there exist a sequence of $$$n$$$ integers $$$b_1, \, b_2, \, \dots, \, b_n$$$ such that the following property holds?  For each $$$1 \le i \le n$$$, there exist two (not necessarily distinct) indices $$$j$$$ and $$$k$$$ ($$$1 \le j, \, k \le n$$$) such that $$$a_i = b_j - b_k$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10$$$). The second line of each test case contains the $$$n$$$ integers $$$a_1, \, \dots, \, a_n$$$ ($$$-10^5 \le a_i \le 10^5$$$).

For each test case, output a line containing YES if a sequence $$$b_1, \, \dots, \, b_n$$$ satisfying the required property exists, and NO otherwise.

NoteIn the first test case, the sequence $$$b = [-9, \, 2, \, 1, \, 3, \, -2]$$$ satisfies the property. Indeed, the following holds:   $$$a_1 = 4 = 2 - (-2) = b_2 - b_5$$$;  $$$a_2 = -7 = -9 - (-2) = b_1 - b_5$$$;  $$$a_3 = -1 = 1 - 2 = b_3 - b_2$$$;  $$$a_4 = 5 = 3 - (-2) = b_4 - b_5$$$;  $$$a_5 = 10 = 1 - (-9) = b_3 - b_1$$$. In the second test case, it is sufficient to choose $$$b = [0]$$$, since $$$a_1 = 0 = 0 - 0 = b_1 - b_1$$$.In the third test case, it is possible to show that no sequence $$$b$$$ of length $$$3$$$ satisfies the property.

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        a = new Array(n);
  for (let i = 0; i < n; i++) a[i] = rn();
  if (a.includes(0)) return 'YES';
  const make = (a, b) => [a - b, a + b, b - a];
  const check = i => {
    let set = new Set([0]),
        nums = [0];
    for (let j = 0; j < n; j++) {
      if (i === j) continue;
      const m = nums.length;
      for (let k = 0; k < m; k++) {
        for (let num of make(nums[k], a[j])) {
          if (a[i] === num) return true;
          if (!set.has(num)) {
            set.add(num);
            nums.push(num);
          }
        }
      }
    }
    return false;
  };
  for (let i = 0; i < n; i++) {
    if (check(i)) return 'YES';
  }
  return 'NO';
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

// Input handling (Ctrl-D for EOF)

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

const input = [];
let currLine = 0;

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

rl.on("close", () => {
    main();
})

function readline() {
    return input[currLine++];
}

// Main function

function checkArr(arr, i, v, used) {
    if (i == arr.length) return used && v === 0;
    const res1 = checkArr(arr, i+1, v, used);
    const res2 = checkArr(arr, i+1, v+arr[i], true);
    const res3 = checkArr(arr, i+1, v-arr[i], true);
    return res1 || res2 || res3;
}

function main() {
    const T = parseInt(readline());
    for (let i = 0; i < T; i++) {
        const N = parseInt(readline());
        const arr = readline().split(' ').map((x) => parseInt(x));
        console.log(checkArr(arr, 0, 0, false) ? "YES" : "NO");
    }
}