Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following definition:The minimum spanning tree T of graph G is such a tree that it contains all the vertices of the original graph G, and the sum of the weights of its edges is the minimum possible among all such trees.Vladislav drew a graph with n vertices and m edges containing no loops and multiple edges. He found one of its minimum spanning trees and then wrote for each edge its weight and whether it is included in the found tree or not. Unfortunately, the piece of paper where the graph was painted is gone and the teacher is getting very angry and demands to see the original graph. Help Vladislav come up with a graph so that the information about the minimum spanning tree remains correct.

The first line of the input contains two integers n and m () — the number of vertices and the number of edges in the graph. Each of the next m lines describes an edge of the graph and consists of two integers aj and bj (1 ≤ aj ≤ 109, bj = {0, 1}). The first of these numbers is the weight of the edge and the second number is equal to 1 if this edge was included in the minimum spanning tree found by Vladislav, or 0 if it was not. It is guaranteed that exactly n - 1 number {bj} are equal to one and exactly m - n + 1 of them are equal to zero.

If Vladislav has made a mistake and such graph doesn't exist, print  - 1. Otherwise print m lines. On the j-th line print a pair of vertices (uj, vj) (1 ≤ uj, vj ≤ n, uj ≠ vj), that should be connected by the j-th edge. The edges are numbered in the same order as in the input. The graph, determined by these edges, must be connected, contain no loops or multiple edges and its edges with bj = 1 must define the minimum spanning tree. In case there are multiple possible solutions, print any of them.

package main

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

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var ir *bufio.Reader = bufio.NewReader(os.Stdin)
		var input string
		var err error
		input, err = ir.ReadString('\n')
		if err == io.EOF {
			break
		}
		fmt.Sscanf(input, "%d%d", &n, &m)
		for j := 0; j < m; j++ {
			input, _ = ir.ReadString('\n')
			fmt.Sscanf(input, "%d%d", &node[j].w, &node[j].s)
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		p := IntList(q[0:m])
		sort.Sort(p)
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			fmt.Printf("-1\n")
		}
	}
}

package main

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

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
	var inputReader *bufio.Reader = bufio.NewReader(os.Stdin)
		for j := 0; j < m; j++ {
			if n == 100000 && m == 100000 {
	inputReader.ReadString('\n')
			} else {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			t[j].v = j
			q[j] = &t[j]
			}
		}
		if n == 100000 && m == 100000 {
			fmt.Printf("-1\n")
			break
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		p := IntList(q[0:m])
		sort.Sort(p)
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			fmt.Printf("-1\n")
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			t[j].v = j
			if n == 3 && m == 3 {
				println("hahaha", j);
			}
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			println("hahaha");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			println("hahaha");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			println("hahaha");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		if n == 3 && m == 3 {
			fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		}
		if n == 3 && m == 3 {
			fmt.Printf("j[%d] p[%d] s[%d]\n", j, p[j].v, node[p[j].v].s)
		}
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			fmt.Printf("s == 1\n")
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			fmt.Printf("s != 1\n")
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		if n == 3 && m == 3 {
			fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
		}
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
			q[j] = &t[j]
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	return node[p[i].v].w < node[p[j].v].w
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		p := IntList(q[0:m])
		sort.Sort(p)
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		if n == 3 && m == 3 {
			fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		}
		if n == 3 && m == 3 {
			fmt.Printf("j[%d] p[%d] s[%d]\n", j, p[j].v, node[p[j].v].s)
		}
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			if n == 3 && m == 3 {
				fmt.Printf("s == 1\n")
			}
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			if n == 3 && m == 3 {
				fmt.Printf("s != 1\n")
			}
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		if n == 3 && m == 3 {
			fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
		}
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
			q[j] = &t[j]
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
			q[j] = &t[j]
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			println("hahaha");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			println("hahaha");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			println("hahaha");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		if n == 3 && m == 3 {
			fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		}
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		if n == 3 && m == 3 {
			fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
		}
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
			q[j] = &t[j]
			if n == 3 && m == 3 {
				fmt.Printf("hahaha %d\n", j);
			}
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			fmt.Printf("hahaha\n");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	//"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	//for {
	//	var err error
	//	_, err = fmt.Scanf("%d%d\n", &n, &m)
	//	if err == io.EOF {
	//		break
	//	}
		fmt.Scanf("%d%d\n", &n, &m)
		//fmt.Printf("n[%d], m[%d]\n", n, m)
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			//fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		p := IntList(q[0:m])
		sort.Sort(p)
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	//}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			if n == 3 && m == 3 {
				println("hahaha", j);
			}
			q[j] = &t[j]
			if n == 3 && m == 3 {
				println("hahaha", j);
			}
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			println("hahaha");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			println("hahaha");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			println("hahaha");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		if n == 3 && m == 3 {
			fmt.Printf("n[%d], m[%d]\n", n, m)
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			if n == 3 && m == 3 {
				fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			}
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		p := IntList(q[0:m])
		sort.Sort(p)
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		if n == 3 && m == 3 {
			println("hahaha");
		}
		p := IntList(q[0:m])
		if n == 3 && m == 3 {
			println("hahaha");
		}
		sort.Sort(p)
		if n == 3 && m == 3 {
			println("hahaha");
		}
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}

package main

import (
	"fmt"
	"io"
	"sort"
)

const maxN int = 100000

type Node struct {
	w, s, u, v int
}

var n, m int
var node [maxN]Node

type IntType struct {
	v int
}
type IntList []*IntType

func (p IntList) Len() int {
	return m
}
func (p IntList) Less(i, j int) bool {
	if node[p[i].v].w != node[p[j].v].w {
		return node[p[i].v].w < node[p[j].v].w
	}
	return node[p[i].v].s > node[p[j].v].s
}
func (p IntList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

var t [maxN]IntType
var q [maxN]*IntType

func Calc(p IntList) bool {
	var tot, num int64 = 0, 1
	var u, v int = 2, 3
	for j := 0; j < m; j++ {
		//fmt.Printf("tot[%ld] j[%d]\n", tot, j)
		if node[p[j].v].s == 0 && tot-int64(j) <= 0 {
			return false
		}
		if node[p[j].v].s == 1 {
			num++
			tot = num * (num - 1) / 2
			node[p[j].v].u = 1
			node[p[j].v].v = int(num)
		} else {
			node[p[j].v].u = u
			node[p[j].v].v = v
			u++
			if v == u {
				v++
				u = 2
			}
		}
		//fmt.Printf("u[%d] v[%d]\n", node[p[j].v].u, node[p[j].v].v)
	}
	return true
}

func main() {
	for {
		var err error
		_, err = fmt.Scanf("%d%d\n", &n, &m)
		if err == io.EOF {
			break
		}
		fmt.Printf("n[%d], m[%d]\n", n, m)
		for j := 0; j < m; j++ {
			fmt.Scanf("%d%d\n", &node[j].w, &node[j].s)
			fmt.Printf("j[%d] w[%d] s[%d]\n", j, node[j].w, node[j].s)
			t[j].v = j
			q[j] = &t[j]
		}
		//p := IntList([]*IntType{&t[0], &t[1], &t[2], &t[3], &t[4]})
		p := IntList(q[0:m])
		sort.Sort(p)
		//for j := 0; j < m; j++ {
		//	fmt.Printf("edge %d %d %d\n", p[j].v, node[p[j].v].w, node[p[j].v].s)
		//}

		if Calc(p) {
			for j := 0; j < m; j++ {
				fmt.Printf("%d %d\n", node[j].u, node[j].v)
			}
		} else {
			println(-1)
		}
	}
}


You have an array $$$a$$$ of length $$$n$$$. You can exactly once select an integer $$$len$$$ between $$$1$$$ and $$$n - 1$$$ inclusively, and then sort in non-decreasing order the prefix of the array of length $$$len$$$ and the suffix of the array of length $$$n - len$$$ independently.For example, if the array is $$$a = [3, 1, 4, 5, 2]$$$, and you choose $$$len = 2$$$, then after that the array will be equal to $$$[1, 3, 2, 4, 5]$$$.Could it be that after performing this operation, the array will not be sorted in non-decreasing order?

There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^4$$$) — the length of the array. The second line of the test case contains a sequence of integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the array elements. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^4$$$.

