Mahmoud and Ehab continue their adventures! As everybody in the evil land knows, Dr. Evil likes bipartite graphs, especially trees.A tree is a connected acyclic graph. A bipartite graph is a graph, whose vertices can be partitioned into 2 sets in such a way, that for each edge (u, v) that belongs to the graph, u and v belong to different sets. You can find more formal definitions of a tree and a bipartite graph in the notes section below.Dr. Evil gave Mahmoud and Ehab a tree consisting of n nodes and asked them to add edges to it in such a way, that the graph is still bipartite. Besides, after adding these edges the graph should be simple (doesn't contain loops or multiple edges). What is the maximum number of edges they can add?A loop is an edge, which connects a node with itself. Graph doesn't contain multiple edges when for each pair of nodes there is no more than one edge between them. A cycle and a loop aren't the same .

The first line of input contains an integer n — the number of nodes in the tree (1 ≤ n ≤ 105). The next n - 1 lines contain integers u and v (1 ≤ u, v ≤ n, u ≠ v) — the description of the edges of the tree. It's guaranteed that the given graph is a tree.

Output one integer — the maximum number of edges that Mahmoud and Ehab can add to the tree while fulfilling the conditions.

NoteTree definition: https://en.wikipedia.org/wiki/Tree_(graph_theory)Bipartite graph definition: https://en.wikipedia.org/wiki/Bipartite_graphIn the first test case the only edge that can be added in such a way, that graph won't contain loops or multiple edges is (2, 3), but adding this edge will make the graph non-bipartite so the answer is 0.In the second test case Mahmoud and Ehab can add edges (1, 4) and (2, 5).

package main

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

var g [][]int
var color []int

func solve() {
	n := readInt()
	g = make([][]int, n)
	color = make([]int, n)
	for i := 0; i < n; i++ {
		color[i] = -1
	}
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}
	dfs(0, 1)
	cnt1 := 0
	for i := 0; i < n; i++ {
		if color[i] != 1 {
			cnt1++
		}
	}
	res := int64(0)
	for i := 0; i < n; i++ {
		if color[i] == 1 {
			res += int64(cnt1 - len(g[i]))
		}
	}
	fmt.Println(res)
}

func dfs(v int, c int) {
	color[v] = c
	for i := 0; i < len(g[v]); i++ {
		next := g[v][i]
		if color[next] == -1 {
			dfs(next, ^c)
		}
	}
}

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

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// For each layer i , it can connect items in level (i + 1) + 2n,
// 	one should notice that for the layer i + 1, some nodes are
// 	already connected.
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	adjList := map[int][]int{}

	for i := 0; i < n; i++ {
		scanner.Scan()
		e1, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		e2, _ := strconv.Atoi(scanner.Text())
		if adjList[e1] == nil {
			adjList[e1] = []int{}
		}
		if adjList[e2] == nil {
			adjList[e2] = []int{}
		}
		adjList[e1] = append(adjList[e1], e2)
		adjList[e2] = append(adjList[e2], e1)
	}

	// BFS to build the layer map
	v, q := map[int]bool{1: true}, []int{1}
	layerCount, layerMap, maxLayer := map[int]int{}, map[int]int{1: 0}, 0
	for len(q) > 0 {
		task := q[0]
		q = q[1:]
		layerCount[layerMap[task]]++

		for _, item := range adjList[task] {
			if v[item] {
				continue
			}
			layerMap[item] = layerMap[task] + 1
			if layerMap[item] > maxLayer {
				maxLayer = layerMap[item]
			}
			v[item] = true
			q = append(q, item)
		}
	}

	// Use eMap, oMap so that the next step does not need nesting loop.
	eMap, oMap := map[int]int64{}, map[int]int64{}
	for i := 0; i <= maxLayer; i++ {
		if i%2 == 1 {
			oMap[i] = oMap[i-2]
			oMap[i] += int64(layerCount[i])
			oMap[i+1] = oMap[i]
		} else {
			eMap[i] = eMap[i-2]
			eMap[i] += int64(layerCount[i])
			eMap[i+1] = eMap[i]
			// fmt.Println(i, eMap[i], i+1, eMap[i+1])
		}
	}
	// fmt.Println(oMap, eMap)

	sum := int64(0)
	for i := 0; i < maxLayer; i++ {
		sum += int64(layerCount[i]-1) * int64(layerCount[i+1])
		if i%2 == 0 {
			sum += int64(layerCount[i]) * (oMap[maxLayer] - oMap[i+1])
		} else {
			sum += int64(layerCount[i]) * (eMap[maxLayer] - eMap[i+1])
		}
	}
	fmt.Println(sum)
}

// For each layer i , it can connect items in level (i + 1) + 2n,
// 	one should notice that for the layer i + 1, some nodes are
// 	already connected.
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	adjList := map[int][]int{}

	for i := 0; i < n; i++ {
		scanner.Scan()
		e1, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		e2, _ := strconv.Atoi(scanner.Text())
		if adjList[e1] == nil {
			adjList[e1] = []int{}
		}
		if adjList[e2] == nil {
			adjList[e2] = []int{}
		}
		adjList[e1] = append(adjList[e1], e2)
		adjList[e2] = append(adjList[e2], e1)
	}

	// BFS to build the layer map
	v, q := map[int]bool{1: true}, []int{1}
	layerCount, layerMap, maxLayer := map[int]int{}, map[int]int{1: 0}, 0
	for len(q) > 0 {
		task := q[0]
		q = q[1:]
		layerCount[layerMap[task]]++

		for _, item := range adjList[task] {
			if v[item] {
				continue
			}
			layerMap[item] = layerMap[task] + 1
			if layerMap[item] > maxLayer {
				maxLayer = layerMap[item]
			}
			v[item] = true
			q = append(q, item)
		}
	}

	eMap, oMap := map[int]int64{}, map[int]int64{}
	for i := 0; i <= maxLayer; i++ {
		oMap[i] = oMap[i-2]
		eMap[i] = eMap[i-2]
		if i%2 == 1 {
			oMap[i] += int64(layerCount[i])
			oMap[i-1] = oMap[i]
		} else {
			eMap[i] += int64(layerCount[i])
			eMap[i+1] = eMap[i]
		}
	}

	sum := int64(0)
	for i := 0; i < maxLayer; i++ {
		sum += int64(layerCount[i]-1) * int64(layerCount[i+1])
		if i%2 == 0 {
			sum += int64(layerCount[i]) * (oMap[maxLayer] - oMap[i+1])
		} else {
			sum += int64(layerCount[i]) * (eMap[maxLayer] - eMap[i+1])
		}
	}
	fmt.Println(sum)
}

// For each layer i , it can connect items in level (i + 1) + 2n,
// 	one should notice that for the layer i + 1, some nodes are
// 	already connected.
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	adjList := map[int][]int{}

	for i := 0; i < n; i++ {
		scanner.Scan()
		e1, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		e2, _ := strconv.Atoi(scanner.Text())
		if adjList[e1] == nil {
			adjList[e1] = []int{}
		}
		if adjList[e2] == nil {
			adjList[e2] = []int{}
		}
		adjList[e1] = append(adjList[e1], e2)
		adjList[e2] = append(adjList[e2], e1)
	}

	// BFS to build the layer map
	v, q := map[int]bool{1: true}, []int{1}
	layerCount, layerMap, maxLayer := map[int]int{}, map[int]int{1: 0}, 0
	for len(q) > 0 {
		task := q[0]
		q = q[1:]
		layerCount[layerMap[task]]++

		for _, item := range adjList[task] {
			if v[item] {
				continue
			}
			layerMap[item] = layerMap[task] + 1
			if layerMap[item] > maxLayer {
				maxLayer = layerMap[item]
			}
			v[item] = true
			q = append(q, item)
		}
	}

	// Use eMap, oMap so that the next step does not need nesting loop.
	eMap, oMap := map[int]int64{}, map[int]int64{}
	for i := 0; i <= maxLayer; i++ {
		if i%2 == 1 {
			oMap[i] = oMap[i-2]
			oMap[i] += int64(layerCount[i])
			oMap[i-1] = oMap[i]
		} else {
			eMap[i] = eMap[i-2]
			eMap[i] += int64(layerCount[i])
			eMap[i+1] = eMap[i]
			// fmt.Println(i, eMap[i], i+1, eMap[i+1])
		}
	}
	// fmt.Println(oMap, eMap)

	sum := int64(0)
	for i := 0; i < maxLayer; i++ {
		sum += int64(layerCount[i]-1) * int64(layerCount[i+1])
		if i%2 == 0 {
			sum += int64(layerCount[i]) * (oMap[maxLayer] - oMap[i+1])
		} else {
			sum += int64(layerCount[i]) * (eMap[maxLayer] - eMap[i+1])
		}
	}
	fmt.Println(sum)
}


Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle only — a funny ring — and does not belong to any other cycles. A funny ring is a cycle that goes through all the vertices just once. Moreover, loops are funny rings too.She has already drawn the apples and some of the graph edges. But now it is not clear, how to connect the rest of the vertices to get an interesting graph as a result. The answer should contain the minimal amount of added edges. And furthermore, the answer should be the lexicographically smallest one. The set of edges (x1, y1), (x2, y2), ..., (xn, yn), where xi ≤ yi, is lexicographically smaller than the set (u1, v1), (u2, v2), ..., (un, vn), where ui ≤ vi, provided that the sequence of integers x1, y1, x2, y2, ..., xn, yn is lexicographically smaller than the sequence u1, v1, u2, v2, ..., un, vn. If you do not cope, Hexadecimal will eat you. ...eat you alive.

