«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.

The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.

Output the sequence in the required format.

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}
pgs[ parseInt(buff) ] = 1;

// ��������� ���������

var flag = 0, k=0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] != 1 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] != 1 && flag == 2)
  {
    k = i-1;
    res = res + k.toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}
if(flag == 2)
{
  k = i-1;
  res = res + k.toString(10);
  flag = 3; // �.��� ������� ����� � res
}

print(res);

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

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

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

function main() {
	var pages = tokenizeIntegers(readline().replace(/,/g, " "));
	var maxPage = 1000;
	var mark = new Array(maxPage+1);
	for (var i = 0; i < pages.length; ++i) {
		mark[pages[i]] = true;
	}

	var spans = [];
	for (var i = 1; i <= maxPage; ++i) {
		if (mark[i]) {
			var start = i;
			while (i < maxPage && mark[i+1]) {
				++i;
			}
			spans.push(i == start ? i : [start, i].join("-"));
		}
	}
	print(spans.join(","));
}

main();

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}

// ��������� ���������

var flag = 0;
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1;
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
  }
}

print(res);

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}

// ��������� ���������

var flag = 0, k=0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 0 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] == 0 && flag == 2)
  {
    k = i-1;
    res = res + k.toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}

print(res);

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}

// ��������� ���������

var flag = 0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 0 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] == 0 && flag == 2)
  {
    res = res + (i-1).toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}

print(res);

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(pgs);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(inp);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;

    if( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + buff;
    }
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(res);

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<=n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}

//pgs[1] = 1;

// ��������� ���������

var flag = 0, k=0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] != 1 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] != 1 && flag == 2)
  {
    k = i-1;
    res = res + k.toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}

print(res);

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}

pgs[1] = 1;

// ��������� ���������

var flag = 0, k=0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] != 1 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] != 1 && flag == 2)
  {
    k = i-1;
    res = res + k.toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}

print(res);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] != ",")
  {
    res = res + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(res);

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}
pgs[ parseInt(buff) ] = 1;

// ��������� ���������

var flag = 0, k=0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] != 1 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] != 1 && flag == 2)
  {
    k = i-1;
    res = res + k.toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}

print(res);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    res = res + buff;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(res);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    res = res + buff;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(res);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

/*
for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
}
*/

print(res);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  /*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
 */
}

print(res);

var inp = readline();

// ��������� ������

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";
  }
  else
  {
    buff = buff + inp[i];
  }
}

// ��������� ���������

var flag = 0, k=0; // �� ���� ����� � res
n = pgs.length;

for(i=0;i<n;i++)
{
  if( pgs[i] == 1 && flag == 0)
  {
    res = res + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] == 1 && flag == 1)
  {
    res = res + "-";
    flag = 2; // �.���� ���� � res
  }
  else if(pgs[i] == 1 && flag == 3)
  {
    res = res + "," + i.toString(10);
    flag = 1; // �.���� ����� � res
  }
  else if(pgs[i] != 1 && flag == 1)
  {
    flag = 3; // �.��� ������� ����� � res
  }
  else if(pgs[i] != 1 && flag == 2)
  {
    k = i-1;
    res = res + k.toString(10);
    flag = 3; // �.��� ������� ����� � res
  }
}

print(res);

var inp = readline();

var pgs=[], i=0, n = inp.length, buff = "", res = "";

for(i=0;i<n;i++)
{
  if( inp[i] == ",")
  {
    res = res + "-";
  }
  else
  {
    res = res + inp[i];
  }

/*
  if( inp[i] == ",")
  {
    pgs[ parseInt(buff) ] = 1;
    buff = "";

    if(i == 0 || res.length == 0)
    {
      res = res + buff;
    }
    elseif( i>0 && pgs[i-1]==1)
    {
      res == res + "-";
    }
    else
    {
      res = res + "," + buff;
    }
  }
  else
  {
    buff = buff + inp[i];
  }
*/
}

print(res);

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], m = integers[1], k = integers[2];
}

main();


This is the easy version of the problem. In this version, $$$n \le 3000$$$, $$$x \ge y$$$ holds. You can make hacks only if both versions of the problem are solved.You are given two binary strings $$$a$$$ and $$$b$$$, both of length $$$n$$$. You can do the following operation any number of times (possibly zero).   Select two indices $$$l$$$ and $$$r$$$ ($$$l < r$$$).  Change $$$a_l$$$ to $$$(1 - a_l)$$$, and $$$a_r$$$ to $$$(1 - a_r)$$$.  If $$$l + 1 = r$$$, the cost of the operation is $$$x$$$. Otherwise, the cost is $$$y$$$. You have to find the minimum cost needed to make $$$a$$$ equal to $$$b$$$ or say there is no way to do so.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 600$$$) — the number of test cases. Each test case consists of three lines. The first line of each test case contains three integers $$$n$$$, $$$x$$$, and $$$y$$$ ($$$5 \le n \le 3000$$$, $$$1 \le y \le x \le 10^9$$$) — the length of the strings, and the costs per operation. The second line of each test case contains the string $$$a$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$. The third line of each test case contains the string $$$b$$$ of length $$$n$$$. The string only consists of digits $$$0$$$ and $$$1$$$. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3000$$$.

For each test case, if there is no way to make $$$a$$$ equal to $$$b$$$, print $$$-1$$$. Otherwise, print the minimum cost needed to make $$$a$$$ equal to $$$b$$$.

NoteIn the first test case, selecting indices $$$2$$$ and $$$3$$$ costs $$$8$$$, which is the minimum possible cost.In the second test case, we cannot make $$$a$$$ equal to $$$b$$$ using any number of operations.In the third test case, we can perform the following operations:  Select indices $$$3$$$ and $$$6$$$. It costs $$$3$$$, and $$$a$$$ is 0101011 now.  Select indices $$$4$$$ and $$$6$$$. It costs $$$3$$$, and $$$a$$$ is 0100001 now. The total cost is $$$6$$$.In the fourth test case, we don't have to perform any operations.

"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++];
}
const solve = () => {
     let t = parseInt(readline());
     while(t--){
          let [n,x,y] = readline().trim().split(" ").map(cur=>parseInt(cur));
          let arr1 = readline().trim().split("").map(cur=>parseInt(cur));
          let arr2 = readline().trim().split("").map(cur=>parseInt(cur));
          let arr3 = [];
          for(let i=0;i<n;i++) arr3.push(arr1[i]^arr2[i]);
          let cnt = 0;
          for(let i=0;i<n;i++) if(arr3[i]===1) cnt++;
          if(cnt%2===1){
               console.log(-1);
               continue;
          }
          if(cnt===2){
               let flag = 1
               for(let i=0;i<n-1;i++){
                    if(arr3[i]===1 && arr3[i+1]===1){
                         console.log(Math.min(2*y,x));
                         flag = 0;
                         break;
                    }
               }
               if(flag===1) console.log(y);
          }
          else{
               console.log((cnt/2)*y);
          }
     }
};
solve();

'use strict';

var fs = require('fs');

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

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

const N = 100010;
new Array(N);
      new Array(N);
