The Berland State University is hosting a ballroom dance in celebration of its 100500-th anniversary! n boys and m girls are already busy rehearsing waltz, minuet, polonaise and quadrille moves.We know that several boy&girl pairs are going to be invited to the ball. However, the partners' dancing skill in each pair must differ by at most one.For each boy, we know his dancing skills. Similarly, for each girl we know her dancing skills. Write a code that can determine the largest possible number of pairs that can be formed from n boys and m girls.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of boys. The second line contains sequence a1, a2, ..., an (1 ≤ ai ≤ 100), where ai is the i-th boy's dancing skill. Similarly, the third line contains an integer m (1 ≤ m ≤ 100) — the number of girls. The fourth line contains sequence b1, b2, ..., bm (1 ≤ bj ≤ 100), where bj is the j-th girl's dancing skill.

Print a single number — the required maximum possible number of pairs.

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		if(!output[+input[i]]){
			output[+input[i]] = 1;
		}
		else{
			output[+input[i]]++;
		}
	}
}

var n = +readline(), boys = readline().split(" "), m = +readline(), girls = readline().split(" "),
boyslevs = {}, girlslevs = {}, pairs = 0;
maxb = Math.max.apply(null,boys);
maxg = Math.max.apply(null,girls);
minb = Math.min.apply(null,boys);
ming = Math.min.apply(null,girls);

if((maxb < ming-1) || (maxg < minb-1)){
	write(0);
}
else{
	countUniqueElements(boys,boyslevs);
	countUniqueElements(girls,girlslevs);

	for(level in boyslevs){
		level = +level;

		if(girlslevs[level-1]){
			if(boyslevs[level] > girlslevs[level-1]){
				pairs += girlslevs[level-1];
				boyslevs[level] -= girlslevs[level-1];
				delete girlslevs[level-1];
			}
			else if(boyslevs[level] == girlslevs[level-1]){
				pairs += boyslevs[level];
				delete girlslevs[level-1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level-1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level]){
				pairs += girlslevs[level];
				boyslevs[level] -= girlslevs[level];
				delete girlslevs[level];
			}
			else if(boyslevs[level] == girlslevs[level]){
				pairs += boyslevs[level];
				delete girlslevs[level];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level+1] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level+1]){
				pairs += girlslevs[level+1];
				boyslevs[level] -= girlslevs[level+1];
				delete girlslevs[level+1];
			}
			else if(boyslevs[level] == girlslevs[level+1]){
				pairs += boyslevs[level];
				delete girlslevs[level+1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level+1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}
	}

	write(pairs);
}

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

binaryHeap = function(comparator) {
  this.arr = [];
  this.cmp = comparator;

  this.swapIndices = function(idx1, idx2) {
    var tmp = this.arr[idx1];
    this.arr[idx1]=this.arr[idx2];
    this.arr[idx2]=tmp;
  };

  this.getLeft = function(val) {
    return val*2+1;
  };

  this.getRight = function(val) {
    return val*2+2;
  };

  this.getParent = function(val) {
    return (((val-1)/2)>>0);
  };

  this.clear = function() {
    this.arr = [];
  };

  this.size = function() {
    return this.arr.length;
  };

  this.empty = function() {
    if(this.arr.length==0) return true;
    return false;
  };

  this.push = function(val) {
    this.arr.push(val);

    var idx=this.arr.length-1;

    while(idx>0 && this.cmp(this.arr[idx], this.arr[this.getParent(idx)])) {
      this.swapIndices(idx, this.getParent(idx));
      idx=this.getParent(idx);
    }
  };

  this.pop = function() {
    this.swapIndices(0, this.arr.length-1);
    this.arr.pop();

    var idx=0, l, r;

    while(true) {
      l = this.getLeft(idx);
      r = this.getRight(idx);

      if(l>=this.arr.length) {
        break;
      }
      if(r>=this.arr.length) {
        if(this.cmp(this.arr[l], this.arr[idx])) {
          this.swapIndices(l, idx);
        }

        break;
      }

      if(this.cmp(this.arr[l], this.arr[idx]) && !this.cmp(this.arr[r], this.arr[l])) {
        this.swapIndices(l, idx);
        idx=l;
      }
      else if(this.cmp(this.arr[r], this.arr[idx]) && !this.cmp(this.arr[l], this.arr[r])) {
        this.swapIndices(r, idx);
        idx=r;
      }
      else {
        break;
      }
    }
  };

  this.top = function() {
    return this.arr[0];
  };
};

function cmpNumbers(a, b) {
  if(a<b) return -1;
  if(a==b) return 0;
  return 1;
}

function cmp2(a, b) {
  if(a<b) return true;
  return false;
}

