let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

    let count = 1;
    for (let i = 0; i < lines[0]; ++i) {
        let total = 0;
        const a = lines[count].split(' ').map((el) => +el);

        let diff1 = a[1] - a[0];
        let diff2 = a[2] - a[1];
        let diff3 = a[2] - a[0];

        // a[0] = 10, a[1] = 5, a[2] = 30
        // diff1 = -5, diff2 = 25, diff3 = 20

        // a[2] * X = a[1] + diff1;
        // X = (a[1] + diff1) / a[2] => (0 / 30) => X = 0
        // a[0] * Y = a[1] - diff2;
        // Y = (a[1] - diff2) / a[0] => (-20 / 10) => Y = -2;
        // if diff3 % 2 === 0 return false
        // a[1] * Z = a[2] - (diff3 / 2)
        // Z = (a[2] - (diff3 / 2)) / a[1] => 20 / 5 => Z = 4

        const x = (a[1] + diff1) / a[2];
        const y = (a[1] - diff2) / a[0];

        let z = 0;
        if (diff3 % 2 === 0) {
            z = (a[2] - (diff3 / 2)) / a[1];
        }

        if ((x > 0 && Number.isInteger(x)) || (y > 0 && Number.isInteger(y)) || (z > 0 && Number.isInteger(z))) {
            console.log("YES");
        } else {
            console.log("NO");
        }

        count += 1;
    }
});

var t = parseInt(readline());

  function solve() {
    var inp = readline()
      .split(" ")
      .map((data) => +data);

    var a = inp[0];
    var b = inp[1];
    var c = inp[2];

    if (2 * b - c > 0 && (2 * b - c) % a === 0) {
      return "Yes";
    } else if ((c + a) % (2 * b) === 0) {
      return "Yes";
    } else if (2 * b - a > 0 && (2 * b - a) % c === 0) {
      return "Yes";
    }

    return "No";
  }

  while (t--) {
    print(solve());
  }

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var a = readline().split(" ").map(w => parseInt(w))
            function as(x,y,z) {
                var d = y-x;
                if(((y+d)%z) == 0 && y+d > 0) return true;
                else return false;
            }
            function ase(x,y,z) {
                var d = y-x;
                if(((x-d)%z) == 0 && x-d > 0) return true;
                else return false;
            }
            function ad(x,y,z) {
                var d = (y-x)/2;
                //if(x+d==0) return false;
                if(((x+d)%z) == 0 && x+d > 0) return true;
                else return false;
            }
            //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))
            var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])
            console.log(c ? 'YES' : 'NO')
}

let data = "";

process.stdin.on("data", (c) => (data += c));
process.stdin.on("end", () => {
  let [_, ...input] = data
    .trim()
    .split(/\n/)
    .map((el) => el.trim());

  input = input.map((el) =>
    el
      .trim()
      .split(" ")
      .map((el) => +el.trim())
  );

  const doesformAP = (a, b, c) => {
    const m1 = (2 * b - c) / a;
    const m2 = (c + a) / (2 * b);
    const m3 = (2 * b - a) / c;

    if (m1 > 0 && Math.ceil(m1) == m1) {
      return true;
    }

    if (m2 > 0 && Math.ceil(m2) == m2) {
      return true;
    }

    if (m3 > 0 && Math.ceil(m3) == m3) {
      return true;
    }
    return false;
  };

  input.forEach((el) => {
    if (doesformAP(el[0], el[1], el[2])) console.log("YES");
    else console.log("NO");
  });
});

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

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

function main () {
	let T = rn();
	while (T--) {
		const [a, b, c] = rna();

		const check = x => x > 0 && x%1 == 0;

		const ans = check((2*b-c)/a) || check((2*b-a)/c) || check((a+c)/(2*b));

		console.log(ans ? 'YES' : 'NO');
	}
}

let readline = require("readline");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);

  if (input.length === +input[0] + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let testCase = 1; testCase < input.length; testCase++) {
    let numbers = input[testCase].split(" ");
    let a = +numbers[0];
    let b = +numbers[1];
    let c = +numbers[2];

    newA = b - (c - b);
    if (newA >= a && newA % a == 0 && newA != 0) {
      console.log("YES");
      continue;
    }

    let newB = a + (c - a) / 2;
    if (newB >= b && (c - a) % 2 == 0 && newB % b == 0 && newB != 0) {
      console.log("YES");
      continue;
    }

    let newC = a + 2 * (b - a);
    if (newC >= c && newC % c == 0 && newC != 0) {
      console.log("YES");
      continue;
    }

    console.log("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; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0], b = k[1], c = k[2];
        var bc = 2 * b - c;
        var ba = 2 * b - a;
        var bcs = bc > 0 && bc % a === 0;
        var bas = ba > 0 && ba % c === 0;
        if(bcs || (a + c) % (b * 2) === 0 || bas){
            console.log('YES');
        }else{
            console.log('NO');
        }
    }
});

/*
===== READ INPUT DATA START =====
=================================
*/

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

let inputString = '';

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

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let a, b, c;

  while (T--) {
    [a, b, c] = lines[index++].split(' ').map(Number);

    if (solve(a, b, c) || solve(c, b, a)) {
      console.log('YES');
    } else {
      console.log('NO');
    }
  }
}

function solve(a, b, c) {
  let diff;
  let newVal;

  // already an AP
  if (isAP([a, b, c ])) {
    return true;
  }

  // a
  diff = c - b;
  newVal = b - diff;
  if (diff >= 0 && newVal > a && newVal % a === 0 && isAP([newVal, b, c])) {
    return true;
  }

  // b
  diff = (c - a) / 2;
  newVal = a + diff;
  if (diff >= 0 && newVal > b && newVal % b === 0 && isAP([a, newVal, c])) {
    return true;
  }

  // c
  diff = b - a;
  newVal = b + diff;
  if (diff >= 0 && newVal > c && newVal % c === 0 && isAP([a, b, newVal])) {
    return true;
  }

  return false;
}

function isAP(arr) {
  return arr[2] - arr[1] === arr[1] - arr[0];
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let nums = readLine().split(" ");
  let a = parseInt(nums[0]);
  let b = parseInt(nums[1]);
  let c = parseInt(nums[2]);
  let m1 = (2 * b - c) / a;
  let m2 = (a + c) / (2 * b);
  let m3 = (2 * b - a) / c;
  if (Number.isSafeInteger(m1) && m1 >= 1 || Number.isSafeInteger(m2) && m2 >= 1 || Number.isSafeInteger(m3) && m3 >= 1) {
    console.log("YES");
  } else {
    console.log("NO");
  }
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;

	let t = inputReader.readNumber();

	function solve(){
	    let [a,b,c] = inputReader.readNumberArray();
	    let ok = false;
	    if((a + c) % (2*b) == 0 && (a + c) / (2 * b) > 0) ok = true;
	    if((2 * b - c) % a == 0 && (2 * b - c) / a > 0) ok = true;
	    if((2 * b - a) % c == 0 && (2 * b - a) / c > 0) ok = true;
	    if(ok) console.log("YES")
	    else console.log("NO");
	}

	while(t--){
	    solve();
	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const n = +(readline());
    for(let i =0; i<n; ++i){
        const arr = readline().split(' ');

        let a = parseInt(arr[0]);
        let b = parseInt(arr[1]);
        let c = parseInt(arr[2]);

        if(doesformAP(a,b,c))
            console.log('YES')
        else
            console.log('NO')

    }
}
const formSubset= (arr)=>{

}

const doesformAP = (a,b,c)=>{
    const m1 = (2*b - c ) / a;
    const m2 = (c+a)/(2*b);
    const m3 = (2*b -a )/(c);

    if(m1>0 && Math.ceil(m1) == m1){
        return true
    }

    if(m2 >0 && Math.ceil(m2) == m2){
        return true
    }

    if(m3>0 && Math.ceil(m3) == m3){
        return true
    }
    return false;
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve([a, b, c]) {
    if (Math.floor((a + c) / 2) % b === 0 && (a + c) % 2 === 0) {
        console.log('YES')
        return
    }
    if ((2 * b - c) % a === 0 && 2 * b - c > 0) {
        console.log('YES')
        return
    }
    if ((2 * b - a) % c === 0 && 2 * b - a > 0) {
        console.log('YES')
        return
    }
    console.log('NO')
}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(inputArr[i])
}

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const tsc = await readInt();
    for(let sc = 0; sc < tsc; sc++) {
        const [a,b,c] = await readIntArray();
        const can = (num1, num2) => {
           if (num2 === 0)
               return true;
           return num1%num2===0 && num1/num2 > 0;
        }
        if (can(b + (b-a), c) || can(b - (c-b), a) || ((c+a)%2 === 0 && can((c+a)/2, b))) {
            console.log("YES");
        } else {
            console.log("NO");
        }
    }
}