function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        x = rn(),
        y = rn(),
        a = read().split('').map(Number),
        b = read().split('').map(Number);
  let c = [];
  for (let i = 0; i < n; i++) if (a[i] !== b[i]) c.push(i);
  if (c.length & 1) return -1;
  if (c.length === 2 && c[0] + 1 === c[1]) {
    if (x > 2 * y) return 2 * y;
    return x;
  }
  return c.length / 2 * y;
}

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

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


Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,  p2,  ...,  pn.The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≤ i < n), that pi > pi + 1.You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k.

The single line contains two space-separated integers: n, k (1 ≤ n ≤ 105, 0 ≤ k < n) — the permutation length and the decreasing coefficient.

In a single line print n space-separated integers: p1, p2, ..., pn — the permutation of length n with decreasing coefficient k.  If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.

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

for(var i=1; i<x; i++){
	ans.push(i);
}
for(var i=n; i>=x; i--){
	ans.push(i);
}

print(ans.join(' '));

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

	var r = [];
	for (var i = 0; i < n - k - 1; i++) {
		r.push(i + 1);
	}

	for (var i = 0; i <= k; i++) {
		r.push(n - i);
	}

	print(r.join(' '));

}).call(this);

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

var i=1;
var j=n;
var ans=[];

while(i<=j){
	if(k>0){
		k--;
		ans.push(j--);
		ans.push(i++);
	}else{
		ans.push(i++);
	}
}
print(ans.join(' '));


Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes...Let's define a Rooted Dead Bush (RDB) of level $$$n$$$ as a rooted tree constructed as described below.A rooted dead bush of level $$$1$$$ is a single vertex. To construct an RDB of level $$$i$$$ we, at first, construct an RDB of level $$$i-1$$$, then for each vertex $$$u$$$:   if $$$u$$$ has no children then we will add a single child to it;  if $$$u$$$ has one child then we will add two children to it;  if $$$u$$$ has more than one child, then we will skip it.   Rooted Dead Bushes of level $$$1$$$, $$$2$$$ and $$$3$$$. Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw:  The center of the claw is the vertex with label $$$1$$$. Lee has a Rooted Dead Bush of level $$$n$$$. Initially, all vertices of his RDB are green.In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow.He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo $$$10^9+7$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Next $$$t$$$ lines contain test cases — one per line. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^6$$$) — the level of Lee's RDB.

For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo $$$10^9 + 7$$$.

NoteIt's easy to see that the answer for RDB of level $$$1$$$ or $$$2$$$ is $$$0$$$.The answer for RDB of level $$$3$$$ is $$$4$$$ since there is only one claw we can choose: $$$\{1, 2, 3, 4\}$$$.The answer for RDB of level $$$4$$$ is $$$4$$$ since we can choose either single claw $$$\{1, 3, 2, 4\}$$$ or single claw $$$\{2, 7, 5, 6\}$$$. There are no other claws in the RDB of level $$$4$$$ (for example, we can't choose $$$\{2, 1, 7, 6\}$$$, since $$$1$$$ is not a child of center vertex $$$2$$$).  Rooted Dead Bush of level 4.

const { KeyObject } = require("crypto");

var data = '';
var M = 1000000007;
process.stdin.setEncoding('utf8');

var res = [0, 0, 0, 4, 4];
for (var i = 5; i < 1 << 21; i++)
{
    if (i % 3 == 0)
        res[i] = res[i - 2] + res[i - 3] * 4 + res[i - 4] * 4 + 4;
    else
        res[i] = res[i - 1] + res[i - 2] * 2;
    res[i] = res[i] % M;
}

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

process.stdin.on('end', () =>
{
    var i = 1;
    var x = data.split(/\s+/).map(Number);
    for (var i = 1; i <= x[0]; i++)
    {
        console.log(res[x[i]]);
    }
});

function solve() {
   function plus(a, b, c) {
      return ((a + b) % 1000000007 + c) % 1000000007;
   }
   var T = Number(read());
   var a = [1, 1, 3];
   var b = [0, 1, 1];
   var c = [0, 0, 1];
   var ans = [0, 0, 1];
   for (var i = 3; i < 2000000; i++) {
      a.push(plus(b[i - 1], b[i - 1], a[i - 1]));
      b.push(a[i - 1]);
      c.push(plus(b[i - 1], c[i - 1], 0));
      ans.push(plus(b[i - 1], ans[i - 3], 0));
   }

   for (var t = 0; t < T; t++) {
      var n = Number(read());
      write((ans[n - 1] * 4) % 1000000007);
   }
}

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


Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to P2 watt per minute. Finally, after T2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes P3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into n time periods [l1, r1], [l2, r2], ..., [ln, rn]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [l1, rn].

The first line contains 6 integer numbers n, P1, P2, P3, T1, T2 (1 ≤ n ≤ 100, 0 ≤ P1, P2, P3 ≤ 100, 1 ≤ T1, T2 ≤ 60). The following n lines contain description of Tom's work. Each i-th of these lines contains two space-separated integers li and ri (0 ≤ li < ri ≤ 1440, ri < li + 1 for i < n), which stand for the start and the end of the i-th period of work.

var lll = readline().split(' ')
var n = lll[0]
var P1 = lll[1]
var P2 = lll[2]
var P3 = lll[3]
var T1 = lll[4]
var T2 = lll[5]

var ss = []

while (lll = readline()) ss.push(lll.split(' '))

var pows = 0
var pse

for (var i = 0; i < n; i++) {
  var s = ss[i]
  pows += (s[1] - s[0]) * P1
  if (pse) {
    var w = s[0] - pse
    pows += Math.min(w, T1) * P1
    w -= T1
    if (w > 0) {
      pows += Math.min(w, T2) * P2
      w -= T2
      if (w > 0) {
        pows += w * P3
      }
    }
  }
  pse = s[1]
}

print(pows)

var data = readline().split(' ').map(item => parseInt(item));
var n = data[0];
var p1 = data[1], p2 = data[2], p3 = data[3];
var t1 = data[4], t2 = data[5];
power = 0;
data = [];
for(var i = 0; i < n; i++) {
  data.push(readline().split(' ').map(item => parseInt(item)));
  power += (data[i][1] - data[i][0]) * p1;
}
for(var i = 0; i < n - 1; i++) {
  var time = data[i + 1][0] - data[i][1];
  var ans = Math.min(time, t1);
  power += ans * p1;
  time -= ans;
  if(time < 0) {
    continue;
  }
  ans = Math.min(time, t2);
  power += ans * p2;
  time -= ans;
  power += time * p3;
}
print(power);

var readline = require('readline'),
    rl = readline.createInterface(process.stdin, process.stdout);

var arr = []
var intervals = [];
var counter = 0;
var n = 1000;
var ans = 0;