function sortSubarray(arr, l, r) {
  var heap = new binaryHeap(cmp2);

  for(var i=l;i<=r;i++) {
    heap.push(arr[i]);
  }

  for(var i=l;i<=r;i++) {
    arr[i] = heap.top();
    heap.pop();
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = parseInt(token[i]);
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = parseInt(token[i]);
}

sortSubarray(a,1,n);
sortSubarray(b,1,m);

print(recurse(1,1));

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

function cmpNumbers(a, b) {
  if(a<b) return -1;
  if(a==b) return 0;
  return 1;
}

function sortSubarray(arr, l, r) {
  var tmp = [];

  for(var i=l;i<=r;i++) {
    tmp.push(arr[i]);
  }

  tmp.sort(cmpNumbers);

  for(var i=0;i<r-l+1;i++) {
    arr[i+l]=tmp[i];
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = parseInt(token[i]);
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = parseInt(token[i]);
}

sortSubarray(a,1,n);
sortSubarray(b,1,m);

print(recurse(1,1));

var ints = function() {
	return readline().split(' ').map(function(x) {
		return parseInt(x)
	})
}

var minus = function(a, b) {
	return a - b
}

readline()
var boys = ints()
readline()
var girls = ints()

boys.sort(minus)
girls.sort(minus)

var i = 0, j = 0, counter = 0

while (i < boys.length && j < girls.length) {
	if (Math.abs(boys[i] - girls[j]) <= 1) {
		i ++
		j ++
		counter ++
	} else if (boys[i] < girls[j])
		i ++
	else
		j++
}

print(counter)

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
}
readline();
let firstGroup = readline().getNumArray().sort((a, b) => a - b);
readline();
let secondGroup = readline().getNumArray().sort((a, b) => a - b);
let counter = 0;

if (firstGroup.length > secondGroup.length) {
  const tempGroup = firstGroup;
  firstGroup = secondGroup;
  secondGroup = tempGroup;
}

for (let i = 0 ; i < firstGroup.length; i++) {
  for (let j = 0; j < secondGroup.length; j++) {
    if (Math.abs(firstGroup[i] - secondGroup[j]) <= 1) {
      counter++;
      secondGroup.splice(j, 1);
      break;
    }
  }
}

write(counter);

var man = readline();
var str = readline().split(" ").sort((x,y)=>x-y);
var woman = readline();
var str2 = readline().split(" ").sort((x,y)=>x-y);
var res = 0;
	for (var i=0; i<+man; i++){
		for (var j=0; j<+woman; j++){
			if (Math.abs(+str[i]-str2[j])<2){
				res++;
				str2[j]="-";
				break;
			}
		}

	}

	print(res);

var input = [
  '4',
  '1 4 6 2',
  '5',
  '5 1 5 7 9'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}
function print(data){
  console.log(data);
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = parseInt(d1Keys[i]);
  var prevKey = key-1;
  var nextKey = key+1;
  var t1 = Math.min(parseInt(d1[key]||0), parseInt(d2[prevKey]||0));
  d1[key]-= t1;
  if (d2[prevKey]!=null)
    d2[prevKey]-=t1;
  var t2 = Math.min(parseInt(d1[key]||0), parseInt(d2[key]||0));
  d1[key] -= t2;
  if (d2[key]!=null)
    d2[key]-=t2;
  var t3 = Math.min(parseInt(d1[key]||0), parseInt(d2[nextKey]||0));
  d1[key] -= t3;
  if (d2[nextKey]!=null)
    d2[nextKey]-=t3;

  ans+=t1+t2+t3;
  //print(ans);
}
//console.log(d1);
//console.log(d2);
print(ans);

function sa(girls,boys){

        girls.sort(function(a,b){ return a-b })
        boys.sort(function(a,b){ return a-b })

        var g=0;
        var b=0;
        var result = 0;
        while(g<girls.length && b < boys.length){
            if(Math.abs(girls[g] - boys[b]) <2){
                result++;
                g++;
                b++;
                continue;
            }
            if(girls[g] > boys[b]){
                b++;
            } else {
                g++;
            }
        }

        return result
    }

    readline();
    var girls = readline().split(" ").map(Number);
    readline();
    var boys = readline().split(" ").map(Number);

    print(sa(girls,boys));

var n=Number(readline())
var A=readline().split(' ').map(Number)
var m=Number(readline())
var B=readline().split(' ').map(Number)

A.sort((l,r)=>l-r)
B.sort((l,r)=>l-r)
var i=0, j=0, r=0;
while (i<A.length && j<B.length) {
  if (Math.abs(A[i]-B[j])<=1) {
   i++; j++; r++;
  } else if (A[i]<B[j]) {
   i++;
  } else if (A[i]>B[j]) ++j;
}

print(r)

var input = readline().split(' ').map(Number), n = input[0];
var a = readline().split(' ').map(Number);
var input = readline().split(' ').map(Number), m = input[0];
var b = readline().split(' ').map(Number);

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

var ida = 0;
var idb = 0;
var res = 0;
while (ida < n && idb < m) {
    if (a[ida] < b[idb] - 1) ida++;
    else if (a[ida] > b[idb] + 1) idb++;
    else {
        res++;
        ida++;
        idb++;
    }
}
write(res);

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
sb.sort((a,b)=>{return a-b});
sg.sort((a,b)=>{return a-b});
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg[j]=190;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

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

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

readLine.on('close', () => {
  let [n] = input[0].split(' ').map(x => parseInt(x));
  const boys = input[1].split(' ').map(x => parseInt(x));

  let [k] = input[2].split(' ').map(x => parseInt(x));
  const girls = input[3].split(' ').map(x => parseInt(x));

  boys.sort((a, b) => a - b); girls.sort((a, b) => a - b);
  let b = 0, g = 0;

  let answ = 0;
  while (b < boys.length && g < girls.length) {
    if (Math.abs( boys[b] - girls[g] ) <= 1) {
      answ += 1;
      b += 1; g += 1; continue;
    } else {
      if (boys[b] > girls[g]) g += 1;
      else b += 1;
    }
  }

  console.log(answ);
});

'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 main() {
  let b = readline();
  let bSkills = readline().split(' ');
  bSkills = bSkills.map(ele => parseInt(ele));
  let g = readline();
  let gSkills = readline().split(' ')
  gSkills = gSkills.map(ele => parseInt(ele));

  berSuBall(bSkills, gSkills);
}

function berSuBall(boysSkills, girlsSkills){
  boysSkills.sort((a, b) =>  a - b);
  girlsSkills.sort((a, b) =>  a - b);

  let count = 0;

  for(let i = 0; i < boysSkills.length; i++){
    for(let j = 0; j < girlsSkills.length; j++){
      let dif = Math.abs(boysSkills[i] - girlsSkills[j]);
      if(dif <= 1){
        count++;
        boysSkills[i] = Infinity;
        girlsSkills[j] = Infinity;
      }
    }
  }
  console.log(count)
  return count;
}

function countUniqueElements(input,output){
	for(var i = 0; i < input.length; i++){
		if(!output[+input[i]]){
			output[+input[i]] = 1;
		}
		else{
			output[+input[i]]++;
		}
	}
}

var n = +readline(), boys = readline().split(" "), m = +readline(), girls = readline().split(" "),
boyslevs = {}, girlslevs = {}, pairs = 0;
maxb = Math.max.apply(null,boys);
maxg = Math.max.apply(null,girls);
minb = Math.min.apply(null,boys);
ming = Math.min.apply(null,girls);

if((maxb < ming) || (maxg < minb)){
	write(0);
}
else{
	countUniqueElements(boys,boyslevs);
	countUniqueElements(girls,girlslevs);

	for(level in boyslevs){
		level = +level;

		if(girlslevs[level-1]){
			if(boyslevs[level] > girlslevs[level-1]){
				pairs += girlslevs[level-1];
				boyslevs[level] -= girlslevs[level-1];
				delete girlslevs[level-1];
			}
			else if(boyslevs[level] == girlslevs[level-1]){
				pairs += boyslevs[level];
				delete girlslevs[level-1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level-1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level]){
				pairs += girlslevs[level];
				boyslevs[level] -= girlslevs[level];
				delete girlslevs[level];
			}
			else if(boyslevs[level] == girlslevs[level]){
				pairs += boyslevs[level];
				delete girlslevs[level];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level] -= boyslevs[level];
				delete boyslevs[level];
			}
		}

		if(girlslevs[level+1] && boyslevs[level]){
			if(boyslevs[level] > girlslevs[level+1]){
				pairs += girlslevs[level+1];
				boyslevs[level] -= girlslevs[level+1];
				delete girlslevs[level+1];
			}
			else if(boyslevs[level] == girlslevs[level+1]){
				pairs += boyslevs[level];
				delete girlslevs[level+1];
				delete boyslevs[level];
			}
			else{
				pairs += boyslevs[level];
				girlslevs[level+1] -= boyslevs[level];
				delete boyslevs[level];
			}
		}
	}

	write(pairs);
}

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