solve();

const readline = require('readline')

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

function solve(a, b, c) {
    if (a + c === 2 * b) return true
    return ok(2 * b - c, a)
        || ok(2 * b - a, c)
        || ok(a + c, 2 * b)
}
function ok(a, b) {
    return a > 0 && !(a % b)
}

var q=+readline();function isInt(a){return a%1==0}function isPosT(a,b){if(a==0&&b==0)return true;if(a==0)return false;if(b==0)return false;return a/b>0&&isInt(a/b)}wb:while(q--){var des=readline().split(" ").map(function(x){return+x});fb:for(var i=0;i<3;i++){switch(i){case 0:if(isPosT(2*des[1]-des[2],des[0])){print("YES");continue wb}break;case 1:if(isPosT((des[0]+des[2])/2,des[1])){print("YES");continue wb}break;case 2:if(isPosT(2*des[1]-des[0],des[2])){print("YES");continue wb}break}}print("NO")}

var q = +readline(); function isInt(a, b) { if (a == 0) return true; if (b == 0) return false; return Math.floor(a / b) === a / b } wb: while (q--) { var des = readline().split(" ").map(function (x) { return +x }); fb: for (var i = 0; i < 3; i++) { switch (i) { case 0: if (isInt(2 * des[1] - des[2], des[0])) { print("YES"); continue wb } break; case 1: if (isInt((des[0] + des[2]) / 2, des[1])) { print("YES"); continue wb } break; case 2: if (isInt(2 * des[1] - des[0], des[2])) { print("YES"); continue wb } break } } print("NO") }

var q = +readline(); function isInt(a, b) { if (a == 0) return true; if (b != 0) return false; return Math.floor(a / b) === a / b } wb: while (q--) { var des = readline().split(" ").map(function (x) { return +x }); fb: for (var i = 0; i < 3; i++) { switch (i) { case 0: if (isInt(2 * des[1] - des[2], des[0])) { print("YES"); continue wb } break; case 1: if (isInt((des[0] + des[2]) / 2, des[1])) { print("YES"); continue wb } break; case 2: if (isInt(2 * des[1] - des[0], des[2])) { print("YES"); continue wb } break } } print("NO") }

var q = +readline(); function isInt(a, b) { if (a != 0 && b != 0) return Math.floor(a / b) === a / b; return false } wb: while (q--) { var des = readline().split(" ").map(function (x) { return +x }); fb: for (var i = 0; i < 3; i++) { switch (i) { case 0: if (isInt(2 * des[1] - des[2], des[0])) { print("YES"); continue wb } break; case 1: if (isInt((des[0] + des[2]) / 2, des[1])) { print("YES"); continue wb } break; case 2: if (isInt(2 * des[1] - des[0], des[2])) { print("YES"); continue wb } break } } print("NO") }

var q = +readline();
function isInt(a, b) {
    if (a != 0 && b != 0) return Math.floor(a / b) === a / b;
    return false;
}
wb: while (q--) {
    var des = readline().split(" ").map(function (x) {
        return +x;
    });
    //   console.log(des);
    fb: for (var i = 0; i < 3; i++) {
        switch (i) {
            case 0:
                if (isInt(2 * des[1] - des[2], des[0])) {
                    print("YES");
                    continue wb;
                }
                break;
            case 1:
                if (isInt((des[0] + des[2]) / 2, des[1])) {
                    print("YES");
                    continue wb;
                }
                break;
            case 2:
                if (isInt(2 * des[1] - des[0], des[2])) {
                    print("YES");
                    continue wb;
                }
                break;
        }
    }
    print("NO");
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
                var a = readline().split(" ").map(w => parseInt(w))
                function as(x,y,z) {
                    var d = y-x;
                    if(((y+d)%z) == 0) return true;
                    else return false;
                }
                function ase(x,y,z) {
                  var d = y-x;

                  if(((x-d)%z) == 0) return true;
                  else return false;
                }
                function ad(x,y,z) {
                    var d = (y-x)/2;

                    if(((x+d)%z) == 0) return true;
                    else return false;
                }
                //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))
                var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])
                console.log(c ? 'YES' : 'NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var a = readline().split(" ").map(w => parseInt(w))
            function as(x,y,z) {
                var d = y-x;
                if(y+d==0) return false
                else if(((y+d)%z) == 0) return true;
                else return false;
            }
            function ase(x,y,z) {
                var d = y-x;
                if(x-d==0) return false
                else if(((x-d)%z) == 0) return true;
                else return false;
            }
            function ad(x,y,z) {
                var d = (y-x)/2;
                if(x+d==0) return false;
                else if(((x+d)%z) == 0) return true;
                else return false;
            }
            //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))
            var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])
            console.log(c ? 'YES' : 'NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
        let a = readline().split(" ").map(w => parseInt(w))
        function as(x,y,z) {
            var d = y-x;
            if(y+d==0) return false
            if((Math.abs(y+d))%z == 0) return true;
            else return false;
        }
        function ase(x,y,z) {
            var d = y-x;
            if(x-d==0) return false
            if((Math.abs(x-d))%z == 0) return true;
            else return false;
        }
        function ad(x,y,z) {
            var d = (y-x)/2;
            if(x+d==0) return false;
            if((Math.abs(x+d))%z == 0) return true;
            else return false;
        }
        //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))
        var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])
        console.log(c ? 'YES' : 'NO')
}

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
    let a = readline().split(" ").map(w => parseInt(w))
    function as(x,y,z) {
        var d = y-x;
        if(y+d==0) return false
        if((y+d)%z == 0) return true;
        else return false;
    }
    function ase(x,y,z) {
        var d = y-x;
        if(x-d==0) return false
        if((x-d)%z == 0) return true;
        else return false;
    }
    function ad(x,y,z) {
        var d = (y-x)/2;
        if(x+d==0) return false;
        if((x+d)%z == 0) return true;
        else return false;
    }
    //console.log(as(a[0],a[1],a[2]), ase(a[1],a[2],a[0]), ad(a[0],a[2],a[1]))
    var c = as(a[0],a[1],a[2]) || ase(a[1],a[2],a[0]) || ad(a[0],a[2],a[1])
    console.log(c ? 'YES' : 'NO')
}

let data = "";

process.stdin.on("data", (c) => (data += c));
process.stdin.on("end", () => {
  let [_, ...input] = data
    .trim()
    .split(/\n/)
    .map((el) => el.trim());

  input = input.map((el) =>
    el
      .trim()
      .split(" ")
      .map((el) => +el.trim())
  );

  let difference = 0;

  input.forEach((el) => {
    const m1 = (2 * el[1] - el[2]) / el[0];
    const m2 = (el[2] + el[0]) / (2 * el[1]);
    const m3 = (2 * el[1] - el[0]) / el[3];

    if (m1 > 0 && Math.ceil(m1) == m1) {
      console.log("YES");
      return 0;
    }

    if (m2 > 0 && Math.ceil(m2) == m2) {
      console.log("YES");
      return 0;
    }

    if (m3 > 0 && Math.ceil(m3) == m3) {
      console.log("YES");
      return 0;
    }
    console.log("NO");
  });
});

