You talked to Polycarp and asked him a question. You know that when he wants to answer "yes", he repeats Yes many times in a row.Because of the noise, you only heard part of the answer — some substring of it. That is, if he answered YesYes, then you could hear esY, YesYes, sYes, e, but you couldn't Yess, YES or se.Determine if it is true that the given string $$$s$$$ is a substring of YesYesYes... (Yes repeated many times in a row).

The first line of input data contains the singular $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Each test case is described by a single string of Latin letters $$$s$$$ ($$$1 \le |s| \le 50$$$) — the part of Polycarp's answer that you heard, where $$$|s|$$$ — is the length of the string $$$s$$$.

Output $$$t$$$ lines, each of which is the answer to the corresponding test case. As an answer, output "YES" if the specified string $$$s$$$ is a substring of the string YesYesYes...Yes (the number of words Yes is arbitrary), and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

12

YES

esYes

codeforces

es

se

YesY

esYesYesYesYesYesYe

seY

Yess

sY

o

Yes

NO
YES
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES

"use strict";
exports.__esModule = true;
var readline_1 = require("readline");
var yesMap = {
	Y: "e",
	e: "s",
	s: "Y",
};
function isValidSubString(s) {
	if (s === "Y" || s === "e" || s === "s") {
		return true;
	}
	return false;
}
function findYesSubString(lines) {
	var testCases = Number(lines[0]);
	var mainString;
	var isPartOfYes;
	for (var i = 1; i <= testCases; i++) {
		isPartOfYes = false;
		mainString = lines[i];
		var char = void 0;
		// mainString = mainString.replace("Yes", "");
		for (var j = 0; j < mainString.length; j++) {
			char = mainString[j];
			if (mainString.length === 1 && isValidSubString(char)) {
				isPartOfYes = true;
				break;
			}
			if (mainString.length === j + 1) {
				break;
			}
			// console.log(i, mainString, yesMap[char], mainString[j + 1], char);
			if (isValidSubString(char) && yesMap[char] === mainString[j + 1]) {
				isPartOfYes = true;
			} else {
				isPartOfYes = false;
				break;
			}
		}
		if (isPartOfYes) {
			console.log("YES");
		} else {
			console.log("NO");
		}
	}
}
var rl = readline_1.createInterface(process.stdin, process.stdout);
var input = [];
rl.on("line", function (line) {
	return input.push(line);
}).on("close", function () {
	return findYesSubString(input);
});
var a = "s";

    const fs = require("fs");
    const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
    let currentline = 0;
    function readline(){
          return input[currentline++];
    }
    function alph() {
      var f = 'abcdefghijklmnopqrstuvwxyz';
      return f;
    }
    function Alph() {
      var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      return f;
    }
    function max(x,y) {
      return x >=y ? x : y;
    }
    function min(x,y) {
      return x <=y ? x : y;
    }
    function abs(x) {
      return x < 0 ? x*(-1) : x;
    }
    var T = readline();
    var inf = 1000000000000;
    for(var tc=1;tc<=T;tc++) {
    	var n = readline();
    	var N = n.length;
    	var ok = false;
    	var ref = ["Y","e","s"];
    	var r = ref.indexOf(n[0]);
    	if(r!==-1) {
    		var j = 0;
    		while(j<N && n[j] === ref[r]) {
    			j++;
    			r = (r+1)%3;
    		}
    		if(j==N) ok = true;
    	}
    	console.log(ok ? "Yes" : "No")
    }

"use strict";

const rl = require('readline').createInterface(process.stdin, process.stdout);
let all_input = [];

rl.on('line', function(input){
  all_input.push(input);
});

rl.on('close', function(line){
  let index = 0;
  let t = +all_input[index++]; // + makes turns a convertable number string to a number

  while(t--)
  {
    let str = all_input[index++];

    solve(str);
  }
});

function solve(str)
{
  let temp_s = '';
  let temp_len = Math.floor(str.length / 3) + 3;

  for(let i = 0; i < temp_len; i++)
  {
    temp_s += "Yes";
  }
  //console.log(temp_s);

  if(temp_s.search(str) !== -1)
    console.log("YES");
  else
    console.log("NO");
}

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 t = parseInt(readline());

	for (let i = 0; i < t; i++) {
		let s = readline();
		let yes = ['Y', 'e', 's'];
		let index = -1;
		let i = 0;

		// s es substring de YesYesYes

		let esSubstring = true;

		if (s[0] != 'Y' && s[0] != 'e' && s[0] != 's') {
			esSubstring = false;
		}

		if (s[0] == 'Y') {
			index = 0;
		} else if (s[0] == 'e') {
			index = 1;
		}
		if (s[0] == 's') {
			index = 2;
		}

		while (esSubstring && i < s.length) {
			if (s[i] != yes[index]) {
				esSubstring = false;
			}
			if (index == 2) {
				index = 0;
			} else {
				index++;
			}
			i++;
		}
		if (esSubstring) {
			console.log('YES');
		} else {
			console.log('NO');
		}
	}
}

'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() {
    const testCases = Number(readline());
    const str = 'Yes'.repeat(50);
    for (let i = 0; i < testCases; i++) {
        let chunk = readline();
        if (findChunk(str, chunk)) console.log("YES");
        else console.log("NO");
    }
}

function findChunk(str, chunk) {
    return str.indexOf(chunk) > -1
}

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

let lines = []

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

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

