Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.

The first line contains the single integer n (1 ≤ n ≤ 1000) — the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.

Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.

NoteIn the first sample the performances number 2 and 3 are amazing.In the second sample the performances number 2, 4, 9 and 10 are amazing.

var n=+readline();

var a=readline().split(' ').map(function(v){return +v;});

var min=a[0];
var max=a[0];
var ans=0;
for(var i=1; i<n; i++){
	if(a[i]>max){
		ans++;
		max=a[i];
	}else if(a[i]<min){
		ans++;
		min=a[i];
	}
}
print(ans);

var n = +readline(), challenges = readline().split(" "), min = +challenges[0], max = +challenges[0], a = 0;

for(i = 1; i < n; i++){
	if(+challenges[i] > max){
		max = +challenges[i];
		a++;
	}
	else if(+challenges[i] < min){
		min = +challenges[i];
		a++;
	}
}

write(a);

var num = parseInt(readline());
var nums = readline().split(' ').map( function(a) {return parseInt(a);} );
var min = nums[0]; var max = nums[0];
var res = 0;
for (var i = 1; i < num; i++) {
    if (nums[i] > max) {
        res++;
        max = nums[i];
    } else if (nums[i] < min) {
        res++;
        min = nums[i];
    }
}
print(res);

;(function () {

	var n = +readline();
	var s = readline().split(' ').map(function (x) { return parseInt(x); });
	var x = 0;
	var min = s[x];
	var max = s[x];

	for (var i = 1; i < n; i++)
		if ( min > s[i] ) {
			x++;
			min = s[i];
		} else if ( max < s[i] ) {
			x++;
			max = s[i];
		}

	print(x);

}).call(this);

'use strict'

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function () {
  readline();
  let array = readline().getNumArray(),
      min = array[0],
      max = array[0],
      counter = 0;

  for (let i = 1; i < array.length; i++) {
    if (array[i] > max) {
      max = array[i];
      counter++;
    } else if (array[i] < min) {
      min = array[i];
      counter++;
    }
  }
  write(counter);
})();

	var n = readline();//readline().split(" ");
	var str = readline().split(" ");
	var max = +str[0], min = +str[0];
	var res = 0;
	for (var i=0; i<+n; i++){
		if (+str[i]>max){
			max = +str[i];
			res++;
		}
		else if (+str[i]<min){
			min = +str[i];
			res++;
		}
	}
	print(res);

var n = Number(readline());
s = readline().split(' ').map(Number);

var curMax = s[0];
var curMin = s[0];
var miracle = 0;

for (var i = 1; i < s.length; i++) {
    if (s[i] > curMax) {
        miracle++;
        curMax = s[i];
    }
    if (s[i] < curMin){
        miracle++;
        curMin = s[i];
    }
}

print(miracle);

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  const len = +readLine();
  const arr = readLine()
    .split(" ")
    .map((n) => parseInt(n));
  let [max, min] = [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER];
  let count = 0;

  for (let i = 0; i < len; i++) {
    if (i > 0) {
      if (arr[i] > max) count++;
      if (arr[i] < min) count++;
    }
    max = Math.max(max, arr[i]);
    min = Math.min(min, arr[i]);
  }
  console.log(count);
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = nextIntArray();
  var min = list[0];
  var max = list[0];
  var output = 0;
  for(var i = 1; i < N; i++){
    if(min > list[i]){
      min = list[i];
      output++;
    }
    if(max < list[i]){
      max = list[i];
      output++;
    }
  }
  myout(output);
}

//I_love_%username%

const {EOL} = require('os');

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL)[1].split(' ').map(c => +c);

    let max = lines[0], min = lines[0];
    let amazcount = 0;
    for(let i = 1; i < lines.length; i++)  {
    	if(lines[i] > max)  {
    		max = lines[i];
    		amazcount++;
    	}
    	if(lines[i] < min)  {
    		min = lines[i];
    		amazcount++;
    	}
    }

    process.stdout.write(amazcount + '');

    return;
});

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

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

  let ans = 0;
  const res = d.split(' ').map(Number);
  let min = max = res[0];

  for (let i = 0; i < res.length; i++) {
    if (res[i] < min) {
      ans++;
      min = res[i];
    }

    if (res[i] > max) {
      ans++;
      max = res[i];
    }
  }

  console.log(ans);

  c++;
});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  let nums = input[1].split(' ').map(x => parseInt(x));
  let min = nums[0], max = nums[0];

  let answ = 0;
  nums.forEach((x, i) => {
    if (i === 0) return;

    if (x > max) { answ += 1; max = x; }
    if (x < min) { answ += 1; min = x; }
  });

  console.log(answ);
});

let inputString = '';
let currentLine = 0;
process.stdin.on('data', data => {
	inputString += data;
});
process.stdin.on('end', function () {
	inputString = inputString
		.trim()
		.split('\n')
		.map(str => str.trim());
	main();
});

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

function isPrime(x) {
	let s = Math.sqrt(x);
	let i = 2;
	while (i <= s) {
		if (x % i === 0) {
			return false;
		}
		i++;
	}
	return true;
}

function main() {
	let n = readLine() >> 0;
	let points = readLine()
		.split(' ')
		.map(x => x >> 0);

	let worse = points[0];
	let best = points[0];
	let amazing = 0;

	for (let i = 1; i < n; ++i) {
		if (points[i] < worse) {
			worse = points[i];
			amazing++;
		}
		if (points[i] > best) {
			best = points[i];
			amazing++;
		}
	}

	console.log(amazing);
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}
function main() {
    let numberOfContests = parseInt(readLine());
    let numbersArray = readLine().split(' ').map(Number);
    let max = numbersArray[0];
    let min = numbersArray[0];
    let count = 0;
    for (let i = 0; i < numberOfContests; i++) {
        if (numbersArray[i] > max) {
            max = numbersArray[i];
            count++;
        }

        if (numbersArray[i] < min) {
            count++;
            min = numbersArray[i];
        }
    }

    console.log(count);
}

// [100, 50, 200, 150, 200]

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let points = inputs[1].trim().split(' ').map(num => Number(num));
    let amazingPoints = 0;
    let best = worst = points[0];
    for (let index = 1; index <= points.length - 1; index++) {

        if (points[index] > best) {
            best = points[index];
            amazingPoints++;
        }

        if (points[index] < worst) {
            worst = points[index];
            amazingPoints++;
        }
    }

    return amazingPoints.toString();
}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let arr = readLine().split(' ').map(v => parseInt(v));
    let best = arr[0];
    let worst = arr[0];
    let ans = 0;
    for (var i = 1; i < n; i++) {
        if (arr[i] > best) {
            ans++;
            best = arr[i];
        }
        if (arr[i] < worst) {
            ans++;
            worst = arr[i];
        }
    }
    console.log(ans);
}