The first line of the input data contains a pair of integers n and m (1 ≤ n ≤ 50, 0 ≤ m ≤ 2500) — the amount of vertices and edges respectively. The following lines contain pairs of numbers xi and yi (1 ≤ xi, yi ≤ n) — the vertices that are already connected by edges. The initial graph may contain multiple edges and loops.

In the first line output «YES» or «NO»: if it is possible or not to construct an interesting graph. If the answer is «YES», in the second line output k — the amount of edges that should be added to the initial graph. Finally, output k lines: pairs of vertices xj and yj, between which edges should be drawn. The result may contain multiple edges and loops. k can be equal to zero.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

var union []int

func initUnion(n int) {
	union = make([]int, n)
	for i := 0; i < n; i++ {
		union[i] = i
	}
}

func queryUnion(x int) int {
	for {
		if union[x] == x {
			return x
		} else {
			u := queryUnion(union[x])
			union[x] = u
			return u
		}
	}
}

func combineUnion(x int, y int) {
	ux := queryUnion(x)
	uy := queryUnion(y)
	if ux != uy {
		union[uy] = ux
	}
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	if n == 1 {
		if m == 0 {
			fmt.Printf("YES\n1\n1 1")
			return
		} else if m == 1 {
			fmt.Printf("YES\n0")
			return
		} else {
			fmt.Printf("NO")
			return
		}
	}
	initUnion(n)

	edge := make([][]int, n)

	for i := 0; i < n; i++ {
		edge[i] = make([]int, 0, 2)
	}
	for i := 0; i < m; i++ {
		var vx, vy int
		fmt.Fscanf(reader, "%d %d\n", &vx, &vy)
		vx--
		vy--
		if vx == vy {
			fmt.Printf("NO")
			return
		}
		edge[vx] = append(edge[vx], vy)
		edge[vy] = append(edge[vy], vx)
		if len(edge[vx]) > 2 {
			fmt.Printf("NO")
			return
		}
		if len(edge[vy]) > 2 {
			fmt.Printf("NO")
			return
		}
		combineUnion(vx, vy)
	}
	ansvx := make([]int, 0, 50)
	ansvy := make([]int, 0, 50)
	for i := 0; i < n; i++ {
		for j := 0; j < n && len(edge[i]) < 2; j++ {
			if i == j {
				continue
			}
			if len(edge[j]) < 2 && ((m < n-1 && queryUnion(i) != queryUnion(j)) || m == n-1) {
				if i < j {
					ansvx = append(ansvx, i)
					ansvy = append(ansvy, j)
				} else {
					ansvx = append(ansvx, j)
					ansvy = append(ansvy, i)
				}
				combineUnion(i, j)
				edge[i] = append(edge[i], j)
				edge[j] = append(edge[j], i)
				m++
			}
		}
	}

	if m != n {
		fmt.Printf("NO")
		return
	}

	for i := 1; i < n; i++ {
		if queryUnion(0) != queryUnion(i) {
			fmt.Printf("NO")
			return
		}
	}

	fmt.Printf("YES\n%d\n", len(ansvx))
	for i := 0; i < len(ansvx); i++ {
		fmt.Printf("%d %d\n", ansvx[i]+1, ansvy[i]+1)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, m := readTwoNums(reader)
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	cnt, res := solve(n, m, E)

	if cnt < 0 {
		fmt.Println("NO")
		return
	}
	var buf bytes.Buffer
	buf.WriteString("YES\n")
	buf.WriteString(fmt.Sprintf("%d\n", cnt))
	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d %d\n", res[i][0], res[i][1]))
	}
	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') {
			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
}

func solve(n, m int, E [][]int) (int, [][]int) {
	if m > n {
		return -1, nil
	}

	if n == 1 {
		if m == 0 {
			return 1, [][]int{{1, 1}}
		}
		return 0, nil
	}

	degree := make([]int, n)

	uf := NewUFSet(n)

	for i := 0; i < m; i++ {
		u, v := E[i][0], E[i][1]
		u--
		v--
		degree[u]++
		if degree[u] > 2 {
			return -1, nil
		}

		degree[v]++
		if degree[v] > 2 {
			return -1, nil
		}
		uf.Union(u, v)
	}
	var sameComp = true
	var tot int
	compDegree := make([]int, n)
	for i := 0; i < n && sameComp; i++ {
		sameComp = uf.Find(i) == uf.Find(0)
		tot += degree[i]
		compDegree[uf.Find(i)] += degree[i]
	}

	if sameComp && tot == 2*n {
		return 0, nil
	}

	for i := 0; i < n; i++ {
		p := uf.Find(i)
		if uf.cnt[p]*2 == compDegree[p] {
			return -1, nil
		}
	}

	res := make([][]int, 0, n-m)

	for i := 0; i < n && uf.size > 1; {
		if degree[i] == 2 {
			i++
			continue
		}
		for j := i + 1; j < n; j++ {
			if degree[j] == 2 || uf.Find(i) == uf.Find(j) {
				continue
			}
			degree[i]++
			degree[j]++

			uf.Union(i, j)

			res = append(res, []int{i + 1, j + 1})
			break
		}
	}

	var first, second = -1, -1
	for i := 0; i < n; i++ {
		if degree[i] == 1 {
			if first < 0 {
				first = i
			}
			second = i
		}
	}
	res = append(res, []int{first + 1, second + 1})

	return len(res), res
}

type Pair struct {
	first, second int
}

type Pairs []Pair

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

func (ps Pairs) Less(i, j int) bool {
	return ps[i].first < ps[j].first || ps[i].first == ps[j].first && ps[i].second < ps[j].second
}

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

type UFSet struct {
	arr  []int
	cnt  []int
	size int
}

func NewUFSet(n int) UFSet {
	arr := make([]int, n)
	cnt := make([]int, n)

	for i := 0; i < n; i++ {
		arr[i] = i
		cnt[i] = 1
	}

	return UFSet{arr, cnt, n}
}

func (uf *UFSet) Find(x int) int {
	if uf.arr[x] != x {
		uf.arr[x] = uf.Find(uf.arr[x])
	}
	return uf.arr[x]
}

