Shichikuji is the new resident deity of the South Black Snail Temple. Her first job is as follows:There are $$$n$$$ new cities located in Prefecture X. Cities are numbered from $$$1$$$ to $$$n$$$. City $$$i$$$ is located $$$x_i$$$ km North of the shrine and $$$y_i$$$ km East of the shrine. It is possible that $$$(x_i, y_i) = (x_j, y_j)$$$ even when $$$i \ne j$$$.Shichikuji must provide electricity to each city either by building a power station in that city, or by making a connection between that city and another one that already has electricity. So the City has electricity if it has a power station in it or it is connected to a City which has electricity by a direct connection or via a chain of connections.     Building a power station in City $$$i$$$ will cost $$$c_i$$$ yen;     Making a connection between City $$$i$$$ and City $$$j$$$ will cost $$$k_i + k_j$$$ yen per km of wire used for the connection. However, wires can only go the cardinal directions (North, South, East, West). Wires can cross each other. Each wire must have both of its endpoints in some cities. If City $$$i$$$ and City $$$j$$$ are connected by a wire, the wire will go through any shortest path from City $$$i$$$ to City $$$j$$$. Thus, the length of the wire if City $$$i$$$ and City $$$j$$$ are connected is $$$|x_i - x_j| + |y_i - y_j|$$$ km. Shichikuji wants to do this job spending as little money as possible, since according to her, there isn't really anything else in the world other than money. However, she died when she was only in fifth grade so she is not smart enough for this. And thus, the new resident deity asks for your help.And so, you have to provide Shichikuji with the following information: minimum amount of yen needed to provide electricity to all cities, the cities in which power stations will be built, and the connections to be made.If there are multiple ways to choose the cities and the connections to obtain the construction of minimum price, then print any of them.

First line of input contains a single integer $$$n$$$ ($$$1 \leq n \leq 2000$$$) — the number of cities. Then, $$$n$$$ lines follow. The $$$i$$$-th line contains two space-separated integers $$$x_i$$$ ($$$1 \leq x_i \leq 10^6$$$) and $$$y_i$$$ ($$$1 \leq y_i \leq 10^6$$$) — the coordinates of the $$$i$$$-th city. The next line contains $$$n$$$ space-separated integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \leq c_i \leq 10^9$$$) — the cost of building a power station in the $$$i$$$-th city. The last line contains $$$n$$$ space-separated integers $$$k_1, k_2, \dots, k_n$$$ ($$$1 \leq k_i \leq 10^9$$$).

In the first line print a single integer, denoting the minimum amount of yen needed. Then, print an integer $$$v$$$ — the number of power stations to be built. Next, print $$$v$$$ space-separated integers, denoting the indices of cities in which a power station will be built. Each number should be from $$$1$$$ to $$$n$$$ and all numbers should be pairwise distinct. You can print the numbers in arbitrary order. After that, print an integer $$$e$$$ — the number of connections to be made. Finally, print $$$e$$$ pairs of integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le n$$$, $$$a \ne b$$$), denoting that a connection between City $$$a$$$ and City $$$b$$$ will be made. Each unordered pair of cities should be included at most once (for each $$$(a, b)$$$ there should be no more $$$(a, b)$$$ or $$$(b, a)$$$ pairs). You can print the pairs in arbitrary order. If there are multiple ways to choose the cities and the connections to obtain the construction of minimum price, then print any of them.

NoteFor the answers given in the samples, refer to the following diagrams (cities with power stations are colored green, other cities are colored blue, and wires are colored red):For the first example, the cost of building power stations in all cities is $$$3 + 2 + 3 = 8$$$. It can be shown that no configuration costs less than 8 yen.For the second example, the cost of building a power station in City 2 is 2. The cost of connecting City 1 and City 2 is $$$2 \cdot (3 + 2) = 10$$$. The cost of connecting City 2 and City 3 is $$$3 \cdot (2 + 3) = 15$$$. Thus the total cost is $$$2 + 10 + 15 = 27$$$. It can be shown that no configuration costs less than 27 yen.

package main

import (
	"bufio"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

type edge struct {
	a    int
	b    int
	cost int64
}

type edgeArray []edge

func (e edgeArray) Len() int           { return len(e) }
func (e edgeArray) Swap(i, j int)      { e[i], e[j] = e[j], e[i] }
func (e edgeArray) Less(i, j int) bool { return e[i].cost < e[j].cost }

var stations []int

func solve() {

	n := readInt()
	coords := make([][2]int64, n)
	c := make([]int64, n)
	k := make([]int64, n)
	for i := 0; i < n; i++ {
		coords[i][0], coords[i][1] = readInt64(), readInt64()
	}
	for i := 0; i < n; i++ {
		c[i] = readInt64()
	}
	for i := 0; i < n; i++ {
		k[i] = readInt64()
	}

	edges := make(edgeArray, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if i == j {
				continue
			}
			cost := (k[i] + k[j]) * dist(coords, i, j)
			edges = append(edges, edge{a: i, b: j, cost: cost})
		}
	}

	sort.Sort(edges)

	y := int64(0)

	stations = make([]int, n)
	for i := 0; i < n; i++ {
		stations[i] = i
		y += c[i]
	}

	v := n
	e := 0
	ans := make(edgeArray, 0)

	for i := 0; i < len(edges); i++ {
		edge := edges[i]
		pa := snm(edge.a)
		pb := snm(edge.b)
		if pa == pb {
			continue
		}
		pmax := pa
		if c[pa] < c[pb] {
			pmax = pb
		}
		if c[pmax] > edge.cost {
			stations[pmax] = snm(pa + pb - pmax)
			ans = append(ans, edge)
			y = y - c[pmax] + edge.cost
			e++
			v--
		}
	}

	printInt64(y)
	ln()

	printInt(v)
	ln()

	for i := 0; i < n; i++ {
		if i == snm(i) {
			printInt(i + 1)
		}
	}
	ln()

	printInt(e)
	ln()

	for i := 0; i < len(ans); i++ {
		printInt(ans[i].a + 1)
		printInt(ans[i].b + 1)
		ln()
	}

}

func snm(k int) int {
	if stations[k] == k {
		return k
	}
	ret := snm(stations[k])
	stations[k] = ret
	return ret
}

func dist(coords [][2]int64, i, j int) int64 {
	x1, y1, x2, y2 := coords[i][0], coords[i][1], coords[j][0], coords[j][1]
	dx := x1 - x2
	if dx < 0 {
		dx = -dx
	}
	dy := y1 - y2
	if dy < 0 {
		dy = -dy
	}
	return dx + dy
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString(" ")
}