rl.on("close", () => {
  const readLine = createReadLine();
  let t = int(readLine());
  while (t--) {
    let str = readLine();
    let len = str.length
    let yes = 'Yes'.repeat(len)
    if (yes.includes(str)) {
      console.log('YES')
    } else {
      console.log('NO')
    }
  }
});

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 str = lines[l++]
        output[i] = solve(str) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(str) {
    const n = str.length
    let a = Array(n)
    let b = Array(n)
    let c = Array(n)
    const s = 'Yes'
    for (let i = 0; i < n; i++) {
        a[i] = s[i % 3]
        b[i] = s[(i + 1) % 3]
        c[i] = s[(i + 2) % 3]
    }
    a = a.join('')
    b = b.join('')
    c = c.join('')
    // console.log(n, a, b, c)
    return a === str || b === str || c === str
}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  let s = read();
  if (s[0] !== 'Y' && s[0] !== 'e' && s[0] !== 's') return 'NO';
  let i = 0,
      j = 0;
  if (s[0] === 'e') j = 1;else if (s[0] === 's') j = 2;
  const s1 = 'Yes';
  while (i < s.length) {
    if (s[i] !== s1[j]) return 'NO';
    j = (j + 1) % 3;
    i++;
  }
  return 'YES';
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

//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();
	var V = "";
	for(var i = 0; i < 10000; i++){
		V += "Yes";
	}
	while(hasNext()){
		var s = next();
		if(V.indexOf(s) != -1){
			myout("Yes");
		}else{
			myout("No");
		}
	}
}

var input = readline();

for(var i=0; i<Number(input); i++) {
    var word = readline();
    if(word[0] != "Y" && word[0] != "e" && word[0] != "s") {
        print("NO");
        continue;
    }

    for(var j=0; j<word.length; j++) {
        if(j == word.length - 1) {
            print("YES");
            break;
        }
        if(word[j] == "Y") {
            if(word[j+1] != "e") {
                print("NO");
                break;
            }
        }
        else if(word[j] == "e") {
            if(word[j+1] != "s") {
                print("NO");
                break;
            }
        }
        else {
            if(word[j+1] != "Y") {
                print("NO");
                break;
            }
        }
    }
}

var numOfCases = Number(readline());

var template = 'YesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYesYes';

for (var testCase = 0; testCase < numOfCases; testCase++) {
    var input = readline();

    var result = process(input);
    print(result);
}

function process(input) {
    return template.indexOf(input) !== -1 ? 'YES' : 'NO';
}

var n = parseInt(readline());

for(var i = 0; i < n; i++) {
  var s = readline();

  var yes = 'Yes';

  var k = 0;

  while(k < 3 && yes[k] !== s[0]) k++;

  k %= 3;

  if(yes[k] !== s[0]) {
    print('NO');
    continue;
  }

  var j = 0;
  for(; j < s.length;) {
    if(yes[k] === s[j]) {
      k = (k + 1) % 3;
      j++;
    } else {
      print('NO')
      break;
    }
  }

  if(j === s.length) print('YES');
}

var n = Number(readline());

for (var i = 0; i < n; i++) {
  var str = readline();
  var b = "Yes".repeat(50).indexOf(str) > -1;
  print(b ? "Yes" : "NO");
}

"use strict";
exports.__esModule = true;
var readline_1 = require("readline");
var yesMap = {
	Y: "e",
	e: "s",
	s: "Y",
};
function isValidSubString(s) {
	if (s === "Y" || s === "e" || s === "s") {
		return true;
	}
	return false;
}
function findYesSubString(lines) {
	var testCases = Number(lines[0]);
	var mainString;
	var isPartOfYes;
	for (var i = 1; i <= testCases; i++) {
		isPartOfYes = false;
		mainString = lines[i];
		var char = void 0;
		// mainString = mainString.replace("Yes", "");
		for (var j = 0; j < mainString.length; j++) {
			char = mainString[j];
			if (mainString.length === j + 1) {
				break;
			}
			// console.log(i, mainString, yesMap[char], mainString[j + 1], char);
			if (isValidSubString(char) && yesMap[char] === mainString[j + 1]) {
				isPartOfYes = true;
			} else {
				isPartOfYes = false;
				break;
			}
		}
		if (isPartOfYes) {
			console.log("YES");
		} else {
			console.log("NO");
		}
	}
}
var rl = readline_1.createInterface(process.stdin, process.stdout);
var input = [];
rl.on("line", function (line) {
	return input.push(line);
}).on("close", function () {
	return findYesSubString(input);
});
var a = "s";

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline();
	var N = n.length;
	var ok = false;
	var ref = ["Y","e","s"];
	var r = ref.indexOf(n[0]);
	if(r!==-1) {
		var j = 0;
		while(j<N && n[j] === ref[r]) {
			j++;
			r = (r+1)%3;
		}
		if(j==N) ok = true;
	}
	console.log(ok ? "Yes" : "No")
}

var input = readline();

print(Number(input))
for(var i=0; i<Number(input); i++) {
    var word = readline();
    if(word[0] != "Y" && word[0] != "e" && word[0] != "s") {
        print("NO");
        break;
    }

    for(var j=0; j<word.length; j++) {
        if(j == word.length - 1) {
            print("YES");
            break;
        }
        if(word[j] == "Y") {
            if(word[j+1] != "e") {
                print("NO");
                break;
            }
        }
        else if(word[j] == "e") {
            if(word[j+1] != "s") {
                print("NO");
                break;
            }
        }
        else {
            if(word[j+1] != "Y") {
                print("NO");
                break;
            }
        }
    }
}

var input = readline();

for(var i=0; i<Number(input); i++) {
    var word = readline();
    if(word[0] != "Y" && word[0] != "e" && word[0] != "s") {
        print("NO");
        break;
    }

    for(var j=0; j<word.length; j++) {
        if(j == word.length - 1) {
            print("YES");
            break;
        }
        if(word[j] == "Y") {
            if(word[j+1] != "e") {
                print("NO");
                break;
            }
        }
        else if(word[j] == "e") {
            if(word[j+1] != "s") {
                print("NO");
                break;
            }
        }
        else {
            if(word[j+1] != "Y") {
                print("NO");
                break;
            }
        }
    }
}

var input = readline();

