const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let isFirstLine = false;
let number;
let maxRank;
let soldiers;
let coin = 0;
readline.on('line', line => {
  if (isFirstLine) {
    let firstLine = line.split(' ');
    number = firstLine[0];
    maxRank = firstLine[1]
    isFirstLine = false;
  } else {
    soldiers = line.split(' ');
    readline.close();
    while(true) {
    if(soldiers.every(function(soldier){
        return soldier == maxRank;
    })){
        break;
    }
    soldiers = soldiers.map(function(soldier, index, self){
        if(index === self.indexOf(soldier) && soldier < maxRank){
            soldier++;
        }
        return soldier;
    });
    coin++;
    }
    console.log(coin);
  }
})

In a strategic computer game "Settlers II" one has to build defense structures to expand and protect the territory. Let's take one of these buildings. At the moment the defense structure accommodates exactly n soldiers. Within this task we can assume that the number of soldiers in the defense structure won't either increase or decrease.Every soldier has a rank — some natural number from 1 to k. 1 stands for a private and k stands for a general. The higher the rank of the soldier is, the better he fights. Therefore, the player profits from having the soldiers of the highest possible rank.To increase the ranks of soldiers they need to train. But the soldiers won't train for free, and each training session requires one golden coin. On each training session all the n soldiers are present.At the end of each training session the soldiers' ranks increase as follows. First all the soldiers are divided into groups with the same rank, so that the least possible number of groups is formed. Then, within each of the groups where the soldiers below the rank k are present, exactly one soldier increases his rank by one.You know the ranks of all n soldiers at the moment. Determine the number of golden coins that are needed to increase the ranks of all the soldiers to the rank k.

The first line contains two integers n and k (1≤n,k≤100). They represent the number of soldiers and the number of different ranks correspondingly. The second line contains n numbers in the non-decreasing order. The i-th of them, ai, represents the rank of the i-th soldier in the defense building (1≤i≤n, 1≤ai≤k).

Print a single integer — the number of golden coins needed to raise all the soldiers to the maximal rank.

In the first example the ranks will be raised in the following manner:
1 2 2 3 → 2 2 3 4 → 2 3 4 4 → 3 4 4 4 → 4 4 4 4
Thus totals to 4 training sessions that require 4 golden coins.

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let isFirstLine = true;
let number;
let maxRank;
let soldiers;
let coin = 0;
readline.on('line', line => {
  if (isFirstLine) {
    let firstLine = line.split(' ').map(x => parseInt(x));
    number = firstLine[0];
    maxRank = firstLine[1]
    isFirstLine = false;
  } else {
    soldiers = line.split(' ').map(x => parseInt(x));
    readline.close();
    while (soldiers.some(s => s < maxRank)) {
      coin++
      let currentSoldeir = 0;
      for (let i = 0; i < soldiers.length; i++) {
        const soldeir = soldiers[i];
        if (soldeir == maxRank) break
        if (currentSoldeir < soldeir) {
          soldiers[i]++
          currentSoldeir = soldeir;
        }
      soldiers = soldiers.sort((a, b) => a - b)
      }
    }
    console.log(coin);
  }
})


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.split(" ")[0];

    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) {
	return l > 2 ? 0 : (l-1)/2
}

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


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 pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function dsu(n){
    this.parent = new Array(n);
    for(let i = 0; i < n; i++)
        this.parent[i] = i;

    this.find = (x) => {
        if(this.parent[x] === x)
            return this.parent[x];

        return this.find(this.parent[x]);
    }

    this.union = (x,y) => {
        this.parent[this.find(x)] = this.find(y);
    }
}

function main(){
    let n = pi(readline());
    let mapX = new Array(1005);
    let mapY = new Array(1005);
    mapX.fill(-1);
    mapY.fill(-1);
    let uf = new dsu(n);

    for(let i = 0; i < n; i++){
        let [x,y] = ti(readline().split(' '));
        if(mapX[x] !== -1){
            uf.union(mapX[x], i);
        }else{
            mapX[x] = i;
        }

        if(mapY[y] !== -1){
            uf.union(mapY[y], i);
        }else{
            mapY[y] = i;
        }
    }

    let res = 0;
    for(let i = 0; i < n; i++)
        if(uf.parent[i] === i)
            res += 1;

    console.log(Math.floor(res / 2));
}

Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created.We assume that Bajtek can only heap up snow drifts at integer coordinates.

The first line of input contains a single integer n (1 ≤ n ≤ 100) — the number of snow drifts. Each of the following n lines contains two integers xi and yi (1 ≤ xi, yi ≤ 1000) — the coordinates of the i-th snow drift. Note that the north direction coinсides with the direction of Oy axis, so the east direction coinсides with the direction of the Ox axis. All snow drift's locations are distinct.

Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one.

// author: Oscar Ramos

/// Source Code
// const input = require('competitive-programming-js').inputReader
// const { forn, vector, range } = require('../utils/utils')
//
// const n = input.readNumber()
//
// const coords = []
// forn(n, () => {
//   const [x, y] = input.readNumberArray()
//   coords.push([x, y])
// })
//
// const visited = vector(n, false)
//
// let ans = -1
//
// const dfs = i => {
//   if (!visited[i]) {
//     visited[i] = true
//     forn(n, (j => {
//       if (coords[i][0] === coords[j][0] ||
//         coords[i][1] === coords[j][1]) {
//         dfs(j)
//       }
//     }))
//   }
// }
//
// forn(n, i => {
//   if (!visited[i]) {
//     ans += 1
//   }
//   dfs(i)
// })
//
// console.log(ans)
//

!function(n){var t={};function r(e){if(t[e])return t[e].exports;var o=t[e]={i:e,l:!1,exports:{}};return n[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=n,r.c=t,r.d=function(n,t,e){r.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:e})},r.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},r.t=function(n,t){if(1&t&&(n=r(n)),8&t)return n;if(4&t&&"object"==typeof n&&n&&n.__esModule)return n;var e=Object.create(null);if(r.r(e),Object.defineProperty(e,"default",{enumerable:!0,value:n}),2&t&&"string"!=typeof n)for(var o in n)r.d(e,o,function(t){return n[t]}.bind(null,o));return e},r.n=function(n){var t=n&&n.__esModule?function(){return n.default}:function(){return n};return r.d(t,"a",t),t},r.o=function(n,t){return Object.prototype.hasOwnProperty.call(n,t)},r.p="",r(r.s=1)}([function(n,t){n.exports=function(n){return null!=n&&"object"==typeof n&&!0===n["@@functional/placeholder"]}},function(n,t,r){n.exports=r(2)},function(n,t,r){let e,o=0,u={readNumber:function(){return Number(e[o++])},readNumberArray:function(){return e[o++].split(" ").map(n=>Number(n))}};var c="";process.stdin.resume(),process.stdin.setEncoding("utf8"),process.stdin.on("data",(function(n){c+=n})).on("end",(function(){e=c.trim().split("\n").map(n=>n.trim());const{forn:n,vector:t,range:o}=r(3),i=u.readNumber(),f=[];n(i,()=>{const[n,t]=u.readNumberArray();f.push([n,t])});const a=t(i,!1);let s=-1;const p=t=>{a[t]||(a[t]=!0,n(i,n=>{f[t][0]!==f[n][0]&&f[t][1]!==f[n][1]||p(n)}))};n(i,n=>{a[n]||(s+=1),p(n)}),console.log(s)}))},function(n,t,r){const e=r(4);n.exports={forn:(n,t)=>e(0,n).map(n=>t(n)),fornm:(n,t,r)=>e(0,n).map(n=>e(0,t).map(t=>r(n,t))),matrix:(n,t,r)=>e(0,n).map(()=>e(0,t).map(()=>r)),vector:(n,t)=>e(0,n).map(()=>t),range:e}},function(n,t,r){var e=r(5),o=r(7),u=e((function(n,t){if(!o(n)||!o(t))throw new TypeError("Both arguments to range must be numbers");for(var r=[],e=n;e<t;)r.push(e),e+=1;return r}));n.exports=u},function(n,t,r){var e=r(6),o=r(0);n.exports=function(n){return function t(r,u){switch(arguments.length){case 0:return t;case 1:return o(r)?t:e((function(t){return n(r,t)}));default:return o(r)&&o(u)?t:o(r)?e((function(t){return n(t,u)})):o(u)?e((function(t){return n(r,t)})):n(r,u)}}}},function(n,t,r){var e=r(0);n.exports=function(n){return function t(r){return 0===arguments.length||e(r)?t:n.apply(this,arguments)}}},function(n,t){n.exports=function(n){return"[object Number]"===Object.prototype.toString.call(n)}}]);