func ln() {
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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

// AbsInt is integer version of math.Abs
func AbsInt(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

type City struct {
	id, x, y int64
}

var n int64
var cities []City
var C []int64
var K []int64

var ans int64
var ansCityIds []int64
var connectedCities [][]int64

const NUM = 2000 + 5

func main() {
	n = ReadInt64()
	for i := int64(0); i < n; i++ {
		x, y := ReadInt64_2()
		cities = append(cities, City{id: i + 1, x: x, y: y})
	}
	C = ReadInt64Slice(int(n))
	K = ReadInt64Slice(int(n))

	// エッジを作る
	for i := int64(0); i < n; i++ {
		for j := i + 1; j < n; j++ {
			ci, cj := cities[i], cities[j]
			dist := AbsInt(ci.x-cj.x) + AbsInt(ci.y-cj.y)
			coef := K[ci.id-1] + K[cj.id-1]
			ecost := coef * dist

			M[ci.id][cj.id] = ecost
			M[cj.id][ci.id] = ecost
		}
	}
	// id:0のダミーノードにダミーエッジをはる
	for i := int64(0); i < n; i++ {
		M[0][i+1] = C[i]
		M[i+1][0] = C[i]
	}

	ans := prim()
	fmt.Println(ans)
	fmt.Println(len(ansCityIds))
	fmt.Println(PrintInts64Line(ansCityIds...))
	fmt.Println(len(connectedCities))
	for i := 0; i < len(connectedCities); i++ {
		fmt.Printf("%d %d\n", connectedCities[i][0], connectedCities[i][1])
	}
}

const MAX = 2000 + 5

var M [MAX][MAX]int64

// O(|V|^2)
func prim() int64 {
	var u, minv int64
	var d, p, color [MAX]int64

	for i := int64(0); i <= n; i++ {
		d[i] = INF_BIT60
		p[i] = -1
		color[i] = WHITE
	}

	d[0] = 0

	// すべてのノードがBLACKになるまで続くのでn回ループする
	for {
		// 次にTに加えるべきノードuを選定する
		minv = INF_BIT60
		u = -1
		for i := int64(0); i <= n; i++ {
			if minv > d[i] && color[i] != BLACK {
				u = i
				minv = d[i]
			}
		}
		if u == -1 {
			break // すべての頂点がTに属していたら終了
		}

		color[u] = BLACK // uをTに所属させる
		if p[u] != -1 {
			if p[u] == 0 {
				ansCityIds = append(ansCityIds, u)
			} else {
				connectedCities = append(connectedCities, []int64{p[u], u})
			}
		}

		for v := int64(0); v <= n; v++ {
			if color[v] != BLACK && M[u][v] != INF_BIT60 {
				if d[v] > M[u][v] {
					d[v] = M[u][v]
					p[v] = u
					color[v] = GRAY // ここをコメントアウトしてもACする
				}
			}
		}
	}

	sum := int64(0)
	for i := int64(0); i <= n; i++ {
		if p[i] != -1 {
			sum += M[i][p[i]]
		}
		// sum += d[i] // これでもACする
	}
	return sum
}

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
- MOD取る系はint64必須ですよ？
*/

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	type pair struct{ x, y int }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &ps[i].x, &ps[i].y)
	}
	costCity := make([]int, n)
	for i := range costCity {
		Fscan(in, &costCity[i])
	}
	costLine := make([]int, n)
	for i := range costLine {
		Fscan(in, &costLine[i])
	}

	type dist struct {
		v, w int
		d    int64
	}
	ds := make([]dist, 0, n*n)
	for i, pi := range ps {
		for j, pj := range ps {
			if j == i {
				ds = append(ds, dist{i, j, int64(costCity[i])})
			} else {
				ds = append(ds, dist{i, j, int64(abs(pi.x-pj.x)+abs(pi.y-pj.y)) * int64(costLine[i]+costLine[j])})
			}
		}
	}
	sort.Slice(ds, func(i, j int) bool { return ds[i].d < ds[j].d })

	ans := int64(0)
	ansCity := []interface{}{}
	ansConn := []pair{}
	initFa(n + 1)
	for _, d_ := range ds {
		v, w, d := d_.v, d_.w, d_.d
		if v == w {
			if !same(v, n) {
				ans += d
				ansCity = append(ansCity, v+1)
				merge(v, n)
			}
		} else {
			if !same(v, w) {
				ans += d
				ansConn = append(ansConn, pair{v + 1, w + 1})
				merge(v, w)
			}
		}
	}
	Fprintln(out, ans)
	Fprintln(out, len(ansCity))
	Fprintln(out, ansCity...)
	Fprintln(out, len(ansConn))
	for _, p := range ansConn {
		if p.x > p.y {
			p.x, p.y = p.y, p.x
		}
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func solve(reader io.Reader, writer io.Writer) {
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	type pair struct{ x, y int }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &ps[i].x, &ps[i].y)
	}
	costCity := make([]int, n)
	for i := range costCity {
		Fscan(in, &costCity[i])
	}
	costLine := make([]int, n)
	for i := range costLine {
		Fscan(in, &costLine[i])
	}

	dist := [2001][2001]int64{}
	for i := 0; i < n; i++ {
		dist[i][n] = int64(costCity[i])
		dist[n][i] = dist[i][n]
		for j := i + 1; j < n; j++ {
			dist[i][j] = int64(abs(ps[i].x-ps[j].x)+abs(ps[i].y-ps[j].y)) * int64(costLine[i]+costLine[j])
			dist[j][i] = dist[i][j]
		}
	}

	ans := int64(0)
	ansCity := []interface{}{}
	ansConn := []pair{}
	type distCity struct {
		d int64
		v int
	}
	minCost := make([]distCity, n+1)
	for i := range minCost {
		minCost[i].d = int64(1e18)
	}
	minCost[0].d = 0
	used := make([]bool, n+1)
	for {
		v := -1
		for w := 0; w <= n; w++ {
			if !used[w] && (v == -1 || minCost[w].d < minCost[v].d) {
				v = w
			}
		}
		if v == -1 {
			break
		}
		used[v] = true
		if minCost[v].d > 0 {
			ans += minCost[v].d
			if v == n {
				ansCity = append(ansCity, minCost[v].v+1)
			} else if minCost[v].v == n {
				ansCity = append(ansCity, v+1)
			} else {
				ansConn = append(ansConn, pair{minCost[v].v + 1, v + 1})
			}
		}
		for w := 0; w <= n; w++ {
			if dist[v][w] < minCost[w].d {
				minCost[w] = distCity{dist[v][w], v}
			}
		}
	}
	Fprintln(out, ans)
	Fprintln(out, len(ansCity))
	Fprintln(out, ansCity...)
	Fprintln(out, len(ansConn))
	for _, p := range ansConn {
		if p.x > p.y {
			p.x, p.y = p.y, p.x
		}
		Fprintln(out, p.x, p.y)
	}
}

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

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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