function sortSubarray(arr, l, r) {
  var tmp = [];

  for(var i=l;i<=r;i++) {
    tmp.push(arr[i]);
  }

  tmp.sort();

  for(var i=0;i<r-l+1;i++) {
    arr[i+l]=tmp[i];
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = token[i];
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = token[i];
}

sortSubarray(a,1,n);
sortSubarray(b,1,m);

print(recurse(1,1));

const N = 107;

var n, m;
var a, b;
var state;
var used;
var token = [];

function initializeData() {
  a = new Array(N);
  b = new Array(N);

  used = new Array(N);
  state = new Array(N);

  for(var i=0;i<N;i++) {
    used[i] = new Array(N);
    state[i] = new Array(N);

    for(var j=0;j<N;j++) {
      used[i][j]=false;
    }
  }
}

function sortSubarray(arr, l, r) {
  var tmp = [];

  for(var i=l;i<=r;i++) {
    tmp.push(arr[i]);
  }

  tmp.sort();

  for(var i=0;i<r-l+1;i++) {
    arr[i+l]=tmp[i];
  }
}

function recurse(l, r) {
  if(l>n || r>m) {
    return 0;
  }

  if(used[l][r]==true) {
    return state[l][r];
  }

  var ans = Math.max(recurse(l+1,r), recurse(l,r+1));

  if(Math.abs(a[l]-b[r])<=1) {
    ans = Math.max(ans, recurse(l+1,r+1)+1);
  }

  used[l][r]=true;
  state[l][r]=ans;

  return ans;
}

initializeData();

n = readline();
token = readline().split(' ');
for(var i=0;i<n;i++) {
  a[i+1] = token[i];
}

m = readline();
token = readline().split(' ');
for(var i=0;i<m;i++) {
  b[i+1] = token[i];
}

//sortSubarray(a,1,n);
//sortSubarray(b,1,m);

print(recurse(1,1));

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
}
readline();
let firstGroup = readline().getNumArray().sort((a, b) => a - b);
readline();
let secondGroup = readline().getNumArray().sort((a, b) => a - b);
let counter = 0;

if (firstGroup.length > secondGroup.length) {
  const tempGroup = firstGroup;
  firstGroup = secondGroup;
  secondGroup = tempGroup;
}

for (let i = 0 ; i < firstGroup.length; i++) {
  for (let j = 0; j < secondGroup.length; j++) {
    if (Math.abs(firstGroup[i] - secondGroup[j]) <= 1) {
      counter++;
      secondGroup.splice(j, 1);
    }
  }
}

write(counter);

var man = readline();
var str = readline().split(" ");
var woman = readline();
var str2 = readline().split(" ");
var res = 0;
	for (var i=0; i<+man; i++){
		for (var j=0; j<+woman; j++){
			if (Math.abs(+str[i]-str2[j])<2){
				res++;
				str2[j]="-";
				break;
			}
		}

	}

	print(res);

var man = readline();
var str = readline().split(" ");
var woman = readline();
var str2 = readline().split(" ");
var res = 0;
	for (var i=0; i<+man; i++){
		for (var j=0; j<+woman; j++){
			if (Math.abs(+str[i]-str2[j])<2){
				res++;
				str2[j]="";
				break;
			}
		}

	}

	print(res);

var input = [
  '4',
  '1 2 3 4',
  '4',
  '10 11 12 13'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}
function print(data){
  console.log(data);
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = parseInt(d1Keys[i]);
  var prevKey = key-1;
  var nextKey = key+1;
  var tAns = Math.min((d1[key]||0), (d2[prevKey]||0));
  d1[key]-= tAns;
  tAns += Math.min((d1[key]||0), (d2[key]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[key]||0));
  tAns += Math.min((d1[key]||0), (d2[nextKey]||0));
  //print(nextKey);
  d1[key] -= Math.min((d1[key]||0), (d2[nextKey]||0));
  ans+=tAns;
}
//console.log(d1);
//console.log(d2);
print(ans);

var input = [
  '2',
  '2 2',
  '1',
  '2'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}
function print(data){
  console.log(data);
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = d1Keys[i];
  var prevKey = key-1;
  var nextKey = key+1;
  var tAns = Math.min((d1[key]||0), (d2[prevKey]||0));
  d1[key]-= tAns;
  tAns += Math.min((d1[key]||0), (d2[key]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[key]||0));
  tAns += Math.min((d1[key]||0), (d2[nextKey]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[nextKey]||0));
  ans+=tAns;
}
//console.log(d1);
//console.log(d2);
print(ans);

var input = [
  '5',
  '1 1 1 1 1',
  '3',
  '1 2 3'
]
var inputIndex = 0;
/*function readline(){
  return input[inputIndex++];
}*/
var n = parseInt(readline())
var a = readline().split(' ')
var m = parseInt(readline())
var b = readline().split(' ')

var d1 = {}
var d2 = {}

for(var i = 0;i<n;i++){
  d1[a[i]] = (d1[a[i]]||0)+1;
}
for(var i = 0;i<m;i++){
  d2[b[i]] = (d2[b[i]]||0)+1;
}
var d1Keys = Object.keys(d1);
var d2Keys = Object.keys(d2);
var ans = 0;
for (var i = 0;i <d1Keys.length;i++){
  var key = d1Keys[i];
  var prevKey = key--;
  var nextKey = key++;
  var tAns = Math.min((d1[key]||0), (d2[prevKey]||0));
  d1[key]-= tAns;
  tAns += Math.min((d1[key]||0), (d2[key]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[key]||0));
  tAns += Math.min((d1[key]||0), (d2[nextKey]||0));
  d1[key] -= Math.min((d1[key]||0), (d2[nextKey]||0));
  ans+=tAns;
}
//console.log(d1);
//console.log(d2);
print(ans);

var input = readline().split(' ').map(Number), n = input[0];
var a = readline().split(' ').map(Number);
var input = readline().split(' ').map(Number), m = input[0];
var b = readline().split(' ').map(Number);

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

var ida = 0;
var idb = 0;
var res = 0;
while (ida < n && idb < m) {
    if (a[ida] < b[idb] - 1) ida++;
    else if (a[ida] > b[idb] + 1) idb++;
    else {
        res++;
        ida++;
        idb++;
    }
}
write(res);

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff==1){
                        count++;
                      //  console.log(j)
                        sg[j]=1000;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg[j]=1000;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],100);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],100);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg.splice(j,1);
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

var numBoys=parseInt(readline().split(' ')[0],10);
var sb=readline().split(' ').map(item=>parseInt(item,10));
var numGirsl=parseInt(readline().split(' ')[0],10);
var sg=readline().split(' ').map(item=>parseInt(item,10));
var count=0;
for(var i=0;i<numBoys;i++){
        for(var j=0;j<numGirsl;j++){
                var diff=Math.abs(sb[i]-sg[j])
                    if(diff<=1){
                        count++;
                      //  console.log(j)
                        sg[j]=190;
                       // console.log(sg)
                        break;
                    }
        }
}
print(count)

function read() {
  let b = readline();
  let bSkills = readline().split(' ');
  boysSkills = boysSkills.map(ele => parseInt(ele));
  let g = readline();
  let girlsSkills = readline().split(' ')
  girlsSkills = girlsSkills.map(ele => parseInt(ele));

  berSuBall(bSkills, gSkills);
}

function berSuBall(boysSkills, girlsSkills){
  boysSkills.sort((a, b) =>  a - b);
  girlsSkills.sort((a, b) =>  a - b);

  let count = 0;

  for(let i = 0; i < boysSkills.length; i++){
    for(let j = 0; j < girlsSkills.length; j++){
      let dif = Math.abs(boysSkills[i] - girlsSkills[j]);
      if(dif <= 1){
        count++;
        boysSkills[i] = Infinity;
        girlsSkills[j] = Infinity;
      }
    }
  } return count;
}

function read() {
  let b = readline();
  let bSkills = readline().split(' ');
  boysSkills = boysSkills.map(ele => parseInt(ele));
  let g = readline();
  let girlsSkills = readline().split(' ')
  girlsSkills = girlsSkills.map(ele => parseInt(ele));

  berSuBall(bSkills, gSkills);
}

