A and B are preparing themselves for programming contests.B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared — the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.Can you help B find out exactly what two errors he corrected?

The first line of the input contains integer n (3 ≤ n ≤ 105) — the initial number of compilation errors. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the errors the compiler displayed for the first time.  The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 — the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.  The fourth line contains n - 2 space-separated integers с1, с2, ..., сn - 2 — the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.

Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.

NoteIn the first test sample B first corrects the error number 8, then the error number 123.In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step.

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

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN().sortLt();
    var B = rdArN().sortLt().concat([null]);
    var C = rdArN().sortLt().concat([null, null]);
    for (var i = 0; i < A.length; ++i) {
        if (A[i] !== B[i]) {
            pr(A[i]);
            break;
        }
    }
    for (var i = 0; i < B.length; ++i) {
        if (B[i] !== C[i]) {
            pr(B[i]);
            break;
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const rdS=readline;
const rdN=()=>+rdS();
const rdArS=()=>rdS().split(' ');
const rdArN=()=>rdArS().map(v=>+v);
const wr=write;
const pr=print;
const prAr=(a)=>pr(...a);
const prOb=(o)=>pr(JSON.stringify(o,null,4));
const cmpLt=(a,b)=>a-b;
const cmpGt=(a,b)=>b-a;
const crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};
const getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};
const defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();

readline()
A=readline().split(' ').map(Number).reduce((a,c)=>{ a[c]=(a[c]||0)+1; return a; },{});
B=Object.assign({},A)
readline().split(' ').map(Number).forEach(c=>A[c]--);
var f;
for (i of Object.keys(A))
    if (A[i]) f=i;

readline().split(' ').map(Number).forEach(c=>B[c]--);
B[f]--;
var ff;
for (i of Object.keys(B))
    if (B[i]) ff=i;

print(f)
print(ff)
//print(JSON.stringify(A))
//print(JSON.stringify(B))

readline()
A=readline().split(' ').map(Number)
AA=new Array(A.length)
for (var i of A)
    AA[i] = (AA[i]||0)+1

readline().split(' ').map(Number).forEach(c=>AA[c]--);

var f;
for (var i in AA)
    if (AA[i]) f=i;

AA=new Array(A.length)
for (var i of A)
    AA[i] = (AA[i]||0)+1

readline().split(' ').map(Number).forEach(c=>AA[c]--);
AA[f]--;
var ff;
for (var i in AA) {
    if (AA[i]) ff=i;
}

print(f)
print(ff)

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);

first.sort();
second.sort();
third.sort();

for (var i = 0, j = 0, k = 0; i < first.length; i++) {
    if (first[i] == second[j] && first[i] == third[k]) {j++; k++;}
    else if ((first[i] == second[j]) && (first[i] != third[k])) {si = first[i]; j++;}
    else if ((first[i] != second[j]) && (first[i] != third[k])) {fi = first[i];}

}

write(fi + '\n' + si);

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);

        if (currentValue == 1) {
            a.delete(index);
        } else {
            a.set(index, currentValue - 1);
        }
    }
});

b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);

        if (currentValue == 1) {
            a.delete(index);
        } else {
            a.set(index, currentValue - 1);
        }
    }
});

write(ans.join('\n'));

Array.prototype.toMap = function toMap()    {
    var resultMap = {};
    this.forEach(function(value, index) {
        if(resultMap[value])    {
            resultMap[value] += 1;
        } else    {
            resultMap[value] = 1;
        }
    });
    return resultMap;
};

function main()  {
    var errorCount = readline(),
        fstErrorList = readline().split(/\s/).map(Number),
        fstErrorMap = fstErrorList.toMap(),
        sndErrorList = readline().split(/\s/).map(Number),
        sndErrorMap = sndErrorList.toMap(),
        trdErrorMap = readline().split(/\s/).map(Number).toMap(),
        result = [];

    // console.log('%o, %o, %o', fstErrorMap, sndErrorMap, trdErrorMap);

    fstErrorList.some(function(errorLine)    {
        if(fstErrorMap[errorLine] != sndErrorMap[errorLine])    {
            result.push(errorLine);
            return true;
        }
    });

    sndErrorList.some(function(errorLine)    {
        if(sndErrorMap[errorLine] != trdErrorMap[errorLine])    {
            result.push(errorLine);
            return true;
        }
    });

    print(result.join('\n'));
};

main();

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline().split(' ').map(x => parseInt(x));
var thirdErrors = readline().split(' ').map(x => parseInt(x));
firstErrors.sort((a,b) => a-b);
secondErrors.sort((a,b) => a-b);
thirdErrors.sort((a,b) => a-b);
var errors = [];
var somethingChanged = false;
for (var i = 0; i < limit - 1; i++) {
  if (secondErrors[i] !== firstErrors[i]) {
    errors.push(firstErrors[i]);
    somethingChanged = true;
    break;
  }
}
if (!somethingChanged) errors.push(firstErrors[limit-1]);
somethingChanged = false;
for (var j = 0; j < limit - 2; j++) {
  if (thirdErrors[j] !== secondErrors[j]) {
    errors.push(secondErrors[j])
    somethingChanged = true;
    break;
  }
}
if (!somethingChanged) errors.push(secondErrors[limit-2]);
for (var k = 0; k < errors.length; k++) print(errors[k]);

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const set = new Set();

  const f1 = input[1].split(' ').map(x => parseInt(x));
  const f2 = input[2].split(' ').map(x => parseInt(x));
  const f3 = input[3].split(' ').map(x => parseInt(x));

  f1.sort((a, b) => a - b);
  f2.sort((a, b) => a - b);
  f3.sort((a, b) => a - b);

  const answ = [];
  for (let i = 0; i < f1.length; i += 1) {
    if (f1[i] !== f2[i]) {
      answ.push(f1[i]); break;
    }
    if (i + 1 === f2.length) { answ.push(f1.pop()); break; }
  }

  for (let i = 0; i < f2.length; i += 1) {
    if (f2[i] !== f3[i]) {
      answ.push(f2[i]); break;
    }

    if (i + 1 === f3.length) { answ.push(f2.pop()); break; }
  }

  answ.forEach(x => console.log(x));
});

var readline = (function () {
    var lines = require("fs")
        .readFileSync(0, "utf-8")
        .split("\n");
    var i = 0;
    return function () { return lines[i++]; };
})();
var initialErrors = parseInt(readline());
var first = readline()
    .split(" ")
    .map(function (v) { return parseInt(v); })
    .sort();
var second = readline()
    .split(" ")
    .map(function (v) { return parseInt(v); })
    .sort();
var third = readline()
    .split(" ")
    .map(function (v) { return parseInt(v); })
    .sort();
var hasFirst = false;
var hasSecond = false;
var firstError = 0;
var secondError = 0;
for (var i = 0; i < initialErrors && !(hasFirst && hasSecond); i++) {
    if (!hasFirst) {
        if (first[i] !== second[i]) {
            hasFirst = true;
            firstError = first[i];
        }
    }
    if (!hasSecond) {
        if (second[i] !== third[i]) {
            hasSecond = true;
            secondError = second[i];
        }
    }
}
console.log(firstError);
console.log(secondError);

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

let stdin = '';

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

process.stdin.on('end', () => {
  const data = stdin.split('\n');
  data.shift();

  const sum = [0, 0, 0];

  data.forEach((errors, i) => {
    errors.split(' ').forEach((value) => {
      sum[i] += Number(value);
    });
  });

  process.stdout.write(`${sum[0] - sum[1]}\n${sum[1] - sum[2]}`);
});