var P1;
var P2;
var P3;
var T1;
var T2;
rl.on('line', function (line) {
    if (arr.length == 0) {
        arr = line.split(' ').map(item => { return parseInt(item) });
        n = arr[0];
        P1 = arr[1];
        P2 = arr[2];
        P3 = arr[3];
        T1 = arr[4];
        T2 = arr[5];
       /* console.log(n,P1,P2,P3,T1,T2);
        console.log(arr);
        console.log("line = "+line);*/
    }
    else {

        if (++counter < n) {

            intervals.push(line.split(' ').map(item => { return parseInt(item) }));
        }
        else {
            intervals.push(line.split(' ').map(item => { return parseInt(item) }));

           /* console.log("intervals.length= " + intervals.length)
            console.log(n,P1,P2,P3,T1,T2);
            console.log*/
            ans += (intervals[0][1] - intervals[0][0]) * P1;

            for (let i = 1; i < n; i++) {
                ans += (intervals[i][1] - intervals[i][0]) * P1;

                gap = intervals[i][0] - intervals[i - 1][1];
                if (gap >= T1) {
                    ans += T1 * P1;
                    gap -= T1;
                }
                else {
                    ans += gap * P1;
                    gap = 0;
                }

                if (gap >= T2) {
                    ans += T2 * P2;
                    gap -= T2;
                }
                else {
                    ans += gap * P2;
                    gap = 0;
                }
                ans += gap * P3;
            }
            console.log(ans);
            rl.close();
        }

    }

});

function solve(p_1, p_2, p_3, t_1, t_2, lrs) {
  const t = t_1 + t_2;
  let [p_l, p_r] = lrs.shift();
  let result = (p_r - p_l) * p_1;
  for (const [c_l, c_r] of lrs) {
    let d = c_l - p_r;
    if (d > t) {
      result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));
    } else if (d > t_1) {
      result = result + (p_1 * t_1) + (p_2 * (d - t_1));
    } else {
      result = result + (p_1 * d);
    }
    result = result + ((c_r - c_l) * p_1);
    p_l = c_l;
    p_r = c_r;
  }
  return result;
};

function main(lines) {
  const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\s+/).map(Number);
  const lrs = [];
  for (const line of lines) {
    const t = line.trim();
    if (t.length > 0) {
      const lr = t.split(/\s+/).map(Number);
      lrs.push(lr);
    }
  }
  const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)
  console.log(result);
};

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding('utf-8');
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
};

processLinesFromStream(process.stdin, main);

function solve(p_1, p_2, p_3, t_1, t_2, lrs) {
  const t = t_1 + t_2;
  const p_lr = lrs.shift();
  let [p_l, p_r] = p_lr;
  let result = (p_r - p_l) * p_1;
  for (const [c_l, c_r] of lrs) {
    let d = c_l - p_r;
    if (d > t) {
      result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));
    } else if (d > t_1) {
      result = result + (p_1 * t_1) + (p_2 * (d - t_1));
    } else {
      result = result + (p_1 * d);
    }
    result = result + ((c_r - c_l) * p_1);
    p_l = c_l;
    p_r = c_r;
  }
  return result;
};

function main(lines) {
  const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\s+/).map(Number);
  const lrs = [];
  for (const line of lines) {
    const t = line.trim();
    if (t.length > 0) {
      const lr = t.split(/\s+/).map(Number);
      lrs.push(lr);
    }
  }
  const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)
  console.log(result);
};

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding('utf-8');
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
};

processLinesFromStream(process.stdin, main);

const readline = require("readline");

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

var array = [];
var n = -1;
var P1 = 0;
var P2 = 0;
var P3 = 0;
var T1 = 0;
var T2 = 0;
var answer = 0;
var temp = 1440;

rl.on("line", input => {
  if (n == -1) {
    array = input.split(" ");
     n = parseInt(array[0]);
     P1 = parseInt(array[1]);
     P2 = parseInt(array[2]);
     P3 = parseInt(array[3]);
     T1 = parseInt(array[4]);
     T2 = parseInt(array[5]);
  } else if (n > 0) {
    array = input.split(" ");
    var start = parseInt(array[0]);
    var end = parseInt(array[1]);

    answer += (end - start) * P1;

    var deference = start - temp > 0 ? start - temp : 0;
    if (T1 < deference) {
      answer += P1 * T1;
      if ((deference - T1) > T2) {
        answer += P2 * T2;
        if (deference - (T1 + T2) > 0) answer += P3 * (deference - (T1 + T2));
      }
      else answer+= (deference-T1)*P2;
    } else if (deference > 0) answer += P1 * deference;
    temp = end;
    n--;
  }
}).on("close", () => {
  console.log(answer);
});

const readline = require('readline');

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

var ans = 0,
    n, P1, P2, P3, T1, T2, indicator = 0,
    l1, r1, l2, r2, cont, gap;

rl.on('line', (input) => {
    if (indicator == 0) {
        cont = input.split(' ').map(item => parseInt(item));
        n = cont[0], P1 = cont[1], P2 = cont[2], P3 = cont[3], T1 = cont[4], T2 = cont[5];
        indicator++;
    } else if (indicator== 1) {
        cont = input.split(' ').map(item => parseInt(item));
        l1 = cont[0], r1 = cont[1];
        ans += (r1 - l1) * P1;
        indicator++;
    } else {
        cont = input.split(' ').map(item => parseInt(item));
        l2 = cont[0], r2 = cont[1];
        //oconsole.log("l1=%d  r1=%d    l2=%d  r2=%d     ans=%d",l1,r1,l2,r2,ans);
        ans += (r2 - l2) * P1;
        gap = l2 - r1;
        if (gap > T1) {
            ans += T1 * P1;
            gap -= T1;
        } else {
            ans += gap * P1;
            gap = 0;
        }
        if (gap > T2) {
            ans += T2 * P2;
            gap -= T2;
        } else {
            ans += gap * P2;
            gap = 0;
        }
        ans += gap * P3;

        l1 = l2;
        r1 = r2;
    }

}).on('close', () => {

    console.log(ans);
    rl.close();
});

var lll = readline().split(' ')
var n = lll[0]
var P1 = lll[1]
var P2 = lll[2]
var P3 = lll[3]
var T1 = lll[4]
var T2 = lll[5]

var ss = []

while (lll = readline()) ss.push(lll.split(' '))

var pows = 0
var pse

for (var i = 0; i < ss.length; i++) {
  var s = ss[i]
  pows += (s[1] - s[0]) * P1
  if (pse) {
    var w = s[0] - pse
    pows += Math.min(w, T1) * P1
    w -= T1
    if (w) {
      pows += Math.min(w, T2) * P2
      w -= T2
      if (w) {
        pows += w * P3
      }
    }
  }
  pse = s[1]
}

print(pows)

function solve(p_1, p_2, p_3, t_1, t_2, lrs) {
  const t = t_1 + t_2;
  const [p_l, p_r] = lrs.shift();
  let result = (p_r - p_l) * p_1;
  for (const [c_l, c_r] of lrs) {
    let d = c_l - p_r;
    if (d > t) {
      result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));
    } else if (d > t_1) {
      result = result + (p_1 * t_1) + (p_2 * (d - t_1));
    } else {
      result = result + (p_1 * d);
    }
    result = result + ((c_r - c_l) * p_1);
    p_l = c_l;
    p_r = c_r;
  }
  return result;
};

function main(lines) {
  const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\s+/).map(Number);
  const lrs = [];
  for (const line of lines) {
    const t = line.trim();
    if (t.length > 0) {
      const lr = t.split(/\s+/).map(Number);
      lrs.push(lr);
    }
  }
  const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)
  console.log(result);
};

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding('utf-8');
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
};

