Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.The park can be represented as a connected graph with $$$n$$$ nodes and $$$m$$$ bidirectional edges. Initially Bob is at the node $$$1$$$ and he records $$$1$$$ on his notebook. He can wander from one node to another through those bidirectional edges. Whenever he visits a node not recorded on his notebook, he records it. After he visits all nodes at least once, he stops wandering, thus finally a permutation of nodes $$$a_1, a_2, \ldots, a_n$$$ is recorded.Wandering is a boring thing, but solving problems is fascinating. Bob wants to know the lexicographically smallest sequence of nodes he can record while wandering. Bob thinks this problem is trivial, and he wants you to solve it.A sequence $$$x$$$ is lexicographically smaller than a sequence $$$y$$$ if and only if one of the following holds:   $$$x$$$ is a prefix of $$$y$$$, but $$$x \ne y$$$ (this is impossible in this problem as all considered sequences have the same length);  in the first position where $$$x$$$ and $$$y$$$ differ, the sequence $$$x$$$ has a smaller element than the corresponding element in $$$y$$$.

The first line contains two positive integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$), denoting the number of nodes and edges, respectively. The following $$$m$$$ lines describe the bidirectional edges in the graph. The $$$i$$$-th of these lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$), representing the nodes the $$$i$$$-th edge connects. Note that the graph can have multiple edges connecting the same two nodes and self-loops. It is guaranteed that the graph is connected.

Output a line containing the lexicographically smallest sequence $$$a_1, a_2, \ldots, a_n$$$ Bob can record.

NoteIn the first sample, Bob's optimal wandering path could be $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 3$$$. Therefore, Bob will obtain the sequence $$$\{1, 2, 3\}$$$, which is the lexicographically smallest one.In the second sample, Bob's optimal wandering path could be $$$1 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 5$$$. Therefore, Bob will obtain the sequence $$$\{1, 4, 3, 2, 5\}$$$, which is the lexicographically smallest one.

"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};
function PriorityQueue(t,i){this._pq=[null].concat(t),this._cf=i||function(t,i){return t>i};for(let t=Math.floor(this._pq.length/2);t>=1;t--)this._maxHeapify(t)}PriorityQueue.prototype._parent=function(t){return Math.floor(t/2)},PriorityQueue.prototype._left=function(t){return 2*t},PriorityQueue.prototype._right=function(t){return 2*t+1},PriorityQueue.prototype._maxHeapify=function(t){(function t(i){let e=this._left(i),p=this._right(i),r=i;if(e<this._pq.length&&this._cf(this._pq[e],this._pq[i])&&(r=e),p<this._pq.length&&this._cf(this._pq[p],this._pq[r])&&(r=p),r!==i){let e=this._pq[i];this._pq[i]=this._pq[r],this._pq[r]=e,t.call(this,r)}}).call(this,t)},PriorityQueue.prototype.maximum=function(){return this._pq[1]},PriorityQueue.prototype.extractMax=function(){if(this._pq.length<=1)return;let t=this._pq[1];return this._pq[1]=this._pq[this._pq.length-1],this._pq.pop(),this._maxHeapify(1),t},PriorityQueue.prototype.increaseKey=function(t,i){let e=t;if(!this._pq[e]||this._cf(i,this._pq[e]))for(this._pq[e]=i;e>1&&!this._cf(this._pq[this._parent(e)],this._pq[e]);){let t=this._pq[e];this._pq[e]=this._pq[this._parent(e)],this._pq[this._parent(e)]=t,e=this._parent(e)}},PriorityQueue.prototype.insert=function(t){this._pq.push(null),this.increaseKey(this._pq.length-1,t)},PriorityQueue.prototype.size=function(t){return this._pq.length-1};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var m = o.a();

  var adj = [];
  for (var i = 1; i <= n; i++) {
    adj[i] = [];
  }

  for (var i = 0; i < m; i++) {
    var u = o.a();
    var v = o.a();
    adj[v].push(u);
    adj[u].push(v);
  }

  var pq = new PriorityQueue([], (a,b) => a < b);
  var mark = Array(n + 1).fill(0);
  var ans = [];

  mark[1] = 1;
  pq.insert(1);

  while (pq.size() > 0) {
    var cur = pq.extractMax();
    ans.push(cur);

    adj[cur].forEach(x => {
      if (mark[x] === 0) {
        mark[x] = 1;
        pq.insert(x);
      }
    });
  }

  console.log(ans.join(" "));
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  main(i)
})

"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};
function PriorityQueue(t,i){this._pq=[null].concat(t),this._cf=i||function(t,i){return t>i};for(let t=Math.floor(this._pq.length/2);t>=1;t--)this._maxHeapify(t)}PriorityQueue.prototype._parent=function(t){return Math.floor(t/2)},PriorityQueue.prototype._left=function(t){return 2*t},PriorityQueue.prototype._right=function(t){return 2*t+1},PriorityQueue.prototype._maxHeapify=function(t){(function t(i){let e=this._left(i),p=this._right(i),r=i;if(e<this._pq.length&&this._cf(this._pq[e],this._pq[i])&&(r=e),p<this._pq.length&&this._cf(this._pq[p],this._pq[r])&&(r=p),r!==i){let e=this._pq[i];this._pq[i]=this._pq[r],this._pq[r]=e,t.call(this,r)}}).call(this,t)},PriorityQueue.prototype.maximum=function(){return this._pq[1]},PriorityQueue.prototype.extractMax=function(){if(this._pq.length<=1)return;let t=this._pq[1];return this._pq[1]=this._pq[this._pq.length-1],this._pq.pop(),this._maxHeapify(1),t},PriorityQueue.prototype.increaseKey=function(t,i){let e=t;if(!this._pq[e]||this._cf(i,this._pq[e]))for(this._pq[e]=i;e>1&&!this._cf(this._pq[this._parent(e)],this._pq[e]);){let t=this._pq[e];this._pq[e]=this._pq[this._parent(e)],this._pq[this._parent(e)]=t,e=this._parent(e)}},PriorityQueue.prototype.insert=function(t){this._pq.push(null),this.increaseKey(this._pq.length-1,t)},PriorityQueue.prototype.size=function(t){return this._pq.length-1};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var m = o.a();

  var adj = [];
  for (var i = 1; i <= n; i++) {
    adj[i] = [];
  }

  for (var i = 0; i < m; i++) {
    var u = o.a();
    var v = o.a();
    adj[v].push(u);
    adj[u].push(v);
  }

  var pq = new PriorityQueue([], (a,b) => a < b);
  var mark = Array(n + 1).fill(0);
  var ans = [];

  pq.insert(1);
  mark[1] = 1;

  while (pq.size() > 0) {
    var cur = pq.extractMax();
    ans.push(cur);

    adj[cur].filter(x => mark[x] === 0).forEach(x => {
      pq.insert(x);
      mark[x] = 1;
    });
  }

  console.log(ans.join(" "));
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  main(i)
})


You are given an array $$$A$$$, consisting of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$, and an array $$$B$$$, consisting of $$$m$$$ positive integers $$$b_1, b_2, \dots, b_m$$$. Choose some element $$$a$$$ of $$$A$$$ and some element $$$b$$$ of $$$B$$$ such that $$$a+b$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. For example, if $$$A = [2, 1, 7]$$$ and $$$B = [1, 3, 4]$$$, we can choose $$$1$$$ from $$$A$$$ and $$$4$$$ from $$$B$$$, as number $$$5 = 1 + 4$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. However, we can't choose $$$2$$$ from $$$A$$$ and $$$1$$$ from $$$B$$$, as $$$3 = 2 + 1$$$ belongs to $$$B$$$.It can be shown that such a pair exists. If there are multiple answers, print any.Choose and print any such two numbers.

The first line contains one integer $$$n$$$ ($$$1\le n \le 100$$$) — the number of elements of $$$A$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 200$$$) — the elements of $$$A$$$. The third line contains one integer $$$m$$$ ($$$1\le m \le 100$$$) — the number of elements of $$$B$$$. The fourth line contains $$$m$$$ different integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le 200$$$) — the elements of $$$B$$$. It can be shown that the answer always exists.

