package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int

// var A []int64
var A []int
var m int
var k, pos int

var answers [105][]int

// var sA Int64Slice
var sA []int

func main() {
	n = ReadInt()
	// A = ReadInt64Slice(n)
	A = ReadIntSlice(n)
	m = ReadInt()

	// sA = make(Int64Slice, n)
	sA = make([]int, n)
	for i := 0; i < n; i++ {
		sA[i] = A[i]
	}
	// sort.Sort(sA)
	sort.Sort(sort.Reverse(sort.IntSlice(sA)))

	sub()

	for i := 0; i < m; i++ {
		k, pos = ReadInt2()
		pos--

		fmt.Println(answers[k][pos])
	}

	// debug
	// for k := 1; k <= n; k++ {
	// 	fmt.Println(answers[k])
	// }
}

func sub() {
	for k := 1; k <= n; k++ {
		answers[k] = make([]int, k)

		topk := sA[:k]
		tmp := subsub(k, topk)

		sort.Sort(sort.IntSlice(tmp))

		for i := 0; i < k; i++ {
			answers[k][i] = A[tmp[i]]
		}
	}
}

// Aのidxの配列を返す
func subsub(k int, topk []int) []int {
	res := make([]int, k)
	memo := make([]bool, n)
	for i := 0; i < k; i++ {
		// Aと照合させる
		for j := 0; j < n; j++ {
			if topk[i] == A[j] && !memo[j] {
				res[i] = j
				memo[j] = true
				break
			}
		}
	}
	return res
}

type Int64Slice []int64

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

// S := Int64Slice{'a', 'b', 'c'}
// sort.Sort(S) or sort.Sort(sort.Reverse(S))

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type Tai struct {
	a int
	i int
}

func solve() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ai := make([]Tai, n)
	for i, v := range a {
		ai[i]= Tai{v, i}
	}
	sort.Slice(ai, func(i, j int) bool {
		return (ai[i].a < ai[j].a) || ((ai[i].a == ai[j].a)&&(ai[i].i > ai[j].i))
	})
	//fmt.Println(ai)
	m := ReadInt()
	for t := 0; t < m; t++ {
		k, p := ReadInt2()
		aisorted := make([]Tai,k)
		copy(aisorted,ai[len(ai)-k:len(ai)])
		sort.Slice(aisorted, func(i, j int) bool {
			return (aisorted[i].i < aisorted[j].i)
		})
//		fmt.Println(aisorted)
		fmt.Println(aisorted[p-1].a)
	}
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type Tai struct {
	a int
	i int
}
type KPI struct{
	k int
	p int
	i int
	ans int
}

func solve() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ai := make([]Tai, n)
	for i, v := range a {
		ai[i] = Tai{v, i}
	}
	sort.Slice(ai, func(i, j int) bool {
		return (ai[i].a < ai[j].a) || ((ai[i].a == ai[j].a) && (ai[i].i > ai[j].i))
	})
	//fmt.Println("n:", n, "ai:", ai)
	m := ReadInt()
	kp := make([]*KPI, m)
	kpidx := make([]*KPI,m)
	for t := 0; t < m; t++ {
		k, p := ReadInt2()
		kp[t] = &KPI{k, p,t, -1}
		kpidx[t] = kp[t]
	}
	sort.Slice(kp, func(i, j int) bool { return (kp[i].k < kp[j].k) })
	//fmt.Println("kp: ", kp)

	aisorted := make([]Tai, n)
	copy(aisorted, ai)
	kold := -1
	for t := 0; t < m; t++ {
		k, p := kp[t].k, kp[t].p
		if k != kold {
			kold = k
			sort.Slice(aisorted[n-k:], func(i, j int) bool {
				return (aisorted[n-k+i].i < aisorted[n-k+j].i)
			})
		}
		kp[t].ans = aisorted[n-k+p-1].a
	}
	for _,v:= range kpidx{
		//fmt.Println("k:", k, "pos:",i," idx:", n-k+p-1, " ais:", aisorted)
		fmt.Printf("%d\n", v.ans)
	}
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	type pair struct {
		val, pos int
	}
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &ps[i].val)
		ps[i].pos = i
	}
	sort.Slice(ps, func(i, j int) bool {
		return ps[i].val > ps[j].val || ps[i].val == ps[j].val && ps[i].pos < ps[j].pos
	})

	var m int
	for Fscan(in, &m); m > 0; m-- {
		var k, pos int
		Fscan(in, &k, &pos)
		arr := make([]pair,  k)
		copy(arr, ps[:k])
		sort.Slice(arr, func(i, j int) bool {
			return arr[i].pos < arr[j].pos
		})
		Fprintln(out, arr[pos-1].val)
	}
}

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

