Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (called vertices), some of which are connected using n - 1 line segments (edges) so that each pair of vertices is connected by a path (a sequence of one or more edges).To decipher the prophecy, Heidi needs to perform a number of steps. The first is counting the number of lifelines in the tree – these are paths of length 2, i.e., consisting of two edges. Help her!

The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n). It is guaranteed that the input represents a tree.

Print one integer – the number of lifelines in the tree.

NoteIn the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.


You are given a matrix, consisting of $$$n$$$ rows and $$$m$$$ columns. The rows are numbered top to bottom, the columns are numbered left to right.Each cell of the matrix can be either free or locked.Let's call a path in the matrix a staircase if it:   starts and ends in the free cell;  visits only free cells;  has one of the two following structures:   the second cell is $$$1$$$ to the right from the first one, the third cell is $$$1$$$ to the bottom from the second one, the fourth cell is $$$1$$$ to the right from the third one, and so on;  the second cell is $$$1$$$ to the bottom from the first one, the third cell is $$$1$$$ to the right from the second one, the fourth cell is $$$1$$$ to the bottom from the third one, and so on.  In particular, a path, consisting of a single cell, is considered to be a staircase.Here are some examples of staircases:  Initially all the cells of the matrix are free.You have to process $$$q$$$ queries, each of them flips the state of a single cell. So, if a cell is currently free, it makes it locked, and if a cell is currently locked, it makes it free.Print the number of different staircases after each query. Two staircases are considered different if there exists such a cell that appears in one path and doesn't appear in the other path.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n, m \le 1000$$$; $$$1 \le q \le 10^4$$$) — the sizes of the matrix and the number of queries. Each of the next $$$q$$$ lines contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x \le n$$$; $$$1 \le y \le m$$$) — the description of each query.

Print $$$q$$$ integers — the $$$i$$$-th value should be equal to the number of different staircases after $$$i$$$ queries. Two staircases are considered different if there exists such a cell that appears in one path and doesn't appear in the other path.

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

function solve(n, m, qs) {
    const free = Array(n).fill(0).map(() => Array(m).fill(1))
    const f1 = (i, j) => i < n && j < m && free[i][j]
    const f2 = (i, j) => i >= 0 && j >= 0 && free[i][j]

    let cur = n * m // cells
    for (let i = 0; i < m; i++) {
        // const l1 = add(n, m - 1 - i + 1 - 1)
        // const l2 = add(n - 1, m - 1 - i + 1)
        // cur += c2(l1)
        // cur += c2(l2)
        const k1 = move(0, i, [[0, 1], [1, 0]], f1)
        // const k3 = move(0, i, [[1, 0], [0, 1]], f1)
        cur += c2(k1) - k1
        // cur += c2(k3) - k3
// console.log('init', l1, l2, k1, k3)
// console.log('init', cur, c2(k1), k1)
    }
    for (let i = 0; i < n; i++) {
        // const l1 = add(n - 1 - i + 1, m - 1)
        // const l2 = add(n - 1 - i + 1 - 1, m)
        // cur += c2(l1)
        // cur += c2(l2)
        // const k1 = move(i, 0, [[0, 1], [1, 0]], f1)
        const k3 = move(i, 0, [[1, 0], [0, 1]], f1)
        // cur += c2(k1) - k1
        cur += c2(k3) - k3
// console.log('init', l1, l2, k1, k3)
    }
// console.log('init', cur)
    return qs.map(([i, j]) => {
        i--; j--
        const k1 = move(i, j, [[0, 1], [1, 0]], f1)
        const k2 = move(i, j, [[-1, 0], [0, -1]], f2)
        const k3 = move(i, j, [[1, 0], [0, 1]], f1)
        const k4 = move(i, j, [[0, -1], [-1, 0]], f2)
        const d = k1 * k2 + k3 * k4 - 1
        // console.log(k1, k2, k3, k4)
        if (free[i][j]) {
            cur -= d
        } else {
            cur += d
        }
        free[i][j] ^= 1
        return cur
    }).join('\n')
}
function move(i, j, ms, fn) {
    let c = 0
    while (!c || fn(i, j)) { // ignore the first cell status
        const [ai, aj] = ms[c % ms.length]
        i += ai
        j += aj
        c++
    }
    return c
}
function add(a, b) {
    if (a <= 0 || b <= 0) return 1
    return a + b
}
function c2(n) {
    // if (n < 0) return 0
    return n * (n + 1) / 2
}

const readline = require('readline')

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

function solve(a, b, c) {
    const oa = a & 1
    const ob = b & 1
    const oc = c & 1
    if (oa) {
        if (ob) {
            if (oc) {
                return 0
            } else {
                return 1
            }
        } else {
            if (oc) {
                return b ? 0 : 1
            } else {
                return 1
            }
        }
    } else {
        if (ob) {
            if (oc) {
                return 1
            } else {
                return 0
            }
        } else {
            if (oc) {
                return 1
            } else {
                return 0
            }
        }
    }
    // if (true) {}
    // const sum = a + 2 * b + 3 * c
    // const half = Math.floor(sum / 2)
    // const k = Math.floor(half / 3)
    // const r = half % 3
    // if (sum & 1) {
    //     if (k <= c) {
    //         switch (r) {
    //         case 2: return (b || a >= 2) ? 0 : (a ? 1 : 2)
    //         case 1: return (b || a >= 2) ? 0 : 1
    //         default:
    //         case 0: return 1
    //         }
    //     } else {
    //         const d = half - 3 * c
    //         if (d & 1) {
    //             return (b >= d / 2 && a) || (a >= d) ? 0 : 1
    //         } else {
    //             return (b >= d / 2 || a >= d) ? 0 : 1
    //         }
    //     }
    // } else {
    //     if (k <= c) {
    //         switch (r) {
    //         case 2: return (b || a >= 2) ? 0 : (a ? 1 : 2)
    //         case 1: return a ? 0 : 1
    //         default:
    //         case 0: return 0
    //         }
    //     } else {
    //         const d = half - 3 * c
    //         if (d & 1) {
    //             return (b >= d / 2 && a) || (a >= d) ? 0 : 1
    //         } else {
    //             return (b >= d / 2 || a >= d) ? 0 : 1
    //         }
    //     }
    // }
}


Consider the set of all nonnegative integers: $$${0, 1, 2, \dots}$$$. Given two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$). We paint all the numbers in increasing number first we paint $$$0$$$, then we paint $$$1$$$, then $$$2$$$ and so on.Each number is painted white or black. We paint a number $$$i$$$ according to the following rules:    if $$$i = 0$$$, it is colored white;   if $$$i \ge a$$$ and $$$i - a$$$ is colored white, $$$i$$$ is also colored white;   if $$$i \ge b$$$ and $$$i - b$$$ is colored white, $$$i$$$ is also colored white;   if $$$i$$$ is still not colored white, it is colored black. In this way, each nonnegative integer gets one of two colors.For example, if $$$a=3$$$, $$$b=5$$$, then the colors of the numbers (in the order from $$$0$$$) are: white ($$$0$$$), black ($$$1$$$), black ($$$2$$$), white ($$$3$$$), black ($$$4$$$), white ($$$5$$$), white ($$$6$$$), black ($$$7$$$), white ($$$8$$$), white ($$$9$$$), ...Note that:    It is possible that there are infinitely many nonnegative integers colored black. For example, if $$$a = 10$$$ and $$$b = 10$$$, then only $$$0, 10, 20, 30$$$ and any other nonnegative integers that end in $$$0$$$ when written in base 10 are white. The other integers are colored black.   It is also possible that there are only finitely many nonnegative integers colored black. For example, when $$$a = 1$$$ and $$$b = 10$$$, then there is no nonnegative integer colored black at all. Your task is to determine whether or not the number of nonnegative integers colored black is infinite.If there are infinitely many nonnegative integers colored black, simply print a line containing "Infinite" (without the quotes). Otherwise, print "Finite" (without the quotes).