Output two numbers $$$a$$$ and $$$b$$$ such that $$$a$$$ belongs to $$$A$$$, $$$b$$$ belongs to $$$B$$$, but $$$a+b$$$ doesn't belong to nor $$$A$$$ neither $$$B$$$. If there are multiple answers, print any.

NoteIn the first example, we can choose $$$20$$$ from array $$$[20]$$$ and $$$20$$$ from array $$$[10, 20]$$$. Number $$$40 = 20 + 20$$$ doesn't belong to any of those arrays. However, it is possible to choose $$$10$$$ from the second array too.In the second example, we can choose $$$3$$$ from array $$$[3, 2, 2]$$$ and $$$1$$$ from array $$$[1, 5, 7, 7, 9]$$$. Number $$$4 = 3 + 1$$$ doesn't belong to any of those arrays.In the third example, we can choose $$$1$$$ from array $$$[1, 3, 5, 7]$$$ and $$$1$$$ from array $$$[7, 5, 3, 1]$$$. Number $$$2 = 1 + 1$$$ doesn't belong to any of those arrays.

var n = readline();
var a = readline().split(" ").map(function(x) { return parseInt(x); });;
var m = readline();
var b = readline().split(" ").map(function(x) { return parseInt(x); });;

var flag = 0;
for (var i = 0; i < n; i++) {
    for (var j = 0; j < m; j++) {

        var sum = parseInt(a[i]) + parseInt(b[j]);
        if(!a.includes(sum) && !b.includes(sum)){
            print(a[i] + ' ' + b[j]);
            flag = 1;
            break;
        }
        else
            continue;
    }
    if(flag == 1)
        break;
}

function input() {
  return [
    parseInt(readline().trim()),
    readline()
      .trim()
      .split(" ")
      .map(function(i) {
        return parseInt(i);
      }),
    parseInt(readline().trim()),
    readline()
      .trim()
      .split(" ")
      .map(function(i) {
        return parseInt(i);
      })
  ];
}

function main() {
  // get input
  var read = input();
  var a = read[1];
  var b = read[3];

  var done = false;

  a.forEach(function(i) {
    if (done) return 0;
    b.forEach(function(j) {
      if (done) return 0;
      if (a.indexOf(i + j) < 0 && b.indexOf(i + j) < 0) {
        print(i, j);
        done = true;
      }
    });
  });
}

main();

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

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var a = rdArN().sortGt()[0];
    var m = rdN();
    var b = rdArN().sortGt()[0];
    wr(a, b);

};

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

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

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN();
    var m = rdN();
    var B = rdArN();
    for (var i = 0; i < n; ++i) {
        for (var j = 0; j < m; ++j) {
            var s = A[i] + B[j];
            if (A.indexOf(s) === -1 && B.indexOf(s) === -1) {
                wr(A[i], B[j]);
                return;
            }
        }
    }
};

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

//var input = readline()

var Max = -9, MAX =-9;
var t = parseInt(readline());
var ar = readline().split(' ').map(x => parseInt(x));
Max = Math.max(...ar);

var k = parseInt(readline());
var arr = readline().split(' ').map(x => parseInt(x));
MAX = Math.max(...arr);

print(Max +' ' + MAX);

//

var a = parseInt(readline().trim());
var numbers1 = readline().trim().split(" ").map(function(x) { return parseInt(x); });
var mx1 = Math.max.apply(null, numbers1);
var b = parseInt(readline().trim());
var numbers2 = readline().trim().split(" ").map(function(x) { return parseInt(x); });
var mx2 = Math.max.apply(null, numbers2);
print(mx1 + " " + mx2);

var n = Number(readline());
var a = readline();
a = a.split(' ');
a = a.map((x) => Number(x));
var m = Number(readline());
var b = readline();
b = b.split(' ');
b = b.map((x) => Number(x));
a.sort((x, y) => x - y);
b.sort((x, y) => x - y);
print(String(a[n - 1]) + " " + String(b[m - 1]));

function main() {
    const [n, a, m, b] = stdin;
    const A = a.split(' ').map(Number);
    const B = b.split(' ').map(Number);
    const C = new Set(A.concat(B));
    for (let i = 0; i < A.length; i++) {
        for (let j = 0; j < B.length; j++) {
            if (!C.has(A[i] + B[j])) {
                console.log(A[i], B[j]);
                return
            }
        }
    }
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

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

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var alist = nextIntArray();
  var M = nextInt();
  var blist = nextIntArray();
  for(var i = 0; i < N; i++){
    for(var j = 0; j < M; j++){
      var sum = alist[i] + blist[j];
      if(alist.indexOf(sum) == -1 && blist.indexOf(sum) == -1){
        myout(alist[i] + " " + blist[j]);
        return;
      }
    }
  }
}

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 processData = (lines) => {
  const [n, a, m, b] = lines

  const A = a.split(' ').map(n => Number(n))
  const B = b.split(' ').map(n => Number(n))

  const C = new Set(A.concat(B))

  for (let i = 0; i < A.length; i++) {
    for (let j = 0; j < B.length; j++) {
      if (!C.has(A[i] + B[j])) {
        console.log(A[i], B[j])
        return
      }
    }
  }
}

let input ='';

process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data',(data)=>input+=data)
process.stdin.on('end',()=>{
   input = input.split('\n')
   let maxA = 0;
   input[1].split(' ').forEach((item)=>{
		item = parseInt(item)
		if(item>maxA) maxA = item
		})
  let maxB = 0;
  input[3].split(' ').forEach((item)=>{
        item = parseInt(item)
		if(item>maxB) maxB = item
		})
    console.log(maxA,maxB)

})

const readline = require('readline');

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

let len1, len2, arr1 = [], arr2 = []

rl.question('', (answer) => {
  len1 = Number(answer);
  rl.question('', (answer) => {
    arr1 = (answer.split(' ').slice(0, len1)).map((x) => Number(x))

    rl.question('', (answer) => {
      len2 = Number(answer);
      rl.question('', (answer) => {
        arr2 = (answer.split(' ').slice(0, len2)).map((x) => Number(x));
        //here call function
        console.log(check(arr1, arr2).join(' '));
      })
    });

  })
});

function check(a, b) {
//   console.log('*************');
//   console.log(arr1);
//   console.log(arr2);
  for (let i = 0; i < a.length; i++) {
    for (let k = 0; k < b.length; k++) {
      const sum = a[i] + b[k]
      if (!a.includes(sum) && !b.includes(sum)) {
        return [a[i], b[k]]
      }
    }
  }
  return [];
}

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

rl.on('line', (d) => {
  if (c === 1) {
    a = d.split(' ').map(Number).sort((a, b) => b - a)[0];
  }

  if (c === 3) {
    b = d.split(' ').map(Number).sort((a, b) => b - a)[0];
  }

  c++;
});

rl.on('close', () => {
  console.log(a, b);
});

const readline = require('readline');

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

rl.question('', function (arr1Size) {
  rl.question('', function (arr1) {
    rl.question('', function (arr2Size) {
      rl.question('', function (arr2) {
        let notBelongs = [];
        arr1 = arr1.split(' ').map(Number)
        arr2 = arr2.split(' ').map(Number)
        arr1Size = Number(arr1Size)
        arr2Size = Number(arr2Size)
        arr1.map(aNum => {
          arr2.map(bNum => {
            if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {
              notBelongs.push([aNum, bNum]);
            }
          });
        });
        console.log(notBelongs[0].join(' ').trim())
      });
    });
  });
});

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    const f = parseInt(readLine().split(' '), 10)

    const firstL = readLine().split(' ').map(item => parseInt(item,10))
   const s = parseInt(readLine().split(' '), 10)
    const secondL = readLine().split(' ').map(item => parseInt(item,10))

    let uniqueSum = 0

    for(let i = 1; i < f ; i++){
        let current = firstL[i]
        let index = i

        while(index >= 0 && current < firstL[index - 1]){
            firstL[index] = firstL[index - 1]
            index--
        }
        firstL[index] = current
    }
    for(let j = 1; j < s; j++){
        let current = secondL[j];
        let index = j;

        while(index >= 0 && current < secondL[index -1 ]){
            secondL[index] = secondL[index -1 ];
            index--
        }
    }

    let array = [firstL.pop(), secondL.pop()];

    console.log(array.join(' '))

}

