You are given an array $$$a$$$ of $$$n$$$ integers, and another integer $$$k$$$ such that $$$2k \le n$$$.You have to perform exactly $$$k$$$ operations with this array. In one operation, you have to choose two elements of the array (let them be $$$a_i$$$ and $$$a_j$$$; they can be equal or different, but their positions in the array must not be the same), remove them from the array, and add $$$\lfloor \frac{a_i}{a_j} \rfloor$$$ to your score, where $$$\lfloor \frac{x}{y} \rfloor$$$ is the maximum integer not exceeding $$$\frac{x}{y}$$$.Initially, your score is $$$0$$$. After you perform exactly $$$k$$$ operations, you add all the remaining elements of the array to the score.Calculate the minimum possible score you can get.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$; $$$0 \le k \le \lfloor \frac{n}{2} \rfloor$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$).

Print one integer — the minimum possible score you can get.

NoteLet's consider the example test.In the first test case, one way to obtain a score of $$$2$$$ is the following one:  choose $$$a_7 = 1$$$ and $$$a_4 = 2$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{2} \rfloor = 0$$$, the array becomes $$$[1, 1, 1, 1, 3]$$$;  choose $$$a_1 = 1$$$ and $$$a_5 = 3$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{3} \rfloor = 0$$$, the array becomes $$$[1, 1, 1]$$$;  choose $$$a_1 = 1$$$ and $$$a_2 = 1$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{1} \rfloor = 1$$$, the array becomes $$$[1]$$$;  add the remaining element $$$1$$$ to the score, so the resulting score is $$$2$$$. In the second test case, no matter which operations you choose, the resulting score is $$$16$$$.In the third test case, one way to obtain a score of $$$0$$$ is the following one:  choose $$$a_1 = 1$$$ and $$$a_2 = 3$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{3} \rfloor = 0$$$, the array becomes $$$[3, 7]$$$;  choose $$$a_1 = 3$$$ and $$$a_2 = 7$$$ for the operation; the score becomes $$$0 + \lfloor \frac{3}{7} \rfloor = 0$$$, the array becomes empty;  the array is empty, so the score doesn't change anymore. In the fourth test case, no operations can be performed, so the score is the sum of the elements of the array: $$$4 + 2 = 6$$$.

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    let sum = 0;
    for (let i = 2 * k; i < n; i++) sum += arr[i];
    let obj = {},
      cnt = 0;
    for (let i = 0; i < 2 * k; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else obj[arr[i]]++;
    }
    let keys = Object.keys(obj);
    let max = 0;
    for (let i = 0; i < keys.length; i++) max = Math.max(max, obj[keys[i]]);
    if (max <= k) console.log(sum);
    else {
      let rem = max - (2 * k - max);
      rem = rem / 2;
      console.log(rem + sum);
    }
  }
};
solve();

/* Common Template Starts */
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++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        let[n, k] = readline().split(' ').map(el=>parseInt(el));
        const nums = readline().split(' ').map(el=>parseInt(el));

        nums.sort((a,b)=>a-b);
        if(nums.length == 1){
            console.log(nums[0]);
            continue;
        }

        let p = nums.length - 2*k;
        let q = nums.length - k ;
        let score = 0;
        while(q < nums.length){
            score += Math.floor(nums[p]/nums[q]);
            p++;
            q++;
        }

        for(let i=0; i< nums.length - 2*k; ++i){
            score+= nums[i];
        }
        console.log(score);
    }
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let T = Number(lines[0]);
  let index = 1;
  let N, K, arr;

  while (T--) {
    [N, K] = lines[index++].split(' ').map(Number);
    arr = lines[index++].split(' ').map(Number);
    solve(N, K, arr);
  }
}

function solve(N, K, input) {
  let result = 0;

  input.sort((a, b) => b - a);

  for (let i = 0; i < K; ++i) {
    result += Number(input[i] === input[i + K]);
  }

  for (let i = 2 * K; i < N; ++i) {
    result += input[i];
  }

  console.log(result);
}

let buffer = '';
process.stdin.on('data', c => buffer += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = buffer.split(EOL);
  lines.pop();

  main(lines);
});

function main(lines) {
  let T = Number(lines[0]);
  let index = 1;
  let N, K, arr;

  while (T--) {
    [N, K] = lines[index++].split(' ').map(Number);
    arr = lines[index++].split(' ').map(Number);
    solve(N, K, arr);
  }
}

function solve(N, K, input) {
  const arr = new Array(N);
  let sum = 0;
  let bestRemovedSum = 0;
  let removedSum;
  let y, x, step;

  for (let i = 0; i < N; ++i) {
    arr[i] = new Array(N);
    sum += input[i];
  }

  input.sort((a, b) => a - b);

  for (let i = 0; i < N; ++i) {
    for (let j = 0; j < N; ++j) {
      arr[i][j] = input[i] + input[j] - Number(input[i] === input[j]);
    }
  }

  step = 0;

  for (let i = N - 1; i > 0; --i) {
    y = N - 1;
    x = i - 1;
    step++;
    k = K;
    removedSum = 0;
    isFlag = true;

    while (k > 0 && y >= 0 && x >= 0) {
      for (let z = 0; z < step && y >= 0 && x >= 0 && k > 0; ++z) {
        if (isFlag) {
          removedSum += arr[y][x];
          k--;
        }

        y--;
        x--;
      }

      isFlag = !isFlag;
    }

    bestRemovedSum = Math.max(bestRemovedSum, removedSum);
  }

  console.log(sum - bestRemovedSum);
}

'use strict';

function solve(n, m, a) {
  var _sort$0$, _sort, _sort$;
  const N = n - 2 * m;
  a.sort((a, b) => a - b);
  let res = a.slice(0, N).reduce((a, b) => a + b, 0);
  const map = new Map();
  for (let num of a.slice(N)) {
    var _map$get;
    map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  const max = (_sort$0$ = (_sort = [...map.entries()].sort((a, b) => b[1] - a[1])) === null || _sort === void 0 ? void 0 : (_sort$ = _sort[0]) === null || _sort$ === void 0 ? void 0 : _sort$[1]) !== null && _sort$0$ !== void 0 ? _sort$0$ : 0;
  res += Math.max(0, (max - (2 * m - max)) / 2);
  return res;
}

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

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

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, k] = rna();
		const a = rna();

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

		let ans = 0;
		for (let i = 2*k; i < n; i++)
			ans += a[i];

		function count (x) {
			let cnt = 0, cntl = 0, cntm = 0;
			for (let i = 0; i < 2*k; i++) {
				cnt  += a[i] == x;
				cntl += a[i] <  x;
				cntm += a[i] > x;
			}
			return [cnt, cntl, cntm];
		}

		ar = [...new Set(a.slice(0, 2*k+1))];
		for (const elm of ar) {
			 const [c, cl, cm] = count(elm);
			 ans += Math.max(0, (c-cl-cm)/2);
			 //console.log(elm, {ans, c, cl, cm});
		}

		console.log(ans);
	}
}

