Some number of people (this number is even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise starting from a person with the number $$$1$$$. Each person is looking through the circle's center at the opposite person.    A sample of a circle of $$$6$$$ persons. The orange arrows indicate who is looking at whom. You don't know the exact number of people standing in the circle (but this number is even, no doubt). It is known that the person with the number $$$a$$$ is looking at the person with the number $$$b$$$ (and vice versa, of course). What is the number associated with a person being looked at by the person with the number $$$c$$$? If, for the specified $$$a$$$, $$$b$$$, and $$$c$$$, no such circle exists, output -1.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing three distinct integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le a,b,c \le 10^8$$$).

For each test case output in a separate line a single integer $$$d$$$ — the number of the person being looked at by the person with the number $$$c$$$ in a circle such that the person with the number $$$a$$$ is looking at the person with the number $$$b$$$. If there are multiple solutions, print any of them. Output $$$-1$$$ if there's no circle meeting the given conditions.

NoteIn the first test case, there's a desired circle of $$$8$$$ people. The person with the number $$$6$$$ will look at the person with the number $$$2$$$ and the person with the number $$$8$$$ will look at the person with the number $$$4$$$.In the second test case, there's no circle meeting the conditions. If the person with the number $$$2$$$ is looking at the person with the number $$$3$$$, the circle consists of $$$2$$$ people because these persons are neighbors. But, in this case, they must have the numbers $$$1$$$ and $$$2$$$, but it doesn't meet the problem's conditions.In the third test case, the only circle with the persons with the numbers $$$2$$$ and $$$4$$$ looking at each other consists of $$$4$$$ people. Therefore, the person with the number $$$10$$$ doesn't occur in the circle.

var t = Number(readline());

while (t--) {
    var arr = readline().split(" ");
    var a = Number(arr[0]);
    var b = Number(arr[1]);
    var c = Number(arr[2]);
    var ppl = Math.abs(a - b) * 2;
    var ans1 = c + ppl / 2;
    var ans2 = c - ppl / 2;

    if (Math.max(a, b) > ppl || c > ppl)
        print(-1);
    else if (ans1 <= ppl)
        print(ans1);
    else if (ans2 >= 1 && ans2 <= ppl)
        print(ans2);
    else
        print(-1);

}

var t = parseInt(readline());
function formate(v) {return  parseInt(v)}
for(i=0;i<t;++i){
    var list = readline().split(' ').map(formate);
    var a = list[0];
    var b = list[1];
    var c = list[2];
    var size = Math.abs(a - b) * 2;

    if (a > size || b > size || c > size) print(-1);
    else print((c + a - b + size - 1)% size + 1);
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0;i < x;i++){
        let array = readline().split(" ").map(x => parseInt(x));
        let a = array[0]
        let b = array[1]
        let c = array[2]

        let length = 2*Math.abs(a-b);
        if (length < Math.max(a,b) || length < c)
            console.log(-1)
        else
            console.log(c > length/2 ? c - length/2 : c + length/2);
    }
}

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

function main(input) {
    var args = input.split("\n");
    const t = parseInt(args[0], 10);
    for (var i = 1; i <= t; i++) {
        var v = args[i].split(" ").map((n) => parseInt(n, 10));
        var a = v[0], b = v[1], c = v[2];
        if (a > b) {
            [a, b] = [b, a];
        }
        if (2 * a > b) {
            console.log(-1);
            continue;
        }
        var n = 2 * b - 2 * a;
        var d = b - a;
        if (c > n) { console.log(-1); }
        else if (c + d <= n) { console.log(c + d); }
        else if (c - d <= 0) { console.log(-1); }
        else if (c - d > n) { console.log(-1); }
        else { console.log(c - d); }
    }
}

// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.

// var t = Number(readline());

// for (var i = 1; i <= t; i++) {
//     // var a = Number(readline()),
//     //     b = Number(readline()),
//     //     c = Number(readline());
//     var arr = readline().split(' ').map(x => parseInt(x));
//     var a = arr[0],
//         b = arr[1],
//         c = arr[2];
//     var sub = 0;
//     if (a > b) {
//         sub = a - b;
//     } else {
//         sub = b - a;
//     }

//     if (sub * 2 === 2) {
//         console.log(-1);
//     } else if (a > sub * 2 || c > sub * 2) {
//         console.log(-1);
//     } else {
//         var spe1 = c - sub;
//         if (spe1 == 1) {
//             // var spe1 = c - sub;
//             console.log(spe1);
//         } else {
//             var spe2 = sub + sub;
//             console.log(spe2);
//         }
//     }

// }

// var a = Number(readline()),
//         b = Number(readline()),
//         c = Number(readline());

// var t = Number(readline());
// for (var i = 1; i <= t; i++) {
//     var arr = readline().split(' ').map(x => parseInt(x));
//     var a = arr[0],
//         b = arr[1],
//         c = arr[2];
//     let nn = Math.abs(b - a);
//     let n = nn * 2;
//     if (n < a || n < b || n < c) {
//         console.log(-1);
//     } else {
//         if (0 < c - nn && c - nn != a && c - nn != b) {
//             console.log(c - nn);
//         } else if (c + nn <= n && c + nn != a && c + nn != b) {
//             console.log(c + nn);
//         } else {
//             console.log(-1);
//         }
//     }
// }

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

function print(x) {
    console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    for (var i = 1; i <= t; i++) {
        var arr = readline().split(' ').map(x => parseInt(x));
        var a = arr[0],
            b = arr[1],
            c = arr[2];
        let nn = Math.abs(b - a);
        let n = nn * 2;
        if (n < a || n < b || n < c) {
            console.log(-1);
        } else {
            if (0 < c - nn && c - nn != a && c - nn != b) {
                console.log(c - nn);
            } else if (c + nn <= n && c + nn != a && c + nn != b) {
                console.log(c + nn);
            } else {
                console.log(-1);
            }
        }
    }

}

// let inputs = []

// function read() {
//     return inputs.pop();
// }

// function readInt() {
//     return parseInt(read());
// }

// function solve() {
//     let test = readInt();
//     while (test--) {
//         let a = readInt();
//         let b = readInt();
//         let c = readInt();
//         let nn = Math.abs(b - a);
//         let n = nn * 2;
//         if (n < a || n < b || n < c) {
//             console.log(-1);
//         }
//         else {
//             if (0 < c - nn && c - nn != a && c - nn != b) {
//                 console.log(c - nn);
//             }
//             else if (c + nn <= n && c + nn != a && c + nn != b) {
//                 console.log(c + nn);
//             }
//             else {
//                 console.log(-1);
//             }
//         }
//     }
// }

// function main() {
//     inputs = inputString.trim().split(/\n| /).map((string) => string.trim());
//     inputs.reverse();
//     solve();
// }

// let inputString = '';

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

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

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
  let numOfTimes = readline();
  let line;
  while (numOfTimes--) {
    line = readline();
    print(work(...convert(line.split(" "))));
  }
}

function convert(arr){
    return arr.map((ele)=> Number(ele));

}

function work(a, b, c) {
  const max = Math.max(a, b);
  const half = 2 * max - a - b;

  if (max > 2 * half || c > 2 * half) return -1;

  if (c > half) {
    return c - half;
  } else {
    return c + half;
  }
}

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

let c = 0;

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

  const [a1, b1, c1] = d.split(" ").map(Number);
  const diameter = Math.abs(a1 - b1);
  const circle = diameter * 2;

  if (circle < a1 || circle < b1) {
    console.log(-1);
  } else if (c1 > circle) {
    console.log(-1);
  } else {
    const guess = c1 + diameter;
    if (guess > circle) {
      console.log(guess - circle);
    } else {
      console.log(guess);
    }
  }
  c++;
});

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

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0]; var b = k[1]; var c = k[2];
        var dif = Math.abs(a - b);
        var v = dif * 2;
        if(a > v || b > v || c > v){
            console.log(-1);
        }else{
            var d = c + dif;
            if(d > v){
                d = c - dif;
            }
            console.log(d);
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
	var t = lines[0];
	var e = 0;
	for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var a = k[0];
        var b = k[1];
        var c = k[2];
        var dif = Math.abs(a - b);
        var val = dif * 2;
        if(a > val || b > val || c > val){
            console.log(-1);
        }else{
            var d = c + dif;
            if(d > val){
                d = c - dif;
            }
            console.log(d);
        }
	}
});

