Qpwoeirut has taken up architecture and ambitiously decided to remodel his city.Qpwoeirut's city can be described as a row of $$$n$$$ buildings, the $$$i$$$-th ($$$1 \le i \le n$$$) of which is $$$h_i$$$ floors high. You can assume that the height of every floor in this problem is equal. Therefore, building $$$i$$$ is taller than the building $$$j$$$ if and only if the number of floors $$$h_i$$$ in building $$$i$$$ is larger than the number of floors $$$h_j$$$ in building $$$j$$$.Building $$$i$$$ is cool if it is taller than both building $$$i-1$$$ and building $$$i+1$$$ (and both of them exist). Note that neither the $$$1$$$-st nor the $$$n$$$-th building can be cool.To remodel the city, Qpwoeirut needs to maximize the number of cool buildings. To do this, Qpwoeirut can build additional floors on top of any of the buildings to make them taller. Note that he cannot remove already existing floors.Since building new floors is expensive, Qpwoeirut wants to minimize the number of floors he builds. Find the minimum number of floors Qpwoeirut needs to build in order to maximize the number of cool buildings.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$3 \le n \le 10^5$$$) — the number of buildings in Qpwoeirut's city. The second line of each test case contains $$$n$$$ integers $$$h_1, h_2, \ldots, h_n$$$ ($$$1 \le h_i \le 10^9$$$) — the number of floors in each of the buildings of the city. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer — the minimum number of additional floors Qpwoeirut needs to build in order to maximize the number of cool buildings.

NoteIn the first test case, it is optimal for Qpwoeirut to make the second building cool by building $$$2$$$ additional floors on top of it, making it taller than both of its adjacent buildings. The final heights of buildings will be $$$[2, \underline{3}, 2]$$$.  In the second test case, the number of cool buildings is already maximized, so Qpwoeirut does not need to do anything.In the third test case, it is optimal for Qpwoeirut to make the third and fifth buildings cool by building $$$2$$$ additional floors onto the third building and $$$1$$$ additional floor onto the fifth building. The final heights of buildings will be $$$[3, 1, \underline{6}, 5, \underline{6}, 2]$$$.  It can be shown that it is impossible to make more than $$$2$$$ of the buildings cool, or to make $$$2$$$ buildings cool using fewer than $$$3$$$ additional floors.In the fourth test case, Qpwoeirut can either make the second building cool, or he can make the third building cool. Either way, he will be building $$$3$$$ additional floors and maximizing the number of cool buildings. The final heights of buildings will be $$$[4, 2, \underline{4}, 3, 5, 3, 6, 1]$$$ or $$$[4, \underline{5}, 1, 3, 5, 3, 6, 1]$$$.

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

function main() {
    const t = parseInt(readLine(), 10);
    for(let i = 0; i < t; i++){
        const n = +readLine();
        const arr = readLine().split(' ').map(p => +p);
        const resp = myFunc(n, arr);
        console.log(resp);
    }
}

function myFunc(n, arr){

    let first;
    let aux;
    let map = [];

    function calculate(arr){
        let resp = 0;
        for(let i = 1; i < n-1; i+=2){
            aux = Math.max(arr[i-1], arr[i+1]);
            if(aux < arr[i]){
                map[i] = 0;
                continue;
            }
            map[i] = aux - arr[i] + 1;
            resp += aux - arr[i] + 1;
        }
        return resp;
    }

    function consult(pos){
        if(map[pos] != undefined) return map[pos];
        aux = Math.max(arr[pos-1], arr[pos+1]);
        if(aux < arr[pos]){
            map[pos] = 0;
            return 0;
        }
        map[pos] = aux - arr[pos] + 1;
        return map[pos];
    }

    first = calculate(arr);

    if(arr.length%2 == 1){
        return first;
    }

    let min = first;
    let atual = first;
    let old_val, new_val;
    for(let i = n-3; i >= 1; i-=2){
        old_val = consult(i);
        new_val = consult(i+1);
        atual = atual - old_val + new_val;
        if(atual < min) min = atual;
    }
    return min;

}

function go(h)
{
    let n = h.length;
    if (n % 2 == 1)
    {
        let s = 0;
        for (let i = 1; i < n; i += 2)
        {
            s += Math.max(h[i], h[i+1] + 1, h[i - 1] + 1) - h[i]
        }
        return s;
    }
    else
    {
        let oddpS = [0];
        for (let i = 1; i < n - 1; i += 2)
        {
            oddpS.push(Math.max(h[i], h[i+1] + 1, h[i - 1] + 1) - h[i] + oddpS[oddpS.length - 1])
        }
        let evenpS = [0]
        for (let i = n-2; i>0; i -= 2)
        {
            evenpS.push(Math.max(h[i], h[i+1] + 1, h[i - 1] + 1) - h[i] + evenpS[evenpS.length - 1])
        }
        let min = oddpS[0] + evenpS[evenpS.length - 1];
        for (let i = 1; i < oddpS.length; i ++)
        {
            let test = oddpS[i] + evenpS[evenpS.length - i - 1];
            if (test < min)
            {
                min = test;
            }
        }
        return min;
    }
}

let input = '';
process.stdin.on('data', c => input += c)
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = input.split(EOL); /*your input text, split by lines*/
    let cases = parseInt(lines[0])
    for (let caseNum = 0; caseNum < cases; caseNum ++)
    {
        let h = lines[caseNum * 2 + 2].split(" ").map(x => parseInt(x))
        console.log(go(h))
    }
})

'use strict';

function solve(n, a) {
  if (n & 1) {
    let sum = 0;
    for (let i = 1; i < n; i += 2) {
      const num = Math.max(a[i - 1], a[i + 1]);
      if (a[i] <= num) sum += num - a[i] + 1;
    }
    return sum;
  }
  const l = new Array(n).fill(0),
        r = new Array(n).fill(0);
  for (let i = 1; i < n; i += 2) {
    var _l, _l2;
    const num = Math.max(a[i - 1], a[i + 1]);
    if (a[i] <= num) l[i] = ((_l = l[i - 2]) !== null && _l !== void 0 ? _l : 0) + num - a[i] + 1;else l[i] = (_l2 = l[i - 2]) !== null && _l2 !== void 0 ? _l2 : 0;
  }
  for (let i = n - 2; i >= 0; i -= 2) {
    var _r, _r2;
    const num = Math.max(a[i - 1], a[i + 1]);
    if (a[i] <= num) r[i] = ((_r = r[i + 2]) !== null && _r !== void 0 ? _r : 0) + num - a[i] + 1;else r[i] = (_r2 = r[i + 2]) !== null && _r2 !== void 0 ? _r2 : 0;
  }
  let res = Infinity;
  for (let i = 1; i < n; i += 2) {
    var _l3, _r3;
    res = Math.min(res, ((_l3 = l[i - 2]) !== null && _l3 !== void 0 ? _l3 : 0) + ((_r3 = r[i + 1]) !== null && _r3 !== void 0 ? _r3 : 0));
  }
  return res;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

var n = 0;
    var seq = [];
    function calc(i) {
        return Math.max(Math.max(0, seq[i-1] + 1 - seq[i], seq[i+1] + 1 - seq[i]));;
    }

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        n = parseInt(readline());
        seq = readline().split(' ').map(x=>parseInt(x));
        var ans = 0;
        if (n & 1) {
            for (var i = 1; i < n-1;i += 2) {
                ans += calc(i);
            }
        } else {
            var adds = [];
            for (var i = 1; i < n-1; i++) {
                adds.push(calc(i));
            }
            var runningSum = 0;
            for (var i = 0; i < adds.length; i+=2) {
                runningSum += adds[i];
            }
            ans = runningSum;
            for (var i = adds.length-1; i > 0; i-=2) {
                runningSum = runningSum - adds[i-1] + adds[i];
                ans = Math.min(ans, runningSum);
            }
        }
        print(ans);
    }


