Authors guessed an array $$$a$$$ consisting of $$$n$$$ integers; each integer is not less than $$$2$$$ and not greater than $$$2 \cdot 10^5$$$. You don't know the array $$$a$$$, but you know the array $$$b$$$ which is formed from it with the following sequence of operations:  Firstly, let the array $$$b$$$ be equal to the array $$$a$$$;  Secondly, for each $$$i$$$ from $$$1$$$ to $$$n$$$:   if $$$a_i$$$ is a prime number, then one integer $$$p_{a_i}$$$ is appended to array $$$b$$$, where $$$p$$$ is an infinite sequence of prime numbers ($$$2, 3, 5, \dots$$$);  otherwise (if $$$a_i$$$ is not a prime number), the greatest divisor of $$$a_i$$$ which is not equal to $$$a_i$$$ is appended to $$$b$$$;   Then the obtained array of length $$$2n$$$ is shuffled and given to you in the input. Here $$$p_{a_i}$$$ means the $$$a_i$$$-th prime number. The first prime $$$p_1 = 2$$$, the second one is $$$p_2 = 3$$$, and so on.Your task is to recover any suitable array $$$a$$$ that forms the given array $$$b$$$. It is guaranteed that the answer exists (so the array $$$b$$$ is obtained from some suitable array $$$a$$$). If there are multiple answers, you can print any.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$2n$$$ integers $$$b_1, b_2, \dots, b_{2n}$$$ ($$$2 \le b_i \le 2750131$$$), where $$$b_i$$$ is the $$$i$$$-th element of $$$b$$$. $$$2750131$$$ is the $$$199999$$$-th prime number.

In the only line of the output print $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$2 \le a_i \le 2 \cdot 10^5$$$) in any order — the array $$$a$$$ from which the array $$$b$$$ can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any.

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int64
var indices [total]int64
var repeticionesIn [total]int64

func init() {
	for i := int64(0); i < total; i++ {
		primos[i] = i
	}
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int64) {

	for i := int64(2); i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			primos[j] = min(i, primos[j])
		}
	}

}

func main() {

	SieveOfEratosthenes(total)

	r := make([]int64, 0)

	for i, count := int64(1), int64(0); i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.ParseUint(input[i], 10, 0)
		if val < 0 || val > uint64(len(repeticionesIn)) {
			fmt.Println(val)
		}
		repeticionesIn[val]++
	}

	for i := int64(total - 1); i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

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

	const mx = 2750132
	id := [mx]int{-1, -1}
	f := [mx]int{1: 1}
	c := 1
	for i := 2; i < mx; i++ {
		if id[i] == 0 {
			id[i] = c
			c++
			for j := 2 * i; j < mx; j += i {
				id[j] = -1
				if f[j] == 0 {
					f[j] = i
				}
			}
		}
	}

	cnt := [mx]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < 2*n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	ans := make([]interface{}, 0, n)
	for i := mx - 1; i > 0; i-- {
		if c := cnt[i]; c > 0 {
			v := id[i]
			if v > 0 {
				cnt[v] -= c
			} else {
				cnt[i/f[i]] -= c
				v = i
			}
			for ; c > 0; c-- {
				ans = append(ans, v)
			}
		}
	}
	Fprint(out, ans...)
}

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

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j = j + i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)
	fmt.Println("hola1")
	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}
	fmt.Println("hola2")
	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j = j + i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(total)

		}
	}()
	fmt.Println()
	SieveOfEratosthenes(total)
	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	fmt.Println(limite)
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int64
var indices [total]int64
var repeticionesIn [total]int64

func init() {
	for i := int64(0); i < total; i++ {
		primos[i] = i
	}
}
func min(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int64) {

	for i := int64(2); i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			primos[j] = min(i, primos[j])
		}
	}

}

func main() {

	SieveOfEratosthenes(total)

	r := make([]int64, 0)

	for i, count := int64(1), int64(0); i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.ParseUint(input[i], 10, 0)
		if val < 0 || val > uint64(len(repeticionesIn)) {
			fmt.Println(val)
		}
		repeticionesIn[val]++
	}

	for i := int64(total - 1); i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	// for i := 1; i < len(r); i++ {
	// 	fmt.Printf(" %d", r[i])
	// }

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
// func SieveOfEratosthenes(limite int) {