function main(input) {
    function readline() {
        return input.shift();
    }

    let lines = Number(readline());
    for(let i=0; i<lines; i++) {
        const data = readline().split(' ').map(Number)
        const [a, b, x] = data;

        const offset = Math.abs(a-b)
        const size = offset * 2;

        function getResult(){
            if([a, b, x].every(i => i <= size)) {
                if(x > offset) {
                    return x - offset
                } else {
                    return x + offset
                }
            }
            return '-1';
        }
        console.log(getResult());
    }
}

////////////////////////
let inputString = '';
process.stdin.on('data', (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on('end', (_) => {
    inputString = inputString.trim().split('\n').map((string) => string.trim());

    main(inputString);
});

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  var t=parseInt(readline())

while(t--){
    var array=readline().split(' ').map(x=>parseInt(x));
    var a=array[0];
    var b=array[1];
    var c=array[2]

    var distance=Math.abs(a-b);
    var n=distance*2;
    if(distance<=1){
        print('-1')
    }else if(n<a || n<b || n<c){
        print('-1')
    }
    else if((distance+c)>n){
        print(c-distance)
    }else{
        print(distance+c)
    }

}

}

function solve() {
   let [a, b, c] = readArray(Number);
   if (a > b) {
      const temp = a;
      a = b;
      b = temp;
   }
   const diff = b - a;
   if (!(a <= diff && b > diff) || c > diff * 2) {
      write(-1);
      return;
   }
   if (c <= diff) {
      write(c + diff);
      return;
   }
   write(c - diff);
}

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

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

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

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

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

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

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

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

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

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let [a, b, c] = nl.nums();
		let n = Math.abs(a - b) ;
		if (a > n * 2  || b > n * 2 || c > n * 2){
			ans.push(-1);
		} else {
			ans.push(n >= c?(c + n):(c - n))
		}
	}
	console.log(ans.join('\n'));
};

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

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

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

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

		const k = Math.abs(a-b);

		let ans = -1;
		if (a <= 2*k && b <= 2*k && c <= 2*k) {
			ans = (c + k - 1) % (2 * k) + 1;
		}

		console.log(ans);
	}
}

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

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

function main(input) {
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];

    while(testCases--){
        let [a, b, c] = input[z++].split(' ').map(Number);
        let diff = Math.abs(a - b);
        if((a > diff * 2)){
            console.log(-1);
        }
        else if(b > diff * 2){
            console.log(-1);
        }
        else if(c > diff * 2){
            console.log(-1);
        }
        else{
            let opposite = diff + c <= diff * 2 ? diff + c : Math.abs(diff - c);
            console.log(opposite);
        }
    }
}

abs = Math.abs

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');

let currentline = 0;
function readline(){
    return input[currentline++];
}

function solve() {
    let lis = readline("enter a number").split(" ");
    let a, b, c;
    a = parseInt(lis[0]);
    b = parseInt(lis[1]);
    c = parseInt(lis[2]);
    if (abs(a - b) * 2 < Math.max(a, b, c)) {
        return -1

    } else {
        let x = abs(b-a);
        let ans = (c + x) ;
        if (ans > (x*2)){
            return c-x
        }
        return ans

    }
}
for (let i = parseInt(readline()); i > 0; i--) {
    console.log(solve())
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const assert = (condition) => { if (!condition) throw new Error("Assertion failed"); }
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const int = parseInt;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg2 = Math.log2;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (n, m) => { let data = []; for (let i = 0; i < n; i++) { let tmp = Array(m).fill(0); data.push(tmp); } return data; };
const initialize3DArray = (n, m, p) => { let res = []; for (let i = 0; i < n; i++) { let data = []; for (let j = 0; j < m; j++) { let tmp = new Array(p).fill(0); data.push(tmp); } res.push(data); } return res; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
const ups = (s, i, c) => s.slice(0, i) + c + s.slice(i + 1);
const isSubsequence = (s, t) => { let sn = s.length; let tn = t.length; let i = j = 0; while (i < sn && j < tn) { if (s[i] == t[j]) { i++; j++; } else { i++; } } return j == tn; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 08/18/21 morning
 * https://codeforces.com/contest/1560/problem/B
 */
const solve = (a, b, c) => {
    // pr()
    // pr(a, b, c)
    let half = Math.abs(a - b);
    let tot = half * 2;
    // pr("tot", tot)
    if (c > tot || a > tot || b > tot) return pr(-1);
    if (c - half >= 1 && c - half != a && c- half != b) return pr(c - half);
    if (c + half <= tot && c + half != a && c + half != b) return pr(c + half);
    pr(-1);
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i][1], input[i][2]);
            i++;
        }
    });
};

main()

let inputs = []

function read() {
    return inputs.pop();
}

function readInt() {
    return parseInt(read());
}

function solve() {
    let test = readInt();
    while (test--) {
        let a = readInt();
        let b = readInt();
        let c = readInt();
        let nn = Math.abs(b - a);
        let n = nn * 2;
        if (n < a || n < b || n < c) {
            console.log(-1);
        }
        else {
            if (0 < c - nn && c - nn != a && c - nn != b) {
                console.log(c - nn);
            }
            else if (c + nn <= n && c + nn != a && c + nn != b) {
                console.log(c + nn);
            }
            else {
                console.log(-1);
            }
        }
    }
}

function main() {
    inputs = inputString.trim().split(/\n| /).map((string) => string.trim());
    inputs.reverse();
    solve();
}

let inputString = '';

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

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

function max(a, b) {
  if (a > b) {
    return {
      max: a,
      min: b
    };
  }
  return {
    max: b,
    min: a
  }
}

function solve(a, b, c) {
  const { max: maxValue, min: minValue } = max(a, b);
  const n = (maxValue - minValue) * 2;
  if (maxValue < (n / 2 + 1)) {
    return -1;
  }
  if (minValue >= (n / 2 + 1)) {
    return -1;
  }
  let res = -1;
  if (c < (n / 2 + 1)) {
    res = n / 2 + c;
    if (res < (n / 2 + 1)) {
      return -1;
    }
  } else {
    res = c - n / 2;
    if (res >= (n / 2 + 1)) {
      return -1;
    }
  }
  return res;
}

function main(array) {
  const T = array[0];
  for (let i = 0; i < T; i++) {
    const arr = array[i + 1];
    const [a, b, c] = arr.split(' ').map((item) => parseInt(item, 10));
    console.log(solve(a, b, c));
  }
}

let inputString = '';

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

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

  main(inputString);
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var A = nextInt();
		var B = nextInt();
		var tmp1 = Math.min(A, B);
		var tmp2 = Math.max(A, B);
		A = tmp1;
		B = tmp2;
		var C = nextInt();
		if(Math.abs(A - B) == 1){
			myout(-1);
			continue;
		}
		var size = Math.abs(A - B) * 2;
		if(size < C || size < A || size < B){
			myout(-1);
			continue;
		}
		var low = B - (size / 2);
		var high = B + (size / 2);
		if(high > size){
			high -= size;
		}
		if(low != high){
			myout(-1);
			continue;
		}
		var nx = C + (size / 2);
		if(nx > size){
			nx -= size;
		}
		myout(nx);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

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

