You are given a directed graph with $$$n$$$ vertices and $$$m$$$ directed edges without self-loops or multiple edges.Let's denote the $$$k$$$-coloring of a digraph as following: you color each edge in one of $$$k$$$ colors. The $$$k$$$-coloring is good if and only if there no cycle formed by edges of same color.Find a good $$$k$$$-coloring of given digraph with minimum possible $$$k$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 5000$$$, $$$1 \le m \le 5000$$$) — the number of vertices and edges in the digraph, respectively. Next $$$m$$$ lines contain description of edges — one per line. Each edge is a pair of integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — there is directed edge from $$$u$$$ to $$$v$$$ in the graph. It is guaranteed that each ordered pair $$$(u, v)$$$ appears in the list of edges at most once.

In the first line print single integer $$$k$$$ — the number of used colors in a good $$$k$$$-coloring of given graph. In the second line print $$$m$$$ integers $$$c_1, c_2, \dots, c_m$$$ ($$$1 \le c_i \le k$$$), where $$$c_i$$$ is a color of the $$$i$$$-th edge (in order as they are given in the input). If there are multiple answers print any of them (you still have to minimize $$$k$$$).

package main

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

type point struct {
	x, y int
}

var ans int64

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

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	u, v := make([]int, m), make([]int, m)
	degree := make([]int, n)
	edges := make([][]int, n)
	for i := 0; i < n; i++ {
		edges[i] = []int{}
	}
	for i := 0; i < m; i++ {
		f, t := 0, 0
		fmt.Fscanf(in, "%d %d\n", &f, &t)
		f--
		t--
		u[i] = f
		v[i] = t
		degree[t]++
		edges[f] = append(edges[f], i)
	}
	queue := []int{}
	tmp := 0
	for i := 0; i < n; i++ {
		if degree[i] == 0 {
			queue = append(queue, i)
		}
	}
	for len(queue) != 0 {
		cur := queue[0]
		queue = queue[1:]
		tmp++
		for i := 0; i < len(edges[cur]); i++ {
			to := v[edges[cur][i]]
			degree[to]--
			if degree[to] == 0 {
				queue = append(queue, to)
			}
		}
	}
	if tmp == n {
		fmt.Fprintf(out, "1\n")
		for i := 0; i < m; i++ {
			if i == 0 {
				fmt.Fprintf(out, "1")
			} else {
				fmt.Fprintf(out, " 1")
			}
		}
		fmt.Fprintf(out, "\n")
		return
	}

	fmt.Fprintf(out, "2\n")
	for i := 0; i < m; i++ {
		ans := 1
		if u[i] > v[i] {
			ans = 2
		}
		if i == 0 {
			fmt.Fprintf(out, "%d", ans)
		} else {
			fmt.Fprintf(out, " %d", ans)
		}
	}
	fmt.Fprintf(out, "\n")
	return
}

package main

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

var n, m int
var g [][]int
var e []int
var vis []int
var circle bool

func dfs(u int) {
	if circle == true || vis[u] == -1 {
		return
	}
	if vis[u] == 1 {
		circle = true
		return
	}

	for i := 0; i < len(g[u]); i++ {
		v := g[u][i]
		vis[u] = 1
		dfs(v)
		vis[u] = 0
	}

	vis[u] = -1
}

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d%d\n", &n, &m)
	g = make([][]int, n)
	e = make([]int, m)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscanf(reader, "%d%d\n", &u, &v)
		u--
		v--
		g[u] = append(g[u], v)
		if u < v {
			e[i] = 1
		} else {
			e[i] = 2
		}
	}

	circle = false
	vis = make([]int, n)
	for i := 0; i < n; i++ {
		if vis[i] == -1 {
			continue
		}
		dfs(i)
		if circle == true {
			break
		}
	}
	if circle == true {
		fmt.Println(2)
		for i := 0; i < m; i++ {
			fmt.Print(e[i], " ")
		}
	} else {
		fmt.Println(1)
		for i := 0; i < m; i++ {
			fmt.Print(1, " ")
		}
	}
}

package main

import "fmt"

type edge struct {
	u, v int
}

var G [][]int
var E []edge
var vis []int
var del []int

func dfs(u, col int) {
	vis[u] = 1
	for _, id := range G[u] {
		v := E[id].v
		if vis[v] != 1 {
			del[id] = col
		}
		if vis[v] == 0 {
			dfs(v, col)
		}
	}
	vis[u] = 2
}

func main() {
	var n, m, u, v int
	_, _ = fmt.Scan(&n, &m)

	E = make([]edge, m)
	del = make([]int, m)
	vis = make([]int, n+1)

	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&u, &v)
		E[i] = edge{u, v}
	}

	iter := 0
	for ccc := 1; ccc <= n+m; ccc++ {
		delcount := 0
		for i := 0; i < m; i++ {
			if del[i] != 0 {
				delcount++
			}
		}
		if delcount >= m {
			break
		}
		G = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			vis[i] = 0
			G[i] = make([]int, 0)
		}
		for i := 0; i < m; i++ {
			if del[i] != 0 {
				continue
			}
			u := E[i].u
			G[u] = append(G[u], i)
		}

		for i := 1; i <= n; i++ {
			if vis[i] == 0 {
				dfs(i, ccc)
			}
		}
		iter++
	}

	fmt.Println(iter)
	for i := 0; i < m; i++ {
		fmt.Printf("%d ", del[i])
	}
}

package main

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

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

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][][2]int, n)
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], [2]int{w, i})
	}

	hasCycle := false
	ans := make([]interface{}, m)
	vis := make([]int8, n)
	var f func(int)
	f = func(v int) {
		vis[v] = 1
		for _, e := range g[v] {
			w, i := e[0], e[1]
			if b := vis[w]; b == 0 {
				f(w)
				ans[i] = 1
			} else if b == 2 {
				ans[i] = 1
			} else {
				hasCycle = true
				ans[i] = 2
			}
		}
		vis[v] = 2
	}
	for i, b := range vis {
		if b == 0 {
			f(i)
		}
	}
	if hasCycle {
		Fprintln(out, 2)
	} else {
		Fprintln(out, 1)
	}
	Fprint(out, ans...)
}

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

package main

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

var n, m int
var g [][]int
var e []int
var vis []bool
var circle bool

func dfs(u int) {
	if vis[u] == true {
		circle = true
		return
	}
	vis[u] = true
	for i := 0; i < len(g[u]); i++ {
		v := g[u][i]
		dfs(v)
	}
}

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d%d\n", &n, &m)
	g = make([][]int, n)
	e = make([]int, m)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscanf(reader, "%d%d\n", &u, &v)
		u--
		v--
		g[u] = append(g[u], v)
		if u < v {
			e[i] = 1
		} else {
			e[i] = 2
		}
	}

	circle = false
	for i := 0; i < n; i++ {
		vis = make([]bool, n)
		dfs(i)
		if circle == true {
			break
		}
	}
	if circle == true {
		for i := 0; i < m; i++ {
			fmt.Print(e[i], " ")
		}
	} else {
		for i := 0; i < m; i++ {
			fmt.Print(1, " ")
		}
	}
}

package main

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

var n, m int
var g [][]int
var e []int
var vis []bool
var circle bool

func dfs(u int) {
	if vis[u] == true {
		circle = true
		return
	}
	vis[u] = true
	for i := 0; i < len(g[u]); i++ {
		v := g[u][i]
		dfs(v)
	}
}

func main() {
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)
	fmt.Fscanf(reader, "%d%d\n", &n, &m)
	g = make([][]int, n)
	e = make([]int, m)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscanf(reader, "%d%d\n", &u, &v)
		u--
		v--
		g[u] = append(g[u], v)
		if u < v {
			e[i] = 1
		} else {
			e[i] = 2
		}
	}

	circle = false
	for i := 0; i < n; i++ {
		vis = make([]bool, n)
		dfs(i)
		if circle == true {
			break
		}
	}
	if circle == true {
		fmt.Println(2)
		for i := 0; i < m; i++ {
			fmt.Print(e[i], " ")
		}
	} else {
		fmt.Println(1)
		for i := 0; i < m; i++ {
			fmt.Print(1, " ")
		}
	}
}

package main

import "fmt"

type edge struct {
	u, v int
}

var G [][]int
var E []edge
var vis []int
var del []int