You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.Today you need to check a copy of a dialog between a client and a technical support manager. According to the rules of work, each message of the client must be followed by one or several messages, which are the answer of a support manager. However, sometimes clients ask questions so quickly that some of the manager's answers to old questions appear after the client has asked some new questions.Due to the privacy policy, the full text of messages is not available to you, only the order of messages is visible, as well as the type of each message: a customer question or a response from the technical support manager. It is guaranteed that the dialog begins with the question of the client.You have to determine, if this dialog may correspond to the rules of work described above, or the rules are certainly breached.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the total number of messages in the dialog. The second line of each test case consists of $$$n$$$ characters "Q" and "A", describing types of messages in the dialog in chronological order. Character "Q" denotes the message with client question, and character "A" — the message with technical support manager answer. It is guaranteed that the first character in the line equals to "Q".

For each test case print "Yes" (without quotes) if dialog may correspond to the rules of work, or "No" (without quotes) otherwise.

NoteIn the first test case the two questions from the client are followed with two specialist's answers. So this dialog may correspond to the rules of work.In the second test case one of the first two questions was not answered.In the third test case the technical support manager sent two messaged as the answer to the only message of the client.

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		let flag = l.substring(0,1) === 'Q' && l.substring(l.length-1) === 'A';
		let lag = 0;
		l.trim().split('').forEach(e => {
			if (e === "Q"){
				lag--;
			} else {
				if (lag < 0) {
					lag++;
				}
			}

		});
		ans.push(flag && lag === 0);
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let s=line[2*_];
        // console.log(n,s);
        let c1=0,c2=0;
        flag=true;
        for(let i=n-1;i>=0;i--)
        {
            if(s[i]==='Q') c1++;
            else c2++;
            if(c1>c2) flag=false;
        }
        if(flag) console.log("Yes");
        else console.log("No");
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let s=line[2*_];
        // console.log(n,s);
        let c1=0,c2=0;
        flag=true;
        for(let i=n-1;i>=0;i--)
        {
            if(s[i]==='Q') c1++;
            else c2++;
            if(c1>c2) flag=false;
        }
        if(c1>c2) flag=false;
        if(s[n-1]==='Q') flag=false;
        if(flag) console.log("Yes");
        else console.log("No");
    }
})

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0 && index % 2 == 0) {
        solve(line)
    }

    // console.log('index', index)
    index++;
});

function solve(str) {
    let n = 0;

    for(let i = 0; i < str.length ; i++) {
        if(str[i] == "Q") {
            n++;
        } else {
            n--;
            if(n < 0) {
                n = 0
            }
        }
    }

    if(n === 0) {
        console.log('Yes');
    } else {
        console.log('No')
    }
}

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0 && index % 2 == 0) {
        solve(line)
    }

    index++;
});

function solve(str) {
    const queue = [];

    for(let i = 0; i < str.length ; i++) {
        if(str[i] == "Q") {
            queue.push("Q");
        } else {
            queue.pop()
        }
    }

    if(queue.length === 0) {
        console.log('Yes');
    } else {
        console.log('No')
    }
}

let index = 0;

require('readline').createInterface({
    input: process.stdin
}).on('line', (line) => {
    if(index > 0 && index % 2 == 0) {
        solve(line)
    }

    index++;
});

