Naruto has sneaked into the Orochimaru's lair and is now looking for Sasuke. There are $$$T$$$ rooms there. Every room has a door into it, each door can be described by the number $$$n$$$ of seals on it and their integer energies $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$. All energies $$$a_i$$$ are nonzero and do not exceed $$$100$$$ by absolute value. Also, $$$n$$$ is even.In order to open a door, Naruto must find such $$$n$$$ seals with integer energies $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ that the following equality holds: $$$a_{1} \cdot b_{1} + a_{2} \cdot b_{2} + ... + a_{n} \cdot b_{n} = 0$$$. All $$$b_i$$$ must be nonzero as well as $$$a_i$$$ are, and also must not exceed $$$100$$$ by absolute value. Please find required seals for every room there.

The first line contains the only integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) standing for the number of rooms in the Orochimaru's lair. The other lines contain descriptions of the doors. Each description starts with the line containing the only even integer $$$n$$$ ($$$2 \leq n \leq 100$$$) denoting the number of seals. The following line contains the space separated sequence of nonzero integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$|a_{i}| \leq 100$$$, $$$a_{i} \neq 0$$$) denoting the energies of seals.

For each door print a space separated sequence of nonzero integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$|b_{i}| \leq 100$$$, $$$b_{i} \neq 0$$$) denoting the seals that can open the door. If there are multiple valid answers, print any. It can be proven that at least one answer always exists.

NoteFor the first door Naruto can use energies $$$[-100, 1]$$$. The required equality does indeed hold: $$$1 \cdot (-100) + 100 \cdot 1 = 0$$$.For the second door Naruto can use, for example, energies $$$[1, 1, 1, -1]$$$. The required equality also holds: $$$1 \cdot 1 + 2 \cdot 1 + 3 \cdot 1 + 6 \cdot (-1) = 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++];
}

// 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();
    const arr = readLine().split(" ").map(Number);
    let result = arr.reverse();
    result = result.map((n, index) => {
      if (index % 2 === 0) {
        return -1 * n;
      } else return n;
    });

    console.log(result.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↑入力 ↓出力');
	Main();
});
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 = nextIntArray();
		var b = new Array(N);
		for(var j = 0; j < N; j += 2){
			var L = lcm(list[j], list[j + 1]);
			b[j] = L / list[j];
			b[j + 1] = -L / list[j + 1];
		}

		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

#!/usr/bin/env node
'use strict';

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

const buf = [];
const prom = [];
let maxBuf = 0;
let maxProm = 0;
rl.on('line', (line) => {
  if (prom.length > 0) {
    maxProm = Math.max(maxProm, prom.length);
    const [resolve, reject] = prom.shift();
    resolve(line);
  } else {
    rl.pause();
    buf.push(line);
    maxBuf = Math.max(maxBuf, buf.length);
  }
});

rl.on('close', () => {
  // console.error({maxProm, maxBuf});
});

async function getLine() {
  return new Promise((resolve, reject) => {
    if (buf.length > 0) {
      const line = buf.shift();
      resolve(line);
    } else {
      prom.push([resolve, reject]);
      rl.resume();
    }
  });
}

/**
 *
 * @param {Number []} a
 * @returns {Number []}
 */
function solve(a) {
  const n = a.length;
  const res = [];
  for (let i = 1; i < n; i += 2) {
    res.push(a[i], -a[i-1]);
  }
  return res;
}

async function main() {
  const t = Number(await getLine());
  for (let i = 0; i < t; i++) {
    const n = Number(await getLine());
    const a = (await getLine()).split(' ').map(Number);
    const res = solve(a);
    console.log(res.join(' '));
  }
}

if (require.main === module) {
  main();
}

const readline = require('readline');

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

function spltoarr(arr){
    for (let i=0; i<arr.length; i++){
        arr[i]=parseInt(arr[i])
    }
};

function sealBreakJutsu(sealValues){
    for(let c=doorSealCount, f=0;c>0;c-=2,f+=2){
        chakraValues += `${sealValues[f+1]*-1} `;
        chakraValues += `${sealValues[f]} `;
        doorSealCount -=2;
    }
    console.log(chakraValues)

}

var doorCount, doorSealCount, sealValues, chakraValues;
chakraValues='';
rl.on('line', (input) => {

if(doorCount>0){

    if(doorSealCount>0 ){
        sealValues=input.split(" ")
        spltoarr(sealValues)
        sealBreakJutsu(sealValues)
        doorCount -=1
        chakraValues = ''
    } else doorSealCount=parseInt(input)

}else doorCount=parseInt(input)

})

const readline = require('readline');

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

let arr = []
let count = 0
let T = 0
let str = '';

rl.on('line', (input) => {
  if (count === 0) {
    T = input
  } else if (count % 2 === 0) {
    arr.push(input.split(' '))
  }
  count++
  if (T * 2 + 1 === count) {
    for (let i = 0; i < arr.length; i++) {
      str = '';
      for (let k = 1; k < arr[i].length; k = k + 2) {
        str = str + ' ' + -arr[i][k] + ' ' + arr[i][k-1];
      }
      console.log(str);
    }
  }
});

'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 A(arr) {
  if (!Array.isArray(arr)) return [];

  if (arr.length === 0 || arr.length % 2 !== 0) return [];

  const result = [];

  for (let i = 0; i < arr.length / 2; i++) {
    result.push(-arr[2 * i + 1], arr[2 * i]);
  }

  return result;
}

function main() {
    const T = readline();
    for (let i = 0; i < T; i++) {
  const n = readline();
  const arrStr = readline();
  const arr = arrStr.split(' ');
  process.stdout.write(A(arr).join(' '));
        process.stdout.write('\n');
    }
}

//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↑入力 ↓出力');
	Main();
});
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 = nextIntArray();
		var L = list[0];
		for(var j = 1; j < N; j++){
			L = lcm(L, list[j]);
		}
		myerr(L);
		var b = new Array(N);
		if(N % 2 == 1){
			for(var j = 0; j < N - 1; j++){
				if(j < Math.floor(N / 2)){
					b[j] = L / list[j];
				}else{
					b[j] = -(L / list[j]);
				}
			}
			b[N - 1] = -L * 2;
		}else{
			for(var j = 0; j < N; j++){
				b[j] = L / list[j];
				if(j >= N / 2){
					b[j] *= -1;
				}
			}
		}
		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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↑入力 ↓出力');
	Main();
});
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 = nextIntArray();
		var L = list[0];
		for(var j = 1; j < N; j++){
			L = lcm(L, list[j]);
		}
		var b = new Array(N);
		for(var j = 0; j < N; j++){
			b[j] = L / list[j];
			if(j >= N / 2){
				b[j] *= -1;
			}
		}
		var sum = 0;
		for(var j = 0; j < N; j++){
			sum += list[j] * b[j];
		}
		myerr(sum);
		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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↑入力 ↓出力');
	Main();
});
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 = nextIntArray();
		var b = new Array(N);
		for(var j = 0; j < N; j += 2){
			var L = lcm(list[j], list[j + 1]);
			b[j] = L / list[j];
			b[j + 1] = L / list[j + 1];
		}

		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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↑入力 ↓出力');
	Main();
});
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 = nextIntArray();
		var L = list[0];
		for(var j = 1; j < N; j++){
			L = lcm(L, list[j]);
		}
		var b = new Array(N);
		if(N % 2 == 1){
			for(var j = 0; j < N - 1; j++){
				if(j <= Math.floor(N / 2)){
					b[j] = L / list[j];
				}else{
					b[j] = -(L / list[j]);
				}
			}
			b[N - 1] = -L * 2 / list[j];
		}else{
			for(var j = 0; j < N; j++){
				b[j] = L / list[j];
				if(j >= N / 2){
					b[j] *= -1;
				}
			}
		}

		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

const readline = require('readline');

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

let arr = []
let count = 0
let T = 0
let str = '';

rl.on('line', (input) => {
  if (count === 0) {
    T = input
  } else if (count % 2 === 0) {
    arr.push(input.split(' '))
  }
  count++
  if (T * 2 + 1 === count) {
    for (let i = 0; i < arr.length; i++) {
      str = '';
      for (let k = 1; k < arr[i].length; k = k + 2) {
        let num = k - 1;
        str = str + ' ' + -k + ' ' + num;
      }
      console.log(str);
    }
  }
});