func dfs(u, col int) {
	vis[u] = 1
	for _, id := range G[u] {
		v := E[id].v
		if vis[v] != 1 {
			del[id] = col
		}
		if vis[v] == 0 {
			dfs(v, col)
		}
	}
	vis[u] = 2
}

func main() {
	var n, m, u, v int
	_, _ = fmt.Scanf("%d%d", &n, &m)

	E = make([]edge, m)
	del = make([]int, m)
	vis = make([]int, n+1)

	for i := 0; i < m; i++ {
		_, _ = fmt.Scanf("%d%d", &u, &v)
		E[i] = edge{u, v}
	}

	delcount := 0
	for ccc := 1; ccc <= n+m; ccc++ {
		if delcount >= m {
			break
		}
		G = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			vis[i] = 0
			G[i] = make([]int, 0)
		}
		for i := 0; i < m; i++ {
			if del[i] != 0 {
				continue
			}
			u := E[i].u
			G[u] = append(G[u], i)
		}

		for i := 1; i <= n; i++ {
			if vis[i] == 0 {
				dfs(i, ccc)
			}
		}
		delcount++
	}

	fmt.Println(delcount)
	for i := 0; i < m; i++ {
		fmt.Printf("%d ", del[i])
	}
}

package main

import "fmt"

type edge struct {
	u, v int
}

var G [][]int
var E []edge
var vis []int
var del []int

func dfs(u, col int) {
	vis[u] = 1
	for _, id := range G[u] {
		v := E[id].v
		if vis[v] != 1 {
			del[id] = col
		}
		if vis[v] == 0 {
			dfs(v, col)
		}
	}
	vis[u] = 2
}

func main() {
	var n, m, u, v int
	_, _ = fmt.Scan(&n, &m)

	E = make([]edge, m)
	del = make([]int, m)
	vis = make([]int, n+1)

	for i := 0; i < m; i++ {
		_, _ = fmt.Scan(&u, &v)
		E[i] = edge{u, v}
	}

	delcount := 0
	for ccc := 1; ccc <= n+m; ccc++ {
		if delcount >= m {
			break
		}
		G = make([][]int, n+1)
		for i := 1; i <= n; i++ {
			vis[i] = 0
			G[i] = make([]int, 0)
		}
		for i := 0; i < m; i++ {
			if del[i] != 0 {
				continue
			}
			u := E[i].u
			G[u] = append(G[u], i)
		}

		for i := 1; i <= n; i++ {
			if vis[i] == 0 {
				dfs(i, ccc)
			}
		}
		delcount++
	}

	fmt.Println(delcount)
	for i := 0; i < m; i++ {
		fmt.Printf("%d ", del[i])
	}
}

package main

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

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

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	rg := make([][][2]int, n)
	for i := 0; i < m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		rg[w] = append(rg[w], [2]int{v, i})
	}

	vs := make([]int, 0, n)
	used := make([]bool, n)
	var dfs func(int)
	dfs = func(v int) {
		used[v] = true
		for _, w := range g[v] {
			if !used[w] {
				dfs(w)
			}
		}
		vs = append(vs, v)
	}
	for v := range g {
		if !used[v] {
			dfs(v)
		}
	}

	hasCycle := false
	ans := make([]interface{}, m)
	for i := range ans {
		ans[i] = 1
	}
	used = make([]bool, n)
	var es []int
	var rdfs func(int)
	rdfs = func(v int) {
		used[v] = true
		for _, e := range rg[v] {
			if w := e[0]; !used[w] {
				es = append(es, e[1])
				rdfs(w)
			}
		}
	}
	for i := len(vs) - 1; i >= 0; i-- {
		if v := vs[i]; !used[v] {
			es = []int{}
			rdfs(v)
			if len(es) > 1 {
				hasCycle = true
				for _, j := range es {
					ans[j] = 2
				}
			}
		}
	}

	if hasCycle {
		Fprintln(out, 2)
	} else {
		Fprintln(out, 1)
	}
	Fprint(out, ans...)
}

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


Roy and Biv have a set of n points on the infinite number line.Each point has one of 3 colors: red, green, or blue.Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it connects.They want to do this in such a way that they will both see that all the points are connected (either directly or indirectly).However, there is a catch: Roy cannot see the color red and Biv cannot see the color blue.Therefore, they have to choose the edges in such a way that if all the red points are removed, the remaining blue and green points are connected (and similarly, if all the blue points are removed, the remaining red and green points are connected).Help them compute the minimum cost way to choose edges to satisfy the above constraints.

The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points. The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes green, and 'B' means blue. The positions will be in strictly increasing order.

Print a single integer, the minimum cost way to solve the problem.

NoteIn the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}

func readString() string {
	if !in.Scan() {
		panic(in.Err())
	}
	return in.Text()
}

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	var lastG, ans int64
	var r, b []int64
	for i := int64(0); i < n; i++ {
		p := readInt()
		switch readString() {
		case "G":
			if lastG == 0 {
				if len(r) > 0 {
					ans += p - r[0]
				}
				if len(b) > 0 {
					ans += p - b[0]
				}
			} else {
				ans += p - lastG
				maxAns := ans + p - lastG
				if len(r) > 0 {
					ma := r[0] - lastG
					for i := range r[1:] {
						if cur := r[i+1] - r[i]; ma < cur {
							ma = cur
						}
					}
					if cur := p - r[len(r)-1]; ma < cur {
						ma = cur
					}
					ans += p - lastG - ma
				}
				if len(b) > 0 {
					ma := b[0] - lastG
					for i := range b[1:] {
						if cur := b[i+1] - b[i]; ma < cur {
							ma = cur
						}
					}
					if cur := p - b[len(b)-1]; ma < cur {
						ma = cur
					}
					ans += p - lastG - ma
				}
				if ans > maxAns {
					ans = maxAns
				}
			}
			lastG = p
			r = r[:0]
			b = b[:0]
		case "R":
			r = append(r, p)
		case "B":
			b = append(b, p)
		default:
			panic("rgb")
		}
	}
	if len(r) > 0 {
		if lastG == 0 {
			ans += r[len(r)-1] - r[0]
		} else {
			ans += r[len(r)-1] - lastG
		}
	}
	if len(b) > 0 {
		if lastG == 0 {
			ans += b[len(b)-1] - b[0]
		} else {
			ans += b[len(b)-1] - lastG
		}
	}
	fmt.Println(ans)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}

func readString() string {
	if !in.Scan() {
		panic(in.Err())
	}
	return in.Text()
}

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	var lastG, ans int64
	var r, b []int64
	for i := int64(0); i < n; i++ {
		p := readInt()
		switch readString() {
		case "G":
			if lastG == 0 {
				if len(r) > 0 {
					ans += p - r[0]
				}
				if len(b) > 0 {
					ans += p - b[0]
				}
			} else {
				ans += p - lastG
				if len(r) > 0 {
					ma := r[0] - lastG
					for i := range r[1:] {
						if cur := r[i+1] - r[i]; ma < cur {
							ma = cur
						}
					}
					if cur := p - r[len(r)-1]; ma < cur {
						ma = cur
					}
					ans += p - lastG - ma
				}
				if len(b) > 0 {
					ma := b[0] - lastG
					for i := range b[1:] {
						if cur := b[i+1] - b[i]; ma < cur {
							ma = cur
						}
					}
					if cur := p - b[len(b)-1]; ma < cur {
						ma = cur
					}
					ans += p - lastG - ma
				}
			}
			lastG = p
			r = r[:0]
			b = b[:0]
		case "R":
			r = append(r, p)
		case "B":
			b = append(b, p)
		default:
			panic("rgb")
		}
	}
	if len(r) > 0 {
		if lastG == 0 {
			ans += r[len(r)-1] - r[0]
		} else {
			ans += r[len(r)-1] - lastG
		}
	}
	if len(b) > 0 {
		if lastG == 0 {
			ans += b[len(b)-1] - b[0]
		} else {
			ans += b[len(b)-1] - lastG
		}
	}
	fmt.Println(ans)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}