type node struct {
	from int
	val  int64
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	tt := 1
	//fmt.Fscanf(in, "%d\n", &tt)
	for ii := 0; ii < tt; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		c := make([]int64, n)
		x := make([]int, n)
		y := make([]int, n)
		k := make([]int64, n)
		a := make([]node, n)
		used := make([]bool, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d %d\n", &x[i], &y[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &c[i])
		}
		fmt.Fscanf(in, "\n")
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &k[i])
		}
		fmt.Fscanf(in, "\n")
		for i := 0; i < n; i++ {
			a[i] = node{-1, c[i]}
		}
		ans := int64(0)
		anss := []int{}
		ansv := make([][]int, 0)
		for i := 0; i < n; i++ {
			selected := -1
			for j := 0; j < n; j++ {
				if !used[j] {
					if selected == -1 {
						selected = j
					} else if a[j].val < a[selected].val {
						selected = j
					}
				}
			}
			if a[selected].from == -1 {
				anss = append(anss, selected)
			} else {
				ansv = append(ansv, []int{a[selected].from, selected})
			}
			ans += a[selected].val
			used[selected] = true
			for j := 0; j < n; j++ {
				if !used[j] {
					dis := dis(x[selected], y[selected], x[j], y[j])
					newcost := int64(dis) * (int64(k[selected]) + int64(k[j]))
					if newcost < a[j].val {
						a[j].val = newcost
						a[j].from = selected
					}
				}
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
		fmt.Fprintf(out, "%d\n", len(anss))
		for i := 0; i < len(anss)-1; i++ {
			fmt.Fprintf(out, "%d ", anss[i]+1)
		}
		if len(anss) > 0 {
			fmt.Fprintf(out, "%d\n", anss[len(anss)-1]+1)
		}
		fmt.Fprintf(out, "%d\n", len(ansv))
		for i := 0; i < len(ansv); i++ {
			fmt.Fprintf(out, "%d %d\n", ansv[i][0]+1, ansv[i][1]+1)
		}
	}
	return
}

func dis(x1, y1, x2, y2 int) int {
	return abs(x1-x2) + abs(y1-y2)
}

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

// if median can be larger or equal to mid
func ok(mid int, a [][]int, s int64) bool {
	n := len(a)
	b := make([]int, n) // salary
	cost := int64(0)
	c := make([]int, 0) // which can be larger then mid
	for i := 0; i < n; i++ {
		if a[i][1] >= mid {
			if a[i][0] <= mid {
				b[i] = mid
			} else {
				b[i] = a[i][0]
			}
			c = append(c, i)
		} else {
			b[i] = a[i][0]
		}
		cost += int64(b[i])
	}
	//fmt.Println("debug3", c)
	if len(c) < (n+1)/2 {
		return false
	}
	save := make([]int, 0)
	for i := 0; i < len(c); i++ {
		id := c[i]
		if a[id][0] <= mid {
			save = append(save, b[id]-a[id][0])
		}
	}

	sort.Ints(save)
	needSave := n/2 - (n - len(c))
	if needSave > len(save) {
		needSave = len(save)
	}
	for i := 0; i < needSave; i++ {
		cost -= int64(save[len(save)-1-i])
	}
	if cost <= s {
		return true
	}
	return false
}

package main

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

const N = 2020
const INF = int64(1e18)
var n int
var x[N] int
var y[N] int
var c[N] int
var k[N] int

type Edge struct {
	to int
	dist int64
}

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

func getDist(i int, j int) int64 {
	if i == 0 {
		return int64(c[j])
	}
	if j == 0 {
		return int64(c[i])
	}
	var diff = int64(k[i] + k[j]) * int64(abs(x[i], x[j]) + abs(y[i], y[j]))
	return diff
}

var visited[N] bool

func main() {
	var reader= bufio.NewReader(os.Stdin)
	var writer= bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &c[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &k[i])
	}

	var ret = int64(0)
	var burn = make([]int, 0)
	var edx = make([]int, 0)
	var edy = make([]int, 0)

	var edges = make([]Edge, n + 1)

	for i := 1; i <= n; i++ {
		edges[i].dist = INF
		edges[i].to = -1
	}
	edges[0].dist = 0

	for i := 1; i <= n + 1; i++ {
		var f = -1
		for j := 0; j <= n; j++ {
			if visited[j] == false && (f == -1 || edges[j].dist < edges[f].dist) {
				f = j
			}
		}

		if f == -1 {
			break
		}

		ret += edges[f].dist

		if edges[f].to != -1 {
			var u = f
			var v = edges[f].to
			if u > v {
				u, v = v, u
			}
			if u == 0 {
				if v > 0 {
					burn = append(burn, v)
				}
			} else {
				edx = append(edx, u)
				edy = append(edy, v)
			}
		}

		visited[f] = true
		for j := 0; j <= n; j++ {
			if !visited[j] {
				var canDist = getDist(f, j)
				if edges[j].dist > canDist {
					edges[j].dist = canDist
					edges[j].to = f
				}
			}
		}
	}

	fmt.Fprintf(writer, "%d\n", ret)

	fmt.Fprintf(writer, "%d\n", len(burn))
	for _, u := range burn {
		fmt.Fprintf(writer, "%d ", u)
	}
	fmt.Fprintf(writer,"\n")

	fmt.Fprintf(writer, "%d\n", len(edx))
	for i := 0; i < len(edx); i++ {
		fmt.Fprintf(writer, "%d %d\n", edx[i], edy[i])
	}

}

package main

import (
	"bufio"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

type edge struct {
	a    int
	b    int
	cost int64
}

type edgeArray []edge

func (e edgeArray) Len() int           { return len(e) }
func (e edgeArray) Swap(i, j int)      { e[i], e[j] = e[j], e[i] }
func (e edgeArray) Less(i, j int) bool { return e[i].cost < e[j].cost }

var stations []int

func solve() {

	n := readInt()
	coords := make([][2]int64, n)
	c := make([]int64, n)
	k := make([]int64, n)
	for i := 0; i < n; i++ {
		coords[i][0], coords[i][1] = readInt64(), readInt64()
	}
	for i := 0; i < n; i++ {
		c[i] = readInt64()
	}
	for i := 0; i < n; i++ {
		k[i] = readInt64()
	}

	edges := make(edgeArray, n*n)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			cost := int64(100000000000000)
			if i != j {
				cost = (k[i] + k[j]) * dist(coords, i, j)
			}
			edges[i*n+j] = edge{a: i, b: j, cost: cost}
		}
	}

	sort.Sort(edges)

	y := int64(0)

	stations = make([]int, n)
	for i := 0; i < n; i++ {
		stations[i] = i
		y += c[i]
	}

	v := n
	e := 0
	ans := make(edgeArray, 0)

	for i := 0; i < n*(n-1); i++ {
		edge := edges[i]
		pa := snm(edge.a)
		pb := snm(edge.b)
		pmax := pa
		if c[pa] < c[pb] {
			pmax = pb
		}
		if c[pmax] > edge.cost {
			stations[pmax] = snm(pa + pb - pmax)
			ans = append(ans, edge)
			y = y - c[pmax] + edge.cost
			e++
			v--
		}
	}

	printInt64(y)
	ln()

	printInt(v)
	ln()

	for i := 0; i < n; i++ {
		if i == snm(i) {
			printInt(i + 1)
		}
	}
	ln()

	printInt(e)
	ln()

	for i := 0; i < len(ans); i++ {
		printInt(ans[i].a + 1)
		printInt(ans[i].b + 1)
		ln()
	}

}

func snm(k int) int {
	if stations[k] == k {
		return k
	}
	ret := snm(stations[k])
	stations[k] = ret
	return ret
}

func dist(coords [][2]int64, i, j int) int64 {
	x1, y1, x2, y2 := coords[i][0], coords[i][1], coords[j][0], coords[j][1]
	dx := x1 - x2
	if dx < 0 {
		dx = -dx
	}
	dy := y1 - y2
	if dy < 0 {
		dy = -dy
	}
	return dx + dy
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString(" ")
}