function main() {
  const xx = readline();
  var array = []
  var i = 0
  while (true) {
    i++
    if (array.length === 1000) break
    if (i % 3 === 0 || i % 10 === 3) continue
    array.push(i)

  }
  // console.log(array)
  Array(Number(xx)).fill(1).map((t, i) => {
    // var n = parseInt(readline());

    var [a, b, c] = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    })
    var dd = Math.abs(b - a)

    var max = dd * 2
    if (max < a || max < b || max < c) return console.log(-1)
    var answer = (c + dd) % (max)

    if(c === dd) return  console.log(max)
    if(c === max) return  console.log(dd)
    console.log(answer)
  })
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readLineAsNumber() {
    return Number(this.readLine())
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(String(e))
  }
  println(e) {
    stdout.write(String(e)), stdout.write('\n')
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  const s = Math.abs(e - n)
  if (e > s && n > s) return -1
  const i = 2 * s
  return t > i ? -1 : t + s <= i ? t + s : t - s >= 1 ? t - s : -1
}
__main__(function (e) {
  const n = e.readLineAsNumber()
  for (let t = 1; t <= n; ++t) {
    const [n, t, s] = e.readIntegersOfLine(),
      i = solve(n, t, s)
    e.print(i + '\n')
  }
})

const readline = require('readline')

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

function solve(a, b, c) {
    const k = Math.abs(a - b)
    const n = 2 * k
    // console.log(n, a, b)
    if (a > n || b > n) return -1
    if (c > n || c + k > n && c - k < 1) return -1

    if (c + k <= n) {
        return c + k
    } else {
        return c - k
    }
}

var t = Number(readline());

while (t--) {
    var arr = readline().split(" ");
    var a = Number(arr[0]);
    var b = Number(arr[1]);
    var c = Number(arr[2]);
    var ppl = Math.abs(a - b) * 2;
    var ans1 = c + ppl / 2;
    var ans2 = c - ppl / 2;

    if (Math.max(a, b) > ppl)
        print(-1);
    else if (ans1 <= ppl)
        print(ans1);
    else if (ans2 >= 1 && ans2 <= ppl)
        print(ans2);
    else
        print(-1);

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0;i < x;i++){
        let array = readline().split(" ").map(x => parseInt(x));
        let a = array[0]
        let b = array[1]
        let c = array[2]

        let length = 2*(a-b);
        if (length < Math.max(a,b) || length < c)
            console.log(-1)
        else
            console.log(c > length/2 ? c - length/2 : c + length/2);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0;i < x;i++){
        let array = readline().split(" ").map(x => parseInt(x));
        let a = array[0]
        let b = array[1]
        let c = array[2]

        let length = 2*(a-b);
        if (length < Math.max(a,b) || length < c){
            console.log(-1)
            continue;
        }

        console.log(c > length/2 ? c - length/2 : c + length/2);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0;i < x;i++){
        let array = readline().split(" ").map(x => parseInt(x));
        let a = array[0]
        let b = array[1]
        let c = array[2]

        let length = 2*(a-b);
        if (length < Math.max(a,b,c)){
            console.log(-1)
            continue;
        }

        console.log(c > length/2 ? c - length/2 : c + length/2);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0;i < x;i++){
        let array = readline().split(" ").map(x => parseInt(x));
        let a = array[0]
        let b = array[1]
        let c = array[2]

        let length = 2*(a-b);
        if (length < Math.max(a,b) || length < c){
            console.log(-1)
        }

        console.log(c > length/2 ? c - length/2 : c + length/2);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

    for(let i = 0;i < x;i++){
        let array = readline().split(" ").map(x => parseInt(x));
        let a = array[0]
        let b = array[1]
        let c = array[2]

        let length = 2*(a-b);
        if (length < Math.max(a,b,c)){
            console.log(-1)
        }

        console.log(c > length/2 ? c - length/2 : c + length/2);
    }
}

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

function main(input) {
    var args = input.split("\n");
    const t = parseInt(args[0], 10);
    for (var i = 1; i <= t; i++) {
        var v = args[i].split(" ").map((n) => parseInt(n, 10));
        var a = v[0], b = v[1], c = v[2];
        if (a > b) {
            [a, b] = [b, a];
        }
        if (2 * a > b) {
            console.log(-1);
            continue;
        }
        var n = 2 * a - 2 * b;
        var d = b - a;
        if (c > n) { console.log(-1); }
        else if (c + d <= n) { console.log(c + d); }
        else if (c - d <= 0) { console.log(-1); }
        else if (c - d > n) { console.log(-1); }
        else { console.log(c - d); }
    }
}

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

function main(input) {
    var args = input.split("\n");
    const t = parseInt(args[0], 10);
    for (var i = 1; i <= t; i++) {
        var v = args[i].split(" ").map((n) => parseInt(n, 10));
        var a = v[0], b = v[1], c = v[2];
        if (a > b) {
            [a, b] = [b, a];
        }
        if (2 * a > b) {
            console.log(-1);
            continue;
        }
        var n;
        for (var j = 0; j <= 10000; j++) {
            if (2 * (a + j) === b + j) {
                n = b + j;
            }
        }
        var d = b - a;
        if (c > n) { console.log(-1); }
        else if (c + d <= n) { console.log(c + d); }
        else if (c - d <= 0) { console.log(-1); }
        else if (c - d > n) { console.log(-1); }
        else { console.log(c - d); }
    }
}

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

function main(input) {
    var args = input.split("\n");
    const t = parseInt(args[0], 10);
    for (var i = 1; i <= t; i++) {
        var v = args[i].split(" ").map((n) => parseInt(n, 10));
        var a = v[0], b = v[1], c = v[2];
        if (a > b) {
            [a, b] = [b, a];
        }
        if (2 * a > b) {
            console.log(-1);
            continue;
        }
        var n;
        for (var j = 0; j <= 10000; j++) {
            if (2 * (a + j) === b + j) {
                n = b + j;
            }
        }
        var d = b - a;
        if (c + d <= n) { console.log(c + d); }
        else if (c - d <= 0) { console.log(-1); }
        else if (c - d > n) { console.log(-1); }
        else { console.log(c - d); }
    }
}

// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.

// var t = Number(readline());

// for (var i = 1; i <= t; i++) {
//     // var a = Number(readline()),
//     //     b = Number(readline()),
//     //     c = Number(readline());
//     var arr = readline().split(' ').map(x => parseInt(x));
//     var a = arr[0],
//         b = arr[1],
//         c = arr[2];
//     var sub = 0;
//     if (a > b) {
//         sub = a - b;
//     } else {
//         sub = b - a;
//     }

//     if (sub * 2 === 2) {
//         console.log(-1);
//     } else if (a > sub * 2 || c > sub * 2) {
//         console.log(-1);
//     } else {
//         var spe1 = c - sub;
//         if (spe1 == 1) {
//             // var spe1 = c - sub;
//             console.log(spe1);
//         } else {
//             var spe2 = sub + sub;
//             console.log(spe2);
//         }
//     }

// }

// var t = Number(readline());
// for (var i = 1; i <= t; i++) {
//     var a = Number(readline()),
//         b = Number(readline()),
//         c = Number(readline());
//     let nn = Math.abs(b - a);
//     let n = nn * 2;
//     if (n < a || n < b || n < c) {
//         console.log(-1);
//     } else {
//         if (0 < c - nn && c - nn != a && c - nn != b) {
//             console.log(c - nn);
//         } else if (c + nn <= n && c + nn != a && c + nn != b) {
//             console.log(c + nn);
//         } else {
//             console.log(-1);
//         }
//     }
// }

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

function print(x) {
    console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());

    for (var i = 1; i <= t; i++) {
        // var a = Number(readline()),
        //     b = Number(readline()),
        //     c = Number(readline());
        var arr = readline().split(' ').map(x => parseInt(x));
        var a = arr[0],
            b = arr[1],
            c = arr[2];
        var sub = 0;
        if (a > b) {
            sub = a - b;
        } else {
            sub = b - a;
        }

        if (sub * 2 === 2) {
            console.log(-1);
        } else if (a > sub * 2 || c > sub * 2) {
            console.log(-1);
        } else {
            var spe1 = c - sub;
            if (spe1 == 1) {
                // var spe1 = c - sub;
                console.log(spe1);
            } else {
                var spe2 = sub + sub;
                console.log(spe2);
            }
        }

    }

}

// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.

// var t = Number(readline());
// for (var i = 1; i <= t; i++) {
//     var a = Number(readline()),
//         b = Number(readline()),
//         c = Number(readline());
//     let nn = Math.abs(b - a);
//     let n = nn * 2;
//     if (n < a || n < b || n < c) {
//         console.log(-1);
//     } else {
//         if (0 < c - nn && c - nn != a && c - nn != b) {
//             console.log(c - nn);
//         } else if (c + nn <= n && c + nn != a && c + nn != b) {
//             console.log(c + nn);
//         } else {
//             console.log(-1);
//         }
//     }
// }

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

function print(x) {
    console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    for (var i = 1; i <= t; i++) {
        var a = Number(readline()),
            b = Number(readline()),
            c = Number(readline());
        let nn = Math.abs(b - a);
        let n = nn * 2;
        if (n < a || n < b || n < c) {
            console.log(-1);
        } else {
            if (0 < c - nn && c - nn != a && c - nn != b) {
                console.log(c - nn);
            } else if (c + nn <= n && c + nn != a && c + nn != b) {
                console.log(c + nn);
            } else {
                console.log(-1);
            }
        }
    }
}

// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.

// var t = Number(readline());
// for (var i = 1; i <= t; i++) {
//     var a = Number(readline()),
//         b = Number(readline()),
//         c = Number(readline());
//     var sub = 0;
//     if (a > b) {
//         sub = a - b;
//     } else {
//         sub = b - a;
//     }

//     if (sub * 2 === 2) {
//         console.log(-1);
//     } else if (a > sub * 2 || c > sub * 2) {
//         console.log(-1);
//     } else {
//         var spe1 = c - sub;
//         if (spe1 === 1) {
//             console.log(spe1);
//         } else {
//             var spe2 = sub + sub;
//             console.log(spe2);
//         }
//     }

// }

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

function print(x) {
    console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    for (var i = 1; i <= t; i++) {
        var a = Number(readline()),
            b = Number(readline()),
            c = Number(readline());
        var sub = 0;
        if (a > b) {
            sub = a - b;
        } else {
            sub = b - a;
        }

        if (sub * 2 === 2) {
            console.log(-1);
        } else if (a > sub * 2 || c > sub * 2) {
            console.log(-1);
        } else {
            var spe1 = c - sub;
            if (spe1 === 1) {
                console.log(spe1);
            } else {
                var spe2 = sub + sub;
                console.log(spe2);
            }
        }

    }

}

// Aujubillhi minassaitoanir rajim Vismillahir Rahmanir Rahim (Allah Hu Ackbar) Allah is Greatest.

// var t = Number(readline());
// for (var i = 0; i <= t; i++) {
//     var a = Number(readline()),
//         b = Number(readline()),
//         c = Number(readline());
//     var sub = 0;
//     if (a > b) {
//         sub = a - b;
//     } else {
//         sub = b - a;
//     }

//     if (sub * 2 === 2) {
//         console.log(-1);
//     } else if (a > sub * 2 || c > sub * 2) {
//         console.log(-1);
//     } else {
//         var spe1 = c - sub;
//         if (spe1 === 1) {
//             console.log(spe1);
//         } else {
//             var spe2 = sub + sub;
//             console.log(spe2);
//         }
//     }

// }

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

function print(x) {
    console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});

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

// ************************ Code Start ***************************

function main() {

    var t = Number(readline());
    for (var i = 0; i <= t; i++) {
        var a = Number(readline()),
            b = Number(readline()),
            c = Number(readline());
        var sub = 0;
        if (a > b) {
            sub = a - b;
        } else {
            sub = b - a;
        }

        if (sub * 2 === 2) {
            console.log(-1);
        } else if (a > sub * 2 || c > sub * 2) {
            console.log(-1);
        } else {
            var spe1 = c - sub;
            if (spe1 === 1) {
                console.log(spe1);
            } else {
                var spe2 = sub + sub;
                console.log(spe2);
            }
        }

    }
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {

  let numOfTimes = readline();
  let line;
  print(readline())
  while (numOfTimes--) {
    line = readline();
    print(work(...line.split(" ")));
  }
}

function work(a,b,c){
const max= Math.max(a,b);
const half= 2*max - a-b;

if((max>2*half)||(c>2*half)) return -1

if(c>half){
    return c-half
}
else{
    return c+half;
}

}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ********** Code Start **********

function main() {
  let numOfTimes = readline();
  let line;
  while (numOfTimes--) {
    line = readline();
    print(work(...line.split(" ")));
  }
}

function work(a,b,c){
const max= Math.max(a,b);
const half= 2*max - a-b;

if((max>2*half)||(c>2*half)) return -1

if(c>half){
    return c-half
}
else{
    return c+half;
}

}

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

let c = 0;

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

  const [a1, b1, c1] = d.split(" ").map(Number);
  const diameter = Math.abs(a1 - b1);
  const circle = diameter * 2;

  if (circle < a1 || circle < b1) {
    console.log(-1);
  } else if (c1 >= circle) {
    console.log(-1);
  } else {
    const guess = c1 + diameter;
    if (guess > circle) {
      console.log(guess - circle);
    } else {
      console.log(guess);
    }
  }
  c++;
});

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

function main(input) {
    function readline() {
        return input.shift();
    }

    let lines = Number(readline());
    for(let i=0; i<lines; i++) {
        const data = readline().split(' ').map(Number)
        const [a, b, x] = data;

        const offset = Math.abs(a-b)
        const size = offset * 2;

        function getResult(){
            if([a, b, x].every(i => i < size)) {
                if(x > offset) {
                    return x - offset
                } else {
                    return x + offset
                }
            }
            return '-1';
        }
        console.log(getResult());
    }
}