func readString() string {
	if !in.Scan() {
		panic(in.Err())
	}
	return in.Text()
}

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	var lastG, ans int64
	var r, b []int64
	for i := int64(0); i < n; i++ {
		p := readInt()
		switch readString() {
		case "G":
			if lastG == 0 {
				if len(r) > 0 {
					ans += p - r[0]
				}
				if len(b) > 0 {
					ans += p - b[0]
				}
				lastG = p
			} else {
				ans += p - lastG
				if len(r) > 0 {
					ma := r[0] - lastG
					for i := range r[1:] {
						if cur := r[i+1] - r[i]; ma < cur {
							ma = cur
						}
					}
					if cur := p - r[len(r)-1]; ma < cur {
						ma = cur
					}
					ans += p - lastG - ma
				}
				if len(b) > 0 {
					ma := b[0] - lastG
					for i := range b[1:] {
						if cur := b[i+1] - b[i]; ma < cur {
							ma = cur
						}
					}
					if cur := p - b[len(b)-1]; ma < cur {
						ma = cur
					}
					ans += p - lastG - ma
				}
			}
			r = r[:0]
			b = b[:0]
		case "R":
			r = append(r, p)
		case "B":
			b = append(b, p)
		default:
			panic("rgb")
		}
	}
	if len(r) > 0 {
		if lastG == 0 {
			ans += r[len(r)-1] - r[0]
		} else {
			ans += r[len(r)-1] - lastG
		}
	}
	if len(b) > 0 {
		if lastG == 0 {
			ans += b[len(b)-1] - b[0]
		} else {
			ans += b[len(b)-1] - lastG
		}
	}
	fmt.Println(ans)
}


Let's define the value of the permutation $$$p$$$ of $$$n$$$ integers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once) as follows:  initially, an integer variable $$$x$$$ is equal to $$$0$$$;  if $$$x < p_1$$$, then add $$$p_1$$$ to $$$x$$$ (set $$$x = x + p_1$$$), otherwise assign $$$0$$$ to $$$x$$$;  if $$$x < p_2$$$, then add $$$p_2$$$ to $$$x$$$ (set $$$x = x + p_2$$$), otherwise assign $$$0$$$ to $$$x$$$;  ...  if $$$x < p_n$$$, then add $$$p_n$$$ to $$$x$$$ (set $$$x = x + p_n$$$), otherwise assign $$$0$$$ to $$$x$$$;  the value of the permutation is $$$x$$$ at the end of this process. For example, for $$$p = [4, 5, 1, 2, 3, 6]$$$, the value of $$$x$$$ changes as follows: $$$0, 4, 9, 0, 2, 5, 11$$$, so the value of the permutation is $$$11$$$.You are given an integer $$$n$$$. Find a permutation $$$p$$$ of size $$$n$$$ with the maximum possible value among all permutations of size $$$n$$$. If there are several such permutations, you can print any of them.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 97$$$) — the number of test cases. The only line of each test case contains one integer $$$n$$$ ($$$4 \le n \le 100$$$).

For each test case, print $$$n$$$ integers — the permutation $$$p$$$ of size $$$n$$$ with the maximum possible value among all permutations of size $$$n$$$.

package main

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

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

func (in *CF1728B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1728B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1728B
Date: 9/10/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1728/B
Problem: CF1728B
**/
func (in *CF1728B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n == 4 {
			fmt.Print("2 1 3 4")
		} else if n == 5 {
			arr := make([]int, n)
			arr[n-1] = n
			arr[n-2] = n - 1
			arr[n-3] = 3
			arr[n-4] = 2
			arr[n-5] = 1
			for i := 0; i < n; i++ {
				fmt.Print(arr[i], " ")
			}
		} else {
			arr := make([]int, n)
			arr[n-1] = n
			arr[n-2] = n - 1
			arr[n-3] = 1
			arr[n-4] = 3
			arr[n-5] = 2
			for i, j := 4, 0; i < n-1; i++ {
				arr[j] = i
				j++
			}
			for i := 0; i < n; i++ {
				fmt.Print(arr[i], " ")
			}
		}
		fmt.Println()
	}

}

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

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

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		if n%2 == 0 {

			for i := n - 2; i >= 1; i-- {
				fmt.Printf("%d ", i)
			}
			fmt.Printf("%d %d", n-1, n)
		} else {
			fmt.Print("1 ")
			for i := n - 2; i > 1; i-- {
				fmt.Printf("%d ", i)
			}
			fmt.Printf("%d %d", n-1, n)
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
	CF1728B()
}
func CF1728B() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := 1; j <= n; j++ {
			if n&1 == 0 {
				if j < n-1 {
					if j&1 == 0 {
						fmt.Print(j - 1)
					} else {
						fmt.Print(j + 1)
					}
				} else {
					fmt.Print(j)
				}
			} else {
				if j == 1 || j >= n-1 {
					fmt.Print(j)
				} else {
					if j&1 == 0 {
						fmt.Print(j + 1)
					} else {
						fmt.Print(j - 1)
					}
				}
			}
			if j == n {
				fmt.Println("")
			} else {
				fmt.Print(" ")
			}
		}
	}
}
func CF1728A() {
	var t int
	fmt.Scan(&t)
	for t != 0 {
		t--
		var n int
		fmt.Scan(&n)
		var m int
		var mi int
		var i int = 1
		for n != 0 {
			n--
			var ai int
			fmt.Scan(&ai)
			if ai > m {
				m = ai
				mi = i
			}
			i++
		}
		fmt.Println(mi)
	}
}

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)

		aa := make([]int, n)
		for i := 0; i < n; i++ {
			aa[i] = i + 1
		}
		var x int
		for i := 0; i < n-2; i++ {
			if x < aa[i] {
				x += aa[i]
			} else {
				x = 0
			}
		}

		if x > 0 {
			aa[0], aa[n-3] = n-2, 1
		}
		x = 0
		for _, v := range aa {
			if x < v {
				x += v
			} else {
				x = 0
			}
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

func value(arr []int) int {
	x := 0
	for _, z := range arr {
		if x < z {
			x += z
		} else {
			x = 0
		}
	}
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	nrTests, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < nrTests; i++ {
		scanner.Scan()
		nr, _ := strconv.Atoi(scanner.Text())
		if nr%2 == 0 {
			for i := nr - 2; i >= 1; i-- {
				fmt.Print(i, " ")
			}
		} else {
			for i := nr - 2; i >= 4; i-- {
				fmt.Print(i, " ")
			}
			for i := 1; i <= 3; i++ {
				fmt.Print(i, " ")
			}
		}
		fmt.Print(nr-1, " ")
		fmt.Println(nr)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		for i := n - 3; i > 1; i-- {
			fmt.Print(i, " ")
		}
		fmt.Print(n-2, 1, n-1, n)
		fmt.Println()
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var tc, n int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		fmt.Fscan(in, &n)
		if n%2 == 1 {
			fmt.Fprintf(out, "1 ")
		}
		for i := n - 2; i >= 2; i-- {
			fmt.Fprintf(out, "%d ", i)
		}
		if n%2 == 0 {
			fmt.Fprintf(out, "1 ")
		}
		fmt.Fprintf(out, "%d %d\n", n-1, n)
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&n)
		if n&1 == 1 {
			// 3 2 1 4 5 6 7
			for i := n-4; i >= 2; i-- {
				fmt.Printf("%d ", i)
			}
			fmt.Printf("1 %d %d %d %d\n", n-3, n-2, n-1, n)
		} else {
			for i := n-2; i >= 1; i-- {
				fmt.Printf("%d ", i)
			}
			fmt.Printf("%d %d\n", n-1, n)
		}
		// 1 0 1 0 1 0 n 是偶数的是可以的
		// n 是奇数的，把 1 2 留出来喽
		// 1 n-3 n-2 n-1 n
	}
}

package main

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

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

func solve(n int) string {
	var r []int
	if n%2 == 0 {
		for i := n - 2; i > 0; i-- {
			r = append(r, i)
		}
	} else {
		for i := n - 5; i > 0; i-- {
			r = append(r, i)
		}
		r = append(r, n-4)
		r = append(r, n-3)
		r = append(r, n-2)
	}
	r = append(r, n-1)
	r = append(r, n)
	return strings.Trim(fmt.Sprint(r), "[]")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

import "fmt"

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

	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		if n == 2 {
			fmt.Println("2 1 3")
			continue
		}
		for j := 1; j <= n; j++ {
			if j < n-1 {
				if n%2 == 0 {
					fmt.Printf("%d ", n-1-j)
				} else {
					if j <= 3 {
						fmt.Printf("%d ", j)
					} else {
						fmt.Printf("%d ", n-j+2)
					}
				}
			} else {
				fmt.Printf("%d ", j)
			}
		}
		fmt.Println()
	}
}

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