processLinesFromStream(process.stdin, main);

function solve(p_1, p_2, p_3, t_1, t_2, lrs) {
  const t = t_1 + t_2;
  const p_lr = lrs.shift();
  const [p_l, p_r] = p_lr;
  let result = (p_r - p_l) * p_1;
  for (const [c_l, c_r] of lrs) {
    let d = c_l - p_r;
    if (d > t) {
      result = result + (p_1 * t_1) + (p_2 * t_2) + (p_3 * (d - t));
    } else if (d > t_1) {
      result = result + (p_1 * t_1) + (p_2 * (d - t_1));
    } else {
      result = result + (p_1 * d);
    }
    result = result + ((c_r - c_l) * p_1);
  }
  return result;
};

function main(lines) {
  const [n, p_1, p_2, p_3, t_1, t_2] = lines.shift().trim().split(/\s+/).map(Number);
  const lrs = [];
  for (const line of lines) {
    const t = line.trim();
    if (t.length > 0) {
      const lr = t.split(/\s+/).map(Number);
      lrs.push(lr);
    }
  }
  const result = solve(p_1, p_2, p_3, t_1, t_2, lrs)
  console.log(result);
};

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding('utf-8');
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
};

processLinesFromStream(process.stdin, main);

const readline = require("readline");

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

var array = [];
var n = -1;
var P1 = 0;
var P2 = 0;
var P3 = 0;
var T1 = 0;
var T2 = 0;
var answer = 0;
var temp = 1440;

rl.on("line", input => {
  if (n == -1) {
    array = input.split(" ");
     n = parseInt(array[0]);
     P1 = parseInt(array[1]);
     P2 = parseInt(array[2]);
     P3 = parseInt(array[3]);
     T1 = parseInt(array[4]);
     T2 = parseInt(array[5]);
  } else if (n > 0) {
    array = input.split(" ");
    var start = parseInt(array[0]);
    var end = parseInt(array[1]);

    answer += (end - start) * P1;

    var deference = start - temp > 0 ? start - temp : 0;
    if (T1 < deference) {
      answer += P1 * T1;
      if (deference - T1 > T2) {
        answer += P2 * T2;
        if (deference - (T1 + T2) > 0) answer += P3 * (deference - (T1 + T2));
      }
    } else if (deference > 0) answer += P1 * deference;
    temp = end;
    n--;
  }
}).on("close", () => {
  console.log(answer);
});

const readline = require('readline');

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

var ans = 0,
    n, P1, P2, P3, T1, T2, indicator = 0,
    l1, r1, l2, r2, cont, gap;

rl.on('line', (input) => {
    if (indicator == 0) {
        cont = input.split(' ').map(item => parseInt(item));
        n = cont[0], P1 = cont[1], P2 = cont[2], P3 = cont[3], T1 = cont[4], T2 = cont[5];
        indicator++;
    } else if (indicator == 1) {
        cont = input.split(' ').map(item => parseInt(item));
        l1 = cont[0], r1 = cont[1];
        ans += (r1 - l1) * P1;
        indicator++;
    } else {
        cont = input.split(' ').map(item => parseInt(item));
        l2 = cont[0], r2 = cont[1];
        ans += (r2 - l2) * P1;
        gap = l2 - r1;
        if (gap > T1) {
            ans += T1 * P1;
            gap -= T1;
        } else {
            ans += gap * P1;
            gap = 0;
        }
        if (gap > T2) {
            ans += T2 * P2;
            gap -= T2;
        } else {
            ans += gap * P2;
            ans = 0;
        }
        ans += gap * P3;

        l1 = l2;
        r1 = r2;
    }

}).on('close', () => {

    console.log(ans);
    rl.close();
});


There are $$$n$$$ bricks numbered from $$$1$$$ to $$$n$$$. Brick $$$i$$$ has a weight of $$$a_i$$$.Pak Chanek has $$$3$$$ bags numbered from $$$1$$$ to $$$3$$$ that are initially empty. For each brick, Pak Chanek must put it into one of the bags. After this, each bag must contain at least one brick.After Pak Chanek distributes the bricks, Bu Dengklek will take exactly one brick from each bag. Let $$$w_j$$$ be the weight of the brick Bu Dengklek takes from bag $$$j$$$. The score is calculated as $$$|w_1 - w_2| + |w_2 - w_3|$$$, where $$$|x|$$$ denotes the absolute value of $$$x$$$.It is known that Bu Dengklek will take the bricks in such a way that minimises the score. What is the maximum possible final score if Pak Chanek distributes the bricks optimally?

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$) — the number of test cases. The following lines contain the description of each test case. The first line of each test case contains an integer $$$n$$$ ($$$3 \leq n \leq 2 \cdot 10^5$$$) — the number of bricks. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the weights of the bricks. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a line containing an integer representing the maximum possible final score if Pak Chanek distributes the bricks optimally.