'use strict';
const readline = require('readline');
const util = require('util');
const rl = readline.createInterface({
    input: process.stdin,
});
let pos = 0;
const words = [];
rl.on('line', (line) => {
    words.push.apply(words, line.split(' ').filter(s => s != ''));
});
rl.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(words[pos++]));
}
function nextStr() {
    return words[pos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        let n = nextInt();
        let k = nextInt();
        const a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        a.sort((x, y) => x - y);
        let ans = 0;
        for (let i = 0; i < n - 2 * k; i++) {
            ans += a[i];
        }
        for (let j = n - 2 * k; j + k < n; j++) {
            ans += Math.floor(a[j] / a[j + k]);
        }
        printf("%d\n", ans);
    }
}

var s = parseInt(readline());
  while (s--) {
    var input = readline()
      .split(" ")
      .map((data) => +data);
    var n = input[0];
    var k = input[1];
    var input1 = readline()
      .split(" ")
      .map((data) => +data)
      .sort((a, b) => {
        if (a > b) {
          return 1;
        } else if (a < b) {
          return -1;
        } else {
          return 0;
        }
      });
    var min1 = n - k;
    var min2 = n - (k + k);

    var min = 0;
    for (var i = 0; i < k; i++) {
      min += Math.floor(input1[min2] / input1[min1]);
      input1[min2] = 0;
      input1[min1] = 0;
      min1++;
      min2++;
    }
    for (var i = 0; i < n; i++) {
      min += input1[i];
    }
    print(min);
  }

"use strict";

const nQueues = this.readline().split(" ");

for (let i = 0; i < nQueues; i++) {
  const lll = this.readline().split(" ");
  const n = lll[0]
  const k = lll[1]
  const numbers = this.readline().split(" ").map(function(e){return Number(e)});
  numbers.sort((a, b) => a - b);
  const ys = numbers.slice(n - k, n + 1);
  const xs = numbers.slice(n - k - k, n - k);
  const somar = numbers.slice(0, n - k - k);
  let score = 0;
  for (let j = 0; j < k; j++) {
    score += Math.floor(xs[j] / ys[j]);
  }
  for (let j = 0; j < somar.length; j++) {
    score += somar[j];
  }
  this.print(score);
}

"use strict";

function answer(nums, k) {
    let score = 0;

    nums.sort((a, b) => a - b);

    const l = nums.length;
    for (let i = 0; i < k; i += 1) {
        score += Math.floor(
            nums[l - 1 - k - i] / nums[l - 1 - i]
        );
    }

    let remaining = 0;
    for (let i = 0; i < (nums.length - (k * 2)); i += 1) {
        remaining += nums[i];
    }

    return score + remaining;
}

const nQueues = this.readline().split(' ');

for (let i = 0; i < nQueues; i++) {
    const k = this.readline().split(' ')[1];
    const nums = this.readline().split(' ').map(e => +e);
    const result = answer(nums, k);
    this.print(result.toString());
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    let sum = 0;
    for (let i = 2 * k; i < n; i++) sum += arr[i];
    let obj = {},
      cnt = 0;
    for (let i = 0; i < 2 * k; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else obj[arr[i]]++;
    }
    for (let i of Object.keys(obj)) {
      if (obj[i] === 1) cnt++;
    }
    if (cnt >= k) console.log(sum);
    else console.log(k - cnt + sum);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    let sum = 0;
    for (let i = 2 * k; i < n; i++) sum += arr[i];
    let obj = {},
      cnt = 0;
    for (let i = 0; i < 2 * k; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else obj[arr[i]]++;
    }
    for (let i of Object.keys(obj)) {
      if (obj[i] === 1) cnt++;
    }
    console.log(k - cnt + sum);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let arr = iInpArr();
    let sum = arr.reduce((i, j) => i + j, 0);
    arr.sort((a, b) => a - b);
    let i = 0,
      j = n - 1;
    while (k > 0) {
      let s1 = arr[i] + arr[j];
      let s2 = arr[j] + arr[j - 1];
      s1 += Math.floor(arr[i] / arr[j]);
      s2 += Math.floor(arr[j - 1] / arr[j]);
      if (s2 > s1) {
        sum -= arr[j - 1] + arr[j];
        sum += Math.floor(arr[j - 1] / arr[j]);
        j = j - 2;
      } else {
        sum -= arr[i] + arr[j];
        sum += Math.floor(arr[i] / arr[j]);
        i++;
      }
      k--;
    }
    console.log(sum);
  }
};
solve();

/* Common Template Starts */
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++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        let[n, k] = readline().split(' ').map(el=>parseInt(el));
        const nums = readline().split(' ').map(el=>parseInt(el));

        nums.sort((a,b)=>a-b);
        if(nums.length == 1){
            console.log(nums[0]);
            continue;
        }
        let p = nums.length - 2*k, q = nums.length - 1 ;
        let score = 0;
        while(p<q){
            score += Math.floor(nums[p]/nums[q]);
            p++;
            q--;
        }

        for(let i=0; i< nums.length - 2*k; ++i){
            score+= nums[i];
        }
        console.log(score);
    }
}

 var t = parseInt(readline())

  while (t--) {
    var b = readline()
      .split(" ")
      .map((data) => +data)
    var n = b[0]
    var k = b[1]
    var a = readline()
      .split(" ")
      .map((data) => +data).sort((a, b) => {
        if (a > b) {
          return 1;
        } else if (a < b) {
          return -1;
        } else {
          return 0;
        }
      })

    var b = [].concat(a)
    var min = 0;
    var min1 = 0;
    for (var i = 0; i < k; i++) {
      var last1 = a.pop()
      var last2 = a.pop()
      min = min + Math.floor(last2 / last1)
    }
    for (var i = 0; i < a.length; i++) {
      min += a[i]
    }

    for (var i = 0; i < k; i++) {
      var last1 = b.shift()
      var last2 = b.pop()
      min1 = min1 + Math.floor(last1 / last2)
    }
    for (var i = 0; i < a.length; i++) {
      min1 += b[i]
    }

    var ans = Math.min(min1, min)
    print(ans)
  }