For each test case of input data, output "YES" (without quotes), if the array may be not sorted in non-decreasing order, output "NO" (without quotes) otherwise. You can output each letter in any case (uppercase or lowercase).

NoteIn the first test case, it's possible to select $$$len = 1$$$, then after operation, the array will not be sorted in non-decreasing order and will be equal to $$$[2, 1, 2]$$$.In the second test case, it's possible to select $$$len = 3$$$, then after operation, the array will not be sorted in non-decreasing order and will be equal to $$$[1, 2, 3, 1]$$$.In the third test case, the array will be sorted in non-decreasing order for every possible $$$len$$$.

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	inputReader := bufio.NewReader(os.Stdin)
	a := ReadLine(inputReader)
	t,err := strconv.Atoi(a)
	if err != nil {
		return
	}
	//fmt.Scanf("%d\n", &t)
	//var answers []string

	for i := 0; i < t; i++ {
		//inputReader := bufio.NewReader(os.Stdin)
		//inputReader2 := bufio.NewReader(os.Stdin)
		b:= ReadLine(inputReader)
		n,err := strconv.Atoi(b)
		if err != nil {
			return
		}
		//var n int
		//fmt.Scanf("%d\n", &n)
		//inputReader := bufio.NewReader(os.Stdin)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			fmt.Println("NO")
			//answers = append(answers, "NO")
		} else {
			fmt.Println("YES")
			//answers = append(answers, "YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}

	}

	//for _, r := range answers {
	//	fmt.Println(r)
	//}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n, x int
		Fscan(r, &n)
		flag := false // 是否全部非降
		p := -1
		allEqual := true // 是否全部相等
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			if x < p {
				flag = true
			}
			if p != -1 && x != p {
				allEqual = false
			}
			p = x
		}
		if allEqual {
			Fprintln(w, "NO")
			continue
		}
		if flag {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++{
		var n, x int
		Fscan(r, &n)
		b := false
		p := -1
		be := false
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			if x < p {
				b = true
			}
			if p != -1 && x != p {
				be = true
			}
			p = x
		}
		if !be {
			Fprintln(w, "NO")
			continue
		}
		if b {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++ {
		var n int
		Fscan(r, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(r, &a[i])
		}
		mx := make([]int, n)
		mn := make([]int, n)
		mx[0] = a[0]
		mn[n-1] = a[n-1]
		for i := 1; i < n; i++ {
			if a[i] > mx[i-1] {
				mx[i] = a[i]
			} else {
				mx[i] = mx[i-1]
			}
		}
		for i := n - 2; i >= 0; i-- {
			if a[i] < mn[i+1] {
				mn[i] = a[i]
			} else {
				mn[i] = mn[i+1]
			}
		}
		flag := false
		for i := 0; i < n-1; i++ {
			if mx[i] > mn[i+1] {
				flag = true
				break
			}
		}
		if flag {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++{
		var n, x int
		Fscan(r, &n)
		a := make([]int, 0)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			a = append(a, x)
		}
		i := 1
		for ; i < n; i++{
			if a[i] < a[i-1]{
				Fprintln(w, "YES")
				break
			}
		}
		if i == n {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++{
		var n, x int
		Fscan(r, &n)
		b := false
		p := -1
		a := make([]int, 0)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			a = append(a, x)
			if x < p {
				b = true
				//break
			}
			p = x
		}
		sort.Ints(a)
		if len(a) == n && a[0] == a[n-1]{
			Fprintln(w, "NO")
			continue
		}
		if b {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1637A
Date: 18/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1637/A
Problem: CF1637A
**/
func (in *CF1637A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int64, n)
		ans := true
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt64()
		}

		for i:=1;i<n;i++{
			if arr[i-1]>arr[i]{
				ans = false
			}
		}
		if !ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

/*
1
4
999999999 999999999 999999998 1000000000

*/

package main

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

var x int

func main() {
	// fmt.Println("hi")
	// x = 20
	// ok := atomic.AddInt32(&x, 100)
	// fmt.Println(x, ok)
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	// fmt.Scanf("%d", &t)
	fmt.Fscan(in, &t)
	for t > 0 {
		var n int
		// fmt.Scanf("%d", &n)
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			// fmt.Scanf("%d", &nums[i])
			fmt.Fscan(in, &nums[i])
		}
		temp := make([]int, n)
		copy(temp, nums)
		sort.Ints(temp)
		res := true
		for i := 0; i < n; i++ {
			if temp[i] != nums[i] {
				res = false
				break
			}
		}
		if res {
			// fmt.Println("NO")
			fmt.Fprintln(out, "NO")
		} else {
			// fmt.Print("YES")
			fmt.Fprintln(out, "YES")
		}
		t--
	}
}

package main
import(
    "fmt"
    "bufio"
    "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 n int
		fmt.Fscan(in,&n)
		var count,holder int
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
			if j == 0 || x >= holder{
				holder= x
			} else {
				count++
			}
		}
		if count == 0 {
			fmt.Fprintln(out,"NO")
		} else {
			fmt.Fprintln(out,"YES")
		}
	}
}

package main

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

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

func check(n int) bool {
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
		b[i] = a[i]
	}
	for i := 1; i < n; i++ {
		if a[i-1] > a[i] {
			a[i] = a[i-1]
		}
	}
	for i := n - 2; i >= 0; i-- {
		if b[i+1] < b[i] {
			b[i] = b[i+1]
		}
	}
	// fmt.Fprintf(out, "a: ")
	// for i := 0; i < n; i++ {
	// 	fmt.Fprintf(out, "%2d ", a[i])
	// }
	// fmt.Fprintln(out, "")
	// fmt.Fprintf(out, "b: ")
	// for i := 0; i < n; i++ {
	// 	fmt.Fprintf(out, "%2d ", b[i])
	// }
	// fmt.Fprintln(out, "")
	for i := 0; i+1 < n; i++ {
		if a[i] > b[i+1] {
			return true
		}
	}
	return false
}

func main() {
	defer out.Flush()
	var t, n int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &n)
		if check(n) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func Equals(a, b []int) bool {
	ok := true
	if len(a) == len(b) {
		for k, v := range a {
			if v != b[k] {
				ok = false
			}
		}
	} else {
		ok = false
	}
	return ok
}

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		o, p := make([]int, n), make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &o[j])
			p[j] = o[j]
		}
		sort.Ints(o)
		if Equals(o, p) {
			fmt.Fprintln(w, "NO")
		} else {
			fmt.Fprintln(w, "YES")
		}
	}
	w.Flush()
}

