var info = readline().split(' ').map(Number);
var Arr = readline().split(' ').map(Number);
var result = 0;
var turn = info[1];
for (var i=0; i<info[0]; i++) {
    if (Arr[i]<0 && turn>0) {
        Arr[i] *= -1;
        turn -= 1;
    }
}
Arr = Arr.sort(function(a, b){return a-b});
if (turn % 2 == 1) {
    Arr[0] *= -1;
}
for (i=0; i<info[0]; i++) {
    result += Arr[i];
}
print(result);

//Input
// var firstLine = "3 2"; var secondLine = "-1 -1 1"; // 3
// var firstLine = "3 1"; var secondLine = "-1 -1 1"; // 1
// var firstLine = "17 27"; var secondLine = "257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343"; // 81852
// var firstLine = "12 28"; var secondLine = "-6652 -6621 -6471 -5559 -5326 -4551 -4401 -4326 -3294 -1175 -1069 -43"; // 49488
// var firstLine = "4 1"; var secondLine = "218 3441 4901 7601"; // 15725
// var firstLine = "1 1"; var secondLine = "10000"; // -10000
// var firstLine = "1 2"; var secondLine = "-1"; // -1
// var firstLine = "2 1"; var secondLine = "0 1"; // 1
// var firstLine = "2 2"; var secondLine = "-1 0"; // 1
// var firstLine = "5 6"; var secondLine = "-3 -2 -1 5 6"; // 15
// var firstLine = "3 3"; var secondLine = "-50 -10 30"; // 70
// var firstLine = "4 4"; var secondLine = "-100 -90 -80 1"; // 269
// var firstLine = "6 4"; var secondLine = "-6 -3 -2 1 2 3"; // 15

var firstLine = readline(); var secondLine = readline();

retorno = eval(firstLine, secondLine);

//Solution
function eval(firstLine, secondLine){
    var tmp = firstLine.split(" ").map(function(x){ return parseInt(x)});
    var n = tmp[0] ; var k = tmp[1];
    var seq = secondLine.split(" ").map(function(x){ return parseInt(x)});

    write(maximizeIncomes(n, k, seq));
    // console.log(maximizeIncomes(n, k, seq));
};

function maximizeIncomes(n, k, seq){
    var totalSum = 0;
    var minAbsValue = 0;

    for(var i = 0 ; i < n ; i++){
        if(i == 0){
            minAbsValue = Math.abs(seq[i]);
        } else{
            if(minAbsValue > Math.abs(seq[i])){
                minAbsValue = Math.abs(seq[i]);
            };
        };

        if(totalSum < (totalSum + seq[i]) ){
            totalSum += seq[i];
        } else if(k > 0){
            totalSum += (seq[i] * -1 );
            k--;
        } else{
            totalSum += seq[i];
        };
    };

    if(k > 0){
        totalSum += (2*minAbsValue * -(k%2));
    };
    return totalSum;
};


//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
var MAX = 1000000;
var M = Array(MAX);
var R = Array(MAX);
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var _ = _a[_i];
    var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];
    var a = readline();
    M.fill(0, 0, m);
    R.fill(0, 0, m);
    var sumR = 0;
    var ans = [];
    var cur = 0;
    var pos = 0;
    for (var i = 0; i < n; i += 1) {
        for (var j = 0; j < m; j += 1) {
            if (a[pos] === '1') {
                if (!R[j]) {
                    R[j] = 1;
                    sumR += 1;
                }
                cur += 1;
            }
            cur -= +!!(pos >= m && a[pos - m] === '1');
            M[j] += +!!cur;
            ans.push(M[j] + sumR);
            pos += 1;
        }
    }
    print(ans.join(' '));
}

//import { readline, print } from '@ip-algorithmics/codeforces-io';
/*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++];
}
*/
var main = function () {
    var t = +readline();
    //t = 10;
    var MAX = 1000000;
    var f = Array(MAX);
    var M = Array(MAX);
    var R = Array(MAX);
    var temp = '';
    for (var i = 0; i < MAX; i += 1)
        temp += Math.random() < 0.5 ? '1' : '0';
    root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
        var _ = _a[_i];
        var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];
        //let n = 1; let m = 1000;
        var a = readline();
        //let a = temp;
        f[-1] = 0;
        f.fill(0, 0, m * n);
        M.fill(0, 0, m);
        R.fill(0, 0, m);
        var sumR = 0;
        var ans = '';
        var pos = 0;
        for (var i = 0; i < n; i += 1) {
            for (var j = 0; j < m; j += 1) {
                f[pos] = f[pos - 1];
                if (a[pos] === '1') {
                    if (!R[j]) {
                        R[j] = 1;
                        sumR += 1;
                    }
                    f[pos] += 1;
                }
                if (a[pos - m] === '1') {
                    f[pos] -= 1;
                }
                if (f[pos]) {
                    M[j] += 1;
                }
                //ans.push(M[j] + sumR);
                ans += "".concat(M[j] + sumR, " ");
                pos += 1;
            }
        }
        //console.log(ans);
        print(ans);
    }
};
main();

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

function solve(n, m, str) {
    const ans = Array(str.length)
    //
    const col = Array(m).fill(0)
    let p = 0
    for (let i = 0; i < str.length; i++) {
        ans[i] = i ? ans[i - 1] : 0
        if (!col[p] && str[i] === '1') {
            col[p] = 1
            ans[i]++
        }
        p = (p - 1 + m) % m
    }
    //
    const pre = []
    for (let i = 0; i < str.length; i++) {
        pre[i] = i ? pre[i - 1] : 0
        pre[i] += +str[i]
    }
// console.log(pre)
    //
    p = 0
    const row = Array(m).fill(0)
    for (let i = 0; i < str.length; i++) {
        row[p] += (pre[i] - (pre[i - m] || 0)) > 0 ? 1 : 0
        ans[i] += row[p]
        p = (p + 1) % m
    }
    return ans.join(' ')
}

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

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

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

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

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, m] = ra();
  let s = readline();
  LT({n, m, s});
  // PROCESSING:
  let cols = new Array(Math.max(n, m)).fill(0)
  let rownum = new Array(Math.max(n, m)).fill(0)
  let colnum = 0;
  let nm = n*m;
  let las = -nm;
  let ans = [];
  for (let i=0; i<nm; i++){
    if (s[i]=='1'){
      las = i;
      if (cols[i%m]==0){
        cols[i%m] = 1;
        colnum++;
      }
    }
    if (i-las<m){
      rownum[i%m]++;
    }
    ans.push(rownum[i%m]+colnum);
  }
  return ans;
};

//import { readline, print as print_ } from '@ip-algorithmics/codeforces-io';
//let temp: any[] = [];
//let write = (...args: any[]) => temp.push(...args);

//const { write } = require("fs");

//let print = (...args: any[]) => { print_([...temp, ...args].join(' ')); temp = []; }
//let s = read('input.txt').split('\n');
//let readline = ((i) => () => s[i++])(0);
var t = +readline();
var MAX = 1000000;
var f = Array(MAX);
var M = Array(MAX);
var R = Array(MAX);
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var _ = _a[_i];
    var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];
    var a = readline();
    var count = 0;
    for (var i = -1; i < n; i += 1) {
        for (var j = -1; j < m; j += 1) {
            f[i * m + j] = 0;
        }
    }
    for (var i = 0; i < m; i += 1) {
        M[i] = 0;
    }
    for (var i = 0; i < m; i += 1) {
        R[i] = 0;
    }
    var sumR = 0;
    var ans = [];
    for (var i = 0; i < n; i += 1) {
        for (var j = 0; j < m; j += 1) {
            f[i * m + j] = f[i * m + j - 1];
            if (a[i * m + j] === '1') {
                if (!R[j]) {
                    R[j] = 1;
                    sumR += 1;
                }
                f[i * m + j] += 1;
            }
            if (a[(i - 1) * m + j] === '1') {
                f[i * m + j] -= 1;
            }
            if (f[i * m + j]) {
                M[j] += 1;
            }
            //ans.push(M[j] + sumR);

            if (t !== 2)
            write(`${M[j] + sumR} `);
        }
    }
    //print(ans.join(' '));
    print();
}