for(var i=0; i<Number(input).length; i++) {
    var word = readline();
    if(word[0] != "Y" && word[0] != "e" && word[0] != "s") {
        print("NO");
        break;
    }

    for(var j=0; j<word.length; j++) {
        if(j == word.length - 1) {
            print("YES");
            break;
        }
        if(word[j] == "Y") {
            if(word[j+1] != "e") {
                print("NO");
                break;
            }
        }
        else if(word[j] == "e") {
            if(word[j+1] != "s") {
                print("NO");
                break;
            }
        }
        else {
            if(word[j+1] != "Y") {
                print("NO");
                break;
            }
        }
    }
}


You are asked to watch your nephew who likes to play with toy blocks in a strange way.He has $$$n$$$ boxes and the $$$i$$$-th box has $$$a_i$$$ blocks. His game consists of two steps:   he chooses an arbitrary box $$$i$$$;  he tries to move all blocks from the $$$i$$$-th box to other boxes.  If he can make the same number of blocks in each of $$$n - 1$$$ other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box $$$i$$$ he chooses he won't be sad. What is the minimum number of extra blocks you need to put?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of boxes. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the number of blocks in each box. It's guaranteed that the sum of $$$n$$$ over test cases doesn't exceed $$$10^5$$$.

For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite.

NoteIn the first test case, you can, for example, put one extra block into the first box and make $$$a = [4, 2, 2]$$$. If your nephew chooses the box with $$$4$$$ blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with $$$2$$$ blocks then he will move these two blocks to the other box with $$$2$$$ blocks.In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.In the third test case, you should put $$$3$$$ extra blocks. For example, you can put $$$2$$$ blocks in the first box and $$$1$$$ block in the third box. You'll get array $$$a = [2, 3, 1]$$$.

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    let [max, sum] = [-Infinity, 0];
    readLine()
      .split(" ")
      .forEach((n) => {
        n = parseInt(n);
        sum += n;
        max = Math.max(max, n);
      });

    const value = Math.ceil(sum / (len - 1));
    if (max > value) {
      let output = Math.abs((len - 1) * max - sum);
      console.log(output);
    } else {
      let output = Math.abs(sum - (len - 1) * value);
      console.log(output);
    }
  }
}

/*
You are asked to watch your nephew who likes to play with toy blocks in a strange way.

He has n boxes and the i-th box has ai blocks. His game consists of two steps:

he chooses an arbitrary box i;
he tries to move all blocks from the i-th box to other boxes.
If he can make the same number of blocks in each of n−1 other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.
You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box i he chooses he won't be sad. What is the minimum number of extra blocks you need to put?

Input
The first line contains a single integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains the integer n (2≤n≤105) — the number of boxes.

The second line of each test case contains n integers a1,a2,…,an (0≤ai≤109) — the number of blocks in each box.

It's guaranteed that the sum of n over test cases doesn't exceed 105.

inputCopy
3
3
3 2 2 -> 3. 1 -> 2 || 2 (2,3,2) || (2,2,3) 2. 1->
4
2 2 3 2
3
0 3 0
outputCopy
1
0
3

In the first test case, you can, for example, put one extra block into the first box and make a=[4,2,2]. If your nephew chooses the box with 4 blocks, then we will move two blocks to the second box and two blocks to the third box (0,4,4). If he chooses the box with 2 blocks then he will move these two blocks to the other box with 2 blocks. (4,0,4) || (4,4,0)

In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.

In the third test case, you should put 3 extra blocks. For example, you can put 2 blocks in the first box and 1 block in the third box. You'll get array a=[2,3,1].
*/

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(data.shift());

    while(testCases--) {

        const n = parseInt(data.shift());

        const arr = get_ints();

        const res = b(n,arr);

        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function b(n, arr)
{
    arr.sort((a,b) => b - a);

    const max = arr[0];

    const sum = arr.reduce((a, b) => a + b);

    const k = Math.max(Math.ceil(sum/(n - 1)), max)

    return (n - 1) * k - sum;
}

module.exports = b;

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

    B();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x,y] = ti(readline().split(' '));

        let min = Math.min(x,y);
        let max = Math.max(x,y);
        if(max === min){
            console.log(max+min);
        }else{
            console.log(2*min+(1+(max-min-1)*2));
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        a.sort((a,b) => a-b);

        let sum = 0;
        for(let i = 0; i < a.length; i++)
            sum += a[i];

        let x = sum-a[0];
        let d = a[n-1]*(n-1)-x;

        if(a[0] > d){
            let diff = a[0]-d;
            console.log(diff % (n-1) === 0 ? 0 : ((n-1) - (diff % (n-1))));
        }else{
            console.log(d-a[0]);
        }
    }
}

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

    B();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x,y] = ti(readline().split(' '));

        let min = Math.min(x,y);
        let max = Math.max(x,y);
        if(max === min){
            console.log(max+min);
        }else{
            console.log(2*min+(1+(max-min-1)*2));
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        a.sort((a,b) => a-b);

        let sum = 0;
        for(let i = 0; i < a.length; i++)
            sum += a[i];

        let x = sum-a[0];
        let d = a[n-1]*(n-1)-x;

        if(a[0] > d){
            let diff = a[0]-d;
            console.log(diff % (n-1));
        }else{
            console.log(d-a[0]);
        }
    }
}


A permutation of length $$$n$$$ is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).For a positive integer $$$n$$$, we call a permutation $$$p$$$ of length $$$n$$$ good if the following condition holds for every pair $$$i$$$ and $$$j$$$ ($$$1 \le i \le j \le n$$$) —   $$$(p_i \text{ OR } p_{i+1} \text{ OR } \ldots \text{ OR } p_{j-1} \text{ OR } p_{j}) \ge j-i+1$$$, where $$$\text{OR}$$$ denotes the bitwise OR operation. In other words, a permutation $$$p$$$ is good if for every subarray of $$$p$$$, the $$$\text{OR}$$$ of all elements in it is not less than the number of elements in that subarray. Given a positive integer $$$n$$$, output any good permutation of length $$$n$$$. We can show that for the given constraints such a permutation always exists.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first and only line of every test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$).