var t = parseInt(readline())

  while (t--) {
    var b = readline()
      .split(" ")
      .map((data) => +data)
    var n = b[0]
    var k = b[1]
    var a = readline()
      .split(" ")
      .map((data) => +data).sort((a, b) => {
        if (a > b) {
          return 1;
        } else if (a < b) {
          return -1;
        } else {
          return 0;
        }
      })
    var min = 0;
    for (var i = 0; i < k; i++) {
      var last1 = a.pop()
      var last2 = a.pop()
      min = min + Math.floor(last2 / last1)
    }
    for (var i = 0; i < a.length; i++) {
      min += a[i]
    }
    print(min)
  }


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Let's call a pair of indices $$$i$$$, $$$j$$$ good if $$$1 \le i < j \le n$$$ and $$$\gcd(a_i, 2a_j) > 1$$$ (where $$$\gcd(x, y)$$$ is the greatest common divisor of $$$x$$$ and $$$y$$$).Find the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$2 \le n \le 2000$$$) — the number of elements in the array. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, output a single integer — the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way.

NoteIn the first example, the array elements can be rearranged as follows: $$$[6, 3, 5, 3]$$$.In the third example, the array elements can be rearranged as follows: $$$[4, 4, 2, 1, 1]$$$.

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function solve() {
   var n = Number(read());
   var a = readArray(Number);
   a.sort((x, y) => {
      var x1 = x & 1;
      var y1 = y & 1;
      if (x1 !== y1) {
         return x1 - y1;
      }
      return y - x;
   });
   var ans = 0;
   for (var i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
         if (gcd(a[i], 2 * a[j]) > 1) {
            ans++;
         }
      }
   }
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

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;

   var needWriteFile = false;

   var writeResult = '';
   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');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var odd = [];
		var even = [];
		for(var i = 0; i < N; i++){
			if(list[i] % 2 == 0){
				even.push(list[i]);
			}else{
				odd.push(list[i]);
			}
		}
		list = even.concat(odd);
		var output = 0;
		for(var i = 0; i < N - 1; i++){
			for(var j = i + 1; j < N; j++){
				if(gcd(list[i], 2 * list[j]) > 1){
					output++;
				}
			}
		}
		myout(output);
	}
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

let readline = require("readline");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);

  if (input.length === +input[0] * 2 + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let testCase = 1; testCase < input.length; testCase += 2) {
    let numbers = input[testCase + 1].split(" ");
    numbers.sort(function (x, y) {
      if (+x % 2 === 0) {
        return -1;
      }
      if (+y % 2 === 0) {
        return 1;
      }
      return 0;
    });

    let i = 0;
    let count = 0;
    let size = numbers.length - 1;
    while (+numbers[i] % 2 === 0) {
      count += size;
      size--;
      i++;
      continue;
    }

    for (let j = i; j < numbers.length - 1; j++) {
      for (let k = j + 1; k < numbers.length; k++) {
        if (findGCD(+numbers[j], +numbers[k] * 2) > 1) count++;
      }
    }

    console.log(count);
  }
};

const findGCD = (num1, num2) => {
  let a = Math.abs(num1);
  let b = Math.abs(num2);
  while (a && b && a !== b) {
    if (a > b) {
      [a, b] = [a % b, b];
    } else {
      [a, b] = [a, b % a];
    }
  }
  return a || b;
};

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function foo(n1, n2) {
    if (n1 == 1) return 0
    if (n2 == 0) return n1
    return foo(n2, n1 % n2)
}

function solve([n], arr) {
    let sum = 0
    for (let i = 0; i < n - 1; ++i) {
        for (let j = i + 1; j < n; ++j) {
            if (arr[i] % 2 == 0) {
                sum++
            } else if (arr[j] % 2 == 0) {
                sum++
            } else {
                if (foo(arr[i], arr[j]) > 1 || foo(arr[j], 2 * arr[i] > 1)) sum++
            }
        }
    }
    console.log(sum)
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i], inputArr[i + 1])
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 06/04/21 morning
 * https://codeforces.com/contest/1535/problem/B
 */

const solve = (n, A) => {
    let even = [];
    let odd = [];
    for (const e of A) e & 1 ? odd.push(e) : even.push(e);
    let a = even.concat(odd);
    let res = 0;
    for (let i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
            res += n - 1 - i;
            continue;
        }
        for (let j = i + 1; j < n; j++) {
            if (gcd(a[i], 2 * a[j]) > 1) {
                res++;
            }
        }
    }
    pr(res);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

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 = +lines[l++]
        var nums = lines[l++].split(' ').map(Number)
        console.log(solve(n, nums));
    }
});

function solve(n, nums) {
    nums.sort((a, b) => {
        const i = a & 1
        const j = b & 1
        if (i === j) {
            return 0
        } else if (i) {
            return 1
        } else {
            return -1
        }
    })

    let count = 0
    for (let i = 0; i < n; i++) {
        for (let j = i + 1; j < n; j++) {
            if (gcd(nums[i], 2 * nums[j]) > 1) count++
        }
    }
    return count
}

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

    while (a) {
        const r = b % a
        b = a
        a = r
    }
    return b
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function solve() {
   var n = Number(read());
   var a = readArray(Number);
   a.sort((x, y) => y - x);
   var ans = 0;
   for (var i = 0; i < n; i++) {
      for (j = i + 1; j < n; j++) {
         if (gcd(a[i], 2 * a[j]) > 1) {
            ans++;
         }
      }
   }
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

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;

   var needWriteFile = false;

   var writeResult = '';
   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');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
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';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//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();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var output = 0;
		for(var i = 0; i < N - 1; i++){
			for(var j = i + 1; j < N; j++){
				if(gcd(list[i], 2 * list[j]) > 1){
					output++;
				}
			}
		}
		myout(output);
	}
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.

The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.

Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.

const readline = require('readline');

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

const getOutput = n => {
  let output = [];
  while(n>0) {
    if(n%7 === 0) {
      n = n-7;
      output.push(7);
    } else if(n>=4 && n!=7) {
      n = n-4;
      output.push(4);
    } else {
      return -1;
    }
  }

  return output.join("");
}

rl.on('line', n => {

  console.log(getOutput(n));

  process.exit();
});

;(function () {

	print(function (n) {

		for (var i = 1, _i = 25e4; i < _i; i++) {
			if (i * 4 > n) return -1;

			var t = (n - i * 4) / 3;
			if ((t%1) === 0 && t <= i) {
				var result = '';
				while (t--) result += '7';
				while (result.length < i) result = '4' + result;
				return result;
			}
		}

	}(+readline()));

}.call(this));

const readline = require('readline');

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