////////////////////////
let inputString = '';
process.stdin.on('data', (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on('end', (_) => {
    inputString = inputString.trim().split('\n').map((string) => string.trim());

    main(inputString);
});

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  var t=parseInt(readline())

while(t--){
    var array=readline().split(' ').map(x=>parseInt(x));
    var a=array[0];
    var b=array[1];
    var c=array[2]

    var distance=Math.abs(a-b);
    var n=distance*2;
    if(distance<=1){
        print('-1')
    }else if(n<=a || n<=b || n<c){
        print('-1')
    }
    else if((distance+c)>n){
        print(c-distance)
    }else{
        print(distance+c)
    }

}

}

function solve() {
   let [a, b, c] = readArray(Number);
   if (a > b) {
      const temp = a;
      a = b;
      b = temp;
   }
   const diff = b - a;
   if (!(a <= diff && b > diff)) {
      write(-1);
      return;
   }
   const ans1 = c + diff;
   const ans2 = c - diff;
   if (ans1 <= diff * 2 && ans1 > 0) {
      write(ans1);
      return;
   }
   if (ans2 <= diff * 2 && ans2 > 0) {
      write(ans2);
      return;
   }
   write(-1);
}

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

function modPow(a, n, mod) {
   let d = a;
   let curN = n;
   let ans = 1n;
   while(curN) {
      if (curN & 1n) {
         ans = modMul(ans, d, mod);
      }
      curN >>= 1n;
      d = modMul(d, d, mod);
   }
   return ans;
}

function modMul(a, b, mod) {
   return (a * b) % mod;
}

function modSum(a, b, mod) {
   return (a + b) % mod;
}

function modDiff(a, b, mod) {
   return (a + mod - b) % mod;
}

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

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

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

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

function xor(a, b, k) {
   if (k === 2) {
      return a ^ b;
   }
}

function decToBin(num) {
   let n = num;
   const ans = [];
   while(n > 0) {
      ans.push(n & 1);
      n = (n >> 1);
   }
   return ans;
}

function binToDec(binN) {
   let ans = 0;
   for (let i = binN.length - 1; i >= 0; i--) {
      ans = ((ans << 1) | binN[i]);
   }
   return ans;
}

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

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

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

   var inTextName;
   var outTextName;

   var needWriteFile = false;

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

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

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


Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?You can assume that initially Vanya had infinitely many cards with each integer number from  - x to x.

The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.

Print a single number — the answer to the problem.

NoteIn the first sample, Vanya needs to find a single card with number -2.In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.

print(function(n, x) {
	var sum = readline().split(' ').map(Number).reduce(function(a, b) {
		return a + b;
	});
	sum = Math.abs(sum);
	return Math.ceil(sum / x);
}.apply(0, readline().split(' ').map(Number)));

function sum(array){
	var result = 0;
	for(var i = 0; i < array.length; i++){
		result += +array[i];
	}
	return result;
}

var input = readline().split(" "), n = +input[0], x = +input[1], numbers = readline().split(" ").map(Number),
all = sum(numbers);

if(all == 0){
	write(0);
}
else{
	if(Math.abs(all) <= x){
		write(1);
	}
	else{
		write(Math.ceil(Math.abs(all)/x));
	}
}

var x = +readline().split(' ')[1];

var s = Math.abs(readline().split(' ').map(Number).reduce(function (p, e) { return p + e; }, 0));

var t = 0;

while (s > 0) {
	t++;
	s -= x;
}

print(t);

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 foundNum = integers[0], max = integers[1];
	var cards = tokenizeIntegers(readline());
	var sum = 0;
	for (var i = 0; i < cards.length; ++i) {
		sum += cards[i];
	}
	sum = Math.abs(sum);
	var count = 0;
	while (sum > max) {
		sum -= max;
		count += 1;
	}
	if (sum > 0) {
		count += 1;
	}
	print(count);
}

main();

function solve(){
    var input = readline().split(" ");
    var n = parseInt(input[0]);
    var x = parseInt(input[1]);
    var a = readline().split(" ");
    var sum = 0;
    for(var i = 0; i < a.length; i++){
        sum += parseInt(a[i]);
    }
    sum = sum < 0 ? -sum : sum;
    var res = Math.floor((sum + x - 1)/x);
    print(res);
}
solve();

function main() {
  var nx = readline().split(' ');
  var line = readline().split(' ');
  var n = Number(nx[0]),
    x = Number(nx[1]),
    sum = 0;

  for (var i = 0; i < n; i++) {
    sum += Number(line[i]);
  }

  var changes = 0;

  while (sum > 0) {
    if (sum > x) {
      sum -= x;
      changes++;
    } else {
      sum = 0;
      changes++;
    }
  }

  while (sum < 0) {
    if (sum * -1 > x) {
      sum += x;
      changes++;
    } else {
      sum = 0;
      changes++;
    }
  }

  print(changes);
}

main();

function main(){
    var line = readline().split(' ');
    var n = parseInt(line[0]);
    var x = parseInt(line[1]);
    var sum = 0;
    readline().split(' ').forEach(function (v){
        sum += parseInt(v);
    });
    print(Math.ceil(Math.abs(sum)/x));
}
main();

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, x] = d.split(' ').map(Number);
    return;
  }

  const arr = d.split(' ').map(Number);
  const sum = Math.abs(arr.reduce((a, b) => a + b, 0));
  const ans = Math.ceil(sum / x);

  console.log(ans);
  c++;
});

/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces_401A
var gi = process.stdin;
gi.setEncoding('utf8');
var go = (x) => process.stdout.write(x);
function parseArray(line) { return line.split(' ').map(function (a) { return parseInt(a); }); }

let main = function(data){
	var lines = data.split("\n");
	var a = parseArray(lines[0]);
	var n = a[0], x = a[1];
	a = parseArray(lines[1]);
	var sum = 0;
	for (var k in a) {
		sum += a[k];
	}
	sum = Math.abs(sum);
	var ans = Math.floor(sum/x);
	if (sum%x != 0) { ans++; }
	go(ans + "");
	return 0;
}
gi.on("data", main);

var x = +readline().split(' ')[1];

var s = Math.abs(readline().split(' ').map(Number).reduce(function (p, e) { return p + e; }, 0));

var t = 0;

while (s > 0) {
	t++;
	s -= (x-1);
}

print(t);

function main(){
    var line = readline().split(' ');
    var n = parseInt(line[0]);
    var x = parseInt(line[1]);
    var sum = 0;
    readline().split(' ').forEach(function (v){
        sum += parseInt(v);
    });
    print(Math.ceil(sum/x));
}
main();

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, x] = d.split(' ').map(Number);
    return;
  }

  const arr = d.split(' ').map(Number);
  const sum = Math.abs(arr.reduce((a, b) => a + b, 0));
  const ans = Math.floor(sum / x) + sum % x;

  console.log(ans);
  c++;
});


YouKn0wWho has two even integers $$$x$$$ and $$$y$$$. Help him to find an integer $$$n$$$ such that $$$1 \le n \le 2 \cdot 10^{18}$$$ and $$$n \bmod x = y \bmod n$$$. Here, $$$a \bmod b$$$ denotes the remainder of $$$a$$$ after division by $$$b$$$. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$)  — the number of test cases. The first and only line of each test case contains two integers $$$x$$$ and $$$y$$$ ($$$2 \le x, y \le 10^9$$$, both are even).

For each test case, print a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^{18}$$$) that satisfies the condition mentioned in the statement. If there are multiple such integers, output any. It can be shown that such an integer always exists under the given constraints.

NoteIn the first test case, $$$4 \bmod 4 = 8 \bmod 4 = 0$$$.In the second test case, $$$10 \bmod 4 = 2 \bmod 10 = 2$$$.In the third test case, $$$420 \bmod 420 = 420 \bmod 420 = 0$$$.

const readline = require('readline')

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

function solve(x, y) {
    const ab = Math.floor(y / x)
    const b1r = y % x
// console.log('-', ab, b1r)
    if (!ab) {
        // y < x
        return x + y
    }
    const limit = Math.sqrt(ab)
    for (let i = 1; i <= limit; i++) {
        if (ab % i) continue
        // b = i or ab / i
        let b = i
        if (!(b1r % (b + 1))) {
            const r = b1r / (b + 1)
            const n = (y - r) / b
            // console.log('b1', b, n)
            if (r < x && r < y) return n
        }
        b = ab / i
        if (!(b1r % (b + 1))) {
            const r = b1r / (b + 1)
            const n = (y - r) / b
            // console.log('b2', b, n)
            if (r < x && r < y) return n
        }
        // console.log(i, ab)
    }
}

'use strict';

function solve(x, y) {
  if (x === y) return x;else if (x > y) return x + y;else if (y % x === 0) return x;else return y - (x + y) / 2 % x;
}

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

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

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

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

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

		let ans;
		if (x > y)
			ans = x + y;
		else
			ans = y - y%x/2;

		console.log(ans);
	}
}

'use strict';

function solve(x, y) {
  if (x === y) return x;else if (x > y) return x + y;else if (y % x === 0) return x;else return (x + y) / 2;
}

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

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

'use strict';

function solve(x, y) {
  if (x === y) return x;else if (x > y) return x + y;else return (x + y) / 2;
}

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

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

'use strict';

function solve(x, y) {
  if (x === y) return x;else if (x > y) return x + y;else return (x + y) / 2;
}

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

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

'use strict';

function solve(n, m) {
  if (n === m) return n;else if (n > m) return n + m;else return (n + m) / 2;
}

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

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