// format: 0,n-1,n
// 1,7,6,5,4,3,2,8,9
// 1,5,4,3,2,6,7
// 4,5,3,6,2,7,1,8,9

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	num, _ := strconv.Atoi(s.Text())

	for i := 0;i < num;i++ {
		s.Scan()
		n, _ := strconv.Atoi(s.Text())

		if n % 2 == 0 {
			for j := n - 2;j > 0;j-- {
				fmt.Printf("%d ", j)
			}
			fmt.Printf("%d %d\n", n - 1, n)
		} else {
			if n == 5 {
				fmt.Printf("1 2 3 4 5\n")
			} else {
				for j := n - 2;j > 3;j-- {
					fmt.Printf("%d ", j)
				}
				fmt.Printf("2 3 1 %d %d\n", n - 1, n)
			}
		}
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	if n%2 == 0 {
		for i := 2; i+2 <= n; i += 2 {
			printf("%d %d ", i, i-1)
		}
		printf("%d %d\n", n-1, n)
	} else {
		printf("1 ")
		for i := 2; i+2 <= n; i += 2 {
			printf("%d %d ", i+1, i)
		}
		printf("%d %d\n", n-1, n)
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
    "fmt"
)

func main() {
    var t int
    fmt.Scan(&t)
    for t != 0  {
        t--
        var n int
        fmt.Scan(&n)
        if n == 1 {
            fmt.Println("1")
            continue
        } else if n == 2 {
            fmt.Println("1 2")
            continue
        } else if n == 3 {
            fmt.Println("2 1 3")
            continue
        }
        a := make([]int, n)
        cur := 0
        if n % 2 != 0 {
            a[0] = 1
            a[1] = 2
            a[2] = 3
            cur = 3
        }
        for ;cur < n - 2; cur = cur + 2 {
            a[cur] = cur + 2
            a[cur + 1] = cur + 1
        }
        a[cur] = cur + 1
        a[cur + 1] = cur + 2
        for _, e := range a {
            fmt.Printf("%d ", e)
        }
        fmt.Printf("\n")
    }
}

// https://codeforces.com/contest/1728/problem/B
package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = j + 1
		}
		for t := n & 1; t < n-2; t += 2 {
			temp := a[t]
			a[t] = a[t+1]
			a[t+1] = temp
		}
		for j := 0; j < n; j++ {
			fmt.Printf("%d ", a[j])
		}
		fmt.Printf("\n")
	}
}

package main

import (
	"fmt"
)

const N = 2e2
const inf = 1e9

func main() {
	var t int
	fmt.Scan(&t)
	for t > 0 {
		t--
		var n int
		fmt.Scan(&n)
		var a [N]int
		a[n-2] = n - 1
		a[n-1] = n
		if n&1 > 0 {
			a[0] = 1
			a[1] = 2
			a[2] = 3
			for i := 3; i < n-2; i += 2 {
				a[i] = i + 2
				a[i+1] = i + 1
			}
		} else {
			for i := 0; i < n-2; i += 2 {
				a[i] = i + 2
				a[i+1] = i + 1
			}
		}
		for i := 0; i < n; i++ {
			fmt.Print(a[i], " ")
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
	"os"
)

func solve() {
	n := readInt()
	if n%2 == 0 {
		for i := 1; i+2 <= n; i += 2 {
			fmt.Print(i+1, i, " ")
		}
		fmt.Println(n-1, n)
	} else {
		fmt.Print("1 2 3 ")
		for i := 4; i+2 < n; i += 2 {
			fmt.Print(i+1, i, " ")
		}
		fmt.Println(n-1, n)
	}
}

func main() {
	t := readInt()

	for i := 0; i < t; i++ {
		solve()
	}
}

func readInt() int {
	var x int
	fmt.Fscan(os.Stdin, &x)
	return x
}

func iota(a []int, start int) {
	for i := 0; i < len(a); i++ {
		a[i] = start
		start++
	}
}

func next_permutation(a []int) bool {
	n := len(a)
	pos := n - 2
	for ; pos >= 0; pos-- {
		if a[pos] < a[pos+1] {
			break
		}
	}
	if pos == -1 {
		return false
	}
	for i := n - 1; i >= 0; i-- {
		if a[i] > a[pos] {
			a[i], a[pos] = a[pos], a[i]
			reverse(a[pos+1 : n])
			break
		}
	}
	return true
}

func reverse(a []int) {
	n := len(a)
	for i := 0; i < n/2; i++ {
		a[i], a[n-i-1] = a[n-i-1], a[i]
	}
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	data, _, _ := input.ReadLine()
	numOfTestCases, _ := strconv.Atoi(string(data))
	nums := make([]int, numOfTestCases)
	// each testcase
	for i := 0; i < numOfTestCases; i++ {
		data, _, _ = input.ReadLine()
		nums[i], _ = strconv.Atoi(string(data))
	}
	// start
	for i := 0; i < numOfTestCases; i++ {
		length := nums[i]
		// 确定最后2个数最大
		ans := make([]int, length)
		ans[length - 1] = length
		ans[length - 2] = length - 1
		// 保证前面的数算出的x为0
		// 前3位cancel掉
		if length & 1 == 1 {
			ans[0] = 1
			ans[1] = 2
			ans[2] = 3
			for j := 3; j < length - 2; j+=2 {
				ans[j], ans[j+1] = j+2, j+1
			}
		} else {
			for j := 0; j < length - 2; j+=2 {
				ans[j], ans[j+1] = j+2, j+1
			}
		}
		for _, num := range ans {
			fmt.Printf("%d ", num)
		}
		fmt.Println()
	}
}

package main

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

var a [200005]int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for cs := 0; cs < t; cs++ {
		var n int
		fmt.Fscan(in, &n)
		for i := 1; i <= n; i++ {
			a[i] = i
		}
		if n % 3 != 2 {
			a[n - 3], a[n - 2] = a[n - 2], a[n - 3]
		}
		if n % 3 == 0 {
			a[n - 4], a[n - 5] = a[n - 5], a[n - 4]
		}
		for i := 1; i < n; i++ {
			fmt.Fprintf(out, "%d ", a[i])
		}
		fmt.Fprintln(out, a[n])
	}
}

package main

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

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

func (in *CF1728B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1728B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1728B
Date: 9/10/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1728/B
Problem: CF1728B
**/
func (in *CF1728B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n == 4 {
			fmt.Print("2 1 3 4")
		} else if n == 5 {
			arr := make([]int, n)
			arr[n-1] = n
			arr[n-2] = n - 1
			arr[n-3] = 1
			arr[n-4] = 2
			arr[n-5] = 3
			for i := 0; i < n; i++ {
				fmt.Print(arr[i], " ")
			}
		} else {
			arr := make([]int, n)
			arr[n-1] = n
			arr[n-2] = n - 1
			arr[n-3] = 1
			arr[n-4] = 3
			arr[n-5] = 2
			for i, j := 4, 0; i < n-1; i++ {
				arr[j] = i
				j++
			}
			for i := 0; i < n; i++ {
				fmt.Print(arr[i], " ")
			}
		}
		fmt.Println()
	}

}

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

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

package main

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

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

func (in *CF1728B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1728B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1728B
Date: 9/10/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1728/B
Problem: CF1728B
**/
func (in *CF1728B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		if n == 4 {
			fmt.Print("2 1 3 4")
		} else if n == 5 {
			arr := make([]int, n)
			arr[n-1] = n
			arr[n-2] = n - 1
			arr[n-3] = 1
			arr[n-4] = 2
			arr[n-5] = 2
			for i := 0; i < n; i++ {
				fmt.Print(arr[i], " ")
			}
		} else {
			arr := make([]int, n)
			arr[n-1] = n
			arr[n-2] = n - 1
			arr[n-3] = 1
			arr[n-4] = 3
			arr[n-5] = 2
			for i, j := 4, 0; i < n-1; i++ {
				arr[j] = i
				j++
			}
			for i := 0; i < n; i++ {
				fmt.Print(arr[i], " ")
			}
		}
		fmt.Println()
	}

}

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

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

package main

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

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

func (in *CF1728B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1728B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1728B
Date: 9/10/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1728/B
Problem: CF1728B
**/
func (in *CF1728B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		if n%2 == 0 {
			for i := n - 2; i >= 1; i-- {
				fmt.Print(i, " ")
			}
			fmt.Println(n-1, n)
		} else {
			for i := 0; i < n; i++ {
				fmt.Print(i+1, " ")
			}
			fmt.Println()
		}
	}

}

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

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

package main

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

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

func (in *CF1728B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1728B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1728B
Date: 9/10/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1728/B
Problem: CF1728B
**/
func (in *CF1728B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		for i := n - 2; i >= 1; i-- {
			fmt.Print(i, " ")
		}
		fmt.Println(n-1, n)
	}

}

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

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

package main

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

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

func (in *CF1728B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1728B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1728B
Date: 9/10/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1728/B
Problem: CF1728B
**/
func (in *CF1728B) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		for i := 2; i <= n-2; i++ {
			fmt.Print(i, " ")
		}
		fmt.Println(1, n-1, n)
	}

}

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

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

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		if n%2 == 0 {

			for i := n - 2; i >= 1; i-- {
				fmt.Printf("%d ", i)
			}
			fmt.Printf("%d %d", n-1, n)
		} else {
			for i := 1; i <= n; i++ {
				fmt.Printf("%d ", i)
			}
		}
		fmt.Println()
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		if n%2 == 0 {
			fmt.Print("2 1 ")
			for i := 3; i <= n; i++ {
				fmt.Printf("%d ", i)
			}
		} else {
			for i := n - 2; i >= 1; i-- {
				fmt.Printf("%d ", i)
			}
			fmt.Printf("%d %d", n-1, n-2)
		}
		fmt.Println()
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	t = readInt(in)
	for t > 0 {
		t--
		n = readInt(in)
		if n%2 == 0 {
			fmt.Print("2 1 ")
			for i := 3; i <= n; i++ {
				fmt.Printf("%d ", i)
			}
		} else {
			for i := 1; i <= n; i++ {
				fmt.Printf("%d ", i)
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
	CF1728B()
}
func CF1728B() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := 1; j <= n; j++ {
			if n&1 == 0 {
				if j == n-3 {
					fmt.Print(j + 1)
				} else if j == n-2 {
					fmt.Print(j - 1)
				} else {
					fmt.Print(j)
				}
			} else {
				fmt.Print(j)
			}
			if j == n {
				fmt.Println("")
			} else {
				fmt.Print(" ")
			}
		}
	}
}
func CF1728A() {
	var t int
	fmt.Scan(&t)
	for t != 0 {
		t--
		var n int
		fmt.Scan(&n)
		var m int
		var mi int
		var i int = 1
		for n != 0 {
			n--
			var ai int
			fmt.Scan(&ai)
			if ai > m {
				m = ai
				mi = i
			}
			i++
		}
		fmt.Println(mi)
	}
}