NoteIn the first test case, one way of achieving a final score of $$$6$$$ is to do the following:   Put bricks $$$1$$$, $$$4$$$, and $$$5$$$ into bag $$$1$$$.  Put brick $$$3$$$ into bag $$$2$$$.  Put brick $$$2$$$ into bag $$$3$$$. If Pak Chanek distributes the bricks that way, a way Bu Dengklek can take the bricks is:   Take brick $$$5$$$ from bag $$$1$$$.  Take brick $$$3$$$ from bag $$$2$$$.  Take brick $$$2$$$ from bag $$$3$$$. The score is $$$|a_5 - a_3| + |a_3 - a_2| = |3 - 5| + |5 - 1| = 6$$$. It can be shown that Bu Dengklek cannot get a smaller score from this distribution.It can be shown that there is no other distribution that results in a final score bigger than $$$6$$$.

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).sort((a, b) => a - b);

        let result = 0
        for(let i = 0; i < A.length - 2; i++) {
            result = Math.max(result, A[A.length-1]-A[i]+A[i+1]-A[i])
        }
        for(let i = 1; i < A.length - 1; i++) {
            result = Math.max(result, A[i+1]-A[0]+A[i+1]-A[i])
        }
        console.log(result)

    }
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  let n = rn(),
      a = rns();
  const b = [...new Set(a)];
  a.sort((a, b) => a - b);
  b.sort((a, b) => a - b);
  if (b.length === 1) return 0;
  if (b.length === 2) return (b[1] - b[0]) * 2;
  n = b.length;
  let res = 0;
  for (let i = n - 1; i > 1; i--) {
    res = Math.max(res, b[i] - b[0] + b[i] - b[i - 1]);
  }
  for (let i = 0; i < n - 2; i++) {
    res = Math.max(res, b[n - 1] - b[i] + b[i + 1] - b[i]);
  }
  if (a[0] === a[1]) {
    res = Math.max(res, (b[1] - b[0]) * 2);
  }
  if (a[a.length - 1] === a[a.length - 2]) {
    res = Math.max(res, (b[n - 1] - b[n - 2]) * 2);
  }
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {
            if (a.indexOf(b) < 0) a.push(b);
            return a;
        }, []).sort((a, b) => a - b);

        let result = 0
        for(let i = 0; i < A.length - 2; i++) {
            result = Math.max(result, A[A.length-1]-A[i]+A[i+1]-A[i])
        }
        for(let i = 1; i < A.length - 1; i++) {
            result = Math.max(result, A[i+1]-A[0]+A[i+1]-A[i])
        }
        console.log(result)

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {
            if (a.indexOf(b) < 0) a.push(b);
            return a;
        }, []).sort((a, b) => a - b);

        if (A.length == 1) {
            console.log(0)
        } else if (A.length == 2) {
            console.log(2 * (A[1] - A[0]))
        } else {
            const p1 = A[A.length - 1] + A[1] - 2 * A[0]
            const p2 = 2 * A[A.length - 1] - A[0] - A[A.length - 2]
            console.log(Math.max(p1, p2))
        }

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {
            if (a.indexOf(b) < 0) a.push(b);
            return a;
        }, []).sort((a, b) => a - b);

        console.log(A)

        if (A.length == 1) {
            console.log(0)
        } else if (A.length == 2) {
            console.log(2 * (A[1] - A[0]))
        } else {
            const p1 = A[A.length - 1] + A[1] - 2 * A[0]
            const p2 = 2 * A[A.length - 1] - A[0] - A[A.length - 2]
            console.log(Math.max(p1, p2))
        }

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {
            if (a.indexOf(b) < 0) a.push(b);
            return a;
        }, []).sort((a, b) => a - b);

        if (A.length == 1) {
            console.log(0)
        } else if (A.length == 2) {
            console.log(2 * (A[1] - A[0]))
        } else {
            const p1 = A[A.length - 1] + A[0] - 2 * A[1]
            const p2 = 2 * A[A.length - 1] - A[A.length - 2] - A[0]
            console.log(Math.max(p1, p2))
        }

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {
            if (a.indexOf(b) < 0) a.push(b);
            return a;
        }, []).sort((a, b) => a - b);

        if (A.length == 1) {
            console.log(0)
        } else if (A.length == 2) {
            console.log(2 * (A[1] - A[0]))
        } else {
            const p1 = 2 * A[A.length - 1] - A[A.length - 2] - A[0]
            const p2 = 2 * A[0] - A[1] - A[A.length - 1]
            console.log(Math.max(p1, p2))
        }

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const A = lines[line++].split(' ').map(x => parseInt(x, 10)).reduce((a, b) => {
            if (a.indexOf(b) < 0) a.push(b);
            return a;
        }, []).sort((a, b) => a - b);

        console.log(A)

        if (A.length == 1) {
            console.log(0)
        } else if (A.length == 2) {
            console.log(2 * (A[1] - A[0]))
        } else {
            const p1 = 2 * A[A.length - 1] - A[A.length - 2] - A[0]
            const p2 = 2 * A[0] - A[1] - A[A.length - 1]
            console.log(Math.max(p1, p2))
        }

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const a = lines[line++].split(' ').map(x => parseInt(x, 10))
        let max = -1, min = a[0], second = -1;

        for (let i = 0; i < n; i++) {
            if (max <= a[i]) {
                second = max
                max = a[i]
            } else if (second <= a[i]) {
                second = a[i]
            }
            if (min > a[i])
                min = a[i]
        }

        console.log((max - second) + (max - min))

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const a = lines[line++].split(' ').map(x => parseInt(x, 10))
        let max = -1, min = a[0], second = -1;

        for (let i = 0; i < n; i++) {
            if (max <= a[i]) {
                second = max
                max = a[i]
            }
            if (min > a[i])
                min = a[i]
        }

        console.log((max - second) + (max - min))

    }
}

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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        const a = lines[line++].split(' ').map(x => parseInt(x, 10))
        let max = a[0], min = a[0], second = -1;

        for (let i = 0; i < n; i++) {
            if (max <= a[i]) {
                second = max
                max = a[i]
            }
            if (min > a[i])
                min = a[i]
        }

        console.log((max - second) + (max - min))

    }
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  a.sort((a, b) => a - b);
  let res = a[n - 1] - a[0] + Math.max(Math.abs(a[0] - a[1]), Math.abs(a[n - 1] - a[n - 2]));
  return res;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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


Turbulent times are coming, so you decided to buy sugar in advance. There are $$$n$$$ shops around that sell sugar: the $$$i$$$-th shop sells one pack of sugar for $$$a_i$$$ coins, but only one pack to one customer each day. So in order to buy several packs, you need to visit several shops.Another problem is that prices are increasing each day: during the first day the cost is $$$a_i$$$, during the second day cost is $$$a_i + 1$$$, during the third day — $$$a_i + 2$$$ and so on for each shop $$$i$$$.On the contrary, your everyday budget is only $$$x$$$ coins. In other words, each day you go and buy as many packs as possible with total cost not exceeding $$$x$$$. Note that if you don't spend some amount of coins during a day, you can't use these coins during the next days.Eventually, the cost for each pack will exceed $$$x$$$, and you won't be able to buy even a single pack. So, how many packs will you be able to buy till that moment in total?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le x \le 10^9$$$) — the number of shops and your everyday budget. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial cost of one pack in each shop. It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the total number of packs you will be able to buy until prices exceed your everyday budget.

NoteIn the first test case,   Day 1: prices are $$$[2, 1, 2]$$$. You can buy all $$$3$$$ packs, since $$$2 + 1 + 2 \le 7$$$.  Day 2: prices are $$$[3, 2, 3]$$$. You can't buy all $$$3$$$ packs, since $$$3 + 2 + 3 > 7$$$, so you buy only $$$2$$$ packs.  Day 3: prices are $$$[4, 3, 4]$$$. You can buy $$$2$$$ packs with prices $$$4$$$ and $$$3$$$.  Day 4: prices are $$$[5, 4, 5]$$$. You can't buy $$$2$$$ packs anymore, so you buy only $$$1$$$ pack.  Day 5: prices are $$$[6, 5, 6]$$$. You can buy $$$1$$$ pack.  Day 6: prices are $$$[7, 6, 7]$$$. You can buy $$$1$$$ pack.  Day 7: prices are $$$[8, 7, 8]$$$. You still can buy $$$1$$$ pack of cost $$$7$$$.  Day 8: prices are $$$[9, 8, 9]$$$. Prices are too high, so you can't buy anything.  In total, you bought $$$3 + 2 + 2 + 1 + 1 + 1 + 1 = 11$$$ packs.In the second test case, prices are too high even at the first day, so you can't buy anything.In the third test case, you can buy only one pack at day one.In the fourth test case, you can buy $$$2$$$ packs first $$$500$$$ days. At day $$$501$$$ prices are $$$[501, 501]$$$, so you can buy only $$$1$$$ pack the next $$$500$$$ days. At day $$$1001$$$ prices are $$$[1001, 1001]$$$ so can't buy anymore. In total, you bought $$$500 \cdot 2 + 500 \cdot 1 = 1500$$$ packs.

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [n, x] = input[index].split(" ").map((item) => parseInt(item));
    index++;
    const a = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      n,
      x,
      a,
    };

    testCases.push(testCase);
  }
}

