A sequence of positive integers is called great for a positive integer $$$x$$$, if we can split it into pairs in such a way that in each pair the first number multiplied by $$$x$$$ is equal to the second number. More formally, a sequence $$$a$$$ of size $$$n$$$ is great for a positive integer $$$x$$$, if $$$n$$$ is even and there exists a permutation $$$p$$$ of size $$$n$$$, such that for each $$$i$$$ ($$$1 \le i \le \frac{n}{2}$$$) $$$a_{p_{2i-1}} \cdot x = a_{p_{2i}}$$$. Sam has a sequence $$$a$$$ and a positive integer $$$x$$$. Help him to make the sequence great: find the minimum possible number of positive integers that should be added to the sequence $$$a$$$ to make it great for the number $$$x$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 20\,000$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$2 \le x \le 10^6$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print a single integer — the minimum number of integers that can be added to the end of $$$a$$$ to make it a great sequence for the number $$$x$$$.

NoteIn the first test case, Sam got lucky and the sequence is already great for the number $$$4$$$ because you can divide it into such pairs: $$$(1, 4)$$$, $$$(4, 16)$$$. Thus we can add $$$0$$$ numbers.In the second test case, you can add numbers $$$1$$$ and $$$14$$$ to the sequence, then you can divide all $$$8$$$ integers into such pairs: $$$(1, 2)$$$, $$$(1, 2)$$$, $$$(2, 4)$$$, $$$(7, 14)$$$. It is impossible to add less than $$$2$$$ integers to fix the sequence.

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline();
for(var q=1;q<=T;q++) {
   var [n, x] = readline().split(' ').map(w => parseInt(w));
   var a = readline().split(' ').map(w => parseInt(w));
   var cnt = [];
   a.sort(function(ar, br) { return ar-br })
   var ans = 0;
   var j = 1;
   for(var i=0;i<n && j<n;i++) {
       if(cnt[i] !== undefined) continue;
       while(a[j] <= x*a[i]) {
           if(a[j] == x*a[i]) {
               //console.log(a[i],a[j])
               cnt[j]=true;
               ans++;
               j++;
               break;
           }
           j++;
       }
       //console.log(i,j)
   }
   console.log(n-(2*ans));
}