The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ lines follow, each line contains two space-separated integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^4$$$).

For each test case, print one line containing either "Infinite" or "Finite" (without the quotes). Output is case-insensitive (i.e. "infinite", "inFiNite" or "finiTE" are all valid answers).

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

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

  for (var i = 0; i < lines; i++) {
    var ab = readline()
      .split(" ")
      .map(function(value) {
        return parseInt(value);
      })
      .sort();

    print(gcd(ab[0], ab[1]) > 1 ? "Infinite" : "Finite");
  }

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.trim().split(EOL)

  main()
})

function main() {
  const t = Number(lines[0])

  for(let i = 1; i <= t; i++) {
    const r = lines[i].split(/\s/).map(Number).sort((a, b) => b - a)

    console.log(isFinite(r))
  }
}

function isFinite([ a, b ]) {
  let t

  while(b) {
    t = a % b
    a = b
    b = t
  }

  return a === 1 ? 'Finite' : 'Infinite'
}

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.trim().split(EOL)

  main()
})

function main() {
  const rows = lines.slice(1)

  rows.forEach(r => console.log(isFinite(r.split(/\s/).map(Number).sort((a, b) => b - a)) ? 'Finite' : 'Infinite'))
}

function isFinite([ a, b ]) {
  let t

  while(b) {
    t = a % b
    a = b
    b = t
  }

  return a === 1
}

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.trim().split(EOL)

  main()
})

function main() {
  const rows = lines.slice(1)

  rows.forEach(r => console.log(isFinite(r.split(/\s/).map(Number).sort((a, b) => b - a)) ? 'Finite' : 'Infinite'))
}

function isFinite([ a, b ]) {
  let t

  while(b) {
    t = a % b
    a = b
    b = t
  }

  return a !== 1
}


PizzaForces is Petya's favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of $$$6$$$ slices, medium ones consist of $$$8$$$ slices, and large pizzas consist of $$$10$$$ slices each. Baking them takes $$$15$$$, $$$20$$$ and $$$25$$$ minutes, respectively.Petya's birthday is today, and $$$n$$$ of his friends will come, so he decided to make an order from his favorite pizzeria. Petya wants to order so much pizza that each of his friends gets at least one slice of pizza. The cooking time of the order is the total baking time of all the pizzas in the order.Your task is to determine the minimum number of minutes that is needed to make pizzas containing at least $$$n$$$ slices in total. For example:   if $$$12$$$ friends come to Petya's birthday, he has to order pizzas containing at least $$$12$$$ slices in total. He can order two small pizzas, containing exactly $$$12$$$ slices, and the time to bake them is $$$30$$$ minutes;  if $$$15$$$ friends come to Petya's birthday, he has to order pizzas containing at least $$$15$$$ slices in total. He can order a small pizza and a large pizza, containing $$$16$$$ slices, and the time to bake them is $$$40$$$ minutes;  if $$$300$$$ friends come to Petya's birthday, he has to order pizzas containing at least $$$300$$$ slices in total. He can order $$$15$$$ small pizzas, $$$10$$$ medium pizzas and $$$13$$$ large pizzas, in total they contain $$$15 \cdot 6 + 10 \cdot 8 + 13 \cdot 10 = 300$$$ slices, and the total time to bake them is $$$15 \cdot 15 + 10 \cdot 20 + 13 \cdot 25 = 750$$$ minutes;  if only one friend comes to Petya's birthday, he can order a small pizza, and the time to bake it is $$$15$$$ minutes.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each testcase consists of a single line that contains a single integer $$$n$$$ ($$$1 \le n \le 10^{16}$$$) — the number of Petya's friends.

For each testcase, print one integer — the minimum number of minutes that is needed to bake pizzas containing at least $$$n$$$ slices in total.

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const n = this.lines[this.lineIndex]
    return (this.lineIndex += 1), n
  }
  readIntegersOfLine() {
    const n = this.readLine().match(integerRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  readNumsOfLine() {
    const n = this.readLine().match(decimalRegex)
    return null == n ? [] : n.map(n => Number(n))
  }
  print(n) {
    stdout.write(n)
  }
  async init() {
    const n = await this.readLines()
    this.lines = n
  }
  readLines() {
    const n = []
    return new Promise(e => {
      stdin.on('data', e => n.push(e)),
        stdin.on('end', function () {
          const t = n.join('').split(os.EOL)
          e(t)
        })
    })
  }
}
async function __main__(n) {
  const e = new InputAndOutput()
  await e.init(), n(e)
}
function solve(n) {
  if (n <= 6n) return 15n
  if (n <= 8n) return 20n
  if (n <= 10n) return 25n
  return (5n * (n % 2n === 1n ? n + 1n : n)) / 2n
}
__main__(function (n) {
  const e = Number(n.readLine())
  for (let t = 1; t <= e; ++t) {
    const e = solve(BigInt(n.readLine()))
    n.print(e + '\n')
  }
})

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

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

const max = (a, b) => a > b ? a : b;

function main () {
	let T = rn();
	while (T--) {
		let n = rn();

		const ans = max(6n, n + 1n) / 2n * 5n;

		console.log(ans.toString());
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		let n = rn();

		if (n < 6) n = 6n;
		if (n&1n) n++;

		console.log((n*5n/2n).toString());
	}
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = BigInt(lines[l++])
        // var arr = lines[l++].split(' ').map(Number)
        console.log(solve(n).toString())
    }
});

function solve(n) {
    // 6 8 10
    // 15 20 25
    if (n < 6n) {
        return 15n
    }
    if (n & 1n) {
        return solve(n + 1n)
    }
    const r = n % 6n
    const k = (n - r) / 6n
    if (r === 0n) {
        return k * 15n
    } else if (r === 2n) {
        return (k - 1n) * 15n + 20n
    } else if (r === 4n) {
        return (k - 1n) * 15n + 25n
    }
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e) {
  if (e <= 6) return 15n
  if (e <= 8) return 20n
  if (e <= 10) return 25n
  let n = BigInt(e)
  return n % 2n === 1n && (n += 1n), (5n * n) / 2n
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()))
    e.print(n + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e) {
  return e <= 6
    ? 15
    : e <= 8
    ? 20
    : e <= 10
    ? 25
    : 1 & e
    ? (5 * (e + 1)) / 2
    : (5 * e) / 2
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()))
    e.print(n + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e) {
  const n = Math.floor(e / 120),
    t = e - 120 * n,
    s = 12 * n * 25,
    i = t % 6,
    r = t % 8,
    o = t % 10
  return 0 === i || 0 === r || 0 === o
    ? s + ((5 * t) >> 1)
    : i >= r && i >= o
    ? s + 15 * Math.ceil(t / 6)
    : r >= i && r >= o
    ? s + 20 * Math.floor(t / 8) + (r <= 6 ? 15 : 20)
    : s + 25 * Math.floor(t / 10) + (o <= 6 ? 15 : o <= 8 ? 20 : 25)
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()))
    e.print(n + '\n')
  }
})


Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.Each customer is characterized by three values: $$$t_i$$$ — the time (in minutes) when the $$$i$$$-th customer visits the restaurant, $$$l_i$$$ — the lower bound of their preferred temperature range, and $$$h_i$$$ — the upper bound of their preferred temperature range.A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the $$$i$$$-th customer is satisfied if and only if the temperature is between $$$l_i$$$ and $$$h_i$$$ (inclusive) in the $$$t_i$$$-th minute.Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.