function solution(testCase, index) {
  const { n, x, a } = testCase;
  // console.log(n, x, a);

  let result = 0;

  let sum = 0;
  b = a
    .sort((c, d) => c - d)
    .map((v) => {
      sum += v;
      return sum;
    });
  // console.log(b);

  let day = 0;
  let couldBuyOnPreviousDay = n;
  while (x >= b[0] + day) {
    let couldBuyThisDay;
    for (
      couldBuyThisDay = couldBuyOnPreviousDay - 1;
      couldBuyThisDay >= 0;
      couldBuyThisDay--
    ) {
      if (x >= b[couldBuyThisDay] + (couldBuyThisDay + 1) * day) {
        break;
      }
    }
    const nbAdditionDays =
      couldBuyThisDay > -1
        ? Math.floor(
            (x - (b[couldBuyThisDay] + (couldBuyThisDay + 1) * day)) /
              (couldBuyThisDay + 1)
          )
        : 0;
    // console.log("day", day);
    // console.log("nbAdditionDays", nbAdditionDays);
    result += (couldBuyThisDay + 1) * (nbAdditionDays + 1);
    // console.log("result", result);
    couldBuyOnPreviousDay = couldBuyThisDay + 1;
    day += nbAdditionDays + 1;
  }

  console.log(result);
}

parseInput();

testCases.forEach(solution);

'use strict';

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (n, x, A)=>{
  A.sort((a, b)=>a-b);
  let l=0, sum = 0, ans = 0;
  for (; l<n; l++){
    if (sum+A[l]<=x)
      sum += A[l];
    else
     break
  }
  let add = 1;
  ans += l;
  if (sum==0)
    return 0;
    let cnt = 0
  while (l>0){
cnt++
    sum += l;
    while (sum>x){ // optimize
      sum -= A[l-1]+add;
      l--;
    }
    if (l==0)
      break;
    // find max i, so sum+i*l=x
    let i = Math.floor((x-sum+l)/l);
    if (i>0){
      ans += l*i;
      add += i;
      sum += l*(i-1);
    }
  }
  //L({x,n,A, l, sum, ans, cnt})
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n, x] = ra();
      let a = ra();
      L('Ans:')
      print(calc(n, x, a));
    }
}

E.calc = calc;

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    arr.sort((a, b) => a - b);
    let sum = arr.reduce((acc, cur) => acc + cur, 0);
    let j = n - 1,
      days = 0,
      pack = 0,
      len = 0,
      s1 = sum;
    while (j >= 0) {
      if (s1 <= k) {
        days = Math.floor((k - s1) / (j + 1)) + 1;
        pack += days * (j + 1);
        len += days;
      }
      sum -= arr[j--];
      s1 = sum + (j + 1) * len;
    }
    console.log(pack);
  }
};
solve();

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, k, arr) {
    arr.sort((a, b) => a - b)
    //
    let now = 0
    let ans = 0
    for (let i = 0; i < arr.length; i++) {
        const s = (arr[i])
        now += s
        //
        if (k < now) break

        const c = (i + 1)
        const d = binarySearch(1, 1e9, x => {
            return now + (x - 1) * c <= k
        })
        // console.log(i, d, now)
        ans += d
    }
    return ans
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        // const m = ((l + r) / 2n)
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const calc = (n, x, a)=>{
    a = a.sort((a0, a1) => a0 - a1);
    let count = 0;
    let sum = 0;

    for (let i = 0; i < n; i++) {
        if (a[i] > x) break;

        sum += a[i];

        if (sum > x) break;

        let num = i + 1;
        let localSum = 0;

        const check = (d) => {
            let seq = d - 1;
            // let seq = d % 2 === 0
            //     ? Math.round((d / 2) * (d + 1))
            //     : Math.round(((d + 1) / 2) * d);
            seq *= num;
            return seq + sum <= x;
        }

        let l = 1, r = x;
        while (l < r) {
            // console.log(`DEBUG l ${l} r ${r}`);
            let mid = l + Math.ceil((r - l) / 2);
            if (check(mid)) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        // console.log(`DEBUG l ${l} r ${r}`);
        count += (l * num);
        count -= (l * (num - 1));
    }

    return count;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, x] = ra();
        let a = ra();
        console.log(`${calc(n, x, a)}`);
    }
}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, x, a) {
  a.sort((x, y) => x - y);
  const sum = [];
  for (let i = 0; i < n; i++) {
    var _sum;
    sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + a[i];
  }
  let res = 0,
      day = 0;
  for (let i = n - 1; i >= 0; i--) {
    let num = Math.max(Math.floor((x - sum[i]) / (i + 1)) + 1, 0);
    res += (i + 1) * (num - day);
    day = num;
  }
  console.log(res);
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const [n, x] = (await read()).split(' ').map(Number);
    const a = (await read()).split(' ').map(Number);
    solve(n, x, a);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict';

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (n, x, A)=>{
  A.sort((a, b)=>a-b);
  let l=0, sum = 0, ans = 0;
  for (; l<n; l++){
    if (sum+A[l]<=x)
      sum += A[l];
    else
     break
  }
  let add = 1;
  ans += l;
  if (sum==0)
    return 0;
    let cnt = 0
  while (l>0){
cnt++
    sum += l;
    if (sum>x){ // optimize
      sum -= A[l-1]+add;
      l--;
    }
    if (l==0)
      break;
    // find max i, so sum+i*l=x
    let i = Math.floor((x-sum+l)/l);
    if (i>0){
      ans += l*i;
      add += i;
      sum += l*(i-1);
    }
  }
  //L({x,n,A, l, sum, ans, cnt})
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n, x] = ra();
      let a = ra();
      L('Ans:')
      print(calc(n, x, a));
    }
}

E.calc = calc;


There is a trampoline park with $$$n$$$ trampolines in a line. The $$$i$$$-th of which has strength $$$S_i$$$.Pekora can jump on trampolines in multiple passes. She starts the pass by jumping on any trampoline of her choice. If at the moment Pekora jumps on trampoline $$$i$$$, the trampoline will launch her to position $$$i + S_i$$$, and $$$S_i$$$ will become equal to $$$\max(S_i-1,1)$$$. In other words, $$$S_i$$$ will decrease by $$$1$$$, except of the case $$$S_i=1$$$, when $$$S_i$$$ will remain equal to $$$1$$$. If there is no trampoline in position $$$i + S_i$$$, then this pass is over. Otherwise, Pekora will continue the pass by jumping from the trampoline at position $$$i + S_i$$$ by the same rule as above.Pekora can't stop jumping during the pass until she lands at the position larger than $$$n$$$ (in which there is no trampoline). Poor Pekora!Pekora is a naughty rabbit and wants to ruin the trampoline park by reducing all $$$S_i$$$ to $$$1$$$. What is the minimum number of passes she needs to reduce all $$$S_i$$$ to $$$1$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 5000$$$) — the number of trampolines. The second line of each test case contains $$$n$$$ integers $$$S_1, S_2, \dots, S_n$$$ ($$$1 \le S_i \le 10^9$$$), where $$$S_i$$$ is the strength of the $$$i$$$-th trampoline. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$5000$$$.