func (uf *UFSet) Union(a, b int) bool {
	pa := uf.Find(a)
	pb := uf.Find(b)
	if pa == pb {
		return false
	}

	if uf.cnt[pa] < uf.cnt[pb] {
		pa, pb = pb, pa
	}
	uf.cnt[pa] += uf.cnt[pb]
	uf.arr[pb] = pa
	uf.size--
	return true
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

var union []int

func initUnion(n int) {
	union = make([]int, n)
	for i := 0; i < n; i++ {
		union[i] = i
	}
}

func queryUnion(x int) int {
	for {
		if union[x] == x {
			return x
		} else {
			u := queryUnion(union[x])
			union[x] = u
			return u
		}
	}
}

func combineUnion(x int, y int) {
	ux := queryUnion(x)
	uy := queryUnion(y)
	if ux != uy {
		union[uy] = ux
	}
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	initUnion(n)

	edge := make([][]int, n)

	for i := 0; i < n; i++ {
		edge[i] = make([]int, 0, 2)
	}
	for i := 0; i < m; i++ {
		var vx, vy int
		fmt.Fscanf(reader, "%d %d\n", &vx, &vy)
		vx--
		vy--
		edge[vx] = append(edge[vx], vy)
		edge[vy] = append(edge[vy], vx)
		if len(edge[vx]) > 2 {
			fmt.Printf("NO")
			return
		}
		if len(edge[vy]) > 2 {
			fmt.Printf("NO")
			return
		}
		combineUnion(vx, vy)
	}
	ansvx := make([]int, 0, 50)
	ansvy := make([]int, 0, 50)
	for i := 0; i < n; i++ {
		for j := 0; j < n && len(edge[i]) < 2; j++ {
			if i == j {
				continue
			}
			if len(edge[j]) < 2 && ((m < n-1 && queryUnion(i) != queryUnion(j)) || m == n-1) {
				if i < j {
					ansvx = append(ansvx, i)
					ansvy = append(ansvy, j)
				} else {
					ansvx = append(ansvx, j)
					ansvy = append(ansvy, i)
				}
				combineUnion(i, j)
				edge[i] = append(edge[i], j)
				edge[j] = append(edge[j], i)
				m++
			}
		}
	}

	if m != n {
		fmt.Printf("NO")
		return
	}

	for i := 1; i < n; i++ {
		if queryUnion(0) != queryUnion(i) {
			fmt.Printf("NO")
			return
		}
	}

	fmt.Printf("YES\n%d\n", len(ansvx))
	for i := 0; i < len(ansvx); i++ {
		fmt.Printf("%d %d\n", ansvx[i]+1, ansvy[i]+1)
	}

}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

var union []int

func initUnion(n int) {
	union = make([]int, n)
	for i := 0; i < n; i++ {
		union[i] = i
	}
}

func queryUnion(x int) int {
	for {
		if union[x] == x {
			return x
		} else {
			u := queryUnion(union[x])
			union[x] = u
			return u
		}
	}
}

func combineUnion(x int, y int) {
	ux := queryUnion(x)
	uy := queryUnion(y)
	if ux != uy {
		union[uy] = ux
	}
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	if n == 1 {
		if m == 0 {
			fmt.Printf("YES\n1\n1 1")
			return
		} else if m == 1 {
			fmt.Printf("YES\n0")
		} else {
			fmt.Printf("NO")
		}
	}
	initUnion(n)

	edge := make([][]int, n)

	for i := 0; i < n; i++ {
		edge[i] = make([]int, 0, 2)
	}
	for i := 0; i < m; i++ {
		var vx, vy int
		fmt.Fscanf(reader, "%d %d\n", &vx, &vy)
		vx--
		vy--
		if vx == vy {
			fmt.Printf("NO")
			return
		}
		edge[vx] = append(edge[vx], vy)
		edge[vy] = append(edge[vy], vx)
		if len(edge[vx]) > 2 {
			fmt.Printf("NO")
			return
		}
		if len(edge[vy]) > 2 {
			fmt.Printf("NO")
			return
		}
		combineUnion(vx, vy)
	}
	ansvx := make([]int, 0, 50)
	ansvy := make([]int, 0, 50)
	for i := 0; i < n; i++ {
		for j := 0; j < n && len(edge[i]) < 2; j++ {
			if i == j {
				continue
			}
			if len(edge[j]) < 2 && ((m < n-1 && queryUnion(i) != queryUnion(j)) || m == n-1) {
				if i < j {
					ansvx = append(ansvx, i)
					ansvy = append(ansvy, j)
				} else {
					ansvx = append(ansvx, j)
					ansvy = append(ansvy, i)
				}
				combineUnion(i, j)
				edge[i] = append(edge[i], j)
				edge[j] = append(edge[j], i)
				m++
			}
		}
	}

	if m != n {
		fmt.Printf("NO")
		return
	}

	for i := 1; i < n; i++ {
		if queryUnion(0) != queryUnion(i) {
			fmt.Printf("NO")
			return
		}
	}

	fmt.Printf("YES\n%d\n", len(ansvx))
	for i := 0; i < len(ansvx); i++ {
		fmt.Printf("%d %d\n", ansvx[i]+1, ansvy[i]+1)
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, m := readTwoNums(reader)
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	cnt, res := solve(n, m, E)

	if cnt < 0 {
		fmt.Println("NO")
		return
	}
	var buf bytes.Buffer
	buf.WriteString("YES\n")
	buf.WriteString(fmt.Sprintf("%d\n", cnt))
	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d %d\n", res[i][0], res[i][1]))
	}
	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') {
			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
}

func solve(n, m int, E [][]int) (int, [][]int) {
	degree := make([]int, n)

	uf := NewUFSet(n)

	for i := 0; i < m; i++ {
		u, v := E[i][0], E[i][1]
		u--
		v--
		degree[u]++
		degree[v]++
		uf.Union(u, v)
	}

	G := make(map[int][]int)

	for i := 0; i < n; i++ {
		p := uf.Find(i)
		if _, found := G[p]; !found {
			G[p] = make([]int, 0, n)
		}
		G[p] = append(G[p], i)
	}
	cand := make([]int, 0, len(G))
	for p, v := range G {
		var first, second = -1, -1
		var allTwo = true
		for _, i := range v {
			if degree[i] > 2 {
				return -1, nil
			}
			if degree[i] == 1 {
				allTwo = false
				if first < 0 {
					first = i
				} else if second < 0 {
					second = i
				}
			}

		}
		if allTwo {
			continue
		}

		if len(v) == 1 {
			cand = append(cand, p)
			cand = append(cand, p)
		} else {
			cand = append(cand, first)
			cand = append(cand, second)
		}

	}

	sort.Ints(cand)

	res := make([][]int, 0, len(G))

	for i := 0; i < len(cand); i += 2 {
		res = append(res, []int{cand[i] + 1, cand[i+1] + 1})
	}

	return len(res), res
}

type UFSet struct {
	arr []int
	cnt []int
}

func NewUFSet(n int) UFSet {
	arr := make([]int, n)
	cnt := make([]int, n)

	for i := 0; i < n; i++ {
		arr[i] = i
		cnt[i] = 1
	}

	return UFSet{arr, cnt}
}

func (uf *UFSet) Find(x int) int {
	if uf.arr[x] != x {
		uf.arr[x] = uf.Find(uf.arr[x])
	}
	return uf.arr[x]
}

func (uf *UFSet) Union(a, b int) bool {
	pa := uf.Find(a)
	pb := uf.Find(b)
	if pa == pb {
		return false
	}

	if uf.cnt[pa] < uf.cnt[pb] {
		pa, pb = pb, pa
	}
	uf.cnt[pa] += uf.cnt[pb]
	uf.arr[pb] = pa
	return true
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, m := readTwoNums(reader)
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	cnt, res := solve(n, m, E)

	if cnt < 0 {
		fmt.Println("NO")
		return
	}
	var buf bytes.Buffer
	buf.WriteString("YES\n")
	buf.WriteString(fmt.Sprintf("%d\n", cnt))
	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d %d\n", res[i][0], res[i][1]))
	}
	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') {
			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
}

func solve(n, m int, E [][]int) (int, [][]int) {
	degree := make([]int, n)

	uf := NewUFSet(n)

	for i := 0; i < m; i++ {
		u, v := E[i][0], E[i][1]
		u--
		v--
		degree[u]++
		degree[v]++
		uf.Union(u, v)
	}

	G := make(map[int][]int)

	for i := 0; i < n; i++ {
		p := uf.Find(i)
		if _, found := G[p]; !found {
			G[p] = make([]int, 0, n)
		}
		G[p] = append(G[p], i)
	}
	cand := make([]int, 0, len(G))
	for _, v := range G {
		var first, second = -1, -1
		var allTwo = true
		for _, i := range v {
			if degree[i] > 2 {
				return -1, nil
			}
			if degree[i] == 1 {
				allTwo = false
				if first < 0 {
					first = i
				}
				if second < 0 {
					second = i
				}
			}

		}
		if allTwo {
			continue
		}

		cand = append(cand, first)
		cand = append(cand, second)
	}

	sort.Ints(cand)

	res := make([][]int, 0, len(G))

	for i := 0; i < len(cand); i += 2 {
		res = append(res, []int{cand[i] + 1, cand[i+1] + 1})
	}

	return len(res), res
}

type UFSet struct {
	arr []int
	cnt []int
}