package main

import "fmt"

func main() {
	CF1728B()
}
func CF1728B() {
	res := make(map[int]string, 97)
	res[4] = "2 1 3 4"
	res[5] = "1 2 3 4 5"
	for i := 6; i <= 100; i++ {
		res[i] = res[i-2] + " " + string(i+48-1) + " " + string(i+48)
	}
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		if r, ok := res[n]; ok {
			fmt.Println(r)
		} else {

		}
	}
}
func CF1728A() {
	var t int
	fmt.Scan(&t)
	for t != 0 {
		t--
		var n int
		fmt.Scan(&n)
		var m int
		var mi int
		var i int = 1
		for n != 0 {
			n--
			var ai int
			fmt.Scan(&ai)
			if ai > m {
				m = ai
				mi = i
			}
			i++
		}
		fmt.Println(mi)
	}
}

package main

import "fmt"

func main() {
	CF1728B()
}
func CF1728B() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		for j := 1; j <= n; j++ {
			fmt.Print(j)
			if j == n {
				fmt.Println("")
			} else {
				fmt.Print(" ")
			}
		}
	}
}
func CF1728A() {
	var t int
	fmt.Scan(&t)
	for t != 0 {
		t--
		var n int
		fmt.Scan(&n)
		var m int
		var mi int
		var i int = 1
		for n != 0 {
			n--
			var ai int
			fmt.Scan(&ai)
			if ai > m {
				m = ai
				mi = i
			}
			i++
		}
		fmt.Println(mi)
	}
}

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)

		aa := make([]int, n)
		for i := 0; i < n; i++ {
			aa[i] = i + 1
		}

		var x int
		for i := 0; i < n-2; i++ {
			if x < aa[i] {
				x += aa[i]
			} else {
				x = 0
			}
		}

		if x != 0 {
			aa[n-3], aa[n-4] = aa[n-4], aa[n-3]
		}
		for _, v := range aa {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

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)

		fmt.Fprintf(out, "%d %d 1 ", n-1, n)
		for i := 2; i <= n-2; i++ {
			fmt.Fprintf(out, "%d ", i)
		}
		fmt.Fprintln(out)
	}
}

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)

		for i := 2; i <= n-2; i++ {
			fmt.Fprintf(out, "%d ", i)
		}
		fmt.Fprintf(out, "1 %d %d\n", n-1, n)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	nrTests, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < nrTests; i++ {
		scanner.Scan()
		nr, _ := strconv.Atoi(scanner.Text())
		for i := nr - 2; i >= 1; i-- {
			fmt.Print(i, " ")
		}
		fmt.Print(nr-1, " ")
		fmt.Println(nr)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	nrTests, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < nrTests; i++ {
		scanner.Scan()
		nr, _ := strconv.Atoi(scanner.Text())
		for i := nr - 2; i >= 1; i-- {
			fmt.Print(i, " ")
		}
		fmt.Print(nr-1, " ")
		fmt.Print(nr)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		for i := n - 3; i > 1; i-- {
			print(i, " ")
		}
		fmt.Print(n-2, 1, n-1, n)
		println()
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		tmp := make([]int, n, n)
		for i := 1; i <= n; i++ {
			tmp[i-1] = i
		}
		var ret []int
		for i := n - 2; i > 1; i-- {
			if tmp[i]+tmp[i-1] > tmp[n-1] {
				// move to first
				ret = append(ret, tmp[i])
				tmp[i] = -1
			}
		}
		for _, v := range tmp {
			if v != -1 {
				ret = append(ret, v)
			}
		}
		for _, v := range ret {
			fmt.Print(v, " ")
		}
		fmt.Println()
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var tc, n int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		fmt.Fscan(in, &n)
		for i := 2; i <= n-2; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Printf("%d %d %d", 1, n-1, n)
		fmt.Println()
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var tc, n int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		fmt.Fscan(in, &n)
		for i := 1; i <= n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for t > 0 {
		t--
		fmt.Scan(&n)
		for i := n-2; i >= 1; i-- {
			fmt.Printf("%d ", i)
		}
		fmt.Printf("%d %d\n", n-1, n)
	}
}

package main

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

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

func solve(n int) string {
	var r []int
	for i := n - 2; i > 0; i-- {
		r = append(r, i)
	}
	r = append(r, n-1)
	r = append(r, n)
	return strings.Trim(fmt.Sprint(r), "[]")
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

import "fmt"

func main() {
	var t, n int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n)
		for j := 1; j <= n; j++ {
			if j < n-1 {
				fmt.Printf("%d ", n-1-j)
			} else {
				fmt.Printf("%d ", j)
			}
		}
		fmt.Println()
	}
}


Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (l2, i, r2, i).Anton needs to choose exactly one of n possible periods of time when he will attend chess classes and exactly one of m possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.The distance between periods (l1, r1) and (l2, r2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |i - j|, where l1 ≤ i ≤ r1 and l2 ≤ j ≤ r2. In particular, when the periods intersect, the distance between them is 0.Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of time periods when Anton can attend chess classes. Each of the following n lines of the input contains two integers l1, i and r1, i (1 ≤ l1, i ≤ r1, i ≤ 109) — the i-th variant of a period of time when Anton can attend chess classes. The following line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of time periods when Anton can attend programming classes. Each of the following m lines of the input contains two integers l2, i and r2, i (1 ≤ l2, i ≤ r2, i ≤ 109) — the i-th variant of a period of time when Anton can attend programming classes.

Output one integer — the maximal possible distance between time periods.

NoteIn the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3.In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.

package main

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

func main() {
	var n [2]int
	var lrs [2][2][]int

	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)

	for k := 0; k < 2; k++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err != io.EOF {
				return
			}
		} else {
			n[k], err = strconv.Atoi(re.ReplaceAllString(s, ""))
			if err != nil {
				return
			}
		}

		lrs[k][0] = make([]int, n[k])
		lrs[k][1] = make([]int, n[k])
		for i := 0; i < n[k]; i++ {
			if _in, err := reader.ReadString('\n'); err != nil {
				if err == io.EOF {
					break
				} else {
					return
				}
			} else {
				lr := strings.Split(re.ReplaceAllString(_in, ""), " ")
				if len(lr) != 2 {
					return
				}
				for j := 0; j < 2; j++ {
					lrs[k][j][i], err = strconv.Atoi(re.ReplaceAllString(lr[j], ""))
					if err != nil {
						return
					}
				}
			}
		}
	}

	merge_sort(lrs[0][0], 0, n[0]-1)
	merge_sort(lrs[0][1], 0, n[0]-1)
	merge_sort(lrs[1][0], 0, n[1]-1)
	merge_sort(lrs[1][1], 0, n[1]-1)

	diff := max(lrs[1][0][n[1]-1]-lrs[0][1][0], lrs[0][0][n[0]-1]-lrs[1][1][0])
	if diff > 0 {
		fmt.Println(diff)
	} else {
		fmt.Println(0)
	}
}

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

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