func ln() {
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

import (
	"bufio"
	"os"
	"runtime"
	"sort"
	"strconv"
)

/* solution */

type edge struct {
	a    int
	b    int
	cost int64
}

type edgeArray []edge

func (e edgeArray) Len() int           { return len(e) }
func (e edgeArray) Swap(i, j int)      { e[i], e[j] = e[j], e[i] }
func (e edgeArray) Less(i, j int) bool { return e[i].cost < e[j].cost }

var stations []int

const inf = int64(9223372036854775807)

func solve() {

	n := readInt()
	coords := make([][2]int64, n)
	c := make([]int64, n)
	k := make([]int64, n)
	for i := 0; i < n; i++ {
		coords[i][0], coords[i][1] = readInt64(), readInt64()
	}
	for i := 0; i < n; i++ {
		c[i] = readInt64()
	}
	for i := 0; i < n; i++ {
		k[i] = readInt64()
	}

	edges := make(edgeArray, n*n)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			cost := inf
			if i != j {
				cost = (k[i] + k[j]) * dist(coords, i, j)
			}
			edges[i*n+j] = edge{a: i, b: j, cost: cost}
		}
	}

	sort.Sort(edges)

	y := int64(0)

	stations = make([]int, n)
	for i := 0; i < n; i++ {
		stations[i] = i
		y += c[i]
	}

	v := n
	e := 0
	ans := make(edgeArray, 0)

	for i := 0; i < n*(n-1); i++ {
		edge := edges[i]
		pa := snm(edge.a)
		pb := snm(edge.b)
		pmax := pa
		if c[pa] < c[pb] {
			pmax = pb
		}
		if c[pmax] > edge.cost {
			stations[pmax] = snm(pa + pb - pmax)
			ans = append(ans, edge)
			y = y - c[pmax] + edge.cost
			e++
			v--
		}
	}

	printInt64(y)
	ln()

	printInt(v)
	ln()

	for i := 0; i < n; i++ {
		if i == snm(i) {
			printInt(i + 1)
		}
	}
	ln()

	printInt(e)
	ln()

	for i := 0; i < len(ans); i++ {
		printInt(ans[i].a + 1)
		printInt(ans[i].b + 1)
		ln()
	}

}

func snm(k int) int {
	if stations[k] == k {
		return k
	}
	ret := snm(stations[k])
	stations[k] = ret
	return ret
}

func dist(coords [][2]int64, i, j int) int64 {
	x1, y1, x2, y2 := coords[i][0], coords[i][1], coords[j][0], coords[j][1]
	dx := x1 - x2
	if dx < 0 {
		dx = -dx
	}
	dy := y1 - y2
	if dy < 0 {
		dy = -dy
	}
	return dx + dy
}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString(" ")
}

func ln() {
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

const N = 2020
var n int
var x[N] int
var y[N] int
var lab[N] int
var labx [N] int

var c[N] int
var k[N] int
var dt[N][] int

type Edge struct {
	u int
	v int
	dist int64
}

func uni(r1 int, r2 int)  {
	var x = lab[r1] + lab[r2]
	if lab[r1] < lab[r2] {
		lab[r1] = x
		lab[r2] = r1
	} else {
		lab[r2] = x
		lab[r1] = r2
	}
}

func unix(r1 int, r2 int)  {
	var x = labx[r1] + labx[r2]
	if labx[r1] < labx[r2] {
		labx[r1] = x
		labx[r2] = r1
	} else {
		labx[r2] = x
		labx[r1] = r2
	}
}

func getx(x int) int {
	if labx[x] < 0 {
		return x
	}
	labx[x] = getx(labx[x])
	return labx[x]
}

func getParent(x int) int {
	if lab[x] < 0 {
		return x
	}
	lab[x] = getParent(lab[x])
	return lab[x]
}

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

func getDist(i int, j int) int64 {
	var diff = int64(k[i] + k[j]) * int64(abs(x[i], x[j]) + abs(y[i], y[j]))
	return diff
}

func shouldConnect(i int, j int) bool {
	var diff = getDist(i, j)
	return int64(c[i]) > diff || int64(c[j]) > diff
}

func main() {
	var reader= bufio.NewReader(os.Stdin)
	var writer= bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &c[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &k[i])
	}

	for i := 1; i <= n; i++ {
		lab[i] = -1
	}

	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			if shouldConnect(i, j) {
				var r1 = getParent(i)
				var r2 = getParent(j)
				if r1 != r2 {
					uni(r1, r2)
				}
			}
		}
	}

	for i := 1; i <= n; i++ {
		dt[i] = make([]int, 0)
	}

	for i := 1; i <= n; i++ {
		var parent = getParent(i)
		dt[parent] = append(dt[parent], i)
	}

	var burn = make([]int, 0)
	var edge_from = make([]int, 0)
	var edge_to = make([]int, 0)

	var ret = int64(0)

	for i := 1; i <= n; i++ {
		var sz = len(dt[i])
		if sz > 0 {

			var f = dt[i][0]
			for _, u := range dt[i] {
				if c[u] < c[f] {
					f = u
				}
			}
			burn = append(burn, f)
			ret += int64(c[f])

			for j := 1; j <= n; j++ {
				labx[j] = -1
			}

			var krusk = make([]Edge, 0)

			for u := 0; u < sz - 1; u++ {
				var uu = dt[i][u]
				var pick = dt[i][u + 1]
				var mindiff = getDist(uu, pick)

				for v := u + 1; v < sz; v++ {
					var vv = dt[i][v]
					var dist = getDist(uu, vv)
					if dist < mindiff {
						mindiff = dist
						pick = vv
					}
				}
				krusk = append(krusk, Edge{uu, pick, mindiff})
			}

			sort.SliceStable(krusk, func(i, j int) bool {
				return krusk[i].dist < krusk[j].dist
			})

			for _, ed := range krusk {
				var r1 = getx(ed.u)
				var r2 = getx(ed.v)
				if r1 != r2 {
					ret += ed.dist
					unix(r1, r2)
					edge_from = append(edge_from, ed.u)
					edge_to = append(edge_to, ed.v)
				}
			}

		}
	}

	fmt.Fprintf(writer, "%d\n", ret)

	fmt.Fprintf(writer, "%d\n", len(burn))
	for _, u := range burn {
		fmt.Fprintf(writer, "%d ", u)
	}
	fmt.Fprintf(writer,"\n")

	fmt.Fprintf(writer, "%d\n", len(edge_from))
	for i := 0; i < len(edge_from); i++ {
		fmt.Fprintf(writer, "%d %d\n", edge_from[i], edge_to[i])
	}

}

package main

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

const N = 2020
const INF = int64(1e18)
var n int
var x[N] int
var y[N] int
var lab[N] int
var labx [N] int

var c[N] int
var k[N] int
var dt[N][] int

type Edge struct {
	u int
	v int
	dist int64
}

func uni(r1 int, r2 int)  {
	var x = lab[r1] + lab[r2]
	if lab[r1] < lab[r2] {
		lab[r1] = x
		lab[r2] = r1
	} else {
		lab[r2] = x
		lab[r1] = r2
	}
}