function berSuBall(boysSkills, girlsSkills){
  boysSkills.sort((a, b) =>  a - b);
  girlsSkills.sort((a, b) =>  a - b);

  let count = 0;

  for(let i = 0; i < boysSkills.length; i++){
    for(let j = 0; j < girlsSkills.length; j++){
      let dif = Math.abs(boysSkills[i] - girlsSkills[j]);
      if(dif <= 1){
        count++;
        boysSkills[i] = Infinity;
        girlsSkills[j] = Infinity;
      }
    }
  }
  console.log(count)
  return count;
}


ATMs of a well-known bank of a small country are arranged so that they can not give any amount of money requested by the user. Due to the limited size of the bill dispenser (the device that is directly giving money from an ATM) and some peculiarities of the ATM structure, you can get at most k bills from it, and the bills may be of at most two distinct denominations.For example, if a country uses bills with denominations 10, 50, 100, 500, 1000 and 5000 burles, then at k = 20 such ATM can give sums 100 000 burles and 96 000 burles, but it cannot give sums 99 000 and 101 000 burles.Let's suppose that the country uses bills of n distinct denominations, and the ATM that you are using has an unlimited number of bills of each type. You know that during the day you will need to withdraw a certain amount of cash q times. You know that when the ATM has multiple ways to give money, it chooses the one which requires the minimum number of bills, or displays an error message if it cannot be done. Determine the result of each of the q of requests for cash withdrawal.

The first line contains two integers n, k (1 ≤ n ≤ 5000, 1 ≤ k ≤ 20). The next line contains n space-separated integers ai (1 ≤ ai ≤ 107) — the denominations of the bills that are used in the country. Numbers ai follow in the strictly increasing order. The next line contains integer q (1 ≤ q ≤ 20) — the number of requests for cash withdrawal that you will make. The next q lines contain numbers xi (1 ≤ xi ≤ 2·108) — the sums of money in burles that you are going to withdraw from the ATM.

For each request for cash withdrawal print on a single line the minimum number of bills it can be done, or print  - 1, if it is impossible to get the corresponding sum.

var InputReader = (function () {
    function InputReader() {
        this.index = 0;
        this.tokenizer = [];
    }
    InputReader.prototype.next = function () {
        while (this.tokenizer == null || this.index == this.tokenizer.length) {
            this.tokenizer = readline().split(" ");
            this.index = 0;
        }
        var res = this.tokenizer[this.index++];
        return res;
    };
    InputReader.prototype.nextInt = function () {
        return parseInt(this.next());
    };
    InputReader.prototype.nextFloat = function () {
        return parseFloat(this.next());
    };
    return InputReader;
})();

function main() {
    var input = new InputReader();

    var n = input.nextInt();
    var k = input.nextInt();
    var a = [];
    var is = {};
    for (var i = 0; i < n; i++) {
        a[i] = input.nextInt();
        is[a[i]] = true;
    }
    var q = input.nextInt();
    for (i = 0; i < q; i++) {
        var x = input.nextInt();
        var ans = k + 1;
        for (var j = 0; j < n; j++) {
            for (var q1 = 1; q1 <= k; q1++) {
                var part = a[j] * q1;
                if (part > x) break;
                if (part == x) {
                    ans = Math.min(ans, q1);
                    break;
                }
                for (var q2 = 1; q1 + q2 <= k; q2++) {
                    var part2 = x - part;
                    if (part2 % q2 == 0 && is[part2 / q2]) {
                        ans = Math.min(ans, q1 + q2);
                    }
                }
            }
        }
        if (ans > k) ans = -1;
        print(ans);
    }
}

main();


There are quite a lot of ways to have fun with inflatable balloons. For example, you can fill them with water and see what happens.Grigory and Andrew have the same opinion. So, once upon a time, they went to the shop and bought $$$n$$$ packets with inflatable balloons, where $$$i$$$-th of them has exactly $$$a_i$$$ balloons inside.They want to divide the balloons among themselves. In addition, there are several conditions to hold:  Do not rip the packets (both Grigory and Andrew should get unbroken packets);  Distribute all packets (every packet should be given to someone);  Give both Grigory and Andrew at least one packet;  To provide more fun, the total number of balloons in Grigory's packets should not be equal to the total number of balloons in Andrew's packets. Help them to divide the balloons or determine that it's impossible under these conditions.

The first line of input contains a single integer $$$n$$$ ($$$1 \le n \le 10$$$) — the number of packets with balloons. The second line contains $$$n$$$ integers: $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_n$$$ ($$$1 \le a_i \le 1000$$$) — the number of balloons inside the corresponding packet.

If it's impossible to divide the balloons satisfying the conditions above, print $$$-1$$$. Otherwise, print an integer $$$k$$$ — the number of packets to give to Grigory followed by $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ — the indices of those. The order of packets doesn't matter. If there are multiple ways to divide balloons, output any of them.

NoteIn the first test Grigory gets $$$3$$$ balloons in total while Andrey gets $$$1$$$.In the second test there's only one way to divide the packets which leads to equal numbers of balloons.In the third test one of the boys won't get a packet at all.

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray().map(Number);
  switch (n) {
    case 1:
      console.log(-1);
      break;
    case 2:
      if (packets[0] === packets[1])
        console.log(-1);
      else {
        console.log(`${1}\n${1}`);
      }
      break;
    default:
      console.log(1);
      const minElement = Math.min.apply(null, packets);
      console.log(packets.indexOf(minElement) + 1);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos = []
        let min = 9999999
        let pos = 0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if (min > arr[i]) {
                min = arr[i]
                pos = i
            }
        }
        if (sum - min !== min && sum - min !== 0) {
            console.log("1")
            console.log(pos + 1)
            return
        }

        console.log("-1")
        return 0;
    }
});

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            arrPos.push([arr[i],i])
        }

        arrPos=arrPos.sort(function sortNumber(a, b) {
            return a[0] - b[0];
        })
        let g = 0
        let currSum = 0
        let res= ""
        for (let i = 0; i < arrPos.length; i++) {
            g++
            currSum+=arrPos[i][0]
            res+=(arrPos[i][1]+1)+" "
            if (sum - arrPos[i][0] !== currSum&&g!== arrPos.length) {

                   console.log(g)
                   console.log(res)
                   return
            }
            sum-=arr[i]
        }

        console.log("-1")
        return 0;
    }
});