let data = "";

process.stdin.on("data", (c) => (data += c));
process.stdin.on("end", () => {
  let [_, ...input] = data
    .trim()
    .split(/\n/)
    .map((el) => el.trim());

  input = input.map((el) =>
    el
      .trim()
      .split(" ")
      .map((el) => +el.trim())
      .sort((a, b) => a - b)
  );

  let difference = 0;

  input.forEach((el) => {
    difference = el[2] - el[1];

    difference % el[0] === 0 && difference * 2 !== el[0] + el[1]
      ? console.log("YES")
      : console.log("NO");
  });
});

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

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

function main () {
	let T = rn();
	while (T--) {
		const [a, b, c] = rna();

		const m1 = (2*b-c) != 0 && (2*b-c)%a == 0;
		const m2 = (2*b-a) != 0 && (2*b-a)%c == 0;
		const m3 = (a+c) != 0 && (a+c) % (2*b) == 0;

		const ans = m1 || m2 || m3;

		console.log(ans ? 'YES' : 'NO');
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		const [a, b, c] = rna();

		const m1 = (2*b-c)/a;
		const m2 = (2*b-a)/c;
		const m3 = (a+c)/(2*b);

		const ans = m1 && m1%1 == 0 || m2 && m2%1 == 0 || m3 && m3%1 == 0;

		console.log(ans ? 'YES' : 'NO');
	}
}

let readline = require("readline");

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

let input = [];
rl.on("line", function (line) {
  input.push(line);

  if (input.length === +input[0] + 1) {
    // call your function here
    solve(input);
    rl.close();
  }
});

let solve = (input) => {
  for (let testCase = 1; testCase < input.length; testCase++) {
    let numbers = input[testCase].split(" ");
    let a = +numbers[0];
    let b = +numbers[1];
    let c = +numbers[2];

    let newA = b - (c - b);
    if (newA >= a && newA % a === 0 && newA !== 0) {
      console.log("YES");
      continue;
    }

    let newB = a + (c - a) / 2;
    if (newB >= b && newB % b === 0 && newB !== 0) {
      console.log("YES");
      continue;
    }

    let newC = b + 2 * (b - a);
    if (newC >= c && newC % c === 0 && newC !== 0) {
      console.log("YES");
      continue;
    }

    console.log("NO");
  }
};


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

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

function main () {
	const [n, k] = rna();
	const a = rna();

	function check (m) {
		const b = []; b[-1] = 0;
		for (let i = 0; i < n; i++) {
			b[i] = a[i] >= m ? 1 : -1;
			b[i] += b[i-1];
		}

		let mn = 0;
		for (let i = k - 1; i < n; i++) {
			mn = Math.min(mn, b[i-k]);
			if (b[i] > mn) return true;
		}
		return false;
	}

	let ans = 0;
	let l = 1, r = n;
	while (l <= r) {
		const mid = l + r >> 1;
		if (check(mid)) {
			ans = mid;
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}

	console.log(ans);
}

const rl = require("readline").createInterface({
	input: process.stdin
});
const it = rl[Symbol.asyncIterator]();
const readln = async () => (await it.next()).value;
const writeln = (value) => process.stdout.write(`${value}\n`);
const run = async (proc)  => { await proc(); rl.close(); };

run(async () =>
{
	const [n,k] = (await readln()).split(" ").map((e) => parseInt(e));
	const a = new Int32Array(n+1);
	const b = new Int32Array(n+1);
	(await readln()).split(" ").forEach((e,i) => a[i+1] = parseInt(e));
	let l = 0;
	let h = n+1;
	while(h-l>=2)
	{
		let m = Math.floor((l+h)/2);
		for(let i=1;i<=n;i++)
		{
			b[i] = b[i-1];
			if (a[i]<m)
			{
				b[i]--;
			}
			else
			{
				b[i]++;
			}
		}
		let found = false;
		for(let i=n-1;i>=0;i--)
		{
			found = found || (((i+k)<=n) && (b[i]<b[i+k]));
			if (found) break;
			b[i] = Math.max(b[i],b[i+1]);
		}
		if (found)
		{
			l = m;
		}
		else
		{
			h = m;
		}
	}
	writeln(l);
});

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

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

function main () {
	const [n, k] = rna();
	const a = rna();

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

	function check (m) {
		const b = [];
		for (let i = 0; i < n; i++) {
			b[i] = a[i] >= m ? 1 : -1;
		}

		const psum = [], pmnsum = []; psum[-1] = 0, pmnsum[-1] = 0;
		for (let i = 0; i < n; i++) {
			psum[i] = psum[i-1] + b[i];
			pmnsum[i] = Math.min(pmnsum[i-1], psum[i]);
		}

		//if (m == 47) console.log({m, b, psum, pmnsum});

		for (let i = k-1; i < n; i++) {
			if (psum[i] - pmnsum[i-k] > 0) return true;
		}

		return false;
	}

	let ans = 0;
	let l = 0, r = n-1;
	while (l <= r) {
		const mid = l + r >> 1;
		if (check(as[mid])) {
			ans = as[mid];
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}

	console.log(ans);
}

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

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

function main () {
	const [n, k] = rna();
	const a = rna();
	const ar = a.slice().reverse();

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

	function check (m, a) {
		const req = Math.ceil((k+1)/2);
		//console.log({m, req})
		let lc = 0, rc = 0;
		for (let i = 0; i < n; i++) {
			if (a[i] >= m) {
				rc++;
				if (rc == Math.max(lc+1, req)) return 1;
			} else {
				if (rc) {
					lc++;
					if (lc - rc >= req) lc = rc = 0;
				}
			}
			//console.log({m, req, i, lc, rc}, a[i])
		}
		return 0;
	}

	let ans = 0;
	let l = 0, r = n-1;
	while (l <= r) {
		const mid = l + r >> 1;
		cur = check(as[mid], a) || check(as[mid], ar);
		//console.log({cur});
		if (cur) {
			ans = as[mid];
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}

	console.log(ans);
}

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

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

function main () {
	const [n, k] = rna();
	const a = rna();

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

	function check (m) {
		const req = Math.ceil((k+1)/2);
		//console.log({m, req})
		let lc = 0, rc = 0;
		for (let i = 0; i < n; i++) {
			if (a[i] >= m) {
				rc++;
				if (rc == Math.max(lc+1, req)) return 1;
			} else {
				if (rc) {
					lc++;
					if (lc - rc > req) lc = rc = 0;
				}
			}
			//console.log({m, req, i, lc, rc}, a[i])
		}
		return 0;
	}

	let ans = 0;
	let l = 0, r = n-1;
	while (l <= r) {
		const mid = l + r >> 1;
		cur = check(as[mid]);
		//console.log({cur});
		if (cur) {
			ans = as[mid];
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}

	console.log(ans);
}

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

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

function main () {
	const [n, k] = rna();
	const a = rna();

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

	function check (m) {
		const req = Math.ceil((k+1)/2);
		let lc = 0, rc = 0;
		for (let i = 0; i < n; i++) {
			if (a[i] >= m) {
				rc++;
				if (rc == req) return 1;
			} else {
				if (rc) {
					lc++;
					if (lc - rc > req) lc = rc = 0;
				}
			}
		}
		return 0;
	}

	let ans = 0;
	let l = 0, r = n-1;
	while (l <= r) {
		const mid = l + r >> 1;
		if (check(a[mid])) {
			ans = a[mid];
			l = mid + 1;
		} else {
			r = mid - 1;
		}
	}

	console.log(ans);
}


var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

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

var ARR = [];
for (var i = 0; i < 101; i++) {
   ARR.push(i);
}
var ans = ARR.join(' ');

function solve() {
   read();
   var hasLessZero = false;
   var arr = readArray((x) => {
      if (Number(x) < 0) {
         hasLessZero = true;
      }
   });
   if (hasLessZero) {
      write('no');
      return;
   }
   write('yes');
   write(101);
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

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

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

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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

(function () {
    var defines = {};
    var entry = [null];
    function define(name, dependencies, factory) {
        defines[name] = { dependencies: dependencies, factory: factory };
        entry[0] = name;
    }
    define("require", ["exports"], function (exports) {
        Object.defineProperty(exports, "__cjsModule", { value: true });
        Object.defineProperty(exports, "default", { value: function (name) { return resolve(name); } });
    });
    var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    };
    var __generator = (this && this.__generator) || function (thisArg, body) {
        var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
        return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
        function verb(n) { return function (v) { return step([n, v]); }; }
        function step(op) {
            if (f) throw new TypeError("Generator is already executing.");
            while (_) try {
                if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
                if (y = 0, t) op = [op[0] & 2, t.value];
                switch (op[0]) {
                    case 0: case 1: t = op; break;
                    case 4: _.label++; return { value: op[1], done: false };
                    case 5: _.label++; y = op[1]; op = [0]; continue;
                    case 7: op = _.ops.pop(); _.trys.pop(); continue;
                    default:
                        if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                        if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                        if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                        if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                        if (t[2]) _.ops.pop();
                        _.trys.pop(); continue;
                }
                op = body.call(thisArg, _);
            } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
            if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
        }
    };
    define("utils/readline", ["require", "exports"], function (require, exports) {
        "use strict";
        exports.__esModule = true;
        exports.getLineReader = exports.getAllLines = void 0;
        function getAllLines() {
            return new Promise(function (res) {
                var inputText = "";
                process.stdin.on("data", function (data) { return (inputText += data); });
                process.stdin.on("end", function () {
                    var EOL = require("os").EOL;
                    res(inputText.split(EOL));
                });
            });
        }
        exports.getAllLines = getAllLines;
        function getLineReader() {
            return __awaiter(this, void 0, void 0, function () {
                var lines, lineNumber;
                return __generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, getAllLines()];
                        case 1:
                            lines = _a.sent();
                            lineNumber = 0;
                            return [2 /*return*/, {
                                    nextLine: function () {
                                        var _a;
                                        return (_a = lines[lineNumber++]) !== null && _a !== void 0 ? _a : "";
                                    }
                                }];
                    }
                });
            });
        }
        exports.getLineReader = getLineReader;
    });
    define("1536/index", ["require", "exports", "utils/readline"], function (require, exports, readline_1) {
        "use strict";
        exports.__esModule = true;
        (function () { return __awaiter(void 0, void 0, void 0, function () {
            var lr, testCases, N, line, arr, result, i;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, readline_1.getLineReader()];
                    case 1:
                        lr = _a.sent();
                        testCases = parseInt(lr.nextLine(), 10);
                        while (testCases--) {
                            N = parseInt(lr.nextLine(), 10);
                            line = lr.nextLine();
                            arr = line
                                .trim()
                                .split(" ")
                                .map(function (v) { return parseInt(v, 10); });
                            if (arr.some(function (v) { return v < 0; })) {
                                console.log("NO");
                            }
                            else {
                                result = [];
                                for (i = 0; i <= 100; i++) {
                                    result.push(i);
                                }
                                console.log("YES");
                                console.log(101);
                                console.log.apply(console, result);
                            }
                        }
                        return [2 /*return*/];
                }
            });
        }); })();
    });

    'marker:resolver';

    function get_define(name) {
        if (defines[name]) {
            return defines[name];
        }
        else if (defines[name + '/index']) {
            return defines[name + '/index'];
        }
        else {
            var dependencies = ['exports'];
            var factory = function (exports) {
                try {
                    Object.defineProperty(exports, "__cjsModule", { value: true });
                    Object.defineProperty(exports, "default", { value: require(name) });
                }
                catch (_a) {
                    throw Error(['module "', name, '" not found.'].join(''));
                }
            };
            return { dependencies: dependencies, factory: factory };
        }
    }
    var instances = {};
    function resolve(name) {
        if (instances[name]) {
            return instances[name];
        }
        if (name === 'exports') {
            return {};
        }
        var define = get_define(name);
        instances[name] = {};
        var dependencies = define.dependencies.map(function (name) { return resolve(name); });
        define.factory.apply(define, dependencies);
        var exports = dependencies[define.dependencies.indexOf('exports')];
        instances[name] = (exports['__cjsModule']) ? exports["default"] : exports;
        return instances[name];
    }
    if (entry[0] !== null) {
        return resolve(entry[0]);
    }
})();

