Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by $$$1$$$. If he manages to finish the level successfully then the number of clears increases by $$$1$$$ as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.So he peeked at the stats $$$n$$$ times and wrote down $$$n$$$ pairs of integers — $$$(p_1, c_1), (p_2, c_2), \dots, (p_n, c_n)$$$, where $$$p_i$$$ is the number of plays at the $$$i$$$-th moment of time and $$$c_i$$$ is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.Help him to check the correctness of his records.For your convenience you have to answer multiple independent test cases.

The first line contains a single integer $$$T$$$ $$$(1 \le T \le 500)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of moments of time Polycarp peeked at the stats. Each of the next $$$n$$$ lines contains two integers $$$p_i$$$ and $$$c_i$$$ ($$$0 \le p_i, c_i \le 1000$$$) — the number of plays and the number of clears of the level at the $$$i$$$-th moment of time. Note that the stats are given in chronological order.

For each test case print a single line. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES". Otherwise, print "NO". You can print each letter in any case (upper or lower).

NoteIn the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.The second test case is a nice example of a Super Expert level.In the third test case the number of plays decreased, which is impossible.The fourth test case is probably an auto level with a single jump over the spike.In the fifth test case the number of clears decreased, which is also impossible.Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it.

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci

				if pi < ci {
					res = "NO"
				}
			} else {
				/*
					if lastCi == ci && lastPi > pi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi >= pi && res == "YES" {
						res = "NO"
					}
					if ci < lastCi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi == pi && res == "YES" {
						res = "NO"
					}

					if ci < lastCi && res == "YES" {
						res = "NO"
					}

					if pi < lastPi && res == "YES" {
						res = "NO"
					}

					if n == 1 {
						res = "YES"
					}

					lastPi = pi
					lastCi = ci
				*/

				if pi > lastPi {
					if ci < lastCi {
						res = "NO"
					}

				} else if pi < lastPi {
					res = "NO"
				} else if pi == lastPi {
					if ci != lastCi {
						res = "NO"
					}
				}

				if pi < ci {
					res = "NO"
				}

				if (pi - lastPi) < (ci - lastCi) {
					res = "NO"
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		if exec() {
			printf("YES\n")
			continue
		}
		printf("NO\n")
	}
}

func exec() bool {
	var n int
	scanf("%d\n", &n)

	var previousP, previousC int
	scanf("%d %d\n", &previousP, &previousC)

	result := true
	isValidated := false

	if previousP < previousC {
		result = false
		isValidated = true
	}

	for i := 0; i < n-1; i++ {
		var p, c int
		scanf("%d %d\n", &p, &c)

		if isValidated {
			continue
		}
		if p < c {
			isValidated = true
			result = false
			continue
		}
		if p < previousP {
			isValidated = true
			result = false
			continue
		}
		if c < previousC {
			isValidated = true
			result = false
			continue
		}
		if p-previousP < c-previousC {
			isValidated = true
			result = false
			continue
		}

		previousP = p
		previousC = c
	}
	return result

}

 // Template from https://www.codementor.io/@tucnak/using-golang-for-competitive-programming-h8lhvxzt3
 package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