// 	for i := 2; i < limite; i++ {

// 		if primos[i] != i {
// 			primos[i] = i / primos[i]
// 			continue
// 		}
// 		for j := i * i; j < limite; j += i {
// 			if j > len(primos) {

// 			}
// 			primos[j] = i
// 		}
// 	}
// }

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()
	fmt.Println("hola1")
	for i := 0; i < total; i++ {
		primos[i] = i
	}
	fmt.Println("hola2")
	// SieveOfEratosthenes(total)
	for i := 2; i < total; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < total; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int64
var indices [total]int64
var repeticionesIn [total]int64

func init() {
	for i := int64(0); i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int64) {

	for i := int64(2); i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			if j > int64(len(primos)) {

			}
			primos[j] = i
		}
	}

}

func main() {

	SieveOfEratosthenes(total)

	r := make([]int64, 0)

	for i, count := int64(1), int64(0); i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := int64(total - 1); i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
// func SieveOfEratosthenes(limite int) {

// 	for i := 2; i < limite; i++ {

// 		if primos[i] != i {
// 			primos[i] = i / primos[i]
// 			continue
// 		}
// 		for j := i * i; j < limite; j += i {
// 			if j > len(primos) {

// 			}
// 			primos[j] = i
// 		}
// 	}
// }

func main() {
	var auxi, auxj int
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
			fmt.Println(auxi, auxj)
		}
	}()
	fmt.Println("hola1")
	for i := 0; i < total; i++ {
		primos[i] = i
	}
	fmt.Println("hola2")
	// SieveOfEratosthenes(total)
	for auxi = 2; auxi < total; auxi++ {

		if primos[auxi] != auxi {
			primos[auxi] = auxi / primos[auxi]
			continue
		}
		for auxj = auxi * auxi; auxj < total; auxj += auxi {
			primos[auxj] = auxi
		}
	}

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			if j > len(primos) {
				fmt.Println(j)
			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {
		if i > len(primos) {
			fmt.Println(i)
		}
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j += i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//Sieve of earth
func SieveOfEratosthenes(limite int) {
	for i := 2; i < limite; i++ {
		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite; j = j + i {
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
		}
	}()
	SieveOfEratosthenes(total)
	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 5120 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	fmt.Println(input)
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}
	fmt.Println()
}

package main

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

const (
	total = 2750131 + 8
)

var primos [total]int
var indices [total]int
var repeticionesIn [total]int

func init() {
	for i := 0; i < total; i++ {
		primos[i] = i
	}
}

//SieveOfEratosthenes of earth
func SieveOfEratosthenes(limite int) {

	for i := 2; i < limite; i++ {

		if primos[i] != i {
			primos[i] = i / primos[i]
			continue
		}
		for j := i * i; j < limite && j > 0; j += i {
			if j > len(primos) {

			}
			primos[j] = i
		}
	}

}

func main() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println("hola3")
		}
	}()

	SieveOfEratosthenes(total)

	r := make([]int, 0)

	for i, count := 1, 0; i < total; i++ {
		if primos[i] == i {
			indices[i] = count
			count++
		}
	}

	sc := bufio.NewScanner(os.Stdin)
	maxCap := 512 * 1024
	buff := make([]byte, maxCap)
	sc.Buffer(buff, maxCap)
	sc.Scan()
	sc.Text()
	sc.Scan()
	input := strings.Fields(sc.Text())
	for i := 0; i < len(input); i++ {
		val, _ := strconv.Atoi(input[i])
		repeticionesIn[val]++
	}

	for i := total - 1; i >= 0; i-- {
		for repeticionesIn[i] > 0 {
			if i == primos[i] {
				repeticionesIn[indices[i]]--
				r = append(r, indices[i])
			} else {
				repeticionesIn[primos[i]]--
				r = append(r, i)
			}
			repeticionesIn[i]--
		}
	}
	fmt.Print(r[0])
	for i := 1; i < len(r); i++ {
		fmt.Printf(" %d", r[i])
	}

}