// Codeforces 785 B Anton and Classes
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
	"sort"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n,m int
var l1,r1,l2,r2 []int
var dist int

func readData() {
	in = bufio.NewReader(os.Stdin)
	n,_,_,_,_ = readFive()
	l1 = make([]int, n)
	r1 = make([]int, n)
	for i:=0; i<n; i++ {
		l1[i],r1[i],_,_,_ = readFive()
	}
	m,_,_,_,_ = readFive()
	l2 = make([]int, m)
	r2 = make([]int, m)
	for i:=0; i<m; i++ {
		l2[i],r2[i],_,_,_ = readFive()
	}
}

func solve() {
	dist = 0
	sort.Ints(l1)
	sort.Ints(r1)
	sort.Ints(l2)
	sort.Ints(r2)
	// check dist for r1 < l2
	d12 := l2[m-1]-r1[0]
	if dist < d12 {
		dist = d12
	}
	d21 := l1[n-1]-r2[0]
	if dist < d21 {
		dist = d21
	}
}

func printRes() {
	fmt.Println(dist)
}

func main() {
	readData()
	solve()
	printRes()
}

package main

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

//arr := strings.Split(strings.TrimSpace(line), " ")
//for i := range arr {
//tmp, _ := strconv.Atoi(arr[i])
//intArr = append(intArr, tmp)
//}

func main() {
	var line string
	var testcount, testcount2 int //, testcount2, i, j int
	var tmp int
	var intArr []int
	var maxSs, minSe, minPe, maxPs int
	minSe = 1000000001
	minPe = 1000000001
	fmt.Scanf("%d\n", &testcount)
	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < testcount; i++ {
		line, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(line), " ")
		for j := range arr {
			tmp, _ = strconv.Atoi(arr[j])
			intArr = append(intArr, tmp)
		}
		if i == testcount-1 {
			line, _ = reader.ReadString('\n')
			arr = strings.Split(strings.TrimSpace(line), " ")
			for j := range arr {
				tmp, _ = strconv.Atoi(arr[j])
				testcount2 = tmp
			}
		}
	}
	for i := 0; i < testcount2; i++ {
		line, _ = reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(line), " ")
		for j := range arr {
			tmp, _ = strconv.Atoi(arr[j])
			intArr = append(intArr, tmp)
		}
	}
	//	var maxSs, minSe, minPe, maxPs int
	for i := 0; i < testcount*2; i++ {
		if i%2 == 0 {
			if intArr[i] > maxSs {
				maxSs = intArr[i]
			}
		} else {
			if intArr[i] < minSe {
				minSe = intArr[i]
			}
		}
	}
	for i := testcount * 2; i < (testcount*2 + testcount2*2); i++ {
		if i%2 == 0 {
			if intArr[i] > maxPs {
				maxPs = intArr[i]
			}
		} else {
			if intArr[i] < minPe {
				minPe = intArr[i]
			}
		}
	}
	if (maxSs-minPe > 0) && (maxSs-minPe) > (maxPs-minSe) {
		fmt.Println(maxSs - minPe)
	} else if (maxPs-minSe > 0) && (maxPs-minSe) > (maxSs-minPe) {
		fmt.Println(maxPs - minSe)
	} else {
		fmt.Println(0)
	}
}

package main

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

type Tuple struct {
	l, r int
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	lrmn := int(1e9)
	llmx := 0
	for i := 0; i < N; i++ {
		l := Tuple{sc.NextInt(), sc.NextInt()}
		if lrmn > l.r {
			lrmn = l.r
		}
		if llmx < l.l {
			llmx = l.l
		}
	}

	M := sc.NextInt()
	ans := 0
	for i := 0; i < M; i++ {
		r := Tuple{sc.NextInt(), sc.NextInt()}
		dist := 0

		if r.r < llmx {
			dist = llmx - r.r
		} else if lrmn < r.l {
			dist = r.l - lrmn
		}
		if ans < dist {
			ans = dist
		}

	}
	fmt.Println(ans)

}

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

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

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

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

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

	return mp
}

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


It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.You are given two polynomials $$$f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1}$$$ and $$$g(x) = b_0 + b_1x + \dots + b_{m-1}x^{m-1}$$$, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to $$$1$$$ for both the given polynomials. In other words, $$$gcd(a_0, a_1, \dots, a_{n-1}) = gcd(b_0, b_1, \dots, b_{m-1}) = 1$$$. Let $$$h(x) = f(x)\cdot g(x)$$$. Suppose that $$$h(x) = c_0 + c_1x + \dots + c_{n+m-2}x^{n+m-2}$$$. You are also given a prime number $$$p$$$. Professor R challenges you to find any $$$t$$$ such that $$$c_t$$$ isn't divisible by $$$p$$$. He guarantees you that under these conditions such $$$t$$$ always exists. If there are several such $$$t$$$, output any of them.As the input is quite large, please use fast input reading methods.

The first line of the input contains three integers, $$$n$$$, $$$m$$$ and $$$p$$$ ($$$1 \leq n, m \leq 10^6, 2 \leq p \leq 10^9$$$),  — $$$n$$$ and $$$m$$$ are the number of terms in $$$f(x)$$$ and $$$g(x)$$$ respectively (one more than the degrees of the respective polynomials) and $$$p$$$ is the given prime number. It is guaranteed that $$$p$$$ is prime. The second line contains $$$n$$$ integers $$$a_0, a_1, \dots, a_{n-1}$$$ ($$$1 \leq a_{i} \leq 10^{9}$$$) — $$$a_i$$$ is the coefficient of $$$x^{i}$$$ in $$$f(x)$$$. The third line contains $$$m$$$ integers $$$b_0, b_1, \dots, b_{m-1}$$$ ($$$1 \leq b_{i} \leq 10^{9}$$$)  — $$$b_i$$$ is the coefficient of $$$x^{i}$$$ in $$$g(x)$$$.

Print a single integer $$$t$$$ ($$$0\le t \le n+m-2$$$)  — the appropriate power of $$$x$$$ in $$$h(x)$$$ whose coefficient isn't divisible by the given prime $$$p$$$. If there are multiple powers of $$$x$$$ that satisfy the condition, print any.

NoteIn the first test case, $$$f(x)$$$ is $$$2x^2 + x + 1$$$ and $$$g(x)$$$ is $$$x + 2$$$, their product $$$h(x)$$$ being $$$2x^3 + 5x^2 + 3x + 2$$$, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.In the second test case, $$$f(x)$$$ is $$$x + 2$$$ and $$$g(x)$$$ is $$$x + 3$$$, their product $$$h(x)$$$ being $$$x^2 + 5x + 6$$$, so the answer can be any of the powers as no coefficient is divisible by the given prime.

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n := NextInt()
	m := NextInt()
	p := NextInt()
	// a := list.New()
	// b := list.New()
	a := make([]int, n)
	b := make([]int, m)
	for i := 0; i < n; i++ {
		a[i] = NextInt()
	}
	for i := 0; i < m; i++ {
		b[i] = NextInt()
	}

	l, r := 0, 0
	for l < n && r < m {
		if a[l]%p == 0 {
			l++
			continue
		}
		if b[r]%p == 0 {
			r++
			continue
		}
		break
	}
	fmt.Fprintln(out, l+r)
}