type pairs []pair                  /**/
func (a pairs) Len() int           { return len(a) }
func (a pairs) Less(i, j int) bool { return a[i].x < a[j].x || a[i].y < a[j].y }
func (a pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
type pair struct {
  x int
  y int
}

func solve(l []pair) bool{
  for i, _ := range l {
    if l[i].x < l[i].y || (i>0 && (l[i-1].x>l[i].x || l[i-1].y>l[i].y)){
      return false
    }
    if i>0 && l[i].x-l[i-1].x < l[i].y-l[i-1].y{
      return false
    }
  }
  return true
}

func main() {
  defer writer.Flush() // Will flush manually before return
  ntc:=0
  scanf("%d\n", &ntc)
  for tc:=1; tc<=ntc; tc++{
    var n int
    scanf("%d\n", &n)
    l := make([]pair, n)
    for i:=0; i<n; i++{
      scanf("%d %d\n", &(l[i].x), &(l[i].y))
    }
    var ans string
    if solve(l){
      ans = "YES\n"
    } else {
      ans = "NO\n"
    }
    printf(ans)
  }
}

package main

import (
	"bufio"
	"fmt"
	"os"

)
func max(a,b int) int{
	if(a>b){
		return a
	}
	return b;
}
func main(){
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int;
	fmt.Fscanln(reader, &T)
	for t:=0;t<T;t++ {
		var n int;
		fmt.Fscanln(reader,&n);
		var attempted,cleared int;
		var prevAttempted,prevCleared int;
		flag:= false
		for i:=0;i<n;i++{
			fmt.Fscanln(reader, &attempted,&cleared)
			if(i==0){
				prevAttempted=attempted
				prevCleared=cleared
			}
			cDiff:=cleared-prevCleared
			aDiff:=attempted-prevAttempted
			if(cleared>attempted||prevAttempted>attempted||prevCleared>cleared ||cDiff>aDiff){
				flag=true
			}else{
				prevAttempted=attempted
				prevCleared=cleared
			}
		}
		if(flag==false){
			fmt.Fprintln(writer,"YES")
		}else{
			fmt.Fprintln(writer,"NO")
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1334/A
*/

package main

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

/********** 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 (
	// General purpose
	MOD          = 1000000000 + 7
	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
)

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

var (
	t    int
	n    int
	P, C []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		P, C = []int{}, []int{}
		for j := 0; j < n; j++ {
			p, c := ReadInt2()
			P = append(P, p)
			C = append(C, c)
		}

		solve()
	}
}

func solve() {
	cp, cc := P[0], C[0]

	if cp < cc {
		fmt.Println("NO")
		return
	}

	for i := 1; i < n; i++ {
		np, nc := P[i], C[i]

		if np < nc {
			fmt.Println("NO")
			return
		}

		// どちらも小さくなっていたらNG
		if cp > np || cc > nc {
			fmt.Println("NO")
			return
		}

		// クリア回数だけ増えるのはだめ
		if cp == np && cc < nc {
			fmt.Println("NO")
			return
		}

		dp, dc := np-cp, nc-cc
		if dp < dc {
			fmt.Println("NO")
			return
		}

		cp, cc = np, nc
	}

	fmt.Println("YES")
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString 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()
	}
}

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

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

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

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

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d\n", &tests)
	for test := 1; test <= tests; test++ {
		result := play()
		if result {
			print("YES\n")
		} else {
			print("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d\n", &n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &plays, &clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func print(format string, args ...interface{}) {
	os.Stdout.WriteString(fmt.Sprintf(format, args...))
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

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

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

	var t, n, a, b int
	for Fscan(in, &t); t > 0; t-- {
		ca, cb := 0, 0
		ans := true
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &a, &b)
			if a < ca || b < cb || a < b || b-cb > a-ca {
				ans = false
			}
			ca, cb = a, b
		}
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	var t, n, a, b int
	for Fscan(in, &t); t > 0; t-- {
		la, lb, ans := 0, 0, true
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &a, &b)
			if b < lb || a-la < b-lb {
				ans = false
			}
			la, lb = a, b
		}
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		r := true

		lp, lc := 0, 0
		for i := 0; i < n; i++ {
			p, c := ScanInt(), ScanInt()
			if r && (c > p || c < lc || p < lp || (p - lp < c - lc)) {
				r = false
			}
			lp, lc = p, c
		}

		if r {
			P("YES")
		} else {
			P("NO")
		}

	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
)

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

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

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var n int
		fmt.Scan(&n)
		p, c := 0, 0
		flag := true
		for i := 0; i < n; i++ {
			var x, y int
			fmt.Scan(&x, &y)
			if x < p || y < c || y-c > x-p {
				flag = false
			}
			p, c = x, y
		}
		if flag {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

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

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		p0, c0 := scanInt(), scanInt()
		ok := p0 >= c0
		for i := 1; i < n; i++ {
			p, c := scanInt(), scanInt()
			if p < c || p < p0 || c < c0 || p-p0 < c-c0 {
				ok = false
			}
			p0, c0 = p, c
		}
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

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

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

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) NextInt() int {
	impl.Scan()
	bb := impl.Bytes()
	i := 0
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		n := reader.NextInt64()
		pc := [][2]int64{}
		for ; n > 0; n-- {
			p, c := reader.NextInt64(), reader.NextInt64()
			pc = append(pc, [2]int64{p, c})
		}
		writer.Printf("%s\n", sol(pc))
	}
}

func sol(pcpc [][2]int64) string {
	prevP, prevC := int64(0), int64(0)
	for _, pc := range pcpc {
		p := pc[0]
		c := pc[1]
		if c-prevC > p-prevP ||
			p < prevP ||
			c < prevC ||
			p < 0 ||
			c < 0 {
			return "NO"
		}
        prevP, prevC = p, c
	}
	return "YES"
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci

				if pi < ci {
					res = "NO"
				}
			} else {
				/*
					if lastCi == ci && lastPi > pi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi >= pi && res == "YES" {
						res = "NO"
					}
					if ci < lastCi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi == pi && res == "YES" {
						res = "NO"
					}

					if ci < lastCi && res == "YES" {
						res = "NO"
					}

					if pi < lastPi && res == "YES" {
						res = "NO"
					}

					if n == 1 {
						res = "YES"
					}

					lastPi = pi
					lastCi = ci
				*/

				if pi > lastPi {
					if ci < lastCi {
						res = "NO"
					}

				} else if pi < lastPi {
					res = "NO"
				} else if pi == lastPi {
					if ci != lastCi {
						res = "NO"
					}
				}

				if pi < ci {
					res = "NO"
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci
			} else {
				/*
					if lastCi == ci && lastPi > pi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi >= pi && res == "YES" {
						res = "NO"
					}
					if ci < lastCi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi == pi && res == "YES" {
						res = "NO"
					}

					if ci < lastCi && res == "YES" {
						res = "NO"
					}

					if pi < lastPi && res == "YES" {
						res = "NO"
					}

					if n == 1 {
						res = "YES"
					}

					lastPi = pi
					lastCi = ci
				*/

				if pi > lastPi {
					if ci < lastCi {
						res = "NO"
					}

				} else if pi < lastPi {
					res = "NO"
				} else if pi == lastPi {
					if ci > lastCi {
						res = "NO"
					}
					if ci < lastCi {
						res = "NO"
					}
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci
			} else {
				if lastCi == ci && lastPi > pi && res == "YES" {
					res = "NO"
				}
				if ci > lastCi && lastPi >= pi && res == "YES" {
					res = "NO"
				}
				if ci < lastCi && res == "YES" {
					res = "NO"
				}
				if ci > lastCi && lastPi == pi && res == "YES" {
					res = "NO"
				}

				if ci < lastCi && res == "YES" {
					res = "NO"
				}

				if pi < lastPi && res == "YES" {
					res = "NO"
				}

				if n == 1 {
					res = "YES"
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci
			} else {
				if lastCi == ci && lastPi > pi && res == "YES" {
					res = "NO"
				}
				if ci > lastCi && lastPi >= pi && res == "YES" {
					res = "NO"
				}
				if ci < lastCi && res == "YES" {
					res = "NO"
				}
				if ci > lastCi && lastPi == pi && res == "YES" {
					res = "NO"
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci
			} else {
				/*
					if lastCi == ci && lastPi > pi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi >= pi && res == "YES" {
						res = "NO"
					}
					if ci < lastCi && res == "YES" {
						res = "NO"
					}
					if ci > lastCi && lastPi == pi && res == "YES" {
						res = "NO"
					}

					if ci < lastCi && res == "YES" {
						res = "NO"
					}

					if pi < lastPi && res == "YES" {
						res = "NO"
					}

					if n == 1 {
						res = "YES"
					}

					lastPi = pi
					lastCi = ci
				*/

				if pi > lastPi {
					if ci < lastCi {
						res = "NO"
					}

				} else if pi < lastPi {
					res = "NO"
				} else if pi == lastPi {
					if ci != lastCi {
						res = "NO"
					}
				}

				if pi < ci {
					res = "NO"
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

var r__ *bufio.Reader = bufio.NewReader(os.Stdin)
var w__ *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(r__, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(w__, f, a...) }
func fflush()                           { w__.Flush() }

func main() {
	defer fflush()

	var t int
	scanf("%d\n", &t)

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

		var n int
		scanf("%d\n", &n)

		var lastPi, lastCi int
		var res string = "YES"
		for j := 0; j < n; j++ {
			var pi, ci int
			scanf("%d %d\n", &pi, &ci)

			if j == 0 {
				lastPi = pi
				lastCi = ci
			} else {
				if lastCi == ci && lastPi > pi && res == "YES" {
					res = "NO"
				}
				if ci > lastCi && lastPi >= pi && res == "YES" {
					res = "NO"
				}
				if ci < lastCi && res == "YES" {
					res = "NO"
				}
				if ci > lastCi && lastPi == pi && res == "YES" {
					res = "NO"
				}

				if ci < lastCi && res == "YES" {
					res = "NO"
				}

				if pi < lastPi && res == "YES" {
					res = "NO"
				}

				lastPi = pi
				lastCi = ci

			}
		}
		printf("%s\n", res)
	}
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		if exec() {
			printf("YES\n")
			continue
		}
		printf("NO\n")
	}
}

func exec() bool {
	var n int
	scanf("%d\n", &n)

	var previousP, previousC int
	scanf("%d %d\n", &previousP, &previousC)

	if previousP < previousC {
		return false
	}

	result := true
	isValidated := false
	for i := 0; i < n-1; i++ {
		var p, c int
		scanf("%d %d\n", &p, &c)

		if isValidated {
			continue
		}
		if p < c {
			isValidated = true
			result = false
			continue
		}
		if p < previousP {
			isValidated = true
			result = false
			continue
		}
		if c < previousC {
			isValidated = true
			result = false
			continue
		}
		if p-previousP < c-previousC {
			isValidated = true
			result = false
			continue
		}

		previousP = p
		previousC = c
	}
	return result
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		if exec() {
			printf("YES\n")
			continue
		}
		printf("NO\n")
	}
}

func exec() bool {
	var n int
	scanf("%d\n", &n)

	var previousP, previousC int
	scanf("%d %d\n", &previousP, &previousC)

	if previousP < previousC {
		return false
	}

	result := true
	isValidated := false
	for i := 0; i < n-1; i++ {
		var p, c int
		scanf("%d %d\n", &p, &c)

		if isValidated {
			continue
		}

		if p < c {
			isValidated = true
			result = false
		}
		if p < previousP {
			isValidated = true
			result = false
		}
		if c < previousC {
			isValidated = true
			result = false
		}
		if p-previousP < c-previousC {
			isValidated = true
			result = false
		}

		previousP = p
		previousC = c
	}
	return result
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanIntArr() ([]int, error) {
	str, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}
	str = strings.TrimRight(str, "\n\r")
	strArr := strings.Split(str, " ")

	arr := make([]int, len(strArr))
	for i, strA := range strArr {
		arr[i], err = strconv.Atoi(strA)
		if err != nil {
			return nil, err
		}
	}

	return arr, nil
}

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		if exec() {
			printf("YES\n")
			continue
		}
		printf("NO\n")
	}
}

func exec() bool {
	var n int
	scanf("%d\n", &n)

	var previousP, previousC int
	scanf("%d %d\n", &previousP, &previousC)

	if previousP < previousC {
		return false
	}

	result := true
	isValidated := false
	for i := 0; i < n-1; i++ {
		var p, c int
		scanf("%d %d\n", &p, &c)

		if isValidated {
			continue
		}

		if p < c {
			isValidated = true
			result = false
		}
		if p < previousP {
			isValidated = true
			result = false
		}
		if c < previousC {
			isValidated = true
			result = false
		}

		previousP = p
		previousC = c
	}
	return result
}

 // Template from https://www.codementor.io/@tucnak/using-golang-for-competitive-programming-h8lhvxzt3
 package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

type pairs []pair                  /**/
func (a pairs) Len() int           { return len(a) }
func (a pairs) Less(i, j int) bool { return a[i].x < a[j].x || a[i].y < a[j].y }
func (a pairs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
type pair struct {
  x int
  y int
}

func solve(l []pair) bool{
  for i, _ := range l {
    if l[i].x < l[i].y || (i>0 && (l[i-1].x>l[i].x || l[i-1].y>l[i].y)){
      return false
    }
  }
  return true
}

func main() {
  defer writer.Flush() // Will flush manually before return
  ntc:=0
  scanf("%d\n", &ntc)
  for tc:=1; tc<=ntc; tc++{
    var n int
    scanf("%d\n", &n)
    l := make([]pair, n)
    for i:=0; i<n; i++{
      scanf("%d %d\n", &(l[i].x), &(l[i].y))
    }
    var ans string
    if solve(l){
      ans = "YES\n"
    } else {
      ans = "NO\n"
    }
    printf(ans)
  }
}

package main

import (
	"bufio"
	"fmt"
	"os"

)
func max(a,b int) int{
	if(a>b){
		return a
	}
	return b;
}
func main(){
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int;
	fmt.Fscanln(reader, &T)
	for t:=0;t<T;t++ {
		var n int;
		fmt.Fscanln(reader,&n);
		var attempted,cleared int;
		var currAttempted,currCleared int;
		flag:= false
		for i:=0;i<n;i++{
			fmt.Fscanln(reader, &attempted,&cleared)
			if(currAttempted==0){
				currAttempted=attempted
				currCleared=cleared
			}
			if(attempted<currAttempted || cleared>attempted||currCleared>cleared){
				flag=true
			}else{
				currAttempted=attempted
				currCleared=cleared
			}
		}
		if(flag==false){
			fmt.Fprintln(writer,"YES")
		}else{
			fmt.Fprintln(writer,"NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"

)
func max(a,b int) int{
	if(a>b){
		return a
	}
	return b;
}
func main(){
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int;
	fmt.Fscanln(reader, &T)
	for t:=0;t<T;t++ {
		var n int;
		fmt.Fscanln(reader,&n);
		var attempted,cleared int;
		var prevAttempted,prevCleared int;
		flag:= false
		for i:=0;i<n;i++{
			fmt.Fscanln(reader, &attempted,&cleared)
			if(i==0){
				prevAttempted=attempted
				prevCleared=cleared
			}
			if(cleared>attempted||prevAttempted>attempted||prevCleared>cleared){
				flag=true
			}else{
				prevAttempted=attempted
				prevCleared=cleared
			}
		}
		if(flag==false){
			fmt.Fprintln(writer,"YES")
		}else{
			fmt.Fprintln(writer,"NO")
		}
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1334/A
*/

package main

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

/********** 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 (
	// General purpose
	MOD          = 1000000000 + 7
	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
)

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

var (
	t    int
	n    int
	P, C []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		P, C = []int{}, []int{}
		for j := 0; j < n; j++ {
			p, c := ReadInt2()
			P = append(P, p)
			C = append(C, c)
		}

		solve()
	}
}

func solve() {
	cp, cc := P[0], C[0]

	if cp < cc {
		fmt.Println("NO")
		return
	}

	for i := 1; i < n; i++ {
		np, nc := P[i], C[i]

		if np < nc {
			fmt.Println("NO")
			return
		}

		// どちらも小さくなっていたらNG
		if cp > np || cc > nc {
			fmt.Println("NO")
			return
		}

		// クリア回数だけ増えるのはだめ
		if cp == np && cc < nc {
			fmt.Println("NO")
			return
		}

		cp, cc = np, nc
	}

	fmt.Println("YES")
}

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

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

var (
	// ReadString returns a WORD string.
	ReadString 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()
	}
}

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

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

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

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

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scan("%d", &tests)
	print("%d\n", tests)
	for test := 1; test <= tests; test++ {
		print("ok test %d\n", test)
		result := play()
		if result {
			print("YES\n")
		} else {
			print("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scan("%d", &n)
	print("n: %d\n", n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scan("%d %d", &plays, &clears)
		print("%d %d\n", plays, clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func print(format string, args ...interface{}) {
	os.Stdout.WriteString(fmt.Sprintf(format, args...))
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d", &tests)
	for test := 1; test <= tests; test++ {
		printDebug("test %d\n", test)
		result := play()
		if result {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d", &n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &plays, &clears)
		printDebug("%d %d\n", plays, clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("ENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d\n", &tests)
	print("%d\n", tests)
	for test := 1; test <= tests; test++ {
		result := play()
		if result {
			print("YES\n")
		} else {
			print("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d\n", &n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &plays, &clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func print(format string, args ...interface{}) {
	os.Stdout.WriteString(fmt.Sprintf(format, args...))
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d", &tests)
	print("%d\n", tests)
	for test := 1; test <= tests; test++ {
		print("ok test %d\n", test)
		result := play()
		if result {
			print("YES\n")
		} else {
			print("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d", &n)
	print("n: %d\n", n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &plays, &clears)
		print("%d %d\n", plays, clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func print(format string, args ...interface{}) {
	os.Stdout.WriteString(fmt.Sprintf(format, args...))
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d\n", &tests)
	print("%d\n", tests)
	for test := 1; test <= tests; test++ {
		print("ok test %d\n", test)
		result := play()
		if result {
			print("YES\n")
		} else {
			print("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d\n", &n)
	print("n: %d\n", n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &plays, &clears)
		print("%d %d\n", plays, clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func print(format string, args ...interface{}) {
	os.Stdout.WriteString(fmt.Sprintf(format, args...))
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d", &tests)
	for test := 1; test <= tests; test++ {
		result := play()
		if result {
			print("YES\n")
		} else {
			print("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d", &n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &plays, &clears)
		print("%d %d\n", plays, clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func print(format string, args ...interface{}) {
	os.Stdout.WriteString(fmt.Sprintf(format, args...))
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d", &tests)
	for test := 1; test <= tests; test++ {
		result := play()
		if result {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d", &n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &plays, &clears)
		fmt.Printf("%d %d\n", plays, clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

import (
	"fmt"
	"os"
)

func main() {
	var tests int
	fmt.Scanf("%d", &tests)
	for test := 1; test <= tests; test++ {
		result := play()
		if result {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

func play() bool {
	var n int
	fmt.Scanf("%d", &n)

	var (
		pplays, pclears int
		plays, clears   int
	)

	result := true
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &plays, &clears)

		if plays < pplays || clears < pclears {
			result = false
		}

		if clears-pclears > plays-pplays {
			result = false
		}

		pplays, pclears = plays, clears
	}

	return result
}

func printDebug(format string, args ...interface{}) {
	if os.Getenv("OENV") == "dev" {
		fmt.Printf("DEBUG: "+format, args...)
	}
}

package main

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

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

	var t, n, a, b int
	for Fscan(in, &t); t > 0; t-- {
		ca, cb := 0, 0
		ans := true
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &a, &b)
			if a < ca || b < cb || a < b || b > cb && a == ca {
				ans = false
			}
			ca, cb = a, b
		}
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

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

	var t, n, a, b int
	for Fscan(in, &t); t > 0; t-- {
		ca, cb := 0, 0
		ans := true
		for Fscan(in, &n); n > 0; n-- {
			Fscan(in, &a, &b)
			if a < ca || b < cb || a < b {
				ans = false
			}
			ca, cb = a, b
		}
		if ans {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		r := true

		lp, lc := 0, 0
		for i := 0; i < n; i++ {
			p, c := ScanInt(), ScanInt()
			if r && (c > p || c < lc || p < lp) {
				r = false
			}
			lp, lc = p, c
		}

		if r {
			P("YES")
		} else {
			P("NO")
		}

	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
)

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

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

func max(arr []int) (max int) {
	max = arr[0]
	for _, val := range arr {
		if val > max {
			max = val
		}
	}
	return max
}

func main() {
	var t int
	fmt.Scan(&t)
	for qt := 0; qt < t; qt++ {
		var n int
		fmt.Scan(&n)
		arr := make([][]int, n)
		for i := range arr {
			arr[i] = make([]int, 2)
		}
		for i := 0; i < n; i++ {
			fmt.Scan(&arr[i][0], &arr[i][1])
		}
		i := 0
		for i = 1; i < n; i++ {
			if arr[i][1] > arr[i-1][1] {
				if arr[i][0] <= arr[i-1][0] {
					break
				}
			} else if arr[i][1] == arr[i-1][1] {
				if arr[i][0] < arr[i-1][0] {
					break
				}
			} else {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

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

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

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		p0, c0 := scanInt(), scanInt()
		ok := p0 >= c0
		for i := 1; i < n; i++ {
			p, c := scanInt(), scanInt()
			if p < c || p < p0 || c < c0 {
				ok = false
			}
			p0, c0 = p, c
		}
		if ok {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


The only difference between the two versions is that in this version $$$n \leq 2 \cdot 10^5$$$ and the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.A terminal is a row of $$$n$$$ equal segments numbered $$$1$$$ to $$$n$$$ in order. There are two terminals, one above the other. You are given an array $$$a$$$ of length $$$n$$$. For all $$$i = 1, 2, \dots, n$$$, there should be a straight wire from some point on segment $$$i$$$ of the top terminal to some point on segment $$$a_i$$$ of the bottom terminal. You can't select the endpoints of a segment. For example, the following pictures show two possible wirings if $$$n=7$$$ and $$$a=[4,1,4,6,7,7,5]$$$.  A crossing occurs when two wires share a point in common. In the picture above, crossings are circled in red.What is the maximum number of crossings there can be if you place the wires optimally?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq n$$$) — the elements of the array. The sum of $$$n$$$ across all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a single integer — the maximum number of crossings there can be if you place the wires optimally.

NoteThe first test case is shown in the second picture in the statement.In the second test case, the only wiring possible has the two wires cross, so the answer is $$$1$$$.In the third test case, the only wiring possible has one wire, so the answer is $$$0$$$.

package main

import (
	"bufio"
	"fmt"
	"io"
	"math/bits"
	"os"
	"sort"
	"strconv"
	"strings"
)

var in *In
var out *Out

const N = 2e5 + 10

var a, b [N]int

func lowbit(x int) int {
	return x & (-x)
}

func add(x, k int) {
	for i := x; i < N; i += lowbit(i) {
		b[i] += k
	}
}

func get(x int) int {
	ans := 0
	for i := x; i > 0; i -= lowbit(i) {
		ans += b[i]
	}
	return ans
}

func problem_solver() {
	T := in.NextInt()
	for T > 0 {
		T--
		n := in.NextInt()
		var ans int64 = 0
		for i := 1; i <= n; i++ {
			a[i] = in.NextInt()
			a[i] = n - a[i] + 1
			ans += int64(get(a[i]))
			add(a[i], 1)
		}
		for i := 1; i <= n; i++ {
			add(a[i], -1)
		}
		out.Println(ans)

	}
}

func main() {

	in, out = InitIo(true)
	defer out.Flush()

	problem_solver()

}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args...)
}

// ==================================================
// 入出力操作
// ==================================================
type In struct {
	// NextString は 次の入力を文字列として読み込んで返します。
	NextString func() string
}

type Out struct {
	writer io.Writer
	Flush  func()
}

// InitIo は inとoutを初期化します。
func InitIo(buffer bool) (*In, *Out) {
	bufsize := 4 * 1024 * 1024 // 4MB

	// 入力はずっとバッファーでいいらしい。ほんとう？
	// TODO バッファなしfmt.Fscanf(os.Stdin)だとTLEだった。要調査
	_in := bufio.NewScanner(os.Stdin)
	_in.Split(bufio.ScanWords)
	_in.Buffer(make([]byte, bufsize), bufsize)
	in := func() string {
		_in.Scan()
		return _in.Text()
	}

	// 出力はバッファon/offが必要
	var out io.Writer
	var flush func()

	if buffer {
		_out := bufio.NewWriterSize(os.Stdout, bufsize)
		out = _out
		flush = func() {
			_out.Flush()
		}
	} else {
		out = os.Stdout
		flush = func() {}
	}

	return &In{in}, &Out{out, flush}
}

// NextBytes は 次の入力をbyteの配列として読み込んで返します。
// 遅いから極力使わない。
func (in *In) NextBytes() []byte {
	return []byte(in.NextString())
}

// NextInt は 次の入力を数値として読み込んで返します。
func (in *In) NextInt() int {
	i, _ := strconv.Atoi(in.NextString())
	return i
}

// NextInt2 は 次の2つの入力を数値として読み込んで返します。
func (in *In) NextInt2() (int, int) {
	return in.NextInt(), in.NextInt()
}

// NextInt2d は 次の2つの入力を数値n1,n2として読み込んで、n1+d1, n2+d2を返します。
func (in *In) NextInt2d(d1, d2 int) (int, int) {
	return in.NextInt() + d1, in.NextInt() + d2
}

// NextInt3 は 次の3つの入力を数値として読み込んで返します。
func (in *In) NextInt3() (int, int, int) {
	return in.NextInt(), in.NextInt(), in.NextInt()
}

// NextInt2d は 次の3つの入力を数値n1,n2,n3として読み込んで、n1+d1, n2+d2, n3+d3を返します。
func (in *In) NextInt3d(d1, d2, d3 int) (int, int, int) {
	return in.NextInt() + d1, in.NextInt() + d2, in.NextInt() + d3
}

// NextInt4 は 次の4つの入力を数値として読み込んで返します。
func (in *In) NextInt4() (int, int, int, int) {
	return in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()
}

// NextInts は 次のn個の入力を数値として読み込んで、配列として返します。
func (in *In) NextInts(n int) sort.IntSlice {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = in.NextInt()
	}
	return sort.IntSlice(a)
}

// NextLongIntAsArray は 次の入力を数値として読み込み、各桁を要素とした配列を返します。
func (in *In) NextLongIntAsArray() []int {
	s := in.NextString()
	l := len(s)
	arr := make([]int, l)
	for i := 0; i < l; i++ {
		arr[i] = int(s[i] - '0')
	}

	return arr
}

// NextFloat は 次の入力を実数値として読み込み、値を返します。
func (in *In) NextFloat() float64 {
	f, _ := strconv.ParseFloat(in.NextString(), 64)
	return f
}

// NextFloatAsInt は次の入力を実数rとして読み込み、r * 10^base の値を返します。
func (in *In) NextFloatAsInt(base int) int {
	if base%10 == 0 {
		panic("baseは小数点の最大桁数を指定する")
	}

	s := in.NextString()
	index := strings.IndexByte(s, '.')

	// 小数点がなければそのまま返す
	if index == -1 {
		n, _ := strconv.Atoi(s)
		return n * pow(10, base)
	}

	// 末尾の0を消しておく
	for s[len(s)-1] == '0' {
		s = s[:len(s)-1]
	}

	// 整数部分 * 10^base + 小数部分 * 10^(足りない分)
	s1, s2 := s[:index], s[index+1:]
	n, _ := strconv.Atoi(s1)
	m, _ := strconv.Atoi(s2)

	return n*pow(10, base) + m*pow(10, base-len(s2))
}

// Println は引数をスペース区切りで出力し、最後に改行を出力します。
func (out *Out) Println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

// Printf はformatにしたがってaを整形して出力します。
func (out *Out) Printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

// PrintStringsln は文字列配列の各要素をスペース区切りで出力し、最後に改行を出力します。
func (out *Out) PrintStringsln(a []string) {
	out.Println(strings.Join(a, " "))
}

// PrintIntsLn は整数配列の各要素をスペース区切りで出力し、最後に改行を出力します。
func (out *Out) PrintIntsLn(a []int) {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = fmt.Sprint(v)
	}
	out.Println(strings.Join(b, " "))
}

func (out *Out) PrintLenAndIntsLn(a []int) {
	b := make([]string, len(a)+1)
	b[0] = fmt.Sprint(len(a))
	for i, v := range a {
		b[i+1] = fmt.Sprint(v)
	}
	out.Println(strings.Join(b, " "))
}

// YesNo は condが真ならYes, 偽ならNoを出力します。
func (out *Out) YesNo(cond bool) {
	if cond {
		out.Println("Yes")
	} else {
		out.Println("No")
	}
}

func (out *Out) YESNO(cond bool) {
	if cond {
		out.Println("YES")
	} else {
		out.Println("NO")
	}
}

// ==================================================
// 数値操作
// ==================================================

// max は aとbのうち大きい方を返します。
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// min は aとbのうち小さい方を返します。
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// abs は aの絶対値を返します。
func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

// pow は aのb乗を返します。
func pow(a, b int) int {
	ans := 1
	for b > 0 {
		if b%2 == 1 {
			ans *= a
		}
		a, b = a*a, b/2
	}
	return ans
}

// divceil は a/b の結果を正の無限大に近づけるように丸めて返します。
func divceil(a, b int) int {
	if a%b == 0 || a/b < 0 {
		return a / b
	}
	return (a + b - 1) / b
}

// divfloor は a/b の結果を負の無限大に近づけるように丸めて返します。
func divfloor(a, b int) int {
	if a%b == 0 || a/b > 0 {
		return a / b
	}
	if b < 0 {
		a, b = -a, -b
	}
	return (a - b + 1) / b
}

// powmod は (x^n) mod m を返します。
func powmod(x, n, m int) int {
	x = x % m
	if x == 0 {
		return 0
	}

	ans := 1
	for n > 0 {
		if n%2 == 1 {
			ans = (ans * x) % m
		}
		x = (x * x) % m
		n /= 2
	}
	return ans
}

// ch は condがtrueのときok, falseのときngを返します。
func ch(cond bool, ok, ng int) int {
	if cond {
		return ok
	}
	return ng
}

// ==================================================
// ビット操作
// ==================================================

// nthbit はaのn番目のビットを返します。
func nthbit(a int, n int) int { return int((a >> uint(n)) & 1) }

// popcount はaのうち立っているビットを数えて返します。
func popcount(a int) int {
	return bits.OnesCount(uint(a))
}

func xor(a, b bool) bool { return a != b }

// ==================================================
// 文字列操作
// ==================================================

// toLowerCase は sをすべて小文字にした文字列を返します。
func toLowerCase(s string) string {
	return strings.ToLower(s)
}

// toUpperCase は sをすべて大文字にした文字列を返します。
func toUpperCase(s string) string {
	return strings.ToUpper(s)
}

// isLower はbが小文字かどうかを判定します
func isLower(b byte) bool {
	return 'a' <= b && b <= 'z'
}

// isUpper はbが大文字かどうかを判定します
func isUpper(b byte) bool {
	return 'A' <= b && b <= 'Z'
}

// ==================================================
// 配列
// ==================================================
// NewIntInt は数値の二次元配列を作成します。
func NewIntInt(rows, cols, val int) [][]int {
	a := make([][]int, rows)
	for i := 0; i < rows; i++ {
		a[i] = make([]int, cols)

		for j := 0; j < cols; j++ {
			a[i][j] = val
		}
	}

	return a
}

func reverse(arr *[]interface{}) {
	for i, j := 0, len(*arr)-1; i < j; i, j = i+1, j-1 {
		(*arr)[i], (*arr)[j] = (*arr)[j], (*arr)[i]
	}
}

func reverseInt(arr *[]int) {
	for i, j := 0, len(*arr)-1; i < j; i, j = i+1, j-1 {
		(*arr)[i], (*arr)[j] = (*arr)[j], (*arr)[i]
	}
}

func uniqueInt(arr []int) []int {
	hist := map[int]bool{}
	j := 0
	for i := 0; i < len(arr); i++ {
		if hist[arr[i]] {
			continue
		}

		a := arr[i]
		arr[j] = a
		hist[a] = true
		j++
	}
	return arr[:j]
}

// ==================================================
// 構造体
// ==================================================

// Point は 座標を表す構造体です。
type Point struct {
	x int
	y int
}

type Geo struct {
}

// NextPointは入力から2点読み込んで座標として返します。
func (g *Geo) NextPoint() *Point {
	return &Point{in.NextInt(), in.NextInt()}
}

// x2areaは3点で囲まれる面積の2倍を返します。
func (g *Geo) x2area(p1 *Point, p2 *Point, p3 *Point) int {
	return abs(p1.x*p2.y + p2.x*p3.y + p3.x*p1.y - p1.y*p2.x - p2.y*p3.x - p3.y*p1.x)
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	cnt := make(map[int]int)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		cnt[nums[i]]++
	}
	f := newFenwick(2e5+5)
	var ans int64
	for i := range nums {
		ans += int64(f.query(nums[i]+1, 2e5+2))
		f.add(nums[i], 1)
	}
	for _, v := range cnt {
		ans += int64((v-1))*int64(v)/2
	}
	fmt.Fprintln(w, ans)
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

type fenwick struct {tree []int}
func newFenwick(n int) fenwick {return fenwick{make([]int, n+1)}}
func (f fenwick) add(i int, val int) {for ; i < len(f.tree); i += i & -i {f.tree[i] += val}}
func (f fenwick) sum(i int) (res int) {for ; i > 0; i -= i & -i {res += f.tree[i]}; return}
func (f fenwick) query(l, r int) int {return f.sum(r) - f.sum(l-1)}

package main

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

// github.com/EndlessCheng/codeforces-go
type fenwick struct {
	tree []int
}

func newFenwickTree(n int) fenwick {
	return fenwick{make([]int, n+1)}
}
func (f fenwick) add(i int, val int) {
    //i++
	for ; i < len(f.tree); i += i & -i {
		f.tree[i] += val
	}
}
func (f fenwick) sum(i int) (res int) {
    //i++
	for ; i > 0; i &= i - 1 {
		res += f.tree[i]
	}
	return
}
func (f fenwick) query(l, r int) (res int) { // [l,r]
	return f.sum(r) - f.sum(l-1)
}

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		f := newFenwickTree(n+1)
		ans := int64(0)
		for _, v := range a {
			s := f.query(v,n)
			ans+= int64(s)
			f.add(v,1)
		}
		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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

package main

import "fmt"

const N = 1e5 + 10

var a, b [N]int

func lowbit(x int) int {
	return x & (-x)
}

func add(x, k int) {
	for i := x; i < N; i += lowbit(i) {
		b[i] += k
	}
}

func get(x int) int {
	ans := 0
	for i := x; i != 0; i -= lowbit(i) {
		ans += b[i]
	}
	return ans
}

func main() {
	var T int
	fmt.Scan(&T)
	for T >= 0 {
		T--
		var n int
		fmt.Scan(&n)
		ans := 0
		for i := 1; i <= n; i++ {
			fmt.Scan(&a[i])
			a[i] = n - a[i] + 1
			ans += get(a[i])
			add(a[i], 1)
		}
		for i := 1; i <= n; i++ {
			add(a[i], -1)
		}
		fmt.Println(ans)

	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	cnt := make(map[int]int)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		cnt[nums[i]]++
	}
	f := newFenwick(2e5+1)
	ans := 0
	for i := range nums {
		ans += f.query(nums[i]+1, 2e5)
		f.add(nums[i], 1)
	}
	for _, v := range cnt {
		ans += (v-1)*v/2
	}
	fmt.Fprintln(w, ans)
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

type fenwick struct {tree []int}
func newFenwick(n int) fenwick {return fenwick{make([]int, n+1)}}
func (f fenwick) add(i int, val int) {for ; i < len(f.tree); i += i & -i {f.tree[i] += val}}
func (f fenwick) sum(i int) (res int) {for ; i > 0; i -= i & -i {res += f.tree[i]}; return}
func (f fenwick) query(l, r int) int {return f.sum(r) - f.sum(l-1)}


You have a fence consisting of $$$n$$$ vertical boards. The width of each board is $$$1$$$. The height of the $$$i$$$-th board is $$$a_i$$$. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is great if and only if for all indices from $$$2$$$ to $$$n$$$, the condition $$$a_{i-1} \neq a_i$$$ holds.Unfortunately, it is possible that now your fence is not great. But you can change it! You can increase the length of the $$$i$$$-th board by $$$1$$$, but you have to pay $$$b_i$$$ rubles for it. The length of each board can be increased any number of times (possibly, zero).Calculate the minimum number of rubles you have to spend to make the fence great again!You have to answer $$$q$$$ independent queries.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 3 \cdot 10^5$$$) — the number of queries. The first line of each query contains one integers $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of boards in the fence. The following $$$n$$$ lines of each query contain the descriptions of the boards. The $$$i$$$-th line contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le 10^9$$$) — the length of the $$$i$$$-th board and the price for increasing it by $$$1$$$, respectively. It is guaranteed that sum of all $$$n$$$ over all queries not exceed $$$3 \cdot 10^5$$$. It is guaranteed that answer to each query will not exceed $$$10^{18}$$$.

For each query print one integer — the minimum number of rubles you have to spend to make the fence great.

NoteIn the first query you have to increase the length of second board by $$$2$$$. So your total costs if $$$2 \cdot b_2 = 2$$$.In the second query you have to increase the length of first board by $$$1$$$ and the length of third board by $$$1$$$. So your total costs if $$$1 \cdot b_1 + 1 \cdot b_3 = 9$$$.In the third query the fence is great initially, so you don't need to spend rubles.

package main

import (
	"bufio"
	"bytes"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func Sol1221D(reader io.Reader, writer io.Writer) {
	const inf int64 = 2e18
	min := func(a, b int64) int64 {
		if a <= b {
			return a
		}
		return b
	}
	mins := func(vals ...int64) int64 {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val < ans {
				ans = val
			}
		}
		return ans
	}

	data, _ := ioutil.ReadAll(reader)
	in := bytes.NewReader(data)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var dp [2][3]int64
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		h := make([]int, n)
		costs := make([]int, n)
		for i := range h {
			Fscan(in, &h[i], &costs[i])
		}

		row := 0
		dp[0][0] = 0
		dp[0][1] = int64(costs[0])
		dp[0][2] = int64(2 * costs[0])
		for i := 1; i < n; i++ {
			row ^= 1
			for d0 := 0; d0 < 3; d0++ {
				ans := inf
				for d1 := 0; d1 < 3; d1++ {
					if h[i]+d0 != h[i-1]+d1 {
						ans = min(ans, dp[row^1][d1]+int64(d0*costs[i]))
					}
				}
				dp[row][d0] = ans
			}
		}
		Fprintln(out, mins(dp[row][:]...))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1221D(reader io.Reader, writer io.Writer) {
	const inf int64 = 2e18
	min := func(a, b int64) int64 {
		if a <= b {
			return a
		}
		return b
	}
	mins := func(vals ...int64) int64 {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val < ans {
				ans = val
			}
		}
		return ans
	}

	in := bufio.NewReaderSize(reader, 1e6)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var dp [2][3]int64
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		h := make([]int, n)
		costs := make([]int, n)
		for i := range h {
			Fscan(in, &h[i], &costs[i])
		}

		row := 0
		dp[0][0] = 0
		dp[0][1] = int64(costs[0])
		dp[0][2] = int64(2 * costs[0])
		for i := 1; i < n; i++ {
			row ^= 1
			for d0 := 0; d0 < 3; d0++ {
				ans := inf
				for d1 := 0; d1 < 3; d1++ {
					if h[i]+d0 != h[i-1]+d1 {
						ans = min(ans, dp[row^1][d1]+int64(d0*costs[i]))
					}
				}
				dp[row][d0] = ans
			}
		}
		Fprintln(out, mins(dp[row][:]...))
	}
}

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

package main

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

func Sol1221D(reader io.Reader, writer io.Writer) {
	const inf int64 = 2e18
	min := func(a, b int64) int64 {
		if a <= b {
			return a
		}
		return b
	}
	mins := func(vals ...int64) int64 {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val < ans {
				ans = val
			}
		}
		return ans
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var dp [2][3]int64
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		h := make([]int, n)
		costs := make([]int, n)
		for i := range h {
			Fscan(in, &h[i], &costs[i])
		}

		row := 0
		dp[0][0] = 0
		dp[0][1] = int64(costs[0])
		dp[0][2] = int64(2 * costs[0])
		for i := 1; i < n; i++ {
			row ^= 1
			for d0 := 0; d0 < 3; d0++ {
				ans := inf
				for d1 := 0; d1 < 3; d1++ {
					if h[i]+d0 != h[i-1]+d1 {
						ans = min(ans, dp[row^1][d1]+int64(d0*costs[i]))
					}
				}
				dp[row][d0] = ans
			}
		}
		Fprintln(out, mins(dp[row][:]...))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1221D(reader io.Reader, writer io.Writer) {
	const inf int64 = 2e18
	min := func(a, b int64) int64 {
		if a <= b {
			return a
		}
		return b
	}
	mins := func(vals ...int64) int64 {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val < ans {
				ans = val
			}
		}
		return ans
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var dp [int(3e5)][3]int64
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		h := make([]int, n)
		costs := make([]int, n)
		for i := range h {
			Fscan(in, &h[i], &costs[i])
		}

		dp[0][1] = int64(costs[0])
		dp[0][2] = int64(2 * costs[0])
		for i := 1; i < n; i++ {
			for d0 := 0; d0 < 3; d0++ {
				dp[i][d0] = inf
				for d1 := 0; d1 < 3; d1++ {
					if h[i]+d0 != h[i-1]+d1 {
						dp[i][d0] = min(dp[i][d0], dp[i-1][d1]+int64(d0*costs[i]))
					}
				}
			}
		}
		Fprintln(out, mins(dp[n-1][:]...))
	}
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	for ii := 0; ii < q; ii++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int64, n)
		b := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d %d\n", &a[i], &b[i])
		}
		ans0 := int64(0)
		ans1 := b[0]
		ans2 := b[0] * 2
		for i := 1; i < n; i++ {
			newans0 := int64(-1)
			if a[i] != a[i-1] {
				newans0 = min(newans0, ans0)
			}
			if a[i] != a[i-1] + 1{
				newans0 = min(newans0, ans1)
			}
			if a[i] != a[i-1] + 2 {
				newans0 = min(newans0, ans2)
			}
			newans1 := int64(-1)
			if a[i]+1 != a[i-1] {
				newans1 = min(newans1, ans0 + b[i])
			}
			if a[i]+1 != a[i-1] + 1{
				newans1 = min(newans1, ans1 + b[i])
			}
			if a[i]+1 != a[i-1] + 2 {
				newans1 = min(newans1, ans2 + b[i])
			}
			newans2 := int64(-1)
			if a[i]+2 != a[i-1] {
				newans2 = min(newans2, ans0 + b[i]*2)
			}
			if a[i]+2 != a[i-1] + 1{
				newans2 = min(newans2, ans1 + b[i]*2)
			}
			if a[i]+2 != a[i-1] + 2 {
				newans2 = min(newans2, ans2 + b[i]*2)
			}
			ans0, ans1, ans2 = newans0, newans1, newans2
		}
		ans := min(ans0, ans1)
		ans = min(ans, ans2)
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func min(a, b int64) int64 {
	if a == -1 {
		return b
	}
	if b == -1 {
		return a
	}
	if a < b {
		return a
	}
	return b
}

package main

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

type state struct {
	index int
	prev  uint32
}

func solve(a, b []uint32) float64 {
	m := map[state]float64{}

	var f func(index int, prev uint32) float64
	f = func(index int, prev uint32) float64 {
		if index > len(a)-1 {
			return 0
		}

		s := state{index, prev}
		res, has := m[s]
		if has {
			return res
		}

		r := 10e18 + 1
		for h := uint32(0); h < 3; h++ {
			t := r
			if a[index]+h != prev {
				t = float64(h*b[index]) + (f(index+1, a[index]+h))
			}

			if t < r {
				r = t
			}
		}

		m[s] = r

		return r
	}

	res := f(0, a[0]-1)
	//fmt.Println(m)

	return res
}

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

	return n
}

func main() {
	var q uint32

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	q = toInt(scanner.Bytes())

	for i := uint32(0); i < q; i++ {
		var n int

		scanner.Scan()
		n = int(toInt(scanner.Bytes()))

		a := make([]uint32, n)
		b := make([]uint32, n)
		for j := range a {
			scanner.Scan()
			a[j] = toInt(scanner.Bytes())

			scanner.Scan()
			b[j] = toInt(scanner.Bytes())
		}

		fmt.Printf("%.0f\n", solve(a, b))
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1221/problem/D

package main

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

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

func createDP(n int64, b []int64) [][]int64 {
	dp := make([][]int64, n)
	for i := int64(0); i < n; i++ {
		dp[i] = make([]int64, 3)
		for j := int64(0); j < 3; j++ {
			if i == 0 {
				dp[0][j] = j * b[0]
			} else {
				dp[i][j] = math.MaxInt64
			}
		}
	}
	return dp
}

func Solve(n int64, a []int64, b []int64) int64 {
	dp := createDP(n, b)
	for i := int64(1); i < n; i++ {
		for j := int64(0); j < 3; j++ {
			for k := int64(0); k < 3; k++ {
				if a[i]+j != a[i-1]+k {
					cost := dp[i-1][k] + j*b[i]
					dp[i][j] = min(dp[i][j], cost)
				}
			}
		}
	}
	var minElem int64 = math.MaxInt64
	for _, elem := range dp[n-1] {
		minElem = min(minElem, elem)
	}
	return minElem
}

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

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

package main

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

type state struct {
	index int
	prev  uint32
}

func solve(a, b []uint32) float64 {
	m := map[state]float64{}

	var f func(index int, prev uint32) float64
	f = func(index int, prev uint32) float64 {
		if index > len(a)-1 {
			return 0
		}

		s := state{index, prev}
		res, has := m[s]
		if has {
			return res
		}

		r := 10e18 + 1
		for h := uint32(0); h < 3; h++ {
			t := r
			if a[index]+h != prev {
				t = float64(h*b[index]) + (f(index+1, a[index]+h))
			}

			if t < r {
				r = t
			}
		}

		m[s] = r

		return r
	}

	res := f(0, a[0]-1)
	//fmt.Println(m)

	return res
}

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

	return n
}

func main() {
	var q uint32

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	q = toInt(scanner.Bytes())

	for i := uint32(0); i < q; i++ {
		var n int

		scanner.Scan()
		n = int(toInt(scanner.Bytes()))

		a := make([]uint32, n)
		b := make([]uint32, n)
		for j := range a {
			scanner.Scan()
			a[j] = toInt(scanner.Bytes())

			scanner.Scan()
			b[j] = toInt(scanner.Bytes())
		}

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