const count = +readline();
const arr = readline().split(' ').map(function(v){return +v;});
const total = arr.reduce((p, e) => p+e);
switch(count) {
    case 1: {
        print(-1);
        break;
    }
    case 2: {
        if (arr[0] === arr[1]) {
            print(-1);
            break;
        }
    }
    default: {
        if (total % 2 != 0 ) {
            print(1);
            print(1);
            break;
        } else {
            const half = total / 2;
            kek = false;
            for(var i=0; i<count; i++) {
                if (arr[i] != half) {
                    print(1);
                    print(i+1);
                    kek = true;
                    break;
                }
            }
            if (kek) break;
        }
        print(-1);
    }
}

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray();
  if (n < 3)
    console.log(-1);
  else {
    console.log(1);
    console.log(packets[0]);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray();
  if (n < 3)
    console.log(-1);
  else {
    console.log(n - 1);
    packets.pop();
    console.log(packets.join(' '));
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray().map(Number);
  if (n < 3)
    console.log(-1);
  else {
    console.log(1);
    const minElement = Math.min.apply(null, packets);
    console.log(packets.indexOf(minElement) + 1);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  const packets = is.nextArray().map(Number);
  switch (n) {
    case 1:
      console.log(-1);
      break;
    case 2:
      if (packets[0] === packets[1])
        console.log(-1);
      else {
        console.log(1);
        console.log(packets[0]);
      }
      break;
    default:
      console.log(1);
      const minElement = Math.min.apply(null, packets);
      console.log(packets.indexOf(minElement) + 1);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const n = is.nextInt();
  if (n < 3)
    console.log(-1);
  else {
    console.log(`${1}\n${1}`);
  }
}

/*
 *  api stdin
 */

class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n');
  }

  nextLine() {
    return this.lines[this.index++];
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray() {
    return this.nextLine().split(' ');
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(10))
        let sum = 0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
        }
        let g = 0
        let currSum = 0
        let res= ""
        for (let i = 0; i < arr.length; i++) {
            g++
            currSum+=arr[i]
            res+=(i+1)+" "
            if (sum - arr[i] !== currSum&&g!== arr.length) {

                   console.log(g)
                   console.log(res)
                   return
            }
            sum-=arr[i]
        }

        console.log("-1")
        return 0;
    }
});

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        let min=9999999
        let pos=0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if(min>arr[i]){
                min=arr[i]
                pos=i
            }
        }
        if(sum-min!==min){
            console.log("1")
            console.log(pos+1)
            return
        }

        console.log("-1")
        return 0;
    }
});

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        let min=9999999
        let pos=0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if(min>arr[i]){
                min=arr[i]
                pos=i
            }
        }
        if(min-sum!==min){
            console.log("1")
            console.log(pos)
            return
        }

        console.log("-1")
        return 0;
    }
});

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

let l = 0;
rl.on('line', (input) => {
    if (l === 0) { l++ }
    else {
        rl.close();
        let arr = input.split(" ").map(x => parseInt(x))
        let sum = 0
        let arrPos= []
        let min=9999999
        let pos=0
        for (let i = 0; i < arr.length; i++) {
            sum += arr[i]
            if(min>arr[i]){
                min=arr[i]
                pos=i
            }
        }
        if(min-sum!==min){
            console.log("1")
            console.log(pos+1)
            return
        }

        console.log("-1")
        return 0;
    }
});


The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.

The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.

Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10 - 9.

function InputReader(){
	this.arr = [];
	this.ind = 1;
}

InputReader.prototype.next = function(){
	if(this.ind<this.arr.length)
		return this.arr[this.ind++];
	else{
		this.arr = readline().split(" ");
		this.ind=0;
		return this.arr[this.ind++];
	}
}

function OutputWriter(){
	this.s = "";
}

OutputWriter.prototype.write = function(s1){
	this.s+=s1;
}
OutputWriter.prototype.writeln = function(s1){
	this.s+=s1;
	print(this.s);
	this.s = "";
}

OutputWriter.prototype.flush = function(){
	print(this.s);
	this.s = "";
}

function main(){
	var input = new InputReader();
	var output = new OutputWriter();

	solve(input,output);

	output.flush();
}

function solve(input, output){

	var r = +input.next();
	var s = +input.next();
	var t = +input.next();

	var dp = [];
	for(var i=0; i<=r; i++){
		var dp2 = [];
		for(var j=0; j<=s; j++){
			var dp3 = [];
			for(var k=0; k<=t; k++)
				dp3.push(0);
			dp2.push(dp3);
		}
		dp.push(dp2);
	}

	dp[r][s][t] = 1;
	for(var i=r; i>=0; i--){
		for(var j=s; j>=0; j--){
			for(var k=t; k>=0; k--){
				if(i==r && j==s && k==t) continue;
				if(i+1<=r && ((i+1)*j+j*k+k*(i+1))>0){
					dp[i][j][k]+=dp[i+1][j][k]*((i+1)*k)/((i+1)*j+j*k+k*(i+1));
				}
				if(j+1<=s && (i*(j+1)+(j+1)*k+k*i)>0){
					dp[i][j][k]+=dp[i][j+1][k]*(i*(j+1))/(i*(j+1)+(j+1)*k+k*i);
				}
				if(k+1<=t && (i*j+j*(k+1)+(k+1)*i)>0){
					dp[i][j][k]+=dp[i][j][k+1]*((j*(k+1))/(i*j+j*(k+1)+(k+1)*i));
				}
			}

		}
	}

	//print(dp[2][1][0]);
	var ansR=0,ansS=0,ansT=0;
	for(i=1; i<=r; i++) ansR+=dp[i][0][0];
	for(i=1; i<=s; i++) ansS+=dp[0][i][0];
	for(i=1; i<=t; i++) ansT+=dp[0][0][i];

	output.write(ansR+" "+ansS+" "+ansT);
}

main();


Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?Note: uppercase and lowercase letters are considered different.

