You are playing a computer game, where you lead a party of $$$m$$$ soldiers. Each soldier is characterised by his agility $$$a_i$$$.The level you are trying to get through can be represented as a straight line segment from point $$$0$$$ (where you and your squad is initially located) to point $$$n + 1$$$ (where the boss is located).The level is filled with $$$k$$$ traps. Each trap is represented by three numbers $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$. $$$l_i$$$ is the location of the trap, and $$$d_i$$$ is the danger level of the trap: whenever a soldier with agility lower than $$$d_i$$$ steps on a trap (that is, moves to the point $$$l_i$$$), he gets instantly killed. Fortunately, you can disarm traps: if you move to the point $$$r_i$$$, you disarm this trap, and it no longer poses any danger to your soldiers. Traps don't affect you, only your soldiers.You have $$$t$$$ seconds to complete the level — that is, to bring some soldiers from your squad to the boss. Before the level starts, you choose which soldiers will be coming with you, and which soldiers won't be. After that, you have to bring all of the chosen soldiers to the boss. To do so, you may perform the following actions:  if your location is $$$x$$$, you may move to $$$x + 1$$$ or $$$x - 1$$$. This action consumes one second;  if your location is $$$x$$$ and the location of your squad is $$$x$$$, you may move to $$$x + 1$$$ or to $$$x - 1$$$ with your squad in one second. You may not perform this action if it puts some soldier in danger (i. e. the point your squad is moving into contains a non-disarmed trap with $$$d_i$$$ greater than agility of some soldier from the squad). This action consumes one second;  if your location is $$$x$$$ and there is a trap $$$i$$$ with $$$r_i = x$$$, you may disarm this trap. This action is done instantly (it consumes no time). Note that after each action both your coordinate and the coordinate of your squad should be integers.You have to choose the maximum number of soldiers such that they all can be brought from the point $$$0$$$ to the point $$$n + 1$$$ (where the boss waits) in no more than $$$t$$$ seconds.

The first line contains four integers $$$m$$$, $$$n$$$, $$$k$$$ and $$$t$$$ ($$$1 \le m, n, k, t \le 2 \cdot 10^5$$$, $$$n < t$$$) — the number of soldiers, the number of integer points between the squad and the boss, the number of traps and the maximum number of seconds you may spend to bring the squad to the boss, respectively. The second line contains $$$m$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_m$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the agility of the $$$i$$$-th soldier. Then $$$k$$$ lines follow, containing the descriptions of traps. Each line contains three numbers $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$ ($$$1 \le l_i \le r_i \le n$$$, $$$1 \le d_i \le 2 \cdot 10^5$$$) — the location of the trap, the location where the trap can be disarmed, and its danger level, respectively.

Print one integer — the maximum number of soldiers you may choose so that you may bring them all to the boss in no more than $$$t$$$ seconds.

NoteIn the first example you may take soldiers with agility $$$3$$$, $$$4$$$ and $$$5$$$ with you. The course of action is as follows:  go to $$$2$$$ without your squad;  disarm the trap $$$2$$$;  go to $$$3$$$ without your squad;  disartm the trap $$$3$$$;  go to $$$0$$$ without your squad;  go to $$$7$$$ with your squad. The whole plan can be executed in $$$13$$$ seconds.

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 m, n, k, t int
var A []int

type Trap struct {
	key     int
	l, r, d int
}
type TrapList []*Trap
type byKey struct {
	TrapList
}

func (l TrapList) Len() int {
	return len(l)
}
func (l TrapList) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l byKey) Less(i, j int) bool {
	return l.TrapList[i].key < l.TrapList[j].key
}

// how to use
// L := make(TrapList, 0, 200000+5)
// L = append(L, &Trap{key: intValue})
// sort.Stable(byKey{ L })                // Stable ASC
// sort.Stable(sort.Reverse(byKey{ L }))  // Stable DESC

var L TrapList

func main() {
	m, n, k, t = ReadInt4()
	A = ReadIntSlice(m)
	L = make(TrapList, 0)
	for i := 0; i < k; i++ {
		l, r, d := ReadInt3()
		L = append(L, &Trap{key: l, l: l, r: r, d: d})
	}
	maxAgility := Max(A...)

	// 区間の左端で昇順ソート
	sort.Stable(byKey{L})

	// m は中央を意味する何らかの値
	isOK := func(m int) bool {
		if C(m) {
			return true
		}
		return false
	}

	ng, ok := -1, maxAgility+1
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	minAgility := ok

	// if minAgility == maxAgility+1 {
	// 	fmt.Println(0)
	// 	return
	// }
	// fmt.Printf("minAgility: %d\n", minAgility)

	num := 0
	for i := 0; i < m; i++ {
		if A[i] >= minAgility {
			num++
		}
	}
	fmt.Println(num)
}

func C(m int) bool {
	segments := []Trap{}
	l, r := 0, -1
	for i := 0; i < len(L); i++ {
		t := L[i]
		if t.d <= m {
			continue
		}

		if r == -1 {
			l, r = t.l, t.r
			continue
		}

		if r >= t.l-1 {
			// マージして継続
			// r = t.r
			ChMax(&r, t.r)
		} else {
			// マージせず中断して追加
			segments = append(segments, Trap{l: l, r: r})
			l, r = t.l, t.r
		}
	}
	if r != -1 {
		segments = append(segments, Trap{l: l, r: r})
	}

	time := 1 + n
	for _, seg := range segments {
		time += 2 * (seg.r - seg.l + 1)
	}
	// fmt.Printf("time: %d\n", time)

	return time <= t
}

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

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

/*
URL:
https://codeforces.com/contest/1260/problem/D
*/

package main

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

var (
	m, n, k, t int
	A          []int
	L          []Trap
)

type Trap struct {
	l, r, d int
}

func main() {
	m, n, k, t = readi4()
	A = readis(m)
	// L = make(TrapList, 0)
	for i := 0; i < k; i++ {
		l, r, d := readi3()
		// L = append(L, &Trap{key: l, l: l, r: r, d: d})
		L = append(L, Trap{l, r, d})
	}
	maxAgility := Max(A...)

	// 区間の左端で昇順ソート
	// sort.Stable(byKey{L})
	sort.Slice(L, func(i, j int) bool { return L[i].l < L[j].l })

	// m は中央を意味する何らかの値
	isOK := func(m int) bool {
		if C(m) {
			return true
		}
		return false
	}

	ng, ok := -1, maxAgility+1
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	minAgility := ok

	num := 0
	for i := 0; i < m; i++ {
		if A[i] >= minAgility {
			num++
		}
	}
	fmt.Println(num)
}