n = +readline();
        numbers = [];
        tokens = readline().split(' ');
        for (i = 0; i < n; i++) {
            numbers[i] = +tokens[i];
        }

        max = numbers[0];
        min = numbers[0];
        amazing = 0;

        for (i = 0; i < n; i++) {
            if (numbers[i] > max) {
                max = numbers[i];
                amazing++;
            }
            if (numbers[i] < min) {
                min = numbers[i];
                amazing++;
            }
        }
        print(amazing);

var temporary = readline();
var inputedNumbers = readline().split(' ');
var resultArray = [];
var marksQuantity = 0;

inputedNumbers.forEach(
    function(current)
    {
        current = +current;
        if (current > getArrayMaximum(resultArray) || current < getArrayMinimum(resultArray))
            {
                marksQuantity++;
                }
        resultArray.push(current);
        });
print(marksQuantity-1);

function getArrayMaximum(array)
{
    return Math.max.apply(null, array);
    }

function getArrayMinimum(array)
{
    return Math.min.apply(null, array);
    }

n = readline().split(' ').map(Number);
results = readline().split(' ').map(Number);
min = max = results[0];
amazingness = 0;
for (i = 1; i< results.length; i++){
	if (results[i]<min){
		min = results[i];
		amazingness++;
	}
	else if (results[i]>max){
		max = results[i];
		amazingness++;
	}
}
print(amazingness);

read = +readline();
var pts = readline().split(' ').map(Number);
var max = pts[0];
var min = pts[0];
var ct = 0;
for (var i = 1; i < pts.length; i++) {
				 if(pts[i] > max)
				 			 ct++,max=pts[i];
				 if(pts[i] < min)
				 			 ct++,min=pts[i];
}
write(ct);

readline()
T=readline().split(' ').map(Number)
print(T.slice(1).reduce((a,c)=>{
	a.a += Number(c<a.lb || a.ub<c)
	a.ub=Math.max(a.ub,c)
	a.lb=Math.min(a.lb,c)
	return a;
}, {lb:T[0],ub:T[0],a:0}).a)

var numberCompetitions = +readline();
var tableResult = readline().split(" ");
var maxPoint = +tableResult[0];
var minPoint = +tableResult[0];
var amazingPerfomance = 0;
for (var perfomance=0; perfomance<numberCompetitions; perfomance++) {
    if (+tableResult[perfomance]<minPoint) {
        minPoint = +tableResult[perfomance];
        amazingPerfomance++;
    } else if (+tableResult[perfomance]>maxPoint) {
        maxPoint = +tableResult[perfomance];
        amazingPerfomance++;
    }
}
print(amazingPerfomance);

var n=+readline();

var a=readline().split(' ').map(function(v){return +v;});

var min=a[0];
var max=a[1];
var ans=0;
for(var i=1; i<n; i++){
	if(a[i]>max){
		ans++;
		max=a[i];
	}else if(a[i]<min){
		ans++;
		min=a[i];
	}
}
print(ans);

var n = readline();
var str = readline().split(" ");
var min =0; var max = 0;
if (+str[0]>+str[1]) {max=+str[0] ; min=+str[1];} else {max=+str[1], min=+str[0];}
var res = 1;
	for (var i=2; i<n; i++){

		 if (str[i]>max)
		 {
				res++;
				max = +str[i];
		 }
		 else if (str[i]<min){
				res++;
				min = +str[i];
		 }
	}
	str.length>1?print(res):print(0);

var n = readline();
var str = readline().split(" ");
var min =0; var max = 0;
if (+str[0]>+str[1]) {max=+str[0] ; min=+str[1];} else {max=+str[1], min=+str[0];}
var res = 1;
	for (var i=2; i<n; i++){

		 if (str[i]>max)
		 {
				res++;
				max = +str[i];
		 }
		 else if (str[i]<min){
				res++;
				min = +str[i];
		 }
	}
	print(res);

var n = Number(readline());
s = readline().split(' ').map(Number);

var cur = [s[0]];
var miracle = 0;

for (var i = 0; i < s.length; i++) {
    if (s[i] > cur[i] || s[i] < cur[i]) {
        miracle++;
    }
    cur.push(s[i]);
}

print(Math.floor(miracle/2));

read = +readline();
var pts = readline().split(' ');
var max = pts[0];
var min = pts[0];
var ct = 0;
pts.shift();
pts.map(function(c){
				if( c > max )
							ct++,max=c;
				else
							ct++,min=c;
});
write(ct);

read = +readline();
var pts = readline().split(' ');
var max = pts[0];
var min = pts[0];
var ct = 0;
pts.shift();
pts.map(function(c){
				if( c > max )
							ct++,max=c;
				if( c < min )
							ct++,min=c;
});
write(ct);


Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down.There is a cursor pointing at some symbol of the string. Suppose that cursor is at position i (1 ≤ i ≤ n, the string uses 1-based indexing) now. Left and right arrow keys are used to move cursor around the string. The string is cyclic, that means that when Nam presses left arrow key, the cursor will move to position i - 1 if i > 1 or to the end of the string (i. e. position n) otherwise. The same holds when he presses the right arrow key (if i = n, the cursor appears at the beginning of the string).When Nam presses up arrow key, the letter which the text cursor is pointing to will change to the next letter in English alphabet (assuming that alphabet is also cyclic, i. e. after 'z' follows 'a'). The same holds when he presses the down arrow key.Initially, the text cursor is at position p. Because Nam has a lot homework to do, he wants to complete this as fast as possible. Can you help him by calculating the minimum number of arrow keys presses to make the string to be a palindrome?

The first line contains two space-separated integers n (1 ≤ n ≤ 105) and p (1 ≤ p ≤ n), the length of Nam's string and the initial position of the text cursor. The next line contains n lowercase characters of Nam's string.

Print the minimum number of presses needed to change string into a palindrome.

NoteA string is a palindrome if it reads the same forward or reversed.In the sample test, initial Nam's string is:  (cursor position is shown bold).In optimal solution, Nam may do 6 following steps:The result, , is now a palindrome.

function getDist(a,b){
	var diff = Math.abs(word.charCodeAt(a)- word.charCodeAt(b));
	return Math.min(diff, 26-diff);
}

var inp = readline().split(" ").map(function(x){return parseInt(x);});
var n = inp[0];
var p = inp[1]-1;
var word = readline();

var lengths = [];
var p0 = -1;
var pn = -1;
var sum = 0;

for(var i=0; i < Math.floor(n/2); i++){
	lengths[i] = getDist(i, n-i-1);
	sum += lengths[i];
	if (p0 == -1 && lengths[i] > 0) p0 = i;
	if (lengths[i] > 0) pn = i;
}

p = (p >= Math.floor(n/2)) ? (n - p - 1) : p;