There is a robot staying at $$$X=0$$$ on the $$$Ox$$$ axis. He has to walk to $$$X=n$$$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.The $$$i$$$-th segment of the path (from $$$X=i-1$$$ to $$$X=i$$$) can be exposed to sunlight or not. The array $$$s$$$ denotes which segments are exposed to sunlight: if segment $$$i$$$ is exposed, then $$$s_i = 1$$$, otherwise $$$s_i = 0$$$.The robot has one battery of capacity $$$b$$$ and one accumulator of capacity $$$a$$$. For each segment, you should choose which type of energy storage robot will use to go to the next point (it can be either battery or accumulator). If the robot goes using the battery, the current charge of the battery is decreased by one (the robot can't use the battery if its charge is zero). And if the robot goes using the accumulator, the current charge of the accumulator is decreased by one (and the robot also can't use the accumulator if its charge is zero).If the current segment is exposed to sunlight and the robot goes through it using the battery, the charge of the accumulator increases by one (of course, its charge can't become higher than it's maximum capacity).If accumulator is used to pass some segment, its charge decreases by 1 no matter if the segment is exposed or not.You understand that it is not always possible to walk to $$$X=n$$$. You want your robot to go as far as possible. Find the maximum number of segments of distance the robot can pass if you control him optimally.

The first line of the input contains three integers $$$n, b, a$$$ ($$$1 \le n, b, a \le 2 \cdot 10^5$$$) — the robot's destination point, the battery capacity and the accumulator capacity, respectively. The second line of the input contains $$$n$$$ integers $$$s_1, s_2, \dots, s_n$$$ ($$$0 \le s_i \le 1$$$), where $$$s_i$$$ is $$$1$$$ if the $$$i$$$-th segment of distance is exposed to sunlight, and $$$0$$$ otherwise.

Print one integer — the maximum number of segments the robot can pass if you control him optimally.

NoteIn the first example the robot can go through the first segment using the accumulator, and charge levels become $$$b=2$$$ and $$$a=0$$$. The second segment can be passed using the battery, and charge levels become $$$b=1$$$ and $$$a=1$$$. The third segment can be passed using the accumulator, and charge levels become $$$b=1$$$ and $$$a=0$$$. The fourth segment can be passed using the battery, and charge levels become $$$b=0$$$ and $$$a=1$$$. And the fifth segment can be passed using the accumulator.In the second example the robot can go through the maximum number of segments using battery two times and accumulator one time in any order.

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function readInt(s) {
    return parseInt(s, 10);
}

function readIntArray(a) {
    return a.map(e => parseInt(e, 10));
}

function solve(n, b, a, l) {
    let ans = 0;
    let aMax = a;
    for (let i = 0; i < n; i++) {
        if (l[i] === 1 && b > 0 && a < aMax) {
            b--;
            a++;
            ans++;
        } else if (a > 0) {
            a--;
            ans++;
        } else if (b > 0) {
            b--;
            ans++;
        } else {
            break;
        }
    }
    return ans;
}

function main() {

    const nk = readLine();

    const n = readInt(nk[0]);
    const b = readInt(nk[1]);
    const a = readInt(nk[2]);
    const l = readIntArray(readLine());
    let result = solve(n, b, a, l);
    console.log(result);
}


A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called $$$k$$$-balanced if every substring of size $$$k$$$ of this bitstring has an equal amount of 0 and 1 characters ($$$\frac{k}{2}$$$ of each).You are given an integer $$$k$$$ and a string $$$s$$$ which is composed only of characters 0, 1, and ?. You need to determine whether you can make a $$$k$$$-balanced bitstring by replacing every ? characters in $$$s$$$ with either 0 or 1.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le k \le n \le 3 \cdot 10^5$$$, $$$k$$$ is even)  — the length of the string and the parameter for a balanced bitstring. The next line contains the string $$$s$$$ ($$$|s| = n$$$). It is given that $$$s$$$ consists of only 0, 1, and ?. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, print YES if we can replace every ? in $$$s$$$ with 0 or 1 such that the resulting bitstring is $$$k$$$-balanced, or NO if it is not possible.

NoteFor the first test case, the string is already a $$$4$$$-balanced bitstring.For the second test case, the string can be transformed into 101.For the fourth test case, the string can be transformed into 0110.For the fifth test case, the string can be transformed into 1100110.

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));
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 main() {
  let t = +readLine();
  while (t--) {
    const [len, limit] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const arr = readLine().split("");
    let possible = true;
    let [count0, count1] = [0, 0];

    for (let i = 0; i < len; i++) {
      const index = i % limit;
      if (arr[i] === "?" && arr[index] !== "?") {
        arr[i] = arr[index];
      } else if (arr[index] === "?" && arr[i] !== "?") {
        arr[index] = arr[i];
      }

      if (arr[i] !== arr[index]) {
        possible = false;
        break;
      }
    }

    if (possible) {
      for (let i = 0; i < limit; i++) {
        if (arr[i] === "1") count1++;
        if (arr[i] === "0") count0++;
      }

      if (count1 <= limit / 2 && count0 <= limit / 2) possible = true;
      else possible = false;
    }

    if (possible) console.log("YES");
    else console.log("NO");
  }
}

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

(async () => {
  await inputPromise;
  let inp = input.split(/\r?\n/); r = 0;
  let t = +inp[r++];
  for (let i = 0; i < t; i++) {
    (() => {
      let [n, k] = inp[r++].split(' ').map(v => +v);
      let s = inp[r++].split('');
      // console.log(s.join(''));
      for (let i = 0; i < k; i++) {
        let c = s[i];
        for (let j = i + k; j < n; j += k) {
          if (c != '?' && s[j] != '?' && c != s[j]) {
            // console.log(c, j, s[j]);
            console.log('NO');
            return;
          }
          if (s[j] != '?') c = s[j];
        }
        s[i] = c;
      }
      let c = {};
      for (let i = 0; i < k; i++) c[s[i]] = (c[s[i]] || 0) + 1;
      // console.log(c);
      console.log((c[0] || 0) <= k / 2 && (c[1] || 0) <= k / 2 ? 'YES' : '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();
    });

    A();
});

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 [n,k] = ti(readline().split(' '));
        let s = readline().split('');
        let v = new Array(n);
        v.fill('?');
        let flag = true;
        for(let i = 0; i < k; i++){
            for(let j = i; j < n; j+=k){
                if(s[j] === '?')
                    continue;
                if(v[i] === '?' || v[i] === s[j])
                    v[i] = s[j];
                else{
                    flag = false;
                    break;
                }
            }
        }

        if(flag){
            let c1 = 0;
            let c0 = 0;
            for(let i = 0; i < k; i++){
                if(v[i] === '1') c1++;
                if(v[i] === '0') c0++;
            }

            if(c1 > k/2 || c0 > k/2)
                console.log('NO');
            else
                console.log('YES');
        }else{
            console.log('NO');
        }
    }
}


There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves from the i-th block to the (i - 1)-th block, he will leave a left footprint on the i-th block. If there already is a footprint on the i-th block, the new footprint will cover the old one.  At the beginning, there were no footprints. Then polar bear Alice starts from the s-th block, makes a sequence of moves and ends in the t-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of s, t by looking at the footprints.

The first line of the input contains integer n (3 ≤ n ≤ 1000). The second line contains the description of the road — the string that consists of n characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists.

Print two space-separated integers — the values of s and t. If there are several possible solutions you can print any of them.

NoteThe first test sample is the one in the picture.

var n = readline();
var footprints = readline();
var s=0,t=0;

footprints = Array.prototype.slice.call(footprints);

footprintsFiltered = footprints.filter((elem) => {
    return elem != '.';
})

footprintsR = footprints.filter((elem)=>{
    return elem == 'R';
})

if(footprintsR.length == footprintsFiltered.length){//all R's

    s=footprints.indexOf('R')+1;
    t=footprints.lastIndexOf('R')+2;

}else if(footprintsR.length == 0){//all L's

    s=footprints.lastIndexOf('L')+1;
    t=footprints.indexOf('L');

}else{
    s=footprints.indexOf('R')+1;
    t=footprints.lastIndexOf('R')+1;
}

print(s,t);


You are given a pair of integers $$$(a, b)$$$ and an integer $$$x$$$.You can change the pair in two different ways:   set (assign) $$$a := |a - b|$$$;  set (assign) $$$b := |a - b|$$$,  where $$$|a - b|$$$ is the absolute difference between $$$a$$$ and $$$b$$$.The pair $$$(a, b)$$$ is called $$$x$$$-magic if $$$x$$$ is obtainable either as $$$a$$$ or as $$$b$$$ using only the given operations (i.e. the pair $$$(a, b)$$$ is $$$x$$$-magic if $$$a = x$$$ or $$$b = x$$$ after some number of operations applied). You can apply the operations any number of times (even zero).Your task is to find out if the pair $$$(a, b)$$$ is $$$x$$$-magic or not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains three integers $$$a$$$, $$$b$$$ and $$$x$$$ ($$$1 \le a, b, x \le 10^{18}$$$).