func C(m int) bool {
	segments := []Trap{}
	l, r := 0, -1
	for i := 0; i < len(L); i++ {
		t := L[i]
		if t.d <= m {
			continue
		}

		if r == -1 {
			l, r = t.l, t.r
			continue
		}

		if r >= t.l-1 {
			// マージして継続
			// r = t.r
			ChMax(&r, t.r)
		} else {
			// マージせず中断して追加
			segments = append(segments, Trap{l: l, r: r})
			l, r = t.l, t.r
		}
	}
	if r != -1 {
		segments = append(segments, Trap{l: l, r: r})
	}

	time := 1 + n
	for _, seg := range segments {
		time += 2 * (seg.r - seg.l + 1)
	}
	// fmt.Printf("time: %d\n", time)

	return time <= t
}

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

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

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

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

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

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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
}

/*
URL:
https://codeforces.com/contest/1260/problem/D
*/

package main

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

var (
	m, n, k, t int
	A          []int
	L          []Trap
)

type Trap struct {
	l, r, d int
}

func main() {
	m, n, k, t = readi4()
	A = readis(m)
	// L = make(TrapList, 0)
	for i := 0; i < k; i++ {
		l, r, d := readi3()
		// L = append(L, &Trap{key: l, l: l, r: r, d: d})
		L = append(L, Trap{l, r, d})
	}
	maxAgility := Max(A...)

	// 区間の左端で昇順ソート
	// sort.Stable(byKey{L})
	sort.Slice(L, func(i, j int) bool { return L[i].l < L[j].l })

	// m は中央を意味する何らかの値
	isOK := func(m int) bool {
		if C(m) {
			return true
		}
		return false
	}

	ng, ok := -1, maxAgility+1
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	minAgility := ok

	num := 0
	for i := 0; i < m; i++ {
		if A[i] >= minAgility {
			num++
		}
	}
	fmt.Println(num)
}

func C(m int) bool {
	// segments := []Trap{}
	// l, r := 0, -1
	// for i := 0; i < len(L); i++ {
	// 	t := L[i]
	// 	if t.d <= m {
	// 		continue
	// 	}

	// 	if r == -1 {
	// 		l, r = t.l, t.r
	// 		continue
	// 	}

	// 	if r >= t.l-1 {
	// 		// マージして継続
	// 		// r = t.r
	// 		ChMax(&r, t.r)
	// 	} else {
	// 		// マージせず中断して追加
	// 		segments = append(segments, Trap{l: l, r: r})
	// 		l, r = t.l, t.r
	// 	}
	// }
	// if r != -1 {
	// 	segments = append(segments, Trap{l: l, r: r})
	// }

	S := [][2]int{}
	for i := 0; i < len(L); i++ {
		if L[i].d <= m {
			continue
		}
		S = append(S, [2]int{L[i].l, L[i].r})
	}

	segments := MergeSegments(S)

	time := 1 + n
	for _, seg := range segments {
		// time += 2 * (seg.r - seg.l + 1)
		time += 2 * (seg[1] - seg[0] + 1)
	}
	// fmt.Printf("time: %d\n", time)

	return time <= t
}

// MergeSegments returns merged source segments.
// Segments(Sections) are closed section.
// e.g.: [l, r], [l', r'] are merged if r >= l'
func MergeSegments(srcSegments [][2]int) [][2]int {
	_chmax := func(updatedValue *int, target int) bool {
		if *updatedValue < target {
			*updatedValue = target
			return true
		}
		return false
	}

	res := [][2]int{}
	isInitialized := false

	// current segment
	curL, curR := 0, 0

	// sort asc by LEFT coordinate
	sort.Slice(srcSegments, func(i, j int) bool {
		return srcSegments[i][0] < srcSegments[j][0]
	})

	for i := 0; i < len(srcSegments); i++ {
		seg := srcSegments[i]

		if !isInitialized {
			curL, curR = seg[0], seg[1]
			isInitialized = true
			continue
		}

		if curR >= seg[0] {
			// merge and continue
			_chmax(&curR, seg[1])
		} else {
			// do not merge, and add it to result
			res = append(res, [2]int{curL, curR})
			curL, curR = seg[0], seg[1]
		}
	}

	if isInitialized {
		res = append(res, [2]int{curL, curR})
	}

	return res
}

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

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

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

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

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

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

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

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

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

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(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"
	"sort"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	m, n, k, t := 0, 0, 0, 0
	fmt.Fscanf(in, "%d %d %d %d\n", &m, &n, &k, &t)
	a := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")
	l, r, d := make([]int, k), make([]int, k), make([]int, k)
	for i := 0; i < k; i++ {
		fmt.Fscanf(in, "%d %d %d\n", &l[i], &r[i], &d[i])
	}
	sort.Ints(a)
	left := 0
	right := m - 1
	for left < right {
		mid := (left + right) / 2
		weakest := a[mid]
		// all traps > weakest should be removed
		time := 0
		b, c := make([]int, n+2), make([]int, n+2)
		for i := 0; i < k; i++ {
			if d[i] > weakest {
				b[l[i]]++
				c[r[i]]++
			}
		}
		i := 0
		//fmt.Println("debug1", b, c)
		for i < n+1 {
			//fmt.Println("here", time)
			if b[i+1] > 0 {
				j := i
				bomb := 0
				for true {
					j++
					bomb += b[j]
					bomb -= c[j]
					b[j] = 0
					c[j] = 0
					if bomb == 0 {
						break
					}
				}
				//fmt.Println("debug3", j)
				time += (j - i) * 2
			}
			time++
			i++
		}
		//fmt.Println("debug", weakest, time)
		if time > t {
			left = mid + 1
		} else {
			right = mid
		}
	}
	mid := left
	weakest := a[mid]
	// all traps > weakest should be removed
	time := 0
	b, c := make([]int, n+2), make([]int, n+2)
	for i := 0; i < k; i++ {
		if d[i] > weakest {
			b[l[i]]++
			c[r[i]]++
		}
	}
	i := 0
	for i < n+1 {
		//fmt.Println("here", time)
		if b[i+1] > 0 {
			j := i
			bomb := 0
			for true {
				j++
				bomb += b[j]
				bomb -= c[j]
				b[j] = 0
				c[j] = 0
				if bomb == 0 {
					break
				}
			}
			//fmt.Println("debug3", j)
			time += (j - i) * 2
		}
		time++
		i++
	}
	if time > t {
		fmt.Fprintf(out, "%d\n", 0)
	} else {
		fmt.Fprintf(out, "%d\n", m-left)
	}

	return
}

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

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 m, n, k, t int
var A []int

type Trap struct {
	key     int
	l, r, d int
}
type TrapList []*Trap
type byKey struct {
	TrapList
}

func (l TrapList) Len() int {
	return len(l)
}
func (l TrapList) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l byKey) Less(i, j int) bool {
	return l.TrapList[i].key < l.TrapList[j].key
}

// how to use
// L := make(TrapList, 0, 200000+5)
// L = append(L, &Trap{key: intValue})
// sort.Stable(byKey{ L })                // Stable ASC
// sort.Stable(sort.Reverse(byKey{ L }))  // Stable DESC

var L TrapList