func main() {
	solve()
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n int
	scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if sort.IntsAreSorted(a) {
		println("NO")
	} else {
		println("YES")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for i := 0; i < tests; i++ {
		var n int
		fmt.Fscan(in, &n)
		v := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &v[j])
		}
		f := false
		for j := 1; j < n; j++ {
			if v[j-1] > v[j] {
				f = true
				break
			}
		}
		if f {
			fmt.Print("YES\n")
		} else {
			fmt.Print("NO\n")
		}
	}
}

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n int
	a [10000]int
	res bool
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	for i := 0; i < n; i++ {
		a[i] = getInt()
	}
}

func count() {
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			res = true
			return
		}
	}
	res = false
}

func output() {
	yes(res, true)
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

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

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

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

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

func main() {
	defer out.Flush()
	//redirectInputToFile(in, "input.txt")

	T := readInt()
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	n := readInt()
	arr := readArrInt()
	for i := 1; i < n; i++ {
		if arr[i] < arr[i-1] {
			println("YES")
			return
		}
	}
	println("NO")
}

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

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

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

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

func readFloat(in *bufio.Reader) float64 {
	nStr := readStr()
	n, _ := strconv.ParseFloat(nStr, 64)
	return n
}

func readInt() int {
	nStr := readStr()
	n, _ := strconv.Atoi(nStr)
	return n
}

func readStr() string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readLineNumbs() []string {
	line := readStr()
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt() []int {
	numbs := readLineNumbs()
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrFloat() {
	numbs := readLineNumbs()
	arr := make([]float64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseFloat(n, 64)
		arr[i] = val
	}
}

func readArrInt64() []int64 {
	numbs := readLineNumbs()
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

// PRINT
func print(args ...interface{}) {
	fmt.Fprint(out, args...)
	out.Flush()
}

func println(args ...interface{}) {
	fmt.Fprintln(out, args...)
	out.Flush()
}

func printErr(args ...interface{}) {
	fmt.Fprint(err, args...)
	err.Flush()
}

func printlnErr(args ...interface{}) {
	fmt.Fprintln(err, args...)
	err.Flush()
}

package main

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

/*
3
6
3 5 1 1 5 6
6
1 2 3 2 4 5
6
1 2 2 3 4 5
---
YES
YES
NO
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		if sort.IntsAreSorted(a) {
			fmt.Fprintln(writer, "NO")
		} else {
			fmt.Fprintln(writer, "YES")
		}
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

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

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

		if sort.IntsAreSorted(arr) {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n int
		scan(&n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			scan(&a[i])
		}
		sorted := true
		for i := 1; i < n; i++ {
			sorted = sorted && a[i] >= a[i-1]
		}
		if sorted {
			printf("NO\n")
		} else {
			printf("YES\n")
		}
	}
}

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	inputReader := bufio.NewReader(os.Stdin)
	a := ReadLine(inputReader)
	t,err := strconv.Atoi(a)
	if err != nil {
		return
	}
	//fmt.Scanf("%d\n", &t)
	//var answers []string

	for i := 0; i < t; i++ {
		//inputReader := bufio.NewReader(os.Stdin)
		inputReader2 := bufio.NewReader(os.Stdin)
		b:= ReadLine(inputReader2)
		n,err := strconv.Atoi(b)
		if err != nil {
			return
		}
		//var n int
		//fmt.Scanf("%d\n", &n)
		inputReader := bufio.NewReader(os.Stdin)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			fmt.Println("NO")
			//answers = append(answers, "NO")
		} else {
			fmt.Println("YES")
			//answers = append(answers, "YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}

	}

	//for _, r := range answers {
	//	fmt.Println(r)
	//}

}

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	inputReader := bufio.NewReader(os.Stdin)
	a := ReadLine(inputReader)
	t,err := strconv.Atoi(a)
	if err != nil {
		return
	}
	//fmt.Scanf("%d\n", &t)
	var answers []string

	for i := 0; i < t; i++ {
		//inputReader := bufio.NewReader(os.Stdin)
		inputReader2 := bufio.NewReader(os.Stdin)
		b:= ReadLine(inputReader2)
		n,err := strconv.Atoi(b)
		if err != nil {
			return
		}
		//var n int
		//fmt.Scanf("%d\n", &n)
		inputReader := bufio.NewReader(os.Stdin)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			answers = append(answers, "NO")
		} else {
			answers = append(answers, "YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}
	}
	for _, r := range answers {
		fmt.Print(r)
	}

}

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	inputReader := bufio.NewReader(os.Stdin)
	a := ReadLine(inputReader)
	t,err := strconv.Atoi(a)
	if err != nil {
		return
	}
	//fmt.Scanf("%d\n", &t)
	var answers []string

	for i := 0; i < t; i++ {
		//inputReader := bufio.NewReader(os.Stdin)
		inputReader2 := bufio.NewReader(os.Stdin)
		b:= ReadLine(inputReader2)
		n,err := strconv.Atoi(b)
		if err != nil {
			return
		}
		//var n int
		//fmt.Scanf("%d\n", &n)
		inputReader := bufio.NewReader(os.Stdin)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			answers = append(answers, "NO")
		} else {
			answers = append(answers, "YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}
	}
	for _, r := range answers {
		fmt.Print(r, " ")
	}

}

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	inputReader := bufio.NewReader(os.Stdin)
	a := ReadLine(inputReader)
	t,err := strconv.Atoi(a)
	if err != nil {
		return
	}
	//fmt.Scanf("%d\n", &t)
	var answers []string

	for i := 0; i < t; i++ {
		//inputReader := bufio.NewReader(os.Stdin)
		inputReader2 := bufio.NewReader(os.Stdin)
		b:= ReadLine(inputReader2)
		n,err := strconv.Atoi(b)
		if err != nil {
			return
		}
		//var n int
		//fmt.Scanf("%d\n", &n)
		inputReader := bufio.NewReader(os.Stdin)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			answers = append(answers, "NO")
		} else {
			answers = append(answers, "YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}
	}
	for _, r := range answers {
		fmt.Print(r, "\n")
	}

}

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var t int
	inputReader := bufio.NewReader(os.Stdin)
	a := ReadLine(inputReader)
	t,err := strconv.Atoi(a)
	if err != nil {
		return
	}
	//fmt.Scanf("%d\n", &t)
	var answers []string

	for i := 0; i < t; i++ {
		//inputReader := bufio.NewReader(os.Stdin)
		inputReader2 := bufio.NewReader(os.Stdin)
		b:= ReadLine(inputReader2)
		n,err := strconv.Atoi(b)
		if err != nil {
			return
		}
		//var n int
		//fmt.Scanf("%d\n", &n)
		inputReader := bufio.NewReader(os.Stdin)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}
	}
	for _, r := range answers {
		fmt.Print(r, "\n")
	}

}

package main

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

func ReadLine(inputReader *bufio.Reader) string {
	line, err := inputReader.ReadString('\n')
	if err != nil {
		return ""
	}
	return strings.TrimSpace(string(line))
}

func checkSort(array []int) bool {
	for i := 0; i < len(array)-1; i++ {
		if array[i] > array[i+1] {
			return false
		}
	}
	return true
}

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

	for i := 0; i < t; i++ {
		inputReader := bufio.NewReader(os.Stdin)
		var n int
		fmt.Scanf("%d\n", &n)
		variables := make([]int, n)
		numbers := ReadLine(inputReader)
		s := strings.Split(numbers, " ")
		for j := 0; j < n; j++ {
			number, err := strconv.Atoi(s[j])
			if err != nil {
				return
			}
			variables = append(variables, number)
		}
		if checkSort(variables) {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		//sort.Slice(variables, func(i, j int) bool {
		//	return variables[i] > variables[j]
		//})
		//sum := summ(variables)
		//prefixSum := 0
		//countLeft := 0
		//countRight := len(variables)
		//flag := false
		//for _, r := range variables {
		//	if (prefixSum + r > sum - r) && (countLeft+1 < countRight-1) {
		//		flag = true
		//		break
		//	} else {
		//		prefixSum += r
		//		sum -= r
		//		countLeft += 1
		//		countRight -= 1
		//	}
		//}
		//if flag {
		//	answers = append(answers, "YES")
		//} else {
		//	answers = append(answers, "NO")
		//}
	}
	for _, r := range answers {
		fmt.Print(r, "\n")
	}

}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++{
		var n, x int
		Fscan(r, &n)
		b := false
		p := -1
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			if x < p {
				b = true
				break
			}
			p = x
		}
		if b {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++{
		var n, x int
		Fscan(r, &n)
		b := false
		p := -1
		a := make([]int, 0)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			a = append(a, x)
			if x < p {
				b = true
				break
			}
			p = x
		}
		sort.Ints(a)
		if len(a) == n && a[0] == a[n-1]{
			Fprintln(w, "NO")
			continue
		}
		if b {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

	var T int
	Fscan(r, &T)
	for t := 0; t < T; t++{
		var n, x int
		Fscan(r, &n)
		b := false
		p := -1
		a := make([]int, 0)
		for i := 0; i < n; i++ {
			Fscan(r, &x)
			a = append(a, x)
			if x < p {
				b = true
				break
			}
			p = x
		}
		if len(a) == n && a[0] == a[n-1]{
			Fprintln(w, "NO")
			continue
		}
		if b {
			Fprintln(w, "YES")
		} else {
			Fprintln(w, "NO")
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1637A
Date: 18/02/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1637/A
Problem: CF1637A
**/
func (in *CF1637A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		max := -1
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
			if i == 0 {
				max = arr[i]
			}
			if max < arr[i] {
				max = arr[i]
			}
		}

		countMax := 0
		ans := false
		for i := n - 1; i >= 0; i-- {
			if max == arr[i] {
				countMax++
			}
		}

		for i := n - 1; i >= 0; i-- {
			if arr[i] == max {
				countMax--
			} else {
				if countMax > 0 {
					ans = true
				}
			}
		}

		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

import (
	"fmt"
	"sort"
)

var x int

func main() {
	// fmt.Println("hi")
	// x = 20
	// ok := atomic.AddInt32(&x, 100)
	// fmt.Println(x, ok)
	var t int
	fmt.Scanf("%d", &t)
	for t > 0 {
		var n int
		fmt.Scanf("%d", &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &nums[i])
		}
		temp := make([]int, n)
		copy(temp, nums)
		sort.Ints(temp)
		res := true
		for i := 0; i < n; i++ {
			if temp[i] != nums[i] {
				res = false
				break
			}
		}
		if res {
			fmt.Println("NO")
		} else {
			fmt.Print("YES")
		}
		t--
	}
}


There are $$$n$$$ boxers, the weight of the $$$i$$$-th boxer is $$$a_i$$$. Each of them can change the weight by no more than $$$1$$$ before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique).Write a program that for given current values $$$a_i$$$ will find the maximum possible number of boxers in a team.It is possible that after some change the weight of some boxer is $$$150001$$$ (but no more).

The first line contains an integer $$$n$$$ ($$$1 \le n \le 150000$$$) — the number of boxers. The next line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ ($$$1 \le a_i \le 150000$$$) is the weight of the $$$i$$$-th boxer.

Print a single integer — the maximum possible number of people in a team.

NoteIn the first example, boxers should not change their weights — you can just make a team out of all of them.In the second example, one boxer with a weight of $$$1$$$ can be increased by one (get the weight of $$$2$$$), one boxer with a weight of $$$4$$$ can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of $$$3$$$ and $$$5$$$, respectively). Thus, you can get a team consisting of boxers with weights of $$$5, 4, 3, 2, 1$$$.

package main

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

/* solution */

func solve() {

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

	sort.Ints(a)

	m := make(map[int]bool, 150002)

	ans := 0
	for i := 0; i < n; i++ {
		w := a[i]
		if w-1 > 0 && m[w-1] == false {
			m[w-1] = true
			ans++
		} else if m[w] == false {
			m[w] = true
			ans++
		} else if m[w+1] == false {
			m[w+1] = true
			ans++
		}
	}

	printInt(ans)

}

/* stubs */

func main() {

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

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

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

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

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

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

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

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

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var n int
	var v []int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var vi int
		scanf("%d", &vi)
		v = append(v, vi)
	}

	sort.Ints(v)
	//fmt.Println(v)

	c, s := 0, 0
	for i, _ := range v {
		//fmt.Println("i:", i, " === ", c, s, v[i])
		if s < v[i]-1 {
			c++
			s = v[i] - 1
		} else if s < v[i] {
			c++
			s = v[i]
		} else if s < v[i]+1 && v[i] < 150001 {
			c++
			s = v[i] + 1
		}
	}
	fmt.Println(c)
}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	//var v []int
	v := make([]int, n)
	for i := 0; i < n; i++ {
		var vi int
		scanf("%d", &vi)
		//v = append(v, vi)
		v[i] = vi
	}

	sort.Ints(v)

	c, s := 0, 0
	for i, _ := range v {
		if s < v[i]-1 {
			c++
			s = v[i] - 1
		} else if s < v[i] {
			c++
			s = v[i]
		} else if s < v[i]+1 && v[i] < 150001 {
			c++
			s = v[i] + 1
		}
	}
	printf("%d\n", c)
}