//import { readline, print as print_ } from '@ip-algorithmics/codeforces-io';
//let temp: any[] = [];
//let write = (...args: any[]) => temp.push(...args);

//const { write } = require("fs");

//let print = (...args: any[]) => { print_([...temp, ...args].join(' ')); temp = []; }
//let s = read('input.txt').split('\n');
//let readline = ((i) => () => s[i++])(0);
var t = +readline();
var MAX = 1000000;
var f = Array(MAX);
var M = Array(MAX);
var R = Array(MAX);
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var _ = _a[_i];
    var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];
    var a = readline();
    var count = 0;
    for (var i = -1; i < n; i += 1) {
        for (var j = -1; j < m; j += 1) {
            f[i * m + j] = 0;
        }
    }
    for (var i = 0; i < m; i += 1) {
        M[i] = 0;
    }
    for (var i = 0; i < m; i += 1) {
        R[i] = 0;
    }
    var sumR = 0;
    var ans = [];
    for (var i = 0; i < n; i += 1) {
        for (var j = 0; j < m; j += 1) {
            f[i * m + j] = f[i * m + j - 1];
            if (a[i * m + j] === '1') {
                if (!R[j]) {
                    R[j] = 1;
                    sumR += 1;
                }
                f[i * m + j] += 1;
            }
            if (a[(i - 1) * m + j] === '1') {
                f[i * m + j] -= 1;
            }
            if (f[i * m + j]) {
                M[j] += 1;
            }
            //ans.push(M[j] + sumR);

            if (m !== 500000)
            write(`${M[j] + sumR} `);
        }
    }
    //print(ans.join(' '));
    print();
}

//import { readline, print as print_ } from '@ip-algorithmics/codeforces-io';
//let temp: any[] = [];
//let write = (...args: any[]) => temp.push(...args);
//let print = (...args: any[]) => { print_([...temp, ...args].join(' ')); temp = []; }
var t = +readline();
var MAX = 1000000;
var f = Array(MAX);
var M = Array(MAX);
var R = Array(MAX);
root: for (var _i = 0, _a = Array.from(Array(t).keys()); _i < _a.length; _i++) {
    var _ = _a[_i];
    var _b = readline().split(' ').map(function (v) { return +v; }), n = _b[0], m = _b[1];
    var a = readline();
    var count = 0;
    for (var i = -1; i < n; i += 1) {
        for (var j = -1; j < m; j += 1) {
            f[i * m + j] = 0;
        }
    }
    for (var i = 0; i < m; i += 1) {
        M[i] = 0;
    }
    for (var i = 0; i < m; i += 1) {
        R[i] = 0;
    }
    var sumR = 0;
    var ans = [];
    for (var i = 0; i < n; i += 1) {
        for (var j = 0; j < m; j += 1) {
            f[i * m + j] = f[i * m + j - 1];
            if (a[i * m + j] === '1') {
                if (!R[j]) {
                    R[j] = 1;
                    sumR += 1;
                }
                f[i * m + j] += 1;
            }
            if (a[(i - 1) * m + j] === '1') {
                f[i * m + j] -= 1;
            }
            if (f[i * m + j]) {
                M[j] += 1;
            }
            //ans.push(M[j] + sumR);
            write(M[j] + sumR);
        }
    }
    //print(ans.join(' '));
    print();
}


var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var l = 0;
    var t = +lines[l++]
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        var arr = lines[l++].trim().split(' ').map(Number)
        console.log(solve(arr))
    }
});

function solve(arr) {
    const sum = arr.reduce((s, x) => s + x, 0)
    const r = sum % arr.length
    // const avg = (sum - r) / arr.length

    return arr.reduce((s, x, i) => {
        return s + (i < r ? arr.length - r : 0)
    }, 0)
}

function getSum(arr) {
    let sum = 0
    arr.forEach((a, i) => {
        arr.forEach((b, j) => {
            if (j > i) sum += Math.abs(a - b)
        })
    })
    return sum
}

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

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

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

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

		const ans = sum%n * (n - sum%n);

		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] = 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 sum = 0;
		for(var i = 0; i < N; i++){
			sum += list[i];
		}
		var div = sum % N;
		myout((N - div) * div);
	}
}

function isZero(num) {
   if (typeof num === 'bigint') {
      return num === 0n;
   }
   return num === 0;
}
function div(a, b) {
   if (typeof a !== typeof b) {
      throw new Error('Different types on division');
   }
   if (typeof a === 'bigint') {
      return a / b;
   }
   return Math.floor(a / b);
}

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

function lcm(x, y) {
   return div(x * y, gcd(x, y));
}

function allIndexOf(arr, value) {
   var index = arr.indexOf(value)
   var ans = [];
   while (index !== -1) {
      ans.push(index);
      index = arr.indexOf(value, index + 1);
   }
   return ans;
}

function solve() {
   const n = BigInt(read());
   let sum = 0n;
   readArray((x) => {
      sum += BigInt(x);
   });
   const rem = sum % n;
   write(rem * (n - rem));
}

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

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

var tests = parseInt(readline());

for (var t = 0; t < tests; t++) {
    var n = parseInt(readline());
    var sum = readline().split(" ").map(Number).reduce((acc, input) => acc + input);

    if (sum === n || sum === 0) {
        print(0)
    } else {
        var abv;
        if (sum > n) {
            abv = (sum % n)
        } else if (sum < n) {
            abv = sum;
        }

        print((n - abv) * abv);
    }
}

var input = readline();
for(var i = 0; i < input; i ++) {
    var num = readline();
    var a = readline().split(' ').map(Number);
    var sum = a.reduce((x, y) => x + y, 0);
    var ans = (num - sum % num) * (sum % num);
    print(ans)
}


var n, a;
    var charSet;

    function cToI(c) {
        return c.charCodeAt(0) - 97;
    }

    function Node() {
        var ch = new Array(26).fill(null);
        return {
            index: 0,
            children: ch,
        }
    }

    function insert(root, k, index) {
        var l = k.length;
        var node = root;
        for (var i = 0; i < l; i++) {
            var c = k.charAt(i);
            if (!charSet.has(c)) {
                return;
            }
            if (!node.children[cToI(c)]) {
                var newNode = new Node();
                node.children[cToI(c)] = newNode;
            }
            node = node.children[cToI(c)];
        }
        node.index = index;
    }

    function search(root, start) {
        var node = root;
        var i = start;
        var lastEnd = -1;
        var lastIndex = 0;
        while (i < a.length) {
            var c = a.charAt(i);
            if (node.children[cToI(c)]) {
                node = node.children[cToI(c)];
                if (node.index) {
                    lastEnd = i;
                    lastIndex = node.index;
                }
            } else {
                break;
            }
            i++;
        }

        return [lastEnd, lastIndex];
    }

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        a = readline();
        charSet = new Set();
        for (var i = 0; i < a.length;i++) {
            charSet.add(a.charAt(i));
        }
        n = parseInt(readline());
        var root = new Node();
        for (var i = 1; i <= n; i++) {
            var k = readline();
            insert(root, k, i);
        }
        var pf = [];
        for (var i = 0; i < a.length; i++) {
            pf.push(search(root, i));
        }

        var start = 0;
        var end = 0;
        var ans = [];
        var exist = true;
        var totalMax = -1;
        while(start < a.length) {
            var max = totalMax;
            var maxIndex = -1;
            for (var i = start; i <= end; i++) {
                var match = pf[i];
                if (match[0] == -1) {
                    continue;
                }
                if (match[0] > max) {
                    max = match[0];
                    maxIndex = i;
                }
            }
            if (max == totalMax) {
                exist = false;
                break;
            }
            ans.push([pf[maxIndex][1], maxIndex+1]);
            if (max == a.length-1) {
                break;
            }
            start = end+1;
            end = Math.min(max+1, a.length-1);
            totalMax = max;
        }
        if (!exist) {
            print(-1);
        } else {
            print(ans.length);
            for (var i = 0; i < ans.length; i++) {
                print(ans[i].join(' '));
            }
        }
    }

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

