function main() {
  const is = new Scanner();
  const [n, h, a, b, k] = is.nextArray(Number);
  let lengthPath, i, j, x, y;
  for (let q = 0; q < k; q += 1) {
    [i, j, x, y] = is.nextArray(Number);
    if (i === x) {
      console.log(Math.abs(y - j));
    } else {
      lengthPath = 0;
      if (j < a) {
        lengthPath += Math.abs(a - j);
        j = a;
      } else if (j > b) {
        lengthPath += Math.abs(b - j);
        j = b;
      }
      lengthPath += Math.abs(x - i);
      lengthPath += Math.abs(y - j);
      console.log(lengthPath);
    }
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

/**
 * cf 1020a
 */
const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});

var data,n,h,a,b,k,ta,tb,fa,fb;
rl.on('line', (line) => {
  data=line.split(' ').map(i => parseInt(i));
  if(data.length===5){
    [n,h,a,b,k]=data;
  }
  else{
    [ta,fa,tb,fb]=data;
    var ans=Math.abs(ta-tb);
    if(ta!=tb){
      if(fa>b&&fb>b){
        ans+=fa-b+fb-b;
      }
      else if(fa<a&&fb<a){
          ans+=a-fa+a-fb;
      }
      else{
          ans+=Math.abs(fa-fb);
      }
    }
    else{
      ans+=Math.abs(fa-fb);
    }

    console.log(ans);
  }
});

/*
3 6 2 3 3
1 2 1 3
1 4 3 4
1 2 2 3
*/

readline = require('readline')

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

let n, h, a, b, k, numLines = 0, queries = []
rl.on('line', line => {
    const integersList = line.split(' ').map(x => parseInt(x))
    if (++numLines == 1) {
        [n, h, a, b, k] = integersList
    } else {
        queries.push(integersList)
    }
}).on('close', () => {
    queries.forEach(query => {
        let [ta, fa, tb, fb] = query, clamp = (x, l, r) => x <= l ? l : (x >= r ? r : x)
        const steps = [
            ta != tb ? Math.abs(fa - clamp(fa, a, b)) : 0,
            Math.abs(ta - tb),
            ta != tb ? Math.abs(fb - clamp(fa, a, b)) : Math.abs(fb - fa)
        ]
        process.stdout.write(`${steps.reduce((a, x) => a + x)}\n`)
    })
})

var inputs = readline().split(' ').map(i => +i);
var towersCount = inputs[0]
var towerHeight = inputs[1]
var lowestPassage = inputs[2]
var highestPassage = inputs[3]
var queries = inputs[4];

for (i = 0; i < queries; i++) {
  var queryInputs = readline().split(' ').map(i => +i);
  var startingTower = queryInputs[0]
  var startingFloor = queryInputs[1]
  var targetTower = queryInputs[2]
  var targetFloor = queryInputs[3];
  var passageFloor = startingFloor > highestPassage ? highestPassage
    : startingFloor < lowestPassage ? lowestPassage : startingFloor;

  if (startingTower === targetTower)
    print(Math.abs(startingFloor - targetFloor));
  else
    print(Math.abs(startingTower - targetTower) + Math.abs(startingFloor - passageFloor) + Math.abs(targetFloor - passageFloor));
}

function main() {
  const is = new Scanner();
  const [n, h, a, b, k] = is.nextArray(Number);
  let lengthPath, i, j, x, y;
  for (let q = 0; q < k; q += 1) {
    [i, j, x, y] = is.nextArray(Number);
    if (i === x) {
      console.log(Math.abs(y - j));
    } else {
      lengthPath = 0;
      if (j < a) {
        console.log('a');
        lengthPath += Math.abs(a - j);
        j = a;
      } else if (j > b) {
        lengthPath += Math.abs(b - j);
        j = b;
      }
      lengthPath += Math.abs(x - i);
      lengthPath += Math.abs(y - j);
      console.log(lengthPath);
    }
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = -1;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    this.index += 1;
    return this.lines[this.index].trim();
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

readline = require('readline')

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

let n, h, a, b, k, numLines = 0, queries = []
rl.on('line', line => {
    const integersList = line.split(' ').map(x => parseInt(x))
    if (++numLines == 1) {
        [n, h, a, b, k] = integersList
    } else {
        queries.push(integersList)
    }
}).on('close', () => {
    queries.forEach(query => {
        let [ta, fa, tb, fb] = query, clamp = (x, l, r) => x <= l ? l : (x >= r ? r : x)
        const steps = [
            ta != fa ? Math.abs(fa - clamp(fa, a, b)) : 0,
            Math.abs(ta - tb),
            Math.abs(fb - clamp(fa, a, b))
        ]
        process.stdout.write(`${steps.reduce((a, x) => a + x)}\n`)
    })
})

/**
 * cf 1020a
 */
const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});

var data,n,h,a,b,k,ta,tb,fa,fb;
rl.on('line', (line) => {
  data=line.split(' ').map(i => parseInt(i));
  if(data.length===5){
    [n,h,a,b,k]=data;
  }
  else{
    [ta,fa,tb,fb]=data;
    var ans=Math.abs(ta-tb);
    if(fa>b&&fb>b){
      ans=eval(ans+fa-b+fb-b);
    }
    else if(fa<a&&fb<a){
        ans+=a-fa+a-fb;
    }
    else{
        ans+=Math.abs(fa-fb);
    }
    console.log(ans);
  }
});

/*
3 6 2 3 3
1 2 1 3
1 4 3 4
1 2 2 3
*/

var inputs = readline().split(' ').map(i => +i);
var towersCount = inputs[0]
var towerHeight = inputs[1]
var lowestPassage = inputs[2]
var highestPassage = inputs[3]
var queries = inputs[4];

for (i = 0; i < queries; i++) {
  var queryInputs = readline().split(' ').map(i => +i);
  var startingTower = queryInputs[0]
  var startingFloor = queryInputs[1]
  var targetTower = queryInputs[2]
  var targetFloor = queryInputs[3];
  var passageFloor = startingFloor > highestPassage ? highestPassage
    : startingFloor < lowestPassage ? lowestPassage : startingFloor;

  var moves = Math.abs(startingTower - targetTower) + Math.abs(startingFloor - passageFloor) + Math.abs(targetFloor - passageFloor);
  print(moves);
}