func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

type el struct {
	val, i int
}

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

	a := make([]el, n)
	var tmp int
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &tmp)
		a[i].val = tmp
		a[i].i = i
	}
	fmt.Fscan(in, &m)

	sort.Slice(a, func(l, r int) bool {
		if a[l].val != a[r].val {
			return a[l].val < a[r].val
		}
		return a[l].i > a[r].i
	})

	var k, pos int
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &k, &pos)

		tmp := append([]el(nil), a[n-k:]...)
		sort.Slice(tmp, func(l, r int) bool {
			return tmp[l].i < tmp[r].i
		})
		fmt.Println(tmp[pos-1].val)
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type Tai struct {
	a int
	i int
}

func solve() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ai := make([]Tai, n)
	for i, v := range a {
		ai[i]= Tai{v, i}
	}
	sort.Slice(ai, func(i, j int) bool {
		return ai[i].a < ai[j].a || ((ai[i].a == ai[j].a) && (ai[i].i < ai[j].i))
	})
	m := ReadInt()
	for t := 0; t < m; t++ {
		k, p := ReadInt2()
		aisorted := ai[len(ai)-k:len(ai)]
		sort.Slice(aisorted, func(i, j int) bool {
			return (ai[i].i < ai[j].i)
		})
		fmt.Println(aisorted[p-1].a)
	}
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type Tai struct {
	a int
	i int
}

func solve() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ai := make([]Tai, n)
	for i, v := range a {
		ai[i]= Tai{v, i}
	}
	sort.Slice(ai, func(i, j int) bool {
		return (ai[i].a < ai[j].a) || ((ai[i].a == ai[j].a)&&(ai[i].i > ai[j].i))
	})
	fmt.Println(ai)
	m := ReadInt()
	for t := 0; t < m; t++ {
		k, p := ReadInt2()
		aisorted := make([]Tai,k)
		copy(aisorted,ai[len(ai)-k:len(ai)])
		sort.Slice(aisorted, func(i, j int) bool {
			return (aisorted[i].i < aisorted[j].i)
		})
//		fmt.Println(aisorted)
		fmt.Println(aisorted[p-1].a)
	}
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func init() {
	var f *os.File
	if runtime.GOROOT() == "C:\\SOFT\\Go" {
		f, _ = os.Open("input.txt")
		//defer f.Close()
	} else {
		f = os.Stdin
	}
	ReadString = newReadString(f)
	stdout = bufio.NewWriter(os.Stdout)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

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

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

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

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

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

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

	return string(res)
}

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

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

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

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

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

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

type Tai struct {
	a int
	i int
}

func solve() {
	n := ReadInt()
	a := ReadIntSlice(n)
	ai := make([]Tai, n)
	for i, v := range a {
		ai[i]= Tai{v, i}
	}
	sort.Slice(ai, func(i, j int) bool {
		return ai[i].a < ai[j].a || ((ai[i].a == ai[j].a) && (ai[i].i > ai[j].i))
	})
//	fmt.Println(ai)
	m := ReadInt()
	for t := 0; t < m; t++ {
		k, p := ReadInt2()
		aisorted := ai[len(ai)-k:len(ai)]
		sort.Slice(aisorted, func(i, j int) bool {
			return (aisorted[i].i < aisorted[j].i)
		})
//		fmt.Println(aisorted)
		fmt.Println(aisorted[p-1].a)
	}
}

func main() {
	//t := ReadInt()
	t := 1
	for ; t > 0; t-- {
		solve()
	}
}


package main

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

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

func (in *CF1535A) 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 *CF1535A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
 Run solve the problem CF1535A
 Date: 11/06/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1535/A
 Problem: CF1535A
**/
func (in *CF1535A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		s1, s2, s3, s4 := in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()

		arr := []int{s1, s2, s3, s4}
		sort.Ints(arr)

		ans := "YES"
		if (arr[3] == s1 && arr[2] == s2) || (arr[3] == s2 && arr[2] == s1) {
			ans = "NO"
		} else if (arr[3] == s3 && arr[2] == s4) || (arr[3] == s4 && arr[2] == s3) {
			ans = "NO"
		}

		fmt.Println(ans)
	}
}

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

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

package main