func NewUFSet(n int) UFSet {
	arr := make([]int, n)
	cnt := make([]int, n)

	for i := 0; i < n; i++ {
		arr[i] = i
		cnt[i] = 1
	}

	return UFSet{arr, cnt}
}

func (uf *UFSet) Find(x int) int {
	if uf.arr[x] != x {
		uf.arr[x] = uf.Find(uf.arr[x])
	}
	return uf.arr[x]
}

func (uf *UFSet) Union(a, b int) bool {
	pa := uf.Find(a)
	pb := uf.Find(b)
	if pa == pb {
		return false
	}

	if uf.cnt[pa] < uf.cnt[pb] {
		pa, pb = pb, pa
	}
	uf.cnt[pa] += uf.cnt[pb]
	uf.arr[pb] = pa
	return true
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, m := readTwoNums(reader)
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	cnt, res := solve(n, m, E)

	if cnt < 0 {
		fmt.Println("NO")
		return
	}
	var buf bytes.Buffer
	buf.WriteString("YES\n")
	buf.WriteString(fmt.Sprintf("%d\n", cnt))
	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d %d\n", res[i][0], res[i][1]))
	}
	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') {
			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
}

func solve(n, m int, E [][]int) (int, [][]int) {
	degree := make([]int, n)

	uf := NewUFSet(n)

	for i := 0; i < m; i++ {
		u, v := E[i][0], E[i][1]
		u--
		v--
		degree[u]++
		degree[v]++
		uf.Union(u, v)
	}

	G := make(map[int][]int)

	for i := 0; i < n; i++ {
		p := uf.Find(i)
		if _, found := G[p]; !found {
			G[p] = make([]int, 0, n)
		}
		G[p] = append(G[p], i)
	}
	cand := make([]int, 0, len(G))
	for p, v := range G {
		// all equals to 1, or all equals 2, or only one node
		if len(v) == 1 {
			// p need to be connected twice
			cand = append(cand, p)
			cand = append(cand, p)
			continue
		}
		var first, second = -1, -1
		var allTwo = true
		for _, i := range v {
			if degree[i] > 2 {
				return -1, nil
			}
			if degree[i] == 1 {
				allTwo = false
				if first < 0 {
					first = i
				} else if second < 0 {
					second = i
				}
			}

		}
		if allTwo {
			continue
		}

		cand = append(cand, first)
		cand = append(cand, second)
	}

	sort.Ints(cand)

	res := make([][]int, 0, len(G))

	for i := 0; i < len(cand); i += 2 {
		res = append(res, []int{cand[i] + 1, cand[i+1] + 1})
	}

	return len(res), res
}

type UFSet struct {
	arr []int
	cnt []int
}

func NewUFSet(n int) UFSet {
	arr := make([]int, n)
	cnt := make([]int, n)

	for i := 0; i < n; i++ {
		arr[i] = i
		cnt[i] = 1
	}

	return UFSet{arr, cnt}
}

func (uf *UFSet) Find(x int) int {
	if uf.arr[x] != x {
		uf.arr[x] = uf.Find(uf.arr[x])
	}
	return uf.arr[x]
}

func (uf *UFSet) Union(a, b int) bool {
	pa := uf.Find(a)
	pb := uf.Find(b)
	if pa == pb {
		return false
	}

	if uf.cnt[pa] < uf.cnt[pb] {
		pa, pb = pb, pa
	}
	uf.cnt[pa] += uf.cnt[pb]
	uf.arr[pb] = pa
	return true
}


Lunar New Year is approaching, and Bob decides to take a wander in a nearby park.The park can be represented as a connected graph with $$$n$$$ nodes and $$$m$$$ bidirectional edges. Initially Bob is at the node $$$1$$$ and he records $$$1$$$ on his notebook. He can wander from one node to another through those bidirectional edges. Whenever he visits a node not recorded on his notebook, he records it. After he visits all nodes at least once, he stops wandering, thus finally a permutation of nodes $$$a_1, a_2, \ldots, a_n$$$ is recorded.Wandering is a boring thing, but solving problems is fascinating. Bob wants to know the lexicographically smallest sequence of nodes he can record while wandering. Bob thinks this problem is trivial, and he wants you to solve it.A sequence $$$x$$$ is lexicographically smaller than a sequence $$$y$$$ if and only if one of the following holds:   $$$x$$$ is a prefix of $$$y$$$, but $$$x \ne y$$$ (this is impossible in this problem as all considered sequences have the same length);  in the first position where $$$x$$$ and $$$y$$$ differ, the sequence $$$x$$$ has a smaller element than the corresponding element in $$$y$$$.

The first line contains two positive integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$), denoting the number of nodes and edges, respectively. The following $$$m$$$ lines describe the bidirectional edges in the graph. The $$$i$$$-th of these lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$), representing the nodes the $$$i$$$-th edge connects. Note that the graph can have multiple edges connecting the same two nodes and self-loops. It is guaranteed that the graph is connected.

Output a line containing the lexicographically smallest sequence $$$a_1, a_2, \ldots, a_n$$$ Bob can record.

NoteIn the first sample, Bob's optimal wandering path could be $$$1 \rightarrow 2 \rightarrow 1 \rightarrow 3$$$. Therefore, Bob will obtain the sequence $$$\{1, 2, 3\}$$$, which is the lexicographically smallest one.In the second sample, Bob's optimal wandering path could be $$$1 \rightarrow 4 \rightarrow 3 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 5$$$. Therefore, Bob will obtain the sequence $$$\{1, 4, 3, 2, 5\}$$$, which is the lexicographically smallest one.

package main

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

var (
	mapp  [][]int
	visit []bool
	mheap []int
	hp    int
)

func addEdge(u, v int) {
	if len(mapp[u]) == 0 {
		mapp[u] = make([]int, 0)
	}
	mapp[u] = append(mapp[u], v)
}
func addD(u int) {
	hp++
	mheap[hp] = u
	p := hp
	fp := p / 2
	for fp > 0 {
		if mheap[fp] > mheap[p] {
			tmp := mheap[fp]
			mheap[fp] = mheap[p]
			mheap[p] = tmp
		} else {
			break
		}
		p = fp
		fp = p / 2
	}
	//fmt.Printf("%d head %d: %v\n",u,hp,mheap)
}
func popD() int {
	if hp <=0{
		return 0
	}
	res := mheap[1]
	mheap[1] = mheap[hp]
	hp--
	root := 1
	for root < hp {
		lc := root * 2
		rc := lc + 1
		if (lc > hp || mheap[root] <= mheap[lc]) && (rc > hp || mheap[root] <= mheap[rc]) {
			break
		}else if lc <= hp && mheap[root] >= mheap[lc] && (rc > hp || mheap[lc] <= mheap[rc]) {
			tmp := mheap[root]
			mheap[root] = mheap[lc]
			mheap[lc] = tmp
			root = lc
		} else if rc <= hp && mheap[root] >= mheap[rc] && (lc > hp || mheap[lc] >= mheap[rc]) {
			tmp := mheap[root]
			mheap[root] = mheap[rc]
			mheap[rc] = tmp
			root = rc
		}else{
			break
		}
	}
//	fmt.Printf("pop %d head pop %d: %v\n",res,hp,mheap)
	return res
}
func solveD() {

	for {
		root := popD()
		if root <= 0 {
			break
		}
		fmt.Printf("%d ", root)
		for _, v := range mapp[root] {
			if visit[v] == false {
				addD(v)
				visit[v] = true
			}
		}

	}
	fmt.Printf("\n")
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	mapp = make([][]int, n+1)
	mheap = make([]int,n+2)
	visit= make([]bool,n+1)
	hp = 0
	addD(1)
	visit[1] = true
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Fscanf(buf, "%d %d\n", &x, &y)
		addEdge(x, y)
		addEdge(y, x)
	}
	solveD()
}

package main

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

var (
	mapp  [][]int
	visit []bool
	mheap []int
	hp    int
)