/// package.json
// {
//   "name": "competitive",
//   "version": "1.0.0",
//   "description": "",
//   "main": "src/index.js",
//   "scripts": {
//     "convert": "cp-convert -s src/index.js -d output/converted.js",
//     "bundle": "webpack --config ./webpack.config.js",
//     "test": "npm run convert && jest ./",
//     "production": "npm run convert && npm run bundle && node src/getOutput.js",
//     "start": "node src/index.js"
//   },
//   "author": "Oscar Ramos",
//   "dependencies": {
//     "child-process-promise": "^2.2.1",
//     "competitive-programming-js": "^1.0.10",
//     "mathball": "^0.4.0",
//     "ramda": "^0.27.1"
//   },
//   "devDependencies": {
//     "@types/jest": "^26.0.10",
//     "concat-stream": "^2.0.0",
//     "cross-spawn": "^7.0.3",
//     "jest": "^26.4.2",
//     "jest-expect-message": "^1.0.2",
//     "mock-stdin": "^1.0.0",
//     "terser-webpack-plugin": "^4.1.0",
//     "webpack": "^4.44.1",
//     "webpack-cli": "^3.3.12"
//   },
//   "jest": {
//     "setupFilesAfterEnv": ["jest-expect-message"]
//   }
// }
//


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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const hw = arr.shift().split(' ')
  const n = parseInt(hw[0])
  const m = parseInt(hw[1])

  const graph = new Map()
  for(let i = 1; i <= n; i++) {
    graph.set(i, 0)
  }

  for(let i = 0; i < m; i++) {
    const edge = arr.shift().split(' ')
    graph.set(parseInt(edge[0]), graph.get(parseInt(edge[0])) + 1)
    graph.set(parseInt(edge[1]), graph.get(parseInt(edge[1])) + 1)
  }

  const deg = new Map()
  graph.forEach((v, k) => {
    if(!deg.get(v)) deg.set(v, 1)
    else  deg.set(v, deg.get(v) + 1)
  })

  // console.log(graph)
  // console.log(deg)
  if(deg.size <= 3){
    var iterator1 = deg.keys()
    const ak = iterator1.next().value
    const bk = iterator1.next().value
    const ck = iterator1.next().value
    const a = deg.get(ak)
    const b = deg.get(bk)
    const c = deg.get(ck)
    // console.log(a,b,c, ak, bk)
    if(a == (b + c)
      || b == (a + c)
      || c == (a + b)
      || (a % 3 == 0 && b == undefined && c == undefined)
      || (a == b && c == undefined)){
      // console.log(graph)
      graph.forEach((v, k) => {
        // console.log(v)
        if(v == ak){
          process.stdout.write('1 ')
        }
        else if(v == bk){
          process.stdout.write('2 ')
        }
        else{
          process.stdout.write('3 ')
        }
      })
      console.log()
    }
    else{
      console.log(-1)
    }
  }
  else{
    console.log(-1)
  }
})

You have a simple undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.Let's make a definition.Let $$$v_1$$$ and $$$v_2$$$ be two some nonempty subsets of vertices that do not intersect. Let $$$f(v_{1}, v_{2})$$$ be true if and only if all the conditions are satisfied:  There are no edges with both endpoints in vertex set $$$v_1$$$.  There are no edges with both endpoints in vertex set $$$v_2$$$.  For every two vertices $$$x$$$ and $$$y$$$ such that $$$x$$$ is in $$$v_1$$$ and $$$y$$$ is in $$$v_2$$$, there is an edge between $$$x$$$ and $$$y$$$. Create three vertex sets ($$$v_{1}$$$, $$$v_{2}$$$, $$$v_{3}$$$) which satisfy the conditions below;  All vertex sets should not be empty.  Each vertex should be assigned to only one vertex set.  $$$f(v_{1}, v_{2})$$$, $$$f(v_{2}, v_{3})$$$, $$$f(v_{3}, v_{1})$$$ are all true. Is it possible to create such three vertex sets? If it's possible, print matching vertex set for each vertex.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n \le 10^{5}$$$, $$$0 \le m \le \text{min}(3 \cdot 10^{5}, \frac{n(n-1)}{2})$$$) — the number of vertices and edges in the graph.
The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$a_{i}$$$ and $$$b_{i}$$$ ($$$1 \le a_{i} \lt b_{i} \le n$$$) — it means there is an edge between $$$a_{i}$$$ and $$$b_{i}$$$. The graph doesn't contain self-loops, there is at most one edge between a pair of vertices. The given graph can be disconnected.

If the answer exists, print $$$n$$$ integers. $$$i$$$-th integer means the vertex set number (from $$$1$$$ to $$$3$$$) of $$$i$$$-th vertex. Otherwise, print $$$-1$$$.
If there are multiple answers, print any.

const readline = require('readline')

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

function solve(n, edges) {
    const adj = {}
    for (let u = 1; u <= n; u++) {
        adj[u] = {}
    }
    edges.forEach(([a, b]) => {
        adj[a][b] = 1
        adj[b][a] = 1
    })

    const gs = Array(n + 1)
    const vs = []
    let g = 1
    for (let u = 1; u <= n; u++) {
        if (gs[u]) continue
        if (g > 3) return -1
        const temp = [u]
        gs[u] = g
        for (let v = u + 1; v <= n; v++) {
            if (!adj[u][v] && !gs[v]) {
                gs[v] = g
                temp.push(v)
            }
        }
        vs.push(temp)
        g++
    }
// console.log(gs, vs)
    if (vs.length < 3) return -1
    for (let i = 0; i < vs.length; i++) {
        for (let a = 0; a < vs[i].length; a++) {
            const u = vs[i][a]
            for (let j = i + 1; j < vs.length; j++) {
                for (let b = 0; b < vs[j].length; b++) {
                    const v = vs[j][b]
                    if (!adj[u][v]) return -1
                }
            }
        }
    }
    for (let [u, v] of edges) {
        if (gs[u] === gs[v]) return -1
    }
    gs.shift()
    return gs.join(' ')
}


'use strict';

function solve(n, m, s) {
  console.log(n, m, s);
  const segTree = new SegTree(new Array(n).fill(0));
  for (let str of s) {
    const num = Number(str.slice(1)) - 1;
    if (str[0] === '+') {
      segTree.update(num, num, 1);
    } else {
      segTree.update(0, num - 1, 1);
      segTree.update(num + 1, n - 1, 1);
    }
  }
  const suspects = new Set();
  for (let i = 0; i < n; i++) {
    const count = segTree.query(i, i);
    if (count === m) suspects.add(i);
  }
  const res = new Array(n);
  for (let i = 0; i < n; i++) {
    const str = s[i];
    const num = Number(str.slice(1)) - 1;
    if (str[0] === '+') {
      if (suspects.has(num)) {
        if (suspects.size === 1) res[i] = 'Truth';else res[i] = 'Not defined';
      } else {
        res[i] = 'Lie';
      }
    } else {
      if (suspects.has(num)) {
        if (suspects.size === 1) res[i] = 'Lie';else res[i] = 'Not defined';
      } else {
        res[i] = 'Truth';
      }
    }
  }
  return res.join('\n');
}
class SegTree {
  constructor(nums = [], n = nums.length - 1) {
    this.nums = nums;
    this.n = n;
    this.root = this._newNode();
    this._build(this.root, 0, n);
    this.update = (x, y, z) => {
      if (x > y) return;
      x = Math.max(x, 0);
      y = Math.min(y, n);
      return this._update(this.root, 0, n, x, y, z);
    };
    this.query = (x, y) => {
      if (x > y) return 0;
      x = Math.max(x, 0);
      y = Math.min(y, n);
      return this._query(this.root, 0, n, x, y);
    };
  }
  _newNode(val = 0, left = null, right = null) {
    return {
      val,
      left,
      right,
      add: 0
    };
  }
  _down(node, l, r) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    const mid = Math.floor((l + r) / 2);
    left.add += node.add;
    left.val += node.add * (mid - l + 1);
    right.add += node.add;
    right.val += node.add * (r - mid);
    node.add = 0;
  }
  _up(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    node.val = left.val + right.val;
  }
  _build(node = this.root, l, r) {
    if (l === r) {
      var _this$nums$l;
      node.val = (_this$nums$l = this.nums[l]) !== null && _this$nums$l !== void 0 ? _this$nums$l : 0;
      return;
    }
    const mid = Math.floor((l + r) / 2);
    node.left = this._newNode();
    node.right = this._newNode();
    this._build(node.left, l, mid);
    this._build(node.right, mid + 1, r);
    node.val = node.left.val + node.right.val;
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.add += z;
      node.val += z * (r - l + 1);
      return;
    }
    this._down(node, l, r);
    const mid = Math.floor((l + r) / 2);
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
    this._up(node);
  }
  _query(node, l, r, x, y) {
    if (y < x) return 0;
    if (!node) return 0;
    if (l === x && r === y) return node.val;
    this._down(node, l, r);
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = this._query(node.left, l, mid, x, mid) + this._query(node.right, mid + 1, r, mid + 1, y);
    this._up(node);
    return res;
  }
}