import(
	"fmt"
	"bufio"
	"io"
	"os"

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		/*var n int

		fmt.Fscan(in , &n)*/

		scorepoints := make([]int , 4)
		var Fisrtmax int
		var FirstMin int
		var Nextmin int
		var Nextmax int

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

		fmt.Fscan(in , &scorepoints[i])

			if i == 1 {

			Fisrtmax = max(scorepoints[i-1], scorepoints[i])
			FirstMin = min(scorepoints[i-1], scorepoints[i])

		}

			if  i == len(scorepoints)-1 {
				Nextmax = max(scorepoints[i-1] , scorepoints[i])
				Nextmin = min(scorepoints[i-1] , scorepoints[i])

		//fmt.Println("maxNum",Nextmax, "Nextmin",Nextmin,"Fisrtmax",Fisrtmax,"FirstMin",FirstMin)
				if Nextmin > Fisrtmax ||  FirstMin > Nextmax {
					fmt.Fprintln(out,"NO")
					return
				}else{
					fmt.Fprintln(out,"YES")
					return
				}
			}

		}

	}

	T := 1

	fmt.Fscan(in ,&T)

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

}

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

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

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

package main

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

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

func maxes(arr [4]int) (int, int) {
	var max1, max2 int
	if arr[0] > arr[1] {
		max1, max2 = arr[0], arr[1]
	} else {
		max2, max1 = arr[0], arr[1]
	}
	for _, v := range arr[1:] {
		if v < max1 && v > max2 {
			max2 = v
		}
		if v > max1 {
			max2 = max1
			max1 = v

		}
	}

	return max1, max2
}

func main() {
	defer writer.Flush()
	var n, max, max2, win1, win2 int
	var arr [4]int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d %d %d\n", &arr[0], &arr[1], &arr[2], &arr[3])
		max, max2 = maxes(arr)
// 		fmt.Fprintln(writer, max, max2)
		win1, win2 = arr[1], arr[2]
		if arr[0] > arr[1] {
			win1 = arr[0]
		}
		if arr[3] > arr[2] {
			win2 = arr[3]
		}
		if win1 > win2 {
			if max != win1 {
				fmt.Fprintln(writer, "NO")
				continue
			}
			if max2 != win2 {
				fmt.Fprintln(writer, "NO")
				continue
			}

		}
		if win1 < win2 {
			if max != win2 {
				fmt.Fprintln(writer, "NO")
				continue
			}
			if max2 != win1 {
				fmt.Fprintln(writer, "NO")
				continue
			}

		}
		fmt.Fprintln(writer, "YES")
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var x, m, sm, im, ism int
		for i := 1; i <= 4; i++ {
			fmt.Scan(&x)
			if x > m {
				sm = m
				ism = im
				m = x
				im = i
			} else if x > sm {
				sm = x
				ism = i
			}
		}
		//fmt.Println(m, im, sm, ism)
		if (im == 3 || im == 4) && (ism == 1 || ism == 2) {
			fmt.Println("YES")
		} else if (im == 1 || im == 2) && (ism == 3 || ism == 4) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scan(&n)
	for i:=0;i<n;i++{
		var a,b,c,d int
		fmt.Scan(&a,&b,&c,&d)
		if a > b {
			if b > c && b > d {
				fmt.Println("NO")
				continue
			}
			if a < c && a < d {
				fmt.Println("NO")
				continue
			}
		} else {
			if a > c && a > d {
				fmt.Println("NO")
				continue
			}
			if b < c && b < d {
				fmt.Println("NO")
				continue
			}
		}
		fmt.Println("YES")
	}
}

// 1535A. Fair Playoff
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		a := make([]int, 4)
		m := make(map[int]int)
		for i := 0; i < 4; i++ {
			fmt.Fscan(reader, &a[i])
			m[a[i]] = i
		}
		sort.Ints(a)
		i, j := m[a[2]], m[a[3]]
		if i < 2 && j >= 2 || j < 2 && i >= 2 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

import (
	"bufio"
	"os"
	"strings"
)

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

	test := parseInt(getString(reader))
	for ; test > 0; test-- {
		S := getIntln(reader)
		a, b, c, d := max(S[0], S[1]), min(S[0], S[1]), max(S[2], S[3]), min(S[2], S[3])
		if a >= d && c >= b {
			writer.WriteString("YES\n")
		} else {
			writer.WriteString("NO\n")
		}
	}
	writer.Flush()
}

func max(a ...int) int {
	var res = a[0]
	for _, v := range a {
		if v > res {
			res = v
		}
	}
	return res
}