For every test, output any good permutation of length $$$n$$$ on a separate line.

'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++];
}
/**
3
1
3
7

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let n = Number(readline());

    let a = [];

    let mid = Math.floor(n / 2);
    a[mid] = 1;

    let start = 2;
    for(let i=0;i<n;i++) {
        if(a[i]) {
            continue;
        }
        a[i] = start;
        start++;
    }

    console.log(a.join(" "));

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const x = readline();
    var cases = parseInt(x);
    for(var i=1;i<=cases;i++){
         var line2 = readline();
         var currentNumber = parseInt(line2);
         console.log(getGoodPermutation(currentNumber));
    }

}
function getGoodPermutation(x) {
    var strs = [];
    for(var i=1;i<=x;i++){
        strs.push(i);
    }
    return strs.join(" ");
}

var readline=require("readline");
var rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
var arr=[];
rl.on('line',function(inp){
    arr.push(parseInt(inp));
    var T=arr[0];
    if(arr.length>1){
        var n=parseInt(arr[arr.length-1]);
        var str="1";
        for(var i=2;i<=n;i++) str+=" "+i;
        console.log(str);
    }
    if(arr.length===(T+1)) process.exit(0);
});

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = [];
    for (let i = 0; i < len; i++) {
      arr.push(i + 1);
    }
    console.log(arr.join(" "));
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
  	var N = nextInt();
  	var list = [];
  	for(var j = N; j > 0; j--){
  		list.push(j);
  	}
  	output[i] = myconv(list, 8);
  }
  myout(myconv(output, 9));
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
});

process.stdin.on('end', () => {
  main(stdinInput);
});

function main(data) {
	data = data.split('\n');
	const testCases = data[0] * 1;
	let i = 1;
	while (i <= testCases) {
    let n = data[i] * 1;
    let arr = [];
    for (let i = n; i > 0; i -= 1) arr.push(i);
    console.log(arr.join(' '));
    i += 1;
	}
}

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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let i = 0; i < t; i++) {
    const n = Number(readLine())
    console.log(Array(n).fill(0).map((_, i) => i + 1).join(' '))
  }
}

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

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

function main() {
	let t = readLine() >> 0;
	while (t--) {
		let n = readLine() >> 0;
		let arr = [];
		for (let i = n; i > 0; i--) {
			arr.push(i);
		}

		console.log(arr.join(' '));
	}
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var n = +readline();
    var arr = [];
    for (var j = n; j > 0; j--) {
      arr.push(j);
    }
    print(arr.join(' '));
  }
}

main();


Alice has an empty grid with $$$n$$$ rows and $$$m$$$ columns. Some of the cells are marked, and no marked cells are adjacent to the edge of the grid. (Two squares are adjacent if they share a side.) Alice wants to fill each cell with a number such that the following statements are true:   every unmarked cell contains either the number $$$1$$$ or $$$4$$$;  every marked cell contains the sum of the numbers in all unmarked cells adjacent to it (if a marked cell is not adjacent to any unmarked cell, this sum is $$$0$$$);  every marked cell contains a multiple of $$$5$$$.  Alice couldn't figure it out, so she asks Bob to help her. Help Bob find any such grid, or state that no such grid exists.

The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in the grid, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either '.' or 'X' — an unmarked and a marked cell, respectively. No marked cells are adjacent to the edge of the grid.

Output "'NO" if no suitable grid exists. Otherwise, output "'YES"'. Then output $$$n$$$ lines of $$$m$$$ space-separated integers — the integers in the grid.

NoteIt can be shown that no such grid exists for the second test.

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const prt = (x) => process.stdout.write(x + " ")
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
const initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };
const addEdgeToG = (G, Edges) => { for (const [x, y] of Edges) { G[x].push(y); G[y].push(x); } };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 09/05/21 evening
 * https://codeforces.com/contest/1567/problem/F
 */

// const dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];

const dir = [[0, -1], [-1, 0], [0, 1], [1, 0]];
const solve = (n, m, g) => {
    // pr(n, m)
    // pr(g)
    let adj = initializeGraph(n * m);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                let q = [];
                for (const [dx, dy] of dir) {
                    let x = i + dx, y = j + dy;
                    // pr("ijxy", i, j, x, y)
                    if (x < 0 || x >= n || y < 0 || y >= m) continue;
                    // pr("xy", x, y)
                    if (g[x][y] == '.') {
                        q.push(x * m + y);
                    }
                }
                if (q.length & 1) return pr('NO');
                for (let k = 0; k < q.length; k += 2) {
                    adj[q[k]].push(q[k + 1]);
                    adj[q[k + 1]].push(q[k]);
                }
            }
        }
    }
    // pr(adj)
    let res = initialize2DArrayNew(n, m);
    let que = [];
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (res[i][j] > 0 || g[i][j] == 'X') continue;
            res[i][j] = 1;
            que.push(i * m + j);
            while (que.length) {
                let cur = que.shift();
                for (const v of adj[cur]) {
                    let d = int(v / m);
                    if (res[d][v % m] == 0) {
                        res[d][v % m] = res[int(cur / m)][cur % m] ^ 5;
                        que.push(v);
                    }
                }
            }
        }
    }
    pr('YES');
    // pr(res);
    for (let i = 0; i < n; i++) {
        let data = [];
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                for (const [dx, dy] of dir) {
                    let x = i + dx, y = j + dy;
                    if (x < 0 || x >= n || y < 0 || y >= m) continue;
                    if (g[x][y] == '.') {
                        res[i][j] += res[x][y];
                    }
                }
            }
            data.push(res[i][j]);
            // j == m - 1 ? pr(res[i][j]) : prt(res[i][j])
        }
        pr(data.join(" "))
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    // rl.on('line', (line) => {
    //     input.push(line.split(" "));
    // });
    // rl.on('close', () => {
    //     let a = input.shift();
    //     // solve(a[0] - '0', a[2] - '0', input); // wrong of m
    //     solve(a[0] - '0', a.slice(2).join("") - '0', input); // wrong n
    // });
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let a = input.shift().split(" ");
        input = input.map(s => s.split(""))
        solve(a[0] - '0', a[1] - '0', input);
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const prt = (x) => process.stdout.write(x + " ")
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
const initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };
const addEdgeToG = (G, Edges) => { for (const [x, y] of Edges) { G[x].push(y); G[y].push(x); } };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 09/05/21 evening
 * https://codeforces.com/contest/1567/problem/F
 */