var n = readline();
var a = readline().split(' ');
var m = readline();
var b = readline().split(' ');
var flag = 0;
for (var i = 0; i < n; i++) {
    for (var j = 0; j < m; j++) {

        var sum = parseInt(a[i]) + parseInt(b[j]);
        if(!a.includes(sum) || !b.includes(sum)){
            print(a[i] + ' ' + b[j]);
            flag = 1;
            break;
        }
        else
            continue;
    }
    if(flag == 1)
        break;
}

var n = readline();
var a = readline().split(' ');
var m = readline();
var b = readline().split(' ');
var flag = 0;
for (var i = 0; i < n; i++) {
    for (var j = 0; j < m; j++) {

        var sum = parseInt(a[i]) + parseInt(b[j]);
        if(!a.includes(sum) && !b.includes(sum)){
            print(a[i] + ' ' + b[j]);
            flag = 1;
            break;
        }
        else
            continue;
    }
    if(flag == 1)
        break;
}

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

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN();
    var m = rdN();
    var B = rdArN();
    for (var i = 0; i < n; ++i) {
        for (var j = 0; j < m; ++j) {
            var s = A[i] + B[j];
            if (A.indexOf(s) === -1 && B.indexOf(s) === -1) {
                wr(A[i], B[i]);
                return;
            }
        }
    }
};

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

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

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN();
    var m = rdN();
    var B = rdArN();
    for (var i = 0; i < n; ++i) {
        for (var j = i; j < m; ++j) {
            var s = A[i] + B[j];
            if (A.indexOf(s) === -1 && B.indexOf(s) === -1) {
                wr(A[i], B[i]);
                return;
            }
        }
    }
};

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

var n = Number(readline());
var a = readline();
a = a.split(' ');
a = a.map((x) => Number(x));
var m = Number(readline());
var b = readline();
b = b.split(' ');
b = b.map((x) => Number(x));
a.sort((x) => Number(x));
b.sort((x) => Number(x));
print(String(a[n - 1]) + " " + String(b[m - 1]));

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 processData = (lines) => {
  const [n, a, m, b] = lines

  const A = a.split(' ').map(n => Number(n))
  const B = b.split(' ').map(n => Number(n))

  const C = new Set(A.concat(B))

  for (let i = 0; i < A.length; i++) {
    for (let j = 0; j < B.length; j++) {
      if (C.has(A[i] + B[j])) {
        console.log(A[i], ' ', B[j])
        return
      }
    }
  }
}

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 processData = (lines) => {
  const [n, a, m, b] = lines

  const A = a.split(' ').map(n => Number(n))
  const B = b.split(' ').map(n => Number(n))

  const C = new Set(A.concat(B))

  for (let i = 0; i < A.length; i++) {
    for (let j = 0; j < B.length; j++) {
      if (!C.has(A[i] + B[j])) {
        console.log(A[i], ' ', B[j])
        return
      }
    }
  }
}

const readline = require('readline');

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

let len1, len2, arr1 = [], arr2 = []

rl.question('enter arr 1 length?', (answer) => {
  len1 = Number(answer);
  rl.question('enter arr 1 values?', (answer) => {
    arr1 = (answer.split(' ').slice(0, len1)).map((x) => Number(x))

    rl.question('enter arr 2 length?', (answer) => {
      len2 = Number(answer);
      rl.question('enter arr 2 values?', (answer) => {
        arr2 = (answer.split(' ').slice(0, len1)).map((x) => Number(x));
        //here call function
        console.log(check(arr1, arr2));
      })
    });

  })
});

function check(a, b) {
  for (let i = 0; i < a.length; i++) {
    for (let k = 0; k < b.length; k++) {
      const sum = a[i] + b[k]
      if (!a.includes(sum) && !b.includes(sum)) {
        return [a[i], b[k]]
      }
    }
  }
  return [];
}

const readline = require('readline');

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

let len1, len2, arr1 = [], arr2 = []

rl.question('', (answer) => {
  len1 = Number(answer);
  rl.question('', (answer) => {
    arr1 = (answer.split(' ').slice(0, len1)).map((x) => Number(x))

    rl.question('', (answer) => {
      len2 = Number(answer);
      rl.question('', (answer) => {
        arr2 = (answer.split(' ').slice(0, len1)).map((x) => Number(x));
        //here call function
        console.log(check(arr1, arr2).join(' '));
      })
    });

  })
});

function check(a, b) {
  for (let i = 0; i < a.length; i++) {
    for (let k = 0; k < b.length; k++) {
      const sum = a[i] + b[k]
      if (!a.includes(sum) && !b.includes(sum)) {
        return [a[i], b[k]]
      }
    }
  }
  return [];
}

const readline = require('readline');

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

rl.question('arr1Size ? ', function (arr1Size) {
  rl.question('arr1 ? ', function (arr1) {
    rl.question('arr2Size ? ', function (arr2Size) {
      rl.question('arr2 ? ', function (arr2) {
          console.log(arr1Size,arr1 ,arr2Size,arr2, "wwww")
        let notBelongs = [];
        arr1 = arr1.split(' ').map(Number)
        arr2 = arr2.split(' ').map(Number)
        arr1Size = Number(arr1Size)
        arr2Size = Number(arr2Size)
        arr1.map(aNum => {
          arr2.map(bNum => {
            if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {
              notBelongs.push([aNum, bNum]);
            }
          });
        });
        console.log(notBelongs[0].join(' ').trim())
      });
    });
  });
});

const readline = require('readline');

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

rl.question('arr1Size ? ', function (arr1Size) {
  rl.question('arr1 ? ', function (arr1) {
    rl.question('arr2Size ? ', function (arr2Size) {
      rl.question('arr2 ? ', function (arr2) {
        let notBelongs = [];
        arr1 = arr1.split(' ').map(Number)
        arr2 = arr2.split(' ').map(Number)
        arr1Size = Number(arr1Size)
        arr2Size = Number(arr2Size)
        arr1.map(aNum => {
          arr2.map(bNum => {
            if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {
              notBelongs.push([aNum, bNum]);
            }
          });
        });
        console.log(notBelongs[0].join(' ').trim())
      });
    });
  });
});

const readline = require('readline');

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

rl.question('arr1Size ? ', function (arr1Size) {
  rl.question('arr1 ? ', function (arr1) {
    rl.question('arr2Size ? ', function (arr2Size) {
      rl.question('arr2 ? ', function (arr2) {
          console.log(arr1Size,arr1 ,arr2Size,arr2, "wwww")
        let notBelongs = [];
        arr1 = arr1.split(' ').map(Number)
        arr2 = arr2.split(' ').map(Number)
        arr1.map(aNum => {
          arr2.map(bNum => {
            if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {
              notBelongs.push([aNum, bNum]);
            }
          });
        });
        console.log(notBelongs[0].join(' ').trim())
      });
    });
  });
});

const readline = require('readline');

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

rl.question('arr1Size ? ', function (arr1Size) {
  rl.question('arr1 ? ', function (arr1) {
    rl.question('arr2Size ? ', function (arr2Size) {
      rl.question('arr2 ? ', function (arr2) {
          console.log(arr1Size,arr1 ,arr2Size,arr2, "wwww")
        let notBelongs = [];
        arr1 = arr1.split(' ').map(Number)
        arr2 = arr2.split(' ').map(Number)
        arr1.map(aNum => {
          arr2.map(bNum => {
            if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {
              notBelongs.push([aNum, bNum]);
            }
          });
        });
        console.log(notBelongs[0]);
        return
      });
    });
  });
});

const readline = require('readline');

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