The Happy Farm 5 creators decided to invent the mechanism of cow grazing. The cows in the game are very slow and they move very slowly, it can even be considered that they stand still. However, carnivores should always be chased off them. For that a young player Vasya decided to make the shepherd run round the cows along one and the same closed path. It is very important that the cows stayed strictly inside the area limited by the path, as otherwise some cows will sooner or later be eaten. To be absolutely sure in the cows' safety, Vasya wants the path completion time to be minimum.The new game is launched for different devices, including mobile phones. That's why the developers decided to quit using the arithmetics with the floating decimal point and use only the arithmetics of integers. The cows and the shepherd in the game are represented as points on the plane with integer coordinates. The playing time is modeled by the turns. During every turn the shepherd can either stay where he stands or step in one of eight directions: horizontally, vertically, or diagonally. As the coordinates should always remain integer, then the length of a horizontal and vertical step is equal to 1, and the length of a diagonal step is equal to . The cows do not move. You have to minimize the number of moves the shepherd needs to run round the whole herd.

The first line contains an integer N which represents the number of cows in the herd (1 ≤ N ≤ 105). Each of the next N lines contains two integers Xi and Yi which represent the coordinates of one cow of (|Xi|, |Yi| ≤ 106). Several cows can stand on one point.

Print the single number — the minimum number of moves in the sought path.

NotePicture for the example test: The coordinate grid is painted grey, the coordinates axes are painted black, the cows are painted red and the sought route is painted green.

var n = parseInt(readline());
var _points = []

for (var i=0; i<n; i++) {
  var point = readline().split(' ').map(Number);
  _points.push(point);
}

_points = _points.sort(function(a,b){return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0];});
var points = [_points[0]];
for (var i=1; i<_points.length; i++) {
  if (_points[i][0] != _points[i-1][0] || _points[i][1] != _points[i-1][1]) {
    points.push(_points[i]);
  }
}

var chull;
n = points.length;

function ccw(a,b,c) {
  return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]) <= 0;
}
if (points.length > 3) {
  var upper = []
  for (var i=0; i<n; i++) {
    while (upper.length >= 2 && ccw(upper[upper.length-2], upper[upper.length-1], points[i]))
      upper.pop();
    upper.push(points[i]);
  }
  upper.pop();

  var lower = []
  for (var i=n-1; i>=0; i--) {
    while (lower.length >= 2 && ccw(lower[lower.length-2], lower[lower.length-1], points[i]))
      lower.pop();
    lower.push(points[i]);
  }
  lower.pop()
  chull = upper.concat(lower);
} else {
  chull = points;
}

function length(a, b) {
  return Math.max(Math.abs(a[0] - b[0]), Math.abs(a[1] - b[1]));
}

var ret = 0;
for (var i=0;i<chull.length;i++) {
  ret += length(chull[i], chull[(i+1) % chull.length]);
}
print(ret + 4);

var n = parseInt(readline());
var points = []

for (var i=0; i<n; i++) {
  var point = readline().split(' ').map(Number);
  points.push(point);
}

points = points.sort(function(a,b){return a[0] == b[0] ? b[1] - a[1] : a[0] - b[0];});

function ccw(a,b,c) {
  return (b[0] - a[0]) * (c[1] - a[1]) + (b[1] - a[1]) * (c[0] - a[0]) > 0;
}

var upper = []
for (var i=0; i<n; i++) {
  while (upper.length > 2 && ccw(upper[upper.length-2], upper[upper.length-1], points[i]))
    upper.pop();
  upper.push(points[i]);
}
upper.pop();

var lower = []
for (var i=n-1; i>=0; i--) {
  while (lower.length > 2 && ccw(lower[lower.length-2], lower[lower.length-1], points[i]))
    lower.pop();
  lower.push(points[i]);
}
lower.pop()

var chull = upper.concat(lower);

function length(a, b) {
  return Math.max(Math.abs(a[0] - b[0]), Math.abs(a[1] - b[1]));
}

var ret = 0;
for (var i=0;i<chull.length;i++) {
  ret += length(chull[i], chull[(i+1) % chull.length]);
}
print(ret + 4);

var n = parseInt(readline());
var points = []

for (var i=0; i<n; i++) {
  var point = readline().split(' ').map(Number);
  points.push(point);
}

points = points.sort(function(a,b){return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0];});
for (var i=1; i<points.length; i++) {
  if (points[i][0] == points[i-1][0] && points[i][1] == points[i-1][1]) {
    points.splice(i--, 1);
  }
}

var chull;
n = points.length;

function ccw(a,b,c) {
  return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]) > 0;
}
if (points.length > 3) {
  var upper = []
  for (var i=0; i<n; i++) {
    while (upper.length > 2 && ccw(upper[upper.length-2], upper[upper.length-1], points[i]))
      upper.pop();
    upper.push(points[i]);
  }
  upper.pop();

  var lower = []
  for (var i=n-1; i>=0; i--) {
    while (lower.length > 2 && ccw(lower[lower.length-2], lower[lower.length-1], points[i]))
      lower.pop();
    lower.push(points[i]);
  }
  lower.pop()
  chull = upper.concat(lower);
} else {
  chull = points;
}

function length(a, b) {
  return Math.max(Math.abs(a[0] - b[0]), Math.abs(a[1] - b[1]));
}

var ret = 0;
for (var i=0;i<chull.length;i++) {
  ret += length(chull[i], chull[(i+1) % chull.length]);
}
print(ret + 4);

var n = parseInt(readline());
var points = []

for (var i=0; i<n; i++) {
  var point = readline().split(' ').map(Number);
  points.push(point);
}

points = points.sort(function(a,b){return a[0] == b[0] ? a[1] - b[1] : a[0] - b[0];});

var chull;

function ccw(a,b,c) {
  return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]) > 0;
}
if (points.length > 3) {
  var upper = []
  for (var i=0; i<n; i++) {
    while (upper.length > 2 && ccw(upper[upper.length-2], upper[upper.length-1], points[i]))
      upper.pop();
    upper.push(points[i]);
  }
  upper.pop();

  var lower = []
  for (var i=n-1; i>=0; i--) {
    while (lower.length > 2 && ccw(lower[lower.length-2], lower[lower.length-1], points[i]))
      lower.pop();
    lower.push(points[i]);
  }
  lower.pop()
  chull = upper.concat(lower);
} else {
  chull = points;
}

function length(a, b) {
  return Math.max(Math.abs(a[0] - b[0]), Math.abs(a[1] - b[1]));
}

var ret = 0;
for (var i=0;i<chull.length;i++) {
  ret += length(chull[i], chull[(i+1) % chull.length]);
}
print(ret + 4);

var n = parseInt(readline());
var points = []

for (var i=0; i<n; i++) {
  var point = readline().split(' ').map(Number);
  points.push(point);
}

points = points.sort(function(a,b){return a[0] == b[0] ? b[1] - a[1] : a[0] - b[0];});

var chull;

function ccw(a,b,c) {
  return (b[0] - a[0]) * (c[1] - a[1]) + (b[1] - a[1]) * (c[0] - a[0]) > 0;
}
if (points.length > 3) {
  var upper = []
  for (var i=0; i<n; i++) {
    while (upper.length > 2 && ccw(upper[upper.length-2], upper[upper.length-1], points[i]))
      upper.pop();
    upper.push(points[i]);
  }
  upper.pop();

  var lower = []
  for (var i=n-1; i>=0; i--) {
    while (lower.length > 2 && ccw(lower[lower.length-2], lower[lower.length-1], points[i]))
      lower.pop();
    lower.push(points[i]);
  }
  lower.pop()
  chull = upper.concat(lower);
} else {
  chull = points;
}

function length(a, b) {
  return Math.max(Math.abs(a[0] - b[0]), Math.abs(a[1] - b[1]));
}

var ret = 0;
for (var i=0;i<chull.length;i++) {
  ret += length(chull[i], chull[(i+1) % chull.length]);
}
print(ret + 4);