if (p0 == -1){}
else if (p > pn) {sum+= (p-p0); }
else if (p < p0) {sum+= (pn-p); }
else if (p-p0 < pn-p) {sum+= (p-p0) + (pn-p0); }
else if (p-p0 > pn-p) {sum+= (pn-p) + (pn-p0); }

print(sum);

function getDist(a,b){
	var diff = Math.abs(word.charCodeAt(a)- word.charCodeAt(b));
	return Math.min(diff, 26-diff);
}

var inp = readline().split(" ").map(function(x){return parseInt(x);});
var n = inp[0];
var p = inp[1]-1;
var word = readline();

var lengths = [];
var p0 = -1;
var pn = -1;
var sum = 0;

for(var i=0; i < Math.floor(n/2); i++){
	lengths[i] = getDist(i, n-i-1);
	sum += lengths[i];
	if (p0 == -1 && lengths[i] > 0) p0 = i;
	if (lengths[i] > 0) pn = i;
}

p = (p > Math.floor(n/2)) ? (n - p) : p;

if (p0 == -1){}
else if (p > pn) {sum+= (p-p0); }
else if (p < p0) {sum+= (pn-p0); }
else if (p-p0 < pn-p) {sum+= (p-p0) + (pn-p0); }
else if (p-p0 > pn-p) {sum+= (pn-p) + (pn-p0); }

print(sum);

function getDist(a,b){
	var diff = Math.abs(word.charCodeAt(a)- word.charCodeAt(b));
	return Math.min(diff, 26-diff);
}

var inp = readline().split(" ").map(function(x){return parseInt(x);});
var n = inp[0];
var p = inp[1]-1;
var word = readline();

var lengths = [];
var p0 = -1;
var pn = -1;
var sum = 0;

for(var i=0; i < Math.floor(n/2); i++){
	lengths[i] = getDist(i, n-i-1);
	sum += lengths[i];
	if (p0 == -1 && lengths[i] > 0) p0 = i;
	if (lengths[i] > 0) pn = i;
}

p = (p > Math.floor(n/2)) ? (n - p) : p;

if (p0 == -1){}
else if (p > pn) {sum+= (p-p0); }
else if (p < p0) {sum+= (pn-p); }
else if (p-p0 < pn-p) {sum+= (p-p0) + (pn-p0); }
else if (p-p0 > pn-p) {sum+= (pn-p) + (pn-p0); }

print(sum);

function getDist(a,b){
	var diff = Math.abs(word.charCodeAt(a)- word.charCodeAt(b));
	return Math.min(diff, 26-diff);
}

var inp = readline().split(" ").map(function(x){return parseInt(x);});
var n = inp[0];
var p = inp[1]-1;
var word = readline();

var lengths = [];
var p0 = -1;
var pn = -1;
var sum = 0;

for(var i=0; i < Math.floor(n/2); i++){
	lengths[i] = getDist(i, n-i-1);
	sum += lengths[i];
	if (p0 == -1 && lengths[i] > 0) p0 = i;
	if (lengths[i] > 0) pn = i;
}

p = (p > Math.floor(n/2)) ? (n - p - 1) : p;

if (p0 == -1){}
else if (p > pn) {sum+= (p-p0); }
else if (p < p0) {sum+= (pn-p); }
else if (p-p0 < pn-p) {sum+= (p-p0) + (pn-p0); }
else if (p-p0 > pn-p) {sum+= (pn-p) + (pn-p0); }

print(sum);


It is a holiday season, and Koala is decorating his house with cool lights! He owns $$$n$$$ lights, all of which flash periodically.After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters $$$a_i$$$ and $$$b_i$$$. Light with parameters $$$a_i$$$ and $$$b_i$$$ will toggle (on to off, or off to on) every $$$a_i$$$ seconds starting from the $$$b_i$$$-th second. In other words, it will toggle at the moments $$$b_i$$$, $$$b_i + a_i$$$, $$$b_i + 2 \cdot a_i$$$ and so on.You know for each light whether it's initially on or off and its corresponding parameters $$$a_i$$$ and $$$b_i$$$. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.    Here is a graphic for the first example.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of lights. The next line contains a string $$$s$$$ of $$$n$$$ characters. The $$$i$$$-th character is "1", if the $$$i$$$-th lamp is initially on. Otherwise, $$$i$$$-th character is "0". The $$$i$$$-th of the following $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le 5$$$)  — the parameters of the $$$i$$$-th light.

Print a single integer — the maximum number of lights that will ever be on at the same time.

NoteFor first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is $$$2$$$ (e.g. at the moment $$$2$$$).In the second example, all lights are initially on. So the answer is $$$4$$$.

let i = '';
process.stdin.on('data', (c) => {
  i += c;
});
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = i.split(EOL);
  const initialState = lines[1];
  const tuples = [];
  for (let i = 2; i < lines.length; i++) {
    let tuple = lines[i].split(' ');
    if (tuple.length === 2) {
      tuple = tuple.map(num => parseInt(num, 10));
      tuples.push(tuple);
    }
  }
  maxLights(initialState, tuples);
});

function maxLights(initial, tuples) {
  let split = initial.split('');
  let states = [];
  for (let i = 0; i < tuples.length; i++) {
    let statesForI = [];
    const [a, b] = tuples[i];

    let state = split[i] === '1';
    for (let j = 0; j < b; j++) {
      statesForI.push(state);
    }

    state = !state;

    let count = 0;
    for (let j = b; j < 125; j++) {
      if (count === a) {
        state = !state;
        count = 0;
      }
      count++;
      statesForI.push(state);
    }

    states.push(statesForI.slice());
  }

  let max = 0;
  for (let i = 0; i < 125; i++) {
    let count = 0;
    states.forEach(state => {
      if (state[i]) count++;
    });
    max = Math.max(count, max);
  }
  console.log(max);
  return max;
}

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

let gcd = (a, b) => a ? gcd(b % a, a) : b;
let lcm = (a, b) => a * b / gcd(a, b);

function main(){

    let n = readLine();
    let lights = readLine().split('').map( x => parseInt(x));
    // console.log(lights);
    var dur = [];
    var del = [];
    for(let i=0; i< n ; ++i){
        let tmp = readLine().split(' ').map( x => parseInt(x));
        dur.push(tmp[0]);
        del.push(tmp[1]);
    }
    // console.log(dur);
    // console.log(del);

     // var l=del.reduce(lcm)
     // console.log(l)
    var c =[];
    for(let i=0;i<2000;++i){
        c[i]=0;
    }

    for(let i=0;i<n;++i ){
        for(let j=0;j<1000;){
            while(j<del[i]){
                c[j++]+=lights[i];
            }

            if(lights[i]){
                j+=dur[i];
                for(let k=0;k<dur[i];++k){
                    c[j++]+=1;
                }
            }

            else{
                for(let k=0;k<dur[i];++k){
                    c[j++]+=1;
                }
                j+=dur[i];
            }
        }
    }
    // console.log(c);
    console.log(Math.max(...c));

}

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = readline().getNumArray()[0];
var defaultState = readline().split('').map(function (value) {
  return parseInt(value);
});
var data = [];

