You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters.We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'.Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored.The verse patterns for the given text is a sequence of n integers p1, p2, ..., pn. Text matches the given verse pattern if for each i from 1 to n one can divide words of the i-th line in syllables in such a way that the total number of syllables is equal to pi.You are given the text and the verse pattern. Check, if the given text matches the given verse pattern.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of lines in the text. The second line contains integers p1, ..., pn (0 ≤ pi ≤ 100) — the verse pattern. Next n lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters.

If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes).

4
13 11 15 15
to be or not to be that is the question
whether tis nobler in the mind to suffer
the slings and arrows of outrageous fortune
or to take arms against a sea of troubles

NoteIn the first sample, one can split words into syllables in the following way: in-telco-dech al-len-geSince the word "ch" in the third line doesn't contain vowels, we can ignore it. As the result we get 2 syllabels in first two lines and 3 syllables in the third one.

var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];

function canDiv (word, num) {
  var char = word.split('');

  for (var i = 0; i < char.length; i++) {
    if (vowels.indexOf(char[i]) >= 0) {
      num--;
    }
  }
  return num === 0;
}

function main (num, numList, strList) {
  for (var i = 0; i < num; i++) {
    if (!canDiv(strList[i], numList[i])) {
      print('NO');
      return;
    }
  }
  print('YES');
}

var num = parseInt(readline()),
    numList = readline().split(' ').map(function (x) {
      return parseInt(x);
    }),
    strList = [];

for (var  i = 0; i < num; i++) {
  strList.push(readline());
}
main(num, numList, strList);

 var p,
  row,
  vowels,
  fit,
  i;

readline();
fit = "YES";
vowels = /[aeiouy]/gi;
i = 0;
p = readline().split( " " ).map( pi => parseInt( pi, 10 ) );
while ( row = readline() ) {
  if ( ( row.match( vowels ) || [] ).length !== p[ i++ ] ) {
    fit = "NO";
    break;
  }
}

print( fit );

var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];

function canDiv (word, num) {
  var char = word.split('');

  var hasVowel = char.map(function (x) {
    return vowels.indexOf(x);
  }).filter(function (x) {
    return x >= 0;
  });
  //if (hasVowel.length === 0) return false;

  for (var i = 0; i < char.length; i++) {
    if (vowels.indexOf(char[i]) >= 0) {
      num--;
    }
  }
  return num === 0;
}

function main (num, numList, strList) {
  for (var i = 0; i < num; i++) {
    if (!canDiv(strList[i], numList[i])) {
      print('NO');
      return;
    }
  }
  print('YES');
}

// var num = parseInt('3'),
//     numList = '2 2 3'.split(' '),
//     strList = 'intel\ncode\nch allenge'.split('\n');
// debugger;
// main(num, numList, strList);

var num = parseInt(readline()),
    numList = readline().split(' '),
    strList = [];
for (var  i = 0; i < num; i++) {
  strList.push(readline());
}
main(num, numList, strList);

var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];

function canDiv (word, num) {
  var char = word.split('');

  var hasVowel = char.map(function (x) {
    return vowels.indexOf(x);
  }).filter(function (x) {
    return x >= 0;
  });
  if (hasVowel.length === 0) return false;

  for (var i = 0; i < char.length; i++) {
    if (vowels.indexOf(char[i]) >= 0) {
      num--;
    }
  }
  return num === 0;
}

function main (num, numList, strList) {
  for (var i = 0; i < num; i++) {
    if (!canDiv(strList[i], numList[i])) {
      print('NO');
      return;
    }
  }
  print('YES');
}

// var num = parseInt('3'),
//     numList = '2 2 3'.split(' '),
//     strList = 'intel\ncode\nch allenge'.split('\n');
// debugger;
// main(num, numList, strList);

var num = parseInt(readline()),
    numList = readline().split(' '),
    strList = [];
for (var  i = 0; i < num; i++) {
  strList.push(readline());
}
main(num, numList, strList);

var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];

function canDiv (word, num) {
  for (var i = 0; i < word.length; i++) {
    if (vowels.indexOf(word[i]) >= 0) {
      num--;
    }
  }
  return num === 0;
}

function main (num, numList, strList) {
  // for (var i = 0; i < num; i++) {
  //   if (!canDiv(strList[i], numList[i])) {
  //     print('NO');
  //     return;
  //   }
  // }
  // print('YES');

  for (var i = 0; i < num; i++)
  {
    for (var j = 0; j < strList[i].length; j++)
      if (vowels.indexOf(strList[i][j]) >= 0)
        numList[i]--;
    if (numList[i] !== 0)
    {
      print('NO');
      return;
    }
  }
  print('YES');
}

var num = parseInt(readline()),
    numList = readline().split(' '),
    strList = [];

for (var  i = 0; i < num; i++) {
  strList.push(readline());
}
main(num, numList, strList);

var vowels = ['a', 'e', 'i', 'o', 'u', 'y'];

function canDiv (word, num) {
  for (var i = 0; i < word.length; i++) {
    if (vowels.indexOf(word[i]) >= 0) {
      num--;
    }
  }
  return num === 0;
}

function main (num, numList, strList) {
  for (var i = 0; i < num; i++) {
    if (!canDiv(strList[i], numList[i])) {
      print('NO');
      return;
    }
  }
  print('YES');
}

// var num = parseInt('3'),
//     numList = '2 2 3'.split(' '),
//     strList = 'intel\ncode\nch allenge'.split('\n');
// debugger;
// main(num, numList, strList);

var num = parseInt(readline()),
    numList = readline().split(' '),
    strList = [];

for (var  i = 0; i < num; i++) {
  strList.push(readline());
}
main(num, numList, strList);


Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom of any non-empty pile. Each player wants to maximize the total sum of the cards he took. The game ends when all piles become empty.Suppose Ciel and Jiro play optimally, what is the score of the game?

The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards listed from top of the current pile to bottom of the pile.

Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.

NoteIn the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10.In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.

var n=+readline();
var ans1=0;
var ans2=0;
var s=[]
for(var i=0;i<n;i++){
	var a=readline().split(' ').map(function(v){return +v;});
	for(var j=1,l=Math.floor(a[0]/2);j<=l;j++){
		ans1+=a[j];
	}
	if(a[0]%2===1){
		s.push(a[j]);
		j++;
	}
	for(;j<=a[0];j++){
		ans2+=a[j];
	}
}
s.sort(function(a,b){return b-a;});
for(var i=0;i<s.length;i++){
	if(i%2===0){
		ans1+=s[i];
	}else{
		ans2+=s[i];
	}
}
print(ans1+' '+ans2);

var n=+readline();
var c=[];
for(var i=0;i<n;i++){
	var l=readline().split(' ').map(function(v){return +v;});
	l.a=1;
	l.b=l.length-1;
	c.push(l);
}
var ans1=0;
var ans2=0;
while(true){
	var flg=false;
	var ret={max:-1e20};
	for(var i=0;i<c.length;i++){
		var cc=c[i];
		if( cc.a<=cc.b && cc[cc.a]>ret.max ){
			flg=true;
			ret.max=cc[cc.a];
			ret.index=i;
		}
	}
	if(flg){

		ans1+=ret.max;
		c[ret.index].a++;
	}

	var flg2=false;
	var ret={max:-1e20};
	for(var i=0;i<c.length;i++){
		var cc=c[i];
		if( cc.a<=cc.b && cc[cc.b]>ret.max ){
			flg2=true;
			ret.max=cc[cc.b];
			ret.index=i;
		}
	}
	if(flg2){
		ans2+=ret.max;
		c[ret.index].b--;
	}
	if(!flg&&!flg2){
		break;
	}
}
print(ans1+' '+ans2);

var n=+readline();
var c=[];
for(var i=0;i<n;i++){
	var l=readline().split(' ').map(function(v){return +v;});
	l.a=1;
	l.b=l.length-1;
	c.push(l);
}
var ans1=0;
var ans2=0;
while(true){
	var flg=false;
	var ret={max:-1e20};
	for(var i=0;i<c.length;i++){
		var cc=c[i];
		if( cc.a<=cc.b && cc[cc.a]>=ret.max ){
			flg=true;
			ret.max=cc[cc.a];
			ret.index=i;
		}
	}
	if(flg){

		ans1+=ret.max;
		c[ret.index].a++;
	}

	var flg2=false;
	var ret={max:-1e20};
	for(var i=0;i<c.length;i++){
		var cc=c[i];
		if( cc.a<=cc.b && cc[cc.b]>=ret.max ){
			flg2=true;
			ret.max=cc[cc.b];
			ret.index=i;
		}
	}
	if(flg2){
		ans2+=ret.max;
		c[ret.index].b--;
	}
	if(!flg&&!flg2){
		break;
	}
}
print(ans1+' '+ans2);


You are given two binary strings $$$x$$$ and $$$y$$$, which are binary representations of some two integers (let's denote these integers as $$$f(x)$$$ and $$$f(y)$$$). You can choose any integer $$$k \ge 0$$$, calculate the expression $$$s_k = f(x) + f(y) \cdot 2^k$$$ and write the binary representation of $$$s_k$$$ in reverse order (let's denote it as $$$rev_k$$$). For example, let $$$x = 1010$$$ and $$$y = 11$$$; you've chosen $$$k = 1$$$ and, since $$$2^1 = 10_2$$$, so $$$s_k = 1010_2 + 11_2 \cdot 10_2 = 10000_2$$$ and $$$rev_k = 00001$$$.For given $$$x$$$ and $$$y$$$, you need to choose such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal (read notes if you don't know what does "lexicographically" means).It's guaranteed that, with given constraints, $$$k$$$ exists and is finite.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$2T$$$ lines contain a description of queries: two lines per query. The first line contains one binary string $$$x$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. The second line contains one binary string $$$y$$$, consisting of no more than $$$10^5$$$ characters. Each character is either 0 or 1. It's guaranteed, that $$$1 \le f(y) \le f(x)$$$ (where $$$f(x)$$$ is the integer represented by $$$x$$$, and $$$f(y)$$$ is the integer represented by $$$y$$$), both representations don't have any leading zeroes, the total length of $$$x$$$ over all queries doesn't exceed $$$10^5$$$, and the total length of $$$y$$$ over all queries doesn't exceed $$$10^5$$$.