func addEdge(u, v int) {
	if len(mapp[u]) == 0 {
		mapp[u] = make([]int, 0)
	}
	mapp[u] = append(mapp[u], v)
}
func addD(u int) {
	hp++
	mheap[hp] = u
	maxx := hp
	p := maxx
	fp := p / 2
	for fp > 0 {
		if mheap[fp] > mheap[p] {
			tmp := mheap[fp]
			mheap[fp] = mheap[p]
			mheap[p] = tmp
		} else {
			break
		}
		p = fp
		fp = p / 2
	}
	//fmt.Printf("%d head %d: %v\n",u,hp,mheap)
}
func popD() int {
	if hp <=0{
		return 0
	}
	res := mheap[1]
	mheap[1] = mheap[hp]
	hp--
	root := 1
	for root < hp {
		lc := root * 2
		rc := lc + 1
		if (lc > hp || mheap[root] <= mheap[lc]) && (rc > hp || mheap[root] <= mheap[rc]) {
			break
		}

		if lc <= hp && mheap[root] >= mheap[lc] && (rc > hp || mheap[lc] <= mheap[rc]) {
			tmp := mheap[root]
			mheap[root] = mheap[lc]
			mheap[lc] = tmp
			root = lc
		}else {
	//	if rc <= hp && mheap[root] >= mheap[rc] && (lc > hp || mheap[lc] >= mheap[rc]) {
			tmp := mheap[root]
			mheap[root] = mheap[rc]
			mheap[rc] = tmp
			root = rc
		}
	}
//	fmt.Printf("pop %d head pop %d: %v\n",res,hp,mheap)
	return res
}
func solveD() {

	for {
		root := popD()
		if root <= 0 {
			return
		}
		fmt.Printf("%d ", root)
		for _, v := range mapp[root] {
			if visit[v] == false {
				addD(v)
				visit[v] = true
			}
		}

	}
	fmt.Printf("\n")
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	mapp = make([][]int, n+1)
	mheap = make([]int,n+2)
	visit= make([]bool,n+1)
	hp = 0
	addD(1)
	visit[1] = true
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Fscanf(buf, "%d %d\n", &x, &y)
		addEdge(x, y)
		addEdge(y, x)
	}
	solveD()
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type minheap []int

func (h minheap) Len() int { return len(h) }

func (h minheap) Less(i, j int) bool { return h[i] < h[j] }

func (h minheap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }

func (h *minheap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *minheap) Pop() interface{} {
	n := len(*h)
	x := (*h)[n-1]
	*h = (*h)[0 : n-1]

	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n, m := in(), in()

	g := make([][]int, n)
	vis := make([]bool, n)

	var u, v int

	for i := 0; i < m; i++ {
		u = in()
		u--
		v = in()
		v--

		if g[u] == nil {
			g[u] = make([]int, 0)
		}

		g[u] = append(g[u], v)

		if g[v] == nil {
			g[v] = make([]int, 0)
		}

		g[v] = append(g[v], u)
	}

	cnt := 0
	h := new(minheap)
	heap.Push(h, 0)

	for cnt < n {
		x := heap.Pop(h).(int)
		fmt.Print(x+1, " ")

		vis[x] = true

		for i := range g[x] {
			if !vis[g[x][i]] {
				heap.Push(h, g[x][i])
				vis[g[x][i]] = true
			}
		}
		cnt++
	}

	fmt.Println()
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type intHeap []int

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

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(r, &n, &m)
	edges := make(map[int]map[int]struct{}, 2*m)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		if edges[a] == nil {
			edges[a] = make(map[int]struct{})
		}
		if edges[b] == nil {
			edges[b] = make(map[int]struct{})
		}
		edges[a][b] = struct{}{}
		edges[b][a] = struct{}{}
	}
	ans := make([]int, 0, n)
	visit := make(map[int]struct{}, n)
	inHeap := make(map[int]struct{}, n)
	var h intHeap
	heap.Push(&h, 1)
	for len(h) > 0 {
		to := heap.Pop(&h).(int)
		ans = append(ans, to)
		visit[to] = struct{}{}
		for dst := range edges[to] {
			if _, ok := visit[dst]; ok {
				continue
			}
			if _, ok := inHeap[dst]; ok {
				continue
			}
			inHeap[dst] = struct{}{}
			heap.Push(&h, dst)
		}
	}
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Printf("%d", ans[i])
	}
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

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...) }

// An IntHeap is a min-heap of ints.
type IntHeap []int

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

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	defer writer.Flush()
	var n, m, t, f int
	scanf("%d %d\n", &n, &m)
	ed := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		ed[i] = []int{}
	}
	for i := 0; i < m; i++ {
		scanf("%d %d\n", &f, &t)
		ed[f] = append(ed[f], t)
		ed[t] = append(ed[t], f)
	}

	vis := make(map[int]bool)

	hp := &IntHeap{}
	heap.Push(hp, 1)
	vis[1] = true

	for i := 0; i < n; i++ {
		t = heap.Pop(hp).(int)
		printf("%d ", t)

		for j := 0; j < len(ed[t]); j++ {
			if !vis[ed[t][j]] {
				heap.Push(hp, ed[t][j])
				vis[ed[t][j]] = true
			}
		}
	}
}

package main

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

var (
	mapp  [][]int
	visit []bool
	mheap []int
	hp    int
)

func addEdge(u, v int) {
	if len(mapp[u]) == 0 {
		mapp[u] = make([]int, 0)
	}
	mapp[u] = append(mapp[u], v)
}
func addD(u int) {
	hp++
	mheap[hp] = u
	maxx := hp
	p := maxx
	fp := p / 2
	for fp > 0 {
		if mheap[fp] > mheap[p] {
			tmp := mheap[fp]
			mheap[fp] = mheap[p]
			mheap[p] = tmp
		} else {
			break
		}
		p = fp
		fp = p / 2
	}
	//fmt.Printf("%d head %d: %v\n",u,hp,mheap)
}
func popD() int {
	if hp <=0{
		return 0
	}
	res := mheap[1]
	mheap[1] = mheap[hp]
	hp--
	root := 1
	for root < hp {
		lc := root * 2
		rc := lc + 1
		if (lc > hp || mheap[root] <= mheap[lc]) && (rc > hp || mheap[root] <= mheap[rc]) {
			break
		}

		if lc <= hp && mheap[root] >= mheap[lc] && (rc > hp || mheap[lc] <= mheap[rc]) {
			tmp := mheap[root]
			mheap[root] = mheap[lc]
			mheap[lc] = tmp
			root = lc
		}
		if rc <= hp && mheap[root] >= mheap[rc] && (lc > hp || mheap[lc] >= mheap[rc]) {
			tmp := mheap[root]
			mheap[root] = mheap[rc]
			mheap[rc] = tmp
			root = rc
		}
	}
//	fmt.Printf("pop %d head pop %d: %v\n",res,hp,mheap)
	return res
}
func solveD() {

	for {
		root := popD()
		if root <= 0 {
			return
		}
		fmt.Printf("%d ", root)
		for _, v := range mapp[root] {
			if visit[v] == false {
				addD(v)
				visit[v] = true
			}
		}

	}
	fmt.Printf("\n")
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	mapp = make([][]int, n+1)
	mheap = make([]int,n+2)
	visit= make([]bool,n+1)
	hp = 0
	addD(1)
	visit[1] = true
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Fscanf(buf, "%d %d\n", &x, &y)
		addEdge(x, y)
		addEdge(y, x)
	}
	solveD()
}

package main

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

var v []bool