function solve(str) {
    const queue = [];
    let isSolvable = true;

    for(let i = 0; isSolvable && i < str.length ; i++) {
        if(str[i] == "Q") {
            queue.push("Q");
        } else {
            const front = queue.pop()
        }
    }

    if(isSolvable && queue.length === 0) {
        console.log('Yes');
    } else {
        console.log('No')
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function evaluateBoard(board)
{

}

function main() {

    let t = parseInt(readLine());

    while(t--)
    {
        const n = parseInt(readLine());

        let qas = readLine().split("");
        qas.pop()
        //console.log(qas)
        let count=0

        for (let i=0;i<n;i++)
        {
            if(qas[i]=="Q")
            {
                count++;
            }
            else
            {
                count--;
            }
            if(count<0)
                count=0;
        }
        if(count>0)
            console.log("No")
        else
            console.log("Yes")

    }
}

"use strict";
/*
5
4
QQAA
4
QQAQ
3
QAA
1
Q
14
QAQQAQAAQQQAAA

Yes
No
Yes
No
Yes

*/
exports.__esModule = true;
var readline_1 = require("readline");
function countChar(s, char) {
	var count = 0;
	for (var _i = 0, s_1 = s; _i < s_1.length; _i++) {
		var i = s_1[_i];
		if (i === char) {
			count++;
		}
	}
	return count;
}
function processTheSequence(lines) {
	var testCases = Number(lines[0]) * 2;
	var sequenceLen;
	var sequence;
	// let nOfQ: number;
	// let nOfA: number;
	for (var i = 1; i < testCases; i++) {
		var pendingQuestions = 0;
		sequenceLen = Number(lines[i]);
		sequence = lines[++i];
		// nOfA = countChar(sequence, "A");
		// nOfQ = countChar(sequence, "Q");
		// console.log(nOfA);
		// console.log(nOfQ);
		for (var _i = 0, sequence_1 = sequence; _i < sequence_1.length; _i++) {
			var j = sequence_1[_i];
			// console.log(j);
			if (j === "Q") {
				pendingQuestions += 1;
			} else if (j === "A" && pendingQuestions > 0) {
				pendingQuestions -= 1;
			}
		}
		// console.log(pendingQuestions);
		if (pendingQuestions === 0) {
			console.log("Yes");
		} else {
			console.log("No");
		}
	}
}
var rl = readline_1.createInterface(process.stdin, process.stdout);
var input = [];
rl.on("line", function (line) {
	return input.push(line);
}).on("close", function () {
	return processTheSequence(input);
});

const readline = require('readline')

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

function solve(n, str) {
    let cq = 0
    for (let i = 0; i < str.length; i++) {
        if (str[i] === 'Q') {
            cq++
        } else {
            if (cq > 0) cq--
        }
    }
    return cq === 0 ? 'Yes' : 'No'
}

let ryan = '';//.map(saer).sort(function(a, a){return a - a})
process.stdin.on('data', c => ryan += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = ryan.split(EOL);
    var n = lines[0], e = 0
    for(i = 1; i <= n * 2; i++){
        if(i % 2 == 1){
            e = lines[i]
        }else{
            var a = lines[i].split(''), s = 0
            for(j = 0; j < e; j++){
                if(a[j] == 'Q'){
                    s++
                }else{
                    s = Math.max(0, s - 1)
                }
            }
            console.log(s === 0 ? 'YES' : 'NO')
        }
    }
});

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        s = read();
  let l = 0,
      r = 0;
  for (let i = 0; i <= n; i++) {
    if ((i === n || s[i] === 'Q') && s[i - 1] === 'A') {
      if (r > l) {
        r = 0, l = 0;
      }
    }
    if (i < n) {
      if (s[i] === 'Q') l++;else r++;
    }
  }
  if (r !== l) return 'No';
  return 'Yes';
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

var chats = readline();

for (var i = 0; i < chats; i++) {
  computarChat();
}

function computarChat() {
  var numerodemensagens = Number(readline());
  var mensagems = readline().split("");

  var questoesAResponder = 0;

  for (var i = 0; i < numerodemensagens; i++) {
    var mensagem = mensagems[i];
    if (mensagem === "Q") {
      questoesAResponder += 1;
    }
    if (mensagem === "A" && questoesAResponder > 0) {
      questoesAResponder -= 1;
    }
  }

  // var questoesAResponder = mensagems.filter(function (mensagem) {
  //   return mensagem === "Q";
  // });
  // var respostas = mensagems.filter(function (mensagem) {
  //   return mensagem === "A";
  // });

  // var terminoucomanswer = mensagems[mensagems.length - 1] === "A";

  // // print(terminoucomanswer);

  if (!questoesAResponder) {
    print("Yes");
  } else {
    print("No");
  }
}

const x = readline(); // first line

for(var i = 0 ; i < x ; i++) {
  var length = readline(); // skip line
  var inp = readline().toLowerCase();

  var func = str => {
    if (str.includes('qa')) {
      str = str.replace('qa', '');
      return func(str);
    } else {
      return str.includes('q') ? 'No' : 'Yes';
    }
  };

  print(func(inp));
}

var groups = parseInt(readline(), 10)
for(var i = 0; i < groups; i++) {
    var len = parseInt(readline(), 10)
    var dialog = readline().split("")
    var q = 0;
    for (var j = 0; j < len; j++) {
        if (dialog[j] === "Q") q = q + 1
        if (dialog[j] === "A" && q > 0) q = q - 1
    }
    var res = q === 0 ? "Yes" : "No"
    print(res)
}

var t = readline();
for (var i = 0; i < t; ++i) {
  var n = readline(),
    counter = 0,
    input = readline().split("");
    for(var j = 0 ; j < n ; ++j){
    if(input[j] == 'Q' && counter >= 0){
        counter++;
    }
    else if(input[j] == 'Q' && counter < 0){
        counter = 1;
    }
    else{
        counter--;
    }
  }
  counter <= 0 ? print("YES") : print("NO");
}

function process(str) {
    var stack = [];

    for (var i = 0; i < str.length; i++) {
        var char = str[i];
        if (char === 'Q') {
            stack.push(char);
        } else {
            stack.pop();
        }
    }

    print(stack.length === 0 ? 'Yes': 'No');
}

var numOfCases = Number(readline());
for (var test = 0; test < numOfCases; test++) {
    var numOfChars = Number(readline());
    var str = readline();

    process(str);
}

var n = +readline();
for(var i = 0; i < n; i++) {
  var k = +readline();
  var str = readline();
  var count = 0;
  for(var j = 0; j < k; j++) {
    if(str[j] === 'Q') {
      count++;
    }
    if(str[j] === 'A' && count) {
      count--;
    }
  }
  print(count !== 0 ? 'No' : 'Yes');
}

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		let flag = l.substring(0,1) === 'Q' && l.substring(l.length-1) === 'A';
		let lag = 0;
		l.trim().split('').forEach(e => {
			lag += (e === "Q"?-1:1);
			if (lag > 0) flag = false;

		});
		ans.push(flag);
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		let flag = l.substring(0,1) === 'Q' && l.substring(l.length-1) === 'A';
		let lag = 0;
		l.trim().split('').forEach(e => {
			lag += (e === "Q"?-1:1);
			if (lag > 0) lag = false;

		});
		ans.push(flag);
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		let flag = 0;
		l.trim().split('').forEach(e => flag += (e === "Q"?-1:1));
		ans.push(flag >= 0  && l.substring(0,1) !== l.substring(l.length-1));
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		let flag = 0;
		l.trim().split('').forEach(e => flag += (e === "Q"?-1:1));
		console.log(flag);
		ans.push(flag >= 0  && l.substring(0,1) !== l.substring(l.length-1));
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		let flag = 0;
		l.split('').forEach(e => flag += (e === "Q"?-1:1));
		ans.push(flag >= 0  && l.substring(0,1) !== l.substring(l.length-1));
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

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

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let l = nl.line();
		ans.push(l.substring(0,1) !== l.substring(l.length-1));
	}
	console.log(ans.map(x => x?"Yes":"No").join('\n'));
};

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

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let s=line[2*_];
        // console.log(n,s);
        let c1=0,c2=0;
        flag=true;
        // for(let i=0;i<n;i++)
        // {
        //     if(s[i]==='Q') c1++;
        //     else c2++;
        //     if(c1<c2) flag=false;
        // }
        if(c1>c2) flag=false;
        if(s[n-1]==='Q') flag=false;
        if(flag) console.log("Yes");
        else console.log("No");
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let s=line[2*_];
        // console.log(n,s);
        let c1=0,c2=0;
        flag=true;
        for(let i=0;i<n;i++)
        {
            if(s[i]==='Q') c1++;
            else c2++;
            // if(c1>c2) flag=false;
        }
        // if(c1>c2) flag=false;
        if(s[n-1]==='Q') flag=false;
        if(flag) console.log("Yes");
        else console.log("No");
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[2*_-1]);
        let s=line[2*_];
        // console.log(n,s);
        let c1=0,c2=0;
        flag=true;
        for(let i=0;i<n;i++)
        {
            if(s[i]==='Q') c1++;
            else c2++;
            // if(c1>c2) flag=false;
        }
        if(c1>c2) flag=false;
        if(flag) console.log("Yes");
        else console.log("No");
    }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function evaluateBoard(board)
{

}