//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] = BigInt(next());
		}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 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 getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var isOK = true;
		var max = 0;
		for(var i = 0; i < N; i++){
			if(list[i] < 0){
				isOK = false;
			}
			max = Math.max(max, list[i]);
		}
		if(!isOK){
			myout("No");
			continue;
		}
		list.sort(function(a,b){
			return a - b;
		});
		for(var i = 0; i < max; i++){
			if(list.indexOf(i) == -1){
				list.push(i);
			}
		}

		myout("Yes");
		myout(list.length);
		myout(myconv(list, 8));
	}
}

// https://codeforces.com/contest/1536/problem/D
// import { readline, print } from "@ip-algorithmics/codeforces-io";
var testCases = parseInt(readline(), 10);
while (testCases--) {
  var N = parseInt(readline(), 10);
  var line = readline();
  var arr = line
    .trim()
    .split(" ")
    .map((v) => parseInt(v, 10));
  if (arr.some((v) => v < 0)) {
    print("NO");
  } else {
    var result = [];
    for (var i = 0; i <= 100; i++) {
      result.push(i);
    }
    print("YES");
    print(101);
    print(...result);
  }
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();

  for (var i = 0; i < testCasesNum; i++) {
    var n = +readline();
    var nums = readNumArray();
    var max = 0;
    var isNegative = false;
    for (var j = 0; j < n; j++) {
      if (nums[j] < 0) {
        isNegative = true;
        break;
      }
      if (nums[j] > max) {
        max = nums[j];
      }
    }
    if (isNegative) {
      print('No');
    } else {
      print('Yes');
      print(String(max + 1));
      var result = '0';
      for (var j = 1; j < max + 1; j++) {
        result = result + ' ' + String(j);
      }
      print(result);
    }
  }
}

main();

(()=>{"use strict";var e={59:function(e,t,n){var r=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function u(e){try{s(r.next(e))}catch(e){i(e)}}function a(e){try{s(r.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(u,a)}s((r=r.apply(e,t||[])).next())}))},o=this&&this.__generator||function(e,t){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!((o=(o=u.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=t.call(e,u)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(t,"__esModule",{value:!0});var i=n(230);r(void 0,void 0,void 0,(function(){var e,t,n,r,u,a;return o(this,(function(o){switch(o.label){case 0:return e=i.getLineReader(),n=parseInt,[4,e.nextLine()];case 1:t=n.apply(void 0,[o.sent(),10]),o.label=2;case 2:return t--?(r=parseInt,[4,e.nextLine()]):[3,5];case 3:return r.apply(void 0,[o.sent(),10]),[4,e.nextLine()];case 4:if(o.sent().trim().split(" ").map((function(e){return parseInt(e,10)})).some((function(e){return e<0})))console.log("NO");else{for(u=[],a=0;a<=100;a++)u.push(a);console.log("YES"),console.log(101),console.log.apply(console,u)}return[3,2];case 5:return[2]}}))}))},230:function(e,t,n){var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.getLineReader=void 0;var o=r(n(58));function i(){var e=o.default.createInterface({input:process.stdin,output:process.stdout,terminal:!1});return{nextLine:function(){return new Promise((function(t,n){e.resume(),e.on("line",(function(n){e.pause(),t(n)}))}))},close:function(){e.close()}}}t.getLineReader=i,t.default=i},58:e=>{e.exports=require("readline")}},t={};!function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r].call(i.exports,i,i.exports,n),i.exports}(59)})();