func min(a ...int) int {
	var res = a[0]
	for _, v := range a {
		if v < res {
			res = v
		}
	}
	return res
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

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

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

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

		var f bool
		if s1 > s2 && (s1 > s3 || s1 > s4) && (s2 < s3 || s2 < s4) {
			f = true
		} else if s2 > s1 && (s2 > s3 || s2 > s4) && (s1 < s3 || s1 < s4) {
			f = true
		}

		if !f {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

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

func solve(s []int) string {
	max1, min1 := maxmin(s[0], s[1])
	max2, min2 := maxmin(s[2], s[3])
	if min1 > max2 || min2 > max1 {
		return "NO"
	}
	return "YES"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		s := make([]int, 4)
		fmt.Fscan(reader, &s[0], &s[1], &s[2], &s[3])
		fmt.Println(solve(s))
	}
}

package main

import "fmt"

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

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

func main() {
	var T int
	fmt.Scan(&T)

	for t := 0; t < T; t++ {
		var arr [4]int

		for i := 0; i < 4; i++ {
			fmt.Scan(&arr[i])
		}

		f1 := max(arr[0], arr[1])
		l1 := min(arr[0], arr[1])

		f2 := max(arr[2], arr[3])
		l2 := min(arr[2], arr[3])

		if f1 > l2 && f2 > l1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int
	fmt.Scanln(&t)

	for i := 0; i < t;i ++ {
		var a, b, c, d float64
		fmt.Scanln(&a, &b, &c, &d)

		abMax := math.Max(a, b)
		abMin := math.Min(a, b)

		cdMax := math.Max(c, d)
		cdMin := math.Min(c, d)

		if abMax > cdMin && cdMax > abMin {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func LITTLE(x int) int64 {
	var answer int64
	answer = answer + int64((x*x*x*x-x*x)/4) + int64(x*x*(x-1)*(x-1)/8) - int64(x*(x-1)*(x+x+1)*(x+x-1)/12)
	return answer
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		ARRAY := make([]int, 5)

		for i := 1; i < 5; i++ {
			fmt.Fscan(input, &ARRAY[i])

		}

		var biggest, bigind int
		var Second, Snd int

		for i := 1; i < 5; i++ {
			if ARRAY[i] > biggest {
				biggest = ARRAY[i]
				bigind = i
			}
		}
		for i := 1; i < 5; i++ {
			if ARRAY[i] > Second && ARRAY[i] < biggest {
				Second = ARRAY[i]
				Snd = i
			}
		}
		if Snd+bigind == 3 || Snd+bigind == 7 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")

		}

	}

}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

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

	solve := func(Case int) {
		type pair struct{ v, i int }
		a := make([]pair, 4)
		for i := range a {
			Fscan(in, &a[i].v)
			a[i].i = i
		}
		sort.Slice(a, func(i, j int) bool { return a[i].v < a[j].v })
		x := 1<<a[0].i | 1<<a[1].i
		if x == 0b11 || x == 0b1100 {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

import (
    "fmt"
)

func main() {
    var s [4]int
    var tc int

    mapping := [4]int{1, 0, 3, 2}

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

    for ; tc != 0; tc-- {
	for i := 0; i < 4; i++ {
	    fmt.Scanf("%d", &s[i])
	}
	fmt.Scanf("\n")
	//fmt.Println(s)

	var imax1, imax2 int

	if s[0] > s[1] {
	    imax1 = 0
	} else {
	    imax1 = 1
	}

	if s[2] > s[3] {
	    imax2 = 2
	} else {
	    imax2 = 3
	}

	var fair bool

	if s[imax1] > s[imax2] {
	    fair = s[mapping[imax1]] < s[imax2]
	    //fmt.Println("first:", mapping[imax1], s[mapping[imax1]], s[imax2])
	} else {
	    fair = s[mapping[imax2]] < s[imax1]
	    //fmt.Println("second:", mapping[imax2], s[mapping[imax2]], s[imax1])
	}

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

package main

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

func minimum(a int32, b int32) int32 {
	if a < b {
		return a
	} else {
		return b
	}
}

func maximum(a int32, b int32) int32 {
	if a > b {
		return a
	} else {
		return b
	}
}

func solve(x int32, y int32, a int32, b int32) string {
	minLeft := minimum(x, y)
	maxLeft := maximum(x, y)
	minRight := minimum(a, b)
	maxRight := maximum(a, b)
	if maxLeft > minRight && maxRight > minLeft {
		return "YES"
	} else {
		return "NO"
	}
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		m := int32(0)
		a := int32(0)
		b := int32(0)
		fmt.Fscanf(in, "%d %d %d %d\n", &n, &m, &a, &b)
		fmt.Fprintf(out, "%s\n", solve(n, m, a, b))
		tt--
	}
	out.Flush()
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (isPrefix bool = true
		err error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln),err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)

	for i:=0; i<k; i++ {
		pln,_ := Readln(reader)
		sln := strings.Split(pln," ")
		ln :=  make([] int, 4)
		for j := range sln {
			ln[j], _ = strconv.Atoi(sln[j])
		}
		win1 := 0
		if ln[0] > ln[1] {
			win1 = ln[0]
		} else {
			win1 = ln[1]
		}
		win2 := 0
		if ln[2] > ln[3] {
			win2 = ln[2]
		} else {
			win2 = ln[3]
		}
		sort.Ints(ln)
		if ln[3]+ln[2] != win1+win2 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")

		}

	}

}

package main

import (
    "fmt"
)

func main() {
    var s [4]int
    var tc int

    mapping := [4]int{1, 0, 3, 2}

    fmt.Scanf("%d", &tc)

    for ; tc != 0; tc-- {
	for i := 0; i < 4; i++ {
	    fmt.Scanf("%d", &s[i])
	}

	var imax1, imax2 int

	if s[0] > s[1] {
	    imax1 = 0
	} else {
	    imax1 = 1
	}

	if s[2] > s[3] {
	    imax2 = 2
	} else {
	    imax2 = 3
	}

	var fair bool

	if s[imax1] > s[imax2] {
	    fair = s[mapping[imax1]] < s[imax2]
	} else {
	    fair = s[mapping[imax2]] < s[imax1]
	}

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

package main

import (
    "fmt"
)

func main() {
    var s [4]int
    var tc int

    mapping := [4]int{1, 0, 3, 2}

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

    for ; tc != 0; tc-- {
	for i := 0; i < 4; i++ {
	    fmt.Scanf("%d", &s[i])
	}
	fmt.Scanf("\n")
	//fmt.Println(s)

	var imax1, imax2 int

	if s[0] > s[1] {
	    imax1 = 0
	} else {
	    imax1 = 1
	}

	if s[2] > s[3] {
	    imax2 = 2
	} else {
	    imax2 = 3
	}

	var fair bool

	if s[imax1] > s[imax2] {
	    fair = s[mapping[imax1]] < s[imax2]
	    //fmt.Println("first:", mapping[imax1], s[mapping[imax1]], s[imax2])
	} else {
	    fair = s[mapping[imax2]] < s[imax1]
	    //fmt.Println("second:", mapping[imax2], s[mapping[imax2]], s[imax1])
	}

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

package main

import (
    "fmt"
)

func main() {
    var s [4]int
    var tc int

    mapping := [4]int{1, 0, 3, 2}

    fmt.Scanf("%d", &tc)

    for ; tc != 0; tc-- {
	for i := 0; i < 4; i++ {
	    fmt.Scanf("%d", &s[i])
	}

	fmt.Println(s)

	var imax1, imax2 int

	if s[0] > s[1] {
	    imax1 = 0
	} else {
	    imax1 = 1
	}

	if s[2] > s[3] {
	    imax2 = 2
	} else {
	    imax2 = 3
	}

	var fair bool

	if s[imax1] > s[imax2] {
	    fair = s[mapping[imax1]] < s[imax2]
	} else {
	    fair = s[mapping[imax2]] < s[imax1]
	}

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

package main

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

func isNotFair(x int32, a int32, b int32) bool {
	return (x < a && x < b) || (x > a && x > b)
}

func solve(x int32, y int32, a int32, b int32) string {
	if x > y && isNotFair(x, a, b) {
		return "NO"
	}
	if y > x && isNotFair(y, a, b) {
		return "NO"
	}
	return "YES"
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		m := int32(0)
		a := int32(0)
		b := int32(0)
		fmt.Fscanf(in, "%d %d %d %d\n", &n, &m, &a, &b)
		fmt.Fprintf(out, "%s\n", solve(n, m, a, b))
		tt--
	}
	out.Flush()
}

package main

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

func isNotFair(x int32, a int32, b int32) bool {
	return (x < a && x < b) || (x > a && x > b)
}

func solve(x int32, y int32, a int32, b int32) string {
	if x > y && isNotFair(x, a, b) {
		return "NO"
	}
	if y > x && isNotFair(y, a, b) {
		return "NO"
	}
	return "YES"
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		m := int32(0)
		a := int32(0)
		b := int32(0)
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		fmt.Fprintf(out, "%s\n", solve(n, m, a, b))
		tt--
	}
	out.Flush()
}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (isPrefix bool = true
		err error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln),err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)

	for i:=0; i<k; i++ {
		pln,_ := Readln(reader)
		sln := strings.Split(pln," ")
		ln :=  make([] int, k)
		for j := range sln {
			ln[j], _ = strconv.Atoi(sln[j])
		}
		win1 := 0
		if ln[0] > ln[1] {
			win1 = ln[0]
		} else {
			win1 = ln[1]
		}
		win2 := 0
		if ln[2] > ln[3] {
			win2 = ln[2]
		} else {
			win2 = ln[3]
		}
		sort.Ints(ln)
		if ln[3]+ln[2] != win1+win2 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")

		}

	}

}

package main

import(
	"fmt"
	"bufio"
	"io"
	"os"

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		/*var n int

		fmt.Fscan(in , &n)*/

		scorepoints := make([]int , 4)
		Fisrtmax := -1
		var FirstMin int
		var Nextmin int
		var Nextmax int

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

		fmt.Fscan(in , &scorepoints[i])

			if i < 2 {

			Fisrtmax = max(Fisrtmax, scorepoints[i])

		}
			FirstMin = min(Fisrtmax , scorepoints[1])

			if  i == len(scorepoints)-1 {
				Nextmax = max(scorepoints[i-1] , scorepoints[i])
				Nextmin = min(scorepoints[i-1] , scorepoints[i])

		//fmt.Println("maxNum",Nextmax, "Nextmin",Nextmin,"Fisrtmax",Fisrtmax,"FirstMin",FirstMin)
				if Nextmin > Fisrtmax ||  FirstMin > Nextmax {
					fmt.Fprintln(out,"NO")
					return
				}else{
					fmt.Fprintln(out,"YES")
					return
				}
			}

		}

	}

	T := 1

	fmt.Fscan(in ,&T)

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

}

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

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

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

package main

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

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

func maxes(arr [4]int) (int, int) {
	var max1, max2 int
	if arr[0] > arr[1] {
		max1, max2 = arr[0], arr[1]
	} else {
		max2, max1 = arr[0], arr[1]
	}
	for _, v := range arr[1:] {
		if v < max1 && v > max2 {
			max2 = v
		}
		if v > max1 {
			max2 = max1
			max1 = v

		}
	}

	return max1, max2
}

func main() {
	defer writer.Flush()
	var n, max, max2, win1, win2 int
	var arr [4]int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d %d %d\n", &arr[0], &arr[1], &arr[2], &arr[3])
		max, max2 = maxes(arr)
		fmt.Fprintln(writer, max, max2)
		win1, win2 = arr[1], arr[2]
		if arr[0] > arr[1] {
			win1 = arr[0]
		}
		if arr[3] > arr[2] {
			win2 = arr[3]
		}
		if win1 > win2 {
			if max != win1 {
				fmt.Fprintln(writer, "NO")
				continue
			}
			if max2 != win2 {
				fmt.Fprintln(writer, "NO")
				continue
			}

		}
		if win1 < win2 {
			if max != win2 {
				fmt.Fprintln(writer, "NO")
				continue
			}
			if max2 != win1 {
				fmt.Fprintln(writer, "NO")
				continue
			}

		}
		fmt.Fprintln(writer, "YES")
	}
}


package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,x int
	fmt.Fscan(in,&n)
	a := make([]int,n + 2)
	for i := 1 ;i  <= n;i++{
		fmt.Fscan(in,&x)
		a[i] = x
	}
	ans := 0
	for i := 1 ; i <= n;i++{
		mx := a[i]
		ans ++
		for mx > i{
			i ++
			mx = max(mx,a[i])
		}
	}
	fmt.Fprint(out,ans)

}

func max(i int, i2 int) int {
	if(i < i2){
		return i2
	}else{
		return i
	}
}
func min(i int , i2 int)  int {
	if(i < i2){
		return i
	}else{
		return i2
	}

}

package main

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

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

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

// task A
func main() {
	defer writer.Flush()

	var n string
	scanf("%s\n", &n)

	size, _ := strconv.Atoi(n)

	var val string
	var page, days, max int
	max = 1;
	days = 0;
	page = 0;

	for (page < size) {
		scanf("%s ", &val)
		page++;
		num, _ := strconv.Atoi(val)
		if (num > max) {
			max = num;
		} else if (page == max) {
			max++;
			days++;
		}
	}
	printf("%d\n", days)
}

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)
	ans := 0
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
		a[i]--
	}
	i := 0
	//	fmt.Println(n)
	for i < n {
		ans++
		max := a[i]
		for i < max && i < n {
			//fmt.Println(i, max)
			i++
			if a[i] > max {
				max = a[i]
			}
		}
		i++
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

package main

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

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

	fmt.Fscan(reader, &n)
	var mx, count int
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)
		mx = max(mx, x)

		if mx == i+1 {
			count++
		}
	}

	fmt.Println(count)
}

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