rl.question('arr1Size ? ', function (arr1Size) {
  rl.question('arr1 ? ', function (arr1) {
    rl.question('arr2Size ? ', function (arr2Size) {
      rl.question('arr2 ? ', function (arr2) {
          console.log(arr1Size,arr1 ,arr2Size,arr2, "wwww")
        let notBelongs = [];
        arr1 = arr1.split(' ').map(Number)
        arr2 = arr2.split(' ').map(Number)
        arr1.map(aNum => {
          arr2.map(bNum => {
            if (!arr1.includes(aNum + bNum) && !arr2.includes(aNum + bNum)) {
              notBelongs.push([aNum, bNum]);
            }
          });
        });
        notBelongs[0].join(' ').trim()
      });
    });
  });
});

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    const f = parseInt(readLine().split(' '), 10)

    const firstL = readLine().split(' ').map(item => parseInt(item,10))
   const s = parseInt(readLine().split(' '), 10)
    const secondL = readLine().split(' ').map(item => parseInt(item,10))

    let uniqueSum = 0

    for(let i = 1; i < f ; i++){
        let current = firstL[i]
        let index = i

        while(index >= 0 && current < firstL[index - 1]){
            firstL[index] = firstL[index - 1]
            index--
        }
        firstL[index] = current
    }
    for(let j = 1; j < s; j++){
        let current = secondL[j];
        let index = j;

        while(index >= 0 && current < secondL[index -1 ]){
            secondL[index] = secondL[index -1 ];
            index--
        }
    }

    uniqueSum = firstL.pop() + secondL.pop()
    console.log(uniqueSum)

}


Given a sequence $$$a_1, a_2, \ldots, a_n$$$, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every $$$2$$$ consecutive elements is even.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2,\dots,a_n$$$ ($$$1\leq a_i\leq10^9$$$) — elements of the sequence. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every $$$2$$$ consecutive elements is even.

NoteIn the first test case, after removing $$$3$$$, the sequence becomes $$$[2,4,6,8]$$$. The pairs of consecutive elements are $$$\{[2, 4], [4, 6], [6, 8]\}$$$. Each consecutive pair has an even sum now. Hence, we only need to remove $$$1$$$ element to satisfy the condition asked.In the second test case, each consecutive pair already has an even sum so we need not remove any element.

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]

    var e = 0
    for(j =1; j <= n * 2;j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
            var even = 0
            var odd = 0
            var k = lines[j].split(' ').map(Number)
            for(l = 0; l < e; l++){
                if(k[l] % 2 === 0){
                    even++
                }else{
                    odd++
                }
            }
            console.log(Math.min(odd, even))
        }
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
        var a = 0
        var b = 0
        var k = lines[j].split(' ').map(Number)
        for(l = 0; l < e; l++){
            if(k[l] % 2 == 1){
                a ++
            }else{
                b++
            }
        }
                console.log(Math.min(a,b))

        }
    }

});

//Bismillah
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

//started here

function main() {

  let t = parseInt(readline());

while (t--) {
  let n = parseInt(readline());
  let m = readline()
    .split(" ")
    .map((x) => parseInt(x));
  let result;
  let even = [];
  let odd = [];
  for (let i = 0; i < m.length; i++) {
    if (m[i] % 2 == 0) {
      even.push(m[i]);
    } else {
      odd.push(m[i]);
    }
  }

  if (even.length === 0 || odd.length === 0) {
    result = 0;
  } else if (odd.length > even.length) {
    result = even.length;
  } else if (even.length > odd.length) {
    result = odd.length;
  } else if (odd.length === even.length) {
    result = even.length;
  }

  console.log(result);
}

}

//Bismillah
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  let t = parseInt(readline());

while (t--) {
  let n = parseInt(readline());
  let m = readline()
    .split(" ")
    .map((x) => parseInt(x));
  let result;
  let even = [];
  let odd = [];
  for (let i = 0; i < m.length; i++) {
    if (m[i] % 2 == 0) {
      even.push(m[i]);
    } else {
      odd.push(m[i]);
    }
  }

  if (even.length === 0 || odd.length === 0) {
    result = 0;
  } else if (odd.length > even.length) {
    result = even.length;
  } else if (even.length > odd.length) {
    result = odd.length;
  } else if (odd.length === even.length) {
    result = even.length;
  }

  console.log(result);
}

}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            var a = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 0; j < n; j++){
                if(a[j] % 2 == 1){
                    ans++;
                }
            }
            console.log(Math.min(ans, n - ans));
        }
    }
});

let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i];
        }else{
            var k = lines[i].split(' ').map(Number);
            var od = 0;
            var ev = 0;
            for(j = 0; j < e; j++){
                if(k[j] % 2 == 1){
                    od++;
                }else{
                    ev++;
                }
            }
            console.log(Math.min(od, ev));
        }
    }
});

'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++) {
        readline();
        let arr = readline().split(' ').map(Number);

        let odd = arr.filter(x => x % 2 === 1).length;
        let even = arr.filter(x => x % 2 === 0).length;

        if (odd > even) {
            output(arr.length - odd);
        } else {
            output(arr.length - even);
        }
    }
}

const readline = require('readline');

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

conIO.setPrompt('');

function reallyAwkward(n) {
    conIO.once('line', () => {
        conIO.once('line', arr => {
            arr = arr.split(' ');
            let oddCnt = 0, evenCnt = 0;
            arr.forEach(x => x % 2 === 0 ? ++evenCnt : ++oddCnt);
            console.log(Math.min(oddCnt, evenCnt));
            if (n != 1)
                reallyAwkward(n - 1);
            else conIO.close();
        });
    });
}

conIO.once('line', n => {
    reallyAwkward(n);
});

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n] = ra();
  let A = ra();
  LT({n, A});
  // PROCESSING:
  let ans1 = 0;
  let ans2 = 0;
  for (let i=0; i<n; i++){
    if (A[i]%2){
      ans1++;
    } else
      ans2++;
  }

  return Math.min(n-ans1, n-ans2);
};

/**
 * Format:
 * {type: 'number', namedVariable?: string }
 * {type: 'repeat', instructionCount: number, count: number, namedVariable?: string }
 * {type: 'array', namedVariable?: string }
 */
const readline = require('readline');

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

  let resolvePromise = null;
  const donePromise = new Promise((res, rej) => {
    resolvePromise = res;
  });

  function waitUntilDone() {
    return donePromise;
  }

  /**
   * {type: 'repeat', count: number, iteration: number, basePointer: number, pointer: number, instructionCount: number, context: array }
   */
  const stack = [];
  let pc = -1;

  function finished() {
    if (pc >= instructions.length) {
      return true;
    }
    return false;
  }

  function checkFinished() {
    // console.log(`Finish check ${pc}, ${JSON.stringify(stack)}, ${pc >= instructions.length}, ${stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1}`);
    if (pc >= instructions.length) {
      return true;
    }
    if (stack.length === 1 && stack[0].pointer === stack[0].instructionCount && stack[0].count === stack[0].iteration + 1) {
      return true;
    }
    return false;
  }

  function getNextInstructionContext() {
    if (!stack.length) {
      return {
        index: ++pc,
      }
    }
    const lastStack = stack[stack.length - 1];
    if (lastStack.pointer === lastStack.instructionCount) {
      lastStack.pointer = 0;
      lastStack.iteration = lastStack.iteration + 1;
    }
    if (lastStack.count === lastStack.iteration) {
      stack.pop();
      pc = lastStack.basePointer + lastStack.instructionCount + 1;
      return {
        index: pc,
      }
    }

    lastStack.pointer = lastStack.pointer + 1;
    return {
      index: lastStack.basePointer + lastStack.pointer,
      context: {
        namedPath: [...lastStack.context.namedPath, lastStack.iteration]
      }
    }
  }

  function pushRepeatToStack(instruction, index, context) {
    stack.push({
      type: 'repeat',
      count: typeof instruction.count === 'number' ? instruction.count : context && context.namedPath ? getIn(mappedVariables, [...context.namedPath, instruction.count]) : mappedVariables[instruction.count],
      iteration: 0,
      basePointer: index,
      pointer: 0,
      instructionCount: instruction.instructionCount,
      context: {
        namedPath: context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable],
      }
    })
    setIn(mappedVariables, context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable], []);
  }

  function nextInstruction() {
    if (finished()) {
      // console.warn('Calling nextInstruction after finished, something is wrong');
      return;
    }
    while (true) {
      const { index, context } = getNextInstructionContext();
      const instruction = instructions[index];

      // console.log(`Debugging: ${index}, ${JSON.stringify(context)}, ${JSON.stringify(instruction)}`);
      switch (instruction.type) {
        case 'number':
        case 'array':
          return {
            ...instruction,
            namedPath: instruction.namedVariable ? context && context.namedPath ? [...context.namedPath, instruction.namedVariable] : [instruction.namedVariable] : undefined,
          }
        case 'repeat':
          pushRepeatToStack(instruction, index, context);
          break;
        default:
          // console.warn('Unclear instruction, abort');
          return;
      }
    }
  }

  function getIn(object, path) {
    for (let i = 0; i < path.length; ++i) {
      object = object[path[i]];
    }
    return object;
  }

  function setIn(object, path, value) {
    for (let i = 0; i < path.length - 1; ++i) {
      if (object[path[i]] == null) {
        object[path[i]] = {};
      }
      object = object[path[i]];
    }
    object[path[path.length - 1]] = value;
  }

  rl.on('line', line => {
    if (finished()) {
      return;
    }
    const { type, namedPath } = nextInstruction();
    switch (type) {
      case 'number':
        if (namedPath) {
          setIn(mappedVariables, namedPath, parseInt(line));
        }
        break;
      case 'array':
        if (namedPath) {
          setIn(mappedVariables, namedPath, line.trim().split(' ').map(x => parseInt(x)));
        }
        break;
      default:
        // console.warn(`Value unread, received type ${type}.`);
    }

    if (checkFinished()) {
      resolvePromise(mappedVariables);
      rl.close();
    }
  });
  return {
    waitUntilDone,
  };
}