'use strict';
const { throws } = require('assert');

 /*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 MOD = 1e9+7;

const calc = (n, x, arr)=>{
  let cnt = new Map();
  for (let a of arr)
    cnt.set(a, (cnt.get(a)||0) + 1);
    arr.sort((a, b)=>a-b)
  for (let a of arr){
    if (!cnt.get(a)) continue;
    if (a%x==0){
      let candidate = a/x;
      if (cnt.get(candidate)>0){
        cnt.set(candidate, cnt.get(candidate)-1);
        cnt.set(a, cnt.get(a)-1);
        continue;
      }
    }
    let candidate = a*x;
    if (cnt.get(candidate)>0){
      cnt.set(candidate, cnt.get(candidate)-1);
      cnt.set(a, cnt.get(a)-1);
      continue;
    }
  }
  l(cnt)
  let ans = 0;
  for (let [k, v] of cnt){
    ans += v;
  }
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n, x] = ra();
      let arr = ra();
      l('ans')
      print(calc(n, x, arr));
    }
}

E.calc = calc;

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var X = nextInt();
		var list = nextIntArray(N);
		var map = getCountMap(list);
		var keys = Object.keys(map);
		keys.sort(function(a,b){
			return b - a;
		});
		for(var i = 0; i < keys.length; i++){
			var L = keys[i];
			var V = map[L];
			if(V > 0 && L % X == 0){
				var R = L / X;
				if(map[R] != null && map[R] > 0){
					V = Math.min(V, map[R]);
					map[L] -= V;
					map[R] -= V;
				}
			}
		}
		var output = 0;
		for(var i = 0; i < keys.length; i++){
			output += map[keys[i]];
		}
		myout(output);
	}
}

'use strict';

function solve(n, m, a) {
  const map = new Map();
  for (let num of a) {
    var _map$get;
    map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  const keys = [...map.keys()].sort((a, b) => a - b);
  for (let key of keys) {
    const x = map.get(key);
    if (x) {
      const y = map.get(key * m);
      if (y) {
        const min = Math.min(x, y);
        map.set(key, map.get(key) - min);
        map.set(key * m, map.get(key * m) - min);
      }
    }
  }
  let res = 0;
  for (let [i, count] of map) {
    res += count;
  }
  return res;
}

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

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

"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] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
    arr.sort((a,b)=>a-b);
    let obj = {};
    for(let i=0;i<n;i++){
      if(obj[arr[i]]) obj[arr[i]]++;
      else obj[arr[i]] = 1;
    }
    let cnt = 0;
    for(let i=0;i<n;i++){
      if(obj[arr[i]]){
        if(obj[arr[i]*x]) obj[arr[i]*x]--;
        else cnt++;
        obj[arr[i]]--;
      }
    }
    console.log(cnt);
};
}
solve();

let inputText = "";

process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (input) => (inputText += input));
process.stdin.on("end", async () => {
  let inputIterator = inputText.split("\n").values();

  let testCases = Number(inputIterator.next().value);
  while (testCases > 0) {
    testCases -= 1;

    const [n, x] = inputIterator
      .next()
      .value.split(" ")
      .map((i) => Number(i));

    let arr = inputIterator
      .next()
      .value.split(" ")
      .map((i) => Number(i));
    arr.sort((x, y) => x - y);

    const used = Array(n).fill(false);
    let ans = 0;
    let j = n - 1;

    for (let i = n - 1; i >= 0; i--) {
      if (used[i]) continue;
      if (arr[i] % x === 0) {
        let f = arr[i] / x;
        while (j >= 0 && (used[j] || arr[j] > f)) {
          j -= 1;
        }
        if (j >= 0 && !used[j] && arr[j] === f) {
          used[i] = true;
          used[j] = true;
          ans += 1;
        }
      }
    }

    console.log(n - 2 * 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;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

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

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

		let ans = n;
		const mp = new Map();
		for (let i = 0; i < n; i++) {
			if (mp.get(a[i]/x) > 0) {
				ans -= 2;
				mp.set(a[i]/x, mp.get(a[i]/x) - 1);
			} else {
				mp.set(a[i], (mp.get(a[i]) || 0) + 1);
			}
		}

		console.log(ans);
	}
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline()
for(var q=1;q<=T;q++) {
       let [n, x] = readline().split(" ").map(w => parseInt(w));
       let a = readline().split(" ").map(w => parseInt(w));
       var cnt = [];
       a.sort(function(ar,br) { return ar-br });
       var max = -1000;
       var ans = n;
       for(var i=0;i<n;i++) max = Math.max(max, a[i])
       for(var i=1;i<=max;i++) cnt[i]=0;
       for(var i=0;i<n;i++) {
           cnt[a[i]]++;
           var r = a[i]/x;
           if(cnt[r] !== undefined) {
               if(cnt[r] > 0) {
                   ans -= 2;
                   cnt[r]--;
               }
           }
       }
       console.log(ans);

}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}
var T = readline()
for(var q=1;q<=T;q++) {
       let [n, x] = readline().split(" ").map(w => parseInt(w));
       let a = readline().split(" ").map(w => parseInt(w));
       var cnt = [];
       var max = -1000;
       var ans = n;
       for(var i=0;i<n;i++) max = Math.max(max, a[i])
       for(var i=1;i<=max;i++) cnt[i]=0;
       for(var i=0;i<n;i++) {
           cnt[a[i]]++;
           var r = a[i]/x;
           if(cnt[r] !== undefined) {
               if(cnt[r] > 0) {
                   ans -= 2;
                   cnt[r]--;
               }
           }
       }
       console.log(ans);

}

'use strict';
const { throws } = require('assert');

 /*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 MOD = 1e9+7;

const calc = (n, x, arr)=>{
  let cnt = new Map();
  for (let a of arr)
    cnt.set(a, (cnt.get(a)||0) + 1);
  for (let a of arr){
    if (!cnt.get(a)) continue;
    if (a%x==0){
      let candidate = a/x;
      if (cnt.get(candidate)>0){
        cnt.set(candidate, cnt.get(candidate)-1);
        cnt.set(a, cnt.get(a)-1);
        continue;
      }
    }
    let candidate = a*x;
    if (cnt.get(candidate)>0){
      cnt.set(candidate, cnt.get(candidate)-1);
      cnt.set(a, cnt.get(a)-1);
      continue;
    }
  }
  let ans = 0;
  for (let [k, v] of cnt){
    ans += v;
  }
  return ans;
};

function main() {
    let T = +readline()
    while (T--){
      let [n, x] = ra();
      let arr = ra();
      l('ans')
      print(calc(n, x, arr));
    }
}

E.calc = calc;

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var X = nextInt();
		var list = nextIntArray(N);
		var map = getCountMap(list);
		var keys = Object.keys(map);
		keys.sort(function(a,b){
			return b - a;
		});
		for(var i = 0; i < keys.length; i++){
			var L = keys[i];
			if(map[L] > 0 && L % X == 0){
				var R = L / X;
				if(map[R] != null && map[R] > 0){
					map[L]--;
					map[R]--;
				}
			}
		}
		var output = 0;
		for(var i = 0; i < keys.length; i++){
			output += map[keys[i]];
		}
		myout(output);
	}
}


Vasya trains to compose crossword puzzles. He can only compose crosswords of a very simplе type so far. All of them consist of exactly six words; the words can be read only from top to bottom vertically and from the left to the right horizontally. The words are arranged in the form of a rectangular "eight" or infinity sign, not necessarily symmetrical.The top-left corner of the crossword coincides with the top-left corner of the rectangle. The same thing is correct for the right-bottom corners. The crossword can't degrade, i.e. it always has exactly four blank areas, two of which are surrounded by letters. Look into the output for the samples for clarification.Help Vasya — compose a crossword of the described type using the given six words. It is allowed to use the words in any order.

Six lines contain the given words. Every word consists of no more than 30 and no less than 3 uppercase Latin letters.

If it is impossible to solve the problem, print Impossible. Otherwise, print the sought crossword. All the empty squares should be marked as dots. If there can be several solutions to that problem, print the lexicographically minimum one. I.e. the solution where the first line is less than the first line of other solutions should be printed. If the two lines are equal, compare the second lines and so on. The lexicographical comparison of lines is realized by the < operator in the modern programming languages.

PTC
JYNYFDSGI
ZGPPC
IXEJNDOP
JJFS
SSXXQOFGJUZ

BAA...
U.I...
R.R...
NEWTON
..A..O
..YARD

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 words = [];
	for (var r = 0; r < 6; ++r) {
		words.push(trim(readline()));
	}

	var permutationLength = 6,
		used = new Array(permutationLength),
		permutation = new Array(permutationLength);

	function len(index) {
		return words[permutation[index]].length;
	}

	function wordChar(wordIndex, charIndex) {
		return words[permutation[wordIndex]].charAt(charIndex);
	}

	function fill(grid, index, r, c, dr, dc) {
		var word = words[permutation[index]];
		for (var pos = 0; pos < word.length; ++pos) {
			grid[r][c] = word.charAt(pos);
			r += dr;
			c += dc;
		}
	}

	var solutions = [];

	function test(permutation) {
		if (len(1) != len(5) + len(3) - 1 || len(4) != len(0) + len(2) - 1) {
			return;
		}

		var rules = [
			[1, len(5)-1, 4, len(0)-1],
			[0, len(0)-1, 1, 0],
			[1, len(1)-1, 2, 0],
			[2, len(2)-1, 3, len(3)-1],
			[3, 0, 4, len(4)-1],
			[4, 0, 5, len(5)-1],
			[5, 0, 0, 0]];

		for (var ruleIndex = 0; ruleIndex < rules.length; ++ruleIndex) {
			var rule = rules[ruleIndex];
			if (wordChar(rule[0], rule[1]) != wordChar(rule[2], rule[3])) {
				return;
			}
		}

		var rowNum = len(1), colNum = len(4),
			grid = new Array(rowNum);
		for (var r = 0; r < rowNum; ++r) {
			grid[r] = new Array(colNum);
			for (var c = 0; c < colNum; ++c) {
				grid[r][c] = '.';
			}
		}

		fill(grid, 0, 0, 0, 0, 1);
		fill(grid, 1, 0, len(0)-1, 1, 0);
		fill(grid, 2, len(1)-1, len(0)-1, 0, 1);
		fill(grid, 3, len(5)-1, len(4)-1, 1, 0);
		fill(grid, 4, len(5)-1, 0, 0, 1);
		fill(grid, 5, 0, 0, 1, 0);

		var parts = [];
		for (var r = 0; r < rowNum; ++r) {
			parts.push(grid[r].join(""));
		}
		solutions.push(parts.join("\n"));
	}

	function fillPermutation(position) {
		if (position == permutationLength) {
			test(permutation);
		}
		else {
			for (var index = 0; index < permutationLength; ++index) {
				if (!used[index]) {
					permutation[position] = index;
					used[index] = true;
					fillPermutation(position+1);
					used[index] = undefined;
				}
			}
		}
	}

	fillPermutation(0);

	if (solutions.length == 0) {
		print("Impossible");
	}
	else {
		solutions.sort();
		print(solutions[0]);
	}
}

main();


William has an array of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. In one move he can swap two neighboring items. Two items $$$a_i$$$ and $$$a_j$$$ are considered neighboring if the condition $$$|i - j| = 1$$$ is satisfied.William wants you to calculate the minimal number of swaps he would need to perform to make it so that the array does not contain two neighboring items with the same parity.

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 an integer $$$n$$$ $$$(1 \le n \le 10^5)$$$ which is the total number of items in William's array. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$ which are William's array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case output the minimal number of operations needed or $$$-1$$$ if it is impossible to get the array to a state when no neighboring numbers have the same parity.

NoteIn the first test case the following sequence of operations would satisfy the requirements:   swap(2, 3). Array after performing the operation: $$$[6, 1, 6]$$$ In the second test case the array initially does not contain two neighboring items of the same parity.In the third test case the following sequence of operations would satisfy the requirements:   swap(3, 4). Array after performing the operation: $$$[1, 1, 2, 1, 2, 2]$$$  swap(2, 3). Array after performing the operation: $$$[1, 2, 1, 1, 2, 2]$$$  swap(4, 5). Array after performing the operation: $$$[1, 2, 1, 2, 1, 2]$$$ In the fourth test case it is impossible to satisfy the requirements.In the fifth test case the following sequence of operations would satisfy the requirements:   swap(2, 3). Array after performing the operation: $$$[6, 3, 2, 4, 5, 1]$$$  swap(4, 5). Array after performing the operation: $$$[6, 3, 2, 5, 4, 1]$$$

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

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

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

		let ocnt = 0, ecnt;
		for (const elm of a) {
			ocnt += elm % 2;
		}
		ecnt = n - ocnt;

		//console.log({ocnt, ecnt});
		if (Math.abs(ocnt - ecnt) > 1) {
			console.log(-1);
			continue;
		}

		let ans = [0, 0];
		for (let start = 0; start < 2; start++) {
			for (let i = 0, pos = start; i < n; i++) {
				if (a[i]%2) {
					ans[start] += Math.abs(pos - i);
					pos += 2;
				}
			}
		}

		//console.log({ans})
		if (ocnt > ecnt)
			ans = ans[0];
		else if (ocnt < ecnt)
			ans = ans[1];
		else
			ans = Math.min(...ans);

		console.log(ans);
	}
}

'use strict'
var os = require('os')
function createInput(t) {
  const n = t.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let u = [],
    o = 0
  return {
    init: async function () {
      const t = []
      ;(u = await new Promise(e => {
        n.on('data', n => t.push(n)),
          n.on('end', function () {
            const n = t.join('').split(os.EOL)
            e(n)
          })
      })),
        (o = 0)
    },
    dried: function () {
      return o >= u.length
    },
    readLine: i,
    readLineAsNumber: function () {
      return Number(i())
    },
    readIntegersOfLine: function () {
      const t = i().match(e)
      return null == t ? [] : t.map(t => Number(t))
    },
    readNumsOfLine: function () {
      const t = i().match(r)
      return null == t ? [] : t.map(t => Number(t))
    },
  }
  function i() {
    return u[o++]
  }
}
function createOutput(t) {
  const n = t.stdout || process.stdout,
    e = t.encoding || 'ascii',
    r = t.outputBufferThreshold || 1 << 24,
    u = r >> 1,
    o = Buffer.alloc(r)
  let i = 0
  return {
    flush: s,
    print: function (t) {
      c('string' == typeof t ? t : t.toString())
    },
    println: function (t) {
      c(('string' == typeof t ? t : t.toString()).concat('\n'))
    },
  }
  function s() {
    n.write(o.toString(e, 0, i)), (i = 0)
  }
  function c(t) {
    const c = Buffer.byteLength(t, e)
    r - i < c && (s(), c > u) ? n.write(t) : (o.write(t, i, e), (i += c))
  }
}
function createInputAndOutput(t) {
  return {
    ...createInput({ stdin: t.stdin, encoding: t.encoding }),
    ...createOutput({
      stdout: t.stdout,
      encoding: t.encoding,
      outputBufferThreshold: t.outputBufferThreshold,
    }),
  }
}
async function __main__(t, n, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(n && n())]),
    await t(r),
    r.flush()
}
__main__(function (t) {
  const n = t.readLineAsNumber()
  for (let r = 1; r <= n; ++r) {
    const n = t.readLineAsNumber(),
      r = t.readIntegersOfLine(),
      u = e()
    function e() {
      const t = r.reduce((t, n) => t + (1 & n), 0),
        e = n - t
      if (Math.abs(t - e) > 1) return -1
      let u = Number.MAX_SAFE_INTEGER
      if (t >= e) {
        u = 0
        for (let t = 0, e = 0; t < n; t += 2, ++e) {
          for (; e < n && !(1 & r[e]); ++e);
          u += Math.abs(e - t)
        }
      }
      let o = Number.MAX_SAFE_INTEGER
      if (e >= t) {
        o = 0
        for (let t = 0, e = 0; t < n; t += 2, ++e) {
          for (; e < n && 0 != (1 & r[e]); ++e);
          o += Math.abs(e - t)
        }
      }
      return u < o ? u : o
    }
    t.println(u)
  }
})

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

const INF = 1e14;

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

		let ocnt = 0, ecnt;
		for (const elm of a) {
			ocnt += elm % 2;
		}
		ecnt = n - ocnt;

		if (Math.abs(ocnt - ecnt) > 1) {
			console.log(-1);
			continue;
		}

		let ans = [0, 0];
		for (let start = 0; start < 2; start++) {
			for (let i = 0, pos = start; i < n; i++) {
				if (a[i]%2) {
					if (pos >= n) {
						ans[start] = INF;
						break;
					}
					ans[start] += Math.abs(pos - i);
					pos += 2;
				}
			}
		}

		ans = Math.min(...ans);

		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--) {
		let n = rn();
		let a = rna();

		let ecnt = 0;
		for (const x of a) ecnt += x%2 == 0;

		const ocnt = n - ecnt;
		if (Math.abs(ecnt - ocnt) > 1) {
			console.log(-1); continue;
		}

		let ans = [0, 0];
		for (let k = 0; k < 2; k++) {
			b = a.slice();
			for (let i = 0, needevn = k, ep = op = 0; i < n; i++, needevn = !needevn) {
				while(ep < n && b[ep] % 2 != 0) ep++;
				while(op < n && b[op] % 2 != 1) op++;

				if(needevn != b[i]%2 == 0) {
					ans[k] += (needevn ? ep : op) - i;
					[b[ep], b[op]] = [b[op], b[ep]];
					ep++; op++;
				}
			}
		}

		if (ecnt == ocnt)
			ans = Math.min(ans[0], ans[1]);
		else
			ans = ecnt > ocnt ? ans[1] : ans[0];

		console.log(ans);
	}
}


Vladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn], where pi denotes the number of page that should be read i-th in turn.Sometimes Vladik’s mom sorted some subsegment of permutation P from position l to position r inclusive, because she loves the order. For every of such sorting Vladik knows number x — what index of page in permutation he should read. He is wondered if the page, which he will read after sorting, has changed. In other words, has px changed? After every sorting Vladik return permutation to initial state, so you can assume that each sorting is independent from each other.

First line contains two space-separated integers n, m (1 ≤ n, m ≤ 104) — length of permutation and number of times Vladik's mom sorted some subsegment of the book. Second line contains n space-separated integers p1, p2, ..., pn (1 ≤ pi ≤ n) — permutation P. Note that elements in permutation are distinct. Each of the next m lines contains three space-separated integers li, ri, xi (1 ≤ li ≤ xi ≤ ri ≤ n) — left and right borders of sorted subsegment in i-th sorting and position that is interesting to Vladik.

For each mom’s sorting on it’s own line print "Yes", if page which is interesting to Vladik hasn't changed, or "No" otherwise.

NoteExplanation of first test case:   [1, 2, 3, 4, 5] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".  [3, 4, 5, 2, 1] — permutation after sorting, 1-st element has changed, so answer is "No".  [5, 2, 3, 4, 1] — permutation after sorting, 3-rd element hasn’t changed, so answer is "Yes".  [5, 4, 3, 2, 1] — permutation after sorting, 4-th element hasn’t changed, so answer is "Yes".  [5, 1, 2, 3, 4] — permutation after sorting, 3-rd element has changed, so answer is "No".

a = readline().split(' ');
b = parseInt(a[0]);
c = parseInt(a[1]);
d = readline().split(' ');
l = new Array(b);
for(x = 0; x < b; x++)
{
     l[x] = parseInt(d[x]);
}
for(x = 1; x <= c; x++)
{
     e = readline().split(' ');
     f = parseInt(e[0]);
     g = parseInt(e[1]);
     h = parseInt(e[2]);
     i = l[h - 1];
     j = 0;
     k = h - f;
     for(y = f - 1; y <= g - 1; y++)
     {
          if(l[y] < i)
          {
               j++;
          }
     }
     if(j == k)
     {
          print('Yes');
     }
     else
     {
          print('No');
     }
}

var arr = readline().split(' ');
var n = parseInt(arr[0]);
var m = parseInt(arr[1]);
// var n = parseInt(readline());
var v = Array(n);
var arr = readline().split(' ');
for (var i = 0; i < n; i ++)
{
    v[i] = parseInt(arr[i]);
}
for (var i = 0; i < m; i ++)
{
    var arr = readline().split(' ');
    var l = parseInt(arr[0]);
    var r = parseInt(arr[1]);
    var t = parseInt(arr[2]);
    if (l<=t && t<=r)
    {
        var vs = v.slice(l-1,r);
        // vs.sort(function(a,b){return a-b;});
        var count = 0;
        for (var j = 0; j < r-l+1; j ++)
        {
            if (vs[j] < v[t-1])
            {
                count ++;
            }
        }
        // print(JSON.stringify(vs));
        print(t-l==count?"Yes":"No");
    }
    else
    {
        print("No");
    }
}

a = readline().split(' ');
b = parseInt(a[0]);
c = parseInt(a[1]);
d = readline().split(' ');
for(x = 1; x <= c; x++)
{
     e = readline().split(' ');
     f = parseInt(e[0]);
     g = parseInt(e[1]);
     h = parseInt(e[2]);
     i = d[h - 1];
     j = 0;
     k = h - f;
     for(y = f - 1; y <= g - 1; y++)
     {
          if(d[y] < i)
          {
               j++;
          }
     }
     if(j == k)
     {
          print('Yes');
     }
     else
     {
          print('No');
     }
}


Pak Chanek has $$$n$$$ two-dimensional slices of cheese. The $$$i$$$-th slice of cheese can be represented as a rectangle of dimensions $$$a_i \times b_i$$$. We want to arrange them on the two-dimensional plane such that:  Each edge of each cheese is parallel to either the x-axis or the y-axis.  The bottom edge of each cheese is a segment of the x-axis.  No two slices of cheese overlap, but their sides can touch.  They form one connected shape. Note that we can arrange them in any order (the leftmost slice of cheese is not necessarily the first slice of cheese). Also note that we can rotate each slice of cheese in any way as long as all conditions still hold.Find the minimum possible perimeter of the constructed shape.

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$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of slices of cheese Pak Chanek has. The $$$i$$$-th of the next $$$n$$$ lines of each test case contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \leq a_i,b_i \leq 10^9$$$) — the dimensions of the $$$i$$$-th slice of cheese. 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 minimum possible perimeter of the constructed shape.

NoteIn the first test case, a way of getting the minimum possible perimeter is to arrange the slices of cheese as follows.We can calculate that the perimeter of the constructed shape is $$$2+5+1+1+1+1+3+1+5+1+2+3=26$$$. It can be shown that we cannot get a smaller perimeter.Consider the following invalid arrangement.Even though the perimeter of the shape above is $$$24$$$, it does not satisfy all conditions of the problem. The bottom edge of the $$$1 \times 1$$$ slice of cheese is not a segment of the x-axis.In the second test case, a way of getting the minimum possible perimeter is to arrange the slices of cheese as follows.We can calculate that the perimeter of the constructed shape is $$$2+2+2+3+2+3+2+2+2+4=24$$$. It can be shown that we cannot get a smaller perimeter.

t = +readline();

while(t--) {
    n = +readline();

    a = [];
    b = [];

    while(n--) {
        side = readline().split(' ');

        a.push(+side[0]);
        b.push(+side[1]);
    }

    maxA = Math.max(...a);
    maxB = Math.max(...b);

    height = Math.max(maxA, maxB);

    width = a.reduce((prevVlue, currentValue, index)=>{
        minValue = Math.min(currentValue, b[index]);

        return prevVlue + minValue;
    }, 0);

    print(height*2 + width*2);
}

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 cnt=0;
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[++cnt]);
        let a=[],b=[];
        let ans=0;
        for(let i=1;i<=n;i++)
        {
            let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
            a.push([x,y]);
            b.push(x);
            b.push(y);
            ans+=2*(x+y);
        }
        let mx1=-1,mx2=-1,mx3=-1;
        for(let i=0;i<2*n;i++)
        {
            let x=b[i];
            if(x>mx1)
            {
                mx2=mx1;
                mx3=mx2;
                mx1=x;
            }
            else if(x>mx2)
            {
                mx3=mx2;
                mx2=x;
            }
            else if(x>mx3)
            {
                mx3=x;
            }
        }
        flag=true;
        for(let i=0;i<n;i++)
        {
            let x=Math.max(a[i][0],a[i][1]);
            let y=Math.min(a[i][0],a[i][1]);
            if(flag&&x===mx1)
            {
                flag=false;
                continue;
            }
            if(x<mx1) ans-=2*x;
            else if(y!=mx2) ans-=2*mx2;
            else if(n>1) ans-=2*mx3;
        }
        console.log(ans);
    }
})

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 cnt=0;
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[++cnt]);
        let a=[],b=[];
        let ans=0;
        for(let i=1;i<=n;i++)
        {
            let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
            a.push([x,y]);
            b.push(x);
            b.push(y);
            ans+=2*(x+y);
        }
        // console.log(a);
        // b.sort(function(x,y){
        //     return x-y;
        // });
        // console.log(b);
        let mx1=-1,mx2=-1,mx3=-1;
        for(let i=0;i<2*n;i++)
        {
            let x=b[i];
            if(x>mx1)
            {
                mx2=mx1;
                mx3=mx2;
                mx1=x;
            }
            else if(x>mx2)
            {
                mx3=mx2;
                mx2=x;
            }
            else if(x>mx3)
            {
                mx3=x;
            }
        }
        flag=true;
        for(let i=0;i<n;i++)
        {
            let x=Math.max(a[i][0],a[i][1]);
            let y=Math.min(a[i][0],a[i][1]);
            // let l=0,r=2*n-1;
            // while(l<r)
            // {
            //     let mid=Math.floor((l+r+1)/2);
            //     if(b[mid]>x) r=mid-1;
            //     else l=mid;
            // }
            // ans-=b[l-1];
            // console.log(b[l-1]);
            if(flag&&x===mx1)
            {
                flag=false;
                continue;
            }
            // console.log(ans);
            if(x<mx1) ans-=2*x;
            else if(y!=mx2) ans-=2*mx2;
            else if(n>1) ans-=2*mx3;
            // flag=false;
        }
        console.log(ans);
    }
})

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
    var n = readline();
    var maxY = -inf;
    var x = 0;
    for(var i=0;i<n;i++) {
        var [a,b] = readline().split(" ").map(w => parseInt(w));
        maxY = max(maxY, max(a,b));
        x += min(a,b);
    }
    console.log((2*maxY) + (2*x));
}

/*
* auther yeling
*
*
*/
'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
function print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n, nums) {
    nums = nums.map((value) => {
        let ret = [];
        if(value[0] < value[1]) {
            ret = value;
        } else {
            ret = [value[1], value[0]];
        }
        return ret;
    })
    //print(nums.join(' '));
    nums.sort((a,b) => {
        return a[1] - b[1];
    })
    //print(nums);
    let sum = 0;
    for(let i = 0; i < nums.length; i++) {
        if(i == 0 ) {
            sum += nums[i][1];
        }
        if(i == nums.length - 1) {
            sum += nums[i][1];
        }
        sum += 2 * nums[i][0];
        if(i > 0) {
            sum += nums[i][1] - nums[i-1][1];
        }
    }
    print(sum);
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        let nums = [];
        for(let j = 0; j < n; j++) {
            var x = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
            nums.push(x);
        }
        begin(n, nums);
    }
}

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)
        let sum = 0, max = 0;

        for (let i = 0; i < n; i++) {
            const a = parseInt(lines[line].split(' ')[0], 10)
            const b = parseInt(lines[line++].split(' ')[1], 10)
            sum += Math.min(a, b);
            if (max < Math.max(a, b))
                max = Math.max(a, b)
        }

        sum += max;
        console.log(sum * 2)

    }
}