for (var i = 0; i < n; i++) {
  var dataElement = readline().getNumArray();
  data.push(dataElement);
}

var period = 0;
var periodStarted = 1;

var toggleLight = function toggleLight(state) {
  if (state === 0) {
    return 1;
  }

  return 0;
};

var checkLight = function checkLight(second, indexOfLight) {
  var periods = parseInt((second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1);
  var stateChanged = periods % 2 === 1;

  if (stateChanged) {
    return toggleLight(defaultState[indexOfLight]);
  }

  return defaultState[indexOfLight];
};

var amountOfLights = 0;

for (var _i = 0; _i <= 1200; _i++) {
  var lights = 0;

  for (var lightIndex = 0; lightIndex < n; lightIndex++) {
    lights += checkLight(_i, lightIndex);
  }

  if (lights > amountOfLights) {
    amountOfLights = lights;
  }
}

write(amountOfLights);

var elements = parseInt(readline());
var initial = readline();
var current = initial
var pairs = []
for (var i = 0; i < elements; i++) {
  pairs.push(readline().split(' ').map(function(num) {
    return parseInt(num);
  }))
}

var maxLights = function(lights) {
  return lights.split('').map(function(num) {
    return parseInt(num);
  }).reduce(function(acc, num) {
    return acc + num;
  }, 0);
}

var max = maxLights(initial);

var uniques = []
for (var i = 0; i < pairs.length; i++) {
  uniques.push(pairs[i][1])
}
uniques = Array.from(new Set(uniques))
uniques = uniques.reduce(function(acc, num) {
  return acc*num;
}, 1);

function foo() {
  var step = 0;
  while (step < 10000) {
    step++;
    for (var i = 0; i < pairs.length; i++) {
      if (step - pairs[i][1] < 0)
        continue;
      if ((step - pairs[i][1]) % pairs[i][0] === 0) {
        current = current.split('')
        current[i] = (current[i] === '0') ? '1' : '0'
        current = current.join('')
      }
    }
    max = Math.max(max, maxLights(current))
  }

  write(max)
}

foo();

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = readline().getNumArray()[0];
var defaultState = readline().split('').map(function (value) {
  return parseInt(value);
});
var data = [];

for (var i = 0; i < n; i++) {
  var dataElement = readline().getNumArray();
  data.push(dataElement);
}

var period = 0;
var periodStarted = 1;

var toggleLight = function toggleLight(state) {
  if (state === 0) {
    return 1;
  }

  return 0;
};

var checkLight = function checkLight(second, indexOfLight) {
  var periods = (second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1;
  var stateChanged = periods % 2 === true;

  if (stateChanged) {
    return toggleLight(defaultState[indexOfLight]);
  }

  return defaultState[indexOfLight];
};

var amountOfLights = 0;

for (var _i = 1; _i <= 120; _i++) {
  var lights = 0;

  for (var lightIndex = 0; lightIndex < n; lightIndex++) {
    lights += checkLight(_i, lightIndex);
  }

  if (lights > amountOfLights) {
    amountOfLights = lights;
  }
}

write(amountOfLights);

"use strict";

String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

var n = readline().getNumArray()[0];
var defaultState = readline().split('').map(function (value) {
  return parseInt(value);
});
var data = [];

for (var i = 0; i < n; i++) {
  var dataElement = readline().getNumArray();
  data.push(dataElement);
}

var period = 0;
var periodStarted = 1;

var toggleLight = function toggleLight(state) {
  if (state === 0) {
    return 1;
  }

  return 0;
};

var checkLight = function checkLight(second, indexOfLight) {
  var periods = parseInt((second - data[indexOfLight][periodStarted]) / data[indexOfLight][period] + 1);
  var stateChanged = periods % 2 === 1;

  if (stateChanged) {
    return toggleLight(defaultState[indexOfLight]);
  }

  return defaultState[indexOfLight];
};

var amountOfLights = 0;

for (var _i = 1; _i <= 500; _i++) {
  var lights = 0;

  for (var lightIndex = 0; lightIndex < n; lightIndex++) {
    lights += checkLight(_i, lightIndex);
  }

  if (lights > amountOfLights) {
    amountOfLights = lights;
  }
}

write(amountOfLights);

var elements = parseInt(readline());
var initial = readline();
var current = initial
var pairs = []
for (var i = 0; i < elements; i++) {
  pairs.push(readline().split(' ').map(function(num) {
    return parseInt(num);
  }))
}

// var initial = '101'
// var current = initial;
// var pairs = [[3, 3], [3, 2], [3, 1]]

var maxLights = function(lights) {
  return lights.split('').map(function(num) {
    return parseInt(num);
  }).reduce(function(acc, num) {
    return acc + num;
  }, 0);
}

var max = maxLights(initial);

var uniques = []
for (var i = 0; i < pairs.length; i++) {
  uniques.push(pairs[i][1])
}
uniques = Array.from(new Set(uniques))
uniques = uniques.reduce(function(acc, num) {
  return acc*num;
}, 1);

function foo() {
  var step = 0;
  while (initial !== current || step < pairs[0][1]) {
    if (step > uniques) {
      write(max);
      return;
    }
    step++;
    for (var i = 0; i < pairs.length; i++) {
      if (step - pairs[i][1] < 0)
        continue;
      if ((step - pairs[i][1]) % pairs[i][0] === 0) {
        current = current.split('')
        current[i] = (current[i] === '0') ? '1' : '0'
        current = current.join('')
      }
    }
    max = Math.max(max, maxLights(current))
  }

  write(max)
}

foo();


This is an interactive problem. In the output section below you will see the information about flushing the output.Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime or composite.Integer x > 1 is called prime if it has exactly two distinct divisors, 1 and x. If integer x > 1 is not prime, it's called composite.You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2, 100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no".For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14.When you are done asking queries, print "prime" or "composite" and terminate your program.You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2, 100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct.You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).

After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.

Up to 20 times you can ask a query — print an integer from interval [2, 100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program. To flush you can use (just after printing an integer and end-of-line):    fflush(stdout) in C++;  System.out.flush() in Java;  stdout.flush() in Python;  flush(output) in Pascal;  See the documentation for other languages.  Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2, 100]. Of course, his/her solution won't be able to read the hidden number from the input.

NoteThe hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30.59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries).

var prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
var factorIndex = [];
var count = 0;
var mul = 1;
var isPrime = true;
for (var i = 0; i < prime.length; i++) {
    if(count === 20){
        break;
    }
    if (factorIndex.length === 1 && prime[i]*prime[factorIndex[0]] > 100) {
        break;
    }
    print(prime[i]*mul);
    mul = 1;
    count++;
    var res = readline();
    if(res === "yes"){
        if (factorIndex.length === 0) {
            factorIndex[0] = i;
            if (prime[i+1]*prime[i] <= 100) {
                mul = prime[i];
                i--;
            }
        } else if(factorIndex.length === 1) {
            factorIndex[1] = i;
            isPrime = false;
            break;
        }
    }
}

if (isPrime) {
    print("prime");
} else {
    print("composite");
}

var prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
var factorIndex = [];
var count = 0;
var mul = 1;
var isPrime = true;
for (var i = 0; i < prime.length; i++) {
    if(count === 20){
        break;
    }
    print(prime[i]*mul);
    mul = 1;
    count++;
    var res = readline();
    if(res === "yes"){
        if (factorIndex.length === 0) {
            factorIndex[0] = i;
            mul = prime[i];
            i--;
        } else if(factorIndex.length === 1) {
            factorIndex[1] = i;
            isPrime = false;
            break;
        }
    }
}

if (isPrime) {
    print("prime");
} else {
    print("composite");
}

var prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
var factorIndex = [];
var count = 0;
var mul = 1;
var isPrime = true;
for (var i = 0; i < prime.length; i++) {
    if(count === 20){
        break;
    }
    if (factorIndex.length === 1 && prime[i]*factorIndex[0] > 100) {
        break;
    }
    print(prime[i]*mul);
    mul = 1;
    count++;
    var res = readline();
    if(res === "yes"){
        if (factorIndex.length === 0) {
            factorIndex[0] = i;
            mul = prime[i];
            i--;
        } else if(factorIndex.length === 1) {
            factorIndex[1] = i;
            isPrime = false;
            break;
        }
    }
}

if (isPrime) {
    print("prime");
} else {
    print("composite");
}

var prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97];
var factorIndex = [];
var count = 0;
var mul = 1;
var isPrime = true;
for (var i = 0; i < prime.length; i++) {
    if(count === 20){
        break;
    }
    if (factorIndex.length === 1 && prime[i]*factorIndex[0] > 100) {
        break;
    }
    print(prime[i]*mul);
    mul = 1;
    count++;
    var res = readline();
    if(res === "yes"){
        if (factorIndex.length === 0) {
            factorIndex[0] = i;
            if (prime[i+1]*prime[i] <= 100) {
                mul = prime[i];
            }
            i--;
        } else if(factorIndex.length === 1) {
            factorIndex[1] = i;
            isPrime = false;
            break;
        }
    }
}