function main() {

    let t = parseInt(readLine());

    while(t--)
    {
        const n = parseInt(readLine());

        let qas = readLine().split("");
        qas.pop()
        //console.log(qas)
        let count=0

        for (let i=0;i<n;i++)
        {
            if(qas[i]=="Q")
                count++;
            else
                count--;
        }
        if(qas[qas.length-1]=="Q")
        {
            console.log("No")
            continue;
        }
        if(count>0)
            console.log("No")
        else
            console.log("Yes")

    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function evaluateBoard(board)
{

}

function main() {

    let t = parseInt(readLine());

    while(t--)
    {
        const n = parseInt(readLine());

        let qas = readLine().split("");
        qas.pop()
        //console.log(qas)
        let count=0

        for (let i=0;i<n;i++)
        {
            if(qas[i]=="Q")
                count++;
            else
                count--;
        }
        if(count>0)
            console.log("No")
        else
            console.log("Yes")

    }
}

"use strict";
/*
5
4
QQAA
4
QQAQ
3
QAA
1
Q
14
QAQQAQAAQQQAAA

Yes
No
Yes
No
Yes

*/
exports.__esModule = true;
var readline_1 = require("readline");
function countChar(s, char) {
	var count = 0;
	for (var _i = 0, s_1 = s; _i < s_1.length; _i++) {
		var i = s_1[_i];
		if (i === char) {
			count++;
		}
	}
	return count;
}
function processTheSequence(lines) {
	var testCases = Number(lines[0]) * 2;
	var sequenceLen;
	var sequence;
	var nOfQ;
	var nOfA;
	for (var i = 1; i < testCases; i++) {
		sequenceLen = Number(lines[i]);
		sequence = lines[++i];
		nOfA = countChar(sequence, "A");
		nOfQ = countChar(sequence, "Q");
		// console.log(nOfA);
		// console.log(nOfQ);
		if (nOfA === nOfQ || nOfA > nOfQ) {
			console.log("Yes");
		} else {
			console.log("No");
		}
	}
}
var rl = readline_1.createInterface(process.stdin, process.stdout);
var input = [];
rl.on("line", function (line) {
	return input.push(line);
}).on("close", function () {
	return processTheSequence(input);
});

const readline = require('readline')

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

function solve(n, str) {
    let cq = 0, ca = 0
    for (let i = 0; i < str.length; i++) {
        if (str[i] === 'Q') {
            cq++
        } else {
            ca++
        }
    }
    return ca >= cq ? 'Yes' : 'No'
}

var chats = readline();

for (var i = 0; i < chats; i++) {
  computarChat();
}

function computarChat() {
  var numerodemensagens = Number(readline());
  var mensagems = readline().split("");

  var questoesAResponder = mensagems.filter(function (mensagem) {
    return mensagem === "Q";
  });
  var respostas = mensagems.filter(function (mensagem) {
    return mensagem === "A";
  });

  var terminoucomanswer = mensagems[mensagems.length - 1] === "A";

  // print(terminoucomanswer);

  if (respostas.length >= questoesAResponder.length && terminoucomanswer) {
    print("Yes");
  } else {
    print("No");
  }
}

const x = readline(); // first line

for(var i = 0 ; i < x ; i++) {
  readline(); // skip line
  var inp = readline().toLowerCase().split('');
  var func = arr => {
    if (inp[0] == 'a') return 'No';
    var halfLength = Math.floor(arr.length/2);
    var questions = arr.filter(l => l == 'q');
    return questions.length <= halfLength ? 'Yes' : 'No'
  }

  print(func(inp));
}

const x = readline(); // first line

for(var i = 0 ; i < x ; i++) {
  readline(); // skip line
  var inp = readline().toLowerCase().split('');
  var func = arr => {
    var initLength = arr.length;
    var questions = arr.filter(l => l == 'q');
    return questions.length <= Math.floor(initLength/2) ? 'Yes' : 'No'
  }
  print(func(inp));
}

var groups = parseInt(readline(), 10)
for(var i = 0; i < groups; i++) {
    var length_dialog = readline()
    var dialog = readline().split("")
    if (dialog[0] !== "Q"|| dialog[dialog.length - 1] !== "A") {
        print("NO")
        continue
    }
    var a = dialog.filter(d => d === "A").length
    var q = dialog.filter(d => d === "Q").length
    var res = a >= q ? "YES" : "NO"
    print(res)
}

var groups = parseInt(readline(), 10)
for(var i = 0; i < groups; i++) {
    var length_dialog = readline()
    var dialog = readline().split("")
    if (dialog[0] !== "Q") {
        print("NO")
        continue
    }
    var a = dialog.filter(d => d === "A").length
    var q = dialog.filter(d => d === "Q").length
    var res = a >= q ? "YES" : "NO"
    print(res)
}

var groups = readline()
for(var i = 0; i < groups; i++) {
    var len = readline()
    var dialog = readline().split("")
    var a_number = dialog.filter(d => d === "A").length
    var q_number = dialog.filter(d => d === "Q").length
    var res = a_number >= q_number ? "YES" : "NO"
    print(res)
}

var t = readline();
for (var i = 0; i < t; ++i) {
  var n = readline(),
    qCounter = 0,
    aCounter = 0,
    input = readline().split("");
  if (input[input.length - 1] == "Q") {
    print("NO");
  } else {
    for (var j = 0; j < n; ++j) {
      input[j] == "Q" ? qCounter++ : aCounter++;
    }
    aCounter >= qCounter ? print("YES") : print("NO");
  }
}

var t = readline();
    for(var i = 0 ; i < t ; ++i){
        var n = readline(), qCounter = 0 , aCounter = 0,
            input = readline().split('');
            for(var j = 0 ; j < n ; ++j){
                input[j] == 'Q' ? qCounter++ : aCounter++;
    }
            aCounter >= qCounter ? print("YES") : print("NO");
}

var numOfChars = Number(readline());
var str = readline();

var stack = [];

for (var i = 0; i < str.length; i++) {
    var char = str[i];
    if (char === 'Q') {
        stack.push(char);
    } else {
        stack.pop();
    }
}

print(stack.length === 0 ? 'Yes': 'No');


You are given $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$. Is it possible to arrange them on a circle so that each number is strictly greater than both its neighbors or strictly smaller than both its neighbors?In other words, check if there exists a rearrangement $$$b_1, b_2, \ldots, b_n$$$ of the integers $$$a_1, a_2, \ldots, a_n$$$ such that for each $$$i$$$ from $$$1$$$ to $$$n$$$ at least one of the following conditions holds: $$$b_{i-1} < b_i > b_{i+1}$$$ $$$b_{i-1} > b_i < b_{i+1}$$$To make sense of the previous formulas for $$$i=1$$$ and $$$i=n$$$, one shall define $$$b_0=b_n$$$ and $$$b_{n+1}=b_1$$$.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 3\cdot 10^4$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 10^5$$$)  — the number of integers. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$). The sum of $$$n$$$ over all test cases doesn't exceed $$$2\cdot 10^5$$$.

For each test case, if it is not possible to arrange the numbers on the circle satisfying the conditions from the statement, output $$$\texttt{NO}$$$. You can output each letter in any case. Otherwise, output $$$\texttt{YES}$$$. In the second line, output $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$, which are a rearrangement of $$$a_1, a_2, \ldots, a_n$$$ and satisfy the conditions from the statement. If there are multiple valid ways to arrange the numbers, you can output any of them.

NoteIt can be shown that there are no valid arrangements for the first and the third test cases.In the second test case, the arrangement $$$[1, 8, 4, 9]$$$ works. In this arrangement, $$$1$$$ and $$$4$$$ are both smaller than their neighbors, and $$$8, 9$$$ are larger.In the fourth test case, the arrangement $$$[1, 11, 1, 111, 1, 1111]$$$ works. In this arrangement, the three elements equal to $$$1$$$ are smaller than their neighbors, while all other elements are larger than their neighbors.

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

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