Input contains a single line containing a string s (1  ≤  |s|  ≤  105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s. The string s contains lowercase and uppercase English letters, i.e. .

Output a single integer, the answer to the problem.

NoteIn the first case, you could pick: Bulbbasaur.In the second case, there is no way to pick even a single Bulbasaur.In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".

function toInt( s ) { return s.charCodeAt(0); }

function main()
{
    var s = readline();
    var t = "Bulbasaur";

    var a = {} , b = {};

    s.split('').forEach( (v) => a[v] = a[v] ? a[v]+1 : 1 );
    t.split('').forEach( (v) => b[v] = b[v] ? b[v]+1 : 1 );

    var ans = 1e9 + 5;
    for ( var i in b )
    {
        var c1 = a[i] ? a[i] : 0;
        var c2 = b[i];
        var thiz = ~~( c1 / c2 );   // ~~ => floor ( http://stackoverflow.com/questions/4228356/how-to-perform-integer-division-and-get-the-remainder-in-javascript )
        ans = Math.min( ans , thiz );
    }
    print( ans );

} main();

function toInt( s ) { return s.charCodeAt(0); }

function main()
{
    var s = readline();
    var t = "Bulbasaur";

    var a = new Array( 256 ).fill(0);
    var b = new Array( 256 ).fill( 0 );

    s.split('').forEach( (v) => a[toInt(v)]++ );
    t.split('').forEach( (v) => b[toInt(v)]++ );

    var ans = 1e9 + 5;
    for ( var i=0 ; i<256 ; i++ )
    {
        if ( b[i] > 0 )
        {
            var thiz = ~~( a[i] / b[i] );   // ~~ => floor ( http://stackoverflow.com/questions/4228356/how-to-perform-integer-division-and-get-the-remainder-in-javascript )
            ans = Math.min( ans , thiz );
        }
    }
    print( ans );

} main();

function main() {
    var s1 = readline();
    var lettersCounts = {};
    for(var i=0;i<s1.length;i++){
        if(lettersCounts[s1[i]]){
            lettersCounts[s1[i]]++;
        } else {
            lettersCounts[s1[i]] = 1;
        }
    }
   var array = [];
    var bulb = "Bulbasaur";
    for(var i=0;i<bulb.length;i++){
        if(bulb[i] == "u" || bulb[i] == "a"){
            array.push(Math.floor((lettersCounts[bulb[i]] || 0)/ 2));
        } else {
            array.push(lettersCounts[bulb[i]] || 0);
        }
    }
    print(Math.min(...array));
}

main()

let str = ''
process.stdin.on('data', c => str += c)
process.stdin.on('end', () => {
let strArr = str.split('')
let obj = {};
let obj1 = { B: 1, u: 2, l: 1, b: 1, a: 2, s: 1, r: 1 }
strArr.forEach((item, i) => {
    Object.keys(obj1).forEach(key => {
        if(item == key) {
            if(!obj[item])
                obj[item] = (obj[item] || 0) + 1
            else {
                obj[item] += 1
            }
        }

    })
})

let objLen = Object.keys(obj).length;
let obj1Len = Object.keys(obj1).length;
if(objLen != obj1Len) {
    console.log(0);
}
else {
    let arr = []
    Object.keys(obj).forEach(k => {
        Object.keys(obj1).forEach(k1 => {
            if(k == k1) {
                arr.push(Math.floor(obj[k]/obj1[k1]))
            }
        })
    })
    let res = arr.reduce((prev, curr) => {
       return (prev < curr) ? prev : curr
    })
    console.log(res)
}
})

let str = ''
process.stdin.on('data', c => str += c)
process.stdin.on('end', () => {
    // console.log(i);

let strArr = str.split('')
// console.log(strArr)
let arr = [];
let obj = {};
let obj1 = { B: 1, u: 2, l: 1, b: 2, a: 2, s: 1, r: 1 }
strArr.forEach((item, i) => {
    Object.keys(obj1).forEach(key => {
        if(item == key) {
            if(!obj[item])
                obj[item] = (obj[item] || 0) + 1
            else {
                obj[item] += 1
            }
        }

    })
})
let objLen = Object.keys(obj).length;
let obj1Len = Object.keys(obj1).length;
if(objLen != obj1Len) {
    console.log(0);
}
else {
    let arr = []
    Object.keys(obj).forEach(k => {
        arr.push(obj[k])
    })
    let res = arr.reduce((prev, curr) => {
       return (prev < curr) ? prev : curr
    })
    console.log(res)
}
})

let str = ''
process.stdin.on('data', c => str += c)
process.stdin.on('end', () => {
let strArr = str.split('')
let obj = {};
let obj1 = { B: 1, u: 2, l: 1, b: 2, a: 2, s: 1, r: 1 }
strArr.forEach((item, i) => {
    Object.keys(obj1).forEach(key => {
        if(item == key) {
            if(!obj[item])
                obj[item] = (obj[item] || 0) + 1
            else {
                obj[item] += 1
            }
        }

    })
})

let objLen = Object.keys(obj).length;
let obj1Len = Object.keys(obj1).length;
if(objLen != obj1Len) {
    console.log(0);
}
else {
    let arr = []
    Object.keys(obj).forEach(k => {
        Object.keys(obj1).forEach(k1 => {
            if(k == k1) {
                arr.push(Math.floor(obj[k]/obj1[k1]))
            }
        })
    })
    let res = arr.reduce((prev, curr) => {
       return (prev < curr) ? prev : curr
    })
    console.log(res)
}
})


Given an array $$$a$$$ of length $$$n$$$ and an integer $$$k$$$, you are tasked to find any two numbers $$$l$$$ and $$$r$$$ ($$$l \leq r$$$) such that:   For each $$$x$$$ $$$(l \leq x \leq r)$$$, $$$x$$$ appears in $$$a$$$ at least $$$k$$$ times (i.e. $$$k$$$ or more array elements are equal to $$$x$$$).  The value $$$r-l$$$ is maximized. If no numbers satisfy the conditions, output -1.For example, if $$$a=[11, 11, 12, 13, 13, 14, 14]$$$ and $$$k=2$$$, then:   for $$$l=12$$$, $$$r=14$$$ the first condition fails because $$$12$$$ does not appear at least $$$k=2$$$ times.  for $$$l=13$$$, $$$r=14$$$ the first condition holds, because $$$13$$$ occurs at least $$$k=2$$$ times in $$$a$$$ and $$$14$$$ occurs at least $$$k=2$$$ times in $$$a$$$.  for $$$l=11$$$, $$$r=11$$$ the first condition holds, because $$$11$$$ occurs at least $$$k=2$$$ times in $$$a$$$. A pair of $$$l$$$ and $$$r$$$ for which the first condition holds and $$$r-l$$$ is maximal is $$$l = 13$$$, $$$r = 14$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains the integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \leq k \leq n$$$) — the length of the array $$$a$$$ and the minimum amount of times each number in the range $$$[l, r]$$$ should appear respectively. Then a single line follows, containing $$$n$$$ integers describing the array $$$a$$$ ($$$1 \leq a_i \leq 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output $$$2$$$ numbers, $$$l$$$ and $$$r$$$ that satisfy the conditions, or "-1" if no numbers satisfy the conditions. If multiple answers exist, you can output any.

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => a - b);
    // console.log(keys)
    let index = 0;
    while (right <= max + 1) {
        // console.log({left, right}, keys[index], keys)
        if (map.get(right) >= k){
            // console.log("expand");
            index++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            if (map.get(keys[index]) >= k) {
                left = keys[index];
            } else {
                left = keys[++index];
            }
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, k] = iInpArr();
    let arr = iInpArr();
    let obj = {};
    for (let i = 0; i < n; i++) {
      if (obj[arr[i]] === undefined) obj[arr[i]] = 1;
      else obj[arr[i]]++;
    }
    let keys = Object.keys(obj);
    let res = [];
    for (let i of keys) {
      if (obj[i] >= k) res.push(parseInt(i));
    }
    if (res.length === 0) console.log(-1);
    else if (res.length === 1) console.log(res[0] + " " + res[0]);
    else {
      res.sort((a, b) => a - b);
      let j = 1,
        i = 0,
        max = 0,
        ans;
      while (j < res.length) {
        let y = res[j] - res[i] + 1;
        if (y === j - i + 1) {
          if (max <= res[j] - res[i]) {
            max = res[j] - res[i];
            ans = [res[i], res[j]];
          }
          j++;
        } else i++;
      }
      console.log(ans.join(" "));
    }
  }
};
solve();