package main

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

const maxCapacity = 1024 * 1024 * 10

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

func ioPrepare() {
	scanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)
}

func solve() {
	var n, m, p int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &n, &m, &p)
	ans := 0
	scanner.Scan()
	aStr := strings.Split(scanner.Text(), " ")
	for i, v := range aStr {
		a, _ := strconv.Atoi(v)
		if a%p != 0 {
			ans += i
			break
		}
	}
	scanner.Scan()
	bStr := strings.Split(scanner.Text(), " ")
	for i, v := range bStr {
		b, _ := strconv.Atoi(v)
		if b%p != 0 {
			ans += i
			break
		}
	}

	outputStr := fmt.Sprintf("%d\n", ans)
	writer.WriteString(outputStr)
}

func main() {
	ioPrepare()
	solve()
	writer.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1316C(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, m, p, x, y := read(), read(), read(), 0, 0
	for i := 0; i < n; i++ {
		if read()%p > 0 {
			x = i
		}
	}
	for i := 0; i < m; i++ {
		if read()%p > 0 {
			y = i
		}
	}
	Fprint(out, x+y)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1316C(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, m, p := read(), read(), read()
	a := make([]int, n)
	for i := range a {
		a[i] = read()
	}
	b := make([]int, m)
	for i := range b {
		b[i] = read()
	}

	i, j := 0, 0
	for a[i]%p == 0 {
		i++
	}
	for b[j]%p == 0 {
		j++
	}
	Fprint(out, i+j)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1316C(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, m, p, x, y := read(), read(), read(), 0, 0
	a := make([]int, n)
	for i := range a {
		a[i] = read()
		if a[i]%p > 0 {
			x = i
		}
	}
	b := make([]int, m)
	for i := range b {
		b[i] = read()
		if b[i]%p > 0 {
			y = i
		}
	}
	Fprint(out, x+y)
}

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

package main

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

var a [1000005]int
var b [1000005]int

func main() {
	n := ReadInt()
	m := ReadInt()
	p := ReadInt()
	for i := 0; i < n; i++ {
		a[i] = ReadInt() % p
	}
	for i := 0; i < m; i++ {
		b[i] = ReadInt() % p
	}
	x := 0
	y := 0
	for a[x] == 0 {
		x++
	}
	for b[y] == 0 {
		y++
	}
	fmt.Println(x + y)
}

////////////////////////////////////

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1316C(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, m, p, x, y := read(), read(), read(), 0, 0
	for i := 0; i < n; i++ {
		if read()%p > 0 {
			x = i
		}
	}
	for i := 0; i < m; i++ {
		if read()%p > 0 {
			y = i
			break
		}
	}
	Fprint(out, x+y)
}

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

package main

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

var a [1000005]int
var b [1000005]int

func main() {
	n := ReadInt()
	m := ReadInt()
	p := ReadInt()
	for i := 0; i < n; i++ {
		a[i] = ReadInt()
		a[i] %= p
	}
	for i := 0; i < m; i++ {
		b[i] = ReadInt()
		b[i] %= p
	}
	x := 0
	y := 0
	if a[x] == 0 {
		x++
	}
	if b[y] == 0 {
		y++
	}
	fmt.Println(x + y)
}

////////////////////////////////////

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

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

package main

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

var a [1000005]int
var b [1000005]int

func main() {
	n := ReadInt()
	m := ReadInt()
	p := ReadInt()
	for i := 0; i < n; i++ {
		a[i] = ReadInt() % p
	}
	for i := 0; i < m; i++ {
		b[i] = ReadInt() % p
	}
	x := 0
	y := 0
	if a[x] == 0 {
		x++
	}
	if b[y] == 0 {
		y++
	}
	fmt.Println(x + y)
}

////////////////////////////////////

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.ParseInt(intStr, 10, 32)
	return int(i)
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

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


On a random day, Neko found $$$n$$$ treasure chests and $$$m$$$ keys. The $$$i$$$-th chest has an integer $$$a_i$$$ written on it and the $$$j$$$-th key has an integer $$$b_j$$$ on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.The $$$j$$$-th key can be used to unlock the $$$i$$$-th chest if and only if the sum of the key number and the chest number is an odd number. Formally, $$$a_i + b_j \equiv 1 \pmod{2}$$$. One key can be used to open at most one chest, and one chest can be opened at most once.Find the maximum number of chests Neko can open.

The first line contains integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$) — the number of chests and the number of keys. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the numbers written on the treasure chests. The third line contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_m$$$ ($$$1 \leq b_i \leq 10^9$$$) — the numbers written on the keys.

Print the maximum number of chests you can open.

NoteIn the first example, one possible way to unlock $$$3$$$ chests is as follows:  Use first key to unlock the fifth chest,  Use third key to unlock the second chest,  Use fourth key to unlock the first chest. In the second example, you can use the only key to unlock any single chest (note that one key can't be used twice).In the third example, no key can unlock the given chest.

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

func main(){
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n,m,tmp := 0,0,0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	odd1, odd2, even1, even2 := 0,0,0,0
	for i:= 0; i<n; i++ {
		fmt.Fscanf(in, "%d", &tmp)
		if tmp%2==0 {
			even1++
		} else{
			odd1++
		}
	}
	fmt.Fscanf(in, "\n")
	for i:= 0; i<m; i++ {
		fmt.Fscanf(in, "%d", &tmp)
		if tmp%2==0 {
			even2++
		} else{
			odd2++
		}
	}
	z := min(odd1,even2) + min(odd2, even1)
	fmt.Fprintf(out, "%d\n", z)
	return
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	odd1, odd2, even1, even2 := 0, 0, 0, 0
	for i := 0; i < n; i++ {
		tmp := 0
		fmt.Fscanf(in, "%d", &tmp)
		if tmp%2 == 0 {
			even1++
		} else {
			odd1++
		}
	}
	fmt.Fscanf(in, "\n")
	for i := 0; i < m; i++ {
		tmp := 0
		fmt.Fscanf(in, "%d", &tmp)
		if tmp%2 == 0 {
			even2++
		} else {
			odd2++
		}
	}
	//fmt.Println(odd1, odd2, even1, even2)
	ans := min(odd1, even2) + min(odd2, even1)
	fmt.Fprintf(out, "%d\n", ans)
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

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

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

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

func main() {
	defer writer.Flush() // STDOUT MUST BE FLUSHED MANUALLY!!!
	var n, m int
	scan(&n, &m)
	var par, impar []int

	for i := 0; i < n; i++ {
		num := 0
		scan(&num)
		if num%2 == 0 {
			par = append(par, num)
		} else {
			impar = append(impar, num)
		}
	}

	cnt := 0

	for i := 0; i < m; i++ {
		num := 0
		scan(&num)

		if num%2 == 0 && len(impar) > 0 {
			impar = impar[:len(impar)-1]
			cnt++
			continue
		}

		if num%2 != 0 && len(par) > 0 {
			par = par[:len(par)-1]
			cnt++
			continue
		}
	}
	print(cnt)
	print("\n")
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math"
)
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 readLine()(string,error) 			{ return reader.ReadString('\n') }

func main() {
	defer writer.Flush()
	var n,m,t int
	scanf("%d %d\n", &n,&m)
	n1 := 0
	m1 := 0
	for i := 0; i < n ; i++ {
		scanf("%d" , &t)
		if t%2 == 0 {
			n1++
		}
	}
	scanf("\n")
	for i := 0; i < m ; i++ {
		scanf("%d" , &t)
		if t%2 == 0 {
			m1++
		}
	}

	fmt.Println(int64(math.Min(float64(n1), float64(m - m1)) + math.Min(float64(m1),float64(n - n1))))
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math"
)
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 readLine()(string,error) 			{ return reader.ReadString('\n') }

func main() {
	defer writer.Flush()
	var n,m,t int
	scanf("%d %d\n", &n,&m)
	n1 := 0
	m1 := 0
	for i := 0; i < n ; i++ {
		scanf("%d" , &t)
		fmt.Println(t)
		if t%2 == 0 {
			n1++
		}
	}
	scanf("\n")
	for i := 0; i < m ; i++ {
		scanf("%d" , &t)
		fmt.Println(t)
		if t%2 == 0 {
			m1++
		}
	}

	fmt.Println(int64(math.Min(float64(n1), float64(m - m1)) + math.Min(float64(m1),float64(n - n1))))
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math"
)
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 readLine()(string,error) 			{ return reader.ReadString('\n') }

func main() {
	defer writer.Flush()
	var n,m,t int
	scanf("%d %d", &n,&m)
	n1 := 0
	m1 := 0
	for i := 0; i < n ; i++ {
		scanf("%d" , &t)
		if t%2 == 0 {
			n1++
		}
	}
	for i := 0; i < m ; i++ {
		scanf("%d" , &t)
		if t%2 == 0 {
			m1++
		}
	}

	fmt.Println(int64(math.Min(float64(n1), float64(m - m1)) + math.Min(float64(m1),float64(n - n1))))
}


We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $$$a$$$ yuan for $$$b$$$ kilos (You don't need to care about what "yuan" is), the same as $$$a/b$$$ yuan for a kilo.Now imagine you'd like to buy $$$m$$$ kilos of apples. You've asked $$$n$$$ supermarkets and got the prices. Find the minimum cost for those apples.You can assume that there are enough apples in all supermarkets.

The first line contains two positive integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 5\,000$$$, $$$1 \leq m \leq 100$$$), denoting that there are $$$n$$$ supermarkets and you want to buy $$$m$$$ kilos of apples. The following $$$n$$$ lines describe the information of the supermarkets. Each line contains two positive integers $$$a, b$$$ ($$$1 \leq a, b \leq 100$$$), denoting that in this supermarket, you are supposed to pay $$$a$$$ yuan for $$$b$$$ kilos of apples.

The only line, denoting the minimum cost for $$$m$$$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $$$10^{-6}$$$. Formally, let your answer be $$$x$$$, and the jury's answer be $$$y$$$. Your answer is considered correct if $$$\frac{|x - y|}{\max{(1, |y|)}} \le 10^{-6}$$$.

NoteIn the first sample, you are supposed to buy $$$5$$$ kilos of apples in supermarket $$$3$$$. The cost is $$$5/3$$$ yuan.In the second sample, you are supposed to buy $$$1$$$ kilo of apples in supermarket $$$2$$$. The cost is $$$98/99$$$ yuan.

package main

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

func main() {
	var n, m int
	var a, b, minA, minB float64
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &m)
	fmt.Fscanf(stdin, "%f %f\n", &minA, &minB)
	for i := 1; i < n; i++ {
		fmt.Fscanf(stdin, "%f %f\n", &a, &b)
		if (minA / minB) > (a / b) {
			minA, minB = a, b
		}
	}
	fmt.Println(float64(m) * minA / minB)
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()
	n := readi()
	m := readi()
	ma := readi()
	mb := readi()
	for i := 1; i < n; i++ {
		a := readi()
		b := readi()
		if a*mb < ma*b {
			ma = a
			mb = b
		}
	}
	printf("%.8f\n", float64(ma*m)/float64(mb))

}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var m, a, b float64
	var ret float64 = math.MaxFloat64
	fmt.Scan(&n, &m)
	for i:=0; i < n; i++ {
		fmt.Scan(&a, &b)
		if x := a/b; x < ret {
			ret = x;
		}
	}
	fmt.Println(ret*m)
}

package main

import "fmt"
import "math"

func main() {
    var n,d int
    fmt.Scan(&n, &d)

    var minPrice float64 = math.MaxFloat64
    for i:=0; i<n; i++ {
        var a, b int
        fmt.Scan(&a, &b)
        p := float64(a) / float64(b)
        if p*float64(d) < minPrice {
            minPrice = p*float64(d)
        }
    }
    fmt.Print(minPrice)
}

package main

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

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), float64(sc.NextInt())
	mx := 0.0
	for i := 0; i < N; i++ {
		a, b := float64(sc.NextInt()), float64(sc.NextInt())
		if mx > M/b*a || mx == 0.0 {
			mx = M / b * a
		}
	}
	fmt.Println(mx)

}

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

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

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

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

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

	return mp
}

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