function sum(array){			//суммирование массива
	var result = 0;
	for(var i = 0; i < array.length; i++){
		result += +array[i];
	}
	return result;
}

var n = +readline(), a = sum(readline().split(" ")), b = sum(readline().split(" ")), c = sum(readline().split(" "));

write((a-b) + "\n" + (b-c));

readline();

var a = readNums();
var b = readNums();
print(diff(a, b));
a = b;
b = readNums();
print(diff(a, b));

function diff(a, b) {
    var d = {};
    a.map(v => d[v] = (d[v] || 0) + 1);
    b.map(v => d[v] = (d[v] || 0) - 1);
    for (var k in d) {
        if (d[k])
            return k;
    }
}

function readNums() {
    return readline().split(' ').map(v => v - 0)
}

var n = parseInt(readline().trim())
var a = readline().trim().split(' ').map((x)=>parseInt(x))
var b = readline().trim().split(' ').map((x)=>parseInt(x))
var c = readline().trim().split(' ').map((x)=>parseInt(x))

var _sort=(_a,_b)=>_a-_b;
a.sort(_sort)
b.sort(_sort)
c.sort(_sort)

var _b=-1;
for(var i=0;i<n-1;i++){
    if(a[i]!=b[i]){
        _b=a[i];
        break;
    }
}
if(_b==-1)
    _b=a[n-1];

var _c=-1;
for(var i=0;i<n-2;i++){
    if(c[i]!=b[i]){
        _c=b[i];
        break;
    }
}
if(_c==-1)
    _c=b[n-2];

print(_b);
print(_c);

var n = parseInt(readline().trim())
var a = readline().trim().split(' ').map((x)=>parseInt(x))
var b = readline().trim().split(' ').map((x)=>parseInt(x))
var c = readline().trim().split(' ').map((x)=>parseInt(x))

var _a={}, _b={}, _c={}
for(var i=0;i<n;i++){
    if(_a[a[i]]==undefined)
        _a[a[i]]=0
    _a[a[i]]++
}
for(var i=0;i<n-1;i++){
    if(_b[b[i]]==undefined)
        _b[b[i]]=0
    _b[b[i]]++
}
for(var i=0;i<n-2;i++){
    if(_c[c[i]]==undefined)
        _c[c[i]]=0
    _c[c[i]]++
}

//print(JSON.stringify(_a),JSON.stringify(_b),JSON.stringify(_c))
for(var i in _a){
   // print(i,_b[i],_a[i])
    if(_b[i]!=_a[i]){
        print(i);
        break;
    }
}

for(var i in _b){
    if(_b[i]!=_c[i]){
        print(i);
        break;
    }
}

(function () {
	'use strict';

	var n = parseInt(readline()),
		a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		c = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

	print((function () {
		for (var i = 0, _i = b.length; i < _i; i++)
			if (a[i] !== b[i]) return a[i];
		return a.pop();
	})());

	print((function () {
		for (var i = 0, _i = c.length; i < _i; i++)
			if (b[i] !== c[i]) return b[i];
		return b.pop();
	})());

}).call(this);

function main(a, b, c) {
    var output = '';
    var aValues = sum(a);
    var bValues = sum(b);
    var cValues = sum(c);

    output += aValues - bValues + '\n';
    output += bValues - cValues;

    return output;
}

function sum(array) {
    var sumResult = 0;
    for (var i = array.length; i--;) {
        sumResult += array[i];
    }

    return sumResult;
}

var n = readline();
var input = [];
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));

print(main(input[0], input[1], input[2]));

function main(a, b, c) {
    var output = '';
    var aValues = a.reduce(function(x, y) { return x + y }, 0);
    var bValues = b.reduce(function(x, y) { return x + y }, 0);
    var cValues = c.reduce(function(x, y) { return x + y }, 0);

    output += aValues - bValues + '\n';
    output += bValues - cValues;

    return output;
}

var n = readline();
var input = [];
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));

print(main(input[0], input[1], input[2]));

function main(a, b, c) {
    var output = '';
    var aValues = cacheValues(a);
    var bValues = cacheValues(b);
    var cValues = cacheValues(c);

    output += compare(aValues, bValues) + '\n';
    output += compare(bValues, cValues);

    return output;
}

function cacheValues(values) {
    var cachedValues = [];

    for(var i = 0; i < values.length; i++) {
        if (!cachedValues[`n${values[i]}`]) {
            cachedValues[`n${values[i]}`] = 1;
        } else {
            cachedValues[`n${values[i]}`]++;
        }
    }

    return cachedValues;
}

function compare(a, b) {
    var differ = 0;

    for (key in a) {
        if(a[key] !== b[key]) {
            differ = parseInt(key.slice(1));
            break;
        }
    }

    return differ;
}

var n = readline();
var input = [];
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));
input.push(readline().split(' ').map(function(v) { return parseInt(v); }));

print(main(input[0], input[1], input[2]));

function sum(array) {
    var sumResult = 0;
    for (var i = array.length; i--;) {
        sumResult += +array[i];
    }

    return sumResult;
}

var n = readline();
a = readline().split(' ');
b = readline().split(' ');
c = readline().split(' ');

var bValues = sum(b);
print((sum(a) - bValues) + '\n' + (bValues - sum(c)));

function sum(array) {
    var sumResult = 0;

    var i = 0;
    var l = array.length;
    for (i = l; i--;) {
        sumResult += +array[i];
    }

    return sumResult;
}

readline();
var aValues = sum(readline().split(' '));
var bValues = sum(readline().split(' '));
print((aValues - bValues) + '\n' + (bValues - sum(readline().split(' '))));

var n=Number(readline());
var arr=readline().split(" ");
arr.sort();
var arr1=readline().split(" ");
arr1.sort();
var flag1=false;
for(var i=0;i<n-1;i++){
	if(arr1[i]!=arr[i]){
		flag1=true;
		print(arr[i]);
		break;
	}
}
if(!flag1){
	print(arr[n-1]);
}
var arr2=readline().split(" ");
arr2.sort();
var flag2=false;
for(var i=0;i<n-2;i++){
	if(arr2[i]!=arr1[i]){
		flag2=true;
		print(arr1[i]);
		break;
	}
}
if(!flag2){
	print(arr1[n-2]);
}

var n = readline();
var str1 = readline().split(" ").reduce((x,y)=>(Number(x)+Number(y)));
var str2 = readline().split(" ").reduce((x,y)=>(Number(x)+Number(y)));
var str3 = readline().split(" ").reduce((x,y)=>(Number(x)+Number(y)));

print(str1-str2);
print(str2-str3);

var nums = readNums();

var arr1 = readNums();
var arr2 = readNums();
var arr3 = readNums();

arr1.sort(function(a,b){return b-a});
arr2.sort(function(a,b){return b-a});
arr3.sort(function(a,b){return b-a});

var k = 0;

for (var i = 0; i <arr2.length; i++) {
    if (arr1[i] > arr2[i]) {
        print(arr1[i]);
        k = 1;
        break;
    }
}

if (k == 0 && arr1[arr1.length-1] <= arr2[arr2.length-1]) {
    print(arr1[arr1.length-1]);
}

var l = 0;

for (var i = 0; i <arr3.length; i++) {
    if (arr2[i] > arr3[i]) {
        print(arr2[i]);
        l = 1;
        break;
    }
}