Each test contains one or more test cases. The first line contains the number of test cases $$$q$$$ ($$$1 \le q \le 500$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$-10^9 \le m \le 10^9$$$), where $$$n$$$ is the number of reserved customers and $$$m$$$ is the initial temperature of the restaurant. Next, $$$n$$$ lines follow. The $$$i$$$-th line of them contains three integers $$$t_i$$$, $$$l_i$$$, and $$$h_i$$$ ($$$1 \le t_i \le 10^9$$$, $$$-10^9 \le l_i \le h_i \le 10^9$$$), where $$$t_i$$$ is the time when the $$$i$$$-th customer visits, $$$l_i$$$ is the lower bound of their preferred temperature range, and $$$h_i$$$ is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive. The customers are given in non-decreasing order of their visit time, and the current time is $$$0$$$.

For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first case, Gildong can control the air conditioner to satisfy all customers in the following way:  At $$$0$$$-th minute, change the state to heating (the temperature is 0).  At $$$2$$$-nd minute, change the state to off (the temperature is 2).  At $$$5$$$-th minute, change the state to heating (the temperature is 2, the $$$1$$$-st customer is satisfied).  At $$$6$$$-th minute, change the state to off (the temperature is 3).  At $$$7$$$-th minute, change the state to cooling (the temperature is 3, the $$$2$$$-nd customer is satisfied).  At $$$10$$$-th minute, the temperature will be 0, which satisfies the last customer. In the third case, Gildong can change the state to heating at $$$0$$$-th minute and leave it be. Then all customers will be satisfied. Note that the $$$1$$$-st customer's visit time equals the $$$2$$$-nd customer's visit time.In the second and the fourth case, Gildong has to make at least one customer unsatisfied.

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').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

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

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

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  let ptr = 0
  let t = readInt(input, ptr++)
  while(t--) {
    const [n, m] = readInts(input, ptr++)
    const vis = new Array(n)
    for(let i = 0; i < n; i ++) {
      vis[i] = readInts(input, ptr++)
    }

    vis.sort((a, b) => a[0] - b[0])

    let li = m
    let hi = m
    let curr = 0
    let f = true
    for(let i = 0; i < n; i ++) {
      const [ti, l, h] = vis[i]
      let diff = ti - curr
      let changed = false
      if(l >= hi) {
        if(diff + hi >= l) {
          changed = true
          li = l
          hi = Math.min(hi + diff, h)
        }
      }
      else if(h <= li) {
        if(li - diff <= h) {
          changed = true
          hi = h
          li = Math.max(li - diff, l)
        }
      }
      else if(l >= li && h <= hi) {
        changed = true
        li = l
        hi = h
      }
      else if(l <= li && h <= hi) {
        changed = true
        li = Math.max(li - diff, l)
        hi = h
      }
      else if(l >= li && h >= hi) {
        changed = true
        li = l
        hi = Math.min(hi + diff, h)
      }
      else if(l <= li && h >= hi) {
        changed = true
        li = Math.max(li - diff, l)
        hi = Math.min(hi + diff, h)
      }

      // console.log(l, h, li, hi, diff)
      if(!changed) {
        wr('NO')
        f = false
        break
      }
      curr = ti
    }

    if(f) wr('YES')
  }
}

const { EOL } = require('os')

const solution = (startTemperature, customers) => {
    let time = 0
    const possibleRange = [
        startTemperature,
        startTemperature,
    ]

    let good = true

    for (const [ arrivalTime, low, high ] of customers) {
        if (good) {
            const elapsed = arrivalTime - time
            possibleRange[0] = Math.max(possibleRange[0] - elapsed, low)
            possibleRange[1] = Math.min(possibleRange[1] + elapsed, high)

            if (possibleRange[1] < possibleRange[0]) {
                good = false
            }

            time = arrivalTime
        }
    }

    return good
}

let input = ''

let m = 0
const readline = () => {
    return input[m++]
}

const readNumbers = () => readline().split(' ').map(Number)

const onEnd = () => {
    input = input.split(EOL)

    const [ inputCount ] = readNumbers()

    for (let i = 0; i < inputCount; i++) {
        const [ customerCount, startTemperature ] = readNumbers()
        const customers = (function * () {
            for (let j = 0; j < customerCount; j++) {
                yield readNumbers()
            }
        }())
        if (solution(startTemperature, customers)) {
            console.log('yes')
        } else {
            console.log('no')
        }

        while (!customers.next().done) {}
    }
}

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

var q = parseInt(readline())

while(q--)
{
    var input = readline().split(" ").map(function(x) { return parseInt(x); });
    var n = input[0];
    var m = input[1];

    var ct = 0;
    var cl = m;
    var ch = m;
    var can = 'YES';
    while(n--)
    {
        input = readline().split(" ").map(function(x) { return parseInt(x); });
        var t = input[0];
        var l = input[1];
        var h = input[2];

        var delT = t - ct;
        var ct = t;
        var cl = Math.max(cl - delT, l);
        var ch = Math.min(ch + delT, h);

        if (cl > ch)
        {
            can = 'NO';
        }
    }
    print(can);
}

const { EOL } = require('os')

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

input = input.split(EOL)

let i = 0
const readline = () => {
    return input[i++]
}

const solution = (startTemperature, customers) => {
    console.log('startTemperature', startTemperature, 'customers', customers)
    let time = 0
    const possibleRange = [
        startTemperature,
        startTemperature,
    ]

    for (const [ arrivalTime, low, high ] of customers) {
        console.log([ arrivalTime, low, high ])
        const elapsed = arrivalTime - time
        possibleRange[0] = Math.max(possibleRange[0] - elapsed, low)
        possibleRange[1] = Math.min(possibleRange[1] + elapsed, high)

        if (possibleRange[1] < possibleRange[0]) {
            return false
        }

        time = arrivalTime
    }

    return true
}

const readNumbers = () => readline().split(' ').map(Number)

console.log('start')

console.log('typeof readline', typeof readline)

const inputCount = readNumbers()

console.log('inputCount', inputCount)

for (let i = 0; i < inputCount; i++) {
    const [ customerCount, startTemperature ] = readNumbers()
    const customers = (function * () {
        for (let j = 0; j < customerCount; j++) {
            yield readNumbers()
        }
    }())
    if (solution(startTemperature, customers)) {
        console.log('yes')
    } else {
        console.log('no')
    }
}


You are given integer $$$n$$$. You have to arrange numbers from $$$1$$$ to $$$2n$$$, using each of them exactly once, on the circle, so that the following condition would be satisfied:For every $$$n$$$ consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard $$$2n$$$ numbers differ not more than by $$$1$$$.For example, choose $$$n = 3$$$. On the left you can see an example of a valid arrangement: $$$1 + 4 + 5 = 10$$$, $$$4 + 5 + 2 = 11$$$, $$$5 + 2 + 3 = 10$$$, $$$2 + 3 + 6 = 11$$$, $$$3 + 6 + 1 = 10$$$, $$$6 + 1 + 4 = 11$$$, any two numbers differ by at most $$$1$$$. On the right you can see an invalid arrangement: for example, $$$5 + 1 + 6 = 12$$$, and $$$3 + 2 + 4 = 9$$$, $$$9$$$ and $$$12$$$ differ more than by $$$1$$$.

The first and the only line contain one integer $$$n$$$ ($$$1 \le n \le 10^5$$$).

If there is no solution, output "NO" in the first line.  If there is a solution, output "YES" in the first line. In the second line output $$$2n$$$ numbers — numbers from $$$1$$$ to $$$2n$$$ in the order they will stay in the circle. Each number should appear only once. If there are several solutions, you can output any of them.

NoteExample from the statement is shown for the first example. It can be proved that there is no solution in the second example.

function input() {
  return [parseInt(readline().trim())];
}