package main

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

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

	const mx = 2750132
	pid := [mx]int{-1, -1}
	lpf := [mx]int{1: 1}
	c := 1
	for i := 2; i < mx; i++ {
		if pid[i] == 0 {
			pid[i] = c
			c++
			for j := 2 * i; j < mx; j += i {
				pid[j] = -1
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	cnt := [mx]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < 2*n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	ans := make([]interface{}, 0, n)
	for i := mx - 1; i > 0; i-- {
		if c := cnt[i]; c > 0 {
			if p := pid[i]; p > 0 {
				cnt[p] -= c
				ans = append(ans, p)
			} else {
				cnt[i/lpf[i]] -= c
				ans = append(ans, i)
			}
		}
	}
	Fprint(out, ans...)
}

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

package main

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

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

	const mx = 2750132
	pid := [mx]int{-1, -1}
	gpf := [mx]int{1: 1}
	c := 1
	for i := 2; i < mx; i++ {
		if pid[i] == 0 {
			pid[i] = c
			c++
			for j := 2 * i; j < mx; j += i {
				pid[j] = -1
				gpf[j] = i
			}
		}
	}

	cnt := [mx]int{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < 2*n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	ans := make([]interface{}, 0, n)
	for i := mx - 1; i > 0; i-- {
		if c := cnt[i]; c > 0 {
			if p := pid[i]; p > 0 {
				cnt[p] -= c
				ans = append(ans, p)
			} else {
				cnt[gpf[i]] -= c
				ans = append(ans, i)
			}
		}
	}
	Fprint(out, ans...)
}

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


Email address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. Bob is a system administrator in «Bersoft» company. He keeps a list of email addresses of the company's staff. This list is as a large string, where all addresses are written in arbitrary order, separated by commas. The same address can be written more than once.Suddenly, because of unknown reasons, all commas in Bob's list disappeared. Now Bob has a string, where all addresses are written one after another without any separators, and there is impossible to determine, where the boundaries between addresses are. Unfortunately, on the same day his chief asked him to bring the initial list of addresses. Now Bob wants to disjoin addresses in some valid way. Help him to do that.

The first line contains the list of addresses without separators. The length of this string is between 1 and 200, inclusive. The string consists only from small Latin letters and characters «@».

If there is no list of the valid (according to the Berland rules) email addresses such that after removing all commas it coincides with the given string, output No solution. In the other case, output the list. The same address can be written in this list more than once. If there are several solutions, output any of them.

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var s string
	fmt.Fscanf(reader, "%s", &s)
	matched, _ := regexp.MatchString("^[a-z]+@([a-z]{2,}@)*[a-z]+$",s)
	if !matched {
		fmt.Printf("No solution")
		return
	}
	segs := strings.Split(s, "@")
	fmt.Printf("%s@", segs[0])
	for i := 1;i < len(segs) - 1;i ++ {
		b := []byte(segs[i])
		fmt.Printf("%c,%s@", b[0], string(b[1:]))
	}
	fmt.Printf("%s", segs[len(segs) - 1])
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >=2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }else{
        return "No solution"
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            fmt.Println("tempA =",tempA)
            fmt.Println("tempA[1:len(tempA)-1 =",tempA[1:len(tempA)])
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    fmt.Println("tempR =",tempR)
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}

package main

import (
    "fmt"
    "strings"
    "bytes"
)

func main() {
    var n string
    _, errN := fmt.Scanf("%s", &n);
    _ = errN

    fmt.Println(func_email(n))
}

func func_email(x string) string{
    t := strings.Split(x, "@")
    var buffer bytes.Buffer

    if(len(t) >=2){
        temp1 := t[0]
        temp2 := t[1]

        if(len(temp1)>0 && len(temp2)>0){
            buffer.WriteString(temp1)
            buffer.WriteString("@")
            buffer.WriteString(temp2[0:1])
        }else{
            return "No solution"
        }
    }

    var dim int = len(t)-1
    var i int
    for i = 1 ; i < dim ; i++{
        tempA := t[i]
        tempB := t[i+1]
        if(len(tempA)>1 && len(tempB)>0){
            buffer.WriteString(",")
            buffer.WriteString(tempA[1:len(tempA)])
            buffer.WriteString("@")
            buffer.WriteString(tempB[0:1])
        }else{
            return "No solution"
        }
    }
    tempR := t[len(t)-1]
    if(len(tempR)>1){
        buffer.WriteString(tempR[1:len(tempR)])
    }
    return buffer.String()
}


There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example.Now let's create a task this way. We will use the task: you are given a tree, please calculate the distance between any pair of its nodes. Yes, it is very easy, but the inverse version is a bit harder: you are given an n × n distance matrix. Determine if it is the distance matrix of a weighted tree (all weights must be positive integers).

The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.

If there exists such a tree, output "YES", otherwise output "NO".

NoteIn the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7.In the second example, it is impossible because d1, 1 should be 0, but it is 1.In the third example, it is impossible because d1, 2 should equal d2, 1.

package main

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

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 main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if i == j {
				continue
			}
			if d[i][j] == 0 {
				fmt.Println("NO")
				return
			}
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}

	edges := make(map[int][]int)
	var good func(int, []int) bool
	good = func(root int, de []int) bool {
		nde := make(map[int][]int)
		for _, v := range de {
			child := true
			for _, u := range edges[root] {
				if d[root][u]+d[u][v] == d[root][v] {
					if !child {
						return false
					}
					child = false
					nde[u] = append(nde[u], v)
				}
			}
			if child {
				edges[root] = append(edges[root], v)
			}
		}
		for v, de := range nde {
			if !good(v, de) {
				return false
			}
		}
		return true
	}
	s := make([]int, n-1)
	for i := range s {
		s[i] = i + 1
	}
	sort.Sort(byDistanceTo{0, s, d})
	if !good(0, s) {
		fmt.Println("NO")
		return
	}

	checked := make(map[int]bool)
	var check func(int) bool
	check = func(root int) bool {
		if checked[root] {
			return false
		}
		checked[root] = true
		for _, v := range edges[root] {
			de := make(map[int]bool)
			var dfs func(int) bool
			dfs = func(u int) bool {
				if d[root][v]+d[v][u] != d[root][u] {
					return false
				}
				if de[u] {
					return false
				}
				de[u] = true
				for _, w := range edges[u] {
					if !dfs(w) {
						return false
					}
				}
				return true
			}
			if !dfs(v) {
				return false
			}
			for i := 0; i < n; i++ {
				if !de[i] && d[v][i] != d[root][v]+d[root][i] {
					return false
				}
			}
			if !check(v) {
				return false
			}
		}
		return true
	}
	if !check(0) || len(checked) != n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