Given the string $$$s$$$ of decimal digits (0-9) of length $$$n$$$.A substring is a sequence of consecutive characters of a string. The substring of this string is defined by a pair of indexes — with its left and right ends. So, each pair of indexes ($$$l, r$$$), where $$$1 \le l \le r \le n$$$, corresponds to a substring of the string $$$s$$$. We will define as $$$v(l,r)$$$ the numeric value of the corresponding substring (leading zeros are allowed in it).For example, if $$$n=7$$$, $$$s=$$$"1003004", then $$$v(1,3)=100$$$, $$$v(2,3)=0$$$ and $$$v(2,7)=3004$$$.You are given $$$n$$$, $$$s$$$ and an integer $$$w$$$ ($$$1 \le w < n$$$).You need to process $$$m$$$ queries, each of which is characterized by $$$3$$$ numbers $$$l_i, r_i, k_i$$$ ($$$1 \le l_i \le r_i \le n; 0 \le k_i \le 8$$$).The answer to the $$$i$$$th query is such a pair of substrings of length $$$w$$$ that if we denote them as $$$(L_1, L_1+w-1)$$$ and $$$(L_2, L_2+w-1)$$$, then:  $$$L_1 \ne L_2$$$, that is, the substrings are different;  the remainder of dividing a number $$$v(L_1, L_1+w-1) \cdot v(l_i, r_i) + v(L_2, L_2 + w - 1)$$$ by $$$9$$$ is equal to $$$k_i$$$. If there are many matching substring pairs, then find a pair where $$$L_1$$$ is as small as possible. If there are many matching pairs in this case, then minimize $$$L_2$$$.Note that the answer may not exist.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — number of input test cases. The first line of each test case contains a string $$$s$$$, which contains only the characters 0-9 and has a length $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$). The second line contains two integers $$$w, m$$$ ($$$1 \le w < n, 1 \le m \le 2 \cdot 10^5$$$), where $$$n$$$ — is the length of the given string $$$s$$$. The number $$$w$$$ denotes the lengths of the substrings being searched for, and $$$m$$$ is the number of queries to be processed. The following $$$m$$$ lines contain integers $$$l_i, r_i, k_i$$$ ($$$1 \le l_i \le r_i \le n$$$, $$$0 \le k_i \le 8$$$) — $$$i$$$th query parameters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. It is also guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each request, print in a separate line:    left borders of the required substrings: $$$L_1$$$ and $$$L_2$$$; -1 -1 otherwise, if there is no solution.  If there are several solutions, minimize $$$L_1$$$ first, and minimize $$$L_2$$$ second.

NoteConsider the first test case of example inputs. In this test case $$$n=7$$$, $$$s=$$$"1003004", $$$w=4$$$ and one query $$$l_1=1$$$, $$$r_1=2$$$, $$$k_1=1$$$. Note that $$$v(1,2)=10$$$. We need to find a pair of substrings of length $$$4$$$ such that $$$v(L_1, L_1+3)\cdot10+v(L_2,L_2+3)$$$ has a remainder of $$$k_1=1$$$ when divided by $$$9$$$. The values $$$L_1=2, L_2=4$$$ actually satisfy all the requirements: $$$v(L_1, L_1+w-1)=v(2,5)=30$$$, $$$v(L_2, L_2+w-1)=v(4,7)=3004$$$. Indeed, $$$30\cdot10+3004=3304$$$, which has a remainder of $$$1$$$ when divided by $$$9$$$. It can be shown that $$$L_1=2$$$ is the minimum possible value, and $$$L_2=4$$$ is the minimum possible with $$$L_1=2$$$.

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const s = read();
  const [w, m] = rns();
  const pre = [];
  const mod = num => (num % 9 + 9) % 9;
  for (let i = 0; i < s.length; i++) {
    var _pre;
    pre[i] = mod(((_pre = pre[i - 1]) !== null && _pre !== void 0 ? _pre : 0) * 10 + Number(s[i]));
  }
  const query = (l, r) => {
    var _pre2;
    return mod(pre[r] - ((_pre2 = pre[l - 1]) !== null && _pre2 !== void 0 ? _pre2 : 0));
  };
  const v = [];
  for (let i = 0; i < s.length - w + 1; i++) {
    v[i] = query(i, i + w - 1);
  }
  const map = new Map();
  for (let i = 0; i < v.length; i++) {
    if (!map.has(v[i])) map.set(v[i], []);
    if (map.get(v[i]).length < 2) map.get(v[i]).push(i);
  }
  const res = [];
  for (let i = 0; i < m; i++) {
    const [l, r, k] = rns();
    const a = query(l - 1, r - 1);
    let ans = [-1, -1];
    const add = ([a, b]) => {
      if (ans[0] === -1 || ans[0] > a || ans[0] === a && ans[1] > b) {
        ans = [a, b];
      }
    };
    for (let j = 0; j < 9; j++) {
      if (!map.has(j)) continue;
      const t = mod(k - a * j);
      if (!map.has(t)) continue;
      if (j === t) {
        if (map.get(j).length < 2) continue;
        add(map.get(j));
      } else {
        add([map.get(j)[0], map.get(t)[0]]);
      }
    }
    res.push(ans.map(num => num !== -1 ? num + 1 : num).join(' '));
  }
  return res.join('\n');
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

const readline = require('readline')

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