// const dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];

const dir = [[0, -1], [-1, 0], [0, 1], [1, 0]];
const solve = (n, m, g) => {
    // pr(n, m)
    // pr(g)
    let adj = initializeGraph(n * m);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                let q = [];
                for (const [dx, dy] of dir) {
                    let x = i + dx, y = j + dy;
                    // pr("ijxy", i, j, x, y)
                    if (x < 0 || x >= n || y < 0 || y >= m) continue;
                    // pr("xy", x, y)
                    if (g[x][y] == '.') {
                        q.push(x * m + y);
                    }
                }
                if (q.length & 1) return pr('NO');
                for (let k = 0; k < q.length; k += 2) {
                    adj[q[k]].push(q[k + 1]);
                    adj[q[k + 1]].push(q[k]);
                }
            }
        }
    }
    // pr(adj)
    let res = initialize2DArrayNew(n, m);
    let que = [];
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (res[i][j] > 0 || g[i][j] == 'X') continue;
            res[i][j] = 1;
            que.push(i * m + j);
            while (que.length) {
                let cur = que.shift();
                for (const v of adj[cur]) {
                    let d = int(v / m);
                    if (res[d][v % m] == 0) {
                        res[d][v % m] = res[int(cur / m)][cur % m] ^ 5;
                        que.push(v);
                    }
                }
            }
        }
    }
    pr('YES');
    // pr(res);
    for (let i = 0; i < n; i++) {
        let data = [];
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                for (const [dx, dy] of dir) {
                    let x = i + dx, y = j + dy;
                    if (x < 0 || x >= n || y < 0 || y >= m) continue;
                    if (g[x][y] == '.') {
                        res[i][j] += res[x][y];
                    }
                }
            }
            data.push(res[i][j]);
            // j == m - 1 ? pr(res[i][j]) : prt(res[i][j])
        }
        pr(data.join(" "))
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(""));
    });
    rl.on('close', () => {
        let a = input.shift();
        // solve(a[0] - '0', a[2] - '0', input); // wrong of m

        // pr(a.slice(2).join("") - '0')
        solve(a[0] - '0', a.slice(2).join("") - '0', input); // wrong of m
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const prt = (x) => process.stdout.write(x + " ")
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
const initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };
const addEdgeToG = (G, Edges) => { for (const [x, y] of Edges) { G[x].push(y); G[y].push(x); } };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 09/05/21 evening
 * https://codeforces.com/contest/1567/problem/F
 */

const dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];
const solve = (n, m, g) => {
    // r(n, m, g)
    let adj = initializeGraph(n * m);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                let q = [];
                for (const [x, y] of dir) {
                    let dx = i + x, dy = j + y;
                    if (g[dx][dy] == '.') {
                        q.push(dx * m + dy);
                    }
                }
                if (q.length & 1) return pr('NO');
                for (let k = 0; k < q.length; k += 2) {
                    adj[q[k]].push(q[k + 1]);
                    adj[q[k + 1]].push(q[k]);
                }
            }
        }
    }
    // pr(adj)
    let res = initialize2DArrayNew(n, m);
    let que = [];
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (res[i][j] > 0 || g[i][j] == 'X') continue;
            res[i][j] = 1;
            que.push(i * m + j);
            while (que.length) {
                let cur = que.shift();
                for (const v of adj[cur]) {
                    let d = int(v / m);
                    if (res[d][v % m] == 0) {
                        res[d][v % m] = res[int(cur / m)][cur % m] ^ 5;
                        que.push(v);
                    }
                }
            }
        }
    }
    pr('YES');
    // pr(res);
    for (let i = 0; i < n; i++) {
        let data = [];
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                for (const [x, y] of dir) {
                    let dx = i + x, dy = j + y;
                    if (g[dx][dy] == '.') {
                        res[i][j] += res[dx][dy];
                    }
                }
            }
            data.push(res[i][j]);
            // j == m - 1 ? pr(res[i][j]) : prt(res[i][j])
        }
        pr(data.join(" "))
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(""));
    });
    rl.on('close', () => {
        let a = input.shift();
        solve(a[0] - '0', a[2] - '0', input);
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const prt = (x) => process.stdout.write(x + " ")
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
const initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };
const addEdgeToG = (G, Edges) => { for (const [x, y] of Edges) { G[x].push(y); G[y].push(x); } };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 09/05/21 evening
 * https://codeforces.com/contest/1567/problem/F
 */

const dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];
const solve = (n, m, g) => {
    // r(n, m, g)
    let adj = initializeGraph(n * m);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                let q = [];
                for (const [x, y] of dir) {
                    let dx = i + x, dy = j + y;
                    if (g[dx][dy] == '.') {
                        q.push(dx * m + dy);
                    }
                }
                if (q.length & 1) return pr('NO');
                for (let k = 0; k < q.length; k += 2) {
                    adj[q[k]].push(q[k + 1]);
                    adj[q[k + 1]].push(q[k]);
                }
            }
        }
    }
    // pr(adj)
    let res = initialize2DArrayNew(n, m);
    let que = [];
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (res[i][j] > 0 || g[i][j] == 'X') continue;
            res[i][j] = 1;
            que.push(i * m + j);
            while (que.length) {
                let cur = que.shift();
                for (const v of adj[cur]) {
                    let d = int(v / m);
                    if (res[d][v % m] == 0) {
                        res[d][v % m] = res[int(cur / m)][cur % m] ^ 5;
                        que.push(v);
                    }
                }
            }
        }
    }
    pr('YES');
    // pr(res);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                for (const [x, y] of dir) {
                    let dx = i + x, dy = j + y;
                    if (g[dx][dy] == '.') {
                        res[i][j] += res[dx][dy];
                    }
                }
            }
            j == m - 1 ? pr(res[i][j]) : prt(res[i][j])
        }
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(""));
    });
    rl.on('close', () => {
        let a = input.shift();
        solve(a[0] - '0', a[2] - '0', input);
    });
};