function solve(str, arr) {
    const m = {}
    for (let j = 0; j < arr.length; j++) {
        const s = arr[j]
    // }
    // for (let s of arr) {
        for (let i = 0; i < s.length; i++) {
            const c = s[i]
            m[c] = m[c] || []
            m[c].push([s.length - 1 - i, j])
        }
    }
    for (let c in m) {
        m[c].sort((a, b) => b[0] - a[0])
    }
// console.log(m)
    // arr.sort((a, b) => b.length - a.length)
    // for (let s of arr) {
    //     const ch = s[0]
    //     m[ch] = m[ch] || []
    //     m[ch].push(s)
    // }
    let k = 0
    const ans = []
    for (let i = 0; i < str.length;) {
        const ch = str[i]
        if (!m[ch]) return -1
        let found = 0
        for (let [add, w] of m[ch]) {
            const s = arr[w]
            const j = i + add
            const start = j + 1 - s.length
                // console.log(start, j)
            if (start < 0 || j >= str.length) continue
                // console.log(str.slice(j + 1 - s.length, j + 1), s)
            if (str.slice(j + 1 - s.length, j + 1) === s) {
                found = 1
                k++
                i = j + 1
                ans.push(w + 1 + ' ' + (start + 1))
                break
            }
        }
        if (!found) return -1
    }
    return k + '\n' + ans.join('\n')
}

'use strict';

function solve(n, a, s) {
  const m = s.length;
  const g = Array.from({
    length: m
  }, () => new Array(n).fill(0));
  for (let i = m - 1; i >= 0; i--) {
    next: for (let j = 0; j < n; j++) {
      for (let k = 0; k < a[j].length; k++) {
        if (a[j][a[j].length - k - 1] !== s[i - k]) continue next;
      }
      g[i][j] = 1;
    }
  }
  const dp = new Array(m).fill(Infinity),
        p = [],
        p1 = [];
  for (let i = 0; i < m; i++) {
    let t = -1;
    for (let j = 0; j < n; j++) {
      if (g[i][j]) {
        if (t === -1 || a[t].length < a[j].length) t = j;
      }
    }
    p[i] = t;
    if (t !== -1) {
      for (let j = i - a[t].length; j < i; j++) {
        var _dp$j;
        if (dp[i] > ((_dp$j = dp[j]) !== null && _dp$j !== void 0 ? _dp$j : 0) + 1) {
          var _dp$j2;
          dp[i] = ((_dp$j2 = dp[j]) !== null && _dp$j2 !== void 0 ? _dp$j2 : 0) + 1;
          p1[i] = j;
        }
      }
    }
  }
  if (dp[m - 1] === Infinity) return -1;
  let res = [];
  for (let i = m - 1; i >= 0; i = p1[i]) {
    res.push(p[i] + 1 + ' ' + (i - a[p[i]].length + 2));
  }
  return `${dp[m - 1]}\n${res.join('\n')}`;
}

async function main(r) {
  const rn = async () => Number(await r());
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const s = await r();
      const n = await rn();
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push(await r());
      }
      res[i] = solve(n, a, s);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

var n, a;
    var charSet;

    function cToI(c) {
        return c.charCodeAt(0) - 97;
    }

    function Node() {
        var ch = new Array(26).fill(null);
        return {
            index: 0,
            children: ch,
        }
    }

    function insert(root, k, index) {
        var l = k.length;
        var node = root;
        for (var i = 0; i < l; i++) {
            var c = k.charAt(i);
            if (!charSet.has(c)) {
                return;
            }
            if (!node.children[cToI(c)]) {
                var newNode = new Node();
                node.children[cToI(c)] = newNode;
            }
            node = node.children[cToI(c)];
        }
        node.index = index;
    }

    function search(root, start) {
        var node = root;
        var i = start;
        var lastEnd = -1;
        var lastIndex = 0;
        while (i < a.length) {
            var c = a.charAt(i);
            if (node.children[cToI(c)]) {
                node = node.children[cToI(c)];
                if (node.index) {
                    lastEnd = i;
                    lastIndex = node.index;
                }
            } else {
                break;
            }
            i++;
        }

        return [lastEnd, lastIndex];
    }

    var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        a = readline();
        charSet = new Set();
        for (var i = 0; i < a.length;i++) {
            charSet.add(a.charAt(i));
        }
        n = parseInt(readline());
        var root = new Node();
        for (var i = 1; i <= n; i++) {
            var k = readline();
            insert(root, k, i);
        }
        var pf = [];
        for (var i = 0; i < a.length; i++) {
            pf.push(search(root, i));
        }

        var start = 0;
        var end = 0;
        var ans = [];
        var exist = true;
        while(start < a.length) {
            var max = -1;
            var maxIndex = -1;
            for (var i = start; i <= end; i++) {
                var match = pf[i];
                if (match[0] == -1) {
                    continue;
                }
                if (match[0] > max) {
                    max = match[0];
                    maxIndex = i;
                }
            }
            if (max == -1) {
                exist = false;
                break;
            }
            ans.push([pf[maxIndex][1], maxIndex+1]);
            if (max == a.length-1) {
                break;
            }
            start = end+1;
            end = Math.min(max+1, a.length-1);
        }
        if (!exist) {
            print(-1);
        } else {
            print(ans.length);
            for (var i = 0; i < ans.length; i++) {
                print(ans[i].join(' '));
            }
        }
    }


var s=readline().split('')
res=0
var alph="abcdefghijklmnopqrstuvwxyz"
for (var i=0;i<alph.length;i++)
{
    kol=0
    for (var j=0;j<s.length;j++)
    {
        if (alph[i]==s[j])
        {
            kol^=1
        }
    }
    if (kol)
    {
        res++
    }
}
print((!res||res%2)?"First":"Second")

var ans = 0,
	A = 'A'.charCodeAt(),
	z = 'z'.charCodeAt(),
	cnt = new Int32Array(128),
	s = readline();

for (var i = 0; i < s.length; i++)
	cnt[s.charCodeAt(i)]++;

for (var i = A; i <= z; i++)
	ans += cnt[i] % 2;

print(ans == 0 || ans % 2 === 1 ? 'First' : 'Second');

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

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

function main() {
  const str = readLine();
  let [map, count1] = [{}, 0];

  for (let i = 0; i < str.length; i++) {
    const char = str[i];
    map[char] = (map[char] || 0) + 1;
  }

  for (let key in map) {
    if (map[key] % 2 === 1) count1++;
  }

  if (count1 === 0) console.log("First");
  else if (count1 % 2 === 0) console.log("Second");
  else console.log("First");
}

;(function () {

	print((function (s) {

		var m = {};
		for (var i = 0, _i = s.length; i < _i; i++) m[s[i]] = m[s[i]] ? m[s[i]] + 1 : 1;
		m = (function () {
			var ret = [0, 0];
			for (var key in m) ret[m[key]%2]++;
			return ret[1] === 0 ? 1 : ret[1];
		})()

		return m % 2 ? 'First' : 'Second';
	})(readline()));

}).call(this);

;(function () {

	print((function (s) {

		var m = {};
		for (var i = 0, _i = s.length; i < _i; i++) m[s[i]] = m[s[i]] ? m[s[i]] + 1 : 1;
		m = (function () {
			var ret = [0, 0];
			for (var key in m) ret[m[key]%2]++;
			return ret[0] + ret[1];
		})()

		return m % 2 ? 'Second' : 'First';
	})(readline()));

}).call(this);


"use strict"

let iter = parseInt(readline());

for(let i = 0; i < iter; i++){
    let length = parseInt(readline());
    let arr = readline().split(" ").map(x => parseInt(x));
    let points = 0;
    arr.sort((a, b) => a - b);

    for(let j = 0; j < length; j++) {
        if(j % 2 === 0 && arr[length - j - 1] % 2 === 0){
            points += arr[length - j - 1];
        } else if (j % 2 === 1 && arr[length - j - 1] % 2 === 1) {
            points -= arr[length - j - 1];
        }
    }

    if(points > 0){
        print("Alice");
    } else if(points === 0){
        print("Tie");
    } else {
        print("Bob");
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var n = Number(readline());
        var answer = []
        var xx = 0
        var array = readline().split(' ').map((x, i) => {
            xx = Number(x)
            return xx
        });
        var sorted = array.sort((a, b) => a - b)
        // console.log(sorted)
        // console.log(array)
        var ii = n - 1
        var i = 0
        var sumA = 0
        var sumB = 0
        var smod2 = 0
        var i2 = 0
        while (ii >= 0) {
            smod2 = sorted[ii] % 2
            i2 = i % 2
            if (smod2 === 0 && i2 === 0) sumA += sorted[ii]
            if (smod2 % 2 === 1 && i2 === 1) sumB += sorted[ii]
            ii--
            i++
        }

        if (sumA > sumB) return console.log('Alice')
        if (sumA < sumB) return console.log('Bob')
        console.log('Tie')
    })

}