if (l == 0 && arr2[arr2.length-1] <= arr3[arr3.length-1]) {
    print(arr2[arr2.length-1]);
}

function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}

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

var main = function() {"use strict";
    // TODO
    var n = rdN();
    var A = rdArN().sortLt();
    var B = rdArN().sortLt();
    var C = rdArN().sortLt();
    for (var i = 0; i < A.length; ++i) {
        if (A[i] !== B[i]) {
            pr(A[i]);
            break;
        }
    }
    for (var i = 0; i < B.length; ++i) {
        if (B[i] !== C[i]) {
            pr(B[i]);
            break;
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const rdS=readline;
const rdN=()=>+rdS();
const rdArS=()=>rdS().split(' ');
const rdArN=()=>rdArS().map(v=>+v);
const wr=write;
const pr=print;
const prAr=(a)=>pr(...a);
const prOb=(o)=>pr(JSON.stringify(o,null,4));
const cmpLt=(a,b)=>a-b;
const cmpGt=(a,b)=>b-a;
const crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};
const getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};
const defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);
first.sort();
third.sort();
var si = 0, fi = 0;
for (var i = 0, j = 0; i < first.length; i++)
    if (third[j] === first[i]) {j++}
    else {
        if (second.indexOf(first[i]) >= 0) si = first[i];
        else fi = first[i];
    }
write(fi + '\n' + si);

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);
first.sort(function(a,b) {return a - b});
third.sort(function(a,b) {return a - b});
var si = 0, fi = 0;
for (var i = 0, j = 0; i < first.length; i++)
    if (third[j] === first[i]) {j++}
    else {
        if (second.indexOf(first[i]) >= 0) si = first[i];
        else fi = first[i];
    }
write(fi + '\n' + si);

str = Number(readline());
first = readline().split(' ').map(Number);
second = readline().split(' ').map(Number);
third = readline().split(' ').map(Number);
var mem1 = [], mem2 = [];
var si = [], fi = [];
for (var i = 0; i < first.length; i++) {
    mem1[first[i]] = mem1[first[i]] + 1 || 1;
}

for (var i = 0; i < second.length; i++) {
    mem1[second[i]]--;
    mem2[second[i]] = mem2[second[i]] + 1 || 1;
}

for (var i = 0; i < third.length; i++) {
    mem2[third[i]]--;
}

for (var i = 0; i < mem1.length; i++) {
    if (mem1[i] !== 0) fi = i;
    if (mem2[i] !== 0) si = i;
}

write(fi + '\n' + si);

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var b = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.push(index);
    b.set(index, (b.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (b.get(index) !== c.get(index)) {
        ans.push(index);
    }
});

write(ans.join('\n'));

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);
        a.delete(index);
    }
});

b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

a.forEach(function(currentValue, index) {
    if (currentValue !== b.get(index)) {
        ans.push(index);
        a.delete(index);
    }
});

write(ans.join('\n'));

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var b = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.push(currentValue);
    b.set(index, (b.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (b.get(index) !== c.get(index)) {
        ans.push(index);
    }
});

write(ans.join('\n'));

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = [];
var b = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.push(index);
    b.set(index, (b.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue) {
    if (b.get(currentValue) !== c.get(currentValue)) {
        ans.push(currentValue);

        b.delete(currentValue);
        c.delete(currentValue);
    }
});

write(ans.join('\n'));

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (b.get(index) !== currentValue) {
        ans.push(index);
    }
});

b = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    b.set(index, (b.get(index) || 0) + 1);
});

a.forEach(function(currentValue, index) {
    if (ans[0] !== currentValue && b.get(index) !== currentValue) {
        ans.push(index);
    }
});

write(ans.join('\n'));

if (!readline) {
    var _i = 0;
    var readline = function() {
        _i ++;

        switch (_i) {
            case 1: return '6';
            case 2: return '1 4 3 3 5 7';
            case 3: return '3 7 5 4 3';
            case 4: return '4 3 7 5';
        }
    }

    var write = console.log;
}

var n = +readline();
var a = new Map();
var c = new Map();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    a.set(index, (a.get(index) || 0) + 1);
});

readline();

readline().split(' ').forEach(function(currentValue) {
    var index = +currentValue;
    c.set(index, (c.get(index) || 0) + 1);
});

var ans = [];

a.forEach(function(currentValue, index) {
    if (c.get(index) !== a.get(index)) {
        ans.push(index);
    }
});

write(ans.join('\n'));

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next();
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  mapCopy.set(thirdErrors[j], mapCopy.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
  if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  print(key);
}

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
  if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if (limit === 10) print(keys);
  print(key);
}

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
  if (map.get(thirdErrors[j]) === 0) map.delete(thirdErrors[j]);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if (limit === 10) print([...keys]);
  print(key);
}

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  map.set(thirdErrors[j], map.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next();
  print(key);
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var limit = parseInt(readline());
var firstErrors = readline().split(' ').map(x => parseInt(x));
var secondErrors = readline();
var thirdErrors = readline().split(' ').map(x => parseInt(x));
// *************SORTING SOLUTION *****************************
// firstErrors.sort((a,b) => a-b);
// secondErrors.sort((a,b) => a-b);
// thirdErrors.sort((a,b) => a-b);
var errors = [];
// var somethingChanged = false;
// for (var i = 0; i < limit - 1; i++) {
//   if (secondErrors[i] !== firstErrors[i]) {
//     errors.push(firstErrors[i]);
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(firstErrors[limit-1]);
// somethingChanged = false;
// for (var j = 0; j < limit - 2; j++) {
//   if (thirdErrors[j] !== secondErrors[j]) {
//     errors.push(secondErrors[j])
//     somethingChanged = true;
//     break;
//   }
// }
// if (!somethingChanged) errors.push(secondErrors[limit-2]);
// for (var k = 0; k < errors.length; k++) print(errors[k]);
// **********************MAP SOLUTION *************************
var map = new Map();
for (var i = 0; i < limit; i++) {
  if (!map.get(firstErrors[i])) map.set(firstErrors[i], 1);
  else map.set(firstErrors[i], map.get(firstErrors[i]) + 1);
}
var mapCopy = new Map(map);
for (var j = 0; j < limit - 2; j++) {
  mapCopy.set(thirdErrors[j], mapCopy.get(thirdErrors[j]) - 1);
}
var keys = map.keys();
var key;
for (var k = 0; k < map.size; k++) {
  key = keys.next().value;
  if ((map.get(key) === mapCopy.get(key)) || ((map.get(key) !== mapCopy.get(key)) && mapCopy.get(key) !== 0)) {
    var n = map.get(key) - mapCopy.get(key);
    n = n === 0 ? 1 : n;
    while (n) {
      n--
      if (errors.length && errors[0] > key) {
        errors[1] = errors[0];
        errors[0] = key;
      } else errors.push(key);
    }
  }
}
for (var e = 0; e < errors.length; e++) print(errors[e]);

var n = +readline(), a = readline().split(" ");
readline();
var c = readline().split(" "), k = [];

a.forEach(function(error, i){
	var index = c.indexOf(error);
	if(index + 1){
		delete c[index];
	}
	else{
		k.push(i);
	}
});

write(a[k[0]] + "\n" + a[k[1]]);

var n = +readline(), a = readline().split(" ");
readline();
var c = readline().split(" "), k = [];

a.forEach(function(error, i){
	var index = c.indexOf(error);
	if(index + 1){
		delete c[index];
	}
	else{
		k.push(i);
	}
});

write( (a[k[0]] > a[k[1]]) ? (a[k[1]] + "\n" + a[k[0]]) : (a[k[0]] + "\n" + a[k[1]]) );

(function () {
	'use strict';

	var n = parseInt(readline()),
		a = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; }),
		c = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

	print((function () {
		for (var i = 0, _i = b.length; i < _i; i++)
			if (a[i] !== b[i]) return a[i];
		return a.pop()[0];
	})());

	print((function () {
		for (var i = 0, _i = c.length; i < _i; i++)
			if (b[i] !== c[i]) return b[i];
		return b.pop()[0];
	})());

}).call(this);