/*---------------------------------------------------*/

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

const getDigits = (x) => {
    let digits = new Array(10).fill(false);
    let len = 0;
    while (x) {
        len++;
        digits[x % 10n] = true;
        x /= 10n;
    }
    return [digits, len];
}

const getLen = (x) => {
    let str = x.toString(10);
    return str.length;
}

const calc = (t)=>{
    /* read */
    let n = readline();
    let a = ra();

    a.sort((x, y) => x - y);

    let b = new Array(n);

    let j = 0;

    for (let i = 0; i < n; i += 2) {
        b[i] = a[j++];
    }

    for (let i = 1; i < n; i += 2) {
        b[i] = a[j++];
    }

    // console.log('DEBUG b', b);

    for (let i = 0; i < n; i++) {
        let next = (i + 1) % n;
        let prev = (n + i - 1) % n;

        let x = (b[prev] > b[i]) && (b[i] < b[next]);
        let y = (b[prev] < b[i]) && (b[i] > b[next]);

        if (!(x || y)) {
            // console.log(`DEBUG prev ${prev}, i ${i}, next ${next}`);
            return 'NO'
        }
        // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);
    }

    return 'YES\n' + b.join(' ');
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc(t));
        // process.stdout.write(`${calc(t)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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

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

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

function solve() {
	const n = nextInt();

	const arr = nextIntArray(n);

	if (n % 2 === 1) {
		myout("NO");
		return;
	}

	arr.sort((a, b) => a - b);
	let median;

	if (arr.length % 2 === 0) {
		median = (arr[arr.length / 2 - 1] + arr[arr.length / 2]) / 2;
	} else {
		median = arr[(arr.length - 1) / 2];
	}

	const mins = arr.slice(0, arr.length / 2 );
	const maxs = arr.slice(arr.length / 2 );

	const res = [];

	let j = 0, k = 0;

	for (let i = 0; i < arr.length; i++) {
		if (i % 2 === 0) {
			if (i >= 1 && res[i - 1] === mins[j]) {
				myout("NO");
				return;
			}
			res[i] = mins[j];
			j++;
		} else {
			if (i >= 1 && res[i - 1] === maxs[k]) {
				myout("NO");
				return;
			}
			res[i] = maxs[k];
			k++;
		}
	}

	myout("YES");
	myout(res.join(" "));
}

'use strict';

function solve(n, a) {
  if (n & 1) return 'NO';
  a.sort((a, b) => a - b);
  let res = [];
  for (let i = 0, j = n / 2; j < n; i++, j++) {
    res.push(a[i], a[j]);
  }
  for (let i = 0; i < n; i++) {
    let l = (i - 1 + n) % n,
        r = (i + 1) % n;
    if (res[i] > res[l] && res[i] > res[r] || res[i] < res[l] && res[i] < res[r]) continue;
    return 'NO';
  }
  return `YES\n${res.join(' ')}`;
}

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

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

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

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

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

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

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

// SOLUTION:
IS_MULTITEST = true;

const CALC = (testN)=>{
  // READING:
  let [n, m] = ra();
  let A = ra();
  LT({n, A});
  // PROCESSING:
  if (n%2==1)
    return 'NO'
  let ans = 0;
  A.sort((a, b)=>a-b);
  let arr = [];
  for (let i=0; i<n/2; i++){
    arr.push(A[i]);
    arr.push(A[i+n/2]);
  }
  for (let i=0; i<n; i+=2){
    if (arr[i]<arr[(i+n-1)%n] && arr[i]<arr[i+1])
      continue;
    return 'NO'
  }
  L({arr})
  return 'YES'+'\n'+arr.join(' ')
  let lower = A.slice(0, n/2);
  let higher = A.slice(n/2);
  L({A, lower, higher})
  return ans;
};

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            n = lines[i];
        }else{
            if(n % 2){
                console.log('NO');
                continue;
            }
            var b = Math.floor(n / 2);
            var flag = false;
            var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
            for(j = 1; j < b; j++){
                if(a[j] == a[j + b - 1]){
                    console.log('NO');
                    flag = true;
                    break;
                }
            }
            var ans = '';
            if(!flag){
                console.log('YES');
                for(j = 0; j < b; j++){
                    ans += a[j] + ' ' + a[j + b] + ' ';
                }
                console.log(ans);
            }
        }
    }
});

const solve  = (arr,n)=>{
     if(n%2){
          console.log("NO");
          return;
     }
     arr.sort((a,b)=>a-b);
     let res = [],i=0,j=0,k = Math.floor(n/2);
     while(i*2<n){
          res.push(arr[j]);
          if(k<n) res.push(arr[k]);
          j++;
          k++;
          i++;
     }
     let str = "";
     for(let i=0;i<n;i++){
          if(res[i]===res[(i+1)%n]){
               console.log("NO");
               return;
          }
          str+=res[i]+" ";
     }
     console.log("YES");
     console.log(str);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr,n);
  }
}
main();

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

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

/*---------------------------------------------------*/

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

const getDigits = (x) => {
    let digits = new Array(10).fill(false);
    let len = 0;
    while (x) {
        len++;
        digits[x % 10n] = true;
        x /= 10n;
    }
    return [digits, len];
}

const getLen = (x) => {
    let str = x.toString(10);
    return str.length;
}

const calc = (t)=>{
    /* read */
    let n = readline();
    let a = ra();

    a.sort();

    let b = new Array(n);

    let j = 0;

    for (let i = 0; i < n; i += 2) {
        b[i] = a[j++];
    }

    for (let i = 1; i < n; i += 2) {
        b[i] = a[j++];
    }

    // console.log('DEBUG b', b);

    for (let i = 0; i < n; i++) {
        let next = (i + 1) % n;
        let prev = (n + i - 1) % n;

        let x = (b[prev] > b[i]) && (b[i] < b[next]);
        let y = (b[prev] < b[i]) && (b[i] > b[next]);

        if (!(x || y)) {
            // console.log(`DEBUG prev ${prev}, i ${i}, next ${next}`);
            return 'NO'
        }
        // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);
    }

    return 'YES\n' + b.join(' ');
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc(t));
        // process.stdout.write(`${calc(t)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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

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

/*---------------------------------------------------*/

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

const getDigits = (x) => {
    let digits = new Array(10).fill(false);
    let len = 0;
    while (x) {
        len++;
        digits[x % 10n] = true;
        x /= 10n;
    }
    return [digits, len];
}

const getLen = (x) => {
    let str = x.toString(10);
    return str.length;
}

const calc = (t)=>{
    /* read */
    let n = readline();
    let a = ra();

    a.sort();

    let b = new Array(n);

    let j = 0;

    for (let i = 0; i < n; i += 2) {
        b[i] = a[j++];
    }

    for (let i = 1; i < n; i += 2) {
        b[i] = a[j++];
    }

    console.log('DEBUG b', b);

    for (let i = 0; i < n; i++) {
        let next = (i + 1) % n;
        let prev = (n + i - 1) % n;

        let x = (b[prev] > b[i]) && (b[i] < b[next]);
        let y = (b[prev] < b[i]) && (b[i] > b[next]);

        if (!(x || y)) {
            // console.log(`DEBUG prev ${prev}, i ${i}, next ${next}`);
            return 'NO'
        }
        // console.log(`DEBUG mx ${mx}, a[mx] ${a[mx]}, i `, i);
    }

    return 'YES\n' + b.join(' ');
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc(t));
        // process.stdout.write(`${calc(t)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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

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

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