package main

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

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

	fmt.Fscan(reader, &n)

	sherlock := make(map[int]bool)

	var count int
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)
		sherlock[x] = true
		delete(sherlock, i+1)
		if len(sherlock) == 0 {
			count++
		}
	}

	fmt.Println(count)
}

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

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    ans := 0
    cur := 1

    for i := 1; i <= n; i ++ {
        var a int
        fmt.Scan(&a)
        cur = max(a, cur)
        if cur <= i {
            ans++
            cur = i + 1
        }
    }

    fmt.Print(ans)
}

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

    return y
}

package main

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

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

	var n int

	fmt.Fscanf(buf, "%d\n", &n)
	mat := make([]int,n+1)

	var ans int64 = 0
	for i:=0;i < n;i++{
		fmt.Fscanf(buf, "%d", &mat[i])
	}
	var p int=0
	for i:=0;i < n;i++{
		if mat[i] > p{
			p = mat[i]
		}
		if p <=i+1{
			ans++
			p = i+1
		//	fmt.Printf("%d\n",i+1)
		}

	}
	fmt.Printf("%d\n", ans)

}

package main

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

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

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

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

	var n string
	scanf("%s\n", &n)

	size, _ := strconv.Atoi(n)
	a := make([]int, size)

	var val string

	for i := 0;  i < size; i++ {
		scanf("%s ", &val)
		a[i], _ = strconv.Atoi(val)
	}
	///////////
   var numOfDays, index int
   size2 := size
   numOfDays = 1

   for {
		if (a[index] > index + 1) {
			size2 = size - a[index]
		} else {
			numOfDays += 1
		}
	   index += 1
		if (size2 == 0 || index >= size) {
			break
		}
	}
	print(numOfDays - 2)
}