For the $$$i$$$-th test case, print YES if the corresponding pair $$$(a, b)$$$ is $$$x$$$-magic and NO otherwise.

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 [a, b, x] = lines[l++].trim().split(' ').map(Number)
        const [a, b, x] = lines[l++].trim().split(' ').map(BigInt)
        output[i] = solve(a, b, x)
    }
    console.log(output.join('\n'))
// })()
})

function solve(a, b, x) {
    while (a) {
        const r = b % a
        // b, b - a, b - 2 * a, ..., r
        if (x === a) return 'YES'
        if (x >= r && x <= b && !((b - x) % a)) return 'YES'
        b = a
        a = r
    }
    return 'NO'
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		let [a, b, x] = rbna();

		function get (a, b, x) {
			// normalize a and b
			if (a > b) [a, b] = [b, a];
			if (b - a < a) a = b - a;

			if (x == b) return true;
			if (x > b || a == 0) return false;
			if ((b - x) % a == 0) return true;
			return get(a, a + b % a, x);
		}

		console.log(get(a, b, x) ? 'YES' : 'NO');
	}
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		let [a, b, x] = rbna();

		function get (a, b, x) {
			if (a > b) [a, b] = [b, a];
			if (b - a < a) a = b - a;
			if (x == b) return true;
			if (x > b || a == 0 || b == 0) return false;
			if ((b - x) % a == 0) return true;
			return get(a, a + b % a, x);
		}

		console.log(get(a, b, x) ? 'YES' : 'NO');
	}
}


Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1, a2, ..., an, where ai is the height of the i-th student in the line and n is the number of students in the line. The children find it hard to keep in mind this strange arrangement, and today they formed the line in the following order: b1, b2, ..., bn, which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: a1, a2, ..., an. During each move Vasya can swap two people who stand next to each other in the line. Help Vasya, find the sequence of swaps leading to the arrangement Vasya needs. It is not required to minimize the number of moves.

The first line contains an integer n (1 ≤ n ≤ 300) which is the number of students. The second line contains n space-separated integers ai (1 ≤ ai ≤ 109) which represent the height of the student occupying the i-th place must possess. The third line contains n space-separated integers bi (1 ≤ bi ≤ 109) which represent the height of the student occupying the i-th place in the initial arrangement. It is possible that some students possess similar heights. It is guaranteed that it is possible to arrange the children in the required order, i.e. a and b coincide as multisets.

In the first line print an integer k (0 ≤ k ≤ 106) which is the number of moves. It is not required to minimize k but it must not exceed 106. Then print k lines each containing two space-separated integers. Line pi, pi + 1 (1 ≤ pi ≤ n - 1) means that Vasya should swap students occupying places pi and pi + 1.

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

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

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