'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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, k] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    // 1
    a.sort((a, b) => {
      if(a < b) return -1;
      else return 1;
    });
    // 2
    let last = a[0];
    let cnt = 1;
    const aa = [];
    for(let i = 1; i < n; i++){
      if(last !== a[i]){
        if(cnt >= k) aa.push(last);
        cnt = 1;
        last = a[i];
      }
      else{
        cnt++;
      }
    }
    if(cnt >= k) aa.push(last);
    if(!aa.length){
      console.log(-1);
      continue;
    }
    // 3
    const aaa = [];
    last = aa[0];
    let tmp = [aa[0]];
    for(let i = 1; i < aa.length; i++){
      if(aa[i]-1 === last){
        tmp.push(aa[i]);
      }
      else{
        aaa.push(JSON.parse(JSON.stringify(tmp)));
        tmp = [aa[i]];
      }
      last = aa[i];
    }
    if(tmp.length) aaa.push(tmp);
    // 4
    const aaaa = [];
    for(let i = 0; i < aaa.length; i++){
      let s = aaa[i].length;
      let l = aaa[i][0];
      let r = aaa[i][s-1];
      aaaa.push([r-l, l, r]);
    }
    aaaa.sort((a, b) => {
      if(a[0] > b[0]) return -1;
      else return 1;
    });
    console.log(aaaa[0][1], aaaa[0][2]);
  }
}

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
const INF = Infinity;
let n;
let k;
let a;
function solve() {
    let b = [];
    a.sort((x, y) => x - y);
    let last = a[0];
    let cnt = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] == last) {
            cnt++;
        }
        else {
            if (cnt >= k) {
                b.push(last);
            }
            cnt = 1;
            last = a[i];
        }
    }
    if (cnt >= k) {
        b.push(last);
    }
    let m = b.length;
    if (m == 0) {
        return false;
    }
    let l = 0;
    let best = 1;
    let lo = b[0];
    let hi = b[0];
    while (l < m) {
        let r = l + 1;
        while (r < m && r - l == b[r] - b[l]) {
            if (best < r - l + 1) {
                best = r - l + 1;
                lo = b[l];
                hi = b[r];
            }
            r++;
        }
        l = r;
    }
    printf("%d %d\n", lo, hi);
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        k = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

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(`Test #${testN}`, obj);

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

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, k] = ra();
  let A = ra();
  LT({n, k, A});
  // PROCESSING:
  A.sort((a, b)=>a-b);
  let cnt = {};
  for (let i=0; i<n; i++){
    cnt[A[i]] = (cnt[A[i]]||0)+1
  }
  L(cnt)
  let uniq = Object.keys(cnt).map(u=>+u);
  let max = -1;
  let ansL, ansR;
  let l=0, r = 0;
  while (l<uniq.length){
    r = l;
    while (r<uniq.length && cnt[uniq[r]]>=k && (r==l || uniq[r]-1==uniq[r-1])){
      r++;
    }
    if (r>l && uniq[r-1]-uniq[l]>max){
      max = uniq[r-1]-uniq[l];
      ansL = uniq[l];
      ansR = uniq[r-1];
    }
    if (l==r)
      l = r+1;
    else
      l = r;
  }
  if (max==-1)
    return -1;
  return [ansL, ansR]
};

'use strict';

var readline = require('readline');

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

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

function solve(n, k, a) {
  const map = new Map();
  for (let num of a) {
    var _map$get;
    map.set(num, ((_map$get = map.get(num)) !== null && _map$get !== void 0 ? _map$get : 0) + 1);
  }
  let nums = [];
  for (let [num, count] of map) {
    if (count >= k) nums.push(num);
  }
  nums.sort((a, b) => a - b);
  let l = 0,
      r = -1;
  for (let i = 0; i < nums.length;) {
    let j = i;
    while (nums[j + 1] === nums[j] + 1) {
      j++;
    }
    if (nums[j] - nums[i] > r - l) {
      l = nums[i];
      r = nums[j];
    }
    i = j + 1;
  }
  if (r === -1) return -1;
  return `${l} ${r}`;
}

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

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

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(N);
		var map = getCountMap(list);
		var key = Object.keys(map);
		key.sort(function(a,b){
			return a - b;
		});
		var ok = false;
		for(var i = 0; i < key.length; i++){
			if(map[key[i]] >= K){
				ok = true;
				break;
			}
		}
		if(!ok){
			myout(-1);
			continue;
		}
		var output = "";
		var size = -1;
		var L = 0;
		var R = 0;
		var lastNo = myconv(key[0], 1);
		while(L < key.length && R < key.length){
			var ok = true;
			if(L != R){
				if(lastNo + 1 != key[R]){
					ok = false;
				}
			}
			if(map[key[R]] != null && map[key[R]] >= K && ok){
				lastNo = myconv(key[R], 1);
				R++;
				continue;
			}else{

				if(R - L + 1 > size){
					size = R - L + 1;
					output = key[L] + " " + key[R - 1];
				}
				if(L == R){
					R++;
				}
				L = R;
			}
		}
		if(R - L + 1 > size){
			size = R - L + 1;
			output = key[L] + " " + key[R - 1];
		}
		myout(output);
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, k] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, k, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, k, arr) {
    const map = arr.reduce((o, x) => {
        o[x] = (o[x] || 0) + 1
        return o
    }, {})
    let max = -1
    let p, c
    let l, r
    Object.keys(map)
        .map(Number)
        .sort((a, b) => a - b)
        .forEach(x => {
            if (map[x] >= k) {
                if (p + 1 === x) {
                    c++
                } else {
                    c = 1
                }
                p = x
                if (c > max) {
                    max = c
                    l = x - max + 1
                    r = x
                }
            } else {
                p = -1
            }
        })
    return max < 0 ? -1 : l + ' ' + r
}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], k = _a[1];
    var a = readline().split(' ').map(function (v) { return +v; });
    a.sort(function (a, b) { return a - b; });
    var m = new Map();
    for (var i = 0; i < n; i++) {
        if (m.has(a[i])) {
            m.set(a[i], m.get(a[i]) + 1);
        }
        else {
            m.set(a[i], 1);
        }
    }
    var b = (Array.from(m.entries()));
    n = b.length;
    var maxL = 0, maxR = 0;
    var max = 0;
    var l = 0;
    var r = 0;
    var prev = b[0][0] - 1;
    while (l < n) {
        while (b[r][1] >= k && b[r][0] === prev + 1) {
            prev = b[r][0];
            r++;
            if (r === n)
                break;
        }
        if (r - l > max) {
            maxR = b[r - 1][0];
            maxL = b[l][0];
            max = r - l;
        }
        if (r === n)
            break;
        l = b[r][1] >= k ? r : r + 1;
        r = l;
        if (r === n)
            break;
        prev = b[r][0] - 1;
    }
    print(max ? "".concat(maxL, " ").concat(maxR) : -1);
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => a - b);
    // console.log(keys)
    let index = 0;
    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand");
            index++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = keys[++index];
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => a - b);
    // console.log(keys)
    let index = 0;
    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand");
            index++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = keys[index++];
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];
    const keys = [...map.keys()].sort((a, b) => b - a);
    let pointer = 0;
    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand");
            pointer++;
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange <= right -1  - left + 1) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = keys[pointer++];
            right = left;
            // console.log(ans)
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

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

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const n = nextInt();
    const k = nextInt();
    const arr = nextIntArray(n);

    const map = new Map();
    let min = Infinity;
    let max = 0;

    for (let i = 0; i < arr.length; i++) {
        if (map.get(arr[i])) {
            map.set(arr[i], map.get(arr[i]) + 1)
        } else {
            map.set(arr[i], 1);
        }
        min = Math.min(min, arr[i]);
        max = Math.max(max, arr[i])
    }

    // console.log({min, max, map, k})
    let left = min, right = min;
    const ans = [0, 0];

    while (right <= max + 1) {
        if (map.get(right) >= k){
            // console.log("expand")
            right++;
        } else {
            // console.log("sink")
            // console.log(left, right)
            let maxRange = ans[1] - ans[0] + 1;
            if (maxRange < right - left) {
                ans[0] = left;
                ans[1] = right - 1;
            }
            left = right + 1;
            right++;
        }
    }

    // console.log(ans)

    if (ans[0] === 0 && ans[1] === 0) {
        myout(-1);
    } else {
        myout(`${ans[0]} ${ans[1]}`);
    }
}