Print $$$T$$$ integers (one per query). For each query print such $$$k$$$ that $$$rev_k$$$ is lexicographically minimal.

NoteThe first query was described in the legend.In the second query, it's optimal to choose $$$k = 3$$$. The $$$2^3 = 1000_2$$$ so $$$s_3 = 10001_2 + 110_2 \cdot 1000_2 = 10001 + 110000 = 1000001$$$ and $$$rev_3 = 1000001$$$. For example, if $$$k = 0$$$, then $$$s_0 = 10111$$$ and $$$rev_0 = 11101$$$, but $$$rev_3 = 1000001$$$ is lexicographically smaller than $$$rev_0 = 11101$$$.In the third query $$$s_0 = 10$$$ and $$$rev_0 = 01$$$. For example, $$$s_2 = 101$$$ and $$$rev_2 = 101$$$. And $$$01$$$ is lexicographically smaller than $$$101$$$.The quote from Wikipedia: "To determine which of two strings of characters comes when arranging in lexicographical order, their first letters are compared. If they differ, then the string whose first letter comes earlier in the alphabet comes before the other string. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one string has no more letters to compare while the other does, then the first (shorter) string is deemed to come first in alphabetical order."

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var T = rdN();
    loop:while (T --> 0) {
        var x = rdS().split('').reverse();
        var y = rdS().split('').reverse();
        var res = 0;
        for(var i = 0, j = 0;;) {
            if (x[i] === '0' && y[j] === '0') {
                ++i; ++j;
            }
            if (x[i] === '0' && y[j] === '1') {
                ++i;
                ++res;
            }
            if (x[i] === '1' && y[j] === '0') {
                ++i; ++j;
            }
            if (x[i] === '1' && y[j] === '1') {
                pr(res);
                continue loop;
            }
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true),primes=[],i,j;for(i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
getPrimeFactors=function(n){var primes=getPrimes(Math.floor(Math.sqrt(n))),last=primes.push(n)-1,factors=[],i,p;for(i=0,p=primes[0];primes[last]>1;){if(primes[last]%p===0){primes[last]/=p;factors.push(p);}else{p=primes[++i];}}return factors;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{value:v,writable:true,enumerable:false,configurable:true});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});

main();
return OUTPUT;
})();


You are given a string $$$s$$$. You can build new string $$$p$$$ from $$$s$$$ using the following operation no more than two times:   choose any subsequence $$$s_{i_1}, s_{i_2}, \dots, s_{i_k}$$$ where $$$1 \le i_1 < i_2 < \dots < i_k \le |s|$$$;  erase the chosen subsequence from $$$s$$$ ($$$s$$$ can become empty);  concatenate chosen subsequence to the right of the string $$$p$$$ (in other words, $$$p = p + s_{i_1}s_{i_2}\dots s_{i_k}$$$). Of course, initially the string $$$p$$$ is empty. For example, let $$$s = \text{ababcd}$$$. At first, let's choose subsequence $$$s_1 s_4 s_5 = \text{abc}$$$ — we will get $$$s = \text{bad}$$$ and $$$p = \text{abc}$$$. At second, let's choose $$$s_1 s_2 = \text{ba}$$$ — we will get $$$s = \text{d}$$$ and $$$p = \text{abcba}$$$. So we can build $$$\text{abcba}$$$ from $$$\text{ababcd}$$$.Can you build a given string $$$t$$$ using the algorithm above?

The first line contains the single integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of test cases. Next $$$2T$$$ lines contain test cases — two per test case. The first line contains string $$$s$$$ consisting of lowercase Latin letters ($$$1 \le |s| \le 400$$$) — the initial string. The second line contains string $$$t$$$ consisting of lowercase Latin letters ($$$1 \le |t| \le |s|$$$) — the string you'd like to build. It's guaranteed that the total length of strings $$$s$$$ doesn't exceed $$$400$$$.

Print $$$T$$$ answers — one per test case. Print YES (case insensitive) if it's possible to build $$$t$$$ and NO (case insensitive) otherwise.

'use strict'
const ord = x => x.charCodeAt(0) - 97;

const problem = (s, p) => {
    const n = s.length;
    const F = [];
    for (let i = 0; i < n + 2; i++) F[i] = Array(26).fill(n);
    for (let i = n-1; i > -1; i--) {
        F[i] = F[i + 1].slice()
        F[i][ord(s[i])] = i
    }
    const interleaving = (l, r) => {
        const dp = Array(r.length + 1).fill(n); dp[0] = -1;

        for (let j = 1; j < r.length + 1; j++) {
            dp[j] = F[dp[j - 1] + 1][ord(r[j - 1])]
        }

        for (let i = 1; i < l.length + 1; i++) {
            dp[0] = F[dp[0] + 1][ord(l[i - 1])]

            for (let j = 1; j < r.length + 1; j++) {
                const a = F[dp[j] + 1][ord(l[i - 1])]
                const b = F[dp[j - 1] + 1][ord(r[j - 1])]
                dp[j] = Math.min(a, b)
            }
        }
        return dp[dp.length - 1] < n
    }

    for (let i = 0; i < p.length; i++) if (interleaving(p.slice(0, i), p.slice(i))) return 'YES'
    return 'NO'
}

let t = +readline()
while(t--) print(problem(readline().split(''), readline()));

'use strict'

const ord = x => x.charCodeAt(0) - 97;

// G - G[i] хранит объект первых индексов каждого символа в строке s, начиная поиск с индекса i
// D - динамика, D[i][j] хранит минимальную длину x префикса строки s, в котором содержится a[:i] и b[:j]
// D[0][0] = 0 - то есть для пустых префиксов - минимальным будет пустой префикс s
const interleaving = (a, b, G) => {
    const D = Array.from({ length: a.length + 1 }, () => Array(b.length + 1).fill(Infinity)); D[0][0] = 0;
    for (let i = 0; i < a.length + 1; i++) {
        for (let j = 0; j < b.length + 1; j++) {
            if (!isFinite(D[i][j])) continue;
            const x = D[i][j];
            if (i !== a.length) D[i+1][j] = Math.min(D[i+1][j], G[x][ord(a[i])] + 1);
            if (j !== b.length) D[i][j+1] = Math.min(D[i][j+1], G[x][ord(b[j])] + 1);
        }
    }

    return isFinite(D[a.length][b.length]);
}

const problem = (s, p) => {
    const n = s.length;
    const G = Array.from({ length: n + 2}, () => Array(26).fill(Infinity));
    for (let i = n - 1; i > -1; i--) { G[i] = G[i + 1].slice(); G[i][ord(s[i])] = i; }
    for (let i = 0; i < p.length; i++) if (interleaving(p.slice(0, i), p.slice(i), G, n)) return 'YES';
    return 'NO';
}

let t = +readline()
while(t--) print(problem(readline(), readline()));

'use strict'

const problem = (s, p) => {
    let j = 0;
    for (let i = 0; i < s.length; i++) {
        if (s[i] === p[j]) j++;
        if (j === p.length) return 'YES';
    }
    for (let i = 0; i < s.length; i++) {
        if (s[i] === p[j]) j++;
        if (j === p.length) return 'YES';
    }
    return 'NO';
}

let t = +readline()
while(t--) print(problem(readline(), readline()));

'use strict'

const problem = (s, p) => {
    let j = 0;
    let t = '';
    const pLen = p.length;
    for (let i = 0; i < s.length; i++) {
        if (s[i] === p[j]) { if (++j === pLen) return 'YES'; }
        else t += s[i];
    }
    for (let i = 0; i < t.length; i++) {
        if (t[i] === p[j])  { if (++j === pLen) return 'YES'; }
    }
    return 'NO';
}
let t = +readline()
while(t--) print(problem(readline(), readline()));

'use strict'

// G - G[i] хранит объект первых индексов каждого символа в строке s, начиная поиск с индекса i
// D - динамика, D[i][j] хранит минимальную длину x префикса строки s, в котором содержится a[:i] и b[:j]
// D[0][0] = 0 - то есть для пустых префиксов - минимальным будет пустой префикс s
const interleaving = (a, b, G) => {
    const D = Array.from({ length: a.length + 1 }, () => Array(b.length + 1).fill(Infinity)); D[0][0] = 0;
    for (let i = 0; i < a.length + 1; i++) {
        for (let j = 0; j < b.length + 1; j++) {
            if (!isFinite(D[i][j])) continue;
            const x = D[i][j];
            if (i !== a.length && a[i] in G[x]) D[i+1][j] = Math.min(D[i+1][j], G[x][a[i]] + 1);
            if (j !== b.length && b[j] in G[x]) D[i][j+1] = Math.min(D[i][j+1], G[x][b[j]] + 1);
        }
    }
    return isFinite(D[a.length][b.length]);
}
const problem = (s, p) => {
    if (s === 'adddbefbbbeeaadcddabfffcbeaecfadbdbfecebabbefbedfbdcafbfcbfacecbdcfaabeacdacfebabaccaddbebdabdeebcafcaabadabeaeeebeddffbabfaeedcbefbdcbfacaeefeafccadadadcdabcbdaadcdbbacadfabfbdaaeceaabbdabfabeacddacecdcabfeeaedebffefcecabcabecffcebdefcfaeadbfddbdfefeacdfcdebbdcbaafcfbbfceadfdabfcdacefdeadadbfedbaaefbcccfcdcdbfbbacfbfcbcabcbcbbffbbcefbeccdcaebabbbbdddaffacabbabbbadfcaadbedbaabbaffebdfbdbbcbfffeafe')
        print(p)
    const G = Array.from({ length: s.length + 1 }, () => ({}));
    for (let i = s.length - 1; i > -1; i--) G[i] = Object.assign({}, G[i + 1], { [s[i]]: i });
    for (let i = 0; i < p.length; i++) if (interleaving(p.slice(0, i), p.slice(i), G)) return 'YES';
    return 'NO';
}