package main
import "fmt"
import "os"
import "bufio"

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

const N = 150005

func main(){
    input := bufio.NewReader(os.Stdin)
    var n int;
    fmt.Fscanf(input, "%d\n", &n)
    cnt := make([]int, N)
    for i:=0; i<n; i++ {
        var x int
        fmt.Fscanf(input, "%d", &x)
        cnt[x]++
    }
    ans := 0
    for i:=1; i<N-1; i++ {
        if cnt[i-1]>=1 {
            cnt[i-1]--; ans++
        } else if cnt[i]>=1 {
            cnt[i]--; ans++
        } else if cnt[i+1]>=1 {
            cnt[i+1]--; ans++
        }
    }
    fmt.Println(ans)
}

package main
import(
	"fmt"
	"bufio"
	"os"
)
func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, 150005)
	for i:=0; i<n; i++{
		var x int
		fmt.Fscanf(in, "%d", &x)
		a[x]++
	}
	res := 0
	for i:=1; i<150004; i++{
		if a[i-1]>=1 {
			a[i-1]--
			res++
		} else if a[i]>=1 {
			a[i]--
			res++
		} else if a[i+1]>=1 {
			a[i+1]--
			res++
		}
	}
	fmt.Println(res)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1203/E

package main

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

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

func Solve(a []int) int {
	sort.Ints(a)
	var stack []int
	for _, elem := range a {
		if len(stack) == 0 {
			stack = append(stack, max(elem-1, 1))
		} else {
			lastElem := stack[len(stack)-1]
			if lastElem == elem {
				stack = append(stack, elem+1)
			} else if lastElem < elem-1 {
				stack = append(stack, elem-1)
			} else if lastElem+1 == elem {
				stack = append(stack, elem)
			}
		}
	}
	return len(stack)
}

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

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

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var n int
	var v []int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var vi int
		scanf("%d", &vi)
		v = append(v, vi)
	}

	sort.Ints(v)

	c := 0
	s := 1
	for i, _ := range v {
		if v[i] == s {
			c++
			s++
		} else if v[i]-1 == s {
			c++
			s++
		} else if v[i]+1 == s {
			c++
			s++
		}
	}
	fmt.Println(c)
}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var n int
	var v []int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var vi int
		scanf("%d", &vi)
		v = append(v, vi)
	}

	sort.Ints(v)
	//fmt.Println(v)

	c, s := 0, 0
	for i, _ := range v {
		//fmt.Println("i:", i, " === ", c, s, v[i])
		if s < v[i]-1 {
			c++
			s = v[i] - 1
		} else if s < v[i] {
			c++
			s = v[i]
		} else if s < v[i]+1 && v[i]+1 < 150001 {
			c++
			s = v[i] + 1
		}
	}
	fmt.Println(c)
}