main()

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
const initializeGraph = (n) => { let G = []; for (let i = 0; i < n; i++) { G.push([]); } return G; };
const addEdgeToG = (G, Edges) => { for (const [x, y] of Edges) { G[x].push(y); G[y].push(x); } };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 09/05/21 evening
 * https://codeforces.com/contest/1567/problem/F
 */

const dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];
const solve = (n, m, g) => {
    // r(n, m, g)
    let adj = initializeGraph(n * m);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                let q = [];
                for (const [x, y] of dir) {
                    let dx = i + x, dy = j + y;
                    if (g[dx][dy] == '.') {
                        q.push(dx * m + dy);
                    }
                }
                if (q.length & 1) return pr('NO');
                for (let k = 0; k < q.length; k += 2) {
                    adj[q[k]].push(q[k + 1]);
                    adj[q[k + 1]].push(q[k]);
                }
            }
        }
    }
    // pr(adj)
    let res = initialize2DArrayNew(n, m);
    let que = [];
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (res[i][j] > 0 || g[i][j] == 'X') continue;
            res[i][j] = 1;
            que.push(i * m + j);
            while (que.length) {
                let cur = que.shift();
                for (const v of adj[cur]) {
                    let d = int(v / m);
                    if (res[d][v % m] == 0) {
                        res[d][v % m] = res[int(cur / m)][cur % m] ^ 5;
                        que.push(v);
                    }
                }
            }
        }
    }
    pr('YES');
    // pr(res);
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (g[i][j] == 'X') {
                for (const [x, y] of dir) {
                    let dx = i + x, dy = j + y;
                    if (g[dx][dy] == '.') {
                        res[i][j] += res[dx][dy];
                    }
                }
            }
            if (j == m - 1) pr(res[i][j], 1);
        }
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(""));
    });
    rl.on('close', () => {
        let a = input.shift();
        solve(a[0] - '0', a[2] - '0', input);
    });
};

main()


You are given a grid with $$$n$$$ rows and $$$m$$$ columns. Rows and columns are numbered from $$$1$$$ to $$$n$$$, and from $$$1$$$ to $$$m$$$. The intersection of the $$$a$$$-th row and $$$b$$$-th column is denoted by $$$(a, b)$$$. Initially, you are standing in the top left corner $$$(1, 1)$$$. Your goal is to reach the bottom right corner $$$(n, m)$$$.You can move in four directions from $$$(a, b)$$$: up to $$$(a-1, b)$$$, down to $$$(a+1, b)$$$, left to $$$(a, b-1)$$$ or right to $$$(a, b+1)$$$.You cannot move in the same direction in two consecutive moves, and you cannot leave the grid. What is the minimum number of moves to reach $$$(n, m)$$$?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of the test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$) — the size of the grid.

For each test case, print a single integer: $$$-1$$$ if it is impossible to reach $$$(n, m)$$$ under the given conditions, otherwise the minimum number of moves.

NoteTest case $$$1$$$: $$$n=1$$$, $$$m=1$$$, and initially you are standing in $$$(1, 1)$$$ so $$$0$$$ move is required to reach $$$(n, m) = (1, 1)$$$.Test case $$$2$$$: you should go down to reach $$$(2, 1)$$$.Test case $$$3$$$: it is impossible to reach $$$(1, 3)$$$ without moving right two consecutive times, or without leaving the grid.Test case $$$4$$$: an optimal moving sequence could be: $$$(1, 1) \to (1, 2) \to (2, 2) \to (2, 1) \to (3, 1) \to (3, 2) \to (4, 2)$$$. It can be proved that this is the optimal solution. So the answer is $$$6$$$.

//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 m = nextInt();

        let max = Math.max(n, m), min = Math.min(n, m);

        if (min === 1) {
            if (max === 1) {
                myout(0);
            } else if (max === 2) {
                myout(1);
            } else {
                myout(-1);
            }
            continue
        }

        if (max === min + 1 || max === min) {
            myout(max + min - 2);
            continue;
        }

        let diff = max - min;
        let res = 0;
        if (diff % 2 === 1) {
            res += 1
        }

        res += min*2 - 2 + Math.floor(diff / 2) * 4;
        myout(res)
        // output in nodeJs
        // console.log(arr)
	}
}

//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 m = nextInt();

        let max = Math.max(n, m), min = Math.min(n, m);

        if (min === 1) {
            if (max === 1) {
                myout(0);
            } else if (max === 2) {
                myout(1);
            } else {
                myout(-1);
            }
            continue
        }

        if (max === min + 1 || max === min) {
            myout(max + min - 2);
            continue;
        }

        let diff = max - min;
        let res = 0;
        if (diff % 2 === 1) {
            res += 1
        }

        res += min*2 - 2 + Math.floor(diff / 2) * 4;
        myout(res)
        // output in nodeJs
        // console.log(arr)
	}
}

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

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

function main(){
    // input in nodeJs
	let test = parseInt(readLine(),10);
	while(test--){
		let [n, m] = readLine().split(" ").map(ele => parseInt(ele, 10));

        let max = Math.max(n, m), min = Math.min(n, m);

        if (min === 1) {
            if (max === 1) {
                console.log(0);
            } else if (max === 2) {
                console.log(1);
            } else {
                console.log(-1);
            }
            continue
        }

        if (max === min + 1 || max === min) {
            console.log(max + min - 2);
            continue;
        }

        let diff = max - min;
        let res = 0;
        if (diff % 2 === 1) {
            res += 1
        }

        res += min*2 - 2 + Math.floor(diff / 2) * 4;
        console.log(res)
        // output in nodeJs
        // console.log(arr)
	}
}

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