async function main(read) {
  try {
    let res = [];
    let t = 1;
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push(await read());
      }
      res.push(solve(n, m, a));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, he asked each one: "Which one committed the crime?". Suspect number i answered either "The crime was committed by suspect number ai", or "Suspect number ai didn't commit the crime". Also, the suspect could say so about himself (ai=i).Sherlock Holmes understood for sure that exactly m answers were the truth and all other answers were a lie. Now help him understand this: which suspect lied and which one told the truth?

The first line contains two integers n and m (1≤n≤10^5,0≤m≤n) — the total number of suspects and the number of suspects who told the truth. Next n lines contain the suspects' answers. The i-th line contains either "+ai" (without the quotes), if the suspect number i says that the crime was committed by suspect number ai, or "-ai" (without the quotes), if the suspect number i says that the suspect number ai didn't commit the crime (ai is an integer, 1≤ai≤n).
It is guaranteed that at least one suspect exists, such that if he committed the crime, then exactly m people told the truth.

Print n lines. Line number i should contain "Truth" if suspect number i has told the truth for sure. Print "Lie" if the suspect number i lied for sure and print "Not defined" if he could lie and could tell the truth, too, depending on who committed the crime.

The first sample has the single person and he confesses to the crime, and Sherlock Holmes knows that one person is telling the truth. That means that this person is telling the truth.
In the second sample there are three suspects and each one denies his guilt. Sherlock Holmes knows that only two of them are telling the truth. Any one of them can be the criminal, so we don't know for any of them, whether this person is telling the truth or not.
In the third sample the second and the fourth suspect defend the first and the third one. But only one is telling the truth, thus, the first or the third one is the criminal. Both of them can be criminals, so the second and the fourth one can either be lying or telling the truth. The first and the third one are lying for sure as they are blaming the second and the fourth one.

'use strict';

function solve(n, m, s) {
  const diff = new Array(n + 2).fill(0);
  for (let str of s) {
    const num = Number(str.slice(1));
    if (str[0] === '+') {
      diff[num]++;
      diff[num + 1]--;
    } else {
      diff[0]++;
      diff[num]--;
      diff[num + 1]++;
      diff[n + 1]--;
    }
  }
  const suspects = new Set();
  let sum = diff[0];
  for (let i = 1; i <= n; i++) {
    sum += diff[i];
    if (sum === m) suspects.add(i);
  }
  const res = new Array(n);
  for (let i = 0; i < n; i++) {
    const str = s[i];
    const num = Number(str.slice(1));
    if (str[0] === '+') {
      if (suspects.has(num)) {
        if (suspects.size === 1) res[i] = 'Truth';else res[i] = 'Not defined';
      } else {
        res[i] = 'Lie';
      }
    } else {
      if (suspects.has(num)) {
        if (suspects.size === 1) res[i] = 'Lie';else res[i] = 'Not defined';
      } else {
        res[i] = 'Truth';
      }
    }
  }
  return res.join('\n');
}

async function main(read) {
  try {
    let res = [];
    let t = 1;
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push(await read());
      }
      res.push(solve(n, m, a));
    }
    console.log(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', () => {
  inputs = str.split('\n').values();
  main(read);
});