For each test case, output a single integer — the minimum number of passes Pekora needs to do to reduce all $$$S_i$$$ to $$$1$$$.

NoteFor the first test case, here is an optimal series of passes Pekora can take. (The bolded numbers are the positions that Pekora jumps into during these passes.)  $$$[1,4,\textbf{2},2,\textbf{2},2,\textbf{2}]$$$  $$$[1,\textbf{4},1,2,1,\textbf{2},1]$$$  $$$[1,\textbf{3},1,2,\textbf{1},\textbf{1},\textbf{1}]$$$  $$$[1,\textbf{2},1,\textbf{2},1,\textbf{1},\textbf{1}]$$$ For the second test case, the optimal series of passes is show below.  $$$[\textbf{2},3]$$$  $$$[1,\textbf{3}]$$$  $$$[1,\textbf{2}]$$$ For the third test case, all $$$S_i$$$ are already equal to $$$1$$$.

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        var ans = 0
        var count = new Array(n).fill(0)
        for (let i = 0; i < n; i++) {
            var current = a[i] - 1

            if (a[i] > Math.max(n - i - 1, 1)) {
                var d = a[i] - Math.max(n - i - 1, 1)
                a[i] -= d
            }

            for (var j = a[i]; j >= 2; j--) {
                count[j + i]++
            }

            ans += Math.max(current - count[i], 0)
            if (i < (n - 1) && count[i] > current) {
                count[i + 1] += count[i] - current
            }
            // console.log(ans, current - count[i])
            // console.log(count)
        }
        console.log(ans)
        // console.log(a)

    })
}

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

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

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

		let ans = 0;
		const has = Array(n).fill(0);
		for (let i = 0; i < n; i++) {
			const need = Math.max(0, (s[i]-1)-has[i]);
			ans += need;

			has[i] = Math.max(s[i]-1, has[i]);
			has[i+1] += has[i]-(s[i]-1);
			for (let j = i+2; j < Math.min(s[i]+i+1, n); j++) {
				has[j]++;
			}
		}

		console.log(ans);
	}
}

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

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

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

		let ans = 0;
		const cur = Array(n).fill(0);
		for (let i = 0; i < n; i++) {
			let need = Math.max(0, s[i]-1-cur[i]);
			ans += need;

			for (let j = i + 2; j <= Math.min(i + s[i], n-1); j++) {
				cur[j]++;
			}

			let have = Math.max(s[i]-1, cur[i]);
			cur[i+1] += have - (s[i]-1);
		}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })

        var ans = 0
        var count = new Array(n).fill(0)
        for (let i = 0; i < n; i++) {
            var current = a[i] - 1

            if (a[i] > Math.max(n - i - 1, 1)) {
                var d = a[i] - Math.max(n - i - 1, 1)
                a[i] -= d
            }

            for (var j = a[i]; j >= 2; j--) {
                count[j + i]++
            }

            ans += Math.max(current - count[i], 0)
            if (j < n - 1 && count[i] > a[i]) {
                count[i + 1] += count[i] - a[i]
            }
            // console.log(ans, current - count[i])
            // console.log(count)
        }
        console.log(ans)
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var ans = 0
        var count = new Array(n).fill(0)
        for (let i = 0; i < n; i++) {
            var current = a[i] - 1

            if (a[i] > Math.max(n - i - 1, 1)) {
                var d = a[i] - Math.max(n - i - 1, 1)
                a[i] -= d
            }

            for (var j = a[i]; j >= 2; j--) {
                count[j + i]++
            }

            ans += Math.max(current - count[i], 0)
        }
        console.log(ans)
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0
        var temp = new Array(n).fill(0)
        for (let i = 0; i < n; i++) {
            var current = temp[i]

            if (a[i] > Math.max(current, 1)) {
                count += a[i] - temp[i] - 1
                current = a[i] - temp[i] - 1
            }
            // console.log(current)

            for (let j = i + 2; j < n && j < i + a[i]+1; j++) {
                temp[j]++
            }
            // console.log(temp)
            // console.log(a)
        }
        console.log(count)
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0
        var temp = new Array(n).fill(0)
        for (let i = 0; i < n; i++) {
            var current = temp[i]

            if (a[i] > Math.max(current, 1)) {
                count += a[i] - temp[i] - 1
                current = a[i] - temp[i] - 1
            }
            // console.log(current)

            for (let j = i + 2; j < n && j < i + 2 + current; j++) {
                temp[j]++
            }
            // console.log(temp)
            // console.log(a)
        }
        console.log(count)
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0
        var next = 0
        var nextI = 0

        while (exist) {
            exist = false
            for (let i = nextI; i < n; i++) {
                // console.log(a, count)
                // console.log(a)
                // console.log(i)
                if (a[i] + i < n && a[i] !== 1) {
                    nextI = i
                    exist = true
                    // var j = i
                    for (let jj = i + 1; jj < n; jj++) {
                        var dd = Math.floor(Math.log2(jj - i))
                        dd = Math.min(dd, a[i]-1)
                        // console.log(jj, jj - i, dd)
                        a[jj] = Math.max(1, a[jj] - dd)
                    }
                    count += a[i] - 1
                    a[i] = 1
                    break
                } else {
                    if (a[i] !== 1 && (a[i] + i) >= n) {
                        nextI = i

                        // console.log(i, a[i], a[i] + i - n + 1)
                        var dif = Math.min(a[i] + i - n + 1, a[i] - 1)
                        a[i] = a[i] - dif
                        count = count + dif
                        exist = true
                        break
                    }
                }
            }
        }
        // console.log(a)

        // for (let i = 0; i < n; i++) {
        //     if (a[i] > 1) count = count + BigInt(a[i]) - 1n
        // }
        console.log(count.toString())
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0
        var next = 0
        var nextI = 0

        while (exist) {
            exist = false
            for (let i = nextI; i < n; i++) {
                // console.log(a)
                // console.log(i)
                if (a[i] + i < n && a[i] !== 1) {
                    nextI = i
                    count++
                    exist = true
                    var j = i
                    while (j < n) {
                        next = a[j] + j
                        if (a[j] === 1) a[j] = 1
                        else a[j]--
                        j = next
                    }
                    break
                } else {
                    if (a[i] !== 1 && (a[i] + i) >= n) {
                        nextI = i
                        for (let jj = i + 1; jj < n; jj++) {
                            var dd = Math.floor((jj - i) / 2)
                            a[jj] = Math.max(1, a[jj] - dd)
                        }
                        var dif = Math.min(a[i] + i - n + 1, a[i] - 1)
                        a[i] = a[i] - dif
                        count = count + dif
                        exist = true
                        break
                    }
                }
            }
        }
        // console.log(a)

        // for (let i = 0; i < n; i++) {
        //     if (a[i] > 1) count = count + BigInt(a[i]) - 1n
        // }
        console.log(count.toString())
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0n
        var next = 0

        while (exist) {
            exist = false
            for (let i = 0; i < n; i++) {
                if (a[i] + i < n && a[i] !== 1) {
                    count++
                    exist = true
                    var j = i
                    while (j < n) {
                        next = a[j] + j
                        if (a[j] === 1) a[j] = 1
                        else a[j]--
                        j = next
                    }
                    // console.log(a)
                    break
                }
            }
        }

        for (let i = 0; i < n; i++) {
            if (a[i] > 1) count = count + BigInt(a[i]) - 1n
        }
        console.log(count.toString())
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0n

        while (exist) {
            exist = false
            for (let i = 0; i < n; i++) {
                if (a[i] + i < n && a[i] !== 1) {
                    count++
                    exist = true
                    var j = i
                    while (j < n) {

                        if (a[j] === 1) a[j] = 1
                        else a[j]--
                        j = a[j] + j
                    }
                }
            }
        }

        for (let i = 0; i < n; i++) {
            if (a[i] > 1) count = count + BigInt(a[i]) - 1n
        }
        console.log(count.toString())
        // console.log(a)

    })
}

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

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
    const x = readline();

    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, iii) => {
        var n = parseInt(readline())
        var x = new Array(n)
        // var [n, u, v] = readline().split(' ').map((x, iii) => {
        //     return parseInt(x)
        // })
        var a = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        var exist = true
        var count = 0

        while (exist) {
            exist = false
            for (let i = 0; i < n; i++) {
                if (a[i] + i < n && a[i] !== 1) {
                    count++
                    exist = true
                    var j = i
                    while (j < n) {

                        if (a[j] === 1) a[j] = 1
                        else a[j]--
                        j = a[j] + j
                    }
                }
            }
        }

        for (let i = 0; i < n; i++) {
            if (a[i] > 1) count += a[i] - 1
        }
        console.log(count)
        // console.log(a)

    })
}