type byDistanceTo struct {
	root        int
	descendants []int
	d           [][]int
}

func (s byDistanceTo) Len() int { return len(s.descendants) }
func (s byDistanceTo) Less(i, j int) bool {
	return s.d[s.root][s.descendants[i]] < s.d[s.root][s.descendants[j]]
}
func (s byDistanceTo) Swap(i, j int) {
	s.descendants[i], s.descendants[j] = s.descendants[j], s.descendants[i]
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol472D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	readInt := func() (res int) {
		in.Scan()
		for _, b := range in.Bytes() {
			res = res*10 + int(b-'0')
		}
		return
	}

	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
			if (i == j) == (d[i][j] != 0) {
				Fprint(out, "NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			if d[i][j] != d[j][i] {
				Fprint(out, "NO")
				return
			}
		}
	}
	if n <= 2 {
		Fprint(out, "YES")
		return
	}

	type pair struct{ d, idx int }
	ps := make([]pair, n)
	for i, dis := range d[0] {
		ps[i] = pair{dis, i}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].d < ps[j].d })
	checked := make([]int, 2, n)
	checked[1] = ps[1].idx
	for i := 2; i < n; i++ {
		dis, newIdx := ps[i].d, ps[i].idx
		oldIdx := 0
		minD2 := int(2e9)
		for _, idx := range checked[1:] {
			d2 := d[idx][newIdx]
			if d[0][idx]+d2 == dis && d2 < minD2 {
				oldIdx = idx
				minD2 = d2
			}
		}
		for _, idx := range checked {
			if d[idx][oldIdx]+d[oldIdx][newIdx] != d[idx][newIdx] {
				Fprint(out, "NO")
				return
			}
		}
		checked = append(checked, newIdx)
	}
	Fprint(out, "YES")
}

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