[{'input': ['1 1\r\n+1\r\n'], 'output': ['Truth\r\n']}, {'input': ['3 2\r\n-1\r\n-2\r\n-3\r\n'], 'output': ['Not defined\r\nNot defined\r\nNot defined\r\n']}, {'input': ['4 1\r\n+2\r\n-3\r\n+4\r\n-1\r\n'], 'output': ['Lie\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': ['1 0\r\n-1\r\n'], 'output': ['Lie\r\n']}, {'input': ['2 2\r\n+1\r\n+1\r\n'], 'output': ['Truth\r\nTruth\r\n']}, {'input': ['2 1\r\n+2\r\n+1\r\n'], 'output': ['Not defined\r\nNot defined\r\n']}, {'input': ['2 0\r\n-2\r\n-2\r\n'], 'output': ['Lie\r\nLie\r\n']}, {'input': ['3 1\r\n+2\r\n+3\r\n+3\r\n'], 'output': ['Truth\r\nLie\r\nLie\r\n']}, {'input': ['6 3\r\n+5\r\n+5\r\n+5\r\n+1\r\n+1\r\n+1\r\n'], 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': ['4 3\r\n-4\r\n-3\r\n-1\r\n-3\r\n'], 'output': ['Not defined\r\nTruth\r\nNot defined\r\nTruth\r\n']}, {'input': ['10 4\r\n-8\r\n+1\r\n-6\r\n-10\r\n+5\r\n-6\r\n-8\r\n-8\r\n-4\r\n-8\r\n'], 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['10 5\r\n-4\r\n+4\r\n+4\r\n-9\r\n-9\r\n-4\r\n-4\r\n+2\r\n-9\r\n-4\r\n'], 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['7 2\r\n+5\r\n+5\r\n+5\r\n-2\r\n+1\r\n-5\r\n-6\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nTruth\r\nNot defined\r\n']}, {'input': ['7 4\r\n+7\r\n-3\r\n-3\r\n-4\r\n+3\r\n+3\r\n+3\r\n'], 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': ['6 3\r\n-6\r\n-1\r\n+5\r\n+1\r\n+6\r\n+1\r\n'], 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nNot defined\r\n']}, {'input': ['5 3\r\n-2\r\n+2\r\n+2\r\n-3\r\n+5\r\n'], 'output': ['Not defined\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\n']}, {'input': ['3 0\r\n-2\r\n-2\r\n-2\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\n']}, {'input': ['5 3\r\n-1\r\n-1\r\n-4\r\n+1\r\n-4\r\n'], 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': ['9 6\r\n+2\r\n+7\r\n+7\r\n-1\r\n-4\r\n+7\r\n-7\r\n+7\r\n+5\r\n'], 'output': ['Lie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['43 18\r\n-14\r\n-28\r\n+16\r\n+10\r\n+25\r\n-30\r\n+25\r\n+30\r\n+25\r\n+25\r\n+25\r\n+25\r\n-25\r\n+22\r\n+3\r\n-17\r\n+16\r\n-25\r\n+10\r\n+14\r\n+41\r\n+25\r\n-25\r\n+33\r\n+24\r\n-23\r\n-25\r\n+25\r\n-22\r\n+29\r\n+28\r\n-25\r\n-25\r\n-29\r\n+11\r\n+26\r\n-25\r\n+25\r\n+10\r\n+1\r\n-20\r\n-17\r\n+23\r\n'], 'output': ['Truth\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nLie\r\nNot defined\r\nNot defined\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': ['28 12\r\n+10\r\n-7\r\n+17\r\n-20\r\n+7\r\n-7\r\n+13\r\n-21\r\n-7\r\n-7\r\n-18\r\n+7\r\n+7\r\n+3\r\n+6\r\n+14\r\n+7\r\n-24\r\n-21\r\n-7\r\n-7\r\n+4\r\n+7\r\n-7\r\n+21\r\n-7\r\n-26\r\n+7\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': ['17 9\r\n-6\r\n+16\r\n+5\r\n+16\r\n-17\r\n+17\r\n-11\r\n+5\r\n+14\r\n+5\r\n-8\r\n-5\r\n+6\r\n-2\r\n-11\r\n+4\r\n+17\r\n'], 'output': ['Truth\r\nNot defined\r\nNot defined\r\nNot defined\r\nTruth\r\nLie\r\nTruth\r\nNot defined\r\nLie\r\nNot defined\r\nTruth\r\nNot defined\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': ['14 3\r\n+14\r\n+12\r\n-9\r\n+9\r\n-9\r\n-9\r\n+8\r\n+9\r\n+2\r\n+1\r\n-13\r\n-9\r\n+13\r\n+3\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': ['10 4\r\n-9\r\n-8\r\n-5\r\n-9\r\n-7\r\n-9\r\n-9\r\n-9\r\n-4\r\n-9\r\n'], 'output': ['Lie\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['10 5\r\n-10\r\n-10\r\n-10\r\n-5\r\n-1\r\n+10\r\n-3\r\n-10\r\n-9\r\n-10\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['10 4\r\n-3\r\n-3\r\n-3\r\n-3\r\n-3\r\n-2\r\n-2\r\n-6\r\n-7\r\n-3\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': ['10 6\r\n-9\r\n-7\r\n-5\r\n-5\r\n-4\r\n-2\r\n-8\r\n-5\r\n-5\r\n-9\r\n'], 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': ['10 4\r\n-8\r\n-2\r\n-8\r\n+1\r\n-4\r\n-8\r\n-2\r\n-8\r\n-8\r\n-1\r\n'], 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': ['10 2\r\n-8\r\n+10\r\n+1\r\n+8\r\n+4\r\n+8\r\n+6\r\n-8\r\n+10\r\n+1\r\n'], 'output': ['Not defined\r\nLie\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nNot defined\r\nLie\r\nLie\r\n']}, {'input': ['10 3\r\n+9\r\n+3\r\n+8\r\n+3\r\n+6\r\n-3\r\n+6\r\n+8\r\n+3\r\n+7\r\n'], 'output': ['Lie\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nNot defined\r\nLie\r\n']}, {'input': ['10 8\r\n-2\r\n+9\r\n+9\r\n-4\r\n+9\r\n+9\r\n+4\r\n-9\r\n-3\r\n+9\r\n'], 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': ['10 7\r\n-4\r\n+6\r\n+4\r\n+9\r\n+6\r\n+6\r\n+6\r\n+6\r\n+6\r\n+2\r\n'], 'output': ['Truth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': ['10 4\r\n+3\r\n+5\r\n+6\r\n+10\r\n+5\r\n+5\r\n+6\r\n+8\r\n+5\r\n+6\r\n'], 'output': ['Lie\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['10 7\r\n-6\r\n-10\r\n-3\r\n-1\r\n-3\r\n-7\r\n-2\r\n-7\r\n-7\r\n-3\r\n'], 'output': ['Truth\r\nTruth\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nTruth\r\nNot defined\r\nNot defined\r\nNot defined\r\n']}, {'input': ['10 5\r\n-4\r\n-4\r\n-1\r\n-5\r\n-7\r\n-4\r\n-4\r\n-4\r\n-1\r\n-7\r\n'], 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\n']}, {'input': ['10 5\r\n-9\r\n-7\r\n-6\r\n-3\r\n-10\r\n-10\r\n-10\r\n-10\r\n-10\r\n-2\r\n'], 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': ['10 3\r\n-10\r\n-10\r\n-10\r\n-3\r\n-10\r\n-10\r\n-10\r\n-8\r\n-4\r\n-10\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nLie\r\n']}, {'input': ['10 5\r\n-8\r\n-8\r\n-4\r\n-9\r\n-10\r\n-2\r\n-9\r\n-8\r\n-8\r\n-8\r\n'], 'output': ['Lie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\n']}, {'input': ['10 5\r\n+7\r\n+8\r\n+9\r\n+1\r\n+7\r\n+7\r\n+7\r\n+6\r\n+6\r\n+7\r\n'], 'output': ['Truth\r\nLie\r\nLie\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': ['10 5\r\n+2\r\n+2\r\n+2\r\n+2\r\n+9\r\n+10\r\n+8\r\n+7\r\n+4\r\n+2\r\n'], 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nLie\r\nLie\r\nLie\r\nTruth\r\n']}, {'input': ['10 9\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+7\r\n+5\r\n+7\r\n+7\r\n+7\r\n'], 'output': ['Truth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nTruth\r\n']}, {'input': ['10 3\r\n+10\r\n+2\r\n+10\r\n+9\r\n+1\r\n+9\r\n+4\r\n+9\r\n+3\r\n+2\r\n'], 'output': ['Lie\r\nLie\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nTruth\r\nLie\r\nLie\r\n']}, {'input': ['10 6\r\n+10\r\n+10\r\n+10\r\n+3\r\n+10\r\n+10\r\n+6\r\n+6\r\n+10\r\n+8\r\n'], 'output': ['Truth\r\nTruth\r\nTruth\r\nLie\r\nTruth\r\nTruth\r\nLie\r\nLie\r\nTruth\r\nLie\r\n']}, {'input': ['3 2\r\n-1\r\n+2\r\n+3\r\n'], 'output': ['Truth\r\nNot defined\r\nNot defined\r\n']}]


var readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
var inputs = []

const fn = debounce(function () {
  var n = +inputs[0];
  var monsters = inputs.slice(1, n + 1).map(function (str) {
    return str.split(' ').map(function (x) {
      return +x;
    });
  });
  var t = +inputs[n + 1];
  var p = inputs[n + 2].split(' ').map(function (x) {
    return +x;
  });
  monsters.sort(function (a, b) {
    return a[1] - b[1];
  });
  var i = 0,
    j = 0,
    sum = 0,
    ans = 0,
    pre = 0,
    factor = 1;
  for (; i < n; i++) {
    var _a = monsters[i],
      cnt = _a[0],
      score = _a[1];
    sum += cnt;
    while (sum > p[j] && j < t) {
      ans += (p[j] - pre) * score * factor;
      // console.log(ans, p[j], pre, score, factor)
      pre = p[j];
      j++;
      factor++;
    }
    if (sum <= p[j]) {
      ans += (sum - pre) * score * factor;
      // console.log(ans, p[j], pre, score, factor)
      pre = sum;
    }
  }
  write(ans + '');
})
rl.on('line', function (line) {
  inputs.push(line.trim());
  fn()
})

function debounce(cb, delay) {
  if (delay === void 0) {
    delay = 100;
  }
  var timer = -1;
  return function () {
    if (timer !== -1) {
      clearTimeout(timer);
    }
    timer = setTimeout(function () {
      cb();
      timer = -1;
    }, delay);
  };
}

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

Vasya plays the Geometry Horse.The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are n types of geometric figures. The number of figures of type ki and figure cost ci is known for each figure type. A player gets ci·f  points for destroying one figure of type i, where f is the current factor. The factor value can be an integer number from 1 to t+1, inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i+1 after destruction of pi (1≤i≤t) figures, so the (pi+1)-th figure to be destroyed is considered with factor equal to i+1.Your task is to determine the maximum number of points Vasya can get after he destroys all figures. Take into account that Vasya is so tough that he can destroy figures in any order chosen by him.

The first line contains the only integer number n (1≤n≤100) — the number of figure types.
Each of the following n lines contains two integer numbers ki and ci (1≤ki≤10^9,0≤ci≤1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly.
The next line contains the only integer number t (1≤t≤100) — the number that describe the factor's changes.
The next line contains t integer numbers pi (1≤p1<p2<...<pt≤10^12), separated with spaces.
Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

Print the only number — the maximum number of points Vasya can get.

In the first example Vasya destroys three figures first and gets 3·1·10=30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10=40 points. As a result Vasya will get 70 points.
In the second example all 8 figures will be destroyed with factor 1, so Vasya will get (3·8+5·10)·1=74 points.

var readline = require('readline')
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
var inputs = []

const fn = debounce(function () {
  var n = +inputs[0];
  var monsters = inputs.slice(1, n + 1).map(function (str) {
    return str.split(' ').map(function (x) {
      return BigInt(x);
    });
  });
  var t = +inputs[n + 1];
  var p = inputs[n + 2].split(' ').map(function (x) {
    return BigInt(x);
  });
  p.push(BigInt(1e13));
  monsters.sort(function (a, b) {
    return Number(a[1] - b[1]);
  });
  var i = 0,
    j = 0,
    sum = 0n,
    ans = 0n,
    pre = 0n,
    factor = 1n;
  for (; i < n; i++) {
    var _a = monsters[i],
      cnt = _a[0],
      score = _a[1];
    sum += cnt;
    while (sum > p[j] && j < t) {
      ans += BigInt(p[j] - pre) * score * factor;
      // console.log(ans, p[j], pre, score, factor)
      pre = p[j];
      j++;
      factor++;
    }
    if (sum <= p[j]) {
      ans += BigInt(sum - pre) * score * factor;
      // console.log(ans, p[j], pre, score, factor)
      pre = sum;
    }
  }
  write(ans + '');
})
rl.on('line', function (line) {
  inputs.push(line.trim());
  fn()
})

function debounce(cb, delay) {
  if (delay === void 0) {
    delay = 100;
  }
  var timer = -1;
  return function () {
    if (timer !== -1) {
      clearTimeout(timer);
    }
    timer = setTimeout(function () {
      cb();
      timer = -1;
    }, delay);
  };
}

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


'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

const N = lll[0]
const D = lll[1]
const M = lll[2]
const L = lll[3]

const MAX = (N - 1) * M + L
console.log(MAX)

let cur = 0
let d = D

;(function () {
  while (true) {
    cur += D
    if (cur > MAX) return print(cur)

    let pop = d % M
    if (pop < L) {
      let ss = Math.floor(L / D)
      cur += D * ss
      d += D * ss
    }
    if (pop > L) return print(cur)
    d = D + pop
  }
})()

In one one-dimensional world there are n platforms. Platform with index k (platforms are numbered from 1) is a segment with coordinates [(k-1)m,(k-1)m+l], and l<m. Grasshopper Bob starts to jump along the platforms from point 0, with each jump he moves exactly d units right. Find out the coordinate of the point, where Bob will fall down. The grasshopper falls down, if he finds himself not on the platform, but if he finds himself on the edge of the platform, he doesn't fall down.

The first input line contains 4 integer numbers n, d, m, l (1≤n,d,m,l≤10^6,l<m) — respectively: amount of platforms, length of the grasshopper Bob's jump, and numbers m and l needed to find coordinates of the k-th platform: [(k-1)m,(k-1)m+l].

Output the coordinates of the point, where the grosshopper will fall down. Don't forget that if Bob finds himself on the platform edge, he doesn't fall down.

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

rl.on('line', (line) => {
  const [n, d, m, l] = line.split(' ').map(Number);
  let platforms = [];
  for (let i = 0; i < n; i++) {
    platforms.push([(i * m), ((i * m) + l)]);
  }
  let coordinate = 0;
  while (true) {
    coordinate += d;
    let onPlatform = false;
    for (let i = 0; i < n; i++) {
      if (coordinate >= platforms[i][0] && coordinate <= platforms[i][1]) {
        onPlatform = true;
        break;
      }
    }
    if (!onPlatform) {
      console.log(coordinate);
      break;
    }
  }
});


function calculateCutArea(input) {
  const [h, w] = input.split(' ').map(Number);

  // Initialize variables to store the best cut area
  let bestHeight = 0;
  let bestWidth = 0;
  let bestArea = 0;

  // Iterate over possible height values
  for (let height = h; height >= Math.ceil(h * 0.8); height--) {
    // Calculate the corresponding width based on the height and the allowed ratio
    const width = Math.floor(height / 0.8);

    // Check if the width is a power of 2
    if ((width & (width - 1)) === 0) {
      // Calculate the area of the current cut area
      const area = height * width;

      // Update the best cut area if the current area is larger
      if (area > bestArea) {
        bestHeight = height;
        bestWidth = width;
        bestArea = area;
      }
    }
  }

  return `${bestHeight} ${bestWidth}`;
}

const inputs = ['2 1\n', '2 2\n', '5 5\n'];
const outputs = inputs.map(calculateCutArea);

JSON.stringify(outputs);

One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height/width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2^x for some integer x). If those rules don't indicate the size of the cut are clearly, then the way with which the cut part possesses the largest area is chosen. Of course, both sides of the cut area should be integer. If there are several answers to this problem, you should choose the answer with the maximal height.

The first line contains a pair of integers h and w (1≤h,w≤10^9) which are the height and width of the uploaded photo in pixels.

Print two integers which are the height and width of the cut area.

function cutArea(h, w) {
    let min = Math.min(h, w);
    let max = Math.max(h, w);
    let power = Math.floor(Math.log2(min));
    let minCut = Math.pow(2, power);
    let maxCut = Math.min(max, Math.floor(minCut * 1.25));
    if (maxCut / minCut < 0.8) {
        minCut = Math.floor(maxCut / 1.25);
    }
    return [maxCut, minCut].sort((a, b) => b - a).join(' ');
}

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let input = [];
rl.on('line', function (line) {
    input.push(line);
}).on('close', function () {
    const [h, w] = input[0].split(' ').map(Number);
    console.log(cutArea(h, w));
    process.exit();
});


// Generated by CoffeeScript 1.4.0
(function() {
  var UniAccel, a, d, l, r, sa, sc, sd, sf, su, sv, sw, td, tf, tu, v, vb, w, _ref, _ref1;

  UniAccel = {
    vel_change_disp: function(v0, v1, a) {
      return (v1 * v1 - v0 * v0) / (2 * a);
    },
    disp_time: function(s, v0, a) {
      return (Math.sqrt(v0 * v0 + 2 * a * s) - v0) / a;
    }
  };

  _ref = readline().split(' ').map(function(x) {
    return parseInt(x);
  }), a = _ref[0], v = _ref[1];

  _ref1 = readline().split(' ').map(function(x) {
    return parseInt(x);
  }), l = _ref1[0], d = _ref1[1], w = _ref1[2];

  sw = UniAccel.vel_change_disp(0, w, a);

  sv = UniAccel.vel_change_disp(0, v, a);

  if (w > v || sw >= d) {
    if (sv > l) {
      print(1);
      print(UniAccel.disp_time(l, 0, a).toFixed(5));
    } else {
      print(2);
      print((v / a + (l - sv) / v).toFixed(5));
    }
  } else {
    sf = UniAccel.vel_change_disp(w, v, a);
    tf = 0;
    r = l - d;
    if (sf > r) {
      tf = UniAccel.disp_time(r, w, a);
    } else {
      tf = UniAccel.disp_time(sf, w, a) + (r - sf) / v;
    }
    su = UniAccel.vel_change_disp(0, v, a);
    sd = UniAccel.vel_change_disp(v, w, -a);
    sa = su + sd;
    if (sa <= d) {
      print(3);
      sc = d - sa;
      tu = UniAccel.disp_time(su, 0, a);
      td = UniAccel.disp_time(sd, v, -a);
      print((tu + sc / v + td + tf).toFixed(5));
    } else {
      print(4);
      vb = Math.sqrt(a * d + (w * w) / 2);
      su = UniAccel.vel_change_disp(0, vb, a);
      sd = UniAccel.vel_change_disp(vb, w, -a);
      tu = UniAccel.disp_time(su, 0, a);
      td = UniAccel.disp_time(sd, vb, -a);
      print((tu + td + tf).toFixed(5));
    }
  }

}).call(this);

Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the road where they are placed. Right after passing the sign it is allowed to drive at any speed.It is known that the car of an average Berland citizen has the acceleration (deceleration) speed of a km/h^2, and has maximum speed of v km/h. The road has the length of l km, and the speed sign, limiting the speed to w km/h, is placed d km (1≤d<l) away from the capital of Berland. The car has a zero speed at the beginning of the journey. Find the minimum time that an average Berland citizen will need to get from the capital to Bercouver, if he drives at the optimal speed.The car can enter Bercouver at any speed.

The first line of the input file contains two integer numbers a and v (1≤a,v≤10000). The second line contains three integer numbers l, d and w (2≤l≤10000; 1≤d<l; 1≤w≤10000).

Print the answer with at least five digits after the decimal point.

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

const getMinTime = (a, v, l, d, w) => {
    let t1, t2, t3, t4, t5, t6, t7, t8, t9;
    let v1 = Math.sqrt(2 * a * d);
    let v2 = Math.sqrt(2 * a * (l - d));
    if (v < w) {
        if (v < v1 && v < v2) {
            t1 = v / a;
            t2 = (l - a * t1 * t1 / 2) / v;
            return t1 + t2;
        } else if (v1 < v2) {
            t1 = v1 / a;
            t2 = (l - a * t1 * t1 / 2) / v1;
            return t1 + t2;
        } else {
            t1 = v2 / a;
            t2 = (l - a * t1 * t1 / 2) / v2;
            return t1 + t2;
        }
    } else {
        if (v1 < w) {
            t1 = v1 / a;
            t2 = (l - a * t1 * t1 / 2) / v1;
            return t1 + t2;
        } else {
            t1 = w / a;
            t2 = (d - a * t1 * t1 / 2) / w;
            if (v2 < v) {
                t3 = v2 / a;
                t4 = (l - d - a * t3 * t3 / 2) / v2;
                return t1 + t2 + t3 + t4;
            } else {
                t3 = (v * v - w * w) / (2 * a);
                t4 = (l - d - t3) / v;
                return t1 + t2 + t3 / v + t4;
            }
        }
    }
}

rl.on('line', (line) => {
    let [a, v] = line.split(' ').map(Number);
    let [l, d, w] = line.split(' ').map(Number);
    console.log(getMinTime(a, v, l, d, w).toFixed(5));
});


"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    var t = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var [n, k] = inputs[0].split(' ').map(v => +v);
    var h = inputs[1].split(' ').map(v => +v);
    var tree = new SplayTree();
    tree.insert(h[0]);
    var max = 1;
    var allRes = [];
    var i = 0, j = 0;
    while (i < n) {
        while (j < n) {
            j++;
            if (!h[j])
                break;
            tree.insert(h[j]);
            if (tree.max() - tree.min() > k)
                break;
        }
        if (max < j - i) {
            max = j - i;
            allRes = [(i + 1) + ' ' + j];
        }
        else if (max == j - i) {
            allRes.push((i + 1) + ' ' + j);
        }
        max = Math.max(j - i, max);
        tree.remove(h[i++]);
        while (tree.max() - tree.min() > k) {
            tree.remove(h[i++]);
        }
    }
    console.log(max, allRes.length);
    console.log(allRes.join('\n'));
    // console.log(Date.now() - t)
})();
var SplayTree = eval(`
(function () {
  var Node = /** @class */ (function () {
    function Node(key, data) {
      this.next = null;
      this.key = key;
      this.data = data;
      this.left = null;
      this.right = null;
    }
    return Node;
  }());

  /* follows "An implementation of top-down splaying"
   * by D. Sleator <sleator@cs.cmu.edu> March 1992
   */
  function DEFAULT_COMPARE(a, b) {
    return a > b ? 1 : a < b ? -1 : 0;
  }
  /**
   * Simple top down splay, not requiring i to be in the tree t.
   */
  function splay(i, t, comparator) {
    var N = new Node(null, null);
    var l = N;
    var r = N;
    while (true) {
      var cmp = comparator(i, t.key);
      //if (i < t.key) {
      if (cmp < 0) {
        if (t.left === null)
          break;
        //if (i < t.left.key) {
        if (comparator(i, t.left.key) < 0) {
          var y = t.left; /* rotate right */
          t.left = y.right;
          y.right = t;
          t = y;
          if (t.left === null)
            break;
        }
        r.left = t; /* link right */
        r = t;
        t = t.left;
        //} else if (i > t.key) {
      }
      else if (cmp > 0) {
        if (t.right === null)
          break;
        //if (i > t.right.key) {
        if (comparator(i, t.right.key) > 0) {
          var y = t.right; /* rotate left */
          t.right = y.left;
          y.left = t;
          t = y;
          if (t.right === null)
            break;
        }
        l.right = t; /* link left */
        l = t;
        t = t.right;
      }
      else
        break;
    }
    /* assemble */
    l.right = t.left;
    r.left = t.right;
    t.left = N.right;
    t.right = N.left;
    return t;
  }
  function insert(i, data, t, comparator) {
    var node = new Node(i, data);
    if (t === null) {
      node.left = node.right = null;
      return node;
    }
    t = splay(i, t, comparator);
    var cmp = comparator(i, t.key);
    if (cmp < 0) {
      node.left = t.left;
      node.right = t;
      t.left = null;
    }
    else if (cmp >= 0) {
      node.right = t.right;
      node.left = t;
      t.right = null;
    }
    return node;
  }
  function split(key, v, comparator) {
    var left = null;
    var right = null;
    if (v) {
      v = splay(key, v, comparator);
      var cmp = comparator(v.key, key);
      if (cmp === 0) {
        left = v.left;
        right = v.right;
      }
      else if (cmp < 0) {
        right = v.right;
        v.right = null;
        left = v;
      }
      else {
        left = v.left;
        v.left = null;
        right = v;
      }
    }
    return { left: left, right: right };
  }
  function merge(left, right, comparator) {
    if (right === null)
      return left;
    if (left === null)
      return right;
    right = splay(left.key, right, comparator);
    right.left = left;
    return right;
  }
  var Tree = /** @class */ (function () {
    function Tree(comparator) {
      if (comparator === void 0) { comparator = DEFAULT_COMPARE; }
      this._root = null;
      this._size = 0;
      this._comparator = comparator;
    }
    /**
     * Inserts a key, allows duplicates
     */
    Tree.prototype.insert = function (key, data) {
      this._size++;
      return this._root = insert(key, data, this._root, this._comparator);
    };
    /**
     * Adds a key, if it is not present in the tree
     */
    Tree.prototype.add = function (key, data) {
      var node = new Node(key, data);
      if (this._root === null) {
        node.left = node.right = null;
        this._size++;
        this._root = node;
      }
      var comparator = this._comparator;
      var t = splay(key, this._root, comparator);
      var cmp = comparator(key, t.key);
      if (cmp === 0)
        this._root = t;
      else {
        if (cmp < 0) {
          node.left = t.left;
          node.right = t;
          t.left = null;
        }
        else if (cmp > 0) {
          node.right = t.right;
          node.left = t;
          t.right = null;
        }
        this._size++;
        this._root = node;
      }
      return this._root;
    };
    /**
     * @param  {Key} key
     * @return {Node|null}
     */
    Tree.prototype.remove = function (key) {
      this._root = this._remove(key, this._root, this._comparator);
    };
    /**
     * Deletes i from the tree if it's there
     */
    Tree.prototype._remove = function (i, t, comparator) {
      var x;
      if (t === null)
        return null;
      t = splay(i, t, comparator);
      var cmp = comparator(i, t.key);
      if (cmp === 0) { /* found it */
        if (t.left === null) {
          x = t.right;
        }
        else {
          x = splay(i, t.left, comparator);
          x.right = t.right;
        }
        this._size--;
        return x;
      }
      return t; /* It wasn't there */
    };
    /**
     * Removes and returns the node with smallest key
     */
    Tree.prototype.pop = function () {
      var node = this._root;
      if (node) {
        while (node.left)
          node = node.left;
        this._root = splay(node.key, this._root, this._comparator);
        this._root = this._remove(node.key, this._root, this._comparator);
        return { key: node.key, data: node.data };
      }
      return null;
    };
    /**
     * Find without splaying
     */
    Tree.prototype.findStatic = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return current;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return null;
    };
    Tree.prototype.find = function (key) {
      if (this._root) {
        this._root = splay(key, this._root, this._comparator);
        if (this._comparator(key, this._root.key) !== 0)
          return null;
      }
      return this._root;
    };
    Tree.prototype.contains = function (key) {
      var current = this._root;
      var compare = this._comparator;
      while (current) {
        var cmp = compare(key, current.key);
        if (cmp === 0)
          return true;
        else if (cmp < 0)
          current = current.left;
        else
          current = current.right;
      }
      return false;
    };
    Tree.prototype.forEach = function (visitor, ctx) {
      var current = this._root;
      var Q = []; /* Initialize stack s */
      var done = false;
      while (!done) {
        if (current !== null) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length !== 0) {
            current = Q.pop();
            visitor.call(ctx, current);
            current = current.right;
          }
          else
            done = true;
        }
      }
      return this;
    };

    Tree.prototype.range = function (low, high, fn, ctx) {
      var Q = [];
      var compare = this._comparator;
      var node = this._root;
      var cmp;
      while (Q.length !== 0 || node) {
        if (node) {
          Q.push(node);
          node = node.left;
        }
        else {
          node = Q.pop();
          cmp = compare(node.key, high);
          if (cmp > 0) {
            break;
          }
          else if (compare(node.key, low) >= 0) {
            if (fn.call(ctx, node))
              return this; // stop if smth is returned
          }
          node = node.right;
        }
      }
      return this;
    };
    /**
     * Returns array of keys
     */
    Tree.prototype.keys = function () {
      var keys = [];
      this.forEach(function (_a) {
        var key = _a.key;
        return keys.push(key);
      });
      return keys;
    };
    /**
     * Returns array of all the data in the nodes
     */
    Tree.prototype.values = function () {
      var values = [];
      this.forEach(function (_a) {
        var data = _a.data;
        return values.push(data);
      });
      return values;
    };
    Tree.prototype.min = function () {
      if (this._root)
        return this.minNode(this._root).key;
      return null;
    };
    Tree.prototype.max = function () {
      if (this._root)
        return this.maxNode(this._root).key;
      return null;
    };
    Tree.prototype.minNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.left)
          t = t.left;
      return t;
    };
    Tree.prototype.maxNode = function (t) {
      if (t === void 0) { t = this._root; }
      if (t)
        while (t.right)
          t = t.right;
      return t;
    };
    /**
     * Returns node at given index
     */
    Tree.prototype.at = function (index) {
      var current = this._root;
      var done = false;
      var i = 0;
      var Q = [];
      while (!done) {
        if (current) {
          Q.push(current);
          current = current.left;
        }
        else {
          if (Q.length > 0) {
            current = Q.pop();
            if (i === index)
              return current;
            i++;
            current = current.right;
          }
          else
            done = true;
        }
      }
      return null;
    };
    Tree.prototype.next = function (d) {
      var root = this._root;
      var successor = null;
      if (d.right) {
        successor = d.right;
        while (successor.left)
          successor = successor.left;
        return successor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0) {
          successor = root;
          root = root.left;
        }
        else
          root = root.right;
      }
      return successor;
    };
    Tree.prototype.prev = function (d) {
      var root = this._root;
      var predecessor = null;
      if (d.left !== null) {
        predecessor = d.left;
        while (predecessor.right)
          predecessor = predecessor.right;
        return predecessor;
      }
      var comparator = this._comparator;
      while (root) {
        var cmp = comparator(d.key, root.key);
        if (cmp === 0)
          break;
        else if (cmp < 0)
          root = root.left;
        else {
          predecessor = root;
          root = root.right;
        }
      }
      return predecessor;
    };
    Tree.prototype.clear = function () {
      this._root = null;
      this._size = 0;
      return this;
    };
    Tree.prototype.toList = function () {
      return toList(this._root);
    };
    /**
     * Bulk-load items. Both array have to be same size
     */
    Tree.prototype.load = function (keys, values, presort) {
      if (values === void 0) { values = []; }
      if (presort === void 0) { presort = false; }
      var size = keys.length;
      var comparator = this._comparator;
      // sort if needed
      if (presort)
        sort(keys, values, 0, size - 1, comparator);
      if (this._root === null) { // empty tree
        this._root = loadRecursive(keys, values, 0, size);
        this._size = size;
      }
      else { // that re-builds the whole tree from two in-order traversals
        var mergedList = mergeLists(this.toList(), createList(keys, values), comparator);
        size = this._size + size;
        this._root = sortedListToBST({ head: mergedList }, 0, size);
      }
      return this;
    };
    Tree.prototype.isEmpty = function () { return this._root === null; };
    Object.defineProperty(Tree.prototype, "size", {
      get: function () { return this._size; },
      enumerable: true,
      configurable: true
    });
    Object.defineProperty(Tree.prototype, "root", {
      get: function () { return this._root; },
      enumerable: true,
      configurable: true
    });
    Tree.prototype.toString = function (printNode) {
      if (printNode === void 0) { printNode = function (n) { return String(n.key); }; }
      var out = [];
      printRow(this._root, '', true, function (v) { return out.push(v); }, printNode);
      return out.join('');
    };
    Tree.prototype.update = function (key, newKey, newData) {
      var comparator = this._comparator;
      var _a = split(key, this._root, comparator), left = _a.left, right = _a.right;
      if (comparator(key, newKey) < 0) {
        right = insert(newKey, newData, right, comparator);
      }
      else {
        left = insert(newKey, newData, left, comparator);
      }
      this._root = merge(left, right, comparator);
    };
    Tree.prototype.split = function (key) {
      return split(key, this._root, this._comparator);
    };
    return Tree;
  }());
  function loadRecursive(keys, values, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var key = keys[middle];
      var data = values[middle];
      var node = new Node(key, data);
      node.left = loadRecursive(keys, values, start, middle);
      node.right = loadRecursive(keys, values, middle + 1, end);
      return node;
    }
    return null;
  }
  function createList(keys, values) {
    var head = new Node(null, null);
    var p = head;
    for (var i = 0; i < keys.length; i++) {
      p = p.next = new Node(keys[i], values[i]);
    }
    p.next = null;
    return head.next;
  }
  function toList(root) {
    var current = root;
    var Q = [];
    var done = false;
    var head = new Node(null, null);
    var p = head;
    while (!done) {
      if (current) {
        Q.push(current);
        current = current.left;
      }
      else {
        if (Q.length > 0) {
          current = p = p.next = Q.pop();
          current = current.right;
        }
        else
          done = true;
      }
    }
    p.next = null; // that'll work even if the tree was empty
    return head.next;
  }
  function sortedListToBST(list, start, end) {
    var size = end - start;
    if (size > 0) {
      var middle = start + Math.floor(size / 2);
      var left = sortedListToBST(list, start, middle);
      var root = list.head;
      root.left = left;
      list.head = list.head.next;
      root.right = sortedListToBST(list, middle + 1, end);
      return root;
    }
    return null;
  }
  function mergeLists(l1, l2, compare) {
    var head = new Node(null, null); // dummy
    var p = head;
    var p1 = l1;
    var p2 = l2;
    while (p1 !== null && p2 !== null) {
      if (compare(p1.key, p2.key) < 0) {
        p.next = p1;
        p1 = p1.next;
      }
      else {
        p.next = p2;
        p2 = p2.next;
      }
      p = p.next;
    }
    if (p1 !== null) {
      p.next = p1;
    }
    else if (p2 !== null) {
      p.next = p2;
    }
    return head.next;
  }
  function sort(keys, values, left, right, compare) {
    if (left >= right)
      return;
    var pivot = keys[(left + right) >> 1];
    var i = left - 1;
    var j = right + 1;
    while (true) {
      do
        i++;
      while (compare(keys[i], pivot) < 0);
      do
        j--;
      while (compare(keys[j], pivot) > 0);
      if (i >= j)
        break;
      var tmp = keys[i];
      keys[i] = keys[j];
      keys[j] = tmp;
      tmp = values[i];
      values[i] = values[j];
      values[j] = tmp;
    }
    sort(keys, values, left, j, compare);
    sort(keys, values, j + 1, right, compare);
  }

  return Tree;

})();
`);

There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.

The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.

In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters. In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.

/**
 *  10.12 night
 *  https://codeforces.com/problemset/problem/6/E
 *
 *  reference:
 *  https://codeforces.com/problemset/status/6/problem/E/page/46?order=BY_PROGRAM_LENGTH_ASC
 *  https://codeforces.com/problemset/submission/6/94367599
 */

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, init) {
    if (typeof (b) == 'function') return Arr(0, a - 1, b, fn);
    if (b < a) return [];
    let arr = Array(b - a + 1).fill(0);
    if (init) init(arr);
    for (let i = a; i <= b; i++) arr[i] = 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) {
    let set = new Set();
    return this.filter(v => {
        let 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.for = function (a, b, fn) {
    let res;
    for (let i = a; i <= b; i++) {
        if ((res = fn(this[i], i, this)) != null) return res;
    }
};
Array.prototype.forR = function (a, b, fn) {
    let res
    for (let i = a; i >= b; i--) {
        if ((res = fn(this[i], i, this)) != null) return res;
    }
};

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

let MOD = 998244353;

function inv(b) {
    for (let 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);
    return (u + MOD) % MOD;
}

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);

function main() {
    let inp = input.split(/\s+/).map(v => +v), _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 = Math.min, max = Math.max,
        abs = Math.abs;

    let [n, k] = $(2), h = $(n), tree = new AVLTree();
    tree.insert(h[0]);
    let Max = 1;
    let allRes = [];
    let i = 0, j = 0;
    while (i < n) {
        while (j < n) {
            j++;
            if (!h[j]) break;
            tree.insert(h[j]);
            if (tree.max() - tree.min() > k) break;
        }
        if (Max < j - i) {
            Max = j - i;
            allRes = [(i + 1) + ' ' + j];
        } else if (Max == j - i) {
            allRes.push((i + 1) + ' ' + j);
        }
        Max = max(j - i, Max);
        tree.remove(h[i++]);
        while (tree.max() - tree.min() > k) {
            tree.remove(h[i++]);
        }
    }
    log(Max, allRes.length);
    log(allRes.join('\n'));
}

let AVLTree = (function () {
    function print(root, printNode) {
        if (printNode === void 0) printNode = function (n) {
            return n.key;
        };

        let out = [];
        row(root, '', true, function (v) {
            return out.push(v);
        }, printNode);
        return out.join('');
    }

    function isBalanced(root) {
        if (root === null) {
            return true;
        }
        let lh = height(root.left);
        let rh = height(root.right);
        if (Math.abs(lh - rh) <= 1 &&
            isBalanced(root.left) &&
            isBalanced(root.right)) {
            return true;
        }
        return false;
    }

    function height(node) {
        return node ? (1 + Math.max(height(node.left), height(node.right))) : 0;
    }

    function loadRecursive(parent, keys, values, start, end) {
        let size = end - start;
        if (size > 0) {
            let middle = start + Math.floor(size / 2);
            let key = keys[middle];
            let data = values[middle];
            let node = { key: key, data: data, parent: parent };
            node.left = loadRecursive(node, keys, values, start, middle);
            node.right = loadRecursive(node, keys, values, middle + 1, end);
            return node;
        }
        return null;
    }

    function markBalance(node) {
        if (node === null) {
            return 0;
        }
        let lh = markBalance(node.left);
        let rh = markBalance(node.right);

        node.balanceFactor = lh - rh;
        return Math.max(lh, rh) + 1;
    }

    function sort(keys, values, left, right, compare) {
        if (left >= right) {
            return;
        }
        let pivot = keys[(left + right) >> 1];
        let i = left - 1;
        let j = right + 1;
        while (true) {
            do {
                i++;
            } while (compare(keys[i], pivot) < 0);
            do {
                j--;
            } while (compare(keys[j], pivot) > 0);
            if (i >= j) {
                break;
            }
            let tmp = keys[i];
            keys[i] = keys[j];
            keys[j] = tmp;

            tmp = values[i];
            values[i] = values[j];
            values[j] = tmp;
        }

        sort(keys, values, left, j, compare);
        sort(keys, values, j + 1, right, compare);
    }

    function DEFAULT_COMPARE(a, b) {
        return a > b ? 1 : a < b ? -1 : 0;
    }

    function rotateLeft(node) {
        let rightNode = node.right;
        node.right = rightNode.left;

        if (rightNode.left) {
            rightNode.left.parent = node;
        }

        rightNode.parent = node.parent;
        if (rightNode.parent) {
            if (rightNode.parent.left === node) {
                rightNode.parent.left = rightNode;
            } else {
                rightNode.parent.right = rightNode;
            }
        }

        node.parent = rightNode;
        rightNode.left = node;

        node.balanceFactor += 1;
        if (rightNode.balanceFactor < 0) {
            node.balanceFactor -= rightNode.balanceFactor;
        }

        rightNode.balanceFactor += 1;
        if (node.balanceFactor > 0) {
            rightNode.balanceFactor += node.balanceFactor;
        }
        return rightNode;
    }

    function rotateRight(node) {
        let leftNode = node.left;
        node.left = leftNode.right;
        if (node.left) {
            node.left.parent = node;
        }

        leftNode.parent = node.parent;
        if (leftNode.parent) {
            if (leftNode.parent.left === node) {
                leftNode.parent.left = leftNode;
            } else {
                leftNode.parent.right = leftNode;
            }
        }

        node.parent = leftNode;
        leftNode.right = node;

        node.balanceFactor -= 1;
        if (leftNode.balanceFactor > 0) {
            node.balanceFactor -= leftNode.balanceFactor;
        }

        leftNode.balanceFactor -= 1;
        if (node.balanceFactor < 0) {
            leftNode.balanceFactor += node.balanceFactor;
        }

        return leftNode;
    }

    let AVLTree = function AVLTree(comparator, noDuplicates) {
        if (noDuplicates === void 0) noDuplicates = false;

        this._comparator = comparator || DEFAULT_COMPARE;
        this._root = null;
        this._size = 0;
        this._noDuplicates = !!noDuplicates;
    };

    let prototypeAccessors = { size: { configurable: true } };

    AVLTree.prototype.destroy = function destroy() {
        return this.clear();
    };

    AVLTree.prototype.clear = function clear() {
        this._root = null;
        this._size = 0;
        return this;
    };

    prototypeAccessors.size.get = function () {
        return this._size;
    };

    AVLTree.prototype.contains = function contains(key) {
        if (this._root) {
            let node = this._root;
            let comparator = this._comparator;
            while (node) {
                let cmp = comparator(key, node.key);
                if (cmp === 0) {
                    return true;
                } else if (cmp < 0) {
                    node = node.left;
                } else {
                    node = node.right;
                }
            }
        }
        return false;
    };

    AVLTree.prototype.next = function next(node) {
        let successor = node;
        if (successor) {
            if (successor.right) {
                successor = successor.right;
                while (successor.left) {
                    successor = successor.left;
                }
            } else {
                successor = node.parent;
                while (successor && successor.right === node) {
                    node = successor;
                    successor = successor.parent;
                }
            }
        }
        return successor;
    };

    AVLTree.prototype.prev = function prev(node) {
        let predecessor = node;
        if (predecessor) {
            if (predecessor.left) {
                predecessor = predecessor.left;
                while (predecessor.right) {
                    predecessor = predecessor.right;
                }
            } else {
                predecessor = node.parent;
                while (predecessor && predecessor.left === node) {
                    node = predecessor;
                    predecessor = predecessor.parent;
                }
            }
        }
        return predecessor;
    };

    AVLTree.prototype.forEach = function forEach(callback) {
        let current = this._root;
        let s = [], done = false, i = 0;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    callback(current, i++);
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return this;
    };

    AVLTree.prototype.range = function range(low, high, fn, ctx) {
        let this$1 = this;
        let Q = [];
        let compare = this._comparator;
        let node = this._root, cmp;
        while (Q.length !== 0 || node) {
            if (node) {
                Q.push(node);
                node = node.left;
            } else {
                node = Q.pop();
                cmp = compare(node.key, high);
                if (cmp > 0) {
                    break;
                } else if (compare(node.key, low) >= 0) {
                    if (fn.call(ctx, node)) {
                        return this$1;
                    }
                }
                node = node.right;
            }
        }
        return this;
    };

    AVLTree.prototype.keys = function keys() {
        let current = this._root;
        let s = [], r = [], done = false;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    r.push(current.key);
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return r;
    };

    AVLTree.prototype.values = function values() {
        let current = this._root;
        let s = [], r = [], done = false;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    r.push(current.data);
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return r;
    };

    AVLTree.prototype.at = function at(index) {
        let current = this._root;
        let s = [], done = false, i = 0;
        while (!done) {
            if (current) {
                s.push(current);
                current = current.left;
            } else {
                if (s.length > 0) {
                    current = s.pop();
                    if (i === index) {
                        return current;
                    }
                    i++;
                    current = current.right;
                } else {
                    done = true;
                }
            }
        }
        return null;
    };

    AVLTree.prototype.minNode = function minNode() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.left) {
            node = node.left;
        }
        return node;
    };

    AVLTree.prototype.maxNode = function maxNode() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.right) {
            node = node.right;
        }
        return node;
    };

    AVLTree.prototype.min = function min() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.left) {
            node = node.left;
        }
        return node.key;
    };

    AVLTree.prototype.max = function max() {
        let node = this._root;
        if (!node) {
            return null;
        }
        while (node.right) {
            node = node.right;
        }
        return node.key;
    };

    AVLTree.prototype.isEmpty = function isEmpty() {
        return !this._root;
    };

    AVLTree.prototype.pop = function pop() {
        let node = this._root, returnValue = null;
        if (node) {
            while (node.left) {
                node = node.left;
            }
            returnValue = { key: node.key, data: node.data };
            this.remove(node.key);
        }
        return returnValue;
    };

    AVLTree.prototype.find = function find(key) {
        let root = this._root;
        let subtree = root, cmp;
        let compare = this._comparator;
        while (subtree) {
            cmp = compare(key, subtree.key);
            if (cmp === 0) {
                return subtree;
            } else if (cmp < 0) {
                subtree = subtree.left;
            } else {
                subtree = subtree.right;
            }
        }

        return null;
    };

    AVLTree.prototype.insert = function insert(key, data) {
        let this$1 = this;
        if (!this._root) {
            this._root = {
                parent: null, left: null, right: null, balanceFactor: 0,
                key: key, data: data
            };
            this._size++;
            return this._root;
        }

        let compare = this._comparator;
        let node = this._root;
        let parent = null;
        let cmp = 0;

        if (this._noDuplicates) {
            while (node) {
                cmp = compare(key, node.key);
                parent = node;
                if (cmp === 0) {
                    return null;
                } else if (cmp < 0) {
                    node = node.left;
                } else {
                    node = node.right;
                }
            }
        } else {
            while (node) {
                cmp = compare(key, node.key);
                parent = node;
                if (cmp <= 0) {
                    node = node.left;
                } //return null;
                else {
                    node = node.right;
                }
            }
        }

        let newNode = {
            left: null,
            right: null,
            balanceFactor: 0,
            parent: parent, key: key, data: data
        };
        let newRoot;
        if (cmp <= 0) {
            parent.left = newNode;
        } else {
            parent.right = newNode;
        }

        while (parent) {
            cmp = compare(parent.key, key);
            if (cmp < 0) {
                parent.balanceFactor -= 1;
            } else {
                parent.balanceFactor += 1;
            }

            if (parent.balanceFactor === 0) {
                break;
            } else if (parent.balanceFactor < -1) {
                if (parent.right.balanceFactor === 1) {
                    rotateRight(parent.right);
                }
                newRoot = rotateLeft(parent);
                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                break;
            } else if (parent.balanceFactor > 1) {
                if (parent.left.balanceFactor === -1) {
                    rotateLeft(parent.left);
                }
                newRoot = rotateRight(parent);

                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                break;
            }
            parent = parent.parent;
        }

        this._size++;
        return newNode;
    };

    AVLTree.prototype.remove = function remove(key) {
        let this$1 = this;
        if (!this._root) {
            return null;
        }
        let node = this._root;
        let compare = this._comparator;
        let cmp = 0;
        while (node) {
            cmp = compare(key, node.key);
            if (cmp === 0) {
                break;
            } else if (cmp < 0) {
                node = node.left;
            } else {
                node = node.right;
            }
        }
        if (!node) {
            return null;
        }

        let returnValue = node.key;
        let max, min;

        if (node.left) {
            max = node.left;

            while (max.left || max.right) {
                while (max.right) {
                    max = max.right;
                }

                node.key = max.key;
                node.data = max.data;
                if (max.left) {
                    node = max;
                    max = max.left;
                }
            }

            node.key = max.key;
            node.data = max.data;
            node = max;
        }

        if (node.right) {
            min = node.right;

            while (min.left || min.right) {
                while (min.left) {
                    min = min.left;
                }

                node.key = min.key;
                node.data = min.data;
                if (min.right) {
                    node = min;
                    min = min.right;
                }
            }

            node.key = min.key;
            node.data = min.data;
            node = min;
        }

        let parent = node.parent;
        let pp = node;
        let newRoot;

        while (parent) {
            if (parent.left === pp) {
                parent.balanceFactor -= 1;
            } else {
                parent.balanceFactor += 1;
            }

            if (parent.balanceFactor < -1) {
                if (parent.right.balanceFactor === 1) {
                    rotateRight(parent.right);
                }
                newRoot = rotateLeft(parent);

                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                parent = newRoot;
            } else if (parent.balanceFactor > 1) {
                if (parent.left.balanceFactor === -1) {
                    rotateLeft(parent.left);
                }
                newRoot = rotateRight(parent);
                if (parent === this$1._root) {
                    this$1._root = newRoot;
                }
                parent = newRoot;
            }
            if (parent.balanceFactor === -1 || parent.balanceFactor === 1) {
                break;
            }
            pp = parent;
            parent = parent.parent;
        }

        if (node.parent) {
            if (node.parent.left === node) {
                node.parent.left = null;
            } else {
                node.parent.right = null;
            }
        }

        if (node === this._root) {
            this._root = null;
        }

        this._size--;
        return returnValue;
    };

    AVLTree.prototype.load = function load(keys, values, presort) {
        if (keys === void 0) keys = [];
        if (values === void 0) values = [];

        if (this._size !== 0) {
            throw new Error('bulk-load: tree is not empty');
        }
        let size = keys.length;
        if (presort) {
            sort(keys, values, 0, size - 1, this._comparator);
        }
        this._root = loadRecursive(null, keys, values, 0, size);
        markBalance(this._root);
        this._size = size;
        return this;
    };

    AVLTree.prototype.isBalanced = function isBalanced$1() {
        return isBalanced(this._root);
    };

    AVLTree.prototype.toString = function toString(printNode) {
        return print(this._root, printNode);
    };

    Object.defineProperties(AVLTree.prototype, prototypeAccessors);

    AVLTree.default = AVLTree;

    return AVLTree;

})();