function main() {
	var numItems = parseInt(readline(), 10),
		desiredOrder = tokenizeIntegers(readline()),
		actualOrder = tokenizeIntegers(readline()),
		versionLookup = {},
		uniques = [],
		positionOf = {};

	function buildVersionString(item) {
		return item + "." + versionLookup[item];
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = desiredOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			uniques.push(item);
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		positionOf[buildVersionString(item)] = itemIndex;
	}

	for (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {
		versionLookup[uniques[uniqueIndex]] = undefined;
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = actualOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		actualOrder[itemIndex] = positionOf[buildVersionString(item)];
	}

	var swaps = [];

	while (true) {
		var madeSwap = (1 == 2);

		for (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {
			if (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {
				var temp = actualOrder[itemIndex-1];
				actualOrder[itemIndex-1] = actualOrder[itemIndex];
				actualOrder[itemIndex] = temp;

				madeSwap = true;
				swaps.push((itemIndex) + " " + (itemIndex+1));
			}
		}// end for

		if (madeSwap == false) {
			break;
		}
	}// end while

	swaps.unshift(swaps.length);
	print(swaps.join("\n"));
}// end main

main();

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

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

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

function main() {
	var numItems = parseInt(readline(), 10),
		desiredOrder = tokenizeIntegers(readline()),
		actualOrder = tokenizeIntegers(readline()),
		versionLookup = {},
		uniques = [],
		positionOf = {};

	function buildVersionString(item) {
		return item + "." + versionLookup[item];
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = desiredOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			uniques.push(item);
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		positionOf[buildVersionString(item)] = itemIndex;
	}

	for (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {
		versionLookup[uniques[uniqueIndex]] = undefined;
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = actualOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		actualOrder[itemIndex] = positionOf[buildVersionString(item)];
	}

	var swaps = new Array();

	while (true) {
		var madeSwap = false;

		for (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {
			if (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {
				var temp = actualOrder[itemIndex-1];
				actualOrder[itemIndex-1] = actualOrder[itemIndex];
				actualOrder[itemIndex] = temp;

				madeSwap = true;
				swaps.push((itemIndex) + " " + (itemIndex+1));
			}
		}// end for

		if (madeSwap == false) {
			break;
		}
	}// end while

	swaps.unshift(swaps.length);
	print(swaps.join("\n"));
}// end main

main();

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

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

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

function main() {
	var numItems = parseInt(readline(), 10),
		desiredOrder = tokenizeIntegers(readline()),
		actualOrder = tokenizeIntegers(readline()),
		itemInfo = {};

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = desiredOrder[itemIndex];
		if (itemInfo[item] == undefined) {
			itemInfo[item] = {
				occurrences: [itemIndex],
				occurrenceIndex: 0
			};
		}
		else {
			itemInfo[item].occurrences.push(itemIndex);
		}
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = actualOrder[itemIndex];

		actualOrder[itemIndex] = itemInfo[item].occurrences[
			itemInfo[item].occurrenceIndex++];
	}

	var swaps = [];

	while (true) {
		var madeSwap = (1+2 == 2);

		for (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {
			if (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {
				var temp = actualOrder[itemIndex-1];
				actualOrder[itemIndex-1] = actualOrder[itemIndex];
				actualOrder[itemIndex] = temp;

				madeSwap = true;
				swaps.push((itemIndex) + " " + (itemIndex+1));
			}
		}// end for

		if (madeSwap == false) {
			break;
		}
	}// end while

	swaps.unshift(swaps.length);
	print(swaps.join("\n"));
}// end main

main();

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

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

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

function main() {
	var numItems = parseInt(readline(), 10),
		desiredOrder = tokenizeIntegers(readline()),
		actualOrder = tokenizeIntegers(readline()),
		versionLookup = {},
		uniques = [],
		positionOf = {};

	function buildVersionString(item) {
		return item + "." + versionLookup[item];
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = desiredOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			uniques.push(item);
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		positionOf[buildVersionString(item)] = itemIndex;
	}

	for (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {
		versionLookup[uniques[uniqueIndex]] = undefined;
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = actualOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		actualOrder[itemIndex] = positionOf[buildVersionString(item)];
	}

	var swaps = [];

	while (true) {
		var madeSwap = (1 == 0);

		for (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {
			if (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {
				var temp = actualOrder[itemIndex-1];
				actualOrder[itemIndex-1] = actualOrder[itemIndex];
				actualOrder[itemIndex] = temp;

				madeSwap = true;
				swaps.push((itemIndex) + " " + (itemIndex+1));
			}
		}// end for

		if (madeSwap == false) {
			break;
		}
	}// end while

	swaps.unshift(swaps.length);
	print(swaps.join("\n"));
}// end main

main();

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

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

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

function main() {
	var numItems = parseInt(readline(), 10),
		desiredOrder = tokenizeIntegers(readline()),
		actualOrder = tokenizeIntegers(readline()),
		versionLookup = {},
		uniques = [],
		positionOf = {};

	function buildVersionString(item) {
		return item + "." + versionLookup[item];
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = desiredOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			uniques.push(item);
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		positionOf[buildVersionString(item)] = itemIndex;
	}

	for (var uniqueIndex = uniques.length-1; uniqueIndex >= 0; --uniqueIndex) {
		versionLookup[uniques[uniqueIndex]] = undefined;
	}

	for (var itemIndex = 0; itemIndex < numItems; ++itemIndex) {
		var item = actualOrder[itemIndex];
		if (versionLookup[item] == undefined) {
			versionLookup[item] = 0;
		}
		else {
			versionLookup[item] += 1;
		}

		actualOrder[itemIndex] = positionOf[buildVersionString(item)];
	}

	var swaps = [];

	while (true) {
		var madeSwap = false;

		for (var itemIndex = 1; itemIndex < numItems; ++itemIndex) {
			if (actualOrder[itemIndex-1] > actualOrder[itemIndex]) {
				var temp = actualOrder[itemIndex-1];
				actualOrder[itemIndex-1] = actualOrder[itemIndex];
				actualOrder[itemIndex] = temp;

				madeSwap = true;
				swaps.push((itemIndex) + " " + (itemIndex+1));
			}
		}// end for

		if (madeSwap == false) {
			break;
		}
	}// end while

	swaps.unshift(swaps.length);
	print(swaps.join("\n"));
}// end main

main();


One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know why their movements are so sluggish, the problem of laggy thinking has been recently resolved. It turns out that the reason is not (as previously suspected) any kind of brain defect – it's the opposite! Independent researchers confirmed that the nervous system of a zombie is highly complicated – it consists of n brains (much like a cow has several stomachs). They are interconnected by brain connectors, which are veins capable of transmitting thoughts between brains. There are two important properties such a brain network should have to function properly:   It should be possible to exchange thoughts between any two pairs of brains (perhaps indirectly, through other brains).  There should be no redundant brain connectors, that is, removing any brain connector would make property 1 false. If both properties are satisfied, we say that the nervous system is valid. Unfortunately (?), if the system is not valid, the zombie stops thinking and becomes (even more) dead. Your task is to analyze a given nervous system of a zombie and find out whether it is valid.

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) denoting the number of brains (which are conveniently numbered from 1 to n) and the number of brain connectors in the nervous system, respectively. In the next m lines, descriptions of brain connectors follow. Every connector is given as a pair of brains a b it connects (1 ≤ a, b ≤ n, a ≠ b).

The output consists of one line, containing either yes or no depending on whether the nervous system is valid.

function getNumberArray() {
    return readline().split(" ").map(function(s) { return Number(s); });
}

var nm = getNumberArray();
var n = nm[0], m = nm[1];

function p(brain) {
    if (subtree[brain] == brain)
        return brain;

    subtree[brain] = p(subtree[brain]);
    return subtree[brain];
}

var subtree = new Array(n); // subtree index for all brains
for (var i = 0; i < n; ++i)
    subtree[i] = i;

if (m != n - 1)
    print("no");
else {

    for (var j = 0; j < m; ++j) {
        var ab = getNumberArray();
        var a = ab[0] - 1, b = ab[1] - 1;

        var k1 = Math.min(p(a), p(b));
        var k2 = Math.max(p(a), p(b));
        //print(a, "<-->", b, " (", k1, "<>", k2, ")");

        subtree[k2] = k1;
    }

    var success = true;
    for (var i = 0; i < n; ++i)
        if (p(i) !== 0) {
            success = false;
            break;
        }

    print(success ? "yes" : "no");
}

function main() {
  var n = +next(), m = +next();
  if (m != n - 1) {
    print("no");
    return;
  }
  var p = [];
  var i;
  for (i = -1; ++ i < n; ) p[i] = i;
  function findp(u) { return (p[u] = u === p[u] ? u : findp(p[u])); }
  function join(u, v) { p[findp(u)] = findp(v); }

  while (m--) {
    join(next() - 1, next() - 1);
  }
  var cnt = 0;
  for (i = -1; ++i < n; )
    cnt += +(i === findp(i));
  print(cnt === 1 ? "yes" : "no");
}

var line = null, linepos = 0;
function next() {
  if (!line || linepos === line.length) {
    line = readline().split(' ');
    linepos = 0;
  }
  return line[linepos++];
}

if (typeof readline == 'undefined') {
  process.stdin.resume();
  process.stdin.setEncoding('ascii');

  var input_stdin = "";
  process.stdin.on('data', function (data) { input_stdin += data; });
  process.stdin.on('end', function () {
    // input_stdin = input_stdin.split(/\s/);
    input_stdin = input_stdin.split('\n');
    var curline = 0;
    readline = () => input_stdin[curline++];
    if (typeof print == 'undefined') print = console.log;
    main();
  });
} else main();

function getNumberArray() {
    return readline().split(" ").map(function(s) { return Number(s); });
}

var nm = getNumberArray();
var n = nm[0], m = nm[1];

function p(brain) {
    if (subtree[brain] == brain)
        return brain;

    subtree[brain] = p(subtree[brain]);
    return subtree[brain];
}

if (m != n - 1)
    print("no");
else {
    var subtree = new Array(n); // subtree index for all brains
    for (var i = 0; i < n; ++i)
        subtree[i] = i;

    for (var j = 0; j < m; ++j) {
        var ab = getNumberArray();
        var a = ab[0], b = ab[1];

        if (a > b) {
            var tmp = a;
            a = b;
            b = tmp;
        }
        //print(a, "<-->", b);

        subtree[b - 1] = a - 1;
    }

    var success = true;
    for (var i = 0; i < n; ++i)
        if (p(i) !== 0) {
            success = false;
            break;
        }

    print(success ? "yes" : "no");
}


You are playing a game on a $$$n \times m$$$ grid, in which the computer has selected some cell $$$(x, y)$$$ of the grid, and you have to determine which one. To do so, you will choose some $$$k$$$ and some $$$k$$$ cells $$$(x_1, y_1),\, (x_2, y_2), \ldots, (x_k, y_k)$$$, and give them to the computer. In response, you will get $$$k$$$ numbers $$$b_1,\, b_2, \ldots b_k$$$, where $$$b_i$$$ is the manhattan distance from $$$(x_i, y_i)$$$ to the hidden cell $$$(x, y)$$$ (so you know which distance corresponds to which of $$$k$$$ input cells). After receiving these $$$b_1,\, b_2, \ldots, b_k$$$, you have to be able to determine the hidden cell. What is the smallest $$$k$$$ for which is it possible to always guess the hidden cell correctly, no matter what cell computer chooses?As a reminder, the manhattan distance between cells $$$(a_1, b_1)$$$ and $$$(a_2, b_2)$$$ is equal to $$$|a_1-a_2|+|b_1-b_2|$$$.

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

For each test case print a single integer — the minimum $$$k$$$ for that test case.

NoteIn the first test case, the smallest such $$$k$$$ is $$$2$$$, for which you can choose, for example, cells $$$(1, 1)$$$ and $$$(2, 1)$$$.Note that you can't choose cells $$$(1, 1)$$$ and $$$(2, 3)$$$ for $$$k = 2$$$, as both cells $$$(1, 2)$$$ and $$$(2, 1)$$$ would give $$$b_1 = 1, b_2 = 2$$$, so we wouldn't be able to determine which cell is hidden if computer selects one of those.In the second test case, you should choose $$$k = 1$$$, for it you can choose cell $$$(3, 1)$$$ or $$$(1, 1)$$$.

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

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

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

		if (n == 1 && m == 1) console.log(0);
		else if (n == 1 || m == 1) console.log(1);
		else console.log(2);
	}
}

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

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

function main () {
	let t = rn();
	while (t--) {
		let [n, m] = rna();

		if (n == 1 && m == 1) console.log(0);
		else if (n == 1 || m == 1) console.log(1);
		else console.log(2);
	}
}

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 s = lines[i].split(' ').map(Number);
        var n = s[0], m = s[1];
        if(n == 1 && m == 1){
            console.log(0);
        }else if(n == 1 || m == 1){
            console.log(1);
        }else{
            console.log(2);
        }
    }
});

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

n = readline();
while (n--) {
  s = readline().split(" ");
  x = +s[0];
  y = +s[1];
  if (x == 1 && y == 1) print(0);
  else if (x == 1 || y == 1) print(1);
  else print(2);
}

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

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

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

		if (n == 1 || m == 1) console.log(1);
		else console.log(2);
	}
}

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

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

function main () {
	let t = rn();
	while (t--) {
		let [n, m] = rna();

		if (n == 1 || m == 1) console.log(1);
		else console.log(2);
	}
}

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 s = lines[i].split(' ').map(Number);
        var n = s[0], m = s[1];
        if(m == 1){
            console.log(1);
        }else{
            console.log(2);
        }
    }
});

n = readline();
while (n--) {
  s = readline().split(" ");
  x = +s[0];
  y = +s[1];
  print(x < y ? x : y);
}


The Bitlandians are quite weird people. They have very peculiar customs.As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. has got n eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.

The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs. Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.

If it is impossible to assign the painting, print "-1" (without quotes). Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as Sa, and the money Uncle J. must pay G. for the painting as Sg, then this inequality must hold: |Sa  -  Sg|  ≤  500.  If there are several solutions, you are allowed to print any of them.

print(function(n) {

	var ans = [],
		sum = 0;
	while (n--)
		ans.push(readline().split(' ').map(Number).reduce(function(a, g) {
			if (sum + a <= 500) {
				sum += a;
				return 'A';
			}
			sum -= g;
			return 'G';
		}));

	return ans.join('');

}(+readline()));

;(function () {

	print(function (n) {

		var a = 0, b = 0, result = '';
		while (n--) {
			var l = readline().split(' ').map(Number),
				_a = a + l[0], _b = b + l[1];

			if (Math.abs(_b - a) < Math.abs(_a - b)) {
				b = _b; result += 'G';
			} else {
				a = _a; result += 'A';
			}
		}

		return Math.abs(a - b) > 500 ? -1 : result;

	}(+readline()));

}.call(this));