(function () {
	'use strict';

	var n = parseInt(readline()),
		a = readline().split(' '),
		b = readline().split(' '),
		c = readline().split(' ');

	print((function () {
		for (var i = 0; i < a.length; i++)
			if (b.indexOf(a[i]) === -1)
				return a[i];
	})());

	print((function () {
		for (var i = 0; i < b.length; i++)
			if (c.indexOf(b[i]) === -1)
				return b[i];
	})());

}).call(this);

function sum(array) {
    var sumResult = 0;

    var i = 0;
    var l = array.length;
    for (i = l; i--;) {
        sumResult += +array[i];
    }

    return sumResult;
}

readline();
var bValues = sum(readline().split(' '));
print((sum(readline().split(' ')) - bValues) + '\n' + (bValues - sum(readline().split(' '))));

var nums = readNums();

var arr1 = readNums();
var arr2 = readNums();
var arr3 = readNums();

arr1.sort(function(a,b){return b-a});
arr2.sort(function(a,b){return b-a});
arr3.sort(function(a,b){return b-a});

for (var i = 0; i <arr2.length; i++) {
    if (arr1[i] > arr2[i]) {
        print(arr1[i]);
        break;
    }
}

if (arr1[arr1.length-1] <= arr2[arr2.length-1]) {
    print(arr1[arr1.length-1]);
}

for (var i = 0; i <arr3.length; i++) {
    if (arr2[i] > arr3[i]) {
        print(arr2[i]);
        break;
    }
}

if (arr2[arr2.length-1] <= arr3[arr3.length-1]) {
    print(arr2[arr2.length-1]);
}

function readNums() {
    return readline().split(' ').map(function(v) {
        return v - 0;
    })
}

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

var main = function() {"use strict";
    // TODO
    rdN();
    var A = rdArN();
    var B = rdArN();
    var C = rdArN();
    var ABC = [...A, ...B, ...C];
    var M = {};
    for (var i = 0; i < ABC.length; ++i) {
        var value = ABC[i];
        M[value] = ++M[value] || 1;
    }
    for (var key in M) {
        var count = M[key];
        if (count%3 === 1) {
            pr(key);
        }
    }
    for (var key in M) {
        var count = M[key];
        if (count%3 === 2) {
            pr(key);
        }
    }
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const rdS=readline;
const rdN=()=>+rdS();
const rdArS=()=>rdS().split(' ');
const rdArN=()=>rdArS().map(v=>+v);
const wr=write;
const pr=print;
const prAr=(a)=>pr(...a);
const prOb=(o)=>pr(JSON.stringify(o,null,4));
const cmpLt=(a,b)=>a-b;
const cmpGt=(a,b)=>b-a;
const crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);};
const getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;};
const defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort(cmpLt);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort(cmpGt);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();


Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.

The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.

Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.

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

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

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

function main() {
	var n = parseInt(readline());
	var cows = tokenizeIntegers(readline());

	var leftCount = 0, rightCount = 0;
	for (var i = 0; i < n; i += 1) {
		if (cows[i] == 0) {
			leftCount += 1;
		}
		else {
			rightCount += 1;
		}
	}
	if (leftCount == 0 || rightCount == 0) {
		print(0);
		return;
	}

	var leftPos = n-1;
	while (cows[leftPos] == 1) {
		rightCount -= 1;
		leftPos -= 1;
	}

	var rightPos = 0;
	while (cows[rightPos] == 0) {
		leftCount -= 1;
		rightPos += 1;
	}

	//print("leftPos = "+leftPos+", rightCount = "+rightCount);
	//print("rightPos = "+rightPos+", leftCount = "+leftCount);

	var loss = 0;

	while (rightPos < leftPos)  {
		if (rightCount < leftCount) {
			loss += rightCount;
			leftCount -= 1;
			leftPos -= 1;
			while (rightPos < leftPos && cows[leftPos] == 1) {
				rightCount -= 1;
				leftPos -= 1;
			}
		}
		else {
			loss += leftCount;
			rightCount -= 1;
			rightPos += 1;
			while (rightPos < leftPos && cows[rightPos] == 0) {
				leftCount -= 1;
				rightPos += 1;
			}
		}
	}

	print(loss);
}

main();

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

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

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

function main() {
	var n = parseInt(readline());
	var cows = tokenizeIntegers(readline());

	var leftCount = 0, rightCount = 0;
	for (var i = 0; i < n; i += 1) {
		if (cows[i] == 0) {
			leftCount += 1;
		}
		else {
			rightCount += 1;
		}
	}

	var leftPos = n-1;
	while (cows[leftPos] == 1) {
		rightCount -= 1;
		leftPos -= 1;
		if (leftPos == -1) {
			print(0);
			return;
		}
	}

	var rightPos = 0;
	while (cows[rightPos] == 0) {
		leftCount -= 1;
		rightPos += 1;
		if (rightPos == n) {
			print(0);
			return;
		}
	}

	//print("leftPos = "+leftPos+", rightCount = "+rightCount);
	//print("rightPos = "+rightPos+", leftCount = "+leftCount);

	var loss = 0;

	while (rightCount != 0 && leftCount != 0) {
		if (rightCount < leftCount) {
			loss += rightCount;
			leftCount -= 1;
			leftPos -= 1;
			while (leftPos != -1 && cows[leftPos] == 1) {
				rightCount -= 1;
				leftPos -= 1;
			}
		}
		else {
			loss += leftCount;
			rightCount -= 1;
			rightPos += 1;
			while (rightPos != n && cows[rightPos] == 0) {
				leftCount -= 1;
				rightPos += 1;
			}
		}
	}

	print(loss + rightCount + leftCount);
}

main();

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

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

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

function main() {
	var n = parseInt(readline());
	var cows = tokenizeIntegers(readline());

	var leftCount = 0, rightCount = 0;
	for (var i = 0; i < n; i += 1) {
		if (cows[i] == 0) {
			leftCount += 1;
		}
		else {
			rightCount += 1;
		}
	}
	if (leftCount == 0 || rightCount == 0) {
		print(0);
		return;
	}

	var leftPos = n-1;
	while (cows[leftPos] == 1) {
		rightCount -= 1;
		leftPos -= 1;
	}

	var rightPos = 0;
	while (cows[rightPos] == 0) {
		leftCount -= 1;
		rightPos += 1;
	}

	//print("leftPos = "+leftPos+", rightCount = "+rightCount);
	//print("rightPos = "+rightPos+", leftCount = "+leftCount);

	var loss = 0;

	while (rightCount != 0 && leftCount != 0) {
		if (rightCount < leftCount) {
			loss += rightCount;
			leftCount -= 1;
			leftPos -= 1;
			while (leftPos > rightPos && cows[leftPos] == 1) {
				rightCount -= 1;
				leftPos -= 1;
			}
		}
		else {
			loss += leftCount;
			rightCount -= 1;
			rightPos += 1;
			while (rightPos < leftPos && cows[rightPos] == 0) {
				leftCount -= 1;
				rightPos += 1;
			}
		}
	}

	print(loss + rightCount + leftCount);
}