const inputs = readline().split(' ').map(i => +i);
const towersCount = inputs[0]
const towerHeight = inputs[1]
const lowestPassage = inputs[2]
const highestPassage = inputs[3]
const queries = inputs[4];

for (i = 0; i < queries; i++) {
  const queryInputs = readline().split(' ').map(i => +i);
  const startingTower = queryInputs[0]
  const startingFloor = queryInputs[1]
  const targetTower = queryInputs[2]
  const targetFloor = queryInputs[3];
  const passageFloor = startingFloor > highestPassage ? highestPassage
    : startingFloor < lowestPassage ? lowestPassage : startingFloor;

  const moves = Math.abs(startingTower - targetTower) + Math.abs(startingFloor - passageFloor) + Math.abs(targetFloor - passageFloor);
  print(moves);
}


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, ''))

  let t = parseInt(arr.shift())

  let i = 0
  while(t --) {
    const n = parseInt(arr[i++])
    // console.log('n', n)
    if(n == 1){
      i++
      console.log(0)
      continue
    }

    let flag = false
    let intervals = new Array(n)

    for(let j = 0; j < n; j++, i++) {
      // console.log(arr[i])
      intervals[j] = arr[i].split(' ').map(a => parseInt(a))
    }

    // console.log(intervals)
    intervals.sort((a, b) => a[0] - b[0])
    // console.log(intervals)

    let x = intervals[0]

    for(let j = 1; j < n; j++) {
      if(x[1] < intervals[j][0] && !flag){
        flag = true
        x[0] = x[1]
        x[1] = intervals[j][0]
      }
      else if(x[1] < intervals[j][0] && flag){
        x[1] = intervals[j][0]
      }
      else if(!flag){
        x[0] = Math.min(x[1], intervals[j][1])
        x[1] = Math.min(x[1], intervals[j][1])
      }
      else {
        x[1] = Math.min(x[1], intervals[j][1])
      }
      // console.log(x)
    }

    console.log(x[1] - x[0])
  }
})

'use strict'

var t=parseInt(readline());

while(t--)
{
    var mx=0,mm=1000000000;
    var n=parseInt(readline());

    for(var i=1;i<=n;i++){
        var s=readline().split(' ').map(Number);
        var a=s[0],b=s[1];
        mx=Math.max(mx,a);
        mm=Math.min(mm,b);
    }
    print((mx-mm<=0)?"0":mx-mm);
}

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, ''))

  let t = parseInt(arr.shift())

  let i = 0
  while(t --) {
    const n = parseInt(arr[i++])
    // console.log('n', n)
    if(n == 1){
      i++
      console.log(0)
      continue
    }

    let flag = false
    let intervals = new Array(n)

    for(let j = 0; j < n; j++, i++) {
      // console.log(arr[i])
      intervals[j] = arr[i].split(' ').map(a => parseInt(a))
    }

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

    let x = intervals[0]

    for(let j = 1; j < n; j++) {
      if(x[1] < intervals[j][0] && !flag){
        flag = true
        x[0] = x[1]
        x[1] = intervals[j][0]
      }
      else if(x[1] < intervals[j][0] && flag){
        x[0] = x[0]
        x[1] = intervals[j][0]
      }
      else {
        x[0] = x[1]
      }
    }

    console.log(x[1] - x[0])
  }
})


'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 foo(x) {

    console.log(x);
}

function bank_notes(n, arr, k){
  arr.sort(function(a, b) {
  return a - b;
});
  for(var i=0; i<n; i++){
    arr[i] = Math.pow(10,arr[i]);
  }
  var count = k+1;
  var ans = 0n;
  for(var i=0; i<n; i++){
    var cnt = count;
    if(i+1<n){
      cnt = Math.min(cnt, arr[i+1]/arr[i]-1);
    }
    ans = ans + BigInt(arr[i])*BigInt(cnt);
    count -= cnt;
    if(count==0)break;
  }
  return ans.toString();
}

function main() {
    const t = parseInt(readline());
    var inp;
    for (var i = 0; i<t; i++){
        inp = readline().split(" ");
        var n = parseInt(inp[0]);
        var k = parseInt(inp[1]);
        var arr = readline().split(" ").map(x=>parseInt(x));
        var ans = bank_notes(n,arr,k);
        foo(ans);
    }
}

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

function solve(n, ok, arr) {
    let ans = 0n
    let k = ok + 1
    for (let i = 0; i < arr.length; i++) {
        const cur = Math.pow(10, arr[i])
        const limit = i === n - 1 ? k : (Math.pow(10, arr[i + 1]) / cur - 1)
        // console.log(cur, limit)
        ans += mul(Math.min(k, limit), cur)
        k -= limit
        if (k <= 0) break
    }
    return ans
}
function mul(a, b) {
    return BigInt(a) * BigInt(b)
}

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--) {
		let [n, k] = rna();
		const a = rna();
		a.push(18);
		++n;

		++k;
		let ans = 0n;
		for (let i = 1; k && i < n; i++) {
			const most = 10**(a[i]-a[i-1]) - 1;
			const take = Math.min(most, k);
			k -= take;

			ans += BigInt(take)*BigInt(10**a[i-1]);
		}

		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 = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		let [n, k] = rna();
		const a = rna();
		a.push(1e20);
		++n;

		++k;
		let ans = 0n;
		for (let i = 1; k && i < n; i++) {
			const use = Math.min(k, 10**a[i]/10**a[i-1] - 1);
			k -= use;

			ans += BigInt(use)*BigInt(10**a[i-1]);
		}

		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 readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while (t--) {
		let [n, k] = rl();
		let a = rl();

		let m = k + 1, ans = 0, i = 0;
		a.push(Number.POSITIVE_INFINITY);
		while (m) {
			x = Math.pow(10, a[i + 1] - a[i]) - 1;
			let used = Math.min(m, x);
			m -= used;
			ans += used * Math.pow(10, a[i]);
			i++;
		}

		console.log(ans);
	}
}


'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(){
    var t=readline();
    while (t--)
    {
        var n=readline();
        console.log(Math.floor(n/2));
    }
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var x = +readline();
    print(x % 2 ? (x - 1) / 2 : x / 2);
  }

}