//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] = BigInt(next());
		}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 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 getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var isOK = true;
		var max = 0;
		for(var i = 0; i < N; i++){
			if(list[i] < 0){
				isOK = false;
			}
			max = Math.max(max, list[i]);
		}
		if(!isOK){
			myout("No");
			continue;
		}
		list.sort(function(a,b){
			return a - b;
		});
		var min = 100000;
		for(var i = 0; i < N - 1; i++){
			min = Math.min(min, list[i + 1] - list[i]);
		}
		for(var i = 1; list.length < 300; i++){
			if(i * min == max){
				break;
			}
			if(list.indexOf(i * min) == -1){
				list.push(i * min);
			}
		}
		myout("Yes");
		myout(list.length);
		myout(myconv(list, 8));
	}
}

//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] = BigInt(next());
		}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 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 getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var isOK = true;
		var max = 0;
		for(var i = 0; i < N; i++){
			if(list[i] < 0){
				isOK = false;
			}
			max = Math.max(max, list[i]);
		}
		if(!isOK){
			myout("No");
			continue;
		}
		list.sort(function(a,b){
			return a - b;
		});
		var min = 100000;
		for(var i = 0; i < N - 1; i++){
			min = Math.min(min, list[i + 1] - list[i]);
		}
		for(var i = 1; list.length < 300; i++){
			if(i * min == max){
				break;
			}
			if(list.indexOf(i * min) == -1){
				list.push(i * min);
			}
		}
		myout(list.length);
		myout(myconv(list, 8));
	}
}

//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] = BigInt(next());
		}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 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 getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var isOK = true;
		for(var i = 0; i < N; i++){
			if(list[i] < 0){
				isOK = false;
				break;
			}
		}
		if(!isOK){
			myout("No");
			continue;
		}
		list.sort(function(a,b){
			return a - b;
		});
		var min = 100000;
		for(var i = 0; i < N - 1; i++){
			min = Math.min(min, list[i + 1] - list[i]);
		}
		for(var i = 1; list.length < 300; i++){
			if(list.indexOf(i * min) == -1){
				list.push(i * min);
			}
		}
		myout(list.length);
		myout(myconv(list, 8));
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

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

var ARR = [];
for (var i = 0; i < 101; i++) {
   ARR.push(i);
}
var ans = ARR.join(' ');

function solve() {
   read();
   var hasLessZero = false;
   var arr = readArray((x) => {
      if (Number(x) < 0) {
         hasLessZero = true;
      }
   });
   if (hasLessZero) {
      write('no');
      return;
   }
   write('yes');
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

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

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

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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


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

let curLine = 0;
let allLines = [];

readline.on("line", line => {
    allLines.push(line);
});

readline.on("close", () => { main() });

let nextLine = () => allLines[curLine++];

const K = 20;

function main() {
    let t = Number(nextLine());

    while(t--) {
        let n = Number(nextLine());
        let ara = nextLine().split(" ").map(value => Number(value));

        let sufMax = [...ara], sufMin = [...ara];

        for(let i = n-2; i >= 0; i--) sufMax[i] = Math.max(sufMax[i], sufMax[i+1]);
        for(let i = n-2; i >= 0; i--) sufMin[i] = Math.min(sufMin[i], sufMin[i+1]);

        let sp = [];
        for(let j = 0; j < K; j++) sp.push([]);

        ara.forEach((element, index) => { sp[0][index] = element; });

        for(let j = 1; j < K; j++) {
            for(let i = 0; i < n; i++) {
                sp[j][i] = sp[j-1][i];
                if(i+(1<<(j-1)) < n) sp[j][i] = Math.min(sp[j][i], sp[j-1][i+(1<<(j-1))]);
            }
        }

        let query = (i, j) => {
            let k = Math.floor(Math.log2(j-i+1));
            return Math.min(sp[k][i], sp[k][j-(1<<k)+1]);
        }

        let mx = 0, flag = false;

        for(let i = 0; i < n-2; i++) {
            mx = Math.max(mx, ara[i]);

            let st = i+1, ed = n;

            while(st+1 < ed) {
                let mid = (st+ed)>>1;

                if(sufMax[mid] > mx) st = mid;
                else ed = mid;
            }

            if(ed == n) continue;
            if(query(i+1, ed-1) != mx && ed < n-1) ed++;

            let rmx = sufMax[ed], mn = query(i+1, ed-1);

            if(mn == mx && mn == rmx) {
                flag = true;

                console.log("YES");
                console.log(`${i+1} ${ed-i-1} ${n-ed}`);

                break;
            }
        }

        if(!flag) console.log("NO");
    }
}

"use strict";

const K = 20;

(function () {

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

    let curLine = 0, allLines = [];

    let nextLine = () => {
        if(curLine == allLines.length) throw new ReferenceError("No more input in the buffer");
        return allLines[curLine++]
    };

    readline.on("line", line => { allLines.push(line); });
    readline.on("close", () => { main(nextLine) });

})();

function main(nextLine) {
    let t = Number(nextLine());

    while(t--) {
        let n = Number(nextLine());
        let ara = nextLine().split(" ").map(value => Number(value));

        let sufMax = [...ara];
        for(let i = n-2; i >= 0; i--) sufMax[i] = Math.max(sufMax[i], sufMax[i+1]);

        let sp = [];
        for(let j = 0; j < K; j++) sp.push([]);

        sp[0] = ara.map(value => value);

        for(let j = 1; j < K; j++) {
            for(let i = 0; i < n; i++) {
                sp[j][i] = sp[j-1][i];
                if(i+(1<<(j-1)) < n) sp[j][i] = Math.min(sp[j][i], sp[j-1][i+(1<<(j-1))]);
            }
        }

        let query = (i, j) => {
            let k = Math.floor(Math.log2(j-i+1));
            return Math.min(sp[k][i], sp[k][j-(1<<k)+1]);
        }

        let mx = 0, flag = false;

        for(let i = 0; i < n-2; i++) {
            mx = Math.max(mx, ara[i]);

            let st = i+1, ed = n;

            while(st+1 < ed) {
                let mid = (st+ed)>>1;

                if(sufMax[mid] > mx) st = mid;
                else ed = mid;
            }

            if(ed == n) continue;
            if(query(i+1, ed-1) != mx && ed < n-1) ed++;

            let rmx = sufMax[ed], mn = query(i+1, ed-1);

            if(mn == mx && mn == rmx) {
                flag = true;

                console.log("YES");
                console.log(`${i+1} ${ed-i-1} ${n-ed}`);

                break;
            }
        }

        if(!flag) 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 gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    //let mod = 10**9+7
    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split(" ").map(x=>parseInt(x));

        let countzeros=0
        let countones=0
        let indicefirstzero=-1
        let indicelastone=-1
        let score = 0
        for(let i =0; i<n ;++i)
        {
            if((arr[i]==0)&&(indicefirstzero==-1))
                indicefirstzero=i

            if(arr[i]==1)
                indicelastone=i

            if(arr[i]==0)
                score +=  countones

            countzeros += (arr[i]==0)
            countones += arr[i]&1

        }
        /*console.log("countzeros " + countzeros)
        console.log("countones " + countones)
        console.log("indicelastone " + indicelastone)
        console.log("indicefirstzero " + indicefirstzero) */

        let firstzeroimpact = countzeros - indicefirstzero - 1
        let lastoneimpact = countones - (n-1-indicelastone) - 1

        //console.log("firstzeroimpact " + firstzeroimpact)
        //console.log("lastoneimpact " + lastoneimpact)

        let maximpact = Math.max(firstzeroimpact,lastoneimpact)
        if(maximpact<0)
            maximpact=0
        /*console.log("maximpact " + maximpact)
        console.log("score " + score)
        console.log("score + maximpact " + (score+ maximpact))*/
        console.log(score+ maximpact)
    }
}

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline()-0;
	var a = readline().split(" ").map(w => parseInt(w));
	var pref1 = [];
	var suf0 = [];
	var ans1 = [];
	var ans0 = [];
	for(var i=0;i<n;i++) {
		pref1[i] = (pref1[i-1]||0) + a[i];
		if(!a[i]) ans1[i] = (ans1[i-1]||0) + pref1[i];
		else ans1[i] = (ans1[i-1]||0);
	}
	for(var i=n-1;i>=0;i--) {
		suf0[i] = (suf0[i+1]||0) + (a[i]===0?1:0);
		if(a[i]) ans0[i] = (ans0[i+1]||0) + suf0[i];
		else ans0[i] = (ans0[i+1]||0)
	}
	var ans = ans1[n-1];
	for(var i=0;i<n;i++) {
		if(!a[i]) {
			ans = max(ans, (ans1[n-1]-(pref1[i-1]||0)) + (suf0[i+1]||0))
		} else {
			ans = max(ans, (ans1[n-1]-(suf0[i+1]||0)) + (pref1[i-1]||0))
		}
	}
	console.log(ans);
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var alpha = "abcdefghijklmnopqrstuvwxyz";
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var L = new Array(N + 2).fill(0);
		var R = new Array(N + 2).fill(0);
		for(var i = 0; i < N; i++){
			if(list[i] == 1){
				L[i + 1]++;
			}
			L[i + 1] += L[i];
		}
		for(var i = N - 1; i >= 0; i--){
			if(list[i] == 0){
				R[i + 1]++;
			}
			R[i] += R[i + 1];
		}
		var sum = 0;
		for(var i = 0; i < N; i++){
			if(list[i] == 0){
				sum += L[i];
			}
		}

		var output = sum;
		for(var i = 1; i <= N; i++){
			if(list[i - 1] == 1){
				output = Math.max(output, sum + L[i - 1] - R[i + 1]);
			}else{
				output = Math.max(output, sum - L[i - 1] + R[i + 1]);
			}
		}

		myout(output);
	}
}