function main() {
  // get input
  var read = input();
  var n = read[0];

  if (n % 2 === 0) {
    print("NO");
    return;
  }

  print("YES");

  var top = n;
  var bot = 0;
  var answer = [];
  for (var i = 0; i < n; i++) {
    if (i % 2 === 0) {
      answer.push(2 * top);
      top--;
    } else {
      answer.push(2 * bot + 1);
      bot++;
    }
  }
  for (var i = 0; i < n; i++) {
    if (i % 2 === 0) {
      answer.push(answer[i] - 1);
    } else {
      answer.push(answer[i] + 1);
    }
  }

  print(answer.join(" "));
}

main();

function input() {
  return [parseInt(readline().trim())];
}

function main() {
  // get input
  var read = input();
  var n = read[0];

  if (n % 2 === 0) {
    print("NO");
    return;
  }

  var top = n;
  var bot = 0;
  var answer = [];
  for (var i = 0; i < n; i++) {
    if (i % 2 === 0) {
      answer.push(2 * top);
      top--;
    } else {
      answer.push(2 * bot + 1);
      bot++;
    }
  }
  for (var i = 0; i < n; i++) {
    if (i % 2 === 0) {
      answer.push(answer[i] - 1);
    } else {
      answer.push(answer[i] + 1);
    }
  }

  print(answer.join(" "));
}

main();


You are given four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$. You should build a sequence $$$a_0, a_1, a_2, \dots, a_n$$$ where $$$a_0 = 0$$$ and for each $$$i \ge 1$$$ you can choose:   either $$$a_i = a_{i - 1} + x$$$  or $$$a_i = a_{i - 1} - y$$$. Your goal is to build such a sequence $$$a$$$ that $$$a_i \le B$$$ for all $$$i$$$ and $$$\sum\limits_{i=0}^{n}{a_i}$$$ is maximum possible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first and only line of each test case contains four integers $$$n$$$, $$$B$$$, $$$x$$$ and $$$y$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le B, x, y \le 10^9$$$). It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the maximum possible $$$\sum\limits_{i=0}^{n}{a_i}$$$.

NoteIn the first test case, the optimal sequence $$$a$$$ is $$$[0, 1, 2, 3, 4, 5]$$$.In the second test case, the optimal sequence $$$a$$$ is $$$[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$$$.In the third test case, the optimal sequence $$$a$$$ is $$$[0, -3, -6, 1, -2]$$$.

var t = readline();

for (var i = 0; i < t; i++) {
  var a = readline().split(' ').map(Number);
  var n = a[0];
  var B = a[1], x = a[2], y = a[3];
  var sum = 0;
  var ans = 0;

  while(n > 0) {
    sum += sum + x <= B ? x : -y;
    ans += sum;
    n--;
  }
  print(ans);
}

var repeatTimes = readline();

while (repeatTimes--) {
    var sum = 0;
    var res = 0;
    var a = readline().split(' ').map(Number);
    var n = a[0], B = a[1], x = a[2], y = a[3];

    while(n) {
        sum += sum + x <= B ? x : -y;
        res += sum;
        n--;
    }

    print(res);
}

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

function sum(n, B, x, y){
  let sum = 0;
  let a = 0;
  for (let i=0; i<n; i++){
    if (a+x<=B)
      a = a+x;
    else
      a = a-y;
    sum += a;
  }
  return sum;
}

function main() {
    let T = +readline();
    while (T--){
      let [n, B, x, y] = readline().split(' ').map(a=>+a);
      print(sum(n, B, x, y))
    }
}

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

/***
Educational Codeforces Round 125 (Div. 2)
2022-03-22

B. XY Sequence
***/

function main() {
  // INPUT: Number of test cases
  let t = readline();
  t = parseInt(t);
  let s;
  for (let i = 0; i < t; i++) {
    // INPUT: 'n B x y'
    // n (int 1..2e5) : length of Sequence
    // b (int 1..1e10) : max of any element
    // x (int 1..1e10) : a' = a+x possible
    // y (int 1..1e10) : a' = a+y possible
    s = readline();
    s = s.split(' ');
    const n = parseInt(s[0]);
    const b = parseInt(s[1]);
    const x = parseInt(s[2]);
    const y = parseInt(s[3]);

    // we might want to think of the problem as a linear combination
    // fx-gy where f+g = 1+2+3+...+(n-1) = n(n-1)/2

    // x and y are positive so we can subtract all the y's first
    // and then add the x's (so don't worry about going over)

    // we might be able to greed x until you can't add any more x's
    // (we want as many x's as we can early on)

    let a = 0;
    let sum = 0;
    for (let j = 0; j < n; j++) {
      if (a + x <= b) {
        a = a + x;
      } else {
        a = a - y;
      }
      sum += a;
    }
    console.log(sum);
  }
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    for(i = 1; i <= t; i++){
        var a = lines[i].split(' ').map(Number);
        var n = a[0], b = a[1], x = a[2], y = a[3];
        var ans = 0;
        var e = 0;
        for(j = 0; j < n; j++){
            if(e + x <= b){
                e += x;
            }else{
                e -= y;
            }
            ans += e;
        }
        console.log(ans);
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let [n, B, x, y] = readline().split(' ').map(Number);
        let sum = 0;
        let curr = 0;

        for (let i = 1; i <= n; i++) {
            let lg = curr + x;
            let sm = curr - y;
            if (lg > B) curr = sm; else curr = lg;
            sum += curr;
        }

        output(sum);
    }
}

const readline = require('readline')

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

function solve(n, b, x, y) {
    let now = 0
    let ans = 0
    for (let i = 1; i <= n; i++) {
        if (now + x <= b && now + x - y <= b) {
            now += x
        } else {
            now -= y
        }
        ans += now
        // console.log(now)
    }
    return ans
}

var t = readline();

for (var i = 0; i < t; i++) {
  var a = readline().split(' ').map(Number);
  var x = a[0];
  var y = a[1];

  if (x === 0 && y === 0) {
    print(0);
    continue;
  }

  var z = Math.sqrt(x * x + y * y);

  var r = Math.round(z);
  if (Math.abs(z - r) < 0.000001) {
    print(1);
    continue;
  }

  print(2);
}

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

function sum(n, B, x, y){
  let sum = 0;
  let a = 0;
  for (let i=0; i<n; i++){
    if (a+x<=B)
      a = a+x;
    else
      a = a-y;
    sum += a;
  }
  return sum;
}

function main() {
    let T = +readline()[0];
    while (T--){
      let [n, B, x, y] = readline().split(' ').map(a=>+a);
      print(sum(n, B, x, y))
    }
}


You have a string $$$s$$$ consisting of $$$n$$$ characters. Each character is either 0 or 1.You can perform operations on the string. Each operation consists of two steps:  select an integer $$$i$$$ from $$$1$$$ to the length of the string $$$s$$$, then delete the character $$$s_i$$$ (the string length gets reduced by $$$1$$$, the indices of characters to the right of the deleted one also get reduced by $$$1$$$);  if the string $$$s$$$ is not empty, delete the maximum length prefix consisting of the same characters (the indices of the remaining characters and the string length get reduced by the length of the deleted prefix). Note that both steps are mandatory in each operation, and their order cannot be changed.For example, if you have a string $$$s =$$$ 111010, the first operation can be one of the following:  select $$$i = 1$$$: we'll get 111010 $$$\rightarrow$$$ 11010 $$$\rightarrow$$$ 010;  select $$$i = 2$$$: we'll get 111010 $$$\rightarrow$$$ 11010 $$$\rightarrow$$$ 010;  select $$$i = 3$$$: we'll get 111010 $$$\rightarrow$$$ 11010 $$$\rightarrow$$$ 010;  select $$$i = 4$$$: we'll get 111010 $$$\rightarrow$$$ 11110 $$$\rightarrow$$$ 0;  select $$$i = 5$$$: we'll get 111010 $$$\rightarrow$$$ 11100 $$$\rightarrow$$$ 00;  select $$$i = 6$$$: we'll get 111010 $$$\rightarrow$$$ 11101 $$$\rightarrow$$$ 01. You finish performing operations when the string $$$s$$$ becomes empty. What is the maximum number of operations you can perform?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$. The second line contains string $$$s$$$ of $$$n$$$ characters. Each character is either 0 or 1. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer — the maximum number of operations you can perform.

NoteIn the first test case, you can, for example, select $$$i = 2$$$ and get string 010 after the first operation. After that, you can select $$$i = 3$$$ and get string 1. Finally, you can only select $$$i = 1$$$ and get empty string.

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

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

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

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

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

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

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

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

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

  let t = +$()
  while (t--) {
    let n = +$(), s = $(), ne = Arr(n, i => i + 1);
    let res = 0, i = 0, j = 0;
    while (i < n) {
      res++;
      while (j < n && s[j] != s[ne[j]]) j = ne[j];
      if (j < n) {
        ne[j] = ne[ne[j]];
      } else {
        i = ne[i];
      }
      while (i < n && s[i] == s[ne[i]]) i = ne[i];
      if (i >= n) break;
      i = ne[i];
      if (j < i) j = i;
      // log(res, i, j)
    }
    log(res)
  }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  var initialStrain = true;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
        operations++;
        spare += strain - 2;
        if (waitForSalvation < spare) {
          operations += waitForSalvation;
          spare = 0;
          waitForSalvation = 0;
        } else {
          operations += spare;
          waitForSalvation -= spare;
          spare = 0;
        }
      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }

  if (strain > 1) {
    operations++;

    spare += strain - 2;
    if (waitForSalvation < spare) {
      operations += waitForSalvation;
      spare = 0;
      waitForSalvation = 0;
    } else {
      operations += spare;
      waitForSalvation -= spare;
      spare = 0;
    }
  } else {
    waitForSalvation++;
  }

  // if (spare >= waitForSalvation) {
  //   operations += waitForSalvation;
  // } else {
  //   operations += spare;
  //   waitForSalvation -= spare;
  operations += Math.ceil(waitForSalvation / 2);
  //}
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}

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

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

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

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

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

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

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

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

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

  let t = +$()
  while (t--) {
    let n = +$(), s = $()
    let res = 0, i = 0, j = n - 1
    while (i <= j) {
      res++;
      if (s[i] == s[i + 1]) {
        while (s[i] == s[i + 1]) i++;
        i++;
      } else {
        i++;
        j--;
      }
      // log(res, i, j)
    }
    log(res)
  }
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  for (var j = 0; j < length; j++) {

     if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
          operations++;
          spare+=strain-2;
          currBit = binString[j];
          strain=1;
      }
      else
      {
          waitForSalvation++;
          strain=1;
          currBit = binString[j];
      }
    }
  }
  if (strain > 1) {
    operations++;
    spare+=strain-2;
    currBit = binString[j];
    strain=1;
}
else
{
    waitForSalvation++;
}