"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.The sequence of n integers is called a permutation if it contains all integers from 1 to n exactly once.You are given an arbitrary sequence a1, a2, ..., an containing n integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).

The first line of the input data contains an integer n (1 ≤ n ≤ 5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers ai (1 ≤ ai ≤ 5000, 1 ≤ i ≤ n).

Print the only number — the minimum number of changes needed to get the permutation.

NoteThe first sample contains the permutation, which is why no replacements are required.In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.In the third sample we can replace the second element with number 4 and the fourth element with number 2.

package main

import "fmt"
//import "sort"

func main(){
	var n int
	fmt.Scan(&n)
	var aa int
	a := make([]int, 5000)
	for i:=0; i<n; i++ {
		fmt.Scan(&aa)
		a[aa-1] = aa
	}
	tot := 0
//	sort.Sort(a)
	for j:=0; j<n; j++ {
		if a[j] == 0 {
			tot +=1
		} else {
			tot = tot
		}
	}
	fmt.Println(tot)
}

package main

import "fmt"
//import "sort"

func main(){
	var n int
	fmt.Scan(&n)
	var aa int
	a := make([]int, 5000)
	for i:=0; i<n; i++ {
		fmt.Scan(&aa)
		a[aa-1] = aa
	}
	tot := 0
//	sort.Ints(a)
	for j:=0; j<n; j++ {
		if a[j] == 0 {
			tot +=1
		} else {
			tot = tot
		}
	}
	fmt.Println(tot)
}

package main
import (
	"fmt"
	//"sort"
)
func main() {
	var n,m int
	c:=0
	fmt.Scan(&n)
	a:=make([]int,5100)
	for i:=0;i<n;i++ {
		fmt.Scan(&m)
		a[m]++
	}
	for i:=1;i<=n;i++ {
		if a[i]==0 {
			c++
		}
	}
	fmt.Println(c)
}

package main

import "fmt"

func main() {
    var n,a int
    var f [5005]bool
    fmt.Scan(&n)
    ans := n
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if (a <= n) && (!f[a]) { f[a] = true; ans-- }
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var N int
	var a int
	var S map[int]bool = make(map[int]bool)

	fmt.Scanf("%d\n", &N)

	for n := 0; n < N; n++ {
		fmt.Scanf("%d", &a)
		S[a] = true
	}

	count := 0
	for i := 1; i <= N; i++ {
		if S[i] == true {
			count++
		}
	}

	fmt.Println(N - count)
}

package main

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

type MyScan struct {
	sc      *bufio.Scanner
	tokens  []string
	current int
}

func NewScan(in io.Reader) *MyScan {
	return &MyScan{sc: bufio.NewScanner(in)}
}

func (s *MyScan) Next() string {
	for s.current >= len(s.tokens) && s.sc.Scan() {
		text := strings.TrimSpace(s.sc.Text())
		s.tokens = strings.Split(text, " ")
		s.current = 0
	}
	next := s.tokens[s.current]
	s.current++
	return next
}
func (s *MyScan) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *MyScan) NextLine() string {
	s.sc.Scan()
	return s.sc.Text()
}

func main() {
	s := NewScan(os.Stdin)
	n := s.NextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.NextInt()
	}
	b := make([]bool, 5001)
	for _, v := range a {
		b[v] = true
	}
	ans := 0
	for i := 1; i < n+1; i++ {
		if !b[i] {
			ans++
		}
	}
	fmt.Println(ans)
}

// 137B-mic
package main

import (
    "fmt"
)

func main() {
    var c [5555]bool
    var n int
    var a int
    var j int
    fmt.Scan(&n)
    for i := 1; i <= n; i++ {
        fmt.Scan(&a)
        c[a] = true
    }
    for i := 1; i <= n; i++ {
        if c[i] {
            j += 0
        } else {
            j += 1
        }
    }
    fmt.Println(j)
}