const readline = require('readline')

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

function solve(n, arr) {
    let a = 0, b = 0, c = cal(n, arr)
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) {
            const temp = arr.slice()
            temp[i] = 1
            a = cal(n, temp)
            break
        }
    }
    for (let i = arr.length - 1; i >= 0; i--) {
        if (arr[i] === 1) {
            const temp = arr.slice()
            temp[i] = 0
            b = cal(n, temp)
            break
        }
    }
    return Math.max(a, b, c)
}
function cal(n, arr) {
    let zero = 0
    let r = 0
    for (let i = arr.length - 1; i >= 0; i--) {
        if (arr[i]) {
            r += zero
        } else {
            zero++
        }
    }
    return r
}

let buf='';

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

function calc(a) {
    let b=new Array(a.length);
    let sum=0;
    for(let i=0;i<a.length;i++)
    {
        if(a[i]===0)
        {
            b[i]=1;
        }
        else
        {
            b[i]=0;
        }
    }
    for(let i=a.length-2;i>=0;i--) b[i]+=b[i+1];
    // console.log(b);
    for(let i=0;i<a.length;i++)
    {
        if(a[i]===1)
        {
            sum+=b[i];
        }
    }
    return sum;
}

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 a=line[2*_].split(' ').map(x=>{return parseInt(x)});
        // console.log(a);
        let ans=calc(a);
        for(let i=0;i<a.length;i++)
        {
            if(a[i]===0)
            {
                a[i]=1;
                ans=Math.max(ans,calc(a));
                a[i]=0;
                break;
            }
        }
        for(let i=a.length-1;i>=0;i--)
        {
            if(a[i]===1)
            {
                a[i]=0;
                ans=Math.max(ans,calc(a));
                a[i]=1;
                break;
            }
        }
        console.log(ans);
    }
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let T = parseInt(readline());
    while (T--) {
        let n = parseInt(readline());
        let ary = readline().trim().split(' ').map(s => parseInt(s));
        let t0 = ary.filter(x => x == 0).length;
        let cnt = [0, 0];
        let tot = 0;
        let mx0 = 0, mx1 = 0;
        for(let x of ary) {
            let y = t0 - cnt[0];
            if (x == 0) {
                tot += cnt[1];
                mx1 = Math.max(mx1, y - 1 - cnt[1]);
            } else {
                mx0 = Math.max(mx0, cnt[1] - y);
            }
            cnt[x]++;
        }
        // console.log(tot, mx0, mx1, cnt);
        console.log(tot + Math.max(mx0, mx1));
    }
}

    const fs = require("fs");
    const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
    let currentline = 0;
    function readline(){
          return input[currentline++];
    }
    function alph() {
      var f = 'abcdefghijklmnopqrstuvwxyz';
      return f;
    }
    function Alph() {
      var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      return f;
    }
    function max(x,y) {
      return x >=y ? x : y;
    }
    function min(x,y) {
      return x <=y ? x : y;
    }
    function abs(x) {
      return x < 0 ? x*(-1) : x;
    }
    var T = readline();
    var inf = 1000000000000;
    for(var tc=1;tc<=T;tc++) {
    	var n = readline();
    	var a = readline().split(" ").map(w => parseInt(w));
    	var pref1 = [];
    	var suf0 = [];
    	var ans1 = [];
    	var ans0 = [];
    	for(var i=0;i<n;i++) {
    		pref1[i] = (pref1[i-1]||0) + a[i];
    		if(a[i]==0) ans1[i] = (ans1[i-1]||0) + pref1[i];
    		else ans1[i] = (ans1[i-1]||0);
    	}
    	for(var i=n-1;i>=0;i--) {
    		suf0[i] = (suf0[i+1]||0) + (a[i]==0?1:0);
    		if(a[i]==1) ans0[i] = (ans0[i+1]||0) + suf0[i];
    		else ans0[i] = (ans0[i+1]||0)
    	}
    	var ans = max(ans0[0], ans1[n-1]);
    	ans = max(0, ans);
    	for(var i=0;i<n;i++) {
    		if(a[i]==0) {
    			ans = max(ans, ((ans1[i-1]||0) + (ans0[i+1]||0) + (suf0[i+1]||0)))
    		} else {
    			ans = max(ans, ((ans1[i-1]||0) + (ans0[i+1]||0) + (pref1[i-1]||0)));
    		}
    	}
    	console.log(ans);
    }

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline()-0;
	var a = readline().split(" ").map(w => parseInt(w));
	var pref1 = [];
	var suf0 = [];
	var ans1 = [];
	var ans0 = [];
	for(var i=0;i<n;i++) {
		pref1[i] = (pref1[i-1]||0) + a[i];
		if(!a[i]) ans1[i] = (ans1[i-1]||0) + pref1[i];
		else ans1[i] = (ans1[i-1]||0);
	}
	for(var i=n-1;i>=0;i--) {
		suf0[i] = (suf0[i+1]||0) + (a[i]===0?1:0);
		if(a[i]) ans0[i] = (ans0[i+1]||0) + suf0[i];
		else ans0[i] = (ans0[i+1]||0)
	}
	var ans = max(ans0[0], ans1[n-1]);
	ans = max(0, ans);
	for(var i=0;i<n;i++) {
		if(!a[i]) {
			ans = max(ans, (ans1[i-1]||0) + (ans0[i+1]||0) + (suf0[i+1]||0))
		} else {
			ans = max(ans, (ans1[i-1]||0) + (ans0[i+1]||0) + (pref1[i-1]||0));
		}
	}
	console.log(ans);
}