if (isPrime) {
    print("prime");
} else {
    print("composite");
}


Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.

The first line contains an integer n (1 ≤ n ≤ 100). Then n lines follow containing the description of the checkerboard. Each of them contains n characters (either 'x' or 'o') without spaces.

Print "YES" or "NO" (without the quotes) depending on the answer to the problem.

var n = +readline();
var array = [], check = true;

for(i = 0; i < n; i++){
	array.push(readline().split(""));
}

for(i = 0; i < n; i++){
	for(j = 0; j < n; j++){
		cnt = 0;
		if(array[i][j-1] == "o"){
			cnt++;
		}
		if(array[i][j+1] == "o"){
			cnt++;
		}
		if(array[i-1] != undefined && array[i-1][j] == "o"){
			cnt++;
		}
		if(array[i+1] != undefined && array[i+1][j] == "o"){
			cnt++;
		}

		if(cnt % 2 != 0){
			check = false;
		}
	}
}

if(check){
	write("YES");
}
else{
	write("NO");
}

var n = readline();
var map = [];

var i, j, x, y;

for (i = 0; i < n; i++) {
	map.push(readline());
}

var count;
var off = [
	[0, 1],
	[0, -1],
	[1, 0],
	[-1, 0]
];

var flag = true;

for (i = 0; i < n; i++) {
	for (j = 0; j < n; j++) {
		count = 0;
		for (k = 0; k < off.length; k++) {
			x = j + off[k][1];
			y = i + off[k][0];
			if (x >= 0 && y >= 0 && x < n && y < n)
				if (map[y].charAt(x) == 'o')
					count++;
		}
		if (count % 2 != 0) {
			flag = false;
			break;
		}
	}
}

write(flag?'YES':'NO');

var n = parseInt(readline());
var allEven = true;
var board = [];

for (var i = 0; i < n; i++) {
  board[i] = readline();
}

out: for (var i = 0; i < n; i++) {
  for (var j = 0; j < n; j++) {
    if (check(board, i, j) % 2 != 0) {
      allEven = false;
      break out;
    }
  }
}

if (allEven) {
  print("YES");
} else {
  print("NO");
}

function check(arr, i, j) {
  var rows = arr.length;
  var cols = arr[0].length;
  var countOfO = 0;

  if (i != 0) {
    if (arr[i - 1][j] =='o') {
      countOfO++;
    }
  }

  if (i != rows - 1) {
    if (arr[i + 1][j] =='o') {
      countOfO++;
    }
  }

  if (j != 0) {
    if (arr[i][j - 1] =='o') {
      countOfO++;
    }
  }

  if (j != cols - 1) {
    if (arr[i][j + 1] =='o') {
      countOfO++;
    }
  }

  return countOfO;
}

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], 10);
	};
	return tokens;
}

function main() {
	var n = parseInt(readline()),
		board = [];
	for (var i = 0; i < n; ++i) {
		var line = trim(readline());
		board.push([]);
		for (var j = 0; j < n; ++j) {
			board[i].push(line.charAt(j));
		}
	}
	var di = [-1, 0, 1, 0], dj = [0, 1, 0, -1];
	for (var i = 0; i < n; ++i) {
		for (var j = 0; j < n; ++j) {
			var count = 0;
			for (var k = 0; k < 4; ++k) {
				var I = i+di[k], J = j+dj[k];
				if (I < 0 || I == n || J < 0 || J == n) {
					continue;
				}
				if (board[I][J] == 'o') {
					++count;
				}
			}
			if (count%2 == 1) {
				print('NO');
				return;
			}
		}
	}
	print('YES');
}

main();

var lineNumber = readline();
var lines = [];
for(var i=0; i<lineNumber; i++){
    var  line = readline();
    lines.push(line);
}

(function(){
    for(var i=0; i<lineNumber; i++){
        var line = lines[i];
        for(var j=0, jLength=line.length; j<jLength; j++){
            var oNum = 0;
            var cell = line[j];
            var left = line[j-1];
            var right = line[j+1];
            var top = lines[i-1] ? lines[i-1][j] : false;
            var bottom = lines[i+1] ? lines[i+1][j] : false ;

            if(left && left=='o') oNum++;
            if(right && right=='o') oNum++;
            if(top && top=='o') oNum++;
            if(bottom && bottom=='o') oNum++;

            if(oNum%2 != 0){
                print('NO');
                return;
            }

        }
    }

    print('YES');
})();

