Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. Team a gets a higher place than team b in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team a gets a higher place than team b in the final results' table if either pa > pb, or pa = pb and ta < tb. It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of x teams that solved the same number of problems with the same penalty time. Let's also say that y teams performed better than the teams from this group. In this case all teams from the group share places y + 1, y + 2, ..., y + x. The teams that performed worse than the teams from this group, get their places in the results table starting from the y + x + 1-th place.Your task is to count what number of teams from the given list shared the k-th place.

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 50). Then n lines contain the description of the teams: the i-th line contains two integers pi and ti (1 ≤ pi, ti ≤ 50) — the number of solved problems and the total penalty time of the i-th team, correspondingly. All numbers in the lines are separated by spaces.

In the only line print the sought number of teams that got the k-th place in the final results' table.

NoteThe final results' table for the first sample is:   1-3 places — 4 solved problems, the penalty time equals 10  4 place — 3 solved problems, the penalty time equals 20  5-6 places — 2 solved problems, the penalty time equals 1  7 place — 1 solved problem, the penalty time equals 10 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.The final table for the second sample is:  1 place — 5 solved problems, the penalty time equals 3  2-5 places — 3 solved problems, the penalty time equals 1 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n,k,p,t int
	fmt.Scan(&n,&k)
	v:=make([]int,n)
	for i:=0;i<n;i++ {
		fmt.Scan(&p,&t)
		v[i]=p*51-t
	}
	sort.Ints(v)
	s,w:=1,1
	for ;n-k+w<n && v[n-k]==v[n-k+w]; {
		s++
		w++
	}
	w=1
	for ;n-k-w>=0 && v[n-k]==v[n-k-w]; {
		s++
		w++
	}
	fmt.Println(s)
}

package main

import (
    "fmt"
    "sort"
)

type Team struct {
    p,t int
}

type TeamSlice []Team

func (t TeamSlice) Len() int { return len(t) }
func (t TeamSlice) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t TeamSlice) Less(i, j int) bool {
    if t[i].p == t[j].p { return t[i].t < t[j].t }
    return t[i].p > t[j].p
}

func main() {
    var n,k int
    fmt.Scan(&n,&k)
    k--
    t := make(TeamSlice,n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t[i].p,&t[i].t)
    }
    sort.Sort(TeamSlice(t))
    ans := 0
    for i := 0; i < n; i++ {
        if (t[i].p == t[k].p) && (t[i].t == t[k].t) {
            ans++
        }
    }
    fmt.Println(ans)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
	buf := make([]byte, 2500000, 2500000)
	in.Buffer(buf, 0)
}
func exit() {
	out.Flush()
}

// io
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}
func nextInt64() int64 {
	in.Scan()
	ret, _ := strconv.ParseInt(in.Text(), 10, 64)
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */

type chengji struct {
	fenshu  int
	shijian int
}
type teams []chengji

func (ts teams) Len() int {
	return len(ts)
}
func (ts teams) Less(i, j int) bool {
	if ts[i].fenshu < ts[j].fenshu {
		return false
	}
	if ts[i].fenshu > ts[j].fenshu {
		return true
	}
	return ts[i].shijian < ts[j].shijian
}
func (ts teams) Swap(i, j int) {
	ts[i], ts[j] = ts[j], ts[i]
}

var num int
var kk int
var liushui teams

func main() {
	defer exit()
	num = nextInt()
	kk = nextInt()
	liushui = make(teams, num+1, num+1)
	for i := 1; i != num+1; i++ {
		liushui[i].fenshu = nextInt()
		liushui[i].shijian = nextInt()
	}
	sort.Sort(liushui[1:])
	// two direction binary search begin
	l := kk
	r := num
	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		midv := (liushui[mid].fenshu == liushui[kk].fenshu) && (liushui[mid].shijian == liushui[kk].shijian)
		if midv {
			l = mid
		} else {
			r = mid - 1
		}
	}
	up := l

	l = 1
	r = kk
	for {
		if l == r {
			break
		}
		mid := (l + r) / 2
		midv := (liushui[mid].fenshu == liushui[kk].fenshu) && (liushui[mid].shijian == liushui[kk].shijian)
		if midv {
			r = mid
		} else {
			l = mid + 1
		}
	}
	down := l
	fmt.Fprintf(out, "%d\n", up-down+1)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n,k,p,t int
	fmt.Scan(&n,&k)
	v:=make([]int,100)
	for i:=0;i<n;i++ {
		fmt.Scan(&p,&t)
		v[i]=p*51-t
	}
	sort.Ints(v)
	s,w:=1,1
	for ;n-k+w<n && v[n-k]==v[n-k+w]; {
		s++
		w++
	}
	w=1
	for ;n-k-w>=0 && v[n-k]==v[n-k-w]; {
		s++
		w++
	}
	fmt.Println(s)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
	buf := make([]byte, 2500000, 2500000)
	in.Buffer(buf, 0)
}
func exit() {
	out.Flush()
}

// io
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}
func nextInt64() int64 {
	in.Scan()
	ret, _ := strconv.ParseInt(in.Text(), 10, 64)
	return ret
}

func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */

type chengji struct {
	fenshu  int
	shijian int
}
type teams []chengji

func (ts teams) Len() int {
	return len(ts)
}
func (ts teams) Less(i, j int) bool {
	if ts[i].fenshu < ts[j].fenshu {
		return false
	}
	if ts[i].fenshu > ts[j].fenshu {
		return true
	}
	return ts[i].shijian < ts[j].shijian
}
func (ts teams) Swap(i, j int) {
	ts[i], ts[j] = ts[j], ts[i]
}

var num int
var kk int
var liushui teams

func main() {
	defer exit()
	num = nextInt()
	kk = nextInt()
	liushui = make(teams, num+1, num+1)
	for i := 1; i != num+1; i++ {
		liushui[i].fenshu = nextInt()
		liushui[i].shijian = nextInt()
	}
	sort.Sort(liushui[1:])
	// two direction binary search begin
	l := kk
	r := num
	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		midv := (liushui[mid].fenshu == liushui[kk].fenshu) && (liushui[mid].shijian == liushui[kk].shijian)
		if midv {
			l = mid
		} else {
			r = mid - 1
		}
	}
	up := l

	l = 1
	r = kk
	for {
		if l == r {
			break
		}
		mid := (l + r + 1) / 2
		midv := (liushui[mid].fenshu == liushui[kk].fenshu) && (liushui[mid].shijian == liushui[kk].shijian)
		if midv {
			l = mid
		} else {
			r = mid - 1
		}
	}
	down := l
	fmt.Fprintf(out, "%d\n", up-down+1)
}


Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch in the i-th restaurant. If time ti exceeds the time k that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal fi - (ti - k). Otherwise, the Rabbits get exactly fi units of joy.Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.

The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the characteristics of the i-th restaurant.

In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.

package main

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

func I(i interface{}, delim string) error {
	_, err := fmt.Fscanf(r, "%v"+delim, i)
	return err
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.txt"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n int
	for I(&n, " ") == nil {
		solve(n)
	}
}

func solve(n int) {
	var k, t, f int64
	I(&k, "\n")
	max := int64(-1e10)
	for i := 0; i < n; i++ {
		I(&f, " ")
		I(&t, "\n")
		if t > k {
			o := f - (t - k)
			if max < o {
				max = o
			}
		} else {
			if max < f {
				max = f
			}
		}
	}
	O(max, "\n")
}

package main

import "fmt"

func main() {
  var n, k int
  fmt.Scan(&n, &k)
  var res int
  res = -1e9
  for i := 0; i < n; i++ {
    var f, t int
    fmt.Scan(&f, &t)
    if t <= k {
      if res < f {
        res = f;
      }
    } else {
      if res < f - t + k {
        res = f - t + k
      }
    }
  }
  fmt.Println(res)
}

package main

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

func main() {
    defer s.Flush()

	n, k := s.Next(), s.Next()
	m := math.MinInt32
	for ; n > 0; n-- {
		f, t := s.Next(), s.Next()
		if t > k {
			t -= k
			m = max(m, f - t)
		} else {
			m = max(m, f)
		}
	}
	s.Println(m)
}

func max(a... int) int {
	result := math.MinInt32
	for _, e := range a {
		if result < e {
			result = e
		}
	}
	return result
}

var (
	s *InOut
)

func init() {
	s = NewInOut(os.Stdin, os.Stdout)
}

type InOut struct {
	*bufio.Reader
	*bufio.Writer
}

func NewInOut(r io.Reader, w io.Writer) *InOut {
	return &InOut{bufio.NewReader(r), bufio.NewWriter(w)}
}