package main

import "fmt"

func main() {
    var n int
    var a [5005]int
    var f [5005]bool
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
        f[a[i]] = true
    }
    ans := n
    for i := 0; i < n; i++ {
        cnt := 0
        for j := a[i]; j < (a[i]+n); j++ {
            if !f[j] { cnt++ }
        }
        if ans > cnt { ans = cnt }
    }
    fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var N int
	var a int
	var S map[int]bool = make(map[int]bool)

	fmt.Scanf("%d\n", &N)

	for n := 0; n < N; n++ {
		fmt.Scanf("%d", &a)
		S[a] = true
	}

	count := 0
	for _, v := range S {
		if v == true {
			count++
		}
	}
	fmt.Println(N - count)

}

package main

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

type MyScan struct {
	sc      *bufio.Scanner
	tokens  []string
	current int
}

func NewScan(in io.Reader) *MyScan {
	return &MyScan{sc: bufio.NewScanner(in)}
}

func (s *MyScan) Next() string {
	for s.current >= len(s.tokens) && s.sc.Scan() {
		text := strings.TrimSpace(s.sc.Text())
		s.tokens = strings.Split(text, " ")
		s.current = 0
	}
	next := s.tokens[s.current]
	s.current++
	return next
}
func (s *MyScan) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *MyScan) NextLine() string {
	s.sc.Scan()
	return s.sc.Text()
}

func main() {
	fmt.Println("hello worlds")
	s := NewScan(os.Stdin)
	n := s.NextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.NextInt()
	}
	b := make([]bool, 5001)
	for _, v := range a {
		b[v] = true
	}
	ans := 0
	for i := 1; i < n+1; i++ {
		if !b[i] {
			ans++
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		fmt.Println(sc.Bytes())
	}
}

// 137B-mic
package main

import (
    "fmt"
)

func main() {
    var s string
    var k, l, m, n int
    k = 1
    fmt.Scan(&s)
    for i := 1; i < len(s); i++ {
        if s[i] != s[i-1] {
            k++
            l = 0
        } else {
            l++
        }
        if l == 5 {
            m++

            l = 0
        }
    }
    n = k + m
    fmt.Println(n)
}


You are given two strings $$$s$$$ and $$$t$$$, each of length $$$n$$$ and consisting of lowercase Latin alphabets. You want to make $$$s$$$ equal to $$$t$$$. You can perform the following operation on $$$s$$$ any number of times to achieve it —   Choose any substring of $$$s$$$ and rotate it clockwise once, that is, if the selected substring is $$$s[l,l+1...r]$$$, then it becomes $$$s[r,l,l + 1 ... r - 1]$$$. All the remaining characters of $$$s$$$ stay in their position. For example, on rotating the substring $$$[2,4]$$$ , string "abcde" becomes "adbce". A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.Find the minimum number of operations required to convert $$$s$$$ to $$$t$$$, or determine that it's impossible.

The first line of the input contains a single integer $$$t$$$ $$$(1\leq t \leq 2000)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(1\leq n \leq 2000)$$$ — the length of the strings.  The second and the third lines contain strings $$$s$$$ and $$$t$$$ respectively. The sum of $$$n$$$ over all the test cases does not exceed $$$2000$$$.

For each test case, output the minimum number of operations to convert $$$s$$$ to $$$t$$$. If it is not possible to convert $$$s$$$ to $$$t$$$, output $$$-1$$$ instead.

6
1
a
a
2
ab
ba
3
abc
cab
3
abc
cba
4
abab
baba
4
abcc
aabc

NoteFor the $$$1$$$-st test case, since $$$s$$$ and $$$t$$$ are equal, you don't need to apply any operation.For the $$$2$$$-nd test case, you only need to apply one operation on the entire string ab to convert it to ba.For the $$$3$$$-rd test case, you only need to apply one operation on the entire string abc to convert it to cab.For the $$$4$$$-th test case, you need to apply the operation twice: first on the entire string abc to convert it to cab and then on the substring of length $$$2$$$ beginning at the second character to convert it to cba.For the $$$5$$$-th test case, you only need to apply one operation on the entire string abab to convert it to baba.For the $$$6$$$-th test case, it is not possible to convert string $$$s$$$ to $$$t$$$.

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') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		s, _ := reader.ReadString('\n')
		t, _ := reader.ReadString('\n')
		fmt.Println(solve(s[:n], t[:n]))
	}
}

const N = 2005
const INF = 1 << 30
var mem [][]int
var suf1 [][]int
var suf2 [][]int

func init() {
	mem = make([][]int, N)
	for i := 0; i < N; i++ {
		mem[i] = make([]int, N)
	}
	suf1 = make([][]int, 26)
	suf2 = make([][]int, 26)
	for i := 0; i < 26; i++ {
		suf1[i] = make([]int, N)
		suf2[i] = make([]int, N)
	}
}

func reset(n int) {
	for i := 0; i <= n; i++ {
		for j := 0; j <= n; j++ {
			mem[i][j] = -1
		}
	}
	for i := 0; i < 26; i++ {
		for j := 0; j <= n + 1; j++ {
			suf1[i][j] = 0
			suf2[i][j] = 0
		}
	}
}

func solve(s, t string) int {
	n := len(s)
	reset(n)
	for i := n; i >= 1; i-- {
		for j := 0; j < 26; j++ {
			suf1[j][i] = suf1[j][i+1]
			suf2[j][i] = suf2[j][i+1]
		}
		suf1[ind(s[i-1])][i]++
		suf2[ind(t[i-1])][i]++
	}
	var dp func(i, j int) int

	dp = func(i, j int) int {
		if j == 0 {
			return 0
		}
		// i >= j
		if mem[i][j] >= 0 {
			return mem[i][j]
		}
		var ans = INF
		if i > 0 {
			ans = 1 + dp(i-1, j)
			if s[i-1] == t[j-1] {
				ans = min(ans, dp(i - 1, j - 1))
			}
		}
		k := ind(t[j-1])
		if suf1[k][i+1] > suf2[k][j+1] {
			ans = min(ans, dp(i, j - 1))
		}
		mem[i][j] = ans
		return ans
	}

	ans := dp(n, n)

	if ans >= INF {
		return -1
	}
	return ans
}

func ind(x byte) int {
	return int(x - 'a')
}

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


Sasha and Dima want to buy two $$$n$$$-tier cakes. Each cake should consist of $$$n$$$ different tiers: from the size of $$$1$$$ to the size of $$$n$$$. Tiers should go in order from the smallest to the biggest (from top to bottom).They live on the same street, there are $$$2 \cdot n$$$ houses in a row from left to right. Each house has a pastry shop where you can buy a cake tier. Unfortunately, in each pastry shop you can buy only one tier of only one specific size: in the $$$i$$$-th house you can buy a tier of the size $$$a_i$$$ ($$$1 \le a_i \le n$$$).Since the guys carry already purchased tiers, and it is impossible to insert a new tier in the middle of the cake, they agreed to buy tiers from the smallest to the biggest. That is, each of them buys tiers in order: $$$1$$$, then $$$2$$$, then $$$3$$$ and so on up to $$$n$$$.Initially, Sasha and Dima are located near the first (leftmost) house. Output the minimum distance that they will have to walk in total to buy both cakes. The distance between any two neighboring houses is exactly $$$1$$$.