if(spare>=waitForSalvation)
{
    operations+=waitForSalvation;
}
else
{
    operations+=spare;
    waitForSalvation-=spare;
    operations+=Math.ceil(waitForSalvation/2);
}
//   if(!blank)
//   {
//       operations++;
//   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  var initialStrain = true;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {

      if (strain > 1) {
        operations++;
        if(!initialStrain)
        {
            spare += strain - 2;
        }
        else
        {
            initialStrain = false;
        }

      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }
  if (strain > 1) {
    operations++;
    if(!initialStrain)
        {
            spare += strain - 2;
        }
        else
        {
            initialStrain = false;
        }
  } else {
    operations++;
  }

  if (spare >= waitForSalvation) {
    operations += waitForSalvation;
  } else {
    operations += spare;
    waitForSalvation -= spare;
    operations += Math.ceil(waitForSalvation / 2);
  }
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit;
  var operations = 0;
  var blank = true;
  for (var j = 0; j < length; j++) {
    if (blank) {
      strain=1
      currBit = binString[j];
      blank=false;
      continue;
    }

     if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
          operations++;
          currBit = binString[j];
          strain=1;
      }
      else
      {
          operations++;
          blank = true;
      }
    }
  }

  if(!blank)
  {
      operations++;
  }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  for (var j = 0; j < length; j++) {

     if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
          operations++;
          spare+=strain-2;
          currBit = binString[j];
          strain=1;
      }
      else
      {
          waitForSalvation++;
          strain=0;
          currBit = binString[j];
      }
    }
  }
  if (strain > 1) {
    operations++;
    spare+=strain-2;
    currBit = binString[j];
    strain=1;
}
else
{
    waitForSalvation++;
}

if(spare>=waitForSalvation)
{
    operations+=waitForSalvation;
}
else
{
    operations+=spare;
    waitForSalvation-=spare;
    operations+=Math.ceil(waitForSalvation/2);
}
//   if(!blank)
//   {
//       operations++;
//   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  var initialStrain = true;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {

      if (strain > 1) {
        operations++;

            spare += strain - 2;
        if(waitForSalvation<spare)
        {
          operations+=waitForSalvation;
          spare=0;
        }
        else
        {
          operations += spare;
          waitForSalvation-=spare;
          spare = 0;
        }
        // else
        // {
        //     initialStrain = false;
        // }

      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }
  if (strain > 1) {
    operations++;

            spare += strain - 2;
            if(waitForSalvation<spare)
        {
          operations+=waitForSalvation;
          spare=0;
        }
        else
        {
          operations += spare;
          waitForSalvation-=spare;
          spare = 0;
        }

  } else {
    waitForSalvation++;
  }

  // if (spare >= waitForSalvation) {
  //   operations += waitForSalvation;
  // } else {
  //   operations += spare;
  //   waitForSalvation -= spare;
    operations += Math.ceil(waitForSalvation / 2);
  //}
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}

var inputs = parseInt(readline());
for (var i = 0; i < inputs; i++) {
  var length = parseInt(readline());
  var binString = readline();
  var strain = 0;
  var currBit = binString[0];
  var operations = 0;
  var spare = 0;
  var waitForSalvation = 0;
  for (var j = 0; j < length; j++) {
    if (currBit == binString[j]) {
      strain++;
    } else {
      if (strain > 1) {
        operations++;
        spare += strain - 2;
      } else {
        waitForSalvation++;
      }
      currBit = binString[j];
      strain = 1;
    }
  }
  if (strain > 1) {
    operations++;
    spare += strain - 2;
  } else {
    operations++;
  }

  if (spare >= waitForSalvation) {
    operations += waitForSalvation;
  } else {
    operations += spare;
    waitForSalvation -= spare;
    operations += Math.ceil(waitForSalvation / 2);
  }
  //   if(!blank)
  //   {
  //       operations++;
  //   }
  print(operations);
}


You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.

For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.

var t = parseInt(readline());
while(t-- > 0){
    var n = parseInt(readline());
    print(`1 ${n-1}`);
}

var test = readline(), x, b;
while(test--) {
  x = readline();
  b = x - 1;
  print('1 ' + b);
}

var test = readline(), x;
while(test--) {
  x = readline();
  print('1 ' + (x - 1));
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let times = readline();
    while (times--) {
        let input = parseInt(readline());
        output(input - 1, 1);
    }

}
function output(...ans) {
    console.log(ans.join(' '));
}

process.stdin.resume();
process.stdin.setEncoding('utf-8')
let inputString = '';
let currentLine = 0;
process.stdin.on('data', input => { inputString += input; })
process.stdin.on('end', _ => { inputString = inputString.split('\n'); main(); })
const readline = () => { return inputString[currentLine++] }