const fs = require("fs");
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}
function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
	var n = readline()-0;
	var a = readline().split(" ").map(w => parseInt(w));
	var pref1 = [];
	var suf0 = [];
	var ans1 = [];
	var ans0 = [];
	for(var i=0;i<n;i++) {
		pref1[i] = (pref1[i-1]||0) + a[i];
		if(!a[i]) ans1[i] = (ans1[i-1]||0) + pref1[i];
		else ans1[i] = (ans1[i-1]||0);
	}
	for(var i=n-1;i>=0;i--) {
		suf0[i] = (suf0[i+1]||0) + (a[i]===0?1:0);
		if(a[i]) ans0[i] = (ans0[i+1]||0) + suf0[i];
		else ans0[i] = (ans0[i+1]||0)
	}
	var ans = ans1[n-1];
	for(var i=0;i<n;i++) {
		if(!a[i]) {
			ans = max(ans, (ans1[i-1]||0) + (ans0[i+1]||0) + (suf0[i+1]||0))
		} else {
			ans = max(ans, (ans1[i-1]||0) + (ans0[i+1]||0) + (pref1[i-1]||0));
		}
	}
	console.log(ans);
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var alpha = "abcdefghijklmnopqrstuvwxyz";
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var L = list.indexOf(1);
		var R = list.lastIndexOf(0);
		if(L == -1 || R == -1){
			var U = Math.floor(N / 2);
			var V = Math.ceil(N / 2);
			myout(U * V);
			continue;
		}
		for(var i = 0; i < L; i++){
			list[i] = 1;
		}
		for(var i = R; i < N; i++){
			list[i] = 0;
		}

		var sum = new Array(N + 1).fill(0);
		for(var i = N - 1; i >= 0; i--){
			if(list[i] == 0){
				sum[i]++;
			}
			sum[i] += sum[i + 1];
		}
		//myerr({list,sum});
		var output = 0;
		for(var i = 0; i < N; i++){
			if(list[i] == 1){
				output += sum[i];
			}
		}
		myout(output);
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var alpha = "abcdefghijklmnopqrstuvwxyz";
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var L = list.indexOf(1);
		if(L == -1){
			list[0] = 1;
		}else{
			for(var i = 0; i < L; i++){
				list[i] = 1;
			}
		}
		var R = list.lastIndexOf(0);
		if(R != -1){
			for(var i = R; i < N; i++){
				list[i] = 0;
			}
		}else{
			list[N - 1] = 0;
		}

		var sum = new Array(N + 1).fill(0);
		for(var i = N - 1; i >= 0; i--){
			if(list[i] == 0){
				sum[i]++;
			}
			sum[i] += sum[i + 1];
		}
		//myerr({list,sum});
		var output = 0;
		for(var i = 0; i < N; i++){
			if(list[i] == 1){
				output += sum[i];
			}
		}
		myout(output);
	}
}

'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 gcd(a,b )
{
    if (!b)
        return a

    return gcd( b , a%b )
}

function main() {

    let t = parseInt(readLine());

    //let mod = 10**9+7
    loopwhile:
    while(t--)
    {
        let n = parseInt(readLine());

        let arr = readLine().trim().split(" ").map(x=>parseInt(x));

        let countzeros=0
        let countones=0
        let indicefirstzero=-1
        let indicelastone=-1
        let score = 0
        for(let i =0; i<n ;++i)
        {
            if((arr[i]==0)&&(indicefirstzero==-1))
                indicefirstzero=i

            if(arr[i]==1)
                indicelastone=i

            if(arr[i]==0)
                score +=  countones

            countzeros += (arr[i]==0)
            countones += arr[i]&1

        }
        /*console.log("countzeros " + countzeros)
        console.log("countones " + countones)
        console.log("indicelastone " + indicelastone)
        console.log("indicefirstzero " + indicefirstzero) */

        let firstzeroimpact = countzeros - indicefirstzero - 1
        let lastoneimpact = countones - (n-1-indicelastone) - 1

        /*console.log("firstzeroimpact " + firstzeroimpact)
        console.log("lastoneimpact " + lastoneimpact)*/

        let maximpact = Math.max(firstzeroimpact,lastoneimpact)
        /*console.log("maximpact " + maximpact)
        console.log("score " + score)
        console.log("score + maximpact " + (score+ maximpact))*/
        console.log(score+ maximpact)
    }
}

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

function solve(n, arr) {
    let a = 0, b = 0, c = cal(n, arr)
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] === 0) {
            const temp = arr.slice()
            temp[i] = 1
            a = cal(n, temp)
            break
        }
    }
    for (let i = arr.length - 1; i >= 0; i--) {
        if (arr[i] === 1) {
            const temp = arr.slice()
            temp[i] = 0
            b = cal(n, temp)
            break
        }
    }
    return Math.max(a, b)
}
function cal(n, arr) {
    let zero = 0
    let r = 0
    for (let i = arr.length - 1; i >= 0; i--) {
        if (arr[i]) {
            r += zero
        } else {
            zero++
        }
    }
    return r
}