;(function () {

	print(function (n) {

		var a = 0, b = 0, result = '';
		while (n--) {
			var l = readline().split(' ').map(Number),
				_a = a + l[0], _b = b + l[1];

			if (Math.abs(_b - a) < Math.abs(_a - b)) {
				b = _b; result += 'B';
			} else {
				a = _a; result += 'A';
			}
		}

		return Math.abs(a - b) > 500 ? -1 : result;

	}(+readline()));

}.call(this));


Nastia has received an array of $$$n$$$ positive integers as a gift.She calls such an array $$$a$$$ good that for all $$$i$$$ ($$$2 \le i \le n$$$) takes place $$$gcd(a_{i - 1}, a_{i}) = 1$$$, where $$$gcd(u, v)$$$ denotes the greatest common divisor (GCD) of integers $$$u$$$ and $$$v$$$.You can perform the operation: select two different indices $$$i, j$$$ ($$$1 \le i, j \le n$$$, $$$i \neq j$$$) and two integers $$$x, y$$$ ($$$1 \le x, y \le 2 \cdot 10^9$$$) so that $$$\min{(a_i, a_j)} = \min{(x, y)}$$$. Then change $$$a_i$$$ to $$$x$$$ and $$$a_j$$$ to $$$y$$$.The girl asks you to make the array good using at most $$$n$$$ operations.It can be proven that this is always possible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_{n}$$$ ($$$1 \le a_i \le 10^9$$$) — the array which Nastia has received as a gift. It's guaranteed that the sum of $$$n$$$ in one test doesn't exceed $$$2 \cdot 10^5$$$.

For each of $$$t$$$ test cases print a single integer $$$k$$$ ($$$0 \le k \le n$$$) — the number of operations. You don't need to minimize this number. In each of the next $$$k$$$ lines print $$$4$$$ integers $$$i$$$, $$$j$$$, $$$x$$$, $$$y$$$ ($$$1 \le i \neq j \le n$$$, $$$1 \le x, y \le 2 \cdot 10^9$$$) so that $$$\min{(a_i, a_j)} = \min{(x, y)}$$$ — in this manner you replace $$$a_i$$$ with $$$x$$$ and $$$a_j$$$ with $$$y$$$. If there are multiple answers, print any.

NoteConsider the first test case.Initially $$$a = [9, 6, 3, 11, 15]$$$.In the first operation replace $$$a_1$$$ with $$$11$$$ and $$$a_5$$$ with $$$9$$$. It's valid, because $$$\min{(a_1, a_5)} = \min{(11, 9)} = 9$$$.After this $$$a = [11, 6, 3, 11, 9]$$$.In the second operation replace $$$a_2$$$ with $$$7$$$ and $$$a_5$$$ with $$$6$$$. It's valid, because $$$\min{(a_2, a_5)} = \min{(7, 6)} = 6$$$.After this $$$a = [11, 7, 3, 11, 6]$$$ — a good array.In the second test case, the initial array is already good.

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

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

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

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

		console.log(n-1);
		for(let i = 0; i < n; i++) {
			if (i == mni) continue;
			console.log(mni+1, i+1, a[mni], a[mni] + Math.abs(i-mni));
		}
	}
}

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

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

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

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

		console.log(mni == 0 ? n-1: n);
		if (mni != 0) console.log(1, mni+1, a[mni], a[0]);
		for(let i = 1; i < n; i++) {
			console.log(1, i+1, a[mni], a[mni]+i);
		}
	}
}

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

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

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

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

		console.log(n-1);
		for(let i = 1; i < n; i++) {
			if (i != mni) {
				console.log(mni+1, i+1, a[mni], a[mni]+i);
			}
		}
		if (mni != 0)
			console.log(mni+1, 1, a[mni]+mni, a[mni]);
	}
}

"use strict";

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

for (; t > 0; --t) {
  var n = parseInt(readline(), 10);
  var arr = readline().split(" ").map(function (v) {
    return parseInt(v, 10);
  });

  if (n === 1) {
    print(0);
    continue;
  } // 找到最小值

  var minn = Math.min.apply(null, arr); // 找到最小值的（第一个）索引

  var mini = arr.indexOf(minn);
  print(n - 1); // 向左

  var add = 0;

  for (var i = mini - 1; i >= 0; --i) {
    ++add;
    print("".concat(mini + 1, " ").concat(i + 1, " ").concat(minn, " ").concat(minn + add));
  } // 向右

  add = 0;

  for (var _i = mini + 1; _i < n; ++_i) {
    ++add;
    print("".concat(mini + 1, " ").concat(_i + 1, " ").concat(minn, " ").concat(minn + add));
  }
}

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

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

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

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

		console.log(n);
		if (mni != 0) console.log(1, mni+1, a[mni], a[0]);
		for(let i = 1; i < n; i++) {
			console.log(1, i+1, a[mni], a[mni]+i);
		}
	}
}

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

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

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

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

		console.log(mni == 0 ? n-2 : n-1);
		for(let i = 1; i < n; i++) {
			if (i != mni) {
				console.log(mni+1, i+1, a[mni], a[mni]+i);
			}
		}
		if (mni != 0)
			console.log(mni+1, 1, a[mni]+mni, a[mni]);
	}
}

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

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

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

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

		console.log(n-1);
		for(let i = 1; i < n; i++) {
			if (i != mni) {
				console.log(mni+1, i+1, a[mni], a[mni] + i);
			}
		}
		console.log(mni+1, 1, a[mni] + mni, a[mni]);
	}
}

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

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

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

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

		console.log(n-1);
		for(let i = 1; i < n; i++) {
			if (i != mni) {
				console.log(mni+1, i+1, a[mni], a[mni] + i);
			}
		}
		console.log(mni+1, 1, a[mni], a[mni] + mni);
	}
}

"use strict";

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

for (; t > 0; --t) {
  var n = parseInt(readline(), 10);
  var arr = readline().split(" ").map(function (v) {
    return parseInt(v, 10);
  });

  if (n === 1) {
    print(0);
    continue;
  } // 找到最小值

  var minn = Math.min.apply(null, arr); // 找到最小值的（第一个）索引

  var mini = arr.indexOf(minn);
  var add = 0;
  var flag = true;
  print(n - 1);

  for (var i = 0; i < n; ++i) {
    if (i === mini && flag) {
      flag = false;
      continue;
    } else {
      ++add;
      print("".concat(mini + 1, " ").concat(i + 1, " ").concat(minn, " ").concat(minn + add));
    }
  }
}

"use strict";

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

  return gcd(b, a % b);
}

var t = parseInt(readline(), 10);
var ret = [];

for (; t > 0; --t) {
  var n = parseInt(readline(), 10);
  var arr = readline().split(" ").map(function (v) {
    return parseInt(v, 10);
  });

  if (n === 1) {
    print(0);
    continue;
  } // 找到最小值

  var minn = Math.min.apply(null, arr); // 找到最小值索引

  var mini = arr.indexOf(minn); // 从最小值往两边扩散

  var ans = 0;
  var ope = []; // 左边

  for (var i = mini; i > 0; --i) {
    if (gcd(arr[i], arr[i - 1]) === 1) {
      continue;
    } else {
      while (gcd(arr[i], arr[i - 1]) !== 1) {
        ++arr[i - 1];
      }

      ++ans;
      ope.push("".concat(i, " ").concat(mini + 1, " ").concat(arr[i - 1], " ").concat(minn));
    }
  } // 右边

  for (var _i = mini; _i < n - 1; ++_i) {
    if (gcd(arr[_i], arr[_i + 1]) === 1) {
      continue;
    } else {
      while (gcd(arr[_i], arr[_i + 1]) !== 1) {
        ++arr[_i + 1];
      }

      ++ans;
      ope.push("".concat(mini + 1, " ").concat(_i + 2, " ").concat(minn, " ").concat(arr[_i + 1]));
    }
  }

  ret.push.apply(ret, [ans].concat(ope));
}

while (ret.length > 0) {
  print(ret.shift());
}

"use strict";

// import readlineSync from "readline-sync";
// const readline = readlineSync.question.bind(null, "input: ");
// const print = console.log;
// 上传时删去上面三行
// 最大公约数的函数
function gcd(a, b) {
  if (b === 0) {
    return a;
  }

  return gcd(b, a % b);
}

var t = parseInt(readline(), 10);
var ret = [];

for (; t > 0; --t) {
  var n = parseInt(readline(), 10);
  var arr = readline()
    .split(" ")
    .map(function (v) {
      return parseInt(v, 10);
    });

  if (n === 1) {
    print(0);
    continue;
  }

  var ans = 0;
  var ope = [];

  for (var i = 0; i < n - 1; ++i) {
    if (gcd(arr[i], arr[i + 1]) === 1) {
      continue;
    } else {
      arr[i + 1] = arr[i] + 1;

      while (gcd(arr[i], arr[i + 1]) !== 1) {
        ++arr[i + 1];
      }

      ++ans;
      ope.push(
        ""
          .concat(i + 1, " ")
          .concat(i + 2, " ")
          .concat(arr[i], " ")
          .concat(arr[i + 1])
      );
    }
  }

  ret.push.apply(ret, [ans].concat(ope));
}