function main() {
    let n = parseInt(readline());
    for (let i = 0; i < n; i++) {
        const number = parseInt(readline());
        console.log(`1 ${number - 1}`);
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
// your code goes here
var arr = '';
process.stdin.on('data',function(chunk){
    arr+=chunk;
    arr = arr.split('\r\n');
    let ncase= arr.length - 1;
    let x = 1;
    while(x<ncase){
        console.log(arr[x]-1,1);
        x++;
    }
});

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

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

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

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

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

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

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

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

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

function main() {
  let t = readInt()
  while(t--) {
    const x = readInt()
    wr(x - 1 + " " + 1)
  }
}

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

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

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

let c = 0;

const gcd = (a, b) => {
  while (b !== 0) {
    const t = b;
    b = a % b;
    a = t;
  }

  return a;
};

const lcm = (a, b) => {
  return (a * b) / gcd(a, b);
};

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

  const n = +d;
  console.log(1, n - 1);

  c++;
});

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

const sol = () => {
     nums = data.trim().split(/\n/g).map(Number);
     nums.shift();
     result = nums.map((e) => {
          return `1 ${e-1}`;
     });
     console.log(result.join('\n'));
}

process.stdin.on('end', sol);

'use strict'

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

main()

function main() {
  let t = getInt()
  while (t --> 0) {
    const x = getInt()
    print(1, x - 1)
  }
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var num = +readline();
    print(`${num - 1} ${1}`);
  }
}
main()

process.stdin.resume();
process.stdin.setEncoding('utf8');
// your code goes here
var arr = '';
process.stdin.on('data',function(chunk){
    arr+=chunk;
    arr = arr.split('\r\n');
    let ncase= arr.length - 1;
    let x = 1;
    while(x<=ncase){
        console.log(arr[x]-1,1);
        x++;
    }
});


Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much.One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to n and the number of a hill is equal to the distance in meters between it and the island. The distance between the n-th hill and the shore is also 1 meter.Thumbelina is too small to make such jumps. Fortunately, a family of frogs living in the swamp suggests to help her. Each frog agrees to give Thumbelina a ride but Thumbelina should choose only one frog. Each frog has a certain jump length. If Thumbelina agrees to accept help from a frog whose jump length is d, the frog will jump from the island on the hill d, then — on the hill 2d, then 3d and so on until they get to the shore (i.e. find itself beyond the hill n).However, there is one more problem: mosquitoes also live in the swamp. At the moment they have a siesta, and they are having a nap on some hills. If the frog jumps on a hill with a mosquito the frog will smash it. The frogs Thumbelina has met are pacifists, so they will find the death of each mosquito very much sad. Help Thumbelina choose a frog that will bring her to the shore and smash as small number of mosquitoes as possible.

The first line contains three integers n, m and k (1 ≤ n ≤ 109, 1 ≤ m, k ≤ 100) — the number of hills, frogs and mosquitoes respectively. The second line contains m integers di (1 ≤ di ≤ 109) — the lengths of the frogs’ jumps. The third line contains k integers — the numbers of the hills on which each mosquito is sleeping. No more than one mosquito can sleep on each hill. The numbers in the lines are separated by single spaces.

In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line — their numbers in increasing order separated by spaces. The frogs are numbered from 1 to m in the order of the jump length given in the input data.

var s1 = readline().split(' ');
var n = Number(s1[0]);
var m = Number(s1[1]);
var k = Number(s1[2]);
var ma = readline().split(' ');
var ka = readline().split(' ');
var fr = new Array(m);
var result = [];

var i, j, f;
var min = 0;
var mis = k;

for(i=0; i<m; i++)
{
  f = 0;
  for(j=0; j<k; j++)
  {
    if( ka[j]%ma[i] == 0)
    {
      f++;
    }
  }
  fr[i] = f;

  if(f == mis)
  {
    min++;
  }
  if(f < mis)
  {
    mis = f;
    min = 1;
  }
}

print(min);

for(i=0; i<m; i++)
{
  if(fr[i] == mis) result.push(i+1);
}

print(result.join(" "));

var s1 = readline().split(' ');
var n = Number(s1[0]);
var m = Number(s1[1]);
var k = Number(s1[2]);
var ma = readline().split(' ');
var ka = readline().split(' ');
var fr = new Array(m);
var result = [];

var i, j, f;
var min = 0;
var mis = k;

for(i=0; i<m; i++)
{
  f = 0;
  for(j=0; j<k; j++)
  {
    if( ka[j]%ma[i] == 0)
    {
      f++;
    }
  }
  fr[i] = f;

  if(f == mis)
  {
    min++;
  }
  if(f < mis)
  {
    mis = f;
    min = 1;
  }
}

print(min);

for(i=0; i<m; i++)
{
  if(fr[i] == mis) result.push(i);
}

print(fr.join(" "));

var s1 = readline().split(' ');
var n = Number(s1[0]);
var m = Number(s1[1]);
var k = Number(s1[2]);
var ma = readline().split(' ');
var ka = readline().split(' ');
var fr = new Array(m);
var result = [];

var i, j, f;
var min = 0;
var mis = k;

for(i=0; i<m; i++)
{
  f = 0;
  for(j=0; j<k; j++)
  {
    if( ka[j]%ma[i] == 0)
    {
      f++;
    }
  }
  fr[i] = f;

  if(f == mis)
  {
    min++;
  }
  if(f < mis)
  {
    mis = f;
    min = 1;
  }
}

print(min);

for(i=0; i<m; i++)
{
  if(fr[i] == mis) result.push(i);
}

print(result.join(" "));


There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

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

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

  if (c === 1) {
    l2 = d;
    c++;
    return;
  }

  const text = d;
  let ans = '';
  const obj = {};

  for (let i = 0; i < l1.length; i++) {
    obj[l1[i]] = l2[i];
    obj[l1[i].toUpperCase()] = l2[i].toUpperCase();
  }

  for (let i = 0; i < text.length; i++) {
    if (obj[text[i]]) {
      ans += obj[text[i]];
    }
    else {
      ans += text[i];
    }
  }

  // for (let i = 0; i < text.length; i++) {
  //   const idx = l1.indexOf(text[i]);
  //   const idxLower = l1.indexOf(text[i].toLowerCase());

  //   if (idx !== -1) {
  //     ans += l2[idx];
  //   }
  //   else if (idxLower !== -1) {
  //     ans += l2[idxLower].toUpperCase();
  //   }
  //   else {
  //     ans += text[i];
  //   }
  // }

  console.log(ans);

  c++;
});

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

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

  if (c === 1) {
    l2 = d;
    c++;
    return;
  }

  const text = d;
  let ans = '';

  for (let i = 0; i < text.length; i++) {
    const idx = l1.indexOf(text[i]);
    const idxLower = l1.indexOf(text[i].toLowerCase());

    if (idx !== -1) {
      ans += l2[idx];
    }
    else if (idxLower !== -1) {
      ans += l2[idxLower].toUpperCase();
    }
    else {
      ans += text[i];
    }
  }

  console.log(ans);

  c++;
});

var k1 = readline();
var k2 = readline();
var inp = readline();

var i = 0, j = 0, z = 0, l = inp.length, out = "";

for(i = 0; i< l; i++)
{
  // ������� �����
  if(inp.charCodeAt(i) >= 65 && inp.charCodeAt(i) <= 90)
  {
    z = inp.charCodeAt(i)+32;
    for(j = 0; j< 26; j++)
    {
      if(k1.charCodeAt(j) == z)
      {
        out = out + k2[j].toUpperCase();
      }
    }
  }
  else if(inp.charCodeAt(i) >= 97 && inp.charCodeAt(i) <= 122)
  // ��������� �����
  {
    for(j = 0; j< 26; j++)
    {
      z = inp.charCodeAt(i);
      if(k1.charCodeAt(j) == z)
      {
        out = out + k2[j];
      }
    }

  }
  // ��� ���������
  else
  {
    out = out + inp[i];
  }
}