// Get Next Integer
func (s *InOut) Next() (r int) {
	b, _ := s.ReadByte()
	p := 1
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

func (s *InOut) NextInt64() (r int64) {
	b, _ := s.ReadByte()
	p := int64(1)
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int64(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

// Get Next Line String
func (s *InOut) NextLine() (r string) {
    b, _ := s.ReadByte()
    for b == '\r' || b == '\n' {
        b, _ = s.ReadByte()
    }
    buf := make([]byte, 0)
    for ; b != '\r' && b != '\n'; b, _ = s.ReadByte() {
        buf = append(buf, b)
    }
    return string(buf)
}

// Get Next String using delimiter whitespace
func (s *InOut) NextStr() (r string) {
    return string(s.NextBytes())
}

// Get Next String using delimiter whitespace
func (s *InOut) NextBytes() (r []byte) {
	b, _ := s.ReadByte()
	for b == '\n' || b == ' ' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n' && b != ' '; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return buf
}

// Print Strings using the suitable way to change type
func (s *InOut) Print(os ...interface{}) {
	for _, o := range os {
		switch o.(type) {
		case byte:
			s.WriteByte(o.(byte))
		case string:
			s.WriteString(o.(string))
		case int:
			s.WriteString(strconv.Itoa(o.(int)))
		case int64:
			s.WriteString(strconv.FormatInt(o.(int64), 10))
		default:
			s.WriteString(fmt.Sprint(o))
		}
	}
}

// Print Strings using the suitable way to change type with new line
func (s *InOut) Println(os ...interface{}) {
	for _, o := range os {
		s.Print(o)
	}
	s.Print("\n")
}

// Print immediately with new line (for debug)
func (s *InOut) PrintlnNow(o interface{}) {
	fmt.Println(o)
}

package main
import (
	"fmt"
)
func main() {
	var n,k,f,t,mj,j int
	fmt.Scan(&n,&k,&f,&t)
	if t>k {
		mj=f-(t-k)
	}else {
		mj=f
	}
	for i:=1; i<n; i++ {
		fmt.Scan(&f,&t)
		if t>k {
			j=f-(t-k)
		}else {
			j=f
		}
		if j>mj{
			mj = j
		}
	}
	fmt.Println(mj)
}

package main

import "fmt"

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

func main() {
    var n,k,f,t int
    fmt.Scan(&n,&k)
    ans := -1000000000
    for i := 0; i < n; i++ {
        fmt.Scan(&f,&t)
        if t > k {
            ans = max(ans,f-(t-k))
        } else {
            ans = max(ans,f)
        }
    }
    fmt.Println(ans)
}

package main

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

func getLine(s *bufio.Scanner) (int,int) {
    s.Scan()
    ab := strings.Fields(s.Text())
    a, _ := strconv.Atoi(ab[0])
    b, _ := strconv.Atoi(ab[1])
    return a,b
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    n, k := getLine(scanner)
    max := math.MinInt32
    for i:=0 ; i<n ; i++ {
        a,b := getLine(scanner)
        c := 0
        if (b > k) {
            c = a -(b-k)
        } else {
            c = a
        }
        if c > max {max = c}
    }
    fmt.Println(max)
}

// https://codeforces.com/problemset/problem/276/A
package main

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

func getTwoNum(text string) (int64, int64) {
	inputs := strings.Split(text, " ")
	input1, _ := strconv.ParseInt(inputs[0], 10, 32)
	input2, _ := strconv.ParseInt(inputs[1], 10, 32)
	return input1, input2
}

func calculateJoy(fi, ti, k int64) (joy int64) {
	if ti > k {
		joy = fi - (ti - k)
	} else {
		joy = fi
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numRest, time := getTwoNum(scanner.Text())
	fun := int64(math.MinInt64)
	var i int64
	for i = 0; i < numRest; i++ {
		scanner.Scan()
		fi, ti := getTwoNum(scanner.Text())
		j := calculateJoy(fi, ti, time)
		if j > fun {
			fun = j
		}
	}
	fmt.Printf("%d", fun)
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var n, k, r int
	r = -INF
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		var f, t int
		fmt.Fscanf(reader, "%d %d\n", &f, &t)
		if t > k {
			r = max(r, f - (t - k))
		} else {
			r = max(r, f)
		}
	}
	fmt.Println(r)
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

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

func main() {
    defer s.Flush()

	n, k := s.Next(), s.Next()
	m := math.MinInt32
	for ; n > 0; n-- {
		f, t := s.Next(), s.Next()
		if t > k {
			t -= k
		}
		m = max(m, f - t)
	}
	s.Println(m)
}

func max(a... int) int {
	result := math.MinInt32
	for _, e := range a {
		if result < e {
			result = e
		}
	}
	return result
}

var (
	s *InOut
)

func init() {
	s = NewInOut(os.Stdin, os.Stdout)
}

type InOut struct {
	*bufio.Reader
	*bufio.Writer
}

func NewInOut(r io.Reader, w io.Writer) *InOut {
	return &InOut{bufio.NewReader(r), bufio.NewWriter(w)}
}

// Get Next Integer
func (s *InOut) Next() (r int) {
	b, _ := s.ReadByte()
	p := 1
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

func (s *InOut) NextInt64() (r int64) {
	b, _ := s.ReadByte()
	p := int64(1)
	for (b < '0' || '9' < b) && b != '-' {
		b, _ = s.ReadByte()
	}
	if b == '-' {
		p = -1
		b, _ = s.ReadByte()
	}
	for '0' <= b && b <= '9' {
		r = 10*r + int64(b-'0')
		b, _ = s.ReadByte()
	}
	return r * p
}

// Get Next Line String
func (s *InOut) NextLine() (r string) {
    b, _ := s.ReadByte()
    for b == '\r' || b == '\n' {
        b, _ = s.ReadByte()
    }
    buf := make([]byte, 0)
    for ; b != '\r' && b != '\n'; b, _ = s.ReadByte() {
        buf = append(buf, b)
    }
    return string(buf)
}

// Get Next String using delimiter whitespace
func (s *InOut) NextStr() (r string) {
    return string(s.NextBytes())
}

// Get Next String using delimiter whitespace
func (s *InOut) NextBytes() (r []byte) {
	b, _ := s.ReadByte()
	for b == '\n' || b == ' ' {
		b, _ = s.ReadByte()
	}
	buf := make([]byte, 0)
	for ; b != '\n' && b != ' '; b, _ = s.ReadByte() {
		buf = append(buf, b)
	}
	return buf
}

// Print Strings using the suitable way to change type
func (s *InOut) Print(os ...interface{}) {
	for _, o := range os {
		switch o.(type) {
		case byte:
			s.WriteByte(o.(byte))
		case string:
			s.WriteString(o.(string))
		case int:
			s.WriteString(strconv.Itoa(o.(int)))
		case int64:
			s.WriteString(strconv.FormatInt(o.(int64), 10))
		default:
			s.WriteString(fmt.Sprint(o))
		}
	}
}

// Print Strings using the suitable way to change type with new line
func (s *InOut) Println(os ...interface{}) {
	for _, o := range os {
		s.Print(o)
	}
	s.Print("\n")
}

// Print immediately with new line (for debug)
func (s *InOut) PrintlnNow(o interface{}) {
	fmt.Println(o)
}

package main
import (
	"fmt"
)
func main() {
	var n,k,f,t,mj,j int
	fmt.Scan(&n,&k,&f,&t)
	if t>k {
		mj=f-t-k
	}else {
		mj=f
	}
	for i:=1; i<n; i++ {
		fmt.Scan(&f,&t)
		if t>k {
			mj=f-t-k
		}else {
			mj=f
		}
		if j>mj{
			mj = j
		}
	}
	fmt.Println(mj)
}

package main

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

func getLine(s *bufio.Scanner) (int,int) {
    s.Scan()
    ab := strings.Fields(s.Text())
    a, _ := strconv.Atoi(ab[0])
    b, _ := strconv.Atoi(ab[1])
    return a,b
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    n, k := getLine(scanner)
    max := 0
    for i:=0 ; i<n ; i++ {
        a,b := getLine(scanner)
        c := 0
        if (b > k) {
            c = a - (b-k)
        } else {
            c = a
        }
        if c > max {max = c}
    }
    fmt.Println(max)
}

package main

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

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var n, k, r int
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		var f, t int
		fmt.Fscanf(reader, "%d %d\n", &f, &t)
		if t > k {
			r = max(r, f - (t - k))
		} else {
			r = max(r, f)
		}
	}
	fmt.Println(r)
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}


Koala Land consists of $$$m$$$ bidirectional roads connecting $$$n$$$ cities. The roads are numbered from $$$1$$$ to $$$m$$$ by order in input. It is guaranteed, that one can reach any city from every other city.Koala starts traveling from city $$$1$$$. Whenever he travels on a road, he writes its number down in his notebook. He doesn't put spaces between the numbers, so they all get concatenated into a single number.Before embarking on his trip, Koala is curious about the resulting number for all possible destinations. For each possible destination, what is the smallest number he could have written for it?Since these numbers may be quite large, print their remainders modulo $$$10^9+7$$$. Please note, that you need to compute the remainder of the minimum possible number, not the minimum possible remainder.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 10^5, n - 1 \le m \le 10^5$$$), the number of cities and the number of roads, respectively. The $$$i$$$-th of the following $$$m$$$ lines contains integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$, $$$x_i \ne y_i$$$), representing a bidirectional road between cities $$$x_i$$$ and $$$y_i$$$. It is guaranteed, that for any pair of cities there is at most one road connecting them, and that one can reach any city from every other city.

Print $$$n - 1$$$ integers, the answer for every city except for the first city. The $$$i$$$-th integer should be equal to the smallest number he could have written for destination $$$i+1$$$. Since this number may be large, output its remainder modulo $$$10^9+7$$$.

package main

import (
    "bufio"
    "fmt"
    "os"
)
const(
    mod int = 1e9 + 7
    N = 1e6
)
type pair struct{
    child, wt int
}
func main() {
    in := bufio.NewReader(os.Stdin)
    var n, m int
    fmt.Fscan(in, &n, &m)
    adj := make([][]pair, N)
    class := make([]int, N)
    value := make([]int, N)
    tot := n
    for i := 1; i <= m; i++ {
        var u, v int
        fmt.Fscan(in, &u, &v)
        var digits []int
        func (num int) {
            for num > 0 {
                digits = append(digits, num % 10)
                num /= 10
            }
        }(i)
        f := func(){
            prev := u
            for j := len(digits) - 1; j >= 1; j-- {
                tot++;
                adj[prev] = append(adj[prev], pair{tot, digits[j],})
                prev = tot
            }
            adj[prev] = append(adj[prev], pair{v, digits[0],})
        }
        f()
        u, v = v, u
        f()

    }
    var level []int
    level = append(level, 1)
    class[1] = 1
    nxt := 1
    for len(level) > 0 {
        var dumlevel []int
        d := make([][]int, 10)
        f := func() {
            for i := 0; i < 10; i++ {
                nxt++
                for _, v := range d[i] {
                    if class[v] > 0 {
                        continue
                    }
                    value[v] = (int(int64(value[v]) * int64(10) % int64(mod)) + i) % mod
                    class[v] = nxt
                    dumlevel = append(dumlevel, v)
                }
                d[i] = make([]int, 0)
            }
        }
        for i, node := range level {
            if i > 0 && class[node] != class[level[i - 1]] {
                f()
            }
            for _, v := range adj[node] {
                if class[v.child] == 0 {
                    value[v.child] = value[node]
                    d[v.wt] = append(d[v.wt], v.child)
                }
            }
        }
        f()
        level = dumlevel
    }
    for i := 2; i <= n; i++ {
        fmt.Println(value[i])
    }
}

package main

import (
    "bufio"
    "fmt"
    "os"
)
const(
    mod int = 1e9 + 7
    N = 1e6
)
type pair struct{
    child, wt int
}
type queue []pair
func(q *queue) push(val pair){
    *q = append(*q, val)
}
func(q *queue) pop(){
    if(len(*q) > 0){
        *q = (*q)[1:]
    }else{
        *q = make(queue, 0)
    }
}
func(q *queue) front() (pair, bool){
    if len(*q) == 0 {
        return pair{0, 0}, false
    }
    return (*q)[0], true
}
func(q *queue) back() (pair, bool){
    if len(*q) == 0 {
        return pair{0, 0}, false
    }
    return (*q)[len(*q) - 1], true
}
func main() {
    in := bufio.NewReader(os.Stdin)
    var n, m int
    fmt.Fscan(in, &n, &m)
    adj := make([][]pair, N)
    dist := make([]int, N)
    value := make([]int, N)
    for i := 0; i < len(dist); i++ {
        dist[i] = 1e9
    }
    tot := n
    for i := 1; i <= m; i++ {
        var u, v int
        fmt.Fscan(in, &u, &v)
        var digits []int
        func (num int) {
            for num > 0 {
                digits = append(digits, num % 10)
                num /= 10
            }
        }(i)
        prev := u
        for j := len(digits) - 1; j >= 1; j-- {
            tot++;
            adj[prev] = append(adj[prev], pair{tot, digits[j],})
            prev = tot
        }
        adj[prev] = append(adj[prev], pair{v, digits[0],})
        u, v = v, u
        prev = u
        for j := len(digits) - 1; j >= 1; j-- {
            tot++;
            adj[prev] = append(adj[prev], pair{tot, digits[j],})
            prev = tot
        }
        adj[prev] = append(adj[prev], pair{v, digits[0],})
    }
    dq := make([]queue, 10)
    dq[0] = append(dq[0], pair{1, 0})
    dist[1] = 0
    empty := false
    for !empty {
        empty = true
        for i := 0; i < 10; i++ {
            if len(dq[i]) > 0 {
                empty = false
                p, _ := dq[i].front()
                node, dis := p.child, p.wt
                dq[i].pop()
                if dis < dist[node] {
                    continue
                }
                for _, v := range adj[node] {
                    if dist[v.child] > dist[node] + 1 {
                        dist[v.child] = dist[node] + 1
                        value[v.child] = (int(int64(value[node]) * int64(10) % int64(mod)) + v.wt) % mod
                        dq[v.wt].push(pair{v.child, dist[v.child]})
                    }
                }
            }
        }
    }
    for i := 2; i <= n; i++ {
        fmt.Println(value[i])
    }
}

package main

import (
    "bufio"
    "fmt"
    "os"
)
const(
    mod int = 1e9 + 7
)
type pair struct{
    child, wt int
}
type queue []int
func(q *queue) push(val int){
    *q = append(*q, val)
}
func(q *queue) pop(){
    if(len(*q) > 0){
        *q = (*q)[1:]
    }else{
        *q = make(queue, 0)
    }
}
func(q *queue) front() (int, bool){
    if len(*q) == 0 {
        return 0, false
    }
    return (*q)[0], true
}
func(q *queue) back() (int, bool){
    if len(*q) == 0 {
        return 0, false
    }
    return (*q)[len(*q) - 1], true
}
func main() {
    in := bufio.NewReader(os.Stdin)
    var n, m int
    fmt.Fscan(in, &n, &m)
    adj := make([][]pair, n + 6 * m + 1)
    dist := make([]int, n + 6 * m + 1)
    for i := 0; i < len(dist); i++ {
        dist[i] = -1
    }
    tot := n
    for i := 1; i <= m; i++ {
        var u, v int
        fmt.Fscan(in, &u, &v)
        var digits []int
        func (num int) {
            for num > 0 {
                digits = append(digits, num % 10)
                num /= 10
            }
        }(i)
        prev := u
        for j := len(digits) - 1; j >= 1; j-- {
            tot++;
            adj[prev] = append(adj[prev], pair{tot, digits[j],})
            prev = tot
        }
        adj[prev] = append(adj[prev], pair{v, digits[0],})
        u, v = v, u
        prev = u
        for j := len(digits) - 1; j >= 1; j-- {
            tot++;
            adj[prev] = append(adj[prev], pair{tot, digits[j],})
            prev = tot
        }
        adj[prev] = append(adj[prev], pair{v, digits[0],})
    }
    dq := make([]queue, 10)
    dq[0] = append(dq[0], 1)
    dist[1] = 0
    empty := false
    for !empty {
        empty = true
        for i := 0; i < 10; i++ {
            if len(dq[i]) > 0 {
                empty = false
                node, _ := dq[i].front()
                dq[i].pop()
                for _, v := range adj[node] {
                    if dist[v.child] == -1 {
                        dist[v.child] = (int(int64(dist[node]) * int64(10) % int64(mod)) + v.wt) % mod
                        dq[v.wt].push(v.child)
                    }
                }
                break;
            }
        }
    }
    for i := 2; i <= n; i++ {
        fmt.Println(dist[i])
    }
}

package main

import (
    "bufio"
    "fmt"
    "os"
)
const(
    mod int = 1e9 + 7
    N = 1e6
)
type pair struct{
    child, wt int
}
type queue []pair
func(q *queue) push(val pair){
    *q = append(*q, val)
}
func(q *queue) pop(){
    if(len(*q) > 0){
        *q = (*q)[1:]
    }else{
        *q = make(queue, 0)
    }
}
func(q *queue) front() (pair, bool){
    if len(*q) == 0 {
        return pair{0, 0}, false
    }
    return (*q)[0], true
}
func(q *queue) back() (pair, bool){
    if len(*q) == 0 {
        return pair{0, 0}, false
    }
    return (*q)[len(*q) - 1], true
}
func main() {
    in := bufio.NewReader(os.Stdin)
    var n, m int
    fmt.Fscan(in, &n, &m)
    adj := make([][]pair, N)
    dist := make([]int, N)
    value := make([]int, N)
    for i := 0; i < len(dist); i++ {
        dist[i] = 1e9
    }
    tot := n
    for i := 1; i <= m; i++ {
        var u, v int
        fmt.Fscan(in, &u, &v)
        var digits []int
        func (num int) {
            for num > 0 {
                digits = append(digits, num % 10)
                num /= 10
            }
        }(i)
        prev := u
        for j := len(digits) - 1; j >= 1; j-- {
            tot++;
            adj[prev] = append(adj[prev], pair{tot, digits[j],})
            prev = tot
        }
        adj[prev] = append(adj[prev], pair{v, digits[0],})
        u, v = v, u
        prev = u
        for j := len(digits) - 1; j >= 1; j-- {
            tot++;
            adj[prev] = append(adj[prev], pair{tot, digits[j],})
            prev = tot
        }
        adj[prev] = append(adj[prev], pair{v, digits[0],})
    }
    dq := make([]queue, 10)
    dq[0] = append(dq[0], pair{1, 0})
    dist[1] = 0
    empty := false
    for !empty {
        empty = true
        for i := 0; i < 10; i++ {
            if len(dq[i]) > 0 {
                empty = false
                p, _ := dq[i].front()
                node, dis := p.child, p.wt
                dq[i].pop()
                for _, v := range adj[node] {
                    if dist[v.child] > dis + 1 {
                        dist[v.child] = dis + 1
                        value[v.child] = (int(int64(value[node]) * int64(10) % int64(mod)) + v.wt) % mod
                        dq[v.wt].push(pair{v.child, dist[v.child]})
                    }
                }
            }
        }
    }
    for i := 2; i <= n; i++ {
        fmt.Println(value[i])
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
const(
	mod int = 1e9 + 7
	N = 1e6
)
type pair struct{
	child, wt int
}
type queue []pair
func(q *queue) push(val pair){
	*q = append(*q, val)
}
func(q *queue) pop(){
	if(len(*q) > 0){
		*q = (*q)[1:]
	}else{
		*q = make(queue, 0)
	}
}
func(q *queue) front() (pair, bool){
	if len(*q) == 0 {
		return pair{0, 0}, false
	}
	return (*q)[0], true
}
func(q *queue) back() (pair, bool){
	if len(*q) == 0 {
		return pair{0, 0}, false
	}
	return (*q)[len(*q) - 1], true
}
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscan(in, &n, &m)
	adj := make([][]pair, N)
	dist := make([]int, N)
	value := make([]int, N)
	for i := 0; i < len(dist); i++ {
		dist[i] = 1e9
	}
	tot := n
	for i := 1; i <= m; i++ {
		var u, v int
		fmt.Fscan(in, &u, &v)
		var digits []int
		func (num int) {
			for num > 0 {
				digits = append(digits, num % 10)
				num /= 10
			}
		}(i)
		prev := u
		for j := len(digits) - 1; j >= 1; j-- {
			tot++;
			adj[prev] = append(adj[prev], pair{tot, digits[j],})
			prev = tot
		}
		adj[prev] = append(adj[prev], pair{v, digits[0],})
		u, v = v, u
		prev = u
		for j := len(digits) - 1; j >= 1; j-- {
			tot++;
			adj[prev] = append(adj[prev], pair{tot, digits[j],})
			prev = tot
		}
		adj[prev] = append(adj[prev], pair{v, digits[0],})
	}
	dq := make([]queue, 10)
	dq[0] = append(dq[0], pair{1, 0})
	dist[1] = 0
	empty := false
	for !empty {
		empty = true
		for i := 0; i < 10; i++ {
			if len(dq[i]) > 0 {
				empty = false
				p, _ := dq[i].front()
				node, dis := p.child, p.wt
				dq[i].pop()
				if dis < dist[node] {
					break
				}
				for _, v := range adj[node] {
					if dist[v.child] > dist[node] + 1 {
						dist[v.child] = dist[node] + 1
						value[v.child] = (int(int64(value[node]) * int64(10) % int64(mod)) + v.wt) % mod
						dq[v.wt].push(pair{v.child, dist[v.child]})
					}
				}
				break;
			}
		}
	}
	for i := 2; i <= n; i++ {
		fmt.Println(value[i])
	}
}


You are given a permutation $$$p$$$ of integers from $$$1$$$ to $$$n$$$, where $$$n$$$ is an even number. Your goal is to sort the permutation. To do so, you can perform zero or more operations of the following type:   take two indices $$$i$$$ and $$$j$$$ such that $$$2 \cdot |i - j| \geq n$$$ and swap $$$p_i$$$ and $$$p_j$$$. There is no need to minimize the number of operations, however you should use no more than $$$5 \cdot n$$$ operations. One can show that it is always possible to do that.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$, $$$n$$$ is even) — the length of the permutation.  The second line contains $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \le p_i \le n$$$) — the given permutation.

On the first line print $$$m$$$ ($$$0 \le m \le 5 \cdot n$$$) — the number of swaps to perform. Each of the following $$$m$$$ lines should contain integers $$$a_i, b_i$$$ ($$$1 \le a_i, b_i \le n$$$, $$$|a_i - b_i| \ge \frac{n}{2}$$$) — the indices that should be swapped in the corresponding swap. Note that there is no need to minimize the number of operations. We can show that an answer always exists.

NoteIn the first example, when one swap elements on positions $$$1$$$ and $$$2$$$, the array becomes sorted.In the second example, pay attention that there is no need to minimize number of swaps.In the third example, after swapping elements on positions $$$1$$$ and $$$5$$$ the array becomes: $$$[4, 5, 3, 1, 2, 6]$$$. After swapping elements on positions $$$2$$$ and $$$5$$$ the array becomes $$$[4, 2, 3, 1, 5, 6]$$$ and finally after swapping elements on positions $$$1$$$ and $$$4$$$ the array becomes sorted: $$$[1, 2, 3, 4, 5, 6]$$$.

package main

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

const (
	mod = uint64(1e9 + 7)
)

type slot struct {
	from uint64
	num  uint64
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int, n)
	aa := make([]int, n)
	pos := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
		a[i]--
		pos[a[i]] = i
		aa[i] = a[i]
	}
	fmt.Fscanf(in, "\n")
	ans := 0
	b := make([][]int, 0)
	for i := 0; i < n/2; i++ {
		if a[i] == i {
			continue
		}
		real := pos[i]
		if real < n/2 {
			ans++
			b = append(b, []int{real + 1, n})
			ans++
			b = append(b, []int{i + 1, n})
			ans++
			b = append(b, []int{real + 1, n})
			a[i], a[real] = a[real], a[i]
			pos[a[real]] = real
			pos[a[i]] = i
		} else {
			ans++
			b = append(b, []int{real + 1, 1})
			ans++
			b = append(b, []int{1, n})
			ans++
			b = append(b, []int{i + 1, n})
			if i != 0 {
				ans++
				b = append(b, []int{1, n})
				ans++
				b = append(b, []int{real + 1, 1})
			}

			a[i], a[real] = a[real], a[i]
			pos[a[real]] = real
			pos[a[i]] = i
		}
	}
	for i := n / 2; i < n; i++ {
		if a[i] == i {
			continue
		}
		real := pos[i]
		if real >= n/2 {
			ans++
			b = append(b, []int{real + 1, 1})
			ans++
			b = append(b, []int{i + 1, 1})
			ans++
			b = append(b, []int{real + 1, 1})
			a[i], a[real] = a[real], a[i]
			pos[a[real]] = real
			pos[a[i]] = i
		} else {
			ans++
			b = append(b, []int{real + 1, n})
			ans++
			b = append(b, []int{1, n})
			ans++
			b = append(b, []int{i + 1, 1})
			if i != n-1 {
				ans++
				b = append(b, []int{n, 1})
				ans++
				b = append(b, []int{n, real + 1})
			}

			a[i], a[real] = a[real], a[i]
			pos[a[real]] = real
			pos[a[i]] = i
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	for i := 0; i < ans; i++ {
		fmt.Fprintf(out, "%d %d\n", b[i][0], b[i][1])
	}
	if false {
		test(aa, b)
	}
	return
}

func test(a []int, b [][]int) []int {
	fmt.Println("debug")
	fmt.Println(a)
	for i := 0; i < len(b); i++ {
		a[b[i][0]-1], a[b[i][1]-1] = a[b[i][1]-1], a[b[i][0]-1]
		fmt.Println(a, b[i])
	}
	fmt.Println("debug end")

	return a
}

// find num of elem >= k
func find(a []int, k int) int {
	if len(a) == 0 {
		return 0
	}
	n := len(a)
	if a[0] > k {
		return n
	}
	if a[n-1] < k {
		return 0
	}
	l := 0
	r := len(a) - 1
	for l < r {
		mid := (l + r) / 2
		if a[mid] < k {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return n - l
}

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

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

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

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

func ok(a, b int) bool {
	if min(abs(a-b), abs(a+b)) <= min(abs(a), abs(b)) && max(abs(a+b), abs(a-b)) >= max(abs(a), abs(b)) {
		return true
	}
	return false
}


Ashish has $$$n$$$ elements arranged in a line. These elements are represented by two integers $$$a_i$$$ — the value of the element and $$$b_i$$$ — the type of the element (there are only two possible types: $$$0$$$ and $$$1$$$). He wants to sort the elements in non-decreasing values of $$$a_i$$$.He can perform the following operation any number of times:  Select any two elements $$$i$$$ and $$$j$$$ such that $$$b_i \ne b_j$$$ and swap them. That is, he can only swap two elements of different types in one move. Tell him if he can sort the elements in non-decreasing values of $$$a_i$$$ after performing any number of operations.

The first line contains one integer $$$t$$$ $$$(1 \le t \le 100)$$$ — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $$$n$$$ $$$(1 \le n \le 500)$$$ — the size of the arrays. The second line contains $$$n$$$ integers $$$a_i$$$ $$$(1 \le a_i \le 10^5)$$$  — the value of the $$$i$$$-th element. The third line containts $$$n$$$ integers $$$b_i$$$ $$$(b_i \in \{0, 1\})$$$  — the type of the $$$i$$$-th element.

For each test case, print "Yes" or "No" (without quotes) depending on whether it is possible to sort elements in non-decreasing order of their value. You may print each letter in any case (upper or lower).

NoteFor the first case: The elements are already in sorted order.For the second case: Ashish may first swap elements at positions $$$1$$$ and $$$2$$$, then swap elements at positions $$$2$$$ and $$$3$$$.For the third case: The elements are already in sorted order.For the fourth case: No swap operations may be performed as there is no pair of elements $$$i$$$ and $$$j$$$ such that $$$b_i \ne b_j$$$. The elements cannot be sorted.For the fifth case: Ashish may swap elements at positions $$$3$$$ and $$$4$$$, then elements at positions $$$1$$$ and $$$2$$$.

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(n, A, B)

		if res {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

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

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

	return i
}

func solve(n int, A []int, B []int) bool {
	cnt := make([]int, 2)

	for i := 0; i < n; i++ {
		cnt[B[i]]++
	}

	if cnt[0] > 0 && cnt[1] > 0 {
		return true
	}
	for i := 1; i < n; i++ {
		if A[i] < A[i-1] {
			return false
		}
	}
	return true
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")
		haveOne := false
		haveZero := false
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &b[i])
			if b[i] == 1 {
				haveOne = true
			} else {
				haveZero = true
			}
		}
		fmt.Fscanf(in, "\n")
		//fmt.Println(a, b)
		if haveOne && haveZero {
			fmt.Fprintf(out, "Yes\n")
		} else {
			ok := true
			for i := 1; i < n; i++ {
				if a[i] < a[i-1] {
					ok = false
					break
				}
			}
			if ok {
				fmt.Fprintf(out, "Yes\n")
			} else {
				fmt.Fprintf(out, "No\n")
			}
		}

	}
	return
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() string {
	var n int
	fmt.Fscan(input, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])
	}
	sum := 0
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &b[i])
		sum += b[i]
	}
	if sum == 0 || sum == n {
		m0 := 0
		m1 := 0
		for i := 0; i < n; i++ {
			if b[i] == 0 {
				if a[i] < m0 {return "NO"}
				m0 = a[i]
			}
			if b[i] == 1 {
				if a[i] < m1 {return "NO"}
				m1 = a[i]
			}
		}
	}

	return "YES"
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for k := 0; k < t; k++ {
		var n int
		groupsCount := 0
		isSorted := true
		fmt.Fscanf(in, "%d\n", &n)
		prev := 0
		for i := 0; i < n; i++ {
			var a int
			if i+1 == n {
				fmt.Fscanf(in, "%d\n", &a)
			} else {
				fmt.Fscanf(in, "%d", &a)
			}
			if prev > a {
				isSorted = false
			}
			prev = a
		}
		for i := 0; i < n; i++ {
			var b int
			if i+1 == n {
				fmt.Fscanf(in, "%d\n", &b)
			} else {
				fmt.Fscanf(in, "%d", &b)
			}
			groupsCount += b
		}
		if isSorted || (!isSorted && groupsCount != n && groupsCount != 0) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

type item struct {
	value int
	ty int
}

//44828 79565 8501
// 0     1    1

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		N := scanner.Text()

		n, _  := strconv.Atoi(N)

		var items []item

		scanner.Scan()

		vs := scanner.Text()

		vsp := strings.Fields(vs)

		scanner.Scan()

		ts := scanner.Text()

		tsp := strings.Fields(ts)

		for k := 0 ; k < n; k ++ {
			v, _  := strconv.Atoi(vsp[k])
			t, _  := strconv.Atoi(tsp[k])

			items = append(items, item{value: v, ty: t})

		}

		ans := solve2(items)

		fmt.Println(ans)
	}
}