fun main() {
    val (n, k) = readLine()!!
        .split(" ")
        .map { it.toInt() }
    val s = readLine()!!
    var cnv = 0
    var ans = "1"
    for (i in 0 until n) {
        if (i == 0) {
            if (s[i] != '1') {
                cnv += 1
            }
            continue
        } else {
            if (s[i] != '0') {
                cnv += 1
            }
            ans += "0"
        }
        if (cnv == k) {
            ans += s.substring(i + 1)
            break
        }
    }
    println(if (ans == "1") "0" else ans)
}

Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ digits and doesn't contain any leading zeroes.

Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.

NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings

private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of Longs

var n = 0

fun main() {

    var (n, k) = readInts()

    val s = readLine()!!

    val sb = StringBuilder()

    if (s.length == 1){
        if (k > 0){
            print("0")
        } else {
            print(s)
        }
        return
    }

    for ((i, c) in s.withIndex()) {
        if (k == 0) {
            sb.append(c)
            continue
        }

        if (i == 0) {
            if (c != '1') {
                sb.append('1')
                k--
            } else {
                sb.append(c)
            }
        } else if (c != '0') {
            k--
            sb.append('0')
        } else {
            sb.append(c)
        }
    }

    print(sb)
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val l = r.readLine()!!.toInt()
    val day = r.readLine()!!.split(" ").map { it.toInt() }
    fun f(i: Int, type: Int): Int =
        when{
            i == l-1 -> if (type==day[i]||day[i]==3) 0 else 1
            type==day[i]||day[i]==3 -> f(i+1, 3-type)
            else -> 1+ minOf(f(i+1, type), f(i+1, 3-type))
        }
    println(minOf(f(0, 1), f(0, 2)))
}

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:  on this day the gym is closed and the contest is not carried out;  on this day the gym is closed and the contest is carried out;  on this day the gym is open and the contest is not carried out;  on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations. The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:    ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;  ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;  ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;  ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:   to do sport on any two consecutive days,  to write the contest on any two consecutive days.

NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

// compile : kotlinc newyear.kt -include-runtime -d test.jar
// run : java -jar test.jar

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main()
{
	// var state = Array(4,{0})
	var dp = Array(105,{IntArray(4)})

	var n = readInt()
	var arr = readInts()
	// arr = readInts()

	for(i in 1..n)
		for(j in 0..2)
			dp[i][j] = 1000000
	for(i in 0..2)
		dp[0][i] = 0
	for(i in 1..n)
	{
		var r = arr[i-1]
		// println("${r} ${dp[i][0]} ${dp[i][1]} ${dp[i][2]}")
		dp[i][0] = 1+minOf(dp[i-1][0],dp[i-1][1],dp[i-1][2])
		if(r==1)
			dp[i][1] = minOf(dp[i-1][0],dp[i-1][2])
		if(r==2)
			dp[i][2] = minOf(dp[i-1][0],dp[i-1][1])
		if(r==3)
		{
			dp[i][1] = minOf(dp[i-1][0],dp[i-1][2])
			dp[i][2] = minOf(dp[i-1][0],dp[i-1][1])
		}
		// println("${r} ${dp[i][0]} ${dp[i][1]} ${dp[i][2]}")
	}

	var res = minOf(dp[n][0],dp[n][1],dp[n][2])
	println("${res}")
}