'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();
  let res = 0,
      max = 0;
  for (let i = 0; i < n; i++) {
    let [x, y] = rns();
    if (x > y) [x, y] = [y, x];
    res += x;
    max = Math.max(max, y);
  }
  return (res + max) * 2;
}
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);
}();


A binary string is a string that consists of characters $$$0$$$ and $$$1$$$.Let $$$\operatorname{MEX}$$$ of a binary string be the smallest digit among $$$0$$$, $$$1$$$, or $$$2$$$ that does not occur in the string. For example, $$$\operatorname{MEX}$$$ of $$$001011$$$ is $$$2$$$, because $$$0$$$ and $$$1$$$ occur in the string at least once, $$$\operatorname{MEX}$$$ of $$$1111$$$ is $$$0$$$, because $$$0$$$ and $$$2$$$ do not occur in the string and $$$0 < 2$$$.A binary string $$$s$$$ is given. You should cut it into any number of substrings such that each character is in exactly one substring. It is possible to cut the string into a single substring — the whole string.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.What is the minimal sum of $$$\operatorname{MEX}$$$ of all substrings pieces can be?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. Each test case contains a single binary string $$$s$$$ ($$$1 \le |s| \le 10^5$$$). It's guaranteed that the sum of lengths of $$$s$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print a single integer — the minimal sum of $$$\operatorname{MEX}$$$ of all substrings that it is possible to get by cutting $$$s$$$ optimally.