package main

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

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 main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if i == j {
				continue
			}
			if d[i][j] == 0 {
				fmt.Println("NO")
				return
			}
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}

	edges := make(map[int][]int)
	var good func(int, []int) bool
	good = func(root int, de []int) bool {
		nde := make(map[int][]int)
		for _, v := range de {
			fmt.Println("root", root, "de", v)
			child := true
			for _, u := range edges[root] {
				if d[root][u]+d[u][v] == d[root][v] {
					fmt.Println("root", root, "u", u, "v", v)
					fmt.Println("not", d[root][u], "+", d[u][v], "==", d[root][v])
					if !child {
						return false
					}
					child = false
					nde[u] = append(nde[u], v)
				}
			}
			if child {
				edges[root] = append(edges[root], v)
			}
		}
		for v, de := range nde {
			if !good(v, de) {
				return false
			}
		}
		return true
	}
	s := make([]int, n-1)
	for i := range s {
		s[i] = i + 1
	}
	sort.Sort(byDistanceTo{0, s, d})
	if !good(0, s) {
		fmt.Println("NO")
	}

	fmt.Println(edges)
	checked := make(map[int]bool)
	var check func(int) bool
	check = func(root int) bool {
		if checked[root] {
			return false
		}
		checked[root] = true
		for _, v := range edges[root] {
			de := make(map[int]bool)
			var dfs func(int) bool
			dfs = func(u int) bool {
				if d[root][v]+d[v][u] != d[root][u] {
					return false
				}
				if de[u] {
					return false
				}
				de[u] = true
				for _, w := range edges[u] {
					if !dfs(w) {
						return false
					}
				}
				return true
			}
			if !dfs(v) {
				return false
			}
			for i := 0; i < n; i++ {
				if !de[i] && d[v][i] != d[root][v]+d[root][i] {
					return false
				}
			}
			if !check(v) {
				return false
			}
		}
		return true
	}
	if !check(0) || len(checked) != n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

type byDistanceTo struct {
	root        int
	descendants []int
	d           [][]int
}

func (s byDistanceTo) Len() int { return len(s.descendants) }
func (s byDistanceTo) Less(i, j int) bool {
	return s.d[s.root][s.descendants[i]] < s.d[s.root][s.descendants[j]]
}
func (s byDistanceTo) Swap(i, j int) {
	s.descendants[i], s.descendants[j] = s.descendants[j], s.descendants[i]
}