private fun readInt() = readString().toInt()
private fun readString() = readLine().toString()
private fun readDouble() = readString().toDouble()
private fun readListString() = readString().split(" ")
private fun readListInt() = readString().split(" ").map { it.toInt() }

fun main() {

    readInt()
    val nums = readListInt()
    var sum = 0L
    for (n in nums)
        sum += n
    val ans = mutableListOf<Int>()
    for (i in 0 until nums.size) {
        val left = sum - nums[i]
        if (left / (nums.size - 1) == nums[i].toLong()) {
            ans.add(i + 1)
        }
    }
    println(ans.size)
    if (ans.isNotEmpty()) {
        println(ans.joinToString(" "))
    }

}

You are given a sequence of positive integers a1,a2,...,an. Find all such indices i, that the i-th element equals the arithmetic mean of all other elements (that is all elements except for this one).

The first line contains the integer n (2≤n≤2·10^5). The second line contains elements of the sequence a1,a2,...,an (1≤ai≤1000). All the elements are positive integers.

Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to n.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line.

private fun readInt() = readString().toInt()
private fun readString() = readLine().toString()
private fun readDouble() = readString().toDouble()
private fun readListString() = readString().split(" ")
private fun readListInt() = readString().split(" ").map { it.toInt() }

fun main() {

    readInt()
    val nums = readListInt()
    var sum = 0L
    for (n in nums)
        sum += n
    val ans = mutableListOf<Int>()
    for (i in 0 until nums.size) {
        val left = sum - nums[i]
        if (left / (nums.size - 1) == nums[i].toLong() && nums[i]*(nums.size-1L)==left) {
            ans.add(i + 1)
        }
    }
    println(ans.size)
    if (ans.isNotEmpty()) {
        println(ans.joinToString(" "))
    }

}