func dfs(i int, g [][]int) {
	if v[i] == true {
		return
	}

	fmt.Print(i+1, " ")

	v[i] = true

	for j := range g[i] {
		dfs(g[i][j], g)
	}
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n, m := in(), in()

	g := make([][]int, n)
	v = make([]bool, n)

	var u, v int

	for i := 0; i < m; i++ {
		u = in()
		u--
		v = in()
		v--

		if g[u] == nil {
			g[u] = make([]int, 0)
		}

		g[u] = append(g[u], v)

		if g[v] == nil {
			g[v] = make([]int, 0)
		}

		g[v] = append(g[v], u)
	}

	for i := range g {
		sort.Slice(g[i], func(j, k int) bool {
			return g[i][j] < g[i][k]
		})
	}

	dfs(0, g)
	fmt.Println()
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

type minheap []int

func (h minheap) Len() int { return len(h) }

func (h minheap) Less(i, j int) bool { return h[i] < h[j] }

func (h minheap) Swap(i, j int) { h[i], h[j] = h[j], h[i] }

func (h *minheap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *minheap) Pop() interface{} {
	n := len(*h)
	x := (*h)[n-1]
	*h = (*h)[0 : n-1]

	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	n, m := in(), in()

	g := make([][]int, n)
	vis := make([]bool, n)

	var u, v int

	for i := 0; i < m; i++ {
		u = in()
		u--
		v = in()
		v--

		if g[u] == nil {
			g[u] = make([]int, 0)
		}

		g[u] = append(g[u], v)

		if g[v] == nil {
			g[v] = make([]int, 0)
		}

		g[v] = append(g[v], u)
	}

	cnt := 1
	vis[0] = true

	h := new(minheap)

	for i := range g[0] {
		heap.Push(h, g[0][i])
		vis[g[0][i]] = true
	}

	fmt.Print(1, " ")

	for cnt < n {
		x := heap.Pop(h).(int)
		fmt.Print(x+1, " ")

		for i := range g[x] {
			if !vis[g[x][i]] {
				heap.Push(h, g[x][i])
				vis[g[x][i]] = true
			}
		}
		cnt++
	}

	fmt.Println()
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type intHeap []int

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

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(r, &n, &m)
	edges := make(map[int]map[int]struct{}, 2*m)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		if edges[a] == nil {
			edges[a] = make(map[int]struct{})
		}
		if edges[b] == nil {
			edges[b] = make(map[int]struct{})
		}
		edges[a][b] = struct{}{}
		edges[b][a] = struct{}{}
	}
	ans := make([]int, 0, n)
	visit := make(map[int]struct{}, n)
	var h intHeap
	heap.Push(&h, 1)
	for len(h) > 0 {
		to := heap.Pop(&h).(int)
		ans = append(ans, to)
		visit[to] = struct{}{}
		for dst := range edges[to] {
			if _, ok := visit[dst]; ok {
				continue
			}
			heap.Push(&h, dst)
		}
	}
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Printf("%d", ans[i])
	}
}

// This example demonstrates an integer heap built using the heap interface.
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type intHeap []int

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

func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}

func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(r, &n, &m)
	edges := make(map[int][]int, 2*m)
	for i := 0; i < m; i++ {
		var a, b int
		fmt.Fscan(r, &a, &b)
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	ans := make([]int, 0, n)
	visit := make(map[int]struct{}, n)
	var h intHeap
	heap.Push(&h, 1)
	for len(h) > 0 {
		to := heap.Pop(&h).(int)
		ans = append(ans, to)
		visit[to] = struct{}{}
		for _, dst := range edges[to] {
			if _, ok := visit[dst]; ok {
				continue
			}
			heap.Push(&h, dst)
		}
	}
	for i := 0; i < n; i++ {
		if i != 0 {
			fmt.Print(" ")
		}
		fmt.Printf("%d", ans[i])
	}
}


Vasya has gotten interested in programming contests in TCMCF+++ rules. On the contest n problems were suggested and every problem had a cost — a certain integral number of points (perhaps, negative or even equal to zero). According to TCMCF+++ rules, only accepted problems can earn points and the overall number of points of a contestant was equal to the product of the costs of all the problems he/she had completed. If a person didn't solve anything, then he/she didn't even appear in final standings and wasn't considered as participant. Vasya understood that to get the maximal number of points it is not always useful to solve all the problems. Unfortunately, he understood it only after the contest was finished. Now he asks you to help him: find out what problems he had to solve to earn the maximal number of points.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of the suggested problems. The next line contains n space-separated integers ci ( - 100 ≤ ci ≤ 100) — the cost of the i-th task. The tasks' costs may coinсide.

Print space-separated the costs of the problems that needed to be solved to get the maximal possible number of points. Do not forget, please, that it was necessary to solve at least one problem. If there are several solutions to that problem, print any of them.

package main

import "fmt"

//go build -gcflags=all="-N -l"

func main() {
	var arr [101]int
	var n int
	fmt.Scan(&n)
	for i:=0; i<n; i++{fmt.Scan(&arr[i])}
	var res []int
	var cnt int // count the number of negative tasks
	var maxneg int = -101
	hasZero := false
	for i:=0; i<n; i++{
		if arr[i] > 0 {
			res = append(res,arr[i])
		} else if arr[i] < 0{
			cnt++
			if maxneg < arr[i] {maxneg = arr[i]}
			res = append(res, arr[i])
		} else {
			hasZero = true
		}
	}
	if len(res) == 0{
		fmt.Println(0)
	}else{
		if cnt&1 == 0{ // even number of negatives
			for i:=0; i < len(res); i++ {
				fmt.Printf("%d ", res[i])
			}
		}else{
			if len(res) == 1{
				if hasZero{
					fmt.Println(0)
				}else{
					fmt.Println(maxneg)
				}
			}else { //exclude one maxneg
				turn := true
				for i:=0; i < len(res); i++ {
					if turn && res[i] == maxneg{
						turn = false
						continue
					}
					fmt.Printf("%d ", res[i])
				}

			}
		}
	}
}

package main

import "fmt"

func main() {
	var arr [101]int
	var n int
	fmt.Scan(&n)
	for i:=0; i<n; i++{fmt.Scan(&arr[i])}
	var res []int
	var cnt int // count the number of negative tasks
	var maxneg int = -101
	hasZero := false
	for i:=0; i<n; i++{
		if arr[i] > 0 {
			res = append(res,arr[i])
		} else if arr[i] < 0{
			cnt++
			if maxneg < arr[i] {maxneg = arr[i]}
			res = append(res, arr[i])
		} else {
			hasZero = true
		}
	}
	if len(arr) == 0{
		fmt.Println(0)
	}else{
		if cnt&1 == 0{ // even number of negatives
			for i:=0; i < len(res); i++ {
				fmt.Printf("%d ", res[i])
			}
		}else{
			if len(arr) == 1{
				if hasZero{
					fmt.Println(0)
				}else{
					fmt.Println(maxneg)
				}
			}else { //exclude one maxneg
				turn := true
				for i:=0; i < len(res); i++ {
					if turn && res[i] == maxneg{
						turn = false
						continue
					}
					fmt.Printf("%d ", res[i])
				}

			}
		}
	}
}


You are given an array $$$A$$$, consisting of $$$n$$$ positive integers $$$a_1, a_2, \dots, a_n$$$, and an array $$$B$$$, consisting of $$$m$$$ positive integers $$$b_1, b_2, \dots, b_m$$$. Choose some element $$$a$$$ of $$$A$$$ and some element $$$b$$$ of $$$B$$$ such that $$$a+b$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. For example, if $$$A = [2, 1, 7]$$$ and $$$B = [1, 3, 4]$$$, we can choose $$$1$$$ from $$$A$$$ and $$$4$$$ from $$$B$$$, as number $$$5 = 1 + 4$$$ doesn't belong to $$$A$$$ and doesn't belong to $$$B$$$. However, we can't choose $$$2$$$ from $$$A$$$ and $$$1$$$ from $$$B$$$, as $$$3 = 2 + 1$$$ belongs to $$$B$$$.It can be shown that such a pair exists. If there are multiple answers, print any.Choose and print any such two numbers.

The first line contains one integer $$$n$$$ ($$$1\le n \le 100$$$) — the number of elements of $$$A$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 200$$$) — the elements of $$$A$$$. The third line contains one integer $$$m$$$ ($$$1\le m \le 100$$$) — the number of elements of $$$B$$$. The fourth line contains $$$m$$$ different integers $$$b_1, b_2, \dots, b_m$$$ ($$$1 \le b_i \le 200$$$) — the elements of $$$B$$$. It can be shown that the answer always exists.

Output two numbers $$$a$$$ and $$$b$$$ such that $$$a$$$ belongs to $$$A$$$, $$$b$$$ belongs to $$$B$$$, but $$$a+b$$$ doesn't belong to nor $$$A$$$ neither $$$B$$$. If there are multiple answers, print any.

NoteIn the first example, we can choose $$$20$$$ from array $$$[20]$$$ and $$$20$$$ from array $$$[10, 20]$$$. Number $$$40 = 20 + 20$$$ doesn't belong to any of those arrays. However, it is possible to choose $$$10$$$ from the second array too.In the second example, we can choose $$$3$$$ from array $$$[3, 2, 2]$$$ and $$$1$$$ from array $$$[1, 5, 7, 7, 9]$$$. Number $$$4 = 3 + 1$$$ doesn't belong to any of those arrays.In the third example, we can choose $$$1$$$ from array $$$[1, 3, 5, 7]$$$ and $$$1$$$ from array $$$[7, 5, 3, 1]$$$. Number $$$2 = 1 + 1$$$ doesn't belong to any of those arrays.

package main

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

/* solution */