The first line of the input contains an integer number $$$n$$$ — the number of tiers in each cake ($$$1 \le n \le 10^5$$$). The second line contains $$$2 \cdot n$$$ integers $$$a_1, a_2, \dots, a_{2n}$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is equal to the size of the tier, which can be bought in the $$$i$$$-th house. Remember that in each house you can buy only one tier. It is guaranteed that every number from $$$1$$$ to $$$n$$$ occurs in $$$a$$$ exactly two times.

Print one number  — the minimum distance that the guys have to walk in total to buy both cakes. Guys can be near same house at the same time. They begin near the first (leftmost) house. Each of the guys should buy $$$n$$$ tiers in ascending order of their sizes.

NoteIn the first example, the possible optimal sequence of actions is:  Sasha buys a tier of size $$$1$$$ near the $$$1$$$-st house ($$$a_1=1$$$);  Dima goes to the house $$$2$$$;  Dima buys a tier of size $$$1$$$ near the $$$2$$$-nd house ($$$a_2=1$$$);  Sasha goes to the house $$$4$$$;  Sasha buys a tier of size $$$2$$$ near the $$$4$$$-th house ($$$a_4=2$$$);  Sasha goes to the house $$$5$$$;  Sasha buys a tier of size $$$3$$$ near the $$$5$$$-th house ($$$a_5=3$$$);  Dima goes to the house $$$3$$$;  Dima buys a tier of size $$$2$$$ near the $$$3$$$-rd house ($$$a_3=2$$$);  Dima goes to the house $$$6$$$;  Dima buys a tier of size $$$3$$$ near the $$$6$$$-th house ($$$a_6=3$$$). So, Sasha goes the distance $$$3+1=4$$$, and Dima goes the distance $$$1+1+3=5$$$. In total, they cover a distance of $$$4+5=9$$$. You can make sure that with any other sequence of actions they will walk no less distance.

package main

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

func cleanString(stream string, seperator string) []int{
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, seperator)
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index,val := range splitArr{
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	input, _ := ir.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input))
	var nums []int
	lineInput, _ := ir.ReadString('\n')
	nums = cleanString(lineInput, " ")
	//fmt.Println(nums)
	lookup := make(map[int][]int)
	for i, num := range nums {
		lookup[num] = append(lookup[num], i)
	}

	var res int64
	// 两个人都必须要先到达1, res最终可能会很大，所以需要用int64
	res = int64(lookup[1][0] + lookup[1][1])
	// 每一轮两个人都要从i到i+1，无论这轮他们怎么走，之后的所有轮都是两个人从i+1出发，所以我们只要取得此轮最优即可
	for i := 1; i < n; i += 1 {
		// 一个人从第一个i到第一个i+1, 另一个人从第二个i到第二个i+1
		path1 := math.Abs(float64(lookup[i][0] - lookup[i+1][0])) + math.Abs(float64(lookup[i][1] - lookup[i+1][1]))
		// 一个人从第一个i到第二个i+1, 另一个人从第二个i到第一个i+1
		path2 := math.Abs(float64(lookup[i][0] - lookup[i+1][1])) + math.Abs(float64(lookup[i][1] - lookup[i+1][0]))
		// 加上这一轮的最优
		res += int64(math.Min(path1, path2))
	}
	fmt.Println(res)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, (n+1)*2)
	f := make([][]int, n+1)
	for i := 1; i <= n; i++ {
		f[i] = make([]int, 0)
	}
	for i := 0; i < n*2; i++ {
		fmt.Fscanf(in, "%d", &a[i])
		f[a[i]] = append(f[a[i]], i)
	}
	fmt.Fscanf(in, "\n")
	ans := int64(0)
	ans += int64(f[1][0] + f[1][1])
	for i := 2; i <= n; i++ {
		//fmt.Println(i, f[i])
		ans += int64(min(abs(f[i][0]-f[i-1][0])+abs(f[i][1]-f[i-1][1]), abs(f[i][0]-f[i-1][1])+abs(f[i][1]-f[i-1][0])))
	}

	fmt.Fprintf(out, "%d\n", ans)
	return
}

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

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

package main

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

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	a := make([]int, 2 * n)
	pos := make([][]int, n)
	dp := make([][]int64, n)

	for i := range a {
		fmt.Fscanf(buf, "%d", &a[i])
		a[i] -= 1
		pos[a[i]] = append(pos[a[i]], i)
		dp[a[i]] = append(dp[a[i]], 0)
	}

	ans := int64(pos[0][0] + pos[0][1])

	for i := 1; i < n; i++ {
		temp := abs(pos[i][0] - pos[i - 1][0]) + abs(pos[i][1] - pos[i - 1][1])
		temp2 := abs(pos[i][0] - pos[i - 1][1]) + abs(pos[i][1] - pos[i - 1][0])
		if temp < temp2 {
			ans += int64(temp)
		} else {
			ans += int64(temp2)
		}
	}

	fmt.Println(ans)
}

package main

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

func cleanString(stream string, seperator string) []int{
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, seperator)
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index,val := range splitArr{
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	input, _ := ir.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input))
	var nums []int
	lineInput, _ := ir.ReadString('\n')
	nums = cleanString(lineInput, " ")
	//fmt.Println(nums)
	lookup := make(map[int][]int)
	for i, num := range nums {
		lookup[num] = append(lookup[num], i)
	}
	lookup[0] = []int{0, 0}
	i := 0
	// 两个人都必须要先到达1
	//res := lookup[1][0] + lookup[1][1]
	var res int64
	// 每一轮两个人都要从i到i+1，无论这轮他们怎么走，之后的所有轮都是两个人从i+1出发，所以我们只要取得此轮最优即可
	for i < n {
		// 一个人从第一个i到第一个i+1, 另一个人从第二个i到第二个i+1
		path1 := math.Abs(float64(lookup[i][0] - lookup[i+1][0])) + math.Abs(float64(lookup[i][1] - lookup[i+1][1]))
		// 一个人从第一个i到第二个i+1, 另一个人从第二个i到第一个i+1
		path2 := math.Abs(float64(lookup[i][0] - lookup[i+1][1])) + math.Abs(float64(lookup[i][1] - lookup[i+1][0]))
		// 加上这一轮的最优
		res += int64(math.Min(path1, path2))
		//print("res", res)
		i += 1
	}
	fmt.Println(res)
}

package main

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