const getOutput = n => {
  let output = [];
  while(n>0) {
    if(n==7) {
      n = n-7;
      output.push(7);
    } else if(n>=4 && n!=7) {
      n = n-4;
      output.push(4);
    } else {
      return -1;
    }
    console.log(output);
  }

  return output.join("");
}

rl.on('line', n => {

  console.log(getOutput(n));

  process.exit();
});

const readline = require('readline');

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

const getOutput = n => {
  let output = [];
  while(n>0) {
    if(n==7) {
      n = n-7;
      output.push(7);
    } else if(n>=4 && n!=7) {
      n = n-4;
      output.push(4);
    } else {
      return -1;
    }
  }

  return output.join("");
}

rl.on('line', n => {

  console.log(getOutput(n));

  process.exit();
});

;(function () {

	print(function (n) {

		for (var i = 1, _i = 25e4; i < _i; i++) {
			var k = i * 4;

			if (k > n) return -1;

			var t = (n - k) / 3;
			if ((t%1) !== 0) continue;

			if (t > i + 1) continue;

			var result = '';
			while (t--) result += '7';
			while (result.length < i) result = '4' + result;
			return result;
		}

	}(+readline()));

}.call(this));


$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied:   All scores are integers  $$$0 \leq a_{i} \leq m$$$  The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$)  — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$)  — scores of the students.

For each testcase, output one integer  — the highest possible score you can assign to yourself such that both conditions are satisfied._

NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$.

'use strict'

const problem = (n, m, a) => {
    let x = a[0];
    for(let i = 1; i < n; i++) if ((x += a[i]) >= m) return m;
    return x;
};

let t = +readline()
while(t--) {
    const nm = readline().split(' ');
    print(problem(+nm[0], +nm[1], readline().split(' ').map(i => +i)));
}

var tests= readline();

for(var n=0;n<tests;n++){
    var inputLine=readline().split(" ");
    var max=inputLine[1];
    var output=null;

    var scores=readline().split(" ").map(function(e){return parseInt(e)});

    for(var i=1;i<scores.length;i++){
        scores[0]+= scores[i];
        if(scores[0]>=max){scores[0]=max;break;}
    }//for each score

    end:print(`${scores[0]}`);

}//for each test

//var input = readline();

var T = parseInt(readline());
while (T-- > 0) {
    var kk = readline().split(" ").map(x => parseInt(x));
    var n = kk[0], m = kk[1];
    var ar = readline().split(' ').map(x => parseInt(x));
    var sum = ar.reduce((a, b) => a + b);
    print(m >= sum ? sum : m);
}

const main = data => {
  const t = data[0];

  for (let i = 0; i < t; i++) {
    const [n, m] = data[i * 2 + 1].split(' ').map(x => +x);
    const arr = data[i * 2 + 2].split(' ').map(x => +x);

    for (let j = 1; j < n; j++) {
      while (arr[j] > 0 && arr[0] < m) {
        arr[j]--;
        arr[0]++;
      }
    }

    console.log(arr[0]);
  }
};

let data = '';

process.stdin.on('data', input => data += input);
process.stdin.on('end', () => {
  data = data.split('\n');

  main(data);
});

function processData(input) {
    //Enter your code here
    input = input.trim().split("\n")
    input.shift()
    let arr = []
    for(let i = 0; i < input.length; i++){
        var first = input[i].trim().split(" ").map(Number)
        var val = first[1]
        arr = input[i+1].trim().split(" ").map(Number)
        console.log(grade(val, arr))
        i = i + 1
    }

    function grade(val, arr){
        let sum = 0
        let len = arr.length
        for(let k = 0; k < len; k++){
            sum = sum + arr[k]
        }
        let aver = sum / len
        let top = 0
        if(val <= sum){
            top = val
        }
        else{
            top = sum
        }
        return top
    }
}
process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

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

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++)
    let ai = readInts(input, ptr++)
    let sum = ai.reduce((a, b) => a + b, 0)
    wr(Math.min(sum, m))
  }
}

//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 = [];
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    var N = one[0];
    var M = one[1];
    var list = nextIntArray();
    var sum = 0;
    for(var j = 0; j < N; j++){
      sum += list[j];
    }
    output[i] = Math.min(sum , M);
  }
  myout(myconv(output, 9));
}

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

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

  if (c % 2 === 1) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  let sum = arr.reduce((a, x) => a + x, 0);

  console.log(Math.min(m, sum));

  c++;
});

'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 solution(n, m, a) {
  let d = m - a[0];

  for(let i = 1; i < n; i++){
    d -= a[i];
    if (d <= 0){
      d = 0;
      break;
    }
  }

  return m - d;
}

function main() {
    const N = parseInt(readline());

    for(let i = 0; i < N; i++){
        const line1 = readline().split(' ').map(item => parseInt(item));
        const line2 = readline().split(' ').map(item => parseInt(item));
        console.log(solution(line1[0], line1[1], line2));
    }
}

'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 solution(n, m, a) {
  let s = 0;
  a.map(i => s+=i);
  return Math.min(m, s);
}

function main() {
    const N = parseInt(readline());

    for(let i = 0; i < N; i++){
        const line1 = readline().split(' ').map(item => parseInt(item));
        const line2 = readline().split(' ').map(item => parseInt(item));
        console.log(solution(line1[0], line1[1], line2));
    }
}

const readline = require('readline');

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

let answer = "";
let n, m;

let lines = [];

rl.on('line', (t)=>{
    lines.push(t);
}).on('close', ()=>{
    let t = parseInt(lines[0]);
    for(let i = 0; i < t; i++){
        let marks = lines[i * 2 + 2].split(" ");
        [n,m] = lines[i * 2 + 1].split(' ');
        //console.log(n + " " + m);
        let my_mark = parseInt(marks[0]);
        let sum = 0;
        for(let j = 1; j < parseInt(n); j++){
            sum += parseInt(marks[j]);
        }
        if(sum + my_mark > parseInt(m))
            answer += m + '\n';
        else{
            answer += (sum + my_mark) + '\n'
        }
    }
    console.log(answer);
});

function main(raw) {
    var lines = raw.trim().split("\n").map(function (v) { return v.trim().split(" ").map(function (u) { return parseInt(u, 10); }); });
    var t = lines.shift()[0];
    while (t > 0) {
        var _a = lines.shift(), n = _a[0], m = _a[1];
        var scores = lines.shift();
        var myScore = scores[0];
        var i = 1;
        while (i < scores.length && myScore < m) {
            myScore += scores[i];
            i++;
        }
        if (myScore > m) {
            console.log(m);
        }
        else {
            console.log(myScore);
        }
        t--;
    }
}
(function () {
    var d = "";
    process.stdin.on("data", function (c) { return d += c; });
    process.stdin.on("end", function () { return main(d); });
})();