while (ret.length > 0) {
  print(ret.shift());
}


Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll represent the cell on the intersection of the i-th row and j-th column as (i, j). Just as is expected, some cells of the giant candy matrix contain candies. Overall the matrix has p candies: the k-th candy is at cell (xk, yk).The time moved closer to dinner and Inna was already going to eat p of her favourite sweets from the matrix, when suddenly Sereja (for the reason he didn't share with anyone) rotated the matrix x times clockwise by 90 degrees. Then he performed the horizontal rotate of the matrix y times. And then he rotated the matrix z times counterclockwise by 90 degrees. The figure below shows how the rotates of the matrix looks like.  Inna got really upset, but Duma suddenly understood two things: the candies didn't get damaged and he remembered which cells contained Inna's favourite sweets before Sereja's strange actions. Help guys to find the new coordinates in the candy matrix after the transformation Sereja made!

The first line of the input contains fix integers n, m, x, y, z, p (1 ≤ n, m ≤ 109; 0 ≤ x, y, z ≤ 109; 1 ≤ p ≤ 105). Each of the following p lines contains two integers xk, yk (1 ≤ xk ≤ n; 1 ≤ yk ≤ m) — the initial coordinates of the k-th candy. Two candies can lie on the same cell.

For each of the p candies, print on a single line its space-separated new coordinates.

NoteJust for clarity. Horizontal rotating is like a mirroring of the matrix. For matrix:QWER      REWQ ASDF  ->  FDSAZXCV      VCXZ

print(function(n, m, x, y, z, p){
	x=x%4;
	y=y%2;
	z=z%4;
	function a(x, y, n, m){
		return [m-y, x, m, n];
	}
	function b(x, y, n, m){
		return [n-x, y, n, m];
	}
	function c(x, y, n, m){
		return [y, n-x, m, n];
	}

	function aa(xx,yy){
		var ans=[yy,xx,m+1,n+1];
		for(var ii=0; ii<x; ii++){
			ans=a.apply(0, ans);
		}
		for(var ii=0; ii<y; ii++){
			ans=b.apply(0, ans);
		}
		for(var ii=0; ii<z; ii++){
			ans=c.apply(0, ans);
		}
		return ans[1]+' '+ans[0];
	}
	var ans=[];
	for(var i=0; i<p; i++){
		ans.push(aa.apply( 0, readline().split(' ').map(Number) ));
	}

	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var rowNum = integers[0], colNum = integers[1],
		clockwise = integers[2]%4, reflection = integers[3]%2,
		counterclockwise = integers[4]%4, pointNum = integers[5];

	var rotateFunctions = [
		function(point) {
			return point;
		},
		function(point) {
			return { r: point.c, c: point.rn+1-point.r,
					rn: point.cn, cn: point.rn };
		},
		function(point) {
			return { r: point.rn+1-point.r, c: point.cn+1-point.c,
					rn: point.rn, cn: point.cn };
		},
		function(point) {
			return { r: point.cn+1-point.c, c: point.r,
					rn: point.cn, cn: point.rn };
		}
	];
	var clockwiseFunction = rotateFunctions[clockwise],
		counterclockwiseFunction = rotateFunctions[(4-counterclockwise)%4];

	if (reflection == 0) {
		var reflectionFunction = rotateFunctions[0];
	}
	else {
		var reflectionFunction = function(point) {
			return { r: point.r, c: point.cn+1-point.c,
					rn: point.rn, cn: point.cn };
		}
	}

	for (var i = 0; i < pointNum; ++i) {
		var rc = tokenizeIntegers(readline());
		var point = { r: rc[0], c: rc[1], rn: rowNum, cn: colNum };
		point = clockwiseFunction(point);
		point = reflectionFunction(point);
		point = counterclockwiseFunction(point);
		print(point.r+" "+point.c);
	}
}

main();

var nmxyzp = readline().split(' ').map(Number);
var n = nmxyzp[0];
var m = nmxyzp[1];
var x = nmxyzp[2]%4;
var y = nmxyzp[3]%2;
var z = nmxyzp[4]%4;
var p = nmxyzp[5];
for (var i=0; i<p; i++) {
	var p1 = readline().split(' ').map(Number);
	var x1 = p1[0];
	var y1 = p1[1];
	var n1 = n;
	var m1 = m;
	for (var j=0; j<x; j++) {
		var x2 = y1;
		var y2 = n1 - x1 + 1;
		x1 = x2;
		y1 = y2;
		n1 = n1 + m1;
		m1 = n1 - m1;
		n1 = n1 - m1;
	}
	for (var j=0; j<y; j++) {
		y1 = m1 - y1 + 1;
	}
	for (var j=0; j<z; j++) {
		var x2 = m1 - y1 + 1;
		var y2 = x1;
		x1 = x2;
		y1 = y2;
		n1 = n1 + m1;
		m1 = n1 - m1;
		n1 = n1 - m1;
	}
	print(x1 + ' ' + y1);
}

print(function(n, m, x, y, z, p){
	x=x%4;
	y=y%2;
	z=z%4;
	function a(v){
		return [v[2]-v[1], v[0], v[3], v[2]];
	}
	function b(v){
		return [v[2]-v[0], v[1], v[2], v[3]];
	}
	function c(v){
		return [v[1], v[2]-v[0], v[3], v[2]];
	}
	function aa(i,j){
		var ans=[j,i,m+1,n+1];
		for(var ii=0; ii<x; ii++){
			ans=a(ans);
		}
		for(var ii=0; ii<y; ii++){
			ans=b(ans);
		}
		for(var ii=0; ii<z; ii++){
			ans=c(ans);
		}
		return ans[1]+' '+ans[0];
	}
	var ans=[];
	for(var i=0; i<p; i++){
		ans.push(aa.apply( 0, readline().split(' ').map(Number) ));
	}

	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

print(function(n, m, x, y, z, p){
	x=x%4;
	y=y%2;
	z=z%4;
	function a(v){
		return [v[3]-v[1], v[0], v[3], v[2]];
	}
	function b(v){
		return [v[0], v[2]-v[1], v[2], v[3]];
	}
	function c(v){
		return [v[1], v[2]-v[0], v[3], v[2]];
	}
	function aa(xx,yy){
		var ans=[xx,yy,n+1,m+1];
		for(var ii=0; ii<x; ii++){
			ans=a(ans);
		}
		for(var ii=0; ii<y; ii++){
			ans=b(ans);
		}
		for(var ii=0; ii<z; ii++){
			ans=c(ans);
		}
		return ans[0]+' '+ans[1];
	}
	var ans=[];
	for(var i=0; i<p; i++){
		ans.push(aa.apply( 0, readline().split(' ').map(Number) ));
	}

	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

print(function(n, m, x, y, z, p){
	x=x%4;
	y=y%2;
	z=z%4;
	function a(v){
		return [v[3]-v[1], v[0], v[3], v[2]];
	}
	function b(v){
		return [v[0], v[2]-v[1], v[2], v[3]];
	}
	function c(v){
		return [v[1], v[2]-v[0], v[3], v[2]];
	}
	function aa(xx,yy){
		var ans=[yy,xx,n+1,m+1];
		for(var ii=0; ii<x; ii++){
			ans=a(ans);
		}
		for(var ii=0; ii<y; ii++){
			ans=b(ans);
		}
		for(var ii=0; ii<z; ii++){
			ans=c(ans);
		}
		return ans[1]+' '+ans[0];
	}
	var ans=[];
	for(var i=0; i<p; i++){
		ans.push(aa.apply( 0, readline().split(' ').map(Number) ));
	}

	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

print(function(n, m, x, y, z, p){
	x=x%4;
	y=y%2;
	z=z%4;
	function a(v){
		return [v[2]-v[1], v[0], v[3], v[2]];
	}
	function b(v){
		return [v[2]-v[0], v[1], v[2], v[3]];
	}
	function c(v){
		return [v[1], v[2]-v[0], v[3], v[2]];
	}
	function aa(i,j){
		var ans=[j,i,n+1,m+1];
		for(var ii=0; ii<x; ii++){
			ans=a(ans);
		}
		for(var ii=0; ii<y; ii++){
			ans=b(ans);
		}
		for(var ii=0; ii<z; ii++){
			ans=c(ans);
		}
		return ans[1]+' '+ans[0];
	}
	var ans=[];
	for(var i=0; i<p; i++){
		ans.push(aa.apply( 0, readline().split(' ').map(Number) ));
	}

	return ans.join('\n');
}.apply(0, readline().split(' ').map(Number)));

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var rowNum = integers[0], colNum = integers[1],
		clockwise = integers[2]%4, reflection = integers[3]%2,
		counterclockwise = integers[4]%4, pointNum = integers[5];
	print("clockwise = "+clockwise+", reflection = "+reflection+
			", counterclockwise = "+counterclockwise);

	var rotateFunctions = [
		function(point) {
			return point;
		},
		function(point) {
			return { r: point.c, c: point.rn+1-point.r,
					rn: point.cn, cn: point.rn };
		},
		function(point) {
			return { r: point.rn+1-point.r, c: point.cn+1-point.c,
					rn: point.rn, cn: point.cn };
		},
		function(point) {
			return { r: point.cn+1-point.c, c: point.r,
					rn: point.cn, cn: point.rn };
		}
	];
	var clockwiseFunction = rotateFunctions[clockwise],
		counterclockwiseFunction = rotateFunctions[(4-counterclockwise)%4];

	if (reflection == 0) {
		var reflectionFunction = rotateFunctions[0];
	}
	else {
		var reflectionFunction = function(point) {
			return { r: point.r, c: point.cn+1-point.c,
					rn: point.rn, cn: point.cn };
		}
	}

	for (var i = 0; i < pointNum; ++i) {
		var rc = tokenizeIntegers(readline());
		var point = { r: rc[0], c: rc[1], rn: rowNum, cn: colNum };
		point = clockwiseFunction(point);
		point = reflectionFunction(point);
		point = counterclockwiseFunction(point);
		print(point.r+" "+point.c);
	}
}

main();

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var rowNum = integers[0], colNum = integers[1],
		clockwise = integers[2]%4, reflection = integers[3]%2,
		counterclockwise = integers[4]%4, pointNum = integers[5];

	var rotateFunctions = [
		function(point) {
			return point;
		},
		function(point) {
			return { r: point.c, c: rowNum+1-point.r };
		},
		function(point) {
			return { r: rowNum+1-point.r, c: colNum+1-point.c };
		},
		function(point) {
			return { r: colNum+1-point.c, c: point.r };
		}
	];
	var clockwiseFunction = rotateFunctions[clockwise],
		counterclockwiseFunction = rotateFunctions[(4-counterclockwise)%4];

	if (reflection == 0) {
		var reflectionFunction = rotateFunctions[0];
	}
	else {
		var reflectionFunction = function(point) {
			return { r: point.r, c: colNum+1-point.c };
		}
	}

	for (var i = 0; i < pointNum; ++i) {
		var rc = tokenizeIntegers(readline());
		var point = { r: rc[0], c: rc[1] };
		point = clockwiseFunction(point);
		point = reflectionFunction(point);
		point = counterclockwiseFunction(point);
		print(point.r+" "+point.c);
	}
}

main();

var nmxyzp = readline().split(' ').map(Number);
var n = nmxyzp[0];
var m = nmxyzp[1];
var x = nmxyzp[2]%4;
var y = nmxyzp[3]%2;
var z = nmxyzp[4]%4;
var p = nmxyzp[5];
for (var i=0; i<p; i++) {
	var p1 = readline().split(' ').map(Number);
	var x1 = p1[1];
	var y1 = p1[0];
	var n1 = n;
	var m1 = m;
	for (var j=0; j<x; j++) {
		var x2 = n - y1 + 1;
		var y2 = x1;
		x1 = x2;
		y1 = y2;
		n1 = n1 + m1;
		m1 = n1 - m1;
		n1 = n1 - m1;
	}
	for (var j=0; j<y; j++) {
		x1 = m - x1 + 1;
	}
	for (var j=0; j<z; j++) {
		var x2 = y1;
		var y2 = m - x1 + 1;
		x1 = x2;
		y1 = y2;
		n1 = n1 + m1;
		m1 = n1 - m1;
		n1 = n1 - m1;
	}
	print(y1 + ' ' + x1);
}


Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare. Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.

The first line contain integer t (1 ≤ t ≤ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 ≤ n ≤ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.

Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.

3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel

2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees

NoteIt is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.

'use strict'

let lll

let GP = +readline()

const gs = {}

while (GP--) {
  let N = +readline()
  let pl = 0
  while (N--) {
    const g = readline()
    gs[g] = gs[g] || {s: 0, p: zeroArr(50)}
    gs[g].s += sc(pl)
    gs[g].p[pl]++
    pl++
  }
}

let fbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.s > gs[fbg].s) {
    fbg = gn
    continue o
  } else if (g.s < gs[fbg].s) {
    continue o
  }
  for (let i = 0; i < 50; i++) {
    if (g.p[i] > gs[fbg].p[i]) {
      fbg = gn
      continue o
    } else if (g.p[i] < gs[fbg].p[i]) {
      continue o
    }
  }
}

let sbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.p[0] > gs[sbg].p[0]) {
    sbg = gn
    continue o
  } else if (g.p[0] < gs[sbg].p[0]) {
    continue o
  }
  if (g.s > gs[sbg].s) {
    sbg = gn
    continue
  } else if (g.s < gs[sbg].s) {
    continue o
  }
  for (let i = 1; i < 50; i++) {
    if (g.p[i] > gs[sbg].p[i]) {
      sbg = gn
      continue o
    } else if (g.p[i] < gs[sbg].p[i]) {
      continue o
    }
  }
}

function sc (p) {
  switch (p) {
    case 0: return 25
    case 1: return 18
    case 2: return 15
    case 3: return 12
    case 4: return 10
    case 5: return 8
    case 6: return 6
    case 7: return 4
    case 8: return 2
    case 9: return 1
    default: return 0
  }
}

print(fbg)
print(sbg)

function zeroArr (l) {
  let a = Array(l)
  for (let i = 0; i < l; i++) {
    a[i] = 0
  }
  return a
}

'use strict'

let lll

let GP = +readline()

const gs = {}

while (GP--) {
  let N = +readline()
  let pl = 0
  while (N--) {
    const g = readline()
    gs[g] = gs[g] || {s: 0, p: zeroArr(10)}
    gs[g].s += sc(pl)
    gs[g].p[pl]++
    pl++
  }
}

let fbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.s > gs[fbg].s) {
    fbg = gn
    continue o
  } else if (g.s < gs[fbg].s) {
    continue o
  }
  for (let i = 0; i < 10; i++) {
    if (g.p[i] > gs[fbg].p[i]) {
      fbg = gn
      continue o
    } else if (g.p[i] < gs[fbg].p[i]) {
      continue o
    }
  }
}

let sbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.p[0] > gs[sbg].p[0]) {
    sbg = gn
    continue o
  } else if (g.p[0] < gs[sbg].p[0]) {
    continue o
  }
  if (g.s > gs[sbg].s) {
    sbg = gn
    continue
  } else if (g.s < gs[sbg].s) {
    continue o
  }
  for (let i = 1; i < 10; i++) {
    if (g.p[i] > gs[sbg].p[i]) {
      sbg = gn
      continue o
    } else if (g.p[i] < gs[sbg].p[i]) {
      continue o
    }
  }
}