NoteIn the first test case the minimal sum is $$$\operatorname{MEX}(0) + \operatorname{MEX}(1) = 1 + 0 = 1$$$.In the second test case the minimal sum is $$$\operatorname{MEX}(1111) = 0$$$.In the third test case the minimal sum is $$$\operatorname{MEX}(01100) = 2$$$.

'use strict';

function solve(s) {
  const n = s.length;
  const dp = new Array(n).fill(0);
  for (let i = 0; i < n; i++) {
    var _dp, _dp2;
    if (s[i] !== s[i - 1] && s[i] === '0') dp[i] = ((_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0) + 1;else dp[i] = (_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0;
  }
  return Math.min(2, dp[n - 1]);
}

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

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

'use strict';

function solve(s) {
  const n = s.length;
  const dp = new Array(n).fill(0);
  for (let i = 0; i < n; i++) {
    var _dp2, _dp3;
    if (s[i] === s[i - 1]) {
      var _dp;
      dp[i] = (_dp = dp[i - 1]) !== null && _dp !== void 0 ? _dp : 0;
      continue;
    }
    if (s[i] === '0') dp[i] = ((_dp2 = dp[i - 1]) !== null && _dp2 !== void 0 ? _dp2 : 0) + 1;else dp[i] = (_dp3 = dp[i - 1]) !== null && _dp3 !== void 0 ? _dp3 : 0;
  }
  return Math.min(2, dp[n - 1]);
}

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

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

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var res = solveMeFirst(b);
    // let out = "";
    // if (res) {
    //   for (let i = 0; i < res.length; i++) {
    //     out += res[i] + " ";
    //   }
    console.log(res);
    // }
  }
}
function solveMeFirst(str) {
  // console.log(str);
  let res,
    res2 = 0;
  if (str.includes("0") && str.includes("1")) res = 2;
  else if (str.includes("0")) res = 1;
  else res = 0;
  let isOne = false;
  for (let i = 0; i < str.length; i++) {
    if (str[i] == "0" && !isOne) {
      res2 += 1;
      isOne = true;
    }
    if (str[i] == "1" && isOne) {
      isOne = false;
    }
  }
  // console.log(res2, res);
  return res > res2 ? res2 : res;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = BigInt(next());
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var s = next().split("1");
		var count = 0;
		for(var i = 0; i < s.length; i++){
			if(s[i] != ''){
				count++;
			}
		}
		myout(Math.min(count, 2));
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
let standardInputString = '';
let curLine = 0;

const readLine = () => {
  return standardInputString[curLine++];
};

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

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

  main();
});