function swap(items, leftIndex, rightIndex) {
    var temp = items[leftIndex];
    items[leftIndex] = items[rightIndex];
    items[rightIndex] = temp;
}

function partition(items, left, right) {
    var pivot = items[Math.floor((right + left) / 2)], //middle element
        i = left, //left pointer
        j = right; //right pointer
    while (i <= j) {
        while (items[i] < pivot) {
            i++;
        }
        while (items[j] > pivot) {
            j--;
        }
        if (i <= j) {
            swap(items, i, j); //sawpping two elements
            i++;
            j--;
        }
    }
    return i;
}

function quickSort(items, left, right) {
    var index;
    if (items.length > 1) {
        index = partition(items, left, right); //index returned from partition
        if (left < index - 1) { //more elements on the left side of the pivot
            quickSort(items, left, index - 1);
        }
        if (index < right) { //more elements on the right side of the pivot
            quickSort(items, index, right);
        }
    }
    return items;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}
function getValue() {
  return parseInt(readline());
}
let mod = BigInt(1e9 + 7);
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    arr.sort((a, b) => b - a);
    let a = 0,
      b = 0,
      k = 1;
    for (let i = 0; i < n; i++, k = !k) {
      if (k) a += arr[i] % 2 === 0 ? arr[i] : 0;
      else b += arr[i] % 2 === 1 ? arr[i] : 0;
    }
    if (a === b) console.log("Tie");
    else if (a > b) console.log("Alice");
    else console.log("Bob");
  }
};
solve();

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

const calculate = (n, a) => {
  a = a.sort((a, b) => b - a)
  let mb = 0
  let ma = 0

  a.forEach((val, index) => {
    if (index % 2 === 0) {
      ma += val % 2 === 0 ? val : 0
    } else {
      mb += val % 2 === 0 ? 0 : val
    }
  })

  if (ma < mb) {
    return 'Bob'
  } else if (ma > mb) {
    return 'Alice'
  } else {
    return 'Tie'
  }
}

let index = -1
let maxRound = 0
let round = 0

let n, a
let answer = []

readline.on('line', line => {
  if (index === -1) {
    maxRound = Number(line)
    index = 0
  } else {
    const mode = index % 2
    if (mode === 0) {
      n = Number(line)
    } else if (mode === 1) {
      a = line.split(' ').map(val => Number(val))
      answer.push(calculate(n, a))
      round++
      if (round === maxRound) {
        readline.close()
        console.log(answer.join('\n'))
        return
      }
    }
    index++
  }
})

// chainNumberList, cList, aList, bList
// console.log(calculate(4, [3, 4, 3, 3], [-1, 1, 2, 2], [-1, 2, 2, 3]))

let i = ''
const { EOL } = require('os')
process.stdin.on('data', c => (i += c))
process.stdin.on('end', () => {
  const lines = i.split(EOL).filter(line => line)
  console.log(processInput(lines))
})

const processInput = lines => {
  return lines
    .slice(1)
    .filter((_, i) => i % 2)
    .map(line => line.split(' ').map(n => +n))
    .map(nums => {
      const sortedNums = nums.sort((a, b) => b - a)
      const alice = sortedNums
        .filter((num, i) => !(i % 2) && num % 2 === 0)
        .reduce((a, b) => a + b, 0)
      const bob = sortedNums
        .filter((num, i) => i % 2 && num % 2 === 1)
        .reduce((a, b) => a + b, 0)
      if (alice > bob) return 'Alice'
      else if (bob > alice) return 'Bob'
      else return 'Tie'
    })
    .join(EOL)
}

const game = a => {
  a.sort((i, j) => j - i);
  let res = 0;
  for (let i = 0; i < a.length; i++) {
    if (a[i] % 2 == 0 && i % 2 == 0) res += a[i];
    else if (a[i] % 2 == 1 && i % 2 == 1) res -= a[i];
  }
  return res;
};

const main = () => {
  let test = parseInt(readline());
  while (test--) {
    readline();
    const a = readline()
      .split(" ")
      .map(s => parseInt(s));
    const res = game(a);
    if (res == 0) console.log("Tie");
    else if (res > 0) console.log("Alice");
    else console.log("Bob");
  }
};

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

let inputString = "";
let currentLine = 0;

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

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

const readline = () => {
  return inputString[currentLine++];
};

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const x = readline();

  for (let i = 0; i < x; i++) {
    let n = readline();
    let arr = readline().split(' ').map(x => +x);

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

    let aliceSum = 0;
    let bobSum = 0;

    for (let i = 0; i <= n; i+=2) {
      if (arr[i] % 2 === 0) {
        aliceSum += arr[i];
      }
      if (arr[i+1] && arr[i+1] % 2 !== 0) {
        bobSum += arr[i+1];
      }
    }

    if (aliceSum === bobSum) {
      console.log('Tie');
    } else if (aliceSum > bobSum) {
      console.log('Alice');
    } else {
      console.log('Bob');
    }
  }
}

'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 getArray(str) {
    return str.split(' ').map(x => Number(x));
}

function getInt(str) {
    return Number(str);
}

function getStrArray(str) {
    return str.split(' ').map(x => x);
}

function create2DArray(rows) {
    var arr = [];

    for (var i = 0; i < rows; i++) {
        arr[i] = [];
    }

    return arr;
}
// ---------------------------------------

function main() {
    let t = getInt(readline());
    while (t--) {
        let len = getInt(readline());
        let arr = getArray(readline());
        arr  = arr.sort((a, b) => b-a);
        let score1 = 0;
        let score2 = 0;
        for(let i=0; i<len; i++) {
            if(i%2 === 0) {
                if (arr[i] % 2 === 0) {
                    score1 += arr[i]
                }
            } else {
                if (arr[i] % 2 !== 0) {
                    score2 += arr[i]
                }
            }
        }
        if(score1 > score2) {
            console.log('Alice');
        } else if (score1 < score2) {
            console.log('Bob');
        } else {
            console.log('Tie');
        }
    }
}

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var sum = 0;
		for(var j = 0; j < N; j++){
			if(j % 2 == 0){
				if(list[j] % 2 == 0){
					sum += list[j];
				}
			}else{
				if(list[j] % 2 == 1){
					sum -= list[j];
				}
			}
		}
		if(sum > 0){
			myout("Alice");
		}else if(sum < 0){
			myout("Bob");
		}else{
			myout("Tie");
		}
	}
}

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

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

function main() {
	let t = +readLine();
	while (t--) {
		const len = +readLine();
		const [evens, odds] = [[], []];
		const arr = readLine()
			.split(' ')
			.map((n) => {
				n = Number(n);
				if (n % 2 === 0) evens.push(n);
				else odds.push(n);
				return n;
			});
		evens.sort((a, b) => a - b);
		odds.sort((a, b) => a - b);
		let [counta, countb] = [0, 0];

		let i = 1;
		while (evens.length || odds.length) {
			const [evenTop, oddTop] = [evens[evens.length - 1] || 0, odds[odds.length - 1] || 0];
			const max = Math.max(evenTop, oddTop);
			if (i % 2 !== 0) {
				// alice
				if (max === evenTop) {
					counta += evenTop;
					evens.pop();
				} else odds.pop();
			} else {
				// bob
				if (max === oddTop) {
					countb += oddTop;
					odds.pop();
				} else evens.pop();
			}
			i++;
		}
		if (counta > countb) console.log('Alice');
		else if (counta < countb) console.log('Bob');
		else console.log('Tie');
	}
}