const solve = (arr, n, k) => {
  let obj = {},narr = [];
  for (let i = 0; i < n; i++) {
    if (!obj[arr[i]]) {
         obj[arr[i]] = 1;
         narr.push(arr[i]);
    }
    else obj[arr[i]]++;
  }
  let max = -Infinity,l,r;
  for(let i=0;i<narr.length;i++){
       for(let j=i;j<narr.length;j++){
            if((obj[narr[i]]>=k)&&(obj[narr[j]]>=k)){
                 if(max<Math.abs(narr[i]-narr[j])){
                      max = Math.abs(narr[i]-narr[j]);
                      if(narr[i]<narr[j]) {
                           l = narr[i];
                           r = narr[j];
                      }
                      else{
                            l = narr[j];
                           r = narr[i];
                      }
                 }
            }
       }
  }
  if (max === -Infinity) return -1;
  return l+" "+r;
};
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    console.log(solve(arr,n,k));
  }
}
main();

'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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, k] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    // 1
    a.sort((a, b) => {
      if(a < b) return -1;
      else return 1;
    });
    // 2
    let last = a[0];
    let cnt = 1;
    const aa = [];
    for(let i = 1; i < n; i++){
      if(last !== a[i]){
        if(cnt >= k) aa.push(last);
        cnt = 1;
        last = a[i];
      }
      else{
        cnt++;
      }
    }
    if(cnt >= k) aa.push(last);
    if(!aa.length){
      continue;
    }
    // 3
    const aaa = [];
    last = aa[0];
    let tmp = [aa[0]];
    for(let i = 1; i < aa.length; i++){
      if(aa[i]-1 === last){
        tmp.push(aa[i]);
      }
      else{
        aaa.push(JSON.parse(JSON.stringify(tmp)));
        tmp = [aa[i]];
      }
      last = aa[i];
    }
    if(tmp.length) aaa.push(tmp);
    // 4
    const aaaa = [];
    for(let i = 0; i < aaa.length; i++){
      let s = aaa[i].length;
      let l = aaa[i][0];
      let r = aaa[i][s-1];
      aaaa.push([r-l, l, r]);
    }
    aaaa.sort((a, b) => {
      if(a[0] > b[0]) return -1;
      else return 1;
    });
    console.log(aaaa[0][1], aaaa[0][2]);
  }
}

'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 input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, k] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    // 1
    a.sort();
    // 2
    let last = a[0];
    let cnt = 1;
    const aa = [];
    for(let i = 1; i < n; i++){
      if(last !== a[i]){
        if(cnt >= k) aa.push(last);
        cnt = 1;
        last = a[i];
      }
      else{
        cnt++;
      }
    }
    if(cnt >= k) aa.push(last);
    if(!aa.length){
      console.log(-1);
      continue;
    }
    // 3
    const aaa = [];
    last = aa[0];
    let tmp = [aa[0]];
    for(let i = 1; i < aa.length; i++){
      if(aa[i]-1 === last){
        tmp.push(aa[i]);
      }
      else{
        aaa.push(JSON.parse(JSON.stringify(tmp)));
        tmp = [aa[i]];
      }
      last = aa[i];
    }
    if(tmp.length) aaa.push(tmp);
    // 4
    let aaaa = [];
    for(let i = 0; i < aaa.length; i++){
      let s = aaa[i].length;
      let l = aaa[i][0];
      let r = aaa[i][s-1];
      aaaa.push([r-l, l, r]);
    }
    aaaa.sort((a, b) => {
      if(a[0] > b[0]) return -1;
      else return 1;
    });
    console.log(aaaa[0][1], aaaa[0][2]);
  }
}

'use strict';
const readline = require('readline');
const util = require('util');
const lineReader = readline.createInterface({
    input: process.stdin,
});
let inputPos = 0;
const inputWords = [];
lineReader.on('line', (line) => {
    inputWords.push.apply(inputWords, line.split(' ').filter(s => s != ''));
});
lineReader.on('close', main);
function check(b) {
    if (!b) {
        process.stderr.write(`${new Error().stack}\n`);
        process.exit(-1);
    }
}
function printf(...args) {
    process.stdout.write(util.format(...args));
}
function nextInt() {
    return Math.trunc(Number(inputWords[inputPos++]));
}
function nextStr() {
    return inputWords[inputPos++];
}
function af(l) {
    return Array.from({ length: l });
}
const INIT = -1;
const INF = Infinity;
let n;
let k;
let a;
function solve() {
    let b = [];
    a.sort((x, y) => x - y);
    let last = a[0];
    let cnt = 1;
    for (let i = 1; i < n; i++) {
        if (a[i] == last) {
            cnt++;
        }
        else {
            if (cnt >= k) {
                b.push(last);
            }
            cnt = 1;
            last = a[i];
        }
    }
    if (cnt >= k) {
        b.push(last);
    }
    let m = b.length;
    if (m == 0) {
        return false;
    }
    let l = 0;
    let best = 0;
    let lo = INF;
    let hi = INF;
    while (l < m) {
        let r = l + 1;
        while (r < m && r - l == b[r] - b[l]) {
            if (best < r - l) {
                best = r - l;
                lo = b[l];
                hi = b[r];
            }
            r++;
        }
        l = r;
    }
    printf("%d %d\n", lo, hi);
    return true;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        n = nextInt();
        k = nextInt();
        a = af(n);
        for (let i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        if (!solve()) {
            printf("%d\n", INIT);
        }
    }
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

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(`Test #${testN}`, obj);

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

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, k] = ra();
  let A = ra();
  LT({n, k, A});
  // PROCESSING:
  A.sort((a, b)=>a-b);
  let cnt = {};
  for (let i=0; i<n; i++){
    cnt[A[i]] = (cnt[A[i]]||0)+1
  }
  L(cnt)
  let uniq = Object.keys(cnt).map(u=>+u);
  let max = -1;
  let ansL, ansR;
  let l=0, r = 0;
  while (l<uniq.length){
    r = l;
    while (r<uniq.length && cnt[uniq[r]]>=k && (r==l || uniq[r]-1==uniq[r-1])){
      r++;
    }
    if (r>l && uniq[r-1]-uniq[l]>max){
      max = uniq[r-1]-uniq[l];
      ansL = uniq[l];
      ansR = uniq[r-1];
    }
    l = r + 1;
  }
  if (max==-1)
    return -1;
  return [ansL, ansR]
};

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], k = _a[1];
    var a = readline().split(' ').map(function (v) { return +v; });
    a.sort();
    var m = new Map();
    for (var i = 0; i < n; i++) {
        if (m.has(a[i])) {
            m.set(a[i], m.get(a[i]) + 1);
        }
        else {
            m.set(a[i], 1);
        }
    }
    var b = (Array.from(m.entries()));
    n = b.length;
    var maxL = 0, maxR = 0;
    var max = 0;
    var l = 0;
    var r = 0;
    var prev = b[0][0] - 1;
    while (l < n) {
        while (b[r][1] >= k && b[r][0] === prev + 1) {
            prev = b[r][0];
            r++;
            if (r === n)
                break;
        }
        if (r - l > max) {
            maxR = b[r - 1][0];
            maxL = b[l][0];
            max = r - l;
        }
        if (r === n)
            break;
        l = b[r][1] >= k ? r : r + 1;
        r = l;
        if (r === n)
            break;
        prev = b[r][0] - 1;
    }
    print(max ? "".concat(maxL, " ").concat(maxR) : -1);
}