function solve({numbers}) {
  if (numbers.length === 1) {
    return 1;
  } else if (numbers.length === 2) {
    return (numbers[0] + numbers[1]) % 2 === 0 ? 0 : 2;
  }

  /**
   * Min case:
   * 1 2 3
   * [0, 1, 2] length = 3
   */

  const chunks = [0];
  for (let i = 1; i < numbers.length; ++i) {
    if ((numbers[i] + numbers[i - 1]) % 2 !== 0) {
      chunks.push(i);
    }
  }
  let firstSum = 0;
  for (let i = 0; i < chunks.length; i = i + 2) {
    if (i === chunks.length - 1) {
      firstSum = firstSum + numbers.length - chunks[i];
    } else {
      firstSum = firstSum + chunks[i + 1] - chunks[i];
    }
  }

  let secondSum = 0;
  for (let i = 1; i < chunks.length; i = i + 2) {
    if (i === chunks.length - 1) {
      secondSum = secondSum + numbers.length - chunks[i];
    } else {
      secondSum = secondSum + chunks[i + 1] - chunks[i];
    }
  }

  return Math.min(firstSum, secondSum);
}
(async function main() {
  const reader = createCLIReader([
    { type: 'number', namedVariable: 'numberOfTestCase' },
    { type: 'repeat', instructionCount: 2, count: 'numberOfTestCase', namedVariable: 'testCase' },
    { type: 'number', namedVariable: 'testCaseLength' },
    { type: 'array', namedVariable: 'numbers' }
  ]);
  const schema = await reader.waitUntilDone();

  for (let i = 0; i < schema.numberOfTestCase; ++i) {
    console.log(solve(schema.testCase[i]));
  }
})();

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {

     let t = readSingleInt();
     while(t--)
     {
         let n = readSingleInt();
         let ar = readIntArray();
         let cnt =0;
         ar.forEach(n=> cnt += n&1)
         console.log(Math.min(n-cnt,cnt));

     }

}

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

let input = [];
rl.on("line", function (line) {
  input.push(line);
}).on("close", function () {
  solution(input);
  process.exit();
});

function solution(_input) {
  const input = _input[Symbol.iterator]();
  const T = Number(input.next().value);
  const results = [];
  for (let tc = 0; tc < T; tc++) {
    const N = Number(input.next().value);
    const A = input.next().value.split(" ").map(Number);
    const evenCnt = A.reduce((acc, v) => acc + ((v & 1) === 0 ? 1 : 0), 0);
    const oddCnt = N - evenCnt;
    results.push(Math.min(N - evenCnt, N - oddCnt));
  }
  console.log(results.join("\n"));
}

function solve() {
   const n = Number(read());
   const a = readArray(Number);
   let oddCount = 0;
   for (let i = 0; i < n; i++) {
      if (a[i] & 1) {
         oddCount++;
      }
   }
   write(Math.min(oddCount, n - oddCount));
}

function init() {
   try {
      var T = 1;
      T = Number(read());
      for (var t = 0; t < T; t++) {
         solve();
      }
   } catch (e) {
      write(e + e.stack);
   }
}

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

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

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

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

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

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');

   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

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

'use strict';

function solve(n, a) {
  let odd = 0,
      even = 0;
  for (let num of a) {
    if (num & 1) odd++;else even++;
  }
  return Math.min(odd, even);
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res.push(solve(n, a));
    }
    console.log(res.join('\n'));
  } catch (error) {
    console.log(error);
  }
}

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

var t = readline();
for(var i = 0 ; i < t ; i++){
    var n = readline(),
        a = readline().split(' ') ,
        eCounter = 0 , oCounter = 0;
        for(var j = 0 ; j < n ; j++){
            if(a[j]%2 === 0 ){
                eCounter++;
            }
            else{
                oCounter++;
            }
        }
        if(oCounter > eCounter){
            print(eCounter);
        }
        else{
            print(oCounter);
        }
}

T = readline()
while (T--) {
   n = readline()
   x = readline().split(' ').map(x => +x)
   sumOne = 0
   sumTwo = 0
   for(i=0; i<n; i++){
      if(x[i] %2 != 0)
         sumOne++
      else
         sumTwo++
   }
   if(sumOne < sumTwo)
      print(sumOne)
   else
      print(sumTwo)
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var even = 0
    var odd = 0
    var e = 0
    for(j =1; j <= n * 2;j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
            var k = lines[j].split(' ').map(Number)
            for(l = 0; l < e; l++){
                if(k[l] % 2 === 0){
                    even++
                }else{
                    odd++
                }
            }
            console.log(Math.min(odd, even))
        }
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
        var a = 0
        var k = lines[j].split(' ').map(Number)
        for(l = 0; l < e; l++){
            if(k[l] % 2 == 1){
                a ++
            }
        }
                console.log(a)

        }
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
        var a = 0
        var k = lines[j].split(' ').map(Number)
        for(l = 0; l < e; l++){
            if(k % 2 == 1){
                a ++
            }
        }
                console.log(a)

        }
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    var e = 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
        var a = 0
        var k = lines[j].split(' ').map(Number)
        for(l = 0; l < e; l++){
            if(k % 2 == 1){
                a ++
            }
        }
        }
        console.log(a)
    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0

    for(j = 1; j <= n * 2; j++){
        if(j % 2 === 0){
        var s = 0
        var a = lines[j].split(' ').map(Number)
        for(k = 0; k < e; k++){
            if(a[k] % 2 == 1 && a[k + 1] % 2 === 0 || a[k] % 2 === 0 && a[k + 1] % 2 == 1  ){
                s++
                k++
            }else{
                continue;
            }
        }
        console.log(s)
        }else{
            e = lines[j]
        }
    }
});

//Bissmillah.
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

let t = parseInt(readline());

while (t--) {
  let n = parseInt(readline());
  let m = readline()
    .split(" ")
    .map((x) => parseInt(x));
  let result;
  let even = [];
  let odd = [];
  for (let i = 0; i < m.length; i++) {
    if (m[i] % 2 == 0) {
      even.push(m[i]);
    } else {
      odd.push(m[i]);
    }
  }

  if (even.length === 0 || odd.length === 0) {
    result = 0;
  } else if (even.length > odd.length) {
    result = odd.length;
  } else {
    result = 0;
  }

  console.log(result);
}

}

//Bissmillah.
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

let t = parseInt(readline());

while (t--) {
  let n = parseInt(readline());
  let m = readline()
    .split(" ")
    .map((x) => parseInt(x));
  let result;
  let even = [];
  let odd = [];
  for (let i = 0; i < m.length; i++) {
    if (m[i] % 2 == 0) {
      even.push(m[i]);
    } else {
      odd.push(m[i]);
    }
  }

  if (even.length === 0 || odd.length === 0) {
    result = 0;
  } else if (odd.length > even.length) {
    result = even.length;
  } else if (even.length > odd.length) {
    result = odd.length;
  } else if (odd.length === even.length) {
    result = m.length;
  }

  console.log(result);
}

}