/**
 * 7
 * 0000
 * 1111
 * 0101
 * 110
 * 011
 * 1011
 * 1010
 */

// https://codeforces.com/contest/1566/problem/B
const main = () => {
    const t = +readLine();

    for (let _ = 0; _ < t; _ += 1) {
        const str = readLine();

        if (str === '1'.repeat(str.length)) {
            console.log(0);
        } else {
            const withoutOnes = str.replace(/^1+/, '').replace(/1+$/, '');

            if (withoutOnes === '0'.repeat(withoutOnes.length)) {
                console.log(1);
            } else {
                console.log(2);
            }
        }
    }
};

var n = parseInt(readline());

for (var i = 0; i < n; i++) {
    var s = readline();
    var z = s.charAt(0) === '0' ? 1 : 0;
    for (var j = 1; j < s.length; j++) {
        if (s.charAt(j) === '0' && s.charAt(j-1) === '1')
            z += 1;
    }

    print(Math.min(z, 2));
}

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

	function main() {
		var testCasesNum = +readline();
		for (var i = 0; i < testCasesNum; i++) {
			var count = 0;
			var hasOnes = true;
			var s = readline();
			for (var j = 0; j < s.length; j++) {
				if (s[j] === '0' && hasOnes) {
					hasOnes = false;
					count++;
					if (count === 2) {
						break;
					}
				}
				if (s[j] === '1') {
					hasOnes = true;
				}
			}
			print(count);
		}
	}

	main();