An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.

var n = parseInt(readline());
var a = new Array(n)
if(n <= 2)print("1\n1")
else if(n == 3)print("2\n1 3")
else {
  for (var i=0;i<n;i++){
    if(i<(n-n%2)/2)a[i]=(i+1)*2
    else a[i]=2*(i-(n-n%2)/2)+1
  }
  var res=""
  for(var i=0;i<n;i++){
     res+=a[i]
     if(i!=n-1)res+=" "
  }
  print(a.length)
  print(res)
}

var n = readline();
var a = new Array(n)
if(n <= 2)print("1\n1")
else if(n == 3)print("2\n1 3")
else {
  for (var i=0;i<n;i++){
    if(i<(n-n%2)/2)a[i]=(i+1)*2
    else a[i]=2*(i-(n-n%2)/2)+1
  }
  var res=""
  for(var i=0;i<n;i++){
     res+=a[i]
     if(i!=n-1)res+=" "
  }
  print(a.length)
  print(res)
}

var n = +readline(), a = [];
for(i = 1; i <= n; i++){
	a[i] = i;
}
var buf, first, last;

if(n == 1){
	write(n + "\n");
	write(1);
}
else if(n == 2){
	write(1 + "\n");
	write(1);
}
else if(n == 3){
	write(2 + "\n");
	write(1 + " " + 3);
}
else{
	if(n % 2 == 0){
		first = 2;
		last = n-1;

		for(var i = 0; i < ((n-2)/2); first++, last--, i++){
			for(var j = first, k = (n/2 + 1); ; j++, k++){
				buf = a[k];
				a[k] = a[j];
				a[j] = buf;

				if(k == last){
					break;
				}
			}
		}

		a.splice(0,1);
		write(n + "\n");
		write(a.join(" "));
	}
	else{
		first = 2;
		last = n-1;

		for(var i = 0; i < ((n-3)/2); first++, last--, i++){
			for(var j = first, k = (Math.ceil(n/2) + 1); ; j++, k++){
				buf = a[k];
				a[k] = a[j];
				a[j] = buf;

				if(k == last){
					break;
				}
			}
		}

		a.splice(Math.ceil(n/2), 1);
		a.splice(0, 1);
		write((n-1) + "\n");
		write(a.join(" "));
	}
}

var n = +readline(), a = [];
for(i = 1; i <= n; i++){
	a[i] = i;
}
var buf, first, last;

if(n == 1){
	write(n + "\n");
	write(1);
}
else if(n == 2){
	write(0 + "\n");
	write("");
}
else if(n == 3){
	write(2 + "\n");
	write(1 + " " + 3);
}
else{
	if(n % 2 == 0){
		first = 2;
		last = n-1;

		for(var i = 0; i < ((n-2)/2); first++, last--, i++){
			for(var j = first, k = (n/2 + 1); ; j++, k++){
				buf = a[k];
				a[k] = a[j];
				a[j] = buf;

				if(k == last){
					break;
				}
			}
		}

		a.splice(0,1);
		write(n + "\n");
		write(a.join(" "));
	}
	else{
		first = 2;
		last = n-1;

		for(var i = 0; i < ((n-3)/2); first++, last--, i++){
			for(var j = first, k = (Math.ceil(n/2) + 1); ; j++, k++){
				buf = a[k];
				a[k] = a[j];
				a[j] = buf;

				if(k == last){
					break;
				}
			}
		}

		a.splice(Math.ceil(n/2), 1);
		a.splice(0, 1);
		write((n-1) + "\n");
		write(a.join(" "));
	}
}

var n = parseInt(readline());
var a = new Array(n)
if(n == 1)print("1\n1")
else if(n == 2)print("0")
else if(n == 3)print("2\n1 3")
else {
  for (var i=0;i<n;i++){
    if(i<(n-n%2)/2)a[i]=(i+1)*2
    else a[i]=2*(i-(n-n%2)/2)+1
  }
  var res=""
  for(var i=0;i<n;i++){
     res+=a[i]
     if(i!=n-1)res+=" "
  }
  print(a.length)
  print(res)
}

var n = readline();
var a = new Array(n)
if(n == 1)print("1\n1")
else if(n == 2)print("0")
else if(n == 3)print("2\n1 3")
else {
  for (var i=0;i<n;i++){
    if(i<(n-n%2)/2)a[i]=(i+1)*2
    else a[i]=2*(i-(n-n%2)/2)+1
  }
  var res=""
  for(var i=0;i<n;i++){
     res+=a[i]
     if(i!=n-1)res+=" "
  }
  print(res)
}

var n = readline();
var a = new Array(n)
if(n == 1)print("1\n1")
else if(n == 2)print("0")
else if(n == 3)print("2\n1 3")
else {
  for (var i=0;i<n;i++){
    if(i<(n-n%2)/2)a[i]=(i+1)*2
    else a[i]=2*(i-(n-n%2)/2)+1
  }
  var res=""
  for(var i=0;i<n;i++){
     res+=a[i]
     if(i!=n-1)res+=" "
  }
  print(a.length)
  print(res)
}

var n = readline();
var a = new Array(n)
if(n <= 1)print("1\n1")
else if(n == 3)print("2\n1 3")
else {
  for (var i=0;i<n;i++){
    if(i<(n-n%2)/2)a[i]=(i+1)*2
    else a[i]=2*(i-(n-n%2)/2)+1
  }
  var res=""
  for(var i=0;i<n;i++){
     res+=a[i]
     if(i!=n-1)res+=" "
  }
  print(a.length)
  print(res)
}