// Time Complexity O(n)
function processData(input) {
    //Enter your code here
    var data = input.trim().split('\n')
    var tcs = Number(data[0])
    var line = 1
    for(var i = 0;i<tcs;i++){
        var [n,m] = data[line].trim().split(' ').map(a=>parseInt(a))
        line++
        var arr = data[line].trim().split(' ').map(a=>parseInt(a))
        line++
        var sum = 0
        for(var j = 0;j< n;j++){
            sum += arr[j]
        }
        // console.log(sum)
        var res = Math.min(sum,m)
        console.log(res)
    }

}

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

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	let t = nl.num();
    let r = [];
    for(let i = 0 ; i < t; i++) {
       let [n, m] = nl.nums();
       let a = nl.nums();
       let s = a.reduce((x,y) => x + y, 0);
       r.push(Math.min(m, s));

    }
	console.log(r.join('\n'));

};

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

'use strict'

const problem = (n, m, a) => {
    let x = a[0];
    for(let i = 1, x = 0; i < n; i++) if ((x += a[i]) >= m) return m;
    return x;
};

let t = +readline()
while(t--) {
    const nm = readline().split(' ');
    print(problem(+nm[0], +nm[1], readline().split(' ').map(i => +i)));
}

'use strict'

const problem = (n, m, a) => {
    if (n > m) return 0;
    let r = 1;

    for (let i = 0; i < n - 1; i++)
        for (let j = i + 1; j < n; j++)
            r = (r * (a[j] -= a[i])) % m;

    return Math.abs(r);
}

const nm = readline().split(' ').map(i => +i);
const n = nm[0], m = nm[1];

print(problem(n, m, readline().split(' ').map(i => +i)))

// Time Complexity O(n)
function processData(input) {
    //Enter your code here
    var data = input.trim().split('\n')
    var tcs = Number(data[0])
    var line = 1
    for(var i = 0;i<tcs;i++){
        var [n,m] = data[line].trim().split(' ').map(a=>parseInt(a))
        line++
        var arr = data[line].trim().split(' ').map(a=>parseInt(a))
        line++
        var sum = 0
        for(var j = 0;j< n;j++){
            sum += arr[j]
        }
        console.log(sum)
        var res = Math.min(sum,m)
        console.log(res)
    }

}

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

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


You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during $$$n$$$ consecutive days. During the $$$i$$$-th day you have to write exactly $$$a_i$$$ names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly $$$m$$$ names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from $$$1$$$ to $$$n$$$.

The first line of the input contains two integers $$$n$$$, $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le m \le 10^9$$$) — the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ means the number of names you will write in the notebook during the $$$i$$$-th day.

Print exactly $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$, where $$$t_i$$$ is the number of times you will turn the page during the $$$i$$$-th day.

NoteIn the first example pages of the Death Note will look like this $$$[1, 1, 1, 2, 2], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [3, 3, 3, 3]$$$. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.

function main() {
  const is = new Scanner();
  const [n, m] = is.nextArray(Number);
  const books = is.nextArray(Number);
  let container = 0, turnPage;
  for (let i = 0; i < n; i += 1) {
    turnPage = 0;
    container += books[i];
    turnPage = Math.trunc(container / m);
    container %= m;
    process.stdout.write(String(turnPage) + ' ');
  }
  console.log();
}