var n = parseInt(readline());
var arr = [];
for (var i=0; i<n; i++) {
arr.push(readline().trim().toLowerCase().split(""));
}

var even = true;
var c;
for (var i=0; i<n; i++) {
for (var j=0; j<n; j++) {
c = 0;
if (i>0 && arr[i-1][j]=="o") c++;
if (i<n-1 && arr[i+1][j]=="o") c++;
if (j>0 && arr[i][j-1]=="o") c++;
if (j<n-1 && arr[i][j+1]=="o") c++;

if (c%2==1) even = false;
}
}

print(even?"YES":"NO");

var n = readline().replace(/\s{1,}/gi, ' ').split(/\s/).map(Number),
			board = [],
			result = true;

		for(var i=0; i<n; i++)	{
			board.push(readline().split(''));
		}

		for(var y=0; y<n; y++)	{
			var row = board[y],
				prevRow = board[y - 1] == undefined ? [] : board[y - 1],
				nextRow = board[y + 1] == undefined ? [] : board[y + 1];

			for(var x=0; x<n; x++)	{
				var ch = row[x];

				var tempArr = [ row[x - 1], row[x + 1], prevRow[x], nextRow[x] ];

				tempArr = tempArr.map(function(a)	{
					return a == 'o' ? 1 : 0;
				});

				if(tempArr.reduce(function(a, b) { return a + b; }) % 2 != 0)	{
					result = false;

					break;
				}
			}

			if(!result)	break;
		}

		print(result ? 'YES' : 'NO');

function gao()
{
    var offset = [[-1,0],[1,-0],[0,-1],[0,1]];

    var n = readline();
	var map = new Array();
	for( var i = 0; i < n; i++ )
	{
	    map[i] = readline().split("");
	}

	var result = 'YES';
	for(var i=0; i<n; i++)
	{
	    for(var j=0; j<n; j++)
		{
		    var num =0;
			for(var k in offset)
			{
			    if( typeof(map[ offset[k][0] + i ]) != 'undefined' &&
				    map[ offset[k][0] + i ][ offset[k][1] + j ] == "o")
				{
				    num++;
				}
			}
			if((num%2)==1)
			{
			    result = "NO";
			}

		}
	}
	print(result);
}

gao();

function gao()
{
    var offset = [[-1,1],[-1,-1],[1,-1],[1,1]];

    var n = readline();
	var map = new Array();
	for( var i = 0; i < n; i++ )
	{
	    map[i] = readline().split("");
	}

	var result = 'YES';
	for(var i=0; i<n; i++)
	{
	    for(var j=0; j<n; j++)
		{
		    var num =0;
			for(var k=0; k<4; k++)
			{
			    if( typeof(map[ offset[k][0] + i ]) != 'undefined' &&
				    map[ offset[k][0] + i ][ offset[k][1] + j ] == "o")
				{
				    num++;
				}
			}
			if((num%2)==1)
			{
			    result = "NO";
			}
		}
	}
	print(result);
}

gao();


You are given an array of positive integers $$$a_1, a_2, \ldots, a_n$$$.Make the product of all the numbers in the array (that is, $$$a_1 \cdot a_2 \cdot \ldots \cdot a_n$$$) divisible by $$$2^n$$$.You can perform the following operation as many times as you like:  select an arbitrary index $$$i$$$ ($$$1 \leq i \leq n$$$) and replace the value $$$a_i$$$ with $$$a_i=a_i \cdot i$$$. You cannot apply the operation repeatedly to a single index. In other words, all selected values of $$$i$$$ must be different.Find the smallest number of operations you need to perform to make the product of all the elements in the array divisible by $$$2^n$$$. Note that such a set of operations does not always exist.

The first line of the input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4$$$) — the number test cases. Then the descriptions of the input data sets follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains exactly $$$n$$$ integers: $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ values over all test cases in a test does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the least number of operations to make the product of all numbers in the array divisible by $$$2^n$$$. If the answer does not exist, print -1.

NoteIn the first test case, the product of all elements is initially $$$2$$$, so no operations needed.In the second test case, the product of elements initially equals $$$6$$$. We can apply the operation for $$$i = 2$$$, and then $$$a_2$$$ becomes $$$2\cdot2=4$$$, and the product of numbers becomes $$$3\cdot4=12$$$, and this product of numbers is divided by $$$2^n=2^2=4$$$. In the fourth test case, even if we apply all possible operations, we still cannot make the product of numbers divisible by $$$2^n$$$  — it will be $$$(13\cdot1)\cdot(17\cdot2)\cdot(1\cdot3)\cdot(1\cdot4)=5304$$$, which does not divide by $$$2^n=2^4=16$$$.In the fifth test case, we can apply operations for $$$i = 2$$$ and $$$i = 4$$$.

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

let lines = []

const createReadLine = () => {
  i = 0;
  return () => lines[i++]
}
const int = (num, radix=10) => parseInt(num, radix)

const countPower = (num) => {
  let pow = 0
  while (!(num & 1)) {
    num >>= 1;
    pow++;
  }
  return pow
}

rl.on('line', line => lines.push(line))

rl.on("close", () => {
  const readLine = createReadLine();
  let t = int(readLine());
  // let t = 1;
  while (t--) {
    const n = int(readLine());
    const arr = readLine().split(' ').map(a => int(a));

    let pow = 0;
    for (let i = 0; i < n; i++) {
      pow += countPower(arr[i]);
    }
    let ans = 0;
    if (pow < n) {
      let powArr = [];
      for (let i = 1; i <= n; i++) {
        powArr.push(countPower(i));
      }
      powArr.sort((a, b) => b - a);

      for (let i = 0; i < n; i++) {
        pow += powArr[i]
        ans++;
        if (pow >= n) break;
      }
    }

    console.log((pow >= n) ? ans : -1);
  }
});

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

function solve(n, arr) {
    let k = 0
    const ps = Array(n)
    for (let i = 0; i < arr.length; i++) {
        let x = arr[i]
        while (!(x & 1)) {
            x /= 2
            k++
        }
        //
        x = i + 1
        ps[i] = 0
        while (!(x & 1)) {
            x /= 2
            ps[i]++
        }
    }
    ps.sort((a, b) => a - b)
// console.log(k, ps)
    let i = n - 1
    let r = 0
    while (k < n && i >= 0 && ps[i] > 0) {
        const x = ps[i]
        // if (x) {
            k += x
            r++
        // }
        i--
    }
    if (k < n) return -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);
const rl = readline;

/*---------------------------------------------------*/

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