func solve2(items []item) string {

	var min item
	for i := 0; i < len(items); i++ {
		min = items[i]

		var minIndex int
		for j := i; j < len(items); j ++ {
			if items[j].value < min.value {
				min = items[j]
				minIndex = j
			}
		}
		if min.value != items[i].value {
			if min.ty == items[i].ty {

				var k int
				for k = 0; k < len(items); k ++ {
					if k != i && k != minIndex {
						if items[k].ty != items[minIndex].ty {
							temp := items[k]
							items[k] = items[i]
							items[i] = temp

							temp = items[i]
							items[i] = min
							items[minIndex] = temp

							break
						}
					}
				}

				if k == len(items) {
					return "NO"
				}

			} else {
				temp := items[i]
				items[i] = min
				items[minIndex] = temp
			}
		}
	}

	return "YES"
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n := nextInt()
		as := nextInts(n)
		bs := nextInts(n)
		if solve(as, bs) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func solve(as, bs []int) bool {
	if sort.IntsAreSorted(as) {
		return true
	}
	found0 := false
	found1 := false
	for i := 0; i < len(bs); i++ {
		if bs[i] == 0 {
			found0 = true
		}
		if bs[i] == 1 {
			found1 = true
		}
		if found0 && found1 {
			return true
		}
	}
	return false
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

/*
URL:
https://codeforces.com/contest/1365/problem/B
*/

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
	A, B []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		A = ReadIntSlice(n)
		B = ReadIntSlice(n)

		solve()
	}
}