/*
 *  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(); });

const readline = require('readline')

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

var n, m
var nums
var lineCount = 0
interface.on('line', function (line) {
  var splits = line.trim().split(' ').map(x => parseInt(x))
  if (lineCount == 0) {
    n = splits[0]
    m = splits[1]
    lineCount ++
  } else if (lineCount == 1) {
    nums = line.trim().split(' ')
    var rest = 0
    var answer = ''
    for (var i = 0; i < nums.length; i++) {
      var pages

      if (nums[i] < rest) {
        // console.log('nums[i]:' + nums[i], 'rest:' + rest, 'result:0')
        pages = 0
        rest = rest - nums[i]
      } else {
        pages = Math.floor((nums[i] - rest) / m)
        if (rest > 0) {
          pages += 1
        }
        // console.log('nums[i]:' + nums[i], 'rest:' + rest, 'result:' + pages)
        if ((nums[i] - rest) % m == 0) {
          rest = 0
        } else {
          rest = m - ((nums[i] - rest) % m)
        }
      }
      answer += pages + ' '
    }
    console.log(answer)
    process.exit()
  }
})

const readline = require('readline')

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

var n, m
var nums
var lineCount = 0
interface.on('line', function (line) {
  var splits = line.trim().split(' ').map(x => parseInt(x))
  if (lineCount == 0) {
    n = splits[0]
    m = splits[1]
    lineCount ++
  } else if (lineCount == 1) {
    nums = line.trim().split(' ')
    var rest = 0
    var answer = ''
    for (var i = 0; i < nums.length; i++) {
      var pages

      if (nums[i] < rest) {
        pages = 0
        rest = rest - nums[i]
      } else {
        pages = Math.floor((nums[i] - rest) / m)
        if (rest > 0) {
          pages += 1
        }
        if ((nums[i] - rest) % m == 0) {
          rest = 0
        } else {
          rest = m - ((nums[i] - rest) % m)
        }
      }
      // console.log(pages + ' ')
      answer += pages + ' '
    }
    console.log(answer)
    process.exit()
  }
})

function main(){
   var r = readline().split(' ');
   var n = r[0];
   var m = r[1];
   var arr = readline().split(' ');
   var result = [];
   var o = 0;
   arr.forEach((v,i)=>{
        v =+v + +o;
        result.push(parseInt(v/m));
        o = v%m;
   });
   print(result.join(' '));
}

main();

var m = parseInt(readline().split(' ')[1]);
var l = 0;

print(readline().split(' ').map(function(order){
    order = parseInt(order) + l;
    l = order % m

    return parseInt(order / m);
}).join(' '));

function deathNote (restArgs) {
	const days = parseInt(restArgs[0]);
	const limit = parseInt(restArgs[1]);
	const names = readline().split(" ");
	var current = 0;
	var pages = "";
	var i;
	for (i =0; i<days;i++) {
		current += parseInt(names[i]);
		pages += Math.floor(current/limit)+" ";
		current = current % limit;
	}
	return pages.trim();
}

print(deathNote(readline().split(" ")));

var line = readline().split(" ")
var names = readline().split(" ")
var limitPage = line[1]
var remaining = 0;
var responseArray = []
for(var i = 0; i < names.length; i++){
    var numOfNames = parseInt(names[i]) + remaining
    responseArray.push(Math.floor(numOfNames / limitPage))
    remaining = numOfNames % limitPage
}

print(responseArray.join(" "))

var nm = readline().split(' ').map(Number);
var n = nm[0];
var m = nm[1];

var a = readline().split(' ').map(Number);
var output = ''
var ostatok = 0;

for (var i=0; i<n; i++){
	if (ostatok == 0) output += Math.floor(a[i]/m) + ' ';
	else output += (Math.floor((a[i] - ostatok)/m) + 1) + ' ';
	if (a[i] <= ostatok) ostatok = ostatok - a[i];
	else ostatok = m - ((a[i] - ostatok) % m);
}

print (output);

// const print = require('lol-io').print;
// const readline = require('lol-io').readline;

var nm = readline().split(' ').map(n => parseInt(n));
var n = nm[0];
var m = nm[1];
var numNames = readline().split(' ').map(n => parseInt(n));

var prev = 0;
var res = [];
for (var i = 0; i < numNames.length; i++) {
  var numName = numNames[i];
  var total = prev + numName;
  var pages = parseInt(total/m);
  prev = total % m;
  res.push(pages);
}
print(res.join(' '));

// const print = require('lol-io').print;
// const readline = require('lol-io').readline;
//

var nm = readline().split(' ').map(n => parseInt(n));
var n = nm[0];
var m = nm[1];
var numNames = readline().split(' ').map(n => parseInt(n));

var prev = 0;
var res = [];
for (var i = 0; i < numNames.length; i++) {
  var numName = numNames[i];
  var total = prev + numName;
  var pages = parseInt(total/m);
  prev = total % m;
  res.push(pages);
}
print(res.join(' '));

var nm = readline().split(' ').map(Number);
var n = nm[0];
var m = nm[1];

var a = readline().split(' ').map(Number);
var output = ''
var ostatok = 0;

for (var i=0; i<n; i++){
	if (ostatok == 0) output += Math.floor(a[i]/m) + ' ';
	else output += (Math.floor((a[i] - ostatok)/m) + 1) + ' ';
	ostatok = m - ((a[i] - ostatok) % m);
}

print (output);

var nm = readline().split(' ').map(Number);
var n = nm[0];
var m = nm[1];

var a = readline().split(' ').map(Number);
var output = ''
var ostatok = 0;

for (var i=0; i<n; i++){
	if (ostatok == 0) output += Math.floor(a[i]/m) + ' ';
	else output += (Math.floor((a[i] - ostatok)/m) + 1) + ' ';
	ostatok = (m - a[i] + ostatok) % m;
}

print (output);


Cowboy Vlad has a birthday today! There are $$$n$$$ children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle arbitrarily, it may turn out, that there is a tall and low child standing next to each other, and it will be difficult for them to hold hands. Therefore, children want to stand in a circle so that the maximum difference between the growth of two neighboring children would be minimal possible.Formally, let's number children from $$$1$$$ to $$$n$$$ in a circle order, that is, for every $$$i$$$ child with number $$$i$$$ will stand next to the child with number $$$i+1$$$, also the child with number $$$1$$$ stands next to the child with number $$$n$$$. Then we will call the discomfort of the circle the maximum absolute difference of heights of the children, who stand next to each other.Please help children to find out how they should reorder themselves, so that the resulting discomfort is smallest possible.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the number of the children who came to the cowboy Vlad's birthday. The second line contains integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) denoting heights of every child.

Print exactly $$$n$$$ integers — heights of the children in the order in which they should stand in a circle. You can start printing a circle with any child. If there are multiple possible answers, print any of them.

NoteIn the first example, the discomfort of the circle is equal to $$$1$$$, since the corresponding absolute differences are $$$1$$$, $$$1$$$, $$$1$$$ and $$$0$$$. Note, that sequences $$$[2, 3, 2, 1, 1]$$$ and $$$[3, 2, 1, 1, 2]$$$ form the same circles and differ only by the selection of the starting point.In the second example, the discomfort of the circle is equal to $$$20$$$, since the absolute difference of $$$10$$$ and $$$30$$$ is equal to $$$20$$$.

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });
s.sort(function(a,b) {return a-b;});
var s_init = s.slice();
var ans2 = Array(n).fill(0);
var i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans2[i] = s[k];
		i--;
	}
	else {
		ans2[j] = s[k];
		j++;
	}
	cc++;
}
for (var i=0; i<n; i++) s[i] = ans2[i];
var ans = 0;
for (var i=0; i<n; i++) ans = Math.max(ans, Math.abs(s[i]-s[(i+1)%n]));

s.sort(function(a,b) {return b-a;});
ans3 = Array(n).fill(0);
i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans3[i] = s[k];
		i--;
	}
	else {
		ans3[j] = s[k];
		j++;
	}
	cc++;
}
var ans_new = 0;
for (var i=0; i<n; i++) ans_new = Math.max(ans_new, Math.abs(ans3[i]-ans3[(i+1)%n]));
if (ans_new < ans) {
	ans = ans_new;
	s = ans3.slice();
}
else {
	s = ans2.slice();
}

for (var iter=0; iter<35; iter++) {
	for (var i=0; i<n; i++)
		for (var j=i+1; j<n; j++) {
			var t = s[i];
			s[i] = s[j];
			s[j] = t;
			var new_ans = 0;
			for (var k=0; k<n; k++) new_ans = Math.max(new_ans, Math.abs(s[k]-s[(k+1)%n]));
			if (new_ans <= ans) {
				ans = new_ans;
				continue;
			}
			t = s[i];
			s[i] = s[j];
			s[j] = t;
		}
}
var down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort(function(a,b) {return a-b;});
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
	w.sort(function(a,b) {return a-b;});
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans = Math.max(new_ans, Math.abs(res[k]-res[(k+1)%n]));
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}
down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort(function(a,b) {return a-b;});
	var nnew = Array(n).fill(0);
	var res = Array(n).fill(0);
	res[0] = w[n-1];
	nnew[n-1] = 1;
	var aa = 1, bb = n-1;
	for (var j=0; j<n-1; j++) {
		var x = 0;
		if (j % 2 === 0) x = res[aa-1];
		else x = res[(bb+1)%n];

		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		x = w[ind];

		if (j%2===0) {
			res[aa] = x;
			aa++;
		}
		else {
			res[bb] = x;
			bb--;
		}
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
    w.sort(function(a,b) {return a-b;});
	var nnew = Array(n).fill(0);
	var res = Array(n).fill(0);
	res[0] = w[n-1];
	nnew[n-1] = 1;
	var aa = 1, bb = n-1;
	for (var j=0; j<n-1; j++) {
		var x = 0;
		if (j % 2 === 0) x = res[aa-1];
		else x = res[(bb+1)%n];

		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		x = w[ind];

		if (j%2===0) {
			res[aa] = x;
			aa++;
		}
		else {
			res[bb] = x;
			bb--;
		}
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans = Math.max(new_ans, Math.abs(res[k]-res[(k+1)%n]));
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}
write(s.join(" "));

var n = +readline(),
    l = readline().split(" ").map(item => +item).sort((a, b) => a - b),
    ans = new Array(n);

ans[0] = l[0];
ans[n - 1] = l[1];

for(var i = 2, pos = 1; i < n - 1; i+= 2, pos++) {
    ans[pos] = l[i];
    ans[n - pos - 1] = l[i + 1];
}

if (n % 2) {
    ans[pos] = l[i];
}

print(ans.join(" "));

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });
s.sort((a,b)=>a>b);
var ans2 = Array(n).fill(0);
var i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans2[i] = s[k];
		i--;
	}
	else {
		ans2[j] = s[k];
		j++;
	}
	cc++;
}
for (var i=0; i<n; i++) s[i] = ans2[i];
var ans = 0;
for (var i=0; i<n; i++) ans += Math.abs(s[i]-s[(i+1)%n]);
for (var iter=0; iter<20; iter++) {
	for (var i=0; i<n; i++)
		for (var j=i+1; j<n; j++) {
			var t = s[i];
			s[i] = s[j];
			s[j] = t;
			var new_ans = 0;
			for (var k=0; k<n; k++) new_ans += Math.abs(s[k]-s[(k+1)%n]);
			if (new_ans < ans) {
				ans = new_ans;
				continue;
			}
			t = s[i];
			s[i] = s[j];
			s[j] = t;
		}
}
write(s.join(" "));
//for (var i=0; i<n; i++) write(ans[i]," ");

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });
s.sort((a,b)=>a>b);
var s_init = s.slice();
var ans2 = Array(n).fill(0);
var i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans2[i] = s[k];
		i--;
	}
	else {
		ans2[j] = s[k];
		j++;
	}
	cc++;
}
for (var i=0; i<n; i++) s[i] = ans2[i];
var ans = 0;
for (var i=0; i<n; i++) ans += Math.abs(s[i]-s[(i+1)%n]);
for (var iter=0; iter<35; iter++) {
	for (var i=0; i<n; i++)
		for (var j=i+1; j<n; j++) {
			var t = s[i];
			s[i] = s[j];
			s[j] = t;
			var new_ans = 0;
			for (var k=0; k<n; k++) new_ans += Math.abs(s[k]-s[(k+1)%n]);
			if (new_ans < ans) {
				ans = new_ans;
				continue;
			}
			t = s[i];
			s[i] = s[j];
			s[j] = t;
		}
}
var down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans += Math.abs(res[k]-res[(k+1)%n]);
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}
down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = Array(n).fill(0);
	res[0] = w[n-1];
	nnew[n-1] = 1;
	var aa = 1, bb = n-1;
	for (var j=0; j<n-1; j++) {
		var x = 0;
		if (j % 2 === 0) x = res[aa-1];
		else x = res[(bb+1)%n];

		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		x = w[ind];

		if (j%2===0) {
			res[aa] = x;
			aa++;
		}
		else {
			res[bb] = x;
			bb--;
		}
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = Array(n).fill(0);
	res[0] = w[n-1];
	nnew[n-1] = 1;
	var aa = 1, bb = n-1;
	for (var j=0; j<n-1; j++) {
		var x = 0;
		if (j % 2 === 0) x = res[aa-1];
		else x = res[(bb+1)%n];

		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		x = w[ind];

		if (j%2===0) {
			res[aa] = x;
			aa++;
		}
		else {
			res[bb] = x;
			bb--;
		}
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
//write(" Mindiff = ", down);
//write("\n So ans = ",res.join(" "));
//write("\n");
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans += Math.abs(res[k]-res[(k+1)%n]);
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}
write(s.join(" "));

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });
s.sort((a,b)=>a>b);
var s_init = s.slice();
var ans2 = Array(n).fill(0);
var i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans2[i] = s[k];
		i--;
	}
	else {
		ans2[j] = s[k];
		j++;
	}
	cc++;
}
for (var i=0; i<n; i++) s[i] = ans2[i];
var ans = 0;
for (var i=0; i<n; i++) ans += Math.abs(s[i]-s[(i+1)%n]);
for (var iter=0; iter<20; iter++) {
	for (var i=0; i<n; i++)
		for (var j=i+1; j<n; j++) {
			var t = s[i];
			s[i] = s[j];
			s[j] = t;
			var new_ans = 0;
			for (var k=0; k<n; k++) new_ans += Math.abs(s[k]-s[(k+1)%n]);
			if (new_ans < ans) {
				ans = new_ans;
				continue;
			}
			t = s[i];
			s[i] = s[j];
			s[j] = t;
		}
}
var down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
//write(" Mindiff = ", down);
//write("\n So ans = ",res.join(" "));
//write("\n");
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans += Math.abs(res[k]-res[(k+1)%n]);
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}

write(s.join(" "));

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });
s.sort((a,b)=>a>b);
var ans = Array(n).fill(0);
var i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans[i] = s[k];
		i--;
	}
	else {
		ans[j] = s[k];
		j++;
	}
	cc++;
}
write(ans.join(" "));
//for (var i=0; i<n; i++) write(ans[i]," ");

var nums = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nums[0];
var s = readline().split(" ").map(function(x) { return parseInt(x); });
s.sort((a,b)=>a>b);
var s_init = s.slice();
var ans2 = Array(n).fill(0);
var i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans2[i] = s[k];
		i--;
	}
	else {
		ans2[j] = s[k];
		j++;
	}
	cc++;
}
for (var i=0; i<n; i++) s[i] = ans2[i];
var ans = 0;
for (var i=0; i<n; i++) ans = Math.max(ans, Math.abs(s[i]-s[(i+1)%n]));

s.sort((a,b)=>a<b);
ans3 = Array(n).fill(0);
i = n-1, j = 0, cc = 0;
for (var k=n-1; k>=0; k--) {
	if (cc%2===0) {
		ans3[i] = s[k];
		i--;
	}
	else {
		ans3[j] = s[k];
		j++;
	}
	cc++;
}
var ans_new = 0;
for (var i=0; i<n; i++) ans_new = Math.max(ans_new, Math.abs(ans3[i]-ans3[(i+1)%n]));
if (ans_new < ans) {
	ans = ans_new;
	s = ans3.slice();
}
else {
	s = ans2.slice();
}

for (var iter=0; iter<35; iter++) {
	for (var i=0; i<n; i++)
		for (var j=i+1; j<n; j++) {
			var t = s[i];
			s[i] = s[j];
			s[j] = t;
			var new_ans = 0;
			for (var k=0; k<n; k++) new_ans = Math.max(new_ans, Math.abs(s[k]-s[(k+1)%n]));
			if (new_ans < ans) {
				ans = new_ans;
				continue;
			}
			t = s[i];
			s[i] = s[j];
			s[j] = t;
		}
}
var down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = [];
	res.push(w[n-1]);
	nnew[n-1] = 1;
	var x = w[n-1];
	for (var j=0; j<n-1; j++) {
		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		res.push(w[ind]);
		x = w[ind];
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans = Math.max(new_ans, Math.abs(res[k]-res[(k+1)%n]));
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}
down = 0, up = 1000000000+10000;
while (up > down) {
	var mid = Math.floor((up + down)/2);
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = Array(n).fill(0);
	res[0] = w[n-1];
	nnew[n-1] = 1;
	var aa = 1, bb = n-1;
	for (var j=0; j<n-1; j++) {
		var x = 0;
		if (j % 2 === 0) x = res[aa-1];
		else x = res[(bb+1)%n];

		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		x = w[ind];

		if (j%2===0) {
			res[aa] = x;
			aa++;
		}
		else {
			res[bb] = x;
			bb--;
		}
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok === 1) up = mid;
	else down = mid + 1;
}
if (down >= 0) {
	var mid = down;
	var Ok = 1;
	var w = s_init.slice();
	w.sort((a,b)=>a>b);
	var nnew = Array(n).fill(0);
	var res = Array(n).fill(0);
	res[0] = w[n-1];
	nnew[n-1] = 1;
	var aa = 1, bb = n-1;
	for (var j=0; j<n-1; j++) {
		var x = 0;
		if (j % 2 === 0) x = res[aa-1];
		else x = res[(bb+1)%n];

		var mx_diff = -100000000000;
		var ind = -1;
		for (var k=0; k<n; k++)
			if (nnew[k] === 0) {
				var diff = Math.abs(w[k] - x);
				if (diff > mx_diff && diff <= mid) {
					mx_diff = diff;
					ind = k;
				}
			}
		if (ind < 0) {
			Ok = 0;
			break;
		}
		nnew[ind] = 1;
		x = w[ind];

		if (j%2===0) {
			res[aa] = x;
			aa++;
		}
		else {
			res[bb] = x;
			bb--;
		}
	}
	if (Ok)
		if (Math.abs(res[0] - res[n-1]) > mid) {
			var t = res[n-1];
			res[n-1] = res[n-2];
			res[n-2] = t;
			for (var k=0; k<n; k++)
				if (Math.abs(res[k]-res[(k+1)%n]) > mid) {Ok = 0; break;}
		}
	if (Ok) {
		var new_ans = 0;
		for (var k=0; k<n; k++) new_ans = Math.max(new_ans, Math.abs(res[k]-res[(k+1)%n]));
		if (new_ans < ans) {
			ans = new_ans;
			s = res.slice();
		}
	}
}
write(s.join(" "));

var intmax = 10000000000;
    n = +readline(),
    l = readline().split(" ").map(item => +item).sort((a, b) => a - b),
    ans = new Array(n);

ans[0] = l[0];
ans[n - 1] = l[1];

for(var i = 2, pos = 1; i <= Math.floor(n/2); i += 2, pos++) {
    ans[pos] = l[i];
    ans[n - pos - 1] = l[i + 1];
}

if (n % 2) {
    ans[pos] = l[i];
}

print(ans.join(" "));

var n = +readline(),
    l = readline().split(" ").map(item => +item).sort((a, b) => a - b),
    ans = [];

for (var i = 0; i < n; i++) {
    ans.push(0);
}

ans[0] = l[0];
ans[n - 1] = l[1];

for(var i = 2, pos = 1; i <= Math.floor(n/2); i += 2, pos++) {
    ans[pos] = l[i];
    ans[n - pos - 1] = l[i + 1];
}

if (n % 2) {
    ans[pos] = l[i];
}

print(ans.join(" "));


Mahmoud was trying to solve the vertex cover problem on trees. The problem statement is:Given an undirected tree consisting of n nodes, find the minimum number of vertices that cover all the edges. Formally, we need to find a set of vertices such that for each edge (u, v) that belongs to the tree, either u is in the set, or v is in the set, or both are in the set. Mahmoud has found the following algorithm:  Root the tree at node 1.  Count the number of nodes at an even depth. Let it be evenCnt.  Count the number of nodes at an odd depth. Let it be oddCnt.  The answer is the minimum between evenCnt and oddCnt. The depth of a node in a tree is the number of edges in the shortest path between this node and the root. The depth of the root is 0.Ehab told Mahmoud that this algorithm is wrong, but he didn't believe because he had tested his algorithm against many trees and it worked, so Ehab asked you to find 2 trees consisting of n nodes. The algorithm should find an incorrect answer for the first tree and a correct answer for the second one.

The only line contains an integer n (2 ≤ n ≤ 105), the number of nodes in the desired trees.

The output should consist of 2 independent sections, each containing a tree. The algorithm should find an incorrect answer for the tree in the first section and a correct answer for the tree in the second. If a tree doesn't exist for some section, output "-1" (without quotes) for that section only. If the answer for a section exists, it should contain n - 1 lines, each containing 2 space-separated integers u and v (1 ≤ u, v ≤ n), which means that there's an undirected edge between node u and node v. If the given graph isn't a tree or it doesn't follow the format, you'll receive wrong answer verdict. If there are multiple answers, you can print any of them.

NoteIn the first sample, there is only 1 tree with 2 nodes (node 1 connected to node 2). The algorithm will produce a correct answer in it so we printed  - 1 in the first section, but notice that we printed this tree in the second section.In the second sample:In the first tree, the algorithm will find an answer with 4 nodes, while there exists an answer with 3 nodes like this:  In the second tree, the algorithm will find an answer with 3 nodes which is correct:

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, ''))
  const n = parseInt(arr[0])

  if(n < 6){
    console.log(-1)
    for(let i = 0; i < n - 1; i++) {
      console.log(`1 ${i + 2}`)
    }
  }

  else {
    console.log('1 2')
    console.log('1 3')
    console.log('1 4')
    for(let i = 5; i <= n ; i++) {
      console.log(`2 ${i}`)
    }
    for(let i = 0; i < n - 1; i++) {
      console.log(`1 ${i + 2}`)
    }
  }
})