package main

import "fmt"

func main() {
    var n,d int
    fmt.Scan(&n, &d)

    var minPrice float64
    for i:=0; i<n; i++ {
        var a, b int
        fmt.Scan(&a, &b)
        p := float64(a) / float64(b)
        if p*float64(d) < minPrice {
            minPrice = p*float64(d)
        }
    }
    fmt.Print(minPrice)
}


Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color ti.For a fixed interval (set of consecutive elements) of balls we can define a dominant color. It's a color occurring the biggest number of times in the interval. In case of a tie between some colors, the one with the smallest number (index) is chosen as dominant.There are  non-empty intervals in total. For each color, your task is to count the number of intervals in which this color is dominant.

The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — the number of balls. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ n) where ti is the color of the i-th ball.

Print n integers. The i-th of them should be equal to the number of intervals where i is a dominant color.

NoteIn the first sample, color 2 is dominant in three intervals:  An interval [2, 2] contains one ball. This ball's color is 2 so it's clearly a dominant color.  An interval [4, 4] contains one ball, with color 2 again.  An interval [2, 4] contains two balls of color 2 and one ball of color 1. There are 7 more intervals and color 1 is dominant in all of them.

package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextLong() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextDouble() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

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

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = io.NextInt() - 1
	}
	C := make([]int, N)
	for i := 0; i < N; i++ {
		D := make([]int, N)
		D[A[i]]++
		argmax := A[i]
		C[argmax]++
		for j := i + 1; j < N; j++ {
			D[A[j]]++
			if D[argmax] < D[A[j]] || (D[argmax] == D[A[j]] && argmax > A[j]) {
				argmax = A[j]
			}
			C[argmax]++
		}
	}
	io.PrintIntLn(C)
}

package main

import (
	"bufio"
	"bytes"
	"container/heap"
	"fmt"
	"io"
	"os"
)

func main() {
	defer out.Flush()
	n := in.NextInt()
	t := make([]int, n)
	for i := range t {
		t[i] = in.NextInt() - 1
	}
	ans := make([]int, n)
	pq := NewPriorityQueue()
	items := make([]*Item, n)
	for j := range items {
		items[j] = new(Item)
		items[j].index = j
		pq.Push(items[j])
	}
	for i := 0; i < n; i++ {
		for L := 1; i+L <= n; L++ {
			items[t[i+L-1]].count++
			pq.Update(items[t[i+L-1]].heapIndex)
			ans[pq.Top().index]++
		}
		for j := range items {
			items[j].count = 0
		}
	}
	for i := range ans {
		if i != 0 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, ans[i])
	}
	fmt.Fprintln(out)
}

type Item struct {
	index     int
	count     int
	heapIndex int
}

func (a *Item) Less(b *Item) bool {
	if a.count != b.count {
		return a.count > b.count
	}
	return a.index < b.index
}

type PriorityQueue struct {
	heap pqHeap
}

func NewPriorityQueue() *PriorityQueue {
	pq := new(PriorityQueue)
	heap.Init(&pq.heap)
	return pq
}

func (pq *PriorityQueue) Push(item *Item) {
	heap.Push(&pq.heap, item)
}

func (pq *PriorityQueue) Pop() *Item {
	return heap.Pop(&pq.heap).(*Item)
}

func (pq *PriorityQueue) Remove(index int) *Item {
	return heap.Remove(&pq.heap, index).(*Item)
}

func (pq *PriorityQueue) Update(index int) {
	heap.Fix(&pq.heap, index)
}

func (pq *PriorityQueue) Top() *Item {
	return pq.heap[0]
}

func (pq *PriorityQueue) Len() int {
	return len(pq.heap)
}

type pqHeap []*Item

func (h pqHeap) Less(i, j int) bool {
	return h[i].Less(h[j])
}

func (h pqHeap) Swap(i, j int) {
	h[i], h[j] = h[j], h[i]
	h[i].heapIndex = i
	h[j].heapIndex = j
}

func (h pqHeap) Len() int {
	return len(h)
}

func (h *pqHeap) Push(x interface{}) {
	item := x.(*Item)
	item.heapIndex = len(*h)
	*h = append(*h, item)
}

func (h *pqHeap) Pop() interface{} {
	old := *h
	n := len(old)
	item := old[n-1]
	item.heapIndex = -1
	*h = old[:n-1]
	return item
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	var err error
	for len(r.buf) == 0 && err != io.EOF {
		buf := new(bytes.Buffer)
		for {
			var chunk []byte
			var more bool
			chunk, more, err = r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}