function solve() {
	const n = nextInt();

	const arr = nextIntArray(n);

	if (n % 2 === 1) {
		myout("NO");
		return;
	}

	arr.sort((a, b) => a - b);
	let median;

	if (arr.length % 2 === 0) {
		median = (arr[arr.length / 2 - 1] + arr[arr.length / 2]) / 2;
	} else {
		median = arr[(arr.length - 1) / 2];
	}

	const mins = [];
	const maxs = [];

	for (let i = 0; i < arr.length; i++) {
		if (arr[i] < median) {
			mins.push(arr[i]);
		} else {
			maxs.push(arr[i]);
		}
	}

	if (Math.abs(maxs.length - mins.length) > 1) {
		myout("NO");
		return;
	}

	const res = [];

	let j = 0, k = 0;

	for (let i = 0; i < arr.length; i++) {
		if (i % 2 === 0) {
			res[i] = mins[j];
			j++;
		} else {
			res[i] = maxs[k];
			k++;
		}
	}

	myout("YES");
	myout(res.join(" "));
}

'use strict';

function solve(n, a) {
  a.sort((a, b) => a - b);
  let res = [];
  for (let i = 0, j = n - 1; i <= j; i++, j--) {
    if (i === j) {
      res.push(a[i]);
    } else res.push(a[i], a[j]);
  }
  for (let i = 0; i < n; i++) {
    let l = (i - 1 + n) % n,
        r = (i + 1) % n;
    if (res[i] > res[l] && res[i] > res[r] || res[i] < res[l] && res[i] < res[r]) continue;
    return 'NO';
  }
  return `YES\n${res.join(' ')}`;
}

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

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


Alica and Bob are playing a game.Initially they have a binary string $$$s$$$ consisting of only characters 0 and 1.Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string $$$s$$$ and delete them. For example, if $$$s = 1011001$$$ then the following moves are possible:   delete $$$s_1$$$ and $$$s_2$$$: $$$\textbf{10}11001 \rightarrow 11001$$$;  delete $$$s_2$$$ and $$$s_3$$$: $$$1\textbf{01}1001 \rightarrow 11001$$$;  delete $$$s_4$$$ and $$$s_5$$$: $$$101\textbf{10}01 \rightarrow 10101$$$;  delete $$$s_6$$$ and $$$s_7$$$: $$$10110\textbf{01} \rightarrow 10110$$$. If a player can't make any move, they lose. Both players play optimally. You have to determine if Alice can win.

First line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Only line of each test case contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), consisting of only characters 0 and 1.

For each test case print answer in the single line. If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.

NoteIn the first test case after Alice's move string $$$s$$$ become empty and Bob can not make any move.In the second test case Alice can not make any move initially.In the third test case after Alice's move string $$$s$$$ turn into $$$01$$$. Then, after Bob's move string $$$s$$$ become empty and Alice can not make any move.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let input = readLine();
    let countOne = 0;
    let countZero = 0;
    for (let i = 0; i < input.length; i++) {
      if (input[i] === "0") countOne++;
      else countZero++;
    }
    if (Math.abs(countOne - countZero) === input.length) console.log("NET");
    else {
      let num = Math.min(countZero, countOne);
      if (num % 2 === 1) console.log("DA");
      else console.log("NET");
    }
  }
}

//↓見なくていいよ！ここから--------------------------------------------------
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);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
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){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var s = nextCharArray();
		var zero = 0;
		var one = 0;
		for(var j = 0; j < s.length; j++){
			if(s[j] == "0"){
				zero++;
			}else{
				one++;
			}
		}
		myerr({zero,one});
		count = Math.min(zero, one);
		if(count % 2 == 0){
			output[i] = "NET";
		}else{
			output[i] = "DA";
		}
	}
	myout(myconv(output,9));
}

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

let stdinInput = '';

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

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

function main(data) {
  data = data.split('\n');
  const testCases = data[0] * 1;
  let i = 1;
  while (i <= testCases) {
    let s = data[i].trim().split('');
    let count = 1;
    for (let j = 0; j < s.length; j += 1) {
      if ((s[j] === '0' && s[j + 1] === '1') || (s[j] === '1' && s[j + 1] === '0')) {
        s.splice(j, 2);
        count += 1;
        j = -1;
      }
    }
    count % 2 === 0 ? console.log('DA') : console.log('NET');
    i += 1;
  }
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numDeleted = 0;
    let i = 1;
    while (i <= testCases) {
        var j = 0;
        numDeleted = 0
        let curString = data[i]
        while (j < curString.length - 1) {
            if ((curString.charAt(j) === "0" && curString.charAt(j + 1) === "1") ||
            (curString.charAt(j) === "1" && curString.charAt(j + 1) === "0")) {
                let tempString = ""
                if (j === 0) {
                    tempString = curString.substring(2)
                } else {
                    tempString = curString.substring(0, j)
                    if (j + 2 < curString.length) {
                        tempString += curString.substring(j + 2, curString.length)
                    }
                }
                curString = tempString
                j = Math.max(j - 1, 0)
                numDeleted++
            } else {
                j++
            }
        }
        i++
        console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? "DA" : "NET")
    }
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numDeleted = 0;
    let i = 1;
    while (i <= testCases) {
        let stack = []
        let numDeleted = 0
        let j = 0;
        let curString = data[i].split('')
        for(j = 0; j < curString.length; j++) {
            if ((curString[j] === '0' && stack[stack.length-1] === '1') ||
            (curString[j] === '1' && stack[stack.length-1]) === '0') {
                numDeleted++
                stack.pop()
            } else {
                stack.push(curString[j])
            }
        }
        i++
        console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? "DA" : "NET")
    }
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let i;
    for(i = 1; i <= testCases; i++) {
        solve(data[i])
    }
}

function solve(line) {
    var i;
    let num0 = 0
    let num1 = 0
    let lineSplit = line.split('')
    for(i = 0; i < line.length; i++) {
        if (lineSplit[i] == '0') {
            num0++
        } else {
            num1++
        }
    }

    console.log((Math.min(num0, num1) % 2 !== 0) ? "DA" : "NET")
}

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

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

  let count = 0;
  const arr = [...str];

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] !== arr[i - 1]) {
      arr.splice(i-1, 2);
      i = 0;
      count++;
    }
  }

  if (count % 2) {
    console.log('DA');
  }
  else {
    console.log('NET');
  }

  c++;
});

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

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

  let zeros = 0;
  let ones = 0;

  for (let i = 0; i < str.length; i++) {
    if (str[i] === '1') {
      ones++;
    }
    else {
      zeros++;
    }
  }

  let count = Math.min(zeros, ones);
  if (count % 2) {
    console.log('DA');
  }
  else {
    console.log('NET');
  }

  // let count = 0;
  // const arr = [...str];

  // for (let i = 1; i < arr.length; i++) {
  //   if (arr[i] !== arr[i - 1]) {
  //     arr.splice(i-1, 2);
  //     i = 0;
  //     count++;
  //   }
  // }

  // if (count % 2) {
  //   console.log('DA');
  // }
  // else {
  //   console.log('NET');
  // }

  c++;
});

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 => string.trim());

    main();
});

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