main();

"use strict";

//readline().split(' ').map(Number);

function sec(){
    var n = readline();
    n -= n%2;
    print(parseInt(n/2));
}

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

main();

function solve(n) {
    return n === 1 ? n : Math.floor(n/2);
}
var t = Number(readline());
while (t--) {
    var n = Number(readline());
    print(solve(n));
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let high = +readLine();
    console.log(solve(high));
  }

  function solve(high) {
    return Math.floor(high / 2);
  }
}

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

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

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let t = 1;
    outer:
    while (t <= testCases) {
        const n = data[t] * 1;
        let high = n;
        let count = Array(high + 1).fill(0);
        for (let i = 2; i <= n; i += 1) count[i]++;
        let counter = 0;
        for (let i = high; i >= 1; i -= 1) {
          let j = i;
          while(j <= high) {
            if (count[j] > 0) counter += count[j];
            j += i;
            if (counter === 2) {
              console.log(i);
              t += 1;
              continue outer;
            }
          }
          counter = 0;
        }
        console.log(1);
        t += 1;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input = '';
process.stdin.on('data', (line) => {
    input += line;
});
process.stdin.on('end', () => {
    const lines = input.split('\n');
    let tests = parseInt(lines.shift(), 10);
    while (tests--) {
        const n = parseInt(lines.shift(), 10);
        console.log(Math.floor(n / 2));
    }
});
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(element => parseInt(element, 10));
}

const testInput = [
    '2',
    '23423',
    '12312',
    '543534',
    '24223',
    '43534543',
    '43856092',
    '6598392'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));
        })
    })
}

function output(lines) {
    process.stdout.write(lines.join(EOL));
}