let s = "";
process.stdin.on("data", (data) => {
  s += data;
});

process.stdin.on("end", () => {
  s = s.trim().split("\n");

  main();
});

function main() {
  let t = Number(s[0]);

  let i = 1;
  while (t--) {
    const [m, n] = s[i].split(" ").map(Number);
    solve(m, n);
    i++;
  }
}

function solve(m, n) {
  if (m === 1 || n === 1) {
    if (Math.abs(m - n) === 1) {
      console.log(1);
      return;
    }
    if (m + n > 2) {
      console.log(-1);
      return;
    }
  }

  if (m < n) {
    [m, n] = [n, m];
  }

  let count = 0;
  const diag = 2 * (n - 1);

  count += diag;

  const remaining = m - n;
  const twoJumps = Math.floor(remaining / 2);
  count += twoJumps * 4;
  count += remaining % 2;

  console.log(count);
}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(n, m) {
  if (n > m) {
    return solve(m, n);
  } else {
    if (n === 1 && m > 2) console.log(-1);else if ((n & 1) === (m & 1)) console.log(m * 2 - 2);else console.log(m * 2 - 3);
  }
}

function main(inputs) {
  const _ = Number(inputs[0]);

  for (let __ = 1; __ <= _; __++) {
    const [n, m] = inputs[__].trim().split(' ').map(Number);

    solve(n, m);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
main(inputs);

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let [x,y]=line[i].split(' ').map(x=>{return parseInt(x)});
        x--;
        y--;
        if(x>y) [x,y]=[y,x];
        if(x===0)
        {
            if(y<=1) console.log(y);
            else console.log(-1);
        }
        else
        {
            let ans=y+x+(y-x-1);
            if((y-x-1)&1) ans++;
            console.log(ans);
        }
    }
})

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let [n, m] = readline().split(' ').map(Number);
        if (m > n) [m, n] = [n, m];

        if (m === 1 && n > 2) {
            output(-1);
            continue;
        }

        output(2*n-2-(n+m)%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;
function solve(n, m) {
    if (n < m) {
        [n, m] = [m, n];
    }
    if (m == 1 && n > 2) {
        return INIT;
    }
    let ans = m + m - 2;
    n -= m;
    let pairs = n - (n % 2);
    ans += pairs * 2;
    if ((n % 2) == 1) {
        ans++;
    }
    return ans;
}
function main() {
    let tc = nextInt();
    while (tc-- > 0) {
        let n = nextInt();
        let m = nextInt();
        printf("%d\n", solve(n, m));
    }
}

const fs = require("fs");

const input = fs.readFileSync(0, "utf8").trim().split("\n");

const testCases = [];
let T;

function parseInput() {
  T = parseInt(input[0]);
  let index = 0;

  for (let i = 0; i < T; i++) {
    index++;
    const [n, m] = input[index].split(" ").map((item) => parseInt(item));
    const testCase = {
      n,
      m,
    };
    testCases.push(testCase);
  }
}

function solution(testCase, index) {
  const { n, m } = testCase;

  const mini = Math.min(m - 1, n - 1);
  const maxi = Math.max(m - 1, n - 1);
  const diff = Math.abs(m - n);

  let result =
    mini == 0 && maxi > 1
      ? -1
      : mini * 2 + Math.floor(diff / 2) * 4 + (diff % 2);
  console.log(result);
}

parseInput();

testCases.forEach(solution);

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

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

const calc = (n, m)=>{
    if (n === 1 && m === 1) return 0;
    if (n === 1 && m > 2 || n > 2 && m === 1) return -1;
    if (n === 1 && m === 2 || n === 2 && m === 1) return 1;

    let diag = (Math.min(n, m) - 1) * 2;
    // console.log('DEBUG diag', diag);
    if (n === m) return diag;

    let diff = Math.abs(n - m);

    let x1 = Math.floor((diff + 1) / 2);
    let x2 = Math.floor(diff / 2);
    // console.log('DEBUG x1', x1);
    // console.log('DEBUG x2', x2);

    let min = Math.min(n, m);
    let divBy2 = min % 2;
    // console.log('DEBUG divBy2', divBy2);

    // let ones = divBy2 ? x2 : x1;
    // let threes = divBy2 ? x1 : x2;
    let ones = x1;
    let threes = x2;

    // console.log('DEBUG ones', ones);
    // console.log('DEBUG threes', threes);

    let res = diag + ones + threes * 3;

    return res;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, m] = ra();

        console.log(`${calc(n, m)}`);
    }
}

'use strict';

const { checkPrime } = require('crypto');
const { Z_FIXED } = require('zlib');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const l = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (n, m)=>{
  if (n>m)
    return calc(m, n);
  // n<m
  n--;
  m--;
  if (n==0 && m>1)
    return -1;
  let ans = n*2;
  m -= n;
  if (m==0)
    return ans;
  l({ans, m})
  return ans + Math.floor((m)/2)*4 + m%2;
  if (m%3==2){
  }
  ans++;
  m--;
  ans += m*2
  if (0)
  if (m%2)
    ans++;
  return ans;
};

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

E.calc = calc;

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var M = nextInt();
		var H = Math.min(N, M);
		var W = Math.max(N, M);
		if(H == 1 && W >= 3){
			myout(-1);
			continue;
		}
		var output = (H - 1) + (W - 1);
		if(W - H >= 2){
			var diff = W - H;
			output += Math.floor(diff / 2) * 2;
		}
		myout(output);
	}
}

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

let s = "";
process.stdin.on("data", (data) => {
  s += data;
});

process.stdin.on("end", () => {
  s = s.trim().split("\n");

  main();
});

