You are given $$$n - 1$$$ integers $$$a_2, \dots, a_n$$$ and a tree with $$$n$$$ vertices rooted at vertex $$$1$$$. The leaves are all at the same distance $$$d$$$ from the root. Recall that a tree is a connected undirected graph without cycles. The distance between two vertices is the number of edges on the simple path between them. All non-root vertices with degree $$$1$$$ are leaves. If vertices $$$s$$$ and $$$f$$$ are connected by an edge and the distance of $$$f$$$ from the root is greater than the distance of $$$s$$$ from the root, then $$$f$$$ is called a child of $$$s$$$.Initially, there are a red coin and a blue coin on the vertex $$$1$$$. Let $$$r$$$ be the vertex where the red coin is and let $$$b$$$ be the vertex where the blue coin is. You should make $$$d$$$ moves. A move consists of three steps:   Move the red coin to any child of $$$r$$$.  Move the blue coin to any vertex $$$b'$$$ such that $$$dist(1, b') = dist(1, b) + 1$$$. Here $$$dist(x, y)$$$ indicates the length of the simple path between $$$x$$$ and $$$y$$$. Note that $$$b$$$ and $$$b'$$$ are not necessarily connected by an edge.  You can optionally swap the two coins (or skip this step). Note that $$$r$$$ and $$$b$$$ can be equal at any time, and there is no number written on the root.After each move, you gain $$$|a_r - a_b|$$$ points. What's the maximum number of points you can gain after $$$d$$$ moves?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of each test case contains $$$n-1$$$ integers $$$v_2, v_3, \dots, v_n$$$ ($$$1 \leq v_i \leq n$$$, $$$v_i \neq i$$$)  — the $$$i$$$-th of them indicates that there is an edge between vertices $$$i$$$ and $$$v_i$$$. It is guaranteed, that these edges form a tree. The third line of each test case contains $$$n-1$$$ integers $$$a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the numbers written on the vertices. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single integer: the maximum number of points you can gain after $$$d$$$ moves.

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type node struct {
	index  int
	parent int
	edges  []int
	data   int64
	// min, max int64
	f   int64
	vis bool
}

type bv struct {
	b, v int64
}

func calcParent(p *node, data, min, max int64) int64 {
	v1, v2 := data-min, max-data
	if v1 < v2 {
		return v2 + p.f
	}
	return v1 + p.f
}

func calc(nodes []*node, lt, gt []bv, index int, min, max int64) int64 {
	now := nodes[index]
	if now.parent == index {
		if index != 0 {
			panic("corrupted")
		}
		return 0
	}

	res := calcParent(nodes[now.parent], now.data, min, max)
	//fmt.Println(index, "parent", res)

	// Search returns the smallest i that func(i) is true
	// which means the tightest range that contains now.data
	pl := sort.Search(len(lt), func(i int) bool {
		return now.data <= lt[i].b
	})
	// actually given that we have <= in the test, it is impossible for
	// it to be out of range
	if pl < len(lt) {
		if v := lt[pl].v - now.data; v > res {
			res = v
		}
		//fmt.Println(index, "lt", lt[pl], lt[pl].v-now.data)
	}
	pg := sort.Search(len(gt), func(i int) bool {
		return now.data >= gt[i].b
	})
	if pg < len(gt) {
		if v := gt[pg].v + now.data; v > res {
			res = v
		}
		//fmt.Println(index, "gt", gt[pg], gt[pg].v+now.data)
	}
	return res
}

// warning: squash is destructive
// although this looks like o(n*n), it is actually o(n), as every elem is only
// pushed into the stack once and popped at most once.
func squash(x []bv) []bv {
	//fmt.Println("squash")
	//fmt.Println(x)
	var top int = 0
	for i := 1; i < len(x); i++ {
		if x[i].b == x[top].b {
			continue
			// save us some trouble as we already sort v in decreasing order
		}
		for top >= 0 && x[top].v <= x[i].v {
			top--
		}
		top++
		x[top] = x[i]
	}
	//fmt.Println(top, x[:top+1])
	return x[:top+1]
}