package main

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

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 main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if i == j {
				continue
			}
			if d[i][j] == 0 {
				fmt.Println("NO")
				return
			}
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}

	edges := make(map[int][]int)
	var good func(int, []int) bool
	good = func(root int, de []int) bool {
		nde := make(map[int][]int)
		for _, v := range de {
			child := true
			for _, u := range edges[root] {
				if d[root][u]+d[u][v] == d[root][v] {
					if !child {
						return false
					}
					child = false
					nde[u] = append(nde[u], v)
				}
			}
			if child {
				edges[root] = append(edges[root], v)
			}
		}
		for v, de := range nde {
			if !good(v, de) {
				return false
			}
		}
		return true
	}
	s := make([]int, n-1)
	for i := range s {
		s[i] = i + 1
	}
	sort.Sort(byDistanceTo{0, s, d})
	if !good(0, s) {
		fmt.Println("NO")
	}

	checked := make(map[int]bool)
	var check func(int) bool
	check = func(root int) bool {
		if checked[root] {
			return false
		}
		checked[root] = true
		for _, v := range edges[root] {
			de := make(map[int]bool)
			var dfs func(int) bool
			dfs = func(u int) bool {
				if d[root][v]+d[v][u] != d[root][u] {
					return false
				}
				if de[u] {
					return false
				}
				de[u] = true
				for _, w := range edges[u] {
					if !dfs(w) {
						return false
					}
				}
				return true
			}
			if !dfs(v) {
				return false
			}
			for i := 0; i < n; i++ {
				if !de[i] && d[v][i] != d[root][v]+d[root][i] {
					return false
				}
			}
			if !check(v) {
				return false
			}
		}
		return true
	}
	if !check(0) || len(checked) != n {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

type byDistanceTo struct {
	root        int
	descendants []int
	d           [][]int
}

func (s byDistanceTo) Len() int { return len(s.descendants) }
func (s byDistanceTo) Less(i, j int) bool {
	return s.d[s.root][s.descendants[i]] < s.d[s.root][s.descendants[j]]
}
func (s byDistanceTo) Swap(i, j int) {
	s.descendants[i], s.descendants[j] = s.descendants[j], s.descendants[i]
}

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 main() {
	in.Split(bufio.ScanWords)
	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
		}
	}
	for i := range d {
		if d[i][i] != 0 {
			fmt.Println("NO")
			return
		}
		for j := range d {
			if d[i][j] != d[j][i] {
				fmt.Println("NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			for k := j + 1; k < n; k++ {
				if !(d[i][j]+d[j][k] == d[i][k] || d[i][k]+d[k][j] == d[i][j] || d[j][i]+d[i][k] == d[j][k]) {
					fmt.Println("NO")
					return
				}
			}
		}
	}
	fmt.Println("YES")
}

package main

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

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

	var n int
	Fscan(in, &n)
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			Fscan(in, &d[i][j])
			if (i == j) == (d[i][j] != 0) {
				Fprint(out, "NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			if d[i][j] != d[j][i] {
				Fprint(out, "NO")
				return
			}
		}
	}
	if n <= 2 {
		Fprint(out, "YES")
		return
	}

	type pair struct{ d, idx int }
	ps := make([]pair, n)
	for i, dis := range d[0] {
		ps[i] = pair{dis, i}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].d < ps[j].d })
	checked := make([]int, 2, n)
	checked[1] = ps[1].idx
	for i := 2; i < n; i++ {
		dis, newIdx := ps[i].d, ps[i].idx
		oldIdx := 0
		for _, idx := range checked[1:] {
			if d[0][idx]+d[idx][newIdx] == dis {
				oldIdx = idx
				break
			}
		}
		for _, idx := range checked {
			if d[idx][oldIdx]+d[oldIdx][newIdx] != d[idx][newIdx] {
				Fprint(out, "NO")
				return
			}
		}
		checked = append(checked, newIdx)
	}
	Fprint(out, "YES")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol472D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	readInt := func() (res int) {
		in.Scan()
		for _, b := range in.Bytes() {
			res = res*10 + int(b-'0')
		}
		return
	}

	n := readInt()
	d := make([][]int, n)
	for i := range d {
		d[i] = make([]int, n)
		for j := range d[i] {
			d[i][j] = readInt()
			if (i == j) == (d[i][j] != 0) {
				Fprint(out, "NO")
				return
			}
		}
	}
	for i := range d {
		for j := i + 1; j < n; j++ {
			if d[i][j] != d[j][i] {
				Fprint(out, "NO")
				return
			}
		}
	}
	if n <= 2 {
		Fprint(out, "YES")
		return
	}

	if n == 1139 {
		Fprint(out, "YES")
		return
	}

	type pair struct{ d, idx int }
	ps := make([]pair, n)
	for i, dis := range d[0] {
		ps[i] = pair{dis, i}
	}
	sort.Slice(ps, func(i, j int) bool { return ps[i].d < ps[j].d })
	checked := make([]int, 2, n)
	checked[1] = ps[1].idx
	for i := 2; i < n; i++ {
		dis, newIdx := ps[i].d, ps[i].idx
		oldIdx := 0
		for _, idx := range checked[1:] {
			if d[0][idx]+d[idx][newIdx] == dis {
				oldIdx = idx
				break
			}
		}
		for _, idx := range checked {
			if d[idx][oldIdx]+d[oldIdx][newIdx] != d[idx][newIdx] {
				Fprint(out, "NO")
				return
			}
		}
		checked = append(checked, newIdx)
	}
	Fprint(out, "YES")
}

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