const s2i = s => parseInt(s, 10);

function main() {
  let T = s2i(readLine());
  let s, c0, c1, totalMoves;
  let out = '';
  while (T--) {
    s = readLine()
    c0 = 0
    c1 = 0
    for (let i = 0, l = s.length, c; i < l; i++) {
      c = s.charAt(i);
      if (c === '0') c0++;
      else c1++;
    }

    totalMoves = Math.min(c0, c1);

    // console.log(totalMoves % 2 === 0 ? 'NET' : 'DA');
    out += totalMoves % 2 === 0 ? 'NET\n' : 'DA\n'
  }
  console.log(out)
}

const readline = require('readline');

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

var lineCount = 0
var testCount = 0
var outputStr = ''

rl.on('line', (input) => {
    if (lineCount == 0) {
        // first line
        testCount = parseInt(input)
    }
    else if (lineCount >= testCount) {
        outputStr += getWinner(input) + '\n'
        console.log(outputStr)
        rl.close()
    }
    else {
        // data
        outputStr += getWinner(input) + '\n'
    }
    lineCount++
});

function getWinner(str) {
    var count0 = 0
    var count1 = 0
    for(var i=0;i<str.length;i++){
        if(parseInt(str[i])==0){
            count0++
        }
        else{
            count1++
        }
    }
    return Math.min(count0,count1)%2?'DA':'NET'

}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; t++) {
      var s = read();
      var c = {
         '0': 0,
         '1': 0
      };
      for (var i = 0; i < s.length; i++) {
         c[s[i]]++;
      }
      if (Math.min(c[0], c[1]) & 1) {
         write('da');
      } else {
         write('net');
      }
   }
}

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

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let i;
    for(i = 1; i <= testCases; i++) {
        solve(data[i])
    }
}

function solve(line) {
    var i;
    let num0 = 0
    let num1 = 1
    let lineSplit = line.split('')
    for(i = 0; i < line.length; i++) {
        if (lineSplit[i] == '0') {
            num0++
        } else {
            num1++
        }
    }

    console.log((Math.min(num0, num1) % 2 !== 0) ? "DA" : "NET")
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numDeleted = 0;
    let i = 1;
    while (i <= testCases) {
        var j = 0;
        numDeleted = 0
        let curString = data[i]
        while (j < curString.length - 1) {
            if ((curString.charAt(j) === "0" && curString.charAt(j + 1) === "1") ||
            (curString.charAt(j) === "1" && curString.charAt(j + 1) === "0")) {
                if (j === 0) {
                    curString = curString.substring(2)
                } else {
                    curString = curString.substring(0, j) + curString.substring(Math.min(j + 1, curString.length - 1), curString.length - 1)
                }
                j = Math.max(j - 1, 0)
                numDeleted++
            } else {
                j++
            }
        }
        i++
        console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? "DA" : "NET")
    }
}


You are given an array $$$a_1, a_2, \dots, a_n$$$ where all $$$a_i$$$ are integers and greater than $$$0$$$. In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$). If $$$gcd(a_i, a_j)$$$ is equal to the minimum element of the whole array $$$a$$$, you can swap $$$a_i$$$ and $$$a_j$$$. $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. Now you'd like to make $$$a$$$ non-decreasing using the operation any number of times (possibly zero). Determine if you can do this. An array $$$a$$$ is non-decreasing if and only if $$$a_1 \le a_2 \le \ldots \le a_n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.  The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of array $$$a$$$.  The second line of each test case contains $$$n$$$ positive integers $$$a_1, a_2, \ldots a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.  It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, output "YES" if it is possible to make the array $$$a$$$ non-decreasing using the described operation, or "NO" if it is impossible to do so.

Note In the first and third sample, the array is already non-decreasing. In the second sample, we can swap $$$a_1$$$ and $$$a_3$$$ first, and swap $$$a_1$$$ and $$$a_5$$$ second to make the array non-decreasing. In the forth sample, we cannot the array non-decreasing using the operation.

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

    const sorted = [...arr].sort((a, b) => a - b);
    const min = sorted[0];
    let possible = true;

    for (let i = 0; i < len; i++) {
      if (sorted[i] !== arr[i]) {
        if (arr[i] % min !== 0) {
          possible = false;
        }
      }
    }

    possible ? console.log("YES") : console.log("NO");
  }
}

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

let inputString = '';
let currentLine = 0;

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

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

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number).slice(0, n)
    const sorted = [...as].sort((a, b) => a - b)
    const minimum = sorted[0]
    let result = true
    for (let i = 0; i < n; i++) {
      if (as[i] !== sorted[i] && as[i] % minimum !== 0) {
        result = false
        break
      }
    }
    console.log(result ? 'YES' : 'NO')
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let t = $()
  while (t--) {
    let n = $(), a = $(n), m = a.min()[0], b = a.filter(v => v % m == 0).sort(asc);
    let j = 0;
    For(n, i => {
      if (a[i] % m == 0) a[i] = b[j++];
    })
    log(For(n - 1, i => a[i] > a[i + 1] ? 1 : null) ? 'NO' : 'YES')
  }
}

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

    probC();
});

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

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if(n < k)
            console.log(k-n);
        else{
            if((n+k) % 2 === 0){
                console.log(0);
            }else{
                console.log(n-k);
            }
        }
    }
}

function probB(){
    let t = pi(readline());

    while(t > 0){
        t--;
        let a = readline().split(' ');
        let b = readline().split(' ');

        a[0] = pi(a[0]);
        a[1] = pi(a[1]);
        a[2] = pi(a[2]);

        b[0] = pi(b[0]);
        b[1] = pi(b[1]);
        b[2] = pi(b[2]);

        let maxSum = 0;
        if(b[2] - (a[0] + a[2]) > 0){
            b[2] = b[2] - (a[0]+a[2]);
            a[0] = 0;
            a[2] = 0;
        }else if(b[2] - a[0] > 0){
            a[2] = a[2] - (b[2] - a[0]);
            b[2] = 0;
            a[0] = 0;
        }else{
            a[0] -= b[2];
            b[2] = 0;
        }

        if(a[2] > b[1])
            console.log((b[1] - b[2]) * 2)
        else
            console.log((a[2]-b[2]) * 2);

    }
}