//Bissmillah.
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

let t = parseInt(readline());

while (t--) {
  let n = parseInt(readline());
  let m = readline()
    .split(" ")
    .map((x) => parseInt(x));
  let result;
  let even = [];
  let odd = [];
  for (let i = 0; i < m.length; i++) {
    if (m[i] % 2 == 0) {
      even.push(m[i]);
    } else {
      odd.push(m[i]);
    }
  }

  if (even.length == 0 || odd.length == 0) {
    result = 0;
  } else if (odd.length > even.length) {
    result = even.length;
  } else if (even.length > odd.length) {
    result = odd.length;
  } else {
    result = 0;
  }

  console.log(result);
}

}

'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++) {
        readline();
        let arr = readline().split(' ').map(Number);

        let odd = arr.filter(x => x % 2 === 1).length;
        let even = arr.filter(x => x % 2 === 0).length;

        if (odd > even) {
            output(arr.length - even);
        } else {
            output(arr.length - odd);
        }
    }
}

const readline = require('readline');

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

conIO.setPrompt('');

function reallyAwkward(n) {
    conIO.once('line', () => {
        conIO.once('line', arr => {
            arr = arr.split(' ');
            let oddCnt = 0, evenCnt = 0;
            arr.forEach(x => x % 2 == 0 ? ++evenCnt : ++oddCnt);
            conIO.write(Math.min(oddCnt, evenCnt) + '\n');
            if (n != 1)
                reallyAwkward(n - 1);
            else conIO.close();
        });
    });
}

conIO.once('line', n => {
    reallyAwkward(n);
});

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = CALC(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n] = ra();
  let A = ra();
  LT({n, A});
  // PROCESSING:
  let ans = 0;
  for (let i=0; i<n-1; i++){
    if (A[i]%2!=A[i+1]%2){
      ans++;
      i++;
    }
  }

  return ans;
};

const readline = require('readline');
(function main() {
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
  });
  rl.on('line', line => {
    console.log(`Received: ${line}`);
  });
})();


Allen is hosting a formal dinner party. $$$2n$$$ people come to the event in $$$n$$$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $$$2n$$$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic.Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of pairs of people. The second line contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$. For each $$$i$$$ with $$$1 \le i \le n$$$, $$$i$$$ appears exactly twice. If $$$a_j = a_k = i$$$, that means that the $$$j$$$-th and $$$k$$$-th people in the line form a couple.

Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions.

NoteIn the first sample case, we can transform $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 2 3 2 3 4 4 \rightarrow 1 1 2 2 3 3 4 4$$$ in two steps. Note that the sequence $$$1 1 2 3 3 2 4 4 \rightarrow 1 1 3 2 3 2 4 4 \rightarrow 1 1 3 3 2 2 4 4$$$ also works in the same number of steps.The second sample case already satisfies the constraints; therefore we need $$$0$$$ swaps.

line = readline()
line = readline()
arr = line.split(' ')
var last = [], total = 0, done = []
for (var i = 0; i < arr.length; i++) {
	last[arr[i]] = i
	done[i] = 0
}
for (var i = 0; i < arr.length; i++) {
	if (done[i]) { continue }
	done[i] = 1
	done[last[arr[i]]] = 1
	for (var j = i + 1; j < last[arr[i]]; j++) {
		if (done[j] === 0) {
			total ++
		}
	}
}
print(total)


The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception.Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right in a row and decided how much money to put in what wallet. Vasily decided to put ai coins to the i-th wallet from the left.Vasily is a very busy man, so the money are sorted into the bags by his robot. Initially, the robot stands by the leftmost wallet in the row. The robot can follow instructions of three types: go to the wallet that is to the left of the current one (if such wallet exists), go to the wallet that is to the right of the current one (if such wallet exists), put a coin to the current wallet. Due to some technical malfunctions the robot cannot follow two "put a coin" instructions in a row.Vasily doesn't want to wait for long, so he wants to write a program for the robot that contains at most 106 operations (not necessarily minimum in length) the robot can use to put coins into the wallets. Help him.

The first line contains integer n (2 ≤ n ≤ 300) — the number of wallets. The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 300). It is guaranteed that at least one ai is positive.

Print the sequence that consists of k (1 ≤ k ≤ 106) characters, each of them equals: "L", "R" or "P". Each character of the sequence is an instruction to the robot. Character "L" orders to move to the left, character "R" orders to move to the right, character "P" orders the robot to put a coin in the wallet. The robot is not allowed to go beyond the wallet line. In other words, you cannot give instructions "L" if the robot is at wallet 1, or "R" at wallet n. As a result of the performed operations, the i-th wallet from the left must contain exactly ai coins. If there are multiple answers, you can print any of them.

var n = parseInt( readline() );
var m0 = readline().split(' ').map(function(v){ return parseInt(v); });
var m1 = [];
for(var i=0; i<n; i++){
	m1[i] = 0;
}

var ret = [];
function put(i){
	while( m1[i]<m0[i] ){
		ret.push('P');
		m1[i]++;
		if(m1[i+1]<m0[i+1]){
			ret.push('RPL');
			m1[i+1]++
		}else if(m1[i-1]<m0[i-1]){
			ret.push('LPR');
			m1[i-1]++
		}else{
			if(i==0){
				ret.push('RL');
			}else{
				ret.push('LR');
			}

		}
	}
}
for(var i=0; i<n; i++){
	put(i);
	ret.push('R');
}
ret.length -= 2;
print(ret.join(''));

var n = 0;
var arr;
var ans = "";

n = readline();
arr = readline().split(" ");

for(var i=0; i<n; i++) {
    var first = true;
    while(arr[i]>0) {
        if(!first) {
            if(i==0) {
                ans += 'RL';
            } else {
                ans += 'LR';
            }
        }
        first = false;
        ans += "P";
        arr[i]--;
    }
    if(i<n-1) ans += 'R';
}
print(ans);

var n = parseInt(readline());
var mas = readline();
var str = "";
mas = mas.split(" ");
var max = 0;
for(var i = 0; i < n; ++i)
{
    mas[i] = parseInt(mas[i]);
    if(mas[i] > max){max = mas[i];}
}
max *= 2;
while(max != 0)
{
    for(var i = 0; i < n; ++i)
    {
        if(mas[i] != 0 && i != 0){mas[i] --; str += "P";}
        if(i != n-1){str += "R";}
    }
    max --;
    if(max == 0){break;}
    for(var i = n-1; i >= 0; --i)
    {
        if(mas[i] != 0 && i != n-1){mas[i] --; str += "P";}
        if(i != 0){str += "L";}
    }
    max --;
    if(max == 0){break;}
}
print(str);

var line1 = readline().split(' ');
var n = parseInt(line1[0]);
var line2 = readline().split(' ');
	var total = [], put=[];
	var total_sum=0, put_sum=0;

	for (var i=0; i < n; i++){
	total[i] = parseInt(line2[i]);
	total_sum+=total[i];
	put[i] = 0;
	}

  /* print ("total: " +total_sum+ "\n"); */

var  max = Math.max.apply(null, total);
res='';

for (var i=0;  i < 2*max;  i++) {

	for (var k=0; k < n; k++){

		if ( i%2==0) {

			if (put[k] < total[k] && res.slice(-1)!='P'){
			res+='P';
			put_sum++;
			put[k]++;
			}

			if (put_sum < total_sum && k!=n-1) res+='R';

		}

		else{

			if (put[n-k-1] < total[n-k-1] && res.slice(-1)!='P') {
			res+='P';
			put_sum++;
			put[n-k-1]++;
			}

			if (put_sum < total_sum && k!=n-1)  res+='L';

		}

	}

}

print(res);

var line1 = readline().split(' ');
var n = parseInt(line1[0]);
var line2 = readline().split(' ');
	var total = [], put=[];
	var total_sum=0, put_sum=0;

	for (var i=0; i < n; i++){
	total[i] = parseInt(line2[i]);
	total_sum+=total[i];
	put[i] = 0;
	}

  /* print ("total: " +total_sum+ "\n"); */