package main

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

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

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

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

	var n string
	scanf("%s\n", &n)

	size, _ := strconv.Atoi(n)
	a := make([]int, size)

	var val string

	for i := 0;  i < size; i++ {
		scanf("%s ", &val)
		a[i], _ = strconv.Atoi(val)
	}
	///////////
   var numOfDays, curMax, index int
	curMax = a[0]
   size2 := size
   numOfDays = 1

   for {
		if (a[index] <= index + 1) {
			if (curMax > index) {
				index = curMax
			} else {
				numOfDays += 1
				index += 1
			}
		} else {
			if (curMax < a[index] ) {
				curMax = a[index]
			}
			index += 1
		}
		if (size2 == 0 || index >= size) {
			break
		}
	}
	print(numOfDays+2)
}

package main

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

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

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

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

	var n string
	scanf("%s\n", &n)

	size, _ := strconv.Atoi(n)
	a := make([]int, size)

	var val string

	for i := 0;  i < size; i++ {
		scanf("%s ", &val)
		a[i], _ = strconv.Atoi(val)
	}
	///////////
   var numOfDays, curMax, index int
	curMax = a[0]
   size2 := size
   numOfDays = 1

   for {
		if (a[index] <= index + 1) {
			if (curMax > index) {
				index = curMax
			} else {
				numOfDays += 1
				index += 1
			}
		} else {
			if (curMax < a[index] ) {
				curMax = a[index]
			}
			index += 1
		}
		if (size2 == 0 || index >= size) {
			break
		}
	}
	printf("%d\n",numOfDays+1)
}