let t = +readline()
while(t--) print(problem(readline(), readline()));


Anu has created her own function $$$f$$$: $$$f(x, y) = (x | y) - y$$$ where $$$|$$$ denotes the bitwise OR operation. For example, $$$f(11, 6) = (11|6) - 6 = 15 - 6 = 9$$$. It can be proved that for any nonnegative numbers $$$x$$$ and $$$y$$$ value of $$$f(x, y)$$$ is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems.A value of an array $$$[a_1, a_2, \dots, a_n]$$$ is defined as $$$f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$$$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). Elements of the array are not guaranteed to be different.

Output $$$n$$$ integers, the reordering of the array with maximum value. If there are multiple answers, print any.

'use strict'

const problem = (n, a) => {
    const d = Array(31).fill(0), p = [];
    const b = a.map(i => (+i).toString(2));

    for (let i = 0; i < n; i++) {
        const x = b[i].split('').reverse();
        for (let j = 0; j < x.length; j++) {
            if (x[j] === '1') { d[j]++; p[j] = i; }
        }
    }
    for (let i = d.length - 1; i > -1; i--) {
        if (d[i] === 1) return [ a[p[i]], a.slice(0, p[i]).join(' '), a.slice(p[i]+1).join(' ') ].join(' ');
    }
    return a.join(' ');
}
print(problem(+readline(), readline().split(' ')))

const f = (x, y) => (x | y) - y

const processData = (lines) => {
  const bits = Array(32).fill(0).map(() => [])

  let nums = lines[1].split(' ').map(x => +x)
  for (let k =0; k<nums.length; k++) {
    const n = nums[k]
    const str = n.toString(2).split('').reverse()
    for (let j = 0; j < str.length; j++) {
      if (str[j] === '1') {
        bits[j].push(k)
      }
    }
  }

  let restNum = null
  for (const bitArr of bits) {
    if (bitArr.length === 1) {
      restNum = bitArr[0]
    }
  }
  if (restNum === null) {
    console.log(nums.join(' '))
  } else {
    const removed = nums.splice(restNum, 1)
    console.log([removed[0], ...nums].join(' '))
  }
}

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

'use strict';

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

const lines = [];
let nextLine = 0;
rl.on('line', (line) => {
  lines.push(line);
});

rl.on('close', () => {
  main();
});

function readline() {
  return lines[nextLine++];
}

function solve(arr) {
  const n = arr.length;
  if (n < 2) {
    return arr;
  }
  const bitIdx = {};
  for (let i = 0; i < n; i++) {
    const a = arr[i];
    for(let b = 1; b <= a; b <<= 1) {
      if (a & b) {
        if (bitIdx[b] === undefined) {
          bitIdx[b] = i;
        } else {
          bitIdx[b] = -1;
        }
      }
    }
  }
  const order = Object.keys(bitIdx).sort((a,b)=> b - a);
  // console.log({bitIdx, order});
  let idx = 0;
  for (const k of order) {
    if (bitIdx[k] !== -1) {
      idx = bitIdx[k];
      break;
    }
  }
  const head = arr[idx];
  arr.splice(idx,1);
  arr.unshift(head);
  return arr;
}

function main() {
  readline();
  const arr = readline().split(' ').map(Number);
  const res = solve(arr);
  console.log(res.join(' '));
}

'use strict'

const problem = (n, a) => {
    const d = Array(31).fill(0), p = [];
    const b = a.map(i => (+i).toString(2));
    for (let i = 0; i < n; i++) {
        const x = b[i]
        for (let j = x.length - 1; j > -1; j--) {
            d[j]++;
            p[j] = i;
        }
    }
    for (let i = d.length - 1; i > -1; i--) {
        if (d[i] === 1) return [ a[p[i]], a.slice(0, p[i]).join(' '), a.slice(p[i]+1).join(' ') ].join(' ');
    }
    return a.join(' ');
}
print(problem(+readline(), readline().split(' ')))

'use strict';

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

const lines = [];
let nextLine = 0;
rl.on('line', (line) => {
  lines.push(line);
});

rl.on('close', () => {
  main();
});

function readline() {
  return lines[nextLine++];
}

function solve(arr) {
  arr.sort((a, b) => b - a);
  return arr;
}

function main() {
  readline();
  const arr = readline().split(' ').map(Number);
  const res = solve(arr);
  console.log(res.join(' '));
}


Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one.The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than d. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section?

The first line of the input contains three integers n, b and d (1 ≤ n ≤ 100 000, 1 ≤ b ≤ d ≤ 1 000 000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value d, which determines the condition when the waste section should be emptied. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000) — sizes of the oranges listed in the order Kolya is going to try to put them in the juicer.

Print one integer — the number of times Kolya will have to empty the waste section.

NoteIn the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all.

function main(n,b,d,arr){

    var fits = 0;
    var res = 0;

    for(var i = 0 ; i < n ; i++){
      if(arr[i] > b)continue;

      fits += arr[i];
      if(fits <= d)continue;

      res++;
      fits = 0;

    }
    print(res);
}

var nbd = readline().split(" ");
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);

  var informations = readline().split(' ').map(Number)
  var oranges = readline().split(' ').map(Number)
  var numberOfOrange = informations[0]
  var sizeMax = informations[1]
  var containerMax = informations[2]

  var totalPressed = 0
  var numberOfTimeCleaned = 0
  for (var i = 0; i < numberOfOrange; i++) {
    if (oranges[i] <= sizeMax) {
      totalPressed += oranges[i]
    }

    if (totalPressed > containerMax) {
      totalPressed = 0
      numberOfTimeCleaned += 1
    }
  }

  print(numberOfTimeCleaned)

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

var n = firstLine[0];
var b = firstLine[1];
var d = firstLine[2];

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

var count = 0;
var currentLoad = 0;

for (var i = 0; i < n; i++) {
  if (oranges[i] <= b) {
    currentLoad += oranges[i];
  }

  if (currentLoad > d) {
    count++;
    currentLoad = 0;
  }
}

print(count);

var params = readline().split(' ').map(Number);
var n = params[0]; var b = params[1]; var d = params[2];
var processed_orange_size = 0;
var do_empty = 0;

readline().split(' ').map(function(x){

    x = parseInt(x);
    if(x <= b)
        processed_orange_size += x;

    if(processed_orange_size > d) {
        do_empty++;
        processed_orange_size = 0;
    }
});

print(do_empty);

var x = readline().split(" ");
var a = readline().split(" ").map(Number);
var c = 0, s = 0;
for (var i = 0; i < x[0]; i++) {
	if (a[i] > x[1]) continue;
	s += a[i];
	if (s > x[2]) {
		c++;
		s = 0;
    }
}
print(c);

var values = readline().split(" ").map(Number);
var b = values[1];
var d = values[2];

var oranges = readline().split(" ").map(Number);

var sum = 0;
var count = 0;
for (var i = 0; i < oranges.length; i++) {
    if (oranges[i] > b) {
        continue;
    }

    sum += oranges[i];

    if (sum > d) {
        count++;
        sum = 0;
    }
}

print(count);

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

function readline() {
  return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {

  const x = readline()
    .split(" ")
    .map((x) => +x);

      const x2 = readline()
    .split(" ")
    .map((x) => +x);

  juicer(x[1],x[2],x2);
}

 function juicer(b, d, oranges) {
  let wasteLand = 0;
  let clearCounts = 0;

  for (const orange of oranges) {
    if (orange <= b) wasteLand += orange;

    if (wasteLand > d) {
      wasteLand = 0;
      clearCounts++;
    }
  }

  console.log(clearCounts);

  return clearCounts;
}

'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(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const [n, b, d] = readline().split(' ').map(x => parseInt(x));
  const a = readline().split(' ').map(x => parseInt(x));
  let k = 0;
  let t = 0;
  for (let i = 0; i < n; i++) {
    if (a[i] > b) {
      continue;
    }
    k += a[i];
    if (k > d) {
      k = 0;
      t++;
    }
  }
 // output
  print(t);
}

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