func unix(r1 int, r2 int)  {
	var x = labx[r1] + labx[r2]
	if labx[r1] < labx[r2] {
		labx[r1] = x
		labx[r2] = r1
	} else {
		labx[r2] = x
		labx[r1] = r2
	}
}

func getx(x int) int {
	if labx[x] < 0 {
		return x
	}
	labx[x] = getx(labx[x])
	return labx[x]
}

func getParent(x int) int {
	if lab[x] < 0 {
		return x
	}
	lab[x] = getParent(lab[x])
	return lab[x]
}

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

func getDist(i int, j int) int64 {
	var diff = int64(k[i] + k[j]) * int64(abs(x[i], x[j]) + abs(y[i], y[j]))
	return diff
}

func shouldConnect(i int, j int) bool {
	var diff = getDist(i, j)
	return int64(c[i]) > diff || int64(c[j]) > diff
}

func main() {
	var reader= bufio.NewReader(os.Stdin)
	var writer= bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &c[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &k[i])
	}

	for i := 1; i <= n; i++ {
		lab[i] = -1
	}

	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			if shouldConnect(i, j) {
				var r1 = getParent(i)
				var r2 = getParent(j)
				if r1 != r2 {
					uni(r1, r2)
				}
			}
		}
	}

	for i := 1; i <= n; i++ {
		dt[i] = make([]int, 0)
	}

	for i := 1; i <= n; i++ {
		var parent = getParent(i)
		dt[parent] = append(dt[parent], i)
	}

	var burn = make([]int, 0)
	var edge_from = make([]int, 0)
	var edge_to = make([]int, 0)

	var ret = int64(0)

	for i := 1; i <= n; i++ {
		var sz = len(dt[i])
		if sz > 0 {

			var f = dt[i][0]
			for _, u := range dt[i] {
				if c[u] < c[f] {
					f = u
				}
			}
			burn = append(burn, f)
			ret += int64(c[f])

			for j := 1; j <= n; j++ {
				labx[j] = -1
			}

			var krusk = make([]Edge, 0)

			for u := 0; u < sz; u++ {
				var uu = dt[i][u]
				var pick = -1
				var mindiff = INF

				for v := 0; v < sz; v++ {
					if u != v {
						var vv= dt[i][v]
						var dist= getDist(uu, vv)

						if dist < mindiff {
							mindiff = dist
							pick = vv
						}
					}
				}
				if mindiff != INF {
					krusk = append(krusk, Edge{uu, pick, mindiff})
				}
			}

			sort.SliceStable(krusk, func(i, j int) bool {
				return krusk[i].dist < krusk[j].dist
			})

			for _, ed := range krusk {
				var r1 = getx(ed.u)
				var r2 = getx(ed.v)
				if r1 != r2 {
					ret += ed.dist
					unix(r1, r2)
					edge_from = append(edge_from, ed.u)
					edge_to = append(edge_to, ed.v)
				}
			}

		}
	}

	fmt.Fprintf(writer, "%d\n", ret)

	fmt.Fprintf(writer, "%d\n", len(burn))
	for _, u := range burn {
		fmt.Fprintf(writer, "%d ", u)
	}
	fmt.Fprintf(writer,"\n")

	fmt.Fprintf(writer, "%d\n", len(edge_from))
	for i := 0; i < len(edge_from); i++ {
		fmt.Fprintf(writer, "%d %d\n", edge_from[i], edge_to[i])
	}

}

package main

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

const N = 2020
const INF = int64(1e18)
var n int
var x[N] int
var y[N] int
var lab[N] int
var labx [N] int

var c[N] int
var k[N] int
var dt[N][] int

type Edge struct {
	u int
	v int
	dist int64
}

func uni(r1 int, r2 int)  {
	var x = lab[r1] + lab[r2]
	if lab[r1] < lab[r2] {
		lab[r1] = x
		lab[r2] = r1
	} else {
		lab[r2] = x
		lab[r1] = r2
	}
}

func unix(r1 int, r2 int)  {
	var x = labx[r1] + labx[r2]
	if labx[r1] < labx[r2] {
		labx[r1] = x
		labx[r2] = r1
	} else {
		labx[r2] = x
		labx[r1] = r2
	}
}

func getx(x int) int {
	if labx[x] < 0 {
		return x
	}
	labx[x] = getx(labx[x])
	return labx[x]
}

func getParent(x int) int {
	if lab[x] < 0 {
		return x
	}
	lab[x] = getParent(lab[x])
	return lab[x]
}

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

func getDist(i int, j int) int64 {
	var diff = int64(k[i] + k[j]) * int64(abs(x[i], x[j]) + abs(y[i], y[j]))
	return diff
}

func shouldConnect(i int, j int) bool {
	var diff = getDist(i, j)
	return int64(c[i]) > diff || int64(c[j]) > diff
}

func main() {
	var reader= bufio.NewReader(os.Stdin)
	var writer= bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &c[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &k[i])
	}

	for i := 1; i <= n; i++ {
		lab[i] = -1
	}

	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			if shouldConnect(i, j) {
				var r1 = getParent(i)
				var r2 = getParent(j)
				if r1 != r2 {
					uni(r1, r2)
				}
			}
		}
	}

	for i := 1; i <= n; i++ {
		dt[i] = make([]int, 0)
	}

	for i := 1; i <= n; i++ {
		var parent = getParent(i)
		dt[parent] = append(dt[parent], i)
	}

	var burn = make([]int, 0)
	var edge_from = make([]int, 0)
	var edge_to = make([]int, 0)

	var ret = int64(0)

	for i := 1; i <= n; i++ {
		var sz = len(dt[i])
		if sz > 0 {

			var f = dt[i][0]
			for _, u := range dt[i] {
				if c[u] < c[f] {
					f = u
				}
			}
			burn = append(burn, f)
			ret += int64(c[f])

			for j := 1; j <= n; j++ {
				labx[j] = -1
			}

			var visited [N] bool

			var root = 0
			for j := 0; j < sz - 1; j++ {
				visited[root] = true
				var minDiff = INF
				var minNode = -1
				for z := 0; z < sz; z++ {
					if visited[z] == false {
						var canDiff = getDist(dt[i][z], dt[i][root])
						if canDiff < minDiff {
							minNode = z
							minDiff = canDiff
						}
					}
				}
				edge_to = append(edge_to, dt[i][root])
				edge_from = append(edge_from, dt[i][minNode])
				root = minNode
				ret += minDiff
			}
		}
	}

	fmt.Fprintf(writer, "%d\n", ret)

	fmt.Fprintf(writer, "%d\n", len(burn))
	for _, u := range burn {
		fmt.Fprintf(writer, "%d ", u)
	}
	fmt.Fprintf(writer,"\n")

	fmt.Fprintf(writer, "%d\n", len(edge_from))
	for i := 0; i < len(edge_from); i++ {
		fmt.Fprintf(writer, "%d %d\n", edge_from[i], edge_to[i])
	}

}

package main

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

const N = 2020
const INF = int64(1e18)
var n int
var x[N] int
var y[N] int
var lab[N] int
var labx [N] int

var c[N] int
var k[N] int
var dt[N][] int

type Edge struct {
	u int
	v int
	dist int64
}