func main() {
	m, n, k, t = ReadInt4()
	A = ReadIntSlice(m)
	L = make(TrapList, 0)
	for i := 0; i < k; i++ {
		l, r, d := ReadInt3()
		L = append(L, &Trap{key: l, l: l, r: r, d: d})
	}
	maxAgility := Max(A...)

	// 区間の左端で昇順ソート
	sort.Stable(byKey{L})

	// m は中央を意味する何らかの値
	isOK := func(m int) bool {
		if C(m) {
			return true
		}
		return false
	}

	ng, ok := -1, maxAgility+1
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	minAgility := ok

	// if minAgility == maxAgility+1 {
	// 	fmt.Println(0)
	// 	return
	// }
	// fmt.Printf("minAgility: %d\n", minAgility)

	num := 0
	for i := 0; i < m; i++ {
		if A[i] >= minAgility {
			num++
		}
	}
	fmt.Println(num)
}

func C(m int) bool {
	segments := []Trap{}
	l, r := 0, -1
	for i := 0; i < len(L); i++ {
		t := L[i]
		if t.d <= m {
			continue
		}

		if r == -1 {
			l, r = t.l, t.r
			continue
		}

		if r >= t.l-1 {
			// マージして継続
			r = t.r
		} else {
			// マージせず中断して追加
			segments = append(segments, Trap{l: l, r: r})
			l, r = 0, -1
		}
	}
	if r != -1 {
		segments = append(segments, Trap{l: l, r: r})
	}

	time := 1 + n
	for _, seg := range segments {
		time += 2 * (seg.r - seg.l + 1)
	}
	// fmt.Printf("time: %d\n", time)

	return time <= t
}

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

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

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 m, n, k, t int
var A []int

type Trap struct {
	key     int
	l, r, d int
}
type TrapList []*Trap
type byKey struct {
	TrapList
}

func (l TrapList) Len() int {
	return len(l)
}
func (l TrapList) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func (l byKey) Less(i, j int) bool {
	return l.TrapList[i].key < l.TrapList[j].key
}

// how to use
// L := make(TrapList, 0, 200000+5)
// L = append(L, &Trap{key: intValue})
// sort.Stable(byKey{ L })                // Stable ASC
// sort.Stable(sort.Reverse(byKey{ L }))  // Stable DESC

var L TrapList

func main() {
	m, n, k, t = ReadInt4()
	A = ReadIntSlice(m)
	L = make(TrapList, 0)
	for i := 0; i < k; i++ {
		l, r, d := ReadInt3()
		L = append(L, &Trap{key: l, l: l, r: r, d: d})
	}
	maxAgility := Max(A...)

	// 区間の左端で昇順ソート
	sort.Stable(byKey{L})

	// m は中央を意味する何らかの値
	isOK := func(m int) bool {
		if C(m) {
			return true
		}
		return false
	}

	ng, ok := -1, maxAgility+1
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}
	minAgility := ok

	// if minAgility == maxAgility+1 {
	// 	fmt.Println(0)
	// 	return
	// }
	// fmt.Printf("minAgility: %d\n", minAgility)

	num := 0
	for i := 0; i < m; i++ {
		if A[i] >= minAgility {
			num++
		}
	}
	fmt.Println(num)
}

func C(m int) bool {
	segments := []Trap{}
	l, r := 0, -1
	for i := 0; i < len(L); i++ {
		t := L[i]
		if t.d <= m {
			continue
		}

		if r == -1 {
			l, r = t.l, t.r
			continue
		}

		if r >= t.l-1 {
			// マージして継続
			// r = t.r
			ChMax(&r, t.r)
		} else {
			// マージせず中断して追加
			segments = append(segments, Trap{l: l, r: r})
			l, r = 0, -1
		}
	}
	if r != -1 {
		segments = append(segments, Trap{l: l, r: r})
	}

	time := 1 + n
	for _, seg := range segments {
		time += 2 * (seg.r - seg.l + 1)
	}
	// fmt.Printf("time: %d\n", time)

	return time <= t
}

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

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


Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed.For example, the following matrices are palindromic:  The following matrices are not palindromic because they change after the order of rows is reversed:  The following matrices are not palindromic because they change after the order of columns is reversed:  You are given $$$n^2$$$ integers. Put them into a matrix of $$$n$$$ rows and $$$n$$$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic. If there are multiple answers, print any. If there is no solution, print "NO".

The first line contains one integer $$$n$$$ ($$$1 \le n \le 20$$$). The second line contains $$$n^2$$$ integers $$$a_1, a_2, \dots, a_{n^2}$$$ ($$$1 \le a_i \le 1000$$$) — the numbers to put into a matrix of $$$n$$$ rows and $$$n$$$ columns.

If it is possible to put all of the $$$n^2$$$ numbers into a matrix of $$$n$$$ rows and $$$n$$$ columns so that each number is used exactly once, each cell contains exactly one number and the resulting matrix is palindromic, then print "YES". Then print $$$n$$$ lines with $$$n$$$ space-separated numbers — the resulting matrix. If it's impossible to construct any matrix, then print "NO". You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

NoteNote that there exist multiple answers for the first two examples.

package main

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

        "sort"
)