main();


Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any other one. Pavel doesn't like it when his maze has too little walls. He wants to turn exactly k empty cells into walls so that all the remaining cells still formed a connected area. Help him.

The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe the original maze. If a character on a line equals ".", then the corresponding cell is empty and if the character equals "#", then the cell is a wall.

Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.

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

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

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

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], m = integers[1], k = integers[2];

	var maze = [], distances = [];
	var startR = -1, startC = -1;
	var inf = n*m;
	for (var r = 0; r < n; r += 1) {
		maze.push(readline());
		distances.push([]);
		for (var c = 0; c < m; c += 1) {
			distances[r].push(inf);
			if (maze[r][c] == '.') {
				startR = r;
				startC = c;
			}
		}
	}

	distances[startR][startC] = 0;
	var queue = [{r: startR, c: startC}];
	var dr = [-1, 0, 1, 0], dc = [0, 1, 0, -1];
	while (queue.length != 0) {
		var r = queue[0].r, c = queue[0].c;
		queue = queue.slice(1);
		var distance = distances[r][c] + 1;
		for (var i = 0; i < 4; i += 1) {
			var nextR = r + dr[i], nextC = c + dc[i];
			if (nextR >= 0 && nextR < n && nextC >= 0 && nextC < m &&
					maze[nextR][nextC] == '.' &&
					distance < distances[nextR][nextC]) {
				distances[nextR][nextC] = distance;
				queue.push({r: nextR, c: nextC});
			}
		}
	}

	var records = [];
	for (var r = 0; r < n; r += 1) {
		for (var c = 0; c < m; c += 1) {
			if (distances[r][c] < inf) {
				records.push({distance: distances[r][c], r: r, c: c});
			}
		}
	}
	records.sort(function(a, b) {
		return b.distance - a.distance;
	});

	for (var i = 0; i < k; i += 1) {
		var r = records[i].r, c = records[i].c;
		var line = maze[r];
		maze[r] = line.slice(0, c) + 'X' + line.slice(c+1);
	}

	for (var r = 0; r < n; r += 1) {
		print(maze[r]);
	}
}

main();

var input = readline().split(' ');
    var INF = 1000000000;
    var n=parseInt(input[0]),
        m=parseInt(input[1]),
        k=parseInt(input[2]);

    var labirinth = [], buf = [];
    for(var i=0; i<n; i++)
    {
        labirinth.push(readline().split('').map(function(e){return e=='#'?INF:0;}));
    }

    function bfs()
    {
        var startX=0, startY=0, result=[], queue = [];

        for(startY=0; startY<n && queue.length==0; startY++)
        {
            for(startX=0; startX<m && queue.length==0; startX++)
            {
                if(labirinth[startY][startX]==0)
                {
                    queue.push([startY,startX]);
                }
            }
        }

        var used = [];
        for(var i=0; i<n; i++)
        {
            used[i] = [];
            for(var j=0; j<m; j++) used[i][j]=0;
        }

        used[queue[0][0]][queue[0][1]]=1;

        function valid(y, x){return y>=0 && y<n && x>=0 && x<m && used[y][x]==0 && labirinth[y][x]!=INF;}
        while(queue.length)
        {
            var curr = queue.shift();
            used[curr[0]][curr[1]]=1;
            result.push(curr);
            if(valid(curr[0]+1,curr[1])) {
                queue.push([curr[0]+1,curr[1]]);
                used[curr[0]+1][curr[1]]=1;
            }
            if(valid(curr[0]-1,curr[1])) {
                queue.push([curr[0]-1,curr[1]]);
                used[curr[0]-1][curr[1]]=1;
            }
            if(valid(curr[0],curr[1]+1)) {
                queue.push([curr[0],curr[1]+1]);
                used[curr[0]][curr[1]+1]=1;
            }
            if(valid(curr[0],curr[1]-1)) {
                queue.push([curr[0],curr[1]-1]);
                used[curr[0]][curr[1]-1]=1;
            }
        }

        return result.reverse();
    }

    var order = bfs();
    for(var i=0; i<k; i++) labirinth[order[i][0]][order[i][1]]=-INF;
    for(var i=0; i<n; i++)
    {
        print(labirinth[i].map(function(e){return e==INF?'#':(e==-INF?'X':'.');}).join(''));
    }

var input = readline().split(' ');
    var INF = 1000000000;
    var n=parseInt(input[0]),
        m=parseInt(input[1]),
        k=parseInt(input[2]);

    var labirinth = [], buf = [];
    for(var i=0; i<n; i++)
    {
        labirinth.push(readline().split('').map(function(e){return e=='#'?INF:0;}));
    }

    function bfs()
    {
        var startX=0, startY=0, result=[], queue = [];

        for(startY=0; startY<n && queue.length==0; startY++)
        {
            for(startX=0; startX<m && queue.length==0; startX++)
            {
                if(labirinth[startY][startX]==0)
                {
                    queue.push([startY,startX]);
                }
            }
        }

        function valid(y, x){return y>=0 && y<n && x>=0 && x<m && labirinth[y][x]==0;}
        while(queue.length)
        {
            var curr = queue.shift();
            labirinth[curr[0]][curr[1]]=1;
            result.push(curr);
            if(valid(curr[0]+1,curr[1])) queue.push([curr[0]+1,curr[1]]);
            if(valid(curr[0]-1,curr[1])) queue.push([curr[0]-1,curr[1]]);
            if(valid(curr[0],curr[1]+1)) queue.push([curr[0],curr[1]+1]);
            if(valid(curr[0],curr[1]-1)) queue.push([curr[0],curr[1]-1]);
        }

        return result.reverse();
    }

    var order = bfs();
    for(var i=0; i<k; i++) labirinth[order[i][0]][order[i][1]]=-INF;
    for(var i=0; i<n; i++)
    {
        print(labirinth[i].map(function(e){return e==INF?'#':(e==-INF?'X':'.');}).join(''));
    }


William arrived at a conference dedicated to cryptocurrencies. Networking, meeting new people, and using friends' connections are essential to stay up to date with the latest news from the world of cryptocurrencies.The conference has $$$n$$$ participants, who are initially unfamiliar with each other. William can introduce any two people, $$$a$$$ and $$$b$$$, who were not familiar before, to each other. William has $$$d$$$ conditions, $$$i$$$'th of which requires person $$$x_i$$$ to have a connection to person $$$y_i$$$. Formally, two people $$$x$$$ and $$$y$$$ have a connection if there is such a chain $$$p_1=x, p_2, p_3, \dots, p_k=y$$$ for which for all $$$i$$$ from $$$1$$$ to $$$k - 1$$$ it's true that two people with numbers $$$p_i$$$ and $$$p_{i + 1}$$$ know each other.For every $$$i$$$ ($$$1 \le i \le d$$$) William wants you to calculate the maximal number of acquaintances one person can have, assuming that William satisfied all conditions from $$$1$$$ and up to and including $$$i$$$ and performed exactly $$$i$$$ introductions. The conditions are being checked after William performed $$$i$$$ introductions. The answer for each $$$i$$$ must be calculated independently. It means that when you compute an answer for $$$i$$$, you should assume that no two people have been introduced to each other yet.