print(out);

var from = readline().split('')
var to = readline().split('')
var convert = readline().split('')
print(convert.map(x => !isNaN(x) ? x : to[from.indexOf(x)] || to[from.indexOf(x.toLowerCase())].toUpperCase() ).join(''))

var layout1 = readline();
var layout2 = readline();
var input = readline();

var output = '';
for(var i=0; i<input.length; i++){
	if(isNaN(input[i])){
		var isLower = (input[i]+'').toLowerCase()==(input[i]+'');
		var char = isLower?(input[i]+''):(input[i]+'').toLowerCase();
		output+=isLower?layout2[layout1.indexOf(char)]:layout2[layout1.indexOf(char)].toUpperCase();
	}else{
		output+=input[i];
	}
}
write(output);

var firstLayout = readline()
var secondLayout = readline()

var input = readline();
var output = '';

for (var i = 0; i < input.length; i++) {
  var char = input[i];

  if (~'0123456789'.indexOf(char)) {
    output += char;
    continue;
  }

  if (char === char.toUpperCase()) {
    var LayoutCharPos = firstLayout.indexOf(char.toLowerCase());
    output += secondLayout[LayoutCharPos].toUpperCase();
  } else {
    var LayoutCharPos = firstLayout.indexOf(char);
    output += secondLayout[LayoutCharPos];
  }
}

print(output);

    var recorder = readline(),
        derecorder = readline(),
        record = readline(),
        result = '';

    for (var i = 0; i < record.length; i++){
        var number = recorder.indexOf(record[i]);
        var numberUpper = recorder.indexOf(record[i].toLowerCase());
        if (number >= 0 ){
            result += derecorder[number];
        } else if(numberUpper >= 0){
            result += derecorder[numberUpper].toUpperCase();
        } else if (!isNaN(parseInt(record[i]))){
            result += record[i];
        }
    }

print(result);

alph1 = readline();
alph2 = readline();
s = readline();
s1 = '';
for(var i=0; i< s.length; i++) {
    var char = s[i];
    if (/[0-9]/.test(char)) {
        s1 = s1 + char;
        continue;
    }
    var lowChar = s[i].toLowerCase();
    var resChar = alph2[alph1.indexOf(lowChar)];
    if (char != lowChar) {
        resChar = resChar.toUpperCase();
    }
    s1 = s1 + resChar;
}

print(s1);

var fr = readline().split('')
var to = readline().split('')
var convert = readline().split('')
write(convert.map(x => !isNaN(x) ? x : to[fr.indexOf(x)] || to[fr.indexOf(x.toLowerCase())].toUpperCase()).join(''))

(function main(){
  //http://codeforces.com/problemset/problem/831/B
  var layout1Minusculas = readline();
  var layout1Mayusculas = layout1Minusculas.toUpperCase();
  var layout2Minusculas = readline();
  var layout2Mayusculas = layout2Minusculas.toUpperCase();
  var datos = readline();

  var salida = "";
  for (var i = 0; i < datos.length; i++) {
    if(!isNaN((datos[i]))){
      salida += datos[i];
    }else if(caracterEsMayuscula(i)){
      traducir(i, layout1Mayusculas, layout2Mayusculas);
    }else{
      traducir(i, layout1Minusculas, layout2Minusculas);
    }
  }

  function caracterEsMayuscula(index){
    var charcode = datos.charCodeAt(index);
    return  charcode >= 65 && charcode <= 90;
  }

  function traducir(index, layoutInicial, layoutFinal){
    var indexLayout = layoutInicial.indexOf(datos[i]);
    salida += layoutFinal.charAt(indexLayout);
  }

  print(salida);
})();

function derecording(record, recorder, derecorder){
    var result = '';

    for (var i = 0; i < record.length; i++){
        var number = recorder.indexOf(record[i]);
        var numberUpper = recorder.indexOf(record[i].toLowerCase());
        if (number >= 0 ){
            result += derecorder[number];
        } else if(numberUpper >= 0){
            result += derecorder[numberUpper].toUpperCase();
        } else if (!isNaN(parseInt(record[i]))){
            result += record[i];
        }
    }

    return result;
}


IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting.Today, when IA looked at the fridge, she noticed that the word formed by magnets is really messy. "It would look much better when I'll swap some of them!" — thought the girl — "but how to do it?". After a while, she got an idea. IA will look at all prefixes with lengths from $$$1$$$ to the length of the word and for each prefix she will either reverse this prefix or leave it as it is. She will consider the prefixes in the fixed order: from the shortest to the largest. She wants to get the lexicographically smallest possible word after she considers all prefixes. Can you help her, telling which prefixes should be chosen for reversing?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first and the only line contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$), describing the initial string formed by magnets. The string $$$s$$$ consists only of characters 'a' and 'b'.

Output exactly $$$|s|$$$ integers. If IA should reverse the $$$i$$$-th prefix (that is, the substring from $$$1$$$ to $$$i$$$), the $$$i$$$-th integer should be equal to $$$1$$$, and it should be equal to $$$0$$$ otherwise. If there are multiple possible sequences leading to the optimal answer, print any of them.

NoteIn the first example, IA can reverse the second and the third prefix and get a string "abbb". She cannot get better result, since it is also lexicographically smallest string obtainable by permuting characters of the initial string.In the second example, she can reverse any subset of prefixes — all letters are 'a'.

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

var input= '', cin, cout;

process.stdin.on('data', function(chunk) {
    input+=chunk;

});

process.stdin.on('end', function() {
    input = input.split('\n');
    cout = function(data) {process.stdout.write(data+'\n')};
    var inputLineIndex = 0;
    cin = function(){return inputLineIndex>=input.length?undefined:input[inputLineIndex++]};
    process.exit(main() || 0);
});

function main() {
    function swap(line, i) {
        return line.substr(0, i+1).split("").reverse().join("") + line.substr(i+1);
    }

    let line = cin().replace(/\r?\n/g, "").trim();
    let ans = '';

    for (let i = 0; i < line.length; i++) {
        if (line[0] === 'b') {
            if (line[i] === 'a' && (line[i+1] !== 'a' || i+1 == line.length)) {
                ans += '1 ';
                line = swap(line, i);
            } else {
                ans += '0 ';
            }
        } else {
            if (line[i] === 'b' && line[i+1] === 'a') {
                ans += '1 ';
                line = swap(line, i);
            } else if (line[i] === 'a' && (line[i+1] !== 'a' || i+1 == line.length)) {
                ans += '1 ';
                line = swap(line, i);
            } else {
                ans += '0 ';
            }
        }
    }

    cout(ans.trim());
    //cout(line);

    return 0;
}

const readline = require('readline')

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

let smallest = [0]
let largest = [0]
interface.on('line', line => {
  for (let i = 1; i < line.length; i++) {
    if (line[i] == 'a') {
      smallest = largest.concat(1)
      largest = largest.concat(0)
    } else if(line[i] == 'b'){
      largest = smallest.concat(1)
      smallest = smallest.concat(0)
    }
  }
  ouputSolution(smallest)
})

function ouputSolution (list) {
  let str = ''
  for (let i = 0; i < list.length; i++) {
    str += list[i] + ' '
  }
  console.log(str)
}

'use strict';

const a = readline();
const n = a.length;

const ans = new Array(n).fill(0);

for (let i = 1; i < n; i++) {
    if (a[i] == 'a') {
        ans[i - 1] = 1 - ans[i - 1];
        ans[i] = 1 - ans[i];
    }
}