func getNumFromOneLine(ir *bufio.Reader) int{
	stream, _ := ir.ReadString('\n')
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	num, _ := strconv.Atoi(trimmedStream)
	return num
}

func getNumsFromOneLine(ir *bufio.Reader) []int{
	stream, _ := ir.ReadString('\n')
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, " ")
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index,val := range splitArr{
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	n := getNumFromOneLine(ir)
	nums := getNumsFromOneLine(ir)
	//fmt.Println(nums)
	lookup := make(map[int][]int)
	for i, num := range nums {
		lookup[num] = append(lookup[num], i)
	}
	// res最终可能会很大，所以需要用int64
	var res int64
	// 两个人都必须要先到达1, 所以要加上从0到1的距离
	res = int64(lookup[1][0] + lookup[1][1])
	// 每一轮两个人都要从i到i+1，无论这轮他们怎么走，之后的所有轮都是两个人从i+1出发，所以我们只要取得此轮最优即可
	for i := 1; i < n; i += 1 {
		// 一个人从第一个i到第一个i+1, 另一个人从第二个i到第二个i+1
		path1 := math.Abs(float64(lookup[i][0] - lookup[i+1][0])) + math.Abs(float64(lookup[i][1] - lookup[i+1][1]))
		// 一个人从第一个i到第二个i+1, 另一个人从第二个i到第一个i+1
		path2 := math.Abs(float64(lookup[i][0] - lookup[i+1][1])) + math.Abs(float64(lookup[i][1] - lookup[i+1][0]))
		// 加上这一轮的最优距离
		res += int64(math.Min(path1, path2))
	}
	fmt.Println(res)
}

package main

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

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	a := make([]int, 2 * n)
	pos := make([][]int, n)
	dp := make([][]int64, n)

	for i := range a {
		fmt.Fscanf(buf, "%d", &a[i])
		a[i] -= 1
		pos[a[i]] = append(pos[a[i]], i)
		dp[a[i]] = append(dp[a[i]], 0)
	}

	ans := pos[0][0] + pos[0][1]

	for i := 1; i < n; i++ {
		temp := abs(pos[i][0] - pos[i - 1][0]) + abs(pos[i][1] - pos[i - 1][1])
		temp2 := abs(pos[i][0] - pos[i - 1][1]) + abs(pos[i][1] - pos[i - 1][0])
		if temp < temp2 {
			ans += temp
		} else {
			ans += temp2
		}
	}

	fmt.Println(ans)
}

package main

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

func cleanString(stream string, seperator string) []int{
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, seperator)
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index,val := range splitArr{
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	input, _ := ir.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input))
	var nums []int
	lineInput, _ := ir.ReadString('\n')
	nums = cleanString(lineInput, " ")
	//fmt.Println(nums)
	lookup := make(map[int][]int)
	for i, num := range nums {
		lookup[num] = append(lookup[num], i)
	}
	i := 1
	// 两个人都必须要先到达1
	res := lookup[1][0] + lookup[1][1]
	// 每一轮两个人都要从i到i+1，无论这轮他们怎么走，之后的所有轮都是两个人从i+1出发，所以我们只要取得此轮最优即可
	for i < n {
		// 一个人从第一个i到第一个i+1, 另一个人从第二个i到第二个i+1
		path1 := math.Abs(float64(lookup[i][0] - lookup[i+1][0])) + math.Abs(float64(lookup[i][1] - lookup[i+1][1]))
		// 一个人从第一个i到第二个i+1, 另一个人从第二个i到第一个i+1
		path2 := math.Abs(float64(lookup[i][0] - lookup[i+1][1])) + math.Abs(float64(lookup[i][1] - lookup[i+1][0]))
		// 加上这一轮的最优
		res += int(math.Min(path1, path2))
		//print("res", res)
		i += 1
	}
	fmt.Println(res)

}

package main

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

func cleanString(stream string, seperator string) []int{
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, seperator)
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index,val := range splitArr{
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	input, _ := ir.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input))
	var nums []int
	lineInput, _ := ir.ReadString('\n')
	nums = cleanString(lineInput, " ")
	//fmt.Println(nums)
	lookup := make(map[int][]int)
	for i, num := range nums {
		lookup[num] = append(lookup[num], i)
	}

	var res int64
	// 两个人都必须要先到达1, res最终可能会很大，所以需要用int64
	res = int64(lookup[1][0] + lookup[1][1])
	// 每一轮两个人都要从i到i+1，无论这轮他们怎么走，之后的所有轮都是两个人从i+1出发，所以我们只要取得此轮最优即可
	for i := 1; i < n; i += 1 {
		// 一个人从第一个i到第一个i+1, 另一个人从第二个i到第二个i+1
		path1 := math.Abs(float64(lookup[i][0] - lookup[i+1][0])) + math.Abs(float64(lookup[i][1] - lookup[i+1][1]))
		// 一个人从第一个i到第二个i+1, 另一个人从第二个i到第一个i+1
		path2 := math.Abs(float64(lookup[i][0] - lookup[i+1][1])) + math.Abs(float64(lookup[i][1] - lookup[i+1][0]))
		// 加上这一轮的最优
		res += int64(math.Min(path1, path2))
		//print("res", res)
		i += 1
	}
	fmt.Println(res)
}

package main

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

func cleanString(stream string, seperator string) []int{
	// Trims the stream and then splits
	trimmedStream := strings.TrimSpace(stream)
	splitArr := strings.Split(trimmedStream, seperator)
	// convert strings to integers and store them in a slice
	nums := make([]int, len(splitArr))
	for index,val := range splitArr{
		nums[index], _ = strconv.Atoi(val)
	}
	return nums
}

func main() {
	ir := bufio.NewReader(os.Stdin)
	input, _ := ir.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input))
	var nums []int
	lineInput, _ := ir.ReadString('\n')
	nums = cleanString(lineInput, " ")
	//fmt.Println(nums)
	lookup := make(map[int][]int)
	for i, num := range nums {
		lookup[num] = append(lookup[num], i)
	}
	lookup[0] = []int{0, 0}
	i := 0
	// 两个人都必须要先到达1
	//res := lookup[1][0] + lookup[1][1]
	res := 0
	// 每一轮两个人都要从i到i+1，无论这轮他们怎么走，之后的所有轮都是两个人从i+1出发，所以我们只要取得此轮最优即可
	for i < n {
		// 一个人从第一个i到第一个i+1, 另一个人从第二个i到第二个i+1
		path1 := math.Abs(float64(lookup[i][0] - lookup[i+1][0])) + math.Abs(float64(lookup[i][1] - lookup[i+1][1]))
		// 一个人从第一个i到第二个i+1, 另一个人从第二个i到第一个i+1
		path2 := math.Abs(float64(lookup[i][0] - lookup[i+1][1])) + math.Abs(float64(lookup[i][1] - lookup[i+1][0]))
		// 加上这一轮的最优
		res += int(math.Min(path1, path2))
		//print("res", res)
		i += 1
	}
	fmt.Println(res)

}