'use strict';

function solve(s) {
  const n = s.length
  const dp = new Array(n + 1).fill(0)
  for (let i = 1; i <= n; i++) {
    if (s[i - 1] === s[i - 2]) continue
    if (s[i - 1] === '1') dp[i] = dp[i - 1]
    else dp[i] = dp[i - 1] + 1
  }
  return Math.min(2, dp[n])
}

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

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

'use strict';

function solve(s) {
  const n = s.length
  const dp = new Array(n + 1).fill(0)
  for (let i = 1; i <= n; i++) {
    if (s[i - 1] === '1') dp[i] = dp[i - 1]
    else dp[i - 1] = dp[i - 1] + 1
  }
  return Math.min(2, dp[n])
}

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

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

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var res = solveMeFirst(b);
    // let out = "";
    // if (res) {
    //   for (let i = 0; i < res.length; i++) {
    //     out += res[i] + " ";
    //   }
    console.log(res);
    // }
  }
}
function solveMeFirst(str) {
  // console.log(str);
  let res,
    res2 = 0;
  if (str.includes("0") && str.includes("1")) res = 2;
  else if (str.includes("0")) res = 1;
  else res = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i] == "0") res2 += 1;
  }
  // console.log(res2);
  return res > res2 ? res2 : res;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", function (data) {
  input_stdin += data;
});

process.stdin.on("end", function () {
  input_stdin_array = input_stdin.split("\n");
  // console.log(input_stdin_array);
  main();
});

function readLine() {
  return input_stdin_array[input_currentline++];
}