var  max = Math.max.apply(null, total);
res='';

for (var i=0;  i < 2*max;  i++) {

	for (var k=0; k < n; k++){

		if ( i%2==0) {

			if (put[k] < total[k] && res.slice(-1)!='P'){
			res+='P';
			put_sum++;
			put[k]++;                    			/*    print(put_sum+" "+"put"+k+"="+put[k]+"   ");  */
			}

			if (put_sum < total_sum && k!=n-1){

			res+='R'

			}

		}

		else{

			if (put[n-k-1] < total[n-k-1] && res.slice(-1)!='P') {
			res+='P';
			put_sum++;
			put[n-k-1]++;                     /*     print(put_sum+" "+"put"+k+"="+put[k]+"   ");  */
			}

			if (put_sum < total_sum && k!=n-1) {

							  /*	print(put_sum+" "+"put"+k+"="+put[k]+"   ");   */

			res+='L'

			}

		}

	}

}

print(res);

;(function () {

	var n = +readline();
	var s = 0;
	var t = readline().split(' ').map(function (e) { var _e = +e; s += _e; return _e; });
	var p = 0;

	var str = '';
	var l, r;

	while (s) {

		if (t[p]) {
			t[p]--;
			str += 'P';
			if (--s) {

				if (p == 0) {
					str += 'R';
					p++;
					continue;
				}

				if (p == (n-1)) {
					str += 'L';
					p--;
					continue;
				}
			} else {
				break;
			}
		}

		for (var r = p + 1; r < n; r++)
			if (t[r]) break;
		if (!t[r]) r = -1;

		for (var l = p - 1; l > -1; l--)
			if (t[l]) break;
		if (!t[l]) l = -1;

		if (r == -1 && l == -1) {
			if (p == 0) {
				str += 'R';
				p++;
			}

			if (p == (n-1)) {
				str += 'L';
				p--;
			}
		} else {
			if (r > l) {
				str += 'R';
				p++;
			}
			else{
				str += 'L';
				p--;
			}
		}

	}

	print(str);

}).call(this)

var
    num  = parseInt(readline()),
    k    = readline().split(" "),
    sum  = 0,
    length = k.length - 1
    pos  = 0,
    cur  = 0,
    str  = ""
;

for(var i in k) {
    k[i] = parseInt(k[i]);
    sum += k[i];
}

while(1){

    if (k[pos] > 0) {
        str += "P";
        cur ++;
        k[pos]--;
        if (cur == sum) break;
    }

    if (pos == length) {
        pos -= 1;
        str += "L";
        continue;
    }

    if (pos > 0 && k[pos-1] > 0) {
        pos--;
        str += "L";
    } else {
        pos++;
        str += "R";
    }
}

print(str);

function main(){
    var i, n = parseInt(readline());
    var a = readline().split(' ');
    for(i = 0 ;  i < n ; ++i){
        a[i] = parseInt(a[i]);
    }
    var last = 0, str = "";
    for(i = 0 ; i < n - 1 ; ++i){
        if ( i ){
            str+="R";
        }
        while ( a[i] > 0 ){
            str += "P";
            --a[i];
            if ( a[i] > 0 ){
                str += "RL";
            }
        }

    }
    if ( a[n-1] > 0 ){
        str += "R";
    }
    while( a[n-1] > 0 ){
        str += "P";
        --a[n-1];
        if ( a[n-1] > 0 ){
            str += "LR";
        }
    }
    print(str);
}
main();

var n = parseInt( readline() );
var m0 = readline().split(' ').map(function(v){ return parseInt(v); });
var m1 = [];
for(var i=0; i<n; i++){
	m1[i] = 0;
}

var ret = [];
function put(i){
	while( m1[i]<m0[i] ){
		ret.push('P');
		m1[i]++;
		if(m1[i+1]<m0[i+1]){
			ret.push('RPL');
			m1[i+1]++
		}else if(m1[i-1]<m0[i-1]){
			ret.push('LPR');
			m1[i-1]++
		}else{
			if(m1[i-1]){
				ret.push('LR');
			}else{
				ret.push('RL');
			}

		}
	}
}
for(var i=0; i<n; i++){
	put(i);
	ret.push('R');
}
ret.length -= 2;
print(ret.join(''));

var n = parseInt( readline() );
var m0 = readline().split(' ').map(function(v){ return parseInt(v); });
var m1 = [];
for(var i=0; i<n; i++){
	m1[i] = 0;
}

var ret = [];
function put(i){
	while( m1[i]<m0[i] ){
		ret.push('P');
		m1[i]++;
		if(m1[i+1]<m0[i+1]){
			ret.push('RPL');
			m1[i+1]++
		}else if(m1[i-1]<m0[i-1]){
			ret.push('LPR');
			m1[i-1]++
		}else{
			ret.push('RL');
		}
	}
}
for(var i=0; i<n; i++){
	put(i);
	ret.push('R');
}

print(ret.join(''));

var n = 0;
var arr;
var ans = "";

n = readline();
arr = readline().split(" ");

for(var i=0; i<n; i++) {
    var first = true;
    while(arr[i]>0) {
        if(!first) {
            if(i==0) {
                ans += 'RL';
            } else {
                ans += 'LR';
            }
        }
        first = !first;
        ans += "P";
        arr[i]--;
    }
    if(i<n-1) ans += 'R';
}
print(ans);

var n = parseInt(readline());
var mas = readline();
var str = "";
mas = mas.split(" ");
var max = 0;
for(var i = 0; i < n; ++i)
{
    mas[i] = parseInt(mas[i]);
    if(mas[i] > max){max = mas[i];}
}
mas[0] --;
str = "P";
while(max != 0)
{
    for(var i = 0; i < n; ++i)
    {
        if(mas[i] != 0 && i != 0){mas[i] --; str += "P";}
        if(i != n-1){str += "R";}
    }
    max --;
    if(max == 0){break;}
    for(var i = n-1; i >= 0; --i)
    {
        if(mas[i] != 0 && i != n-1){mas[i] --; str += "P";}
        if(i != 0){str += "L";}
    }
    max --;
    if(max == 0){break;}
}
print(str);

var n = parseInt(readline());
var mas = readline();
var str = "";
mas = mas.split(" ");
var max = 0;
for(var i = 0; i < n; ++i)
{
    mas[i] = parseInt(mas[i]);
    if(mas[i] > max){max = mas[i];}
}
while(max != 0)
{
    for(var i = 0; i < n; ++i)
    {
        if(mas[i] != 0 && i != 0){mas[i] --; str += "P";}
        if(i != n-1){str += "R";}
    }
    max --;
    if(max == 0){break;}
    for(var i = n-1; i >= 0; --i)
    {
        if(mas[i] != 0 && i != n-1){mas[i] --; str += "P";}
        if(i != 0){str += "L";}
    }
    max --;
    if(max == 0){break;}
}
print(str);

var n = parseInt(readline());
var mas = readline();
var str = "";
mas = mas.split(" ");
var max = 0;
for(var i = 0; i < n; ++i)
{
    mas[i] = parseInt(mas[i]);
    if(mas[i] > max){max = mas[i];}
}
mas[0] --;
str = "P";
max *= 2;
while(max != 0)
{
    for(var i = 0; i < n; ++i)
    {
        if(mas[i] != 0 && i != 0){mas[i] --; str += "P";}
        if(i != n-1){str += "R";}
    }
    max --;
    if(max == 0){break;}
    for(var i = n-1; i >= 0; --i)
    {
        if(mas[i] != 0 && i != n-1){mas[i] --; str += "P";}
        if(i != 0){str += "L";}
    }
    max --;
    if(max == 0){break;}
}
print(str);