rl.on('line', (data) => {
  if (c === 0) {
    [n, b, d] = data.split(' ').map(Number);
    c++;
    return;
  }

  const arr = data.split(' ').map(Number).filter(x => x <= b);
  let ans = 0;

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

    if (cup > d) {
      cup = 0;
      ans++;
    }
  }

  console.log(ans);

  c++;
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function readint() {
    let line = readline().split(' ').map(function(num) {
        return parseInt(num);
    });
    return line;
}

function readfloat() {
    let line = readline().split(' ').map(function(num) {
        return parseFloat(num);
    });
    return line;
}

function print(x) {
    console.log(x);
}

function write(x) {
    process.stdout.write(x);
}
function main() {
    let t = readint();
    let n, b, d;
    [n,b,d] = t;
    let a = readint();
    let ans = 0;
    let garbage = 0;
    for(let i = 0; i < n; i++) {
        if(a[i] <= b) {
            garbage += a[i];
        }
        if(garbage > d) {
            garbage = 0;
            ans++;
        }
    }
    print(ans);
}

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let input = [];
readline.on('line', line => {
  input.push(line);
});
process.stdin.on('end', () => {
let firstLine = input[0].split(' ');
firstLine = firstLine.map((b) => parseInt(b));
const n = firstLine[0];
const maxSize = firstLine[1];
const threshold = firstLine[2];
let oranges = input[1].split(' ');
oranges = oranges.map((b) => parseInt(b));

const res = oranges.reduce((acc, cv) => {
  if (cv > maxSize) {
    return acc;
  }
  acc.currentWaste += cv;
  if (acc.currentWaste > threshold) {
    acc.totalCleanups += 1;
    acc.currentWaste = 0;
  }
  return acc;
}, { totalCleanups: 0, currentWaste: 0 });
console.log(res.totalCleanups)

});

function main(n,b,d,arr){

    var fits = 0;

    for(var i = 0 ; i < n ; i++){
      if(arr[i] < b)fits += arr[i];
    }
    fits = Math.floor(fits/d);
    print(fits);
}

var nbd = readline().split(" ");
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);

function main(n,b,d,arr){

    var fits = 0;

    for(var i = 0 ; i < n ; i++){
      if(arr[i] <= b)fits += arr[i];
    }
    fits = Math.floor(fits/d);
    print(fits);
}

var nbd = readline().split(" ");
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);

function main(n,b,d,arr){

    var fits = 0;

    for(var i = 0 ; i < n ; i++){
      if(arr[i] <= b)fits += arr[i];
    }
    fits = fits%d;
    print(fits);
}

var nbd = readline().split(" ");
var arr = readline().split(" ");
for(var i = 0 ; i < arr.length ; i++)arr[i] = parseInt(arr[i]);

main(parseInt(nbd[0]),parseInt(nbd[1]),parseInt(nbd[2]),arr);

  var informations = readline().split(' ').map(Number)
  var oranges = readline().split(' ').map(Number)
  var numberOfOrange = informations[0]
  var sizeMax = informations[1]
  var containerMax = informations[2]

  var totalPressed = 0
  var numberOfTimeCleaned = 0
  for (var i = 0; i < numberOfOrange; i++) {
    if (oranges[i] < sizeMax) {
      totalPressed += oranges[i]
    }

    if (totalPressed > containerMax) {
      totalPressed = 0
      numberOfTimeCleaned += 1
    }
  }

  print(numberOfTimeCleaned)

  var informations = readline().split(' ').map(Number)
  var oranges = readline().split(' ').map(Number)
  var numberOfOrange = informations[0]
  var sizeMax = informations[1]
  var containerMax = informations[2]

  var totalPressed = 0
  for (var i = 0; i < numberOfOrange; i++) {
    if (oranges[i] < sizeMax) {
      totalPressed += oranges[i]
    }
  }

  var numberOfTimeCleaned = Math.floor(totalPressed / containerMax)
  print(numberOfTimeCleaned)

var values = readline().split(" ").map(Number);
var b = values[1];
var d = values[2];

var oranges = readline().split(" ").map(Number);

var sum = 0;
for (var i = 0; i < oranges.length; i++) {
    if (oranges[i] > b) {
        continue;
    }

    sum += oranges[i];
}

print(sum === d ? 0: Math.floor(sum/d));

var values = readline().split(" ").map(Number);
var n = values[1];
var d = values[2];

var oranges = readline().split(" ").map(Number)
                .filter(x => x <= n)
                .reduce((acc, n) => {
                    return acc + n;
                }, 0);

print(Math.floor(oranges/d));

var values = readline().split(" ").map(Number);
var n = values[1];
var d = values[2];

var oranges = readline().split(" ").map(Number)
                .filter(x => x <= n)
                .reduce((acc, n) => {
                    return acc + n;
                }, 0);

print(Math.floor(oranges/10));

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

rl.on('line', (data) => {
  if (c === 0) {
    [n, b, d] = data.split(' ').map(Number);
    c++;
    return;
  }

  const arr = data.split(' ').map(Number).filter(x => x <= b);
  const sum = arr.reduce((a, b) => a + b, 0);
  let ans = Math.floor(sum / d);

  if (d === 1) {
    ans--;
  }

  console.log(ans);

  c++;
});

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

rl.on('line', (data) => {
  if (c === 0) {
    [n, b, d] = data.split(' ').map(Number);
    c++;
    return;
  }

  const arr = data.split(' ').map(Number).filter(x => x <= b);
  const sum = arr.reduce((a, b) => a + b, 0);
  const ans = Math.floor(sum / d);

  console.log(ans);

  c++;
});

const readline = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
let input = [];
readline.on('line', line => {
  input.push(line);
});
process.stdin.on('end', () => {
let firstLine = input[0].split(' ');
firstLine = firstLine.map((b) => parseInt(b));
const n = firstLine[0];
const maxSize = firstLine[1];
const threshold = firstLine[2];
let oranges = input[1].split(' ');
oranges = oranges.map((b) => parseInt(b));

const res = oranges.reduce((acc, cv) => {
  if (cv > maxSize) {
    return acc;
  }
  acc.currentWaste += cv;
  if (acc.currentWaste > threshold) {
    acc.totalCleanups += 1;
    acc.currentWaste = 0;
  }
  console.log({cv,acc})
  return acc;
}, { totalCleanups: 0, currentWaste: 0 });
console.log(res.totalCleanups)

});

var values = readline().split(" ").map(Number);
var n = values[1];
var d = values[2];

var oranges = readline().split(" ").map(Number)
                .filter(x => x <= n)
                .reduce((acc, n) => {
                    return acc + n;
                }, 0);

print(oranges === d ? 0: Math.floor(oranges/d));


You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).More formally, if you are standing at the point $$$(x, y)$$$, you can:   go left, and move to $$$(x - 1, y)$$$, or  go right, and move to $$$(x + 1, y)$$$, or  go up, and move to $$$(x, y + 1)$$$, or  go down, and move to $$$(x, y - 1)$$$. There are $$$n$$$ boxes on this plane. The $$$i$$$-th box has coordinates $$$(x_i,y_i)$$$. It is guaranteed that the boxes are either on the $$$x$$$-axis or the $$$y$$$-axis. That is, either $$$x_i=0$$$ or $$$y_i=0$$$.You can collect a box if you and the box are at the same point. Find the minimum number of moves you have to perform to collect all of these boxes if you have to start and finish at the point $$$(0,0)$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of boxes. The $$$i$$$-th line of the following $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-100 \le x_i, y_i \le 100$$$) — the coordinate of the $$$i$$$-th box. It is guaranteed that either $$$x_i=0$$$ or $$$y_i=0$$$. Do note that the sum of $$$n$$$ over all test cases is not bounded.

For each test case output a single integer — the minimum number of moves required.

NoteIn the first test case, a possible sequence of moves that uses the minimum number of moves required is shown below.  $$$$$$(0,0) \to (1,0) \to (1,1) \to (1, 2) \to (0,2) \to (-1,2) \to (-1,1) \to (-1,0) \to (-1,-1) \to (-1,-2) \to (0,-2) \to (0,-1) \to (0,0)$$$$$$ In the second test case, a possible sequence of moves that uses the minimum number of moves required is shown below.  $$$$$$(0,0) \to (0,1) \to (0,2) \to (-1, 2) \to (-2,2) \to (-3,2) \to (-3,1) \to (-3,0) \to (-3,-1) \to (-2,-1) \to (-1,-1) \to (0,-1) \to (0,0)$$$$$$ In the third test case, we can collect all boxes without making any moves.

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 i=1;i<=t;i++)
    {
        let n=parseInt(line[++cnt]);
        let ans=0;
        let a=0,b=0,c=0,d=0;
        for(let j=1;j<=n;j++)
        {
            let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
            if(!x)
            {
                a=Math.max(a,y);
                b=Math.min(b,y);
            }
            if(!y)
            {
                c=Math.max(c,x);
                d=Math.min(d,x);
            }
            // ans+=2*Math.abs(x);
            // ans+=2*Math.abs(y);
        }
        ans+=2*Math.abs(a);
        ans+=2*Math.abs(b);
        ans+=2*Math.abs(c);
        ans+=2*Math.abs(d);
        console.log(ans);
    }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        const n = parseInt(readline(), 10);
        let maxY = 0;
        let minY = 0;
        let maxX = 0;
        let minX = 0;
        for (let i = 0; i < n; i++) {
            const [x, y] = readline().split(' ').map(Number);
            if (x > maxX) maxX = x;
            if (x < minX) minX = x;
            if (y > maxY) maxY = y;
            if (y < minY) minY = y;
        }

        let res = Math.abs(maxY) + Math.abs(minY) + Math.abs(maxX) + Math.abs(minX);
        res *= 2;
        output(res);
    }
}

T = readline()

while(T--){
  n = readline()
  x = 0
  y = 0
  minX = 0
  minY = 0

  while(n--){
    str = readline().split(' ').map(el => +el)
    curx = str[0]
    cury = str[1]

    if(curx){
      if(curx>0)
        x = Math.max(curx, x)
      else if(curx<0)
        minX = Math.max(Math.abs(curx), minX)
    }

    else{
      if(cury>0)
      y = Math.max(cury, y)
    else if(cury<0)
      minY = Math.max(Math.abs(cury), minY)
    }
  }

  ans = (x+y+minX+minY) * 2

  print(ans)
}