package main

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

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

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

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

	var n string
	scanf("%s\n", &n)

	size, _ := strconv.Atoi(n)
	a := make([]int, size)

	var val string

	for i := 0;  i < size; i++ {
		scanf("%s ", &val)
		a[i], _ = strconv.Atoi(val)
	}
	///////////
   var numOfDays, curMax, index int
	curMax = a[0]
   size2 := size
   numOfDays = 1

   for {
		if (a[index] <= index + 1) {
			if (curMax > index) {
				index = curMax
			} else {
				numOfDays += 1
				index += 1
			}
		} else {
			if (curMax < a[index] ) {
				curMax = a[index]
			}
			index += 1
		}
		if (size2 == 0 || index >= size) {
			break
		}
	}
	print(numOfDays+1)
}


/*
URL:
https://codeforces.com/contest/1455/problem/C
*/

package main

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

var (
	t int

	x, y int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		x, y = readi2()

		solve()
	}
}

func solve() {
	printf("%d %d\n", x-1, y)
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

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

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

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

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

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

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

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

	return res
}

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &x, &y)

		fmt.Printf("%d %d\n", x-1, y)
	}
}


package main

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

func main() {
	sc := NewScanner()
	N, A := sc.NextInt(), sc.NextInt()

	S := sc.NextLine()
	if A == 1 {
		fmt.Println(S)
		return
	}

	last := N
	for i := 1; i < N; i++ {
		flag := true
		for j := 0; i+j < N; j++ {
			if S[i+j] != S[j] {
				flag = false
				break
			}
		}
		if flag {
			last = i
			break
		}
	}

	out := S
	for i := 1; i < A; i++ {
		out += S[N-last:]
	}
	fmt.Println(out)

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

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

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

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

	return mp
}

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