func solve() {
	ok := true
	for i := 1; i < n; i++ {
		if A[i-1] > A[i] {
			ok = false
			break
		}
	}

	if ok {
		fmt.Println("Yes")
		return
	}

	memo := make(map[int]bool)
	for _, b := range B {
		memo[b] = true
	}

	if len(memo) == 2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

/*********** 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 (
	"bufio"
	"fmt"
	"os"
)

var nTest, n int
var a [555]int
var b [555]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscanf(in, "%d\n", &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscanf(in, "%d\n", &n)

		// fmt.Println(n)
		for i := 0; i < n-1; i++ {
			fmt.Fscanf(in, "%d ", &a[i])
		}
		fmt.Fscanf(in, "%d\n", &a[n-1])

		for i := 0; i < n-1; i++ {
			fmt.Fscanf(in, "%d ", &b[i])
		}
		fmt.Fscanf(in, "%d\n", &b[n-1])

		// for i := 0; i < n; i++ {
		// 	fmt.Println(a[i])
		// }
		nonDecrease := true
		oneType := true

		for i := 0; i < n-1; i++ {
			if a[i] > a[i+1] {
				nonDecrease = false
			}

			if b[i] != b[i+1] {
				oneType = false
			}

		}

		if oneType && !nonDecrease {
			fmt.Fprintf(out, "No\n")
		} else {
			fmt.Fprintf(out, "Yes\n")
		}
	}
	out.Flush()
}

package main

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

var nTest, n int
var a [555]int
var b [555]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscan(in, &n)

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

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

		nonDecrease := true
		oneType := true

		for i := 0; i < n-1; i++ {
			if a[i] > a[i+1] {
				nonDecrease = false
			}

			if b[i] != b[i+1] {
				oneType = false
			}

		}

		if oneType && !nonDecrease {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
	out.Flush()
}

package main

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

var nTest, n int
var a [555]int
var b [555]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscanf(in, "%d\n", &nTest)

	for i := 0; i < nTest; i++ {
		fmt.Fscanf(in, "%d\n", &n)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &a[i])
		}
		fmt.Fscanf(in, "\n")

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &b[i])
		}
		fmt.Fscanf(in, "\n")

		nonDecrease := true
		oneType := true

		for i := 0; i < n-1; i++ {
			if a[i] > a[i+1] {
				nonDecrease = false
			}

			if b[i] != b[i+1] {
				oneType = false
			}

		}

		if oneType && !nonDecrease {
			fmt.Fprintf(out, "No\n")
		} else {
			fmt.Fprintf(out, "Yes\n")
		}
	}
	out.Flush()
}

package main

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

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

	var t, n, v int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		has := [2]bool{}
		for ; n > 0; n-- {
			Fscan(in, &v)
			has[v] = true
		}
		if sort.IntsAreSorted(a) || has[0] && has[1] {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n, v int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		has := [2]bool{}
		for ; n > 0; n-- {
			Fscan(in, &v)
			has[v] = true
		}
		if sort.IntsAreSorted(a) || has[0] && has[1] {
			Println("Yes")
		} else {
			Println("No")
		}
	}
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int64
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n int
		fmt.Fscanf(in, "%v\n", &n)
		a := make([]int, n, n)
		b := make([]int, n, n)
		for i := 0;i < n;i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fscanf(in, "\n")
		for i := 0;i < n;i++ {
			fmt.Fscan(in, &b[i])
		}
		fmt.Fscanf(in, "\n")
		na := make([]int, 0, n)
		nb := make([]int, 0, n)
		for i := 0; i < n;i++ {
			if b[i] == 1 {
				nb = append(nb, a[i])
			} else {
				na = append(na, a[i])
			}
		}
		sort.Ints(b)
		pizda := false
		if b[0] == b[n - 1] {
			pizda = true
		}

		if pizda && (sort.IntsAreSorted(na) == false || sort.IntsAreSorted(nb) == false) {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
		}
	}
	return
}

package main
import (
        "fmt"
        "os"
        "bufio"
)
func worker(in *bufio.Reader) {
    var n, x, y int
    fmt.Fscan(in, &n)
    ans := true
    fmt.Fscan(in, &x)
    for i := 1; i < n; i++ {
        fmt.Fscan(in, &y)
        if x > y {
            ans = false
        }
        x = y
    }
    x, y = 0, 0
    for i := 0; i < n; i++ {
        var tmp int
        fmt.Fscan(in, &tmp)
        if tmp == 0 {
            x++
        } else {
            y++
        }
    }
    if x * y > 0 || ans {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")
    }
}
func main(){
    var t int
    in := bufio.NewReader(os.Stdin)
    fmt.Fscan(in, &t)
    for ; t > 0; t-- {
        worker(in)
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	scan := func(x ...interface{}) (n int, err error) {
		return fmt.Fscan(in, x...)
	}
	println := func(x ...interface{}) (n int, err error) {
		return fmt.Fprintln(out, x...)
	}

	var t int
	for scan(&t); t > 0; t-- {
		var n int
		scan(&n)
		var a int
		var aPrev int = -1
		isSorted := true
		for i := 0; i < n; i++ {
			scan(&a)
			if a < aPrev {
				isSorted = false
			}
			aPrev = a
		}
		var b int
		hasType0 := false
		hasType1 := false
		for i := 0; i < n; i++ {
			scan(&b)
			if b == 0 {
				hasType0 = true
			} else {
				hasType1 = true
			}
		}
		if (hasType0 && hasType1) || isSorted {
			println("Yes")
		} else {
			println("No")
		}
	}
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		increasing, zeros, ones := true, false, false
		var n int

		fmt.Fscan(in, &n)
		prev := -1
		for i := 0; i < n; i++ {
			var curr int
			fmt.Fscan(in, &curr)
			increasing = increasing && (prev <= curr)
			prev = curr
		}
		for i := 0; i < n; i++ {
			var curr int
			fmt.Fscan(in, &curr)
			if curr == 1 {
				ones = true
			} else {
				zeros = true
			}
		}
		if increasing || (ones && zeros) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	var res string
	for i := 0; i < t; i++ {
		increasing, zeros, ones := true, false, false
		var n int

		fmt.Fscan(in, &n)
		prev := -1
		for i := 0; i < n; i++ {
			var curr int
			fmt.Fscan(in, &curr)
			increasing = increasing && (prev <= curr)
			prev = curr
		}
		for i := 0; i < n; i++ {
			var curr int
			fmt.Fscan(in, &curr)
			if curr == 1 {
				ones = true
			} else {
				zeros = true
			}
		}
		if increasing || (ones && zeros) {
			res += "Yes\n"
		} else {
			res += "No\n"
		}
	}
	fmt.Printf("%v", res)
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	var res string
	for i := 0; i < t; i++ {
		increasing, zeros, ones := true, false, false
		var n int

		fmt.Fscan(in, &n)
		prev := -1
		for i := 0; i < n; i++ {
			var curr int
			fmt.Fscan(in, &curr)
			increasing = increasing && (prev <= curr)
			prev = curr
		}
		for i := 0; i < n; i++ {
			var curr int
			fmt.Fscan(in, &curr)
			if curr == 1 {
				ones = true
			} else {
				zeros = true
			}
		}
		if increasing || (ones && zeros) {
			fmt.Println("Yes")
			res += "Yes\n"
		} else {
			fmt.Println("No")
			res += "No\n"
		}
	}
	//fmt.Printf("%v", res)
}

package main

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

func solve(s1 []string, s2 []string) string {
	a := []int{}
	b := []int{}
	for i := range s1 {
		v, _ := strconv.Atoi(s1[i])
		if s2[i] == "1" {
			b = append(b, v)
		} else {
			a = append(a, v)
		}
	}
	if len(a) > 0 && len(b) > 0 {
		return "Yes"
	}
	if len(a) == 0 {
		a = b
	}
	last := 0
	for i := range a {
		if a[i] < last {
			return "No"
		}
		last = a[i]
	}
	return "Yes"

}

func output(i int, ans string) {
	fmt.Printf("%s\n", ans)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1000000), 1000000)
	var numTests int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &numTests)
	for i := 1; i <= numTests; i++ {
		scanner.Scan()
		scanner.Scan()
		s1 := strings.Split(scanner.Text(), " ")
		scanner.Scan()
		s2 := strings.Split(scanner.Text(), " ")
		output(i, solve(s1, s2))
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1365/problem/B

package main

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

func Solve(n int, a []int, b []int) string {
	s := 0
	for _, elem := range b {
		s += elem
	}
	if s != 0 && s < n {
		return "Yes"
	}
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			return "No"
		}
	}
	return "Yes"
}

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

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

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"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 {
	Int64() int64
	UInt64() uint64
	String() 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) Int64() 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) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		a := make([]int64, n)
		for i := range a {
			a[i] = reader.Int64()
		}
		b := make([]int64, n)
		for i := range b {
			b[i] = reader.Int64()
		}
		writer.Printf("%s\n", sol(a, b))
	}
}

func sol(a, b []int64) string {
	type0 := []int64{}
	type1 := []int64{}
	for i := range a {
		if b[i] == 0 {
			type0 = append(type0, a[i])
		} else {
			type1 = append(type1, a[i])
		}
	}
	if len(type0) > 0 && len(type1) > 0 {
		return "Yes"
	}
	if len(type1) == 0 {
		return isSorted(type0)
	}
	if len(type0) == 0 {
		return isSorted(type1)
	}
	return "Yes"
}

func isSorted(a []int64) string {
	for i := 1; i < len(a); i++ {
		if a[i] < a[i-1] {
			return "No"
		}
	}
	return "Yes"
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		B := readNNums(reader, n)
		res := solve(n, A, B)

		if res {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

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

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

	return i
}

func solve(n int, A []int, B []int) bool {
	cnt := make([]int, 2)

	for i := 0; i < n; i++ {
		cnt[B[i]]++
	}

	if B[0] > 0 && B[1] > 0 {
		return true
	}
	for i := 1; i < n; i++ {
		if A[i] < A[i-1] {
			return false
		}
	}
	return true
}

// https://codeforces.com/contest/x/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var T int

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		fmt.Println(solver())
	}
}

func solver() string {
	var n int
	fmt.Fscan(input, &n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &a[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(input, &b[i])
	}

	m0 := 0
	m1 := 0
	for i := 0; i < n; i++ {
		if b[i] == 0 {
			if a[i] < m0 {return "NO"}
			m0 = a[i]
		}
		if b[i] == 1 {
			if a[i] < m1 {return "NO"}
			m1 = a[i]
		}
	}

	return "YES"
}

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

package main

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

type item struct {
	value int
	ty int
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		N := scanner.Text()

		n, _  := strconv.Atoi(N)

		var items []item

		scanner.Scan()

		vs := scanner.Text()

		vsp := strings.Fields(vs)

		scanner.Scan()

		ts := scanner.Text()

		tsp := strings.Fields(ts)

		for k := 0 ; k < n; k ++ {
			v, _  := strconv.Atoi(vsp[k])
			t, _  := strconv.Atoi(tsp[k])

			items = append(items, item{value: v, ty: t})

		}

		ans := solve2(items)

		fmt.Println(ans)
	}
}

func solve2(items []item) string {

	for i:=1 ; i < len(items); i++ {
		for j := i ; j > 0; j-- {
			if items[j].value < items[j - 1].value {
				if items[j].ty == items[j - 1].ty {
					return "NO"
				}
				temp := items[j - 1]
				items[j - 1] = items[j]
				items[j] = temp
			}
		}
	}

	return "YES"
}

package main

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

type item struct {
	value int
	ty int
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		N := scanner.Text()

		n, _  := strconv.Atoi(N)

		var items []item

		scanner.Scan()

		vs := scanner.Text()

		vsp := strings.Fields(vs)

		scanner.Scan()

		ts := scanner.Text()

		tsp := strings.Fields(ts)

		for k := 0 ; k < n; k ++ {
			v, _  := strconv.Atoi(vsp[k])
			t, _  := strconv.Atoi(tsp[k])

			items = append(items, item{value: v, ty: t})

		}

		ans := solve2(items)

		fmt.Println(ans)
	}
}

func solve2(items []item) string {

	var min item
	for i := 0; i < len(items); i++ {
		min = items[i]

		var minIndex int
		for j := i; j < len(items); j ++ {
			if items[j].value < min.value {
				min = items[j]
				minIndex = j
			}
		}
		if min.value != items[i].value {
			if min.ty == items[i].ty {
				return "NO"
			}
			temp := items[i]
			items[i] = min
			items[minIndex] = temp
		}
	}

	return "YES"
}

package main

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

type item struct {
	value int
	ty int
}

//44828 79565 8501
// 0     1    1

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		N := scanner.Text()

		n, _  := strconv.Atoi(N)

		var items []item

		scanner.Scan()

		vs := scanner.Text()

		vsp := strings.Fields(vs)

		scanner.Scan()

		ts := scanner.Text()

		tsp := strings.Fields(ts)

		for k := 0 ; k < n; k ++ {
			v, _  := strconv.Atoi(vsp[k])
			t, _  := strconv.Atoi(tsp[k])

			items = append(items, item{value: v, ty: t})

		}

		ans := solve2(items)

		fmt.Println(ans)
	}
}

func solve2(items []item) string {

	var min item
	for i := 0; i < len(items); i++ {
		min = items[i]

		var minIndex int
		for j := i; j < len(items); j ++ {
			if items[j].value < min.value {
				min = items[j]
				minIndex = j
			}
		}
		if min.value != items[i].value {
			if min.ty == items[i].ty {

				var k int
				for k = 0; k < len(items); k ++ {
					if k != i && k != minIndex {
						if items[k].ty != items[minIndex].ty {
							temp := items[k]
							items[k] = items[i]
							items[i] = temp

							temp = items[i]
							items[i] = min
							items[minIndex] = temp
						}
					}
				}

				if k == len(items) {
					return "NO"
				}

			} else {
				temp := items[i]
				items[i] = min
				items[minIndex] = temp
			}
		}
	}

	return "YES"
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, now int64
	fmt.Fscanf(in, "%d\n", &t)
	for now < t {
		now++
		var n int
		fmt.Fscanf(in, "%v\n", &n)
		a := make([]int, n, n)
		b := make([]int, n, n)
		for i := 0;i < n;i++ {
			fmt.Fscan(in, &a[i])
		}
		fmt.Fscanf(in, "\n")
		for i := 0;i < n;i++ {
			fmt.Fscan(in, &b[i])
		}
		fmt.Fscanf(in, "\n")
		na := make([]int, 0, n)
		nb := make([]int, 0, n)
		for i := 0; i < n;i++ {
			if b[i] == 1 {
				nb = append(nb, a[i])
			} else {
				na = append(na, a[i])
			}
		}
		if sort.IntsAreSorted(na) && sort.IntsAreSorted(nb) {
			fmt.Fprintln(out, "Yes")
		} else {
			fmt.Fprintln(out, "No")
		}
	}
	return
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"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 {
	Int64() int64
	UInt64() uint64
	String() 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) Int64() 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) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		a := make([]int64, n)
		for i := range a {
			a[i] = reader.Int64()
		}
		b := make([]int64, n)
		for i := range b {
			b[i] = reader.Int64()
		}
		writer.Printf("%s\n", sol(a, b))
	}
}

func sol(a, b []int64) string {
	type0 := []int64{}
	type1 := []int64{}
	for i := range b {
		if b[i] == 0 {
			type0 = append(type0, a[i])
		} else {
			type1 = append(type1, a[i])
		}
	}
	for i := 1; i < len(type0); i++ {
		if type0[i] < type0[i-1] {
			return "No"
		}
	}
	for i := 1; i < len(type1); i++ {
		if type1[i] < type1[i-1] {
			return "No"
		}
	}
	return "Yes"
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"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 {
	Int64() int64
	UInt64() uint64
	String() 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) Int64() 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) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		a := make([]int64, n)
		for i := range a {
			a[i] = reader.Int64()
		}
		b := make([]int64, n)
		for i := range b {
			b[i] = reader.Int64()
		}
		writer.Printf("%s\n", sol(a, b))
	}
}

func sol(a, b []int64) string {
	type0 := []int64{}
	type1 := []int64{}
	for i := range b {
		if b[i] == 0 {
			type0 = append(type0, a[i])
		} else {
			type1 = append(type1, a[i])
		}
	}
	maxSwap := min(int64(len(type0)), int64(len(type1)))
	c0 := int64(0)
	for i := 1; i < len(type0); i++ {
		if type0[i] < type0[i-1] {
			c0++
		}
		if c0 > maxSwap {
			return "No"
		}
	}
	c1 := int64(0)
	for i := 1; i < len(type1); i++ {
		if type1[i] < type1[i-1] {
			c1++
		}
		if c1 > maxSwap {
			return "No"
		}
	}
	return "Yes"
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"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 {
	Int64() int64
	UInt64() uint64
	String() 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) Int64() 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) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		a := make([]int64, n)
		for i := range a {
			a[i] = reader.Int64()
		}
		b := make([]int64, n)
		for i := range b {
			b[i] = reader.Int64()
		}
		writer.Printf("%s\n", sol(a, b))
	}
}

func sol(a, b []int64) string {
	type0 := []int64{}
	type1 := []int64{}
	for i := range b {
		if b[i] == 0 {
			type0 = append(type0, a[i])
		} else {
			type1 = append(type1, a[i])
		}
	}
	c0 := int64(0)
	for i := 1; i < len(type0); i++ {
		if type0[i] < type0[i-1] {
			c0++
		}
	}
	c1 := int64(0)
	for i := 1; i < len(type1); i++ {
		if type1[i] < type1[i-1] {
			c1++
		}
	}
	if c0 == 0 && c1 == 0 {
		return "Yes"
	}
	if c0 == 0 || c1 == 0 {
		return "No"
	}
	return "Yes"
}


Polycarp was dismantling his attic and found an old floppy drive on it. A round disc was inserted into the drive with $$$n$$$ integers written on it.Polycarp wrote the numbers from the disk into the $$$a$$$ array. It turned out that the drive works according to the following algorithm:   the drive takes one positive number $$$x$$$ as input and puts a pointer to the first element of the $$$a$$$ array;  after that, the drive starts rotating the disk, every second moving the pointer to the next element, counting the sum of all the elements that have been under the pointer. Since the disk is round, in the $$$a$$$ array, the last element is again followed by the first one;  as soon as the sum is at least $$$x$$$, the drive will shut down. Polycarp wants to learn more about the operation of the drive, but he has absolutely no free time. So he asked you $$$m$$$ questions. To answer the $$$i$$$-th of them, you need to find how many seconds the drive will work if you give it $$$x_i$$$ as input. Please note that in some cases the drive can work infinitely.For example, if $$$n=3, m=3$$$, $$$a=[1, -3, 4]$$$ and $$$x=[1, 5, 2]$$$, then the answers to the questions are as follows:   the answer to the first query is $$$0$$$ because the drive initially points to the first item and the initial sum is $$$1$$$.  the answer to the second query is $$$6$$$, the drive will spin the disk completely twice and the amount becomes $$$1+(-3)+4+1+(-3)+4+1=5$$$.  the answer to the third query is $$$2$$$, the amount is $$$1+(-3)+4=2$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case consists of two positive integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5$$$) — the number of numbers on the disk and the number of asked questions. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$). The third line of each test case contains $$$m$$$ positive integers $$$x_1, x_2, \ldots, x_m$$$ ($$$1 \le x \le 10^9$$$). It is guaranteed that the sums of $$$n$$$ and $$$m$$$ over all test cases do not exceed $$$2 \cdot 10^5$$$.

Print $$$m$$$ numbers on a separate line for each test case. The $$$i$$$-th number is:    $$$-1$$$ if the drive will run infinitely;  the number of seconds the drive will run, otherwise.

package main

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

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

	var T, n, q int
	var x int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &q)
		s := make([]int64, n+1)
		p := []int{0}
		for i := 1; i <= n; i++ {
			Fscan(in, &x)
			s[i] = s[i-1] + x
			if s[i] > s[p[len(p)-1]] {
				p = append(p, i)
			}
		}
		for ; q > 0; q-- {
			Fscan(in, &x)
			if x <= s[p[len(p)-1]] {
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				Fprint(out, p[i]-1, " ")
			} else if s[n] < 1 {
				Fprint(out, "-1 ")
			} else {
				loop := (x-s[p[len(p)-1]]-1)/s[n] + 1
				x -= loop * s[n]
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				Fprint(out, loop*int64(n)+int64(p[i]-1), " ")
			}
		}
		Fprintln(out)
	}
}
func main() { CF1490G(os.Stdin, os.Stdout) }

package main

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

func ofdisk(_r io.Reader, _w io.Writer) {
	input := bufio.NewReader(_r)
	output := bufio.NewWriter(_w)
	defer output.Flush()

	var a, b, c int
	var x int64

	for fmt.Fscan(input, &a); a > 0; a-- {

		fmt.Fscan(input, &b, &c)
		s := make([]int64, b+1)
		p := []int{0}
		for i := 1; i <= b; i++ {
			fmt.Fscan(input, &x)
			s[i] = s[i-1] + x
			if s[i] > s[p[len(p)-1]] {
				p = append(p, i)
			}
		}
		for ; c > 0; c-- {
			fmt.Fscan(input, &x)
			if x <= s[p[len(p)-1]] {
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				fmt.Fprint(output, p[i]-1, " ")
			} else if s[b] < 1 {
				fmt.Fprint(output, "-1 ")
			} else {
				loop := (x-s[p[len(p)-1]]-1)/s[b] + 1
				x -= loop * s[b]
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				fmt.Fprint(output, loop*int64(b)+int64(p[i]-1), " ")
			}
		}
		fmt.Fprintln(output)
	}
}

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

package main

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

var (
    inn = bufio.NewScanner(os.Stdin)
    out = bufio.NewWriter(os.Stdout)
)

func main() {
    defer out.Flush()
    inn.Buffer([]byte{}, 10000000)
    inn.Split(bufio.ScanWords)
    //prep
    for tt:=rd(); tt>0 ;tt-- {
        n, m:=rd(), rd()
        a:=make([]int64, n)
        for i :=range a {
            a[i]=rdll()
        }
        ps:=make([]int64, n)
        ps[0]=a[0];
        for i:=1; i<n; i++ {
            ps[i]=ps[i-1]+a[i]
        }
        var mx int64
        for _, x := range ps {
            mx=maxll(mx, x)
        }
        type pair struct {
            first int64
            second int
        }
        inc:=make([]pair, 0)
        for i:=0; i<n; i++ {
            if len(inc)==0 || ps[i]>inc[len(inc)-1].first {
                inc=append(inc, pair{ps[i], i})
            }
        }

        for ; m>0; m-- {
            x:=rdll()
            if ps[n-1]<=0 && x>mx {
                Printf("-1 ")
            } else {
                if x<=mx {
                    Printf("%d ", inc[sort.Search(len(inc), func(i int) bool { return inc[i].first>=x })].second)
                } else {
                    back:=ps[n-1];
                    rev:=(x-mx+back-1)/back
                    x-=rev*back
                    Printf("%d ", int64(inc[sort.Search(len(inc), func(i int) bool { return inc[i].first>=x })].second)+int64(n)*rev)
                }
            }
        }
        Println()
    }
}

//-------------------template------------------
func gcd(a, b int) int {
    for b != 0 {
        a, b = b, a%b
    }
    return a
}
func max(a ...int) int {
    mx := a[0]
    for _, x := range a {
        if x > mx {
            mx = x
        }
    }
    return mx
}
func maxll(a ...int64) int64 {
    mx := a[0]
    for _, x := range a {
        if x > mx {
            mx = x
        }
    }
    return mx
}
func min(a ...int) int {
    mn := a[0]
    for _, x := range a {
        if x < mn {
            mn = x
        }
    }
    return mn
}
func minll(a ...int64) int64 {
    mn := a[0]
    for _, x := range a {
        if x < mn {
            mn = x
        }
    }
    return mn
}
func rd() (x int) {
    inn.Scan()
    x, _ = strconv.Atoi(string(inn.Bytes()))
    return x
}
func rdll() (x int64) {
    inn.Scan()
    x, _ = strconv.ParseInt(string(inn.Bytes()), 10, 64)
    return x
}
func rdch() (x byte) {
    inn.Scan()
    return inn.Bytes()[0]
}
func rds() string {
    inn.Scan()
    return string(inn.Bytes())
}

package main

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

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

	var T, n, q int
	var x int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &q)
		s := make([]int64, n+1)
		p := []int{0}
		for i := 1; i <= n; i++ {
			Fscan(in, &x)
			s[i] = s[i-1] + x
			if s[i] > s[p[len(p)-1]] {
				p = append(p, i)
			}
		}
		for ; q > 0; q-- {
			Fscan(in, &x)
			if x <= s[n] {
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				Fprint(out, p[i]-1, " ")
			} else if s[n] < 1 {
				Fprint(out, "-1 ")
			} else {
				loop := (x-s[p[len(p)-1]]-1)/s[n] + 1
				x -= loop * s[n]
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				Fprint(out, loop*int64(n)+int64(p[i]-1), " ")
			}
		}
		Fprintln(out)
	}
}

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

package main

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

func ofd(r io.Reader, w io.Writer) {
	input := bufio.NewReader(r)
	output := bufio.NewWriter(w)
	defer output.Flush()

	var a, b, c int
	var x int64

	for fmt.Fscan(input, &a); a > 0; a-- {

		fmt.Fscan(input, &b, &c)
		s := make([]int64, b+1)
		p := []int{0}
		for i := 1; i <= b; i++ {
			fmt.Fscan(input, &x)
			s[i] = s[i-1] + x
			if s[i] > s[p[len(p)-1]] {
				p = append(p, i)
			}
		}
		for ; c > 0; c-- {
			fmt.Fscan(input, &x)
			if x <= s[p[len(p)-1]] {
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				fmt.Fprint(output, p[i]-1, " ")
			} else if s[b] < 1 {
				fmt.Fprint(output, "-1 ")
			} else {
				loop := (x-s[p[len(p)-1]]-1)/s[b] + 1
				x -= loop * s[b]
				i := sort.Search(len(p), func(i int) bool { return s[p[i]] >= x })
				fmt.Fprint(output, loop*int64(b)+int64(p[i]-1), " ")
			}
		}

		fmt.Println("")

		fmt.Fprintln(output)
	}
}

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