function sc (p) {
  switch (p) {
    case 0: return 25
    case 1: return 18
    case 2: return 15
    case 3: return 12
    case 4: return 10
    case 5: return 8
    case 6: return 6
    case 7: return 4
    case 8: return 2
    case 9: return 1
    default: return 0
  }
}

print(fbg)
print(sbg)

function zeroArr (l) {
  let a = Array(l)
  for (let i = 0; i < l; i++) {
    a[i] = 0
  }
  return a
}

'use strict'

let lll

let GP = +readline()

const gs = {}

while (GP--) {
  let N = +readline()
  let pl = 0
  while (N--) {
    const g = readline()
    gs[g] = gs[g] || {s: 0, p: zeroArr(10)}
    gs[g].s += sc(pl)
    gs[g].p[pl]++
    pl++
  }
}

let fbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.s > gs[fbg].s) {
    fbg = gn
    continue o
  } else if (g.s < gs[fbg].s) {
    continue o
  }
  q: for (let i = 0; i < 10; i++) {
    if (g.p[i] > gs[fbg].p[i]) {
      fbg = gn
      continue o
    } else if (g.p[i] < gs[fbg].p[i]) {
      continue q
    }
  }
}

let sbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.p[0] > gs[sbg].p[0]) {
    sbg = gn
    continue o
  } else if (g.p[0] < gs[sbg].p[0]) {
    continue o
  }
  if (g.s > gs[sbg].s) {
    sbg = gn
    continue
  } else if (g.s < gs[sbg].s) {
    continue o
  }
  q: for (let i = 1; i < 10; i++) {
    if (g.p[i] > gs[sbg].p[i]) {
      sbg = gn
      continue o
    } else if (g.p[i] < gs[sbg].p[i]) {
      continue q
    }
  }
}