function main() {
  var a = readLine();
  while (a--) {
    var b = readLine();
    var res = solveMeFirst(b);
    // let out = "";
    // if (res) {
    //   for (let i = 0; i < res.length; i++) {
    //     out += res[i] + " ";
    //   }
    console.log(res);
    // }
  }
}
function solveMeFirst(str) {
  console.log(str);
  let res,
    res2 = 0;
  if (str.includes("0") && str.includes("1")) res = 2;
  else if (str.includes("0")) res = 1;
  else res = 0;
  for (let i = 0; i < str.length; i++) {
    if (str[i] == "0") res2 += 1;
  }
  // console.log(res2);
  return res > res2 ? res2 : res;
}

// console.log(solveMeFirst(2, [2, 3, 2, 4, 1, 3, 4, 1]));
// console.log(timeConversion([100, 90, 90, 80], [70, 80, 105]));


You are given array ai of length n. You may consecutively apply two operations to this array:  remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins;  change some elements of the array by at most 1, and pay b coins for each change. Please note that each of operations may be applied at most once (and may be not applied at all) so you can remove only one segment and each number may be changed (increased or decreased) by at most 1. Also note, that you are not allowed to delete the whole array.Your goal is to calculate the minimum number of coins that you need to spend in order to make the greatest common divisor of the elements of the resulting array be greater than 1.

The first line of the input contains integers n, a and b (1 ≤ n ≤ 1 000 000, 0 ≤ a, b ≤ 109) — the length of the array, the cost of removing a single element in the first operation and the cost of changing an element, respectively. The second line contains n integers ai (2 ≤ ai ≤ 109) — elements of the array.

Print a single number — the minimum cost of changes needed to obtain an array, such that the greatest common divisor of all its elements is greater than 1.

NoteIn the first sample the optimal way is to remove number 3 and pay 1 coin for it.In the second sample you need to remove a segment [17, 13] and then decrease number 6. The cost of these changes is equal to 2·3 + 2 = 8 coins.

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function fact(v, primes) {
    for (var p = 2; p*p <= v; p++) {
        if (v % p ==0) {
            primes.push(p);
            while (v % p == 0) v /= p;
        }
    }
    if (v != 1) primes.push(v);
}

function sortNumber(a,b) {
    return a - b;
}

function onlyUnique(value, index, self) {
    return self.indexOf(value) === index;
}

var cand = new Array();
for (var d = -1; d <= 1; d++) {
    fact(arr[0]+d,cand);
    fact(arr[n-1]+d,cand);
}

cand = cand.filter(onlyUnique);
cand.sort(sortNumber);

var cost = [];
var rightcostsum = [];
var dp = [];
var result = Number.MAX_VALUE;
for (var p = 0; p < cand.length; p++) {
    for (var i = 0; i < n; i++) {
        if (arr[i] % cand[p] == 0) cost[i] = 0;
        else if ((arr[i]-1) % cand[p] == 0) cost[i] = p2;
        else if ((arr[i]+1) % cand[p] == 0) cost[i] = p2;
        else cost[i] = Number.MAX_VALUE;
    }

    rightcostsum[n-1] = cost[n-1];

    for (var i = n-2; i>=0; i--) {
        rightcostsum[i] = Math.min(Number.MAX_VALUE, rightcostsum[i+1] + cost[i]);
    }
    dp[n] = 0;
    for (var i = n-1; i >=  0; i--) {
        dp[i] = Math.min(p1 + dp[i+1], rightcostsum[i]);
    }
    result = Math.min(result, dp[0]);
    var leftcostsum = 0;
    for (var i = 0; i < n; i++) {
        leftcostsum = Math.min(Number.MAX_VALUE, leftcostsum + cost[i]);
        result = Math.min(result, leftcostsum + dp[i+1]);
    }

}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    if (y == 0) return 0;
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