func main() {
	n := readInts()[0]
	a := readInts()

        sort.Sort(sort.IntSlice(a))
	r := make([]int, n*n)
	r4, r2h, r2v, r1 := (n/2)*(n/2), (n%2)*(n/2), (n%2)*(n/2), n%2
	for i := 0; i < n*n; {
		switch {
		case r4 > 0 && i < n*n-3 && a[i] == a[i+1] && a[i] == a[i+2] && a[i] == a[i+3]:
			r4 -= 1
			x, y := r4 % (n/2), r4 / (n/2)
			r[x+n*y], r[(n-1-x)+n*y], r[x+n*(n-1-y)], r[(n-1-x)+n*(n-1-y)] = a[i], a[i], a[i], a[i]
			i += 4
		case r2h > 0 && i < n*n-1 && a[i] == a[i+1]:
			r2h -= 1
			r[r2h+n*(n/2)], r[(n-1-r2h)+n*(n/2)] = a[i], a[i]
			i += 2
		case r2v > 0 && i < n*n-1 && a[i] == a[i+1]:
			r2v -= 1
			r[(n/2)+n*r2v], r[(n/2)+n*(n-1-r2v)] = a[i], a[i]
			i += 2
		case r1 > 0:
			r1 -= 1
			r[n*n/2] = a[i]
			i += 1
		default:
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	for y := 0; y < n; y++ {
		for x := 0; x < n; x++ {
			fmt.Print(r[x+n*y], " ")
		}
		fmt.Println()
	}
}

var (
	stdin = bufio.NewReader(os.Stdin)
)

func readLine() string {
	s, _ := stdin.ReadString('\n')
	return s
}

func readInts() (r []int) {
	reader := strings.NewReader(readLine())
	for {
		var x int
		_, err := fmt.Fscan(reader, &x)
		if err != nil {
			break
		}
		r = append(r, x)
	}
	return
}

package main

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

func fillOdd(mapp [][]int, cnt []int, n int) bool {

	l := len(cnt)
	for i := 0; i < l; i++ {
		if cnt[i]%2==1{
			mapp[n/2][n/2]=i
			cnt[i]--
			break
		}
	}
	for i := 0; i < n/2; i++ {
		index := findC(cnt)
		if index < 0{
			return false
		}
		mapp[n/2][i] = index
		mapp[n/2][n-i-1] = index
		cnt[index]-=2
		index = findC(cnt)
		if index < 0{
			return false
		}
		mapp[i][n/2] = index
		mapp[n-i-1][n/2] = index
		cnt[index]-=2
	}

	if mapp[n/2][n/2] <= 0 {
		return false
	}
	return true
}
func fillEven(mapp [][]int, cnt []int, n int) bool {
	index := 0
	l := len(cnt)
	for i := 0; i < n/2; i++ {
		for j := 0; j < n/2; j++ {
			for index < l {
				if cnt[index]>0&& cnt[index]%4 == 0 {
					break
				}
				index++
			}
			if index >= l {
			//	fmt.Printf("->%d %d\n",i,j)
			//	PrintC(mapp,n)
				return false
			}
			mapp[i][j] = index
			mapp[n-1-i][j] = index
			mapp[i][n-1-j] = index
			mapp[n-1-i][n-1-j] = index
			cnt[index] -= 4
		}
	}
	return true
}
func PrintC(mapp [][]int,n int)  {
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if j != 0 {
				fmt.Printf(" ")
			}
			fmt.Printf("%d", mapp[i][j])
		}
		fmt.Printf("\n")
	}
}
func findC(cnt []int) (int) {
	l := len(cnt)
	for i := 0; i < l; i++ {
		if cnt[i] > 0&&cnt[i]%4==2 {
			return i
		}
	}
	for i := 0; i < l; i++ {
		if cnt[i] > 0&&cnt[i]%4==0 {
			return i
		}
	}
	return -1
}
func main() {
	buf := bufio.NewReader(os.Stdin)

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

	mat := make([]int, n*n)
	cnt := make([]int, 1010)
	for i := 0; i < n*n; i++ {
		fmt.Fscanf(buf, "%d", &mat[i])
		cnt[mat[i]]++
	}
	mapp := make([][]int,n)
	for i:=0;i< n;i++{
		mapp[i] = make([]int,n)
	}
	if (n&1)==1&&fillOdd(mapp, cnt, n) == false {
		fmt.Printf("No Even\n")
		return
	}
	if fillEven(mapp, cnt, n) == false {
		fmt.Printf("No\n")
		return
	}
	fmt.Printf("Yes\n")
	PrintC(mapp,n)

}

package main

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

func solve(N int, a []int) (bool, [][]int) {
	res := [][]int{}
	for i := 0; i < N; i++ {
		res = append(res, make([]int, N))
	}

	counts := map[int]int{}
	for _, n := range a {
		counts[n]++
	}

	oddCount := 0
	centerValue := 0
	for k, v := range counts {
		if v%2 == 1 {
			oddCount++
			centerValue = k
		}
	}

	if oddCount > 1 {
		return false, nil
	}

	mid := N >> 1

	if oddCount == 1 {
		if N%2 == 1 {
			res[mid][mid] = centerValue
			counts[centerValue]--
		} else {
			return false, nil
		}
	}

	center := N >> 1

	components := [][][]int{}

	x, y := 0, 0
	for x < center && y < center {
		com := [][]int{
			[]int{x, y},
			[]int{N - 1 - x, y},
			[]int{x, N - 1 - y},
			[]int{N - 1 - x, N - 1 - y},
		}

		components = append(components, com)

		y++
		if y >= center {
			y = 0
			x++
		}
	}

	if N%2 == 1 {
		x, y = center, 0
		for y < center {
			com := [][]int{
				[]int{x, y},
				[]int{x, N - 1 - y},
			}

			components = append(components, com)

			com = [][]int{
				[]int{y, x},
				[]int{N - 1 - y, x},
			}

			components = append(components, com)

			y++
		}
	}

	for _, com := range components {
		slotsCount := len(com)
		n := 0

		for k, v := range counts {
			if v >= slotsCount {
				n = k
				counts[k] -= slotsCount
			}
			if counts[k] == 0 {
				delete(counts, k)
			}
			if n > 0 {
				break
			}
		}

		if n <= 0 {
			return false, nil
		}

		for _, pair := range com {
			res[pair[0]][pair[1]] = n
		}
	}

	return true, res
}

func toInt(buf []byte) int {
	n := 0
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return n
}

