The BFS algorithm is defined as follows.  Consider an undirected graph with vertices numbered from $$$1$$$ to $$$n$$$. Initialize $$$q$$$ as a new queue containing only vertex $$$1$$$, mark the vertex $$$1$$$ as used.  Extract a vertex $$$v$$$ from the head of the queue $$$q$$$.  Print the index of vertex $$$v$$$.  Iterate in arbitrary order through all such vertices $$$u$$$ that $$$u$$$ is a neighbor of $$$v$$$ and is not marked yet as used. Mark the vertex $$$u$$$ as used and insert it into the tail of the queue $$$q$$$.  If the queue is not empty, continue from step 2.  Otherwise finish. Since the order of choosing neighbors of each vertex can vary, it turns out that there may be multiple sequences which BFS can print.In this problem you need to check whether a given sequence corresponds to some valid BFS traversal of the given tree starting from vertex $$$1$$$. The tree is an undirected graph, such that there is exactly one simple path between any two vertices.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) which denotes the number of nodes in the tree.  The following $$$n - 1$$$ lines describe the edges of the tree. Each of them contains two integers $$$x$$$ and $$$y$$$ ($$$1 \le x, y \le n$$$) — the endpoints of the corresponding edge of the tree. It is guaranteed that the given graph is a tree. The last line contains $$$n$$$ distinct integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the sequence to check.

Print "Yes" (quotes for clarity) if the sequence corresponds to some valid BFS traversal of the given tree and "No" (quotes for clarity) otherwise. You can print each letter in any case (upper or lower).

NoteBoth sample tests have the same tree in them.In this tree, there are two valid BFS orderings:   $$$1, 2, 3, 4$$$,  $$$1, 3, 2, 4$$$. The ordering $$$1, 2, 4, 3$$$ doesn't correspond to any valid BFS order.

package main

import."fmt"
import"bufio"
import"os"

func main(){
	var n int
	Scan(&n)
	g:=make([]map[int]bool,n+1)
	for i:=1;i<n+1;i++{
		g[i]=map[int]bool{}
	}
	in:=bufio.NewReader(os.Stdin)
	for i:=0;i<n-1;i++{
		var x,y int
		Fscan(in,&x,&y)
		g[x][y]=true
		g[y][x]=true
	}
	isCheckeds:=make([]bool,n+1)
	isCheckeds[1]=true
	checks:=[]int{1}
	checksLen:=1
	for checksLen>0{
		newChecks:=[]int{}
		for i:=0;i<checksLen;i++{
			for k:=range g[checks[i]]{
				if isCheckeds[k]{
					delete(g[checks[i]],k)
					continue
				}
				newChecks=append(newChecks,k)
				isCheckeds[k]=true
			}
		}
		checks=newChecks
		checksLen=len(checks)
	}
	var aI int
	Fscan(in,&aI)
	if aI!=1{
		Print("No")
		return
	}
	checks=[]int{1}
	checksLen=1
	for checksLen>0{
		newChecks:=[]int{}
		for i:=0;i<checksLen;i++{
			lenG:=len(g[checks[i]])
			for j:=0;j<lenG;j++{
				Fscan(in,&aI)
				if !g[checks[i]][aI]{
					Print("No")
					return
				}
				newChecks=append(newChecks,aI)
			}
		}
		checks=newChecks
		checksLen=len(checks)
	}

	Print("Yes")
}

package main

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

func solve(n int, vertices [][]int, tocheck []int) string {
	relorder := make([]int, n+1)
	q := make([]int, 0, n-1)
	q = append(q, 1)
	visited := make([]bool, n+1)
	answer := make([]int, 0, n)

	for idx, val := range tocheck {
		relorder[val] = idx
	}
	for _, lst := range vertices {
		sort.Slice(lst, func(i, j int) bool {
			return relorder[lst[i]] < relorder[lst[j]]
		})
	}
	for len(q) > 0 {
		elem := q[0]
		q = q[1:]
		visited[elem] = true
		answer = append(answer, elem)
		for _, v := range vertices[elem] {
			if !visited[v] {
				q = append(q, v)
			}
		}
	}
	for i, v := range answer {
		if tocheck[i] != v {
			return "NO"
		}
	}
	return "YES"
}

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	vertices := make([][]int, n+1)
	tocheck := make([]int, n)

	for i := 1; i <= n-1; i++ {
		var from, to int
		fmt.Fscan(in, &from, &to)

		vertices[to] = append(vertices[to], from)
		vertices[from] = append(vertices[from], to)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &tocheck[i])
	}
	//fmt.Print(vertices)
	//fmt.Print(tocheck)
	res := solve(n, vertices, tocheck)
	fmt.Println(res)
}

package main

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

func qsort(a []int, relorder []int) []int {
	if len(a) < 2 {
		return a
	}

	left, right := 0, len(a)-1

	// Pick a pivot
	pivotIndex := rand.Int() % len(a)

	// Move the pivot to the right
	a[pivotIndex], a[right] = a[right], a[pivotIndex]

	// Pile elements smaller than the pivot on the left
	for i := range a {
		if relorder[a[i]] < relorder[a[right]] {
			a[i], a[left] = a[left], a[i]
			left++
		}
	}

	// Place the pivot after the last smaller element
	a[left], a[right] = a[right], a[left]

	// Go down the rabbit hole
	qsort(a[:left], relorder)
	qsort(a[left+1:], relorder)

	return a
}

func solve(n int, vertices [][]int, tocheck []int) string {
	relorder := make([]int, n+1)
	q := make([]int, 0, n-1)
	q = append(q, 1)
	visited := make([]bool, n+1)
	answer := make([]int, 0, n)

	for idx, val := range tocheck {
		relorder[val] = idx
	}
	for _, lst := range vertices {
		qsort(lst, relorder)
	}
	for len(q) > 0 {
		elem := q[0]
		q = q[1:]
		visited[elem] = true
		answer = append(answer, elem)
		for _, v := range vertices[elem] {
			if !visited[v] {
				q = append(q, v)
			}
		}
	}
	for i, v := range answer {
		if tocheck[i] != v {
			return "NO"
		}
	}
	return "YES"
}

func main() {
	var n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	vertices := make([][]int, n+1)
	tocheck := make([]int, n)

	for i := 1; i <= n-1; i++ {
		var from, to int
		fmt.Fscan(in, &from, &to)

		vertices[to] = append(vertices[to], from)
		vertices[from] = append(vertices[from], to)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &tocheck[i])
	}
	//fmt.Print(vertices)
	//fmt.Print(tocheck)
	res := solve(n, vertices, tocheck)
	fmt.Println(res)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n+1)
	g[1] = []int{0}
	for m := n - 1; m > 0; m-- {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	g2 := make([][]int, n+1)
	g2[1] = []int{0}
	Fscan(in, &v)
	for q := []int{v}; len(q) > 0; {
		v, q = q[0], q[1:]
		for m := len(g[v]) - 1; m > 0; m-- {
			Fscan(in, &w)
			g2[v] = append(g2[v], w)
			g2[w] = append(g2[w], v)
			q = append(q, w)
		}
	}

	for i, e := range g {
		e2 := g2[i]
		if len(e) != len(e2) {
			Print("No")
			return
		}
		sort.Ints(e)
		sort.Ints(e2)
		for j, w := range e {
			if w != e2[j] {
				Print("No")
				return
			}
		}
	}
	Print("Yes")
}

package main

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

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

	var n, v, w int
	Fscan(in, &n)
	g := make([][]int, n+1)
	g[1] = []int{0}
	for m := n - 1; m > 0; m-- {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}
	for _, e := range g {
		sort.Ints(e)
	}

	g2 := make([][]int, n+1)
	g2[1] = []int{0}
	Fscan(in, &v)
	for queue := []int{v}; len(queue) > 0; {
		v, queue = queue[0], queue[1:]
		for m := len(g[v]) - 1; m > 0; m-- {
			Fscan(in, &w)
			g2[v] = append(g2[v], w)
			g2[w] = append(g2[w], v)
			queue = append(queue, w)
		}
	}
	for _, e := range g2 {
		sort.Ints(e)
	}

	for i, e := range g {
		if len(e) != len(g2[i]) {
			Fprint(out, "No")
			return
		}
		for j, w := range e {
			if w != g2[i][j] {
				Fprint(out, "No")
				return
			}
		}
	}
	Fprint(out, "Yes")
}

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

package main

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

const (
	MaxN = 200005
)