var n = parseInt(readline());
var mas = readline();
var str = "";
mas = mas.split(" ");
var max = 0;
for(var i = 0; i < n; ++i)
{
    mas[i] = parseInt(mas[i]);
    if(mas[i] > max){max = mas[i];}
}
while(max != 0)
{
    for(var i = 0; i < n; ++i)
    {
        if(mas[i] != 0){mas[i] --; str += "P";}
        if(i != n-1){str += "R";}
    }
    max --;
    if(max == 0){break;}
    for(var i = n-1; i >= 0; --i)
    {
        if(mas[i] != 0){mas[i] --; str += "P";}
        if(i != 0){str += "L";}
    }
    max --;
    if(max == 0){break;}
}
print(str);

var n = parseInt(readline());
var mas = readline();
var str = "";
mas = mas.split(" ");
var max = 0;
for(var i = 0; i < n; ++i)
{
    mas[i] = parseInt(mas[i]);
    if(mas[i] > max){max = mas[i];}
}
while(max != 0)
{
    for(var i = 0; i < n; ++i)
    {
        if(mas[i] != 0){mas[i] --; str += "P";}
        str += "R";
    }
    max --;
    if(max == 0){break;}
    for(var i = n-1; i >= 0; --i)
    {
        if(mas[i] != 0){mas[i] --; str += "P";}
        str += "L";
    }
    max --;
    if(max == 0){break;}
}
print(str);

var line1 = readline().split(' ');
var n = parseInt(line1[0]);
var line2 = readline().split(' ');
	var total = [], put=[];
	var total_sum=0, put_sum=0;

	for (var i=0; i < n; i++){
	total[i] = parseInt(line2[i]);
	total_sum+=total[i];
	put[i] = 0;
	}

var  max = Math.max.apply(null, total);
res='';

for (var i=0;  i < max;  i++) {

	for (var k=0; k < n; k++){

		if ( i%2==0) {

			if (put[k] < total[k] && res.slice(-1)!='P'){
			res+='P';
			put_sum++;
			}

			if (put_sum < total_sum && k!=n-1){

			res+='R'

			}

		}

		else{

			if (put[n-k-1] < total[n-k-1] && res.slice(-1)!='P') {
			res+='P';
			put_sum++;
			}

			if (put_sum < total_sum && k!=n-1) {

			res+='L'

			}

		}

	}

}

print(res);

var line1 = readline().split(' ');
var n = parseInt(line1[0]);
var line2 = readline().split(' ');
	var total = [], put=[];

	for (var i=0; i < n; i++){
	total[i] = parseInt(line2[i]);
	put[i] = 0;
	}

var  max = Math.max.apply(null, total);
res='';

for (var i=0; i < max; i++){

	for (var k=0; k < n; k++){

		if (put[k] < total[k] && res.slice(-1)!='P')  res+='P';
		if ( (k!=n-1) && i%2==0) res+='R'
			else if ( (k!=n-1) && i%2==1) res+='L';

	}

}

print(res);

var line1 = readline().split(' ');
var n = parseInt(line1[0]);
var line2 = readline().split(' ');
	var total = [], put=[];

	for (var i=0; i < n; i++){
	total[i] = parseInt(line2[i]);
	put[i] = 0;
	}

var  max = Math.max.apply(null, total);  				print(max+"\n");

res='';

for (var i=0; i < max; i++){

	for (var k=0; k < n; k++){

		if (put[k] < total[k] && res.slice(-1)!='P')  res+='P';
		if ( (k!=n-1) && i%2==0) res+='R'
			else if ( (k!=n-1) && i%2==1) res+='L';

	}

}

print(res);

var n = parseInt( readline() );
var m0 = readline().split(' ').map(function(v){ return parseInt(v); });
var m1 = [];
for(var i=0; i<n; i++){
	m1[i] = 0;
}

var ret = [];
function put(i){
	while( m1[i]<m0[i] ){
		ret.push('P');
		m1[i]++;
		if(m1[i+1]<m0[i+1]){
			ret.push('RPL');
		}else if(m1[i-1]<m0[i-1]){
			ret.push('LPR');
		}else{
			ret.push('RL');
		}
	}
}
for(var i=0; i<n; i++){
	put(i);
	ret.push('R');
}

print(ret.join(''));

var n = parseInt( readline() );
var m0 = readline().split(' ').map(function(v){ return parseInt(v); });
var m1 = [];
for(var i=0; i<n; i++){
	m1[i] = 0;
}

var ret = [];
function put(i){
	while( m1[i]<m0[i] ){
		ret.push('P');
		m1[i]++;
		if(m1[i+1]<m0[i+1]){
			ret.push('RPL');
			m1[i+1]++
		}else if(m1[i-1]<m0[i-1]){
			ret.push('LPR');
			m1[i-1]++
		}else{
			ret.push('RL');
		}
	}
}
for(var i=0; i<n; i++){
	put(i);
	ret.push('R');
}
ret.length -= 2;
print(ret.join(''));


One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some integer x). If those rules don't indicate the size of the cut are clearly, then the way with which the cut part possesses the largest area is chosen. Of course, both sides of the cut area should be integer. If there are several answers to this problem, you should choose the answer with the maximal height.

The first line contains a pair of integers h and w (1 ≤ h, w ≤ 109) which are the height and width of the uploaded photo in pixels.

Print two integers which are the height and width of the cut area.

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

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

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

function solve(height, width) {
	var subHeight = Math.pow(2, Math.floor(Math.log(height) / Math.log(2)));
	while (true) {
		var subWidth = Math.min(width, Math.floor(5*subHeight/4));
		if (subWidth >= Math.ceil(4*subHeight/5)) {
			return { height: subHeight, width: subWidth,
					 getArea: function() {
						 return this.height * this.width;
					 },
					 toString: function() {
						 return this.height+" "+this.width;
					 },
					 rotate: function() {
						 var temp = this.height;
						 this.height = this.width;
						 this.width = temp;
					 }
			};
		}
		subHeight /= 2;
	}
}

function main() {
	var data = tokenizeIntegers(readline());
	var height = data[0], width = data[1];

	var solutionA = solve(height, width), areaA = solutionA.getArea(),
		solutionB = solve(width, height), areaB = solutionB.getArea();
	solutionB.rotate();

	if (areaA > areaB || (areaA == areaB && solutionA.height > solutionB.height)) {
		print(solutionA.toString());
	}
	else {
		print(solutionB.toString());
	}
}

main();

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let H = lll[0]
let W = lll[1]

let ph = -1
while (ph++ < 30) {
  let ch = Math.pow(2, ph)
  if (ch > H || ch * 0.8 > W) {ph--; break}
}
let ch = Math.pow(2, ph)

let pw = -1
while (pw++ < 30) {
  let cw = Math.pow(2, pw)
  if (cw > W || cw * 0.8 > H) {pw--; break}
}
let cw = Math.pow(2, pw)

let sh = ch * Math.min(ch * 1.25, W)
let sw = cw * Math.min(cw * 1.25, H)

if (sh > sw) {
  print(ch + ' ' + Math.floor(Math.min(ch * 1.25, W)))
} else if (sw > sh) {
  print(Math.floor(Math.min(cw * 1.25, H)) + ' ' + cw)
} else {
  print(ch > cw * 1.25 ? ch + ' ' + Math.floor(Math.min(ch * 1.25, W)) : Math.floor(Math.min(cw * 1.25, H)) + ' ' + cw)
}

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

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

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

function solve(height, width) {
	var subHeight = Math.pow(2, Math.floor(Math.log(height) / Math.log(2)));
	while (true) {
		var subWidth = Math.min(width, Math.floor(5*subHeight/4));
		if (subWidth >= Math.ceil(4*subHeight/5)) {
			return { height: subHeight, width: subWidth,
					 getArea: function() {
						 return this.height * this.width;
					 },
					 toString: function() {
						 return this.height+" "+this.width;
					 },
					 rotate: function() {
						 var temp = this.height;
						 this.height = this.width;
						 this.width = temp;
					 }
			};
		}
		subHeight /= 2;
	}
}

function main() {
	var data = tokenizeIntegers(readline());
	var height = data[0], width = data[1];
	var solutionA = solve(height, width), areaA = solutionA.getArea(),
		solutionB = solve(width, height), areaB = solutionB.getArea();

	solutionA.rotate();

	if (areaA > areaB || (areaA == areaB && solutionA.height > solutionB.height)) {
		print(solutionA.toString());
	}
	else {
		print(solutionB.toString());
	}
}

main();