package main

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

// github.com/EndlessCheng/codeforces-go
func CF1444A(in io.Reader, out io.Writer) {
	var T, p, q int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &p, &q)
		if p%q > 0 {
			Fprintln(out, p)
			continue
		}
		ans := int64(0)
		for i := int64(2); i*i <= q; i++ {
			e := 0
			for ; q%i == 0; q /= i {
				e++
			}
			if e > 0 {
				c := 0
				for v := p; v%i == 0; v /= i {
					c++
				}
				v := p
				for ; c >= e; c-- {
					v /= i
				}
				ans = max(ans, v)
			}
		}
		if q > 1 {
			for ; p%q == 0; p /= q {
			}
			ans = max(ans, p)
		}
		Fprintln(out, ans)
	}
}

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

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

package main

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

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

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

func solve() {
	var p, q int64
	scanf("%d %d\n", &p, &q)
	prime := make([]int64, 0)
	t := q
	for i := int64(2); i * i <= q && t > 1; i++ {
		if t % i != 0 {
			continue
		}
		for ; t % i == 0; {
			t /= i
		}
		prime = append(prime, i)
	}
	if t != 1 {
		prime = append(prime, t)
	}
	//fmt.Println("prime = ", prime)
	if p % q != 0 {
		printf("%d\n", p)
		return
	}
	r := p
	for i := 0; i < len(prime); i++ {
		for ; r % prime[i] == 0; {
			r /= prime[i]
		}
	}
	//fmt.Println(prime)
	ans := int64(1)
	for i := 0; i < len(prime); i++ {
		part := p / r
		for ; part % q == 0 && part % prime[i] == 0; {
			part /= prime[i]
		}
		if part % q != 0 {
			if part > ans {
				ans = part
			}
		}
	}
	printf("%d\n", r * ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

	in := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var p0, q uint64
		fmt.Fscan(in, &p0, &q)

		if p0%q != 0 {
			fmt.Fprintf(out, "%d\n", p0)
			continue
		}

		f := factorization(q)

		max := uint64(1)

		for k := range f {
			p := p0

			for ; p%k == 0; {
				x := p / k
				if x%q != 0 {
					if x > max {
						max = x
					}
					break
				}
				p /= k
			}
		}

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

func factorization(a uint64) map[uint64]int {
	res := map[uint64]int{}
	b := uint64(0)
	for ; a > 1 && b != 1; {
		b := findD(a)
		if b > 1 {
			res[b]++
			a /= b
		}
	}

	return res
}

func findD(m uint64) uint64 {
	max := uint64(math.Sqrt(float64(m))) + 1

	for i := uint64(2); i < max; i++ {
		if m%i == 0 {
			return i
		}
	}

	return m
}

package main

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

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

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

func solve() {
	var p, q int64
	scanf("%d %d\n", &p, &q)
	prime := make([]int64, 0)
	t := q
	for i := int64(2); i * i <= q && t > 1; i++ {
		if t % i != 0 {
			continue
		}
		for ; t % i == 0; {
			t /= i
		}
		prime = append(prime, i)
	}
	if t != 1 {
		prime = append(prime, t)
	}
	//fmt.Println("prime = ", prime)
	if p % q != 0 {
		printf("%d\n", p)
		return
	}
	list := make([]int64, len(prime))
	for i := 0; i < len(prime); i++ {
		list[i] = prime[i]
	}
	//fmt.Println("list = ", list)
	for head := 0; head < len(list); head++ {
		/*sort.Slice(list, func(i, j int) bool {
			return list[i] < list[j]
		})*/
		//fmt.Println("el =", list[head])
		if p % list[head] == 0 && (p / list[head]) % q != 0 {
			printf("%d\n", p / list[head])
			return
		}
		for j := head; j < len(list); j++ {
			if p % (list[head] * list[j]) == 0 {
				list = append(list, list[head] * list[j])
			}
		}
	}
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func solve() {
	var p, q int64
	scanf("%d %d\n", &p, &q)
	less := make([]int64, 0)
	more := make([]int64, 0)
	for i := int64(1); i * i <= q; i++ {
		if q % i != 0 {
			continue
		}
		less = append(less, i)
		if i * i != q {
			more = append(more, q / i)
		}
	}
	var ans int64
	ans = 1
	for _, v := range less {
		if (p / v) % q != 0 {
			ans = p / v
			printf("%d\n", ans)
			return
		}
	}
	for i := 0; i < len(more) / 2; i++ {
		more[i], more[len(more) - i - 1] = more[len(more) - i - 1], more[i]
	}
	//fmt.Println(more)
	for _, v := range(more) {
		if (p / v) % q != 0 {
			ans = p / v
			printf("%d\n", ans)
			return
		}
	}
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func solve() {
	var p, q int64
	scanf("%d %d\n", &p, &q)
	prime := make([]int64, 0)
	t := q
	for i := int64(2); i * i <= q && t > 1; i++ {
		if t % i != 0 {
			continue
		}
		for ; t % i == 0; {
			t /= i
		}
		prime = append(prime, i)
	}
	if t != 1 {
		prime = append(prime, t)
	}
	//fmt.Println("prime = ", prime)
	if p % q != 0 {
		printf("%d\n", p)
		return
	}
	r := p
	for i := 0; i < len(prime); i++ {
		for ; r % prime[i] == 0; {
			r /= prime[i]
		}
	}
	//fmt.Println(prime)
	ans := r
	for i := 0; i < len(prime); i++ {
		part := p / r
		for ; part % q == 0 && part % prime[i] == 0; {
			part /= prime[i]
		}
		if part % q != 0 {
			if part > ans {
				ans = part
			}
		}
	}
	printf("%d\n", r * ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

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

func solve() {
	var p, q int64
	scanf("%d %d\n", &p, &q)
	prime := make([]int64, 0)
	t := q
	for i := int64(2); i * i <= q && t > 1; i++ {
		if t % i != 0 {
			continue
		}
		for ; t % i == 0; {
			t /= i
		}
		prime = append(prime, i)
	}
	if t != 1 {
		prime = append(prime, t)
	}
	//fmt.Println("prime = ", prime)
	if p % q != 0 {
		printf("%d\n", p)
		return
	}
	r := p
	deg := make([]int, len(prime))
	for i := 0; i < len(prime); i++ {
		for ; r % prime[i] == 0; {
			r /= prime[i]
			deg[i]++
		}
	}
	ans := r
	for i := 0; i < len(prime); i++ {
		part := p / r
		for ; part % q == 0 && part % prime[i] == 0; {
			part /= prime[i]
		}
		if part % q != 0 {
			if part > ans {
				ans = part
			}
		}
	}
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1444A(in io.Reader, out io.Writer) {
	var T, p, q int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &p, &q)
		if p%q > 0 {
			Fprintln(out, p)
			continue
		}
		ans := int64(0)
		for i := int64(2); i*i <= q; i++ {
			e := 0
			for ; q%i == 0; q /= i {
				e++
			}
			if e > 0 {
				c := 0
				for v := p; v%i == 0; v /= i {
					c++
				}
				v := p
				for ; c >= e; c-- {
					v /= i
				}
				if v > ans {
					ans = v
				}
			}
		}
		if q > 1 && p/q > ans {
			ans = p / q
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	in := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var p0, q uint64
		fmt.Fscan(in, &p0, &q)

		if p0%q != 0 {
			fmt.Fprintf(out, "%d\n", p0)
			continue
		}

		f := factorization(q)
		fi := make([]int, len(f))
		fv := make([]uint64, 0, len(f))

		for k := range f {
			fv = append(fv, k)
		}

		max := uint64(0)

	L:
		for {
			fi[0]++

			for i := 0; i < len(fv); i++ {
				if fi[i] > f[fv[i]] {
					if i == len(fv)-1 {
						break L
					}
					fi[i+1]++
					fi[i] = 0
				} else {
					break
				}
			}

			p := p0
			r := []uint64{}
			for j := 0; j < len(fi); j++ {
				if fi[j] > 0 {
					for w := 0; w < fi[j]; w++ {
						if p%fv[j] != 0 {
							continue L
						}
						p /= fv[j]
						r = append(r, fv[j])
					}
				}
			}

			if p > max && p%q != 0 {
				max = p
			}
		}
		fmt.Fprintf(out, "%d\n", max)
	}
}

func factorization(a uint64) map[uint64]int {
	res := map[uint64]int{}
	b := uint64(0)
	for ; a > 1 && b != 1; {
		b := findD(a)
		if b > 1 {
			res[b]++
			a /= b
		}
	}

	return res
}

func findD(m uint64) uint64 {
	max := uint64(math.Sqrt(float64(m))) + 1

	for i := uint64(2); i < max; i++ {
		if m%i == 0 {
			return i
		}
	}

	return m
}

package main

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

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

	in := bufio.NewReader(os.Stdin)

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

LOOP:
	for i := 0; i < t; i++ {
		var p, q uint64
		fmt.Fscan(in, &p, &q)

		for j := uint64(1); j <= p; {
			x := p / j

			if p%j == 0 && j%q != 0 {
				fmt.Fprintf(out, "%d\n", j)
				continue LOOP
			}

			j = uint64(math.Ceil(float64(p) / float64(x-1)))
		}
	}
}

package main

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

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

	in := bufio.NewReader(os.Stdin)

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

LOOP:
	for i := 0; i < t; i++ {
		var p, q uint64
		fmt.Fscan(in, &p, &q)

		for j := uint64(1); j <= p; {
			x := p / j

			if p%j == 0 && j%q != 0 {
				fmt.Fprintf(out, "%d\n", x)
				continue LOOP
			}

			j = uint64(math.Ceil(float64(p) / float64(x-1)))
		}
	}
}

package main

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

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

	in := bufio.NewReader(os.Stdin)

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

	for i := 0; i < t; i++ {
		var p0, q uint64
		fmt.Fscan(in, &p0, &q)

		if p0%q != 0 {
			fmt.Fprintf(out, "%d\n", p0)
			continue
		}

		f := factorization(q)
		fi := make([]int, len(f))
		fv := make([]uint64, 0, len(f))

		for k := range f {
			fv = append(fv, k)
		}

		max := uint64(1)

	L:
		for {
			fi[0]++

			for i := 0; i < len(fv); i++ {
				if fi[i] > f[fv[i]] {
					if i == len(fv)-1 {
						break L
					}
					fi[i+1]++
					fi[i] = 0
				} else {
					break
				}
			}

			p := p0
			r := []uint64{}
			for j := 0; j < len(fi); j++ {
				if fi[j] > 0 {
					for w := 0; w < fi[j]; w++ {
						if p%fv[j] != 0 {
							continue L
						}
						p /= fv[j]
						r = append(r, fv[j])
					}
				}
			}

			if p > max && p%q != 0 {
				max = p
			}
		}
		fmt.Fprintf(out, "%d\n", max)
	}
}

func factorization(a uint64) map[uint64]int {
	res := map[uint64]int{}
	b := uint64(0)
	for ; a > 1 && b != 1; {
		b := findD(a)
		if b > 1 {
			res[b]++
			a /= b
		}
	}

	return res
}

func findD(m uint64) uint64 {
	max := uint64(math.Sqrt(float64(m))) + 1

	for i := uint64(2); i < max; i++ {
		if m%i == 0 {
			return i
		}
	}

	return m
}


package main

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

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

	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		sum1 := make([]int, n+1)
		for i := range s {
			s[i] -= '0'
			sum1[i+1] = sum1[i] + int(s[i])
		}
		all1 := sum1[n]
		if all1 <= 1 {
			Fprintln(out, 0)
			continue
		}
		ans := n
		for st := 0; st < k; st++ {
			r := n - 1 - st
			r = st + r - r%k
			for ; r >= st; r -= k {
				if s[r] > 0 {
					break
				}
			}
			if r < st {
				continue
			}
			for l := st; l <= r; l += k {
				if s[l] > 0 {
					cnt := [2]int{}
					for ; l <= r; l += k {
						cnt[s[l]]++
						if cnt[0] > cnt[1] {
							break
						}
						if cost := cnt[0] + all1 - cnt[1]; cost < ans {
							ans = cost
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		ones := 0
		for i := range s {
			s[i] -= '0'
			ones += int(s[i])
		}
		if ones <= 1 {
			Fprintln(out, 0)
			continue
		}
		ans := n
		for st := 0; st < k; st++ {
			for i := st; i < n; i += k {
				if s[i] > 0 {
					cnt := [2]int{}
					for ; i < n; i += k {
						cnt[s[i]]++
						if cnt[0] > cnt[1] {
							break
						}
						if cost := cnt[0] + ones - cnt[1]; cost < ans {
							ans = cost
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, k int
	var s []byte
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &k, &s)
		sum1 := make([]int, n+1)
		for i := range s {
			s[i] -= '0'
			sum1[i+1] = sum1[i] + int(s[i])
		}
		all1 := sum1[n]
		if all1 <= 1 {
			Fprintln(out, 0)
			continue
		}
		ans := n
		for st := 0; st < k; st++ {
			for i := st; i < n; i += k {
				if s[i] > 0 {
					cnt := [2]int{}
					for ; i < n; i += k {
						cnt[s[i]]++
						if cnt[0] > cnt[1] {
							break
						}
						if cost := cnt[0] + all1 - cnt[1]; cost < ans {
							ans = cost
						}
					}
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

func CF1353E(_r io.Reader, _w io.Writer) {
    in := bufio.NewReader(_r)
    out := bufio.NewWriter(_w)
    defer out.Flush()
    var t, n, k int
    var s []byte
    for Fscan(in, &t); t > 0; t-- {
        Fscan(in, &n, &k, &s)
        dp := make([]int, 0, n+5)
        dp = dp[:cap(dp)]
        pre := make([]int, 0, n+5)
        pre = pre[:cap(pre)]
        for i:=1; i<=n; i++ {
            pre[i] = pre[i-1]
            if s[i-1] == '1' {
                pre[i]++
            }
        }
        ans := pre[n]
        for i:=n; i>=1; i-- {
            ct := 0
            if pre[i] == pre[i-1] {
                ct++
            }
            mn := 2000000000
            mn = min(mn, pre[n]-pre[i])
            if i+k<=n {
                mn = min(mn, dp[i+k]+pre[i+k-1]-pre[i])
            }
            ct += mn
            ans = min(ans, ct+pre[i-1])
            dp[i] = ct
        }
        Fprintln(out, ans)
    }
}
func main() {
    CF1353E(os.Stdin, os.Stdout)
}


package main

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

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

func gcd(x, y int) int {
	if y > x {
		return gcd(y, x)
	}
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func solve(n int, a []int) string {
	if a[0] != n && a[n-1] != n {
		return "-1"
	}
	var x []string
	for i := n - 1; i >= 0; i-- {
		x = append(x, fmt.Sprint(a[i]))
	}
	return strings.Join(x, " ")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			mx = max(mx, a[i])
		}
		start := 0
		end := n - 1
		if mx == a[start] {
			start++
			for k := end; k > 0; k-- {
				write(f, a[k], " ")
			}
			write(f, a[0], "\n")

		} else if mx == a[end] {
			write(f, a[end])
			end--
			for k := end; k >= 0; k-- {
				write(f, " ", a[k])
			}
			write(f, "\n")
		} else {
			write(f, "-1\n")
		}

	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer){
	defer out.Flush()
	n := 0
	Fscan(in,&n)
	var arr []int
	for i := 0;i < n;i++{
		var next int
		Fscan(in,&next)
		arr = append(arr,next)
	}
	if arr[n - 1] == n{
		Fprintf(out,"%d ",n)
		for i := n - 2;i >= 0;i--{
			Fprintf(out,"%d ",arr[i])
		}
	}else if arr[0] == n{
		Fprintf(out,"%d ",n)
		for i := n - 1;i >= 1;i--{
			Fprintf(out,"%d ",arr[i])
		}
	}else{
		Fprintf(out,"%d",-1)
	}
	Fprintln(out)
}

func main(){
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 0
	Fscan(in,&n)
	for i := 0;i < n;i++{
		solve(in,out)
	}
}

package main

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

func solve(in *bufio.Reader, out *bufio.Writer){
	defer out.Flush()
	n := 0
	Fscan(in,&n)
	var arr []int
	for i := 0;i < n;i++{
		var next int
		Fscan(in,&next)
		arr = append(arr,next)
	}
	if arr[n - 1] == n{
		Printf("%d ",n)
		for i := n - 2;i >= 0;i--{
			Printf("%d ",arr[i])
		}
	}else if arr[0] == n{
		Printf("%d ",n)
		for i := n - 1;i >= 1;i--{
			Printf("%d ",arr[i])
		}
	}else{
		Printf("%d",-1)
	}
	Println()
}

func main(){
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 0
	Fscan(in,&n)
	for i := 0;i < n;i++{
		solve(in,out)
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

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

func isEven(c byte) bool {
	return c == '2' || c == '4' || c == '6' || c == '8'
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		l := scanInt()
		var tmp = make([]int, l)
		for j := range tmp {
			tmp[j] = scanInt()
		}
		if tmp[0] == l {
			fmt.Print(l)
			for k := len(tmp)-1; k > 0; k-- {
				fmt.Print(" ", tmp[k])
			}
			fmt.Println()
		} else if tmp[len(tmp)-1] == l {
			for k := len(tmp)-2; k >= 0; k-- {
				fmt.Print(tmp[k], " ")
			}
			fmt.Println(l)
		} else {
			fmt.Println(-1)
		}
	}
}

package main

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

type DequeItem = int

type Deque struct {
	first    int
	size     int
	capacity int
	values   *[]DequeItem
}

func NewDeque(capacity int) Deque {
	var values = make([]DequeItem, capacity)
	return Deque{
		first:    0,
		size:     0,
		capacity: capacity,
		values:   &values,
	}
}

func (d *Deque) Grow() {
	d.SetCapacity((d.capacity + 1) * 2)
}

func (d *Deque) SetCapacity(newCapacity int) {
	var newValues = make([]DequeItem, newCapacity)
	for i := 0; i < d.size; i += 1 {
		newValues[i] = d.Get(i)
	}
	d.first = 0
	d.capacity = newCapacity
	d.values = &newValues
}

func (d *Deque) Get(i int) DequeItem {
	return (*d.values)[(d.first+i)%d.capacity]
}

func (d *Deque) Left() DequeItem {
	return (*d.values)[d.first]
}

func (d *Deque) Right() DequeItem {
	return d.Get(d.size - 1)
}

func (d *Deque) PushRight(x DequeItem) {
	if d.size == d.capacity {
		d.Grow()
	}
	(*d.values)[(d.first+d.size)%d.capacity] = x
	d.size++
}

func (d *Deque) PushLeft(x DequeItem) {
	if d.size == d.capacity {
		d.Grow()
	}
	d.first = (d.first + d.capacity - 1) % d.capacity
	(*d.values)[d.first] = x
	d.size++
}

func (d *Deque) PopRight() {
	d.size--
}

func (d *Deque) PopLeft() {
	d.first = (d.first + 1) % d.capacity
	d.size--
}

func (d *Deque) ToString() string {
	var s string = ""
	for i := 0; i < d.size; i += 1 {
		s += strconv.Itoa(d.Get(i)) + " "
	}
	return fmt.Sprintf("{ values: [%s] first=%d, size=%d, capacity=%d }", s, d.first, d.size, d.capacity)
}

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

func Solve(d *Deque, sol *Deque) {
	for d.size > 0 {
		var left = d.Left() < sol.Right()
		var right = d.Right() < sol.Left()
		if !left && !right {
			return
		}
		if left && right {
			left = sol.Left() < sol.Right()
		}
		if left {
			sol.PushLeft(d.Left())
			d.PopLeft()
		} else {
			sol.PushRight(d.Right())
			d.PopRight()
		}
	}
}

func main() {
	var ntc, n int
	var arr = make([]int, 2e5+100)
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t += 1 {
		fmt.Fscan(in, &n)
		for i := 0; i < n; i += 1 {
			fmt.Fscan(in, &arr[i])
		}

		var lastAddedIndex = 0
		if arr[n-1] > arr[0] {
			lastAddedIndex = n - 1
		}
		var d = NewDeque(n)
		var sol = NewDeque(n)

		sol.PushRight(arr[lastAddedIndex])
		for i := 0; i < n; i += 1 {
			if i != lastAddedIndex {
				d.PushRight(arr[i])
			}
		}

		Solve(&d, &sol)
		if sol.size < n {
			fmt.Fprintf(out, "-1\n")
		} else {
			for i := 0; i < n; i++ {
				fmt.Fprintf(out, "%d ", sol.Get(i))
			}
			fmt.Fprintln(out)
		}
	}
	out.Flush()
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

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

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

		max := nums[0]
		if nums[len(nums)-1] > max {
			max = nums[len(nums)-1]
		}

		valid := true
		for _, v := range nums {
			if v > max {
				valid = false
				break
			}
		}

		if !valid {
			fmt.Fprintln(out, -1)
		} else {
			if max == nums[0] {
				for i := len(nums) - 1; i >= 1; i-- {
					fmt.Fprintf(out, "%d ", nums[i])
				}
				fmt.Fprintf(out, "%d", max)
			} else {
				fmt.Fprintf(out, "%d ", max)
				for i := len(nums) - 2; i >= 0; i-- {
					fmt.Fprintf(out, "%d ", nums[i])
				}
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

var (
	rr = bufio.NewReader(os.Stdin)
	ww = bufio.NewWriter(os.Stdout)
)

const (
	MaxN int = 2e5
)

var (
	T int
	A [MaxN]int
)

func solve(a []int) []int {
	if a[0] != len(a) && a[len(a)-1] != len(a) {
		return []int{-1}
	}
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
	return a
}

func main() {
	_, _ = fmt.Fscan(rr, &T)
	for iCase := 0; iCase < T; iCase++ {
		var (
			n int
			a = A[:0]
		)

		_, _ = fmt.Fscan(rr, &n)
		for i := 0; i < n; i++ {
			var t int
			_, _ = fmt.Fscan(rr, &t)
			a = append(a, t)
		}

		for _, i := range solve(a) {
			_, _ = fmt.Fprintf(ww, "%d ", i)
		}
		_, _ = fmt.Fprintln(ww)
	}
	_ = ww.Flush()
}

package main

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

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

func min(a,b int) int{
    if a < b {
        return a
    }
    return b
}
func solve() {
    var n int
    scanf("%d\n", &n)
    ar := make([]int, 0)
    var x int
    for i:=0; i<n; i++ {
        scanf("%d", &x)
        ar = append(ar,x)
    }
    scanf("\n")

    if ar[0] == n {
        for i:=1; i+i<n;i++ {
            x := ar[i]
            ar[i] = ar[n-i]
            ar[n-i] = x
        }

        for i:=0; i<n;i++ {
            printf("%d ", ar[i])
        }
        printf("\n")
    }else if ar[n-1] == n {
        for i:=0; i+i<n-2;i++ {
            x := ar[i]
            ar[i] = ar[n-i-2]
            ar[n-i-2] = x
        }
        for i:=0; i<n;i++ {
            printf("%d ", ar[i])
        }
        printf("\n")
    }else {
        printf("-1\n")
    }

}

func main() {

    defer writer.Flush()

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

package main

import (
	"bufio"
	//	"container/heap" for heap.Init()
	"fmt"
	"os"
	"runtime"
)

func check(b bool) {
	if !b {
		_, _, line, _ := runtime.Caller(1)
		fmt.Printf("check failed line %d\n", line)
		os.Exit(-1)
	}
}

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

type IntHeap []int

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

const (
	INIT = -1
)

var (
	n int
	a []int
)

func solve(start, l, r int) bool {
	pl := []int{a[start]}
	pr := []int{a[start]}

	for l <= r {
		if a[l] < pr[len(pr)-1] {
			pl = append(pl, a[l])
			l++
		} else if a[r] < pl[len(pl)-1] {
			pr = append(pr, a[r])
			r--
		} else {
			return false
		}
	}

	for i := len(pl) - 1; i >= 0; i-- {
		fmt.Printf("%d ", pl[i])
	}
	for i := 1; i < len(pr); i++ {
		fmt.Printf("%d ", pr[i])
	}
	fmt.Println()

	return true
}

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

	var tc int
	fmt.Fscan(r, &tc)

	for ; tc > 0; tc-- {

		fmt.Fscan(r, &n)

		a = make([]int, n)

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

		if solve(0, 1, n-1) {
			continue
		}

		if solve(n-1, 0, n-2) {
			continue
		}

		fmt.Println(INIT)

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		mx := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			mx = max(mx, a[i])
		}
		l := list.New()
		start := 0
		end := n - 1
		ok := true
		for start <= end {
			possible := false
			if a[start] > a[end] {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[end])
					end--
					possible = true
				} else {
					front := l.Front().Value.(int)
					if a[end] < front {
						l.PushBack(a[end])
						end--
						possible = true
					}
				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				if start == end {

					if a[start] != mx {
						l.PushBack(a[start])
						break
					}
				}
				ok = false
				break
			}
		}
		if ok {
			for e := l.Front(); e != nil; e = e.Next() {
				write(f, e.Value.(int))
				write(f, " ")
			}
			write(f, "\n")
		} else {
			write(f, "-1\n")
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		l := list.New()
		start := 0
		end := n - 1
		ok := true
		for start <= end {
			possible := false
			if a[start] > a[end] {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[end])
					end--
					possible = true
				} else {
					front := l.Front().Value.(int)
					if a[end] < front {
						l.PushBack(a[end])
						end--
						possible = true
					}
				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				// if start == end {
				// 	l.PushBack(a[start])
				// 	break
				// }
				ok = false
				break
			}
		}
		if ok {
			for e := l.Front(); e != nil; e = e.Next() {
				write(f, e.Value.(int))
				write(f, " ")
			}
			write(f, "\n")
		} else {
			write(f, "-1\n")
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		l := list.New()
		start := 0
		end := n - 1
		ok := true
		for start <= end {
			possible := false
			if a[start] > a[end] {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[end])
					end--
					possible = true
				} else {
					front := l.Front().Value.(int)
					if a[end] < front {
						l.PushBack(a[end])
						end--
						possible = true
					}
				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				if start == end {
					l.PushBack(a[start])
					break
				}
				ok = false
				break
			}
		}
		if ok {
			for e := l.Front(); e != nil; e = e.Next() {
				write(f, e.Value.(int))
				write(f, " ")
			}
			write(f, "\n")
		} else {
			write(f, "-1\n")
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		l := list.New()
		start := 0
		end := n - 1
		ok := true
		for start <= end {
			possible := false
			if a[start] > a[end] {
				if l.Len() == 0 {
					l.PushBack(a[start])
					start++
					possible = true
				} else {
					back := l.Back().Value.(int)
					if a[start] < back {
						l.PushFront(a[start])
						start++
						possible = true
					}

				}
			}
			if !possible {
				if l.Len() == 0 {
					l.PushBack(a[end])
					end--
					possible = true
				} else {
					front := l.Front().Value.(int)
					if a[end] < front {
						l.PushBack(a[end])
						end--
						possible = true
					}
				}
			}
			if !possible {
				ok = false
				break
			}
		}
		if ok {
			for e := l.Front(); e != nil; e = e.Next() {
				write(f, e.Value.(int))
				write(f, " ")
			}
			write(f, "\n")
		} else {
			write(f, "-1\n")
		}

	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

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

func isEven(c byte) bool {
	return c == '2' || c == '4' || c == '6' || c == '8'
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		l := scanInt()
		var tmp = make([]int, l)
		for j := range tmp {
			tmp[j] = scanInt()
		}
		if tmp[0] == l {
			fmt.Print(l)
			for k := 1; k < len(tmp); k++ {
				fmt.Print(" ", tmp[k])
			}
			fmt.Println()
		} else if tmp[len(tmp)-1] == l {
			for k := len(tmp)-2; k >= 0; k-- {
				fmt.Print(tmp[k], " ")
			}
			fmt.Println(l)
		} else {
			fmt.Println(-1)
		}
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func scan() string {
	for sc.Scan() {
		break
	}
	return sc.Text()
}

func scanInt() int {
	i, err := strconv.Atoi(scan())
	if err != nil {
		panic(err)
	}
	return i
}

func scanInt64() int64 {
	i, err := strconv.ParseInt(scan(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

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

func isEven(c byte) bool {
	return c == '2' || c == '4' || c == '6' || c == '8'
}

func main() {
	sc.Split(bufio.ScanWords)
	t := scanInt()
	for i := 0; i < t; i++ {
		l := scanInt()
		var tmp = make([]int, l)
		for j := range tmp {
			tmp[j] = scanInt()
		}
		if tmp[0] == t {
			fmt.Print(t)
			for k := 1; k < len(tmp); k++ {
				fmt.Print(" ", tmp[k])
			}
			fmt.Println()
		} else if tmp[len(tmp)-1] == t {
			for k := len(tmp)-2; k >= 0; k-- {
				fmt.Print(tmp[k], " ")
			}
			fmt.Println(t)
		} else {
			fmt.Println(-1)
		}
	}
}

package main

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

type DequeItem = int

type Deque struct {
	first    int
	size     int
	capacity int
	values   *[]DequeItem
}

func NewDeque(capacity int) Deque {
	var values = make([]DequeItem, capacity)
	return Deque{
		first:    0,
		size:     0,
		capacity: capacity,
		values:   &values,
	}
}

func (d *Deque) Grow() {
	d.SetCapacity((d.capacity + 1) * 2)
}

func (d *Deque) SetCapacity(newCapacity int) {
	var newValues = make([]DequeItem, newCapacity)
	for i := 0; i < d.size; i += 1 {
		newValues[i] = d.Get(i)
	}
	d.first = 0
	d.capacity = newCapacity
	d.values = &newValues
}

func (d *Deque) Get(i int) DequeItem {
	return (*d.values)[(d.first+i)%d.capacity]
}

func (d *Deque) Left() DequeItem {
	return (*d.values)[d.first]
}

func (d *Deque) Right() DequeItem {
	return d.Get(d.size - 1)
}

func (d *Deque) PushRight(x DequeItem) {
	if d.size == d.capacity {
		d.Grow()
	}
	(*d.values)[(d.first+d.size)%d.capacity] = x
	d.size++
}

func (d *Deque) PushLeft(x DequeItem) {
	if d.size == d.capacity {
		d.Grow()
	}
	d.first = (d.first + d.capacity - 1) % d.capacity
	(*d.values)[d.first] = x
	d.size++
}

func (d *Deque) PopRight() {
	d.size--
}

func (d *Deque) PopLeft() {
	d.first = (d.first + 1) % d.capacity
	d.size--
}

func (d *Deque) ToString() string {
	var s string = ""
	for i := 0; i < d.size; i += 1 {
		s += strconv.Itoa(d.Get(i)) + " "
	}
	return fmt.Sprintf("{ values: [%s] first=%d, size=%d, capacity=%d }", s, d.first, d.size, d.capacity)
}

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

func Solve(d *Deque, sol *Deque) {
	for d.size > 0 {
		var left = d.Left() < sol.Right()
		var right = d.Right() < sol.Left()
		if !left && !right {
			return
		}
		if left && right {
			left = d.Left() > d.Right()
		}
		if left {
			sol.PushLeft(d.Left())
			d.PopLeft()
		} else {
			sol.PushRight(d.Right())
			d.PopRight()
		}
	}
}

func main() {
	var ntc, n int
	var arr = make([]int, 2e5+100)
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t += 1 {
		fmt.Fscan(in, &n)
		for i := 0; i < n; i += 1 {
			fmt.Fscan(in, &arr[i])
		}

		var lastAddedIndex = 0
		if arr[n-1] > arr[0] {
			lastAddedIndex = n - 1
		}
		var d = NewDeque(n)
		var sol = NewDeque(n)

		sol.PushRight(arr[lastAddedIndex])
		for i := 0; i < n; i += 1 {
			if i != lastAddedIndex {
				d.PushRight(arr[i])
			}
		}

		Solve(&d, &sol)
		if sol.size < n {
			fmt.Fprintf(out, "-1\n")
		} else {
			for i := 0; i < n; i++ {
				fmt.Fprintf(out, "%d ", sol.Get(i))
			}
			fmt.Fprintln(out)
		}
	}
	out.Flush()
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, x, m := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &x, &m)
		leftMost := x
		rightMost := x
		for i := 0; i < m; i++ {
			l, r := 0, 0
			fmt.Fscanf(in, "%d %d\n", &l, &r)
			if !(l > rightMost || r < leftMost) {
				if l < leftMost {
					leftMost = l
				}
				if r > rightMost {
					rightMost = r
				}
			}
		}
		fmt.Fprintf(out, "%d\n", rightMost-leftMost+1)
	}
	return
}

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

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

package main

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

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

func main() {
	var test int
	fmt.Fscan(in, &test)
	for test > 0 {
		solve()
		test--
	}
	out.Flush()
}

func solve() {
	var n, x, m, l, r int
	fmt.Fscan(in, &n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Fscan(in, &l, &r)
		if r >= lo && l <= hi {
			if l < lo {
				lo = l
			}
			if r > hi {
				hi = r
			}
		}
	}
	fmt.Fprintln(out, hi-lo+1)
}

package main

import "fmt"

func main() {
	var test int
	fmt.Scan(&test)
	for test > 0 {
		solve()
		test--
	}
}

func solve() {
	var n, x, m, l, r int
	fmt.Scan(&n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Scan(&l, &r)
		if r >= lo && l <= hi {
			lo = min(lo, l)
			hi = max(hi, r)
		}
	}
	fmt.Println(hi - lo + 1)
}

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

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

package main

import "fmt"

func main() {
	var test int
	fmt.Scan(&test)
	for test > 0 {
		solve()
		test--
	}
}

func solve() {
	var n, x, m, l, r int
	fmt.Scan(&n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Scan(&l, &r)
		if r >= lo && l <= hi {
			if l < lo {
				lo = l
			}
			if r > hi {
				hi = r
			}
		}
	}
	fmt.Println(hi - lo + 1)
}

package main

import "fmt"

func main() {
	var test int
	fmt.Scanf("%d\n", &test)
	for test > 0 {
		solve()
		test--
	}
}

func solve() {
	var n, x, m, l, r int
	fmt.Scanf("%d %d %d\n", &n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Scanf("%d %d\n", &l, &r)
		if r >= lo && l <= hi {
			lo = min(lo, l)
			hi = max(hi, r)
		}
	}
	fmt.Println(hi - lo + 1)
}

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

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

package main

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

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

func main() {
	var test int
	fmt.Scan(&test)
	for test > 0 {
		solve()
		test--
	}
	out.Flush()
}

func solve() {
	var n, x, m, l, r int
	fmt.Scan(&n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Scan(&l, &r)
		if r >= lo && l <= hi {
			if l < lo {
				lo = l
			}
			if r > hi {
				hi = r
			}
		}
	}
	fmt.Fprintln(out, hi-lo+1)
}

package main

import "fmt"

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

	for test_case := 0; test_case < t; test_case++ {
		var n, x, m int
		fmt.Scan(&n, &x, &m)

		tempL := x
		tempR := x

		for i:=0; i<m; i++ {
			var l, r int
			fmt.Scan(&l, &r)
			if (r>=tempL && tempR >= l) {
				if l < tempL {
					tempL = l
				}
				if r > tempR {
					tempR = r
				}
			}
		}
		fmt.Println(tempR-tempL+1)
	}

}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		line := readNNums(reader, 3)
		n, x, m := line[0], line[1], line[2]
		ops := make([][]int, m)
		for i := 0; i < m; i++ {
			ops[i] = readNNums(reader, 2)
		}
		fmt.Println(solve(n, x, m, ops))
	}
}

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, x int, m int, ops [][]int) int {
	l, r := x, x

	for i := 0; i < m; i++ {
		a, b := ops[i][0], ops[i][1]
		if b < l || a > r {
			continue
		}
		l = min(l, a)
		r = max(r, b)
	}

	return r - l + 1
}

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

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

package main

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

// Range ... Just range
type Range struct {
	l, h uint64
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() uint64 {
		sc.Scan()
		i, _ := strconv.ParseUint(sc.Text(), 10, 64)
		return i
	}

	for t := in(); t > 0; t-- {
		_, x, m := in(), in(), in()

		rng := Range{l: x, h: x}

		for i := m; i > 0; i-- {
			l, h := in(), in()

			if l <= rng.h && h >= rng.l {
				if rng.h < h {
					rng.h = h
				}

				if rng.l > l {
					rng.l = l
				}
			}
		}

		fmt.Println(rng.h - rng.l + 1)
	}
}

package main

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

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, x, m := nextInt64(), nextInt64(), nextInt()
		ops := make([][]int64, m)
		for i := 0; i < m; i++ {
			ops[i] = nextInt64s(2)
		}
		fmt.Println(solve(n, x, ops))
	}
}

func solve(n, x int64, ops [][]int64) int64 {
	l, r := x, x
	for _, op := range ops {
		opl, opr := op[0], op[1]
		if (opl <= l && l <= opr) || (opl <= r && r <= opr) {
			l = Min(l, opl)
			r = Max(r, opr)
		}
	}
	return r - l + 1
}

func Max(xs ...int64) int64 {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

func Min(xs ...int64) int64 {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

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
}

func nextInt64() int64 {
	a, err := strconv.ParseInt(next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return a
}

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

/*
URL:
https://codeforces.com/problemset/problem/1366/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, x, m int
	L, R    []int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, x, m = ReadInt3()
		L, R = []int{}, []int{}
		for j := 0; j < m; j++ {
			l, r := ReadInt2()
			L = append(L, l)
			R = append(R, r)
		}

		solve()
	}
}

func solve() {
	cl, cr := x, x
	for i := 0; i < m; i++ {
		l, r := L[i], R[i]

		if l <= cl && cl <= r || l <= cr && cr <= r {
			cl, cr = Min(cl, l), Max(cr, r)
		}
	}

	fmt.Println(cr - cl + 1)
}

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

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

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

/*********** 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, x, m 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, &x, &m)

		L, R := x, x
		var l, r int
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &l, &r)

			if (l <= R && R <= r) || (l <= L && L <= r) {
				if l < L {
					L = l
				}

				if r > R {
					R = r
				}
			}
		}

		fmt.Fprintln(out, R-L+1)
	}
	out.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1366B(_r io.Reader, out io.Writer) {
	type pair struct{ l, r int }
	in := bufio.NewReader(_r)
	var t, n, x, m, l, r int
	for Fscan(in, &t); t > 0; t-- {
		var a, es []pair
		for Fscan(in, &n, &x, &m); m > 0; m-- {
			Fscan(in, &l, &r)
			if l <= x && x <= r {
				a = append(a, pair{l, r})
				es = append(es, pair{l, 1}, pair{r, -1})
				continue
			}
			for _, p := range a {
				if p.l <= r && p.r >= l {
					a = append(a, pair{l, r})
					es = append(es, pair{l, 1}, pair{r, -1})
					break
				}
			}
		}
		if len(es) == 0 {
			Fprintln(out, 1)
			continue
		}
		sort.Slice(es, func(i, j int) bool { return es[i].l < es[j].l })
		ans := es[len(es)-1].l - es[0].l + 1
		c, st := 0, es[0].l
		for _, e := range es {
			if c == 0 {
				if d := e.l - st - 1; d > 0 {
					ans -= d
				}
			}
			c += e.r
			if c == 0 {
				st = e.l
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, x, m, l, r int
	for Scan(&t); t > 0; t-- {
		Scan(&n, &x, &m)
		ll, rr := x, x
		for ; m > 0; m-- {
			if Scan(&l, &r); l <= rr && r >= ll {
				if l < ll {
					ll = l
				}
				if r > rr {
					rr = r
				}
			}
		}
		Println(rr - ll + 1)
	}
}

// 範囲は飛び飛びにならず、ひとつながりで広がっていくので、左右の端で判断する

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

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

func main(){
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	T := nextInt()
	for i:=0; i<T; i++{
		_, X, M := nextInt(), nextInt(), nextInt()
		left, right := X, X
		for i:=0; i<M; i++{
			L, R := nextInt(),nextInt()
			if L<=left && left<=R{
				left = L
			}
			if L<=right && right <= R{
				right = R
			}
		}
		fmt.Fprintln(out, right - left + 1)
	}
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

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

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

package main

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

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, m, x int
		fmt.Fscanf(in, "%d %d %d\n", &n, &x, &m)
		x--
		mas := make([]int, 2*m)
		for i := 0; i < m; i++ {
			fmt.Fscanf(in, "%d %d\n", &mas[2*i], &mas[2*i+1])
			mas[2*i]--
			mas[2*i+1]--
		}
		var left, right int
		var flag bool
		for i := 0; i < m; i++ {
			if flag {
				if (left <= mas[2*i] && right >= mas[2*i]) || (left <= mas[2*i+1] && right >= mas[2*i+1]) || (mas[2*i] <= left && mas[2*i+1] >= right){
					left = min(left, mas[2*i])
					right = max(right, mas[2*i+1])
				}
				continue
			}
			if x >= mas[2*i] && x <= mas[2*i+1] {
				flag = true
				left = mas[2*i]
				right = mas[2*i+1]
			}
		}
		if !flag{
			fmt.Fprintln(out, 1)
		} else{
			fmt.Fprintln(out, right+1-left)
		}
	}
	return
}

package main

import (
	"fmt"
	"math"
)

const PI = math.Pi
const mod = 1e9 + 7

func main() {
	//rand.Seed(time.Now().UnixNano())
	var t int
	fmt.Scanln(&t)
	for t > 0 {
		t--
		var n,x,m int
		fmt.Scanln(&n,&x,&m)
		l, r := x, x
		for i := 0; i < m ; i++ {
			var q,e int
			fmt.Scanln(&q,&e)
			if (q <= l && e >= l) || (q <= r && e >= r) {
				l = int(math.Min(float64(l),float64(q)))
				r = int(math.Max(float64(r),float64(e)))
			}
			//fmt.Printf("l=%d r=%d\n",l,r)
		}
		fmt.Println(r-l+1)
	}
}

package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for i := 0; i < t; i++ {
		testcase(scanner, writer)
	}
}
func testcase(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	x := getNextInt(scanner)
	m := getNextInt(scanner)
	min := x
	max := x
	for i := 0; i < m; i++ {
		l := getNextInt(scanner)
		r := getNextInt(scanner)
		if r < min {
			continue
		}
		if max < l {
			continue
		}
		min = minint(l, min)
		max = minint(maxint(r, max), n)
	}
	fmt.Fprintln(writer, max-min+1)
}

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

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

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.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 suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.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
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n := sint64()
		x := sint64()
		m := sint64()
		lr := make([][2]int64, m)
		for i := range lr {
			lr[i] = [2]int64{sint64(), sint64()}
		}
		printf("%d\n", sol(n, x, lr))
	}
}

func sol(_, x int64, lr [][2]int64) int64 {
	l, r := x, x
	for i := range lr {
		if lr[i][1] < l || lr[i][0] > r {
			continue
		}
		l = min(l, lr[i][0])
		r = max(r, lr[i][1])
	}
	return r-l+1
}

package main

import "fmt"

func main() {
	var test int
	fmt.Scanf("%d", &test)
	for test > 0 {
		solve()
		test--
	}
}

func solve() {
	var n, x, m, l, r int
	fmt.Scanf("%d %d %d", &n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Scanf("%d %d", &l, &r)
		if r >= lo && l <= hi {
			lo = min(lo, l)
			hi = max(hi, r)
		}
	}
	fmt.Println(hi - lo + 1)
}

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

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

package main

import "fmt"

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

	for test_case := 0; test_case < t; test_case++ {
		var n, x, m int
		fmt.Scan(&n, &x, &m)

		tempL := x
		tempR := x

		for i:=0; i<m; i++ {
			var l, r int
			fmt.Scan(&l, &r)
			if (!(r < tempR || tempL < l)) {
				if l < tempL {
					tempL = l
				}
				if r > tempR {
					tempR = r
				}
			}
		}
		fmt.Println(tempR-tempL+1)
	}

}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n, x, m, l, r int
	for Scan(&t); t > 0; t-- {
		Scan(&n, &x, &m)
		ll, rr := x, x
		for ; m > 0; m-- {
			if Scan(&l, &r); l <= rr && r >= ll {
				if l < ll {
					ll = l
				}
				if r > rr {
					rr = r
				}
			}
			Println(rr - ll + 1)
		}
	}
}

package main

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

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, m, x int
		fmt.Fscanf(in, "%d %d %d\n", &n, &x, &m)
		x--
		mas := make([]int, 2*m)
		for i := 0; i < m; i++ {
			fmt.Fscanf(in, "%d %d\n", &mas[2*i], &mas[2*i+1])
			mas[2*i]--
			mas[2*i+1]--
		}
		var left, right int
		var flag bool
		for i := 0; i < m; i++ {
			if flag {
				if (left <= mas[2*i] && right >= mas[2*i]) || (left <= mas[2*i+1] && right >= mas[2*i+1]) {
					left = min(left, mas[2*i])
					right = max(right, mas[2*i+1])
				}
				continue
			}
			if x >= mas[2*i] && x <= mas[2*i+1] {
				flag = true
				left = mas[2*i]
				right = mas[2*i+1]
			}
		}
		fmt.Fprintln(out, right+1-left)
	}
	return
}

package main

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

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, m, x int
		fmt.Fscanf(in, "%d %d %d\n", &n, &x, &m)
		x--
		mas := make([]int, 2*m)
		for i := 0; i < m; i++ {
			fmt.Fscanf(in, "%d %d\n", &mas[2*i], &mas[2*i+1])
			mas[2*i]--
			mas[2*i+1]--
		}
		var left, right int
		var flag bool
		for i := 0; i < m; i++ {
			if flag {
				if (left <= mas[2*i] && right >= mas[2*i]) || (left <= mas[2*i+1] && right >= mas[2*i+1]) || (mas[2*i] <= left && mas[2*i+1] >= right){
					left = min(left, mas[2*i])
					right = max(right, mas[2*i+1])
				}
				continue
			}
			if x >= mas[2*i] && x <= mas[2*i+1] {
				flag = true
				left = mas[2*i]
				right = mas[2*i+1]
			}
		}
		if !flag{
			fmt.Fprintln(out, 0)
		} else{
			fmt.Fprintln(out, right+1-left)
		}
	}
	return
}

package main

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

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, m, x int
		fmt.Fscanf(in, "%d %d %d\n", &n, &x, &m)
		x--
		mas := make([]int, 2*m)
		for i := 0; i < m; i++ {
			fmt.Fscanf(in, "%d %d\n", &mas[2*i], &mas[2*i+1])
			mas[2*i]--
			mas[2*i+1]--
		}
		var left, right int
		var flag bool
		for i := 0; i < m; i++ {
			if flag {
				if (left <= mas[2*i] && right >= mas[2*i]) || (left <= mas[2*i+1] && right >= mas[2*i+1]) {
					left = min(left, mas[2*i])
					right = max(right, mas[2*i+1])
				}
				continue
			}
			if x >= mas[2*i] && x <= mas[2*i+1] {
				flag = true
				left = mas[2*i]
				right = mas[2*i+1]
			}
		}
		if !flag{
			fmt.Fprintln(out, 0)
		} else{
			fmt.Fprintln(out, right+1-left)
		}
	}
	return
}

package main

import "fmt"

func main() {
	var test int
	fmt.Scan(&test)
	for test > 0 {
		solve()
		test--
	}
}

func solve() {
	var n, x, m, l, r int
	fmt.Scan(&n, &x, &m)
	lo, hi := x, x
	for m > 0 {
		m--
		fmt.Scan(&l, &r)
		if r >= lo && l <= hi {
			if l < lo {
				lo = lo
			}
			if r > hi {
				hi = r
			}
		}
	}
	fmt.Println(hi - lo + 1)
}


package main

import "fmt"
import "math"

func main() {
	var n int
	var s string
	var zero, one int
	fmt.Scan(&n)
	fmt.Scan(&s)
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			zero++
		}
		if s[i] == '1' {
			one++
		}
	}
	fmt.Println(int(math.Abs(float64(zero - one))))
}

package main

import "fmt"

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

func main() {
    var n int
    var s string
    fmt.Scanf("%d\n%s", &n, &s)

    n0 := 0
    n1 := 0
    for i := 0; i < n; i++ {
        if s[i] == '0' {
            n0++
        } else {
            n1++
        }
    }

    fmt.Println(n - 2*min(n0, n1))
}

package main

import (
    "fmt"
    "math"
)

func main(){
    var n int
    var str string
    fmt.Scanf("%d %s", &n, &str)
    zero := 0.0
    one := 0.0

    for _, v := range(str) {
        if v == '1' {
            one += 1
        } else {
            zero += 1
        }
    }

    fmt.Printf("%d\n", int(math.Abs(zero - one)))
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		n   int
		str string
	)
	fmt.Scanf("%d\n%s\n", &n, &str)

	countOnes := 0
	countZeros := 0
	for i := 0; i < len(str); i++ {
		if str[i] == '1' {
			countOnes++
		} else {
			countZeros++
		}
	}

	fmt.Printf("%d\n", int(math.Abs(float64(countOnes-countZeros))))

}

package main

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

func main() {
	var n int
	fmt.Scanf("%d \n", &n)
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	result := strings.Count(s, "1") - strings.Count(s, "0")
	if result < 0 {
		result = -result
	}
	fmt.Print(result)
}

package main

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

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

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

func getLine() string {
	s, _ := reader.ReadString('\n')
	for len(s) > 0 && (s[len(s)-1] == '\n' || s[len(s)-1] == '\r') {
		s = s[:len(s)-1]
	}
	return s
}

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

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

	s := getLine()
	ss := []rune(s)
	var c0 int
	var c1 int
	for i := 0; i < len(ss); i++ {
		if ss[i] == '0' {
			c0++
		} else {
			c1++
		}
	}
	var c int
	if c1 > c0 {
		c = c1 - c0
	} else {
		c = c0 - c1
	}
	printf("%d\n", c)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)

	one := 0
	zero := 0

	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			one++;
		}else{
			zero++;
		}
	}

	fmt.Println(math.Abs(float64(one - zero)))
}

package main

import (
	"fmt"
)

func main() {
	var (
		n   int
		A   [200001]int
		top = -1
		str string
	)
	fmt.Scanf("%d\n%s\n", &n, &str)
	for i := 0; i < n; i++ {
		if top == -1 || A[top] == int(str[i]) {
			top++
			A[top] = int(str[i])
		} else {
			top--
		}
	}
	fmt.Println(top + 1)
}

package main

import (
	"container/list"
	"fmt"
)

func main() {
	var n int
	var line string
	var c, t byte
	fmt.Scan(&n)
	fmt.Scan(&line)

	lst := list.New()
	for i := 0; i < len(line); i++ {
		c = line[i]
		if lst.Len() == 0 {
			lst.PushBack(c)
		} else {
			t = lst.Back().Value.(byte)
			if t != c {
				lst.Remove(lst.Back())
			} else {
				lst.PushBack(c)
			}
		}
	}

	fmt.Println(lst.Len())
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	_, _ = fmt.Scan(&len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	fmt.Printf("%d\n", len - int(math.Min(ones, zeroes)))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	in.ReadString('\n')
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	res := 0
	for _, v := range str[0] {
		if v == '1' {
			res++
		} else {
			res--
		}
	}
	res = int(math.Abs(float64(res)))
	out := bufio.NewWriter(os.Stdout)
	fmt.Fprint(out, res)
	out.Flush()
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var s string

func main() {
	fmt.Fscan(reader, &n, &s)
	var a, b int
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			a++
		} else {
			b++
		}
	}
	fmt.Println(math.Abs(float64(a - b)))
}

package main

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

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

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

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

func main() {
	var T int
	var S string

	scanf("%d \n", &T)
	scanf("%s \n", &S)

	// for strings.Contains(S, "01") || strings.Contains(S, "10") {
	// 	S = strings.ReplaceAll(S, "01", "")
	// 	S = strings.ReplaceAll(S, "10", "")
	// }

	A := strings.Split(S, "")
	M := map[string]float64{}
	for _, v := range A {
		if _, ok := M[v]; !ok {
			M[v] = 1.0
		}else {
			M[v] = M[v] + 1.0
		}
	}

	fmt.Println(math.Abs(M["1"] - M["0"]))
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, cnt int
	var s string
	scan(&n, &s)

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			cnt--
		} else {
			cnt++
		}
	}
	println(Abs(int64(cnt)))

}

func Abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()
	var cnt rune = 0
	for {
		i, ok := in.ReadByte()
		if ok != nil {
			break;
		}
		switch i {
		case '0':
			cnt++
		case '1':
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

// codeforce 556A.go
package main

import (
	"fmt"
	"os"
)

func main() {
	var l int
	var str string
	//fin, _ := os.Open("in.txt")
	//fmt.Fscanf(fin, "%d %s", &l, &str)
	fmt.Fscanf(os.Stdin, "%d %s", &l, &str)
	//fmt.Println(l, str)
	rt := make([]int, l+5)
	j := 0
	var p int
	rt[0] = int(str[0]) - '0'
	for i := 1; i < l; i++ {
		p = int(str[i]) - '0'
		if j < 0 {
			j++
			rt[j] = p
		} else if rt[j]+p == 1 {
			j--
		} else {
			j++
			rt[j] = p
		}
	}
	fmt.Printf("%d\n", j+1)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	var n, cnt0, cnt1 int
	var s string

	scan(&n, &s)

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			cnt0++
		} else {
			cnt1++
		}
	}

	if cnt0 > cnt1 {
		cnt0 = cnt1
	}

	println(len(s) - cnt0*2)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	in.Scan()
	in.Scan()
	var cnt rune = 0
	for _, i := range in.Text() {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()
	var cnt rune = 0
	a := make([]byte, 200100)
	for i, _ := in.Read(a); i > 0; i-- {
		switch a[i - 1] {
		case '0':
			cnt++
		case '1':
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

type Tuple struct{ x, y, z interface{} }

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	in.Scan()
	in.Scan()
	cnt := int32(0)
	for _, i := range in.Text() {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()

	var cnt rune = 0
	a, _, _ := in.ReadLine()
	for _, i := range a {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

type Tuple struct{ x, y, z interface{} }

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	in.Scan()
	in.Scan()
	cnt := 0
	for _, i := range in.Text() {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()
	var cnt rune = 0
	a := make([]byte, 200100)
	for i, _ := in.Read(a); i > 0; i-- {
		if a[i-1] == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

func main() {
	var len int // Size of the string
	var str string // Input string

	_, _ = fmt.Scan(&len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
	bufio.NewWriter(os.Stdout).Flush()
}

package main

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

func main() {
	var len int // Size of the string
	var str string // Input string

	reader := bufio.NewReader(os.Stdin)
	in, _, _ := reader.ReadLine()
	len,_ = strconv.Atoi(string(in))
	in, _, _ = reader.ReadLine()
	str = string(in)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d\n%s", &len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scan(&len)
	fmt.Scan(&str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d %s", &len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

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

func main() {
	var len int // Size of the string
	var str string // Input string

	reader := bufio.NewReader(os.Stdin)
	in, _, _ := reader.ReadLine()
	len,_ = strconv.Atoi(string(in))
	in, _, _ = reader.ReadLine()
	str = string(in)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	print(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	_, _ = fmt.Scan(&len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d", &len)
	fmt.Scanf("%s", &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d\n%s\n", &len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var s string

func main() {
	fmt.Fscan(reader, &n, &s)
	var a, b []int
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			a = append(a, i)
		} else {
			b = append(b, i)
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Sort(sort.IntSlice(b))
	ans := 0
	for i := len(b) - 1; i >= 0; i-- {
		for {
			if len(a) == 0 {
				break
			}
			if b[i] < a[0] {
				a = a[1:len(a)]
			} else {
				a = a[1:len(a)]
				ans++
				break
			}
		}
	}
	fmt.Println(n - 2*ans)
}


package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

func scInit() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	z := 0
	for i := 0; i < n; i++ {
		z = max(z, nextInt())
	}
	fmt.Println(z)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)
	var height = make([]int, n)
	var res = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &height[i])
		if res < height[i] {
			res = height[i]
		}
	}
	fmt.Println(res)
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
    scanner.Scan()
    ans, _ := strconv.Atoi(scanner.Text())
    return ans
}

func main() {
    defer writer.Flush()
    scanner.Split(bufio.ScanWords)

    var n, h1, h2 int
    n = ReadInt32()
    power := 0
    ans := 0
    h1 = 0
    for i := 0; i < n; i++ {
        h2 = ReadInt32()
        power += h1 - h2
        if power < 0 {
            ans += power
            power = 0
        }
        h1 = h2
    }

    fmt.Println(-ans)
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	money, energy := 0, 0
	preHeight, currentHeight := nextInt(), 0
	money += preHeight
	difHeight := 0
			// println(money, energy, preHeight, currentHeight)
	for i := 1; i < n; i++ {
		currentHeight = nextInt()

		if currentHeight <= preHeight {
			energy += preHeight - currentHeight
		} else {
			difHeight = currentHeight - preHeight

			if energy >= difHeight {
				energy = energy - difHeight
			} else {
				money += difHeight - energy
				energy = 0
			}
		}
			// println(money, energy, preHeight, currentHeight)

		preHeight = currentHeight
	}

	println(money)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
	"math/rand"
)

// ******************************** CODE STARTS ********************************

const (
)

var (
)

func solve() {
	n := readInt()
	min := 0
	value := 0
	x0 := 0
	for i := 0; i < n; i++ {
		x1 := readInt()
		value += x0 - x1
		min = minInt(min, value)
		x0 = x1
	}
	if min < 0 {
		printInt(-min)
	} else {
		printInt(0)
	}
	printLine()
}
// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}