var n int
var a, u, d []int
var g map[int]map[int]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	g = make(map[int]map[int]bool, n+1)
	a = make([]int, n)
	d = make([]int, n+1)
	u = make([]int, n+1)
	for i := 0; i < n - 1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		if _, ok := g[v1]; !ok {
			g[v1] = make(map[int]bool)
		}
		g[v1][v2] = true
		if _, ok := g[v2]; !ok {
			g[v2] = make(map[int]bool)
		}
		g[v2][v1] = true
	}
	for i := 1; i <= n; i++ {
		d[i] = len(g[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}

	if a[0] != 1 {
		fmt.Println("No")
		return
	}

	checked := 1
	u[a[0]] = 1
	for i := 0; i < n; i++ {
		for j := checked; j < n; j++ {
			if _, ok := g[a[i]][a[j]]; ok && u[a[j]] == 0 {
				u[a[j]] = 1
				checked++
				d[a[i]]--
				d[a[j]]--
			} else {
				break
			}
		}
		if d[a[i]] > 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

package main

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

const (
	MaxN = 200005
)

var n int
var a, u, d []int
var g map[int]map[int]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	g = make(map[int]map[int]bool, n+1)
	a = make([]int, n)
	d = make([]int, n+1)
	u = make([]int, n+1)
	for i := 0; i < n - 1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		if _, ok := g[v1]; !ok {
			g[v1] = make(map[int]bool)
		}
		g[v1][v2] = true
		if _, ok := g[v2]; !ok {
			g[v2] = make(map[int]bool)
		}
		g[v2][v1] = true
	}
	for i := 1; i <= n; i++ {
		d[i] = len(g[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}

	checked := 1
	u[a[0]] = 1
	for i := 0; i < n; i++ {
		for j := checked; j < n; j++ {
			if _, ok := g[a[i]][a[j]]; ok && u[a[j]] == 0 {
				u[a[j]] = 1
				checked++
				d[a[i]]--
				d[a[j]]--
			} else {
				break
			}
		}
		if d[a[i]] > 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

package main

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

const (
	MaxN = 200005
)

var n int
var a, u, d []int
var g map[int]map[int]bool

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	g = make(map[int]map[int]bool, n+1)
	a = make([]int, n)
	d = make([]int, n+1)
	u = make([]int, n+1)
	for i := 0; i < n - 1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		if _, ok := g[v1]; !ok {
			g[v1] = make(map[int]bool)
		}
		g[v1][v2] = true
		if _, ok := g[v2]; !ok {
			g[v2] = make(map[int]bool)
		}
		g[v2][v1] = true
	}
	for i := 1; i <= n; i++ {
		d[i] = len(g[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}

	if a[0] != 1 {
		fmt.Println("No")
		return
	}

	checked := 1
	u[a[0]] = 1
	for i := 0; i < n; i++ {
		for j := checked; j < n; j++ {
			if _, ok := g[a[i]][a[j]]; ok && u[a[j]] == 0 {
				u[a[j]] = 1
				checked++
				d[a[i]]--
				d[a[j]]--
			} else {
				break
			}
		}
		if d[a[i]] > 0 {
			fmt.Println(d)
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

package main

import."fmt"
import"bufio"
import"os"

func main(){
	var n int
	Scan(&n)
	g:=make([][]int,n+1)
	in:=bufio.NewReader(os.Stdin)
	for i:=0;i<n-1;i++{
		var x,y int
		Fscan(in,&x,&y)
		g[x]=append(g[x],y)
		g[y]=append(g[y],x)
	}
	lvls:=make([]int,n+1)
	lvls[1]=1
	children:=g[1]
	lvl:=2
	lvlCounts:=[]int{0,1}
	for len(children)>0{
		leng:=len(children)
		lvlCounts=append(lvlCounts,leng)
		for i:=0;i<leng;i++{
			lvls[children[i]]=lvl
			lengG:=len(g[children[i]])
			for j:=0;j<lengG;j++{
				if lvls[g[children[i]][j]]==0{
					children=append(children,g[children[i]][j])
				}
			}
		}
		children=children[leng:]
		lvl++
	}
	lvl=1
	for i:=0;i<n;i++{
		var aI int
		Fscan(in,&aI)
		if lvls[aI]!=lvl{
			Print("No")
			return
		}
		lvlCounts[lvl]--
		if lvlCounts[lvl]==0{
			lvl++
		}
	}

	Print("Yes")
}

package main

import (
	"container/list"
	"fmt"
	"sort"
)

type value struct {
	current int
	level   int
}

func solve(n int, vertices [][]int, tocheck []int) string {
	q := list.New()
	q.PushBack(value{1, 1})
	visited := make([]bool, n+1)
	level := 0
	start := 0
	for q.Len() > 0 {
		elem := q.Front().Value.(value)
		visited[elem.current] = true
		if level != elem.level {
			slice := tocheck[start : start+q.Len()]
			sort.Ints(slice)
			// fmt.Print(slice)
			for e := q.Front(); e != nil; e = e.Next() {
				idx := sort.SearchInts(slice, e.Value.(value).current)
				if idx == len(slice) {
					return "NO"
				}
			}
			level = elem.level
			start += q.Len()
		}
		q.Remove(q.Front())
		for _, v := range vertices[elem.current] {
			if !visited[v] {
				q.PushBack(value{v, elem.level + 1})
			}
		}
	}
	return "YES"
}

func main() {
	var n int
	fmt.Scan(&n)
	vertices := make([][]int, n+1)
	tocheck := make([]int, n)

	for i := 1; i <= n-1; i++ {
		var from, to int
		fmt.Scan(&from, &to)

		vertices[to] = append(vertices[to], from)
		vertices[from] = append(vertices[from], to)
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&tocheck[i])
	}
	//fmt.Print(vertices)
	//fmt.Print(tocheck)
	res := solve(n, vertices, tocheck)
	fmt.Println(res)
}

package main

import (
	"container/list"
	"fmt"
	"sort"
)

type value struct {
	current int
	level   int
}

func solve(n int, vertices [][]int, tocheck []int) string {
	q := list.New()
	q.PushBack(value{1, 1})
	visited := make([]bool, n+1)
	level := 0
	start := 0
	for q.Len() > 0 {
		elem := q.Front().Value.(value)
		visited[elem.current] = true
		if level != elem.level {
			slice := tocheck[start : start+q.Len()]
			sort.Ints(slice)
			// fmt.Print(slice)
			for e := q.Front(); e != nil; e = e.Next() {
				idx := sort.SearchInts(slice, e.Value.(value).current)
				if idx == len(slice) {
					return "NO"
				}
			}
			level = elem.level
			start += q.Len()
		}
		q.Remove(q.Front())
		for _, v := range vertices[elem.current] {
			if !visited[v] {
				q.PushBack(value{v, elem.level + 1})
			}
		}
	}
	return "YES"
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	vertices := make([][]int, n+1)
	tocheck := make([]int, n)

	for i := 1; i <= n-1; i++ {
		var from, to int
		fmt.Scanf("%d %d ", &from, &to)

		vertices[to] = append(vertices[to], from)
		vertices[from] = append(vertices[from], to)
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tocheck[i])
	}
	// fmt.Print(vertices)
	// fmt.Print(tocheck)
	res := solve(n, vertices, tocheck)
	fmt.Println(res)
}

package main

import (
	"container/list"
	"fmt"
	"sort"
)

type value struct {
	current int
	level   int
}

func solve(n int, vertices [][]int, tocheck []int) string {
	q := list.New()
	q.PushBack(value{1, 1})
	visited := make([]bool, n+1)
	level := 0
	start := 0
	for q.Len() > 0 {
		elem := q.Front().Value.(value)
		visited[elem.current] = true
		if level != elem.level {
			slice := tocheck[start : start+q.Len()]
			sort.Ints(slice)
			//	fmt.Print(slice)
			for e := q.Front(); e != nil; e = e.Next() {
				idx := sort.SearchInts(slice, e.Value.(value).current)
				if idx == len(slice) {
					return "NO"
				}
			}
			level = elem.level
			start += q.Len()
		}
		q.Remove(q.Front())
		for _, v := range vertices[elem.current] {
			if !visited[v] {
				q.PushBack(value{v, elem.level + 1})
			}
		}
	}
	return "YES"
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	vertices := make([][]int, n+1)
	tocheck := make([]int, n)

	for i := 0; i < n-1; i++ {
		var from, to int
		fmt.Scanf("%d %d", &from, &to)

		vertices[to] = append(vertices[to], from)
		vertices[from] = append(vertices[from], to)
	}
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &tocheck[i])
	}
	// fmt.Print(vertices)
	// fmt.Print(tocheck)
	res := solve(n, vertices, tocheck)
	fmt.Println(res)
}

package main

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

const (
	MaxN = 200005
)

var n int
var a, d []int
var g [][]int

func bfs(v int) {
	q := []int{v}
	d[v] = 1
	for len(q) > 0 {
		t := q[0]
		q = q[1:]
		for _, v := range g[t] {
			if d[v] == 0 {
				d[v] = d[t] + 1
				q = append(q, v)
			}
		}
	}
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	g = make([][]int, n+1)
	a = make([]int, n+1)
	d = make([]int, n+1)
	for i := 0; i < n - 1; i++ {
		var v1, v2 int
		fmt.Fscanf(buf, "%d %d\n", &v1, &v2)
		g[v1] = append(g[v1], v2)
		g[v2] = append(g[v2], v1)
	}
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}
	bfs(a[0])
	for i := 0; i < n - 1; i++ {
		if d[a[i]] > d[a[i+1]] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.

For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)

		fmt.Println(1, n-1)

	}
}

package main

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

func main() {

	t := ScanInt64()
	for ; t > 0; t-- {
		n := ScanInt64()
		fmt.Println(n-1, 1)
	}

}

/*********************** 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 []int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args []int64) int64 { mn, _ := MnMx(args); return mn }
func Mx(args []int64) int64 { _, mx := MnMx(args); return mx }
func LCM(a, b int64) int64  { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	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 int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func MinimumMaximum(a, b int64) (int64, int64) {
	if a < b {
		return a, b
	}
	return b, a

}
func Minimum(a, b int64) int64 {
	min, _ := MinimumMaximum(a, b)
	return min

}
func Maximum(a, b int64) int64 {
	_, max := MinimumMaximum(a, b)
	return max

}

package main

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

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 fillNNums(bs []byte, n int, res []int) {
	x := 0
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		a, b := solve(n)
		fmt.Printf("%d %d\n", a, b)
	}
}

func solve(x int) (int, int) {

	for g := 1; g*g <= x; g++ {
		if x%g != 0 {
			continue
		}
		h := x / g
		// g * h = x
		// let h = (1 + m * n)
		if h > 1 {
			mn := h - 1
			return g, g * mn
		}

		if g > 1 {
			mn := g - 1
			return h, h * mn
		}
	}

	return 1, 1
}

package main

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

func main() {

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

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

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

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

		fmt.Fprintln(out, x-1, 1)
	}

}

package main

import ("fmt")

// func calculate(y,d int32){
// 	answer := y%d
// 	if answer==0{
// 		fmt.Println("YES")
// 	}else{
// 		fmt.Println("NO")
// 	}
// }

func main(){
	var t int
	fmt.Scanln(&t)
	for i:=0;i<t;i++{
		var x int32
		//var y int32
		fmt.Scanln(&x)
		//fmt.ScanLN(&y)
		fmt.Println(1,x-1)
		//calculate(x,y)
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()
	for t := 0; t < T; t++ {
		x := NextInt()
		fmt.Fprintln(out, 1, x-1)
	}
}

package main

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

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

    var T, n int
    fmt.Fscan(r, &T)
    for t := 0; t < T; t++ {
        fmt.Fscan(r, &n)
        fmt.Fprint(w, 1, n-1, "\n")
    }
}

package main

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

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

func printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func nextInt() int {
	in.Scan()
	n, _ := strconv.Atoi(in.Text())
	return n
}

func main() {
	in.Split(bufio.ScanWords)
	defer out.Flush()
	for t := nextInt(); t > 0; t-- {
		printf("%d %d\n", 1, nextInt()-1)
	}
}

package main

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

func main() {

	t := ReadInt()
	for tidx:=1;tidx<=t;tidx++ {
		a:=ReadInt()-1
		fmt.Printf("%d %d\n", 1, a)
	}
}

////////////////////////////////////

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
}

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadInt64() int64 {
	intstr := ReadString()
	i, _ := strconv.ParseInt(intstr, 10, 64)
	return int64(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

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

package main

import (
	"bufio"
	"fmt"
)

func main() {
	// reader := bufio.NewReader(os.Stdin)
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var x int64
		fmt.Scanf("%d\n", &x)
		a := 1
		b := x - 1
		fmt.Println(a, b)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import (
	"fmt"
)

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

func main() {
	var n int
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Println(err)
		return
	}
	for i := 0; i < n; i++ {
		var x int
		_, err = fmt.Scanf("%d\n", &x)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(x-1, 1)
	}
}

package main

import(
	"fmt"
)

func main(){
	var t int
	_, _ = fmt.Scan( &t)

	for ; t>0 ; t-- {
		var x int
		_, _ = fmt.Scan( &x)
		g,l:=1,x-1
		a,b:=g*l/g,g*l/l
		fmt.Println(a,b)

	}
}

package main

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

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

	var ts int
	fmt.Fscanf(r, "%d\n", &ts)

	for t := 0; t < ts; t++ {
		var x int
		fmt.Fscanf(r, "%d\n", &x)
		fmt.Printf("1 %d\n", x-1)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325A(in io.Reader, out io.Writer) {
	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fprintln(out, 1, n-1)
	}
}

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

package main

import "fmt"

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for i := 0; i < T; i++ {
		Val := 0
		fmt.Scanf("%d\n", &Val)
		fmt.Println(1, Val-1)
	}
}

package main

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

func main() {
	t := nextInt()
	for t > 0 {
		x := nextInt()
		print(x - 1, 1, "\n")
		t--
	}
	writer.Flush()
}

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

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

func nextInt() int {
	var n int
	fmt.Fscan(reader, &n)
	return n
}

package main

import "fmt"

func main()  {
	var T, x int
	_, _ = fmt.Scan(&T)
	for ;T > 0; T-- {
		_, _ = fmt.Scan(&x)
		fmt.Println(1,x-1)
	}
}

package main

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

func main() {
	input := bufio.NewScanner(os.Stdin)
	input.Scan()
	t, _ := strconv.Atoi(input.Text())
	for i := 0; i < t; i++ {
		input.Scan()
		x, _ := strconv.Atoi(input.Text())
		fmt.Printf("1 %v\n", x - 1)
	}
}

package main

import (
	"fmt"
)

func solve() {
	var x int
	fmt.Scan(&x)
	fmt.Printf("%d %d\n", 1, x-1)
}

func main() {
	var tst int
	fmt.Scan(&tst)
	for t := 0; t < tst; t++ {
		solve()
	}

}

package main

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

func smth(x string)(string){
	var n int
	n, _ = strconv.Atoi(x)
	return "1 " + strconv.Itoa(n - 1)
}
func main() {
	var line string
	var testcount int
	fmt.Scanln(&testcount)
	answer := ""
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < testcount; i++ {
		line, _ = reader.ReadString('\n')
		line = strings.TrimSpace(line)
		answer += smth(line)
		if i < testcount - 1{
			answer += "\n"
		}
	}
	fmt.Print(answer)
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt(s *bufio.Scanner) int {
	if s.Scan() {
		t := s.Text()
		if v, err := strconv.Atoi(t); err == nil {
			return v
		}
		panic(fmt.Sprintln("Could't scan int from input", t))
	}
	panic(s.Err())
}

func scanInts(s *bufio.Scanner, n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt(s)
	}
	return a
}

var sc *bufio.Scanner = newScanner()

func solve() {
	x := scanInt(sc)
	fmt.Println(1, x-1)
}

func main() {
	t := scanInt(sc)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"strings"
)

func GCD(x, y int64) int64 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

func LCM(x, y int64) int64 {
	return x / GCD(x, y) * y
}

func Find(x int64) (int64, int64) {
	var a, b int64
	if x % 2 == 0 {
		a = x / 2
		b = a
		return a, b
	}
	b = 1
	a = x - 1
	return a, b
}

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}
	var n, i uint64
	var t int64
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	_, err := fmt.Scanf("%d\n", &n)
	if err != nil {
		fmt.Printf("err1: %v", err.Error())
		os.Exit(1)
	}
	for i = 0; i < n; i++ {
		str, _ := reader.ReadString('\n')
		t, err = strconv.ParseInt(strings.TrimSpace(str), 10, 64)
		if err != nil {
			fmt.Printf("err2: %v", err.Error())
			os.Exit(1)
		}

		a, b := Find(t)
		//writer.WriteString(strconv.FormatInt(a, 10))
		//writer.WriteString(" ")
		//writer.WriteString(strconv.FormatInt(b, 10))
		fmt.Fprintf(writer, "%d %d\n", a, b)
	}
	writer.Flush()
}

package main

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

var (
    reader Reader = NewReader()
    writer Writer = NewWriter()
)

type Reader interface {
    Scanf(format string, a ...interface{})
    Int() int
    Int64() int64
    String() string
    IntStream(size int) <-chan int
    Int64Stream(size int) <-chan int64
    StringStream(size int) <-chan string
    IntSlice(size int) []int
    Int64Slice(size int) []int64
    StringSlice(size int) []string
}

type Writer interface {
    Printf(format string, a ...interface{})
    Flush()
}

type readerImpl struct {
    *bufio.Reader
}

func NewReader() Reader {
    return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) Scanf(f string, a ...interface{}) {
    fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
    var ret int
    impl.Scanf("%d\n", &ret)
    return ret
}

func (impl *readerImpl) Int64() int64 {
    var ret int64
    impl.Scanf("%d\n", &ret)
    return ret
}

func (impl *readerImpl) String() string {
    var ret string
    impl.Scanf("%s\n", &ret)
    return ret
}

func (impl *readerImpl) IntStream(size int) <-chan int {
    c := make(chan int)
    go func() {
        for i := 0; i < size-1; i++ {
            var v int
            impl.Scanf("%d ", &v)
            c <- v
        }
        var v int
        impl.Scanf("%d\n", &v)
        c <- v
    }()
    return c
}

func (impl *readerImpl) Int64Stream(size int) <-chan int64 {
    c := make(chan int64)
    go func() {
        for i := 0; i < size-1; i++ {
            var v int64
            impl.Scanf("%d ", &v)
            c <- v
        }
        var v int64
        impl.Scanf("%d\n", &v)
        c <- v
    }()
    return c
}

func (impl *readerImpl) StringStream(size int) <-chan string {
    c := make(chan string)
    go func() {
        for i := 0; i < size-1; i++ {
            var v string
            impl.Scanf("%d ", &v)
            c <- v
        }
        var v string
        impl.Scanf("%d\n", &v)
        c <- v
    }()
    return c
}

func (impl *readerImpl) IntSlice(size int) []int {
    ret := make([]int, size)
    for i := 0; i < size-1; i++ {
        impl.Scanf("%d ", &ret[i])
    }
    impl.Scanf("%d\n", &ret[size-1])
    return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
    ret := make([]int64, size)
    for i := 0; i < size-1; i++ {
        impl.Scanf("%d ", &ret[i])
    }
    impl.Scanf("%d\n", &ret[size-1])
    return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
    ret := make([]string, size)
    for i := 0; i < size-1; i++ {
        impl.Scanf("%s ", &ret[i])
    }
    impl.Scanf("%s\n", &ret[size-1])
    return ret
}

type writerImpl struct {
    *bufio.Writer
}

func NewWriter() Writer {
    return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
    fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
    impl.Writer.Flush()
}

func main() {
    defer writer.Flush()
    t := reader.Int()
    for ; t > 0; t-- {
        x := reader.Int()
        a, b := sol(x)
        writer.Printf("%d %d\n", a, b)
    }
}

func sol(x int) (int, int) {
    if x % 2 == 0 {
        return x/2, x/2
    }
    return 1, x-1
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		if n%2 == 0 {
			fmt.Println(2, n-2)
		} else {
			fmt.Println(1, n-1)
		}
	}
}

package main

import (
	"fmt"
)

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

func main() {
	var n int
	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		fmt.Println(err)
		return
	}
	for i := 0; i < n; i++ {
		var x int
		_, err = fmt.Scanf("%d", &x)
		if err != nil {
			fmt.Println(err)
			return
		}
		fmt.Println(x-1, 1)
	}
}

package main

import(
	"fmt"
)

func main(){
	var t int
	_, _ = fmt.Scanf("%d", &t)

	for ; t>0 ; t-- {
		var x int
		_, _ = fmt.Scanf("%d", &x)
		g,l:=1,x-1
		a,b:=g*l/g,g*l/l
		fmt.Println(a,b)

	}
}

package main

import(
	"fmt"
)

func main(){
	var t int
	fmt.Scanf("%d",&t)

	for ; t>0 ; t-- {
		var x int
		fmt.Scanf("%d",&x)
		g,l:=1,x-1
		a,b:=g*l/g,g*l/l
		fmt.Println(a,b)
	}
}

package main

import "fmt"

func main() {
	var T int32
	fmt.Scan(&T)
	for i := int32(0); i < T; i++ {
		var Val int32
		fmt.Scanf("%d", &Val)
		fmt.Println(1, Val-1)
	}
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scanf("%d", &T)
	for i := 0; i < T; i++ {
		var Val int
		fmt.Scanf("%d", &Val)
		fmt.Println(1, Val-1)
	}
}

package main

import "fmt"

func main()  {
	var T, x int
	_, _ = fmt.Scanf("%d", &T)
	for ;T > 0; T-- {
		_, _ = fmt.Scanf("%d",&x)
		fmt.Println(1,x-1)
	}
}


You are given an undirected unweighted connected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.Your task is to find any spanning tree of this graph such that the maximum degree over all vertices is maximum possible. Recall that the degree of a vertex is the number of edges incident to it.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$$$) — the number of vertices and edges, respectively. The following $$$m$$$ lines denote edges: edge $$$i$$$ is represented by a pair of integers $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$), which are the indices of vertices connected by the edge. There are no loops or multiple edges in the given graph, i. e. for each pair ($$$v_i, u_i$$$) there are no other pairs ($$$v_i, u_i$$$) or ($$$u_i, v_i$$$) in the list of edges, and for each pair $$$(v_i, u_i)$$$ the condition $$$v_i \ne u_i$$$ is satisfied.

Print $$$n-1$$$ lines describing the edges of a spanning tree such that the maximum degree over all vertices is maximum possible. Make sure that the edges of the printed spanning tree form some subset of the input edges (order doesn't matter and edge $$$(v, u)$$$ is considered the same as the edge $$$(u, v)$$$). If there are multiple possible answers, print any of them.

NotePicture corresponding to the first example: In this example the number of edges of spanning tree incident to the vertex $$$3$$$ is $$$3$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer.Picture corresponding to the second example: In this example the number of edges of spanning tree incident to the vertex $$$1$$$ is $$$3$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer.Picture corresponding to the third example: In this example the number of edges of spanning tree incident to the vertex $$$2$$$ is $$$4$$$. It is the maximum degree over all vertices of the spanning tree. It is easy to see that we cannot obtain a better answer. But because this example is symmetric, we can choose almost the same spanning tree but with vertex $$$5$$$ instead of $$$2$$$.

package main

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

var pre []int

type Edge struct {
	v, u int
}

func findp(root int) int {
	if pre[root] == root {
		return root
	}
	pre[root] = findp(pre[root])
	return pre[root]
}
func merge(a, b int) bool {
	fa := findp(a)
	fb := findp(b)
	if fa == fb {
		return false
	}
	pre[fa] = fb
	return true
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n,&m)
	edge := make([]*Edge, m)
	cnt := make([]int, n+1)
	pre = make([]int, n+1)
	for i:=0;i < n;i++{
		pre[i+1] = i + 1
	}
	maxv := -1
	for i := 0; i < m; i++ {

		edge[i] = &Edge{
		}
		fmt.Fscanf(buf, "%d %d\n", &edge[i].v, &edge[i].u)
		cnt[edge[i].v]++
		cnt[edge[i].u]++

		if maxv == -1 || cnt[maxv] < cnt[edge[i].v] {
			maxv = edge[i].v
		}
		if maxv == -1 || cnt[maxv] < cnt[edge[i].u] {
			maxv = edge[i].u
		}
	}
	//fmt.Printf("--maxv = %d\n",maxv)
	flag := 0
	for i := 0; flag < n-1 && i < m; i++ {
		if edge[i].v == maxv || edge[i].u == maxv {
			flag++
			fmt.Printf("%d %d\n", edge[i].v, edge[i].u)
			merge(edge[i].v, edge[i].u)
		}
	}
	for i := 0; flag < n-1 && i < m; i++ {
		if edge[i].v == maxv || edge[i].u == maxv {
			continue
		}
		if merge(edge[i].v, edge[i].u) {
			flag++
			fmt.Printf("%d %d\n", edge[i].v, edge[i].u)

		}

	}
}


There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var a, b, c string
	for I(&a, &b, &c) == nil {
		solve(a, b, c)
	}
	w.Flush()
}

func solve(a, b, c string) {
	m := make(map[rune]byte)
	cc := make([]byte, len(c))
	for i, ch := range a {
		m[ch] = b[i]
	}
	for i, ch := range c {
		if o, ok := m[ch]; ok {
			cc[i] = o
		} else if o, ok := m[ch+32]; ok {
			cc[i] = o - 32
		} else {
			cc[i] = c[i]
		}
	}
	O(string(cc), "\n")
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	a := *readString(reader)
	b := *readString(reader)
	s := *readString(reader)

	//fmt.Println(a)
	//fmt.Println(b)
	//fmt.Println(s)

	m := make(map[byte]byte)
	for i:=0; i<len(a); i++ {
		m[a[i]] = b[i]
		m[a[i]-32] = b[i] -32
	}

	for i:=0; i<len(s); i++ {
		c, ok := m[s[i]]
		if !ok {
			fmt.Print(string(s[i]))
		} else {
			fmt.Print(string(c))
		}
	}
	fmt.Println()

}

func readString(nr *bufio.Reader) *string {
	line, _, err := nr.ReadLine()
	if err!=nil {
		panic(err)
	}
	s := string(line)
	return &s
}

func readN() int {
	var a int
	fmt.Scan(&a)
	//a = 100000

	return a
}

func readA(n int) *[]int {
	a := make([]int, n)

	reader := bufio.NewReader(os.Stdin)

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

	return &a
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var a, b, text []byte
	fmt.Fscan(os.Stdin, &a, &b, &text)
	m := make(map[byte]byte)
	for i := range a {
		m[a[i]] = b[i]
		m[a[i] - 32] = b[i] - 32
	}
	for i := range text {
	    if text[i] >= '0' && text[i] <= '9' {
	        fmt.Printf("%c", text[i])
	    } else {
		    fmt.Printf("%c", m[text[i]])
	    }
	}
}

package main

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

func Solve(input io.Reader) (result string) {
	var first []byte
	var second []byte
	var origin []byte
	fmt.Fscan(input, &first, &second, &origin)

	dict := make([]byte, 255)
	for i := range first {
		dict[first[i]] = second[i]
		dict[first[i]-32] = second[i] - 32
	}
	for i := '0'; i <= '9'; i++ {
		dict[i] = byte(i)
	}
	preResult := make([]byte, len(origin))
	for i := range origin {
		preResult[i] = dict[origin[i]]
	}
	result = string(preResult) + "\n"
	return
}

func main() {
	fmt.Print(Solve(os.Stdin))
}

package main

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

func solve() {
	a := readString()
	b := readString()
	text := readString()
	m := make(map[rune]rune)
	for k, v := range a {
		m[v] = rune(b[k])
		m[unicode.ToUpper(v)] = unicode.ToUpper(rune(b[k]))
	}
	var buffer bytes.Buffer
	for _, v := range text {
		if to, ok := m[v]; ok {
			buffer.WriteRune(to)
		} else {
			buffer.WriteRune(v)
		}

	}
	fmt.Println(buffer.String())
}

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
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    layoutA, _ := reader.ReadString('\n')
    layoutB, _ := reader.ReadString('\n')
    text, _ := reader.ReadString('\n')

    mappingA := make(map[rune]int)
    lettersA := strings.Split(layoutA, "")
    for i, s := range lettersA {
        for _, c := range s {
            mappingA[c] = i
        }
    }
    var lettersB []rune
    lettersB = make([]rune, len(lettersA), len(lettersA))
    for i, s := range strings.Split(layoutB, "") {
        for _, c := range s {
            lettersB[i] = c
        }
    }

    for _, c := range text {
        if unicode.IsDigit(c) {
            fmt.Printf("%c", c)
        } else if unicode.IsUpper(c) {
            j := mappingA[unicode.ToLower(c)]
            fmt.Printf("%c", unicode.ToUpper(lettersB[j]))
        } else {
            j := mappingA[c]
            fmt.Printf("%c", lettersB[j])
        }
    }

}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var first, second, result string

	fmt.Scan(&first)
	fmt.Scan(&second)
	fmt.Scan(&result)

	splited := strings.Split(result, "")
	first = strings.ToLower(first)

	var finallText string
	for _, letter := range splited {

		index := strings.Index(first, strings.ToLower(letter))

		if index < 0 {
			finallText += letter
		} else {
			current := string(second[index])
			if letter == strings.ToUpper(letter) {
				current = strings.ToUpper(current)
			}

			finallText += current
		}

	}

	fmt.Println(finallText)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var first, second, result string

	fmt.Scan(&first)
	fmt.Scan(&second)
	fmt.Scan(&result)

	splited := strings.Split(result, "")

	first += "1234567890"
	second += "1234567890"

	var finallText string
	for _, letter := range splited {

		index := strings.Index(first, strings.ToLower(letter))

		if letter == strings.ToUpper(letter) {
			finallText += strings.ToUpper(string(second[index]))
		} else {
			finallText += string(second[index])
		}
	}

	fmt.Println(finallText)
}

package main

import "fmt"
import "strings"

func main() {
	var f1 string
	var f2 string
	var s  string

	var m = make(map[string]string)

	fmt.Scanf("%s\n", &f1)
	fmt.Scanf("%s\n",   &f2)
	fmt.Scanf("%s\n",   &s)

	for i, c := range f1 {
		m[string(c)] = string(f2[i])
		m[strings.ToUpper(string(c))] = strings.ToUpper(string(f2[i]))
	}

	var ret string
	for _, c := range s {
		c2, ok := m[string(c)]
		if ok {
			ret += string(c2)
		} else {
			ret += string(c)
		}
	}

	fmt.Printf("%s\n", ret)
}

package main

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

func main() {
	sc := NewScanner()
	A := sc.NextLine()
	B := sc.NextLine()

	mp := map[byte]byte{}
	for i, v := range []byte(A) {
		mp[v] = B[i]
	}
	C := sc.NextLine()

	for _, v := range []byte(C) {

		t := bytes.ToLower([]byte{v})[0]
		a, ok := mp[t]
		if ok {
			if t != v {
				a = bytes.ToUpper([]byte{a})[0]
			}

			fmt.Print(string(a))
		} else {
			fmt.Print(string(v))
		}
	}
	fmt.Println()

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) 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 *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func fillKeys(keys *map[byte]byte, firstLayout, secondLayout string) {
	*keys = make(map[byte]byte, 0)
	for i := 0; i < len(firstLayout); i++ {
		(*keys)[firstLayout[i]] = secondLayout[i]
	}
}

func correctLayout(keys map[byte]byte, text string) string {
	return strings.Map(func(r rune) rune {
		if val, ok := keys[byte(r)]; ok {
			return rune(val)
		} else if val, ok := keys[byte(unicode.ToLower(r))]; ok {
			return unicode.ToUpper(rune(val))
		}

		return r
	}, text)
}

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

	var keys map[byte]byte
	var firstLayout, secondLayout, text string

	fmt.Fscan(reader, &firstLayout, &secondLayout, &text)

	fillKeys(&keys, firstLayout, secondLayout)

	fmt.Println(correctLayout(keys, text))
}

package main

import (
	"fmt"
)

func upperCase(c rune) bool {
	return (c >= 'A') && (c <= 'Z')
}

func digit(c rune) bool {
	return (c >= '0') && (c <= '9')
}

func main() {

	var pos [26]int
	var kb1 string
	var kb2 string
	var msg string

	// kb1 = "qwertyuiopasdfghjklzxcvbnm"
	// kb2 = "veamhjsgqocnrbfxdtwkylupzi"
	// msg = "TwccpQZAvb2017"

	fmt.Scan(&kb1)
	fmt.Scan(&kb2)
	fmt.Scan(&msg)

	for i, c := range kb1 {
		j := c-'a'
		pos[j] = i
		// pos[0] = i
	}

	for _, c := range msg {
		if (digit(c)) {
			fmt.Printf("%c", c)
		} else if (upperCase(c)) {
			j := c - 'A'
			// fmt.Printf("%c %d\n", c, j)
			fmt.Printf("%c", kb2[pos[j]] - 32)
		} else {
			j := c - 'a'
			// fmt.Printf("%c %d\n", c, j)
			fmt.Printf("%c", kb2[pos[j]])
		}
	}
}

package main

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

func Solve(input io.Reader) (result string) {
	var first []byte
	var second []byte
	var origin []byte
	fmt.Fscan(input, &first, &second, &origin)

	dict := make([]byte, 255)
	for i := range first {
		dict[first[i]] = second[i]
		dict[first[i]-32] = second[i] - 32
	}
	for i := '0'; i < '9'; i++ {
		dict[i] = byte(i)
	}
	preResult := make([]byte, len(origin))
	for i := range origin {
		preResult[i] = dict[origin[i]]
	}
	result = string(preResult) + "\n"
	return
}

func main() {
	fmt.Print(Solve(os.Stdin))
}

package main

import "fmt"
import "strings"

func main() {
	var f1 string
	var f2 string
	var s  string

	var m = make(map[string]string)

	fmt.Scanf("%s\n", &f1)
	fmt.Scanf("%s",   &f2)
	fmt.Scanf("%s",   &s)

	for i, c := range f1 {
		m[string(c)] = string(f2[i])
		m[strings.ToUpper(string(c))] = strings.ToUpper(string(f2[i]))
	}

	var ret string
	for _, c := range s {
		c2, ok := m[string(c)]
		if ok {
			ret += string(c2)
		} else {
			ret += string(c)
		}
	}

	fmt.Printf("%s", ret)
}


IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting.Today, when IA looked at the fridge, she noticed that the word formed by magnets is really messy. "It would look much better when I'll swap some of them!" — thought the girl — "but how to do it?". After a while, she got an idea. IA will look at all prefixes with lengths from $$$1$$$ to the length of the word and for each prefix she will either reverse this prefix or leave it as it is. She will consider the prefixes in the fixed order: from the shortest to the largest. She wants to get the lexicographically smallest possible word after she considers all prefixes. Can you help her, telling which prefixes should be chosen for reversing?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first and the only line contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$), describing the initial string formed by magnets. The string $$$s$$$ consists only of characters 'a' and 'b'.

Output exactly $$$|s|$$$ integers. If IA should reverse the $$$i$$$-th prefix (that is, the substring from $$$1$$$ to $$$i$$$), the $$$i$$$-th integer should be equal to $$$1$$$, and it should be equal to $$$0$$$ otherwise. If there are multiple possible sequences leading to the optimal answer, print any of them.

NoteIn the first example, IA can reverse the second and the third prefix and get a string "abbb". She cannot get better result, since it is also lexicographically smallest string obtainable by permuting characters of the initial string.In the second example, she can reverse any subset of prefixes — all letters are 'a'.

package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	ans := make([]string, len(s))
	for i := range ans {
		ans[i] = "0"
	}

	i := 0
	for ; i < len(s); i++ {
		if s[i] == 'b' {
			break
		}
	}
	last := byte('b')
	for ; i < len(s); i++ {
		if s[i] == last {
			continue
		}
		ans[i-1] = "1"
		last = s[i]
	}
	if last == 'a' {
		ans[i-1] = "1"
	}
	fmt.Println(strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var input string

	fmt.Scan(&input)
	s := input + "b"

	for i := 0; i < (len(s) - 1); i++ {
		if i > 0 {
			fmt.Printf(" ")
		}

		if s[i] != s[i+1] {
			fmt.Printf("1")
		} else {
			fmt.Printf("0")
		}
	}
	fmt.Printf("\n")
}

package main

import "fmt"

func main() {
	var input string
	fmt.Scan(&input)

	word := []byte(input)
	N := len(word)
	doIt := make([]int, N)
	start, end := 0, N-1
	for scope := N - 1; scope > 0; scope-- {
		l, r := start, end
		isReversed := false
		if l > r {
			isReversed = true
			l, r = r, l
		}
		if word[l] == 'b' && word[r] == 'a' ||
			word[l] == 'b' && word[r] == 'b' && isReversed ||
			word[l] == 'a' && word[r] == 'a' && !isReversed {
			reverse(word, l, r)
			doIt[scope] = 1
			start, end = end, start
		}

		if start < end {
			end--
		} else {
			end++
		}
	}
	for _, x := range doIt {
		fmt.Printf("%d ", x)
	}

}

func reverse(word []byte, l, r int) {
	for ; l < r; l, r = l+1, r-1 {
		word[l], word[r] = word[r], word[l]
	}
}

package main

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

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 Reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

var ans []int

func fundi(s string) string {
	if len(s) == 0 {
		return ""
	}

	if s[len(s)-1] == 'b' {
		ans = append(ans, 1)
		return "b" + Reverse(funli(s[:len(s)-1]))
	} else {
		ans = append(ans, 0)
		return fundi(s[:len(s)-1]) + "a"
	}
}

func funli(s string) string {
	if len(s) == 0 {
		return ""
	}

	if s[len(s)-1] == 'a' {
		ans = append(ans, 1)
		return "a" + Reverse(fundi(s[:len(s)-1]))
	} else {
		ans = append(ans, 0)
		return funli(s[:len(s)-1]) + "b"
	}
}

func main() {
	defer writer.Flush()

	var s string
	fmt.Scanln(&s)
	n := len(s)
	//fmt.Print(s)
	ans = make([]int, 0)
	funli(s)

	for i := 0; i < n; i++ {
		fmt.Print(strconv.Itoa(ans[n-i-1]) + " ")
	}

}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()

	N := len(S)

	ans := make([]int, N)
	abMode := true
	for i := 0; i+1 < N; i++ {
		if abMode {
			if S[i+1] == 'a' {
				ans[i] = 1
				abMode = false
			}
		} else {
			if S[i+1] == 'b' {
				ans[i] = 1
				abMode = true
			}
		}
	}
	if !abMode {
		ans[N-1] = 1
	}

	// fwd := make([]string, N)
	// fwdFrom := make([]int, N)
	// fwdRev := make([]int, N)
	// bwd := make([]string, N)
	// bwdFrom := make([]int, N)
	// bwdRev := make([]int, N)
	// for i := 1; i < N; i++ {
	// 	fwd[i] = "omg"
	// 	bwd[i] = "wtf"
	// }
	// fwd[0] = S[:1]
	// bwd[0] = S[:1]

	// // for i := 0; i + 1 < N; i++ {

	// // }

	// for i := 1; i < N; i++ {
	// 	// rf := reverse(fwd[i-1])
	// 	// rb := reverse(bwd[i-1])
	// 	c := S[i : i+1]
	// 	{
	// 		fwdF := fwd[i-1] + c
	// 		if strings.Compare(fwdF, fwd[i]) < 0 {
	// 			fwd[i] = fwdF
	// 		}
	// 		if strings.Compare(reverse(fwdF), reverse(bwd[i])) < 0 {
	// 			bwd[i] = fwdF
	// 		}
	// 	}
	// 	{
	// 		fwdR := reverse(fwd[i-1] + c)
	// 		if strings.Compare(fwdR, fwd[i]) < 0 {
	// 			fwd[i] = fwdR
	// 			fwdRev[i] = 1
	// 		}
	// 		if strings.Compare(reverse(fwdR), reverse(bwd[i])) < 0 {
	// 			bwd[i] = fwdR
	// 			bwdRev[i] = 1
	// 		}
	// 	}
	// 	{
	// 		bwdF := bwd[i-1] + c
	// 		if strings.Compare(bwdF, fwd[i]) < 0 {
	// 			fwd[i] = bwdF
	// 			fwdFrom[i] = 1
	// 		}
	// 		if strings.Compare(reverse(bwdF), reverse(bwd[i])) < 0 {
	// 			bwd[i] = bwdF
	// 			bwdFrom[i] = 1
	// 		}
	// 	}
	// 	{
	// 		bwdR := reverse(bwd[i-1] + c)
	// 		if strings.Compare(bwdR, fwd[i]) < 0 {
	// 			fwd[i] = bwdR
	// 			fwdFrom[i] = 1
	// 			fwdRev[i] = 1
	// 		}
	// 		if strings.Compare(reverse(bwdR), reverse(bwd[i])) < 0 {
	// 			bwd[i] = bwdR
	// 			bwdFrom[i] = 1
	// 			bwdRev[i] = 1
	// 		}
	// 	}

	// 	fmt.Printf("%d: fwd[i] = %s, bwd[i] = %s\n", i, fwd[i], bwd[i])

	// 	// for _, next := range []string{
	// 	// 	fwd[i-1] + c,
	// 	// 	bwd[i-1] + c,
	// 	// } {
	// 	// 	if strings.Compare(next, fwd[i]) < 0 {
	// 	// 		fwd[i] = next
	// 	// 	}
	// 	// 	r := reverse(next)
	// 	// 	if strings.Compare(r, reverse(bwd[i])) < 0 {
	// 	// 		bwd[i] = next
	// 	// 	}
	// 	// }
	// 	// for _, next := range []string{
	// 	// 	c + rf,
	// 	// 	c + rb,
	// 	// } {
	// 	// 	if strings.Compare(next, fwd[i]) < 0 {
	// 	// 		fwd[i] = next
	// 	// 		fwdRev = 1
	// 	// 	}
	// 	// 	r := reverse(next)
	// 	// 	if strings.Compare(r, reverse(bwd[i])) < 0 {
	// 	// 		bwd[i] = next
	// 	// 		bwdRev = 1
	// 	// 	}
	// 	// }
	// }

	// ans := make([]int, N)
	// which := 0
	// for i := N - 1; i >= 0; i-- {
	// 	if which == 0 {
	// 		ans[i] = fwdRev[i]
	// 		which = fwdFrom[i]
	// 	} else {
	// 		ans[i] = bwdRev[i]
	// 		which = bwdFrom[i]
	// 	}
	// }

	for _, v := range ans {
		io.Printf("%d ", v)
	}
	io.Println()
}

func reverse(S string) string {
	A := []rune(S)
	for i, j := 0, len(A)-1; i < j; i, j = i+1, j-1 {
		A[i], A[j] = A[j], A[i]
	}
	return string(A)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

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 Reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

var ans []int

func fundi(s string) string {
	if len(s) == 0 {
		return ""
	}

	if s[len(s)-1] == 'b' {
		ans = append(ans, 1)
		return "b" + Reverse(funli(s[:len(s)-1]))
	} else {
		ans = append(ans, 0)
		return funli(s[:len(s)-1]) + "a"
	}
}

func funli(s string) string {
	if len(s) == 0 {
		return ""
	}

	if s[len(s)-1] == 'a' {
		ans = append(ans, 1)
		return "a" + Reverse(fundi(s[:len(s)-1]))
	} else {
		ans = append(ans, 0)
		return funli(s[:len(s)-1]) + "b"
	}
}

func main() {
	defer writer.Flush()

	var s string
	fmt.Scanln(&s)
	n := len(s)
	//fmt.Print(s)
	ans = make([]int, 0)
	funli(s)

	for i := 0; i < n; i++ {
		fmt.Print(strconv.Itoa(ans[n-i-1]) + " ")
	}

}

package main

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

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 Reverse(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

var ans []int

func fun(s string) string {
	if len(s) == 0 {
		return ""
	}

	ss := fun(s[:len(s)-1])
	rs := string(s[len(s)-1]) + Reverse(ss)
	if rs < s {
		ans = append(ans, 1)
		return rs
	} else {
		ans = append(ans, 0)
		return s
	}

}

func main() {
	defer writer.Flush()

	var s string
	fmt.Scanln(&s)
	n := len(s)
	//fmt.Print(s)
	ans = make([]int, 0)
	fun(s)

	for i := 0; i < n; i++ {
		fmt.Print(strconv.Itoa(ans[i]) + " ")
	}

}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()

	N := len(S)
	fwd := make([]string, N)
	fwdFrom := make([]int, N)
	fwdRev := make([]int, N)
	bwd := make([]string, N)
	bwdFrom := make([]int, N)
	bwdRev := make([]int, N)
	for i := 1; i < N; i++ {
		fwd[i] = "omg"
		bwd[i] = "wtf"
	}
	fwd[0] = S[:1]
	bwd[0] = S[:1]
	for i := 1; i < N; i++ {
		// rf := reverse(fwd[i-1])
		// rb := reverse(bwd[i-1])
		c := S[i : i+1]

		fwdF := fwd[i-1] + c
		if strings.Compare(fwdF, fwd[i]) < 0 {
			fwd[i] = fwdF
		}
		if strings.Compare(reverse(fwdF), reverse(bwd[i])) < 0 {
			bwd[i] = fwdF
		}

		fwdR := c + fwd[i-1]
		if strings.Compare(fwdR, fwd[i]) < 0 {
			fwd[i] = fwdR
			fwdRev[i] = 1
		}
		if strings.Compare(reverse(fwdR), reverse(bwd[i])) < 0 {
			bwd[i] = fwdR
			bwdRev[i] = 1
		}

		bwdF := bwd[i-1] + c
		if strings.Compare(bwdF, fwd[i]) < 0 {
			fwd[i] = bwdF
			fwdFrom[i] = 1
		}
		if strings.Compare(reverse(bwdF), reverse(bwd[i])) < 0 {
			bwd[i] = bwdF
			bwdFrom[i] = 1
		}

		bwdR := c + bwd[i-1]
		if strings.Compare(bwdR, fwd[i]) < 0 {
			fwd[i] = bwdR
			fwdFrom[i] = 1
			fwdRev[i] = 1
		}
		if strings.Compare(reverse(bwdR), reverse(bwd[i])) < 0 {
			bwd[i] = bwdR
			bwdFrom[i] = 1
			bwdRev[i] = 1
		}

		// for _, next := range []string{
		// 	fwd[i-1] + c,
		// 	bwd[i-1] + c,
		// } {
		// 	if strings.Compare(next, fwd[i]) < 0 {
		// 		fwd[i] = next
		// 	}
		// 	r := reverse(next)
		// 	if strings.Compare(r, reverse(bwd[i])) < 0 {
		// 		bwd[i] = next
		// 	}
		// }
		// for _, next := range []string{
		// 	c + rf,
		// 	c + rb,
		// } {
		// 	if strings.Compare(next, fwd[i]) < 0 {
		// 		fwd[i] = next
		// 		fwdRev = 1
		// 	}
		// 	r := reverse(next)
		// 	if strings.Compare(r, reverse(bwd[i])) < 0 {
		// 		bwd[i] = next
		// 		bwdRev = 1
		// 	}
		// }
	}

	ans := make([]int, N)
	which := 0
	for i := N - 1; i >= 0; i-- {
		if which == 0 {
			ans[i] = fwdRev[i]
			which = fwdFrom[i]
		} else {
			ans[i] = bwdRev[i]
			which = bwdFrom[i]
		}
	}

	for _, v := range ans {
		io.Printf("%d ", v)
	}
	io.Println()
}

func reverse(S string) string {
	A := []rune(S)
	for i, j := 0, len(A)-1; i < j; i, j = i+1, j-1 {
		A[i], A[j] = A[j], A[i]
	}
	return string(A)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	S := io.NextLine()

	N := len(S)
	fwd := make([]string, N)
	fwdFrom := make([]int, N)
	fwdRev := make([]int, N)
	bwd := make([]string, N)
	bwdFrom := make([]int, N)
	bwdRev := make([]int, N)
	for i := 1; i < N; i++ {
		fwd[i] = "omg"
		bwd[i] = "wtf"
	}
	fwd[0] = S[:1]
	bwd[0] = S[:1]

	// for i := 0; i + 1 < N; i++ {

	// }

	for i := 1; i < N; i++ {
		// rf := reverse(fwd[i-1])
		// rb := reverse(bwd[i-1])
		c := S[i : i+1]
		{
			fwdF := fwd[i-1] + c
			if strings.Compare(fwdF, fwd[i]) < 0 {
				fwd[i] = fwdF
			}
			if strings.Compare(reverse(fwdF), reverse(bwd[i])) < 0 {
				bwd[i] = fwdF
			}
		}
		{
			fwdR := reverse(fwd[i-1] + c)
			if strings.Compare(fwdR, fwd[i]) < 0 {
				fwd[i] = fwdR
				fwdRev[i] = 1
			}
			if strings.Compare(reverse(fwdR), reverse(bwd[i])) < 0 {
				bwd[i] = fwdR
				bwdRev[i] = 1
			}
		}
		{
			bwdF := bwd[i-1] + c
			if strings.Compare(bwdF, fwd[i]) < 0 {
				fwd[i] = bwdF
				fwdFrom[i] = 1
			}
			if strings.Compare(reverse(bwdF), reverse(bwd[i])) < 0 {
				bwd[i] = bwdF
				bwdFrom[i] = 1
			}
		}
		{
			bwdR := reverse(bwd[i-1] + c)
			if strings.Compare(bwdR, fwd[i]) < 0 {
				fwd[i] = bwdR
				fwdFrom[i] = 1
				fwdRev[i] = 1
			}
			if strings.Compare(reverse(bwdR), reverse(bwd[i])) < 0 {
				bwd[i] = bwdR
				bwdFrom[i] = 1
				bwdRev[i] = 1
			}
		}

		// fmt.Printf("%d: fwd[i] = %s, bwd[i] = %s\n", i, fwd[i], bwd[i])

		// for _, next := range []string{
		// 	fwd[i-1] + c,
		// 	bwd[i-1] + c,
		// } {
		// 	if strings.Compare(next, fwd[i]) < 0 {
		// 		fwd[i] = next
		// 	}
		// 	r := reverse(next)
		// 	if strings.Compare(r, reverse(bwd[i])) < 0 {
		// 		bwd[i] = next
		// 	}
		// }
		// for _, next := range []string{
		// 	c + rf,
		// 	c + rb,
		// } {
		// 	if strings.Compare(next, fwd[i]) < 0 {
		// 		fwd[i] = next
		// 		fwdRev = 1
		// 	}
		// 	r := reverse(next)
		// 	if strings.Compare(r, reverse(bwd[i])) < 0 {
		// 		bwd[i] = next
		// 		bwdRev = 1
		// 	}
		// }
	}

	ans := make([]int, N)
	which := 0
	for i := N - 1; i >= 0; i-- {
		if which == 0 {
			ans[i] = fwdRev[i]
			which = fwdFrom[i]
		} else {
			ans[i] = bwdRev[i]
			which = bwdFrom[i]
		}
	}

	for _, v := range ans {
		io.Printf("%d ", v)
	}
	io.Println()
}

func reverse(S string) string {
	A := []rune(S)
	for i, j := 0, len(A)-1; i < j; i, j = i+1, j-1 {
		A[i], A[j] = A[j], A[i]
	}
	return string(A)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


You found a useless array $$$a$$$ of $$$2n$$$ positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of $$$a$$$.It could have been an easy task, but it turned out that you should follow some rules:   In the beginning, you select any positive integer $$$x$$$. Then you do the following operation $$$n$$$ times:   select two elements of array with sum equals $$$x$$$;  remove them from $$$a$$$ and replace $$$x$$$ with maximum of that two numbers.  For example, if initially $$$a = [3, 5, 1, 2]$$$, you can select $$$x = 6$$$. Then you can select the second and the third elements of $$$a$$$ with sum $$$5 + 1 = 6$$$ and throw them out. After this operation, $$$x$$$ equals $$$5$$$ and there are two elements in array: $$$3$$$ and $$$2$$$. You can throw them out on the next operation.Note, that you choose $$$x$$$ before the start and can't change it as you want between the operations.Determine how should you behave to throw out all elements of $$$a$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$). The second line of each test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \leq a_i \leq 10^6$$$) — the initial array $$$a$$$. It is guaranteed that the total sum of $$$n$$$ over all test cases doesn't exceed $$$1000$$$.

For each test case in the first line print YES if it is possible to throw out all elements of the array and NO otherwise. If it is possible to throw out all elements, print the initial value of $$$x$$$ you've chosen. Print description of $$$n$$$ operations next. For each operation, print the pair of integers you remove.

NoteThe first test case was described in the statement.In the second and third test cases, we can show that it is impossible to throw out all elements of array $$$a$$$.

package main

import (
	"fmt"
	"sort"
)

func main() {
	t := 0
	fmt.Scan(&t)

	for T := 0; T < t; T++ {
		n := 0
		fmt.Scan(&n)

		a := make([]int, 2*n)
		for i := 0; i < len(a); i++ {
			fmt.Scan(&a[i])
		}

		solve(a)
	}
}

type pair [2]int

// MaxInt returns maximum of received int numbers
func MaxInt(nums ...int) int {
	cand := nums[0]
	for _, num := range nums {
		if cand < num {
			cand = num
		}
	}
	return cand
}

func solve(a []int) {
	var (
		need int
		cnt  = make(map[int]int)
		res  = make([]pair, 0)
	)

	update := func(a, b int) {
		cnt[a]--
		cnt[b]--
		need--
		res = append(res, pair{a, b})
	}

	prepare := func() {
		need = len(a) / 2
		res = res[:0]
		for _, x := range a {
			cnt[x] = 0
		}
		for _, x := range a {
			cnt[x]++
		}
	}

	sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
	for _, x := range a {
		cnt[x]++
	}

	for i := 1; i < len(a); i++ {
		prepare()
		res = append(res, pair{a[0] + a[i], 0})
		update(a[0], a[i])
		for i, sum := 0, a[0]; true; {
			for i < len(a) && cnt[a[i]] == 0 {
				i++
			}
			if i == len(a) {
				break
			}
			if a[i] == sum-a[i] && cnt[a[i]] <= 1 {
				break
			}
			if cnt[a[i]] == 0 || cnt[sum-a[i]] == 0 {
				break
			}
			update(a[i], sum-a[i])
			sum = MaxInt(a[i], sum-a[i])
		}

		if need == 0 {
			fmt.Println("YES")
			fmt.Println(res[0][0])
			for i := 1; i < len(res); i++ {
				fmt.Printf("%v %v\n", res[i][0], res[i][1])
			}
			return
		}
	}

	fmt.Println("NO")
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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 sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

type Solver struct {
	a     []int64
	cache map[int64]int64
	n     int64
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		a := make([]int64, n*2)
		for i := range a {
			a[i] = sint64()
		}
		res := (&Solver{a, map[int64]int64{}, n}).Solve()
		if res == nil {
			printf("NO\n")
		} else {
			printf("YES\n")
			printf("%d\n", res[0][0]+res[0][1])
			for _, r := range res {
				printf("%d %d\n", r[0], r[1])
			}
		}
	}
}

func (s *Solver) Solve() [][2]int64 {
	sort.Slice(s.a, func(il, ir int) bool {
		return s.a[il] < s.a[ir]
	})
	for i := range s.a {
		s.cache[s.a[i]]++
	}
	for i := 0; i < len(s.a)-1; i++ {
		res := s.trySolve(i)
		if res != nil {
			return res
		}
	}
	return nil
}

func (s *Solver) trySolve(i int) [][2]int64 {
	l := s.a[i]
	r := s.a[len(s.a)-1]
	tmp := [][2]int64{{l, r}}
	count := map[int64]int64{}
	count[l]++
	count[r]++
	for i := len(s.a) - 2; i >= 0; i-- {
		curr := s.a[i]
		if count[curr] == s.cache[curr] {
			continue
		}
		match := tmp[len(tmp)-1][1] - curr
		count[curr]++
		count[match]++
		if count[match] > s.cache[match] {
			return nil
		}
		tmp = append(tmp, [2]int64{match, curr})
		if int64(len(tmp)) == s.n {
			return tmp
		}
	}
	return tmp
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	out := os.Stdout
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		a := make([]int,2*n)
		for i:=1;i<=2*n;i++{
			fmt.Fscan(in,&a[i-1])
		}
		st := make([]int,2*n)
		copy(st,a)
		sort.Ints(st)
		ans := []int{}
		flag := false
		for i:=0;i<2*n-1;i++ {
			mindex := len(st) - 1
			mp := map[int]int{}
			for j:=0;j<2*n;j++{
				mp[st[j]]++
			}
			mp[st[i]]--
			mp[st[mindex]]--
			ans = []int{}
			ans = append(ans,st[i],st[mindex])
			for j:=1;j<=n-1;j++{
				lstma := st[mindex]
				mindex--
				for mp[st[mindex]]==0{
					mindex--
				}
				nexm := st[mindex]
				if mp[lstma-nexm]==0||(lstma-nexm == nexm && mp[nexm]<=1){
					break
				}else{
					ans = append(ans,nexm,lstma-nexm)
					mp[nexm]--
					mp[lstma-nexm]--

				}
			}
			if len(ans)==2*n{
				flag = true
				break
			}
		}
		if flag{
			fmt.Fprintln(out,"YES")
			fmt.Fprintln(out,ans[0]+ans[1])
			for i:=0;i<2*n;i+=2{
				fmt.Println(ans[i],ans[i+1])
			}
		}else{
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

const (
	MAX = 1e6+10;
)

func solve(n int, a []int)(bool, int, []int, []int){
	d := make([]int, MAX)
	s := make([]int, n)
	t := make([]int, n)

	for i:=1; i<2*n; i++{
		//初始化
		for j:=1; j<2*n; j++{
			d[a[j]]++
		}

		cMax := a[0]
		cx := a[0]+a[i]
		d[a[i]]--

		k := 0
		s[k] = a[0]
		t[k] = a[i]
		k++

		for j:=1; j<2*n; j++{
			if d[a[j]] >0{
				d[a[j]]--
				if d[cMax-a[j]] > 0 {
					d[a[j]]--
					d[cMax-a[j]]--

					s[k] = a[j]
					t[k] = cMax - a[j]

					cMax = a[j]
					k++
				}else{
					break
				}
			}
		}

		if k == n{
			return true, cx, s, t
		}

		//恢复
		for j:=0; j<2*n; j++{
			d[a[j]] = 0
		}
	}

	return false, -1, nil, nil
}

func main(){
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)

	for (t > 0) {
		t--
		fmt.Fscan(in, &n)
		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			fmt.Fscan(in, &a[i])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))

		if ok, x, s, t := solve(n, a); ok {
			fmt.Printf("%s\n%d\n", "YES", x)
			for i := 0; i < n; i++ {
				fmt.Printf("%d %d\n", t[i], s[i])
			}
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		solve()
	}
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	n <<= 1
	a := make([]int, n)
	cnt := make(map[int]int)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		cnt[a[i]]++
	}
	sort.Ints(a)
	for i := 0; i < n-1; i++ {
		if solve1(a, cnt, a[i]) {
			return
		}
	}
	fmt.Fprintln(out, "NO")
}

func solve1(a []int, cnt map[int]int, pp int) bool {
	res := make([][]int, 0)
	n := len(a)
	cc := make(map[int]int)
	cc[a[n-1]]++
	cc[pp]++
	i := n - 2
	x := a[n-1]
	res = append(res, []int{x, pp})
	sum := x + pp
	for i > 0 {
		if cnt[a[i]] <= cc[a[i]] {
			i--
			continue
		}
		cc[a[i]]++
		if cnt[x-a[i]] <= cc[x-a[i]] {
			return false
		}
		res = append(res, []int{a[i], x - a[i]})
		cc[x-a[i]]++
		x = a[i]
		i--
	}
	fmt.Fprintln(out, "YES")
	fmt.Fprintln(out, sum)
	for _, r := range res {
		fmt.Fprintln(out, r[0], r[1])
	}
	return true
}

package main

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

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

	var T, m, v int
O:
	for Fscan(in, &T); T > 0; T-- {
		cnt := map[int]int{}
		Fscan(in, &m)
		for i := 0; i < 2*m; i++ {
			Fscan(in, &v)
			cnt[v]++
		}
		n := len(cnt)
		a := make([]int, 0, n)
		for k := range cnt {
			a = append(a, k)
		}
		sort.Ints(a)
		X := a[n-1]
		cnt[X]--
	o:
		for _, v := range a {
			if cnt[v] == 0 {
				continue
			}
			c := make(map[int]int, n)
			for k, v := range cnt {
				c[k] = v
			}
			ans := append(make([]interface{}, 0, 2*m), X, v)
			c[v]--
			x := X
			for j := n - 1; j >= 0; j-- {
				v := a[j]
				if c[v] == 0 {
					continue
				}
				c[v]--
				if c[x-v] == 0 {
					continue o
				}
				c[x-v]--
				if c[v] > 0 {
					continue o
				}
				ans = append(ans, v, x-v)
				x = v
			}
			Fprintln(out, "YES")
			Fprintln(out, X+v)
			Fprintln(out, ans...)
			continue O
		}
		Fprintln(out, "NO")
	}
}

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

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1e6), 1e6)
}

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 sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

type Solver struct {
	a     []int64
	cache map[int64]int64
	n     int64
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		a := make([]int64, n*2)
		for i := range a {
			a[i] = sint64()
		}
		res := (&Solver{a, map[int64]int64{}, n}).Solve()
		if res == nil {
			printf("NO\n")
		} else {
			printf("YES\n")
			printf("%d\n", res[0][0]+res[0][1])
			for _, r := range res {
				printf("%d %d\n", r[0], r[1])
			}
		}
	}
}

func (s *Solver) Solve() [][2]int64 {
	sort.Slice(s.a, func(il, ir int) bool {
		return s.a[il] < s.a[ir]
	})
	for i := range s.a {
		s.cache[s.a[i]]++
	}
	for i := 0; i < len(s.a)-1; i++ {
		res := s.trySolve(i)
		if res != nil {
			return res
		}
	}
	return nil
}

func (s *Solver) trySolve(i int) [][2]int64 {
	l := s.a[i]
	r := s.a[len(s.a)-1]
	tmp := [][2]int64{{l, r}}
	count := map[int64]int64{}
	count[l]++
	count[r]++
	for i := len(s.a) - 2; i >= 0; i-- {
		curr := s.a[i]
		if count[curr] == s.cache[curr] {
			continue
		}
		match := tmp[len(tmp)-1][1] - curr
		count[curr]++
		count[match]++
		if count[match] > s.cache[match] {
			return nil
		}
		tmp = append(tmp, [2]int64{match, curr})
		if int64(len(tmp)) == s.n {
			return tmp
		}
	}
	return nil
}


Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm!Of course, there is a code lock is installed on the safe. The lock has a screen that displays a string of n lowercase Latin letters. Initially, the screen displays string s. Whitfield and Martin found out that the safe will open when string t will be displayed on the screen.The string on the screen can be changed using the operation «shift x». In order to apply this operation, explorers choose an integer x from 0 to n inclusive. After that, the current string p = αβ changes to βRα, where the length of β is x, and the length of α is n - x. In other words, the suffix of the length x of string p is reversed and moved to the beginning of the string. For example, after the operation «shift 4» the string «abcacb» will be changed with string «bcacab », since α = ab, β = cacb, βR = bcac.Explorers are afraid that if they apply too many operations «shift», the lock will be locked forever. They ask you to find a way to get the string t on the screen, using no more than 6100 operations.

The first line contains an integer n, the length of the strings s and t (1 ≤ n ≤ 2 000). After that, there are two strings s and t, consisting of n lowercase Latin letters each.

If it is impossible to get string t from string s using no more than 6100 operations «shift», print a single number  - 1. Otherwise, in the first line output the number of operations k (0 ≤ k ≤ 6100). In the next line output k numbers xi corresponding to the operations «shift xi» (0 ≤ xi ≤ n) in the order in which they should be applied.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := 0
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func readString() string {
	if !in.Scan() {
		panic(in.Err())
	}
	return in.Text()
}

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

	n := readInt()
	s := readString()
	t := readString()
	var cntS, cntT [256]int
	for _, c := range s {
		cntS[c]++
	}
	for _, c := range t {
		cntT[c]++
	}
	if cntS != cntT {
		fmt.Println(-1)
		return
	}

	buf := []byte(s)
	buf2 := make([]byte, n)
	var ans []int
	for done := 0; done < n; done++ {
		pos := 0
		for buf[pos] != t[done] {
			pos++
		}
		ans = append(ans, n-1-pos, 1, n)
		for i := 0; i < pos; i++ {
			buf2[i] = buf[pos-1-i]
		}
		for i := pos; i < n-1; i++ {
			buf2[i] = buf[i+1]
		}
		buf2[n-1] = buf[pos]
		buf, buf2 = buf2, buf
	}
	fmt.Fprintln(out, len(ans))
	for i := range ans {
		if i+1 == len(ans) {
			fmt.Fprintln(out, ans[i])
		} else {
			fmt.Fprint(out, ans[i], " ")
		}
	}
}

package main

import (
	"fmt"
)

func shift(b []byte, n int) []byte {
	ret := make([]byte, 0, len(b))
	for i := len(b) - 1; i > len(b) - 1 - n; i -- {
		ret = append(ret, b[i])
	}
	ret = append(ret, b[:(len(b) - n)]...)
	return ret
}

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

	bs := []byte(s)

	mid := n / 2
	flag := true
	ans := make([]int, 0, 6100)
	for i := 0;i < n;i ++ {
		if t[mid] == bs[i] {
			bs = shift(bs, n - i - 1)
			if n - i - 1 != 0 {
				ans = append(ans, n - i - 1)
			}
			bs = shift(bs, 1)
			ans = append(ans, 1)
			flag = false
			break
		}
	}
	if flag {
		fmt.Printf("-1")
		return
	}
	left, right, reversed := mid, mid, false

	for left != 0 || right != n - 1 {
		var target byte = '\n'
		if !reversed && left != 0 {
			target = t[left - 1]
		} else if reversed && right != n - 1 {
			target = t[right + 1]
		}
		if target != '\n' {
			flag := true
			for i := right - left + 1;i < n;i ++ {
				if target == bs[i] {
					if n - i != 0 {
						bs = shift(bs, n - i)
						ans = append(ans, n - i)
					}
					if i - right + left - 1 != 0 {
						bs = shift(bs, i - right + left - 1)
						ans = append(ans, i - right + left - 1)
					}
					bs = shift(bs, n)
					ans = append(ans, n)
					if reversed {
						right ++
					} else {
						left --
					}
					reversed = !reversed
					flag = false
					break
				}
			}
			if flag {
				fmt.Printf("-1")
				return
			}
		} else {
			if n - right + left - 1 != 0 {
				bs = shift(bs, n - right + left - 1)
				ans = append(ans, n - right + left - 1)
			}
			bs = shift(bs, n)
			ans = append(ans, n - right + left - 1, n)
			reversed = !reversed
		}
	}
	if reversed {
		bs = shift(bs, n)
		ans = append(ans, n)
	}
	fmt.Printf("%d\n", len(ans))
	for i := 0;i < len(ans);i ++ {
		fmt.Printf("%d ", ans[i])
	}
}


Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy's family is a bit weird so all the clothes is enumerated. For example, each of Arseniy's n socks is assigned a unique integer from 1 to n. Thus, the only thing his mother had to do was to write down two integers li and ri for each of the days — the indices of socks to wear on the day i (obviously, li stands for the left foot and ri for the right). Each sock is painted in one of k colors.When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses k jars with the paint — one for each of k colors.Arseniy wants to repaint some of the socks in such a way, that for each of m days he can follow the mother's instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now.The new computer game Bota-3 was just realised and Arseniy can't wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother's instructions and wear the socks of the same color during each of m days.

The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively. The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks. Each of the following m lines contains two integers li and ri (1 ≤ li, ri ≤ n, li ≠ ri) — indices of socks which Arseniy should wear during the i-th day.

Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.

NoteIn the first sample, Arseniy can repaint the first and the third socks to the second color.In the second sample, there is no need to change any colors.

package main

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

func solve() {
    n, m, _ := readInt(), readInt(), readInt()
    a, c := make([][]int, n), readIntArray(n)
    for i := 0; i < m; i++ {
        l, r := readInt()-1, readInt()-1
        a[l], a[r] = append(a[l], r), append(a[r], l)
    }
    was, ans := make([]bool, n), 0
    for s := range c {
        if was[s] {
            continue
        }
        was[s] = true
        cnts, mx, mxC := make(map[int]int), -1, 0
        for q := []int{s}; len(q) > 0; {
            cur := q[len(q)-1]
            q = q[:len(q)-1]
            for _, v := range a[cur] {
                if !was[v] {
                    q, was[v] = append(q, v), true
                }
            }
            col := c[cur]
            cnts[col]++
            if cnt := cnts[col]; cnt > mx {
                mx, mxC = cnt, col
            }
        }
        for k, v := range cnts {
            if k != mxC {
                ans += v
            }
        }
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

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

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

var bufin *bufio.Reader
var bufout *bufio.Writer

var n, m, k, E int
var c, adj, next, last, cols []int
var vst []bool

func add(u int, v int) {
	adj[E] = v
	next[E] = last[u]
	last[u] = E
	E++
}

func dfs(u int) {
	vst[u] = true
	cols = append(cols, c[u])
	for i := last[u]; i != -1; i = next[i] {
		v := adj[i]
		if !vst[v] {
			dfs(v)
		}
	}
}

func repaint(u int) int {
	cols = make([]int, 0)
	dfs(u)

	sort.Ints(cols)

	most := 0
	nc := len(cols)

	for i := 0; i < nc; i++ {
		j := i
		for (j < nc) && (cols[j] == cols[i]) {
			j++
		}
		if most < j-i {
			most = j - i
		}
		i = j - 1
	}

	return nc - most
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

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

	adj = make([]int, 2*m+1)
	next = make([]int, 2*m+1)
	last = make([]int, n+1)
	vst = make([]bool, n+1)

	E = 0
	for i := 0; i <= n; i++ {
		last[i] = -1
		vst[i] = false
	}

	var u, v int
	for i := 0; i < m; i++ {
		fmt.Fscanf(bufin, "%d %d\n", &u, &v)
		add(u, v)
		add(v, u)
	}

	res := 0
	for u := 1; u <= n; u++ {
		if !vst[u] {
			res += repaint(u)
		}
	}

	fmt.Fprintf(bufout, "%d\n", res)
}