func uni(r1 int, r2 int)  {
	var x = lab[r1] + lab[r2]
	if lab[r1] < lab[r2] {
		lab[r1] = x
		lab[r2] = r1
	} else {
		lab[r2] = x
		lab[r1] = r2
	}
}

func unix(r1 int, r2 int)  {
	var x = labx[r1] + labx[r2]
	if labx[r1] < labx[r2] {
		labx[r1] = x
		labx[r2] = r1
	} else {
		labx[r2] = x
		labx[r1] = r2
	}
}

func getx(x int) int {
	if labx[x] < 0 {
		return x
	}
	labx[x] = getx(labx[x])
	return labx[x]
}

func getParent(x int) int {
	if lab[x] < 0 {
		return x
	}
	lab[x] = getParent(lab[x])
	return lab[x]
}

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

func getDist(i int, j int) int64 {
	var diff = int64(k[i] + k[j]) * int64(abs(x[i], x[j]) + abs(y[i], y[j]))
	return diff
}

func shouldConnect(i int, j int) bool {
	var diff = getDist(i, j)
	return int64(c[i]) > diff || int64(c[j]) > diff
}

func main() {
	var reader= bufio.NewReader(os.Stdin)
	var writer= bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%d\n", &n)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &x[i], &y[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &c[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &k[i])
	}

	for i := 1; i <= n; i++ {
		lab[i] = -1
	}

	for i := 1; i < n; i++ {
		for j := i + 1; j <= n; j++ {
			if shouldConnect(i, j) {
				var r1 = getParent(i)
				var r2 = getParent(j)
				if r1 != r2 {
					uni(r1, r2)
				}
			}
		}
	}

	for i := 1; i <= n; i++ {
		dt[i] = make([]int, 0)
	}

	for i := 1; i <= n; i++ {
		var parent = getParent(i)
		dt[parent] = append(dt[parent], i)
	}

	var burn = make([]int, 0)
	var edge_from = make([]int, 0)
	var edge_to = make([]int, 0)

	var ret = int64(0)

	for i := 1; i <= n; i++ {
		var sz = len(dt[i])
		if sz > 0 {

			var f = dt[i][0]
			for _, u := range dt[i] {
				if c[u] < c[f] {
					f = u
				}
			}
			burn = append(burn, f)
			ret += int64(c[f])

			for j := 1; j <= n; j++ {
				labx[j] = -1
			}

			var visited [N] bool

			var root = 0
			for j := 0; j < sz - 1; j++ {
				visited[root] = true
				var minDiff = INF
				var minNode = -1
				for z := 0; z < sz; z++ {
					if visited[z] == false {
						var canDiff = getDist(dt[i][z], dt[i][root])
						if canDiff < minDiff {
							minNode = z
							minDiff = canDiff
						}
					}
				}
				edge_to = append(edge_to, root)
				edge_from = append(edge_from, minNode)
				root = minNode
				ret += minDiff
			}
		}
	}

	fmt.Fprintf(writer, "%d\n", ret)

	fmt.Fprintf(writer, "%d\n", len(burn))
	for _, u := range burn {
		fmt.Fprintf(writer, "%d ", u)
	}
	fmt.Fprintf(writer,"\n")

	fmt.Fprintf(writer, "%d\n", len(edge_from))
	for i := 0; i < len(edge_from); i++ {
		fmt.Fprintf(writer, "%d %d\n", edge_from[i], edge_to[i])
	}

}


Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 109.In the evening after the conference, all n scientists decided to go to the cinema. There are m movies in the cinema they came to. Each of the movies is characterized by two distinct numbers — the index of audio language and the index of subtitles language. The scientist, who came to the movie, will be very pleased if he knows the audio language of the movie, will be almost satisfied if he knows the language of subtitles and will be not satisfied if he does not know neither one nor the other (note that the audio language and the subtitles language for each movie are always different). Scientists decided to go together to the same movie. You have to help them choose the movie, such that the number of very pleased scientists is maximum possible. If there are several such movies, select among them one that will maximize the number of almost satisfied scientists.

The first line of the input contains a positive integer n (1 ≤ n ≤ 200 000) — the number of scientists. The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is the index of a language, which the i-th scientist knows. The third line contains a positive integer m (1 ≤ m ≤ 200 000) — the number of movies in the cinema.  The fourth line contains m positive integers b1, b2, ..., bm (1 ≤ bj ≤ 109), where bj is the index of the audio language of the j-th movie. The fifth line contains m positive integers c1, c2, ..., cm (1 ≤ cj ≤ 109), where cj is the index of subtitles language of the j-th movie. It is guaranteed that audio languages and subtitles language are different for each movie, that is bj ≠ cj.

Print the single integer — the index of a movie to which scientists should go. After viewing this movie the number of very pleased scientists should be maximum possible. If in the cinema there are several such movies, you need to choose among them one, after viewing which there will be the maximum possible number of almost satisfied scientists.  If there are several possible answers print any of them.

NoteIn the first sample, scientists must go to the movie with the index 2, as in such case the 1-th and the 3-rd scientists will be very pleased and the 2-nd scientist will be almost satisfied.In the second test case scientists can go either to the movie with the index 1 or the index 3. After viewing any of these movies exactly two scientists will be very pleased and all the others will be not satisfied.

package main

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

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A := make([]int, N)

	mapla := map[int]int{}
	for i := 0; i < N; i++ {
		A[i] = fsc.NextInt()
		mapla[A[i]]++
	}
	M := fsc.NextInt()

	B := make([]int, M) //audio
	C := make([]int, M) //subtitle

	for i := 0; i < M; i++ {
		B[i] = fsc.NextInt()
	}
	for i := 0; i < M; i++ {
		C[i] = fsc.NextInt()
	}
	vs := 0
	s := 0
	ans := 1
	for i := 0; i < M; i++ {
		if vs < mapla[B[i]] {
			vs = mapla[B[i]]
			s = mapla[C[i]]
			ans = i + 1
		} else if vs == mapla[B[i]] && s < mapla[C[i]] {
			vs = mapla[B[i]]
			s = mapla[C[i]]
			ans = i + 1
		}
	}
	fmt.Println(ans)
}

type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}

func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	get := wrapStdin()
	n := get.Int()
	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		a := get.Int()
		cnt[a]++
	}
	m := get.Int()
	b := get.Nint(m)
	var besta, bestb int
	ans := 1
	for i := 0; i < m; i++ {
		c := cnt[get.Int()]
		cur := cnt[b[i]]
		if besta > cur {
			continue
		}
		if besta < cur {
			besta = cur
			bestb = c
			ans = i + 1
			continue
		}
		if bestb >= c {
			continue
		}
		bestb = c
		ans = i + 1
	}
	fmt.Println(ans)
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}
func (in Input) Nint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = in.Int()
	}
	return v
}
func (in Input) Vint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = in.IntOk()
	}
	return ok
}

package main

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

func main() {
	n := getInt()
	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		a := getInt()
		cnt[a]++
	}
	m := getInt()
	b := getNint(m)
	var besta, bestb int
	ans := 0
	for i := 0; i < m; i++ {
		c := cnt[getInt()]
		cur := cnt[b[i]]

		if remax(&besta, cur) {
			bestb = c
			ans = i
		} else if besta == cur {
			if remax(&bestb, c) {
				ans = i
			}
		}
	}
	fmt.Println(ans + 1)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

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

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}