let i = '';
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);

    const t = parseInt(lines[0]);

    for (let i = 1; i <= t * 2; i += 2) {
        const n = parseInt(lines[i]);
        const arr = lines[i + 1].split(' ').map(num => parseInt(num));

        console.log(solve(n, arr));
    }
});

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

    let alice = 0;
    let bob = 0;

    for (let i = 0; i < arr.length; i++) {
        if (arr[i] % 2 === 0 && i % 2 === 0) {
            alice += arr[i];
        } else if (arr[i] % 2 === 1 && i % 2 === 1) {
            bob += arr[i];
        }
    }

    if (alice > bob) {
        return 'Alice';
    } else if (bob > alice) {
        return 'Bob';
    } else {
        return 'Tie';
    }
}

let i = '';
process.stdin.on('data', (c) => (i += c));
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL).filter((line) => line);
    console.log(processInput(lines));
});

const processInput = (lines) => {
    return lines
        .slice(1)
        .filter((_, i) => i % 2)
        .map((line) => line.split(' ').map((n) => +n))
        .map((nums) => {
            const sortedNums = nums.sort((a, b) => b - a);
            let alice = 0,
                bob = 0;
            for (let i = 0; i < sortedNums.length; i++) {
                if (i % 2 === 0) {
                    if (sortedNums[i] % 2 === 0) {
                        alice += sortedNums[i];
                    }
                } else {
                    if (sortedNums[i] % 2 === 1) {
                        bob += sortedNums[i];
                    }
                }
            }
            return alice > bob ? 'Alice' : alice < bob ? 'Bob' : 'Tie';
        })
        .join('\n');
};


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

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

function main() {
  let t = +readLine();
  while (t--) {
    const [x, y] = readLine().split(" ").map(Number);
    let diff = Math.abs(x - y);
    if (diff > 0) diff = diff - 1;
    console.log(x + y + diff);
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var x = one[0];
		var y = one[1];
		var count = 0;
		if(x > 0 && y > 0){
			count = Math.min(x, y) * 2;
			x -= count / 2;
			y -= count / 2;
		}

		if(x > 0){
			count += x * 2 - 1;
		}else if(y > 0){
			count += y * 2 - 1;
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],a=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return s[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:a,runEachTest:t=>{a((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let[t,e]=i.default.nextNumbers(),r=2*[t,e].min(),n=[t,e].max()-[t,e].min();n>0&&(r+=2*n-1),i.default.puts(r)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [x, y] = io.nextNumbers()
//
//   let cnt = [x, y].min() * 2
//
//   let d = [x, y].max() - [x, y].min()
//
//   if (d > 0) {
//     cnt += d * 2 - 1
//   }
//
//   io.puts(cnt)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

/*
 * File Created: Sunday, 29th November 2020 9:28:45 pm
 * Author: Lukas Rimkus (lukasrimkuslg@gmail.com)
 */

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

let data = '';
let currentLine = 0;

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

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

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

        while(testCases--) {

            const [n, m ] = get_ints();

            const res = robot(n,m);

            console.log(res);
        }
    });

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

function readLine() {
    return data[currentLine++];
}
function robot(x ,y)
{
    //i - 2 j - 2
    return 2*(x > y ? x : y) - (x != y);
}

module.exports = robot

///https://codeforces.com/problemset/problem/1452/A

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

let inputString = '';

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

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

    main(inputString);
});

function main(fileContents) {//input lines as an array
    const amoutOfInputsForTheProgram = fileContents.splice(0,1);
    const listOfEndpointsForRobot = [...fileContents];

    listOfEndpointsForRobot
        .map((endpoints)=>endpoints.split(" "))
        .map((endpoints)=>{
           const diffBetweetVertAndHorizontal = Math.abs(parseInt(endpoints[0])-parseInt(endpoints[1]));
           return parseInt(endpoints[0])+parseInt(endpoints[1])
               +(diffBetweetVertAndHorizontal > 0 ? (diffBetweetVertAndHorizontal-1) : 0)
        })
        .forEach(x=>console.log(x));

}

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

let inputString = '';
let currentLine = 0;

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

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

    A();
});

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

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

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

    return a;
}

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

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const x = readline();
  var answer = []
  Array(Number(x)).fill(1).map((t, i)=>{
    var line2 = readline().split( ' ').map(x=>Number(x));
    // console.log(typeof line2)
    // line2 = line2.map(x=>Number(x))
    if(Math.max(line2[0],line2[1]) === 0) return console.log(0)
    if(line2[0] === line2[1]) return console.log(line2[1]*2)
    console.log(Math.max(line2[0],line2[1])*2-1)
    // answer[i] = Math.max(line2[0],line2[1])*2-1
  })
}
function foo(x) {
  // process.stdout.write("hello: ");   // without auto '\n' (newline)

  console.log(x);  // with auto '\n' (newline)
}

function task(input){
	let ia = input.trim().split('\n');
	let t = +ia.shift();
	for (let i = 0; i < t; i++) {
		let x = [], [X, Y] = ia.shift().split(' ').map((el) => +el), d = Math.abs(X - Y)
		x = X + Y + (d>1 ? (d-1) : 0)
		console.log(x)
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', _ => {
    task(inputString);
});

var tc = parseInt(readline());
for (; tc--;){
  var ar = readline().split(' ').map(x => +x);
  var a = ar[0], b = ar[1];
  var mn = Math.min(a, b);
  var mx = Math.max(a, b);

  print(mn * 2 + (mx - mn) * 2 - (mx - mn > 0 ? 1 : 0));
}

function task(input){
	let ia = input.trim().split('\n');
	let t = +ia.shift();
	for (let i = 0; i < t; i++) {
		let x = [], [X, Y] = ia.shift().split(' ').map((el) => +el), d = Math.abs(X - Y)
		x = X + Y + (d>1 ? (d-1) : 0)
		console.log(`Case #${i+1}: `+x)
	}
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', _ => {
    task(inputString);
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const x = readline();
  var answer = []
  Array(Number(x)).fill(1).map((t, i)=>{
    var line2 = readline();
    if(Math.max(line2[0],line2[1]) == 0) return console.log(0)
    console.log(Math.max(line2[0],line2[1])*2-1)
    // answer[i] = Math.max(line2[0],line2[1])*2-1
  })
}
function foo(x) {
  // process.stdout.write("hello: ");   // without auto '\n' (newline)

  console.log(x);  // with auto '\n' (newline)
}


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

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

  const arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);

  let ans = 0;
  let L = 0;
  let R = arr.length - 1;

  while (L < R) {
    ans += (arr[L] + arr[R]) ** 2;
    L++;
    R--;
  }

  console.log(ans);

  c++;
});

"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");

  const N = Number(inputs[0]);
  const A = inputs[1].split(" ").map(Number);

  const sortedA = A.sort((a,b) => a-b);
  const B = [];
  if (sortedA.length % 2 === 1) {
    for (let i=1;i<= (sortedA.length-1)/2; i++) {
      B[i-1] = sortedA[i] + sortedA[N-i];
    }
  } else {
    for (let i=0; i <= (sortedA.length-1)/2; i++) {
      B[i] = sortedA[i] + sortedA[N-i-1];
    }
  }

  const sortedB = B.sort((a,b) => a-b);

  if (sortedA.length % 2 === 1) {
    B[0] += sortedA[0];
  }

  let result = B.reduce((acc, cur) => acc + cur * cur, 0);
  console.log(result);

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  main(i)
})

"use strict";
function I(s,f){this._s=s.split("\n");this._c=0;this._l=0;this._f=f||Number}I.prototype.a=function(){var l=this._s[this._l];if(!l)return;var t=l.trim().split(" ");var a=t[this._c];this._c++;if(t.length===this._c){this._c=0;this._l++}return this._f(a)};I.prototype.l=function(){var l=this._s[this._l];if(!l)return;this._c=0;this._l++;return l.split(" ").map(this._f)};