function sc (p) {
  switch (p) {
    case 0: return 25
    case 1: return 18
    case 2: return 15
    case 3: return 12
    case 4: return 10
    case 5: return 8
    case 6: return 6
    case 7: return 4
    case 8: return 2
    case 9: return 1
  }
}

print(fbg)
print(sbg)

function zeroArr (l) {
  let a = Array(l)
  for (let i = 0; i < l; i++) {
    a[i] = 0
  }
  return a
}

'use strict'

let lll

let GP = +readline()

const gs = {}

while (GP--) {
  let N = +readline()
  let pl = 0
  while (N--) {
    const g = readline()
    gs[g] = gs[g] || {s: 0, p: zeroArr(10)}
    gs[g].s += sc(pl)
    gs[g].p[pl]++
    pl++
  }
}

let fbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.s > gs[fbg].s) {
    fbg = gn
    continue o
  } else if (g.s < gs[fbg].s) {
    continue o
  }
  q: for (let i = 0; i < 10; i++) {
    if (g.p[i] > gs[fbg].p[i]) {
      fbg = gn
      continue o
    } else if (g.p[i] < gs[fbg].p[i]) {
      continue q
    }
  }
}

let sbg = Object.keys(gs)[0]
o: for (let gn in gs) {
  const g = gs[gn]
  if (g.p[0] > gs[sbg].p[0]) {
    sbg = gn
    continue o
  } else if (g.p[0] < gs[sbg].p[0]) {
    continue o
  }
  if (g.s > gs[sbg].s) {
    sbg = gn
    continue
  } else if (g.s < gs[sbg].s) {
    continue o
  }
  q: for (let i = 1; i < 10; i++) {
    if (g.p[i] > gs[sbg].p[i]) {
      sbg = gn
      continue o
    } else if (g.p[i] < gs[sbg].p[i]) {
      continue q
    }
  }
}

function sc (p) {
  switch (p) {
    case 0: return 25
    case 1: return 18
    case 2: return 15
    case 3: return 12
    case 4: return 10
    case 5: return 8
    case 6: return 6
    case 7: return 4
    case 8: return 2
    case 9: return 1
    default: return 0
  }
}

print(fbg)
print(sbg)

function zeroArr (l) {
  let a = Array(l)
  for (let i = 0; i < l; i++) {
    a[i] = 0
  }
  return a
}


You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:  Write parity(a) to the end of a. For example, .  Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.

The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.

Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.

NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110

var input = readline();
var input2 = readline();
var k1 = 0, k2 = 0;
for (var i = 0; i < input.length; i++) if (input[i] == '1') k1++;
for (var i = 0; i < input2.length; i++) if (input2[i] == '1') k2++;
if (k1 % 2 === 0 && k2 > k1) write('NO');
else if (k1 % 2 === 1 && k2 > k1 + 1) write('NO');
else write('YES');

var input = readline();
var input2 = readline();
var k1 = 0, k2 = 0;
for (var i = 0; i < input.length; i++) if (input[i] == '1') k1++;
for (var i = 0; i < input2.length; i++) if (input2[i] == '1') k2++;
if (k1 % 2 ==- 0 && k2 > k1) write('NO');
else if (k1 %2 ==- 1 && k2 > k1 + 1) write('NO');
else write('YES');


There are $$$n$$$ pillars aligned in a row and numbered from $$$1$$$ to $$$n$$$.Initially each pillar contains exactly one disk. The $$$i$$$-th pillar contains a disk having radius $$$a_i$$$.You can move these disks from one pillar to another. You can take a disk from pillar $$$i$$$ and place it on top of pillar $$$j$$$ if all these conditions are met:  there is no other pillar between pillars $$$i$$$ and $$$j$$$. Formally, it means that $$$|i - j| = 1$$$;  pillar $$$i$$$ contains exactly one disk;  either pillar $$$j$$$ contains no disks, or the topmost disk on pillar $$$j$$$ has radius strictly greater than the radius of the disk you move. When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all $$$n$$$ disks on the same pillar simultaneously?

The first line contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of pillars. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_i$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the radius of the disk initially placed on the $$$i$$$-th pillar. All numbers $$$a_i$$$ are distinct.

Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

NoteIn the first case it is possible to place all disks on pillar $$$3$$$ using the following sequence of actions:  take the disk with radius $$$3$$$ from pillar $$$2$$$ and place it on top of pillar $$$3$$$;  take the disk with radius $$$1$$$ from pillar $$$1$$$ and place it on top of pillar $$$2$$$;  take the disk with radius $$$2$$$ from pillar $$$4$$$ and place it on top of pillar $$$3$$$;  take the disk with radius $$$1$$$ from pillar $$$2$$$ and place it on top of pillar $$$3$$$.

n=+readline()
a=readline().split(' ').map(function(x){return +x-1})
b=new Array(n)
for (i=0;i<n;i++)
    b[a[i]]=i

l=b[n-1]
r=b[n-1]
for (i=n-2;i>=0;i--)
{
    if (b[i]+1==l)
        --l;
    else if (b[i]-1==r)
        ++r
    else
        break
}
if (r-l==n-1)
    print("yeS")
else
    print("NO")

const readLines = () => {
	try {
		return require("fs").readFileSync("input.txt", "utf8").split(/[\r\n]+/);
	} catch(e) {}
	const lines = [];
	for(var line; undefined !== (line = readline()); )
		lines.push(line);
	return lines;
};
const output = (text) => {
	try {
		console.log(text);
	} catch(e) {}
	try {
		text.toString().split(/[\r\n]+/).map(s => print(s));
	} catch(e) {}
};

var a = readLines();
var count = +a.shift();
var radiusArray = a.shift().split(" ").map(Number);

var max = radiusArray[0], iMax = 0;
for(var i = 0; i < count; i++)
	if ( max < radiusArray[i] ) {
		max = radiusArray[i];
		iMax = i;
	}

function check(ra, iMax) {
	var iLeft = iMax - 1;
	var iRight = iMax + 1;
	var max = ra[iMax];
	while(1) {
		var l = iLeft >= 0 ? ra[iLeft] : -1;
		var r = iRight < ra.length ? ra[iRight] : -1;
		if ( l === -1 && r === -1 ) return true;
		lrMax = Math.max(l, r);
		if ( max <= lrMax ) return false;
		max = lrMax;

		if ( l > r ) {
			iLeft--;
		} else {
			iRight++;
		}
	}
}

output( check(radiusArray, iMax) ? "YES" : "NO" );

var n = +readline()
  , as = readline().split(' ')

for ( var i in as ) as[i] = +as[i]
var topI = as.indexOf(n--)
  , upI = topI + 1
  , downI = topI - 1

while ( n ) {
  if ( downI >= 0 && as[downI] == n ) {
    downI--
    n--
  } else if ( upI < as.length && as[upI] == n ) {
    upI++
    n--
  } else break;
}

if ( !n ) print('YES')
else print('NO')

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

var main = function() {
    var n = +rd();
    var A = rdAr();
    var max = Math.max(...A);
    A = [-Infinity].concat(A.concat([-Infinity]));
    var ind = A.indexOf(max);
    var top = max;
    for (var L = ind - 1, R = ind + 1; top !== -Infinity;) {
        var LVAL = A[L];
        var RVAL = A[R];
        var pos;
        if (LVAL > RVAL) {
            pos = L;
            --L;
        } else {
            pos = R;
            ++R;
        }
        var plate = A[pos];
        if (plate > top) {
            wr('NO'); return;
        }
        top = plate;
    }
    wr('YES');
};

if (INPUT) {
INPUT = INPUT.split('\n').reverse();
readline = () => INPUT.pop();
write = (s) => {OUTPUT += s};
print = (s) => {OUTPUT += s + '\n'};
}
const rd = readline;
const wr = write;
const pr = print;
const rdAr = () => rd().split(' ').map(v => +v);
const prAr = (a) => pr(a.join(' '));
const cmpLt = (a, b) => a - b;
const cmpGt = (a, b) => b - a;
Array.prototype.sortLt = function() { return this.sort(cmpLt); };
Array.prototype.sortGt = function() { return this.sort(cmpGt); };
const crAr = function(length, ...fillArgs) { return new Array(length).fill(...fillArgs); };
const getPrimes = function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(var i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};

try {main();}finally{return OUTPUT;}
})();

var n = +readline()
  , as = readline().split(' ')
  , topI = as.indexOf(n--)

for ( var i in as ) as[i] = +as[i]

while ( n ) {
  var nextI = as.indexOf(n--)
  if ( Math.abs(nextI - topI) != 1) break;
  as.splice(nextI, 1)
  if ( nextI < topI ) topI--
}

if ( !n ) print('YES')
else print('NO')