var T = parseInt(readline());
for (var tt=0; tt<T; tt++) {
    var n = parseInt(readline());
    var minx=0;
    var maxx=0;
    var miny=0;
    var maxy=0;
    for (var i=0; i<n; i++) {
        var coords = readline().split(" ").map(x => parseInt(x));
        minx=Math.min(coords[0], minx);
        maxx=Math.max(coords[0], maxx);
        miny=Math.min(coords[1], miny);
        maxy=Math.max(coords[1], maxy);
    }

    print(minx*-2+maxx*2+miny*-2+maxy*2);
}

var tests = parseInt(readline());
    var n;
    for (var t=0; t < tests; t++) {
        n = parseInt(readline());
        var minX = 0, maxX = 0, minY = 0, maxY = 0;
        for (var i = 0; i < n; i++) {
            var c = readline().split(' ').map(x=>parseInt(x));
            minX = Math.min(minX, c[0]);
            maxX = Math.max(maxX, c[0]);
            minY = Math.min(minY, c[1]);
            maxY = Math.max(maxY, c[1]);
        }
        var dist = (maxX - minX) * 2 + (maxY - minY) * 2;
        print(dist);
    }

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 i=1;i<=t;i++)
    {
        let n=parseInt(line[++cnt]);
        let ans=0;
        for(let j=1;j<=n;j++)
        {
            let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
            ans+=2*Math.abs(x);
            ans+=2*Math.abs(y);
        }
        console.log(ans);
    }
})

T = readline()

while(T--){
  n = readline()
  x = 0
  y = 0
  minX = 0
  minY = 0

  while(n--){
    str = readline().split(' ').map(el => +el)
    curx = str[0]
    cury = str[1]

    if(curx){
      if(curx>0)
        x =+ curx
      else if(curx<0)
        minX =+ Math.abs(curx)
    }

    else{
      if(cury>0)
      y =+ cury
    else if(cury<0)
      minY =+ Math.abs(cury)
    }
  }

  ans = (x+y+minX+minY) * 2

  print(ans)
}


You are given two integers $$$n$$$ and $$$m$$$ ($$$m < n$$$). Consider a convex regular polygon of $$$n$$$ vertices. Recall that a regular polygon is a polygon that is equiangular (all angles are equal in measure) and equilateral (all sides have the same length).  Examples of convex regular polygons Your task is to say if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given as two space-separated integers $$$n$$$ and $$$m$$$ ($$$3 \le m < n \le 100$$$) — the number of vertices in the initial polygon and the number of vertices in the polygon you want to build.

For each test case, print the answer — "YES" (without quotes), if it is possible to build another convex regular polygon with $$$m$$$ vertices such that its center coincides with the center of the initial polygon and each of its vertices is some vertex of the initial polygon and "NO" otherwise.

Note  The first test case of the example It can be shown that the answer for the second test case of the example is "NO".

process.stdin.resume();
process.stdin.setEncoding('utf8');
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() {
    const t = +(readLine());
    for (let i = 0; i < t; i++){
        const nums = readLine().split(' ').map(Number);
        const [n, m] = nums;
        const res = n % m;
        console.log((res) ? 'NO' : 'YES');
    }

}

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

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

  const [n,m] = d.split(' ').map(Number);

  if (n % m === 0) {
    console.log('YES');
  }
  else {
    console.log("NO");
  }

  c++;
});

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

});

let input = ''
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    main(input.split(EOL))
})

const main = (lines) => {
    let n = lines[0] * 1

    for (let i = 1; i <= n; i++) {
        let nums = lines[i].split(" ").map(el => el * 1)
        if (nums[0] % nums[1] === 0) {
            console.log("yes")
        } else {
            console.log("no")
        }
    }
}

const readline = require('readline');

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

let answer = "";

let lines = [];

rl.on('line', (t)=>{
    lines.push(t);
}).on('close', ()=>{
    let t = parseInt(lines[0]);

    for(let i = 1; i <= t; i++)
    {
        let [n,m] = lines[i].split(' ').map(function (x) {
            return parseInt(x);
        });

        if(n % m === 0){
            answer += 'YES\n';
        }
        else{
            answer += 'NO\n';
        }

    }

    console.log(answer);
});

const processData = (lines) => {
  const num = +lines[0]
  for (let j =0; j<num; j++) {
    const [n, m] = lines[j + 1].split(' ').map(x => +x)
    if (n%m === 0) {
      console.log('YES')
    } else {
      console.log('NO')
    }
  }
}

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

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

// Write your logic in main();
// let t = readline().split(' ').map(x => parseInt(x));
const main = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, m] = readline().split(' ').map(x => parseInt(x));
    print((n - m) % m === 0 ? 'YES' : 'NO');
  }
};

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStd => {
    inputString += inputStd;
});
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => {
        return str.trim();
    });
    main();
});

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

function main() {
	    const t = +(readLine());
	    for(let i = 0; i < t; i++) {
	    	const nums = readLine().split(' ').map(Number);
		    const [n, m] = nums;
		    const res = n % m;
		    console.log( (res) ? 'NO' : 'YES' );
	    }
}

process.stdin.resume();
process.stdin.setEncoding('ascii');
var inputString="";
var currentLine=0;

process.stdin.on('data',function(data){
	inputString+=data;

});
process.stdin.on('end',function(){
	inputString=inputString.split('\n');
	main();

});
function readline(){
	return inputString[currentLine++];
}
function main(){
	var t=parseInt(readline());
	 for(let i=0;i<=t-1;i++){
	   var arr=readline().split(' ');
	     drawgiag(arr[0],arr[1]);
	}
}

function drawgiag(n,m){
    n=parseInt(n);
	m=parseInt(m);
	if(n%m==0){
		console.log("YES");
	}
	else{
		console.log("NO");
	}
}

var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
function main(raw) {
    var lines = raw.trim().split("\n").map(function (v) { return v.split(" ").map(function (u) { return parseInt(u, 10); }); });
    var _a = __read(lines.shift(), 1), t = _a[0];
    while (t > 0) {
        var _b = __read(lines.shift(), 2), n = _b[0], m = _b[1];
        console.log((n - m) % m === 0 || (n - m) % n === 0 ? "YES" : "NO");
        t--;
    }
}
(function () {
    var d = "";
    process.stdin.on("data", function (c) { return d += c; });
    process.stdin.on("end", function () { return main(d); });
})();

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

const sol = () => {
    let line = data.trim().split('\n');
    let t = Number(line.shift());
    let r = [];
    for(let l of line) {
        let [n, m] = l.split(' ').map(Number);
        r.push((n > m && n%m === 0)?"YES":"NO");
    }
    console.log(r.join('\n'));
};

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

var line = readline();
for (var i = 0; i < line; i++)
    print(getDone());

function getDone() {
    var lines = readline().split(" ");
    return ((lines[0] % lines[1] == 0) ? "YES" : "NO");
}

function processItem() {
  var items = readline().split(' ').map(function(i) { return +i; });
  var x = items[0];
  var y = items[1];

  print(x % y === 0 ? 'YES' : 'NO');
}

function processItems() {
var itemsCount = +readline();
var items = [];

for (var i = 0; i < itemsCount; ++i) {
  processItem();
}

return items;
}

processItems();

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t);
    for(var i = 0; i < t; i++){
        var one = nextIntArray();
        var n = one[0];
        var m = one[1];
        if(n % m == 0){
            output[i] = "YES";
        }else{
            output[i] = "NO";
        }
    }
    myout(myconv(output,9));
}

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

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var mn = readNumArray();
    var m = mn[0];
    var n = mn[1];
    print(m % n === 0 ? "YES" : "NO");
  }
}
main()

var limit = readline()

while(limit > 0){
    var values = readline()
    var valuesSplitted = values.split(" ")
    if(parseInt(valuesSplitted[0]) % parseInt(valuesSplitted[1]) == 0){
        print("YES")
    }else{
        print("NO")
    }
    limit--
}

const readline = require("readline")

function* range(n) {
    let index = 0
    while (index < n) yield index++
}

const simpleReadline = async () => {
    let rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout,
    })
    let p = new Promise((resolve, reject) => {
        rl.question("", (answer) => {
            rl.close()
            resolve(answer)
        })
    })
    return p
}

const main = async () => {
    let n = (await simpleReadline()) * 1
    for await (i of range(n)) {
        let nums = (await simpleReadline()).split(" ").map((el) => el * 1)
        if (nums[0] % nums[1] === 0) {
            console.log("YES")
        } else {
            console.log("NO")
        }
    }
}

main()

const init = () => {
  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();
  });

  global.readline = () => {
    return inputString[currentLine++];
  };
};

if (typeof readline === 'undefined') {
  init();
}

const print = (...args) => {
  console.log(...args);
};

// Write your logic in main();
// let t = readline().split(' ').map(x => parseInt(x));
const main = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, m] = readline().split(' ').map(x => parseInt(x));
    print(Math.ceil(n / 2) === m ? 'YES' : 'NO');
  }
};