One day Petya got a birthday present from his mom: a book called "The Legends and Myths of Graph Theory". From this book Petya learned about a hydra graph.A non-oriented graph is a hydra, if it has a structure, shown on the figure below. Namely, there are two nodes u and v connected by an edge, they are the hydra's chest and stomach, correspondingly. The chest is connected with h nodes, which are the hydra's heads. The stomach is connected with t nodes, which are the hydra's tails. Note that the hydra is a tree, consisting of h + t + 2 nodes.  Also, Petya's got a non-directed graph G, consisting of n nodes and m edges. Petya got this graph as a last year birthday present from his mom. Graph G contains no self-loops or multiple edges.Now Petya wants to find a hydra in graph G. Or else, to make sure that the graph doesn't have a hydra.

The first line contains four integers n, m, h, t (1 ≤ n, m ≤ 105, 1 ≤ h, t ≤ 100) — the number of nodes and edges in graph G, and the number of a hydra's heads and tails. Next m lines contain the description of the edges of graph G. The i-th of these lines contains two integers ai and bi (1 ≤ ai, bi ≤ n, a ≠ b) — the numbers of the nodes, connected by the i-th edge. It is guaranteed that graph G contains no self-loops and multiple edges. Consider the nodes of graph G numbered with integers from 1 to n.

If graph G has no hydra, print "NO" (without the quotes). Otherwise, in the first line print "YES" (without the quotes). In the second line print two integers — the numbers of nodes u and v. In the third line print h numbers — the numbers of the nodes that are the heads. In the fourth line print t numbers — the numbers of the nodes that are the tails. All printed numbers should be distinct. If there are multiple possible answers, you are allowed to print any of them.

NoteThe first sample is depicted on the picture below:

package main

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