function main() {
  let t = Number(s[0]);

  let i = 1;
  while (t--) {
    const [m, n] = s[i].split(" ").map(Number);
    solve(m, n);
    i++;
  }
}

function solve(m, n) {
  if (m === 1 || n === 1) {
    if (m - n === 1) {
      console.log(1);
      return;
    }
    if (m + n > 2) {
      console.log(-1);
      return;
    }
  }

  if (m < n) {
    [m, n] = [n, m];
  }

  let count = 0;
  const diag = 2 * (n - 1);

  count += diag;

  const remaining = m - n;
  const twoJumps = Math.floor(remaining / 2);
  count += twoJumps * 4;
  count += remaining % 2;

  console.log(count);
}

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

let s = "";
process.stdin.on("data", (data) => {
  s += data;
});

process.stdin.on("end", () => {
  s = s.trim().split("\n");

  main();
});

function main() {
  let t = Number(s[0]);

  let i = 1;
  while (t--) {
    const [m, n] = s[i].split(" ").map(Number);
    solve(m, n);
    i++;
  }
}

function solve(m, n) {
  if (m === 1 && n === 1) {
    console.log(0);
    return 0;
  }
  if (m === 1 || n === 1) {
    console.log(-1);
    return;
  }

  let sx = 1,
    sy = 1;

  let count = 0;
  const defOptions = [
    [1, 0],
    [0, 1],
  ];
  let i = 0;
  while (sx !== m && sy !== n) {
    sx += defOptions[i][0];
    sy += defOptions[i][1];
    i = (i + 1) % 2;
    count++;
  }

  const diff = sx === m ? n - sy : m - sx;
  const q = Math.floor(diff / 2);
  const r = diff % 2;
  count += q * 4 + r;

  console.log(count);
}

'use strict';

var fs = require('fs');

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

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(n, m) {
  if (m === n) {
    console.log(n * (n - 1));
  } else if (n > m) {
    return solve(m, n);
  } else {
    if (n === 1 && m > 2) console.log(-1);else if ((n & 1) === (m & 1)) console.log(m * 2 - 2);else console.log(m * 2 - 3);
  }
}

function main(inputs) {
  const _ = Number(inputs[0]);

  for (let __ = 1; __ <= _; __++) {
    const [n, m] = inputs[__].trim().split(' ').map(Number);

    solve(n, m);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
main(inputs);


Palo Alto is an unusual city because it is an endless coordinate line. It is also known for the office of Lyft Level 5.Lyft has become so popular so that it is now used by all $$$m$$$ taxi drivers in the city, who every day transport the rest of the city residents — $$$n$$$ riders.Each resident (including taxi drivers) of Palo-Alto lives in its unique location (there is no such pair of residents that their coordinates are the same).The Lyft system is very clever: when a rider calls a taxi, his call does not go to all taxi drivers, but only to the one that is the closest to that person. If there are multiple ones with the same distance, then to taxi driver with a smaller coordinate is selected.But one morning the taxi drivers wondered: how many riders are there that would call the given taxi driver if they were the first to order a taxi on that day? In other words, you need to find for each taxi driver $$$i$$$ the number $$$a_{i}$$$ — the number of riders that would call the $$$i$$$-th taxi driver when all drivers and riders are at their home?The taxi driver can neither transport himself nor other taxi drivers.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n,m \le 10^5$$$) — number of riders and taxi drivers. The second line contains $$$n + m$$$ integers $$$x_1, x_2, \ldots, x_{n+m}$$$ ($$$1 \le x_1 < x_2 < \ldots < x_{n+m} \le 10^9$$$), where $$$x_i$$$ is the coordinate where the $$$i$$$-th resident lives.  The third line contains $$$n + m$$$ integers $$$t_1, t_2, \ldots, t_{n+m}$$$ ($$$0 \le t_i \le 1$$$). If $$$t_i = 1$$$, then the $$$i$$$-th resident is a taxi driver, otherwise $$$t_i = 0$$$. It is guaranteed that the number of $$$i$$$ such that $$$t_i = 1$$$ is equal to $$$m$$$.

Print $$$m$$$ integers $$$a_1, a_2, \ldots, a_{m}$$$, where $$$a_i$$$ is the answer for the $$$i$$$-th taxi driver. The taxi driver has the number $$$i$$$ if among all the taxi drivers he lives in the $$$i$$$-th smallest coordinate (see examples for better understanding).

NoteIn the first example, we have only one taxi driver, which means an order from any of $$$n$$$ riders will go to him.In the second example, the first taxi driver lives at the point with the coordinate $$$2$$$, and the second one lives at the point with the coordinate $$$6$$$. Obviously, the nearest taxi driver to the rider who lives on the $$$3$$$ coordinate is the first one, and to the rider who lives on the coordinate $$$5$$$ is the second one. The rider who lives on the $$$4$$$ coordinate has the same distance to the first and the second taxi drivers, but since the first taxi driver has a smaller coordinate, the call from this rider will go to the first taxi driver.In the third example, we have one rider and the taxi driver nearest to him is the fourth one.

var fl = readline().split(' ').map(v=>+v);
var p = fl[0]; var t = fl[1];

var taxists = [];
var data = readline().split(' ').map(v=>+v);

var cnt = 0, prevCoord = 0, prevInd =-1;
readline().split(' ').forEach((v, ind)=> {
    if(!(+v)) {
        cnt++;
    } else {
        var coord = data[ind]
        var people = 0;

        if(prevInd < 0) {
            people = cnt
        } else {
            for(var i = prevInd + 1; i < ind; i++) {
                if(data[i] - prevCoord <= coord - data[i]) {
                    taxists[taxists.length - 1] ++;
                } else {
                    people++;
                }
            }
        }

        taxists.push(people)

        prevInd = ind;
        prevCoord = coord;

        cnt = 0;
    }
})

taxists[taxists.length - 1] += cnt;

print(taxists.join(' '));