You are given an integer $$$n$$$.Let's define $$$s(n)$$$ as the string "BAN" concatenated $$$n$$$ times. For example, $$$s(1)$$$ = "BAN", $$$s(3)$$$ = "BANBANBAN". Note that the length of the string $$$s(n)$$$ is equal to $$$3n$$$.Consider $$$s(n)$$$. You can perform the following operation on $$$s(n)$$$ any number of times (possibly zero): Select any two distinct indices $$$i$$$ and $$$j$$$ $$$(1 \leq i, j \leq 3n, i \ne j)$$$. Then, swap $$$s(n)_i$$$ and $$$s(n)_j$$$. You want the string "BAN" to not appear in $$$s(n)$$$ as a subsequence. What's the smallest number of operations you have to do to achieve this? Also, find one such shortest sequence of operations.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \leq t \leq 100)$$$  — the number of test cases. The description of the test cases follows. The only line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$.

For each test case, in the first line output $$$m$$$ ($$$0 \le m \le 10^5$$$) — the minimum number of operations required. It's guaranteed that the objective is always achievable in at most $$$10^5$$$ operations under the constraints of the problem.  Then, output $$$m$$$ lines. The $$$k$$$-th of these lines should contain two integers $$$i_k$$$, $$$j_k$$$ $$$(1\leq i_k, j_k \leq 3n, i_k \ne j_k)$$$ denoting that you want to swap characters at indices $$$i_k$$$ and $$$j_k$$$ at the $$$k$$$-th operation.  After all $$$m$$$ operations, "BAN" must not appear in $$$s(n)$$$ as a subsequence.  If there are multiple possible answers, output any.

NoteIn the first testcase, $$$s(1) = $$$ "BAN", we can swap $$$s(1)_1$$$ and $$$s(1)_2$$$, converting $$$s(1)$$$ to "ABN", which does not contain "BAN" as a subsequence.In the second testcase, $$$s(2) = $$$ "BANBAN", we can swap $$$s(2)_2$$$ and $$$s(2)_6$$$, converting $$$s(2)$$$ to "BNNBAA", which does not contain "BAN" as a subsequence.

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)
        if (n == 1) {
            console.log(1)
            console.log(1, 2)
        } else {
            const m = parseInt((n+1)/2)
            console.log(m)
            for(let i = 1; i <= m; i++) {
                console.log(i * 3 - 1, (n+1-i)* 3)
            }
        }
    }
}

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();
	if(n==1) {
		console.log(1);
		console.log("1 3")
	} else {
		console.log(Math.ceil(n/2));
		for(var i=1;i<=Math.ceil(n/2);i++) console.log(`${(i*3)-1} ${(n-(i-1))*3}`);
	}
}

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++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    // const arr = Array(n).fill('BAN').join('').split('')
    const k = Math.floor(n / 2)
    const ans = []
    for (let i = 0; i < k; i++) {
        const j = n - 1 - i
        const a = 3 * i + 1
        const b = 3 * j + 2
        ans.push([a + 1, b + 1].join(' '))
        // ;[arr[a], arr[b]] = [arr[b], arr[a]]
    }
    if (n & 1) {
        const j = k
        const a = 3 * j + 1
        const b = 3 * j + 2
        ans.push([a + 1, b + 1].join(' '))
        // ;[arr[a], arr[b]] = [arr[b], arr[a]]
    }
    // console.log(arr.join(''))
    ans.unshift(ans.length)
    return ans.join('\n')
}