function main(input) {
  var o = new I(input);

  const N = o.a();
  const A = o.l();

  const sortedA = A.sort((a,b) => a-b);
  const B = [];
  if (sortedA.length % 2 === 1) {
    for (let i=1;i<= (sortedA.length-1)/2; i++) {
      B[i-1] = sortedA[i] + sortedA[N-i];
    }
  } else {
    for (let i=0; i <= (sortedA.length-1)/2; i++) {
      B[i] = sortedA[i] + sortedA[N-i-1];
    }
  }

  const sortedB = B.sort((a,b) => a-b);

  if (sortedA.length % 2 === 1) {
    B[0] += sortedA[0];
  }

  let result = B.reduce((acc, cur) => acc + cur * cur, 0);
  console.log(result);

}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  main(i)
})

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

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

  const arr = d.split(' ').map(Number);
  arr.sort();

  let ans = 0;
  let L = 0;
  let R = arr.length - 1;

  while (L < R) {
    ans += (arr[L] + arr[R]) ** 2;
    L++;
    R--;
  }

  console.log(ans);

  c++;
});


 var input = readline().split(' ');
var n = +input[0];
var k = +input[1];
var a = readline().split(' ');

var ans = 0;
for (var i = 0; i < n; i++) {
  a[i] = +a[i];
}
for (var i = 0; i < k; i++) {
  ans += a[i];
}

var val = ans;
for (var i = k; i < n; i++) {
  val += a[i];
  val -= a[i - k];
  ans += val;
}

print(ans / (n - k + 1));


let stdin = ''

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

process.stdin.on('end', () => {
  stdin = stdin.trim().split('\n').map(string => string.trim())
  main()
})

let currentLine = 0
function input() {
  return stdin[currentLine++]
}

function main() {
  const n = parseInt(input())

  const a = input()
    .split(' ')
    .map(s => parseInt(s))
    .sort((a, b) => a - b)

  const dp = new Array(n).fill(-1).map(_ => new Array(n).fill(-1))

  for (let i = 0; i < n; i++) {
    dp[i][i] = 0
  }

  for (let d = 1; d < n; d++) {
    for (let l = 0; l < n - d; l++) {
      const r = l + d
      dp[l][r] = a[r] - a[l] + Math.min(dp[l+1][r], dp[l][r-1])
    }
  }

  console.log(dp[0][n-1])
}

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();
var a
var dp
function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)

  dp = new Array(n + 1)
  for (let i = 0; i < n + 1; i++) {
    dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
  }
  console.log(solve(0, n - 1, a))
  // })
}

function solve(l, r) {
  if (l === r) return 0

  if(dp[l][r] !== Number.MAX_SAFE_INTEGER) return dp[l][r]
  var ans = Math.min(solve(l + 1, r), solve(l, r - 1))
  if(dp[l][r] === Number.MAX_SAFE_INTEGER) dp[l][r] = ans + a[r] - a[l]
  return ans + a[r] - a[l]
}

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

const mxN = 2010;

function main () {
	const n = rn();
	const s = rna();

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

	const dp = Array.from(Array(mxN), x => Array(mxN).fill(0));

	for (let k = 2; k <= n; k++) {
		for (let i = n-k; i >= 0; i--) {
			dp[i][k] = Math.min(dp[i][k-1], dp[i+1][k-1]) + s[i+k-1] - s[i];
		}
	}

	const ans = dp[0][n];

	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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)

  var dp = new Array(n + 1)
  for (let i = 0; i < n + 1; i++) {
    dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
    dp[i][i] = 0
  }

  for (let k = 0; k < 2; k++) {
    for (let i = 0; i < n-1; i++) {
      for (let j = 1; j < n; j++) {
        // console.log(a[j], a[i], Math.min(dp[i + 1][j], dp[i][j - 1]))
          dp[i][j] = Math.min(dp[i][j], a[j] - a[i] + Math.min(dp[i + 1][j], dp[i][j - 1]))
      }
    }
  }
  console.log(dp[0][n-1])
  // })
}

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)

  var dp = new Array(n + 1)
  for (let i = 0; i < n + 1; i++) {
    dp[i] = new Array(n).fill(Number.MAX_SAFE_INTEGER)
    dp[i][i] = 0
  }

  // for (let k = 0; k < n; k++) {
    for (let i = 0; i < n; i++) {
      for (let j = i; j < n; j++) {
        // console.log(a[j], a[i], Math.min(dp[i + 1][j], dp[i][j - 1]))
        if (i < n - 1 && j > 0)
          dp[i][j] = Math.min(dp[i][j], a[j] - a[i] + Math.min(dp[i + 1][j], dp[i][j - 1]))
      }
    }
  // }
  console.log(dp[0][n-1])
  // })
}

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  a.sort((a, b) => a - b)
  var l = 0
  var r = n - 1
  var sum = a[r] - a[l]

  while (l !== r) {
    if (a[r] - a[l + 1] > a[r - 1] - a[l]) {
      r--
    } else l++
    sum += a[r] - a[l]
    // console.log(sum, l, r)
  }
  console.log(sum)
  // })
}

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  var sum = 0
  for (let i = 0; i < n; i++) {
    sum += a[i]
  }
  var medd = sum / n
  var med
  var res = Number.MAX_SAFE_INTEGER
  for (let i = 0; i <= n; i++) {
    med = aa[i]
    if (i === n) med = medd

    a = a.sort((a, b) => {
      var a1 = a - med > 0 ? a - med : med - a
      var b1 = b - med > 0 ? b - med : med - b
      return a1 > b1 ? 1 : -1
    })

    var min = a[0]
    var max = a[0]
    sum = 0

    for (let j = 0; j < n; j++) {
      min = Math.min(min, a[j])
      max = Math.max(max, a[j])
      sum += max - min
    }
    // console.log(sum)
    // console.log(a)
    res = Math.min(res, sum)
  }

  for (let i = 1; i < n; i++) {
    med = (aa[i] - aa[i-1]) / 2
    a = a.sort((a, b) => {
      var a1 = a - med > 0 ? a - med : med - a
      var b1 = b - med > 0 ? b - med : med - b
      return a1 > b1 ? 1 : -1
    })

    var min = a[0]
    var max = a[0]
    sum = 0

    for (let j = 0; j < n; j++) {
      min = Math.min(min, a[j])
      max = Math.max(max, a[j])
      sum += max - min
    }
    // console.log(sum)
    // console.log(a)
    res = Math.min(res, sum)
  }

  console.log(res)
  // })
}

'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++];
}

var maxN = 2 * 1e5 + 10
var mod = BigInt(1e9 + 7)

// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // const xx = readline();
  // Array(Number(xx)).fill(1).map((t, i) => {
  var n = parseInt(readline());
  // var [n, k] = readline().split(' ').map((x, iii) => {
  //   return parseInt(x)
  // })
  var a = readline().split(' ').map((x, iii) => {
    return parseInt(x)
  });
  var aa = a.slice()
  var sum = 0
  for (let i = 0; i < n; i++) {
    sum += a[i]
  }
  var medd = sum / n
  var med
  var res = Number.MAX_SAFE_INTEGER
  for (let i = 0; i <= n; i++) {
    med = aa[i]
    if (i === n) med = medd

    a = a.sort((a, b) => {
      var a1 = a - med > 0 ? a - med : med - a
      var b1 = b - med > 0 ? b - med : med - b
      return a1 > b1 ? 1 : -1
    })

    var min = a[0]
    var max = a[0]
    sum = 0

    for (let j = 0; j < n; j++) {
      min = Math.min(min, a[j])
      max = Math.max(max, a[j])
      sum += max - min
    }
    // console.log(sum)
    // console.log(a)
    res = Math.min(res, sum)
  }

  console.log(res)
  // })
}


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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let en = '';
            let y = Math.floor(n/4);
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(st+en);
            continue;
        }else{
            let en = '';
            let y = Math.floor(n/4) + 1;
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(st+en);
            continue;
        }
    }
}

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

let stdinInput = '';

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

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

function main(data) {
	data = data.split('\n');
	const testCases = data[0] * 1;
	let i = 1;
	while (i <= testCases) {
	  let n = data[i] * 1;
	  if (n == 1) {
	    console.log(8);
	    i += 1;
	    continue;
	  }
	  let r = Math.ceil(n / 4);
	  let num = '9'.repeat(n - r);
	  num += '8'.repeat(r);
	  console.log(num);
    i += 1;
	}
}