package main

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

func main() {
	n := getInt()
	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		a := getInt()
		cnt[a]++
	}
	m := getInt()
	b := getNint(m)
	var besta, bestb int
	ans := 1
	for i := 0; i < m; i++ {
		c := cnt[getInt()]
		cur := cnt[b[i]]
		if besta > cur {
			continue
		}
		if besta < cur {
			besta = cur
			bestb = c
			ans = i + 1
			continue
		}
		if bestb >= c {
			continue
		}
		bestb = c
		ans = i + 1
	}
	fmt.Println(ans)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}

package main

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

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	A := make([]int, N)

	mapla := map[int]int{}
	for i := 0; i < N; i++ {
		A[i] = fsc.NextInt()
		mapla[A[i]]++
	}
	M := fsc.NextInt()

	B := make([]int, M) //audio
	C := make([]int, M) //subtitle

	for i := 0; i < M; i++ {
		B[i] = fsc.NextInt()
	}
	for i := 0; i < M; i++ {
		C[i] = fsc.NextInt()
	}
	vs := 0
	s := 0
	ans := 0
	for i := 0; i < M; i++ {
		if vs < mapla[B[i]] {
			vs = mapla[B[i]]
			s = mapla[C[i]]
			ans = i + 1
		} else if vs == mapla[B[i]] && s < mapla[C[i]] {
			vs = mapla[B[i]]
			s = mapla[C[i]]
			ans = i + 1
		}
	}
	fmt.Println(ans)
}

type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}

func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	get := wrapStdin()
	n := get.Int()
	cnt := map[int]int{}
	for i := 0; i < n; i++ {
		a := get.Int()
		cnt[a]++
	}
	m := get.Int()
	b := get.Nint(m)
	var besta, bestb int
	ans := 1
	for i := 0; i < m; i++ {
		c := get.Int()
		cur := cnt[b[i]]
		if besta > cur {
			continue
		}
		if besta < cur {
			besta = cur
			bestb = c
			ans = i + 1
			continue
		}
		if bestb >= c {
			continue
		}
		bestb = c
		ans = i + 1
	}
	fmt.Println(ans)
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}
func (in Input) Nint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = in.Int()
	}
	return v
}
func (in Input) Vint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = in.IntOk()
	}
	return ok
}


Alice and Bob are playing a fun game of tree tag.The game is played on a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. Recall that a tree on $$$n$$$ vertices is an undirected, connected graph with $$$n-1$$$ edges.Initially, Alice is located at vertex $$$a$$$, and Bob at vertex $$$b$$$. They take turns alternately, and Alice makes the first move. In a move, Alice can jump to a vertex with distance at most $$$da$$$ from the current vertex. And in a move, Bob can jump to a vertex with distance at most $$$db$$$ from the current vertex. The distance between two vertices is defined as the number of edges on the unique simple path between them. In particular, either player is allowed to stay at the same vertex in a move. Note that when performing a move, a player only occupies the starting and ending vertices of their move, not the vertices between them.If after at most $$$10^{100}$$$ moves, Alice and Bob occupy the same vertex, then Alice is declared the winner. Otherwise, Bob wins.Determine the winner if both players play optimally.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The first line of each test case contains five integers $$$n,a,b,da,db$$$ ($$$2\le n\le 10^5$$$, $$$1\le a,b\le n$$$, $$$a\ne b$$$, $$$1\le da,db\le n-1$$$)  — the number of vertices, Alice's vertex, Bob's vertex, Alice's maximum jumping distance, and Bob's maximum jumping distance, respectively. The following $$$n-1$$$ lines describe the edges of the tree. The $$$i$$$-th of these lines contains two integers $$$u$$$, $$$v$$$ ($$$1\le u, v\le n, u\ne v$$$), denoting an edge between vertices $$$u$$$ and $$$v$$$. It is guaranteed that these edges form a tree structure. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$10^5$$$.

For each test case, output a single line containing the winner of the game: "Alice" or "Bob".

NoteIn the first test case, Alice can win by moving to vertex $$$1$$$. Then wherever Bob moves next, Alice will be able to move to the same vertex on the next move.  In the second test case, Bob has the following strategy to win. Wherever Alice moves, Bob will always move to whichever of the two vertices $$$1$$$ or $$$6$$$ is farthest from Alice.

package main

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

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

	var T, n, a, b, da, db, dab, v, w, u, maxD int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &a, &b, &da, &db)
		g := make([][]int, n+1)
		for i := 1; i < n; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		var f func(v, fa, d int)
		f = func(v, fa, d int) {
			if v == b {
				dab = d
			}
			if d > maxD {
				maxD, u = d, v
			}
			for _, w := range g[v] {
				if w != fa {
					f(w, v, d+1)
				}
			}
		}
		maxD = -1
		f(a, 0, 0)
		if 2*da >= db || da >= dab {
			Fprintln(out, "Alice")
			continue
		}
		maxD = -1
		f(u, 0, 0)
		if 2*da >= maxD {
			Fprintln(out, "Alice")
		} else {
			Fprintln(out, "Bob")
		}
	}
}

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

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func max2(a, b, c int64) (int64, int64) {
	tmp := []int64{a, b, c}
	sort.Slice(tmp, func(il, ir int) bool {
		return tmp[il] < tmp[ir]
	})
	return tmp[1], tmp[2]
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		a := sint64() - 1
		b := sint64() - 1
		da := sint64()
		db := sint64()
		nodes := make([][]int64, n)
		for i := int64(0); i < n-1; i++ {
			u := sint64() - 1
			v := sint64() - 1
			nodes[u] = append(nodes[u], v)
			nodes[v] = append(nodes[v], u)
		}
		printf("%s\n", sol(n, a, b, da, db, nodes))
	}
}

func sol(n, a, b, da, db int64, nodes [][]int64) string {
	// check if bob is able to jump necessarily further than alice
	if db < da*2+1 {
		return "Alice"
	}

	// check if alice finds bob in the first move
	var findBob func(int64, int64) (int64, bool)
	findBob = func(from, to int64) (int64, bool) {
		if to == b {
			return 0, true
		}
		for _, nxt := range nodes[to] {
			if nxt == from {
				continue
			}
			dist, found := findBob(to, nxt)
			if found {
				return dist + 1, true
			}
		}
		return 0, false
	}
	dist, found := findBob(-1, a)
	if !found {
		panic("no path found from alice to bob")
	}
	if dist <= da {
		return "Alice"
	}

	// check if max path is long enough for bob to jump around
	var maxPathSum func(int64, int64) (int64, int64)
	maxPathSum = func(from, to int64) (int64, int64) {
		straight1 := int64(0)
		straight2 := int64(0)
		curve := int64(0)
		for _, node := range nodes[to] {
			if node == from {
				continue
			}
			ncurve, nstraight := maxPathSum(to, node)
			straight1, straight2 = max2(straight1, straight2, nstraight)
			curve = max(curve, ncurve)
		}
		return max(curve, 1+straight1+straight2), 1+max(straight1, straight2)
	}
	maxPath, _ := maxPathSum(-1, 0)
	if maxPath < da*2+2 {
		return "Alice"
	}

	return "Bob"
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		a := sint64() - 1
		b := sint64() - 1
		da := sint64()
		db := sint64()
		nodes := make([][]int64, n)
		for i := int64(0); i < n-1; i++ {
			u := sint64() - 1
			v := sint64() - 1
			nodes[u] = append(nodes[u], v)
			nodes[v] = append(nodes[v], u)
		}
		printf("%s\n", sol(n, a, b, da, db, nodes))
	}
}