The first line contains two integers $$$n$$$ and $$$d$$$ ($$$2 \le n \le 10^3, 1 \le d \le n - 1$$$), the number of people, and number of conditions, respectively. Each of the next $$$d$$$ lines each contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n, x_i \neq y_i$$$), the numbers of people which must have a connection according to condition $$$i$$$.

Output $$$d$$$ integers. $$$i$$$th number must equal the number of acquaintances the person with the maximal possible acquaintances will have, if William performed $$$i$$$ introductions and satisfied the first $$$i$$$ conditions.

NoteThe explanation for the first test case:In this explanation, the circles and the numbers in them denote a person with the corresponding number. The line denotes that William introduced two connected people. The person marked with red has the most acquaintances. These are not the only correct ways to introduce people.

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

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

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

class dsu {
	constructor (n) {
		this.components = n;
		this.data = Array(n).fill(-1);
	}
	unite (a, b) {
		// BEWARE: don't pass undefined values
		a = this.find(a);
		b = this.find(b);
		if (a == b) return;
		this.data[a] += this.data[b];
		this.data[b] = a;
		this.components--;
	}
	find (a) {
		return this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);
	}
	size (a) {
		return -this.data[this.find(a)];
	}
	getcomponents () {
		return this.components;
	}
}

function main () {
	let [n, d] = rna();

	const a = new dsu(n);
	let extras = 0;
	while (d--) {
		let [x, y] = rna(); x--, y--;

		if (a.find(x) == a.find(y)) {
			extras++;
		} else {
			a.unite(x, y);
		}

		const sizes = [];
		for (let i = 0; i < n; i++) {
			if (a.find(i) == i) {
				sizes.push(a.size(i));
			}
		}
		sizes.sort((x, y) => y - x);

		let sum = 0;
		for (let i = 0; i < extras + 1; i++) {
			sum += sizes[i];
		}

		console.log(sum - 1);
	}
}

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

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

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

class dsu {
	constructor (n) {
		this.components = n;
		this.data = Array(n).fill(-1);
	}
	unite (a, b) {
		// BEWARE: don't past undefined values
		a = this.find(a);
		b = this.find(b);
		if (a == b) return;
		this.data[a] += this.data[b];
		this.data[b] = a;
		this.components--;
	}
	find (a) {
		return this.data[a] < 0 ? a : this.data[a] = this.find(this.data[a]);
	}
	size (a) {
		return -this.data[this.find(a)];
	}
	getcomponents () {
		return this.components;
	}
}

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

	const a = new dsu(n);
	let extras = 0;
	for (let i = 0; i < d; i++) {
		let [x, y] = rna(); x--, y--;

		if (a.find(x) == a.find(y)) {
			extras++;
		} else {
			a.unite(x, y);
		}

		const sizes = [];
		for (let j = 0, visited = []; j < n; j++) {
			const cur = a.find(j);
			if (visited[cur]) continue;
			visited[cur] = 1;
			sizes.push(a.size(cur));
		}

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

		let sum = 0;
		for (let j = 0; j < extras + 1; j++) {
			sum += sizes[j];
		}

		console.log(sum- 1);
	}
}

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

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

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

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

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

// SOLUTION:
IS_MULTITEST = false;

class DSU {
  constructor(n){
    this.parents = new Array(n).fill(0);
    this.rank = new Array(n).fill(0);
    for (let i=0; i<n; i++)
      this.parents[i] = i;
  }
  getParent(x){
    if (this.parents[x]==x)
      return x;
    return this.parents[x] = this.getParent(this.parents[x]);
  }
  getRank(x){
    return this.rank[this.getParent(x)];
  }
  unite(x, y){
    x = this.getParent(x);
    y = this.getParent(y);
    if (x != y) {
      if (this.rank[x] < this.rank[y]){
        let tmp = x;
        x = y;
        y = tmp;
      }
      this.parents[y] = x;
      if (this.rank[x] == this.rank[y])
        this.rank[x]++;
    }
  }
}

const calc = (testN)=>{
  // READING:
  let [n, d] = ra();
  LT({n, d});
  let A = [];
  for (let i=0; i<d; i++){
    let [x, y] = ra();
    x--; y--;
    A.push([x, y]);
  }
  // PROCESSING:
  for (let I=0; I<d; I++){
    let dsu = new DSU(n);
    let extra = 0;
    for (let k=0; k<=I; k++){
      let px = dsu.getParent(A[k][0]);
      let py = dsu.getParent(A[k][1]);
      if (px==py){
        extra++
      } else {
        dsu.unite(px, py);
      }
    }
    let sets = [];
    let sizes = {};
    for (let i=0; i<n; i++){
      let p = dsu.getParent(i);
      if (sizes[p]){
        sizes[p]++;
      } else {
        sizes[p] = 1;
        sets.push(p);
      }
    }
    sets.sort((a, b)=>sizes[b]-sizes[a]);
    //L({I, extra, sets, sizes})
    let res = 0;
    for (let i=0; i<=extra && i<sets.length; i++){
      res += sizes[sets[i]];
    }
    print(res-1)
  }
};


Andrew has $$$n$$$ piles with stones. The $$$i$$$-th pile contains $$$a_i$$$ stones. He wants to make his table clean so he decided to put every stone either to the $$$1$$$-st or the $$$n$$$-th pile.Andrew can perform the following operation any number of times: choose $$$3$$$ indices $$$1 \le i < j < k \le n$$$, such that the $$$j$$$-th pile contains at least $$$2$$$ stones, then he takes $$$2$$$ stones from the pile $$$j$$$ and puts one stone into pile $$$i$$$ and one stone into pile $$$k$$$. Tell Andrew what is the minimum number of operations needed to move all the stones to piles $$$1$$$ and $$$n$$$, or determine if it's impossible.

The input contains several test cases. The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$) — the number of test cases. The first line for each test case contains one integer $$$n$$$ ($$$3 \leq n \leq 10^5$$$) — the length of the array. The second line contains a sequence of integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the array elements. It is guaranteed that the sum of the values $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print the minimum number of operations needed to move stones to piles $$$1$$$ and $$$n$$$, or print $$$-1$$$ if it's impossible.

NoteIn the first test case, it is optimal to do the following:   Select $$$(i, j, k) = (1, 2, 5)$$$. The array becomes equal to $$$[2, 0, 2, 3, 7]$$$.  Select $$$(i, j, k) = (1, 3, 4)$$$. The array becomes equal to $$$[3, 0, 0, 4, 7]$$$.  Twice select $$$(i, j, k) = (1, 4, 5)$$$. The array becomes equal to $$$[5, 0, 0, 0, 9]$$$. This array satisfy the statement, because every stone is moved to piles $$$1$$$ and $$$5$$$.  There are $$$4$$$ operations in total.In the second test case, it's impossible to put all stones into piles with numbers $$$1$$$ and $$$3$$$:   At the beginning there's only one possible operation with $$$(i, j, k) = (1, 2, 3)$$$. The array becomes equal to $$$[2, 1, 2]$$$.  Now there is no possible operation and the array doesn't satisfy the statement, so the answer is $$$-1$$$. In the third test case, it's optimal to do the following:   Select $$$(i, j, k) = (1, 2, 3)$$$. The array becomes equal to $$$[2, 0, 2]$$$. This array satisfies the statement, because every stone is moved to piles $$$1$$$ and $$$3$$$.  The is $$$1$$$ operation in total.In the fourth test case, it's impossible to do any operation, and the array doesn't satisfy the statement, so the answer is $$$-1$$$.

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