var helper = []
result = Number.MAX_VALUE;
for (var i = 0; i < n; i++) {
    for (var j = i; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        print(helper, NOD(helper));
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
            break;
        }

        for (var k=0; k < helper.length; k++) {
            helper[k]--;
            if (NOD(helper) > 1) {
                result = Math.min((j-i) * p1 + p2, result);
                break;
            }
            helper[k]++;
        }
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

var helper = []
result = Number.MAX_VALUE;
for (var i = 0; i < n; i++) {
    for (var j = i + 1; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
        } else {
            for (var k=0; k < helper.length; k++) {
                helper[k]--;
                if (NOD(helper) > 1) {
                    result = Math.min((j-i) * p1 + p2, result);
                }
                helper[k]++;
            }
        }
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

result = Number.MAX_VALUE;

for (var k = 0; k < arr.length; k++) {
    arr[k]--;
    if (NOD(arr) > 1) {
        result = Math.min(p2, result);
        break;
    }
    arr[k]++;
}

var helper = []
for (var i = 0; i < n; i++) {
    for (var j = i + 1; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
        }

        for (var k=0; k < helper.length; k++) {
            helper[k]--;
            if (NOD(helper) > 1) {
                result = Math.min((j-i) * p1 + p2, result);
                break;
            }
            helper[k]++;
        }
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

var helper = []
result = Number.MAX_VALUE;
for (var i = 0; i < n; i++) {
    for (var j = i; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
            break;
        }

        for (var k=0; k < helper.length; k++) {
            helper[k]--;
            if (NOD(helper) > 1) {
                result = Math.min((j-i) * p1 + p2, result);
                break;
            }
            helper[k]++;
        }
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

result = Number.MAX_VALUE;

for (var k = 0; k < arr.length; k++) {
    arr[k]--;
    if (NOD(arr) > 1) {
        result = Math.min(p2, result);
        break;
    }
    arr[k]++;
}

var helper = []
for (var i = 0; i < n; i++) {
    for (var j = i + 1; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
        }

        for (var k=0; k < helper.length; k++) {
            helper[k]--;
            if (NOD(helper) > 1) {
                result = Math.min((j-i) * p1 + p2, result);
            }
            helper[k]++;
        }
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

result = Number.MAX_VALUE;

for (var k = 0; k < arr.length; k++) {
    arr[k]--;
    if (NOD(arr) > 1) {
        result = Math.min(p2, result);
        break;
    }
    arr[k]++;
}

var helper = []
for (var i = 0; i < n; i++) {
    for (var j = i + 1; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        print(helper);
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
        }

        for (var k=0; k < helper.length; k++) {
            helper[k]--;
            print(helper);
            if (NOD(helper) > 1) {
                result = Math.min((j-i) * p1 + p2, result);
            }
            helper[k]++;
        }
    }
}

print(result);

var data = readline().split(' ').map(Number);
var n = data[0],
    p1 = data[1],
    p2 = data[2];

var arr = readline().split(' ').map(Number);

function NOD ( arr ) {
  for ( var x = arr[ 0 ], i = 1; i < arr.length; i++ ) {
    var y = arr[ i ];
    if (y == 0) return 0;
    while ( x && y ) {
      x > y ? x %= y : y %= x;
    }
    x += y;
  }
  return x;
}

var helper = []
result = Number.MAX_VALUE;
for (var i = 0; i < n; i++) {
    for (var j = i; j < n + 1; j++) {
        helper = arr.slice();
        helper.splice(i, j-i);
        if (NOD(helper) > 1) {
            result = Math.min((j-i) * p1, result);
            break;
        }

        for (var k=0; k < helper.length; k++) {
            helper[k]--;
            if (NOD(helper) > 1) {
                result = Math.min((j-i) * p1 + p2, result);
                break;
            }
            helper[k]++;
        }
    }
}

print(result);


Today Pari and Arya are playing a game called Remainders.Pari chooses two positive integer x and k, and tells Arya k but not x. Arya have to find the value . There are n ancient numbers c1, c2, ..., cn and Pari has to tell Arya  if Arya wants. Given k and the ancient values, tell us if Arya has a winning strategy independent of value of x or not. Formally, is it true that Arya can understand the value  for any positive integer x?Note, that  means the remainder of x after dividing it by y.

The first line of the input contains two integers n and k (1 ≤ n,  k ≤ 1 000 000) — the number of ancient integers and value k that is chosen by Pari. The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 1 000 000).

Print "Yes" (without quotes) if Arya has a winning strategy independent of value of x, or "No" (without quotes) otherwise.

NoteIn the first sample, Arya can understand  because 5 is one of the ancient numbers.In the second sample, Arya can't be sure what  is. For example 1 and 7 have the same remainders after dividing by 2 and 3, but they differ in remainders after dividing by 7.

'use strict';

// var inpArr = `
// 15 91
// 49 121 83 67 128 125 27 113 41 169 149 19 37 29 71
// `.trim().split('\n').map(x => x.trim()), inpLine = 0;
// function readline() {
//   return inpArr[inpLine++];
// }
// function print(x) {
//   console.log(x);
// }

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}
function lcm(a, b) {
  return (a * b) / gcd(a, b);
}

var nk = readline().split(' ').map(Number),
    n = nk[0], k = nk[1]
var arr = readline().split(' ').map(Number);

var req = k, acc = 1;
for (var i = 0; i < arr.length; i++) {
  arr[i] /= gcd(arr[i], acc);
  var extract = gcd(req, arr[i]);
  req /= extract; acc *= extract;
  if (req === 1) {
    break;
  }
}

print((req === 1) ? 'Yes' : 'No')

function gcd(a, b) {
    return !b ? a : gcd(b, a % b);
}

var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var c = readline().split(' ').map(Number);

var extract = 1;
c.forEach(function(num) {
    num /= gcd(num, extract);
    var temp = gcd(num, k);
    k /= temp;
    extract *= temp;
});
print((k === 1) ? 'Yes' : 'No');

'use strict';

// var inpArr = `
// 2 7
// 2 3
// `.trim().split('\n').map(x => x.trim()), inpLine = 0;
// function readline() {
//   return inpArr[inpLine++];
// }
// function print(x) {
//   console.log(x);
// }

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}
function lcm(a, b) {
  return (a * b) / gcd(a, b);
}

var nk = readline().split(' ').map(Number),
    n = nk[0], k = nk[1]
var arr = readline().split(' ').map(Number),
    lcmArr = arr.reduce((res,x)=>lcm(res,x), 1);
print((lcmArr % k === 0) ? 'Yes' : 'No')

'use strict';

// var inpArr = `
// 15 91
// 49 121 83 67 128 125 27 113 41 169 149 19 37 29 71
// `.trim().split('\n').map(x => x.trim()), inpLine = 0;
// function readline() {
//   return inpArr[inpLine++];
// }
// function print(x) {
//   console.log(x);
// }

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}
function lcm(a, b) {
  return (a * b) / gcd(a, b);
}

var nk = readline().split(' ').map(Number),
    n = nk[0], k = nk[1]
var arr = readline().split(' ').map(Number);

var req = k;
for (var i = 0; i < arr.length; i++) {
  var extract = gcd(req, arr[i]);
  req /= extract;
  if (req === 1) {
    break;
  }
}

print((req === 1) ? 'Yes' : 'No')

function gcd(a, b) {
    return !b ? a : gcd(b, a % b);
}
function lcmOfTwo(a, b) {
    return (a * b) / gcd(a, b);
}

var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var c = readline().split(' ').map(Number);

var lcm = 1;
c.forEach(function(num) {
    lcm = lcmOfTwo(lcm, gcd(num, k));
});
print(lcm)
print((lcm%k === 0) ? 'Yes' : 'No');

function gcd(a, b) {
    return !b ? a : gcd(b, a % b);
}
function lcmOfTwo(a, b) {
    return (a * b) / gcd(a, b);
}

var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var c = readline().split(' ').map(Number);

var lcm = 1;
c.forEach(function(n) {
    lcm = lcmOfTwo(lcm, n);
});
print((lcm%k === 0) ? 'Yes' : 'No');

function gcd(a, b) {
    return !b ? a : gcd(b, a % b);
}

var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var c = readline().split(' ').map(Number);

var extract = 1;
c.forEach(function(num) {
    num /= gcd(num, extract);
    k /= gcd(num, k);
    extract *= gcd(num, k);
});
print((k === 1) ? 'Yes' : 'No');

function gcd(a, b) {
    return !b ? a : gcd(b, a % b);
}
function lcmOfTwo(a, b) {
    return (a * b) / gcd(a, b);
}

var input = readline().split(' ').map(Number);
var n = input[0], k = input[1];
var c = readline().split(' ').map(Number);

c.forEach(function(num) {
    k /= gcd(num, k);
});
print((k === 1) ? 'Yes' : 'No');