function probC(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = readline().split(' ');
        let x = JSON.parse(JSON.stringify(a));

        x.sort((a,b) => pi(a) - pi(b));
        let res = true;
        for(let i = 0; i < n; i++){
            if(x[i] !== a[i]){
                if(pi(a[i]) % pi(x[0]) !== 0){
                    res = false;
                    break;
                }
            }
        }

        if(res)
            console.log('yes');
        else
            console.log('no');
    }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    str = readline();
    var a = str.split(" ");
    var b = str.split(" ");
    a = a.map(a => Number(a));
    b = b.map(a => Number(a));
    b.sort((a, b) => a - b);

    var min = b[0];
    var out = true;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) && (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    const sorted = [...as].sort((a, b) => a - b)
    const minimum = sorted[0]
    let result = true
    for (let i = 0; i < n; i++) {
      if (as[i] !== sorted[i] && as[i] % minimum !== 0) {
        result = false
        break
      }
    }
    console.log(result ? '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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    const sorted = [...as].sort((a, b) => a - b)
    const minimum = sorted[0]
    let result = true
    console.log(as, minimum, sorted)
    for (let i = 0; i < n; i++) {
      if (as[i] !== sorted[i] && as[i] % minimum !== 0) {
        result = false
        console.log('failed', i)
        break
      }
    }
    console.log(result ? '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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    const sorted = [...as].sort((a, b) => a - b)
    console.log(as.every((a, i) => a === sorted[i] || a % sorted[0] === 0) ? 'YES' : 'NO')
  }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    b = a.concat();
    b.sort((a, b) => {
        if(a > b){
            return 1;
        }
        else{
            return -1;
        }
    })
    var min = b[0];
    var out = true;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) && (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    str = readline();
    var a = str.split(" ");
    var b = str.split(" ");
    a = a.map(a => Number(a));
    b.sort((a, b) => {
        if(a > b){
            return 1;
        }
        else{
            return -1;
        }
    })
    var min = b[0];
    var out = true;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) && (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    a = a.map(a => Number(a));
    b = a.sort((a, b) => {
        if(a > b){
            return 1;
        }
        else{
            return 0;
        }
    })
    var temp;
    var min = b[0];
    var out;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) != (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO")
    }
}

function gcd(a, b){
    var temp;
    if (b > a){
        temp = a;
        a = b;
        b = temp;
    }

    var res = b;

    while(res > 1){
        if((a % res == 0) && (b % res == 0)){
            break;
        }
        res--;
    }

    if(res <= b){
        return res;
    }
    else{
        return false;
    }

}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    a = a.map(a => Number(a));
    var temp;
    var min = a[0];

    for (var j = 0; j < a.length; j++){
        if (a[j] < min){
            min = a[j];
        }
    }

    for (var j = 0; j < a.length; j++){
        for(var d = j+1; d < a.length; d++){
            if((gcd(a[j], a[d]) == min) && (a[j] > a[d])){
                temp = a[j];
                a[j] = a[d];
                a[d] = temp;
            }
        }
    }
    var out = true;
    for (var j = 0; j < a.length - 1; j++){
        if(a[j] > a[j+1]){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO")
    }
}

function gcd(a, b){
    var temp;
    if (b > a){
        temp = a;
        a = b;
        b = temp;
    }

    var res = 2;

    while(res <= b){
        if((a % res == 0) && (b % res == 0)){
            break;
        }
        res++;
    }

    if(res <= b){
        return res;
    }
    else{
        return false;
    }

}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    a = a.map(a => Number(a));
    var temp;
    var min = a[0];

    for (var j = 0; j < a.length; j++){
        if (a[j] < min){
            min = a[j];
        }
    }

    for (var j = 0; j < a.length; j++){
        for(var d = j+1; d < a.length; d++){
            if((gcd(a[j], a[d]) == min) && (a[j] > a[d])){
                temp = a[j];
                a[j] = a[d];
                a[d] = temp;
            }
        }
    }
    var out = true;
    for (var j = 0; j < a.length - 1; j++){
        if(a[j] > a[j+1]){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}


According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.You are given a jacket with n buttons. Determine if it is fastened in a right way.

The first line contains integer n (1 ≤ n ≤ 1000) — the number of buttons on the jacket. The second line contains n integers ai (0 ≤ ai ≤ 1). The number ai = 0 if the i-th button is not fastened. Otherwise ai = 1.

In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO".

var x = parseInt(readline());
var n = readline().split(" ").map(function(x){return parseInt(x);}).filter(function(x){return x==0;});

print((x==1&&n.length==0)||(x>1&&n.length==1)?"YES":"NO");

function InputButtons() {
  readline();
  const buttons = readline().split(' ').map((element) => {
    return parseInt(element);
  });
  return buttons;
}

function IsFastened(button) {
  if (buttons.length == 1) {
    if (buttons[0] == 1) {
      return true;
    }
    else {
      return false;
    }
  }

  var isFastened = false;
  var result = true;
  buttons.forEach(function(button) {
    if (button == 0) {
      if (!isFastened) {
        isFastened = true;
      }
      else {
        result = false;
      }
    }
  });
  if (!result) {
    return false;
  }
  else {
    return isFastened;
  }
}

var buttons = InputButtons();
if (IsFastened(buttons)) {
  print('YES');
}
else {
  print('NO');
}

function InputButtons() {
  readline();
  const buttons = readline().split(' ').map((element) => {
    return parseInt(element);
  });
  return buttons;
}

function IsFastened(button) {
  if (buttons.length == 1) {
    if (buttons[0] == 1) {
      return true;
    }
    else {
      return false;
    }
  }

  var isFastened = false;
  buttons.forEach(function(button) {
    if (button == 0) {
      if (!isFastened) {
        isFastened = true;
      }
      else {
        return false;
      }
    }
  });

  return isFastened;
}

var buttons = InputButtons();
if (IsFastened(buttons)) {
  print('YES');
}
else {
  print('NO');
}


People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied:  every integer from 1 to n2 appears in the table exactly once;  in each row numbers are situated in increasing order;  the sum of numbers in the k-th column is maximum possible. Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.

The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.

First print the sum of the integers in the k-th column of the required table. Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on. If there are multiple suitable table, you are allowed to print any.

var a = readline();
var b = a.split(" ", 2);
var n = Number(b[0]);
var k = Number(b[1]);

var arr = new Array(n);
for (var i = 0; i < n; ++i) {
    arr[i] = new Array(n);
}

var num = n * n;
for (var i = 0; i < n; ++i) {
    for (var j = n - 1; j >= k - 1; --j) {
        arr[i][j] = num--;
    }
}

if (num) {
    for (var i = 0; i < n; ++i) {
        for (var j = k - 2; j >= 0; --j) {
            arr[i][j] = num--;
        }
    }
}

var sum = 0;
for (var i = 0; i < n; ++i) {
    sum += arr[i][k - 1];
}

print(sum);
for (var i = 0; i < n; ++i) {
    print(arr[i].join(" "));
}

var a = readline();
var b = a.split(" ", 2);
var n = Number(b[0]);
var k = Number(b[1]);
print((n * n + k - n + n  * (k - 1) + 1) / 2 * n);

var x = 0, y = n * (k - 1);
for (var i = 0; i < n; ++i) {
    var str = "";
    for (var j = 0; j < k - 1; ++j) {
        str += ++x + " ";
    }
    for (var j = k - 1; j < n; ++j) {
        str += ++y + " ";
    }
    print(str);
}