function solve(str, w, qs) {
    const n = str.length
    const rs = Array(n)
    // const trs = [] // 10^i % 9
    let temp = 0
    let ten = 1
    for (let i = str.length - 1; i >= 0; i--) {
        const x = +str[i]
        // temp += x * ten
        // ten *= 10
        temp = add(temp, mul(x, ten))
        rs[i] = temp
        // trs.push(ten)
        ten = mul(ten, 10)
    }
// console.log(rs)
    //
    const first = Array(9).fill(0)
        .map(() => [])
    for (let i = n - 1; i - w + 1 >= 0; i--) {
        const x = range(i - w + 1, i)
        // console.log(str.slice(i - w + 1, i + 1), x)
        // first[x] = i - w + 1
        first[x].unshift(i - w + 1)
    }
    // console.log(first)
    return qs.map(([l, r, k]) => {
        // v1 * vlr + v2 = k
        const vlr = range(l - 1, r - 1)
        let l1 = Infinity, l2 = Infinity
        for (let v1 = 0; v1 < 9; v1++) {
            if (first[v1].length) {
                const v2 = minus(k, mul(v1, vlr))
            // console.log(v1, v2)
                if (first[v2].length) {
                    let a = first[v1][0]
                    let b = first[v2][0]
                    if (v1 === v2) {
                        if (first[v1].length < 2) continue
                        b = first[v1][1]
                    }
                    if (a < l1) {
                        l1 = a
                        l2 = b
                    } else if (a === l1) {
                        if (b < l2) {
                            l2 = b
                        }
                    }
                }
            }
        }
        const ans = (l1 === Infinity || l2 === Infinity) ? [-1, -1] : [l1 + 1, l2 + 1]
        return ans.join(' ')
    }).join('\n')

    function range(l, r) {
        return minus(rs[l], r + 1 < n ? rs[r + 1] : 0)
    }
}
const MOD = 9
function minus(a, b) {
    return add(add(a, -b), MOD)
}
function add(a, b) {
    return (a + b) % 9
}
function mul(a, b) {
    return (a * b) % 9
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const s = read();
  const [w, m] = rns();
  const pre = [];
  const mod = num => (num % 9 + 9) % 9;
  for (let i = 0; i < s.length; i++) {
    var _pre;
    pre[i] = mod(((_pre = pre[i - 1]) !== null && _pre !== void 0 ? _pre : 0) * 10 + Number(s[i]));
  }
  const query = (l, r) => {
    var _pre2;
    return mod(pre[r] - ((_pre2 = pre[l - 1]) !== null && _pre2 !== void 0 ? _pre2 : 0));
  };
  const v = [];
  for (let i = 0; i < s.length - w + 1; i++) {
    v[i] = query(i, i + w - 1);
  }
  const map = new Map();
  for (let i = 0; i < v.length; i++) {
    if (!map.has(v[i])) map.set(v[i], []);
    if (map.get(v[i]).length < 2) map.get(v[i]).push(i);
  }
  const res = [];
  for (let i = 0; i < m; i++) {
    const [l, r, k] = rns();
    const a = query(l - 1, r - 1);
    let ans = [-1, -1];
    const add = ([a, b]) => {
      if (a > b) [a, b] = [b, a];
      if (ans[0] === -1 || ans[0] > a || ans[0] === a && ans[1] > b) {
        ans = [a, b];
      }
    };
    for (let j = 0; j < 9; j++) {
      if (!map.has(j)) continue;
      const t = mod(k - a * j);
      if (!map.has(t)) continue;
      if (j === t) {
        if (map.get(j).length < 2) continue;
        add(map.get(j));
      } else {
        add([map.get(j)[0], map.get(t)[0]]);
      }
    }
    res.push(ans.map(num => num !== -1 ? num + 1 : num).join(' '));
  }
  return res.join('\n');
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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


A MIPT student named Misha has a birthday today, and he decided to celebrate it in his country house in suburban Moscow. n friends came by, and after a typical party they decided to play blind man's buff.The birthday boy gets blindfolded and the other players scatter around the house. The game is played in several rounds. In each round, Misha catches exactly one of his friends and has to guess who it is. The probability of catching the i-th friend does not change between rounds and is equal to pi percent (as we know, it is directly proportional to the amount of alcohol consumed by the i-th friend) and p1 + p2 + ... + pn = 100 holds. Misha has no information about who he caught. After Misha makes an attempt to guess the caught person, the round ends. Even then, Misha isn't told whether he guessed correctly, and a new round begins.The game ends when Misha guesses every friend at least once, that is, there exists such set of rounds k1, k2, ..., kn, that during round number ki Misha caught the i-th friend and guessed him. Misha wants to minimize the expectation of the number of rounds of the game. Despite the fact that at any point in the game Misha has no information about who he has already guessed, his friends are honest, and if they see that the condition for the end of the game is fulfilled, the game ends immediately. Find the expectation of the number of rounds in the game if Misha plays optimally.

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of Misha's friends. The second line contains n integers pi (), giving the probability to catch the i-th friend in one particular round in percent.

Print a single real value — the expectation of the number of rounds provided that Misha plays optimally. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteThe optimal strategy in the first sample is to guess friends alternately.

/* TEST CASE
input
2
50 50
output
5.0000000000
input
4
50 20 20 10
output
39.2846263444
 */
function main() {
	var n = parseInt(readline());
	var p = new Array(n);
	var f = new Array(n);
	var splitted = readline().split(' ');
	var i, g = 1.0;

	for (i = 0; i < n; i++) {
		var Pi = parseFloat(splitted[i]) / 100.0;
		p[i] = Pi;
		f[i] = Pi
		g *= Pi;
	}

	var answer = g * n;
	var x = n;

	while (x++ < 300001) {
        var maxProb = 0;
        var id;
        for (i = 0; i < n; i++) {
            if (p[i] * (1-f[i])/f[i] > maxProb) {
            	maxProb = p[i] * (1-f[i])/f[i];
                id = i;
            }
        }
        f[id] += p[id] * (1 - f[id]);
        answer += x * g * maxProb;
        g *= (1.0 + maxProb);
	}
	print(answer.toFixed(10));
}

main();

/* TEST CASE
input
2
50 50
output
5.0000000000
input
4
50 20 20 10
output
39.2846263444
 */
function main() {
	var n = parseInt(readline());
	var p = new Array(n);
	var f = new Array(n);
	var splitted = readline().split(' ');
	var i, g = 1.0;

	for (i = 0; i < n; i++) {
		var Pi = parseFloat(splitted[i]) / 100.0;
		p[i] = Pi;
		f[i] = Pi
		g *= Pi;
	}

	var answer = g * n;
	var x = n;

	while (x++ < 300001) {
        var tmp = 0;
        var id;
        for (i = 0; i < n; i++) {
            if (p[i] * (1-f[i])/f[i] + 1 > tmp) {
                tmp = p[i] * (1-f[i])/f[i] + 1;
                id = i;
            }
        }
        f[id] += p[id] * (1 - f[id]);
        answer += x * g * (tmp - 1);
        g *= tmp;
	}
	print(answer.toFixed(10));
}

main();

/* TEST CASE
input
2
50 50
output
5.0000000000
input
4
50 20 20 10
output
39.2846263444
 */
function main() {
	var n = parseInt(readline());
	var p = new Array(n);
	var f = new Array(n);
	var splitted = readline().split(' ');
	var i, g = 1.0;

	for (i = 0; i < n; i++) {
		var Pi = parseFloat(splitted[i]) / 100.0;
		p[i] = Pi;
		f[i] = Pi
		g *= Pi;
	}

	var answer = g * n;
	var x = n;

	while (x++ < 300001) {
        var maxProb = 0;
        var id;
        for (i = 0; i < n; i++) {
        	var prob = p[i] * (1-f[i])/f[i];
            if (prob > maxProb) {
            	maxProb = prob;
                id = i;
            }
        }
        f[id] += p[id] * (1 - f[id]);
        answer += x * g * maxProb;
        g *= (1 + maxProb);
	}
	print(answer.toFixed(10));
}

main();


You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them.You know that you have $$$n$$$ bacteria in the Petri dish and size of the $$$i$$$-th bacteria is $$$a_i$$$. Also you know intergalactic positive integer constant $$$K$$$.The $$$i$$$-th bacteria can swallow the $$$j$$$-th bacteria if and only if $$$a_i > a_j$$$ and $$$a_i \le a_j + K$$$. The $$$j$$$-th bacteria disappear, but the $$$i$$$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $$$i$$$ can swallow any bacteria $$$j$$$ if $$$a_i > a_j$$$ and $$$a_i \le a_j + K$$$. The swallow operations go one after another.For example, the sequence of bacteria sizes $$$a=[101, 53, 42, 102, 101, 55, 54]$$$ and $$$K=1$$$. The one of possible sequences of swallows is: $$$[101, 53, 42, 102, \underline{101}, 55, 54]$$$ $$$\to$$$ $$$[101, \underline{53}, 42, 102, 55, 54]$$$ $$$\to$$$ $$$[\underline{101}, 42, 102, 55, 54]$$$ $$$\to$$$ $$$[42, 102, 55, \underline{54}]$$$ $$$\to$$$ $$$[42, 102, 55]$$$. In total there are $$$3$$$ bacteria remained in the Petri dish.Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope.

The first line contains two space separated positive integers $$$n$$$ and $$$K$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le K \le 10^6$$$) — number of bacteria and intergalactic constant $$$K$$$. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — sizes of bacteria you have.

Print the only integer — minimal possible number of bacteria can remain.

NoteThe first example is clarified in the problem statement.In the second example an optimal possible sequence of swallows is: $$$[20, 15, 10, 15, \underline{20}, 25]$$$ $$$\to$$$ $$$[20, 15, 10, \underline{15}, 25]$$$ $$$\to$$$ $$$[20, 15, \underline{10}, 25]$$$ $$$\to$$$ $$$[20, \underline{15}, 25]$$$ $$$\to$$$ $$$[\underline{20}, 25]$$$ $$$\to$$$ $$$[25]$$$.In the third example no bacteria can swallow any other bacteria.

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
var n = numbers[0], k = numbers[1];
var cells = readline().split(" ").map(function(x) { return parseInt(x); });

cells.sort((a,b) => a-b);

var eat = 0;

var i = 0;
var j = 0;

while (i < cells.length && j < cells.length) {
    if (cells[i]<cells[j] && cells[j]<=cells[i]+k) {
        eat++;
        i++;
    } else {
        if(cells[j]>cells[i]+k) {
            i++
        } else {
            j++
        }
    }
}

print(cells.length - eat);