func main() {
	n := 0

	fmt.Scan(&n)
	a := make([]int, n*n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := range a {
		scanner.Scan()
		a[i] = toInt(scanner.Bytes())
	}

	valid, res := (solve(n, a))
	if !valid {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for _, r := range res {
		for _, n := range r {
			fmt.Print(n, " ")
		}
		fmt.Println()
	}
}

package main

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

func solve(N int, a []int) (string, [][]int) {
	const NO = "NO"
	const YES = "YES"

	res := [][]int{}
	for i := 0; i < N; i++ {
		res = append(res, make([]int, N))
	}

	counts := map[int]int{}
	for _, n := range a {
		counts[n]++
	}

	oddCount := 0
	centerValue := 0
	for k, v := range counts {
		if v%2 == 1 {
			oddCount++
			centerValue = k
		}
	}

	if oddCount > 1 {
		return NO, res
	}

	mid := N >> 1

	if oddCount == 1 {
		if N%2 == 1 {
			res[mid][mid] = centerValue
			counts[centerValue]--
		} else {
			return NO, res
		}
	}

	center := N >> 1

	components := [][][]int{}

	x, y := 0, 0
	for x < center && y < center {
		com := [][]int{
			[]int{x, y},
			[]int{N - 1 - x, y},
			[]int{x, N - 1 - y},
			[]int{N - 1 - x, N - 1 - y},
		}

		components = append(components, com)

		y++
		if y >= center {
			y = 0
			x++
		}
	}

	if N%2 == 1 {
		x, y = center, 0
		for y < center {
			com := [][]int{
				[]int{x, y},
				[]int{x, N - 1 - y},
			}

			components = append(components, com)

			com = [][]int{
				[]int{y, x},
				[]int{N - 1 - y, x},
			}

			components = append(components, com)

			y++
		}
	}

	for _, com := range components {
		slotsCount := len(com)
		n := 0

		for k, v := range counts {
			if v >= slotsCount {
				n = k
				counts[k] -= slotsCount
			}
			if counts[k] < slotsCount {
				delete(counts, k)
			}
			if n > 0 {
				break
			}
		}

		if n <= 0 {
			//fmt.Println(counts)
			return NO, res
		}

		for _, pair := range com {
			res[pair[0]][pair[1]] = n
		}
	}

	return YES, res
}

func toInt(buf []byte) int {
	n := 0
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return n
}

func main() {
	n := 0

	fmt.Scan(&n)
	a := make([]int, n*n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := range a {
		scanner.Scan()
		a[i] = toInt(scanner.Bytes())
	}

	fmt.Println(solve(n, a))
}

package main

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

func solve(N int, a []int) (bool, [][]int) {
	res := [][]int{}
	for i := 0; i < N; i++ {
		res = append(res, make([]int, N))
	}

	counts := map[int]int{}
	for _, n := range a {
		counts[n]++
	}

	oddCount := 0
	centerValue := 0
	for k, v := range counts {
		if v%2 == 1 {
			oddCount++
			centerValue = k
		}
	}

	if oddCount > 1 {
		return false, res
	}

	mid := N >> 1

	if oddCount == 1 {
		if N%2 == 1 {
			res[mid][mid] = centerValue
			counts[centerValue]--
		} else {
			return false, res
		}
	}

	center := N >> 1

	components := [][][]int{}

	x, y := 0, 0
	for x < center && y < center {
		com := [][]int{
			[]int{x, y},
			[]int{N - 1 - x, y},
			[]int{x, N - 1 - y},
			[]int{N - 1 - x, N - 1 - y},
		}

		components = append(components, com)

		y++
		if y >= center {
			y = 0
			x++
		}
	}

	if N%2 == 1 {
		x, y = center, 0
		for y < center {
			com := [][]int{
				[]int{x, y},
				[]int{x, N - 1 - y},
			}

			components = append(components, com)

			com = [][]int{
				[]int{y, x},
				[]int{N - 1 - y, x},
			}

			components = append(components, com)

			y++
		}
	}

	for _, com := range components {
		slotsCount := len(com)
		n := 0

		for k, v := range counts {
			if v >= slotsCount {
				n = k
				counts[k] -= slotsCount
			}
			if counts[k] < slotsCount {
				delete(counts, k)
			}
			if n > 0 {
				break
			}
		}

		if n <= 0 {
			return false, res
		}

		for _, pair := range com {
			res[pair[0]][pair[1]] = n
		}
	}

	return true, res
}

func toInt(buf []byte) int {
	n := 0
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return n
}

func main() {
	n := 0

	fmt.Scan(&n)
	a := make([]int, n*n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := range a {
		scanner.Scan()
		a[i] = toInt(scanner.Bytes())
	}

	valid, res := (solve(n, a))
	if !valid {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for _, r := range res {
		for _, n := range r {
			fmt.Print(n, " ")
		}
		fmt.Println()
	}
}


Polycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has $$$n$$$ friends, numbered from $$$1$$$ to $$$n$$$.Recall that a permutation of size $$$n$$$ is an array of size $$$n$$$ such that each integer from $$$1$$$ to $$$n$$$ occurs exactly once in this array.So his recent chat list can be represented with a permutation $$$p$$$ of size $$$n$$$. $$$p_1$$$ is the most recent friend Polycarp talked to, $$$p_2$$$ is the second most recent and so on.Initially, Polycarp's recent chat list $$$p$$$ looks like $$$1, 2, \dots, n$$$ (in other words, it is an identity permutation).After that he receives $$$m$$$ messages, the $$$j$$$-th message comes from the friend $$$a_j$$$. And that causes friend $$$a_j$$$ to move to the first position in a permutation, shifting everyone between the first position and the current position of $$$a_j$$$ by $$$1$$$. Note that if the friend $$$a_j$$$ is in the first position already then nothing happens.For example, let the recent chat list be $$$p = [4, 1, 5, 3, 2]$$$:   if he gets messaged by friend $$$3$$$, then $$$p$$$ becomes $$$[3, 4, 1, 5, 2]$$$;  if he gets messaged by friend $$$4$$$, then $$$p$$$ doesn't change $$$[4, 1, 5, 3, 2]$$$;  if he gets messaged by friend $$$2$$$, then $$$p$$$ becomes $$$[2, 4, 1, 5, 3]$$$. For each friend consider all position he has been at in the beginning and after receiving each message. Polycarp wants to know what were the minimum and the maximum positions.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 3 \cdot 10^5$$$) — the number of Polycarp's friends and the number of received messages, respectively. The second line contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le n$$$) — the descriptions of the received messages.

Print $$$n$$$ pairs of integers. For each friend output the minimum and the maximum positions he has been in the beginning and after receiving each message.

NoteIn the first example, Polycarp's recent chat list looks like this:   $$$[1, 2, 3, 4, 5]$$$  $$$[3, 1, 2, 4, 5]$$$  $$$[5, 3, 1, 2, 4]$$$  $$$[1, 5, 3, 2, 4]$$$  $$$[4, 1, 5, 3, 2]$$$ So, for example, the positions of the friend $$$2$$$ are $$$2, 3, 4, 4, 5$$$, respectively. Out of these $$$2$$$ is the minimum one and $$$5$$$ is the maximum one. Thus, the answer for the friend $$$2$$$ is a pair $$$(2, 5)$$$.In the second example, Polycarp's recent chat list looks like this:   $$$[1, 2, 3, 4]$$$  $$$[1, 2, 3, 4]$$$  $$$[2, 1, 3, 4]$$$  $$$[4, 2, 1, 3]$$$

package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

func scanInt64() int64 {
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return a
}

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

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

type bit struct {
	a []int
}

func (b bit) update(x, v, n int) {
	for i := uint(x); i <= uint(n); i += i & -i {
		b.a[i] += v
	}
}

func (b bit) sum(x int) int {
	ret := 0
	for i := uint(x); i > 0; i -= i & -i {
		ret += b.a[i]
	}
	return ret
}

func (b bit) query(x, y int) int {
	if x > y {
		return 0
	}
	return b.sum(y) - b.sum(x-1)
}

type qus struct {
	ql int
	qr int
	id int
}

func newQus(ql, qr, id int) qus {
	return qus{
		ql,
		qr,
		id,
	}
}

var (
	n    int
	m    int
	q    [][]qus
	b    bit
	a    []int
	last []int
	lPos []int
	rPos []int
)

func main() {
	sc.Split(bufio.ScanWords)
	n = scanInt()
	m = scanInt()
	a = make([]int, m+1)
	last = make([]int, n+1)
	lPos = make([]int, n+1)
	rPos = make([]int, n+1)
	q = make([][]qus, m+1)
	b.a = make([]int, m+1)
	for i := 1; i <= n; i++ {
		lPos[i] = i
		rPos[i] = i
	}
	for i := 1; i <= m; i++ {
		a[i] = scanInt()
		lPos[a[i]] = 1
		if last[a[i]] != 0 {
			ql := last[a[i]] + 1
			qr := i - 1
			if ql <= qr {
				q[qr] = append(q[qr], newQus(ql, qr, a[i]))
			}
		}
		last[a[i]] = i
	}
	for i := 1; i <= n; i++ {
		ql := last[i] + 1
		qr := m
		if ql <= qr {
			q[qr] = append(q[qr], newQus(ql, qr, i))
		}
		last[i] = 0
	}
	for i := 1; i <= m; i++ {
		if last[a[i]] != 0 {
			b.update(last[a[i]], -1, m)
		}
		b.update(i, 1, m)
		last[a[i]] = i
		for _, op := range q[i] {
			cnt := b.query(op.ql, op.qr)
			if cnt+1 > rPos[op.id] {
				rPos[op.id] = cnt + 1
			}
		}
	}
	for i := 1; i <= n; i++ {
		last[i] = 0
	}
	b.a = make([]int, n+1)
	for i := 1; i <= m; i++ {
		if last[a[i]] == 0 {
			cnt := b.query(a[i], n)
			b.update(a[i], 1, n)
			if rPos[a[i]] < cnt+a[i] {
				rPos[a[i]] = cnt + a[i]
			}
		}
		last[a[i]] = i
	}
	for i := 1; i <= n; i++ {
		if last[i] == 0 {
			cnt := b.query(i, n)
			if rPos[i] < cnt+i {
				rPos[i] = cnt + i
			}
		}
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", lPos[i], rPos[i])
	}
}

package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

func scanInt64() int64 {
	sc.Scan()
	a, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return a
}

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

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

type bit struct {
	a []int
}

func (b bit) update(x, v, n int) {
	for i := uint(x); i <= uint(n); i += i & -i {
		b.a[i] += v
	}
}

func (b bit) sum(x int) int {
	ret := 0
	for i := uint(x); i > 0; i -= i & -i {
		ret += b.a[i]
	}
	return ret
}

func (b bit) query(x, y int) int {
	if x > y {
		return 0
	}
	return b.sum(y) - b.sum(x-1)
}

type qus struct {
	ql int
	qr int
	id int
}

func newQus(ql, qr, id int) qus {
	return qus{
		ql,
		qr,
		id,
	}
}

var (
	n    int
	m    int
	q    [][]qus
	b    bit
	a    []int
	last []int
	lPos []int
	rPos []int
)

func main() {
	sc.Split(bufio.ScanWords)
	n = scanInt()
	m = scanInt()
	a = make([]int, m+1)
	last = make([]int, n+1)
	lPos = make([]int, n+1)
	rPos = make([]int, n+1)
	q = make([][]qus, m+1)
	b.a = make([]int, m+1)
	for i := 1; i <= n; i++ {
		lPos[i] = i
		rPos[i] = i
	}
	for i := 1; i <= m; i++ {
		a[i] = scanInt()
		lPos[a[i]] = 1
		if last[a[i]] != 0 {
			ql := last[a[i]] + 1
			qr := i - 1
			if ql <= qr {
				q[qr] = append(q[qr], newQus(ql, qr, a[i]))
			}
		}
		last[a[i]] = i
	}
	for i := 1; i <= n; i++ {
		ql := last[i] + 1
		qr := m
		if ql <= qr {
			q[qr] = append(q[qr], newQus(ql, qr, i))
		}
		last[i] = 0
	}
	for i := 1; i <= m; i++ {
		if last[a[i]] != 0 {
			b.update(last[a[i]], -1, m)
		}
		b.update(i, 1, m)
		last[a[i]] = i
		for _, op := range q[i] {
			cnt := b.query(op.ql, op.qr)
			if cnt+1 > rPos[op.id] {
				rPos[op.id] = cnt + 1
			}
		}
	}
	for i := 1; i <= n; i++ {
		last[i] = 0
	}
	b.a = make([]int, n+1)
	for i := 1; i <= m; i++ {
		if last[a[i]] == 0 {
			cnt := b.query(a[i], n)
			b.update(a[i], 1, n)
			if rPos[a[i]] < cnt+a[i] {
				rPos[a[i]] = cnt + a[i]
			}
		}
		last[a[i]] = i
	}
	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", lPos[i], rPos[i])
	}
}


Recently, your friend discovered one special operation on an integer array $$$a$$$:   Choose two indices $$$i$$$ and $$$j$$$ ($$$i \neq j$$$);  Set $$$a_i = a_j = |a_i - a_j|$$$. After playing with this operation for a while, he came to the next conclusion:   For every array $$$a$$$ of $$$n$$$ integers, where $$$1 \le a_i \le 10^9$$$, you can find a pair of indices $$$(i, j)$$$ such that the total sum of $$$a$$$ will decrease after performing the operation. This statement sounds fishy to you, so you want to find a counterexample for a given integer $$$n$$$. Can you find such counterexample and prove him wrong?In other words, find an array $$$a$$$ consisting of $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) such that for all pairs of indices $$$(i, j)$$$ performing the operation won't decrease the total sum (it will increase or not change the sum).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first and only line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the length of array $$$a$$$.

For each test case, if there is no counterexample array $$$a$$$ of size $$$n$$$, print NO. Otherwise, print YES followed by the array $$$a$$$ itself ($$$1 \le a_i \le 10^9$$$). If there are multiple counterexamples, print any.

NoteIn the first test case, the only possible pairs of indices are $$$(1, 2)$$$ and $$$(2, 1)$$$.If you perform the operation on indices $$$(1, 2)$$$ (or $$$(2, 1)$$$), you'll get $$$a_1 = a_2 = |1 - 337| = 336$$$, or array $$$[336, 336]$$$. In both cases, the total sum increases, so this array $$$a$$$ is a counterexample.

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	arr[0] = 1
	r := 21
	for i := 1; i < r; i += 1 {
		arr[i] = arr[i-1] * 3
		if arr[i] >= int64(1000000000) {
			r = i
			break
		}
	}

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

		if z > r {
			fmt.Printf("NO\n")
			continue
		}

		str := fmt.Sprintf("%v", arr[:z])
		fmt.Printf("YES\n%v\n", str[1:len(str)-1])
	}
	println()
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if n <= 19 {
			fmt.Fprintln(out,"YES")
			for j:=0;j<n;j++{
				fmt.Fprintf(out,"%v ",int(math.Pow(float64(3),float64(j))))
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1651B
Date: 18/04/22
User: epradere
URL: https://codeforces.com/problemset/problem/1651/B
Problem: CF1651B
**/
func (in *CF1651B) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n > 19 {
			str.WriteString("NO\n")
		} else {
			str.WriteString("YES\n")
			value := int64(1)
			for i := 0; i < n; i++ {
				str.WriteString(fmt.Sprintf("%v ", value))
				value *= 3
			}
			str.WriteString("\n")
		}
	}
	fmt.Println(str.String())
}

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

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

package main

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

/*
3
5
10
20
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	arr := make([]int, 0)

	num := int64(1)

	for i := 0; i < n; i++ {
		if num <= 1e9 {
			arr = append(arr, int(num))
			num = 3 * num
		} else {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
	for _, num := range arr {
		fmt.Fprintf(writer, "%d ", num)
	}
	fmt.Fprintln(writer)
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return nums[idx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

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

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int64, n)
		nums[0] = 1
		ok := true
		for i := 1; i < n; i++ {
			nums[i] = nums[i-1]*3 + 1
			if nums[i] > 1e9 {
				ok = false
				break
			}
		}
		if ok {
			fmt.Fprintln(out, "YES")
			for i := 0; i < n; i++ {
				fmt.Fprint(out, nums[i])
				if i < n-1 {
					fmt.Fprint(out, " ")
				} else {
					fmt.Fprintln(out)
				}
			}
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T, n int
	for Scan(&T); T > 0; T-- {
		Scan(&n)
		if n > 19 {
			Println("NO")
			continue
		}
		Println("YES")
		for v := 1; n > 0; n-- {
			Println(v)
			v *= 3
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	a := make([]int, 0)
	a = append(a, 1)
	for {
		b := a[len(a)-1]*3 + 1
		if b >= int(1e9) {
			break
		} else {
			a = append(a, b)
		}
	}
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		if n > len(a) {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			for i := 0; i < n; i++ {
				fmt.Printf("%d ", a[i])
			}
			fmt.Println()
		}
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		n, _ := strconv.Atoi(ninps[0])

		/*val := 0
                for i := 0; val < 1e+9; i++ {
                	val = val * 3 + 1
			fmt.Println(val, i+1, "R:", n)
		}*/
		if n > 19 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			val := 0
			for i := 0; i < n; i++ {
                		val = val * 3 + 1
				fmt.Printf("%d ", val)
			}
		}
	}
}

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)
	ar := make([]int64, 0, 500)
	for i := int64(1); i <= 1000_000_000; i *= 3 {
		ar = append(ar, i)
	}
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		if n <= len(ar) {
			fmt.Fprintln(out, "YES")
			for i := 0; i < n; i++ {
				if i > 0 {
					fmt.Fprint(out, " ")
				}
				fmt.Fprint(out, ar[i])
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	var b []int
	for j := 1; j <= 1000000000; j += j + j {
		b = append(b, j)
	}
	if n <= len(b) {
		cout.Println("YES")
		for i, v := range b[:n] {
			cout.Print(v)
			if i+1 < n {
				cout.Print(" ")
			}
		}
		cout.Println()
	} else {
		cout.Println("NO")
	}

}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := 21
	for i := 0; i < r; i += 1 {
		arr[i] = v
		v *= int64(3)
	}

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

		if z > r {
			fmt.Printf("NO\n")
			continue
		}

		str := fmt.Sprintf("%v", arr[:z])
		fmt.Printf("YES\n%v\n", str[1:len(str)-1])
	}
	println()
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := -1
	for i := 0; i < 1024; i += 1 {
		arr[i] = v
		v *= int64(3)
		if v >= 1000000000 {
			r = i
			break
		}
	}

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

		if z >= r {
			fmt.Printf("NO\n")
			continue
		}

		str := fmt.Sprintf("%v", arr[:z])
		fmt.Printf("YES\n%v\n", str[1:len(str)-1])
	}
	println()
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := -1
	for i := 0; i < 1024; i += 1 {
		arr[i] = v
		v *= int64(3)
		if v >= 1000000000 {
			r = i
			break
		}
	}

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

		if z >= r {
			fmt.Printf("NO\n")
			continue
		}

		str := fmt.Sprintf("%v", arr[:z])
		fmt.Printf("YES\n%v\n", str[1:len(str)-1])
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := -1
	for i := 0; i < 1024; i += 1 {
		arr[i] = v
		v *= int64(3)
		if v > 10e9 {
			r = i + 1
			break
		}
	}

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

		if z >= r {
			fmt.Printf("NO\n")
			continue
		}

		str := fmt.Sprintf("%v", arr[:z])
		fmt.Printf("YES\n%v\n", str[1:len(str)-1])
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := -1
	for i := 0; i < 1024; i += 1 {
		arr[i] = v
		v *= int64(3)
		if v > 10e9 {
			r = i + 1
			break
		}
	}

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

		if z > r {
			fmt.Printf("NO\n")
			continue
		}

		str := fmt.Sprintf("%v", arr[:z])
		fmt.Printf("YES\n%v\n", str[1:len(str)-1])
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := -1
	for i := 0; i < 1024; i += 1 {
		arr[i] = v
		v *= 3
		if v > 10e9 {
			r = i + 1
			break
		}
	}

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

		if z > r {
			fmt.Printf("NO\n")
			continue
		}

		fmt.Printf("YES\n")

		str := fmt.Sprintf("%v", arr[0:z+1])
		fmt.Printf("%v\n", str[1:len(str)-2])
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var n int
	fmt.Fscan(in, &n)

	arr := make([]int64, 50)

	v := int64(1)
	r := -1
	for i := 0; i < 1024; i += 1 {
		arr[i] = v
		v *= 3
		if v > 10e9 {
			r = i + 1
			break
		}
	}

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

		if z > r {
			fmt.Printf("NO\n")
			continue
		}

		fmt.Printf("YES\n")

		str := fmt.Sprintf("%v", arr[0:z])
		fmt.Printf("%v\n", str[1:len(str)-2])
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if n < 19 {
			fmt.Fprintln(out,"YES")
			for j:=0;j<n;j++{
				fmt.Fprintf(out,"%v ",int(math.Pow(float64(3),float64(j))))
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if (n%2 == 1 || n == 2) && n <= 19 {
			fmt.Fprintln(out,"YES")
			for j:=0;j<n;j++{
				fmt.Fprintf(out,"%v ",int(math.Pow(float64(3),float64(j))))
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if (n%2 == 1 || n == 2) && n < 19 {
			fmt.Fprintln(out,"YES")
			for j:=0;j<n;j++{
				fmt.Fprintf(out,"%v ",int(math.Pow(float64(3),float64(j))))
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
    "math"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if (n%2 == 1 || n == 2) && int(math.Pow(float64(3),float64(n))) <= int(math.Pow(float64(10),float64(9))) {
			fmt.Fprintln(out,"YES")
			for j:=0;j<n;j++{
				fmt.Fprintf(out,"%v ",int(math.Pow(float64(3),float64(j))))
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		if n%2 == 1 || n == 2 {
			fmt.Fprintln(out,"YES")
			var sum int
			for j:=1;j<=n;j++{
				sum = sum * j + 1
				fmt.Fprintf(out,"%v ",sum)
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1651B
Date: 18/04/22
User: epradere
URL: https://codeforces.com/problemset/problem/1651/B
Problem: CF1651B
**/
func (in *CF1651B) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n > 18 {
			str.WriteString("NO\n")
		} else {
			str.WriteString("YES\n")
			value := int64(1)
			for i := 0; i < n; i++ {
				str.WriteString(fmt.Sprintf("%v ", value))
				value *= 3
			}
			str.WriteString("\n")
		}
	}
	fmt.Println(str.String())
}

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

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

package main

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

/*
3
5
10
20
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	arr := make([]int, 0)

	num := int64(1)

	for i := 0; i < n; i++ {
		if num <= 1e9 {
			arr = append(arr, int(num))
			num = 2*num + 1
		} else {
			fmt.Fprintln(writer, "NO")
			return
		}
	}

	fmt.Fprintln(writer, "YES")
	for _, num := range arr {
		fmt.Fprintf(writer, "%d ", num)
	}
	fmt.Fprintln(writer)
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return nums[idx]
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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


Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it.Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same?

The first line of the input contains a single integer n (1 ≤ n ≤ 100) — the number of participants Anton has outscored in this contest . The next n lines describe participants results: the i-th of them consists of a participant handle namei and two integers beforei and afteri ( - 4000 ≤ beforei, afteri ≤ 4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct.

Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise.

3
Burunduk1 2526 2537
BudAlNik 2084 2214
subscriber 2833 2749

3
Applejack 2400 2400
Fluttershy 2390 2431
Pinkie_Pie -2500 -2450

NoteIn the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before the contest.

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	res := false
	var c string
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%s%d%d\n", &c, &a, &b)
		//fmt.Printf("%s %d %d", c, a, b)
		//fmt.Println(a, b)
		if b > a && a >= 2400 {
			res = true
		}
	}
	if res {
		c = "YES"
	} else {
		c = "NO"
	}
	fmt.Println(c)
}

package main

import "fmt"

func main() {
	var n int
	var ok bool
	var name string
	var before, after int
	fmt.Scan(&n)

	ok = false
	for i := 0; i < n; i++ {
	    fmt.Scanf("%s",&name)
		fmt.Scanf("%s %d %d", &name, &before, &after)
		if before < after && before >= 2400 {
			fmt.Println("YES")
			ok = true
			break
		}
	}
	if !ok {
		fmt.Println("NO")
	}

}

package main

import (
	"fmt"
	"os"
)

func settest() (*os.File, *os.File) {
	f, err := os.Open("a.dat")
	if err != nil {
		panic(err)
	}

	oldStdin := os.Stdin
	os.Stdin = f

	return f, oldStdin
}

func main() {
	/*f, oldStdin := settest()
	defer f.Close()
	defer func() { os.Stdin = oldStdin }()*/

	var s string
	r := "NO"
	n, a, b := 0, 0, 0

	fmt.Scan(&n)
	for k := 0; k < n; k++ {
		fmt.Scan(&s, &a, &b)
		if a >= 2400 && b > a {
			r = "YES"
			break
		}
	}

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

package main

import (
	"fmt"
)

type contest struct {
	before int
	after  int
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	interested := []contest{}
	for index := 0; index < n; index++ {
		var name string
		var before, after int
		fmt.Scanf("%s %d %d\n", &name, &before, &after)
		if before >= 2400 {
			add := contest{before, after}
			interested = append(interested, add)
		}
	}

	found := false
	for _, contest := range interested {
		if contest.after > contest.before {
			found = true
			break
		}
	}

	if found == false {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}

}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    var found bool
    for i:=0;i<n;i++{
        var s string
        var before, after int
        fmt.Scan(&s, &before, &after)
        if before >=2400 && before < after {
            found = true
        }
    }
    if found {
        fmt.Print("YES")
    } else {
        fmt.Print("NO")
    }
}

package main

import (
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scanln(&n)
	if err != nil {
		panic(err)
	}
	for i := 0; i < n; i++ {
		var s string
		var before, after int
		fmt.Scanln(&s, &before, &after)
		if before >= 2400 && after > before {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

package main

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

func main() {
    var n int
    fmt.Scan(&n)
    can := false
    for i:=0; i<n; i++{
        var chert string
        fmt.Scan(&chert)
        var bef, aft int
        fmt.Scan(&bef, &aft)
        if aft > bef && bef >= 2400{
            can = true
        }
    }
    if can{
        fmt.Print("YES")
    } else{
        fmt.Print("NO")
    }
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	res := false
	var c string
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%s %d %d", &c, &a, &b)
		//fmt.Println(a, b)
		if b > a && a > 2400 {
			res = true
		}
	}
	if res {
		c = "YES"
	} else {
		c = "NO"
	}
	fmt.Println(c)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	res := false
	var c string
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%s %d %d", &c, &a, &b)
		//fmt.Println(a, b)
		if b > a && a >= 2400 {
			res = true
		}
	}
	if res {
		c = "YES"
	} else {
		c = "NO"
	}
	fmt.Println(c)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d", &n)
	res := false
	for i := 0; i < n; i++ {
		var a, b int
		var c string
		fmt.Scanf("%s %d %d", &c, &a, &b)
		//fmt.Println(a, b)
		if b > a && a >= 2400 {
			res = true
		}
	}
	fmt.Println(res)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	res := false
	var c string
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%s%d%d", &c, &a, &b)
		//fmt.Printf("%s %d %d", c, a, b)
		//fmt.Println(a, b)
		if b > a && a >= 2400 {
			res = true
		}
	}
	if res {
		c = "YES"
	} else {
		c = "NO"
	}
	fmt.Println(c)
}

package main

import "fmt"

func main() {
	var n int
	var ok bool
	var name string
	var before, after int
	fmt.Scan(&n)

	ok = false
	for i := 0; i < n; i++ {
		fmt.Scanf("%s %d %d", &name, &before, &after)
		if before < after && before >= 2400 {
			fmt.Println("YES")
			ok = true
			break
		}
	}
	if !ok {
		fmt.Println("NO")
	}

}

package main

import (
	"fmt"
)

type contest struct {
	before int
	after  int
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	interested := []contest{}

	for index := 0; index < n; index++ {
		var name string
		var before, after int
		fmt.Scanf("%s %d %d", &name, &before, &after)
		if before >= 2400 {
			add := contest{before, after}
			interested = append(interested, add)
		}
	}

	found := false
	for _, contest := range interested {
		if contest.after > contest.before {
			found = true
			break
		}
	}

	if found == false {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}

}


Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points. After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game.

The first line contains a single integer n (1 ≤ n ≤ 5·105) — the number of elements in the array. The next line contains n integers ai (1 ≤ ai ≤ 106) — the values of the array elements.

In a single line print a single integer — the maximum number of points Artem can get.

package main

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

const N = 500000

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

var v, stk [N]int

func main() {
  r := bufio.NewReader(os.Stdin)
  var n, top int = 0, 0
  var res int64 = 0
  fmt.Fscan(r, &n)
  for i := 0; i < n; i++ {
    fmt.Fscan(r, &v[i])
    for top >= 2 && stk[top-2] >= stk[top-1] && stk[top-1] <= v[i] {
      res += int64(IntMin(v[i], stk[top-2]))
      top--
    }
    stk[top] = v[i]
    top++
  }
  sort.Sort(sort.IntSlice(stk[:top]))
  for i := 0; i < top-2; i++ {
    res += int64(stk[i])
  }
  fmt.Println(res)
}