const sumab = (a, b) => {
    if (a > b) return 0;
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return x * y;
}

let fact2 = (a) => {
    let cnt = 0;
    while (a % 2 === 0) {
        cnt++;
        a /= 2;
    }
    return cnt;
}

const NN = 200005;
let twos = new Array(NN).fill(0);
for (let i = 0; i < NN; i++) {
    twos[i] = fact2(i + 1);
}

const calc = (t)=>{
    /* read */
    let n = +rl();
    let a = ra();

    let sum2 = 0;
    let potential2 = [];
    let potentialsum = 0;
    let moves = 0;
    for (let i = 0; i < n; i++) {
        if (a[i] < NN) {
            sum2 += twos[a[i] - 1];
        } else {
            sum2 += fact2(a[i]);
        }
        potential2.push(twos[i]);
        potentialsum += twos[i];
    }
    if (sum2 >= n) return 0;
    if (sum2 + potentialsum < n) return -1;

    potential2.sort((a, b) => b - a);
    let cursum = 0;
    for (let i = 0; i < n; i++) {
        cursum += potential2[i];
        if (sum2 + cursum >= n) return i + 1;
    }
    return -1;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        // calc(t);
        out.push(calc(t));
        // process.stdout.write(`${calc(t)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let z=0;
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[++z]);
        let a=line[++z].split(' ').map(x=>{return parseInt(x)});
        let ans=0;
        let cnt=0;
        for(let i=0;i<n;i++)
        {
            let x=a[i];
            while(x%2==0)
            {
                x/=2;
                cnt++;
            }
        }
        if(cnt>=n) console.log(0);
        else
        {
            let b=[];
            for(let i=1;i<=n;i++)
            {
                let c=0;
                let x=i;
                while(x%2==0)
                {
                    x/=2;
                    c++;
                }
                b.push(c);
            }
            b.sort(function(a,b){
                return b-a;
            })
            for(let i=0;i<n;i++) {
                cnt+=b[i];
                ans++;
                if(cnt>=n) break;
            }
            if(cnt>=n) console.log(ans);
            else console.log(-1);
        }
    }
})

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    let k = n;
    for (let i = 0; i < n; i++) {
      while (arr[i] % 2 === 0) {
        k--;
        arr[i] = arr[i] / 2;
      }
    }
    if (k <= 0) console.log(0);
    else {
      const helper = () => {
        let j = [];
        for (let i = 1; i <= n; i++) {
          if (i % 2 === 0) {
            if (Math.log2(i) % 1 === 0) j.push(Math.log2(i));
            else {
              let cnt = 0,
                l = i;
              while (l % 2 === 0) {
                cnt++;
                l = l / 2;
              }
              j.push(cnt);
            }
          }
        }
        j.sort((a, b) => b - a);
        for (let i = 0; i < j.length; i++) {
          k = k - j[i];
          if (k <= 0) return i + 1;
        }
        return -1;
      };
      console.log(helper());
    }
  }
};
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);

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  let t = n;
  for (let i = 0; i < n; i++) {
    let ans = 0,
        num = a[i];
    while (num % 2 === 0) {
      ans++;
      num /= 2;
    }
    t -= ans;
  }
  if (t <= 0) return 0;
  let nums = [];
  for (let i = n; i; i--) {
    let ans = 0,
        num = i;
    while (num % 2 === 0) {
      ans++;
      num /= 2;
    }
    if (ans) nums.push(ans);
  }
  nums.sort((a, b) => b - a);
  for (let i = 0; i < n; i++) {
    t -= nums[i];
    if (t <= 0) return i + 1;
  }
  return -1;
}
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++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      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);
}();

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

function solve(n, arr) {
    let k = 0
    for (let i = 0; i < arr.length; i++) {
        let x = arr[i]
        while (!(x & 1)) {
            x /= 2
            k++
        }
    }
    let m = Math.floor(Math.log2(n))
    let r = 0
    while (k < n && m > 0) {
        k += m--
        r++
    }
    if (k < n) return -1
    return r
}


Egor has a table of size $$$n \times m$$$, with lines numbered from $$$1$$$ to $$$n$$$ and columns numbered from $$$1$$$ to $$$m$$$. Each cell has a color that can be presented as an integer from $$$1$$$ to $$$10^5$$$.Let us denote the cell that lies in the intersection of the $$$r$$$-th row and the $$$c$$$-th column as $$$(r, c)$$$. We define the manhattan distance between two cells $$$(r_1, c_1)$$$ and $$$(r_2, c_2)$$$ as the length of a shortest path between them where each consecutive cells in the path must have a common side. The path can go through cells of any color. For example, in the table $$$3 \times 4$$$ the manhattan distance between $$$(1, 2)$$$ and $$$(3, 3)$$$ is $$$3$$$, one of the shortest paths is the following: $$$(1, 2) \to (2, 2) \to (2, 3) \to (3, 3)$$$. Egor decided to calculate the sum of manhattan distances between each pair of cells of the same color. Help him to calculate this sum.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \le m$$$, $$$n \cdot m \leq 100\,000$$$) — number of rows and columns in the table. Each of next $$$n$$$ lines describes a row of the table. The $$$i$$$-th line contains $$$m$$$ integers $$$c_{i1}, c_{i2}, \ldots, c_{im}$$$ ($$$1 \le c_{ij} \le 100\,000$$$) — colors of cells in the $$$i$$$-th row.

Print one integer — the the sum of manhattan distances between each pair of cells of the same color.

NoteIn the first sample there are three pairs of cells of same color: in cells $$$(1, 1)$$$ and $$$(2, 3)$$$, in cells $$$(1, 2)$$$ and $$$(2, 2)$$$, in cells $$$(1, 3)$$$ and $$$(2, 1)$$$. The manhattan distances between them are $$$3$$$, $$$1$$$ and $$$3$$$, the sum is $$$7$$$.

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 1e5 + 5;
const mxP = 1e5 + 5;
const pos = Array.from(Array(2 * mxP), x => []);