const rl = () => stdin_input_itr.next().value;
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 ans = 0;
		if (Math.max(...a.slice(1, n-1)) == 1 || n == 3 && a[1]&1) {
			ans = -1;
		} else {
			for (let i = 1; i < n-1; i++) {
				ans += Math.ceil(a[i]/2);
			}
		}

		console.log(ans);
	}
}

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

const rl = () => stdin_input_itr.next().value;
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, odds = 0;
		for (let i = 1; i < n-1; i++) {
			sum += a[i];
			odds += a[i]&1;
		}

		if ((n==3 && sum&1) || sum == n-2) {
			console.log(-1);
		} else {
			console.log(Math.floor(sum/2) + Math.ceil(odds/2));
		}
	}
}

"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++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
    let cnt = 0;
    if((n===3)&&(arr[1]%2===1)){
      console.log(-1);
      continue;
    }
    let ans = false;
    for(let i=1;i<n-1;i++){
      if(arr[i]>1) {
        ans = true;
        break;
      }
    }
    if(!ans){
      console.log(-1);
      continue;
    }
    for(let i=1;i<n-1;i++){
      cnt+=Math.ceil(arr[i]/2);
    }
    console.log(cnt);
};
}
solve();

'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() {
    //Write your code here
    const t = parseInt(readline());
    for(let i = 0; i < t; i++){
        const n = parseInt(readline());
        const arr = readline().split(" ").map((v)=>parseInt(v));
        let ret = 0;
        if(arr.slice(1,arr.length-1).every(v=>v==1)){
            console.log(-1);
            continue;
        }
        if(arr.length==3){
            console.log(arr[1]%2==0?arr[1]/2:-1)
            continue;
        } else {
            for(let i = 1; i < arr.length-1; i++){
                if(arr[i])
                ret+=arr[i]%2==0?arr[i]/2:(arr[i]+1)/2;
            }
        }
        console.log(ret);
    }
}


Vasya has the square chessboard of size n × n and m rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there is a rook located in the cell, this cell is also under attack.You are given the positions of the board where Vasya will put rooks. For each rook you have to determine the number of cells which are not under attack after Vasya puts it on the board.

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ min(100 000, n2)) — the size of the board and the number of rooks.  Each of the next m lines contains integers xi and yi (1 ≤ xi, yi ≤ n) — the number of the row and the number of the column where Vasya will put the i-th rook. Vasya puts rooks on the board in the order they appear in the input. It is guaranteed that any cell will contain no more than one rook.

Print m integer, the i-th of them should be equal to the number of cells that are not under attack after first i rooks are put.

NoteOn the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack.

function rda(){ return readline().split(" ").map(Number); }
function rdn(){ return +readline(); }

var inp = rda(), n = inp[0], m = inp[1];
delete inp;

var ver = [], hor = [];
for(var i = 1; i <= n; i++){
    ver[i] = 0;
    hor[i] = 0;
}

var total = n*n;
var v = 0, h = 0;
var ans = [];
for(var i = 0; i < m; i++){
    var inp = rda(), x = inp[0], y = inp[1];
    delete inp;

    if(hor[x] == 0){
        hor[x] = 1;
        h++;
    }
    if(ver[y] == 0){
        ver[y] = 1;
        v++;
    }
    ans.push( total - (h*n + v*n - v*h) );
}

write(ans.join(" "));

var nm = readline().split(' ').map(
	function(x){
		return parseInt(x);
	}
);
var n = nm[0];
var m = nm[1];
var t = n*n;
var row = [];
var col = [];
var urow = n;
var ucol = n;
function pr(el, i, a){
	write(el + " ");
};
for(i = 0; i < m; ++i){
	var coord = readline().split(' ').map(function(x){return parseInt(x)});
	var x = coord[0] - 1;
	var y = coord[1] - 1;
	if(row[x] == undefined){
		t -= ucol;
		row[x] = 1;
		urow--;
	};
	if(col[y] == undefined){
		t -= urow;
		col[y] = 1;
		ucol--;
	};
	write(t + " ");
};
print();

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var rowsCount = 0;
var colsCount = 0;

var t = n * n;
var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        ++rowsCount;
        t -= (n - colsCount);
    }

    if (cols[y] == undefined) {
        ++colsCount;
        t -= (n - rowsCount);
    }

    results.push(t);

    rows[x] = 1;
    cols[y] = 1;
}

print(results.join(" "));
//console.log(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var rowsCount = 0;
var colsCount = 0;

var t = n * n;
//var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        ++rowsCount;
        t -= (n - colsCount);
    }

    if (cols[y] == undefined) {
        ++colsCount;
        t -= (n - rowsCount);
    }

    //results.push(t);
    write(t+" ");

    rows[x] = 1;
    cols[y] = 1;
}

//print(results.join(" "));
//console.log(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = nm[0];
var m = nm[1];

//var a = [[1, 1], [3, 1], [2, 2]];

var rows = {};
var cols = {};

var t = n * n;
for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (i > 0) {
        if (rows[x] == undefined || cols[y] == undefined) {
            t -= n - 1;
        }
    } else {
        t -= 2 * n - 1;
    }

    print(t);
    //console.log(t);

    if (t == 0) break;

    rows[x] = 1;
    cols[y] = 1;
}

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

var rows = {};
var cols = {};

var t = n * n;
var offset = n;
var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        t -= offset;
    }

    if (cols[y] == undefined) {
        offset -= 1;
        t -= offset;
        if (t < 0) t = 0;
    }

    results.push(t);

    if (t == 0) break;

    rows[x] = 1;
    cols[y] = 1;
}

print(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var t = n * n;
var offsetX = n;
var offsetY = n;
var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        t -= offsetY;
        offsetX -= 1;
    }

    if (cols[y] == undefined) {

        if(rows[x] != undefined) {
            t -= offsetX;
        }

        offsetY -= 1;
        t -= offsetY;
        if (t < 0) t = 0;
    }

    results.push(t);

    if (t == 0) break;

    rows[x] = 1;
    cols[y] = 1;
}

print(results.join(" "));
//console.log(results.join(" "));

var nm = readline().split(" ").map(function(x) { return parseInt(x); });
var n = parseInt(nm[0]);
var m = parseInt(nm[1]);

//var n = 5;
//var m = 2;
//var a = [[1, 5], [5, 1]];

//var n = 3;
//var m = 3;
//var a = [[1, 1], [3, 1], [2, 2]];

//var n = 100000;
//var m = 1;
//var a = [[300, 400]];

//var n = 2;
//var m = 2;
//var a = [[1, 1], [1, 2]];

var rows = {};
var cols = {};

var rowsCount = 0;
var colsCount = 0;

var t = n * n;
//var results = [];

for (var i = 0; i < m; ++i) {
    //var coor = a[i];
    var coor = readline().split(" ").map(function(x) { return parseInt(x); });

    var x = coor[0];
    var y = coor[1];

    if (rows[x] == undefined) {
        ++rowsCount;
        t -= (n - colsCount);
    }

    if (cols[y] == undefined) {
        ++colsCount;
        t -= (n - rowsCount);
    }

    //results.push(t);
    write(t);

    rows[x] = 1;
    cols[y] = 1;
}

//print(results.join(" "));
//console.log(results.join(" "));