func sol(n, a, b, da, db int64, nodes [][]int64) string {
	// bob needs to be able to jump far enough
	if db < da*2+1 {
		return "Alice"
	}

	// if alice finds bob in the first move
	var findBob func(int64, int64) (int64, bool)
	findBob = func(from, to int64) (int64, bool) {
		if to == b {
			return 0, true
		}
		for _, nxt := range nodes[to] {
			if nxt == from {
				continue
			}
			dist, found := findBob(to, nxt)
			if found {
				return dist+1, true
			}
		}
		return 0, false
	}
	dist, found := findBob(-1, a)
	if !found {
		panic("no path found from alice to bob")
	}
	if dist <= da {
		return "Alice"
	}

	// check if max path is long enough for bob to jump around
	var maxPathSum func(int64, int64) int64
	maxPathSum = func(from, to int64) int64 {
		maxPath := int64(0)
		for _, node := range nodes[to] {
			if node == from {
				continue
			}
			maxPath = max(maxPath, maxPathSum(to, node))
		}
		return maxPath+1
	}
	maxPath := maxPathSum(-1, 0)
	if maxPath < da*2+2 {
		return "Alice"
	}

	return "Bob"
}


There is a game called "Unique Bid Auction". You can read more about it here: https://en.wikipedia.org/wiki/Unique_bid_auction (though you don't have to do it to solve this problem).Let's simplify this game a bit. Formally, there are $$$n$$$ participants, the $$$i$$$-th participant chose the number $$$a_i$$$. The winner of the game is such a participant that the number he chose is unique (i. e. nobody else chose this number except him) and is minimal (i. e. among all unique values of $$$a$$$ the minimum one is the winning one).Your task is to find the index of the participant who won the game (or -1 if there is no winner). Indexing is $$$1$$$-based, i. e. the participants are numbered from $$$1$$$ to $$$n$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of participants. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th participant chosen number. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer — the index of the participant who won the game (or -1 if there is no winner). Note that the answer is always unique.

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func solve() {
	var n int
	scanf("%d\n", &n)
	v := make([]int, n)
	d := make([]int, n)
	for i := 0; i < n; i++ {
		if i + 1 == n {
			scanf("%d\n", &v[i])
		} else {
			scanf("%d ", &v[i])
		}
		d[i] = v[i]
	}
	sort.Ints(v)
	ans := -1
	for i := 0; i < n; i++ {
		j := i
		for ; j < n && v[i] == v[j]; j++ {
		}
		if j - i == 1 {
			ans = v[i]
			break
		}
		i = j - 1
	}
	if ans == -1 {
		printf("-1\n")
		return
	}
	for i := 0; i < n; i++ {
		if d[i] == ans {
			printf("%d\n", i + 1)
			return
		}
	}
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		cnt := map[int]int{}
		for _, v := range a {
			cnt[v]++
		}
		ans := -1
		for i, v := range a {
			if cnt[v] == 1 && (ans ==-1 || v < a[ans]) {
				ans = i
			}
		}
		if ans>-1 {
			ans++
		}
		Fprintln(out, ans)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

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

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getInt64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}

func getInt() int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func getFloat() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}

func getString() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	for i := getInt(); i > 0; i-- {
		sol()
	}
}

func sol() {
	var arr []int
	n := getInt()
	a := make([]int, n)

	for i := 0; i < n; i++ {
		temp := getInt()
		arr = append(arr, temp)
		a[temp-1]++
	}
	ans := -1
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			ans = i + 1
			break
		}
	}

	if ans == -1 {
		writer.WriteString(fmt.Sprintf("%d\n", ans))
		return
	}

	for i := 0; i < n; i++ {
		if arr[i] == ans {
			writer.WriteString(fmt.Sprintf("%d\n", i+1))
			return
		}
	}
}

package main
import (
	"bufio"
	"fmt"
	"math"
	"os"
)
var rd = bufio.NewReader(os.Stdin)
func min(a, b int) int {
	if a <= b {
		return a
	} else {
		return b
	}
}
func main() {
	q := 0
	fmt.Fscan(rd, &q)
	for t := 0; t < q; t++ {
		n := 0
		fmt.Fscan(rd, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(rd, &a[i])
		}
		cnt := make(map[int]int)
		for _, v := range a {
			cnt[v]++
		}
		mn := math.MaxInt32
		for k, v := range cnt {
			if v == 1 {
				mn = min(mn, k)
			}
		}
		res := -1
		for i := range a {
			if a[i] == mn {
				res = i + 1
				break
			}
		}
		fmt.Println(res)
	}
}

package main

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

type pair struct {
	k, v int
}

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

	var t, n int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		a := make([]pair, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i].v)
			a[i].k = i + 1
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i].v < a[j].v
		})
		result := -1
		if n == 1 || a[1].v != a[0].v {
			result = a[0].k
		} else {
			for i := 1; i < n-1; i++ {
				if a[i].v != a[i+1].v && a[i].v != a[i-1].v {
					result = a[i].k
					break
				}
			}
			if result < 0 && a[n-1].v != a[n-2].v {
				result = a[n-1].k
			}
		}
		fmt.Println(result)
	}
}

package main

import(

	"fmt"
	."fmt"
	"bufio"
	"os"
)

func main(){
	var TESTS int
	in := bufio.NewReader(os.Stdin)

	Fscan(in,&TESTS)

	for ;TESTS>0;TESTS--{
		var n int
		Fscan(in,&n)
		a := make([]int,n)

		for i := range a{
			Fscan(in,&a[i])
		}

		m := make(map[int]int)

		for i := range a{
			m[a[i]]+=1
		}

		idx,val := -1,-1

		for i := range a{
			if m[a[i]]==1{
				if val==-1 || val>a[i]{
					idx,val = i+1,a[i]
				}
			}
		}

		fmt.Println(idx)
	}
}

package main

import(

	"fmt"
	."fmt"
	"bufio"
	"os"
)

func solve(n int){
	a := make([]int,n)
	in := bufio.NewReader(os.Stdin)

	for i := range a{
		Fscan(in,&a[i])
	}

	m := make(map[int]int)

	for i := range a{
		m[a[i]]+=1
	}

	idx,val := -1,-1

	for i := range a{
		if m[a[i]]==1{
			if val==-1 || val>a[i]{
				idx,val = i+1,a[i]
			}
		}
	}

	fmt.Println(idx)
	return

}

func main(){
	var TESTS int
	in := bufio.NewReader(os.Stdin)

	Fscan(in,&TESTS)

	for ;TESTS>0;TESTS--{
		var n int
		Fscan(in,&n)
		solve(n)
	}
}