getInput(false).then(lines => {
    lines.pop();
    const amount = lines.shift();
    const inputs = lines.map(element => parseInt(element));
    const answer = [];
    inputs.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

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

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

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

const s2i = s => parseInt(s, 10);

function main() {
  const T = s2i(readLine());
  for(let i = 0; i < T; i++) {
    const x = s2i(readLine());

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

'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++];
}
/**
2
3
5

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

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

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

}

function solve() {
    let a = parseInt(readline());

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

}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let t = 1;
    outer:
    while (t <= testCases) {
        const n = data[t] * 1;
        let high = n;
        let count = Array(high + 1).fill(0);
        for (let i = 2; i <= n; i += 1) count[i]++;
        let counter = 0;
        for (let i = high; i >= 1; i -= 1) {
          let j = i;
          while(j <= high) {
            if (count[j] > 0) counter += count[j];
            j += i;
            if (counter === 2) {
              console.log(i);
              t += 1;
              continue outer;
            }
          }
          counter = 0;
        }
        console.log(1);
        console.log(count);
        t += 1;
    }
}

const testInput = [
    '2',
    '3',
    '5'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));//.map(line => line.split(' ')));
        })
    })
}

function output(lines) {
    process.stdout.write(lines.join(EOL));
}

getInput(true).then(lines => {
    const amount = lines.shift();
    const sortedNs = lines.map(element => parseInt(element)).sort((a,b) => a - b);
    const answer = [];
    sortedNs.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

const testInput = [
    '2',
    '1'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));//.map(line => line.split(' ')));
        })
    })
}

function output(lines) {
    console.log(lines.join(EOL));
}

getInput(false).then(lines => {
    const amount = lines.shift();
    const sortedNs = lines.map(element => parseInt(element)).sort((a,b) => a - b);
    const answer = [];
    sortedNs.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

const testInput = [
    '2',
    '23423',
    '12312',
    '543534',
    '24223',
    '43534543',
    '43856092',
    '6598392'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));
        })
    })
}

function output(lines) {
    process.stdout.write(lines.join(EOL));
}

getInput(false).then(lines => {
    const amount = lines.shift();
    const inputs = lines.map(element => parseInt(element));
    const answer = [];
    inputs.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

const testInput = [
    '2',
    '3',
    '5'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));//.map(line => line.split(' ')));
        })
    })
}

function output(lines) {
    console.log(lines.join(EOL)+EOL);
}

getInput(false).then(lines => {
    const amount = lines.shift();
    const sortedNs = lines.map(element => parseInt(element)).sort((a,b) => a - b);
    const answer = [];
    sortedNs.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

const testInput = [
    '2',
    '23423',
    '12312',
    '543534',
    '24223',
    '43534543',
    '43856092',
    '6598392'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));//.map(line => line.split(' ')));
        })
    })
}

function output(lines) {
    process.stdout.write(lines.join(EOL));
}

getInput(false).then(lines => {
    const amount = lines.shift();
    const Ns = lines.map(element => parseInt(element));
    const answer = [];
    Ns.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

const testInput = [
    '2',
    '3',
    '5'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));//.map(line => line.split(' ')));
        })
    })
}

function output(lines) {
    process.stdout.write(lines.join(EOL));
}

getInput(false).then(lines => {
    const amount = lines.shift();
    const sortedNs = lines.map(element => parseInt(element)).sort((a,b) => a - b);
    const answer = [];
    sortedNs.forEach(num => {
        answer.push(greatestGCF(num));
    })
    output(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}

const testInput = [
    '2',
    '3',
    '5'
];

const {EOL} = require('os')
function getInput(test = false) {
    return new Promise((res,rej) => {
        if (test) res(testInput);
        let i = ''
        process.stdin.on('data', c => i += c)
        process.stdin.on('end', () => {
            res(i.split(EOL));//.map(line => line.split(' ')));
        })
    })
}

function output(lines) {
    console.log(lines.join(EOL));
}

getInput(false).then(lines => {
    const amount = lines.shift();
    const sortedNs = lines.map(element => parseInt(element)).sort((a,b) => a - b);
    const answer = [];
    sortedNs.forEach(num => {
        answer.push(greatestGCF(num));
        console.log(greatestGCF(num));
    })
    //console.log(answer);
})

const greatestGCF = (n) => {
    n-=n%2;
    return n/2;
}


var row = readline().split(" ").map(function(x) { return parseInt(x); });
var n = row[0];

var a = [];
row = readline().split(" ").map(function(x) { return parseInt(x); });
for(var i = 0; i < n; i++) {
	a.push(row[i]);
}

var result = 0;
var min = a[0];
var resultMin = -1;
for(var i = 1; i < n; i++) {
	if(a[i] < min) {
		min = a[i];
		result = 0;
                resultMin = -1;
	} else if (a[i] > min) {
		result++;
	} else {
		if(resultMin == -1) {
			resultMin = result + 1;
		} else {
			if(resultMin > result + 1) {
				resultMin = result + 1;
			}
		}
		result = 0;
	}
}

write(resultMin);

const getMinDistanceBetweenMins = (nums) => {
  var lastIndexOfMin = 0;
  var minDistanceBetweenMins = Infinity;

  for (var i = 1; i < nums.length; i++) {
    if (nums[i] < nums[lastIndexOfMin]) {
      lastIndexOfMin = i;
      minDistanceBetweenMins = Infinity;
    } else if (nums[i] === nums[lastIndexOfMin]) {
      minDistanceBetweenMins = Math.min(
        minDistanceBetweenMins,
        i - lastIndexOfMin
      );
      lastIndexOfMin = i;
    }
  }

  return minDistanceBetweenMins;
};

const main = () => {
  readline();

  const nums = readline()
    .split(" ")
    .map((i) => Number(i));

  return getMinDistanceBetweenMins(nums);
};

print(main());

var min
var distance = 1
var n=Number(readline())
var data = readline().split(" ")
var savedDistance = data.length
for (var i=0;i<data.length;i++) {
    var x = Number(data[i])
    if(min === undefined) {
        min = x
    } else {
        if (min > x) {
            min = x
            distance = 1
            savedDistance = n
        } else if (min === x) {
            if(savedDistance > distance){
                savedDistance = distance
            }
            distance = 1
        } else {
            distance++
        }
    }
}

print(savedDistance)

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e9;
    let r = 10e9;
    let k = 10e9;

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

        if (arr[i] < a) {
            a = arr[k = i];
            r = 10e9;
        } else if (arr[i] === a) {
            r = Math.min(r, i - k);
            k = i;
        }
    }

    console.log(r);
}

readline()
A=readline().split(' ').map(Number)
m1=Math.min.apply(null,A)
var i1=-1,i2=-1;
m2=2000000000;
for (i=0;i<A.length;++i) {
  if (A[i]===m1) {
    if (i1>=0) {
      i2=i;
      m2 = Math.min(m2, i2-i1)
      i1=i2;
    }else{
      i1=i;
    }
  }
}
print(m2)

var n = parseInt(readline());
var aa = readline().split(' ').map(parseFloat);
var m = Math.min.apply(null, aa);
var j = -n, r = n;
for (var i = 0; i < n; i++) {
    if (aa[i] === m) {
        if (r > i - j) r = i - j;
        j = i;
    }
}
print(r);

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e9;
    let r = 10e9;
    let k = 10e9;

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

        if (arr[i] < a) {
            a = arr[k = i];
        } else if (arr[i] === a) {
            r = Math.min(r, i - k);
            k = i;
        }
    }

    console.log(r);
}

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e5;
    let b = 10e5;
    let c = 0;
    let d = 10e5;
    let e = 10e5;

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

        if (arr[i] < a) {
            e = Math.abs((c = i) - d);
            a = arr[i];
        } else if (arr[i] < b) {
            e = Math.abs(c - (d = i));
            b = arr[i];
        } else if (arr[i] === a && Math.abs(i - d) < e) {
            e = Math.abs((c = i) - d);
            a = arr[i];
        } else if (arr[i] === b && Math.abs(c - i) < e) {
            e = Math.abs(c - (d = i));
            b = arr[i];
        }
    }

    console.log(e);
}

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e5;
    let b = 10e5;
    let c = 0;
    let d = 0;
    let e = 10e5;

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

        if (arr[i] < a) {
            e = Math.abs((c = i) - d);
            a = arr[i];
        } else if (arr[i] < b) {
            e = Math.abs(c - (d = i));
            b = arr[i];
        } else if (arr[i] === a && Math.abs(i - d) < e) {
            e = Math.abs((c = i) - d);
            a = arr[i];
        } else if (arr[i] === b && Math.abs(c - i) < e) {
            e = Math.abs(c - (d = i));
            b = arr[i];
        }
    }

    console.log(e);
}

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e5;
    let r = 10e5;
    let k = 0;

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

        if (arr[i] < a) {
            a = arr[i];
            k = i;
        } else if (arr[i] === a) {
            r = Math.min(r, i - k);
            k = i;
        }
    }

    console.log(r);
}

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e9;
    let r = 10e9;
    let k = 0;

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

        if (arr[i] < a) {
            a = arr[k = i];
        } else if (arr[i] === a) {
            r = Math.min(r, i - k);
            k = i;
        }

        console.log(a, arr[i]);
    }

    console.log(r);
}

'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 n = parseInt(readline());
    let arr = readline().split(' ');

    let a = 10e9;
    let r = 10e9;
    let k = 0;

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

        if (arr[i] < a) {
            a = arr[k = i];
        } else if (arr[i] === a) {
            r = Math.min(r, i - k);
            k = i;
        }
    }

    console.log(r);
}

var row = readline().split(" ").map(function(x) { return parseInt(x); });
var n = row[0];

var a = [];
row = readline().split(" ").map(function(x) { return parseInt(x); });
for(var i = 0; i < n; i++) {
	a.push(row[i]);
}

var result = 0;
var min = a[0];
var resultMin = -1;
for(var i = 1; i < n; i++) {
	if(a[i] < min) {
		min = a[i];
		result = 0;
	} else if (a[i] > min) {
		result++;
	} else {
		if(resultMin == -1) {
			resultMin = result + 1;
		} else {
			if(resultMin > result + 1) {
				resultMin = result + 1;
			}
		}
		result = 0;
	}
}

write(resultMin);

var min
var distance = 1
n=Number(readline())
var savedDistance = n
for (var i=0;i<n;i++) {
    var x=Number(readline())
    if(min === undefined) {
        min = x
    } else {
        if (min > x) {
            min = x
            distance = 1
            savedDistance = n
        } else if (min === x) {
            if(savedDistance > distance){
                savedDistance = distance
            }
            distance = 1
        } else {
            distance++
        }
    }
}

print(savedDistance)

var min
var distance = 0
n=Number(readline())
var savedDistance = n
for (var i=0;i<n;i++) {
    var x=Number(readline())
    if(min === undefined) {
        min = x
    } else {
        if (min > x) {
            min = x
            distance = 0
            savedDistance = n
        } else if (min === x) {
            if(savedDistance > distance){
                savedDistance = distance
            }
            distance = 0
        } else {
            distance++
        }
    }
}

print(savedDistance)


n = Number(readline());
Ar = [];
Stack = [];
ans = 0;
current = 0;
for(var i = 0;i < n; i++) {
	Ar.push(readline().split(' ').map(Number));
}
Ar.sort((x,y) => {
	if(x[1] > y[1]) {
		return -1;
	}
	else if(x[1] < y[1]) {
		return 1;
	}
	else if(x[0] > y[0]) {
		return -1;
	}
	else if(x[0] < y[0]) {
		return 1;
	}
	else {
		return 0;
	}
});

for(var i = 0;i < n; i++) {
	while(Stack.length > 0 && Stack[Stack.length-1][0] >= Ar[i][1]) {
		current = current - Stack[Stack.length-1][2];
		Stack.pop();
	}
	Stack.push(Ar[i]);
	current += Ar[i][2];
	ans = max(ans,current);
}
print(ans);

function min(a,b) {
	return a > b ? b : a;
}
function max(a,b) {
	return a > b ? a : b;
}

function min(a,b) {
	if(a<b) {
		return a;
	}
	else {
		return b;
	}
}
function max(a,b) {
	if(a>b) {
		return a;
	}
	else {
		return b;
	}
}
n = Number(readline());
Ar = [];
Stack = [];
ans = 0;
now = 0;
for(var i=0;i<n;i++) {
	Ar.push(readline().split(' ').map(Number));
}
Ar.sort((x,y) => {
	if(x[1] > y[1]) {
		return -1;
	}
	else if(x[1] < y[1]) {
		return 1;
	}
	else if(x[0] > y[0]) {
		return -1;
	}
	else if(x[0] < y[0]) {
		return 1;
	}
	else {
		return 0;
	}
});
for(var i = 0;i < n;i++) {
	while(Stack.length > 0 && Stack[Stack.length-1][0] >= Ar[i][1]) {
		now = now - Stack[Stack.length-1][2];
		Stack.pop();
	}
	Stack.push(Ar[i]);
	now = now + Ar[i][2];
	ans = max(ans,now);
}
print(ans);

function getLine(){
    return readline().split(' ').map((a) => parseInt(a));
}
function getInt(){
    return parseInt(readline());
}
function SegmentTree(n){
    this.n = n;
    var P = [];
    P.length = n * 4 + 1;
    var self = this;

    function Fun(x, y){
        return Math.max(x, y);
    }

    function build(v, l, r){
        if(l == r){
            P[v] = 0;
            return;
        }
        var s = (l + r) >> 1;
        build(v * 2, l, s);
        build(v * 2 + 1, s + 1, r);
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    build(1, 0, n - 1);

    var get = function(v, l, r, lq, rq){
        if(lq > rq){
            return 0;
        }
        if(lq == l && rq == r){
            return P[v];
        }
        var s = (l + r) >> 1;
        return Fun(get(v * 2, l, s, lq, Math.min(rq, s)),
                get(v * 2 + 1, s + 1, r, Math.max(lq, s + 1), rq));
    }

    this.get = function(l, r){
        return get(1, 0, self.n - 1, l, r);
    };

    var upd = function(v, l, r, x, t){
        if(l == r){
            P[v] = Fun(P[v], t);
            return;
        }
        var s = (l + r) >> 1;
        if(x <= s){
            upd(v * 2, l, s, x, t);
        }
        else{
            upd(v * 2 + 1, s + 1, r, x, t);
        }
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    this.upd = function(x, t){
        upd(1, 0, self.n - 1, x, t);
    };
}

var n = getInt();
var P = [];
for(var i = 0; i < n; i++){
    P.push(getLine());
}

P.sort(function(a, b){
    if(a[1] == b[1]){
        return a[0] - b[0];
    }
    return a[1] - b[1];
});
var W = P.map((x) => x[1]).concat(P.map((x) => x[0]));
var Z = W.sort((a, b) => a - b).filter((x, ind, self) => ind === 0 || self[ind - 1] != x);
var Go = {};
Z.forEach((x, ind) => Go[x] = ind);

var m = Z.length;
var dp = new SegmentTree(m);

for(var i = 0; i < n; i++){
    var up = Go[P[i][0]];
    var t = dp.get(up + 1, m - 1);
    var s = Go[P[i][1]];
    dp.upd(s, t + P[i][2]);
}

print(dp.get(0, m - 1));

function getLine(){
    return readline().split(' ').map(a => parseInt(a));
}
function getInt(){
    return parseInt(readline());
}
function SegmentTree(n){
    this.n = n;
    var P = [];
    P.length = n * 4 + 1;
    var self = this;

    function Fun(x, y){
        return Math.max(x, y);
    }

    function build(v, l, r){
        if(l == r){
            P[v] = 0;
            return;
        }
        var s = (l + r) >> 1;
        build(v * 2, l, s);
        build(v * 2 + 1, s + 1, r);
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    build(1, 0, n - 1);

    var get = function(v, l, r, lq, rq){
        if(lq > rq){
            return 0;
        }
        if(lq == l && rq == r){
            return P[v];
        }
        var s = (l + r) >> 1;
        return Fun(get(v * 2, l, s, lq, Math.min(rq, s)),
                get(v * 2 + 1, s + 1, r, Math.max(lq, s + 1), rq));
    }

    this.get = function(l, r){
        return get(1, 0, self.n - 1, l, r);
    };

    var upd = function(v, l, r, x, t){
        if(l == r){
            P[v] = Fun(P[v], t);
            return;
        }
        var s = (l + r) >> 1;
        if(x <= s){
            upd(v * 2, l, s, x, t);
        }
        else{
            upd(v * 2 + 1, s + 1, r, x, t);
        }
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    this.upd = function(x, t){
        upd(1, 0, self.n - 1, x, t);
    };
}

var n = getInt();
var P = [];
for(var i = 0; i < n; i++){
    P.push(getLine());
}

P.sort(function(a, b){
    if(a[1] == b[1]){
        return a[0] - b[0];
    }
    return a[1] - b[1];
});
var W = P.map(x => x[1]).concat(P.map(x => x[0]));
var Z = W.sort((a, b) => a - b).filter((x, ind, self) => ind === 0 || self[ind - 1] != x);
var Go = {};
Z.forEach((x, ind) => Go[x] = ind);

var m = Z.length;
var dp = new SegmentTree(m);

for(var i = 0; i < n; i++){
    var up = Go[P[i][0]];
    var t = dp.get(up + 1, m - 1);
    var s = Go[P[i][1]];
    dp.upd(s, t + P[i][2]);
}

print(dp.get(0, m - 1));

function getLine(){
    return readline().split(' ').map((a) => parseInt(a));
}
function getInt(){
    return parseInt(readline());
}
function SegmentTree(n){
    this.n = n;
    var P = [];
    P.length = n * 4 + 1;
    var self = this;

    function Fun(x, y){
        return Math.max(x, y);
    }

    function build(v, l, r){
        if(l == r){
            P[v] = 0;
            return;
        }
        var s = (l + r) >> 1;
        build(v * 2, l, s);
        build(v * 2 + 1, s + 1, r);
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    build(1, 0, n - 1);

    var get = function(v, l, r, lq, rq){
        if(lq > rq){
            return 0;
        }
        if(lq == l && rq == r){
            return P[v];
        }
        var s = (l + r) >> 1;
        return Fun(get(v * 2, l, s, lq, Math.min(rq, s)),
                get(v * 2 + 1, s + 1, r, Math.max(lq, s + 1), rq));
    }

    this.get = function(l, r){
        return get(1, 0, self.n - 1, l, r);
    };

    var upd = function(v, l, r, x, t){
        if(l == r){
            P[v] = Fun(P[v], t);
            return;
        }
        var s = (l + r) >> 1;
        if(x <= s){
            upd(v * 2, l, s, x, t);
        }
        else{
            upd(v * 2 + 1, s + 1, r, x, t);
        }
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    this.upd = function(x, t){
        upd(1, 0, self.n - 1, x, t);
    };
}

var n = getInt();
var P = [];
for(var i = 0; i < n; i++){
    P.push(getLine());
}

P.sort(function(a, b){
    if(a[1] == b[1]){
        return a[0] - b[0];
    }
    return a[1] - b[1];
});
var W = P.map((x) => x[1]).concat(P.map((x) => x[0]));
var Z = W.sort((a, b) => a - b).filter((x, ind, self) => ind === 0 || self[ind - 1] != x);
var Go = {};
Z.forEach((x, ind) => Go[x] = ind);

var m = Z.length;
var dp = new SegmentTree(m);

for(var i = 0; i < n; i++){
    var up = Go[P[i][0]];
    var t = dp.get(up + 1, m - 1);
    var s = Go[P[i][1]];
    dp.upd(s, t + P[i][2]);
    print(s, t + P[i][2]);
}

print(dp.get(0, m - 1));

function getLine(){
    return readline().split(' ').map((a) => parseInt(a));
}
function getInt(){
    return parseInt(readline());
}
function SegmentTree(n){
    this.n = n;
    var P = [];
    P.length = n * 4 + 1;
    var self = this;

    function Fun(x, y){
        return Math.max(x, y);
    }

    function build(v, l, r){
        if(l == r){
            P[v] = 0;
            return;
        }
        var s = (l + r) >> 1;
        build(v * 2, l, s);
        build(v * 2 + 1, s + 1, r);
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    build(1, 0, n - 1);

    var get = function(v, l, r, lq, rq){
        if(lq > rq){
            return 0;
        }
        if(lq == l && rq == r){
            return P[v];
        }
        var s = (l + r) >> 1;
        return Fun(get(v * 2, l, s, lq, Math.min(rq, s)),
                get(v * 2 + 1, s + 1, r, Math.max(lq, s + 1), rq));
    }

    this.get = function(l, r){
        return get(1, 0, self.n - 1, l, r);
    };

    var upd = function(v, l, r, x, t){
        if(l == r){
            P[v] = Fun(P[v], t);
            return;
        }
        var s = (l + r) >> 1;
        if(x <= s){
            upd(v * 2, l, s, x, t);
        }
        else{
            upd(v * 2 + 1, s + 1, r, x, t);
        }
        P[v] = Fun(P[v * 2], P[v * 2 + 1]);
    }
    this.upd = function(x, t){
        upd(1, 0, self.n - 1, x, t);
    };
}

var n = getInt();
var P = [];
for(var i = 0; i < n; i++){
    P.push(getLine());
}

P.sort((a, b) => a[1] - b[1]);
var W = P.map((x) => x[1]).concat(P.map((x) => x[0]));
var Z = W.sort().filter((x, ind, self) => ind === 0 || self[ind - 1] != x);
var Go = {};
Z.forEach((x, ind) => Go[x] = ind);

var m = Z.length;
var dp = new SegmentTree(m);

for(var i = 0; i < n; i++){
    var up = Go[P[i][0]];
    var t = dp.get(up + 1, m - 1);
    var s = Go[P[i][1]];
    dp.upd(s, t + P[i][2]);
}

print(dp.get(0, m - 1));

function min(a,b) {
	if(a<b) {
		return a;
	}
	else {
		return b;
	}
}
function max(a,b) {
	if(a>b) {
		return a;
	}
	else {
		return b;
	}
}
n = Number(readline());
Ar = [];
Stack = [];
ans = 0;
now = 0;
for(var i=0;i<n;i++) {
	Ar.push(readline().split(' ').map(Number));
}
Ar.sort((x,y) => {
	if(x[1] > y[1]) {
		return -1;
	}
	else if(x[1] < y[1]) {
		return 1;
	}
	else if(x[0] > y[0]) {
		return 1;
	}
	else if(x[0] < y[0]) {
		return -1;
	}
	else {
		return 0;
	}
});
for(var i = 0;i < n;i++) {
	while(Stack.length > 0 && Stack[Stack.length-1][0] >= Ar[i][1]) {
		now = now - Stack[Stack.length-1][2];
		Stack.pop();
	}
	Stack.push(Ar[i]);
	now = now + Ar[i][2];
	ans = max(ans,now);
}
print(ans);


var inp = readline().split(' ');
var n = Number(inp[0]);
var k = Number(inp[1]);
var A = readline().split(' ').map((x)=>Number(x));
A.sort((x,y) => x-y);

if(n-k < 0 || A[n-k]==A[n-k-1])print(-1);
else print(A[n-k] + " " + A[n-k]);

print(function(n,k){
	var a = readline().split(' ').map(Number).sort(function(a,b){return b-a;});
	return a[k-1] ? a[k-1]+' 0' : -1;
}.apply(0, readline().split(' ').map(Number)))

;(function () {

	var n = readline().split(' ');
	var k = +n[1];
	n = +n[0];

	if (k > n) {
		print(-1);
		return;
	}

	var s = readline().split(' ').map(Number)
		.filter(function (e, i, a) { return i == a.lastIndexOf(e); })
		.sort(function (a, b) { return a - b; });

	print( s[s.length - k] + ' 0' );

}).call(this);


var n = parseInt(readline()),
    first = [], second = [], total = [],
    firstSum = 0, secondSum = 0,
    result = '';

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

    if(value > 0)    {
        first.push(Math.abs(value));
        firstSum += value;
    } else    {
        second.push(Math.abs(value));
        secondSum += value;
    }

    total.push(value);
}

firstSum = Math.abs(firstSum);
secondSum = Math.abs(secondSum);

if(firstSum > secondSum)    result = 'first';
else if(firstSum < secondSum)    result = 'second';
else    {
    if(second.length > first.length)    {
        first.some(function(fv, idx)    {
            var sv = second[idx];

            if(fv > sv)    {
                result = 'first';
                return true;
            } else if(fv < sv)    {
                result = 'second';
                return true;
            }
        });
    } else if(second.length <= first.length)    {
        second.some(function(sv, idx)    {
            var fv = first[idx];

            if(fv > sv)    {
                result = 'first';
                return true;
            } else if(fv < sv)    {
                result = 'second';
                return true;
            }
        });
    }

    if(result == '')    total[total.length - 1] < 0 ? result = 'second' : result = 'first';
}

print(result);

function main() {
    var n = nextInt();

    var p1 = [], p2 = [];
    var res = '';
    var s1 = 0, s2 = 0;
    var i;

    for (i = 0; i < n; i++) {
        var a = nextInt();
        if (a > 0) {
            p1.push(a);
            s1 += a;
        } else {
            p2.push(-a);
            s2 += -a;
        }
        if (i === n - 1) {
            res = a > 0 ? 'first' : 'second';
        }
    }

    if (s1 != s2) {
        res = s1 > s2 ? 'first' : 'second';
    } else {
        var found = false;
        for (i = 0; i < Math.min(p1.length, p2.length); i++) {
            if (p1[i] != p2[i]) {
                res = p1[i] > p2[i] ? 'first' : 'second';
                found = true;
                break;
            }
        }
        if (!found && p1.length !== p2.length) {
            res = p1.length > p2.length ? 'first' : 'second';
        }
    }

    print(res);
}

// auxiliary code
var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(' ');
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

main();

function main() {
    var n = nextInt();

    var a = [], p1 = [], p2 = [];
    var res = '';
    var s1 = 0, s2 = 0;
    var i;

    for (i = 0; i < n; i++) {
        a[i] = nextInt();
        if (a[i] > 0) {
            p1.push(a[i]);
            s1 += a[i];
        } else {
            p2.push(-a[i]);
            s2 += -a[i];
        }
        if (i == a.length - 1) {
            res = a[i] > 0 ? 'first' : 'second';
        }
    }

    if (s1 != s2) {
        res = s1 > s2 ? 'first' : 'second';
    } else {
        res = null;
        for (i = 0; i < Math.min(p1.length, p2.length); i++) {
            if (p1[i] != p2[i]) {
                res = p1[i] > p2[i] ? 'first' : 'second';
                break;
            }
        }
        if (res === null) {
            res = p1.length > p2.length ? 'first' : 'second';
        }
    }

    print(res);
}

// auxiliary code
var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(' ');
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

main();

var n = parseInt(readline()),
			fa, sa;

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

			value < 0 ? sa = value : fa = value;
		}

		fa = Math.abs(fa);
		sa = Math.abs(sa);

		if(Math.abs(fa) > Math.abs(sa))	print('first');
		if(Math.abs(fa) < Math.abs(sa))	print('second');
		if(Math.abs(fa) == Math.abs(sa))	{
			fa < 0 ? print('first') : print('second');
		}

var n = parseInt(readline()),
			fa = [], sa = [];

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

			value < 0 ? sa.push(value) : fa.push(value);
		}

		var faLast = fa[fa.length - 1],
			saLast = sa[sa.length - 1];

		if(Math.abs(faLast) > Math.abs(saLast))	print('first');
		else if(Math.abs(faLast) < Math.abs(saLast))	print('second');
		else if(Math.abs(faLast) == Math.abs(saLast))	{
			var result = loopFunc(2);
		}

		function loopFunc(v)	{
			var faNum = Math.abs(fa[fa.length - v]),
				saNum = Math.abs(sa[sa.length - v]);

			!faNum ? faNum = -1 : false;
			!saNum ? saNum = 0 : false;

			if(faNum > saNum)	{
				print('first');
				return;
			} else if(faNum < saNum)	{
				print('second');
				return;
			} else if(faNum == saNum)	{
				loopFunc(v + 1);
			}
		};


function solve() {
    var T = Number(read());
    for (var t = 0; t < T; ++t) {
       var xy = read().split(' ');
       var x = xy[0];
       var y = xy[1];
       var xl = x.length;
       var yl = y.length;
       if (xl - yl > 2) {
          write('yes');
          continue;
       }
       if (xl < 10) {
          write(Number(x) - Number(y) > 1 ? 'yes' : 'no');
          continue;
       }
       var bx = Number(x.substr(0, xl - 9));
       var lx = Number(x.substr(xl - 9));
       var by = Number(y.substr(0, yl - 9));
       var ly = Number(y.substr(yl - 9));
       var d = (bx - by) * 1000000000;
       write(d + lx - ly > 1 ? 'yes' : 'no')
    }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

'use strict'

const q = parseInt(readline());

const fn = (x, y) => {
    y = ('0' + y).slice(-x.length);
    if ((x.length > y.length)) return 'YES'
    let i = 0;
    while (x[i] === y[i]) i++;
    if (x[i] - y[i] > 1) return 'YES';
    const j = x.length - i - 1;
    if (j === 0) return 'NO';
    if (x.slice(-j) === '0'.repeat(j) && y.slice(-j) === '9'.repeat(j)) return 'NO';
    return 'YES';
}

for(let i = 0; i < q; i++) {
    const xy = readline().split(' ');
    print(fn(xy[0],xy[1]));
}

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

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

  const [x, y] = d.split(' ').map(BigInt);

  if (y + 1n === x) {
    console.log('NO');
  }
  else {
    console.log('YES');
  }

  c++;
});

function solve() {
    var T = Number(read());
    for (var t = 0; t < T; ++t) {
       var xy = read().split(' ').map(Number);
       write(xy[0] - xy[1] > 1 ? 'YES' : 'NO');
    }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

'use strict'

const q = parseInt(readline());

const fn = (x, y) => {
    y = ('0' + y).slice(-x.length);
    if ((x.length > y.length)) return 'YES'
    let i = 0;
    while (x[i] === y[i]) i++;
    if (x[i] - y[i] > 1) return 'YES';
    i++;
    const j = x.length - i;
    if (x.slice(-i) === '0'.repeat(j) && y.slice(-i) === '9'.repeat(j)) return 'NO';
    return 'YES';
}
for(let i = 0; i < q; i++) {
    const xy = readline().split(' ');
    print(fn(xy[0],xy[1]));
}

'use strict'

const eratosthenes = n => {
    const array = Array(n).fill(true);
    const upperLimit = Math.sqrt(n);
    const output = [];

    for (var i = 2; i <= upperLimit; i++) {
        if (array[i]) {
            for (var j = i * i; j < n; j += i) {
                array[j] = false;
            }
        }
    }
    for (var i = 2; i < n; i++) {
        if(array[i]) output.push(i);
    }

    return output;
};

const q = parseInt(readline());
const isPrime = num => {
    for(let i = 2, s = Math.sqrt(num); i <= s; i++)
        if(num % i === 0) return false;
    return num > 1;
}

const primes = eratosthenes(1000000);
const fn = d => {
    if (d < 2) return 'NO';
    if (isPrime(d)) return 'YES';
    const last = primes.findIndex(i => i > Math.sqrt(d));
    if (last === -1) return 'YS'
    for (let i = 0; i < last; i++) {
        if (d%primes[i] === 0) return 'YES';
    }
    return 'NO';
}
for(let i = 0; i < q; i++) {
    const xy = readline().split(' ').map(Number);
    print(fn(xy[0] - xy[1]));
}

'use strict'

const eratosthenes = n => {
    const array = Array(n).fill(true);
    const upperLimit = Math.sqrt(n);
    const output = [];

    for (var i = 2; i <= upperLimit; i++) {
        if (array[i]) {
            for (var j = i * i; j < n; j += i) {
                array[j] = false;
            }
        }
    }
    for (var i = 2; i < n; i++) {
        if(array[i]) output.push(i);
    }

    return output;
};

const q = parseInt(readline());
const isPrime = num => {
    for(let i = 2, s = Math.sqrt(num); i <= s; i++)
        if(num % i === 0) return false;
    return num > 1;
}

const primes = eratosthenes(1000000);
const fn = d => {
    if (d < 2) return 'NO';
    if (isPrime(d)) return 'YES';
    const last = primes.findIndex(i => i > Math.sqrt(d));
    if (last === -1) return 'YES'
    for (let i = 0; i < last; i++) {
        if (d%primes[i] === 0) return 'YES';
    }
    return 'NO';
}
for(let i = 0; i < q; i++) {
    const xy = readline().split(' ').map(Number);
    print(fn(xy[0] - xy[1]));
}

'use strict'

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const xy = readline().split(' ');
    const x = xy[0];
    const y = xy[1];
    if ((x.length > y.length)) print('YES');
    else if (x.slice(0, -2) !== y.slice(0, -2)) print('YES');
    else print((x.slice(-2) - y.slice(-2) > 1) ? 'YES' : 'NO');
}

'use strict'

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const xy = readline().split(' ');
    const x = xy[0];
    const y = xy[1];
    if ((x.length > y.length)) print('YES');
    else if (x.slice(0, -1) !== y.slice(0, -1)) print('YES');
    else print((x.slice(-1) - y.slice(-1) > 1) ? 'YES' : 'NO');
}

'use strict'

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const xy = readline().split(' ');
    const x = xy[0];
    const y = xy[1];
    if (x.length > y.length || x.split('').slice(0, -1).join('') !== y.split('').slice(0, -1).join('') ) print('YES');
    else print(parseInt(x[x.length - 1]) - parseInt(y[y.length - 1]) > 1 ? 'YES' : 'NO');
}

'use strict'

const q = parseInt(readline());

for(let i = 0; i < q; i++) {
    const xy = readline().split(' ').map(Number);
    print(xy[0] - xy[1] > 1 ? 'YES' : 'NO');
}

function solve() {
    var T = Number(read());
    for (var t = 0; t < T; ++t) {
       var xy = read().split(' ');
       write(xy[0].length - xy[1].length > 1 || Number(xy[0]) - Number(xy[1]) > 1 ? 'YES' : 'NO');
    }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

function solve() {
    var T = Number(read());
    for (var t = 0; t < T; ++t) {
       var xy = read().split(' ');
       var x = xy[0];
       var y = xy[1];
       var xl = x.length;
       var yl = y.length;
       if (xl - yl > 2) {
          write('yes');
          continue;
       }
       if (xl < 10) {
          write(Number(x) - Number(y) > 1 ? 'yes' : 'no');
          continue;
       }
       var bx = x.substr(0, xl - 9);
       var lx = x.substr(xl - 9);
       var by = y.substr(0, yl - 9);
       var ly = y.substr(yl - 9);
       write(bx > by ? 'yes' : lx - ly > 1 ? 'yes' : 'no')
    }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}