Tomorrow is a difficult day for Polycarp: he has to attend $$$a$$$ lectures and $$$b$$$ practical classes at the university! Since Polycarp is a diligent student, he is going to attend all of them.While preparing for the university, Polycarp wonders whether he can take enough writing implements to write all of the lectures and draw everything he has to during all of the practical classes. Polycarp writes lectures using a pen (he can't use a pencil to write lectures!); he can write down $$$c$$$ lectures using one pen, and after that it runs out of ink. During practical classes Polycarp draws blueprints with a pencil (he can't use a pen to draw blueprints!); one pencil is enough to draw all blueprints during $$$d$$$ practical classes, after which it is unusable.Polycarp's pencilcase can hold no more than $$$k$$$ writing implements, so if Polycarp wants to take $$$x$$$ pens and $$$y$$$ pencils, they will fit in the pencilcase if and only if $$$x + y \le k$$$.Now Polycarp wants to know how many pens and pencils should he take. Help him to determine it, or tell that his pencilcase doesn't have enough room for all the implements he needs tomorrow!Note that you don't have to minimize the number of writing implements (though their total number must not exceed $$$k$$$).

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then the test cases follow. Each test case is described by one line containing five integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ and $$$k$$$, separated by spaces ($$$1 \le a, b, c, d, k \le 100$$$) — the number of lectures Polycarp has to attend, the number of practical classes Polycarp has to attend, the number of lectures which can be written down using one pen, the number of practical classes for which one pencil is enough, and the number of writing implements that can fit into Polycarp's pencilcase, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.

For each test case, print the answer as follows: If the pencilcase can't hold enough writing implements to use them during all lectures and practical classes, print one integer $$$-1$$$. Otherwise, print two non-negative integers $$$x$$$ and $$$y$$$ — the number of pens and pencils Polycarp should put in his pencilcase. If there are multiple answers, print any of them. Note that you don't have to minimize the number of writing implements (though their total number must not exceed $$$k$$$).

NoteThere are many different answers for the first test case; $$$x = 7$$$, $$$y = 1$$$ is only one of them. For example, $$$x = 3$$$, $$$y = 1$$$ is also correct.$$$x = 1$$$, $$$y = 3$$$ is the only correct answer for the third test case.

'use strict'

const problem = (a, b, c, d, k) => ((x, y) => (k >= x + y) ? `${x} ${y}` : -1)(Math.ceil(a/c), Math.ceil(b/d));

let t = parseInt(readline());
while (t--) {
    const abcdk = readline().split(' ').map(Number);
    write(problem(abcdk[0], abcdk[1], abcdk[2], abcdk[3], abcdk[4]) + '\n');
}

var t = +readline();

while(t--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
    return Math.ceil(i/j);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [1, 1, 1, 1, 2],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] % query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join(' ') + '\n' : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

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

const main = (input) => {
	for (var i = 1; i <= parseInt(input[0]); i++) {
		var [a, b,c,d, k] = input[i].split(" ").map(num => parseInt(num));
		var aTotal = Math.ceil(a / c);
		var bTotal = Math.ceil(b / d);
		if (aTotal + bTotal <= k) {
			console.log(aTotal, bTotal);
		} else {
			console.log(-1);
		}
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  for(var i = 0; i < t; i++){
    var one = nextIntArray();
    var a = one[0];
    var b = one[1];
    var c = one[2];
    var d = one[3];
    var k = one[4];
    var L = Math.ceil(a / c);
    var R = Math.ceil(b / d);
    if(L + R <= k){
      output[i] = L + " " + R;
    }else{
      output[i] = -1;
    }
  }
  myout(myconv(output, 9));
}

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

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

  const [a, b, c, d, k] = data.split(' ').map(Number);
  const x = Math.ceil(a / c);
  const y = Math.ceil(b / d);

  if (x + y > k) {
    console.log(-1);
  }
  else {
    console.log(x, y);
  }

  count++;
});

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

const sol = () => {
	let line = data.split(/\n/);
    let n = Number(line[0]);
    let ans = [];
    for(let i = 0; i < n; i++){
		let [a, b, c, d, k] = line[i+1].split(/\s/).map(v => Number(v));
		let x = Math.ceil(a/c);
		let y = Math.ceil(b/d);
		if (x + y > k) {
			ans.push(-1);
		} else {
			ans.push(`${x} ${y}`);
		}
	}
	console.log(ans.join('\n'));
};

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

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1);
     else write(x, y);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = Math.ceil(a/c), y = Math.ceil(b/d);
     if(x + y > k) write(-1 + '\n');
     else write(x + ' ' + y + '\n');
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1);
     else print(x, y);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c);
     // , y = findMin(b, d);
     // if(x + y > k) print(-1);
     // else print(x, y);
     print(x,x);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = Math.ceil(a/c), y = Math.ceil(b/d);
     if(x + y > k) print(-1);
     else print(x, y);
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     // var x = findMin(a, c), y = findMin(b, d);
     // if(x + y > k) print(-1);
     // else print(x, y);
     print(a,b);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) write(-1 + '\n');
     else write(x + ' ' + y + '\n');

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var q = readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
     var ans;

     if(j > i) ans = 1;
     else {
          ans = i/j;
          ans += i%j ? 1:0;
     }

     return ans;
}

var t = +readline();

while(t--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1)
     else print(`${x} ${y}`)

}

function findMin(i, j) {
     var ans;

     if(j > i) ans = 1;
     else {
          ans = i/j;
          ans += i%j ? 1:0;
     }

     return ans;
}

var q = +readline();

while(q--) {
     var q = readline().split(' ').map(Number);
     var a = q[0], b=q[1], c=q[2], d=q[3], k=q[4];
     var x = findMin(a, c), y = findMin(b, d);
     if(x + y > k) print(-1);
     else print(x, y);

}

function findMin(i, j) {
     return j > i ? 1 : Math.ceil(i/j);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1" : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join('') : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1\n" : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join(' ') + '\n' : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? -1 : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "\n-1\n" : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1\n" : [x, y].join(' '));

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = xLeftover ? x + 1 : x;

  write(x + y  > query[4] ? [-1].join(' ') : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

var queriesCount = parseInt(readline());
var queries = [];

for (var i = 0; i < queriesCount; i++) {
  queries.push(
    readline().split(' ').map(function(num) {
      return parseInt(num);
    })
  )
}

// queriesCount = 3;
// queries = [
//   [7, 5, 4, 5, 8],
//   [7, 5, 4, 5, 2],
//   [20, 53, 45, 26, 4]
// ]

function main(query) {
  var xLeftover = query[0] % query[2]
  var x = Math.floor(query[0] / query[2]);
  var yLeftover = query[1] / query[3];
  var y = Math.floor(query[1] / query[3]);
  y = yLeftover ? y + 1 : y;
  x = yLeftover ? x + 1 : x;

  write(x + y  > query[4] ? "-1\n" : [x, y].join(' ') + '\n');

}

for (var i = 0; i < queriesCount; i++) {
  main(queries[i]);
}

'use strict'

const problem = (a, b, c, d, k) => ((x, y) => (k <= x + y) ? `${x} ${y}` : -1)(Math.ceil(a/c), Math.ceil(b/d));

let t = parseInt(readline());
while (t--) {
    const abcdk = readline().split(' ').map(Number);
    write(problem(abcdk[0], abcdk[1], abcdk[2], abcdk[3], abcdk[4]) + '\n');
}