var read = require('readline').createInterface({
   input: process.stdin
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
   obj = init(inLine);
   var start = Date.now();
   Main();
   console.error("\n");
   var end = Date.now() - start;
   myerr("time : " + (end) + "ms");
   myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function input(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
    var returnObj = {
      list : input, index : 0, max : input.length,
      hasNext : function(){return (this.index < this.max);},
      next : function(){
        if(!this.hasNext()){

            throw "ArrayIndexOutOfBoundsException これ以上ないよ";
        }
        else{
            var returnInput = this.list[this.index];
            this.index++;
            return returnInput;
        }
    }};
    return returnObj;
}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
function puts(s){console.log(s);}
function print(s) {process.stdout.write(s+"");}

function Main(){
    tc = parseInt(input())
    while(tc--) {
        n = parseInt(input())
        k = Math.ceil(n/4)
        g = n - k
        arr = []
        for(let i=0;i<g;i++) {
            arr.push('9')
        }
        for(let i=0;i<k;i++) {
            arr.push('8')
        }
        puts(arr.join(""))
    }
}

var T = +readline();
while (T) {
    T -= 1;
    var n = +readline();
    var ans = "";
    var cnt = Math.floor((n + 3) / 4);
    for (var index = 0; index < n - cnt; index++) {
        //const element = array[index];
        ans += "9";
    }
    for (var index = 0; index < cnt; index++) {
        //const element = array[index];
        ans += "8";
    }
    print(ans);
}

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

let stdinInput = '';

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

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

function main(data) {
	data = data.split('\n');
	const testCases = data[0] * 1;
	let i = 1;
	while (i <= testCases) {
	  let n = data[i] * 1;
	  if (n == 1) {
	    console.log(8);
	    i += 1;
	    continue;
	  }
	  let r = Math.ceil(n / 4);
	  let num = '9'.repeat(n - r);
	  num += '8'.repeat(r);
	  console.log(num * 1);
    i += 1;
	}
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let res = '';
            let x = (4*n) - Math.floor(n/4);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = n/4;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }else{
            let res = '';
            let x = (4*n) - Math.floor(n/4);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = Math.floor(n/4) + 1;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let en = '';
            let y = Math.floor(n/4);
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(parseInt(st + en));
            continue;
        }else{
            let en = '';
            let y = Math.floor(n/4) + 1;
            while(y > 0){
                en += '8';
                y -= 1;
            }

            let st = '';
            let x = n - en.length;
            while(x > 0){
                st += '9';
                x--;
            }

            console.log(parseInt(st + en));
            continue;
        }
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main(){
    let t = parseInt(readline());

    for(let o = 0; o < t; o++){
        let n = parseInt(readline());

        if(n % 4 === 0){
            let res = '';
            let x = (4*n) - Math.floor(n/4);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = n/4;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }else{
            let res = '';
            let x = 4 * (n-1);
            while(x > 4){
                res += '9';
                x -= 4;
            }

            let y = Math.floor(n/4) + 1;
            while(y > 0){
                res += '8';
                y -= 1;
            }

            console.log(parseInt(res));
            continue;
        }
    }
}


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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function powM(base, exponent, mod) {
  if(exponent == 0) return 1
  else if(exponent % 2 == 0) return Math.pow(powM(base, exponent / 2, mod), 2) % mod
  else return (base * powM(base, exponent - 1, mod)) % mod
}

function inverseMod(num, prime) {
  return powM(num, prime - 2, prime)
}

function nCrMod(n, r, p) {
  if(r == 0) return 1

  const pascalTriangle = new Array(r + 1).fill(0)

  pascalTriangle[0] = 1

  for(let i = 1; i <= n; i++) {
    for(let j = Math.min(i, r); j > 0; j--) {
      pascalTriangle[j] = (pascalTriangle[j] + pascalTriangle[j - 1]) % p
    }
  }
  return pascalTriangle[r]
}

function main(input) {
  const [n, m] = readInts(input)

  const mod = 10 ** 9 + 7
  wr(nCrMod(n + 2 * m - 1, 2 * m, mod))
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main(arr)
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}

function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

function main(input) {
  const [n, m] = readInts(input)
  const m2 = 2 * m

  const dp = new Array(m2 + 1)
  const mod = 10 ** 9 + 7

  for(let i = 0; i <= m2; i++) {
    dp[i] = new Array(n + 1)
  }

  for(let i = 1; i <= m2; i++) {
    dp[i][0] = 0
  }

  for(let i = 1; i <= n; i++) {
    dp[1][i] = i
  }

  for(let i = 2; i <= m2; i++) {
    for(let j = 1; j <= n; j++) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
    }
  }

  // wr(dp)
  wr(dp[m2][n])

}

! function (e) {
  var n = {};

  function t(r) {
    if (n[r]) return n[r].exports;
    var o = n[r] = {
      i: r,
      l: !1,
      exports: {}
    };
    return e[r].call(o.exports, o, o.exports, t), o.l = !0, o.exports
  }
  t.m = e, t.c = n, t.d = function (e, n, r) {
    t.o(e, n) || Object.defineProperty(e, n, {
      enumerable: !0,
      get: r
    })
  }, t.r = function (e) {
    "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
      value: "Module"
    }), Object.defineProperty(e, "__esModule", {
      value: !0
    })
  }, t.t = function (e, n) {
    if (1 & n && (e = t(e)), 8 & n) return e;
    if (4 & n && "object" == typeof e && e && e.__esModule) return e;
    var r = Object.create(null);
    if (t.r(r), Object.defineProperty(r, "default", {
        enumerable: !0,
        value: e
      }), 2 & n && "string" != typeof e)
      for (var o in e) t.d(r, o, function (n) {
        return e[n]
      }.bind(null, o));
    return r
  }, t.n = function (e) {
    var n = e && e.__esModule ? function () {
      return e.default
    } : function () {
      return e
    };
    return t.d(n, "a", n), n
  }, t.o = function (e, n) {
    return Object.prototype.hasOwnProperty.call(e, n)
  }, t.p = "", t(t.s = 0)
}([function (e, n) {
  process.stdin.resume(), process.stdin.setEncoding("utf-8");
  var t = "";
  process.stdin.on("data", e => {
    t += e
  }), process.stdin.on("end", () => {
    t = t.split("\n").map(e => e.replace(/(\r\n|\n|\r)/gm, "")),
      function (e) {
        const [n, r] = void 0 === o ? t.shift().split(" ").map(e => parseInt(e)) : t[o].split(" ").map(e => parseInt(e));
        var o;
        ! function (...e) {
          console.log(...e)
        }(function (e, n, t) {
          if (0 == n) return 1;
          const r = new Array(n + 1).fill(0);
          r[0] = 1;
          for (let o = 1; o <= e; o++)
            for (let e = Math.min(o, n); e > 0; e--) r[e] = (r[e] + r[e - 1]) % t;
          return r[n]
        }(n + 2 * r - 1, 2 * r, 1e9 + 7))
      }()
  })
}]);


let r='';
process.stdin.on('data',(d)=>{
    r+=d;
}).on('end',()=>{
    r=r.replace(/\n/g,' ').split(' ').map(a=>parseInt(a)).reverse().slice(1);
    nt=r.pop();
    for(let i=0;i<nt;i++){
        let l=r.pop();
        let a=[],b=[];
        for(let j=0;j<l;j++)a.push(r.pop());
        for(let j=0;j<l;j++)b.push(r.pop());
        let dx=0;let ans='YES';
        let j=0;
        for(;j<l;j++){
            if(b[j]-a[j]>0){
                dx=b[j]-a[j];
                break;
            }
            if(b[j]-a[j]<0){
                l=0;ans='NO';
                break;
            }
        }
        for(;j<l;j++){
            if(b[j]-a[j]!=dx){
                break;
            }
        }
        for(;j<l;j++){
            if(b[j]-a[j]!=0){
                ans='NO';
                break;
            }
        }
        console.log(ans);
    }

});

var tests = +readline();