func solve() {

	n := readInt()
	maxA := readInt()
	for i := 1; i < n; i++ {
		a := readInt()
		if a > maxA {
			maxA = a
		}
	}

	m := readInt()
	maxB := readInt()
	for i := 1; i < m; i++ {
		b := readInt()
		if b > maxB {
			maxB = b
		}
	}

	printInt(maxA)
	printInt(maxB)

}

/* 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)
	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

package main

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

func main() {
	var n, m, x int64

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	ma := make(map[int64]bool)

	for i := int64(0); i < n; i++ {
		fmt.Fscanf(scr, "%d", &x)
		ma[x] = true
	}
	fmt.Fscanf(scr, "%d", &x)

	fmt.Fscanln(scr, &m)
	mb := make(map[int64]bool)

	for i := int64(0); i < m; i++ {
		fmt.Fscanf(scr, "%d", &x)
		mb[x] = true
	}

oc:
	for y := range ma {
		for x := range mb {
			if !ma[x+y] && !mb[x+y] {
				fmt.Println(y, x)
				break oc
			}
		}
	}

}

package main

import ("fmt")

func Max(n int) (max int) {
    var tmp int
    for i:=0; i < n; i++ {
        fmt.Scan(&tmp)
        if tmp > max {
            max = tmp
        }
    }
    return
}

func main() {
    var n int
    fmt.Scan(&n)
    a := Max(n)
    fmt.Scan(&n)
    b := Max(n)
    fmt.Print(a, b)
}

package main

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

func main() {
	var n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	max1 := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		if max1 < a {
			max1 = a
		}
	}
	fmt.Fscan(in, &n)
	max2 := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		if max2 < a {
			max2 = a
		}
	}
	fmt.Println(max1, max2)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n)
	var m []int = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&m[i])
	}
	sort.Ints(m)
	fmt.Scan(&k)
	var m2 []int = make([]int, k)
	for i := 0; i < k; i++ {
		fmt.Scan(&m2[i])
	}
	sort.Ints(m2)
	fmt.Println(m[n-1], m2[k-1])
}

package main

import "fmt"

func max() (maxA int) {
	var n, buf int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&buf)
		if buf > maxA {
			maxA = buf
		}
	}
	return maxA
}

func main() {
	fmt.Println(max(), max())
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r := 0
	for _, c := range in.Bytes() {
		r *= 10
		r += int(c - '0')
	}
	return r
}

func main() {
	in.Split(bufio.ScanWords)
	ra, rb := 0, 0
	for n := nextInt(); n > 0; n-- {
		if a := nextInt(); ra < a {
			ra = a
		}
	}
	for m := nextInt(); m > 0; m-- {
		if b := nextInt(); rb < b {
			rb = b
		}
	}
	fmt.Println(ra, rb)
}

package main

import (
	"fmt"
  "math/rand"
)

func main() {

  var n int
  var verif int = 1
  var lA int
  var lB int
  var m int
  var randomA int
  var randomB int
  var SUM int
  var A [150]int
  var B [150]int
	fmt.Scan(&n)
	for i := 0; i <= n-1; i++{
		fmt.Scan(&A[i])
	}
  fmt.Scan(&m)
  for i := 0; i <= m-1; i++{
		fmt.Scan(&B[i])
	}
  for verif==1 {
    lA=0
    lB=0
    randomA=rand.Intn(n)
    randomB=rand.Intn(m)
    SUM = A[randomA]+B[randomB]
    for SUM!=A[lA] && lA<n {
            lA++
    }
    for SUM!=B[lB] && lB<m {
            lB++
    }
    if (lA==n) && (lB==m) && (A[n-1]!=SUM) && (B[m-1]!=SUM) {
      verif = 0

    }
}
    fmt.Printf("%d %d\n", A[randomA] , B[randomB])
}

package main

import "fmt"

func Max(x1, x2 int) int {
	if x1 < x2 {
		return x2
	} else {
		return x1
	}
}

func main() {
	var n, m int
	fmt.Scan(&n)
	maxA := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		maxA = Max(x, maxA)
	}
	fmt.Scan(&m)
	maxB := 0
	for i := 0; i < m; i++ {
		var x int
		fmt.Scan(&x)
		maxB = Max(x, maxB)
	}
	fmt.Printf("%v %v\n", maxA, maxB)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]int,n)
	readN(a,0,n)
	fmt.Scan(&n)
	b := make([]int,n)
	readN(b,0,n)
	fmt.Println(max(a),max(b))
}

func max(a []int)int{
	m:= a[0]
	for i:=0;i<len(a);i++{
		if a[i]>m{
			m = a[i]
		}
	}
	return m
}

func readN(a []int,i ,n int){
	if n==0{
		return
	}
	if m,err := scan(&a[i]);m!=1{
		panic(err)
	}
	readN(a,i+1,n-1)
}

func scan(i *int)(int,error){
	return fmt.Scan(i)
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

/*******************************************************************/
func _max(a []int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		if a[i] > ret {
			ret = a[i]
		}
	}
	return ret
}

func main() {
	n := ReadInt()
	a := ReadIntSlice(n)
	m := ReadInt()
	b := ReadIntSlice(m)
	fmt.Println(_max(a), _max(b))
}

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

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