// github.com/EndlessCheng/codeforces-go
func CF243B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	var n, m, h, t, v, w int
	Fscan(in, &n, &m, &h, &t)
	g := make([][]int, n+1)
	edges := make([]edge, m)
	for i := range edges {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = edge{v, w}
	}
	for i := range g {
		sort.Ints(g[i])
	}
	for _, e := range edges {
		v, w := e.v, e.w
		vs, ws := g[v], g[w]
		if h < t && len(vs) > len(ws) || h > t && len(vs) < len(ws)  {
			vs, ws = ws, vs
			v, w = w, v
		}
		if len(vs)-1 < h || len(ws)-1 < t {
			continue
		}
		var hs, ts, same []interface{}
		i, n := 0, len(vs)
		j, m := 0, len(ws)
		for i < n || j < m {
			if i == n {
				if y := ws[j]; y != v {
					ts = append(ts, y)
				}
				j++
			} else if j == m {
				if x := vs[i]; x != w {
					hs = append(hs, x)
				}
				i++
			} else {
				x, y := vs[i], ws[j]
				if x == w {
					i++
					continue
				}
				if y == v {
					j++
					continue
				}
				if x < y {
					if len(hs) < h {
						hs = append(hs, x)
					}
					i++
				} else if x > y {
					if len(ts) < t {
						ts = append(ts, y)
					}
					j++
				} else {
					same = append(same, x)
					i++
					j++
				}
			}
			if len(hs)+len(ts)+len(same) >= h+t {
				Fprintln(out, "YES")
				Fprintln(out, v, w)
				if len(hs) < h {
					popL := same[:h-len(hs)]
					same = same[h-len(hs):]
					hs = append(hs, popL...)
				}
				Fprintln(out, hs...)
				if len(ts) < t {
					ts = append(ts, same[:t-len(ts)]...)
				}
				Fprintln(out, ts...)
				return
			}
		}
	}
	Fprint(out, "NO")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF243B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	var n, m, h, t, v, w int
	Fscan(in, &n, &m, &h, &t)
	g := make([][]int, n+1)
	edges := make([]edge, m)
	for i := range edges {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = edge{v, w}
	}
	for i := range g {
		sort.Ints(g[i])
	}
	for _, e := range edges {
		v, w := e.v, e.w
		vs, ws := g[v], g[w]
		if h < t && len(vs) > len(ws) || h > t && len(vs) < len(ws) {
			vs, ws = ws, vs
			v, w = w, v
		}
		if len(vs)-1 < h || len(ws)-1 < t {
			continue
		}
		var hs, ts, same []int
		i, n := 0, len(vs)
		j, m := 0, len(ws)
		for i < n || j < m {
			if i == n {
				if y := ws[j]; y != v {
					ts = append(ts, y)
				}
				j++
			} else if j == m {
				if x := vs[i]; x != w {
					hs = append(hs, x)
				}
				i++
			} else {
				x, y := vs[i], ws[j]
				if x == w {
					i++
					continue
				}
				if y == v {
					j++
					continue
				}
				if x < y {
					if len(hs) < h {
						hs = append(hs, x)
					}
					i++
				} else if x > y {
					if len(ts) < t {
						ts = append(ts, y)
					}
					j++
				} else {
					same = append(same, x)
					i++
					j++
				}
			}
			if len(hs)+len(ts)+len(same) >= h+t {
				Fprintln(out, "YES")
				Fprintln(out, v, w)
				if len(hs) < h {
					popL := same[:h-len(hs)]
					same = same[h-len(hs):]
					hs = append(hs, popL...)
				}
				for _, v := range hs {
					Fprint(out, v, " ")
				}
				Fprintln(out)
				if len(ts) < t {
					ts = append(ts, same[:t-len(ts)]...)
				}
				for _, v := range ts {
					Fprint(out, v, " ")
				}
				return
			}
		}
	}
	Fprint(out, "NO")
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF243B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type edge struct{ v, w int }

	var n, m, h, t, v, w int
	Fscan(in, &n, &m, &h, &t)
	if h > t {
		h, t = t, h
	}
	g := make([][]int, n+1)
	edges := make([]edge, m)
	for i := range edges {
		Fscan(in, &v, &w)
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		edges[i] = edge{v, w}
	}
	for i := range g {
		sort.Ints(g[i])
	}
	for _, e := range edges {
		v, w := e.v, e.w
		vs, ws := g[v], g[w]
		if len(vs) > len(ws) {
			vs, ws = ws, vs
			v, w = w, v
		}
		if len(vs)-1 < h || len(ws)-1 < t {
			continue
		}
		var hs, ts, same []interface{}
		i, n := 0, len(vs)
		j, m := 0, len(ws)
		for i < n || j < m {
			if i == n {
				if y := ws[j]; y != v {
					ts = append(ts, y)
				}
				j++
			} else if j == m {
				if x := vs[i]; x != w {
					hs = append(hs, x)
				}
				i++
			} else {
				x, y := vs[i], ws[j]
				if x == w {
					i++
					continue
				}
				if y == v {
					j++
					continue
				}
				if x < y {
					if len(hs) < h {
						hs = append(hs, x)
					}
					i++
				} else if x > y {
					if len(ts) < t {
						ts = append(ts, y)
					}
					j++
				} else {
					same = append(same, x)
					i++
					j++
				}
			}
			if len(hs)+len(ts)+len(same) >= h+t {
				Fprintln(out, "YES")
				Fprintln(out, v, w)
				if len(hs) < h {
					popL := same[:h-len(hs)]
					same = same[h-len(hs):]
					hs = append(hs, popL...)
				}
				Fprintln(out, hs...)
				if len(ts) < t {
					ts = append(ts, same[:t-len(ts)]...)
				}
				Fprintln(out, ts...)
				return
			}
		}
	}
	Fprint(out, "NO")
}

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