function main () {
	const [n, m] = rna();

	for (let i = 0; i < n; i++) {
		for (const [j, c] of rna().entries()) {
			pos[2 * c + 0].push(i);
			pos[2 * c + 1].push(j);
		}
	}

	let ans = 0;
	for (const v of pos) {
		v.sort((x, y) => x - y);
		for (let i = 0, sum = 0; i < v.length - 1; i++) {
			sum += (i + 1) * (v[i + 1] - v[i]);
			ans += sum;
		}
	}

	console.log(ans);
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

const mxN = 1e5+5;
const sum = Array(mxN).fill(0);
const cnt = Array(mxN).fill(0);
const pos = Array(mxN).fill(0);

function main () {
	const [n, m] = rna();
	const a = [];
	for (let i = 0; i < n; i++) a[i] = rna();

	let ans = 0;
	for (let i = 0; i < n; i++) {
		for (let j = 0; j < m; j++) {
			const curCol = a[i][j];
			sum[curCol] += cnt[curCol] * (i - pos[curCol]);
			cnt[curCol]++;
			pos[curCol] = i;
			ans += sum[curCol];
		}
	}

	for (let i = 0; i < mxN; i++) sum[i] = cnt[i] = pos[i] = 0;

	for (let j = 0; j < m; j++) {
		for (let i = 0; i < n; i++) {
			const curCol = a[i][j];
			sum[curCol] += cnt[curCol] * (j - pos[curCol]);
			cnt[curCol]++;
			pos[curCol] = j;
			ans += sum[curCol];
		}
	}

	console.log(ans);
}


You have a knapsack with the capacity of $$$W$$$. There are also $$$n$$$ items, the $$$i$$$-th one has weight $$$w_i$$$. You want to put some of these items into the knapsack in such a way that their total weight $$$C$$$ is at least half of its size, but (obviously) does not exceed it. Formally, $$$C$$$ should satisfy: $$$\lceil \frac{W}{2}\rceil \le C \le W$$$. Output the list of items you will put into the knapsack or determine that fulfilling the conditions is impossible. If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights of items in the knapsack.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains integers $$$n$$$ and $$$W$$$ ($$$1 \le n \le 200\,000$$$, $$$1\le W \le 10^{18}$$$).  The second line of each test case contains $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \le w_i \le 10^9$$$) — weights of the items. The sum of $$$n$$$ over all test cases does not exceed $$$200\,000$$$.

For each test case, if there is no solution, print a single integer $$$-1$$$.  If there exists a solution consisting of $$$m$$$ items, print $$$m$$$ in the first line of the output and $$$m$$$ integers $$$j_1$$$, $$$j_2$$$, ..., $$$j_m$$$ ($$$1 \le j_i \le n$$$, all $$$j_i$$$ are distinct) in the second line of the output  — indices of the items you would like to pack into the knapsack. If there are several possible lists of items satisfying the conditions, you can output any. Note that you don't have to maximize the sum of weights items in the knapsack.

NoteIn the first test case, you can take the item of weight $$$3$$$ and fill the knapsack just right.In the second test case, all the items are larger than the knapsack's capacity. Therefore, the answer is $$$-1$$$.In the third test case, you fill the knapsack exactly in half.

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => b[0] - a[0]);

    if (arr[arr.length - 1][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (value <= target) {
          count += value;
          result.push(index);
        }

        if (count >= Math.ceil(target / 2)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (value <= target) {
          count += value;
          result.push(index);
        }

        if (count >= Math.ceil(target / 2)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        count += value;
        if (count <= target) result.push(index);

        if (count > target || (count >= Math.ceil(target / 2) && count <= target)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(BigInt);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = BigInt(n);
        return [n, index + 1];
      });
    const result = [];
    arr.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));

    let count = 0n;
    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (count + value <= target) {
          count += value;
          result.push(index);
        }
      }
    }
    if (count >= (target + 1n) / 2n && count <= target) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    let count = 0;
    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (count + value <= target) {
          count += value;
          result.push(index);
        }
      }
    }
    if (count >= Math.ceil(target / 2) && count <= target) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        count += value;
        if (count <= target) result.push(index);

        if (count >= Math.ceil(target / 2)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        count += value;
        if (count <= target) result.push(index);

        if (count > target || count >= Math.ceil(target / 2)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    let count = 0;
    if (!arr.length || arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (count + value <= target) {
          count += value;
          result.push(index);
        }
      }
    }
    if (count >= Math.ceil(target / 2) && count <= target) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    let count = 0;
    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (count + value <= target) {
          count += value;
          result.push(index);
        }
      }
    }
    if (result.length && count >= Math.ceil(target / 2)) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        if (count + value <= target) {
          count += value;
          result.push(index);
        }

        if (count >= Math.ceil(target / 2)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}

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

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const [len, target] = readLine().split(" ").map(Number);
    const arr = readLine()
      .split(" ")
      .map((n, index) => {
        n = parseInt(n);
        return [n, index + 1];
      });
    let found = false;
    const result = [];
    arr.sort((a, b) => a[0] - b[0]);

    if (arr[0][0] > target) {
      console.log(-1);
      continue;
    } else {
      let count = 0;
      for (let i = 0; i < len; i++) {
        const [value, index] = arr[i];
        count += value;
        if (count <= target) result.push(index);
        else count -= value;

        if (count >= Math.ceil(target / 2)) {
          found = true;
          break;
        }
      }
    }
    if (found) {
      console.log(result.length);
      console.log(result.join(" "));
    } else console.log(-1);
  }
}


A permutation p is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p1,   p2,   ...,   pn.Simon has a positive integer n and a non-negative integer k, such that 2k ≤ n. Help him find permutation a of length 2n, such that it meets this equation: .

The first line contains two integers n and k (1 ≤ n ≤ 50000, 0 ≤ 2k ≤ n).

Print 2n integers a1, a2, ..., a2n — the required permutation a. It is guaranteed that the solution exists. If there are multiple solutions, you can print any of them.

NoteRecord |x| represents the absolute value of number x. In the first sample |1 - 2| - |1 - 2| = 0.In the second sample |3 - 2| + |1 - 4| - |3 - 2 + 1 - 4| = 1 + 3 - 2 = 2.In the third sample |2 - 7| + |4 - 6| + |1 - 3| + |5 - 8| - |2 - 7 + 4 - 6 + 1 - 3 + 5 - 8| = 12 - 12 = 0.

print(function(n, k) {
	var i, ans = [];
	for (i = 1; i <= n * 2; i++) {
		ans.push(i);
	}

	if (k > 0) {
		ans[0] = k + 1;
		ans[1] = 1;
		if (k > 1) {
			if ((k + 1) % 2) {
				ans[k] = 2;
			} else {
				ans[k] = ans[k - 1];
				ans[k - 1] = 2;
			}
		}
	}

	return ans.join(' ');

}.apply(0, readline().split(' ').map(Number)));

print(function(n, k) {
	var ans = [];

	for (var i = 1, c = 0; i <= n * 2; i += 2, c++) {
		if (c < k) {
			ans.push(i + 1);
			ans.push(i);
		} else {
			ans.push(i);
			ans.push(i + 1);
		}
	}

	return ans.join(' ');

}.apply(0, readline().split(' ').map(Number)));

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], k = integers[1];
	var m = 2*n;
	var perm = [];
	for (var i = 1; i <= k; ++i) {
		perm.push(2*i);
		perm.push(2*i-1);
	}
	for ( ; i <= n; ++i) {
		perm.push(2*i-1);
		perm.push(2*i);
	}
	print(perm.join(" "));
}

main();