// You can edit this code!
// Click here and start typing.
package main

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

var nxt [55]int

func getNext(s string, n int) {
	nxt[0] = -1
	j := -1
	for i := 0; i < n; {
		if j == -1 || s[i] == s[j] {
			i++
			j++
			nxt[i] = j
		} else {
			j = nxt[j]
		}
	}
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var n, k int
	var s string
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &k)
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &s)

	getNext(s, n)
	p := n - nxt[n]

	fmt.Println(s + strings.Repeat(s[n-p:n], k-1))
}

package main

import "fmt"

func main() {
	var n, k int
	var s string
	fmt.Scan(&n, &k)
	fmt.Scan(&s)
	id := 0
	for i := 1; i < n; i++ {
		ns := s[i:n] + s[n-i:n]
		if s == ns {
			id = n - i
			break
		}
	}
	for i := 1; i < k; i++ {
		s += s[id:n]
	}
	fmt.Println(s)
}

package main

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

func main()  {

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

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

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

	s := t
	for i := 0; i < k - 1; i++ {
		p := false
		for j := 1; j < len(t); j++ {
			if s[len(s) - len(t[:len(t) - j]):] == t[:len(t) - j] {
				s += t[len(t) - j:]
				p = true
				break
			}
		}
		if !p {
			s += t
		}
	}

	fmt.Fprintln(out, s)

}

package main

import (
	"fmt"
)

func main() {
	var n,k int
	var s string
	fmt.Scan(&n,&k,&s)
	var j int
	l := len(s)
	for i:=0;i<n-1;i++{

		if s[:i+1] == s[l-i-1:] {
			j = i + 1
		}
	}
	var r string
	r += s

	for i := 0;i< k-1;i++{
		r += s[j:]
	}

	fmt.Println(r)
}

package main

import "fmt"

func main() {
	var str string
	var count, k int
	fmt.Scan(&count, &k, &str)
	addstr := str
	for i := 0; i < len(str)-1; i++{

		if str == str[1+i:] + str[len(str)-1-i:] {
			addstr = str[len(str)-1-i:]
			break
		}
	}
	for i:=0; i < k-1; i++{
		str += addstr
	}
	fmt.Println(str)

}

package main

import "fmt"

func main() {
	var str string
	var count, k int
	fmt.Scan(&count, &k, &str)
	addstr := str
	for i := 0; i < count-1; i++{

		if str == str[1+i:] + str[count-1-i:] {
			addstr = str[count-1-i:]
			break
		}
	}
	for i:=0; i < k-1; i++{
		str += addstr
	}
	fmt.Println(str)

}

package main

import (
	"fmt"
)

func main() {
	var n,k int
	var s string
	fmt.Scan(&n,&k,&s)
	var j int
	l := len(s)
	for i:=0;i<n/2;i++{

		if s[i] == s[l-i-1] {
			j = i + 1
		} else {
			break
		}
	}
	var r string
	for i := 0;i< k-1;i++{
		r += s[:l-j]
	}
	r += s
	fmt.Println(r)
}

package main

import "fmt"

func main() {
	var str string
	var count, k int
	fmt.Scan(&count, &k, &str)
	addstr := str
	for i := 0; i < len(str)-1; i++{
		fmt.Println(str[1+i:], str[len(str)-1-i:])

		if str == str[1+i:] + str[len(str)-1-i:] {
			addstr = str[len(str)-1-i:]
		}
	}
	for i:=0; i < k-1; i++{
		str += addstr
	}
	fmt.Println(str)

}

package main

import "fmt"

func main() {
	var str string
	var count, k int
	fmt.Scan(&count, &k, &str)
	addstr := str
	for i := 0; i < k-1; i++{

		if str == str[1+i:] + str[k-1-i:] {
			addstr = str[k-1-i:]
			break
		}
	}
	for i:=0; i < k-1; i++{
		str += addstr
	}
	fmt.Println(str)

}

package main

import "fmt"

func main() {
	var str string
	var count, k int
	fmt.Scan(&count, &k, &str)
	addstr := str
	for i := 0; i < len(str)-1; i++{

		if str == str[1+i:] + str[len(str)-1-i:] {
			addstr = str[len(str)-1-i:]
		}
	}
	for i:=0; i < k-1; i++{
		str += addstr
	}
	fmt.Println(str)

}