print(function(a, s) {

	const L = 40000;

	var i, j, sum, ans = 0,
		l = s.length,
		q = new Int32Array(L);

	for (i = 0; i < l; i++)
		for (j = i, sum = 0; j < l; j++)
			q[sum += s[j]]++;

	for (i = 1; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	if (a === 0)
		ans += ans + q[0] * q[0];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {
	var i, l = s.length,
		p = new Int32Array(l),
		sum = 0;

	for (i = 0; i < l; i++)
		p[i] = (sum += s[i]);

	p[-1] = 0;

	var q = new Int32Array(1e6);

	for (i = -1; i < l; i++)
		for (j = i + 1; j < l; j++)
			q[p[j] - p[i]]++;

	var ans = 0;
	if (a === 0) {
		ans += q[0] * q[0];
		for (i = 1; i < 1e6; i++) {
			if (q[i] > 0)
				ans += q[i] * q[0] * 2;
		}
		return ans;
	}

	for (i = 0; i < 1e6; i++)
		if (q[i] > 0 && a % i === 0 && a / i < 1e6)
			ans += q[i] * q[a / i];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {

	const L = 40000;

	var i, j, ans = 0,
		l = s.length,
		p = new Int32Array(L),
		q = new Int32Array(L);

	for (i = 0; i < l; i++)
		p[i + 1] = p[i] + s[i];

	for (i = 0; i <= l; i++)
		for (j = 0; j < i; j++)
			q[p[i] - p[j]]++;

	for (i = 1; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	if (a === 0)
		ans += ans + q[0] * q[0];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {

	const L = 81 * 4000 + 3;

	var i, j, ans = 0,
		l = s.length,
		p = new Int32Array(l),
		q = new Int32Array(L),
		sum = 0;

	for (i = 0; i < l; i++)
		p[i] = (sum += s[i]);

	p[-1] = 0;

	for (i = -1; i < l; i++)
		for (j = i + 1; j < l; j++)
			q[p[j] - p[i]]++;

	for (i = 1; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	if (a === 0)
		ans += ans + q[0] * q[0];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {
	const L = 81 * 4000 + 3;

	var i, j, ans = 0,
		l = s.length,
		p = new Int32Array(l),
		q = new Int32Array(L),
		sum = 0;

	for (i = 0; i < l; i++)
		p[i] = (sum += s[i]);

	p[-1] = 0;

	for (i = -1; i < l; i++)
		for (j = i + 1; j < l; j++)
			q[p[j] - p[i]]++;

	for (i = 0; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	if (a === 0) {
		ans += ans + q[0]*q[0];
	}

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {
	var i, l = s.length,
		p = new Int32Array(l),
		sum = 0;

	for (i = 0; i < l; i++) {
		p[i] = (sum += s[i]);
	}
	p[-1] = 0;

	var q = new Int32Array(1e6);

	for (i = -1; i < l; i++) {
		for (j = i + 1; j < l; j++) {
			q[p[j] - p[i]]++;
		}
	}

	var ans = 0;
	for (i = 0; i < 1e6; i++) {
		if (q[i] > 0 && a % i === 0 && a / i < 1e6) {
			ans += q[i] * q[a / i];
		}
	}

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {
	var i, l = s.length,
		p = new Int32Array(l),
		sum = 0;

	for (i = 0; i < l; i++)
		p[i] = (sum += s[i]);

	p[-1] = 0;

	var q = new Int32Array(1e6);

	for (i = -1; i < l; i++)
		for (j = i + 1; j < l; j++)
			q[p[j] - p[i]]++;

	var r=[];
	for(i=0;i<1e6;i++)
		if(q[i]>0)
			r.push(i);

	var ans=0;
	for(i=0;i<r.length;i++)
		for(j=i;j<r.length;j++)
			if(r[i]*r[j]===a)
				ans+=q[r[i]]*q[r[j]];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {
	const L = 81 * 4000 + 3;

	var i, j, ans = 0,
		l = s.length,
		p = new Int32Array(l),
		q = new Int32Array(L),
		sum = 0;

	for (i = 0; i < l; i++)
		p[i] = (sum += s[i]);

	p[-1] = 0;

	for (i = -1; i < l; i++)
		for (j = i + 1; j < l; j++)
			q[p[j] - p[i]]++;

	for (i = 0; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {

	const L = 40000;

	var i, j, sum, ans = 0,
		l = s.length,
		q = new Int32Array(L);

	for (i = 0; i < l; i++)
		for (j = i, sum = 0; j < l; j++)
			q[sum += s[i]]++;

	for (i = 1; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	if (a === 0)
		ans += ans + q[0] * q[0];

	return ans;

}(+readline(), readline().split('').map(Number)));

print(function(a, s) {
	const L = 81 * 4000 + 3;

	var i, j, ans = 0,
		l = s.length,
		p = new Int32Array(l),
		q = new Int32Array(L),
		sum = 0;

	for (i = 0; i < l; i++)
		p[i] = (sum += s[i]);

	p[-1] = 0;

	for (i = -1; i < l; i++)
		for (j = i + 1; j < l; j++)
			q[p[j] - p[i]]++;

	for (i = 0; i < L; i++)
		if (a % i === 0 && a / i < L)
			ans += q[i] * q[a / i];

	if (a === 0) {
		ans += ans + q[0];
	}

	return ans;

}(+readline(), readline().split('').map(Number)));


var n = readline();
var arr = readline().split(" ").map(v => +v.trim());
var a = [];
var k = 0;
for (i = 0; i < n; i++) {
    if (k < a.length) {
        a[k] = arr[i];
        ++k;
    } else {
        a.push(arr[i]);
        ++k;
    }
    while (k > 1) {
        if (a[k - 1] == a[k - 2]) {
            ++a[k - 2];
            --k;
        } else {
            break;
        }
    }
}
print(k)
for (i = 0; i < k; ++i) {
    print(a[i])
}

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

for(var i = 0; i < n; i = i + 1){
	stack.push(a[i]);
	//print(stack)
	while(stack.length >= 2 && stack[stack.length - 1] === stack[stack.length - 2]){
		var x = stack[stack.length - 1];
		//print(x)
		stack.pop();
		stack.pop();
		stack.push(x + 1);
	}
}
print(stack.length)
for(var i = 0; i < stack.length; i = i + 1){
	print(stack[i]);
}

n = Number(readline())
var a = readline().split(' ').map(function(x){return Number(x)});
var b = []
k = -1;
for (i = 0; i < n; i++) {
    k += 1
    b[k] = a[i];
    while (k >= 1 && b[k] == b[k - 1]) {
        k -= 1
        b[k] = b[k + 1] + 1
    }
}
s = ""
for (i = 0; i <= k; i++) {
    s += b[i] + ' '
}
print(k + 1)
print(s)

readline()
var list = readline().split(' ').map(function(string) {
    return {
        value: Number(string),
        previous: null,
        next: null
    }
})

for (var i = 0; i < list.length; ++i) {
    if (i > 0) {
        list[i].previous = list[i - 1]
    }
    if (i < list.length - 1) {
        list[i].next = list[i + 1]
    }
}

function d(x) {
    arr = []
    do {
        arr.push(x.value)
        x = x.next
    } while(x !== null)
    print(arr.length)
    print(arr.join(' '))
}

var node = list[0]
var didGoIn;
while (node.next !== null) {
    // d(node)
    didGoIn = false
    if (node.value === node.next.value) {
        node.value += 1
        node.next = node.next.next
        if (node.next !== null) {
            node.next.previous = node
        }
        if (node.previous !== null) {
            node = node.previous
        }
        didGoIn = true
    }
    if (!didGoIn && node.next !== null)  {
        node = node.next
    }
}

while(node.previous !== null) {
    node = node.previous
}

d(node)

stack = []
var n = +readline()
var a = readline().split(' ').map(function(v){return +v;});

for (var i = 0; i < n; ++i) {
   stack.push(a[i])
   while (stack.length >= 2) {
      var sz = stack.length
      if (stack[sz-1] == stack[sz-2]) {
         stack.pop()
         stack.push(stack.pop() + 1)
      } else {
         break
      }
   }
}
print(stack.length)
print(stack.join(" "))

var arr = readline().split(" ").map(v => +v.trim());
var n = arr[0];
var l = readline().split(" ").map(v => +v.trim());

que = []
que.push(l[0]);
for (i=1; i<n; i++)
{
    ok = 1;
    ne = l[i];
    while (ok == 1)
    {

        ok = 0;
        if(que.length > 0)
        {
            last = que.pop();
            if(last == ne)
            {
                ne = last + 1;
                ok = 1;
            }
            else
            {
                que.push(last);
            }
        }
    }
    que.push(ne);
}
print(que.length);
s = ""
for(i=0; i<que.length; i++)
{
     s = s + que[i] + " ";
}
print(s)

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

for(var i = 0; i < n; i = i + 1){
	stack.push(a[i]);
	//print(stack)
	while(stack.length >= 2 && stack[stack.length - 1] === stack[stack.length - 2]){
		var x = stack[stack.length - 1];
		//print(x)
		stack.pop();
		stack.pop();
		stack.push(x + 1);
	}
}

for(var i = 0; i < stack.length; i = i + 1){
	print(stack[i]);
}

var n = readline();
var arr = readline().split(" ").map(v => +v.trim());
var a = [];
var k = 0;
for (i = 0; i < n; i++) {
    if (k < a.length) {
        a[k] = arr[i];
        ++k;
    } else {
        a.push(arr[i]);
        ++k;
    }
    while (k > 1) {
        if (a[k - 1] == a[k - 2]) {
            ++a[k - 2];
            --k;
        } else {
            break;
        }
    }
}
for (i = 0; i < k; ++i) {
    print(a[i])
}

readline()
var list = readline().split(' ').map(function(string) {
    return {
        value: Number(string),
        previous: null,
        next: null
    }
})

for (var i = 0; i < list.length; ++i) {
    if (i > 0) {
        list[i].previous = list[i - 1]
    }
    if (i < list.length - 1) {
        list[i].next = list[i + 1]
    }
}

function d(x) {
    arr = []
    do {
        arr.push(x.value)
        x = x.next
    } while(x !== null)
    print(arr.length)
    print(arr.join(' '))
}

var node = list[0]
var didGoBack;
while (node.next !== null) {
    // d(node)
    didGoBack = false
    if (node.value === node.next.value) {
        node.value += 1
        node.next = node.next.next
        if (node.next !== null) {
            node.next.previous = node
        }
        if (node.previous !== null) {
            node = node.previous
            didGoBack = true
        }
    }
    if (!didGoBack && node.next !== null)  {
        node = node.next
    }
}

while(node.previous !== null) {
    node = node.previous
}

d(node)