/*
* 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) {
    if(n%2 == 0) {
        print(n/2);
        let dis = (n/2) * 3 + 2;
        for(let i = 1; i <= n/2; i++) {
            print(`${(i - 1) * 3 + 1} ${(i - 1) * 3 + 1 + dis}`);
        }
    } else {
        print(Math.ceil(n/2));
        let dis = (n-1)/2 * 3 + 2;
        for(let i = 1; i <= Math.floor(n/2); i++) {
            print(`${(i - 1) * 3 + 1} ${(i - 1) * 3 + 1 + dis}`);
        }
        print(`${2} ${n*3}`);
    }

}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        begin(n);
    }
}

'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();
  if (n === 1) return `1\n1 2`;
  const res = [],
        str = 'BAN'.repeat(n).split('');
  for (let l = 0, r = str.length - 1; l < r; l++, r--) {
    while (l < r && str[l] !== 'B') {
      l++;
    }
    while (l < r && str[r] !== 'N') {
      r--;
    }
    if (l < r) {
      [str[l], str[r]] = [str[r], str[l]];
      res.push([l + 1, r + 1]);
    }
  }
  return `${res.length}\n${res.map(a => a.join(' ')).join('\n')}`;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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

// your code goes here

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

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

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

function start() {
    const T = parseInt(lines[0])
    let line = 1
    for (let t = 1; t <= T; t++) {
        const n = parseInt(lines[line++].split(' ')[0], 10)
        if (n == 1) {
            console.log(1)
            console.log(1, 2)
        } else {
            console.log(n-1)
            for(let i = 0; i < n-1; i++) {
                console.log(i == 0 ? 2 : i + 3, (i+2) * 3)
            }
        }
    }
}

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)
        if (n == 1) {
            console.log(1)
            console.log(1, 2)
        } else {
            console.log(n-1)
            for(let i = 0; i < n-1; i++) {
                console.log(i * 3 + 3, i * 3 + 4)
            }
        }
    }
}

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();
	if(n==1) {
		console.log(1);
		console.log("1 3")
	} else {
		console.log(n-1);
		for(var i=0;i<n-1;i++) console.log(`${(i*3)+2} ${(i*3)+6}`)
	}
}


You are given one integer number $$$n$$$. Find three distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$ and $$$a \cdot b \cdot c = n$$$ or say that it is impossible to do it.If there are several answers, you can print any.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$n$$$ lines describe test cases. The $$$i$$$-th test case is given on a new line as one integer $$$n$$$ ($$$2 \le n \le 10^9$$$).

For each test case, print the answer on it. Print "NO" if it is impossible to represent $$$n$$$ as $$$a \cdot b \cdot c$$$ for some distinct integers $$$a, b, c$$$ such that $$$2 \le a, b, c$$$. Otherwise, print "YES" and any possible such representation.

var T = parseInt(readline(), 10);

for(var t=1; t<=T; t++) {
    var n = parseInt(readline(), 10);
    var ok = false;
    var x=0,y=0,z=0;
    for(var a=2; !ok && a<=Math.sqrt(n); a++) {
        if(n%a != 0) continue;
        for(var b=a+1; !ok && b<=Math.sqrt(n); b++) {
            x = a; y = b; z = n/(a*b);
            if(z <= 1 || z == x || z == y || n%(x*y) != 0) continue;
            ok = true;
        }
    }
    if(ok) {
        print('YES');
        print(x,y,z);
    }
    else print('NO');
}

function solve (n){
	var found = 0;
	var stop = Math.floor(Math.sqrt(n));
	for(var i = 2; i <= stop; i++ )
	{
		if (n%i == 0)
		{
			if (found < 1){
				mySet.add(i);
				found+=1;
				n /= i;
			}
			else
			{
				mySet.add(i);
				if (n%i == 0){
				mySet.add(n/i);
				break
			}
			else{
				break;
			}
			}

		}
	}
	if (mySet.size == 3){
		print('YES');
		var interim = [...mySet]
		print(interim[0],interim[1],interim[2]);
	}
	else{
		print('NO');
	}
}
var mySet = new Set();
var queries = parseInt(readline())
for (var k =0 ;k <queries;k++){
solve(parseInt(readline()))
mySet.clear();
}

'use strict'

const problem = (n) => {
    for (let i = 2; i < Math.cbrt(n); i++) {
        if (n % i === 0) {
            n /= i;
            for (let j = i + 1; j < Math.sqrt(n); j++) {
                if (n % j === 0) return `YES\n${i} ${j} ${n/j}`;
            }
        }
    }
    return 'NO';
}

let t = +readline();
while(t--) print(problem(+readline()));

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
   var t = myconv(next(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(next(),1);
      var list = getDivisorList(n);
      var yesFlg = false;
      for(var j = 1; j < list.length -2; j++){
          if(yesFlg){break;}
          for(var k = j+1; k < list.length -1; k++){
              if(yesFlg){break;}
              for(var l = k+1; l < list.length; l++){
                  if(list[j] * list[k] * list[l] == n){
                      yesFlg = true;
                      output.push("YES");
                      output.push(list[j] + " " + list[k] + " " + list[l]);
                      break;
                  }
              }
          }
      }
      if(!yesFlg){
          output.push("NO");
      }

  }
  myout(myconv(output,9));
}
function getDivisorList(val){
        var list = [];
        for(var i = 1; i * i <= val; i++){
                if(val % i == 0){
                        list.push(i);
                        if(i * i != val){
                                list.push(val / i);
                        }
                }
        }
        list.sort(function(a,b){ return a - b; });
        return list;
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    findNext();
  }
}

function findNext() {
    var num = +readline();
    var n1 = findDiv(num);
    var n2;
    if (n1) {
        n2 = findDiv(num / n1, n1);
    }
    var n3;
    if (n1 && n2) {
        n3 = (num / n1) / n2
    }
    if (n1 && n2 && (n3 >= 2) && (n3 % 1 === 0) && n3 !== n1 && n3 !== n2) {
        print('YES');
        print(n1 + ' ' + n2 + ' ' + n3);
    } else {
        print('NO');
    }
};

function findDiv(n, ex1) {
    var sqrtN = Math.ceil(Math.sqrt(n));
    for (var i = 2; i < sqrtN; i += 1) {
        if (n % i === 0 && i !== ex1) {
            return i;
        }
    }
    return 0;
};

main()

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10), a = 0, b = 0, c = 0, rem, valid = false;

    for(var j=2; j<=Math.sqrt(n); j++) {
        if(n%j === 0) {
            a = j;
            rem = n/j;

            for(var k=j+1; k<=Math.sqrt(n); k++) {
                if(rem%k === 0) {
                    b = k;
                    c = rem/k;

                    if(b !== c) valid = true;

                    break;
                }
            }

            break;
        }
    }

    if(a === b || a === c || b === c) valid = false;
    else valid = true;

    if(valid) {
        print('YES');
        print(a, b, c);

    } else print('NO');
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function findPrimeFactors (num) {
  let primeFactors = [];
  while (num % 2 === 0) {
    primeFactors.push(2);
    num = num / 2;
  }

  let sqrtNum = Math.sqrt(num);
  for (let i = 3; i <= sqrtNum; i++) {
    while (num % i === 0) {
      primeFactors.push(i);
      num = num / i;
    }
  }

  if (num > 2) {
    primeFactors.push(num);
  }
  return primeFactors;
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  let i = 0
  const t = readInt(input, i++)

  for(let j = 0; j < t; j++) {
    const n = readInt(input, i++)

    let p = findPrimeFactors(n)
    let k = 0
    let a = 1, b = 1, c = 1
    let f = true
    if(p[k] === n) {
      wr('NO')
      continue
    }
    for(let len = p.length; k < len; k++) {
      if(k === 0) {
        a = p[k]
      }
      else if(b <= a) {
        b *= p[k]
      }
      else {
        c = n / (a * b)
        break
      }
    }
    if(a === 1 || b === 1 || c === 1 || (b === c) || (b <= a) || (a === c)) {
      wr('NO')
    }
    else {
      wr('YES')
      wr(`${a} ${b} ${c}`)
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function readint() {
    let line = readline().split(' ').map(function(num) {
        return parseInt(num);
    });
    return line;
}

function readfloat() {
    let line = readline().split(' ').map(function(num) {
        return parseFloat(num);
    });
    return line;
}

function print(x) {
    console.log(x);
}

function write(x) {
    process.stdout.write(x);
}
function main() {
    let t = parseInt(readline());
    //go go bro!!!
    while(t--) {
        let n = parseInt(readline());
        let a = 0,b = 0,c = 0;
        for(let i = 2; i*i < n; i++) {
            if(n % i == 0) {
                a = i;
                n = n / a;
                break;
            }
        }
        if(a==0) {
            print("NO");
            continue;
        }
        for(let i = a + 1; i*i < n; i++) {
            if(n % i == 0) {
                b = i;
                n = n / b;
                break;
            }
        }
        if(b==0) {
            print("NO");
            continue;
        }
        c = n;
        if(c != 1 && c != a && c != b) {
            print("YES");
            write(a + " " + b + " " + c + "\n");
            continue;
        } else {
            print("NO");
            continue;
        }
    }

}

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10), a, b, c, rem, valid = false;

    for(var j=2; j<=Math.sqrt(n); j++) {
        if(n%j === 0) {
            a = j;
            rem = n/j;

            for(var k=j+1; k<=Math.sqrt(n); k++) {
                if(rem%k === 0) {
                    b = k;
                    c = rem/k;
                    valid = true;
                    break;
                }
            }

            break;
        }
    }

    if(valid) {
        print('YES');
        print(a, b, c);

    } else print('NO');
}

var T = parseInt(readline(), 10);

for(var t=1; t<=T; t++) {
    var n = parseInt(readline(), 10);
    var ok = false;
    var x=0,y=0,z=0;
    for(var a=2; !ok && a<=2000; a++) {
        for(var b=a+1; !ok && b<=2000; b++) {
            x = a; y = b; z = n/(a*b);
            if(z <= 1 || z == x || z == y || n%(x*y) != 0) continue;
        }
    }
    if(ok) {
        print('YES');
        print(x,y,z);
    }
    else print('NO');
}

var T = parseInt(readline(), 10);

for(var t=1; t<=T; t++) {
    var n = parseInt(readline(), 10);
    var ok = false;
    var x=0,y=0,z=0;
    for(var a=2; !ok && a<=2000; a++) {
        for(var b=a+1; !ok && b<=2000; b++) {
            x = a; y = b; z = n/(a*b);
            if(z <= 1 || z == x || z == y || n%(x*y) != 0) continue;
            ok = true;
        }
    }
    if(ok) {
        print('YES');
        print(x,y,z);
    }
    else print('NO');
}

var T = parseInt(readline(), 10);

for(var t=1; t<=T; t++) {
    var n = parseInt(readline(), 10);
    var ok = false;
    var x=0,y=0,z=0;
    for(var a=2; !ok && a<=1000 && a<=n; a++) {
        for(var b=a+1; !ok && b<=1000 && b<=n/a; b++) {
            x = a; y = b; z = n/(a*b);
            if(n%(a*b)==0 && n != a*b && n/(a*b) != a && n/(a*b) != b) {
                ok = true;
            }
        }
    }
    if(ok) {
        print('YES');
        print(x,y,z);
    }
    else print('NO');
}

var T = parseInt(readline(), 10);

for(var t=1; t<=T; t++) {
    var n = parseInt(readline(), 10);
    var ok = false;
    for(var a=2; !ok && a<=1000 && a<=n; a++) {
        for(var b=a; !ok && b<=1000 && b<=n/a; b++) {
            if(n%(a*b)==0) ok = true;
        }
    }
    if(ok) print('YES');
    else print('NO');
}

function solve (n){
	var found = 0;
	for(var i = 2; i <= 10; i++ )
	{
		if (found == 2){
			break;
		}
		if (n%i == 0)
		{
			if (found < 1){
				mySet.add(i);
				found+=1;
				n /= i;
			}
			else
			{
				mySet.add(i);
				mySet.add(n/i);
				found +=1;
			}
		}
	}
	if (mySet.size == 3){
		print('YES');
		print([...mySet]);
	}
	else{
		print('NO');
	}
}
var mySet = new Set();
var queries = parseInt(readline())
for (var k =0 ;k <queries;k++){
solve(parseInt(readline()))
mySet.clear();
}

function solve (n){
	var found = 0;
	for(var i = 2; i <= 10; i++ )
	{
		if (found == 2){
			break;
		}
		if (n%i == 0)
		{
			if (found < 1){
				mySet.add(i);
				found+=1;
				n /= i;
			}
			else
			{
				mySet.add(i);
				mySet.add(n/i);
				found +=1;
			}
		}
	}
	if (mySet.size == 3){
		print('YES');
		var interim = [...mySet]
		print(interim[0],interim[1],interim[2]);
	}
	else{
		print('NO');
	}
}
var mySet = new Set();
var queries = parseInt(readline())
for (var k =0 ;k <queries;k++){
solve(parseInt(readline()))
mySet.clear();
}

function solve (n){
	var found = 0;
	for(var i = 2; i <= 10; i++ )
	{
		if (found == 2){
			break;
		}
		if (n%i == 0)
		{
			if (found < 1){
				mySet.add(i);
				found+=1;
				n /= i;
			}
			else
			{
				mySet.add(i);
				if (n/i != 1){
				mySet.add(n/i);
			}
				found +=1;
			}
		}
	}
	if (mySet.size == 3){
		print('YES');
		var interim = [...mySet]
		print(interim[0],interim[1],interim[2]);
	}
	else{
		print('NO');
	}
}
var mySet = new Set();
var queries = parseInt(readline())
for (var k =0 ;k <queries;k++){
solve(parseInt(readline()))
mySet.clear();
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
  var t = myconv(next(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(next(),1);
      var out = [];
      var tmpN = n;
      for(var j = 2; j <= Math.sqrt(n); j++){
          if(tmpN % j == 0){
              out.push(j);
              tmpN /= j;
          }
          if(out.length == 2){
            if(out[1] != tmpN && n % tmpN == 0){
              out.push(tmpN);
            }
            break;
          }
      }
      if(out.length == 3){
          output.push("YES");
          output.push(myconv(out,8));
      }else{
          output.push("NO");
      }
  }
  myout(myconv(output,9));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
  var t = myconv(next(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(next(),1);
      var out = [];
      var tmpN = n;
      for(var j = 2; j <= Math.sqrt(n); j++){
          if(n % j == 0){
              out.push(j);
              tmpN /= j;
          }
          if(out.length == 2){
            if(out[1] != tmpN){
              out.push(tmpN);
            }
            break;
          }
      }
      if(out.length == 3){
          output.push("YES");
          output.push(myconv(out,8));
      }else{
          output.push("NO");
      }
  }
  myout(myconv(output,9));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
   var t = myconv(next(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(next(),1);
      var out = [];
      var tmpN = n;
    var first = false;
      for(var j = 2; j <= Math.sqrt(n); j++){
          if(tmpN % j == 0 && !first){
              out.push(j);
              tmpN /= j;
            first = true;
              continue;
          }
        if(tmpN % j == 0 && n % (tmpN / j) == 0 && j != tmpN / j){
            out.push(j);
            out.push(tmpN / j);
            break;
          }
      }
      if(out.length == 3){
          output.push("YES");
          output.push(myconv(out,8));
      }else{
          output.push("NO");
      }
  }
  myout(myconv(output,9));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
  var t = myconv(next(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(next(),1);
      var out = [];
      var tmpN = n;
      for(var j = 2; j <= Math.sqrt(n); j++){
          if(n % j == 0){
              out.push(j);
              tmpN /= j;
          }
          if(out.length == 2){
            if(out[1] != tmpN && n % tmpN == 0){
              out.push(tmpN);
            }
            break;
          }
      }
      if(out.length == 3){
          output.push("YES");
          output.push(myconv(out,8));
      }else{
          output.push("NO");
      }
  }
  myout(myconv(output,9));
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main() {
   var t = myconv(next(),1);
  var output = [];
  for(var i = 0; i < t; i++){
      var n = myconv(next(),1);
      var out = [];
      var tmpN = n;
    var first = false;
      for(var j = 2; j <= Math.sqrt(n); j++){
          if(tmpN % j == 0 && !first){
              out.push(j);
              tmpN /= j;
            first = true;
              continue;
          }
        if(tmpN % j == 0){
          if(n % (tmpN / j) == 0){
            out.push(j);
            out.push(tmpN / j);
            break;
           }
          }
      }
      if(out.length == 3){
          output.push("YES");
          output.push(myconv(out,8));
      }else{
          output.push("NO");
      }
  }
  myout(myconv(output,9));
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    findNext();
  }
}

function findNext() {
    var num = +readline();
    var n1 = findDiv(num);
    var n2;
    if (n1) {
        n2 = findDiv(num / n1);
    }
    var n3;
    if (n1 && n2) {
        n3 = (num / n1) / n2;
    }
    if (n1 && n2 && (n3 >= 2) && (n3 % 1 === 0)) {
        print('YES');
        print(n1 + ' ' + n2 + ' ' + n3);
    } else {
        print('NO');
    }
};

function findDiv(n) {
    if (n % 2 === 0) {
        return 2;
    }
    var sqrtN = Math.ceil(Math.sqrt(n));
    for (var i = 3; i < sqrtN; i += 2) {
        if (n % i === 0) {
            return i;
        }
    }
    return 0;
};
main()

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10), a, b, c, rem, valid = false;

    for(var j=2; j<=Math.sqrt(n); j++) {
        if(n%j === 0) {
            a = j;
            rem = n/j;

            for(var k=j+1; k<=Math.sqrt(n); k++) {
                if(rem%k === 0) {
                    b = k;
                    c = rem/k;

                    if(b !== c) valid = true;

                    break;
                }
            }

            break;
        }
    }

    if(valid) {
        print('YES');
        print(a, b, c);

    } else print('NO');
}

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10), a = 0, b = 0, c = 0, rem, valid = false;

    for(var j=2; j<=Math.sqrt(n); j++) {
        if(n%j === 0) {
            a = j;
            rem = n/j;

            for(var k=j+1; k<=Math.sqrt(n); k++) {
                if(rem%k === 0) {
                    b = k;
                    c = rem/k;

                    if(b !== c) valid = true;

                    break;
                }
            }

            break;
        }
    }

    if(a === b || a === c || b === c) valid = false;
    else valid = true;

    if(valid) {
        print('YES');
        print(a, b, c, n);

    } else print('NO');
}

var t = parseInt(readline(), 10);

for(var i=1; i<=t; i++) {
    var n = parseInt(readline(), 10), a, b, c, rem, valid = false;

    for(var j=2; j<=Math.sqrt(n); j++) {
        if(n%j === 0) {
            a = j;
            rem = n/j;

            for(var k=j+1; k<=Math.sqrt(n); k++) {
                if(rem%k === 0) {
                    b = k;
                    c = rem/k;

                    if(b !== c) valid = true;

                    break;
                }
            }

            break;
        }
    }

    if(a === b || a === c || b === c) valid = false;
    else valid = true;

    if(valid) {
        print('YES');
        print(a, b, c);

    } else print('NO');
}


PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, if both play optimally?

The first input line contains two integers n and m (1 ≤ n, m ≤ 103) — number of words PolandBall and EnemyBall know, respectively. Then n strings follow, one per line — words familiar to PolandBall. Then m strings follow, one per line — words familiar to EnemyBall. Note that one Ball cannot know a word more than once (strings are unique), but some words can be known by both players. Each word is non-empty and consists of no more than 500 lowercase English alphabet letters.

In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally.

2 2
kremowka
wadowicka
kremowka
wiedenska

NoteIn the first example PolandBall knows much more words and wins effortlessly.In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins.

   var s = readline().split(' ');
   var n = +s[0], m = +s[1];
   var set = [], nw = 0, mw = 0, sh = 0;
   for (var i=0;i<n;i++)
   {
       s = readline();
       var index = set.indexOf(s);
       if (index==-1)
       {
           index = set.length;
           set.push(s);
       }
       nw++;
   }
   for (i=0;i<m;i++)
   {
       s = readline();
       var index = set.indexOf(s);
       if (index==-1)
       {
           index = set.length;
           set.push(s);
       }
       else sh++;
       mw++;
   }
   var h = 0;
   while(nw>0 && h==0 || mw>0 && h==1)
   {
       if (h)
       {
           mw--;
           if (sh){ sh--; nw--; }
       }
       else
       {
           nw--;
           if (sh){ sh--; mw--; }
       }
       h = 1 - h;
   }
   print(h ? 'YES' : 'NO');

var input = readline();
var aWordsCount = parseInt(input.split(" ")[0]);
var bWordsCount = parseInt(input.split(" ")[1]);

var aWords = readWordList(aWordsCount);
var bWords = readWordList(bWordsCount);
var commonWords = new Set(intersect(aWords, bWords));

var result = "YES";
var advantage = commonWords.size % 2 === 0 ? 0 : 1;
if (aWordsCount - commonWords.size + advantage <= bWordsCount - commonWords.size) {
    result = "NO";
}

print(result);

function readWordList(listLength) {
    var words = [];

    for (var i = 0; i < listLength; i++) {
        words.push(readline());
    }

    return words;
}

function intersect(a, b) {
    return a.filter(x => b.includes(x));
}

var input = readline();
var aWordsCount = parseInt(input.split(" ")[0]);
var bWordsCount = parseInt(input.split(" ")[1]);

var aWords = readWordList(aWordsCount);
var bWords = readWordList(bWordsCount);
var commonWords = new Set(intersect(aWords, bWords));
aWordsCount -= commonWords.size;
bWordsCount -= commonWords.size;

var result = "NO";
if (commonWords.size % 2 === 0) {
    if (aWordsCount > bWordsCount + 1) {
        result = "YES";
    }
} else if (aWordsCount > bWordsCount - 1) {
    result = "YES"
}

print(result);

function readWordList(listLength) {
    var words = [];

    for (var i = 0; i < listLength; i++) {
        words.push(readline());
    }

    return words;
}

function intersect(a, b) {
    return a.filter(x => b.includes(x));
}

var input = readline();
var aWordsCount = parseInt(input.split(" ")[0]);
var bWordsCount = parseInt(input.split(" ")[1]);

var aWords = readWordList(aWordsCount);
var bWords = readWordList(bWordsCount);
var commonWords = new Set(intersect(aWords, bWords));

aWords = aWords.sort((a, b) => {
    return sortByPresenceInSet(a, b, commonWords);
});
bWords = bWords.sort((a, b) => {
    return sortByPresenceInSet(a, b, commonWords);
});

var usedWords = new Set();
var roundsCount = Math.max(aWordsCount, bWordsCount) + 1;
var result = "YES";

for (var i = 0; i < roundsCount; i++) {
    var a = useWord(usedWords, aWords);
    if (!a) {
        result = "NO";
        break;
    }

    var b = useWord(usedWords, bWords);
    if (!b) {
        break;
    }
}

print(result);

function useWord(usedWords, availableWords) {
    if (!availableWords.length) {
        return false;
    }

    if (usedWords.has(availableWords[0])) {
        availableWords.splice(0, 1)
        return useWord(usedWords, availableWords);
    }

    usedWords.add(availableWords[0])

    return true;
}

function readWordList(listLength) {
    var words = [];

    for (var i = 0; i < listLength; i++) {
        words.push(readline());
    }

    return words;
}

function intersect(a, b) {
    return a.filter(x => b.includes(a));
}

function sortByPresenceInSet(a, b, set) {
    if (commonWords.has(a)) {
        return -1;
    };

    if (commonWords.has(b)) {
        return 1
    };

    return 0;
}

var input = readline();
var aWordsCount = parseInt(input.split(" ")[0]);
var bWordsCount = parseInt(input.split(" ")[1]);

var aWords = readWordList(aWordsCount);
var bWords = readWordList(bWordsCount);
var commonWords = new Set(intersect(aWords, bWords));

var result = "NO";
if (commonWords.size % 2 === 0 && aWordsCount >= bWordsCount) {
    result = "YES";
}

print(result);

function readWordList(listLength) {
    var words = [];

    for (var i = 0; i < listLength; i++) {
        words.push(readline());
    }

    return words;
}

function intersect(a, b) {
    return a.filter(x => b.includes(x));
}

var input = readline();
var aWordsCount = parseInt(input.split(" ")[0]);
var bWordsCount = parseInt(input.split(" ")[1]);

var aWords = [];
var bWords = [];

for (var i = 0; i < aWordsCount; i++) {
    aWords.push(readline());
}

for (var i = 0; i < bWordsCount; i++) {
    bWords.push(readline());
}

var usedWords = new Set();
var roundsCount = Math.max(aWordsCount, bWordsCount) + 1;
var result = "YES";

for (var i = 0; i < roundsCount; i++) {
    var a = useWord(usedWords, aWords);
    if (!a) {
        result = "NO";
        break;
    }

    var b = useWord(usedWords, bWords);
    if (!b) {
        break;
    }
}

print(result);

function useWord(usedWords, availableWords) {
    if (!availableWords.length) {
        return false;
    }

    if (usedWords.has(availableWords[0])) {
        availableWords.splice(0, 1)
        return useWord(usedWords, availableWords);
    }

    usedWords.add(availableWords[0])

    return true;
}