print(ans.join(' '));

'use strict';

const a = readline();
const n = a.length;

const ans = new Array(n).fill(0);

for (let i = 1; i < n; i++) {
    if (a[i] == 'a') {
        ans[i - 1] = 1 - ans[i - 1];
    }
}

ans[n - 1] = 1;

print(ans.join(' '));


You found a useless array $$$a$$$ of $$$2n$$$ positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of $$$a$$$.It could have been an easy task, but it turned out that you should follow some rules:   In the beginning, you select any positive integer $$$x$$$. Then you do the following operation $$$n$$$ times:   select two elements of array with sum equals $$$x$$$;  remove them from $$$a$$$ and replace $$$x$$$ with maximum of that two numbers.  For example, if initially $$$a = [3, 5, 1, 2]$$$, you can select $$$x = 6$$$. Then you can select the second and the third elements of $$$a$$$ with sum $$$5 + 1 = 6$$$ and throw them out. After this operation, $$$x$$$ equals $$$5$$$ and there are two elements in array: $$$3$$$ and $$$2$$$. You can throw them out on the next operation.Note, that you choose $$$x$$$ before the start and can't change it as you want between the operations.Determine how should you behave to throw out all elements of $$$a$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \leq a_i \leq 10^6$$$) — the initial array $$$a$$$. It is guaranteed that the total sum of $$$n$$$ over all test cases doesn't exceed $$$1000$$$.

For each test case in the first line print YES if it is possible to throw out all elements of the array and NO otherwise. If it is possible to throw out all elements, print the initial value of $$$x$$$ you've chosen. Print description of $$$n$$$ operations next. For each operation, print the pair of integers you remove.

NoteThe first test case was described in the statement.In the second and third test cases, we can show that it is impossible to throw out all elements of array $$$a$$$.

'use strict';

function solve(n, a) {
  a.sort((a, b) => b - a);
  next: for (let skip = 1; skip < 2 * n; skip++) {
    const res = [];
    res.push([a[0]]);
    const vis = new Set([0]);
    let sum = a[0];
    const map = new Map();
    for (let [i, num] of a.entries()) {
      if (i === 0 || i === skip) continue;
      if (!map.has(num)) map.set(num, []);
      map.get(num).push(i);
    }
    for (let i = 1; i < 2 * n; i++) {
      if (vis.has(i) || skip === i) continue;
      const x = a[i],
            y = sum - x;
      const b = map.get(y);
      if (!b || !b.length || b.length === 1 && b[0] === i) continue next;
      let j = b.pop();
      if (j === i) j = b.pop();
      vis.add(i);
      vis.add(j);
      res.push([a[i], y]);
      sum = x;
    }
    for (let i = 0; i < 2 * n; i++) {
      if (!vis.has(i)) res[0].push(a[i]);
    }
    return `YES\n${res[0][0] + res[0][1]}\n` + res.map(arr => arr.join(' ')).join('\n');
  }
  return 'NO';
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res.push(await solve(n, a));
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		a.sort((x, y) => x - y);

		const mp = new Map();
		for (let i = 0; i < 2*n; i++) {
			const [cnt, usecnt] = mp.has(a[i]) ? mp.get(a[i]) : [0, 0];
			mp.set(a[i], [cnt + 1, usecnt]);
		}

		function use (k) {
			if (mp.has(k)) {
				const [cnt, usecnt] = mp.get(k);
				if (usecnt < cnt) {
					mp.set(k, [cnt, usecnt + 1]);
					return true;
				}
			}
			return false;
		}

		function resetMap () {
			for (const [ky, [cnt, usecnt]] of mp.entries()) {
				mp.set(ky, [cnt, 0]);
			}
		}

		let ans = [];
		for (let i = 0; !ans.length && i < 2*n - 1; i++) {
			resetMap();
			let curx = a[2*n - 1] + a[i];
			for (let j = 2*n - 1; j >= 0; j--) {
				const [cnt, usecnt] = mp.get(a[j]);
				if (cnt == usecnt) {
					continue;
				}

				use(a[j]);
				if (use(curx - a[j])) {
					ans.push([a[j], curx - a[j]]);
					curx = Math.max(a[j], curx - a[j]);
				} else {
					ans = [];
					break;
				}
			}
		}

		if (ans.length) {
			console.log('YES\n', ans[0][0] + ans[0][1]);
			for (const row of ans)
				console.log(row.join(' '));
		} else {
			console.log('NO');
		}
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const n = rn();
		const a = rna();

		a.sort((x, y) => x - y);

		const mp = new Map();
		for (let i = 0; i < 2*n; i++) {
			mp.set(a[i], [mp.has(a[i]) ? mp.get(a[i])[0] + 1 : 1, 0]);
		}

		function use (k) {
			if (mp.has(k)) {
				const [cnt, curcnt] = mp.get(k);
				if (curcnt < cnt) {
					mp.set(k, [cnt, curcnt + 1]);
					return true;
				}
			}
			return false;
		}

		function resetMap() {
			for (const [ky, [cnt, curcnt]] of mp.entries()) {
				mp.set(ky, [cnt, 0]);
			}
		}

		let ans, ansx;
		for (let i = 0; i < 2*n - 1; i++) {
			resetMap();
			use(a[i]);
			curx = a[2*n - 1];
			ok = true;
			ans = [[a[i], a[2*n - 1]]];
			for (let j = 2*n - 2; j >= 0; j--) {
				if (j != i) {
					const [cnt, curcnt] = mp.get(a[j]);
					if (cnt == curcnt) {
						continue;
					}

					use(a[j]);
					if (use(curx - a[j])) {
						ans.push([a[j], curx - a[j]]);
						curx = Math.max(a[j], curx - a[j]);
					} else {
						ok = false;
						break;
					}
				}
			}
			if (ok) {
				ansx = a[2*n-1] + a[i];
				break;
			}
		}

		if (ansx) {
			console.log('YES\n', ansx);
			for (const row of ans)
				console.log(row.join(' '));
		} else {
			console.log('NO');
		}
	}
}

'use strict';

function solve(n, a) {
  a.sort((a, b) => b - a);
  const nums = new Map([...new Set(a)].sort((a, b) => a - b).map((num, i) => [num, i]));
  const N = nums.size;
  const g = Array.from({
    length: N
  }, () => []);
  for (let i = 0; i < 2 * n; i++) {
    for (let j = i + 1; j < 2 * n; j++) {
      const sum = a[i] + a[j];
      if (nums.has(sum)) {
        g[nums.get(sum)].push([i, j]);
      }
    }
  }
  let res = [];
  const dfs = (sum = a[0], vis = new Set([0]), path = [[0]]) => {
    if (vis.size === 2 * n - 1) {
      res = [...path];
      return true;
    }
    for (let [i, j] of g[nums.get(sum)]) {
      if (vis.has(i) || vis.has(j)) continue;
      vis.add(i);
      vis.add(j);
      path.push([i, j]);
      let res = false;
      if (a[i] > a[j]) {
        res = dfs(a[i], vis, path);
      } else {
        res = dfs(a[j], vis, path);
      }
      vis.delete(i);
      vis.delete(j);
      path.pop();
      if (res) return true;
    }
    return false;
  };
  if (dfs()) {
    let vis = [];
    for (let [i, j] of res) {
      vis[i] = 1;
      vis[j] = 1;
    }
    for (let i = 1; i < 2 * n; i++) {
      if (!vis[i]) {
        res[0].push(i);
        break;
      }
    }
    return 'YES\n' + res.map(arr => arr.map(i => a[i]).join(' ')).join('\n');
  } else {
    return 'NO';
  }
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res.push(await solve(n, a));
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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