/*********** 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+9))
	// 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 readInt()
}
func ReadInt2() (int, int) {
	return readInt(), readInt()
}
func ReadInt3() (int, int, int) {
	return readInt(), readInt(), readInt()
}
func ReadInt4() (int, int, int, int) {
	return readInt(), readInt(), readInt(), readInt()
}

func readInt64() int64 {
	return readIntNbits(64)
}

func readInt() int {
	return int(readIntNbits(32))
}

func readIntNbits(n int) int64 {
	i, err := strconv.ParseInt(ReadString(), 0, n)
	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
}

// 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())
}

// PrintIntsLine returns integers string delimited by a space.
func PrintlnInts(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)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var an int
	fmt.Fscan(r, &an)
	a := make([]int, an)
	for i := 0; i < an; i++ {
		fmt.Fscan(r, &a[i])
	}
	var bn int
	fmt.Fscan(r, &bn)
	b := make([]int, bn)
	for i := 0; i < bn; i++ {
		fmt.Fscan(r, &b[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(b)))
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	fmt.Printf("%d %d", a[0], b[0])

}

package main

import "fmt"

func main() {
    var n,m int
	var a,b,mark [401]int

	fmt.Scan(&n)
	for i:=0 ; i<n; i++ {
	    fmt.Scan(&a[i])
	    mark[a[i]] = 1
	}

	fmt.Scan(&m)
	for i:=0 ; i<m; i++ {
	    fmt.Scan(&b[i])
	    mark[b[i]] = 1
	}

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

	    for j:=0; j<m; j++ {

	        var val = a[i] + b[j]

	        if mark[val]!=1 {
	            fmt.Println(a[i], b[j])
	            return
	        }
	    }
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
	"sync"
)

func main() {
	firstArrayCount := ScanInt()
	firstArray := ScanIntSlice(firstArrayCount)
	secondArrayCount := ScanInt()
	secondArray := ScanIntSlice(secondArrayCount)
	totalArrayMap := make(map[int]int, firstArrayCount+ secondArrayCount+ 1)

	for i := 0; i < firstArrayCount; i++{
		totalArrayMap[firstArray[i]] = 1
	}

	for i := 0; i < secondArrayCount; i++{
		totalArrayMap[secondArray[i]] = 1
	}
	for i := 0; i < firstArrayCount; i++{
		for j := 0; j < secondArrayCount; j++{
			if totalArrayMap[firstArray[i] + secondArray[j]] != 1{
				P(firstArray[i] , secondArray[j])
				return
			}
		}
	}

	P(totalArrayMap)

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	n, a, b := 0, 0, 0
	str := ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanln(&str)
	a, _ = strconv.Atoi(str)
	for i := 1; i < n; i++ {
		tmp := 0
		fmt.Scanf("%d", &tmp)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		tmp := 0
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func solution(reader io.Reader, writer io.Writer) {
	var n, m int

	h := make(map[int]bool)

	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
		h[a[i]] = true
	}

	fmt.Fscanf(reader, "\n%d\n", &m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &b[i])
		h[b[i]] = true
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			_, ok := h[a[i] + b[j]]
			if !ok {
				fmt.Fprintf(writer, "%d %d\n", a[i], b[j])
				return
			}
		}
	}

}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

import "fmt"

func solve(n, m int, a, b []int) (x, y int) {
	mark := make([]bool, 401)
	for i := 0; i < n; i++ {
		mark[a[i]] = true
	}
	for j := 0; j < m; j++ {
		mark[b[j]] = true
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if !mark[a[i]+b[j]] {
				return a[i], b[j]
			}
		}
	}
	return 0, 0
}

func main() {
	var n, m int
	var a, b []int
	fmt.Scan(&n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scan(&m)
	b = make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
	}
	var x, y = solve(n, m, a, b)
	fmt.Printf("%d %d\n", x, y)
}

package main

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

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

	var n, m, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		a[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fscanf(reader, "%d\n", &m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		b[i] = temp
	}
	sort.Ints(a)
	sort.Ints(b)
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d %d\n", a[len(a)-1], b[len(b)-1])
}

package main

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

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

	var n, m, temp, aMax, bMax int
	aMax = 0
	bMax = 0
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		if temp > aMax {
			aMax = temp
		}
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fscanf(reader, "%d\n", &m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		if temp > bMax {
			bMax = temp
		}
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d %d\n", aMax, bMax)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1206/problem/A

package main

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

type Solution struct {
	maxA int
	maxB int
}

func max(arr []int) int {
	maxElem := arr[0]
	for i := 1; i < len(arr); i++ {
		if arr[i] > maxElem {
			maxElem = arr[i]
		}
	}
	return maxElem
}

func Solve(A []int, B []int) Solution {
	return Solution{maxA: max(A), maxB: max(B)}
}

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

	var n int
	fmt.Fscan(reader, &n)
	A := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &A[i])
	}

	var m int
	fmt.Fscan(reader, &m)
	B := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscan(reader, &B[i])
	}

	solution := Solve(A, B)
	fmt.Fprintf(writer, "%d %d\n", solution.maxA, solution.maxB)
}

package main

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

func main() {
	var n, m, x int64

	scr := bufio.NewReader(os.Stdin)
	// ocr := bufio.NewWriter(os.Stdout)

	fmt.Fscanln(scr, &n)
	ma := make(map[int64]bool)

	for i := int64(0); i < n; i++ {
		fmt.Fscanf(scr, "%d", &x)
		ma[x] = true
	}
	fmt.Fscanf(scr, "%d", &x)

	fmt.Fscanln(scr, &m)
	mb := make(map[int64]bool)

	for i := int64(0); i < m; i++ {
		fmt.Fscanf(scr, "%d", &x)
		mb[x] = true
	}

oc:
	for y := range ma {
		for x := range mb {
			if !ma[x+y] || !mb[x+y] {
				fmt.Println(y, x)
				break oc
			}
		}
	}

}

package main

import (
	"fmt"
  "math/rand"
)

func main() {

  var n int
  var verif int = 1
  var lA int= 0
  var lB int= 0
  var m int
  var randomA int
  var randomB int
  var SUM int
  var A [100]int
  var B [100]int
	fmt.Scan(&n)
	for i := 0; i <= n-1; i++{
		fmt.Scan(&A[i])
	}
  fmt.Scan(&m)
  for i := 0; i <= m-1; i++{
		fmt.Scan(&B[i])
	}
  for verif==1 {
    randomA=rand.Intn(n)
    randomB=rand.Intn(m)
    SUM = A[randomA]+B[randomB]
    for SUM!=A[lA] && lA<n {
      lA++
    }
    for SUM!=B[lB] && lB<m {
      lB++
    }
    if (lA!=n-1) && (lB!=m-1) {
      verif = 0
    }
}
    fmt.Printf("%d %d\n", A[randomA] , B[randomB])
}

package main

import (
	"fmt"
  "math/rand"
)

func main() {

  var n int
  var verif int = 1
  var lA int= 0
  var lB int= 0
  var m int
  var randomA int
  var randomB int
  var SUM int
  var A [200]int
  var B [200]int
	fmt.Scan(&n)
	for i := 0; i <= n-1; i++{
		fmt.Scan(&A[i])
	}
  fmt.Scan(&m)
  for i := 0; i <= m-1; i++{
		fmt.Scan(&B[i])
	}
  for verif==1 {
    randomA=rand.Intn(n)
    randomB=rand.Intn(m)
    SUM = A[randomA]+B[randomB]

    for SUM!=A[lA] && lA<n {
      lA++
    }
    for SUM!=B[lB] && lB<m {
      lB++
    }
    if (lA==n) && (lB==m) && (A[n-1]!=SUM) && (B[m-1]!=SUM) {
      verif = 0

    }
}
    fmt.Printf("%d %d\n", A[randomA] , B[randomB])
}

package main

import (
	"fmt"
  "math/rand"
)

func main() {

  var n int
  var verif int = 1
  var lA int= 0
  var lB int= 0
  var m int
  var randomA int
  var randomB int
  var SUM int
  var A [150]int
  var B [150]int
	fmt.Scan(&n)
	for i := 0; i <= n-1; i++{
		fmt.Scan(&A[i])
	}
  fmt.Scan(&m)
  for i := 0; i <= m-1; i++{
		fmt.Scan(&B[i])
	}
  for verif==1 {
    randomA=rand.Intn(n)
    randomB=rand.Intn(m)
    SUM = A[randomA]+B[randomB]
    for SUM!=A[lA] && lA<n {
      lA++
    }
    for SUM!=B[lB] && lB<m {
      lB++
    }
    if (lA==n) && (lB==m) && (A[n-1]!=SUM) && (B[m-1]!=SUM) {
      verif = 0

    }
}
    fmt.Printf("%d %d\n", A[randomA] , B[randomB])
}

package main

import "fmt"

func main() {
    var n,m int
	var a,b,mark [401]int

	fmt.Scan(&n)
	for i:=0 ; i<n; i++ {
	    fmt.Scan(&a[i])
	    mark[a[i]] = 1
	}

	fmt.Scan(&m)
	for i:=0 ; i<m; i++ {
	    fmt.Scan(&b[i])
	    mark[b[i]] = 1
	}

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

	    for j:=0; j<n; j++ {

	        var val = a[i] + b[j]

	        if mark[val]!=1 {
	            fmt.Println(a[i], b[j])
	            return
	        }
	    }
	}

}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d/n", &n)
	fmt.Scanf("%d", &a)
	for i := 1; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d/n", &n)
	fmt.Scanf("%d", &b)
	for i := 1; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	n, a, b := 0, 0, 0
	str := ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanln(&str)
	for _, s := range strings.Split(str, " ") {
		tmp, _ := strconv.Atoi(s)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		tmp := 0
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &a)
	for i := 1; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &b)
	for i := 1; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d/n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d/n", &n)
	fmt.Scanf("%d", &b)
	for i := 1; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("\n%d\n", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	n, a, b := 0, 0, 0
	str := ""
	fmt.Scanf("%d\n", &n)
	fmt.Scanln(&str)
	for _, s := range strings.Split(str, " ") {
		tmp, _ := strconv.Atoi(s)
		if tmp > a {
			a = tmp
		}
	}
	fmt.Scanf("%d\n", &n)
	fmt.Scanln(&str)
	fmt.Println(str)
	for _, s := range strings.Split(str, " ") {
		tmp, _ := strconv.Atoi(s)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		fmt.Printf("tmp = %d a = %d\n", tmp, a)
		if tmp > a {
			a = tmp
		}
		fmt.Printf("a = %d\n", a)
	}
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d\n", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		fmt.Printf("tmp = %d a = %d\n", tmp, a)
		if tmp > a {
			a = tmp
		}
		fmt.Printf("a = %d\n", a)
	}
	fmt.Scanf("%d", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

import "fmt"

func main() {
	n, a, b, tmp := 0, 0, 0, 0
	fmt.Scanf("%d", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		fmt.Printf("tmp = %d a = %d\n", tmp, a)
		if tmp > a {
			a = tmp
		}
		fmt.Printf("a = %d\n", a)
	}
	fmt.Scanf("%d", &n)
	fmt.Printf("n = %d\n", n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tmp)
		if tmp > b {
			b = tmp
		}
	}
	fmt.Println(a, b)
}

package main

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

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

	var n, m, temp int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		a[i] = temp
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fscanf(reader, "%d\n", &m)
	b := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		b[i] = temp
	}
	sort.Ints(a)
	sort.Ints(b)
	fmt.Fscanf(reader, "\n")
	fmt.Fprintf(writer, "%d %d\n", a[len(a)-1], b[len(a)-1])
}