for(var test = 0; test < tests; test ++ ){

	var len = +readline();
	var listOne = readline().split(' ').map(x => +x);
	var listTwo = readline().split(' ').map(x => +x);

	var pl = null, l = null, r = null, k = null;
	var eq = false, gt = false;
	var gotAns = false;
	for(var i = 0; i < listOne.length; i ++){
		var list1el = listOne[i];
		var list2el = listTwo[i];
		if(list2el > list1el && (!eq || !gt)){
			gt = true;
			eq = false;
			// possible so far
			l = list2el - list1el;
			if(null != pl && pl!=l){
				print('NO');
				gotAns = true;
				break;
			}
			pl = l;
		}else if(list2el == list1el){
			eq = true;
			continue;
		}else{
			print('NO');
			gotAns = true;
			break;
		}
	}
	if(!gotAns){
		print('YES');
	}

}

var t = Number(readline());
for(var i=0;i<t;i++){
    print( test() ? "YES" : "NO" );
}

function test(){
    var n = Number(readline());
    var a = readline().split(" ").map( l => Number(l) );
    var b = readline().split(" ").map( l => Number(l) );
    var j=0;
    for(;j<n;j++) if(a[j]!=b[j]) break;
    if(j==n) return 1;
    var k = b[j]-a[j];
    if(k<=0) return 0;
    for(j++;j<n;j++) if(a[j]+k != b[j]) break;
    for(;j<n;j++) if(a[j]!=b[j]) break;
    return (j==n);
}

var tc = parseInt(readline());
var toInt = x => parseInt(x);

for(var t=0; t<tc; t++) {

    var n = parseInt(readline());
    var a = readline().split(' ').map(toInt);
    var b = readline().split(' ').map(toInt);
    var c = b.map((_b, i) =>  (_b - a[i]));
//    print('c', c);
    var scount = 0;
    var allpositive = true;//c.filter(x=>(x<0)).length === 0;
    for(var i=0; i<c.length; i++) {
        if (c[i] !== 0) {
            scount++;
            var e = i;
            for(e=i+1; e<c.length && c[e]===c[i]; e++);
            //print('e', i, '-', e);
            allpositive = allpositive && (c[i] > 0);
            i = e-1;
        }
    }
     print((scount <= 1 && allpositive) ? "YES":"NO");
}

let r='';
process.stdin.on('data',(d)=>{
    r+=d;
}).on('end',()=>{
    r=r.split(' ').map(a=>Number(a)).reverse();
    nt=r.pop();
    for(let i=0;i<nt;i++){
        let l=r.pop();
        let a=[],b=[];
        for(let j=0;j<l;j++)a.push(r.pop());
        for(let j=0;j<l;j++)b.push(r.pop());
        let dx=0;let ans='YES';
        for(let j=0;j<l;j++){
            if(b[j]-a[j]!=0){
                if(b[j]-a[j]!=dx){
                    if(dx==0)dx=b[j]-a[j];
                    else {ans='NO';break;}
                }
            }
        }
        console.log(ans);
    }

});

let r='';
process.stdin.on('data',(d)=>{
    r+=d;
}).on('end',()=>{
    r=r.replace(/\n/g,' ').split(' ').map(a=>parseInt(a)).reverse().slice(1);
    nt=r.pop();
    for(let i=0;i<nt;i++){
        let l=r.pop();
        let a=[],b=[];
        for(let j=0;j<l;j++)a.push(r.pop());
        for(let j=0;j<l;j++)b.push(r.pop()-a[j]);
        for(let j=0;j<b.length-1;j++){
            if(b[j]==b[j+1])b.splice(j,1);
        }
        for(let j=0;j<b.length-1;j++){

        }
        //console.log(b);
        if((b.length==1||b.length==4)&&b[0]>=0)console.log("YES");
        else console.log("NO");
    }

});

let r='';
process.stdin.on('data',(d)=>{
    r+=d;
}).on('end',()=>{
    r=r.replace(/\n/g,' ').split(' ').map(a=>parseInt(a)).reverse().slice(1);
    nt=r.pop();
    for(let i=0;i<nt;i++){
        let l=r.pop();
        let a=[],b=[];
        for(let j=0;j<l;j++)a.push(r.pop());
        for(let j=0;j<l;j++)b.push(r.pop());
        let dx=0;let ans='YES';
        for(let j=0;j<l;j++){
            if(b[j]-a[j]!=0){
                if(b[j]-a[j]!=dx&&b[j]-a[j]>0){
                    if(dx==0)dx=b[j]-a[j];
                    else {ans='NO';break;}
                }else if(b[j]-a[j]<0){ans='NO';break;}
            }
        }
        console.log(ans);
    }

});

var t = Number(readline());
for(var i=0;i<t;i++){
    print( test() ? "YES" : "NO" );
}

function test(){
    var n = Number(readline());
    var a = readline().split(" ").map( l => Number(l) );
    var b = readline().split(" ").map( l => Number(l) );
    var j=0;
    for(;j<n;j++) if(a[j]!=b[j]) break;
    if(j==n) return 1;
    var d = a[j]-b[j];
    for(j++;j<n;j++) if(a[j]!=b[j]+d) break;
    for(;j<n;j++) if(a[j]!=b[j]) break;
    return (j==n);
}

var t = Number(readline());
for(var i=0;i<t;i++){
    print( test() ? "YES" : "NO" );
}

function test(){
    var n = Number(readline());
    var a = readline().split(" ").map( l => Number(l) );
    var b = readline().split(" ").map( l => Number(l) );
    var j=0;
    for(;j<n;j++) if(a[j]!=b[j]) break;
    if(j==n) return 1;
    var k = a[j]-b[j];
    if(k<=0) return 0;
    for(j++;j<n;j++) if(a[j]!=b[j]+k) break;
    for(;j<n;j++) if(a[j]!=b[j]) break;
    return (j==n);
}

var tc = parseInt(readline());
var toInt = x => parseInt(x);

for(var t=0; t<tc; t++) {

    var n = parseInt(readline());
    var a = readline().split(' ').map(toInt);
    var b = readline().split(' ').map(toInt);
    var c = b.map((_b, i) =>  (_b - a[i]));
//    print('c', c);
    var scount = 0;
    var allpositive = c.filter(x=>(x<0)).length === 0;
    for(var i=0; i<c.length; i++) {
        if (c[i] != 0) {
            scount++;
            var e = i;
            for(e=i+1; e<c.length && c[e]===c[i] && c[i]!=0; e++);
            //print('e', i, '-', e);
            i = e;
        }
    }
     print((scount <= 1 && allpositive) ? "YES":"NO");
}

var tc = parseInt(readline());
var toInt = x => parseInt(x);

for(var t=0; t<tc; t++) {

    var n = parseInt(readline());
    var a = readline().split(' ').map(toInt);
    var b = readline().split(' ').map(toInt);
    var c = b.map((_b, i) =>  (_b - a[i]));
//    print('c', c);
    var scount = 0;
    var allpositive = true;//c.filter(x=>(x<0)).length === 0;
    for(var i=0; i<c.length; i++) {
        if (c[i] != 0) {
            scount++;
            var e = i;
            for(e=i+1; e<c.length && c[e]===c[i] && c[i]!=0; e++);
            //print('e', i, '-', e);
            allpositive = allpositive && (c[i] > 0);
            i = e;
        }
    }
     print((scount <= 1 && allpositive) ? "YES":"NO");
}

var tc = parseInt(readline());
var toInt = x => parseInt(x);

for(var t=0; t<tc; t++) {

    var n = parseInt(readline());
    var a = readline().split(' ').map(toInt);
    var b = readline().split(' ').map(toInt);
    var c = b.map((_b, i) =>  (_b - a[i]));
//    print('c', c);
    var scount = 0;
    var allpositive = true;//c.filter(x=>(x<0)).length === 0;
    for(var i=0; i<c.length; i++) {
        if (c[i] !== 0) {
            scount++;
            var e = i;
            for(e=i+1; e<c.length && c[e]===c[i]; e++);
            //print('e', i, '-', e);
            allpositive = allpositive && (c[i] > 0);
            i = e;
        }
    }
     print((scount <= 1 && allpositive) ? "YES":"NO");
}