func solve(nodes []*node) {
	var (
		queue, next      []int
		lt, gt           []bv //less than, greater than
		nextLt, nextGt   []bv
		res              int64 = -1
		min, max         int64
		nextMin, nextMax int64
		count            int
	)

	queue = []int{0}
	nodes[0].vis = true

	for len(queue) != 0 {
		/*fmt.Println("=====================")
		fmt.Println(lt)
		fmt.Println(gt)*/
		nextMin, nextMax = 1e9+1, 0
		for _, nowIndex := range queue {
			var nowMin, nowMax int64 = 1e9 + 1, 0
			now := nodes[nowIndex]
			now.vis = true
			for _, index := range now.edges {
				n := nodes[index]
				if n.vis {
					continue
				}
				if n.data < nowMin {
					nowMin = n.data
				}
				if n.data > nowMax {
					nowMax = n.data
				}
				n.parent = nowIndex
				next = append(next, index)
			}
			now.f = calc(nodes, lt, gt, nowIndex, min, max)
			//fmt.Println(nowIndex, "f:", now.f)
			if res < now.f {
				res = now.f
			}
			//fmt.Println("lt", bv{b: nowMax, v: nowMax + now.f})
			//fmt.Println("gt", bv{b: nowMin, v: now.f - nowMin})
			nextLt = append(nextLt, bv{b: nowMax, v: nowMax + now.f})
			nextGt = append(nextGt, bv{b: nowMin, v: now.f - nowMin})

			if nowMin < nextMin {
				nextMin = nowMin
			}
			if nowMax > nextMax {
				nextMax = nowMax
			}
			count++
		}
		// sort the nextLt/nextGt into an order that the smallest range is at the first,
		// and v in dereasing order
		sort.Slice(nextLt, func(i, j int) bool {
			if nextLt[i].b == nextLt[j].b {
				return nextLt[i].v > nextLt[j].v
			}
			return nextLt[i].b < nextLt[j].b
		})
		sort.Slice(nextGt, func(i, j int) bool {
			if nextGt[i].b == nextGt[j].b {
				return nextGt[i].v > nextGt[j].v
			}
			return nextGt[i].b > nextGt[j].b
		})
		lt, gt = squash(nextLt), squash(nextGt)
		nextLt, nextGt = []bv{}, []bv{}
		//fmt.Println(queue, next)
		//fmt.Scanf("\n")
		queue, next = next, queue[:0]
		min, max = nextMin, nextMax
	}
	fmt.Println(res)
	if len(nodes) != count {
		fmt.Println(len(nodes), count)
		panic("not all visited")
	}
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanln(input, &t)
	for ; t > 0; t-- {
		var n int
		_, err := fmt.Fscanln(input, &n)
		if err != nil {
			panic(err)
		}
		nodes := make([]*node, n)
		for i := range nodes {
			nodes[i] = new(node)
			nodes[i].parent = i // set parent = self, means uninitialized
		}
		for i := 1; i < n; i++ {
			var x int
			fmt.Fscan(input, &x)
			x--
			nodes[i].edges = append(nodes[i].edges, x)
			nodes[x].edges = append(nodes[x].edges, i)
		}
		/*for i := 0; i < n; i++ {
			fmt.Printf("%d: %v\n", i, nodes[i].edges)
		}*/
		fmt.Fscanf(input, "\n")
		for i := 1; i < n; i++ {
			fmt.Fscan(input, &nodes[i].data)
			if nodes[i].data > 1e9 {
				panic("invalid input")
			}
		}
		fmt.Fscanf(input, "\n")
		solve(nodes)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type node struct {
	index  int
	parent int
	edges  []int
	data   int64
	// min, max int64
	f   int64
	vis bool
}

func calcParent(p *node, data, min, max int64) int64 {
	v1, v2 := data-min, max-data
	if v1 < v2 {
		return v2 + p.f
	}
	return v1 + p.f
}

func calc(nodes []*node, lt, gt int64, index int, min, max int64) int64 {
	now := nodes[index]
	if now.parent == index {
		if index != 0 {
			panic("corrupted")
		}
		return 0
	}

	res := calcParent(nodes[now.parent], now.data, min, max)
	// fmt.Printf("%d - parent value: %d\n", index, res)

	if v := lt - now.data; v > res {
		// fmt.Printf("%d - lt value: %d\n", index, v)
		res = v
	}
	if v := now.data + gt; v > res {
		// fmt.Printf("%d - gt value: %d\n", index, v)
		res = v
	}

	return res
}

func solve(nodes []*node) {
	var (
		queue, next      []int
		maxLt, maxGt     int64
		res              int64 = -1
		min, max         int64
		nextMin, nextMax int64
		count            int
	)

	queue = []int{0}
	nodes[0].vis = true

	for len(queue) != 0 {
		// fmt.Println("=====================")
		// fmt.Printf("maxLt&Gt: %d, %d\n", maxLt, maxGt)
		nextMin, nextMax = 1e9+1, 0
		var nextMaxGt, nextMaxLt int64 = -1e9 - 1, -1e9 - 1
		for _, nowIndex := range queue {
			var nowMin, nowMax int64 = 1e9 + 1, 0
			now := nodes[nowIndex]
			now.vis = true
			for _, index := range now.edges {
				n := nodes[index]
				if n.vis {
					continue
				}
				if n.data < nowMin {
					nowMin = n.data
				}
				if n.data > nowMax {
					nowMax = n.data
				}
				n.parent = nowIndex
				next = append(next, index)
			}
			now.f = calc(nodes, maxLt, maxGt, nowIndex, min, max)
			// fmt.Println(nowIndex, "f:", now.f)
			if res < now.f {
				res = now.f
			}

			if v := nowMax + now.f; v > nextMaxLt {
				nextMaxLt = v
			}

			if v := now.f - nowMin; v > nextMaxGt {
				nextMaxGt = v
			}

			if nowMin < nextMin {
				nextMin = nowMin
			}
			if nowMax > nextMax {
				nextMax = nowMax
			}
			count++
		}
		maxLt, maxGt = nextMaxLt, nextMaxGt

		queue, next = next, queue[:0]
		min, max = nextMin, nextMax
	}
	fmt.Println(res)
	if len(nodes) != count {
		fmt.Println(len(nodes), count)
		panic("not all visited")
	}
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanln(input, &t)
	for ; t > 0; t-- {
		var n int
		_, err := fmt.Fscanln(input, &n)
		if err != nil {
			panic(err)
		}
		nodes := make([]*node, n)
		for i := range nodes {
			nodes[i] = new(node)
			nodes[i].parent = i // set parent = self, means uninitialized
		}
		for i := 1; i < n; i++ {
			var x int
			fmt.Fscan(input, &x)
			x--
			nodes[i].edges = append(nodes[i].edges, x)
			nodes[x].edges = append(nodes[x].edges, i)
		}
		/*for i := 0; i < n; i++ {
			fmt.Printf("%d: %v\n", i, nodes[i].edges)
		}*/
		fmt.Fscanf(input, "\n")
		for i := 1; i < n; i++ {
			fmt.Fscan(input, &nodes[i].data)
			if nodes[i].data > 1e9 {
				panic("invalid input")
			}
		}
		fmt.Fscanf(input, "\n")
		solve(nodes)
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		P := readNNums(reader, n-1)
		A := readNNums(reader, n-1)
		res := solve(n, P, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const N_INF = -(1 << 59)

func solve(n int, P []int, A []int) int64 {

	pp := make([]int, n)
	copy(pp[1:], P)

	g := NewGraph(n, n+10)

	for i := 1; i < n; i++ {
		pp[i]--
		g.AddEdge(pp[i], i)
	}

	D := make([]int, n)
	var mx int
	var dfs func(u int)
	dfs = func(u int) {
		mx = max(mx, D[u])
		for i := g.nodes[u]; i > 0; i = g.next[i] {
			v := g.to[i]
			D[v] = D[u] + 1
			dfs(v)
		}
	}
	dfs(0)
	mx++
	C := make([]int, mx)
	for i := 0; i < n; i++ {
		C[D[i]]++
	}
	L := make([][]Pair, mx)
	for i := 0; i < mx; i++ {
		L[i] = make([]Pair, 0, C[i])
	}
	for i := 1; i < n; i++ {
		L[D[i]] = append(L[D[i]], Pair{A[i-1], i})
	}

	for i := 0; i < mx; i++ {
		sort.Sort(Pairs(L[i]))
	}
	dp := make([]int64, n)

	for i := 1; i < mx; i++ {
		cur := L[i]
		// if place blue at j'th node in this level, find another best red
		// because all nodes before j < A[j], so the best is A[j] - A[k] + dp[P[k]]
		// let best is dp[P[k]] - A[k]
		var best int64 = N_INF
		for _, p := range cur {
			j := p.second
			dp[j] = max2(dp[j], best+int64(A[j-1]))
			best = max2(best, dp[pp[j]]-int64(A[j-1]))
		}
		// A[k] - A[j] + dp[pp[k]]
		best = N_INF
		for k := len(cur) - 1; k >= 0; k-- {
			p := cur[k]
			j := p.second
			dp[j] = max2(dp[j], best-int64(A[j-1]))
			best = max2(best, int64(A[j-1])+dp[pp[j]])
		}
		// a0 or an is blue
		a0 := cur[0].first
		an := cur[len(cur)-1].first
		for _, p := range cur {
			j := p.second
			//if make j as red, then it's parent has to be red
			dp[j] = max2(dp[j], int64(p.first-a0)+dp[pp[j]])
			dp[j] = max2(dp[j], int64(an-p.first)+dp[pp[j]])
		}
	}

	var res int64

	for _, p := range L[mx-1] {
		res = max2(res, dp[p.second])
	}

	return res
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (this Pairs) Len() int {
	return len(this)
}

func (this Pairs) Less(i, j int) bool {
	return this[i].first < this[j].first
}

func (this Pairs) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func max2(a, b int64) int64 {
	if a >= b {
		return a
	}
	return b
}

type Graph struct {
	nodes []int
	next  []int
	to    []int
	cur   int
}

func NewGraph(n int, e int) *Graph {
	nodes := make([]int, n)
	next := make([]int, e)
	to := make([]int, e)
	return &Graph{nodes, next, to, 0}
}

func (g *Graph) AddEdge(u, v int) {
	g.cur++
	g.next[g.cur] = g.nodes[u]
	g.nodes[u] = g.cur
	g.to[g.cur] = v
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type node struct {
	index  int
	parent int
	edges  []int
	data   int64
	// min, max int64
	f   int64
	vis bool
}

type bv struct {
	b, v int64
}

func calcParent(p *node, data, min, max int64) int64 {
	v1, v2 := data-min, max-data
	if v1 < v2 {
		return v2 + p.f
	}
	return v1 + p.f
}

func calc(nodes []*node, lt, gt []bv, index int, min, max int64) int64 {
	now := nodes[index]
	if now.parent == index {
		return 0
	}

	res := calcParent(nodes[now.parent], now.data, min, max)
	//fmt.Println(index, "parent", res)

	// Search returns the smallest i that f(i) is true
	// which means the tightest range that contains now.data
	pl := sort.Search(len(lt), func(i int) bool {
		return now.data <= lt[i].b
	})
	// actually given that we have <= in the test, it is impossible for
	// it to be out of range
	if pl < len(lt) {
		if v := lt[pl].v - now.data; v > res {
			res = v
		}
		//fmt.Println(index, "lt", lt[pl], lt[pl].v-now.data)
	}
	pg := sort.Search(len(gt), func(i int) bool {
		return now.data >= gt[i].b
	})
	if pg < len(gt) {
		if v := gt[pg].v + now.data; v > res {
			res = v
		}
		//fmt.Println(index, "gt", lt[pg], gt[pg].v+now.data)
	}
	return res
}

// warning: squash is destructive
// although this looks like o(n*n), it is actually o(n), as every elem is only
// pushed into the stack once and popped at most once.
func squash(x []bv) []bv {
	//fmt.Println("squash")
	//fmt.Println(x)
	var top int = 0
	for i := 1; i < len(x); i++ {
		if x[i].b == x[top].b {
			continue
			// save us some trouble as we already sort v in decreasing order
		}
		for top >= 0 && x[top].v < x[i].v {
			top--
		}
		top++
		x[top] = x[i]
	}
	//fmt.Println(top, x[:top+1])
	return x[:top+1]
}

func solve(nodes []*node) {
	var (
		queue, next      []int
		lt, gt           []bv //less than, greater than
		nextLt, nextGt   []bv
		res              int64 = -1
		min, max         int64
		nextMin, nextMax int64
		count            int
	)

	queue = []int{0}
	nodes[0].vis = true

	for len(queue) != 0 {
		/*fmt.Println("=====================")
		fmt.Println(lt)
		fmt.Println(gt)*/
		nextMin, nextMax = 1e9+1, 0
		for _, nowIndex := range queue {
			var nowMin, nowMax int64 = 1e9 + 1, 0
			now := nodes[nowIndex]
			now.vis = true
			for _, index := range now.edges {
				n := nodes[index]
				if n.vis {
					continue
				}
				if n.data < nowMin {
					nowMin = n.data
				}
				if n.data > nowMax {
					nowMax = n.data
				}
				n.parent = nowIndex
				next = append(next, index)
			}
			now.f = calc(nodes, lt, gt, nowIndex, min, max)
			//fmt.Println(nowIndex, "f:", now.f)
			if res < now.f {
				res = now.f
			}
			//fmt.Println(bv{b: nowMax, v: nowMax + now.f})
			//fmt.Println(bv{b: nowMin, v: now.f - nowMin})
			nextLt = append(nextLt, bv{b: nowMax, v: nowMax + now.f})
			nextGt = append(nextGt, bv{b: nowMin, v: now.f - nowMin})

			if nowMin < nextMin {
				nextMin = nowMin
			}
			if nowMax > nextMax {
				nextMax = nowMax
			}
			count++
		}
		// sort the nextLt/nextGt into an order that the smallest range is at the first,
		// and v in dereasing order
		sort.Slice(nextLt, func(i, j int) bool {
			if nextLt[i].b == nextLt[j].b {
				return nextLt[i].v > nextLt[i].v
			}
			return nextLt[i].b < nextLt[j].b
		})
		sort.Slice(nextGt, func(i, j int) bool {
			if nextGt[i].b == nextGt[j].b {
				return nextGt[i].v > nextGt[j].v
			}
			return nextGt[i].b > nextGt[j].b
		})
		lt, gt = squash(nextLt), squash(nextGt)
		nextLt, nextGt = []bv{}, []bv{}
		//fmt.Println(queue, next)
		//fmt.Scanf("\n")
		queue, next = next, queue[:0]
		min, max = nextMin, nextMax
	}
	fmt.Println(res)
	if len(nodes) != count {
		fmt.Println(len(nodes), count)
		panic("not all visited")
	}
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanln(input, &t)
	for ; t > 0; t-- {
		var n int
		_, err := fmt.Fscanln(input, &n)
		if err != nil {
			panic(err)
		}
		nodes := make([]*node, n)
		for i := range nodes {
			nodes[i] = new(node)
		}
		for i := 1; i < n; i++ {
			var x int
			fmt.Fscan(input, &x)
			x--
			nodes[i].edges = append(nodes[i].edges, x)
			nodes[x].edges = append(nodes[x].edges, i)
			nodes[i].parent = i // set parent = self, means uninitialized
		}
		/*for i := 0; i < n; i++ {
			fmt.Printf("%d: %v\n", i, nodes[i].edges)
		}*/
		fmt.Fscanf(input, "\n")
		for i := 1; i < n; i++ {
			fmt.Fscan(input, &nodes[i].data)
			if nodes[i].data > 1e9 {
				panic("invalid input")
			}
		}
		fmt.Fscanf(input, "\n")
		solve(nodes)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type node struct {
	index  int
	parent int
	edges  []int
	data   int64
	// min, max int64
	f   int64
	vis bool
}

type bv struct {
	b, v int64
}

func calcParent(p *node, data, min, max int64) int64 {
	v1, v2 := data-min, max-data
	if v1 < v2 {
		return v2 + p.f
	}
	return v1 + p.f
}

func calc(nodes []*node, lt, gt []bv, index int, min, max int64) int64 {
	now := nodes[index]
	if now.parent == index {
		return 0
	}

	res := calcParent(nodes[now.parent], now.data, min, max)
	//fmt.Println(index, "parent", res)

	pl := sort.Search(len(lt), func(i int) bool {
		return now.data <= lt[i].b
	})
	if pl < len(lt) {
		if v := lt[pl].v - now.data; v > res {
			res = v
		}
		//fmt.Println(index, "lt", lt[pl], lt[pl].v-now.data)
	}
	pg := sort.Search(len(gt), func(i int) bool {
		return now.data >= gt[i].b
	})
	if pg < len(gt) {
		if v := gt[pg].v + now.data; v > res {
			res = v
		}
		//fmt.Println(index, "gt", lt[pg], gt[pg].v+now.data)
	}
	return res
}

// warning: squash is destructive
// although this looks like o(n*n), it is actually o(n), as every elem is only
// pushed into the stack once and popped at most once.
func squash(x []bv) []bv {
	//fmt.Println("squash")
	//fmt.Println(x)
	var top int = 0
	for i := 1; i < len(x); i++ {
		if x[i].b == x[top].b {
			continue
			// save us some trouble as we already sort v in decreasing order
		}
		for top >= 0 && x[top].v < x[i].v {
			top--
		}
		top++
		x[top] = x[i]
	}
	//fmt.Println(top, x[:top+1])
	return x[:top+1]
}

func solve(nodes []*node) {
	var (
		queue, next      []int
		lt, gt           []bv //less than, greater than
		nextLt, nextGt   []bv
		res              int64 = -1
		min, max         int64
		nextMin, nextMax int64
	)

	queue = []int{0}
	nodes[0].vis = true

	for len(queue) != 0 {
		/*fmt.Println("=====================")
		fmt.Println(lt)
		fmt.Println(gt)*/
		nextMin, nextMax = 1e9+1, 0
		for _, nowIndex := range queue {
			var nowMin, nowMax int64 = 1e9 + 1, 0
			now := nodes[nowIndex]
			now.vis = true
			for _, index := range now.edges {
				n := nodes[index]
				if n.vis {
					continue
				}
				if n.data < nowMin {
					nowMin = n.data
				}
				if n.data > nowMax {
					nowMax = n.data
				}
				n.parent = nowIndex
				next = append(next, index)
			}
			now.f = calc(nodes, lt, gt, nowIndex, min, max)
			//fmt.Println(nowIndex, "f:", now.f)
			if res < now.f {
				res = now.f
			}
			//fmt.Println(bv{b: nowMax, v: nowMax + now.f})
			//fmt.Println(bv{b: nowMin, v: now.f - nowMin})
			nextLt = append(nextLt, bv{b: nowMax, v: nowMax + now.f})
			nextGt = append(nextGt, bv{b: nowMin, v: now.f - nowMin})

			if nowMin < nextMin {
				nextMin = nowMin
			}
			if nowMax > nextMax {
				nextMax = nowMax
			}
		}
		// sort the nextLt/nextGt into an order that the smallest range is at the first,
		// and v in dereasing order
		sort.Slice(nextLt, func(i, j int) bool {
			if nextLt[i].b == nextLt[j].b {
				return nextLt[i].v > nextLt[i].v
			}
			return nextLt[i].b < nextLt[j].b
		})
		sort.Slice(nextGt, func(i, j int) bool {
			if nextGt[i].b == nextGt[j].b {
				return nextGt[i].v > nextGt[j].v
			}
			return nextGt[i].b > nextGt[j].b
		})
		lt, gt = squash(nextLt), squash(nextGt)
		nextLt, nextGt = []bv{}, []bv{}
		//fmt.Println(queue, next)
		//fmt.Scanf("\n")
		queue, next = next, queue[:0]
		min, max = nextMin, nextMax
	}
	fmt.Println(res)
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanln(input, &t)
	for ; t > 0; t-- {
		var n int
		_, err := fmt.Fscanln(input, &n)
		if err != nil {
			panic(err)
		}
		nodes := make([]*node, n)
		for i := range nodes {
			nodes[i] = new(node)
		}
		for i := 1; i < n; i++ {
			var x int
			fmt.Fscan(input, &x)
			x--
			nodes[i].edges = append(nodes[i].edges, x)
			nodes[x].edges = append(nodes[x].edges, i)
			nodes[i].parent = i // set parent = self, means uninitialized
		}
		/*for i := 0; i < n; i++ {
			fmt.Printf("%d: %v\n", i, nodes[i].edges)
		}*/
		fmt.Fscanf(input, "\n")
		for i := 1; i < n; i++ {
			fmt.Fscan(input, &nodes[i].data)
			if nodes[i].data > 1e9 {
				panic("invalid input")
			}
		}
		fmt.Fscanf(input, "\n")
		solve(nodes)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type node struct {
	index  int
	parent int
	edges  []int
	data   int64
	// min, max int64
	f   int64
	vis bool
}

type bv struct {
	b, v int64
}

func calcParent(p *node, data, min, max int64) int64 {
	v1, v2 := data-min, max-data
	if v1 < v2 {
		return v2 + p.f
	}
	return v1 + p.f
}

func calc(nodes []*node, lt, gt []bv, index int, min, max int64) int64 {
	now := nodes[index]
	if now.parent == index {
		return 0
	}

	res := calcParent(nodes[now.parent], now.data, min, max)
	//fmt.Println(index, "parent", res)

	pl := sort.Search(len(lt), func(i int) bool {
		return now.data <= lt[i].b
	})
	if pl < len(lt) {
		if v := lt[pl].v - now.data; v > res {
			res = v
		}
		//fmt.Println(index, "lt", lt[pl], lt[pl].v-now.data)
	}
	pg := sort.Search(len(gt), func(i int) bool {
		return now.data >= gt[i].b
	})
	if pg < len(gt) {
		if v := gt[pg].v + now.data; v > res {
			res = v
		}
		//fmt.Println(index, "gt", lt[pg], gt[pg].v+now.data)
	}
	return res
}

// warning: squash is destructive
// although this looks like o(n*n), it is actually o(n), as every elem is only
// pushed into the stack once and popped at most once.
func squash(x []bv) []bv {
	//fmt.Println("squash")
	//fmt.Println(x)
	var top int = 0
	for i := 1; i < len(x); i++ {
		if x[i].b == x[top].b {
			continue
			// save us some trouble as we already sort v in decreasing order
		}
		for top >= 0 && x[top].v < x[i].v {
			top--
		}
		top++
		x[top] = x[i]
	}
	//fmt.Println(top, x[:top+1])
	return x[:top+1]
}

func solve(nodes []*node) {
	var (
		queue, next      []int
		lt, gt           []bv //less than, greater than
		nextLt, nextGt   []bv
		res              int64 = -1
		min, max         int64
		nextMin, nextMax int64
	)

	queue = []int{0}
	nodes[0].vis = true

	for len(queue) != 0 {
		/*fmt.Println("=====================")
		fmt.Println(lt)
		fmt.Println(gt)*/
		nextMin, nextMax = 1e9+1, 0
		for _, nowIndex := range queue {
			var nowMin, nowMax int64 = 1e9 + 1, 0
			now := nodes[nowIndex]
			now.vis = true
			for _, index := range now.edges {
				n := nodes[index]
				if n.vis {
					continue
				}
				if n.data < nowMin {
					nowMin = n.data
				}
				if n.data > nowMax {
					nowMax = n.data
				}
				n.parent = nowIndex
				next = append(next, index)
			}
			now.f = calc(nodes, lt, gt, nowIndex, min, max)
			//fmt.Println(nowIndex, "f:", now.f)
			if res < now.f {
				res = now.f
			}
			//fmt.Println(bv{b: nowMax, v: nowMax + now.f})
			//fmt.Println(bv{b: nowMin, v: now.f - nowMin})
			nextLt = append(nextLt, bv{b: nowMax, v: nowMax + now.f})
			nextGt = append(nextGt, bv{b: nowMin, v: now.f - nowMin})

			if nowMin < nextMin {
				nextMin = nowMin
			}
			if nowMax > nextMax {
				nextMax = nowMax
			}
		}
		// sort the nextLt/nextGt into an order that the smallest range is at the first,
		// and v in dereasing order
		sort.Slice(nextLt, func(i, j int) bool {
			if nextLt[i].b == nextLt[j].b {
				return nextLt[i].v > nextLt[i].v
			}
			return nextLt[i].b < nextLt[j].b
		})
		sort.Slice(nextGt, func(i, j int) bool {
			if nextGt[i].b == nextGt[j].b {
				return nextGt[i].v > nextGt[j].v
			}
			return nextGt[i].b > nextGt[j].b
		})
		lt, gt = squash(nextLt), squash(nextGt)
		nextLt, nextGt = []bv{}, []bv{}
		//fmt.Println(queue, next)
		//fmt.Scanf("\n")
		queue, next = next, queue[:0]
		min, max = nextMin, nextMax
	}
	fmt.Println(res)
}

func main() {
	input := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanln(input, &t)
	for ; t > 0; t-- {
		var n int
		_, err := fmt.Fscanln(input, &n)
		if err != nil {
			panic(err)
		}
		nodes := make([]*node, n)
		for i := range nodes {
			nodes[i] = new(node)
		}
		for i := 1; i < n; i++ {
			var x int
			fmt.Fscan(input, &x)
			x--
			nodes[i].edges = append(nodes[i].edges, x)
			nodes[x].edges = append(nodes[x].edges, i)
			nodes[i].parent = i // set parent = self, means uninitialized
		}
		/*for i := 0; i < n; i++ {
			fmt.Printf("%d: %v\n", i, nodes[i].edges)
		}*/
		fmt.Fscanf(input, "\n")
		for i := 1; i < n; i++ {
			fmt.Fscan(input, &nodes[i].data)
		}
		fmt.Fscanf(input, "\n")
		solve(nodes)
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		P := readNNums(reader, n-1)
		A := readNNums(reader, n-1)
		res := solve(n, P, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const N_INF = -(1 << 29)

func solve(n int, P []int, A []int) int64 {

	pp := make([]int, n)
	copy(pp[1:], P)

	g := NewGraph(n, n+10)

	for i := 1; i < n; i++ {
		pp[i]--
		g.AddEdge(pp[i], i)
	}

	D := make([]int, n)
	var mx int
	var dfs func(u int)
	dfs = func(u int) {
		mx = max(mx, D[u])
		for i := g.nodes[u]; i > 0; i = g.next[i] {
			v := g.to[i]
			D[v] = D[u] + 1
			dfs(v)
		}
	}
	dfs(0)
	mx++
	C := make([]int, mx)
	for i := 0; i < n; i++ {
		C[D[i]]++
	}
	L := make([][]Pair, mx)
	for i := 0; i < mx; i++ {
		L[i] = make([]Pair, 0, C[i])
	}
	for i := 1; i < n; i++ {
		L[D[i]] = append(L[D[i]], Pair{A[i-1], i})
	}

	for i := 0; i < mx; i++ {
		sort.Sort(Pairs(L[i]))
	}
	dp := make([]int64, n)

	for i := 1; i < mx; i++ {
		cur := L[i]
		// if place blue at j'th node in this level, find another best red
		// because all nodes before j < A[j], so the best is A[j] - A[k] + dp[P[k]]
		// let best is dp[P[k]] - A[k]
		var best int64 = N_INF
		for _, p := range cur {
			j := p.second
			dp[j] = max2(dp[j], best+int64(A[j-1]))
			best = max2(best, dp[pp[j]]-int64(A[j-1]))
		}
		// A[k] - A[j] + dp[pp[k]]
		best = N_INF
		for k := len(cur) - 1; k >= 0; k-- {
			p := cur[k]
			j := p.second
			dp[j] = max2(dp[j], best-int64(A[j-1]))
			best = max2(best, int64(A[j-1])+dp[pp[j]])
		}
		// a0 or an is blue
		a0 := cur[0].first
		an := cur[len(cur)-1].first
		for _, p := range cur {
			j := p.second
			//if make j as red, then it's parent has to be red
			dp[j] = max2(dp[j], int64(p.first-a0)+dp[pp[j]])
			dp[j] = max2(dp[j], int64(an-p.first)+dp[pp[j]])
		}
	}

	var res int64

	for _, p := range L[mx-1] {
		res = max2(res, dp[p.second])
	}

	return res
}

type Pair struct {
	first, second int
}

type Pairs []Pair

func (this Pairs) Len() int {
	return len(this)
}

func (this Pairs) Less(i, j int) bool {
	return this[i].first < this[j].first
}

func (this Pairs) Swap(i, j int) {
	this[i], this[j] = this[j], this[i]
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func max2(a, b int64) int64 {
	if a >= b {
		return a
	}
	return b
}

type Graph struct {
	nodes []int
	next  []int
	to    []int
	cur   int
}

func NewGraph(n int, e int) *Graph {
	nodes := make([]int, n)
	next := make([]int, e)
	to := make([]int, e)
	return &Graph{nodes, next, to, 0}
}

func (g *Graph) AddEdge(u, v int) {
	g.cur++
	g.next[g.cur] = g.nodes[u]
	g.nodes[u] = g.cur
	g.to[g.cur] = v
}


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.

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.ParseInt(s, 10, 32); return int(x) }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                              { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop

func main() {
	rw = newIop()
	defer func() {
		if isLocal() {
			rw.Println("Recovering ", recover())
		}
		rw.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		rw.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	test := rw.GetNextInt()
	for test > 0 {
		test--
		func() {
			a := rw.GetNextInt()
			b := rw.GetNextInt()
			c := rw.GetNextInt()

			if a > b {
				a, b = b, a
			}
			var maxNumber int
			maxNumber = b - a
			if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
				rw.Println(-1)
			} else {
				if c > maxNumber {
					c -= maxNumber
				} else {
					c += maxNumber
				}
				rw.Println(c)
			}
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.ParseInt(s, 10, 32); return int(x) }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                              { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop

func main() {
	rw=newIop()
	defer func() {
		if isLocal() {
			rw.Println("Recovering ", recover())
		}
		rw.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		rw.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	test := rw.GetNextInt()
	for test > 0 {
		test--
		func(){
				a := rw.GetNextInt()
				b := rw.GetNextInt()
				c := rw.GetNextInt()

			if a > b {
				a, b = b, a
			}
			//rw.Print(" test",test)
			if c > (b - a)*2 || a > (b - a)*2 || b > (b - a)*2 {
				rw.Println(-1)
			} else {
				if c > (b - a) {
					c -= (b - a)
				} else {
					c += (b - a)
				}
				rw.Println(c)
			}
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.ParseInt(s, 10, 32); return int(x) }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                              { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop

func main() {
	rw=newIop()
	defer func() {
		if isLocal() {
			rw.Println("Recovering ", recover())
		}
		rw.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		rw.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	test := rw.GetNextInt()
	for test > 0 {
		test--
		func(){
				a := rw.GetNextInt()
				b := rw.GetNextInt()
				c := rw.GetNextInt()

			if a > b {
				a, b = b, a
			}
			ret := -1
			if c <= (b-a)*2 && b <= (b-a)*2 {
				if c <= (b - a) {
					ret = c + (b - a)
				} else {
					ret = c - (b - a)
				}
			}
			rw.Println(ret)
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type IOP struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}
var iost *IOP

func NewIOP() *IOP {
	fp := os.Stdin
	wfp := os.Stdout
	//fmt.Println("adsfa",os.Getenv("inLocalEnv"))
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &IOP{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *IOP) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *IOP) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *IOP) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *IOP) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *IOP) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *IOP) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *IOP) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *IOP) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *IOP) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *IOP) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("inLocalEnv") == "indeed" }

func main() {

	iost = NewIOP()
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			a := iost.GetNextInt()
			b := iost.GetNextInt()
			c := iost.GetNextInt()
			if a > b {
				a, b = b, a
			}
			ret := -1
			if c <= (b-a)*2 && b <= (b-a)*2 {
				if c <= (b - a) {
					ret = c + (b - a)
				} else {
					ret = c - (b - a)
				}
			}
			iost.Println(ret)
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}
var iost *Iost

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("inLocalEnv") == "indeed" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	//fmt.Println("adsfa",os.Getenv("inLocalEnv"))
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			a := iost.GetNextInt()
			b := iost.GetNextInt()
			c := iost.GetNextInt()
			if a > b {
				a, b = b, a
			}
			ret := -1
			if c <= (b-a)*2 && b <= (b-a)*2 {
				if c <= (b - a) {
					ret = c + (b - a)
				} else {
					ret = c - (b - a)
				}
			}
			iost.Println(ret)
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.ParseInt(s, 10, 32); return int(x) }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                              { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop = newIop()

func main() {
	defer func() {
		if isLocal() {
			rw.Println("Recovering ", recover())
		}
		rw.Writer.Flush()
	}()
	solve()
}

func solve() {
	test := rw.GetNextInt()
	for test > 0 {
		test--
		func(){
			var (
				a = rw.GetNextInt()
				b = rw.GetNextInt()
				c = rw.GetNextInt()
			)
			if a > b {
				a, b = b, a
			}
			var maxNumber int
			maxNumber = b - a
			if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
				fmt.Println(-1)

			} else {
				if c > maxNumber {
					c -= maxNumber
				} else {
					c += maxNumber
				}
				fmt.Println(c)
			}
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop= newIop()
func main() {
	defer func() {
		if isLocal() {
			rw.Println("Recovering ",recover())
		}
		rw.Writer.Flush()
	}()
solve()
}

func solve()  {
	test:=rw.GetNextInt()
	for test>0{
		test--
		var (
			a=rw.GetNextInt()
			b=rw.GetNextInt()
			c=rw.GetNextInt()
		)
		if a > b {
			a, b = b, a
		}
		var maxNumber int
		maxNumber = b - a
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(wfp)
	return &iop{Scanner: scanner, Writer: writer}
}

var rw *iop= newIop()
func main() {
	defer func() {
		if isLocal() {
			rw.Println("Recovering ",recover())
		}
		rw.Writer.Flush()
	}()
solve()
}

func solve()  {
	test:=rw.GetNextInt()
	for test>0{
		test--
		var (
			a=rw.GetNextInt()
			b=rw.GetNextInt()
			c=rw.GetNextInt()
		)
		if a > b {
			a, b = b, a
		}
		var maxNumber int
		maxNumber = b - a
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

const BufSize = 1000000

//type iop struct {
//	scanner *bufio.Scanner
//	writer  *bufio.Writer
//}
//
//func newIop(fp *io.Reader,wfp *io.Writer) *iop   {
//	const BufSize = 1000000
//	scanner:=bufio.NewScanner(fp)
//	scanner.Buffer(make([]byte,BufSize),BufSize)
//}

//func (i iop) newIop()  {
//
//}
func main() {

	fp := os.Stdin
	scanner := bufio.NewScanner(fp)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	scanner.Split(bufio.ScanLines)
		if !scanner.Scan() {
			panic("NOOOOOO!")
			//fmt.Println(scanner.Text())
		}
	test ,_:= strconv.Atoi(scanner.Text())
	//fmt.Println(test)
	var (
		a, b, c, maxNumber int
	)
	for idx := 0; idx < test; idx++ {
		if !scanner.Scan() {
			fmt.Println(scanner.Text())
			break
		}
		x := scanner.Text()
		INTS := strings.Split(x, " ")
		a, _ = strconv.Atoi(INTS[0])
		b, _ = strconv.Atoi(INTS[1])
		c, _ = strconv.Atoi(INTS[2])
		if a > b {
			a, b = b, a
		}
		maxNumber = b - a
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}
}

package main

import (
	"fmt"
)

//// IntSlice Sorted
//type IntSlice []int
//func (x IntSlice) Sort() {
//	sort.Sort(x)
//}
//func (x IntSlice) Len() int           { return len(x) }
//func (x IntSlice) Less(i, j int) bool { return x[i] < x[j] }
//func (x IntSlice) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	var (
		a, b, c,maxNumber int
	)
	for idx := 0; idx < n; idx++ {
		fmt.Scan(&a, &b, &c)
		if a > b {
			a, b = b, a
		}
		maxNumber= b - a
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}

}

// Main Implementation
//
//func Cases() {
//}
//
//func TestCase() {
//
//}

package main

import (
	"fmt"
)

//// IntSlice Sorted
//type IntSlice []int
//func (x IntSlice) Sort() {
//	sort.Sort(x)
//}
//func (x IntSlice) Len() int           { return len(x) }
//func (x IntSlice) Less(i, j int) bool { return x[i] < x[j] }
//func (x IntSlice) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	var (
		a, b, c int
	)
	for idx := 0; idx < n; idx++ {
		fmt.Scan(&a, &b, &c)
		if a > b {
			a, b = b, a
		}
		maxNumber := b - a
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}

}

// Main Implementation
//
//func Cases() {
//}
//
//func TestCase() {
//
//}

package main

import (
	"fmt"
)

//// IntSlice Sorted
//type IntSlice []int
//func (x IntSlice) Sort() {
//	sort.Sort(x)
//}
//func (x IntSlice) Len() int           { return len(x) }
//func (x IntSlice) Less(i, j int) bool { return x[i] < x[j] }
//func (x IntSlice) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	for idx := 0; idx < n; idx++ {
		var (
			a, b, c int
		)
		fmt.Scan(&a, &b, &c)
		if a > b {
			a, b = b, a
		}
		maxNumber := (b - a)
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}

}

// Main Implementation
//
//func Cases() {
//}
//
//func TestCase() {
//
//}

package main

import "C"
import (
	"fmt"
)

//// IntSlice Sorted
//type IntSlice []int
//func (x IntSlice) Sort() {
//	sort.Sort(x)
//}
//func (x IntSlice) Len() int           { return len(x) }
//func (x IntSlice) Less(i, j int) bool { return x[i] < x[j] }
//func (x IntSlice) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func main() {
	Cases()
	//TestCase()
}

// Main Implementation

func Cases() {
	var n int
	_, _ = fmt.Scan(&n)
	for idx := 0; idx < n; idx++ {
		TestCase()
	}
}

func TestCase() {
	var (
		a, b, c int
	)
	fmt.Scan(&a, &b, &c)
	if a > b {
		a, b = b, a
	}
	maxNumber:=(b-a)
	//answer:=b+c-a
	if c>maxNumber*2||a>maxNumber*2||b>maxNumber*2{
		fmt.Println(-1)
		return
	}
	if c>maxNumber{
		c-=maxNumber
	}else{
		c+=maxNumber
	}
	fmt.Println(c)
}

package main

import "C"
import (
	"fmt"
)

//// IntSlice Sorted
//type IntSlice []int
//func (x IntSlice) Sort() {
//	sort.Sort(x)
//}
//func (x IntSlice) Len() int           { return len(x) }
//func (x IntSlice) Less(i, j int) bool { return x[i] < x[j] }
//func (x IntSlice) Swap(i, j int)      { x[i], x[j] = x[j], x[i] }

func main() {
	Cases()
	//TestCase()
}

// Main Implementation

func Cases() {
	var n int
	_, _ = fmt.Scan(&n)
	for idx := 0; idx < n; idx++ {
		TestCase()
	}
}

func TestCase() {
	var (
		a, b, c int
	)
	fmt.Scan(&a, &b, &c)
	if a > b {
		a, b = b, a
	}
	maxNumber:=2*(b-a)
	answer:=(b+(c-a)+maxNumber)%maxNumber
	//answer:=b+c-a
	if c>maxNumber||a>maxNumber||b>maxNumber{
		fmt.Println(-1)
		return
	}
	if answer==0{
		answer=maxNumber
	}
	fmt.Println(answer)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		dd := abs(a - b)
		if a > 2*dd || b > 2*dd || c > 2*dd {
			fmt.Println("-1")
		} else {
			if c <= dd {
				c += dd
			} else {
				c -= dd
			}
			fmt.Println(c)
		}

	}
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import (
	"fmt"
	"os"
	"bufio"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &c)
		a--; b--; c--
		if a > b {
		    a, b = b, a
		}
		tmp := 2 * (b - a)
		var ans int
		if b >= tmp || c >= tmp || a * 2 >= b {
		    ans = -1
		} else {
		    ans = (c + b - a) % tmp + 1
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var a, b, c int64
		fmt.Fscan(r, &a, &b, &c)
		maxNum,minNum := abs(a, b)
		abs:=maxNum-minNum
		if 2*abs<maxNum||2*abs<c{
			fmt.Println(-1)
		}else {
			if c>abs{
				fmt.Println(c-abs)
			}else {
				fmt.Println(c+abs)
			}
		}
	}
}

func abs(a int64, b int64) (int64, int64) {
	var max, min int64
	if a >= b {
		max = a
		min = b
	} else {
		max = b
		min = a

	}

	return max, min
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	ins  :=  bufio . NewReader ( os.Stdin )
	out  :=  bufio . NewWriter ( os.Stdout )
	defer  out . Flush ()

	scan := func(a ...interface{}) (int, error)             { return fmt.Fscan(ins, a...) }
	printf := func(s string, a ...interface{}) (int, error) { return fmt.Fprintf(out, s, a...) }
	var n int
	scan(&n)

	for i:=0; i<n;i++{
		var a,b,c int
		scan(&a, &b, &c)
		res := fn(a, b, c)

		printf("%d\n",res)
	}

}
func fn(a ,b, c int) int{
	ln := (b-a) *2

	if ln < 0{
		ln = (a-b)*2
	}
	max := a
	if b>max{
		max = b
	}
	if c>max{
		max = c
	}
	if ln < max{
		return -1
	}

	cgetted := getop(c, ln)
	if cgetted != a && cgetted != b{
		return cgetted
	}
	return -1

}

func getop(a, mle int) int{
	res := a + ((mle-2)/2) + 1
	if res > mle{
		res = res - mle
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t, a, b, c int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &a, &b, &c)
		w1 := do(a, b, c)
		fmt.Fprint(w, w1)
		fmt.Fprintln(w)
	}
}

func do(a, b, c int) int {
	n := a - b
	if n < 0 {
		n = -n
	}
	if a > n+n || b > n+n || c > n+n {
		return -1
	}
	if v := n + c; 1 <= v && v <= n+n {
		return v
	}
	if v := -n + c; 1 <= v && v <= n+n {
		return v
	}
	return -1
}

package main
import(
    "fmt"
)
func main(){
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Scan(&a,&b,&c)
		if (abs(a-b)*2) < c || (abs(a-b)*2) < b || (abs(a-b)*2) < a {
			fmt.Println(-1)
		}else{
			if abs(a-b)*2 < c+abs(a-b) {
				fmt.Println(abs((abs(a-b)*2)-(c+abs(a-b))))
			} else {
				fmt.Println(c+abs(a-b))
			}
		}
	}
}

func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main

import (
	"fmt"
	"math"
)

func main() {

	var a, b, c, t int

	fmt.Scan(&t)

	res := make([]int, t)

	for i := 0; i < t; i++ {

		fmt.Scan(&a, &b, &c)

		sub := math.Abs(float64(a - b))

		if a > (int(sub)*2) || b > (int(sub)*2) || c > (int(sub)*2) {

			res[i] = -1

		} else if int(sub) >= c {

			res[i] = c + int(sub)

		} else {
			res[i] = c - int(sub)
		}

	}

	for _, nums := range res {

		fmt.Println(nums)
	}

}

package main

import (
	"fmt"
	"math"
)

func main() {

	var a, b, c, t int

	fmt.Scan(&t)
	var d float64 = 0

	res := make([]int, t)

	for i := 0; i < t; i++ {

		fmt.Scan(&a, &b, &c)

		 sub := math.Abs(float64(a - b))
		 eq := math.Abs(float64(a - b))

		if sub >= 2 {

			if sub >= float64(c) {

				d = float64(c) + sub

			} else {

				d = float64(c) - sub
			}

			if a > (int(eq)*2) || b > (int(eq)*2) || c > (int(eq)*2) {

				res[i] = -1

			} else {
				res[i] = int(d)

			}

		} else {

			res[i] = -1

		}

	}

	for _, nums := range res {

		fmt.Println(nums)
	}

}

package main

import (
	"fmt"
	"math"
)

func fun(a, b, c int32) int32 {
	max := int32(math.Abs(float64(a)-float64(b))) * 2
	if c < 0 || c > max || a < 0 || a > max || b < 0 || b > max {
		return -1
	}
	diff := max / 2
	if c <= diff {
		return c + diff
	} else {
		return c - diff
	}
}

func main() {
	var n int32
	fmt.Scanf("%v\n", &n)
	var a, b, c int32
	for i := int32(0); i < n; i++ {
		fmt.Scanf("%v %v %v\n", &a, &b, &c)
		fmt.Println(fun(a, b, c))
	}
}

package main

import (
	"fmt"
	"math"

)

func maxOfThree(a,b,c int) int{
	max := 0
	var g []int = []int{a,b,c}

	for _, i:=range g {
		if i > max {
			max = i
		}
	}

	return max
}

func main() {
	var t int
	fmt.Scanln(&t)
	var a,b,c int

	for i:= 0; i<t; i++ {
		fmt.Scanln(&a,&b,&c)
		var val int = int(math.Abs(float64(a - b)))
		if 2 * val < maxOfThree(a,b,c){
			fmt.Println(-1)
			continue
		}
		if c <= val{
			fmt.Println(c + val)
		}else{
			fmt.Println(c - val)
		}

	}
}

package main

import (

	"fmt"
	"math"

)

func maxOfThree(a,b,c int) int{
	max := 0
	var g []int = []int{a,b,c}

	for _, i:=range g {
		if i > max {
			max = i
		}
	}

	return max
}

func main() {
	var t int
	fmt.Scanln(&t)
	var a,b,c,sol int

	for i:= 0; i<t; i++ {
		fmt.Scanln(&a,&b,&c)
		if 2 * int(math.Abs(float64(a - b))) < maxOfThree(a,b,c){
			sol = -1

		}else if 2 * int(math.Abs(float64(a - b))) >= c{

			sol = int(math.Abs(float64(a - b))) + c
			if sol > 2 * int(math.Abs(float64(a - b))){
				sol -= 2 * int(math.Abs(float64(a - b)))
			}

			if sol == a ||  sol == b || sol == c {
				sol = -1
			}

		}else{

			sol = -1
		}
		fmt.Println(sol)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	var (
		t int
		a int
		b int
		c int
	)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		sl := strings.Split(scanner.Text(), " ")
		a, _ = strconv.Atoi(sl[0])
		b, _ = strconv.Atoi(sl[1])
		c, _ = strconv.Atoi(sl[2])
		d := 0
		if a > b {
			d = a - b
		} else {
			d = b - a
		}
		if a > d*2 || b > d*2 || c > d*2 {
			fmt.Println(-1)
		} else {
			if c > d {
				fmt.Println(c - d)
			} else {
				fmt.Println(c + d)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	test := parseInt(getString(reader))
	for ; test > 0; test-- {
		abc := getIntln(reader)
		a, b, c := abc[0], abc[1], abc[2]
		var n int
		if a > b {
			n = 2 * (a - b)
		} else {
			n = 2 * (b - a)
		}
		if n < a || n < b {
			writer.WriteString("-1\n")
		} else if c <= n/2 {
			writer.WriteString(fmt.Sprintln(c + n/2))
		} else if c <= n {
			writer.WriteString(fmt.Sprintln(c - n/2))
		} else {
			writer.WriteString("-1\n")
		}
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func Abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		a, b, c := 0, 0, 0
		fmt.Fscan(f, &a, &b, &c)
		del := Abs(a - b)
		if a > del*2 || b > del*2 || c > del*2 || c-del == a || c-del == b || c+del == a || c+del == b {
			fmt.Fprintln(w, -1)
			continue
		}
		if c < 1+del {
			fmt.Fprintln(w, c+del)
		} else {
			fmt.Fprintln(w, c-del)
		}
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var a, b, c int
		fmt.Fscan(in, &a, &b, &c)

		size := abs(b-a) * 2

		cf := (size / 2) + c
		cb := c - (size / 2)

		pos := -1
		if cf <= size && (cf != a && cf != b) {
			pos = cf
		}

		if cb > 0 && (cb != a && cb != b) {
			pos = cb
		}

		if a > size || b > size || c > size {
			pos = -1
		}

		if pos > 0 {
			fmt.Fprintln(out, pos)
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader     = bufio.NewReader(os.Stdin)
	t, a, b, c int
)

func solve(a, b, c int) int {
	if b < a {
		a, b = b, a
	}
	half := b - a
	if c > 2*half || b > 2*half {
		return -1
	}
	if c > half {
		return c - half
	}
	return c + half
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &a, &b, &c)
		fmt.Println(solve(a, b, c))
	}
}

package main

import (
	"fmt"
)

func sort(a, b int) (int, int) {
	if a < b {
		return a, b
	}
	return b, a
}

func b() {
	var a, b, c int
	fmt.Scanf("%d%d%d\n", &a, &b, &c)

	a, b = sort(a, b)
	m := b - a
	if a > m || a+m != b || m == 1 || c > 2*m {
		fmt.Println(-1)
		return
	}
	if c <= m {
		fmt.Println(c + m)
	} else {
		fmt.Println(c - m)
	}
}

func main() {
	var test int
	fmt.Scanf("%d\n", &test)

	for ; test > 0; test-- {
		b()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type CF1560B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1560B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1560B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1560B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1560B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1560B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1560B
Date: 16/09/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1560/B
Problem: CF1560B
**/
func (in *CF1560B) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		a, b, c := in.NextInt64(), in.NextInt64(), in.NextInt64()

		max := Max(a, b) - Min(a, b)

		ans := int64(-1)

		if c <= max*2 && max > 1 && a <= max*2 && b <= max*2 {
			if c+max <= max*2 {
				ans = c + max
			} else if c-max >= 1 {
				ans = c - max
			}
		}
		fmt.Println(ans)
	}
}
func Min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func Max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func NewCF1560B(r *bufio.Reader) *CF1560B {
	return &CF1560B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1560B(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1560B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, a, b, c int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b, &c)
		m := abs(a - b)
		n := m * 2
		if a > n || b > n || c > n {
			Fprintln(out, -1)
		} else {
			Fprintln(out, (c-1+m)%n+1)
		}
	}
}

func main() { CF1560B(os.Stdin, os.Stdout) }

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var a, b, c int
		Fscan(in, &a, &b, &c)

		total := abs(a-b) << 1
		if c > total || a > total || b > total {
			Fprintln(out, -1)
			continue
		}
		Fprintln(out, (c + total/2 - 1) % total + 1 )
	}
}

func main() { run(os.Stdin, os.Stdout) }

func abs(num int) int {
	if num >= 0 {
		return num
	}
	return -num
}

package main

import "fmt"

func main() {
	var a,b,c,T int
	fmt.Scan(&T)
	for i:=0;i<T;i++ {
		fmt.Scan(&a, &b, &c)
		dis := a-b
		if dis <0{
			dis = b-a
		}
		if false {

		} else {
			total := 2 * dis
			if c <1 || c> total || a<1 ||a>total ||
			 b<1 || b>total {
				fmt.Println(-1)
			} else {
				ans := c + dis
				if ans > total {
					ans -= total
				}
				fmt.Println(ans)
			}
		}

	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	out = bufio.NewWriter(os.Stdout)
	in  = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}

func solve() {
	var a, b, c int64
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &b)
	fmt.Fscan(in, &c)
	var diffToOne int64
	var oneisAt int64
	var maxTime int64
	if a > b {
		diffToOne = b - 1
		oneisAt = a - diffToOne
		if oneisAt > a || oneisAt <= b {
			fmt.Println(-1)
			return
		}
	} else {
		diffToOne = a - 1
		oneisAt = b - diffToOne
		if oneisAt > b || oneisAt <= a {
			fmt.Println(-1)
			return
		}
	}
	maxTime = 2*oneisAt - 2
	if c > maxTime {
		fmt.Println(-1)
		return
	}
	var ans int64
	if c >= oneisAt {
		c = c - oneisAt + 1
		ans = oneisAt + c - 1
		ans -= oneisAt
		ans += 1
	} else {
		ans = oneisAt + c - 1
	}
	fmt.Println(ans)

}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

func (r runeSort) Len() int           { return len(r) }
func (r runeSort) Swap(i, j int)      { r[i], r[j] = r[j], r[i] }
func (r runeSort) Less(i, j int) bool { return r[i] < r[j] }

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func Abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int16
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var a, b, c int64
		fmt.Fscan(in, &a, &b, &c)
		half_n := Abs(a - b)
		if a > half_n*2 || b > half_n*2 || c > half_n*2 {
			fmt.Fprintln(out, -1)
		} else {
			if c-half_n > 0 {
				fmt.Fprintln(out, c-half_n)
			} else {
				fmt.Fprintln(out, c+half_n)
			}
		}
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("I") == "IronMan" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			a := iost.GetNextInt()
			b := iost.GetNextInt()
			c := iost.GetNextInt()
			if a > b {
				a, b = b, a
			}
			ret := -1
			if c <= (b-a)*2 && b <= (b-a)*2 {
				if c <= (b - a) {
					ret = c + (b - a)
				} else {
					ret = c - (b - a)
				}
			}
			iost.Println(ret)
		}()
	}
}

package main

import (
	"fmt"
)

func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		a--
		b--
		c--
		diff := Abs(a - b)
		if diff > 0 && (c >= 2*diff || a >= 2*diff || b >= 2*diff) {
			fmt.Println("-1")
			continue
		}
		if diff == 0 {
			mx := Max(a, c)
			mx += mx % 2
			diff = mx / 2
		}
		fmt.Println((c+diff)%(2*diff) + 1)
	}
}

package main

import (
	"bufio"
	. "fmt"
	"os"
)

func main() {
	var T, a, b, c int
	in := bufio.NewReader(os.Stdin)
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &a, &b, &c)
		d, ok := D(a, b, c)
		if !ok {
			Println(-1)
			continue
		}
		Println(Det(c-1, d) + 1)
	}
}

func D(a, b, c int) (int, bool) {
	d := dist(a, b)
	s := 2 * d
	i, j, k := a-1, b-1, c-1
	if i >= s || j >= s || k >= s {
		return -1, false
	}
	if Det(i, d) != j {
		return -1, false
	}

	return d, true
}

func Det(a, d int) int {
	return (a + d) % (2 * d)
}

func dist(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

package main

import (
	"fmt"
  // "log"
)

func solve(a,b,c int) int{
  // pre operation.
  if a > b{
    a,b = b,a
  }

  // validate the input
  diff := b - a
  total := diff * 2
  // log.Println(total)
  if total < b ||  total < a || total < c || total % 2 != 0{
    return -1
  }
  // calculate the circle dimensions
  var ret int
  if c > diff {
    ret = c - diff
  }else{
    ret = c + diff
  }

  return ret
}
func main() {
  // how to find a correlation between A, B, and C.

  var testcases int
  fmt.Scanf("%d\n", &testcases)

  for ; testcases > 0; testcases-- {
	  var a,b,c int
	  fmt.Scanf("%d %d %d\n", &a,&b,&c)
    fmt.Println(solve(a,b,c))
  }
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var a, b, c int
		fmt.Fscan(input, &a, &b, &c)

		// ARR := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	fmt.Fscan(input, &ARR[i])

		// }
		m := MODULE(a, b)
		length := m * 2

		if a > length || b > length || c > length {
			fmt.Println(-1)
		} else {
			var q int
			if c > m {
				q = c - m
			} else {
				q = c + m
			}
			fmt.Println(q)
		}

	}

}

package main

import "fmt"

func main() {
    var testCases int
    fmt.Scanln(&testCases)

    for i := 0; i < testCases; i++ {
        var (
            a int
            b int
            c int
        )
        fmt.Scanf("%d %d %d\n", &a, &b, &c)
        if a == b {
            fmt.Println(-1)
            continue
        }
        diff := a - b
        if diff <= 0 {
            diff = b - a
        }
        n := 2*diff
        if c > n {
            fmt.Println(-1)
            continue
        }
        if a > n {
            fmt.Println(-1)
            continue
        }
        if b > n {
            fmt.Println(-1)
            continue
        }
        cPair := c - diff
        if cPair <= 0 {
            cPair = c + diff
        }
        if cPair > n {
            fmt.Println(-1)
            continue
        }
        if cPair == a || cPair == b {
            fmt.Println(-1)
            continue
        }
        fmt.Println(cPair)

    }
}

package main

import "fmt"

func main() {
	var n int
	var number int
	fmt.Scan(&n)
	var input = make([][]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&number)
		input[i] = make([]int, 3)
		input[i][0] = number
		fmt.Scan(&number)
		input[i][1] = number
		fmt.Scan(&number)
		input[i][2] = number
	}
	for i := 0; i < n; i++ {
		pair := tru(input[i][0], input[i][1])
		if pair*2 < input[i][0] || pair*2 < input[i][1] || pair*2 < input[i][2] {
			fmt.Println(-1)
		} else if input[i][2] > pair {
			fmt.Println(input[i][2] - pair)
		} else {
			fmt.Println(input[i][2] + pair)
		}
	}
}

func tru(a, b int) int {
	if a > b {
		return a - b
	} else {
		return b - a
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	in := NewIn()
	out := NewOut()
	defer out.flush()

	run(in, out)
}

/* --- Solution B --- */
func solve(in *In, out *Out) {
	a := in.nextInt()
	b := in.nextInt()
	c := in.nextInt()

	var k int
	if a > b {
		k = a - b
	} else {
		k = b - a
	}

	var d int
	if 2*k < a || 2*k < b || 2*k < c {
		d = -1
	} else if c-k > 0 {
		d = c - k
	} else if c+k > 0 {
		d = c + k
	} else {
		d = -1
	}

	out.println(d)
}

func run(in *In, out *Out) {
	cases(in, out)
	// solve(in, out)
}

func cases(in *In, out *Out) {
	t := in.nextInt()
	for ; t > 0; t-- {
		solve(in, out)
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 1e7

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) nextDouble() float64 {
	in.scanner.Scan()
	i, _ := strconv.ParseFloat(in.scanner.Text(), 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

func (out *Out) println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for c:=1;c<=t;c++{
		var a, b, c int
		fmt.Fscan(in,&a,&b,&c)
		var numa,numb int
		if a<b{
			numa=a
			numb=b
		}else{
			numa = b
			numb = a
		}
		ans:=0
	//	fmt.Println(numb+1-numa,numa)
		if numb+1-numa<=numa {
			ans = -1
		}
		mid := numb-numa+1
		if c > mid+(mid-2){
			ans = -1
		}else if c<mid && ans!=-1{
			ans = mid + (c-1)
		}else if c== mid && ans !=-1{
			ans = 1
		}else if c>mid && ans!=-1{
			ans = 1 + (c-mid)
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		fmt.Fprintln(wr, solve())
	}
}

func solve() int {
	a, b, c := scanInt(), scanInt(), scanInt()
	if a > b {
		a, b = b, a
	}

	// a < b
	n := (b - a) * 2
	if a > n || b > n || c > n {
		return -1
	} else if a <= n/2 && b <= n/2 {
		return -1
	} else if a > n/2 && b > n/2 {
		return -1
	}

	if c <= n/2 {
		return c + n/2
	}
	return c - n/2
}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

func scanInt() int {
	sc.Scan()
	ret, _ := strconv.Atoi(sc.Text())
	return ret
}

package main
//this code is written by likely
//do not distribute it freely

import (
	"bufio"
	"fmt"
	"os"
)

func main(){
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t,a,b,c,i,n int32
	fmt.Fscan(in,&t)
	for i=1;i<=t;i++{
		fmt.Fscan(in,&a);fmt.Fscan(in,&b);fmt.Fscan(in,&c)
		if a==b {
			fmt.Fprintln(out, -1)
			continue
		}else{
			if a>b{
				n=(a-b)*2
			}else{
				n=(b-a)*2
			}
			if a>n{
				fmt.Fprintln(out,-1)
				continue
			}
			if(b>n){
				fmt.Fprintln(out,-1)
				continue
			}
			if c<=n {
				if c > n/2 {
					fmt.Fprintln(out,c-n/2)
				} else {
					fmt.Fprintln(out,c+n/2)
				}
			}else{
				fmt.Fprintln(out,-1)
			}
		}
	}
}

/******************************************************************************

                            Online Go Lang Compiler.
                Code, Compile, Run and Debug Go Lang program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/

package main

import "fmt"
import "bufio"
import "os"
//import "sort"

func main() {
    in := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(in, &n)
    for ; n > 0; n--{
        var a, b, c int
        fmt.Fscan(in, &a, &b, &c)
        if (b > a) {
            a,b = b,a
        }
        var sz = (a - b) * 2

        if (c > sz || a > sz || b > sz) {
            fmt.Println(-1)
        } else {
            sz /= 2
            if (c > sz) {
                fmt.Println(c - sz)
            } else {
                fmt.Println(c + sz)
            }
        }
    }

}

package main

import (
	"bufio"
	"os"
	"fmt"
)

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(r, &a, &b, &c)

		solve(a, b, c)
	}
}

func solve(a, b , c int) {
	diff := abs(a - b)

	all := 2 * diff

	if c > all || a > all || b > all{
		fmt.Println(-1)
		return
	}

	if c <= diff {
		fmt.Println(c + diff)
	} else {
		fmt.Println(c - diff)
	}

}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T, a, b, c int

	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		fmt.Fscanf(r, "%d %d %d\n", &a, &b, &c)

		if a > b {
			a, b = b, a
		}
		d := b - a

		x := 1
		y := 2 * d

		if a >= x && a <= y && b >= x && b <= y && c >= x && c <= y {
			if c >= 1+d {
				fmt.Println(c - d)
			} else {
				fmt.Println(c + d)
			}
		} else {
			fmt.Println(-1)
		}
	}
}

package main

import (
	"fmt"
	"bufio"
	"os"
)

func toInt(buf []byte) (n int) {
    for _, v := range buf {
        n = n*10 + int(v-'0')
    }
    return
}

func max(a, b int) int{
  if a > b{
    return a
  }else{
    return b
  }
}

func min(a, b int) int{
  if a < b{
    return a
  }else{
    return b
  }
}

func main() {
	var a, b, c int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
  var t int
  scanner.Scan()
  t = toInt(scanner.Bytes())
  for g := 0; g < t; g++{
    scanner.Scan()
    a = toInt(scanner.Bytes())
    scanner.Scan()
    b = toInt(scanner.Bytes())
    scanner.Scan()
    c = toInt(scanner.Bytes())
    sz := (max(a, b) - min(a, b)) * 2
    if (a <= sz) && (b <= sz) && (c <= sz){
      fmt.Println((c + (sz / 2) - 1) % sz + 1)
    }else{
      fmt.Println(-1)
    }
  }
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.ParseInt(s, 10, 32); return int(x) }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                              { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop

func main() {
	rw=newIop()
	defer func() {
		if isLocal() {
			rw.Println("Recovering ", recover())
		}
		rw.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		rw.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	test := rw.GetNextInt()
	for test > 0 {
		test--
		func(){
				a := rw.GetNextInt()
				b := rw.GetNextInt()
				c := rw.GetNextInt()

			if a > b {
				a, b = b, a
			}

			if c > (b - a)*2 || a > (b - a)*2 || b > (b - a)*2 {
				fmt.Println(-1)
			} else {
				if c > (b - a) {
					c -= b - a
				} else {
					c += b - a
				}
				rw.Println(c)
			}
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

type iop struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func (i *iop) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *iop) Atoi(s string) int                 { x, _ := strconv.ParseInt(s, 10, 32); return int(x) }
func (i *iop) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *iop) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *iop) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *iop) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *iop) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *iop) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *iop) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *iop) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                              { return os.Getenv("inLocalEnv") == "indeed" }
func newIop() *iop {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("input"))
	}
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &iop{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

var rw *iop = newIop()

func main() {
	defer func() {
		if isLocal() {
			rw.Println("Recovering ", recover())
		}
		rw.Writer.Flush()
	}()
	solve()
}

func solve() {
	test := rw.GetNextInt()
	for test > 0 {
		test--
		func(){
				a := rw.GetNextInt()
				b := rw.GetNextInt()
				c := rw.GetNextInt()

			if a > b {
				a, b = b, a
			}
			var maxNumber int
			maxNumber = b - a
			if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
				fmt.Println(-1)

			} else {
				if c > maxNumber {
					c -= maxNumber
				} else {
					c += maxNumber
				}
				rw.Println(c)
			}
		}()
	}
}

package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

func checkErr(e error) {
	if e != nil {
		log.Fatal("Error occurred ", e)
	}
}

const BufSize = 1000000

//type iop struct {
//	scanner *bufio.Scanner
//	writer  *bufio.Writer
//}
//
//func newIop(fp *io.Reader,wfp *io.Writer) *iop   {
//	const BufSize = 1000000
//	scanner:=bufio.NewScanner(fp)
//	scanner.Buffer(make([]byte,BufSize),BufSize)
//}

//func (i iop) newIop()  {
//
//}
func main() {

	fp := os.Stdin
	scanner := bufio.NewScanner(fp)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	scanner.Split(bufio.ScanLines)
		if !scanner.Scan() {
			panic("NOOOOOO!")
			//fmt.Println(scanner.Text())
		}
	test ,_:= strconv.Atoi(scanner.Text())
	fmt.Println(test)
	var (
		a, b, c, maxNumber int
	)
	for idx := 0; idx < test; idx++ {
		if !scanner.Scan() {
			fmt.Println(scanner.Text())
			break
		}
		x := scanner.Text()
		INTS := strings.Split(x, " ")
		a, _ = strconv.Atoi(INTS[0])
		b, _ = strconv.Atoi(INTS[1])
		c, _ = strconv.Atoi(INTS[2])
		if a > b {
			a, b = b, a
		}
		maxNumber = b - a
		if c > maxNumber*2 || a > maxNumber*2 || b > maxNumber*2 {
			fmt.Println(-1)

		} else {
			if c > maxNumber {
				c -= maxNumber
			} else {
				c += maxNumber
			}
			fmt.Println(c)
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		dd := abs(a - b)
		if a > 2*dd || b > 2*dd || c > 2*dd {
			fmt.Println("-1")
		} else {
			if c <= dd {
				c += dd
			} else {
				c -= dd
			}

		}
		fmt.Println(c)
	}
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		dd := abs(a - b)
		if a > 2*dd || b > 2*dd || c > 2*dd {
			fmt.Println("-1")
		} else {
			if c <= dd {
				c += n
			} else {
				c -= n
			}

		}
		fmt.Println(c)
	}
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		fmt.Println(dd(a, b, c))
	}
}

func dd(a, b, c int) int {
	d := abs(a - b)
	if d*2 < a || d*2 < b || d*2 < c {
		return -1
	}
	if c > d {
		return d*2 - c - 1
	} else {
		return d + c
	}

}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		fmt.Println(dd(a, b, c))
	}
}

func dd(a, b, c int) int {
	d := abs(a - b)
	if d*2 < a || d*2 < b || d*2 < c {
		return -1
	}
	if c > d {
		return d*2 - c - 1
	} else if c == d {
		return 2 * c
	} else {
		return d + c
	}

}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		fmt.Println(dd(a, b, c))
	}
}

func dd(a, b, c int) int {
	if abs(a-b)*2 < a || abs(a-b)*2 < b || abs(a-b)*2 < c {
		return -1
	}
	if c > abs(a-b) {
		return abs(a-b)*2 - c - 1
	} else if c == abs(a-b) {
		return 2 * c
	} else {
		return abs(a-b) + c
	}

}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		fmt.Println(dd(a, b, c))
	}
}

func dd(a, b, c int) int {
	if abs(a-b)*2 < a || abs(a-b)*2 < b || abs(a-b)*2 < c {
		return -1
	}
	if c < abs(a-b) {
		return c + abs(a-b)
	} else {
		return abs(a-b)*2 - c + 1
	}
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		fmt.Println(dd(a, b, c))
	}
}

func dd(a, b, c int) int {
	if abs(a-b)*2 < a || abs(a-b)*2 < b || abs(a-b)*2 < c {
		return -1
	}
	if c < abs(a-b) {
		return c + abs(a-b)
	} else {
		return c - abs(a-b)
	}
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scan(&a, &b, &c)
		fmt.Println(dd(a, b, c))
	}
}

func dd(a, b, c int) int {
	if abs(a-b) < a || abs(a-b) < b || abs(a-b) < c {
		return -1
	}
	if c < abs(a-b) {
		return c + abs(a-b)
	} else {
		return c - abs(a-b)
	}
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

package main

import (
	"fmt"
	"os"
	"bufio"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &c)
		a--; b--; c--
		if a > b {
		    a, b = b, a
		}
		tmp := 2 * (b - a)
		var ans int
		if b > tmp || c > tmp || a * 2 >= b {
		    ans = -1
		} else {
		    ans = (c + b - a) % tmp + 1
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &c)
		a--; b--; c--
		if a > b {
		    a, b = b, a
		}
		tmp := 2 * (b - a)
		var ans int
		if b > tmp || c > tmp {
		    ans = -1
		} else {
		    ans = (c + b - a) % tmp + 1
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a int
		var b int
		var c int
		fmt.Fscan(in, &a)
		fmt.Fscan(in, &b)
		fmt.Fscan(in, &c)
		if a > b {
		    a, b = b, a
		}
		tmp := 2 * (b - a)
		var ans int
		if b > tmp || c > tmp {
		    ans = -1
		} else {
		    ans = (c + b - a) % tmp
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var a, b, c int64
		fmt.Fscan(r, &a, &b, &c)
		maxNum,minNum := abs(a, b)
		abs:=maxNum-minNum
		if 2*abs<maxNum&&2*abs<c{
			fmt.Println(-1)
		}else {
			if c>abs{
				fmt.Println(c-abs)
			}else {
				fmt.Println(c+abs)
			}
		}
	}
}

func abs(a int64, b int64) (int64, int64) {
	var max, min int64
	if a >= b {
		max = a
		min = b
	} else {
		max = b
		min = a

	}

	return max, min
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var a, b, c int64
		fmt.Fscan(r, &a, &b, &c)
		maxNum,minNum := abs(a, b)
		abs:=maxNum-minNum
		if 2*abs<maxNum&&2*abs<c{
			fmt.Println(-1)
		}else {
			if c>=abs{
				fmt.Println(c-abs)
			}else {
				fmt.Println(c+abs)
			}
		}
	}
}

func abs(a int64, b int64) (int64, int64) {
	var max, min int64
	if a >= b {
		max = a
		min = b
	} else {
		max = b
		min = a

	}

	return max, min
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var t int64
	r := bufio.NewReader(os.Stdin)
	w:=bufio.NewWriter(os.Stdout)
	fmt.Fscan(r, &t)
	for i := int64(0); i < t; i++ {
		var a, b, c int64
		fmt.Fscan(r, &a, &b, &c)
		maxNum,minNum := abs(a, b)
		abs:=maxNum-minNum
		if 2*abs<maxNum&&2*abs<c{
			fmt.Fprintln(w,-1)
		}else {
			if c>=abs{
				fmt.Fprintln(w,c+abs)
			}else {
				fmt.Fprintln(w,c-abs)
			}
		}
	}
}

func abs(a int64, b int64) (int64, int64) {
	var max, min int64
	if a >= b {
		max = a
		min = b
	} else {
		max = b
		min = a

	}

	return max, min
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	ins  :=  bufio . NewReader ( os.Stdin )
	out  :=  bufio . NewWriter ( os.Stdout )
	defer  out . Flush ()

	scan := func(a ...interface{}) (int, error)             { return fmt.Fscan(ins, a...) }
	printf := func(s string, a ...interface{}) (int, error) { return fmt.Fprintf(out, s, a...) }
	var n int
	scan(&n)

	for i:=0; i<n;i++{
		var a,b,c int
		scan(&a, &b, &c)
		res := fn(a, b, c)

		printf("%d\n",res)
	}

}
func fn(a ,b, c int) int{
	minlen := a
	if b>a {
		minlen = b
	}
	if c>a && c>b{
		minlen=c
	}
	if minlen %2 != 0{
		minlen++
	}
	maxlen := minlen+4

	for minlen<maxlen{
		cgetted := getop(c, minlen)
		if getop(a, minlen) == b && cgetted != a && cgetted != b{
			return cgetted
		}
		minlen += 2
	}
	return -1

}

func getop(a, mle int) int{
	res := a + ((mle-2)/2) + 1
	if res > mle{
		res = res - mle
	}
	return res
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t, a, b, c int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &a, &b, &c)
		w1 := do(a, b, c)
		fmt.Fprint(w, w1)
		fmt.Fprintln(w)
	}
}

func do(a, b, c int) int {
	n := a - b
	if n < 0 {
		n = -n
	}
	if a > n+n || b > n+n {
		return -1
	}
	if v := n + c; 1 <= v && v <= n+n {
		return v
	}
	if v := -n + c; 1 <= v && v <= n+n {
		return v
	}
	return -1
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t, a, b, c int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &a, &b, &c)
		w1 := do(a, b, c)
		fmt.Fprint(w, w1)
		fmt.Fprintln(w)
	}
}

func do(a, b, c int) int {
	n := a - b
	if n < 0 {
		n = -n
	}
	if a >= n+n || b >= n+n {
		return -1
	}
	if v := n + c; 1 <= v && v <= n+n {
		return v
	}
	if v := -n + c; 1 <= v && v <= n+n {
		return v
	}
	return -1
}

package main
import(
    "fmt"
)
func main(){
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Scan(&a,&b,&c)
		if (abs(a-b)*2) < c || (abs(a-b)*2) < b || (abs(a-b)*2) < a {
			fmt.Println(-1)
		}else{
			if abs((abs(a-b)*2)-(c+abs(a-b))) == 0 {
				fmt.Println(abs(a-b)*2)
			}else {
				fmt.Println(abs((abs(a-b)*2)-(c+abs(a-b))))
			}
		}
	}
}

func abs(x int) int {
	var result int
	if x > 0 {
		result = x
	} else {
		if x < 0 {
			result = x*-1
		}
	}
	return result
}

package main;

import (
    "fmt"
)

func main() {
    fmt.Println("hi")
}